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