Example #1
0
/*
 * Convert a CIEBasedA color into device color.
 */
static int
client_remap_CIEBasedA(client_custom_color_params_t * pparams,
    const gs_client_color * pc, const gs_color_space * pcs,
    gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
    gs_color_select_t select)
{
    demo_color_space_data_t * pdata =
	(demo_color_space_data_t *)(pcs->pclient_color_space_data);
    frac gray = convert2frac(pc->paint.values[0], pcs->params.a->RangeA);

    /*** Demonstrate method to convert to XYZ ***/
    if (pdata->CIEtoXYZ_pis) {
	frac xyz[3];

	cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
	/* We don't really do anything with these values, but this */
	/* is where a real client could convert to a device color  */
	if_debug4('|', "[c]client_remap CIEA [%g] -> XYZ [%g, %g, %g]\n",
		  pc->paint.values[0],
		  frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));

    }
    /*
     * For demo and debug purposes, make our colors a function of the
     * intensity of the given color value and the object type.
     */
    return client_remap_DeviceGray(pparams, &gray, pcs, pdc, pis, dev, select);
}
Example #2
0
/*
 * Convert a CIEBasedDEFG color into device color.
 */
static int
client_remap_CIEBasedDEFG(client_custom_color_params_t * pparams,
    const gs_client_color * pc, const gs_color_space * pcs,
    gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
    gs_color_select_t select)
{
    demo_color_space_data_t * pdata =
	(demo_color_space_data_t *)(pcs->pclient_color_space_data);
    frac cmyk[4];
    int i;

    /*** Demonstrate method to convert to XYZ ***/
    if (pdata->CIEtoXYZ_pis) {
	frac xyz[3];

	cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
	/* We don't really do anything with these values, but this */
	/* is where a real client could convert to a device color  */
	if_debug7('|', "[c]client_remap CIEDEFG [%g, %g, %g] -> XYZ [%g, %g, %g]\n",
		  pc->paint.values[0], pc->paint.values[1], pc->paint.values[2],
		  pc->paint.values[3],
		  frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
    }
    /*
     * For demo and debug purposes, make our colors a function of the
     * intensity of the given color value and the object type.  The color
     * values could represent almost anything.  However we are assuming
     * that they are CMYK values.
     */
    for (i = 0; i < 4; i++)
	cmyk[i] = convert2frac(pc->paint.values[i],
		       	pcs->params.defg->RangeDEFG.ranges[i]);
    return client_remap_DeviceRGB(pparams, cmyk, pcs, pdc, pis, dev, select);
}
Example #3
0
static int
gx_concretize_DeviceN(const gs_client_color * pc, const gs_color_space * pcs,
		      frac * pconc, const gs_imager_state * pis)
{
    int code, tcode = 0;
    gs_client_color cc;
    const gs_color_space *pacs = pcs->base_space;
    gs_device_n_map *map = pcs->params.device_n.map;

#ifdef DEBUG
    /* 
     * Verify that the color space and imager state info match.
     */
    if (pcs->id != pis->color_component_map.cspace_id)
	dprintf("gx_concretize_DeviceN: color space id mismatch");
#endif

    /*
     * Check if we need to map into the alternate color space.
     * We must preserve tcode for implementing a semi-hack in the interpreter.
     */
    if (pis->color_component_map.use_alt_cspace) {
	    /* Check the 1-element cache first. */
	if (map->cache_valid) {
	    int i;

	    for (i = pcs->params.device_n.num_components; --i >= 0;) {
		if (map->tint[i] != pc->paint.values[i])
		    break;
	    }
	    if (i < 0) {
		int num_out = gs_color_space_num_components(pacs);

		for (i = 0; i < num_out; ++i)
		    pconc[i] = map->conc[i];
		return 0;
	    }
	}
        tcode = (*pcs->params.device_n.map->tint_transform)
	     (pc->paint.values, &cc.paint.values[0],
	     pis, pcs->params.device_n.map->tint_transform_data);
        if (tcode < 0)
	    return tcode;
	code = cs_concretize_color(&cc, pacs, pconc, pis);
    }
    else {
	float ftemp;
	int i;

	for (i = pcs->params.device_n.num_components; --i >= 0;)
	    pconc[i] = unit_frac(pc->paint.values[i], ftemp);
	return 0;
    }
    return (code < 0 || tcode == 0 ? code : tcode);
}
Example #4
0
/*
 * Convert a ICCBased color into device color.
 */
static int
client_remap_ICCBased(client_custom_color_params_t * pparams,
    const gs_client_color * pc, const gs_color_space * pcs,
    gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
    gs_color_select_t select)
{
    demo_color_space_data_t * pdata =
	(demo_color_space_data_t *)(pcs->pclient_color_space_data);
    frac frac_color[GS_CLIENT_COLOR_MAX_COMPONENTS];
    int i, num_values = pcs->params.icc.picc_info->num_components;

    /*** Demonstrate method to convert to XYZ ***/
    if (pdata->CIEtoXYZ_pis) {

		frac xyz[3];

		cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
		/* We don't really do anything with these values, but this */
		/* is where a real client could convert to a device color  */
		if_debug6('|', "[c]client_remap ICCBased [%g, %g, %g] -> XYZ [%g, %g, %g]\n",
			  pc->paint.values[0], pc->paint.values[1], pc->paint.values[2],
			  frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
    }

    /*
     * For demo and debug purposes, make our colors a function of the
     * intensity of the given color value and the object type.  The color
     * values could represent almost anything.  However based upon the
     * number of color values, we are assuming that they are either
     * gray, RGB, or CMYK values.
     */
    for (i = 0; i < num_values; i++)
	frac_color[i] = convert2frac(pc->paint.values[i],
		       	pcs->params.icc.picc_info->Range.ranges[i]);
    switch (num_values) {
	case 0:
	case 2:
	    return_error(gs_error_rangecheck);
	case 1:
	    return client_remap_DeviceGray(pparams, frac_color, pcs,
			   		 pdc, pis, dev, select);
	case 3:
	    return client_remap_DeviceRGB(pparams, frac_color, pcs,
			   		 pdc, pis, dev, select);
	case 4:
	default:
	    return client_remap_DeviceCMYK(pparams, frac_color, pcs,
			   		 pdc, pis, dev, select);
    }
}
Example #5
0
/* Transform a CIEBased color to XYZ. */
static int
cie_to_xyz(const double *in, double out[3], const gs_color_space *pcs,
	   const gs_imager_state *pis)
{
    gs_client_color cc;
    frac xyz[3];
    int ncomp = gs_color_space_num_components(pcs);
    int i;

    for (i = 0; i < ncomp; ++i)
	cc.paint.values[i] = in[i];
    cs_concretize_color(&cc, pcs, xyz, pis);
    out[0] = frac2float(xyz[0]);
    out[1] = frac2float(xyz[1]);
    out[2] = frac2float(xyz[2]);
    return 0;
}
Example #6
0
static int
gx_concretize_Separation(const gs_client_color *pc, const gs_color_space *pcs,
                         frac *pconc, const gs_imager_state *pis, gx_device *dev)
{
    int code;
    gs_client_color cc;
    gs_color_space *pacs = pcs->base_space;
    bool is_lab;
    int k;
    int num_des_comps = dev->color_info.num_components;

    if (pcs->params.separation.sep_type == SEP_OTHER &&
        pcs->params.separation.use_alt_cspace) {
        gs_device_n_map *map = pcs->params.separation.map;
        /* First see if we have a named color object that we can use to try
           to map from the spot color into device values.  */
        if (pis->icc_manager->device_named != NULL) {
            /* There is a table present.  If we have the colorant name
               then get the device values */
            gx_color_value device_values[GX_DEVICE_COLOR_MAX_COMPONENTS];
            const gs_separation_name name = pcs->params.separation.sep_name;
            byte *pname;
            uint name_size;
            gsicc_rendering_param_t rendering_params;

            /* Define the rendering intents. */
            rendering_params.black_point_comp = BP_ON;
            rendering_params.graphics_type_tag = GS_PATH_TAG;
            rendering_params.rendering_intent = pis->renderingintent;

            pcs->params.separation.get_colorname_string(pis->memory, name,
                                                &pname, &name_size);
            code = gsicc_transform_named_color(pc->paint.values[0], pname,
                            name_size, device_values, pis, dev, NULL,
                            &rendering_params);
            if (code == 0) {
                for (k = 0; k < num_des_comps; k++){
                    pconc[k] = float2frac(((float) device_values[k])/65535.0);
                }
                return(0);
            }
        }
        /* Check the 1-element cache first. */
        if (map->cache_valid && map->tint[0] == pc->paint.values[0]) {
            int i, num_out = gs_color_space_num_components(pacs);

            for (i = 0; i < num_out; ++i)
                pconc[i] = map->conc[i];
            return 0;
        }
        code = (*pcs->params.separation.map->tint_transform)
            (pc->paint.values, &cc.paint.values[0],
             pis, pcs->params.separation.map->tint_transform_data);
        if (code < 0)
            return code;
        /* First check if this was PS based. */
        if (gs_color_space_is_PSCIE(pacs)) {
            /* If we have not yet create the profile do that now */
            if (pacs->icc_equivalent == NULL) {
                gs_colorspace_set_icc_equivalent(pacs, &(is_lab), pis->memory);
            }
            /* Use the ICC equivalent color space */
            pacs = pacs->icc_equivalent;
        }
        if (pacs->cmm_icc_profile_data->data_cs == gsCIELAB) {
            /* Get the data in a form that is concrete for the CMM */
            cc.paint.values[0] /= 100.0;
            cc.paint.values[1] = (cc.paint.values[1]+128)/255.0;
            cc.paint.values[2] = (cc.paint.values[2]+128)/255.0;
        }
        return cs_concretize_color(&cc, pacs, pconc, pis, dev);
    }
    else {
        pconc[0] = gx_unit_frac(pc->paint.values[0]);
    }
    return 0;
}
Example #7
0
static int
gx_concretize_DeviceN(const gs_client_color * pc, const gs_color_space * pcs,
                      frac * pconc, const gs_imager_state * pis, gx_device *dev)
{
    int code, tcode = 0;
    gs_client_color cc;
    gs_color_space *pacs = (gs_color_space*) (pcs->base_space);
    gs_device_n_map *map = pcs->params.device_n.map;
    bool is_lab;
    int num_src_comps = pcs->params.device_n.num_components;

#ifdef DEBUG
    /*
     * Verify that the color space and imager state info match.
     */
    if (pcs->id != pis->color_component_map.cspace_id)
        dmprintf(dev->memory, "gx_concretize_DeviceN: color space id mismatch");
#endif

    /*
     * Check if we need to map into the alternate color space.
     * We must preserve tcode for implementing a semi-hack in the interpreter.
     */

    if (pis->color_component_map.use_alt_cspace) {
        /* Check the 1-element cache first. */
        if (map->cache_valid) {
            int i;

            for (i = pcs->params.device_n.num_components; --i >= 0;) {
                if (map->tint[i] != pc->paint.values[i])
                    break;
            }
            if (i < 0) {
                int num_out = gs_color_space_num_components(pacs);

                for (i = 0; i < num_out; ++i)
                    pconc[i] = map->conc[i];
                return 0;
            }
        }
        tcode = (*pcs->params.device_n.map->tint_transform)
             (pc->paint.values, &cc.paint.values[0],
             pis, pcs->params.device_n.map->tint_transform_data);
        (*pacs->type->restrict_color)(&cc, pacs);
        if (tcode < 0)
            return tcode;
        /* First check if this was PS based. */
        if (gs_color_space_is_PSCIE(pacs)) {
            /* We may have to rescale data to 0 to 1 range */
            rescale_cie_colors(pacs, &cc);
            /* If we have not yet created the profile do that now */
            if (pacs->icc_equivalent == NULL) {
                gs_colorspace_set_icc_equivalent(pacs, &(is_lab), pis->memory);
            }
            /* Use the ICC equivalent color space */
            pacs = pacs->icc_equivalent;
        }
        if (pacs->cmm_icc_profile_data->data_cs == gsCIELAB ||
            pacs->cmm_icc_profile_data->islab) {
            /* Get the data in a form that is concrete for the CMM */
            cc.paint.values[0] /= 100.0;
            cc.paint.values[1] = (cc.paint.values[1]+128)/255.0;
            cc.paint.values[2] = (cc.paint.values[2]+128)/255.0;
        }
        code = cs_concretize_color(&cc, pacs, pconc, pis, dev);
    }
    else {
        int i;

        for (i = num_src_comps; --i >= 0;)
            pconc[i] = gx_unit_frac(pc->paint.values[i]);
        return 0;
    }
    return (code < 0 || tcode == 0 ? code : tcode);
}
Example #8
0
static int
gx_concretize_DeviceN(const gs_client_color * pc, const gs_color_space * pcs,
                      frac * pconc, const gs_imager_state * pis, gx_device *dev)
{
    int code, tcode = 0;
    gs_client_color cc;
    gs_color_space *pacs = (gs_color_space*) (pcs->base_space);
    gs_device_n_map *map = pcs->params.device_n.map;
    bool is_lab;
    int k;
    int num_des_comps = dev->color_info.num_components;
    gsicc_namedcolor_t *named_color;
    const gs_separation_name *names = pcs->params.device_n.names;
    int num_src_comps = pcs->params.device_n.num_components;

#ifdef DEBUG
    /*
     * Verify that the color space and imager state info match.
     */
    if (pcs->id != pis->color_component_map.cspace_id)
        dmprintf(dev->memory, "gx_concretize_DeviceN: color space id mismatch");
#endif

    /*
     * Check if we need to map into the alternate color space.
     * We must preserve tcode for implementing a semi-hack in the interpreter.
     */

    if (pis->color_component_map.use_alt_cspace) {
        /* First see if we have a named color object that we can use to try
           to map from the spot color into device values.  */
        if (pis->icc_manager->device_named != NULL) {
            /* There is a table present.  If we have the colorant name
               then get the device values */
            gx_color_value device_values[GX_DEVICE_COLOR_MAX_COMPONENTS];
            byte *pname;
            uint name_size;
            gsicc_rendering_param_t rendering_params;

            /* Define the rendering intents. */
            rendering_params.black_point_comp = pis->blackptcomp;
            rendering_params.graphics_type_tag = dev->graphics_type_tag;
            rendering_params.override_icc = false;
            rendering_params.preserve_black = gsBKPRESNOTSPECIFIED;
            rendering_params.rendering_intent = pis->renderingintent;
            rendering_params.cmm = gsCMM_DEFAULT;

            /* Allocate and initialize name structure */
            named_color = 
                (gsicc_namedcolor_t*) gs_alloc_bytes(dev->memory,
                    num_src_comps * sizeof(gsicc_namedcolor_t),
                    "gx_remap_concrete_DeviceN");

            for (k = 0; k < num_src_comps; k++) {
                pcs->params.device_n.get_colorname_string(dev->memory, names[k], 
                                                          &pname, &name_size);
                named_color[k].colorant_name = (char*) pname;
                named_color[k].name_size = name_size;
            }
            code = gsicc_transform_named_color(pc->paint.values, named_color,
                                               num_src_comps, device_values, 
                                               pis, dev, NULL, 
                                               &rendering_params);
            gs_free_object(dev->memory, named_color, 
                           "gx_remap_concrete_DeviceN");
            if (code == 0) {
                for (k = 0; k < num_des_comps; k++){
                    pconc[k] = float2frac(((float) device_values[k])/65535.0);
                }
                return(0);
            }
        }
        /* Check the 1-element cache first. */
        if (map->cache_valid) {
            int i;

            for (i = pcs->params.device_n.num_components; --i >= 0;) {
                if (map->tint[i] != pc->paint.values[i])
                    break;
            }
            if (i < 0) {
                int num_out = gs_color_space_num_components(pacs);

                for (i = 0; i < num_out; ++i)
                    pconc[i] = map->conc[i];
                return 0;
            }
        }
        tcode = (*pcs->params.device_n.map->tint_transform)
             (pc->paint.values, &cc.paint.values[0],
             pis, pcs->params.device_n.map->tint_transform_data);
        (*pacs->type->restrict_color)(&cc, pacs);
        if (tcode < 0)
            return tcode;
        /* First check if this was PS based. */
        if (gs_color_space_is_PSCIE(pacs)) {
            /* We may have to rescale data to 0 to 1 range */
            rescale_cie_colors(pacs, &cc);
            /* If we have not yet created the profile do that now */
            if (pacs->icc_equivalent == NULL) {
                gs_colorspace_set_icc_equivalent(pacs, &(is_lab), pis->memory);
            }
            /* Use the ICC equivalent color space */
            pacs = pacs->icc_equivalent;
        }
        if (pacs->cmm_icc_profile_data->data_cs == gsCIELAB ||
            pacs->cmm_icc_profile_data->islab) {
            /* Get the data in a form that is concrete for the CMM */
            cc.paint.values[0] /= 100.0;
            cc.paint.values[1] = (cc.paint.values[1]+128)/255.0;
            cc.paint.values[2] = (cc.paint.values[2]+128)/255.0;
        }
        code = cs_concretize_color(&cc, pacs, pconc, pis, dev);
    }
    else {
        int i;

        for (i = num_src_comps; --i >= 0;)
            pconc[i] = gx_unit_frac(pc->paint.values[i]);
        return 0;
    }
    return (code < 0 || tcode == 0 ? code : tcode);
}