[gs-cvs] gs/src

Ray Johnston ray at ghostscript.com
Mon Jan 12 18:06:14 PST 2004


Update of /cvs/ghostscript/gs/src
In directory casper:/tmp/cvs-serv26044/src

Modified Files:
	gsdevmem.c gdevmem.c 
Log Message:
Fix problems with the "image" device when the palette is an 8-bit gray
palette (uses the image8 device with num_components == 1). Since the
DeviceN changes, changing num_components requires also setting the
gray_index value appropriately. Also the rgb to color mapping function
did not allow for num_components == 1 and used uninitialized values for
the green and blue comonents. Fixes bugs 458261, 686909 and 687204.

DETAILS:

The gray_index value was being left at GX_CINFO_COMP_NO_INDEX, so the
gx_device_has_color macro indicated a color device. This means that
when the gs_initialize_wordimagedevice function changed the num_components
value to 1, the gray_index was incorrect (should be 0 for a gray shade
device).

Also the mem_mapped_map_rgb_color function didn't check for num_components
== 1, thus using uninitialized cv[1] and cv[2] values and getting incorrect
palette selections. Also I optimized the single component case a bit as
well as an "early out" for both color and monochrome when diff == 0 (can't
get any better than a perfect match).

I guess 8-bit monochrome image devices haven't been used much.

Expected Differences:

none. (we don't test ps2epsi in the regression suite).


Index: gsdevmem.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/gsdevmem.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- gsdevmem.c	21 Feb 2002 22:24:52 -0000	1.4
+++ gsdevmem.c	13 Jan 2004 02:06:12 -0000	1.5
@@ -177,6 +177,7 @@
 	    new_dev->color_info.num_components = 1;
 	    new_dev->color_info.max_color = 0;
 	    new_dev->color_info.dither_colors = 0;
+	    new_dev->color_info.gray_index = 0;
 	}
     }
     new_dev->initial_matrix = *pmat;

Index: gdevmem.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/gdevmem.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- gdevmem.c	16 Sep 2002 22:04:43 -0000	1.6
+++ gdevmem.c	13 Jan 2004 02:06:12 -0000	1.7
@@ -529,33 +529,59 @@
 {
     gx_device_memory * const mdev = (gx_device_memory *)dev;
     byte br = gx_color_value_to_byte(cv[0]);
-    byte bg = gx_color_value_to_byte(cv[1]);
-    byte bb = gx_color_value_to_byte(cv[2]);
+    
     register const byte *pptr = mdev->palette.data;
     int cnt = mdev->palette.size;
     const byte *which = 0;	/* initialized only to pacify gcc */
     int best = 256 * 3;
 
-    while ((cnt -= 3) >= 0) {
-	register int diff = *pptr - br;
+    if (mdev->color_info.num_components != 1) {
+	/* not 1 component, assume three */
+	/* The comparison is rather simplistic, treating differences in	*/
+	/* all components as equal. Better choices would be 'distance'	*/
+	/* in HLS space or other, but these would be much slower.	*/
+	/* At least exact matches will be found.			*/
+	byte bg = gx_color_value_to_byte(cv[1]);
+	byte bb = gx_color_value_to_byte(cv[2]);
 
-	if (diff < 0)
-	    diff = -diff;
-	if (diff < best) {	/* quick rejection */
-	    int dg = pptr[1] - bg;
+	while ((cnt -= 3) >= 0) {
+	    register int diff = *pptr - br;
 
-	    if (dg < 0)
-		dg = -dg;
-	    if ((diff += dg) < best) {	/* quick rejection */
-		int db = pptr[2] - bb;
+	    if (diff < 0)
+		diff = -diff;
+	    if (diff < best) {	/* quick rejection */
+		    int dg = pptr[1] - bg;
 
-		if (db < 0)
-		    db = -db;
-		if ((diff += db) < best)
-		    which = pptr, best = diff;
+		if (dg < 0)
+		    dg = -dg;
+		if ((diff += dg) < best) {	/* quick rejection */
+		    int db = pptr[2] - bb;
+
+		    if (db < 0)
+			db = -db;
+		    if ((diff += db) < best)
+			which = pptr, best = diff;
+		}
 	    }
+	    if (diff == 0)	/* can't get any better than 0 diff */
+		break;
+	    pptr += 3;
+	}
+    } else {
+	/* Gray scale conversion. The palette is made of three equal	*/
+	/* components, so this case is simpler.				*/
+	while ((cnt -= 3) >= 0) {
+	    register int diff = *pptr - br;
+
+	    if (diff < 0)
+		diff = -diff;
+	    if (diff < best) {	/* quick rejection */
+		which = pptr, best = diff;
+	    }
+	    if (diff == 0)
+		break;
+	    pptr += 3;
 	}
-	pptr += 3;
     }
     return (gx_color_index) ((which - mdev->palette.data) / 3);
 }




More information about the gs-cvs mailing list