/* Remap=0 is used by the interpreter. */ int gs_setcolortransfer_remap(gs_gstate * pgs, gs_mapping_proc red_proc, gs_mapping_proc green_proc, gs_mapping_proc blue_proc, gs_mapping_proc gray_proc, bool remap) { gx_transfer *ptran = &pgs->set_transfer; gx_transfer old; gs_id new_ids = gs_next_ids(pgs->memory, 4); gx_device * dev = pgs->device; old = *ptran; rc_unshare_struct(ptran->gray, gx_transfer_map, &st_transfer_map, pgs->memory, goto fgray, "gs_setcolortransfer"); rc_unshare_struct(ptran->red, gx_transfer_map, &st_transfer_map, pgs->memory, goto fred, "gs_setcolortransfer"); rc_unshare_struct(ptran->green, gx_transfer_map, &st_transfer_map, pgs->memory, goto fgreen, "gs_setcolortransfer"); rc_unshare_struct(ptran->blue, gx_transfer_map, &st_transfer_map, pgs->memory, goto fblue, "gs_setcolortransfer"); ptran->gray->proc = gray_proc; ptran->gray->id = new_ids; ptran->red->proc = red_proc; ptran->red->id = new_ids + 1; ptran->green->proc = green_proc; ptran->green->id = new_ids + 2; ptran->blue->proc = blue_proc; ptran->blue->id = new_ids + 3; ptran->red_component_num = gs_color_name_component_number(dev, "Red", 3, ht_type_colorscreen); ptran->green_component_num = gs_color_name_component_number(dev, "Green", 5, ht_type_colorscreen); ptran->blue_component_num = gs_color_name_component_number(dev, "Blue", 4, ht_type_colorscreen); ptran->gray_component_num = gs_color_name_component_number(dev, "Gray", 4, ht_type_colorscreen); if (remap) { load_transfer_map(pgs, ptran->red, 0.0); load_transfer_map(pgs, ptran->green, 0.0); load_transfer_map(pgs, ptran->blue, 0.0); load_transfer_map(pgs, ptran->gray, 0.0); gx_set_effective_transfer(pgs); gx_unset_dev_color(pgs); } else gx_set_effective_transfer(pgs); return 0; fblue: rc_assign(ptran->green, old.green, "setcolortransfer"); fgreen: rc_assign(ptran->red, old.red, "setcolortransfer"); fred: rc_assign(ptran->gray, old.gray, "setcolortransfer"); fgray: return_error(gs_error_VMerror); }
/* Set the target of a forwarding device. */ void gx_device_set_target(gx_device_forward *fdev, gx_device *target) { /* * ****** HACK: if this device doesn't have special finalization yet, * make it decrement the reference count of the target. */ if (target && !fdev->finalize) fdev->finalize = gx_device_forward_finalize; rc_assign(fdev->target, target, "gx_device_set_target"); }
/* Set the target of a forwarding device. */ void gx_device_set_target(gx_device_forward *fdev, gx_device *target) { /* * ****** HACK: if this device doesn't have special finalization yet, * make it decrement the reference count of the target. */ if (target && !fdev->finalize) fdev->finalize = gx_device_forward_finalize; rc_assign(fdev->target, target, "gx_device_set_target"); fdev->graphics_type_tag = target != NULL ? target->graphics_type_tag : 0; /* initialize to same as target */ }
/* Remap=0 is used by the interpreter. */ int gs_setcolortransfer_remap(gs_state *pgs, gs_mapping_proc red_proc, gs_mapping_proc green_proc, gs_mapping_proc blue_proc, gs_mapping_proc gray_proc, bool remap) { gx_transfer_colored *ptran = &pgs->set_transfer.colored; gx_transfer_colored old; gs_id new_ids = gs_next_ids(4); old = *ptran; rc_unshare_struct(ptran->gray, gx_transfer_map, &st_transfer_map, pgs->memory, goto fgray, "gs_setcolortransfer"); rc_unshare_struct(ptran->red, gx_transfer_map, &st_transfer_map, pgs->memory, goto fred, "gs_setcolortransfer"); rc_unshare_struct(ptran->green, gx_transfer_map, &st_transfer_map, pgs->memory, goto fgreen, "gs_setcolortransfer"); rc_unshare_struct(ptran->blue, gx_transfer_map, &st_transfer_map, pgs->memory, goto fblue, "gs_setcolortransfer"); ptran->gray->proc = gray_proc; ptran->gray->id = new_ids; ptran->red->proc = red_proc; ptran->red->id = new_ids + 1; ptran->green->proc = green_proc; ptran->green->id = new_ids + 2; ptran->blue->proc = blue_proc; ptran->blue->id = new_ids + 3; if ( remap ) { load_transfer_map(pgs, ptran->red, 0.0); load_transfer_map(pgs, ptran->green, 0.0); load_transfer_map(pgs, ptran->blue, 0.0); load_transfer_map(pgs, ptran->gray, 0.0); gx_set_effective_transfer(pgs); gx_unset_dev_color(pgs); } return 0; fblue: rc_assign(ptran->green, old.green, "setcolortransfer"); fgreen: rc_assign(ptran->red, old.red, "setcolortransfer"); fred: rc_assign(ptran->gray, old.gray, "setcolortransfer"); fgray: return_error(gs_error_VMerror); }
static int bbox_text_begin(gx_device * dev, gs_imager_state * pis, const gs_text_params_t * text, gs_font * font, gx_path * path, const gx_device_color * pdcolor, const gx_clip_path * pcpath, gs_memory_t * memory, gs_text_enum_t ** ppenum) { gx_device_bbox *const bdev = (gx_device_bbox *) dev; int code = gx_default_text_begin(dev, pis, text, font, path, pdcolor, pcpath, memory, ppenum); if (bdev->target != NULL) { /* See note on imaging_dev in gxtext.h */ rc_assign((*ppenum)->imaging_dev, dev, "bbox_text_begin"); } return code; }
/* Note that, to support PDF, ICCBased color spaces may be used to substitute * for the Device* color spaces (previously, only CIEBased color spaces could * be used for this purpose). */ int gs_setsubstitutecolorspace(gs_state *pgs, gs_color_space_index csi, const gs_color_space *pcs) { int index = (int)csi; static const uint masks[3] = { (1 << gs_color_space_index_DeviceGray) | (1 << gs_color_space_index_CIEA), (1 << gs_color_space_index_DeviceRGB) | (1 << gs_color_space_index_CIEABC) | (1 << gs_color_space_index_CIEDEF), (1 << gs_color_space_index_DeviceCMYK) | (1 << gs_color_space_index_CIEDEFG) }; const gs_color_space *pcs_old; if (index < 0 || index > 2) return_error(gs_error_rangecheck); if (pcs) { if (gs_color_space_get_index(pcs) == gs_color_space_index_CIEICC) { static const byte dev_ncomps[3] = {1, 3, 4}; if (dev_ncomps[index] != cs_num_components(pcs)) return_error(gs_error_rangecheck); } else if (!masks[index] && (1 << gs_color_space_get_index(pcs))) return_error(gs_error_rangecheck); } pcs_old = pgs->device_color_spaces.indexed[index]; if (pcs_old == 0 && (pcs == 0 || gs_color_space_get_index(pcs) == csi)) return 0; rc_assign(pgs->device_color_space.indexed[index], (pcs ? pcs : pgs->shared->device_color_spaces.indexed[index]), "gs_setsubstitutecolorspace"); return 0; }
/* * <dict> .set_outputintent - * * Set and use the specified output intent. * */ static int zset_outputintent(i_ctx_t * i_ctx_p) { os_ptr op = osp; int code = 0; gx_device *dev = gs_currentdevice(igs); gs_imager_state *pis = (gs_imager_state *)igs; cmm_dev_profile_t *dev_profile; stream * s = 0L; ref * pnval; ref * pstrmval; int ncomps, dev_comps; cmm_profile_t *picc_profile; int expected = 0; gs_color_space_index index; gsicc_manager_t *icc_manager = pis->icc_manager; cmm_profile_t *source_profile = NULL; check_type(*op, t_dictionary); check_dict_read(*op); if_debug0m(gs_debug_flag_icc, imemory, "[icc] Using OutputIntent\n"); /* Get the device structure */ code = dev_proc(dev, get_profile)(dev, &dev_profile); if (dev_profile == NULL) { code = gsicc_init_device_profile_struct(dev, NULL, 0); code = dev_proc(dev, get_profile)(dev, &dev_profile); } if (dev_profile->oi_profile != NULL) { return 0; /* Allow only one setting of this object */ } code = dict_find_string(op, "N", &pnval); if (code < 0) return code; ncomps = pnval->value.intval; /* verify the DataSource entry. Creat profile from stream */ if (dict_find_string(op, "DataSource", &pstrmval) <= 0) return_error(e_undefined); check_read_file(i_ctx_p, s, pstrmval); picc_profile = gsicc_profile_new(s, gs_state_memory(igs), NULL, 0); picc_profile->num_comps = ncomps; picc_profile->profile_handle = gsicc_get_profile_handle_buffer(picc_profile->buffer, picc_profile->buffer_size, gs_state_memory(igs)); if (picc_profile->profile_handle == NULL) { rc_decrement(picc_profile,"zset_outputintent"); return -1; } picc_profile->data_cs = gscms_get_profile_data_space(picc_profile->profile_handle); switch (picc_profile->data_cs) { case gsCIEXYZ: case gsCIELAB: case gsRGB: expected = 3; source_profile = icc_manager->default_rgb; break; case gsGRAY: expected = 1; source_profile = icc_manager->default_gray; break; case gsCMYK: expected = 4; source_profile = icc_manager->default_cmyk; break; case gsNCHANNEL: expected = 0; break; case gsNAMED: case gsUNDEFINED: break; } if (expected && ncomps != expected) { rc_decrement(picc_profile,"zset_outputintent"); return_error(e_rangecheck); } gsicc_init_hash_cs(picc_profile, pis); /* All is well with the profile. Lets set the stuff that needs to be set */ dev_profile->oi_profile = picc_profile; picc_profile->name = (char *) gs_alloc_bytes(picc_profile->memory, MAX_DEFAULT_ICC_LENGTH, "zset_outputintent"); strncpy(picc_profile->name, OI_PROFILE, strlen(OI_PROFILE)); picc_profile->name[strlen(OI_PROFILE)] = 0; picc_profile->name_length = strlen(OI_PROFILE); /* Set the range of the profile */ gscms_set_icc_range(&picc_profile); /* If the output device has a different number of componenets, then we are going to set the output intent as the proofing profile, unless the proofing profile has already been set. If the device has the same number of components (and color model) then as the profile we will use this as the output profile, unless someone has explicitly set the output profile. Finally, we will use the output intent profile for the default profile of the proper Device profile in the icc manager, again, unless someone has explicitly set this default profile. */ dev_comps = dev_profile->device_profile[0]->num_comps; index = gsicc_get_default_type(dev_profile->device_profile[0]); if (ncomps == dev_comps && index < gs_color_space_index_DevicePixel) { /* The OI profile is the same type as the profile for the device and a "default" profile for the device was not externally set. So we go ahead and use the OI profile as the device profile. Care needs to be taken here to keep from screwing up any device parameters. We will use a keyword of OIProfile for the user/device parameter to indicate its usage. Also, note conflicts if one is setting object dependent color management */ rc_assign(dev_profile->device_profile[0], picc_profile, "zset_outputintent"); if_debug0m(gs_debug_flag_icc, imemory, "[icc] OutputIntent used for device profile\n"); } else { if (dev_profile->proof_profile == NULL) { /* This means that we should use the OI profile as the proofing profile. Note that if someone already has specified a proofing profile it is unclear what they are trying to do with the output intent. In this case, we will use it just for the source data below */ dev_profile->proof_profile = picc_profile; rc_increment(picc_profile); if_debug0m(gs_debug_flag_icc, imemory, "[icc] OutputIntent used for proof profile\n"); } } /* Now the source colors. See which source color space needs to use the output intent ICC profile */ index = gsicc_get_default_type(source_profile); if (index < gs_color_space_index_DevicePixel) { /* source_profile is currently the default. Set it to the OI profile */ switch (picc_profile->data_cs) { case gsGRAY: if_debug0m(gs_debug_flag_icc, imemory, "[icc] OutputIntent used source Gray\n"); rc_assign(icc_manager->default_gray, picc_profile, "zset_outputintent"); break; case gsRGB: if_debug0m(gs_debug_flag_icc, imemory, "[icc] OutputIntent used source RGB\n"); rc_assign(icc_manager->default_rgb, picc_profile, "zset_outputintent"); break; case gsCMYK: if_debug0m(gs_debug_flag_icc, imemory, "[icc] OutputIntent used source CMYK\n"); rc_assign(icc_manager->default_cmyk, picc_profile, "zset_outputintent"); break; default: break; } } /* Remove the output intent dict from the stack */ pop(1); return code; }