/* * Scale an array of subsidiary functions. Note that the scale may either * be propagated unchanged (step_ranges = false) or divided among the * (1-output) subfunctions (step_ranges = true). */ static int fn_scale_functions(gs_function_t ***ppsfns, const gs_function_t *const *pfns, int count, const gs_range_t *pranges, bool step_ranges, gs_memory_t *mem) { gs_function_t **psfns; int code = alloc_function_array(count, &psfns, mem); const gs_range_t *ranges = pranges; int i; if (code < 0) return code; for (i = 0; i < count; ++i) { int code = gs_function_make_scaled(pfns[i], &psfns[i], ranges, mem); if (code < 0) { fn_free_functions((const gs_function_t *const *)psfns, count, mem); return code; } if (step_ranges) ++ranges; } *ppsfns = psfns; return 0; }
/* Collect a Function value. */ static int build_shading_function(i_ctx_t *i_ctx_p, const ref * op, gs_function_t ** ppfn, int num_inputs, gs_memory_t *mem, const float *shading_domain) { ref *pFunction; int code; *ppfn = 0; if (dict_find_string(op, "Function", &pFunction) <= 0) return 0; if (r_is_array(pFunction)) { uint size = r_size(pFunction); gs_function_t **Functions; uint i; gs_function_AdOt_params_t params; check_read(*pFunction); if (size == 0) return_error(gs_error_rangecheck); code = alloc_function_array(size, &Functions, mem); if (code < 0) return code; for (i = 0; i < size; ++i) { ref rsubfn; array_get(imemory, pFunction, (long)i, &rsubfn); code = fn_build_function(i_ctx_p, &rsubfn, &Functions[i], mem, shading_domain, num_inputs); if (code < 0) break; } params.m = num_inputs; params.Domain = 0; params.n = size; params.Range = 0; params.Functions = (const gs_function_t * const *)Functions; if (code >= 0) code = gs_function_AdOt_init(ppfn, ¶ms, mem); if (code < 0) gs_function_AdOt_free_params(¶ms, mem); } else { code = fn_build_function(i_ctx_p, pFunction, ppfn, mem, shading_domain, num_inputs); if (code < 0) return code; if ((*ppfn)->params.m != num_inputs) { gs_function_free(*ppfn, true, mem); return_error(gs_error_rangecheck); } } return code; }
/* 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; *(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); if (code < 0) goto fail; } } if ((code = fn_build_float_array(op, "Bounds", true, false, ¶ms.Bounds, mem)) != params.k - 1 || (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)); }
/* 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)); }