/* <dict> .buildcolorrendering1 <crd> */ static int zbuildcolorrendering1(i_ctx_t *i_ctx_p) { os_ptr op = osp; gs_memory_t *mem = gs_state_memory(igs); int code; es_ptr ep = esp; gs_cie_render *pcrd; ref_cie_render_procs procs; check_read_type(*op, t_dictionary); check_dict_read(*op); code = gs_cie_render1_build(&pcrd, mem, ".buildcolorrendering1"); if (code < 0) return code; code = zcrd1_params(op, pcrd, &procs, mem); if (code < 0 || (code = cache_colorrendering1(i_ctx_p, pcrd, &procs, (gs_ref_memory_t *) mem)) < 0 ) { rc_free_struct(pcrd, ".buildcolorrendering1"); esp = ep; return code; } /****** FIX refct ******/ /*rc_decrement(pcrd, ".buildcolorrendering1"); *//* build sets rc = 1 */ istate->colorrendering.dict = *op; make_istruct_new(op, a_readonly, pcrd); return (esp == ep ? 0 : o_push_estack); }
/* <dict> .builddevicecolorrendering1 <crd> */ static int zbuilddevicecolorrendering1(i_ctx_t *i_ctx_p) { os_ptr op = osp; gs_memory_t *mem = gs_state_memory(igs); dict_param_list list; gs_cie_render *pcrd = 0; int code; check_type(*op, t_dictionary); code = dict_param_list_read(&list, op, NULL, false, iimemory); if (code < 0) return code; code = gs_cie_render1_build(&pcrd, mem, ".builddevicecolorrendering1"); if (code >= 0) { code = param_get_cie_render1(pcrd, (gs_param_list *) & list, gs_currentdevice(igs)); if (code >= 0) { /****** FIX refct ******/ /*rc_decrement(pcrd, ".builddevicecolorrendering1"); *//* build sets rc = 1 */ } } iparam_list_release(&list); if (code < 0) { rc_free_struct(pcrd, ".builddevicecolorrendering1"); return code; } istate->colorrendering.dict = *op; make_istruct_new(op, a_readonly, pcrd); return 0; }
static int test6(gs_state * pgs, gs_memory_t * mem) { gs_color_space *pcs; gs_cie_abc *pabc; gs_cie_render *pcrd; static const gs_vector3 white_point = {1, 1, 1}; static const gs_cie_render_proc3 encode_abc = { {render_abc, render_abc, render_abc} }; int code; gs_color_space *rgb_cs; rgb_cs = gs_cspace_new_DeviceRGB(mem); gs_scale(pgs, 150.0, 150.0); gs_translate(pgs, 0.5, 0.5); gs_setcolorspace(pgs, rgb_cs); spectrum(pgs, 5); gs_translate(pgs, 1.2, 0.0); /* We must set the CRD before the color space. */ code = gs_cie_render1_build(&pcrd, mem, "test6"); if (code < 0) return code; gs_cie_render1_initialize(mem, pcrd, NULL, &white_point, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &encode_abc, NULL, NULL); gs_setcolorrendering(pgs, pcrd); gs_cspace_build_CIEABC(&pcs, NULL, mem); /* There should be an API for initializing CIE color spaces too.... */ pabc = pcs->params.abc; pabc->common.points.WhitePoint = white_point; gs_cie_abc_complete(pabc); /* End of initializing the color space. */ gs_setcolorspace(pgs, pcs); spectrum(pgs, 5); gs_free_object(mem, rgb_cs, "test6 rgb_cs"); return 0; }
static int pl_build_crd(gs_state *pgs) { int code; /* nothing to do */ if ( pl_pcrd_built == true ) return gs_setcolorrendering(pgs, pl_pcrd); code = gs_cie_render1_build(&pl_pcrd, gs_state_memory(pgs), "build_crd"); if ( code < 0 ) return code; pl_pcrd_built = true; if ( pl_read_device_CRD(pl_pcrd, pgs) ) { dprintf("CRD initialized from device\n"); return 0; } code = gs_cie_render1_initialize(pgs->memory, pl_pcrd, NULL, &pl_WhitePoint, &pl_BlackPoint, &pl_MatrixPQR, &pl_RangePQR, &pl_TransformPQR, &pl_MatrixCRDLMN, NULL, /* EncodeLMN */ NULL, /* RangeLMN */ NULL, /* MatrixABC */ &pl_EncodeABC_procs, NULL, NULL); if ( code < 0 ) return code; /* should not fail */ code = gs_setcolorrendering(pgs, pl_pcrd); return code; }
/* * Implement get_params for a sample device CRD. A useful convention, * for devices that can provide more than one CRD, is to have a settable * parameter CRDName, which gives the name of the CRD in use. This sample * code provides a constant CRDName: making it settable is left as an * exercise to the reader. */ int sample_device_crd_get_params(gx_device *pdev, gs_param_list *plist, const char *crd_param_name) { int ecode = 0; if (param_requested(plist, "CRDName") > 0) { gs_param_string cns; int code; cns.data = (const byte *)crd_param_name; cns.size = strlen(crd_param_name); cns.persistent = true; code = param_write_string(plist, "CRDName", &cns); if (code < 0) ecode = code; } if (param_requested(plist, crd_param_name) > 0) { gs_cie_render *pcrd; int code = gs_cie_render1_build(&pcrd, pdev->memory, "sample_device_crd_get_params"); if (code >= 0) { gs_cie_transform_proc3 tpqr; tpqr = bit_TransformPQR; tpqr.driver_name = pdev->dname; code = gs_cie_render1_initialize(pdev->memory, pcrd, NULL, &bit_WhitePoint, NULL /*BlackPoint*/, NULL /*MatrixPQR*/, &bit_RangePQR, &tpqr, NULL /*MatrixLMN*/, &bit_EncodeLMN, &bit_RangeLMN, &bit_MatrixABC, &bit_EncodeABC, NULL /*RangeABC*/, &bit_RenderTable); if (code >= 0) { code = param_write_cie_render1(plist, crd_param_name, pcrd, pdev->memory); } rc_decrement(pcrd, "sample_device_crd_get_params"); /* release */ } if (code < 0) ecode = code; } if (param_requested(plist, bit_TransformPQR.proc_name) > 0) { /* * We definitely do not recommend the following use of a static * to hold the address: this is a shortcut. */ gs_cie_transform_proc my_proc = bit_TransformPQR_proc; byte *my_addr = gs_alloc_string(pdev->memory, sizeof(my_proc), "sd_crd_get_params(proc)"); int code; if (my_addr == 0) code = gs_note_error(gs_error_VMerror); else { gs_param_string as; memcpy(my_addr, &my_proc, sizeof(my_proc)); as.data = my_addr; as.size = sizeof(my_proc); as.persistent = true; code = param_write_string(plist, bit_TransformPQR.proc_name, &as); } if (code < 0) ecode = code; } return ecode; }