diff options
author | Kristian Høgsberg <krh@bitplanet.net> | 2011-11-22 14:40:00 -0500 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2011-11-22 14:40:48 -0500 |
commit | 02453dd699291cd6ef8f3e06ab24878cac9cc2aa (patch) | |
tree | d3f1f4525ff1cbcafdb1c8a8f3d89287bca1dfeb | |
parent | c5241f5b73b0ff67fd8f4223da7e78636d1a2fe4 (diff) |
cairo-util: Dont use non-standard JCS_EXT_BGRX color space
Everytime somebody has to write a channel swizzling loop,
God kills a kitten... and a dolphin and a unicorn.
-rw-r--r-- | clients/cairo-util.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/clients/cairo-util.c b/clients/cairo-util.c index 61a053b3..54a05b1a 100644 --- a/clients/cairo-util.c +++ b/clients/cairo-util.c @@ -289,13 +289,28 @@ rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius) cairo_close_path(cr); } +static void +swizzle_row(JSAMPLE *row, JDIMENSION width) +{ + JSAMPLE *s; + uint32_t *d; + + s = row + (width - 1) * 3; + d = (uint32_t *) (row + (width - 1) * 4); + while (s >= row) { + *d = 0xff000000 | (s[0] << 16) | (s[1] << 8) | (s[2] << 0); + s -= 3; + d--; + } +} + cairo_surface_t * load_jpeg(const char *filename) { struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; FILE *fp; - int stride, i; + int stride, i, first; JSAMPLE *data, *rows[4]; cinfo.err = jpeg_std_error(&jerr); @@ -310,7 +325,7 @@ load_jpeg(const char *filename) jpeg_read_header(&cinfo, TRUE); - cinfo.out_color_space = JCS_EXT_BGRX; + cinfo.out_color_space = JCS_RGB; jpeg_start_decompress(&cinfo); stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, @@ -322,10 +337,13 @@ load_jpeg(const char *filename) } while (cinfo.output_scanline < cinfo.output_height) { + first = cinfo.output_scanline; for (i = 0; i < ARRAY_LENGTH(rows); i++) - rows[i] = data + (cinfo.output_scanline + i) * stride; + rows[i] = data + (first + i) * stride; jpeg_read_scanlines(&cinfo, rows, ARRAY_LENGTH(rows)); + for (i = 0; first + i < cinfo.output_scanline; i++) + swizzle_row(rows[i], cinfo.output_width); } jpeg_finish_decompress(&cinfo); |