Support CMYK JPEGs on big endian

This commit is contained in:
Přemysl Eric Janouch 2021-11-26 22:16:48 +01:00
parent 18e96d8c9d
commit 6c089eb1d2
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 9 additions and 3 deletions

View File

@ -497,7 +497,7 @@ open_wuffs_using(wuffs_base__image_decoder *(*allocate)(),
} }
static void static void
trivial_cmyk_to_bgra(unsigned char *p, int len) trivial_cmyk_to_host_byte_order_argb(unsigned char *p, int len)
{ {
// Inspired by gdk-pixbuf's io-jpeg.c: // Inspired by gdk-pixbuf's io-jpeg.c:
// //
@ -505,10 +505,17 @@ trivial_cmyk_to_bgra(unsigned char *p, int len)
// does, see https://bugzilla.gnome.org/show_bug.cgi?id=618096 // does, see https://bugzilla.gnome.org/show_bug.cgi?id=618096
while (len--) { while (len--) {
int c = p[0], m = p[1], y = p[2], k = p[3]; int c = p[0], m = p[1], y = p[2], k = p[3];
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
p[0] = k * y / 255; p[0] = k * y / 255;
p[1] = k * m / 255; p[1] = k * m / 255;
p[2] = k * c / 255; p[2] = k * c / 255;
p[3] = 255; p[3] = 255;
#else
p[3] = k * y / 255;
p[2] = k * m / 255;
p[1] = k * c / 255;
p[0] = 255;
#endif
p += 4; p += 4;
} }
} }
@ -644,11 +651,10 @@ open_libjpeg_turbo(const gchar *data, gsize len, GError **error)
return NULL; return NULL;
} }
// TODO(p): Support big-endian machines, too, those need ARGB ordering.
if (pixel_format == TJPF_CMYK) { if (pixel_format == TJPF_CMYK) {
// CAIRO_STRIDE_ALIGNMENT is 4 bytes, so there will be no padding with // CAIRO_STRIDE_ALIGNMENT is 4 bytes, so there will be no padding with
// ARGB/BGR/XRGB/BGRX. // ARGB/BGR/XRGB/BGRX.
trivial_cmyk_to_bgra( trivial_cmyk_to_host_byte_order_argb(
cairo_image_surface_get_data(surface), width * height); cairo_image_surface_get_data(surface), width * height);
} }