aboutsummaryrefslogtreecommitdiff
path: root/fastiv-io.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-11-26 22:16:48 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-11-26 22:28:42 +0100
commit6c089eb1d2013be14338139e8215d86b1868608c (patch)
treed5ddb3ffc9a7980f4f1aff751c90bdf4baac714b /fastiv-io.c
parent18e96d8c9dd6b0346514121facf8137f13ccd6dc (diff)
downloadfiv-6c089eb1d2013be14338139e8215d86b1868608c.tar.gz
fiv-6c089eb1d2013be14338139e8215d86b1868608c.tar.xz
fiv-6c089eb1d2013be14338139e8215d86b1868608c.zip
Support CMYK JPEGs on big endian
Diffstat (limited to 'fastiv-io.c')
-rw-r--r--fastiv-io.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/fastiv-io.c b/fastiv-io.c
index 35e640d..426d4c7 100644
--- a/fastiv-io.c
+++ b/fastiv-io.c
@@ -497,7 +497,7 @@ open_wuffs_using(wuffs_base__image_decoder *(*allocate)(),
}
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:
//
@@ -505,10 +505,17 @@ trivial_cmyk_to_bgra(unsigned char *p, int len)
// does, see https://bugzilla.gnome.org/show_bug.cgi?id=618096
while (len--) {
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[1] = k * m / 255;
p[2] = k * c / 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;
}
}
@@ -644,11 +651,10 @@ open_libjpeg_turbo(const gchar *data, gsize len, GError **error)
return NULL;
}
- // TODO(p): Support big-endian machines, too, those need ARGB ordering.
if (pixel_format == TJPF_CMYK) {
// CAIRO_STRIDE_ALIGNMENT is 4 bytes, so there will be no padding with
// ARGB/BGR/XRGB/BGRX.
- trivial_cmyk_to_bgra(
+ trivial_cmyk_to_host_byte_order_argb(
cairo_image_surface_get_data(surface), width * height);
}