[poppler] poppler/poppler: GfxState.cc,1.5,1.6

Kristian Høgsberg krh at freedesktop.org
Sun Nov 20 15:17:34 PST 2005


Update of /cvs/poppler/poppler/poppler
In directory gabe:/tmp/cvs-serv11036/poppler

Modified Files:
	GfxState.cc 
Log Message:
2005-11-20  Kristian Høgsberg  <krh at redhat.com>

        * poppler/GfxState.cc: Fix the byte_lookup initialization broken
        by the merges (#4350).  Modify GfxColorSpace::getRGBLine() to work
        with new GfXColor type.



Index: GfxState.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/GfxState.cc,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- GfxState.cc	30 Oct 2005 20:29:05 -0000	1.5
+++ GfxState.cc	20 Nov 2005 23:17:32 -0000	1.6
@@ -194,7 +194,7 @@
   for (i = 0; i < length; i++) {
     
     for (j = 0; j < n; j++)
-      color.c[j] = in[i * n + j] / 255.0;
+      color.c[j] = in[i * n + j] * 256;
 
     getRGB (&color, &rgb);
     out[i] =
@@ -360,16 +360,14 @@
 		 0.11 * color->c[2] + 0.5));
 }
 
-// TODO THE ABOVE FORMULA HAS CHANGED MAYBE CHANGE THE BELOW ONE TOO?
-#warning read the TODO in this file
 void GfxDeviceRGBColorSpace::getGrayLine(Guchar *in, Guchar *out, int length) {
   int i;
 
   for (i = 0; i < length; i++) {
     out[i] = 
       (in[i * 3 + 0] * 19595 + 
-       in[i * 3 + 0] * 38469 + 
-       in[i * 3 + 0] * 7472) / 65536;
+       in[i * 3 + 1] * 38469 + 
+       in[i * 3 + 2] * 7472) / 65536;
   }
 }
 
@@ -513,15 +511,14 @@
 		 0.114 * color->c[2] + 0.5));
 }
 
-// TODO Same as above
 void GfxCalRGBColorSpace::getGrayLine(Guchar *in, Guchar *out, int length) {
   int i;
 
   for (i = 0; i < length; i++) {
     out[i] = 
       (in[i * 3 + 0] * 19595 + 
-       in[i * 3 + 0] * 38469 + 
-       in[i * 3 + 0] * 7472) / 65536;
+       in[i * 3 + 1] * 38469 + 
+       in[i * 3 + 2] * 7472) / 65536;
   }
 }
 
@@ -3237,7 +3234,8 @@
   Object obj;
   double x[gfxColorMaxComps];
   double y[gfxColorMaxComps];
-  int i, j, k;
+  int i, j, k, byte;
+  double mapped;
 
   ok = gTrue;
 
@@ -3295,18 +3293,21 @@
     nComps2 = colorSpace2->getNComps();
     lookup2 = indexedCS->getLookup();
     colorSpace2->getDefaultRanges(x, y, indexHigh);
+    byte_lookup = (Guchar *)gmalloc ((maxPixel + 1) * nComps2);
     for (k = 0; k < nComps2; ++k) {
       lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
 					   sizeof(GfxColorComp));
-    for (i = 0; i <= maxPixel; ++i) {
-      j = (int)(decodeLow[0] + (i * decodeRange[0]) / maxPixel + 0.5);
-      if (j < 0) {
-	j = 0;
-      } else if (j > indexHigh) {
-	j = indexHigh;
-      }
-	lookup[k][i] =
-	    dblToCol(x[k] + (lookup2[j*nComps2 + k] / 255.0) * y[k]);
+      for (i = 0; i <= maxPixel; ++i) {
+	j = (int)(decodeLow[0] + (i * decodeRange[0]) / maxPixel + 0.5);
+	if (j < 0) {
+	  j = 0;
+	} else if (j > indexHigh) {
+	  j = indexHigh;
+	}
+
+	mapped = x[k] + (lookup2[j*nComps2 + k] / 255.0) * y[k];
+	lookup[k][i] = dblToCol(mapped);
+	byte_lookup[i * nComps2 + k] = (Guchar) (mapped * 255);
       }
     }
   } else if (colorSpace->getMode() == csSeparation) {
@@ -3314,22 +3315,31 @@
     colorSpace2 = sepCS->getAlt();
     nComps2 = colorSpace2->getNComps();
     sepFunc = sepCS->getFunc();
+    byte_lookup = (Guchar *)gmallocn ((maxPixel + 1), nComps2);
     for (k = 0; k < nComps2; ++k) {
       lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
 					   sizeof(GfxColorComp));
-    for (i = 0; i <= maxPixel; ++i) {
-      x[0] = decodeLow[0] + (i * decodeRange[0]) / maxPixel;
-      sepFunc->transform(x, y);
+      for (i = 0; i <= maxPixel; ++i) {
+	x[0] = decodeLow[0] + (i * decodeRange[0]) / maxPixel;
+	sepFunc->transform(x, y);
 	lookup[k][i] = dblToCol(y[k]);
+	byte_lookup[i*nComps2 + k] = (Guchar) (y[k] * 255);
       }
     }
   } else {
-      for (k = 0; k < nComps; ++k) {
+    byte_lookup = (Guchar *)gmallocn ((maxPixel + 1), nComps);
+    for (k = 0; k < nComps; ++k) {
       lookup[k] = (GfxColorComp *)gmallocn(maxPixel + 1,
 					   sizeof(GfxColorComp));
       for (i = 0; i <= maxPixel; ++i) {
-	lookup[k][i] = dblToCol(decodeLow[k] +
-				(i * decodeRange[k]) / maxPixel);
+	mapped = decodeLow[k] + (i * decodeRange[k]) / maxPixel;
+	lookup[k][i] = dblToCol(mapped);
+	byte = (int) (mapped * 255.0 + 0.5);
+	if (byte < 0)  
+	  byte = 0;  
+	else if (byte > 255)  
+	  byte = 255;  
+	byte_lookup[i * nComps + k] = byte;	
       }
     }
   }
@@ -3386,6 +3396,7 @@
   for (i = 0; i < gfxColorMaxComps; ++i) {
     gfree(lookup[i]);
   }
+  gfree(byte_lookup);
 }
 
 void GfxImageColorMap::getGray(Guchar *x, GfxGray *gray) {



More information about the poppler mailing list