[gs-cvs] gs/src
Ray Johnston
ray at ghostscript.com
Fri Feb 13 10:45:02 PST 2004
Update of /cvs/ghostscript/gs/src
In directory casper:/tmp/cvs-serv22342/src
Modified Files:
Tag: GS_8_1X
gdevmem.c gsdevmem.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.
Corresponds to rev 1.7 gdevmem.c and rev 1.5 gsdevmem.c on main branch.
Index: gdevmem.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/gdevmem.c,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -u -d -r1.6 -r1.6.2.1
--- gdevmem.c 16 Sep 2002 22:04:43 -0000 1.6
+++ gdevmem.c 13 Feb 2004 18:45:00 -0000 1.6.2.1
@@ -529,13 +529,21 @@
{
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;
+ 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]);
+
while ((cnt -= 3) >= 0) {
register int diff = *pptr - br;
@@ -555,7 +563,25 @@
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;
+ }
}
return (gx_color_index) ((which - mdev->palette.data) / 3);
}
Index: gsdevmem.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/gsdevmem.c,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -u -d -r1.4 -r1.4.2.1
--- gsdevmem.c 21 Feb 2002 22:24:52 -0000 1.4
+++ gsdevmem.c 13 Feb 2004 18:45:00 -0000 1.4.2.1
@@ -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;
More information about the gs-cvs
mailing list