summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-03-31 15:04:30 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-03-31 15:04:30 +0200
commitaf6d16923fab4597e364c891fee2deb89998bdde (patch)
treea664fed72ae61c6447c80c35b8d8b477bf2a0076
parentf158d944be90b6657c57f3ad850b814c1d5ade59 (diff)
downloadmupdf-af6d16923fab4597e364c891fee2deb89998bdde.tar.xz
xps: Fix bugs in TIFF reader.
WhiteIsBlack was flipped for fax images. re-multiplying alpha with CMYK images needs special care because of subtractive colors.
-rw-r--r--fitz/res_pixmap.c30
-rw-r--r--xps/xpstiff.c10
2 files changed, 28 insertions, 12 deletions
diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c
index b37b7a3e..93fdb307 100644
--- a/fitz/res_pixmap.c
+++ b/fitz/res_pixmap.c
@@ -103,14 +103,32 @@ fz_premultiplypixmap(fz_pixmap *pix)
unsigned char *s = pix->samples;
unsigned char a;
int k, x, y;
- for (y = 0; y < pix->h; y++)
+
+ /* special case for CMYK (subtractive colors) */
+ if (pix->n == 5)
+ {
+ 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] = 255 - fz_mul255(255 - s[k], a);
+ s += pix->n;
+ }
+ }
+ }
+ else
{
- for (x = 0; x < pix->w; x++)
+ for (y = 0; y < pix->h; y++)
{
- a = s[pix->n - 1];
- for (k = 0; k < pix->n - 1; k++)
- s[k] = fz_mul255(s[k], a);
- s += pix->n;
+ 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;
+ }
}
}
}
diff --git a/xps/xpstiff.c b/xps/xpstiff.c
index 4c9494f2..889635a8 100644
--- a/xps/xpstiff.c
+++ b/xps/xpstiff.c
@@ -187,7 +187,7 @@ xps_decode_tiff_fax(xps_context *ctx, xps_tiff *tiff, int comp, fz_stream *chain
columns = fz_newint(tiff->imagewidth);
rows = fz_newint(tiff->imagelength);
- blackis1 = fz_newbool(tiff->photometric == 0);
+ blackis1 = fz_newbool(tiff->photometric != 0);
k = fz_newint(comp == 4 ? -1 : 0);
encodedbytealign = fz_newbool(comp == 2);
@@ -324,8 +324,6 @@ xps_expand_tiff_colormap(xps_context *ctx, xps_tiff *tiff)
stride = tiff->imagewidth * (tiff->samplesperpixel + 2);
samples = fz_malloc(stride * tiff->imagelength);
- if (!samples)
- return fz_throw("out of memory: samples");
for (y = 0; y < tiff->imagelength; y++)
{
@@ -353,10 +351,10 @@ xps_expand_tiff_colormap(xps_context *ctx, xps_tiff *tiff)
}
}
+ tiff->samplesperpixel += 2;
tiff->bitspersample = 8;
tiff->stride = stride;
tiff->samples = samples;
-
return fz_okay;
}
@@ -841,8 +839,8 @@ xps_decode_tiff(xps_image **imagep, xps_context *ctx, byte *buf, int len)
fz_unpacktile(pixmap, tiff.samples, tiff.samplesperpixel, tiff.bitspersample, tiff.stride, 0);
- /* Non-pre-multiplied transparency */
- if (tiff.extrasamples == 2)
+ /* We should only do this on non-pre-multiplied images, but files in the wild are bad */
+ if (tiff.extrasamples /* == 2 */)
fz_premultiplypixmap(pixmap);
image = fz_malloc(sizeof(xps_image));