Ejemplo n.º 1
0
int
gs_pop_transparency_state(gs_state *pgs, bool force)
{
    gs_pdf14trans_params_t params = { 0 };
    gs_imager_state * pis = (gs_imager_state *)pgs;
    int code;

    if (check_for_nontrans_pattern(pgs,
                  (unsigned char *)"gs_pop_transparency_state")) {
        return(0);
    }
    /* Check if flag is set, which indicates that we have
       an active softmask for the graphic state.  We
       need to communicate to the compositor to pop
       the softmask */
    if ( pis->trans_flags.xstate_change || force) {
        if_debug0m('v', pgs->memory, "[v]gs_pop_transparency_state sending\n");
        params.pdf14_op = PDF14_POP_TRANS_STATE;
        code = gs_state_update_pdf14trans(pgs, &params);
        if ( code < 0 )
            return (code);
    } else {
        if_debug0m('v', pgs->memory, "[v]gs_pop_transparency_state NOT sending\n");
    }
    /* There is no reason to reset any of the flags since
       they will be reset by the graphic state restore */
    return(0);
}
Ejemplo n.º 2
0
int
gs_end_transparency_group(gs_state *pgs)
{
    gs_pdf14trans_params_t params = { 0 };

    if (pgs->is_gstate && check_for_nontrans_pattern(pgs,
                  (unsigned char *)"gs_end_transparency_group")) {
        return(0);
    }
    if_debug0m('v', pgs->memory, "[v]gs_end_transparency_group\n");
    params.pdf14_op = PDF14_END_TRANS_GROUP;  /* Other parameters not used */
    return gs_state_update_pdf14trans(pgs, &params);
}
Ejemplo n.º 3
0
int
gs_push_transparency_state(gs_state *pgs)
{
    gs_pdf14trans_params_t params = { 0 };
    gs_imager_state * pis = (gs_imager_state *)pgs;
    int code;

    if (check_for_nontrans_pattern(pgs,
                  (unsigned char *)"gs_push_transparency_state")) {
        return(0);
    }
    /* Set the pending flag to true, which indicates
       that we need to watch for end transparency
       soft masks when we are at this graphic state
       level */
    /* pis->trans_flags.xstate_pending = true; */
    /* Actually I believe the above flag is not
       needed.  We really should be watching for
       the softmask even at the base level.  What
       we need to watch for are q operations after
       a soft mask end has occured. */
    /* Check if we have a change flag set to true.
       this indicates that a softmask is present.
       We will need to send a push state to save
       the current soft mask, so that we can
       restore it later */
    if (pis->trans_flags.xstate_change) {
        if_debug0m('v', pgs->memory, "[v]gs_push_transparency_state sending\n");
        params.pdf14_op = PDF14_PUSH_TRANS_STATE;
        code = gs_state_update_pdf14trans(pgs, &params);
        if (code < 0)
            return(code);
    } else {
        if_debug0m('v', pgs->memory, "[v]gs_push_transparency_state NOT sending\n");
    }
    return(0);
}
Ejemplo n.º 4
0
int
gs_end_transparency_mask(gs_state *pgs,
                         gs_transparency_channel_selector_t csel)
{
    gs_pdf14trans_params_t params = { 0 };
    gs_pdf14trans_params_t params_color = { 0 };
    gs_imager_state * pis = (gs_imager_state *)pgs;
    int code;

    if (check_for_nontrans_pattern(pgs,
                  (unsigned char *)"gs_end_transparency_mask")) {
        return(0);
    }
    /* If we have done a q then set a flag to watch for any Qs */
   /* if (pis->trans_flags.xstate_pending)
        pis->trans_flags.xstate_change = true; */
    /* This should not depend upon if we have encountered a q
       operation.  We could be setting a softmask, before
       there is any q operation.  Unlikely but it could happen.
       Then if we encouter a q operation (and this flag
       is true) we will need to
       push the mask graphic state (PDF14_PUSH_TRANS_STATE). */
    pis->trans_flags.xstate_change = true;
    if_debug1('v', "[v]xstate_changed set true, gstate level is %d\n", pgs->level);
    if_debug2('v', "[v](0x%lx)gs_end_transparency_mask(%d)\n", (ulong)pgs,
              (int)csel);
    params.pdf14_op = PDF14_END_TRANS_MASK;  /* Other parameters not used */
    params.csel = csel;
    /* If this is the outer end then return us to our normal defaults */
    if_debug0('v', "[v]popping soft mask color sending\n");
    params_color.pdf14_op = PDF14_POP_SMASK_COLOR;
    code = gs_state_update_pdf14trans(pgs, &params_color);
    if (code < 0)
        return(code);
    return gs_state_update_pdf14trans(pgs, &params);
}
Ejemplo n.º 5
0
int
gs_begin_transparency_mask(gs_state * pgs,
                           const gs_transparency_mask_params_t * ptmp,
                           const gs_rect * pbbox, bool mask_is_image)
{
    gs_pdf14trans_params_t params = { 0 };
    gs_pdf14trans_params_t params_color = { 0 };
    const int l = sizeof(params.Background[0]) * ptmp->Background_components;
    int i, code;
    gs_color_space *blend_color_space;
    gsicc_manager_t *icc_manager = pgs->icc_manager;

    if (check_for_nontrans_pattern(pgs,
                  (unsigned char *)"gs_pop_transparency_state")) {
        return(0);
    }
    params.pdf14_op = PDF14_BEGIN_TRANS_MASK;
    params.bbox = *pbbox;
    params.subtype = ptmp->subtype;
    params.Background_components = ptmp->Background_components;
    memcpy(params.Background, ptmp->Background, l);
    params.GrayBackground = ptmp->GrayBackground;
    params.transfer_function = ptmp->TransferFunction_data;
    params.function_is_identity =
            (ptmp->TransferFunction == mask_transfer_identity);
    params.mask_is_image = mask_is_image;
    params.replacing = ptmp->replacing;

    /* The eventual state that we want this smask to be moved to
       is always gray.  This should provide us with a significant
       speed improvement over the old code.  This does not keep us
       from having groups within the softmask getting blended in different
       color spaces, it just makes the final space be gray, which is what
       we will need to get to eventually anyway. In this way we avoid a
       final color conversion on a potentially large buffer. */
    /* Also check if we have loaded in the transparency icc profiles.  If not
       go ahead and take care of that now */
    if (icc_manager->smask_profiles == NULL) {
        code = gsicc_initialize_iccsmask(icc_manager);
        if (code < 0)
            return(code);
    }
    /* A new soft mask group,  make sure the profiles are set */
    if_debug0m('v', pgs->memory, "[v]pushing soft mask color sending\n");
    if (params.subtype != TRANSPARENCY_MASK_None) {
        params_color.pdf14_op = PDF14_PUSH_SMASK_COLOR;
        code = gs_state_update_pdf14trans(pgs, &params_color);
        if (code < 0)
            return(code);
        blend_color_space = gs_cspace_new_DeviceGray(pgs->memory);
        blend_color_space->cmm_icc_profile_data = pgs->icc_manager->default_gray;
        rc_increment(blend_color_space->cmm_icc_profile_data);
        if_debug8m('v', pgs->memory, "[v](0x%lx)gs_begin_transparency_mask [%g %g %g %g]\n\
          subtype = %d  Background_components = %d %s\n",
                  (ulong)pgs, pbbox->p.x, pbbox->p.y, pbbox->q.x, pbbox->q.y,
                  (int)ptmp->subtype, ptmp->Background_components,
                  (ptmp->TransferFunction == mask_transfer_identity ? "no TR" :
                   "has TR"));
        /* Sample the transfer function */
        for (i = 0; i < MASK_TRANSFER_FUNCTION_SIZE; i++) {
            float in = (float)(i * (1.0 / (MASK_TRANSFER_FUNCTION_SIZE - 1)));
            float out;

            ptmp->TransferFunction(in, &out, ptmp->TransferFunction_data);
            params.transfer_fn[i] = (byte)floor((double)(out * 255 + 0.5));
        }
        /* Note:  This function is called during the c-list writer side. */
        if ( blend_color_space->cmm_icc_profile_data != NULL ) {
        /* Blending space is ICC based.  If we are doing c-list rendering we will
           need to write this color space into the clist. */
            params.group_color = ICC;
            params.group_color_numcomps =
                    blend_color_space->cmm_icc_profile_data->num_comps;
            /* Get the ICC profile */
            /* We don't reference count this - see comment in
             * pdf14_update_device_color_procs_pop_c()
             */
            params.iccprofile = blend_color_space->cmm_icc_profile_data;
            params.icc_hash = blend_color_space->cmm_icc_profile_data->hashcode;
        } else {
            params.group_color = GRAY_SCALE;
            params.group_color_numcomps = 1;  /* Need to check */
        }
        /* Explicitly decrement the profile data since blend_color_space may not
         * be an ICC color space object.
         */
        rc_decrement(blend_color_space->cmm_icc_profile_data, "gs_begin_transparency_mask");
        rc_decrement_only_cs(blend_color_space, "gs_begin_transparency_mask");
    }
Ejemplo n.º 6
0
int
gs_begin_transparency_group(gs_state *pgs,
                            const gs_transparency_group_params_t *ptgp,
                            const gs_rect *pbbox)
{
    gs_pdf14trans_params_t params = { 0 };
    const gs_color_space *blend_color_space;
    gs_imager_state * pis = (gs_imager_state *)pgs;
    cmm_profile_t *profile;

    if (check_for_nontrans_pattern(pgs,
                  (unsigned char *)"gs_begin_transparency_group")) {
        return(0);
    }
    /*
     * Put parameters into a compositor parameter and then call the
     * create_compositor.  This will pass the data to the PDF 1.4
     * transparency device.
     */
    params.pdf14_op = PDF14_BEGIN_TRANS_GROUP;
    params.Isolated = ptgp->Isolated;
    params.Knockout = ptgp->Knockout;
    params.image_with_SMask = ptgp->image_with_SMask;
    params.opacity = pgs->opacity;
    params.shape = pgs->shape;
    params.blend_mode = pgs->blend_mode;
    /* This function is called during the c-list writer side.
       Store some information so that we know what the color space is
       so that we can adjust according later during the clist reader.
       We currently will use the concrete space for any space other than a
       device space.  However, if the device is a sep device it will blend
       in DeviceN color space as required.  */
    blend_color_space = gs_currentcolorspace_inline(pgs);
    if (gs_color_space_get_index(blend_color_space) > gs_color_space_index_DeviceCMYK) {
        /* ICC and PS CIE based case.  Note that unidirectional PS CIE color
           spaces should not be allowed but end up occuring when processing
           PDF files with -dUseCIEColor.  We will end up using the appropriate
           ICC default color space in these cases. */
        blend_color_space = gs_currentcolorspace_inline(pgs);
    } else {
        blend_color_space = cs_concrete_space(blend_color_space, pis);
    }
    /* Note that if the /CS parameter was NOT present in the push
       of the transparency group, then we must actually inherent
       the previous group color space, or the color space of the
       target device (process color model).  Here we just want
       to set it as a unknown type for clist writing, as we will take care
       of using the parent group color space later during clist reading.
       Also, if the group was not isolated we MUST use the parent group 
       color space regardless of what the group color space is specified to be
       */
    if (ptgp->ColorSpace == NULL || params.Isolated != true) {
        params.group_color = UNKNOWN;
        params.group_color_numcomps = 0;
    } else {
        /* The /CS parameter was present.  Use what was set.  Currently
           all our Device spaces are actually ICC based.  The other options
           are if -dUseCIEColor is set, in which case it could be
           coming in as a PS CIE color space, which should not be allowed
           but should default to one of the default ICC color spaces.  Note
           that CalRGB and CalGray, which are valid bidirectional color spaces
           are converted to ICC profiles during installation. PS CIE building
           to ICC is delayed. */
        if ( gs_color_space_is_ICC(blend_color_space) ) {
            /* Blending space is ICC based.  If we are doing c-list rendering
               we will need to write this color space into the clist.
               */
            params.group_color = ICC;
            params.group_color_numcomps =
                blend_color_space->cmm_icc_profile_data->num_comps;
            /* Get the ICC profile */
            params.iccprofile = blend_color_space->cmm_icc_profile_data;
            params.icc_hash = blend_color_space->cmm_icc_profile_data->hashcode;
        } else {
            /* Color space was NOT ICC based.  PS CIE space and DeviceN are the only
               other option.  Use the ICC default based upon the component count. */
            switch (cs_num_components(blend_color_space)) {
                case 1:
                    profile =  pgs->icc_manager->default_gray;
                    break;
                case 3:
                    profile =  pgs->icc_manager->default_rgb;
                    break;
                case 4:
                    profile =  pgs->icc_manager->default_cmyk;
                break;
                default:
                    /* We can end up here if we are in a deviceN color space and
                       we have a sep output device */
                    profile = NULL;
                    params.group_color = DEVICEN;
                    params.group_color_numcomps = cs_num_components(blend_color_space);
                break;
            }
            if (profile != NULL) {
                params.group_color = ICC;
                params.group_color_numcomps = profile->num_comps;
                params.iccprofile = profile;
                params.icc_hash = profile->hashcode;
            }
        }
    }
#ifdef DEBUG
    if (gs_debug_c('v')) {
        static const char *const cs_names[] = {
            GS_COLOR_SPACE_TYPE_NAMES
        };
        dmlprintf6(pgs->memory, "[v](0x%lx)begin_transparency_group [%g %g %g %g] Num_grp_clr_comp = %d\n",
                  (ulong)pgs, pbbox->p.x, pbbox->p.y, pbbox->q.x, pbbox->q.y,params.group_color_numcomps);
        if (ptgp->ColorSpace)
            dmprintf1(pgs->memory, "     CS = %s",
                cs_names[(int)gs_color_space_get_index(ptgp->ColorSpace)]);
        else
            dmputs(pgs->memory, "     (no CS)");

        dmprintf2(pgs->memory, "  Isolated = %d  Knockout = %d\n",
                 ptgp->Isolated, ptgp->Knockout);
    }
#endif
    params.bbox = *pbbox;
    return gs_state_update_pdf14trans(pgs, &params);
}