1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/* Copyright (C) 2001-2012 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
implied.
This software is distributed under license and may not be copied,
modified or distributed except as expressly authorized under the terms
of the license contained in the file LICENSE in this distribution.
Refer to licensing information at http://www.artifex.com or contact
Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, San Rafael,
CA 94903, U.S.A., +1(415)492-9861, for further information.
*/
/* 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"
#include "igstate.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_forced(op, "C0", false, ¶ms.C0, mem)) < 0 ||
(code = n1 = fn_build_float_array_forced(op, "C1", 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(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 (gs_currentcpsimode(imemory)) {
/* 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));
}
|