diff options
Diffstat (limited to 'pdf/pdf_trans.c')
-rw-r--r-- | pdf/pdf_trans.c | 89 |
1 files changed, 52 insertions, 37 deletions
diff --git a/pdf/pdf_trans.c b/pdf/pdf_trans.c index df0194d7..fecb74c9 100644 --- a/pdf/pdf_trans.c +++ b/pdf/pdf_trans.c @@ -103,7 +103,7 @@ static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs, int color double f; gs_matrix save_matrix, GroupMat, group_Matrix; gs_transparency_mask_subtype_t subtype = TRANSPARENCY_MASK_Luminosity; - pdf_bool *Processed = NULL; + bool Processed, ProcessedKnown = 0; bool save_OverrideICC = gs_currentoverrideicc(ctx->pgs); #if DEBUG_TRANSPARENCY @@ -114,28 +114,26 @@ static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs, int color /* Following the logic of the ps code, cram a /Processed key in the SMask dict to * track whether it's already been processed. */ - code = pdfi_dict_knownget_type(ctx, SMask, "Processed", PDF_BOOL, (pdf_obj **)&Processed); - if (code > 0 && Processed->value) { + code = pdfi_dict_knownget_bool(ctx, SMask, "Processed", &Processed); + if (code > 0) { + if (Processed) { #if DEBUG_TRANSPARENCY - dbgmprintf(ctx->memory, "SMask already built, skipping\n"); + dbgmprintf(ctx->memory, "SMask already built, skipping\n"); #endif - goto exit; + code = 0; + goto exit; + } + ProcessedKnown = 1; } gs_setoverrideicc(ctx->pgs, true); /* If /Processed not in the dict, put it there */ if (code == 0) { - /* the cleanup at end of this routine assumes Processed has a ref */ - code = pdfi_object_alloc(ctx, PDF_BOOL, 0, (pdf_obj **)&Processed); - if (code < 0) - goto exit; - Processed->value = false; - /* pdfi_object_alloc() doesn't grab a ref */ - pdfi_countup(Processed); - code = pdfi_dict_put(ctx, SMask, "Processed", (pdf_obj *)Processed); + code = pdfi_dict_put_bool(ctx, SMask, "Processed", false); if (code < 0) goto exit; + ProcessedKnown = 1; } /* See pdf1.7 pg 553 (pain in the butt to find this!) */ @@ -172,21 +170,25 @@ static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs, int color /* TR is transfer function (Optional) */ code = pdfi_dict_knownget(ctx, SMask, "TR", (pdf_obj **)&TR); if (code > 0) { - if (TR->type == PDF_DICT || TR->type == PDF_STREAM) { - code = pdfi_build_function(ctx, &gsfunc, NULL, 1, TR, NULL); - if (code < 0) - goto exit; - if (gsfunc->params.m != 1 || gsfunc->params.n != 1) { - pdfi_free_function(ctx, gsfunc); - gsfunc = NULL; - dmprintf(ctx->memory, "WARNING: Ignoring invalid TR (number of inpuits or outputs not 1) in SMask\n"); - } - } else if (TR->type == PDF_NAME) { - if (!pdfi_name_is((pdf_name *)TR, "Identity")) { - dmprintf(ctx->memory, "WARNING: Unknown TR in SMask\n"); - } - } else { - dmprintf(ctx->memory, "WARNING: Ignoring invalid TR in SMask\n"); + switch (pdfi_type_of(TR)) { + case PDF_DICT: + case PDF_STREAM: + code = pdfi_build_function(ctx, &gsfunc, NULL, 1, TR, NULL); + if (code < 0) + goto exit; + if (gsfunc->params.m != 1 || gsfunc->params.n != 1) { + pdfi_free_function(ctx, gsfunc); + gsfunc = NULL; + dmprintf(ctx->memory, "WARNING: Ignoring invalid TR (number of inpuits or outputs not 1) in SMask\n"); + } + break; + case PDF_NAME: + if (!pdfi_name_is((pdf_name *)TR, "Identity")) { + dmprintf(ctx->memory, "WARNING: Unknown TR in SMask\n"); + } + break; + default: + dmprintf(ctx->memory, "WARNING: Ignoring invalid TR in SMask\n"); } } @@ -251,8 +253,14 @@ static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs, int color if (code > 0) { /* TODO: Stuff with colorspace, see .execmaskgroup */ code = pdfi_dict_knownget(ctx, Group, "CS", &CS); - if (code < 0) - goto exit; + if (code < 0) { + code = pdfi_dict_knownget(ctx, Group, "ColorSpace", &CS); + if (code < 0) { + pdfi_set_error(ctx, 0, NULL, E_PDF_GROUP_NO_CS, "pdfi_trans_set_mask", (char *)"*** Defaulting to currrent colour space"); + goto exit; + } + pdfi_set_warning(ctx, 0, NULL, W_PDF_GROUP_HAS_COLORSPACE, "pdfi_trans_set_mask", NULL); + } if (code > 0) { code = pdfi_create_colorspace(ctx, CS, (pdf_dict *)ctx->main_stream, ctx->page.CurrentPageDict, &pcs, false); @@ -284,6 +292,9 @@ static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs, int color } params.Background_components = pdfi_array_size(BC); + if (gs_color_space_num_components(params.ColorSpace) != params.Background_components) + pdfi_set_warning(ctx, 0, NULL, W_PDF_GROUP_BAD_BC, "pdfi_trans_set_mask", NULL); + /* TODO: Not sure how to handle this... recheck PS code (pdf_draw.ps/gssmask) */ /* This should be "currentgray" for the color that we put in params.ColorSpace, * It looks super-convoluted to actually get this value. Really? @@ -300,7 +311,7 @@ static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs, int color code = pdfi_form_execgroup(ctx, ctx->page.CurrentPageDict, G_stream, igs->GroupGState, NULL, &group_Matrix); code1 = gs_end_transparency_mask(ctx->pgs, colorindex); - if (code != 0) + if (code == 0) code = code1; /* Put back the matrix (we couldn't just rely on gsave/grestore for whatever reason, @@ -309,8 +320,12 @@ static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs, int color gs_setmatrix(ctx->pgs, &save_matrix); /* Set Processed flag */ - if (code == 0 && Processed) - Processed->value = true; + if (code == 0 && ProcessedKnown) + { + code = pdfi_dict_put_bool(ctx, SMask, "Processed", true); + if (code < 0) + goto exit; + } } else { /* take action on a non-/Mask entry. What does this mean ? What do we need to do */ dmprintf(ctx->memory, "Warning: Type is not /Mask, entry ignored in pdfi_set_trans_mask\n"); @@ -332,7 +347,6 @@ static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs, int color pdfi_countdown(BBox); pdfi_countdown(Matrix); pdfi_countdown(CS); - pdfi_countdown(Processed); #if DEBUG_TRANSPARENCY dbgmprintf(ctx->memory, "pdfi_trans_set_mask (.execmaskgroup) END\n"); #endif @@ -393,7 +407,7 @@ static int pdfi_transparency_group_common(pdf_context *ctx, pdf_dict *page_dict, /* Didn't find a /CS key, try again using /ColorSpace */ code = pdfi_dict_knownget(ctx, group_dict, "ColorSpace", &CS); } - if (code > 0 && CS->type != PDF_NULL) { + if (code > 0 && pdfi_type_of(CS) != PDF_NULL) { code = pdfi_setcolorspace(ctx, CS, group_dict, page_dict); if (code < 0) goto exit; @@ -865,6 +879,7 @@ int pdfi_trans_teardown(pdf_context *ctx, pdfi_trans_state_t *state) int pdfi_trans_set_params(pdf_context *ctx) { + int code = 0; pdfi_int_gstate *igs = (pdfi_int_gstate *)ctx->pgs->client_data; gs_transparency_channel_selector_t csel; @@ -874,9 +889,9 @@ int pdfi_trans_set_params(pdf_context *ctx) else csel = TRANSPARENCY_CHANNEL_Opacity; if (igs->SMask) { - pdfi_trans_set_mask(ctx, igs, csel); + code = pdfi_trans_set_mask(ctx, igs, csel); } } - return 0; + return code; } |