diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc index 9cff25f..9f4d19d 100644 --- a/poppler/Gfx.cc +++ b/poppler/Gfx.cc @@ -1306,6 +1306,7 @@ void Gfx::doSoftMask(Object *str, GBool alpha, } void Gfx::opSetRenderingIntent(Object args[], int numArgs) { + state->setRenderingIntent(args[0].getName()); } //------------------------------------------------------------------------ @@ -4130,7 +4131,22 @@ void Gfx::doImage(Object *ref, Stream *str, GBool inlineImg) { } } if (!obj1.isNull()) { + Object objIntent; + char *tempIntent = NULL; + dict->lookup("Intent", &objIntent); + if (objIntent.isName()) { + tempIntent = state->getRenderingIntent(); + if (tempIntent != NULL) { + tempIntent = strdup(tempIntent); + } + state->setRenderingIntent(objIntent.getName()); + } colorSpace = GfxColorSpace::parse(&obj1, this); + if (objIntent.isName()) { + state->setRenderingIntent(tempIntent); + free(tempIntent); + } + objIntent.free(); } else if (csMode == streamCSDeviceGray) { colorSpace = new GfxDeviceGrayColorSpace(); } else if (csMode == streamCSDeviceRGB) { diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc index 78ac5a8..0956d32 100644 --- a/poppler/GfxState.cc +++ b/poppler/GfxState.cc @@ -1515,12 +1515,26 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr, Gfx *gfx) { unsigned int dNChannels = getCMSNChannels(cmsGetColorSpace(dhp)); unsigned int dcst = getCMSColorSpaceType(cmsGetColorSpace(dhp)); cmsHTRANSFORM transform; + + int cmsIntent = INTENT_RELATIVE_COLORIMETRIC; + if (gfx != NULL) { + const char *intent = gfx->getState()->getRenderingIntent(); + if (intent != NULL) { + if (strcmp(intent, "AbsoluteColorimetric") == 0) { + cmsIntent = INTENT_ABSOLUTE_COLORIMETRIC; + } else if (strcmp(intent, "Saturation") == 0) { + cmsIntent = INTENT_SATURATION; + } else if (strcmp(intent, "Perceptual") == 0) { + cmsIntent = INTENT_PERCEPTUAL; + } + } + } + if ((transform = cmsCreateTransform(hp, - COLORSPACE_SH(cst) |CHANNELS_SH(nCompsA) | BYTES_SH(1), + COLORSPACE_SH(cst) | CHANNELS_SH(nCompsA) | BYTES_SH(1), dhp, - COLORSPACE_SH(dcst) | - CHANNELS_SH(dNChannels) | BYTES_SH(1), - INTENT_RELATIVE_COLORIMETRIC,0)) == 0) { + COLORSPACE_SH(dcst) | CHANNELS_SH(dNChannels) | BYTES_SH(1), + cmsIntent, 0)) == 0) { error(-1, "Can't create transform"); cs->transform = NULL; } else { @@ -1529,8 +1543,10 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr, Gfx *gfx) { if (dcst == PT_RGB) { // create line transform only when the display is RGB type color space if ((transform = cmsCreateTransform(hp, - CHANNELS_SH(nCompsA) | BYTES_SH(1),dhp, - TYPE_RGB_8,INTENT_RELATIVE_COLORIMETRIC,0)) == 0) { + CHANNELS_SH(nCompsA) | BYTES_SH(1), + dhp, + TYPE_RGB_8, + cmsIntent, 0)) == 0) { error(-1, "Can't create transform"); cs->lineTransform = NULL; } else { @@ -4732,6 +4748,8 @@ GfxState::GfxState(double hDPIA, double vDPIA, PDFRectangle *pageBox, clipXMax = pageWidth; clipYMax = pageHeight; + renderingIntent = NULL; + saved = NULL; #ifdef USE_CMS GfxColorSpace::setupColorProfiles(); diff --git a/poppler/GfxState.h b/poppler/GfxState.h index b425b4a..b382d1e 100644 --- a/poppler/GfxState.h +++ b/poppler/GfxState.h @@ -1290,6 +1290,7 @@ public: double getLeading() { return leading; } double getRise() { return rise; } int getRender() { return render; } + char *getRenderingIntent() { return renderingIntent; } GfxPath *getPath() { return path; } void setPath(GfxPath *pathA); double getCurX() { return curX; } @@ -1367,6 +1368,15 @@ public: { rise = riseA; } void setRender(int renderA) { render = renderA; } + void setRenderingIntent(const char *intent) + { + free(renderingIntent); + if (intent != NULL) { + renderingIntent = strdup(intent); + } else { + renderingIntent = NULL; + } + } // Add to path. void moveTo(double x, double y) @@ -1453,6 +1463,7 @@ private: double clipXMin, clipYMin, // bounding box for clip region clipXMax, clipYMax; + char *renderingIntent; GfxState *saved; // next GfxState on stack