/* Copyright (C) 1997, 1998, 1999 artofcode LLC. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA, 02111-1307. */ /*$Id: zfunc3.c,v 1.2.6.2.2.1 2003/01/17 00:49:06 giles Exp $ */ /* PostScript language interface to LL3 Functions */ #include "memory_.h" #include "ghost.h" #include "oper.h" #include "gsfunc3.h" #include "gsstruct.h" #include "stream.h" /* for files.h */ #include "files.h" #include "ialloc.h" #include "idict.h" #include "idparam.h" #include "ifunc.h" #include "store.h" /* Check prototypes */ build_function_proc(gs_build_function_2); build_function_proc(gs_build_function_3); /* Finish building a FunctionType 2 (ExponentialInterpolation) function. */ int gs_build_function_2(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_ElIn_params_t params; int code, n0, n1; *(gs_function_params_t *)¶ms = *mnDR; params.C0 = 0; params.C1 = 0; if ((code = dict_float_param(op, "N", 0.0, ¶ms.N)) != 0 || (code = n0 = fn_build_float_array(op, "C0", false, false, ¶ms.C0, mem)) < 0 || (code = n1 = fn_build_float_array(op, "C1", false, false, ¶ms.C1, mem)) < 0 ) goto fail; if (params.C0 == 0) n0 = 1; /* C0 defaulted */ if (params.C1 == 0) n1 = 1; /* C1 defaulted */ if (params.Range == 0) params.n = n0; /* either one will do */ if (n0 != n1 || n0 != params.n) goto fail; code = gs_function_ElIn_init(ppfn, ¶ms, mem); if (code >= 0) return 0; fail: gs_function_ElIn_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; *(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(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)); }