/src/ghostpdl/psi/zfunc0.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2023 Artifex Software, Inc. |
2 | | All Rights Reserved. |
3 | | |
4 | | This software is provided AS-IS with no warranty, either express or |
5 | | implied. |
6 | | |
7 | | This software is distributed under license and may not be copied, |
8 | | modified or distributed except as expressly authorized under the terms |
9 | | of the license contained in the file LICENSE in this distribution. |
10 | | |
11 | | Refer to licensing information at http://www.artifex.com or contact |
12 | | Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
13 | | CA 94129, USA, for further information. |
14 | | */ |
15 | | |
16 | | |
17 | | /* PostScript language interface to FunctionType 0 (Sampled) Functions */ |
18 | | #include "memory_.h" |
19 | | #include "ghost.h" |
20 | | #include "oper.h" |
21 | | #include "gsdsrc.h" |
22 | | #include "gsfunc.h" |
23 | | #include "gsfunc0.h" |
24 | | #include "stream.h" /* for files.h */ |
25 | | #include "files.h" |
26 | | #include "ialloc.h" |
27 | | #include "idict.h" |
28 | | #include "idparam.h" |
29 | | #include "ifunc.h" |
30 | | |
31 | | /* Check prototype */ |
32 | | build_function_proc(gs_build_function_0); |
33 | | |
34 | | /* Finish building a FunctionType 0 (Sampled) function. */ |
35 | | int |
36 | | gs_build_function_0(i_ctx_t *i_ctx_p, const ref *op, const gs_function_params_t * mnDR, |
37 | | int depth, gs_function_t ** ppfn, gs_memory_t *mem) |
38 | 0 | { |
39 | 0 | gs_function_Sd_params_t params; |
40 | 0 | ref *pDataSource; |
41 | 0 | int code; |
42 | |
|
43 | 0 | *(gs_function_params_t *) & params = *mnDR; |
44 | 0 | params.Encode = params.Decode = NULL; |
45 | 0 | params.pole = NULL; |
46 | 0 | params.Size = params.array_step = params.stream_step = NULL; |
47 | 0 | if ((code = dict_find_string(op, "DataSource", &pDataSource)) <= 0) |
48 | 0 | return (code < 0 ? code : gs_note_error(gs_error_rangecheck)); |
49 | 0 | switch (r_type(pDataSource)) { |
50 | 0 | case t_string: |
51 | 0 | data_source_init_string2(¶ms.DataSource, |
52 | 0 | pDataSource->value.const_bytes, |
53 | 0 | r_size(pDataSource)); |
54 | 0 | break; |
55 | 0 | case t_file: { |
56 | 0 | stream *s; |
57 | |
|
58 | 0 | check_read_known_file_else(s, pDataSource, return_error, |
59 | 0 | return_error(gs_error_invalidfileaccess)); |
60 | 0 | if (!(s->modes & s_mode_seek)) |
61 | 0 | return_error(gs_error_ioerror); |
62 | 0 | data_source_init_stream(¶ms.DataSource, s); |
63 | 0 | break; |
64 | 0 | } |
65 | 0 | default: |
66 | 0 | return_error(gs_error_rangecheck); |
67 | 0 | } |
68 | 0 | if ((code = dict_int_param(op, "Order", 1, 3, 1, ¶ms.Order)) < 0 || |
69 | 0 | (code = dict_int_param(op, "BitsPerSample", 1, 32, 0, |
70 | 0 | ¶ms.BitsPerSample)) < 0 || |
71 | 0 | ((code = fn_build_float_array(op, "Encode", false, true, ¶ms.Encode, mem)) != 2 * params.m && (code != 0 || params.Encode != 0)) || |
72 | 0 | ((code = fn_build_float_array(op, "Decode", false, true, ¶ms.Decode, mem)) != 2 * params.n && (code != 0 || params.Decode != 0)) |
73 | 0 | ) { |
74 | 0 | goto fail; |
75 | 0 | } { |
76 | 0 | int *ptr = (int *) |
77 | 0 | gs_alloc_byte_array(mem, params.m, sizeof(int), "Size"); |
78 | |
|
79 | 0 | if (ptr == 0) { |
80 | 0 | code = gs_note_error(gs_error_VMerror); |
81 | 0 | goto fail; |
82 | 0 | } |
83 | 0 | params.Size = ptr; |
84 | 0 | code = dict_ints_param(mem, op, "Size", params.m, ptr); |
85 | 0 | if (code != params.m) |
86 | 0 | goto fail; |
87 | 0 | } |
88 | 0 | code = gs_function_Sd_init(ppfn, ¶ms, mem); |
89 | 0 | if (code >= 0) |
90 | 0 | return 0; |
91 | 0 | fail: |
92 | 0 | gs_function_Sd_free_params(¶ms, mem); |
93 | 0 | return (code < 0 ? code : gs_note_error(gs_error_rangecheck)); |
94 | 0 | } |