/src/ghostpdl/psi/zfdcte.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2021 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., 1305 Grant Avenue - Suite 200, Novato, |
13 | | CA 94945, U.S.A., +1(415)492-9861, for further information. |
14 | | */ |
15 | | |
16 | | |
17 | | /* DCTEncode filter creation */ |
18 | | #include "memory_.h" |
19 | | #include "stdio_.h" /* for jpeglib.h */ |
20 | | #include "jpeglib_.h" |
21 | | #include "ghost.h" |
22 | | #include "oper.h" |
23 | | #include "gsmemory.h" |
24 | | #include "ialloc.h" |
25 | | #include "idict.h" |
26 | | #include "idparam.h" |
27 | | #include "strimpl.h" |
28 | | #include "sdct.h" |
29 | | #include "sjpeg.h" |
30 | | #include "ifilter.h" |
31 | | #include "iparam.h" |
32 | | |
33 | | /* Import the parameter processing procedure from sdeparam.c */ |
34 | | stream_state_proc_put_params(s_DCTE_put_params, stream_DCT_state); |
35 | | |
36 | | /* <target> <dict> DCTEncode/filter <file> */ |
37 | | static int |
38 | | zDCTE(i_ctx_t *i_ctx_p) |
39 | 0 | { |
40 | 0 | os_ptr op = osp; |
41 | 0 | gs_memory_t *mem = gs_memory_stable(imemory); |
42 | 0 | stream_DCT_state state; |
43 | 0 | dict_param_list list; |
44 | 0 | jpeg_compress_data *jcdp; |
45 | 0 | int code; |
46 | 0 | const ref *dop; |
47 | 0 | uint dspace; |
48 | | |
49 | | /* First allocate space for IJG parameters. */ |
50 | 0 | jcdp = gs_alloc_struct_immovable(mem, jpeg_compress_data, |
51 | 0 | &st_jpeg_compress_data, "zDCTE"); |
52 | 0 | if (jcdp == 0) |
53 | 0 | return_error(gs_error_VMerror); |
54 | 0 | state.memory = mem; |
55 | 0 | if (s_DCTE_template.set_defaults) |
56 | 0 | (*s_DCTE_template.set_defaults) ((stream_state *) & state); |
57 | 0 | state.data.compress = jcdp; |
58 | 0 | jcdp->memory = state.jpeg_memory = mem; /* set now for allocation */ |
59 | 0 | state.report_error = filter_report_error; /* in case create fails */ |
60 | 0 | if ((code = gs_jpeg_create_compress(&state)) < 0) |
61 | 0 | goto fail; /* correct to do jpeg_destroy here */ |
62 | | /* Read parameters from dictionary */ |
63 | 0 | if (r_has_type(op, t_dictionary)) |
64 | 0 | dop = op, dspace = r_space(op); |
65 | 0 | else |
66 | 0 | dop = 0, dspace = 0; |
67 | 0 | if ((code = dict_param_list_read(&list, dop, NULL, false, iimemory)) < 0) |
68 | 0 | goto fail; |
69 | 0 | if ((code = s_DCTE_put_params((gs_param_list *) & list, &state)) < 0) |
70 | 0 | goto rel; |
71 | | /* Create the filter. */ |
72 | 0 | jcdp->templat = s_DCTE_template; |
73 | | /* Make sure we get at least a full scan line of input. */ |
74 | 0 | state.scan_line_size = jcdp->cinfo.input_components * |
75 | 0 | jcdp->cinfo.image_width; |
76 | 0 | state.icc_profile = NULL; |
77 | 0 | jcdp->templat.min_in_size = |
78 | 0 | max(s_DCTE_template.min_in_size, state.scan_line_size); |
79 | | /* Make sure we can write the user markers in a single go. */ |
80 | 0 | jcdp->templat.min_out_size = |
81 | 0 | max(s_DCTE_template.min_out_size, state.Markers.size); |
82 | 0 | code = filter_write(i_ctx_p, 0, &jcdp->templat, |
83 | 0 | (stream_state *) & state, dspace); |
84 | 0 | if (code >= 0) /* Success! */ |
85 | 0 | return code; |
86 | | /* We assume that if filter_write fails, the stream has not been |
87 | | * registered for closing, so s_DCTE_release will never be called. |
88 | | * Therefore we free the allocated memory before failing. |
89 | | */ |
90 | 0 | rel: |
91 | 0 | iparam_list_release(&list); |
92 | 0 | fail: |
93 | 0 | gs_jpeg_destroy(&state); |
94 | 0 | gs_free_object(mem, jcdp, "zDCTE fail"); |
95 | 0 | return code; |
96 | 0 | } |
97 | | |
98 | | /* ------ Initialization procedure ------ */ |
99 | | |
100 | | const op_def zfdcte_op_defs[] = |
101 | | { |
102 | | op_def_begin_filter(), |
103 | | {"2DCTEncode", zDCTE}, |
104 | | op_def_end(0) |
105 | | }; |