From ae20681b54c54755d14cd4631ed13b2a19eeaa67 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 6 May 2014 13:05:04 +0200 Subject: Fix 694909: revert "Force colorspaces to match with JPX images." and ... ... instead convert a JPEG2000 used as a soft mask into grayscale. This is more robust than trusting the PDF specified colorspace over the internal JPX colorspace. The spec implies that in a colorspace conflict, the internal JPX colorspace should be used. The PDF colorspace may be a DeviceN or Separation colorspace. DeviceN and Separation colorspaces are not valid destination colorspaces, so we may not always be able to convert the internal JPX colorspace into the PDF specified colorspace. Converting from the internal colorspace into grayscale is more robust, and solves the issue that the original commit was intended to fix. --- source/fitz/load-jpx.c | 10 ---------- source/pdf/pdf-image.c | 10 +++++++++- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/source/fitz/load-jpx.c b/source/fitz/load-jpx.c index dfb89f41..dd7bf9e1 100644 --- a/source/fitz/load-jpx.c +++ b/source/fitz/load-jpx.c @@ -75,7 +75,6 @@ fz_pixmap * fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs, int indexed) { fz_pixmap *img; - fz_colorspace *origcs; opj_dparameters_t params; opj_codec_t *codec; opj_image_t *jpx; @@ -179,7 +178,6 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs else if (n > 4) { n = 4; a = 1; } else { a = 0; } - origcs = defcs; if (defcs) { if (defcs->n == n) @@ -246,13 +244,5 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs fz_premultiply_pixmap(ctx, img); } - if (origcs != defcs) - { - fz_pixmap *tmp = fz_new_pixmap(ctx, origcs, w, h); - fz_convert_pixmap(ctx, tmp, img); - fz_drop_pixmap(ctx, img); - img = tmp; - } - return img; } diff --git a/source/pdf/pdf-image.c b/source/pdf/pdf-image.c index bb663ba2..9f4195e4 100644 --- a/source/pdf/pdf-image.c +++ b/source/pdf/pdf-image.c @@ -40,7 +40,15 @@ pdf_load_image_imp(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, fz_stream *cs { fz_pixmap *mask_pixmap; if (image->n != 2) - fz_throw(ctx, FZ_ERROR_GENERIC, "soft mask must be grayscale"); + { + fz_pixmap *gray; + fz_irect bbox; + fz_warn(ctx, "soft mask should be grayscale"); + gray = fz_new_pixmap_with_bbox(ctx, fz_device_gray(ctx), fz_pixmap_bbox(ctx, image->tile, &bbox)); + fz_convert_pixmap(ctx, gray, image->tile); + fz_drop_pixmap(ctx, image->tile); + image->tile = gray; + } mask_pixmap = fz_alpha_from_gray(ctx, image->tile, 1); fz_drop_pixmap(ctx, image->tile); image->tile = mask_pixmap; -- cgit v1.2.3