Example #1
0
/*
 * Adjust the reference count on our client data,
 * freeing it if necessary.
 */
static void
client_adjust_cspace_count(const gs_color_space * pcs, int delta)
{
    demo_color_space_data_t * pdata =
	(demo_color_space_data_t *)(pcs->pclient_color_space_data);

    pdata->ref_count += delta;
    if (pdata->ref_count <= 0) {
	/* Free up the CIE to XYZ imager state if it was allocated */
	if (pdata->CIEtoXYZ_pis) {
	    gx_cie_to_xyz_free(pdata->CIEtoXYZ_pis);
	}
	gs_free_object(pdata->memory, pdata, "client_adjust_cspace_count(pdata)");
    }
}
Example #2
0
/* Create a PDF Lab color space corresponding to a CIEBased color space. */
static int
lab_range(gs_range range_out[3] /* only [1] and [2] used */,
	  const gs_color_space *pcs, const gs_cie_common *pciec,
	  const gs_range *ranges, gs_memory_t *mem)
{
    /*
     * Determine the range of a* and b* by evaluating the color space
     * mapping at all of its extrema.
     */
    int ncomp = gs_color_space_num_components(pcs);
    gs_imager_state *pis;
    int code = gx_cie_to_xyz_alloc(&pis, pcs, mem);
    int i, j;

    if (code < 0)
	return code;
    for (j = 1; j < 3; ++j)
	range_out[j].rmin = 1000.0, range_out[j].rmax = -1000.0;
    for (i = 0; i < 1 << ncomp; ++i) {
	double in[4], xyz[3];

	for (j = 0; j < ncomp; ++j)
	    in[j] = (i & (1 << j) ? ranges[j].rmax : ranges[j].rmin);
	if (cie_to_xyz(in, xyz, pcs, pis) >= 0) {
	    double lab[3];

	    xyz_to_lab(xyz, lab, pciec);
	    for (j = 1; j < 3; ++j) {
		range_out[j].rmin = min(range_out[j].rmin, lab[j]);
		range_out[j].rmax = max(range_out[j].rmax, lab[j]);
	    }
	}
    }
    gx_cie_to_xyz_free(pis);
    return 0;
}