From 200cd7237b794eb46927f00f837d63138cea6240 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 24 Sep 2014 21:20:42 +0930 Subject: [PATCH] cairo: Only embed mime data for gray/rgb/cmyk colorspaces Bug 80719 --- poppler/CairoOutputDev.cc | 39 +++++++++++++++++++++++++++++++-------- poppler/CairoOutputDev.h | 2 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc index 1c67b5c..d25243f 100644 --- a/poppler/CairoOutputDev.cc +++ b/poppler/CairoOutputDev.cc @@ -2571,7 +2571,7 @@ void CairoOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *s cairo_surface_mark_dirty (image); - setMimeData(str, ref, image); + setMimeData(state, str, ref, image); pattern = cairo_pattern_create_for_surface (image); cairo_surface_destroy (image); @@ -2674,22 +2674,45 @@ GBool CairoOutputDev::getStreamData (Stream *str, char **buffer, int *length) return gTrue; } -void CairoOutputDev::setMimeData(Stream *str, Object *ref, cairo_surface_t *image) +void CairoOutputDev::setMimeData(GfxState *state, Stream *str, Object *ref, cairo_surface_t *image) { char *strBuffer; int len; Object obj; + GfxColorSpace *colorSpace; if (!printing || !(str->getKind() == strDCT || str->getKind() == strJPX)) return; + str->getDict()->lookup("ColorSpace", &obj); + colorSpace = GfxColorSpace::parse(&obj, this, state); + obj.free(); + // colorspace in stream dict may be different from colorspace in jpx // data - if (str->getKind() == strJPX) { - GBool hasColorSpace = !str->getDict()->lookup("ColorSpace", &obj)->isNull(); - obj.free(); - if (hasColorSpace) - return; + if (str->getKind() == strJPX && colorSpace) + return; + + // only embed mime data for gray, rgb, and cmyk colorspaces. + if (colorSpace) { + GfxColorSpaceMode mode = colorSpace->getMode(); + delete colorSpace; + switch (mode) { + case csDeviceGray: + case csCalGray: + case csDeviceRGB: + case csCalRGB: + case csDeviceCMYK: + case csICCBased: + break; + + case csLab: + case csIndexed: + case csSeparation: + case csDeviceN: + case csPattern: + return; + } } if (getStreamData (str->getNextStream(), &strBuffer, &len)) { @@ -2909,7 +2932,7 @@ void CairoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, filter = getFilterForSurface (image, interpolate); if (!inlineImg) /* don't read stream twice if it is an inline image */ - setMimeData(str, ref, image); + setMimeData(state, str, ref, image); pattern = cairo_pattern_create_for_surface (image); cairo_surface_destroy (image); diff --git a/poppler/CairoOutputDev.h b/poppler/CairoOutputDev.h index 28f97fd..bad88a8 100644 --- a/poppler/CairoOutputDev.h +++ b/poppler/CairoOutputDev.h @@ -276,7 +276,7 @@ protected: cairo_filter_t getFilterForSurface(cairo_surface_t *image, GBool interpolate); GBool getStreamData (Stream *str, char **buffer, int *length); - void setMimeData(Stream *str, Object *ref, cairo_surface_t *image); + void setMimeData(GfxState *state, Stream *str, Object *ref, cairo_surface_t *image); void fillToStrokePathClip(GfxState *state); void alignStrokeCoords(GfxSubpath *subpath, int i, double *x, double *y); -- 2.1.0