diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc index eae85dc..b0e1bfa 100644 --- a/poppler/GfxState.cc +++ b/poppler/GfxState.cc @@ -203,10 +203,11 @@ void GfxColorTransform::doTransform(void *in, void *out, unsigned int size) { } // transformA should be a cmsHTRANSFORM -GfxColorTransform::GfxColorTransform(void *transformA, int cmsIntentA, unsigned int transformPixelTypeA) { +GfxColorTransform::GfxColorTransform(void *transformA, int cmsIntentA, unsigned int inputPixelTypeA, unsigned int transformPixelTypeA) { transform = transformA; refCount = 1; cmsIntent = cmsIntentA; + inputPixelType = inputPixelTypeA; transformPixelType = transformPixelTypeA; } @@ -250,7 +251,7 @@ void GfxColorSpace::setDisplayProfile(void *displayProfileA) { INTENT_RELATIVE_COLORIMETRIC,LCMS_FLAGS)) == 0) { error(errSyntaxWarning, -1, "Can't create Lab transform"); } else { - XYZ2DisplayTransform = new GfxColorTransform(transform, INTENT_RELATIVE_COLORIMETRIC, displayPixelType); + XYZ2DisplayTransform = new GfxColorTransform(transform, INTENT_RELATIVE_COLORIMETRIC, PT_XYZ, displayPixelType); } cmsCloseProfile(XYZProfile); } @@ -452,7 +453,7 @@ int GfxColorSpace::setupColorProfiles() INTENT_RELATIVE_COLORIMETRIC,LCMS_FLAGS)) == 0) { error(errSyntaxWarning, -1, "Can't create Lab transform"); } else { - XYZ2DisplayTransform = new GfxColorTransform(transform, INTENT_RELATIVE_COLORIMETRIC, displayPixelType); + XYZ2DisplayTransform = new GfxColorTransform(transform, INTENT_RELATIVE_COLORIMETRIC, PT_XYZ, displayPixelType); } cmsCloseProfile(XYZProfile); } @@ -1950,7 +1951,7 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr, OutputDev *out, GfxState error(errSyntaxWarning, -1, "Can't create transform"); cs->transform = NULL; } else { - cs->transform = new GfxColorTransform(transform, cmsIntent, dcst); + cs->transform = new GfxColorTransform(transform, cmsIntent, cst, dcst); } if (dcst == PT_RGB || dcst == PT_CMYK) { // create line transform only when the display is RGB type color space @@ -1960,7 +1961,7 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr, OutputDev *out, GfxState error(errSyntaxWarning, -1, "Can't create transform"); cs->lineTransform = NULL; } else { - cs->lineTransform = new GfxColorTransform(transform, cmsIntent, dcst); + cs->lineTransform = new GfxColorTransform(transform, cmsIntent, cst, dcst); } } cmsCloseProfile(hp); @@ -1982,8 +1983,14 @@ void GfxICCBasedColorSpace::getGray(GfxColor *color, GfxGray *gray) { Guchar in[gfxColorMaxComps]; Guchar out[gfxColorMaxComps]; - for (int i = 0;i < nComps;i++) { + if (nComps == 3 && transform->getInputPixelType() == PT_Lab) { + in[0] = colToByte(dblToCol(colToDbl(color->c[0]) / 100.0)); + in[1] = colToByte(dblToCol((colToDbl(color->c[1]) + 128.0) / 255.0)); + in[2] = colToByte(dblToCol((colToDbl(color->c[2]) + 128.0) / 255.0)); + } else { + for (int i = 0;i < nComps;i++) { in[i] = colToByte(color->c[i]); + } } if (nComps <= 4) { unsigned int key = 0; @@ -2025,8 +2032,14 @@ void GfxICCBasedColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) { Guchar in[gfxColorMaxComps]; Guchar out[gfxColorMaxComps]; - for (int i = 0;i < nComps;i++) { + if (nComps == 3 && transform->getInputPixelType() == PT_Lab) { + in[0] = colToByte(dblToCol(colToDbl(color->c[0]) / 100.0)); + in[1] = colToByte(dblToCol((colToDbl(color->c[1]) + 128.0) / 255.0)); + in[2] = colToByte(dblToCol((colToDbl(color->c[2]) + 128.0) / 255.0)); + } else { + for (int i = 0;i < nComps;i++) { in[i] = colToByte(color->c[i]); + } } if (nComps <= 4) { unsigned int key = 0; @@ -2059,8 +2072,14 @@ void GfxICCBasedColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) { Guchar out[gfxColorMaxComps]; double c, m, y, k, c1, m1, y1, k1, r, g, b; - for (int i = 0;i < nComps;i++) { + if (nComps == 3 && transform->getInputPixelType() == PT_Lab) { + in[0] = colToByte(dblToCol(colToDbl(color->c[0]) / 100.0)); + in[1] = colToByte(dblToCol((colToDbl(color->c[1]) + 128.0) / 255.0)); + in[2] = colToByte(dblToCol((colToDbl(color->c[2]) + 128.0) / 255.0)); + } else { + for (int i = 0;i < nComps;i++) { in[i] = colToByte(color->c[i]); + } } if (nComps <= 4) { unsigned int key = 0; @@ -2271,8 +2290,14 @@ void GfxICCBasedColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) { Guchar in[gfxColorMaxComps]; Guchar out[gfxColorMaxComps]; - for (int i = 0;i < nComps;i++) { + if (nComps == 3 && transform->getInputPixelType() == PT_Lab) { + in[0] = colToByte(dblToCol(colToDbl(color->c[0]) / 100.0)); + in[1] = colToByte(dblToCol((colToDbl(color->c[1]) + 128.0) / 255.0)); + in[2] = colToByte(dblToCol((colToDbl(color->c[2]) + 128.0) / 255.0)); + } else { + for (int i = 0;i < nComps;i++) { in[i] = colToByte(color->c[i]); + } } if (nComps <= 4) { unsigned int key = 0; @@ -6668,7 +6693,7 @@ void GfxState::setDisplayProfile(cmsHPROFILE localDisplayProfileA) { INTENT_RELATIVE_COLORIMETRIC,LCMS_FLAGS)) == 0) { error(errSyntaxWarning, -1, "Can't create Lab transform"); } else { - XYZ2DisplayTransformRelCol = new GfxColorTransform(transform, INTENT_RELATIVE_COLORIMETRIC, localDisplayPixelType); + XYZ2DisplayTransformRelCol = new GfxColorTransform(transform, INTENT_RELATIVE_COLORIMETRIC, PT_XYZ, localDisplayPixelType); } if ((transform = cmsCreateTransform(XYZProfile, TYPE_XYZ_DBL, localDisplayProfile, @@ -6677,7 +6702,7 @@ void GfxState::setDisplayProfile(cmsHPROFILE localDisplayProfileA) { INTENT_ABSOLUTE_COLORIMETRIC,LCMS_FLAGS)) == 0) { error(errSyntaxWarning, -1, "Can't create Lab transform"); } else { - XYZ2DisplayTransformAbsCol = new GfxColorTransform(transform, INTENT_ABSOLUTE_COLORIMETRIC, localDisplayPixelType); + XYZ2DisplayTransformAbsCol = new GfxColorTransform(transform, INTENT_ABSOLUTE_COLORIMETRIC, PT_XYZ, localDisplayPixelType); } if ((transform = cmsCreateTransform(XYZProfile, TYPE_XYZ_DBL, localDisplayProfile, @@ -6686,7 +6711,7 @@ void GfxState::setDisplayProfile(cmsHPROFILE localDisplayProfileA) { INTENT_SATURATION,LCMS_FLAGS)) == 0) { error(errSyntaxWarning, -1, "Can't create Lab transform"); } else { - XYZ2DisplayTransformSat = new GfxColorTransform(transform, INTENT_SATURATION, localDisplayPixelType); + XYZ2DisplayTransformSat = new GfxColorTransform(transform, INTENT_SATURATION, PT_XYZ, localDisplayPixelType); } if ((transform = cmsCreateTransform(XYZProfile, TYPE_XYZ_DBL, localDisplayProfile, @@ -6695,7 +6720,7 @@ void GfxState::setDisplayProfile(cmsHPROFILE localDisplayProfileA) { INTENT_PERCEPTUAL,LCMS_FLAGS)) == 0) { error(errSyntaxWarning, -1, "Can't create Lab transform"); } else { - XYZ2DisplayTransformPerc = new GfxColorTransform(transform, INTENT_PERCEPTUAL, localDisplayPixelType); + XYZ2DisplayTransformPerc = new GfxColorTransform(transform, INTENT_PERCEPTUAL, PT_XYZ, localDisplayPixelType); } cmsCloseProfile(XYZProfile); } diff --git a/poppler/GfxState.h b/poppler/GfxState.h index 106b2c0..a1fef4b 100644 --- a/poppler/GfxState.h +++ b/poppler/GfxState.h @@ -182,9 +182,10 @@ class GfxColorTransform { public: void doTransform(void *in, void *out, unsigned int size); // transformA should be a cmsHTRANSFORM - GfxColorTransform(void *transformA, int cmsIntent, unsigned int transformPixelType); + GfxColorTransform(void *transformA, int cmsIntent, unsigned int inputPixelType, unsigned int transformPixelType); ~GfxColorTransform(); int getIntent() { return cmsIntent; } + int getInputPixelType() { return inputPixelType; } int getTransformPixelType() { return transformPixelType; } void ref(); unsigned int unref(); @@ -193,6 +194,7 @@ private: void *transform; unsigned int refCount; int cmsIntent; + unsigned int inputPixelType; unsigned int transformPixelType; };