[poppler] poppler/GfxState.cc poppler/GfxState.h

Albert Astals Cid aacid at kemper.freedesktop.org
Fri Nov 28 02:11:47 PST 2014


 poppler/GfxState.cc |   51 ++++++++++++++++++++++++++++++++++++++-------------
 poppler/GfxState.h  |    4 +++-
 2 files changed, 41 insertions(+), 14 deletions(-)

New commits:
commit 832046c57ab2909d329340f1c941b29e8246ff73
Author: Thomas Freitag <Thomas.Freitag at alfa.de>
Date:   Fri Nov 28 11:08:34 2014 +0100

    Use correct LAB byte array for lcms input
    
    Bug #86388

diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc
index a303529..359c0d6 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);
   }
@@ -551,7 +552,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);
   }
@@ -2049,7 +2050,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 
@@ -2059,7 +2060,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);
@@ -2081,8 +2082,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;
@@ -2124,8 +2131,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;
@@ -2158,8 +2171,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;
@@ -2370,8 +2389,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;
@@ -6767,7 +6792,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,
@@ -6776,7 +6801,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,
@@ -6785,7 +6810,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,
@@ -6794,7 +6819,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 d5853e3..f018e93 100644
--- a/poppler/GfxState.h
+++ b/poppler/GfxState.h
@@ -183,9 +183,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();
@@ -194,6 +195,7 @@ private:
   void *transform;
   unsigned int refCount;
   int cmsIntent;
+  unsigned int inputPixelType;
   unsigned int transformPixelType;
 };
 


More information about the poppler mailing list