[gs-code-review] Accepting images in pattern color space.

Alex Cherepanov alexcher at quadnet.net
Sun Jan 7 07:44:20 PST 2007


Adobe interpreters appear to accept sampled images in the pattern
color space using the base color space instead of the pattern space.
We do the same in the CPSI compatibility mode to meed CET 12-07a-12.

DIFFERENCES:
None

This hack need a careful review because:
- it contradicts the published PostScript specification
- it is not clear (to me) whether the base color space can be
   always used this way.

-------------- next part --------------

S:\gs_svn>svn diff gs/src/zimage.c gs/src/zimage3.c gs/src/ztrans.c gs/src/iimage.h gs/src/int.mak gs/doc/pscet_status.txt 
Index: gs/src/zimage.c
===================================================================
--- gs/src/zimage.c	(revision 7577)
+++ gs/src/zimage.c	(working copy)
@@ -35,6 +35,7 @@
 #include "stream.h"
 #include "ifilter.h"		/* for stream exception handling */
 #include "iimage.h"
+#include "gxcspace.h"
 
 /* Forward references */
 private int zimage_data_setup(i_ctx_t *i_ctx_p, const gs_pixel_image_t * pim,
@@ -116,15 +117,15 @@
 int
 pixel_image_params(i_ctx_t *i_ctx_p, const ref *op, gs_pixel_image_t *pim,
 		   image_params *pip, int max_bits_per_component,
-		   bool has_alpha)
+		   bool has_alpha, const gs_color_space *csp)
 {
     int num_components =
-	gs_color_space_num_components(gs_currentcolorspace(igs));
+	gs_color_space_num_components(csp);
     int code;
 
     if (num_components < 1)
 	return_error(e_rangecheck);	/* Pattern space not allowed */
-    pim->ColorSpace = gs_currentcolorspace(igs);
+    pim->ColorSpace = csp;
     code = data_image_params(imemory, op, (gs_data_image_t *) pim, pip, true,
 			     num_components, max_bits_per_component,
 			     has_alpha);
@@ -161,14 +162,26 @@
     gs_image_t      image;
     image_params    ip;
     int             code;
+    const gs_color_space *csp = gs_currentcolorspace(igs);
+    extern bool CPSI_mode;
 
-    gs_image_t_init(&image, gs_currentcolorspace(igs));
+    /* Adobe interpreters accept sampled images when the current color
+     * space is a pattern color space using the base color space instead
+     * of the pattern space. CET 12-07a-12
+     */
+    if (CPSI_mode && gs_color_space_num_components(csp) < 1) {
+       const gs_color_space *bsp = cs_base_space(csp);
+       if (bsp)
+         csp = bsp;
+    }
+
+    gs_image_t_init(&image, csp);
     code = pixel_image_params( i_ctx_p,
                                op,
                                (gs_pixel_image_t *)&image,
                                &ip,
 			       (level2_enabled ? 16 : 8),
-                               has_alpha );
+                               has_alpha, csp);
     if (code < 0)
 	return code;
 
Index: gs/src/zimage3.c
===================================================================
--- gs/src/zimage3.c	(revision 7577)
+++ gs/src/zimage3.c	(working copy)
@@ -52,8 +52,8 @@
 	)
 	return_error(e_rangecheck);
     if ((code = pixel_image_params(i_ctx_p, pDataDict,
-				   (gs_pixel_image_t *)&image, &ip_data,
-				   12, false)) < 0 ||
+			(gs_pixel_image_t *)&image, &ip_data,
+			12, false, gs_currentcolorspace(igs))) < 0 ||
 	(mcode = code = data_image_params(imemory, pMaskDict, &image.MaskDict,
 				   &ip_mask, false, 1, 12, false)) < 0 ||
 	(code = dict_int_param(pDataDict, "ImageType", 1, 1, 0, &ignored)) < 0 ||
@@ -95,7 +95,7 @@
 
     gs_image4_t_init(&image, NULL);
     code = pixel_image_params(i_ctx_p, op, (gs_pixel_image_t *)&image, &ip,
-			      12, false);
+			      12, false, gs_currentcolorspace(igs));
     if (code < 0)
 	return code;
     code = dict_int_array_check_param(imemory, op, "MaskColor",
Index: gs/src/ztrans.c
===================================================================
--- gs/src/ztrans.c	(revision 7577)
+++ gs/src/ztrans.c	(working copy)
@@ -365,8 +365,8 @@
     if (dict_find_string(op, "DataDict", &pDataDict) <= 0)
 	return_error(e_rangecheck);
     if ((code = pixel_image_params(i_ctx_p, pDataDict,
-				   (gs_pixel_image_t *)&image, &ip_data,
-				   16, false)) < 0 ||
+		   (gs_pixel_image_t *)&image, &ip_data,
+		   16, false, gs_currentcolorspace(igs))) < 0 ||
 	(code = dict_int_param(pDataDict, "ImageType", 1, 1, 0, &ignored)) < 0
 	)
 	return code;
Index: gs/src/iimage.h
===================================================================
--- gs/src/iimage.h	(revision 7577)
+++ gs/src/iimage.h	(working copy)
@@ -38,7 +38,8 @@
                       bool has_alpha);
 int pixel_image_params(i_ctx_t *i_ctx_p, const ref *op,
                        gs_pixel_image_t *pim, image_params * pip,
-                       int max_bits_per_component, bool has_alpha);
+                       int max_bits_per_component, bool has_alpha,
+                       const gs_color_space *csp);
 
 /* Exported for zimage3.c and ztrans.c */
 int zimage_setup(i_ctx_t *i_ctx_p, const gs_pixel_image_t * pim,
Index: gs/src/int.mak
===================================================================
--- gs/src/int.mak	(revision 7577)
+++ gs/src/int.mak	(working copy)
@@ -481,7 +481,7 @@
  $(gscspace_h) $(gscssub_h) $(gsimage_h) $(gsmatrix_h) $(gsstruct_h)\
  $(gxiparam_h)\
  $(estack_h) $(ialloc_h) $(ifilter_h) $(igstate_h) $(iimage_h) $(ilevel_h)\
- $(store_h) $(stream_h)
+ $(store_h) $(stream_h) $(gxcspace_h)
 	$(PSCC) $(PSO_)zimage.$(OBJ) $(C_) $(PSSRC)zimage.c
 
 $(PSOBJ)zmatrix.$(OBJ) : $(PSSRC)zmatrix.c $(OP)\
Index: gs/doc/pscet_status.txt
===================================================================
--- gs/doc/pscet_status.txt	(revision 7577)
+++ gs/doc/pscet_status.txt	(working copy)
@@ -2168,8 +2168,8 @@
 
 12-07A-11  OK	Minor differences visually reviewed by RJJ
 
-12-07A-12  DIFF	GS reports one more rangecheck in image than CPSI.  Square
-		pattern missing in GS output.  assign Alex (initially).
+12-07A-12  OK  	Adobe acceptts images in the pattern color space.
+		Since rev. 7578 we do this too in the compatibility mode. - Alex
 
 12-07A-13  OK	Minor differences in positions and character shapes - ADC
 


More information about the gs-code-review mailing list