/src/libjpeg-turbo.dev/src/jdsample.c
Line | Count | Source |
1 | | /* |
2 | | * jdsample.c |
3 | | * |
4 | | * This file was part of the Independent JPEG Group's software: |
5 | | * Copyright (C) 1991-1996, Thomas G. Lane. |
6 | | * libjpeg-turbo Modifications: |
7 | | * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
8 | | * Copyright (C) 2010, 2015-2016, 2022, 2024-2025, D. R. Commander. |
9 | | * Copyright (C) 2014, MIPS Technologies, Inc., California. |
10 | | * Copyright (C) 2015, Google, Inc. |
11 | | * Copyright (C) 2019-2020, Arm Limited. |
12 | | * For conditions of distribution and use, see the accompanying README.ijg |
13 | | * file. |
14 | | * |
15 | | * This file contains upsampling routines. |
16 | | * |
17 | | * Upsampling input data is counted in "row groups". A row group |
18 | | * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size) |
19 | | * sample rows of each component. Upsampling will normally produce |
20 | | * max_v_samp_factor pixel rows from each row group (but this could vary |
21 | | * if the upsampler is applying a scale factor of its own). |
22 | | * |
23 | | * An excellent reference for image resampling is |
24 | | * Digital Image Warping, George Wolberg, 1990. |
25 | | * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. |
26 | | */ |
27 | | |
28 | | #include "jinclude.h" |
29 | | #include "jdsample.h" |
30 | | #ifdef WITH_SIMD |
31 | | #include "../simd/jsimd.h" |
32 | | #endif |
33 | | #include "jpegapicomp.h" |
34 | | #ifdef WITH_PROFILE |
35 | | #include "tjutil.h" |
36 | | #endif |
37 | | |
38 | | |
39 | | |
40 | | #if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) |
41 | | |
42 | | /* |
43 | | * Initialize for an upsampling pass. |
44 | | */ |
45 | | |
46 | | METHODDEF(void) |
47 | | start_pass_upsample(j_decompress_ptr cinfo) |
48 | 0 | { |
49 | 0 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; |
50 | | |
51 | | /* Mark the conversion buffer empty */ |
52 | 0 | upsample->next_row_out = cinfo->max_v_samp_factor; |
53 | | /* Initialize total-height counter for detecting bottom of image */ |
54 | 0 | upsample->rows_to_go = cinfo->output_height; |
55 | 0 | } Unexecuted instantiation: jdsample-8.c:start_pass_upsample Unexecuted instantiation: jdsample-12.c:start_pass_upsample Unexecuted instantiation: jdsample-16.c:start_pass_upsample |
56 | | |
57 | | |
58 | | /* |
59 | | * Control routine to do upsampling (and color conversion). |
60 | | * |
61 | | * In this version we upsample each component independently. |
62 | | * We upsample one row group into the conversion buffer, then apply |
63 | | * color conversion a row at a time. |
64 | | */ |
65 | | |
66 | | METHODDEF(void) |
67 | | sep_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf, |
68 | | JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail, |
69 | | _JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, |
70 | | JDIMENSION out_rows_avail) |
71 | 0 | { |
72 | 0 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; |
73 | 0 | int ci; |
74 | 0 | jpeg_component_info *compptr; |
75 | 0 | JDIMENSION num_rows; |
76 | | |
77 | | /* Fill the conversion buffer, if it's empty */ |
78 | 0 | if (upsample->next_row_out >= cinfo->max_v_samp_factor) { |
79 | 0 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
80 | 0 | ci++, compptr++) { |
81 | | /* Invoke per-component upsample method. Notice we pass a POINTER |
82 | | * to color_buf[ci], so that fullsize_upsample can change it. |
83 | | */ |
84 | | #ifdef WITH_PROFILE |
85 | | cinfo->master->start = getTime(); |
86 | | #endif |
87 | 0 | (*upsample->methods[ci]) (cinfo, compptr, |
88 | 0 | input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]), |
89 | 0 | upsample->color_buf + ci); |
90 | | #ifdef WITH_PROFILE |
91 | | cinfo->master->upsample_elapsed += getTime() - cinfo->master->start; |
92 | | cinfo->master->upsample_msamples += |
93 | | (double)cinfo->output_width * cinfo->max_v_samp_factor / 1000000.; |
94 | | #endif |
95 | 0 | } |
96 | 0 | upsample->next_row_out = 0; |
97 | 0 | } |
98 | | |
99 | | /* Color-convert and emit rows */ |
100 | | |
101 | | /* How many we have in the buffer: */ |
102 | 0 | num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out); |
103 | | /* Not more than the distance to the end of the image. Need this test |
104 | | * in case the image height is not a multiple of max_v_samp_factor: |
105 | | */ |
106 | 0 | if (num_rows > upsample->rows_to_go) |
107 | 0 | num_rows = upsample->rows_to_go; |
108 | | /* And not more than what the client can accept: */ |
109 | 0 | out_rows_avail -= *out_row_ctr; |
110 | 0 | if (num_rows > out_rows_avail) |
111 | 0 | num_rows = out_rows_avail; |
112 | |
|
113 | | #ifdef WITH_PROFILE |
114 | | cinfo->master->start = getTime(); |
115 | | #endif |
116 | 0 | (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf, |
117 | 0 | (JDIMENSION)upsample->next_row_out, |
118 | 0 | output_buf + *out_row_ctr, |
119 | 0 | (int)num_rows); |
120 | | #ifdef WITH_PROFILE |
121 | | cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start; |
122 | | cinfo->master->cconvert_mpixels += |
123 | | (double)cinfo->output_width * num_rows / 1000000.; |
124 | | #endif |
125 | | |
126 | | /* Adjust counts */ |
127 | 0 | *out_row_ctr += num_rows; |
128 | 0 | upsample->rows_to_go -= num_rows; |
129 | 0 | upsample->next_row_out += num_rows; |
130 | | /* When the buffer is emptied, declare this input row group consumed */ |
131 | 0 | if (upsample->next_row_out >= cinfo->max_v_samp_factor) |
132 | 0 | (*in_row_group_ctr)++; |
133 | 0 | } Unexecuted instantiation: jdsample-8.c:sep_upsample Unexecuted instantiation: jdsample-12.c:sep_upsample Unexecuted instantiation: jdsample-16.c:sep_upsample |
134 | | |
135 | | |
136 | | /* |
137 | | * These are the routines invoked by sep_upsample to upsample pixel values |
138 | | * of a single component. One row group is processed per call. |
139 | | */ |
140 | | |
141 | | |
142 | | /* |
143 | | * For full-size components, we just make color_buf[ci] point at the |
144 | | * input buffer, and thus avoid copying any data. Note that this is |
145 | | * safe only because sep_upsample doesn't declare the input row group |
146 | | * "consumed" until we are done color converting and emitting it. |
147 | | */ |
148 | | |
149 | | METHODDEF(void) |
150 | | fullsize_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
151 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
152 | 0 | { |
153 | 0 | *output_data_ptr = input_data; |
154 | 0 | } Unexecuted instantiation: jdsample-8.c:fullsize_upsample Unexecuted instantiation: jdsample-12.c:fullsize_upsample Unexecuted instantiation: jdsample-16.c:fullsize_upsample |
155 | | |
156 | | |
157 | | /* |
158 | | * This is a no-op version used for "uninteresting" components. |
159 | | * These components will not be referenced by color conversion. |
160 | | */ |
161 | | |
162 | | METHODDEF(void) |
163 | | noop_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
164 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
165 | 0 | { |
166 | 0 | *output_data_ptr = NULL; /* safety check */ |
167 | 0 | } Unexecuted instantiation: jdsample-8.c:noop_upsample Unexecuted instantiation: jdsample-12.c:noop_upsample Unexecuted instantiation: jdsample-16.c:noop_upsample |
168 | | |
169 | | |
170 | | /* |
171 | | * This version handles any integral sampling ratios. |
172 | | * This is not used for typical JPEG files, so it need not be fast. |
173 | | * Nor, for that matter, is it particularly accurate: the algorithm is |
174 | | * simple replication of the input pixel onto the corresponding output |
175 | | * pixels. The hi-falutin sampling literature refers to this as a |
176 | | * "box filter". A box filter tends to introduce visible artifacts, |
177 | | * so if you are actually going to use 3:1 or 4:1 sampling ratios |
178 | | * you would be well advised to improve this code. |
179 | | */ |
180 | | |
181 | | METHODDEF(void) |
182 | | int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
183 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
184 | 0 | { |
185 | 0 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; |
186 | 0 | _JSAMPARRAY output_data = *output_data_ptr; |
187 | 0 | register _JSAMPROW inptr, outptr; |
188 | 0 | register _JSAMPLE invalue; |
189 | 0 | register int h; |
190 | 0 | _JSAMPROW outend; |
191 | 0 | int h_expand, v_expand; |
192 | 0 | int inrow, outrow; |
193 | |
|
194 | 0 | h_expand = upsample->h_expand[compptr->component_index]; |
195 | 0 | v_expand = upsample->v_expand[compptr->component_index]; |
196 | |
|
197 | 0 | inrow = outrow = 0; |
198 | 0 | while (outrow < cinfo->max_v_samp_factor) { |
199 | | /* Generate one output row with proper horizontal expansion */ |
200 | 0 | inptr = input_data[inrow]; |
201 | 0 | outptr = output_data[outrow]; |
202 | 0 | outend = outptr + cinfo->output_width; |
203 | 0 | while (outptr < outend) { |
204 | 0 | invalue = *inptr++; |
205 | 0 | for (h = h_expand; h > 0; h--) { |
206 | 0 | *outptr++ = invalue; |
207 | 0 | } |
208 | 0 | } |
209 | | /* Generate any additional output rows by duplicating the first one */ |
210 | 0 | if (v_expand > 1) { |
211 | 0 | _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, |
212 | 0 | v_expand - 1, cinfo->output_width); |
213 | 0 | } |
214 | 0 | inrow++; |
215 | 0 | outrow += v_expand; |
216 | 0 | } |
217 | 0 | } Unexecuted instantiation: jdsample-8.c:int_upsample Unexecuted instantiation: jdsample-12.c:int_upsample Unexecuted instantiation: jdsample-16.c:int_upsample |
218 | | |
219 | | |
220 | | /* |
221 | | * Fast processing for the common case of 2:1 horizontal and 1:1 vertical. |
222 | | * It's still a box filter. |
223 | | */ |
224 | | |
225 | | METHODDEF(void) |
226 | | h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
227 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
228 | 0 | { |
229 | 0 | _JSAMPARRAY output_data = *output_data_ptr; |
230 | 0 | register _JSAMPROW inptr, outptr; |
231 | 0 | register _JSAMPLE invalue; |
232 | 0 | _JSAMPROW outend; |
233 | 0 | int inrow; |
234 | |
|
235 | 0 | for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) { |
236 | 0 | inptr = input_data[inrow]; |
237 | 0 | outptr = output_data[inrow]; |
238 | 0 | outend = outptr + cinfo->output_width; |
239 | 0 | while (outptr < outend) { |
240 | 0 | invalue = *inptr++; |
241 | 0 | *outptr++ = invalue; |
242 | 0 | *outptr++ = invalue; |
243 | 0 | } |
244 | 0 | } |
245 | 0 | } Unexecuted instantiation: jdsample-8.c:h2v1_upsample Unexecuted instantiation: jdsample-12.c:h2v1_upsample Unexecuted instantiation: jdsample-16.c:h2v1_upsample |
246 | | |
247 | | |
248 | | /* |
249 | | * Fast processing for the common case of 2:1 horizontal and 2:1 vertical. |
250 | | * It's still a box filter. |
251 | | */ |
252 | | |
253 | | METHODDEF(void) |
254 | | h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
255 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
256 | 0 | { |
257 | 0 | _JSAMPARRAY output_data = *output_data_ptr; |
258 | 0 | register _JSAMPROW inptr, outptr; |
259 | 0 | register _JSAMPLE invalue; |
260 | 0 | _JSAMPROW outend; |
261 | 0 | int inrow, outrow; |
262 | |
|
263 | 0 | inrow = outrow = 0; |
264 | 0 | while (outrow < cinfo->max_v_samp_factor) { |
265 | 0 | inptr = input_data[inrow]; |
266 | 0 | outptr = output_data[outrow]; |
267 | 0 | outend = outptr + cinfo->output_width; |
268 | 0 | while (outptr < outend) { |
269 | 0 | invalue = *inptr++; |
270 | 0 | *outptr++ = invalue; |
271 | 0 | *outptr++ = invalue; |
272 | 0 | } |
273 | 0 | _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1, |
274 | 0 | cinfo->output_width); |
275 | 0 | inrow++; |
276 | 0 | outrow += 2; |
277 | 0 | } |
278 | 0 | } Unexecuted instantiation: jdsample-8.c:h2v2_upsample Unexecuted instantiation: jdsample-12.c:h2v2_upsample Unexecuted instantiation: jdsample-16.c:h2v2_upsample |
279 | | |
280 | | |
281 | | /* |
282 | | * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical. |
283 | | * |
284 | | * The upsampling algorithm is linear interpolation between pixel centers, |
285 | | * also known as a "triangle filter". This is a good compromise between |
286 | | * speed and visual quality. The centers of the output pixels are 1/4 and 3/4 |
287 | | * of the way between input pixel centers. |
288 | | * |
289 | | * A note about the "bias" calculations: when rounding fractional values to |
290 | | * integer, we do not want to always round 0.5 up to the next integer. |
291 | | * If we did that, we'd introduce a noticeable bias towards larger values. |
292 | | * Instead, this code is arranged so that 0.5 will be rounded up or down at |
293 | | * alternate pixel locations (a simple ordered dither pattern). |
294 | | */ |
295 | | |
296 | | METHODDEF(void) |
297 | | h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
298 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
299 | 0 | { |
300 | 0 | _JSAMPARRAY output_data = *output_data_ptr; |
301 | 0 | register _JSAMPROW inptr, outptr; |
302 | 0 | register int invalue; |
303 | 0 | register JDIMENSION colctr; |
304 | 0 | int inrow; |
305 | |
|
306 | 0 | for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) { |
307 | 0 | inptr = input_data[inrow]; |
308 | 0 | outptr = output_data[inrow]; |
309 | | /* Special case for first column */ |
310 | 0 | invalue = *inptr++; |
311 | 0 | *outptr++ = (_JSAMPLE)invalue; |
312 | 0 | *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2); |
313 | |
|
314 | 0 | for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { |
315 | | /* General case: 3/4 * nearer pixel + 1/4 * further pixel */ |
316 | 0 | invalue = (*inptr++) * 3; |
317 | 0 | *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2); |
318 | 0 | *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2); |
319 | 0 | } |
320 | | |
321 | | /* Special case for last column */ |
322 | 0 | invalue = *inptr; |
323 | 0 | *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2); |
324 | 0 | *outptr++ = (_JSAMPLE)invalue; |
325 | 0 | } |
326 | 0 | } Unexecuted instantiation: jdsample-8.c:h2v1_fancy_upsample Unexecuted instantiation: jdsample-12.c:h2v1_fancy_upsample Unexecuted instantiation: jdsample-16.c:h2v1_fancy_upsample |
327 | | |
328 | | |
329 | | /* |
330 | | * Fancy processing for 1:1 horizontal and 2:1 vertical (4:4:0 subsampling). |
331 | | * |
332 | | * This is a less common case, but it can be encountered when losslessly |
333 | | * rotating/transposing a JPEG file that uses 4:2:2 chroma subsampling. |
334 | | */ |
335 | | |
336 | | METHODDEF(void) |
337 | | h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
338 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
339 | 0 | { |
340 | 0 | _JSAMPARRAY output_data = *output_data_ptr; |
341 | 0 | _JSAMPROW inptr0, inptr1, outptr; |
342 | | #if BITS_IN_JSAMPLE == 8 |
343 | | int thiscolsum, bias; |
344 | | #else |
345 | | JLONG thiscolsum, bias; |
346 | | #endif |
347 | 0 | JDIMENSION colctr; |
348 | 0 | int inrow, outrow, v; |
349 | |
|
350 | 0 | inrow = outrow = 0; |
351 | 0 | while (outrow < cinfo->max_v_samp_factor) { |
352 | 0 | for (v = 0; v < 2; v++) { |
353 | | /* inptr0 points to nearest input row, inptr1 points to next nearest */ |
354 | 0 | inptr0 = input_data[inrow]; |
355 | 0 | if (v == 0) { /* next nearest is row above */ |
356 | 0 | inptr1 = input_data[inrow - 1]; |
357 | 0 | bias = 1; |
358 | 0 | } else { /* next nearest is row below */ |
359 | 0 | inptr1 = input_data[inrow + 1]; |
360 | 0 | bias = 2; |
361 | 0 | } |
362 | 0 | outptr = output_data[outrow++]; |
363 | |
|
364 | 0 | for (colctr = 0; colctr < compptr->downsampled_width; colctr++) { |
365 | 0 | thiscolsum = (*inptr0++) * 3 + (*inptr1++); |
366 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2); |
367 | 0 | } |
368 | 0 | } |
369 | 0 | inrow++; |
370 | 0 | } |
371 | 0 | } Unexecuted instantiation: jdsample-8.c:h1v2_fancy_upsample Unexecuted instantiation: jdsample-12.c:h1v2_fancy_upsample Unexecuted instantiation: jdsample-16.c:h1v2_fancy_upsample |
372 | | |
373 | | |
374 | | /* |
375 | | * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical. |
376 | | * Again a triangle filter; see comments for h2v1 case, above. |
377 | | * |
378 | | * It is OK for us to reference the adjacent input rows because we demanded |
379 | | * context from the main buffer controller (see initialization code). |
380 | | */ |
381 | | |
382 | | METHODDEF(void) |
383 | | h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
384 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
385 | 0 | { |
386 | 0 | _JSAMPARRAY output_data = *output_data_ptr; |
387 | 0 | register _JSAMPROW inptr0, inptr1, outptr; |
388 | | #if BITS_IN_JSAMPLE == 8 |
389 | | register int thiscolsum, lastcolsum, nextcolsum; |
390 | | #else |
391 | | register JLONG thiscolsum, lastcolsum, nextcolsum; |
392 | | #endif |
393 | 0 | register JDIMENSION colctr; |
394 | 0 | int inrow, outrow, v; |
395 | |
|
396 | 0 | inrow = outrow = 0; |
397 | 0 | while (outrow < cinfo->max_v_samp_factor) { |
398 | 0 | for (v = 0; v < 2; v++) { |
399 | | /* inptr0 points to nearest input row, inptr1 points to next nearest */ |
400 | 0 | inptr0 = input_data[inrow]; |
401 | 0 | if (v == 0) /* next nearest is row above */ |
402 | 0 | inptr1 = input_data[inrow - 1]; |
403 | 0 | else /* next nearest is row below */ |
404 | 0 | inptr1 = input_data[inrow + 1]; |
405 | 0 | outptr = output_data[outrow++]; |
406 | | |
407 | | /* Special case for first column */ |
408 | 0 | thiscolsum = (*inptr0++) * 3 + (*inptr1++); |
409 | 0 | nextcolsum = (*inptr0++) * 3 + (*inptr1++); |
410 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4); |
411 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4); |
412 | 0 | lastcolsum = thiscolsum; thiscolsum = nextcolsum; |
413 | |
|
414 | 0 | for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { |
415 | | /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */ |
416 | | /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */ |
417 | 0 | nextcolsum = (*inptr0++) * 3 + (*inptr1++); |
418 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4); |
419 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4); |
420 | 0 | lastcolsum = thiscolsum; thiscolsum = nextcolsum; |
421 | 0 | } |
422 | | |
423 | | /* Special case for last column */ |
424 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4); |
425 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4); |
426 | 0 | } |
427 | 0 | inrow++; |
428 | 0 | } |
429 | 0 | } Unexecuted instantiation: jdsample-8.c:h2v2_fancy_upsample Unexecuted instantiation: jdsample-12.c:h2v2_fancy_upsample Unexecuted instantiation: jdsample-16.c:h2v2_fancy_upsample |
430 | | |
431 | | |
432 | | /* |
433 | | * Module initialization routine for upsampling. |
434 | | */ |
435 | | |
436 | | GLOBAL(void) |
437 | | _jinit_upsampler(j_decompress_ptr cinfo) |
438 | 0 | { |
439 | 0 | my_upsample_ptr upsample; |
440 | 0 | int ci; |
441 | 0 | jpeg_component_info *compptr; |
442 | 0 | boolean need_buffer, do_fancy; |
443 | 0 | int h_in_group, v_in_group, h_out_group, v_out_group; |
444 | |
|
445 | 0 | #ifdef D_LOSSLESS_SUPPORTED |
446 | 0 | if (cinfo->master->lossless) { |
447 | | #if BITS_IN_JSAMPLE == 8 |
448 | 0 | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
449 | | #else |
450 | 0 | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
451 | 0 | cinfo->data_precision < BITS_IN_JSAMPLE - 3) |
452 | 0 | #endif |
453 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
454 | 0 | } else |
455 | 0 | #endif |
456 | 0 | { |
457 | 0 | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
458 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
459 | 0 | } |
460 | |
|
461 | 0 | if (!cinfo->master->jinit_upsampler_no_alloc) { |
462 | 0 | upsample = (my_upsample_ptr) |
463 | 0 | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
464 | 0 | sizeof(my_upsampler)); |
465 | 0 | cinfo->upsample = (struct jpeg_upsampler *)upsample; |
466 | 0 | upsample->pub.start_pass = start_pass_upsample; |
467 | 0 | upsample->pub._upsample = sep_upsample; |
468 | 0 | upsample->pub.need_context_rows = FALSE; /* until we find out differently */ |
469 | 0 | } else |
470 | 0 | upsample = (my_upsample_ptr)cinfo->upsample; |
471 | |
|
472 | 0 | if (cinfo->CCIR601_sampling) /* this isn't supported */ |
473 | 0 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); |
474 | | |
475 | | /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, |
476 | | * so don't ask for it. |
477 | | */ |
478 | 0 | do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1; |
479 | | |
480 | | /* Verify we can handle the sampling factors, select per-component methods, |
481 | | * and create storage as needed. |
482 | | */ |
483 | 0 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
484 | 0 | ci++, compptr++) { |
485 | | /* Compute size of an "input group" after IDCT scaling. This many samples |
486 | | * are to be converted to max_h_samp_factor * max_v_samp_factor pixels. |
487 | | */ |
488 | 0 | h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) / |
489 | 0 | cinfo->_min_DCT_scaled_size; |
490 | 0 | v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / |
491 | 0 | cinfo->_min_DCT_scaled_size; |
492 | 0 | h_out_group = cinfo->max_h_samp_factor; |
493 | 0 | v_out_group = cinfo->max_v_samp_factor; |
494 | 0 | upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ |
495 | 0 | need_buffer = TRUE; |
496 | 0 | if (!compptr->component_needed) { |
497 | | /* Don't bother to upsample an uninteresting component. */ |
498 | 0 | upsample->methods[ci] = noop_upsample; |
499 | 0 | need_buffer = FALSE; |
500 | 0 | } else if (h_in_group == h_out_group && v_in_group == v_out_group) { |
501 | | /* Fullsize components can be processed without any work. */ |
502 | 0 | upsample->methods[ci] = fullsize_upsample; |
503 | 0 | need_buffer = FALSE; |
504 | 0 | } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) { |
505 | | /* Special cases for 2h1v upsampling */ |
506 | 0 | if (do_fancy && compptr->downsampled_width > 2) { |
507 | | #ifdef WITH_SIMD |
508 | 0 | if (jsimd_set_h2v1_fancy_upsample(cinfo)) |
509 | 0 | upsample->methods[ci] = jsimd_h2v1_fancy_upsample; |
510 | 0 | else |
511 | 0 | #endif |
512 | 0 | upsample->methods[ci] = h2v1_fancy_upsample; |
513 | 0 | } else { |
514 | | #ifdef WITH_SIMD |
515 | 0 | if (jsimd_set_h2v1_upsample(cinfo)) |
516 | 0 | upsample->methods[ci] = jsimd_h2v1_upsample; |
517 | 0 | else |
518 | 0 | #endif |
519 | 0 | upsample->methods[ci] = h2v1_upsample; |
520 | 0 | } |
521 | 0 | } else if (h_in_group == h_out_group && |
522 | 0 | v_in_group * 2 == v_out_group && do_fancy) { |
523 | | /* Non-fancy upsampling is handled by the generic method */ |
524 | | #if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM) |
525 | | if (jsimd_set_h1v2_fancy_upsample(cinfo)) |
526 | | upsample->methods[ci] = jsimd_h1v2_fancy_upsample; |
527 | | else |
528 | | #endif |
529 | 0 | upsample->methods[ci] = h1v2_fancy_upsample; |
530 | 0 | upsample->pub.need_context_rows = TRUE; |
531 | 0 | } else if (h_in_group * 2 == h_out_group && |
532 | 0 | v_in_group * 2 == v_out_group) { |
533 | | /* Special cases for 2h2v upsampling */ |
534 | 0 | if (do_fancy && compptr->downsampled_width > 2) { |
535 | | #ifdef WITH_SIMD |
536 | 0 | if (jsimd_set_h2v2_fancy_upsample(cinfo)) |
537 | 0 | upsample->methods[ci] = jsimd_h2v2_fancy_upsample; |
538 | 0 | else |
539 | 0 | #endif |
540 | 0 | upsample->methods[ci] = h2v2_fancy_upsample; |
541 | 0 | upsample->pub.need_context_rows = TRUE; |
542 | 0 | } else { |
543 | | #ifdef WITH_SIMD |
544 | 0 | if (jsimd_set_h2v2_upsample(cinfo)) |
545 | 0 | upsample->methods[ci] = jsimd_h2v2_upsample; |
546 | 0 | else |
547 | 0 | #endif |
548 | 0 | upsample->methods[ci] = h2v2_upsample; |
549 | 0 | } |
550 | 0 | } else if ((h_out_group % h_in_group) == 0 && |
551 | 0 | (v_out_group % v_in_group) == 0) { |
552 | | /* Generic integral-factors upsampling method */ |
553 | | #if defined(WITH_SIMD) && SIMD_ARCHITECTURE == MIPS |
554 | | if (jsimd_set_int_upsample(cinfo)) |
555 | | upsample->methods[ci] = jsimd_int_upsample; |
556 | | else |
557 | | #endif |
558 | 0 | upsample->methods[ci] = int_upsample; |
559 | 0 | upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group); |
560 | 0 | upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group); |
561 | 0 | } else |
562 | 0 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); |
563 | 0 | if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) { |
564 | 0 | upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) |
565 | 0 | ((j_common_ptr)cinfo, JPOOL_IMAGE, |
566 | 0 | (JDIMENSION)jround_up((long)cinfo->output_width, |
567 | 0 | (long)cinfo->max_h_samp_factor), |
568 | 0 | (JDIMENSION)cinfo->max_v_samp_factor); |
569 | 0 | } |
570 | 0 | } |
571 | 0 | } Unexecuted instantiation: jinit_upsampler Unexecuted instantiation: j12init_upsampler Unexecuted instantiation: j16init_upsampler |
572 | | |
573 | | #endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */ |