Exemplo n.º 1
0
static bool
client_install_CIEtoXYZ(client_custom_color_params_t * pparams,
	    gs_color_space * pcs, gs_state * pgs)
{
    /* get ready for converting to XYZ */
    demo_color_space_data_t * pdata;

    /* Exit if we have already installed this color space. */
    if (pcs->pclient_color_space_data != NULL)
	return true;

    pdata = allocate_client_data_block(1, pcs->rc.memory->stable_memory);
    pcs->pclient_color_space_data = (client_color_space_data_t *) pdata;
    if (pdata)
    {
	int code;
	const gs_cie_abc *pcie;

	pdata->client_is_going_to_handle_color_space = 1;
        switch (pcs->type->index) {
	  case gs_color_space_index_CIEDEF: {
	    gs_cie_def *pcie_def = pcs->params.def;

	    pcie = (gs_cie_abc *)pcie_def;
	    CIE_LOAD_CACHE_BODY(pcie_def->caches_def.DecodeDEF, pcie_def->RangeDEF.ranges,
			    &pcie_def->DecodeDEF, DecodeDEF_default, pcie_def,
			    "DecodeDEF");
	    break;
	  }
	  case gs_color_space_index_CIEDEFG: {
	    gs_cie_defg *pcie_defg = pcs->params.defg;

	    pcie = (gs_cie_abc *)pcie_defg;
	    CIE_LOAD_CACHE_BODY(pcie_defg->caches_defg.DecodeDEFG, pcie_defg->RangeDEFG.ranges,
			    &pcie_defg->DecodeDEFG, DecodeDEFG_default, pcie_defg,
			    "DecodeDEFG");
	    break;
	  }
	  case gs_color_space_index_CIEABC: {
	    pcie = pcs->params.abc;
	    break;
	  }
	  default:
	    /* can't happen since we only come here for certain color spaces */
	    return false;
	}
	/* Fill the caches we need in the CIE color space */
        if ((code=gx_install_cie_abc((gs_cie_abc *)pcie, pgs)) >= 0) {
	    /* Now allocate the conversion imager state in stable_memory */
	    /* so that the garbage collector won't free it               */
	    code = gx_cie_to_xyz_alloc(&pdata->CIEtoXYZ_pis, pcs,
				    pcs->rc.memory->stable_memory);
	}
	if (code < 0) {
	    client_adjust_cspace_count(pcs, -1);  /* free it up */
	    return false;
	}
    }
    return true;
}
Exemplo n.º 2
0
static bool
client_install_CIEtoA(client_custom_color_params_t * pparams,
	    gs_color_space * pcs, gs_state * pgs)
{
    /* get ready for converting to XYZ */
    demo_color_space_data_t * pdata;

    /* Exit if we have already installed this color space. */
    if (pcs->pclient_color_space_data != NULL)
	return true;

    pdata = allocate_client_data_block(1, pcs->rc.memory->stable_memory);
    pcs->pclient_color_space_data = (client_color_space_data_t *) pdata;
    if (pdata)
    {
	int code;
	gs_cie_a *pcie = pcs->params.a;
	gs_sample_loop_params_t lp;
	int i;

	pdata->client_is_going_to_handle_color_space = 1;

	/* Fill the caches we need in the CIE color space */
	gs_cie_cache_init(&pcie->caches.DecodeA.floats.params, &lp,
			  &pcie->RangeA, "DecodeA");
	for (i = 0; i <= lp.N; ++i) {
	    float in = SAMPLE_LOOP_VALUE(i, lp);

	    pcie->caches.DecodeA.floats.values[i] = (*pcie->DecodeA)(in, pcie);
	}
	gx_cie_load_common_cache(&pcie->common, pgs);
	gs_cie_a_complete(pcie);
	if ((code=gs_cie_cs_complete(pgs, true)) >= 0) {
	    /* Now allocate the conversion imager state in stable_memory */
	    /* so that the garbage collector won't free it		 */
	    code = gx_cie_to_xyz_alloc(&pdata->CIEtoXYZ_pis, pcs,
					pcs->rc.memory->stable_memory);
	}
	if (code < 0) {
	    client_adjust_cspace_count(pcs, -1);  /* free it up */
	    return false;
	}
    }
    return true;
}
Exemplo n.º 3
0
static bool
client_install_ICCtoXYZ(client_custom_color_params_t * pparams,
	    gs_color_space * pcs, gs_state * pgs)
{
    int code;
    const gs_icc_params * picc_params = (const gs_icc_params *)&pcs->params.icc;
    gs_cie_icc *    picc_info = picc_params->picc_info;
    demo_color_space_data_t * pdata;

    if (pcs->pclient_color_space_data != NULL)
	return true;

    pdata = allocate_client_data_block(1, pcs->rc.memory->stable_memory);
    pcs->pclient_color_space_data = (client_color_space_data_t *) pdata;

	/* Need to initialize the client data.  The imager_state is what is needed in pdata->CIEtoXZY_ps */

    /* update the stub information used by the joint caches  */
    gx_cie_load_common_cache(&picc_info->common, pgs);
    gx_cie_common_complete(&picc_info->common);

    if ((code=gs_cie_cs_complete(pgs, true)) < 0) {
	client_adjust_cspace_count(pcs, -1);  /* free it up  */
	return false;
    }

	/* Now allocate the conversion imager state in stable_memory	*/
	/* so that the garbage collector won't free it			*/
	code = gx_cie_to_xyz_alloc(&pdata->CIEtoXYZ_pis, pcs,
				pcs->rc.memory->stable_memory);

	if (code < 0) {
	    client_adjust_cspace_count(pcs, -1);  /* free it up */
	    return false;
	}

    return true;
}
Exemplo n.º 4
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;
}