From fe1361f5a2af6783c30cf0790308aec9c97b8f8e Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 31 Dec 2010 12:11:40 +1030 Subject: [PATCH] cairo: Don't set JPX mime data if the stream specifies a colorspace The stream colorspace overides, and may be different to, the colorspace in the JPX data. https://bugs.freedesktop.org/show_bug.cgi?id=32746 --- poppler/CairoOutputDev.cc | 44 +++++++++++++++++++++++++++++--------------- poppler/CairoOutputDev.h | 1 + 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc index 0507f8c..c01c3fc 100644 --- a/poppler/CairoOutputDev.cc +++ b/poppler/CairoOutputDev.cc @@ -2283,6 +2283,34 @@ GBool CairoOutputDev::getStreamData (Stream *str, char **buffer, int *length) return gTrue; } +void CairoOutputDev::setMimeData(Stream *str, cairo_surface_t *image) +{ + char *strBuffer; + int len; + Object obj; + + if (!printing || !(str->getKind() == strDCT || str->getKind() == strJPX)) + return; + + // colorspace in stream dict may be different from colorspace in jpx + // data + if (str->getKind() == strJPX) { + if (str->getDict()->lookup("ColorSpace", &obj)) + return; + } + + if (getStreamData (str->getNextStream(), &strBuffer, &len)) { + cairo_status_t st; + st = cairo_surface_set_mime_data (image, + str->getKind() == strDCT ? + CAIRO_MIME_TYPE_JPEG : CAIRO_MIME_TYPE_JP2, + (const unsigned char *)strBuffer, len, + gfree, strBuffer); + if (st) + gfree (strBuffer); + } +} + void CairoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, @@ -2396,21 +2424,7 @@ void CairoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, cairo_surface_mark_dirty (image); - if (printing && (str->getKind() == strDCT || str->getKind() == strJPX)) { - char *strBuffer; - int len; - - if (getStreamData (str->getNextStream(), &strBuffer, &len)) { - cairo_status_t st; - st = cairo_surface_set_mime_data (image, - str->getKind() == strDCT ? - CAIRO_MIME_TYPE_JPEG : CAIRO_MIME_TYPE_JP2, - (const unsigned char *)strBuffer, len, - gfree, strBuffer); - if (st) - gfree (strBuffer); - } - } + setMimeData(str, image); pattern = cairo_pattern_create_for_surface (image); cairo_surface_destroy (image); diff --git a/poppler/CairoOutputDev.h b/poppler/CairoOutputDev.h index 26efadc..30acf81 100644 --- a/poppler/CairoOutputDev.h +++ b/poppler/CairoOutputDev.h @@ -275,6 +275,7 @@ protected: cairo_filter_t getFilterForSurface(cairo_surface_t *image, GBool interpolate); GBool getStreamData (Stream *str, char **buffer, int *length); + void setMimeData(Stream *str, cairo_surface_t *image); GfxRGB fill_color, stroke_color; cairo_pattern_t *fill_pattern, *stroke_pattern; -- 1.7.1