[gs-commits] ghostpdl branch, pdfi, updated. jbig2dec-0.14-2344-g5de6aee

[email protected] (Nancy Durgin) Wed, 30 Oct 2019 22:28:10 +0000 (UTC)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
The ghostpdl branch, pdfi has been updated
       via  5de6aee41bbe059374f8d38f96c30ddc39677f4b (commit)
      from  9f40c369f92326477fa893ddf8b9e869dd3e0052 (commit)

----------------------------------------------------------------------
commit 5de6aee41bbe059374f8d38f96c30ddc39677f4b
Author: Nancy Durgin <[email protected]>
Date:   Wed Oct 30 14:54:57 2019 -0700

    Add support for SMaskInData = 2 and some cleanups
    
    SMaskInData = 2 is in fts_17_1718.pdf, but supporting it
    properly actually doesn't affect that sample.  Not sure what that
    means.
    
    Anyway, do same as the gs code, which is to put a "Matte" array
    of size=comps, full of 0's.
    
    Re-arrange code in main pdfi_do_image() routine so that 'comps' will
    be available at the time the pdfi_make_smask() routine is called.
    
    Also cleaned up some initialization and error handling.

diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c
index 4b0fbd0..63c4e34 100644
--- a/pdf/pdf_image.c
+++ b/pdf/pdf_image.c
@@ -1070,22 +1070,19 @@ pdfi_image_get_color(pdf_context *ctx, pdf_stream *source, pdfi_image_info_t *im
 
 /* Make a fake SMask dict from a JPX SMaskInData */
 static int
-pdfi_make_smask_dict(pdf_context *ctx, pdf_dict *image_dict, pdfi_image_info_t *image_info)
+pdfi_make_smask_dict(pdf_context *ctx, pdf_dict *image_dict, pdfi_image_info_t *image_info,
+                     int comps)
 {
-    int code;
+    int code = 0;
     pdf_dict *smask_dict = NULL;
     pdf_array *array = NULL;
+    pdf_array *matte = NULL;
 
     if (image_info->SMask != NULL) {
         dmprintf(ctx->memory, "ERROR SMaskInData when there is already an SMask?\n");
         goto exit;
     }
 
-    if (image_info->SMaskInData != 1) {
-        dmprintf1(ctx->memory, "Unsupported SMaskInData = %ld\n", image_info->SMaskInData);
-        goto exit;
-    }
-
     code = pdfi_alloc_object(ctx, PDF_DICT, 32, (pdf_obj **)&smask_dict);
     if (code < 0) goto exit;
     pdfi_countup(&smask_dict);
@@ -1122,13 +1119,32 @@ pdfi_make_smask_dict(pdf_context *ctx, pdf_dict *image_dict, pdfi_image_info_t *
     code = pdfi_dict_put(ctx, smask_dict, "Decode", (pdf_obj *)array);
     if (code < 0) goto exit;
 
+    /* Make Matte array if needed */
+    /* This just makes an array [0,0,0...] of size 'comps'
+     * See pdf_draw.ps/makeimagekeys
+     * TODO: The only sample in our test suite that triggers this path is fts_17_1718.pdf
+     * and this code being there or not makes no difference on that sample, so.. ???
+     */
+    if (image_info->SMaskInData == 2) {
+        int i;
+        code = pdfi_array_alloc(ctx, comps, &matte);
+        if (code < 0) goto exit;
+        pdfi_countup(matte);
+        for (i=0; i<comps; i++) {
+            code = pdfi_array_put_int(ctx, matte, i, 0);
+            if (code < 0) goto exit;
+        }
+        code = pdfi_dict_put(ctx, smask_dict, "Matte", (pdf_obj *)matte);
+        if (code < 0) goto exit;
+    }
+
     image_info->SMask = (pdf_obj *)smask_dict;
 
  exit:
-    if (code < 0) {
+    if (code < 0)
         pdfi_countdown(smask_dict);
-        pdfi_countdown(array);
-    }
+    pdfi_countdown(array);
+    pdfi_countdown(matte);
     return code;
 }
 
@@ -1212,11 +1228,17 @@ pdfi_do_image(pdf_context *ctx, pdf_dict *page_dict, pdf_dict *stream_dict, pdf_
         code = pdfi_scan_jpxfilter(ctx, source, image_info.Length, &image_info.jpx_info);
         if (code < 0)
             goto cleanupExit;
-        if (ctx->page_has_transparency && image_info.SMaskInData != 0) {
-            code = pdfi_make_smask_dict(ctx, image_dict, &image_info);
-            if (code < 0)
-                goto cleanupExit;
-        }
+    }
+
+    /* Get the color for this image */
+    code = pdfi_image_get_color(ctx, source, &image_info, &comps, &pcs);
+    if (code < 0)
+        goto cleanupExit;
+
+    if (ctx->page_has_transparency && image_info.is_JPXDecode && image_info.SMaskInData != 0) {
+        code = pdfi_make_smask_dict(ctx, image_dict, &image_info, comps);
+        if (code < 0)
+            goto cleanupExit;
     }
 
     if (ctx->page_has_transparency == true && image_info.SMask != NULL) {
@@ -1251,11 +1273,6 @@ pdfi_do_image(pdf_context *ctx, pdf_dict *page_dict, pdf_dict *stream_dict, pdf_
         }
     }
 
-    /* Get the color for this image */
-    code = pdfi_image_get_color(ctx, source, &image_info, &comps, &pcs);
-    if (code < 0)
-        goto cleanupExit;
-
     /* Get the image into a supported gs type (type1, type3, type4) */
     if (!image_info.Mask) { /* Type 1 and ImageMask */
         memset(&t1image, 0, sizeof(t1image));


Summary of changes:
 pdf/pdf_image.c | 57 +++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 37 insertions(+), 20 deletions(-)