/src/ghostpdl/base/sjpege.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 encoding code. */ |
18 | | #include "stdio_.h" |
19 | | #include "string_.h" |
20 | | #include "jpeglib_.h" |
21 | | #include "jerror_.h" |
22 | | #include "gx.h" |
23 | | #include "strimpl.h" |
24 | | #include "sdct.h" |
25 | | #include "sjpeg.h" |
26 | | #include "setjmp_.h" |
27 | | |
28 | | /* |
29 | | * Interface routines. This layer of routines exists solely to limit |
30 | | * side-effects from using setjmp. |
31 | | */ |
32 | | |
33 | | OPTIMIZE_SETJMP |
34 | | int |
35 | | gs_jpeg_create_compress(stream_DCT_state * st) |
36 | 6.15k | { /* Initialize error handling */ |
37 | 6.15k | gs_jpeg_error_setup(st); |
38 | | /* Establish the setjmp return context for gs_jpeg_error_exit to use. */ |
39 | 6.15k | if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) |
40 | 0 | return_error(gs_jpeg_log_error(st)); |
41 | | |
42 | 6.15k | jpeg_stream_data_common_init(st->data.compress); |
43 | | |
44 | 6.15k | if (gs_jpeg_mem_init (st->memory, (j_common_ptr)&st->data.compress->cinfo) < 0) |
45 | 0 | return_error(gs_error_VMerror); |
46 | | |
47 | 6.15k | jpeg_create_compress(&st->data.compress->cinfo); |
48 | 6.15k | return 0; |
49 | 6.15k | } |
50 | | |
51 | | OPTIMIZE_SETJMP |
52 | | int |
53 | | gs_jpeg_set_defaults(stream_DCT_state * st) |
54 | 6.15k | { |
55 | 6.15k | if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) |
56 | 0 | return_error(gs_jpeg_log_error(st)); |
57 | 6.15k | jpeg_set_defaults(&st->data.compress->cinfo); |
58 | 6.15k | return 0; |
59 | 6.15k | } |
60 | | |
61 | | OPTIMIZE_SETJMP |
62 | | int |
63 | | gs_jpeg_set_colorspace(stream_DCT_state * st, |
64 | | J_COLOR_SPACE colorspace) |
65 | 0 | { |
66 | 0 | if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) |
67 | 0 | return_error(gs_jpeg_log_error(st)); |
68 | 0 | jpeg_set_colorspace(&st->data.compress->cinfo, colorspace); |
69 | 0 | return 0; |
70 | 0 | } |
71 | | |
72 | | OPTIMIZE_SETJMP |
73 | | int |
74 | | gs_jpeg_set_linear_quality(stream_DCT_state * st, |
75 | | int scale_factor, boolean force_baseline) |
76 | 6.15k | { |
77 | 6.15k | if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) |
78 | 0 | return_error(gs_jpeg_log_error(st)); |
79 | 6.15k | jpeg_set_linear_quality(&st->data.compress->cinfo, |
80 | 6.15k | scale_factor, force_baseline); |
81 | 6.15k | return 0; |
82 | 6.15k | } |
83 | | |
84 | | OPTIMIZE_SETJMP |
85 | | int |
86 | | gs_jpeg_set_quality(stream_DCT_state * st, |
87 | | int quality, boolean force_baseline) |
88 | 0 | { |
89 | 0 | if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) |
90 | 0 | return_error(gs_jpeg_log_error(st)); |
91 | 0 | jpeg_set_quality(&st->data.compress->cinfo, |
92 | 0 | quality, force_baseline); |
93 | 0 | return 0; |
94 | 0 | } |
95 | | |
96 | | OPTIMIZE_SETJMP |
97 | | int |
98 | | gs_jpeg_start_compress(stream_DCT_state * st, |
99 | | boolean write_all_tables) |
100 | 6.15k | { |
101 | 6.15k | if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) |
102 | 23 | return_error(gs_jpeg_log_error(st)); |
103 | 6.12k | jpeg_start_compress(&st->data.compress->cinfo, write_all_tables); |
104 | 6.12k | return 0; |
105 | 6.15k | } |
106 | | |
107 | | OPTIMIZE_SETJMP |
108 | | int |
109 | | gs_jpeg_write_scanlines(stream_DCT_state * st, |
110 | | JSAMPARRAY scanlines, |
111 | | int num_lines) |
112 | 582k | { |
113 | 582k | if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) |
114 | 0 | return_error(gs_jpeg_log_error(st)); |
115 | 582k | return (int)jpeg_write_scanlines(&st->data.compress->cinfo, |
116 | 582k | scanlines, (JDIMENSION) num_lines); |
117 | 582k | } |
118 | | |
119 | | OPTIMIZE_SETJMP |
120 | | int |
121 | | gs_jpeg_finish_compress(stream_DCT_state * st) |
122 | 5.80k | { |
123 | 5.80k | if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) |
124 | 0 | return_error(gs_jpeg_log_error(st)); |
125 | 5.80k | jpeg_finish_compress(&st->data.compress->cinfo); |
126 | 5.80k | return 0; |
127 | 5.80k | } |