Patch for 687770

Raph Levien <[email protected]> Thu, 18 Nov 2004 17:42:03 -0800
Newsgroups gmane.comp.printing.ghostscript.patches
Message-ID <[email protected]>
The problem was a null device (for implementing stringwidth) with
inconsistent color info; the color_info struct specified 4 components,
but the get_color_mapping_procs was
gx_default_DevGray_get_color_mapping_procs, which is the desired value
for null devices instantiated through gs_copydevice
(i.e. -sDEVICE=null). As a result, cm_comps[1] through [3] were left
uninitialized, and, when negative, would crash the halftone logic.

This patch copies over the new-style color mapping procs (the
old-style were already copied) in the gs_make_null_device routine. A
strong argument could be made for changing the logic in
gx_device_copy_color_procs() instead, but it was felt that this change
was more localized.

Dan reviewed this patch during a phone conversation, so I am going ahead
and committing. I'm also opening a new bug to encourage a closer look
at other uses of gx_device_copy_color_procs() to see whether a change
there is beneficial or harmful.

Raph

Index: src/gsdevice.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/gsdevice.c,v
retrieving revision 1.23
diff -C2 -r1.23 gsdevice.c
*** src/gsdevice.c	19 Aug 2004 19:33:09 -0000	1.23
--- src/gsdevice.c	19 Nov 2004 01:33:55 -0000
***************
*** 442,447 ****
  		   mem, true);
      gx_device_set_target((gx_device_forward *)dev_null, dev);
!     if (dev)
! 	gx_device_copy_color_params((gx_device *)dev_null, dev);
  }
  
--- 442,459 ----
  		   mem, true);
      gx_device_set_target((gx_device_forward *)dev_null, dev);
!     if (dev) {
! 	/* The gx_device_copy_color_params() call below should
! 	   probably copy over these new-style color mapping procs, as
! 	   well as the old-style (map_rgb_color and friends). However,
! 	   the change was made here instead, to minimize the potential
! 	   impact of the patch.
! 	*/
! 	gx_device *dn = (gx_device *)dev_null;
! 	set_dev_proc(dn, get_color_mapping_procs, gx_forward_get_color_mapping_procs);
! 	set_dev_proc(dn, get_color_comp_index, gx_forward_get_color_comp_index);
! 	set_dev_proc(dn, encode_color, gx_forward_encode_color);
! 	set_dev_proc(dn, decode_color, gx_forward_decode_color);
! 	gx_device_copy_color_params(dn, dev);
!     }
  }
  
***************
*** 617,620 ****
--- 629,637 ----
  	dev_proc(dev, map_color_rgb);
  
+     /* The logic in this function seems a bit stale; it sets the
+        old-style color procs, but not the new ones
+        (get_color_mapping_procs, get_color_comp_index, encode_color,
+        and decode_color). It should probably copy those as well.
+     */
      if (from_cmyk == gx_forward_map_cmyk_color ||
  	from_cmyk == cmyk_1bit_map_cmyk_color ||