[gs-cvs] rev 7459 - in trunk/gs: lib src

giles at ghostscript.com giles at ghostscript.com
Wed Dec 6 15:48:08 PST 2006


Author: giles
Date: 2006-12-06 15:48:07 -0800 (Wed, 06 Dec 2006)
New Revision: 7459

Modified:
   trunk/gs/lib/pdf_base.ps
   trunk/gs/src/int.mak
   trunk/gs/src/sjpx.c
   trunk/gs/src/sjpx.h
   trunk/gs/src/sjpx_luratech.h
   trunk/gs/src/zfjpx.c
Log:
Copy the /ColorSpace key (if any) from a stream dictionary into the
DecodeParms, so the JPXDecode filter implementation can access it.

Pass this key through the JPXDecode filter implementation when
the ColorSpace is Indexed to the underlying jasper implementation,
requesting that it return raw palette indexes instead of the
fully decoded image. This is necessary when the overriding PDF image
colorspace is itself paletted.

Bug 688869 for customer 531.


Modified: trunk/gs/lib/pdf_base.ps
===================================================================
--- trunk/gs/lib/pdf_base.ps	2006-12-06 23:40:57 UTC (rev 7458)
+++ trunk/gs/lib/pdf_base.ps	2006-12-06 23:48:07 UTC (rev 7459)
@@ -1,4 +1,4 @@
-%    Copyright (C) 1994-2003 artofcode LLC.  All rights reserved.
+%    Copyright (C) 1994-2006 artofcode LLC.  All rights reserved.
 % 
 % This software is provided AS-IS with no warranty, either express or
 % implied.
@@ -851,6 +851,23 @@
   } if
 } bind def
 
+% When used with a PDF image dict, the JPXDecode filter needs to know
+% about any ColorSpace entries, since this overrides whatever is in
+% the image stream itself. We therefore propagate any such key into
+% a filter's DecodeParms.
+/jpxparmfix {	% <streamdict> <readdata?> jpxparmfix <streamdict <readdata?>
+  1 index /ColorSpace knownoget {
+    2 index /DecodeParms knownoget {
+      % insert in the existing DecodeParms dict
+      /ColorSpace 3 -1 roll put
+    }{
+      1 dict % need to create a custom DecodeParms dict
+      dup /ColorSpace 4 -1 roll put
+      2 index exch /DecodeParms exch put
+    } ifelse
+  } if
+} bind def
+
 % Resolve a stream dictionary to a PostScript stream.
 % Streams with no filters require special handling:
 %     - Whether we are going to interpret the stream, or If we are just
@@ -859,6 +876,7 @@
 % Note that, in general, resolving a stream repositions PDFfile.
 % Clients must save and restore the position of PDFfile themselves.
 /resolvestream {	% <streamdict> <readdata?> resolvestream <stream>
+  jpxparmfix
   1 index /F knownoget {
 		% This stream is stored on an external file.
     (r) file 3 -1 roll

Modified: trunk/gs/src/int.mak
===================================================================
--- trunk/gs/src/int.mak	2006-12-06 23:40:57 UTC (rev 7458)
+++ trunk/gs/src/int.mak	2006-12-06 23:48:07 UTC (rev 7459)
@@ -1341,7 +1341,8 @@
 
 $(PSOBJ)zfjpx.$(OBJ) : $(PSSRC)zfjpx.c $(OP) $(memory__h)\
  $(gsstruct_h) $(gstypes_h) $(ialloc_h) $(idict_h) $(ifilter_h)\
- $(store_h) $(stream_h) $(strimpl_h) $(sjpx_h)
+ $(store_h) $(stream_h) $(strimpl_h) $(ialloc_h) $(iname_h)\
+ $(gdebug_h) $(sjpx_h)
 	$(PSJASCC) $(PSO_)zfjpx.$(OBJ) $(C_) $(PSSRC)zfjpx.c
 
 $(PSD)jpx_luratech.dev : $(INT_MAK) $(ECHOGS_XE) $(fjpx_luratech) $(GLD)sjpx.dev

Modified: trunk/gs/src/sjpx.c
===================================================================
--- trunk/gs/src/sjpx.c	2006-12-06 23:40:57 UTC (rev 7458)
+++ trunk/gs/src/sjpx.c	2006-12-06 23:48:07 UTC (rev 7459)
@@ -291,10 +291,17 @@
 {
     jas_stream_t *stream = state->stream;
     jas_image_t *image = NULL;
+    char *optstr = NULL;
 
+    /* if the external Colorspace key is indexed, we need to ask
+       for raw index values so the external palette can be applied */
+    if (state->colorspace == gs_jpx_cs_indexed) {
+	if_debug0('w', "[w] got indexed colorspace in s_jpxd_decode_image\n");
+	optstr = (char *)"raw";
+    }
     /* see if an image is available */
     if (stream != NULL) {
-	image = jas_image_decode(stream, -1, 0);
+	image = jas_image_decode(stream, -1, optstr);
 	if (image == NULL) {
 	    dprintf("unable to decode JPX image data.\n");
 	    return ERRC;
@@ -377,16 +384,22 @@
 	    x = x/numcmpts;               /* now samples */
 	    /* copy data out of the decoded image data */
 	    /* be lazy and only write the rest of the current row */
+	    if (state->colorspace == gs_jpx_cs_indexed) {
+		/* we've passed 'raw' but the palette is the same pixel
+		   format as a grayscale image. The PDF interpreter will
+		   know to handle it differently. */
+		done = copy_row_gray(pw->ptr, image, x, y, usable);
+	    } else /* use the stream's colorspace */
 	    switch (jas_clrspc_fam(clrspc)) {
+		case JAS_CLRSPC_FAM_GRAY:
+		    done = copy_row_gray(pw->ptr, image, x, y, usable);
+		    break;
 		case JAS_CLRSPC_FAM_RGB:
 		    done = copy_row_rgb(pw->ptr, image, x, y, usable);
 		    break;
 		case JAS_CLRSPC_FAM_YCBCR:
 		    done = copy_row_yuv(pw->ptr, image, x, y, usable);
 		    break;
-		case JAS_CLRSPC_FAM_GRAY:
-		    done = copy_row_gray(pw->ptr, image, x, y, usable);
-		    break;
 		case JAS_CLRSPC_FAM_XYZ:
 		case JAS_CLRSPC_FAM_LAB:
 		case JAS_CLRSPC_FAM_UNKNOWN:
@@ -435,6 +448,7 @@
     state->buffer = NULL;
     state->bufsize = 0;
     state->buffill = 0;
+    state->colorspace = gs_jpx_cs_unset;
 }
 
 

Modified: trunk/gs/src/sjpx.h
===================================================================
--- trunk/gs/src/sjpx.h	2006-12-06 23:40:57 UTC (rev 7458)
+++ trunk/gs/src/sjpx.h	2006-12-06 23:48:07 UTC (rev 7459)
@@ -23,6 +23,15 @@
 #include "scommon.h"
 #include <jasper/jasper.h>
 
+/* define colorspace enumeration for the input image data */
+typedef enum {
+  gs_jpx_cs_unset,  /* colorspace hasn't been set */
+  gs_jpx_cs_gray,   /* single component grayscale image */ 
+  gs_jpx_cs_rgb,    /* three component (s)RGB image */
+  gs_jpx_cs_cmyk,   /* four component CMYK image */
+  gs_jpx_cs_indexed /* PDF image wants raw index values */
+} gs_jpx_cs;
+
 /* Our local state consists of pointers to the JasPer library's
  * stream and image structs for sending and retrieving the
  * image data. There's no way to feed a jasper stream with
@@ -42,6 +51,7 @@
     unsigned char *buffer; /* temporary buffer for compressed data */
     long bufsize; /* total size of the buffer */
     long buffill; /* number of bytes written into the buffer */
+    gs_jpx_cs colorspace; /* external colorspace setting */
 }
 stream_jpxd_state;
 

Modified: trunk/gs/src/sjpx_luratech.h
===================================================================
--- trunk/gs/src/sjpx_luratech.h	2006-12-06 23:40:57 UTC (rev 7458)
+++ trunk/gs/src/sjpx_luratech.h	2006-12-06 23:48:07 UTC (rev 7459)
@@ -23,6 +23,15 @@
 #include "scommon.h"
 #include <lwf_jp2.h>
 
+/* define colorspace enumeration for the decompressed image data */
+typedef enum {
+  gs_jpx_cs_unset,  /* colorspace hasn't been set */
+  gs_jpx_cs_gray,   /* single component grayscale image */ 
+  gs_jpx_cs_rgb,    /* three component (s)RGB image */
+  gs_jpx_cs_cmyk    /* four component CMYK image */
+  gs_jpx_cs_indexed /* PDF image wants raw index values */
+} gs_jpx_cs;
+
 /* Stream state for the Luratech jp2 codec
  * We rely on our finalization call to free the
  * associated handle and pointers.
@@ -35,6 +44,7 @@
     unsigned char *inbuf;	/* input data buffer */
     unsigned long inbuf_size;
     unsigned long inbuf_fill;
+    gs_jpx_cs colorspace;	/* requested output colorspace */
     int ncomp;			/* number of image components */
     int bpc;			/* sample bits per component */
     unsigned long width, height;
@@ -50,13 +60,6 @@
     "JPXDecode filter state")
 extern const stream_template s_jpxd_template;
 
-/* define colorspace enumeration for the input image data */
-typedef enum {
-  gs_jpx_cs_gray, /* single component grayscale image */
-  gs_jpx_cs_rgb,  /* three component (s)RGB image */
-  gs_jpx_cs_cmyk  /* four component CMYK image */
-} gs_jpx_cs;
-
 /* JPX encoder internal state */
 typedef struct stream_jpxe_state_s {
     stream_state_common;	/* inherit base object from scommon.h */

Modified: trunk/gs/src/zfjpx.c
===================================================================
--- trunk/gs/src/zfjpx.c	2006-12-06 23:40:57 UTC (rev 7458)
+++ trunk/gs/src/zfjpx.c	2006-12-06 23:48:07 UTC (rev 7459)
@@ -13,8 +13,8 @@
 
 /* $Id$ */
 
-/* this is the ps interpreter interface to the jbig2decode filter
-   used for (1bpp) scanned image compression. PDF only specifies
+/* this is the ps interpreter interface to the JPXDecode filter
+   used for (JPEG2000) scanned image compression. PDF only specifies
    a decoder filter, and we don't currently implement anything else */
 
 #include "memory_.h"
@@ -28,6 +28,8 @@
 #include "stream.h"
 #include "strimpl.h"
 #include "ifilter.h"
+#include "iname.h"
+#include "gdebug.h"
 
 #ifdef USE_LWF_JP2
 #include "sjpx_luratech.h"
@@ -42,13 +44,33 @@
 {
     os_ptr op = osp;
     ref *sop = NULL;
+    ref *csname = NULL;
     stream_jpxd_state state;
 
     state.jpx_memory = imemory->non_gc_memory;
     if (r_has_type(op, t_dictionary)) {
         check_dict_read(*op);
-        if ( dict_find_string(op, "Colorspace", &sop) > 0) {
-	    dlprintf("found Colorspace parameter (NYI)\n");
+        if ( dict_find_string(op, "ColorSpace", &sop) > 0) {
+	    /* parse the value */
+	    if (r_is_array(sop)) {
+		/* assume it's the first array element */
+		csname =  sop->value.refs;
+	    } else if (r_has_type(sop,t_name)) {
+		/* use the name directly */
+		csname = sop;
+	    } else {
+		dprintf("warning: JPX ColorSpace value is an unhandled type!\n");
+	    }
+	    if (csname != NULL) {
+		ref sref;
+		/* get a reference to the name's string value */
+		name_string_ref(imemory, csname, &sref);
+		/* request raw index values if the colorspace is /Indexed */
+		if (!memcmp(sref.value.const_bytes, "Indexed", min(7,r_size(&sref))))
+		    state.colorspace = gs_jpx_cs_indexed;
+	    } else {
+		if_debug0('w', "[w] Couldn't read JPX ColorSpace key!\n");
+	    }
         }
     }
     	



More information about the gs-cvs mailing list