/src/libjpeg-turbo/src/jdpostct.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * jdpostct.c |
3 | | * |
4 | | * This file was part of the Independent JPEG Group's software: |
5 | | * Copyright (C) 1994-1996, Thomas G. Lane. |
6 | | * libjpeg-turbo Modifications: |
7 | | * Copyright (C) 2022-2024, D. R. Commander. |
8 | | * For conditions of distribution and use, see the accompanying README.ijg |
9 | | * file. |
10 | | * |
11 | | * This file contains the decompression postprocessing controller. |
12 | | * This controller manages the upsampling, color conversion, and color |
13 | | * quantization/reduction steps; specifically, it controls the buffering |
14 | | * between upsample/color conversion and color quantization/reduction. |
15 | | * |
16 | | * If no color quantization/reduction is required, then this module has no |
17 | | * work to do, and it just hands off to the upsample/color conversion code. |
18 | | * An integrated upsample/convert/quantize process would replace this module |
19 | | * entirely. |
20 | | */ |
21 | | |
22 | | #define JPEG_INTERNALS |
23 | | #include "jinclude.h" |
24 | | #include "jpeglib.h" |
25 | | #include "jsamplecomp.h" |
26 | | |
27 | | |
28 | | #if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) |
29 | | |
30 | | /* Private buffer controller object */ |
31 | | |
32 | | typedef struct { |
33 | | struct jpeg_d_post_controller pub; /* public fields */ |
34 | | |
35 | | /* Color quantization source buffer: this holds output data from |
36 | | * the upsample/color conversion step to be passed to the quantizer. |
37 | | * For two-pass color quantization, we need a full-image buffer; |
38 | | * for one-pass operation, a strip buffer is sufficient. |
39 | | */ |
40 | | jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */ |
41 | | _JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */ |
42 | | JDIMENSION strip_height; /* buffer size in rows */ |
43 | | /* for two-pass mode only: */ |
44 | | JDIMENSION starting_row; /* row # of first row in current strip */ |
45 | | JDIMENSION next_row; /* index of next row to fill/empty in strip */ |
46 | | } my_post_controller; |
47 | | |
48 | | typedef my_post_controller *my_post_ptr; |
49 | | |
50 | | |
51 | | /* Forward declarations */ |
52 | | #if BITS_IN_JSAMPLE != 16 |
53 | | METHODDEF(void) post_process_1pass(j_decompress_ptr cinfo, |
54 | | _JSAMPIMAGE input_buf, |
55 | | JDIMENSION *in_row_group_ctr, |
56 | | JDIMENSION in_row_groups_avail, |
57 | | _JSAMPARRAY output_buf, |
58 | | JDIMENSION *out_row_ctr, |
59 | | JDIMENSION out_rows_avail); |
60 | | #endif |
61 | | #if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 |
62 | | METHODDEF(void) post_process_prepass(j_decompress_ptr cinfo, |
63 | | _JSAMPIMAGE input_buf, |
64 | | JDIMENSION *in_row_group_ctr, |
65 | | JDIMENSION in_row_groups_avail, |
66 | | _JSAMPARRAY output_buf, |
67 | | JDIMENSION *out_row_ctr, |
68 | | JDIMENSION out_rows_avail); |
69 | | METHODDEF(void) post_process_2pass(j_decompress_ptr cinfo, |
70 | | _JSAMPIMAGE input_buf, |
71 | | JDIMENSION *in_row_group_ctr, |
72 | | JDIMENSION in_row_groups_avail, |
73 | | _JSAMPARRAY output_buf, |
74 | | JDIMENSION *out_row_ctr, |
75 | | JDIMENSION out_rows_avail); |
76 | | #endif |
77 | | |
78 | | |
79 | | /* |
80 | | * Initialize for a processing pass. |
81 | | */ |
82 | | |
83 | | METHODDEF(void) |
84 | | start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode) |
85 | 205k | { |
86 | 205k | my_post_ptr post = (my_post_ptr)cinfo->post; |
87 | | |
88 | 205k | switch (pass_mode) { |
89 | 205k | case JBUF_PASS_THRU: |
90 | | #if BITS_IN_JSAMPLE != 16 |
91 | 198k | if (cinfo->quantize_colors) { |
92 | | /* Single-pass processing with color quantization. */ |
93 | 0 | post->pub._post_process_data = post_process_1pass; |
94 | | /* We could be doing buffered-image output before starting a 2-pass |
95 | | * color quantization; in that case, jinit_d_post_controller did not |
96 | | * allocate a strip buffer. Use the virtual-array buffer as workspace. |
97 | | */ |
98 | 0 | if (post->buffer == NULL) { |
99 | 0 | post->buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) |
100 | 0 | ((j_common_ptr)cinfo, post->whole_image, |
101 | 0 | (JDIMENSION)0, post->strip_height, TRUE); |
102 | 0 | } |
103 | 0 | } else |
104 | 198k | #endif |
105 | 198k | { |
106 | | /* For single-pass processing without color quantization, |
107 | | * I have no work to do; just call the upsampler directly. |
108 | | */ |
109 | 205k | post->pub._post_process_data = cinfo->upsample->_upsample; |
110 | 198k | } |
111 | 205k | break; |
112 | | #if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 |
113 | 0 | case JBUF_SAVE_AND_PASS: |
114 | | /* First pass of 2-pass quantization */ |
115 | 0 | if (post->whole_image == NULL) |
116 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); |
117 | 0 | post->pub._post_process_data = post_process_prepass; |
118 | 0 | break; |
119 | 0 | case JBUF_CRANK_DEST: |
120 | | /* Second pass of 2-pass quantization */ |
121 | 0 | if (post->whole_image == NULL) |
122 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); |
123 | 0 | post->pub._post_process_data = post_process_2pass; |
124 | 0 | break; |
125 | 0 | #endif /* defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */ |
126 | 0 | default: |
127 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); |
128 | 0 | break; |
129 | 205k | } |
130 | 205k | post->starting_row = post->next_row = 0; |
131 | 205k | } jdpostct-8.c:start_pass_dpost Line | Count | Source | 85 | 173k | { | 86 | 173k | my_post_ptr post = (my_post_ptr)cinfo->post; | 87 | | | 88 | 173k | switch (pass_mode) { | 89 | 173k | case JBUF_PASS_THRU: | 90 | 173k | #if BITS_IN_JSAMPLE != 16 | 91 | 173k | if (cinfo->quantize_colors) { | 92 | | /* Single-pass processing with color quantization. */ | 93 | 0 | post->pub._post_process_data = post_process_1pass; | 94 | | /* We could be doing buffered-image output before starting a 2-pass | 95 | | * color quantization; in that case, jinit_d_post_controller did not | 96 | | * allocate a strip buffer. Use the virtual-array buffer as workspace. | 97 | | */ | 98 | 0 | if (post->buffer == NULL) { | 99 | 0 | post->buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 100 | 0 | ((j_common_ptr)cinfo, post->whole_image, | 101 | 0 | (JDIMENSION)0, post->strip_height, TRUE); | 102 | 0 | } | 103 | 0 | } else | 104 | 173k | #endif | 105 | 173k | { | 106 | | /* For single-pass processing without color quantization, | 107 | | * I have no work to do; just call the upsampler directly. | 108 | | */ | 109 | 173k | post->pub._post_process_data = cinfo->upsample->_upsample; | 110 | 173k | } | 111 | 173k | break; | 112 | 0 | #if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 | 113 | 0 | case JBUF_SAVE_AND_PASS: | 114 | | /* First pass of 2-pass quantization */ | 115 | 0 | if (post->whole_image == NULL) | 116 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 117 | 0 | post->pub._post_process_data = post_process_prepass; | 118 | 0 | break; | 119 | 0 | case JBUF_CRANK_DEST: | 120 | | /* Second pass of 2-pass quantization */ | 121 | 0 | if (post->whole_image == NULL) | 122 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 123 | 0 | post->pub._post_process_data = post_process_2pass; | 124 | 0 | break; | 125 | 0 | #endif /* defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */ | 126 | 0 | default: | 127 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 128 | 0 | break; | 129 | 173k | } | 130 | 173k | post->starting_row = post->next_row = 0; | 131 | 173k | } |
jdpostct-12.c:start_pass_dpost Line | Count | Source | 85 | 25.1k | { | 86 | 25.1k | my_post_ptr post = (my_post_ptr)cinfo->post; | 87 | | | 88 | 25.1k | switch (pass_mode) { | 89 | 25.1k | case JBUF_PASS_THRU: | 90 | 25.1k | #if BITS_IN_JSAMPLE != 16 | 91 | 25.1k | if (cinfo->quantize_colors) { | 92 | | /* Single-pass processing with color quantization. */ | 93 | 0 | post->pub._post_process_data = post_process_1pass; | 94 | | /* We could be doing buffered-image output before starting a 2-pass | 95 | | * color quantization; in that case, jinit_d_post_controller did not | 96 | | * allocate a strip buffer. Use the virtual-array buffer as workspace. | 97 | | */ | 98 | 0 | if (post->buffer == NULL) { | 99 | 0 | post->buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 100 | 0 | ((j_common_ptr)cinfo, post->whole_image, | 101 | 0 | (JDIMENSION)0, post->strip_height, TRUE); | 102 | 0 | } | 103 | 0 | } else | 104 | 25.1k | #endif | 105 | 25.1k | { | 106 | | /* For single-pass processing without color quantization, | 107 | | * I have no work to do; just call the upsampler directly. | 108 | | */ | 109 | 25.1k | post->pub._post_process_data = cinfo->upsample->_upsample; | 110 | 25.1k | } | 111 | 25.1k | break; | 112 | 0 | #if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 | 113 | 0 | case JBUF_SAVE_AND_PASS: | 114 | | /* First pass of 2-pass quantization */ | 115 | 0 | if (post->whole_image == NULL) | 116 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 117 | 0 | post->pub._post_process_data = post_process_prepass; | 118 | 0 | break; | 119 | 0 | case JBUF_CRANK_DEST: | 120 | | /* Second pass of 2-pass quantization */ | 121 | 0 | if (post->whole_image == NULL) | 122 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 123 | 0 | post->pub._post_process_data = post_process_2pass; | 124 | 0 | break; | 125 | 0 | #endif /* defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */ | 126 | 0 | default: | 127 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 128 | 0 | break; | 129 | 25.1k | } | 130 | 25.1k | post->starting_row = post->next_row = 0; | 131 | 25.1k | } |
jdpostct-16.c:start_pass_dpost Line | Count | Source | 85 | 6.17k | { | 86 | 6.17k | my_post_ptr post = (my_post_ptr)cinfo->post; | 87 | | | 88 | 6.17k | switch (pass_mode) { | 89 | 6.17k | case JBUF_PASS_THRU: | 90 | | #if BITS_IN_JSAMPLE != 16 | 91 | | if (cinfo->quantize_colors) { | 92 | | /* Single-pass processing with color quantization. */ | 93 | | post->pub._post_process_data = post_process_1pass; | 94 | | /* We could be doing buffered-image output before starting a 2-pass | 95 | | * color quantization; in that case, jinit_d_post_controller did not | 96 | | * allocate a strip buffer. Use the virtual-array buffer as workspace. | 97 | | */ | 98 | | if (post->buffer == NULL) { | 99 | | post->buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) | 100 | | ((j_common_ptr)cinfo, post->whole_image, | 101 | | (JDIMENSION)0, post->strip_height, TRUE); | 102 | | } | 103 | | } else | 104 | | #endif | 105 | 6.17k | { | 106 | | /* For single-pass processing without color quantization, | 107 | | * I have no work to do; just call the upsampler directly. | 108 | | */ | 109 | 6.17k | post->pub._post_process_data = cinfo->upsample->_upsample; | 110 | 6.17k | } | 111 | 6.17k | break; | 112 | | #if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 | 113 | | case JBUF_SAVE_AND_PASS: | 114 | | /* First pass of 2-pass quantization */ | 115 | | if (post->whole_image == NULL) | 116 | | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 117 | | post->pub._post_process_data = post_process_prepass; | 118 | | break; | 119 | | case JBUF_CRANK_DEST: | 120 | | /* Second pass of 2-pass quantization */ | 121 | | if (post->whole_image == NULL) | 122 | | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 123 | | post->pub._post_process_data = post_process_2pass; | 124 | | break; | 125 | | #endif /* defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */ | 126 | 0 | default: | 127 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 128 | 0 | break; | 129 | 6.17k | } | 130 | 6.17k | post->starting_row = post->next_row = 0; | 131 | 6.17k | } |
|
132 | | |
133 | | |
134 | | /* |
135 | | * Process some data in the one-pass (strip buffer) case. |
136 | | * This is used for color precision reduction as well as one-pass quantization. |
137 | | */ |
138 | | |
139 | | #if BITS_IN_JSAMPLE != 16 |
140 | | |
141 | | METHODDEF(void) |
142 | | post_process_1pass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf, |
143 | | JDIMENSION *in_row_group_ctr, |
144 | | JDIMENSION in_row_groups_avail, _JSAMPARRAY output_buf, |
145 | | JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail) |
146 | 0 | { |
147 | 0 | my_post_ptr post = (my_post_ptr)cinfo->post; |
148 | 0 | JDIMENSION num_rows, max_rows; |
149 | | |
150 | | /* Fill the buffer, but not more than what we can dump out in one go. */ |
151 | | /* Note we rely on the upsampler to detect bottom of image. */ |
152 | 0 | max_rows = out_rows_avail - *out_row_ctr; |
153 | 0 | if (max_rows > post->strip_height) |
154 | 0 | max_rows = post->strip_height; |
155 | 0 | num_rows = 0; |
156 | 0 | (*cinfo->upsample->_upsample) (cinfo, input_buf, in_row_group_ctr, |
157 | 0 | in_row_groups_avail, post->buffer, &num_rows, |
158 | 0 | max_rows); |
159 | | /* Quantize and emit data. */ |
160 | 0 | (*cinfo->cquantize->_color_quantize) (cinfo, post->buffer, |
161 | 0 | output_buf + *out_row_ctr, |
162 | 0 | (int)num_rows); |
163 | 0 | *out_row_ctr += num_rows; |
164 | 0 | } Unexecuted instantiation: jdpostct-8.c:post_process_1pass Unexecuted instantiation: jdpostct-12.c:post_process_1pass |
165 | | |
166 | | #endif |
167 | | |
168 | | |
169 | | #if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 |
170 | | |
171 | | /* |
172 | | * Process some data in the first pass of 2-pass quantization. |
173 | | */ |
174 | | |
175 | | METHODDEF(void) |
176 | | post_process_prepass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf, |
177 | | JDIMENSION *in_row_group_ctr, |
178 | | JDIMENSION in_row_groups_avail, _JSAMPARRAY output_buf, |
179 | | JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail) |
180 | 0 | { |
181 | 0 | my_post_ptr post = (my_post_ptr)cinfo->post; |
182 | 0 | JDIMENSION old_next_row, num_rows; |
183 | | |
184 | | /* Reposition virtual buffer if at start of strip. */ |
185 | 0 | if (post->next_row == 0) { |
186 | 0 | post->buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) |
187 | 0 | ((j_common_ptr)cinfo, post->whole_image, |
188 | 0 | post->starting_row, post->strip_height, TRUE); |
189 | 0 | } |
190 | | |
191 | | /* Upsample some data (up to a strip height's worth). */ |
192 | 0 | old_next_row = post->next_row; |
193 | 0 | (*cinfo->upsample->_upsample) (cinfo, input_buf, in_row_group_ctr, |
194 | 0 | in_row_groups_avail, post->buffer, |
195 | 0 | &post->next_row, post->strip_height); |
196 | | |
197 | | /* Allow quantizer to scan new data. No data is emitted, */ |
198 | | /* but we advance out_row_ctr so outer loop can tell when we're done. */ |
199 | 0 | if (post->next_row > old_next_row) { |
200 | 0 | num_rows = post->next_row - old_next_row; |
201 | 0 | (*cinfo->cquantize->_color_quantize) (cinfo, post->buffer + old_next_row, |
202 | 0 | (_JSAMPARRAY)NULL, (int)num_rows); |
203 | 0 | *out_row_ctr += num_rows; |
204 | 0 | } |
205 | | |
206 | | /* Advance if we filled the strip. */ |
207 | 0 | if (post->next_row >= post->strip_height) { |
208 | 0 | post->starting_row += post->strip_height; |
209 | 0 | post->next_row = 0; |
210 | 0 | } |
211 | 0 | } Unexecuted instantiation: jdpostct-8.c:post_process_prepass Unexecuted instantiation: jdpostct-12.c:post_process_prepass |
212 | | |
213 | | |
214 | | /* |
215 | | * Process some data in the second pass of 2-pass quantization. |
216 | | */ |
217 | | |
218 | | METHODDEF(void) |
219 | | post_process_2pass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf, |
220 | | JDIMENSION *in_row_group_ctr, |
221 | | JDIMENSION in_row_groups_avail, _JSAMPARRAY output_buf, |
222 | | JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail) |
223 | 0 | { |
224 | 0 | my_post_ptr post = (my_post_ptr)cinfo->post; |
225 | 0 | JDIMENSION num_rows, max_rows; |
226 | | |
227 | | /* Reposition virtual buffer if at start of strip. */ |
228 | 0 | if (post->next_row == 0) { |
229 | 0 | post->buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) |
230 | 0 | ((j_common_ptr)cinfo, post->whole_image, |
231 | 0 | post->starting_row, post->strip_height, FALSE); |
232 | 0 | } |
233 | | |
234 | | /* Determine number of rows to emit. */ |
235 | 0 | num_rows = post->strip_height - post->next_row; /* available in strip */ |
236 | 0 | max_rows = out_rows_avail - *out_row_ctr; /* available in output area */ |
237 | 0 | if (num_rows > max_rows) |
238 | 0 | num_rows = max_rows; |
239 | | /* We have to check bottom of image here, can't depend on upsampler. */ |
240 | 0 | max_rows = cinfo->output_height - post->starting_row; |
241 | 0 | if (num_rows > max_rows) |
242 | 0 | num_rows = max_rows; |
243 | | |
244 | | /* Quantize and emit data. */ |
245 | 0 | (*cinfo->cquantize->_color_quantize) (cinfo, post->buffer + post->next_row, |
246 | 0 | output_buf + *out_row_ctr, |
247 | 0 | (int)num_rows); |
248 | 0 | *out_row_ctr += num_rows; |
249 | | |
250 | | /* Advance if we filled the strip. */ |
251 | 0 | post->next_row += num_rows; |
252 | 0 | if (post->next_row >= post->strip_height) { |
253 | 0 | post->starting_row += post->strip_height; |
254 | 0 | post->next_row = 0; |
255 | 0 | } |
256 | 0 | } Unexecuted instantiation: jdpostct-8.c:post_process_2pass Unexecuted instantiation: jdpostct-12.c:post_process_2pass |
257 | | |
258 | | #endif /* defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */ |
259 | | |
260 | | |
261 | | /* |
262 | | * Initialize postprocessing controller. |
263 | | */ |
264 | | |
265 | | GLOBAL(void) |
266 | | _jinit_d_post_controller(j_decompress_ptr cinfo, boolean need_full_buffer) |
267 | 233k | { |
268 | 233k | my_post_ptr post; |
269 | | |
270 | 233k | #ifdef D_LOSSLESS_SUPPORTED |
271 | 233k | if (cinfo->master->lossless) { |
272 | | #if BITS_IN_JSAMPLE == 8 |
273 | 35.7k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
274 | | #else |
275 | 16.6k | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
276 | 16.6k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) |
277 | 0 | #endif |
278 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
279 | 52.3k | } else |
280 | 181k | #endif |
281 | 181k | { |
282 | 181k | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
283 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
284 | 181k | } |
285 | | |
286 | 233k | post = (my_post_ptr) |
287 | 233k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
288 | 233k | sizeof(my_post_controller)); |
289 | 233k | cinfo->post = (struct jpeg_d_post_controller *)post; |
290 | 233k | post->pub.start_pass = start_pass_dpost; |
291 | 233k | post->whole_image = NULL; /* flag for no virtual arrays */ |
292 | 233k | post->buffer = NULL; /* flag for no strip buffer */ |
293 | | |
294 | | /* Create the quantization buffer, if needed */ |
295 | 233k | if (cinfo->quantize_colors) { |
296 | | #if BITS_IN_JSAMPLE != 16 |
297 | | /* The buffer strip height is max_v_samp_factor, which is typically |
298 | | * an efficient number of rows for upsampling to return. |
299 | | * (In the presence of output rescaling, we might want to be smarter?) |
300 | | */ |
301 | | post->strip_height = (JDIMENSION)cinfo->max_v_samp_factor; |
302 | 0 | if (need_full_buffer) { |
303 | | /* Two-pass color quantization: need full-image storage. */ |
304 | | /* We round up the number of rows to a multiple of the strip height. */ |
305 | 0 | #ifdef QUANT_2PASS_SUPPORTED |
306 | 0 | post->whole_image = (*cinfo->mem->request_virt_sarray) |
307 | 0 | ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, |
308 | 0 | cinfo->output_width * cinfo->out_color_components, |
309 | 0 | (JDIMENSION)jround_up((long)cinfo->output_height, |
310 | 0 | (long)post->strip_height), |
311 | 0 | post->strip_height); |
312 | | #else |
313 | | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); |
314 | | #endif /* QUANT_2PASS_SUPPORTED */ |
315 | 0 | } else { |
316 | | /* One-pass color quantization: just make a strip buffer. */ |
317 | 0 | post->buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) |
318 | 0 | ((j_common_ptr)cinfo, JPOOL_IMAGE, |
319 | 0 | cinfo->output_width * cinfo->out_color_components, |
320 | 0 | post->strip_height); |
321 | 0 | } |
322 | | #else |
323 | 0 | ERREXIT(cinfo, JERR_NOTIMPL); |
324 | | #endif |
325 | 0 | } |
326 | 233k | } Line | Count | Source | 267 | 194k | { | 268 | 194k | my_post_ptr post; | 269 | | | 270 | 194k | #ifdef D_LOSSLESS_SUPPORTED | 271 | 194k | if (cinfo->master->lossless) { | 272 | 35.7k | #if BITS_IN_JSAMPLE == 8 | 273 | 35.7k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 274 | | #else | 275 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 276 | | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 277 | | #endif | 278 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 279 | 35.7k | } else | 280 | 158k | #endif | 281 | 158k | { | 282 | 158k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 283 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 284 | 158k | } | 285 | | | 286 | 194k | post = (my_post_ptr) | 287 | 194k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 288 | 194k | sizeof(my_post_controller)); | 289 | 194k | cinfo->post = (struct jpeg_d_post_controller *)post; | 290 | 194k | post->pub.start_pass = start_pass_dpost; | 291 | 194k | post->whole_image = NULL; /* flag for no virtual arrays */ | 292 | 194k | post->buffer = NULL; /* flag for no strip buffer */ | 293 | | | 294 | | /* Create the quantization buffer, if needed */ | 295 | 194k | if (cinfo->quantize_colors) { | 296 | 0 | #if BITS_IN_JSAMPLE != 16 | 297 | | /* The buffer strip height is max_v_samp_factor, which is typically | 298 | | * an efficient number of rows for upsampling to return. | 299 | | * (In the presence of output rescaling, we might want to be smarter?) | 300 | | */ | 301 | 0 | post->strip_height = (JDIMENSION)cinfo->max_v_samp_factor; | 302 | 0 | if (need_full_buffer) { | 303 | | /* Two-pass color quantization: need full-image storage. */ | 304 | | /* We round up the number of rows to a multiple of the strip height. */ | 305 | 0 | #ifdef QUANT_2PASS_SUPPORTED | 306 | 0 | post->whole_image = (*cinfo->mem->request_virt_sarray) | 307 | 0 | ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, | 308 | 0 | cinfo->output_width * cinfo->out_color_components, | 309 | 0 | (JDIMENSION)jround_up((long)cinfo->output_height, | 310 | 0 | (long)post->strip_height), | 311 | 0 | post->strip_height); | 312 | | #else | 313 | | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 314 | | #endif /* QUANT_2PASS_SUPPORTED */ | 315 | 0 | } else { | 316 | | /* One-pass color quantization: just make a strip buffer. */ | 317 | 0 | post->buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 318 | 0 | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 319 | 0 | cinfo->output_width * cinfo->out_color_components, | 320 | 0 | post->strip_height); | 321 | 0 | } | 322 | | #else | 323 | | ERREXIT(cinfo, JERR_NOTIMPL); | 324 | | #endif | 325 | 0 | } | 326 | 194k | } |
j12init_d_post_controller Line | Count | Source | 267 | 30.1k | { | 268 | 30.1k | my_post_ptr post; | 269 | | | 270 | 30.1k | #ifdef D_LOSSLESS_SUPPORTED | 271 | 30.1k | if (cinfo->master->lossless) { | 272 | | #if BITS_IN_JSAMPLE == 8 | 273 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 274 | | #else | 275 | 7.77k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 276 | 7.77k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 277 | 0 | #endif | 278 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 279 | 7.77k | } else | 280 | 22.3k | #endif | 281 | 22.3k | { | 282 | 22.3k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 283 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 284 | 22.3k | } | 285 | | | 286 | 30.1k | post = (my_post_ptr) | 287 | 30.1k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 288 | 30.1k | sizeof(my_post_controller)); | 289 | 30.1k | cinfo->post = (struct jpeg_d_post_controller *)post; | 290 | 30.1k | post->pub.start_pass = start_pass_dpost; | 291 | 30.1k | post->whole_image = NULL; /* flag for no virtual arrays */ | 292 | 30.1k | post->buffer = NULL; /* flag for no strip buffer */ | 293 | | | 294 | | /* Create the quantization buffer, if needed */ | 295 | 30.1k | if (cinfo->quantize_colors) { | 296 | 0 | #if BITS_IN_JSAMPLE != 16 | 297 | | /* The buffer strip height is max_v_samp_factor, which is typically | 298 | | * an efficient number of rows for upsampling to return. | 299 | | * (In the presence of output rescaling, we might want to be smarter?) | 300 | | */ | 301 | 0 | post->strip_height = (JDIMENSION)cinfo->max_v_samp_factor; | 302 | 0 | if (need_full_buffer) { | 303 | | /* Two-pass color quantization: need full-image storage. */ | 304 | | /* We round up the number of rows to a multiple of the strip height. */ | 305 | 0 | #ifdef QUANT_2PASS_SUPPORTED | 306 | 0 | post->whole_image = (*cinfo->mem->request_virt_sarray) | 307 | 0 | ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, | 308 | 0 | cinfo->output_width * cinfo->out_color_components, | 309 | 0 | (JDIMENSION)jround_up((long)cinfo->output_height, | 310 | 0 | (long)post->strip_height), | 311 | 0 | post->strip_height); | 312 | | #else | 313 | | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 314 | | #endif /* QUANT_2PASS_SUPPORTED */ | 315 | 0 | } else { | 316 | | /* One-pass color quantization: just make a strip buffer. */ | 317 | 0 | post->buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 318 | 0 | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 319 | 0 | cinfo->output_width * cinfo->out_color_components, | 320 | 0 | post->strip_height); | 321 | 0 | } | 322 | | #else | 323 | | ERREXIT(cinfo, JERR_NOTIMPL); | 324 | | #endif | 325 | 0 | } | 326 | 30.1k | } |
j16init_d_post_controller Line | Count | Source | 267 | 8.82k | { | 268 | 8.82k | my_post_ptr post; | 269 | | | 270 | 8.82k | #ifdef D_LOSSLESS_SUPPORTED | 271 | 8.82k | if (cinfo->master->lossless) { | 272 | | #if BITS_IN_JSAMPLE == 8 | 273 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 274 | | #else | 275 | 8.82k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 276 | 8.82k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 277 | 0 | #endif | 278 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 279 | 8.82k | } else | 280 | 0 | #endif | 281 | 0 | { | 282 | 0 | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 283 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 284 | 0 | } | 285 | | | 286 | 8.82k | post = (my_post_ptr) | 287 | 8.82k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 288 | 8.82k | sizeof(my_post_controller)); | 289 | 8.82k | cinfo->post = (struct jpeg_d_post_controller *)post; | 290 | 8.82k | post->pub.start_pass = start_pass_dpost; | 291 | 8.82k | post->whole_image = NULL; /* flag for no virtual arrays */ | 292 | 8.82k | post->buffer = NULL; /* flag for no strip buffer */ | 293 | | | 294 | | /* Create the quantization buffer, if needed */ | 295 | 8.82k | if (cinfo->quantize_colors) { | 296 | | #if BITS_IN_JSAMPLE != 16 | 297 | | /* The buffer strip height is max_v_samp_factor, which is typically | 298 | | * an efficient number of rows for upsampling to return. | 299 | | * (In the presence of output rescaling, we might want to be smarter?) | 300 | | */ | 301 | | post->strip_height = (JDIMENSION)cinfo->max_v_samp_factor; | 302 | | if (need_full_buffer) { | 303 | | /* Two-pass color quantization: need full-image storage. */ | 304 | | /* We round up the number of rows to a multiple of the strip height. */ | 305 | | #ifdef QUANT_2PASS_SUPPORTED | 306 | | post->whole_image = (*cinfo->mem->request_virt_sarray) | 307 | | ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, | 308 | | cinfo->output_width * cinfo->out_color_components, | 309 | | (JDIMENSION)jround_up((long)cinfo->output_height, | 310 | | (long)post->strip_height), | 311 | | post->strip_height); | 312 | | #else | 313 | | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 314 | | #endif /* QUANT_2PASS_SUPPORTED */ | 315 | | } else { | 316 | | /* One-pass color quantization: just make a strip buffer. */ | 317 | | post->buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 318 | | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 319 | | cinfo->output_width * cinfo->out_color_components, | 320 | | post->strip_height); | 321 | | } | 322 | | #else | 323 | 0 | ERREXIT(cinfo, JERR_NOTIMPL); | 324 | 0 | #endif | 325 | 0 | } | 326 | 8.82k | } |
|
327 | | |
328 | | #endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */ |