static int z_imscale_d(i_ctx_t * i_ctx_p) { os_ptr op = osp; /* i_ctx_p->op_stack.stack.p defined in osstack.h */ int width, height; stream_imscale_state state; /* extract the key from the parameter dictionary */ check_type(*op, t_dictionary); check_dict_read(*op); if (dict_int_param(op, "Width", 0, 1<<24, -1, &width) < 0) return_error(gs_error_rangecheck); if (dict_int_param(op, "Height", 0, 1<<24, -1, &height) < 0) return_error(gs_error_rangecheck); state.params.spp_decode = 1; state.params.spp_interp = 1; state.params.BitsPerComponentIn = 1; state.params.MaxValueIn = 1; state.params.WidthIn = width; state.params.HeightIn = height; state.params.BitsPerComponentOut = 1; state.params.MaxValueOut = 1; state.params.WidthOut = width << 2; state.params.HeightOut = height << 2; /* we pass npop=0, since we've no arguments left to consume */ /* we pass 0 instead of the usual rspace(sop) will allocate storage for filter state from the same memory pool as the stream it's coding. this causes no trouble because we maintain no pointers */ return filter_read(i_ctx_p, 0, &s_imscale_template, (stream_state *) & state, 0); }
/* <dict> begin - */ int zbegin(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_type(*op, t_dictionary); check_dict_read(*op); if ( dsp == dstop ) { int code = ref_stack_extend(&d_stack, 1); if ( code < 0 ) { if (code == e_dictstackoverflow) { /* Adobe doesn't restore the operand that caused stack */ /* overflow. We do the same to match CET 20-02-02 */ pop(1); } return code; } } ++dsp; ref_assign(dsp, op); dict_set_top(); pop(1); return 0; }
/* <key> load <value> */ static int zload(i_ctx_t *i_ctx_p) { os_ptr op = osp; ref *pvalue; switch (r_type(op)) { case t_name: /* Use the fast lookup. */ if ((pvalue = dict_find_name(op)) == 0) return_error(e_undefined); ref_assign(op, pvalue); return 0; case t_null: return_error(e_typecheck); case t__invalid: return_error(e_stackunderflow); default: { /* Use an explicit loop. */ uint size = ref_stack_count(&d_stack); uint i; for (i = 0; i < size; i++) { ref *dp = ref_stack_index(&d_stack, i); check_dict_read(*dp); if (dict_find(dp, op, &pvalue) > 0) { ref_assign(op, pvalue); return 0; } } return_error(e_undefined); } } }
/* <local_dict|null> .setpagedevice - */ static int zsetpagedevice(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code; /****** if ( igs->in_cachedevice ) return_error(e_undefined); ******/ if (r_has_type(op, t_dictionary)) { check_dict_read(*op); #if 0 /****************/ /* * In order to avoid invalidaccess errors on setpagedevice, * the dictionary must be allocated in local VM. */ if (!(r_is_local(op))) return_error(e_invalidaccess); #endif /****************/ /* Make the dictionary read-only. */ code = zreadonly(i_ctx_p); if (code < 0) return code; } else { check_type(*op, t_null); } istate->pagedevice = *op; pop(1); return 0; }
/* <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); }
static int z_aes_d(i_ctx_t * i_ctx_p) { os_ptr op = osp; /* i_ctx_p->op_stack.stack.p defined in osstack.h */ ref *sop = NULL; stream_aes_state state; int use_padding; /* extract the key from the parameter dictionary */ check_type(*op, t_dictionary); check_dict_read(*op); if (dict_find_string(op, "Key", &sop) <= 0) return_error(gs_error_rangecheck); s_aes_set_key(&state, sop->value.const_bytes, r_size(sop)); /* extract the padding flag, which defaults to true for compatibility */ if (dict_bool_param(op, "Padding", 1, &use_padding) < 0) return_error(gs_error_rangecheck); s_aes_set_padding(&state, use_padding); /* we pass npop=0, since we've no arguments left to consume */ /* FIXME: passing 0 instead of the usual rspace(sop) will allocate storage for filter state from the same memory pool as the stream it's coding. this caused no trouble when we were the arcfour cipher and maintained no pointers. */ return filter_read(i_ctx_p, 0, &s_aes_template, (stream_state *) & state, 0); }
/* <key> where false */ int zwhere(i_ctx_t *i_ctx_p) { os_ptr op = osp; ref_stack_enum_t rsenum; check_op(1); ref_stack_enum_begin(&rsenum, &d_stack); do { const ref *const bot = rsenum.ptr; const ref *pdref = bot + rsenum.size; ref *pvalue; int code; while (pdref-- > bot) { check_dict_read(*pdref); code = dict_find(pdref, op, &pvalue); if (code < 0 && code != e_dictfull) return code; if (code > 0) { push(1); ref_assign(op - 1, pdref); make_true(op); return 0; } } } while (ref_stack_enum_next(&rsenum)); make_false(op); return 0; }
/* Only the type of *op has been checked. */ int zcopy_dict(i_ctx_t *i_ctx_p) { os_ptr op = osp; os_ptr op1 = op - 1; int code; check_type(*op1, t_dictionary); check_dict_read(*op1); check_dict_write(*op); if (!imemory->gs_lib_ctx->dict_auto_expand && (dict_length(op) != 0 || dict_maxlength(op) < dict_length(op1)) ) return_error(e_rangecheck); code = idict_copy(op1, op); if (code < 0) return code; /* * In Level 1 systems, we must copy the access attributes too. * The only possible effect this can have is to make the * copy read-only if the original dictionary is read-only. */ if (!level2_enabled) r_copy_attrs(dict_access_ref(op), a_write, dict_access_ref(op1)); ref_assign(op1, op); pop(1); return 0; }
/* <array|dict|name|packedarray|string> length <int> */ static int zlength(i_ctx_t *i_ctx_p) { os_ptr op = osp; switch (r_type(op)) { case t_array: case t_string: case t_mixedarray: case t_shortarray: check_read(*op); make_int(op, r_size(op)); return 0; case t_dictionary: check_dict_read(*op); make_int(op, dict_length(op)); return 0; case t_name: { ref str; name_string_ref(imemory, op, &str); make_int(op, r_size(&str)); return 0; } case t_astruct: if (gs_object_type(imemory, op->value.pstruct) != &st_bytes) return_error(e_typecheck); check_read(*op); make_int(op, gs_object_size(imemory, op->value.pstruct)); return 0; default: return_op_typecheck(op); } }
/* <source> <dict> /JBIG2Decode <file> */ static int z_jbig2decode(i_ctx_t * i_ctx_p) { os_ptr op = osp; ref *sop = NULL; s_jbig2_global_data_t *gref; stream_jbig2decode_state state; /* Extract the global context reference, if any, from the parameter dictionary and embed it in our stream state. The original object ref is under the JBIG2Globals key. We expect the postscript code to resolve this and call z_jbig2makeglobalctx() below to create an astruct wrapping the global decoder data and store it under the .jbig2globalctx key */ s_jbig2decode_set_global_data((stream_state*)&state, NULL); if (r_has_type(op, t_dictionary)) { check_dict_read(*op); if ( dict_find_string(op, ".jbig2globalctx", &sop) > 0) { gref = r_ptr(sop, s_jbig2_global_data_t); s_jbig2decode_set_global_data((stream_state*)&state, gref); } } /* we pass npop=0, since we've no arguments left to consume */ return filter_read(i_ctx_p, 0, &s_jbig2decode_template, (stream_state *) & state, (sop ? r_space(sop) : 0)); }
/* <pattern> <matrix> <shading> .buildshadingpattern <pattern> <instance> */ static int zbuildshadingpattern(i_ctx_t *i_ctx_p) { os_ptr op = osp; os_ptr op2 = op - 2; gs_matrix mat; gs_pattern2_template_t templat; int_pattern *pdata; gs_client_color cc_instance; int code; check_type(*op2, t_dictionary); check_dict_read(*op2); gs_pattern2_init(&templat); if ((code = read_matrix(imemory, op - 1, &mat)) < 0 || (code = dict_uid_param(op2, &templat.uid, 1, imemory, i_ctx_p)) != 1 || (code = shading_param(op, &templat.Shading)) < 0 || (code = int_pattern_alloc(&pdata, op2, imemory)) < 0 ) return_error((code < 0 ? code : gs_error_rangecheck)); templat.client_data = pdata; code = gs_make_pattern(&cc_instance, (const gs_pattern_template_t *)&templat, &mat, igs, imemory); if (code < 0) { ifree_object(pdata, "int_pattern"); return code; } make_istruct(op - 1, a_readonly, cc_instance.pattern); pop(1); return code; }
/* <dict> maxlength <int> */ static int zmaxlength(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_type(*op, t_dictionary); check_dict_read(*op); make_int(op, dict_maxlength(op)); return 0; }
/* <dict> .image3 - */ private int zimage3(i_ctx_t *i_ctx_p) { os_ptr op = osp; gs_image3_t image; int interleave_type; ref *pDataDict; ref *pMaskDict; image_params ip_data, ip_mask; int ignored; int code, mcode; check_type(*op, t_dictionary); check_dict_read(*op); if ((code = dict_int_param(op, "InterleaveType", 1, 3, -1, &interleave_type)) < 0 ) return code; gs_image3_t_init(&image, NULL, interleave_type); if (dict_find_string(op, "DataDict", &pDataDict) <= 0 || dict_find_string(op, "MaskDict", &pMaskDict) <= 0 ) return_error(e_rangecheck); if ((code = pixel_image_params(i_ctx_p, pDataDict, (gs_pixel_image_t *)&image, &ip_data, 12, false)) < 0 || (mcode = code = data_image_params(imemory, pMaskDict, &image.MaskDict, &ip_mask, false, 1, 12, false)) < 0 || (code = dict_int_param(pDataDict, "ImageType", 1, 1, 0, &ignored)) < 0 || (code = dict_int_param(pMaskDict, "ImageType", 1, 1, 0, &ignored)) < 0 ) return code; /* * MaskDict must have a DataSource iff InterleaveType == 3. */ if ((ip_data.MultipleDataSources && interleave_type != 3) || ip_mask.MultipleDataSources || mcode != (image.InterleaveType != 3) ) return_error(e_rangecheck); if (image.InterleaveType == 3) { /* Insert the mask DataSource before the data DataSources. */ memmove(&ip_data.DataSource[1], &ip_data.DataSource[0], (countof(ip_data.DataSource) - 1) * sizeof(ip_data.DataSource[0])); ip_data.DataSource[0] = ip_mask.DataSource[0]; } return zimage_setup(i_ctx_p, (gs_pixel_image_t *)&image, &ip_data.DataSource[0], image.CombineWithColor, 1); }
/* <target> <dict> CCITTFaxEncode/filter <file> */ static int zCFE(i_ctx_t *i_ctx_p) { os_ptr op = osp; stream_CFE_state cfs; int code; check_type(*op, t_dictionary); check_dict_read(*op); code = zcf_setup(op, (stream_CF_state *)&cfs, iimemory); if (code < 0) return code; return filter_write(i_ctx_p, 0, &s_CFE_template, (stream_state *)&cfs, 0); }
/* <target> <dict> BWBlockSortEncode/filter <file> */ static int zBWBSE(i_ctx_t *i_ctx_p) { os_ptr op = osp; stream_BWBSE_state bwbss; int code; check_type(*op, t_dictionary); check_dict_read(*op); code = bwbs_setup(op, (stream_BWBS_state *)&bwbss); if (code < 0) return code; return filter_write(op, 0, &s_BWBSE_template, (stream_state *)&bwbss, 0); }
static int zforall(i_ctx_t *i_ctx_p) { os_ptr op = osp; os_ptr obj = op - 1; es_ptr ep = esp; es_ptr cproc = ep + 4; check_estack(6); check_proc(*op); switch (r_type(obj)) { default: return_op_typecheck(obj); case t_array: check_read(*obj); make_op_estack(cproc, array_continue); break; case t_dictionary: check_dict_read(*obj); make_int(cproc, dict_first(obj)); ++cproc; make_op_estack(cproc, dict_continue); break; case t_string: check_read(*obj); make_op_estack(cproc, string_continue); break; case t_mixedarray: case t_shortarray: check_read(*obj); make_op_estack(cproc, packedarray_continue); break; } /* * Push: * - a mark; * - the composite object; * - the procedure; * - the iteration index (only for dictionaries, done above); * and invoke the continuation operator. */ make_mark_estack(ep + 1, es_for, forall_cleanup); ep[2] = *obj; ep[3] = *op; esp = cproc - 1; pop(2); return (*real_opproc(cproc))(i_ctx_p); }
/* <dict> <key> .knownget false */ static int zknownget(i_ctx_t *i_ctx_p) { os_ptr op = osp; register os_ptr op1 = op - 1; ref *pvalue; check_type(*op1, t_dictionary); check_dict_read(*op1); if (dict_find(op1, op, &pvalue) <= 0) { make_false(op1); pop(1); } else { ref_assign(op1, pvalue); make_true(op); } return 0; }
/* * Get the metrics for a character from the Metrics dictionary of a base * font. If present, store the l.s.b. in psbw[0,1] and the width in * psbw[2,3]. */ int /*metrics_present*/ zchar_get_metrics(const gs_font_base *pbfont, const ref *pcnref, float psbw[4]) { const ref *pfdict = &pfont_data(pbfont)->dict; ref *pmdict; if ( dict_find_string(pfdict, "Metrics", &pmdict) > 0 ) { ref *pmvalue; check_type_only(*pmdict, t_dictionary); check_dict_read(*pmdict); if ( dict_find(pmdict, pcnref, &pmvalue) > 0 ) { if ( num_params(pmvalue, 1, psbw + 2) >= 0 ) { /* <wx> only */ psbw[3] = 0; return metricsWidthOnly; } else { int code; check_read_type_only(*pmvalue, t_array); switch ( r_size(pmvalue) ) { case 2: /* [<sbx> <wx>] */ code = num_params(pmvalue->value.refs + 1, 2, psbw); psbw[2] = psbw[1]; psbw[1] = psbw[3] = 0; break; case 4: /* [<sbx> <sby> <wx> <wy>] */ code = num_params(pmvalue->value.refs + 3, 4, psbw); break; default: return_error(e_rangecheck); } if ( code < 0 ) return code; return metricsSideBearingAndWidth; } } } return metricsNone; }
/* Extract Width, Height, and TransferFunction from a dictionary. */ static int dict_threshold_common_params(const ref * pdict, gs_threshold_halftone_common * ptp, ref **pptstring, ref *ptproc) { int code; check_dict_read(*pdict); if ((code = dict_int_param(pdict, "Width", 1, 0x7fff, -1, &ptp->width)) < 0 || (code = dict_int_param(pdict, "Height", 1, 0x7fff, -1, &ptp->height)) < 0 || (code = dict_find_string(pdict, "Thresholds", pptstring)) <= 0 || (code = dict_proc_param(pdict, "TransferFunction", ptproc, false)) < 0 ) return (code < 0 ? code : e_undefined); ptp->transfer_closure.proc = 0; ptp->transfer_closure.data = 0; return code; }
int dict_param_list_read(dict_param_list * plist, const ref * pdict, const ref * ppolicies, bool require_all, gs_ref_memory_t *imem) { iparam_list *const iplist = (iparam_list *) plist; uint count; if (pdict == 0) { plist->u.r.read = empty_param_read; count = 0; } else { check_dict_read(*pdict); plist->u.r.read = dict_param_read; plist->dict = *pdict; count = dict_max_index(pdict) + 1; } plist->enumerate = dict_param_enumerate; return ref_param_read_init(iplist, count, ppolicies, require_all, imem); }
/* <dict> .fontbbox -false- */ static int zfontbbox(i_ctx_t *i_ctx_p) { os_ptr op = osp; double bbox[4]; int code; check_type(*op, t_dictionary); check_dict_read(*op); code = font_bbox_param(imemory, op, bbox); if (code < 0) return code; if (bbox[0] < bbox[2] && bbox[1] < bbox[3]) { push(4); make_reals(op - 4, bbox, 4); make_true(op); } else { /* No bbox, or an empty one. */ make_false(op); } return 0; }
/* * This operator is a special-purpose accelerator for use by 'restore' (see * gs_dps1.ps). Note that this operator does *not* require that dict2 be * writable. Hence it is in the same category of "dangerous" operators as * .forceput and .forceundef. */ static int zforcecopynew(i_ctx_t *i_ctx_p) { os_ptr op = osp; os_ptr op1 = op - 1; int code; check_type(*op1, t_dictionary); check_dict_read(*op1); check_type(*op, t_dictionary); /*check_dict_write(*op);*/ /* see above */ /* This is only recognized in Level 2 mode. */ if (!imemory->gs_lib_ctx->dict_auto_expand) return_error(e_undefined); code = idict_copy_new(op1, op); if (code < 0) return code; ref_assign(op1, op); pop(1); return 0; }
/* <source> <dict> /JPXDecode <file> */ private int z_jpx_decode(i_ctx_t * i_ctx_p) { os_ptr op = osp; ref *sop = NULL; stream_jpxd_state state; state.jpx_memory = imemory->non_gc_memory; if (r_has_type(op, t_dictionary)) { check_dict_read(*op); if ( dict_find_string(op, "Colorspace", &sop) > 0) { dlprintf("found Colorspace parameter (NYI)\n"); } } /* we pass npop=0, since we've no arguments left to consume */ /* we pass 0 instead of the usual rspace(sop) which will allocate storage for filter state from the same memory pool as the stream it's coding. this causes no trouble because we maintain no pointers */ return filter_read(i_ctx_p, 0, &s_jpxd_template, (stream_state *) & state, 0); }
/* encode version of the filter */ static int z_arcfour_e(i_ctx_t * i_ctx_p) { os_ptr op = osp; /* i_ctx_p->op_stack.stack.p defined in osstack.h */ ref *sop = NULL; stream_arcfour_state state; /* extract the key from the parameter dictionary */ check_type(*op, t_dictionary); check_dict_read(*op); if (dict_find_string(op, "Key", &sop) <= 0) return_error(e_rangecheck); s_arcfour_set_key(&state, sop->value.const_bytes, r_size(sop)); /* we pass npop=0, since we've no arguments left to consume */ /* we pass 0 instead of the usual rspace(sop) will allocate storage for filter state from the same memory pool as the stream it's coding. this causes no trouble because we maintain no pointers */ return filter_write(i_ctx_p, 0, &s_arcfour_template, (stream_state *) & state, 0); }
/* from a dictionary. */ static int dict_spot_params(const ref * pdict, gs_spot_halftone * psp, ref * psproc, ref * ptproc) { int code; check_dict_read(*pdict); if ((code = dict_float_param(pdict, "Frequency", 0.0, &psp->screen.frequency)) != 0 || (code = dict_float_param(pdict, "Angle", 0.0, &psp->screen.angle)) != 0 || (code = dict_proc_param(pdict, "SpotFunction", psproc, false)) != 0 || (code = dict_bool_param(pdict, "AccurateScreens", gs_currentaccuratescreens(), &psp->accurate_screens)) < 0 || (code = dict_proc_param(pdict, "TransferFunction", ptproc, false)) < 0 ) return (code < 0 ? code : e_undefined); psp->transfer = (code > 0 ? (gs_mapping_proc) 0 : gs_mapped_transfer); psp->transfer_closure.proc = 0; psp->transfer_closure.data = 0; return 0; }
/* Get the vertical metrics for a character from Metrics2, if present. */ int zchar_get_metrics2(const gs_font_base * pbfont, const ref * pcnref, double pwv[4]) { const ref *pfdict = &pfont_data(gs_font_parent(pbfont))->dict; ref *pmdict; if (dict_find_string(pfdict, "Metrics2", &pmdict) > 0) { ref *pmvalue; check_type_only(*pmdict, t_dictionary); check_dict_read(*pmdict); if (dict_find(pmdict, pcnref, &pmvalue) > 0) { check_read_type_only(*pmvalue, t_array); if (r_size(pmvalue) == 4) { int code = num_params(pmvalue->value.refs + 3, 4, pwv); return (code < 0 ? code : metricsSideBearingAndWidth); } } } return metricsNone; }
/* <dict> <key> known <bool> */ static int zknown(i_ctx_t *i_ctx_p) { os_ptr op = osp; register os_ptr op1 = op - 1; ref *pvalue; int code; check_type(*op1, t_dictionary); check_dict_read(*op1); code = dict_find(op1, op, &pvalue); switch (code) { case e_dictfull: code = 0; case 0: case 1: break; default: return code; } make_bool(op1, code); pop(1); return 0; }
/* <dict> <key> get <obj> */ static int zget(i_ctx_t *i_ctx_p) { int code; os_ptr op = osp; os_ptr op1 = op - 1; ref *pvalue; switch (r_type(op1)) { case t_dictionary: check_dict_read(*op1); if (dict_find(op1, op, &pvalue) <= 0) return_error(e_undefined); op[-1] = *pvalue; break; case t_string: check_read(*op1); check_int_ltu(*op, r_size(op1)); make_int(op1, op1->value.bytes[(uint) op->value.intval]); break; case t_array: case t_mixedarray: case t_shortarray: check_type(*op, t_integer); check_read(*op1); code = array_get(imemory, op1, op->value.intval, op1); if (code < 0) return code; break; case t__invalid: return_error(e_stackunderflow); default: return_error(e_typecheck); } pop(1); return 0; }
static int zsethalftone5(i_ctx_t *i_ctx_p) { os_ptr op = osp; uint count; gs_halftone_component *phtc; gs_halftone_component *pc; int code = 0; int j; gs_halftone *pht; gx_device_halftone *pdht; ref sprocs[GS_CLIENT_COLOR_MAX_COMPONENTS + 1]; ref tprocs[GS_CLIENT_COLOR_MAX_COMPONENTS + 1]; gs_memory_t *mem; uint edepth = ref_stack_count(&e_stack); int npop = 2; int dict_enum = dict_first(op); ref rvalue[2]; int cname, colorant_number; byte * pname; uint name_size; int halftonetype, type = 0; gs_state *pgs = igs; int space_index = r_space_index(op - 1); mem = (gs_memory_t *) idmemory->spaces_indexed[space_index]; check_type(*op, t_dictionary); check_dict_read(*op); check_type(op[-1], t_dictionary); check_dict_read(op[-1]); /* * We think that Type 2 and Type 4 halftones, like * screens set by setcolorscreen, adapt automatically to * the device color space, so we need to mark them * with a different internal halftone type. */ dict_int_param(op - 1, "HalftoneType", 1, 5, 0, &type); halftonetype = (type == 2 || type == 4) ? ht_type_multiple_colorscreen : ht_type_multiple; /* Count how many components that we will actually use. */ for (count = 0; ;) { bool have_default = false; /* Move to next element in the dictionary */ if ((dict_enum = dict_next(op, dict_enum, rvalue)) == -1) break; /* * Verify that we have a valid component. We may have a * /HalfToneType entry. */ if (!r_has_type(&rvalue[1], t_dictionary)) continue; /* Get the name of the component verify that we will use it. */ cname = name_index(mem, &rvalue[0]); code = gs_get_colorname_string(mem, cname, &pname, &name_size); if (code < 0) break; colorant_number = gs_cname_to_colorant_number(pgs, pname, name_size, halftonetype); if (colorant_number < 0) continue; else if (colorant_number == GX_DEVICE_COLOR_MAX_COMPONENTS) { /* If here then we have the "Default" component */ if (have_default) return_error(e_rangecheck); have_default = true; } count++; /* * Check to see if we have already reached the legal number of * components. */ if (count > GS_CLIENT_COLOR_MAX_COMPONENTS + 1) { code = gs_note_error(e_rangecheck); break; } } check_estack(5); /* for sampling Type 1 screens */ refset_null(sprocs, count); refset_null(tprocs, count); rc_alloc_struct_0(pht, gs_halftone, &st_halftone, imemory, pht = 0, ".sethalftone5"); phtc = gs_alloc_struct_array(mem, count, gs_halftone_component, &st_ht_component_element, ".sethalftone5"); rc_alloc_struct_0(pdht, gx_device_halftone, &st_device_halftone, imemory, pdht = 0, ".sethalftone5"); if (pht == 0 || phtc == 0 || pdht == 0) { j = 0; /* Quiet the compiler: gs_note_error isn't necessarily identity, so j could be left ununitialized. */ code = gs_note_error(e_VMerror); } else { dict_enum = dict_first(op); for (j = 0, pc = phtc; ;) { int type; /* Move to next element in the dictionary */ if ((dict_enum = dict_next(op, dict_enum, rvalue)) == -1) break; /* * Verify that we have a valid component. We may have a * /HalfToneType entry. */ if (!r_has_type(&rvalue[1], t_dictionary)) continue; /* Get the name of the component */ cname = name_index(mem, &rvalue[0]); code = gs_get_colorname_string(mem, cname, &pname, &name_size); if (code < 0) break; colorant_number = gs_cname_to_colorant_number(pgs, pname, name_size, halftonetype); if (colorant_number < 0) continue; /* Do not use this component */ pc->cname = cname; pc->comp_number = colorant_number; /* Now process the component dictionary */ check_dict_read(rvalue[1]); if (dict_int_param(&rvalue[1], "HalftoneType", 1, 7, 0, &type) < 0) { code = gs_note_error(e_typecheck); break; } switch (type) { default: code = gs_note_error(e_rangecheck); break; case 1: code = dict_spot_params(&rvalue[1], &pc->params.spot, sprocs + j, tprocs + j); pc->params.spot.screen.spot_function = spot1_dummy; pc->type = ht_type_spot; break; case 3: code = dict_threshold_params(&rvalue[1], &pc->params.threshold, tprocs + j); pc->type = ht_type_threshold; break; case 7: code = dict_threshold2_params(&rvalue[1], &pc->params.threshold2, tprocs + j, imemory); pc->type = ht_type_threshold2; break; } if (code < 0) break; pc++; j++; } } if (code >= 0) { pht->type = halftonetype; pht->params.multiple.components = phtc; pht->params.multiple.num_comp = j; pht->params.multiple.get_colorname_string = gs_get_colorname_string; code = gs_sethalftone_prepare(igs, pht, pdht); } if (code >= 0) { /* * Put the actual frequency and angle in the spot function component dictionaries. */ dict_enum = dict_first(op); for (pc = phtc; ; ) { /* Move to next element in the dictionary */ if ((dict_enum = dict_next(op, dict_enum, rvalue)) == -1) break; /* Verify that we have a valid component */ if (!r_has_type(&rvalue[1], t_dictionary)) continue; /* Get the name of the component and verify that we will use it. */ cname = name_index(mem, &rvalue[0]); code = gs_get_colorname_string(mem, cname, &pname, &name_size); if (code < 0) break; colorant_number = gs_cname_to_colorant_number(pgs, pname, name_size, halftonetype); if (colorant_number < 0) continue; if (pc->type == ht_type_spot) { code = dict_spot_results(i_ctx_p, &rvalue[1], &pc->params.spot); if (code < 0) break; } pc++; } } if (code >= 0) { /* * Schedule the sampling of any Type 1 screens, * and any (Type 1 or Type 3) TransferFunctions. * Save the stack depths in case we have to back out. */ uint odepth = ref_stack_count(&o_stack); ref odict, odict5; odict = op[-1]; odict5 = *op; pop(2); op = osp; esp += 5; make_mark_estack(esp - 4, es_other, sethalftone_cleanup); esp[-3] = odict; make_istruct(esp - 2, 0, pht); make_istruct(esp - 1, 0, pdht); make_op_estack(esp, sethalftone_finish); for (j = 0; j < count; j++) { gx_ht_order *porder = NULL; if (pdht->components == 0) porder = &pdht->order; else { /* Find the component in pdht that matches component j in the pht; gs_sethalftone_prepare() may permute these. */ int k; int comp_number = phtc[j].comp_number; for (k = 0; k < count; k++) { if (pdht->components[k].comp_number == comp_number) { porder = &pdht->components[k].corder; break; } } } switch (phtc[j].type) { case ht_type_spot: code = zscreen_enum_init(i_ctx_p, porder, &phtc[j].params.spot.screen, &sprocs[j], 0, 0, space_index); if (code < 0) break; /* falls through */ case ht_type_threshold: if (!r_has_type(tprocs + j, t__invalid)) { /* Schedule TransferFunction sampling. */ /****** check_xstack IS WRONG ******/ check_ostack(zcolor_remap_one_ostack); check_estack(zcolor_remap_one_estack); code = zcolor_remap_one(i_ctx_p, tprocs + j, porder->transfer, igs, zcolor_remap_one_finish); op = osp; } break; default: /* not possible here, but to keep */ /* the compilers happy.... */ ; } if (code < 0) { /* Restore the stack. */ ref_stack_pop_to(&o_stack, odepth); ref_stack_pop_to(&e_stack, edepth); op = osp; op[-1] = odict; *op = odict5; break; } npop = 0; } } if (code < 0) { gs_free_object(mem, pdht, ".sethalftone5"); gs_free_object(mem, phtc, ".sethalftone5"); gs_free_object(mem, pht, ".sethalftone5"); return code; } pop(npop); return (ref_stack_count(&e_stack) > edepth ? o_push_estack : 0); }
/* <source> <dict> /JPXDecode <file> */ static int z_jpx_decode(i_ctx_t * i_ctx_p) { os_ptr op = osp; ref *sop = NULL; ref *csname = NULL; stream_jpxd_state state; /* it's our responsibility to call set_defaults() */ state.memory = imemory->non_gc_memory; if (s_jpxd_template.set_defaults) (*s_jpxd_template.set_defaults)((stream_state *)&state); if (r_has_type(op, t_dictionary)) { check_dict_read(*op); if ( dict_find_string(op, "Alpha", &sop) > 0) { check_type(*sop, t_boolean); if (sop->value.boolval) state.alpha = true; } if ( dict_find_string(op, "ColorSpace", &sop) > 0) { /* parse the value */ if (r_is_array(sop)) { /* assume it's the first array element */ csname = sop->value.refs; } else if (r_has_type(sop,t_name)) { /* use the name directly */ csname = sop; } else { dmprintf(imemory, "warning: JPX ColorSpace value is an unhandled type!\n"); } if (csname != NULL) { ref sref; /* get a reference to the name's string value */ name_string_ref(imemory, csname, &sref); /* request raw index values if the colorspace is /Indexed */ if (!ISTRCMP(&sref, "Indexed")) state.colorspace = gs_jpx_cs_indexed; /* tell the filter what output we want for other spaces */ else if (!ISTRCMP(&sref, "DeviceGray")) state.colorspace = gs_jpx_cs_gray; else if (!ISTRCMP(&sref, "DeviceRGB")) state.colorspace = gs_jpx_cs_rgb; else if (!ISTRCMP(&sref, "DeviceCMYK")) state.colorspace = gs_jpx_cs_cmyk; else if (!ISTRCMP(&sref, "ICCBased")) { /* The second array element should be the profile's stream dict */ ref *csdict = sop->value.refs + 1; ref *nref; ref altname; if (r_is_array(sop) && (r_size(sop) > 1) && r_has_type(csdict, t_dictionary)) { check_dict_read(*csdict); /* try to look up the alternate space */ if (dict_find_string(csdict, "Alternate", &nref) > 0) { name_string_ref(imemory, csname, &altname); if (!ISTRCMP(&altname, "DeviceGray")) state.colorspace = gs_jpx_cs_gray; else if (!ISTRCMP(&altname, "DeviceRGB")) state.colorspace = gs_jpx_cs_rgb; else if (!ISTRCMP(&altname, "DeviceCMYK")) state.colorspace = gs_jpx_cs_cmyk; } /* else guess based on the number of components */ if (state.colorspace == gs_jpx_cs_unset && dict_find_string(csdict, "N", &nref) > 0) { if_debug1m('w', imemory, "[w] JPX image has an external %"PRIpsint " channel colorspace\n", nref->value.intval); switch (nref->value.intval) { case 1: state.colorspace = gs_jpx_cs_gray; break; case 3: state.colorspace = gs_jpx_cs_rgb; break; case 4: state.colorspace = gs_jpx_cs_cmyk; break; } } } } } else { if_debug0m('w', imemory, "[w] Couldn't read JPX ColorSpace key!\n"); } } } /* we pass npop=0, since we've no arguments left to consume */ /* we pass 0 instead of the usual rspace(sop) which will allocate storage for filter state from the same memory pool as the stream it's coding. this causes no trouble because we maintain no pointers */ return filter_read(i_ctx_p, 0, &s_jpxd_template, (stream_state *) & state, 0); }