diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2009-07-04 18:30:24 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2009-07-04 18:30:24 +0100 |
commit | 9942a89870f7754e28ff334010c4432553cf7d91 (patch) | |
tree | cbcc1ca48c65bdc746d1f3ef455cbcc32179e639 /boilerplate | |
parent | 23648e2fdfefba4df08bc854d725758209998e1f (diff) |
[boilerplate] Read whole RGB lines at a time
Rather than read+unpack each pixel, read in a whole RGB packed line and
unpack the whole line in a single pass.
Diffstat (limited to 'boilerplate')
-rw-r--r-- | boilerplate/cairo-boilerplate.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c index af6f9fa86..f3e574c05 100644 --- a/boilerplate/cairo-boilerplate.c +++ b/boilerplate/cairo-boilerplate.c @@ -1102,19 +1102,20 @@ cairo_boilerplate_image_surface_create_from_ppm_stream (FILE *file) data = cairo_image_surface_get_data (image); stride = cairo_image_surface_get_stride (image); for (y = 0; y < height; y++) { - unsigned char *buf = data + y *stride; + unsigned char *buf = data + y*stride; switch (format) { case '7': if (! freadn (buf, 4 * width, file)) goto FAIL; break; case '6': - for (x = 0; x < width; x++) { - if (! freadn (buf, 3, file)) - goto FAIL; - *(uint32_t *) buf = + if (! freadn (buf, 3*width, file)) + goto FAIL; + buf += 3*width; + for (x = width; x--; ) { + buf -= 3; + ((uint32_t *) (data + y*stride))[x] = (buf[0] << 16) | (buf[1] << 8) | (buf[2] << 0); - buf += 4; } break; case '5': |