summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-03-19 15:19:17 +0000
committerRobin Watts <robin.watts@artifex.com>2012-03-19 15:19:17 +0000
commitd11a38dbd783b746d7a35f03fecfb3cbca65527e (patch)
tree968ced2794aac77e45b1b1cc2567f2ee4f57f838
parent3598f93db06f029ce4851cc0b43bdfa9ec182a2d (diff)
downloadmupdf-d11a38dbd783b746d7a35f03fecfb3cbca65527e.tar.xz
Bug 692746; avoid 'double palettes' on jpx images.
It seems that JPX images can be supplied in indexed format, with both a palette internal to the jpx stream, and a palette in the PDF. Googling seems to suggest that the internal palette should be ignored in this case, and the external palette applied. Fortunately, since OpenJPEG-1.5 there is a flag that can be used to tell OpenJPEG not to decode palettes. We update the code here to spot that there is an external palette, and to set this flag.
-rw-r--r--fitz/fitz-internal.h2
-rw-r--r--fitz/image_jpx.c4
-rw-r--r--pdf/pdf_image.c2
3 files changed, 5 insertions, 3 deletions
diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h
index eda9736a..ae64b89d 100644
--- a/fitz/fitz-internal.h
+++ b/fitz/fitz-internal.h
@@ -639,7 +639,7 @@ struct fz_image_s
fz_pixmap *(*get_pixmap)(fz_context *, fz_image *, int w, int h);
};
-fz_pixmap *fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *cs);
+fz_pixmap *fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *cs, int indexed);
fz_pixmap *fz_load_jpeg(fz_context *doc, unsigned char *data, int size);
fz_pixmap *fz_load_png(fz_context *doc, unsigned char *data, int size);
fz_pixmap *fz_load_tiff(fz_context *doc, unsigned char *data, int size);
diff --git a/fitz/image_jpx.c b/fitz/image_jpx.c
index ac1db35a..af5ef263 100644
--- a/fitz/image_jpx.c
+++ b/fitz/image_jpx.c
@@ -21,7 +21,7 @@ static void fz_opj_info_callback(const char *msg, void *client_data)
}
fz_pixmap *
-fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs)
+fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs, int indexed)
{
fz_pixmap *img;
opj_event_mgr_t evtmgr;
@@ -50,6 +50,8 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs
evtmgr.info_handler = fz_opj_info_callback;
opj_set_default_decoder_parameters(&params);
+ if (indexed)
+ params.flags |= OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
info = opj_create_decompress(format);
opj_set_event_mgr((opj_common_ptr)info, &evtmgr, ctx);
diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c
index 17996a74..dc9cc088 100644
--- a/pdf/pdf_image.c
+++ b/pdf/pdf_image.c
@@ -504,7 +504,7 @@ pdf_load_jpx(pdf_document *xref, pdf_obj *dict, pdf_image *image)
indexed = !strcmp(colorspace->name, "Indexed");
}
- img = fz_load_jpx(ctx, buf->data, buf->len, colorspace);
+ img = fz_load_jpx(ctx, buf->data, buf->len, colorspace, indexed);
/* RJW: "cannot load jpx image" */
if (img && colorspace == NULL)