diff --git a/poppler/Function.cc b/poppler/Function.cc index 67283df..31348a9 100644 --- a/poppler/Function.cc +++ b/poppler/Function.cc @@ -43,6 +43,7 @@ #include "Stream.h" #include "Error.h" #include "Function.h" +#include "GfxState.h" #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -629,6 +630,10 @@ ExponentialFunction::ExponentialFunction(Object *funcObj, Dict *dict) { obj1.free(); isLinear = fabs(e-1.) < 1e-10; + inverted = c0[0] <= c1[0]; + for (i = 1; i < n; ++i) { + inverted = inverted && c0[i] <= c1[i]; + } ok = gTrue; return; @@ -650,6 +655,7 @@ ExponentialFunction::ExponentialFunction(const ExponentialFunction *func) : Func e = func->e; isLinear = func->isLinear; ok = func->ok; + inverted = func->inverted; } void ExponentialFunction::transform(double *in, double *out) { @@ -676,6 +682,10 @@ void ExponentialFunction::transform(double *in, double *out) { return; } +GBool ExponentialFunction::isInvertedFunction(GfxColorSpace *cs) { + return (cs->getMode() == csDeviceGray || cs->getMode() == csDeviceRGB) ? inverted : gFalse; +} + //------------------------------------------------------------------------ // StitchingFunction //------------------------------------------------------------------------ diff --git a/poppler/Function.h b/poppler/Function.h index 90e2a76..885b8bc 100644 --- a/poppler/Function.h +++ b/poppler/Function.h @@ -40,6 +40,7 @@ class Stream; struct PSObject; class PSStack; class PopplerCache; +class GfxColorSpace; //------------------------------------------------------------------------ // Function @@ -82,6 +83,7 @@ public: double getRangeMax(int i) { return range[i][1]; } GBool getHasRange() { return hasRange; } virtual GBool hasDifferentResultSet(Function *func) { return gFalse; } + virtual GBool isInvertedFunction(GfxColorSpace *cs) { return gFalse; } // Transform an input tuple into an output tuple. virtual void transform(double *in, double *out) = 0; @@ -175,6 +177,7 @@ public: virtual int getType() { return 2; } virtual void transform(double *in, double *out); virtual GBool isOk() { return ok; } + virtual GBool isInvertedFunction(GfxColorSpace *cs); double *getC0() { return c0; } double *getC1() { return c1; } @@ -189,6 +192,7 @@ private: double e; bool isLinear; GBool ok; + GBool inverted; }; //------------------------------------------------------------------------ diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc index ab796f7..6d402a5 100644 --- a/poppler/GfxState.cc +++ b/poppler/GfxState.cc @@ -2867,7 +2867,7 @@ void GfxSeparationColorSpace::getGray(GfxColor *color, GfxGray *gray) { x = colToDbl(color->c[0]); func->transform(&x, c); for (i = 0; i < alt->getNComps(); ++i) { - color2.c[i] = dblToCol(c[i]); + color2.c[i] = (func->isInvertedFunction(alt)) ? gfxColorComp1 - dblToCol(c[i]) : dblToCol(c[i]); } alt->getGray(&color2, gray); } @@ -2881,7 +2881,7 @@ void GfxSeparationColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) { x = colToDbl(color->c[0]); func->transform(&x, c); for (i = 0; i < alt->getNComps(); ++i) { - color2.c[i] = dblToCol(c[i]); + color2.c[i] = (func->isInvertedFunction(alt)) ? gfxColorComp1 - dblToCol(c[i]) : dblToCol(c[i]); } alt->getRGB(&color2, rgb); } @@ -2895,7 +2895,7 @@ void GfxSeparationColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) { x = colToDbl(color->c[0]); func->transform(&x, c); for (i = 0; i < alt->getNComps(); ++i) { - color2.c[i] = dblToCol(c[i]); + color2.c[i] = (func->isInvertedFunction(alt)) ? gfxColorComp1 - dblToCol(c[i]) : dblToCol(c[i]); } alt->getCMYK(&color2, cmyk); }