diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2011-04-04 21:17:14 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-04-04 21:17:14 +0200 |
commit | 05a6d9c992ebac6ec7a382c6f124e0e4f817a1ca (patch) | |
tree | c5b8332045547e7d729daa204a28fde6fdb124c9 | |
parent | 0a48595b5721790d2010a089e71688e804b78744 (diff) | |
download | mupdf-05a6d9c992ebac6ec7a382c6f124e0e4f817a1ca.tar.xz |
xps: Convert CMYK with alpha to RGB early to avoid premul alpha headaches.
-rw-r--r-- | fitz/res_pixmap.c | 29 | ||||
-rw-r--r-- | xps/xps_tiff.c | 12 |
2 files changed, 18 insertions, 23 deletions
diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index 9f336ab1..85138be1 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -106,31 +106,14 @@ fz_premultiplypixmap(fz_pixmap *pix) unsigned char a; int k, x, y; - /* special case for CMYK (subtractive colors) */ - if (pix->n == 5) + for (y = 0; y < pix->h; y++) { - for (y = 0; y < pix->h; y++) + for (x = 0; x < pix->w; x++) { - for (x = 0; x < pix->w; x++) - { - a = s[pix->n - 1]; - for (k = 0; k < pix->n - 1; k++) - s[k] = 255 - fz_mul255(255 - s[k], a); - s += pix->n; - } - } - } - else - { - for (y = 0; y < pix->h; y++) - { - for (x = 0; x < pix->w; x++) - { - a = s[pix->n - 1]; - for (k = 0; k < pix->n - 1; k++) - s[k] = fz_mul255(s[k], a); - s += pix->n; - } + a = s[pix->n - 1]; + for (k = 0; k < pix->n - 1; k++) + s[k] = fz_mul255(s[k], a); + s += pix->n; } } } diff --git a/xps/xps_tiff.c b/xps/xps_tiff.c index c4fdbfcd..384c4338 100644 --- a/xps/xps_tiff.c +++ b/xps/xps_tiff.c @@ -832,7 +832,19 @@ xps_decode_tiff(fz_pixmap **imagep, byte *buf, int len) /* We should only do this on non-pre-multiplied images, but files in the wild are bad */ if (tiff.extrasamples /* == 2 */) + { + /* CMYK is a subtractive colorspace, we want additive for premul alpha */ + if (image->n == 5) + { + fz_pixmap *rgb = fz_newpixmap(fz_devicergb, 0, 0, image->w, image->h); + fz_convertpixmap(image, rgb); + rgb->xres = image->xres; + rgb->yres = image->yres; + fz_droppixmap(image); + image = rgb; + } fz_premultiplypixmap(image); + } /* Clean up scratch memory */ |