/* and return maxlen. */ int dict_float_array_check_param(const gs_memory_t *mem, const ref * pdict, const char *kstr, uint len, float *fvec, const float *defaultvec, int under_error, int over_error) { ref *pdval; uint size; int code; if (pdict == 0 || dict_find_string(pdict, kstr, &pdval) <= 0) { if (defaultvec == NULL) return 0; memcpy(fvec, defaultvec, len * sizeof(float)); return len; } if (!r_is_array(pdval)) return_error(e_typecheck); size = r_size(pdval); if (size > len) return_error(over_error); code = process_float_array(mem, pdval, size, fvec); return (code < 0 ? code : size == len || under_error >= 0 ? size : gs_note_error(under_error)); }
/* Calculate bonding box of a box transformed by a matrix. */ static int zbbox_transform(i_ctx_t *i_ctx_p) { os_ptr op = osp; gs_matrix m; float bbox[4]; gs_point aa, az, za, zz; double temp; int code; if ((code = read_matrix(imemory, op, &m)) < 0) return code; if (!r_is_array(op - 1)) return_op_typecheck(op - 1); check_read(op[-1]); if (r_size(op - 1) != 4) return_error(gs_error_rangecheck); if ((code = process_float_array(imemory, op - 1, 4, bbox) < 0)) return code; gs_point_transform(bbox[0], bbox[1], &m, &aa); gs_point_transform(bbox[0], bbox[3], &m, &az); gs_point_transform(bbox[2], bbox[1], &m, &za); gs_point_transform(bbox[2], bbox[3], &m, &zz); if ( aa.x > az.x) temp = aa.x, aa.x = az.x, az.x = temp; if ( za.x > zz.x) temp = za.x, za.x = zz.x, zz.x = temp; if ( za.x < aa.x) aa.x = za.x; /* min */ if ( az.x > zz.x) zz.x = az.x; /* max */ if ( aa.y > az.y) temp = aa.y, aa.y = az.y, az.y = temp; if ( za.y > zz.y) temp = za.y, za.y = zz.y, zz.y = temp; if ( za.y < aa.y) aa.y = za.y; /* min */ if ( az.y > zz.y) zz.y = az.y; /* max */ push(2); make_real(op - 3, (float)aa.x); make_real(op - 2, (float)aa.y); make_real(op - 1, (float)zz.x); make_real(op , (float)zz.y); return 0; }
/* Finish building a FunctionType 3 (1-Input Stitching) function. */ int gs_build_function_3(i_ctx_t *i_ctx_p, const ref *op, const gs_function_params_t * mnDR, int depth, gs_function_t ** ppfn, gs_memory_t *mem) { gs_function_1ItSg_params_t params; int code; extern bool CPSI_mode; *(gs_function_params_t *) & params = *mnDR; params.Functions = 0; params.Bounds = 0; params.Encode = 0; { ref *pFunctions; gs_function_t **ptr; int i; if ((code = dict_find_string(op, "Functions", &pFunctions)) <= 0) return (code < 0 ? code : gs_note_error(e_rangecheck)); check_array_only(*pFunctions); params.k = r_size(pFunctions); code = alloc_function_array(params.k, &ptr, mem); if (code < 0) return code; params.Functions = (const gs_function_t * const *)ptr; for (i = 0; i < params.k; ++i) { ref subfn; array_get(mem, pFunctions, (long)i, &subfn); code = fn_build_sub_function(i_ctx_p, &subfn, &ptr[i], depth, mem, 0, 0); if (code < 0) goto fail; } } if ((code = fn_build_float_array(op, "Bounds", true, false, ¶ms.Bounds, mem)) != params.k - 1) goto fail; if (CPSI_mode) { /* Adobe implementation doesn't check the Encode length. */ /* Extra elements are ignored; missing elements are filled with 0. */ /* CET 12-14m.ps depends on this bug */ uint sz, k2 = 2 * params.k; ref *encode; float *p = (float *)gs_alloc_byte_array(mem, k2, sizeof(float), "Encode"); params.Encode = p; if (p == 0) { code = gs_note_error(e_VMerror); goto fail; } if (dict_find_string(op, "Encode", &encode) <= 0) { code = gs_note_error(e_undefined); goto fail; } if (!r_is_array(encode)) { code = gs_note_error(e_typecheck); goto fail; } sz = min(k2, r_size(encode)); code = process_float_array(mem, encode, sz, p); if (code < 0) goto fail; while (sz < k2) p[sz++] = 0.0; } else if ((code = fn_build_float_array(op, "Encode", true, true, ¶ms.Encode, mem)) != 2 * params.k) goto fail; if (params.Range == 0) params.n = params.Functions[0]->params.n; code = gs_function_1ItSg_init(ppfn, ¶ms, mem); if (code >= 0) return 0; fail: gs_function_1ItSg_free_params(¶ms, mem); return (code < 0 ? code : gs_note_error(e_rangecheck)); }
/* Collect parameters for a mesh shading. */ static int build_mesh_shading(i_ctx_t *i_ctx_p, const ref * op, gs_shading_mesh_params_t * params, float **pDecode, gs_function_t ** pFunction, gs_memory_t *mem) { int code; float *data = 0; ref *pDataSource; *pDecode = 0; *pFunction = 0; if (dict_find_string(op, "DataSource", &pDataSource) <= 0) return_error(gs_error_rangecheck); if (r_is_array(pDataSource)) { uint size = r_size(pDataSource); data = (float *)gs_alloc_byte_array(mem, size, sizeof(float), "build_mesh_shading"); if (data == 0) return_error(gs_error_VMerror); code = process_float_array(mem, pDataSource, size, data); if (code < 0) { gs_free_object(mem, data, "build_mesh_shading"); return code; } data_source_init_floats(¶ms->DataSource, data, size); } else switch (r_type(pDataSource)) { case t_file: { stream *s; check_read_file(i_ctx_p, s, pDataSource); data_source_init_stream(¶ms->DataSource, s); break; } case t_string: check_read(*pDataSource); data_source_init_string2(¶ms->DataSource, pDataSource->value.bytes, r_size(pDataSource)); break; default: return_error(gs_error_typecheck); } code = build_shading_function(i_ctx_p, op, pFunction, 1, mem, NULL); if (code < 0) { gs_free_object(mem, data, "build_mesh_shading"); return code; } if (data_source_is_array(params->DataSource)) { params->BitsPerCoordinate = 0; params->BitsPerComponent = 0; } else { int num_decode = 4 + (*pFunction != 0 ? 1 : gs_color_space_num_components(params->ColorSpace)) * 2; if ((code = dict_int_param(op, "BitsPerCoordinate", 1, 32, 0, ¶ms->BitsPerCoordinate)) >= 0 && (code = dict_int_param(op, "BitsPerComponent", 1, 16, 0, ¶ms->BitsPerComponent)) >= 0 ) { *pDecode = (float *) gs_alloc_byte_array(mem, num_decode, sizeof(float), "build_mesh_shading"); if (*pDecode == 0) code = gs_note_error(gs_error_VMerror); else { code = dict_floats_param(mem, op, "Decode", num_decode, *pDecode, NULL); if (code < 0) { gs_free_object(mem, *pDecode, "build_mesh_shading"); *pDecode = 0; } } } } if (code < 0) { if (*pFunction != 0) { gs_function_free(*pFunction, true, mem); *pFunction = 0; } gs_free_object(mem, data, "build_mesh_shading"); } return code; }