Beispiel #1
0
/*
 * DeviceN and NChannel color spaces can have an attributes dict.  In the
 * attribute dict can be a Colorants dict which contains Separation color
 * spaces.  If the Colorant dict is present, the PS logic will build each of
 * the Separation color spaces in a temp gstate and then call this procedure
 * to attach the Separation color space to the DeviceN color space.
 * The parameter to this procedure is a colorant name.  The Separation
 * color space is in the current (temp) gstate.  The DeviceN color space is
 * in the next gstate down in the gstate list (pgs->saved).
 */
int
gs_attachattributecolorspace(gs_separation_name sep_name, gs_state * pgs)
{
    gs_color_space * pdevncs;
    gs_device_n_attributes * patt;

    /* Verify that we have a DeviceN color space */
    if (!pgs->saved)
        return_error(gs_error_rangecheck);
    pdevncs = gs_currentcolorspace_inline(pgs->saved);
    if (pdevncs->type != &gs_color_space_type_DeviceN)
        return_error(gs_error_rangecheck);

    /* Allocate an attribute list element for our linked list of attributes */
    rc_alloc_struct_1(patt, gs_device_n_attributes, &st_device_n_attributes,
                        pgs->memory, return_error(gs_error_VMerror),
                        "gs_attachattributrescolorspace");

    /* Point our attribute list entry to the attribute color space */
    patt->colorant_name = sep_name;
    patt->cspace = gs_currentcolorspace_inline(pgs);
    rc_increment_cs(patt->cspace);

    /* Link our new attribute color space to the DeviceN color space */
    patt->next = pdevncs->params.device_n.colorants;
    pdevncs->params.device_n.colorants = patt;

    return 0;
}
Beispiel #2
0
/*
 * Get pointers to the current color space and client color.
 *
 * More description in src/gxhldevc.h
 */
gx_hld_get_color_space_and_ccolor_status
gx_hld_get_color_space_and_ccolor(const gs_imager_state * pis,
                const gx_device_color * pdevc, const gs_color_space ** ppcs,
                const gs_client_color ** ppcc)
{
    /* Check if the current color space was used to build the device color */
    if (gx_hld_is_hl_color_available(pis, pdevc)) {
        const gs_state * pgs = gx_hld_get_gstate_ptr(pis);
        const gs_color_space * pcs = gs_currentcolorspace_inline(pgs);

        *ppcs = pcs;
        *ppcc = &(pdevc->ccolor);
        if (pdevc->type == gx_dc_type_pattern
           || pdevc->type == &gx_dc_pure_masked
           || pdevc->type == gx_dc_type_pattern2)
            return pattern_color_space;
        else {
            return non_pattern_color_space;
        }
    }
    /* No color space */
    *ppcs = NULL;
    *ppcc = NULL;
    return use_process_color;
}
Beispiel #3
0
/* Install a Separation color space. */
static int
gx_install_Separation(gs_color_space * pcs, gs_state * pgs)
{
    int code;

    code = check_Separation_component_name(pcs, pgs);
    if (code < 0)
       return code;
    gs_currentcolorspace_inline(pgs)->params.separation.use_alt_cspace =
        using_alt_color_space(pgs);
    if (gs_currentcolorspace_inline(pgs)->params.separation.use_alt_cspace)
        code = (pcs->base_space->type->install_cspace)
            (pcs->base_space, pgs);
    /*
     * Give the device an opportunity to capture equivalent colors for any
     * spot colors which might be present in the color space.
     */
    if (code >= 0)
        code = dev_proc(pgs->device, update_spot_equivalent_colors)
                                                        (pgs->device, pgs);
    return code;
}
Beispiel #4
0
/*
 * Get the number of components in the current color space.
 *
 * More description in src/gxhldevc.h
 */
int
gx_hld_get_number_color_components(const gs_imager_state * pis)
{
    const gs_state * pgs = gx_hld_get_gstate_ptr(pis);

    if (pgs != NULL) {
        const gs_color_space * pcs = gs_currentcolorspace_inline(pgs);
        int n = gs_color_space_num_components(pcs);

        return (n >= 0 ? n : -n - 1);
    } else
        return -1;
}
Beispiel #5
0
/*
 * Save the device color information including the color space id and
 * client color data (if available).
 *
 * More description in src/gxhldevc.h
 */
bool
gx_hld_save_color(const gs_imager_state * pis, const gx_device_color * pdevc,
                gx_hl_saved_color * psc)
{
    const gs_state * pgs = gx_hld_get_gstate_ptr(pis);
    memset(psc, 0, sizeof(*psc));	/* clear the entire structure */

    if (pdevc == NULL) {
        /* No device color given, should not happen */
        gx_hld_saved_color_init(psc);	/* revert to unknown color */
        return false;
    } else if (pgs == NULL) {
        /* No color space, simply save device color specific info */
        psc->color_space_id = psc->pattern_id = gs_no_id;
        pdevc->type->save_dc(pdevc, &(psc->saved_dev_color));
        return false;
    } else {
        /*
         * Have color space, save id,  ccolor, & device color specific info.
         * Also save the high level colors since two gx_color_index values
         * may be the same but for differing high level colors (due to the
         * usual lower resolution of the gx_color_index values.
         */
        const gs_color_space * pcs = gs_currentcolorspace_inline(pgs);
        int i = gs_color_space_num_components(pcs);

        psc->color_space_id = pcs->id;
        pdevc->type->save_dc(pdevc, &(psc->saved_dev_color));
        if (pdevc->type == gx_dc_type_pattern2)
            i = 0;
        else if (i < 0)
            i = -i - 1; /* See gx_num_components_Pattern. */
        for (i--; i >= 0; i--)
            psc->ccolor.paint.values[i] = pdevc->ccolor.paint.values[i];

        /* Save the pattern id - if present */
        if ((pdevc->type == gx_dc_type_pattern
           || pdevc->type == gx_dc_type_pattern2) && pdevc->ccolor_valid)
            psc->pattern_id = pdevc->ccolor.pattern->pattern_id;
        else
            psc->pattern_id = gs_no_id;
        return true;
    }
}
Beispiel #6
0
/* If possible, update the equivalent CMYK color for a spot color */
void
update_spot_equivalent_cmyk_colors(gx_device * pdev, const gs_state * pgs,
    gs_devn_params * pdevn_params, equivalent_cmyk_color_params * pparams)
{
    const gs_color_space * pcs;

    /* If all of the color_info is valid then there is nothing to do. */
    if (pparams->all_color_info_valid)
        return;

    /* Verify that we really have some separations. */
    if (pdevn_params->separations.num_separations == 0) {
        pparams->all_color_info_valid = true;
        return;
    }
    /*
     * Verify that the given color space is a Separation or a DeviceN color
     * space.  If so then when check if the color space contains a separation
     * color for which we need a CMYK equivalent.
     */
    pcs = gs_currentcolorspace_inline(pgs);
    if (pcs != NULL) {
        if (pcs->type->index == gs_color_space_index_Separation) {
            update_Separation_spot_equivalent_cmyk_colors(pdev, pgs, pcs,
                                                pdevn_params, pparams);
            pparams->all_color_info_valid = check_all_colors_known
                    (pdevn_params->separations.num_separations, pparams);
        }
        else if (pcs->type->index == gs_color_space_index_DeviceN) {
            update_DeviceN_spot_equivalent_cmyk_colors(pdev, pgs, pcs,
                                                pdevn_params, pparams);
            pparams->all_color_info_valid = check_all_colors_known
                    (pdevn_params->separations.num_separations, pparams);
        }
    }
}
Beispiel #7
0
/* This does all the work of setpattern except for the final setcolor. */
int
gs_setpatternspace(gs_state * pgs)
{
    int code = 0;
    gs_color_space *ccs_old;

    if (pgs->in_cachedevice)
        return_error(gs_error_undefined);
    ccs_old = gs_currentcolorspace_inline(pgs);
    if (ccs_old->type->index != gs_color_space_index_Pattern) {
        gs_color_space *pcs;

        pcs = gs_cspace_alloc(pgs->memory, &gs_color_space_type_Pattern);
        if (pcs == NULL)
            return_error(gs_error_VMerror);
        /* reference to base space shifts from pgs to pcs with no net change */
        pcs->base_space = ccs_old;
        pcs->params.pattern.has_base_space = true;
        pgs->color[0].color_space = pcs;
        cs_full_init_color(pgs->color[0].ccolor, pcs);
        gx_unset_dev_color(pgs);
    }
    return code;
}
Beispiel #8
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);
}