/src/ghostpdl/base/sdctc.c
Line | Count | Source |
1 | | /* Copyright (C) 2001-2025 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 | | /* Code common to DCT encoding and decoding streams */ |
18 | | #include "stdio_.h" |
19 | | #include "jpeglib_.h" |
20 | | #include "strimpl.h" |
21 | | #include "sdct.h" |
22 | | #include "sjpeg.h" |
23 | | |
24 | | extern const stream_template s_DCTE_template; |
25 | | extern const stream_template s_DCTD_template; |
26 | | |
27 | | static void stream_dct_finalize(const gs_memory_t *cmem, void *vptr); |
28 | | |
29 | | public_st_DCT_state(); |
30 | | |
31 | | /* Set the defaults for the DCT filters. */ |
32 | | void |
33 | | s_DCT_set_defaults(stream_state * st) |
34 | 32.9k | { |
35 | 32.9k | stream_DCT_state *const ss = (stream_DCT_state *) st; |
36 | | |
37 | 32.9k | ss->jpeg_memory = ss->memory->non_gc_memory; |
38 | 32.9k | ss->data.common = 0; |
39 | | /**************** |
40 | | ss->data.common->Picky = 0; |
41 | | ss->data.common->Relax = 0; |
42 | | ****************/ |
43 | 32.9k | ss->ColorTransform = -1; |
44 | 32.9k | ss->QFactor = 1.0; |
45 | | /* Clear pointers */ |
46 | 32.9k | ss->Markers.data = 0; |
47 | 32.9k | ss->Markers.size = 0; |
48 | 32.9k | } |
49 | | |
50 | | static void |
51 | | stream_dct_finalize(const gs_memory_t *cmem, void *vptr) |
52 | 19.5k | { |
53 | 19.5k | stream_state *const st = vptr; |
54 | 19.5k | stream_DCT_state *const ss = (stream_DCT_state *) st; |
55 | 19.5k | (void)cmem; /* unused */ |
56 | | |
57 | 19.5k | if (st->templat->process == s_DCTE_template.process) { |
58 | 6.15k | gs_jpeg_destroy(ss); |
59 | 6.15k | if (ss->data.compress != NULL) { |
60 | 6.15k | gs_free_object(ss->data.common->memory, ss->data.compress, |
61 | 6.15k | "s_DCTE_release"); |
62 | 6.15k | ss->data.compress = NULL; |
63 | 6.15k | } |
64 | | /* Switch the template pointer back in case we still need it. */ |
65 | 6.15k | st->templat = &s_DCTE_template; |
66 | 6.15k | } |
67 | 13.3k | else { |
68 | 13.3k | stream_dct_end_passthrough(ss->data.decompress); |
69 | 13.3k | gs_jpeg_destroy(ss); |
70 | 13.3k | if (ss->data.decompress != NULL) { |
71 | 13.3k | if (ss->data.decompress->scanline_buffer != NULL) { |
72 | 424 | gs_free_object(gs_memory_stable(ss->data.common->memory), |
73 | 424 | ss->data.decompress->scanline_buffer, |
74 | 424 | "s_DCTD_release(scanline_buffer)"); |
75 | 424 | ss->data.decompress->scanline_buffer = NULL; |
76 | 424 | } |
77 | 13.3k | gs_free_object(ss->data.common->memory, ss->data.decompress, |
78 | 13.3k | "s_DCTD_release"); |
79 | 13.3k | ss->data.decompress = NULL; |
80 | 13.3k | } |
81 | | /* Switch the template pointer back in case we still need it. */ |
82 | 13.3k | st->templat = &s_DCTD_template; |
83 | 13.3k | } |
84 | 19.5k | } |
85 | | |
86 | | void |
87 | | stream_dct_end_passthrough(jpeg_decompress_data *jddp) |
88 | 39.0k | { |
89 | 39.0k | char EOI[2] = {0xff, 0xD9}; |
90 | | |
91 | 39.0k | if (jddp != NULL && jddp->PassThrough != 0 && jddp->PassThroughfn != NULL) { |
92 | 3.01k | (jddp->PassThroughfn)(jddp->device, NULL, 0); |
93 | 3.01k | jddp->PassThrough = 0; |
94 | 3.01k | jddp->PassThroughfn = NULL; |
95 | 3.01k | jddp->StartedPassThrough = 0; |
96 | 3.01k | } |
97 | 39.0k | } |