[gs-commits] ghostpdl branch, pdfi, updated. jbig2dec-0.14-2462-g75a1b10

[email protected] (Nancy Durgin) Wed, 13 Nov 2019 17:46:08 +0000 (UTC)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
The ghostpdl branch, pdfi has been updated
       via  75a1b103f1feed842c434c766c6748f304374661 (commit)
      from  0c6e72399d68165970fd7ad6baa946df127c8ea5 (commit)

----------------------------------------------------------------------
commit 75a1b103f1feed842c434c766c6748f304374661
Author: Nancy Durgin <[email protected]>
Date:   Wed Nov 13 08:21:05 2019 -0800

    Interim fix to calculate reasonable GrayBackground for BC
    
    This calculates "currentgray" for the GrayBackground param for smasks.
    Not sure this is correct (mvrhel is looking into it) but it gives a better
    result than doing nothing...
    
    This assumes the color is either RGB or CMYK and then uses the calculation
    from the PLRM2 for currentgray.

diff --git a/pdf/pdf_trans.c b/pdf/pdf_trans.c
index c98322b..39e6e18 100644
--- a/pdf/pdf_trans.c
+++ b/pdf/pdf_trans.c
@@ -39,6 +39,37 @@ pdfi_tf_using_function(double in_val, float *out, void *proc_data)
     return gs_function_evaluate(pfn, &in, out);
 }
 
+static void
+pdfi_set_GrayBackground(gs_transparency_mask_params_t *params)
+{
+    float num;
+
+    /* This uses definition from PLRM2 6.2.1 and 6.2.2 */
+    /* TODO: We are assuming 3 components is RGB and 4 components is CMYK,
+       which might not strictly be true?  But it provides a better
+       estimated value than doing nothing.
+    */
+    switch(params->Background_components) {
+    case 3:
+        /* RGB: currentgray = 0.3*R + 0.59*G + 0.11*B */
+        params->GrayBackground = (0.3 * params->Background[0] +
+                                  0.59 * params->Background[1] +
+                                  0.11 * params->Background[2]);
+        break;
+    case 4:
+        /* CMYK: currentgray = 1.0 – min (1.0, .3*C + .59*M + .11*Y + K)
+        */
+        num = 0.3*params->Background[1] + 0.59*params->Background[1] +
+            0.11*params->Background[2] + params->Background[3];
+        if (num > 1)
+            num = 1;
+        params->GrayBackground = 1 - num;
+    default:
+        /* No clue... */
+        params->GrayBackground = 0;
+    }
+}
+
 /* (see pdf_draw.ps/execmaskgroup) */
 static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs, int colorindex)
 {
@@ -226,8 +257,9 @@ static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs, int color
             /* This should be "currentgray" for the color that we put in params.ColorSpace,
              * It looks super-convoluted to actually get this value.  Really?
              * (see zcurrentgray())
+             * For now, use simple definition from PLRM2 and assume it is RGB or CMYK
              */
-            params.GrayBackground = 0; /* TODO */
+            pdfi_set_GrayBackground(&params);
         }
 
         code = gs_begin_transparency_mask(ctx->pgs, &params, &bbox, true);


Summary of changes:
 pdf/pdf_trans.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)