/* return SRGB color space to the client */ int pl_cspace_init_SRGB(gs_color_space **ppcs, const gs_state *pgs) { int code; /* make sure we have a crd set up */ #ifdef DEVICE_DOES_COLOR_CONVERSION *ppcs = gs_cspace_new_DeviceRGB(pgs->memory); return 0; #endif code = pl_build_crd((gs_state *)pgs); if ( code < 0 ) return code; code = gs_cspace_build_CIEABC(ppcs, NULL, gs_state_memory(pgs)); if ( code < 0 ) return code; *(gs_cie_DecodeLMN(*ppcs)) = pl_DecodeLMN; *(gs_cie_MatrixLMN(*ppcs)) = pl_MatrixLMN; (gs_cie_WhitePoint(*ppcs)) = pl_WhitePoint; (gs_cie_BlackPoint(*ppcs)) = pl_BlackPoint; return 0; }
/* * Create a local Device{Gray,RGB,CMYK} color space corresponding to the * given number of components. */ int pdf_cspace_init_Device(gs_memory_t *mem, gs_color_space **ppcs, int num_components) { switch (num_components) { case 1: *ppcs = gs_cspace_new_DeviceGray(mem); break; case 3: *ppcs = gs_cspace_new_DeviceRGB(mem); break; case 4: *ppcs = gs_cspace_new_DeviceCMYK(mem); break; default: return_error(gs_error_rangecheck); } 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 test8(gs_state * pgs, gs_memory_t * mem) { /* * Define a 16 x 16 pattern using a 4-entry palette * (white, red, green, black). */ static const byte pdata[] = { 0x7f, 0xff, 0x00, 0x03, 0x7f, 0xff, 0x00, 0x0c, 0x50, 0x00, 0x00, 0x30, 0x50, 0x00, 0x00, 0xc0, 0x50, 0x00, 0x03, 0x00, 0x50, 0x00, 0x0c, 0x00, 0x50, 0x00, 0x30, 0x00, 0x50, 0x00, 0xc0, 0x00, 0xf0, 0x00, 0xc0, 0x00, 0xf0, 0x00, 0x30, 0x00, 0xf0, 0x00, 0x0c, 0x00, 0xf0, 0x00, 0x03, 0x00, 0xf0, 0x00, 0x00, 0xc0, 0xf0, 0x00, 0x00, 0x30, 0xea, 0x55, 0xaa, 0x5c, 0xea, 0x55, 0xaa, 0x57, }; gs_depth_bitmap ptile; gs_const_string table; gs_color_space *pcs; gs_client_color ccolor; gs_color_space *rgb_cs; rgb_cs = gs_cspace_new_DeviceRGB(mem); table.data = (const byte *)"\377\377\377\377\000\000\000\377\000\000\000\000"; table.size = 12; gs_cspace_build_Indexed(&pcs, rgb_cs, 4, &table, mem); ptile.data = pdata; ptile.raster = 4; ptile.size.x = ptile.size.y = 16; ptile.id = gs_no_bitmap_id; ptile.pix_depth = 2; ptile.num_comps = 1; gs_makepixmappattern(&ccolor, &ptile, false /*mask */ , NULL /*pmat */ , gs_no_id, pcs, 0 /*white_index */ , pgs, mem); { gs_rect r; r.p.x = 100; r.p.y = 100; r.q.x = 200; r.q.y = 200; gs_setrgbcolor(pgs, 1.0, 1.0, 0.0); gs_rectfill(pgs, &r, 1); gs_setpattern(pgs, &ccolor); gs_settexturetransparent(pgs, true); gs_rectfill(pgs, &r, 1); r.p.x += 150; r.q.x += 150; gs_setrgbcolor(pgs, 1.0, 1.0, 0.0); gs_rectfill(pgs, &r, 1); gs_setpattern(pgs, &ccolor); gs_settexturetransparent(pgs, false); gs_rectfill(pgs, &r, 1); } gs_free_object(mem, rgb_cs, "test8 rgb_cs"); return 0; }
/* Set up the color space information for a bitmap image or pattern. */ int px_image_color_space(gs_image_t *pim, const px_bitmap_params_t *params, const gs_string *palette, const gs_state *pgs) { int depth = params->depth; gs_color_space *pbase_pcs = NULL; gs_color_space *pcs = NULL; bool cie_space = false; int code = 0; switch ( params->color_space ) { case eGray: pbase_pcs = gs_cspace_new_DeviceGray(pgs->memory); pbase_pcs->cmm_icc_profile_data = pgs->icc_manager->default_gray; pbase_pcs->type = &gs_color_space_type_ICC; rc_increment(pbase_pcs->cmm_icc_profile_data); break; case eRGB: pbase_pcs = gs_cspace_new_DeviceRGB(pgs->memory); pbase_pcs->cmm_icc_profile_data = pgs->icc_manager->default_rgb; pbase_pcs->type = &gs_color_space_type_ICC; rc_increment(pbase_pcs->cmm_icc_profile_data); break; case eSRGB: case eCRGB: if ( pl_cspace_init_SRGB(&pbase_pcs, pgs) < 0 ) /* should not happen */ return_error(errorInsufficientMemory); cie_space = true; pbase_pcs->cmm_icc_profile_data = pgs->icc_manager->default_rgb; pbase_pcs->type = &gs_color_space_type_ICC; rc_increment(pbase_pcs->cmm_icc_profile_data); break; default: return_error(errorIllegalAttributeValue); } if (pbase_pcs == NULL) return_error(errorInsufficientMemory); if ( params->indexed ) { pcs = gs_cspace_alloc(pgs->memory, &gs_color_space_type_Indexed); if ( pcs == NULL ) { /* free the base space also */ rc_decrement(pbase_pcs, "px_image_color_space"); return_error(errorInsufficientMemory); } pcs->base_space = pbase_pcs; pcs->params.indexed.hival = (1 << depth) - 1; pcs->params.indexed.lookup.table.size = palette->size; { uint n = palette->size; byte *p = gs_alloc_string(pgs->memory, n, "px_image_color_space(palette)"); if ( p == 0 ) { rc_decrement(pbase_pcs, "px_image_color_space"); return_error(errorInsufficientMemory); } memcpy(p, palette->data, n); pcs->params.indexed.lookup.table.data = p; } pcs->params.indexed.use_proc = 0; } else { pcs = pbase_pcs; } gs_image_t_init(pim, pcs); pim->ColorSpace = pcs; pim->BitsPerComponent = depth; if ( params->indexed ) pim->Decode[1] = (1 << depth) - 1; /* NB - this needs investigation */ if (cie_space && !px_is_currentcolor_pattern(pgs)) { code = pl_setSRGBcolor((gs_state *)pgs, 0.0, 0.0, 0.0); } return code; }