[gs-commits] rev 11845 - in trunk/gs: Resource/Init base

alexcher at ghostscript.com alexcher at ghostscript.com
Sun Oct 24 22:23:55 UTC 2010


Author: alexcher
Date: 2010-10-24 22:23:55 +0000 (Sun, 24 Oct 2010)
New Revision: 11845

Modified:
   trunk/gs/Resource/Init/pdf_draw.ps
   trunk/gs/base/sjpx.c
Log:
Implement /SMaskInData using images with /SMask and separate streams for the
mask and image data. Our /ImageType 103 seems to have issues and cannot be
used directly. /JPXDecode filter now takes /Alpha parameter, which controls
whether opacity or image data stream is extracted.

This commit introduces a PS error on pdfwrite device in fts_18_1805.pdf 
and a few other files with the same image. However, this image has never
been combined with SMask before and the actual bug may predate the commit.
Bug 691489, customer 532.


Modified: trunk/gs/Resource/Init/pdf_draw.ps
===================================================================
--- trunk/gs/Resource/Init/pdf_draw.ps	2010-10-23 22:38:17 UTC (rev 11844)
+++ trunk/gs/Resource/Init/pdf_draw.ps	2010-10-24 22:23:55 UTC (rev 11845)
@@ -1164,6 +1164,7 @@
 currentdict /jp2_csp_dict .undef
 
 % Add a key-value pair to the last /DecodeParms dictionary
+% Copy the objects to avoid spoiling shared ones.
 % <resdict> <key> <value> -> <resdict>
 /add-to-last-param {
   2 index /DecodeParms knownoget {
@@ -1181,7 +1182,7 @@
       ] 
       dup dup length 1 sub get           % <resdict> <key> <value> []   <<>>
     } {
-      dup                                % <resdict> <key> <value> <<>> <<>>
+      dup length 1 add dict copy dup     % <resdict> <key> <value> <<>> <<>>
     } ifelse
     4 2 roll put                         % <resdict> obj
   } {
@@ -1327,32 +1328,51 @@
         } ifelse
       } if % fi missing csp, bpc
 
+      //last-ditch-bpc-csp exec
+
+      dup /ColorSpace oknown {
+        % Propagate known color space to the filter
+        /ColorSpace currentdict /ColorSpace get //add-to-last-param exec
+      } if
+
+      /Decode 2 copy knownoget not {
+        ColorSpace //defaultdecodedict
+        ColorSpace dup type /arraytype eq { 0 get } if get exec
+      } if def
+
       dup get-smask-in-data dup 0 ne {
         PDFusingtransparency {
-          /SMaskInData exch def                  % Propagate the flag to imagedict
-          /Alpha //true //add-to-last-param exec % and to the filter.
+          currentdict dup length dict copy begin
+          {/Mask/SMask/SMaskInData/Name} { currentdict exch undef } forall
+          2 eq {
+            /Matte [ Decode length 2 idiv { 0 } repeat ] def
+          } if
+          /Decode //01_1 def
+          /ColorSpace /DeviceGray def
+          {/File /FilePosition /Filter /Length /DecodeParms /FFilter /FDecodeParms } {
+            2 copy knownoget {
+              def
         } {
           pop
         } ifelse
+          } forall
+          currentdict /Alpha //true //add-to-last-param exec pop
+          /SMask currentdict end def
       } {
         pop
       } ifelse
-
-      //last-ditch-bpc-csp exec
-
-      dup /ColorSpace oknown {
-        % Propagate known color space to the filter
-        /ColorSpace currentdict /ColorSpace get //add-to-last-param exec
-      } if
+      } {
+        pop
+      } ifelse
     } { % not JPX image
       //last-ditch-bpc-csp exec
-    } ifelse % fi JPX tricks
-
-		% Decode is required for the PostScript image operators.
     /Decode 2 copy knownoget not {
       ColorSpace //defaultdecodedict
       ColorSpace dup type /arraytype eq { 0 get } if get exec
     } if def
+
+    } ifelse % fi JPX tricks
+
 		% Even though we're going to read data,
 		% pass false to resolvestream so that
 		% it doesn't try to use Length (which may not be present).

Modified: trunk/gs/base/sjpx.c
===================================================================
--- trunk/gs/base/sjpx.c	2010-10-23 22:38:17 UTC (rev 11844)
+++ trunk/gs/base/sjpx.c	2010-10-24 22:23:55 UTC (rev 11845)
@@ -165,14 +165,14 @@
 #endif /* DEBUG */
 
 static int
-copy_row_gray(byte *dest, jas_image_t *image,
-        int x, int y, int bytes)
+copy_row_1comp(byte *dest, jas_image_t *image,
+        int x, int y, int bytes, int channel)
 {
     int i, p;
     int v;
     int shift, bits;
 
-    v = jas_image_getcmptbytype(image, JAS_IMAGE_CT_GRAY_Y);
+    v = jas_image_getcmptbytype(image, channel);
     if (v < 0) return 0; /* no matching component */
 
     bits = jas_image_cmptprec(image, v);
@@ -361,8 +361,8 @@
 }
 
 static int
-copy_row_gray16(byte *dest, jas_image_t *image,
-        int x, int y, int bytes, int bits)
+copy_row_1comp16(byte *dest, jas_image_t *image,
+        int x, int y, int bytes, int bits, int channel)
 {
     int count;
     int pixel_width;
@@ -371,7 +371,7 @@
     int p, v;
     unsigned short value;
 
-    v = jas_image_getcmptbytype(image, JAS_IMAGE_CT_GRAY_Y);
+    v = jas_image_getcmptbytype(image, channel);
     if (v < 0) return 0; /* no matching component */
 
     count = bytes;
@@ -503,7 +503,7 @@
       }
       if (state->image != NULL) {
         jas_image_t *image = state->image;
-        int numcmpts = color_cmpts(image);
+        int numcmpts = (state->alpha ? 1 : color_cmpts(image));
         int bits = jas_image_cmptprec(image, 0);
         int stride, image_size;
         int clrspc = jas_image_clrspc(image);
@@ -531,7 +531,16 @@
            This can fail if we get the colorspace wrong. */
         if (usable < numcmpts) return ERRC;
 
-        if (state->colorspace != gs_jpx_cs_unset)
+        if (state->alpha) {
+            if (bits > 8)
+                done = copy_row_1comp16(pw->ptr, image, x, y, usable, bits, JAS_IMAGE_CT_OPACITY);
+            else
+                done = copy_row_1comp(pw->ptr, image, x, y, usable, JAS_IMAGE_CT_OPACITY);
+            if (usable && done == 0) {
+               memset(pw->ptr + 1, 0xff, usable);
+               done = usable;
+            }
+        } else if (state->colorspace != gs_jpx_cs_unset)
           /* An external colorspace from the interpreter overrides */
           switch (state->colorspace) {
             case gs_jpx_cs_gray:
@@ -539,7 +548,7 @@
             /* 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);
+              done = copy_row_1comp(pw->ptr, image, x, y, usable, JAS_IMAGE_CT_GRAY_Y);
               break;
             case gs_jpx_cs_rgb:
               done = copy_row_rgb(pw->ptr, image, x, y, usable);
@@ -553,9 +562,9 @@
           switch (jas_clrspc_fam(clrspc)) {
                 case JAS_CLRSPC_FAM_GRAY:
                     if (bits > 8) {
-                        done = copy_row_gray16(pw->ptr, image, x, y, usable, bits);
+                        done = copy_row_1comp16(pw->ptr, image, x, y, usable, bits, JAS_IMAGE_CT_GRAY_Y);
                     } else {
-                        done = copy_row_gray(pw->ptr, image, x, y, usable);
+                        done = copy_row_1comp(pw->ptr, image, x, y, usable, JAS_IMAGE_CT_GRAY_Y);
                     }
                     break;
                 case JAS_CLRSPC_FAM_RGB:



More information about the gs-commits mailing list