/src/ghostpdl/base/sjpegd.c
Line | Count | Source (jump to first uncovered line) |
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 | | /* Interface routines for IJG decoding code. */ |
18 | | #include "stdio_.h" |
19 | | #include "string_.h" |
20 | | #include "jpeglib_.h" |
21 | | #include "jerror_.h" |
22 | | #include "gserrors.h" |
23 | | #include "gx.h" |
24 | | #include "strimpl.h" |
25 | | #include "sdct.h" |
26 | | #include "sjpeg.h" |
27 | | #include "setjmp_.h" |
28 | | |
29 | | /* |
30 | | * Interface routines. This layer of routines exists solely to limit |
31 | | * side-effects from using setjmp. |
32 | | */ |
33 | | |
34 | | OPTIMIZE_SETJMP |
35 | | int |
36 | | gs_jpeg_create_decompress(stream_DCT_state * st) |
37 | 13.3k | { /* Initialize error handling */ |
38 | 13.3k | gs_jpeg_error_setup(st); |
39 | 13.3k | #if INIT_GS_JMPBUF==1 |
40 | 13.3k | memset(&(st->data.common->exit_jmpbuf), 0x00, sizeof(st->data.common->exit_jmpbuf)); |
41 | 13.3k | #endif |
42 | | /* Establish the setjmp return context for gs_jpeg_error_exit to use. */ |
43 | 13.3k | if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) |
44 | 0 | return_error(gs_jpeg_log_error(st)); |
45 | | |
46 | 13.3k | jpeg_stream_data_common_init(st->data.decompress); |
47 | | |
48 | 13.3k | if (gs_jpeg_mem_init (st->memory, (j_common_ptr)&st->data.decompress->dinfo) < 0) |
49 | 0 | return_error(gs_error_VMerror); |
50 | | |
51 | 13.3k | jpeg_create_decompress(&st->data.decompress->dinfo); |
52 | 13.3k | return 0; |
53 | 13.3k | } |
54 | | |
55 | | OPTIMIZE_SETJMP |
56 | | int |
57 | | gs_jpeg_read_header(stream_DCT_state * st, |
58 | | boolean require_image) |
59 | 26.8k | { |
60 | 26.8k | #if INIT_GS_JMPBUF==1 |
61 | 26.8k | memset(&(st->data.common->exit_jmpbuf), 0x00, sizeof(st->data.common->exit_jmpbuf)); |
62 | 26.8k | #endif |
63 | 26.8k | if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) |
64 | 3.22k | return_error(gs_jpeg_log_error(st)); |
65 | 23.6k | return jpeg_read_header(&st->data.decompress->dinfo, require_image); |
66 | 26.8k | } |
67 | | |
68 | | OPTIMIZE_SETJMP |
69 | | int |
70 | | gs_jpeg_start_decompress(stream_DCT_state * st) |
71 | 17.2k | { |
72 | 17.2k | #if INIT_GS_JMPBUF==1 |
73 | 17.2k | memset(&(st->data.common->exit_jmpbuf), 0x00, sizeof(st->data.common->exit_jmpbuf)); |
74 | 17.2k | #endif |
75 | 17.2k | if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) |
76 | 46 | return_error(gs_jpeg_log_error(st)); |
77 | 17.1k | #if JPEG_LIB_VERSION > 55 |
78 | 17.1k | return (int)jpeg_start_decompress(&st->data.decompress->dinfo); |
79 | | #else |
80 | | /* in IJG version 5, jpeg_start_decompress had no return value */ |
81 | | jpeg_start_decompress(&st->data.decompress->dinfo); |
82 | | return 1; |
83 | | #endif |
84 | 17.2k | } |
85 | | |
86 | | OPTIMIZE_SETJMP |
87 | | int |
88 | | gs_jpeg_read_scanlines(stream_DCT_state * st, |
89 | | JSAMPARRAY scanlines, |
90 | | int max_lines) |
91 | 2.26M | { |
92 | 2.26M | #if INIT_GS_JMPBUF==1 |
93 | 2.26M | memset(&(st->data.common->exit_jmpbuf), 0x00, sizeof(st->data.common->exit_jmpbuf)); |
94 | 2.26M | #endif |
95 | 2.26M | if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) |
96 | 0 | return_error(gs_jpeg_log_error(st)); |
97 | 2.26M | return (int)jpeg_read_scanlines(&st->data.decompress->dinfo, |
98 | 2.26M | scanlines, (JDIMENSION) max_lines); |
99 | 2.26M | } |
100 | | |
101 | | OPTIMIZE_SETJMP |
102 | | int |
103 | | gs_jpeg_finish_decompress(stream_DCT_state * st) |
104 | 12.6k | { |
105 | 12.6k | int code = 0; |
106 | 12.6k | #if INIT_GS_JMPBUF==1 |
107 | 12.6k | memset(&(st->data.common->exit_jmpbuf), 0x00, sizeof(st->data.common->exit_jmpbuf)); |
108 | 12.6k | #endif |
109 | 12.6k | if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) |
110 | 862 | code = gs_note_error(gs_jpeg_log_error(st)); |
111 | 12.6k | if (code >= 0) |
112 | 12.6k | code = (int)jpeg_finish_decompress(&st->data.decompress->dinfo); |
113 | 12.6k | stream_dct_end_passthrough(st->data.decompress); |
114 | 12.6k | return code; |
115 | 12.6k | } |