/src/libjpeg-turbo.3.0.x/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, 2026, 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 is defined to |
18 | | * be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size) sample rows of |
19 | | * each component. Upsampling will normally produce max_v_samp_factor rows of |
20 | | * each component from each row group (but this could vary if the upsampler is |
21 | | * 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 | | #include "jsimd.h" |
31 | | #include "jpegapicomp.h" |
32 | | |
33 | | |
34 | | |
35 | | #if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) |
36 | | |
37 | | /* |
38 | | * Initialize for an upsampling pass. |
39 | | */ |
40 | | |
41 | | METHODDEF(void) |
42 | | start_pass_upsample(j_decompress_ptr cinfo) |
43 | 12.9k | { |
44 | 12.9k | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; |
45 | | |
46 | | /* Mark the conversion buffer empty */ |
47 | 12.9k | upsample->next_row_out = cinfo->max_v_samp_factor; |
48 | | /* Initialize total-height counter for detecting bottom of image */ |
49 | 12.9k | upsample->rows_to_go = cinfo->output_height; |
50 | 12.9k | } |
51 | | |
52 | | |
53 | | /* |
54 | | * Control routine to do upsampling (and color conversion). |
55 | | * |
56 | | * In this version we upsample each component independently. |
57 | | * We upsample one row group into the conversion buffer, then apply |
58 | | * color conversion a row at a time. |
59 | | */ |
60 | | |
61 | | METHODDEF(void) |
62 | | sep_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf, |
63 | | JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail, |
64 | | _JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, |
65 | | JDIMENSION out_rows_avail) |
66 | 26.4M | { |
67 | 26.4M | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; |
68 | 26.4M | int ci; |
69 | 26.4M | jpeg_component_info *compptr; |
70 | 26.4M | JDIMENSION num_rows; |
71 | | |
72 | | /* Fill the conversion buffer, if it's empty */ |
73 | 26.4M | if (upsample->next_row_out >= cinfo->max_v_samp_factor) { |
74 | 71.7M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
75 | 45.3M | ci++, compptr++) { |
76 | | /* Invoke per-component upsample method. Notice we pass a POINTER |
77 | | * to color_buf[ci], so that fullsize_upsample can change it. |
78 | | */ |
79 | 45.3M | (*upsample->methods[ci]) (cinfo, compptr, |
80 | 45.3M | input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]), |
81 | 45.3M | upsample->color_buf + ci); |
82 | 45.3M | } |
83 | 26.4M | upsample->next_row_out = 0; |
84 | 26.4M | } |
85 | | |
86 | | /* Color-convert and emit rows */ |
87 | | |
88 | | /* How many we have in the buffer: */ |
89 | 26.4M | num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out); |
90 | | /* Not more than the distance to the end of the image. Need this test |
91 | | * in case the image height is not a multiple of max_v_samp_factor: |
92 | | */ |
93 | 26.4M | if (num_rows > upsample->rows_to_go) |
94 | 4.88k | num_rows = upsample->rows_to_go; |
95 | | /* And not more than what the client can accept: */ |
96 | 26.4M | out_rows_avail -= *out_row_ctr; |
97 | 26.4M | if (num_rows > out_rows_avail) |
98 | 0 | num_rows = out_rows_avail; |
99 | | |
100 | 26.4M | (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf, |
101 | 26.4M | (JDIMENSION)upsample->next_row_out, |
102 | 26.4M | output_buf + *out_row_ctr, |
103 | 26.4M | (int)num_rows); |
104 | | |
105 | | /* Adjust counts */ |
106 | 26.4M | *out_row_ctr += num_rows; |
107 | 26.4M | upsample->rows_to_go -= num_rows; |
108 | 26.4M | upsample->next_row_out += num_rows; |
109 | | /* When the buffer is emptied, declare this input row group consumed */ |
110 | 26.4M | if (upsample->next_row_out >= cinfo->max_v_samp_factor) |
111 | 26.4M | (*in_row_group_ctr)++; |
112 | 26.4M | } |
113 | | |
114 | | |
115 | | /* |
116 | | * These are the routines invoked by sep_upsample to upsample values of a |
117 | | * single component. One row group is processed per call. |
118 | | */ |
119 | | |
120 | | |
121 | | /* |
122 | | * For full-size components, we just make color_buf[ci] point at the |
123 | | * input buffer, and thus avoid copying any data. Note that this is |
124 | | * safe only because sep_upsample doesn't declare the input row group |
125 | | * "consumed" until we are done color converting and emitting it. |
126 | | */ |
127 | | |
128 | | METHODDEF(void) |
129 | | fullsize_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
130 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
131 | 28.2M | { |
132 | 28.2M | *output_data_ptr = input_data; |
133 | 28.2M | } |
134 | | |
135 | | |
136 | | /* |
137 | | * This is a no-op version used for "uninteresting" components. |
138 | | * These components will not be referenced by color conversion. |
139 | | */ |
140 | | |
141 | | METHODDEF(void) |
142 | | noop_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
143 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
144 | 7.20M | { |
145 | 7.20M | *output_data_ptr = NULL; /* safety check */ |
146 | 7.20M | } |
147 | | |
148 | | |
149 | | /* |
150 | | * This version handles any integral sampling ratios. |
151 | | * This is not used for typical JPEG files, so it need not be fast. Nor, for |
152 | | * that matter, is it particularly accurate: the algorithm is simple |
153 | | * replication of the input sample onto the corresponding output components. |
154 | | * The hi-falutin sampling literature refers to this as a "box filter". A box |
155 | | * filter tends to introduce visible artifacts, so if you are actually going to |
156 | | * use 3:1 or 4:1 sampling ratios you would be well advised to improve this |
157 | | * code. |
158 | | */ |
159 | | |
160 | | METHODDEF(void) |
161 | | int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
162 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
163 | 5.96M | { |
164 | 5.96M | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; |
165 | 5.96M | _JSAMPARRAY output_data = *output_data_ptr; |
166 | 5.96M | register _JSAMPROW inptr, outptr; |
167 | 5.96M | register _JSAMPLE invalue; |
168 | 5.96M | register int h; |
169 | 5.96M | _JSAMPROW outend; |
170 | 5.96M | int h_expand, v_expand; |
171 | 5.96M | int inrow, outrow; |
172 | | |
173 | 5.96M | h_expand = upsample->h_expand[compptr->component_index]; |
174 | 5.96M | v_expand = upsample->v_expand[compptr->component_index]; |
175 | | |
176 | 5.96M | inrow = outrow = 0; |
177 | 14.0M | while (outrow < cinfo->max_v_samp_factor) { |
178 | | /* Generate one output row with proper horizontal expansion */ |
179 | 8.11M | inptr = input_data[inrow]; |
180 | 8.11M | outptr = output_data[outrow]; |
181 | 8.11M | outend = outptr + cinfo->output_width; |
182 | 144M | while (outptr < outend) { |
183 | 136M | invalue = *inptr++; |
184 | 356M | for (h = h_expand; h > 0; h--) { |
185 | 220M | *outptr++ = invalue; |
186 | 220M | } |
187 | 136M | } |
188 | | /* Generate any additional output rows by duplicating the first one */ |
189 | 8.11M | if (v_expand > 1) { |
190 | 4.21M | _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, |
191 | 4.21M | v_expand - 1, cinfo->output_width); |
192 | 4.21M | } |
193 | 8.11M | inrow++; |
194 | 8.11M | outrow += v_expand; |
195 | 8.11M | } |
196 | 5.96M | } |
197 | | |
198 | | |
199 | | /* |
200 | | * Fast processing for the common case of 2:1 horizontal and 1:1 vertical. |
201 | | * It's still a box filter. |
202 | | */ |
203 | | |
204 | | METHODDEF(void) |
205 | | h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
206 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
207 | 1.35M | { |
208 | 1.35M | _JSAMPARRAY output_data = *output_data_ptr; |
209 | 1.35M | register _JSAMPROW inptr, outptr; |
210 | 1.35M | register _JSAMPLE invalue; |
211 | 1.35M | _JSAMPROW outend; |
212 | 1.35M | int inrow; |
213 | | |
214 | 4.00M | for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) { |
215 | 2.65M | inptr = input_data[inrow]; |
216 | 2.65M | outptr = output_data[inrow]; |
217 | 2.65M | outend = outptr + cinfo->output_width; |
218 | 23.6M | while (outptr < outend) { |
219 | 21.0M | invalue = *inptr++; |
220 | 21.0M | *outptr++ = invalue; |
221 | 21.0M | *outptr++ = invalue; |
222 | 21.0M | } |
223 | 2.65M | } |
224 | 1.35M | } |
225 | | |
226 | | |
227 | | /* |
228 | | * Fast processing for the common case of 2:1 horizontal and 2:1 vertical. |
229 | | * It's still a box filter. |
230 | | */ |
231 | | |
232 | | METHODDEF(void) |
233 | | h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
234 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
235 | 389k | { |
236 | 389k | _JSAMPARRAY output_data = *output_data_ptr; |
237 | 389k | register _JSAMPROW inptr, outptr; |
238 | 389k | register _JSAMPLE invalue; |
239 | 389k | _JSAMPROW outend; |
240 | 389k | int inrow, outrow; |
241 | | |
242 | 389k | inrow = outrow = 0; |
243 | 904k | while (outrow < cinfo->max_v_samp_factor) { |
244 | 514k | inptr = input_data[inrow]; |
245 | 514k | outptr = output_data[outrow]; |
246 | 514k | outend = outptr + cinfo->output_width; |
247 | 10.4M | while (outptr < outend) { |
248 | 9.97M | invalue = *inptr++; |
249 | 9.97M | *outptr++ = invalue; |
250 | 9.97M | *outptr++ = invalue; |
251 | 9.97M | } |
252 | 514k | _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1, |
253 | 514k | cinfo->output_width); |
254 | 514k | inrow++; |
255 | 514k | outrow += 2; |
256 | 514k | } |
257 | 389k | } |
258 | | |
259 | | |
260 | | /* |
261 | | * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical. |
262 | | * |
263 | | * The upsampling algorithm is linear interpolation between component centers, |
264 | | * also known as a "triangle filter". This is a good compromise between speed |
265 | | * and visual quality. The centers of the output components are 1/4 and 3/4 of |
266 | | * the way between input component centers. |
267 | | * |
268 | | * A note about the "bias" calculations: when rounding fractional values to |
269 | | * integer, we do not want to always round 0.5 up to the next integer. |
270 | | * If we did that, we'd introduce a noticeable bias towards larger values. |
271 | | * Instead, this code is arranged so that 0.5 will be rounded up or down at |
272 | | * alternate pixel locations (a simple ordered dither pattern). |
273 | | */ |
274 | | |
275 | | METHODDEF(void) |
276 | | h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
277 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
278 | 155k | { |
279 | 155k | _JSAMPARRAY output_data = *output_data_ptr; |
280 | 155k | register _JSAMPROW inptr, outptr; |
281 | 155k | register int invalue; |
282 | 155k | register JDIMENSION colctr; |
283 | 155k | int inrow; |
284 | | |
285 | 728k | for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) { |
286 | 573k | inptr = input_data[inrow]; |
287 | 573k | outptr = output_data[inrow]; |
288 | | /* Special case for first column */ |
289 | 573k | invalue = *inptr++; |
290 | 573k | *outptr++ = (_JSAMPLE)invalue; |
291 | 573k | *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2); |
292 | | |
293 | 5.93M | for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { |
294 | | /* General case: 3/4 * nearer component + 1/4 * further component */ |
295 | 5.35M | invalue = (*inptr++) * 3; |
296 | 5.35M | *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2); |
297 | 5.35M | *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2); |
298 | 5.35M | } |
299 | | |
300 | | /* Special case for last column */ |
301 | 573k | invalue = *inptr; |
302 | 573k | *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2); |
303 | 573k | *outptr++ = (_JSAMPLE)invalue; |
304 | 573k | } |
305 | 155k | } |
306 | | |
307 | | |
308 | | /* |
309 | | * Fancy processing for 1:1 horizontal and 2:1 vertical (4:4:0 subsampling). |
310 | | * |
311 | | * This is a less common case, but it can be encountered when losslessly |
312 | | * rotating/transposing a JPEG file that uses 4:2:2 chroma subsampling. |
313 | | */ |
314 | | |
315 | | METHODDEF(void) |
316 | | h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
317 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
318 | 378k | { |
319 | 378k | _JSAMPARRAY output_data = *output_data_ptr; |
320 | 378k | _JSAMPROW inptr0, inptr1, outptr; |
321 | | #if BITS_IN_JSAMPLE == 8 |
322 | | int thiscolsum, bias; |
323 | | #else |
324 | 378k | JLONG thiscolsum, bias; |
325 | 378k | #endif |
326 | 378k | JDIMENSION colctr; |
327 | 378k | int inrow, outrow, v; |
328 | | |
329 | 378k | inrow = outrow = 0; |
330 | 853k | while (outrow < cinfo->max_v_samp_factor) { |
331 | 1.42M | for (v = 0; v < 2; v++) { |
332 | | /* inptr0 points to nearest input row, inptr1 points to next nearest */ |
333 | 951k | inptr0 = input_data[inrow]; |
334 | 951k | if (v == 0) { /* next nearest is row above */ |
335 | 475k | inptr1 = input_data[inrow - 1]; |
336 | 475k | bias = 1; |
337 | 475k | } else { /* next nearest is row below */ |
338 | 475k | inptr1 = input_data[inrow + 1]; |
339 | 475k | bias = 2; |
340 | 475k | } |
341 | 951k | outptr = output_data[outrow++]; |
342 | | |
343 | 50.8M | for (colctr = 0; colctr < compptr->downsampled_width; colctr++) { |
344 | 49.8M | thiscolsum = (*inptr0++) * 3 + (*inptr1++); |
345 | 49.8M | *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2); |
346 | 49.8M | } |
347 | 951k | } |
348 | 475k | inrow++; |
349 | 475k | } |
350 | 378k | } |
351 | | |
352 | | |
353 | | /* |
354 | | * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical. |
355 | | * Again a triangle filter; see comments for h2v1 case, above. |
356 | | * |
357 | | * It is OK for us to reference the adjacent input rows because we demanded |
358 | | * context from the main buffer controller (see initialization code). |
359 | | */ |
360 | | |
361 | | METHODDEF(void) |
362 | | h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, |
363 | | _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr) |
364 | 35.4k | { |
365 | 35.4k | _JSAMPARRAY output_data = *output_data_ptr; |
366 | 35.4k | register _JSAMPROW inptr0, inptr1, outptr; |
367 | | #if BITS_IN_JSAMPLE == 8 |
368 | | register int thiscolsum, lastcolsum, nextcolsum; |
369 | | #else |
370 | 35.4k | register JLONG thiscolsum, lastcolsum, nextcolsum; |
371 | 35.4k | #endif |
372 | 35.4k | register JDIMENSION colctr; |
373 | 35.4k | int inrow, outrow, v; |
374 | | |
375 | 35.4k | inrow = outrow = 0; |
376 | 76.9k | while (outrow < cinfo->max_v_samp_factor) { |
377 | 124k | for (v = 0; v < 2; v++) { |
378 | | /* inptr0 points to nearest input row, inptr1 points to next nearest */ |
379 | 82.9k | inptr0 = input_data[inrow]; |
380 | 82.9k | if (v == 0) /* next nearest is row above */ |
381 | 41.4k | inptr1 = input_data[inrow - 1]; |
382 | 41.4k | else /* next nearest is row below */ |
383 | 41.4k | inptr1 = input_data[inrow + 1]; |
384 | 82.9k | outptr = output_data[outrow++]; |
385 | | |
386 | | /* Special case for first column */ |
387 | 82.9k | thiscolsum = (*inptr0++) * 3 + (*inptr1++); |
388 | 82.9k | nextcolsum = (*inptr0++) * 3 + (*inptr1++); |
389 | 82.9k | *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4); |
390 | 82.9k | *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4); |
391 | 82.9k | lastcolsum = thiscolsum; thiscolsum = nextcolsum; |
392 | | |
393 | 4.61M | for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { |
394 | | /* General case: 3/4 * nearer component + 1/4 * further component in |
395 | | * each dimension, thus 9/16, 3/16, 3/16, 1/16 overall |
396 | | */ |
397 | 4.52M | nextcolsum = (*inptr0++) * 3 + (*inptr1++); |
398 | 4.52M | *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4); |
399 | 4.52M | *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4); |
400 | 4.52M | lastcolsum = thiscolsum; thiscolsum = nextcolsum; |
401 | 4.52M | } |
402 | | |
403 | | /* Special case for last column */ |
404 | 82.9k | *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4); |
405 | 82.9k | *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4); |
406 | 82.9k | } |
407 | 41.4k | inrow++; |
408 | 41.4k | } |
409 | 35.4k | } |
410 | | |
411 | | |
412 | | /* |
413 | | * Module initialization routine for upsampling. |
414 | | */ |
415 | | |
416 | | GLOBAL(void) |
417 | | _jinit_upsampler(j_decompress_ptr cinfo) |
418 | 18.4k | { |
419 | 18.4k | my_upsample_ptr upsample; |
420 | 18.4k | int ci; |
421 | 18.4k | jpeg_component_info *compptr; |
422 | 18.4k | boolean need_buffer, do_fancy; |
423 | 18.4k | int h_in_group, v_in_group, h_out_group, v_out_group; |
424 | | |
425 | 18.4k | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
426 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
427 | | |
428 | 18.4k | if (!cinfo->master->jinit_upsampler_no_alloc) { |
429 | 18.4k | upsample = (my_upsample_ptr) |
430 | 18.4k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
431 | 18.4k | sizeof(my_upsampler)); |
432 | 18.4k | cinfo->upsample = (struct jpeg_upsampler *)upsample; |
433 | 18.4k | upsample->pub.start_pass = start_pass_upsample; |
434 | 18.4k | upsample->pub._upsample = sep_upsample; |
435 | 18.4k | upsample->pub.need_context_rows = FALSE; /* until we find out differently */ |
436 | 18.4k | } else |
437 | 0 | upsample = (my_upsample_ptr)cinfo->upsample; |
438 | | |
439 | 18.4k | if (cinfo->CCIR601_sampling) /* this isn't supported */ |
440 | 0 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); |
441 | | |
442 | | /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, |
443 | | * so don't ask for it. |
444 | | */ |
445 | 18.4k | do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1; |
446 | | |
447 | | /* Verify we can handle the sampling factors, select per-component methods, |
448 | | * and create storage as needed. |
449 | | */ |
450 | 58.8k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
451 | 40.3k | ci++, compptr++) { |
452 | | /* Compute size of an "input group" after IDCT scaling. This many samples |
453 | | * are to be converted to max_h_samp_factor * max_v_samp_factor components. |
454 | | */ |
455 | 40.3k | h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) / |
456 | 40.3k | cinfo->_min_DCT_scaled_size; |
457 | 40.3k | v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / |
458 | 40.3k | cinfo->_min_DCT_scaled_size; |
459 | 40.3k | h_out_group = cinfo->max_h_samp_factor; |
460 | 40.3k | v_out_group = cinfo->max_v_samp_factor; |
461 | 40.3k | upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ |
462 | 40.3k | need_buffer = TRUE; |
463 | 40.3k | if (!compptr->component_needed) { |
464 | | /* Don't bother to upsample an uninteresting component. */ |
465 | 3.33k | upsample->methods[ci] = noop_upsample; |
466 | 3.33k | need_buffer = FALSE; |
467 | 36.9k | } else if (h_in_group == h_out_group && v_in_group == v_out_group) { |
468 | | /* Fullsize components can be processed without any work. */ |
469 | 16.8k | upsample->methods[ci] = fullsize_upsample; |
470 | 16.8k | need_buffer = FALSE; |
471 | 20.1k | } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) { |
472 | | /* Special cases for 2h1v upsampling */ |
473 | 1.97k | if (do_fancy && compptr->downsampled_width > 2) { |
474 | | #ifdef WITH_SIMD |
475 | 269 | if (jsimd_can_h2v1_fancy_upsample()) |
476 | 269 | upsample->methods[ci] = jsimd_h2v1_fancy_upsample; |
477 | 0 | else |
478 | 0 | #endif |
479 | 0 | upsample->methods[ci] = h2v1_fancy_upsample; |
480 | 1.44k | } else { |
481 | | #ifdef WITH_SIMD |
482 | 605 | if (jsimd_can_h2v1_upsample()) |
483 | 605 | upsample->methods[ci] = jsimd_h2v1_upsample; |
484 | 0 | else |
485 | 0 | #endif |
486 | 0 | upsample->methods[ci] = h2v1_upsample; |
487 | 1.44k | } |
488 | 18.1k | } else if (h_in_group == h_out_group && |
489 | 6.47k | v_in_group * 2 == v_out_group && do_fancy) { |
490 | | /* Non-fancy upsampling is handled by the generic method */ |
491 | | #if defined(WITH_SIMD) && (defined(__arm__) || defined(__aarch64__) || \ |
492 | | defined(_M_ARM) || defined(_M_ARM64)) |
493 | | if (jsimd_can_h1v2_fancy_upsample()) |
494 | | upsample->methods[ci] = jsimd_h1v2_fancy_upsample; |
495 | | else |
496 | | #endif |
497 | 783 | upsample->methods[ci] = h1v2_fancy_upsample; |
498 | 783 | upsample->pub.need_context_rows = TRUE; |
499 | 17.3k | } else if (h_in_group * 2 == h_out_group && |
500 | 7.19k | v_in_group * 2 == v_out_group) { |
501 | | /* Special cases for 2h2v upsampling */ |
502 | 6.49k | if (do_fancy && compptr->downsampled_width > 2) { |
503 | | #ifdef WITH_SIMD |
504 | 91 | if (jsimd_can_h2v2_fancy_upsample()) |
505 | 91 | upsample->methods[ci] = jsimd_h2v2_fancy_upsample; |
506 | 0 | else |
507 | 0 | #endif |
508 | 0 | upsample->methods[ci] = h2v2_fancy_upsample; |
509 | 155 | upsample->pub.need_context_rows = TRUE; |
510 | 6.34k | } else { |
511 | | #ifdef WITH_SIMD |
512 | 2.01k | if (jsimd_can_h2v2_upsample()) |
513 | 2.01k | upsample->methods[ci] = jsimd_h2v2_upsample; |
514 | 0 | else |
515 | 0 | #endif |
516 | 0 | upsample->methods[ci] = h2v2_upsample; |
517 | 6.34k | } |
518 | 10.9k | } else if ((h_out_group % h_in_group) == 0 && |
519 | 10.7k | (v_out_group % v_in_group) == 0) { |
520 | | /* Generic integral-factors upsampling method */ |
521 | | #if defined(WITH_SIMD) && defined(__mips__) |
522 | | if (jsimd_can_int_upsample()) |
523 | | upsample->methods[ci] = jsimd_int_upsample; |
524 | | else |
525 | | #endif |
526 | 10.1k | upsample->methods[ci] = int_upsample; |
527 | 10.1k | upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group); |
528 | 10.1k | upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group); |
529 | 10.1k | } else |
530 | 734 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); |
531 | 40.3k | if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) { |
532 | 19.4k | upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) |
533 | 19.4k | ((j_common_ptr)cinfo, JPOOL_IMAGE, |
534 | 19.4k | (JDIMENSION)jround_up((long)cinfo->output_width, |
535 | 19.4k | (long)cinfo->max_h_samp_factor), |
536 | 19.4k | (JDIMENSION)cinfo->max_v_samp_factor); |
537 | 19.4k | } |
538 | 40.3k | } |
539 | 18.4k | } Line | Count | Source | 418 | 6.44k | { | 419 | 6.44k | my_upsample_ptr upsample; | 420 | 6.44k | int ci; | 421 | 6.44k | jpeg_component_info *compptr; | 422 | 6.44k | boolean need_buffer, do_fancy; | 423 | 6.44k | int h_in_group, v_in_group, h_out_group, v_out_group; | 424 | | | 425 | 6.44k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 426 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 427 | | | 428 | 6.44k | if (!cinfo->master->jinit_upsampler_no_alloc) { | 429 | 6.44k | upsample = (my_upsample_ptr) | 430 | 6.44k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 431 | 6.44k | sizeof(my_upsampler)); | 432 | 6.44k | cinfo->upsample = (struct jpeg_upsampler *)upsample; | 433 | 6.44k | upsample->pub.start_pass = start_pass_upsample; | 434 | 6.44k | upsample->pub._upsample = sep_upsample; | 435 | 6.44k | upsample->pub.need_context_rows = FALSE; /* until we find out differently */ | 436 | 6.44k | } else | 437 | 0 | upsample = (my_upsample_ptr)cinfo->upsample; | 438 | | | 439 | 6.44k | if (cinfo->CCIR601_sampling) /* this isn't supported */ | 440 | 0 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); | 441 | | | 442 | | /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, | 443 | | * so don't ask for it. | 444 | | */ | 445 | 6.44k | do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1; | 446 | | | 447 | | /* Verify we can handle the sampling factors, select per-component methods, | 448 | | * and create storage as needed. | 449 | | */ | 450 | 19.8k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 451 | 13.3k | ci++, compptr++) { | 452 | | /* Compute size of an "input group" after IDCT scaling. This many samples | 453 | | * are to be converted to max_h_samp_factor * max_v_samp_factor components. | 454 | | */ | 455 | 13.3k | h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) / | 456 | 13.3k | cinfo->_min_DCT_scaled_size; | 457 | 13.3k | v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / | 458 | 13.3k | cinfo->_min_DCT_scaled_size; | 459 | 13.3k | h_out_group = cinfo->max_h_samp_factor; | 460 | 13.3k | v_out_group = cinfo->max_v_samp_factor; | 461 | 13.3k | upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ | 462 | 13.3k | need_buffer = TRUE; | 463 | 13.3k | if (!compptr->component_needed) { | 464 | | /* Don't bother to upsample an uninteresting component. */ | 465 | 908 | upsample->methods[ci] = noop_upsample; | 466 | 908 | need_buffer = FALSE; | 467 | 12.4k | } else if (h_in_group == h_out_group && v_in_group == v_out_group) { | 468 | | /* Fullsize components can be processed without any work. */ | 469 | 5.49k | upsample->methods[ci] = fullsize_upsample; | 470 | 5.49k | need_buffer = FALSE; | 471 | 7.00k | } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) { | 472 | | /* Special cases for 2h1v upsampling */ | 473 | 818 | if (do_fancy && compptr->downsampled_width > 2) { | 474 | | #ifdef WITH_SIMD | 475 | | if (jsimd_can_h2v1_fancy_upsample()) | 476 | | upsample->methods[ci] = jsimd_h2v1_fancy_upsample; | 477 | | else | 478 | | #endif | 479 | 242 | upsample->methods[ci] = h2v1_fancy_upsample; | 480 | 576 | } else { | 481 | | #ifdef WITH_SIMD | 482 | | if (jsimd_can_h2v1_upsample()) | 483 | | upsample->methods[ci] = jsimd_h2v1_upsample; | 484 | | else | 485 | | #endif | 486 | 576 | upsample->methods[ci] = h2v1_upsample; | 487 | 576 | } | 488 | 6.18k | } else if (h_in_group == h_out_group && | 489 | 2.04k | v_in_group * 2 == v_out_group && do_fancy) { | 490 | | /* Non-fancy upsampling is handled by the generic method */ | 491 | | #if defined(WITH_SIMD) && (defined(__arm__) || defined(__aarch64__) || \ | 492 | | defined(_M_ARM) || defined(_M_ARM64)) | 493 | | if (jsimd_can_h1v2_fancy_upsample()) | 494 | | upsample->methods[ci] = jsimd_h1v2_fancy_upsample; | 495 | | else | 496 | | #endif | 497 | 219 | upsample->methods[ci] = h1v2_fancy_upsample; | 498 | 219 | upsample->pub.need_context_rows = TRUE; | 499 | 5.96k | } else if (h_in_group * 2 == h_out_group && | 500 | 2.35k | v_in_group * 2 == v_out_group) { | 501 | | /* Special cases for 2h2v upsampling */ | 502 | 2.06k | if (do_fancy && compptr->downsampled_width > 2) { | 503 | | #ifdef WITH_SIMD | 504 | | if (jsimd_can_h2v2_fancy_upsample()) | 505 | | upsample->methods[ci] = jsimd_h2v2_fancy_upsample; | 506 | | else | 507 | | #endif | 508 | 53 | upsample->methods[ci] = h2v2_fancy_upsample; | 509 | 53 | upsample->pub.need_context_rows = TRUE; | 510 | 2.01k | } else { | 511 | | #ifdef WITH_SIMD | 512 | | if (jsimd_can_h2v2_upsample()) | 513 | | upsample->methods[ci] = jsimd_h2v2_upsample; | 514 | | else | 515 | | #endif | 516 | 2.01k | upsample->methods[ci] = h2v2_upsample; | 517 | 2.01k | } | 518 | 3.89k | } else if ((h_out_group % h_in_group) == 0 && | 519 | 3.83k | (v_out_group % v_in_group) == 0) { | 520 | | /* Generic integral-factors upsampling method */ | 521 | | #if defined(WITH_SIMD) && defined(__mips__) | 522 | | if (jsimd_can_int_upsample()) | 523 | | upsample->methods[ci] = jsimd_int_upsample; | 524 | | else | 525 | | #endif | 526 | 3.62k | upsample->methods[ci] = int_upsample; | 527 | 3.62k | upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group); | 528 | 3.62k | upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group); | 529 | 3.62k | } else | 530 | 272 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); | 531 | 13.3k | if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) { | 532 | 6.72k | upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 533 | 6.72k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 534 | 6.72k | (JDIMENSION)jround_up((long)cinfo->output_width, | 535 | 6.72k | (long)cinfo->max_h_samp_factor), | 536 | 6.72k | (JDIMENSION)cinfo->max_v_samp_factor); | 537 | 6.72k | } | 538 | 13.3k | } | 539 | 6.44k | } |
Line | Count | Source | 418 | 9.71k | { | 419 | 9.71k | my_upsample_ptr upsample; | 420 | 9.71k | int ci; | 421 | 9.71k | jpeg_component_info *compptr; | 422 | 9.71k | boolean need_buffer, do_fancy; | 423 | 9.71k | int h_in_group, v_in_group, h_out_group, v_out_group; | 424 | | | 425 | 9.71k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 426 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 427 | | | 428 | 9.71k | if (!cinfo->master->jinit_upsampler_no_alloc) { | 429 | 9.71k | upsample = (my_upsample_ptr) | 430 | 9.71k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 431 | 9.71k | sizeof(my_upsampler)); | 432 | 9.71k | cinfo->upsample = (struct jpeg_upsampler *)upsample; | 433 | 9.71k | upsample->pub.start_pass = start_pass_upsample; | 434 | 9.71k | upsample->pub._upsample = sep_upsample; | 435 | 9.71k | upsample->pub.need_context_rows = FALSE; /* until we find out differently */ | 436 | 9.71k | } else | 437 | 0 | upsample = (my_upsample_ptr)cinfo->upsample; | 438 | | | 439 | 9.71k | if (cinfo->CCIR601_sampling) /* this isn't supported */ | 440 | 0 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); | 441 | | | 442 | | /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, | 443 | | * so don't ask for it. | 444 | | */ | 445 | 9.71k | do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1; | 446 | | | 447 | | /* Verify we can handle the sampling factors, select per-component methods, | 448 | | * and create storage as needed. | 449 | | */ | 450 | 29.8k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 451 | 20.1k | ci++, compptr++) { | 452 | | /* Compute size of an "input group" after IDCT scaling. This many samples | 453 | | * are to be converted to max_h_samp_factor * max_v_samp_factor components. | 454 | | */ | 455 | 20.1k | h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) / | 456 | 20.1k | cinfo->_min_DCT_scaled_size; | 457 | 20.1k | v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / | 458 | 20.1k | cinfo->_min_DCT_scaled_size; | 459 | 20.1k | h_out_group = cinfo->max_h_samp_factor; | 460 | 20.1k | v_out_group = cinfo->max_v_samp_factor; | 461 | 20.1k | upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ | 462 | 20.1k | need_buffer = TRUE; | 463 | 20.1k | if (!compptr->component_needed) { | 464 | | /* Don't bother to upsample an uninteresting component. */ | 465 | 2.40k | upsample->methods[ci] = noop_upsample; | 466 | 2.40k | need_buffer = FALSE; | 467 | 17.7k | } else if (h_in_group == h_out_group && v_in_group == v_out_group) { | 468 | | /* Fullsize components can be processed without any work. */ | 469 | 9.12k | upsample->methods[ci] = fullsize_upsample; | 470 | 9.12k | need_buffer = FALSE; | 471 | 9.12k | } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) { | 472 | | /* Special cases for 2h1v upsampling */ | 473 | 874 | if (do_fancy && compptr->downsampled_width > 2) { | 474 | 269 | #ifdef WITH_SIMD | 475 | 269 | if (jsimd_can_h2v1_fancy_upsample()) | 476 | 269 | upsample->methods[ci] = jsimd_h2v1_fancy_upsample; | 477 | 0 | else | 478 | 0 | #endif | 479 | 0 | upsample->methods[ci] = h2v1_fancy_upsample; | 480 | 605 | } else { | 481 | 605 | #ifdef WITH_SIMD | 482 | 605 | if (jsimd_can_h2v1_upsample()) | 483 | 605 | upsample->methods[ci] = jsimd_h2v1_upsample; | 484 | 0 | else | 485 | 0 | #endif | 486 | 0 | upsample->methods[ci] = h2v1_upsample; | 487 | 605 | } | 488 | 7.75k | } else if (h_in_group == h_out_group && | 489 | 3.49k | v_in_group * 2 == v_out_group && do_fancy) { | 490 | | /* Non-fancy upsampling is handled by the generic method */ | 491 | | #if defined(WITH_SIMD) && (defined(__arm__) || defined(__aarch64__) || \ | 492 | | defined(_M_ARM) || defined(_M_ARM64)) | 493 | | if (jsimd_can_h1v2_fancy_upsample()) | 494 | | upsample->methods[ci] = jsimd_h1v2_fancy_upsample; | 495 | | else | 496 | | #endif | 497 | 556 | upsample->methods[ci] = h1v2_fancy_upsample; | 498 | 556 | upsample->pub.need_context_rows = TRUE; | 499 | 7.20k | } else if (h_in_group * 2 == h_out_group && | 500 | 2.41k | v_in_group * 2 == v_out_group) { | 501 | | /* Special cases for 2h2v upsampling */ | 502 | 2.10k | if (do_fancy && compptr->downsampled_width > 2) { | 503 | 91 | #ifdef WITH_SIMD | 504 | 91 | if (jsimd_can_h2v2_fancy_upsample()) | 505 | 91 | upsample->methods[ci] = jsimd_h2v2_fancy_upsample; | 506 | 0 | else | 507 | 0 | #endif | 508 | 0 | upsample->methods[ci] = h2v2_fancy_upsample; | 509 | 91 | upsample->pub.need_context_rows = TRUE; | 510 | 2.01k | } else { | 511 | 2.01k | #ifdef WITH_SIMD | 512 | 2.01k | if (jsimd_can_h2v2_upsample()) | 513 | 2.01k | upsample->methods[ci] = jsimd_h2v2_upsample; | 514 | 0 | else | 515 | 0 | #endif | 516 | 0 | upsample->methods[ci] = h2v2_upsample; | 517 | 2.01k | } | 518 | 5.09k | } else if ((h_out_group % h_in_group) == 0 && | 519 | 5.02k | (v_out_group % v_in_group) == 0) { | 520 | | /* Generic integral-factors upsampling method */ | 521 | | #if defined(WITH_SIMD) && defined(__mips__) | 522 | | if (jsimd_can_int_upsample()) | 523 | | upsample->methods[ci] = jsimd_int_upsample; | 524 | | else | 525 | | #endif | 526 | 4.64k | upsample->methods[ci] = int_upsample; | 527 | 4.64k | upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group); | 528 | 4.64k | upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group); | 529 | 4.64k | } else | 530 | 448 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); | 531 | 20.1k | if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) { | 532 | 8.18k | upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 533 | 8.18k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 534 | 8.18k | (JDIMENSION)jround_up((long)cinfo->output_width, | 535 | 8.18k | (long)cinfo->max_h_samp_factor), | 536 | 8.18k | (JDIMENSION)cinfo->max_v_samp_factor); | 537 | 8.18k | } | 538 | 20.1k | } | 539 | 9.71k | } |
Line | Count | Source | 418 | 2.32k | { | 419 | 2.32k | my_upsample_ptr upsample; | 420 | 2.32k | int ci; | 421 | 2.32k | jpeg_component_info *compptr; | 422 | 2.32k | boolean need_buffer, do_fancy; | 423 | 2.32k | int h_in_group, v_in_group, h_out_group, v_out_group; | 424 | | | 425 | 2.32k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 426 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 427 | | | 428 | 2.32k | if (!cinfo->master->jinit_upsampler_no_alloc) { | 429 | 2.32k | upsample = (my_upsample_ptr) | 430 | 2.32k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 431 | 2.32k | sizeof(my_upsampler)); | 432 | 2.32k | cinfo->upsample = (struct jpeg_upsampler *)upsample; | 433 | 2.32k | upsample->pub.start_pass = start_pass_upsample; | 434 | 2.32k | upsample->pub._upsample = sep_upsample; | 435 | 2.32k | upsample->pub.need_context_rows = FALSE; /* until we find out differently */ | 436 | 2.32k | } else | 437 | 0 | upsample = (my_upsample_ptr)cinfo->upsample; | 438 | | | 439 | 2.32k | if (cinfo->CCIR601_sampling) /* this isn't supported */ | 440 | 0 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); | 441 | | | 442 | | /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, | 443 | | * so don't ask for it. | 444 | | */ | 445 | 2.32k | do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1; | 446 | | | 447 | | /* Verify we can handle the sampling factors, select per-component methods, | 448 | | * and create storage as needed. | 449 | | */ | 450 | 9.09k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 451 | 6.76k | ci++, compptr++) { | 452 | | /* Compute size of an "input group" after IDCT scaling. This many samples | 453 | | * are to be converted to max_h_samp_factor * max_v_samp_factor components. | 454 | | */ | 455 | 6.76k | h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) / | 456 | 6.76k | cinfo->_min_DCT_scaled_size; | 457 | 6.76k | v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / | 458 | 6.76k | cinfo->_min_DCT_scaled_size; | 459 | 6.76k | h_out_group = cinfo->max_h_samp_factor; | 460 | 6.76k | v_out_group = cinfo->max_v_samp_factor; | 461 | 6.76k | upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ | 462 | 6.76k | need_buffer = TRUE; | 463 | 6.76k | if (!compptr->component_needed) { | 464 | | /* Don't bother to upsample an uninteresting component. */ | 465 | 24 | upsample->methods[ci] = noop_upsample; | 466 | 24 | need_buffer = FALSE; | 467 | 6.73k | } else if (h_in_group == h_out_group && v_in_group == v_out_group) { | 468 | | /* Fullsize components can be processed without any work. */ | 469 | 2.21k | upsample->methods[ci] = fullsize_upsample; | 470 | 2.21k | need_buffer = FALSE; | 471 | 4.52k | } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) { | 472 | | /* Special cases for 2h1v upsampling */ | 473 | 280 | if (do_fancy && compptr->downsampled_width > 2) { | 474 | | #ifdef WITH_SIMD | 475 | | if (jsimd_can_h2v1_fancy_upsample()) | 476 | | upsample->methods[ci] = jsimd_h2v1_fancy_upsample; | 477 | | else | 478 | | #endif | 479 | 12 | upsample->methods[ci] = h2v1_fancy_upsample; | 480 | 268 | } else { | 481 | | #ifdef WITH_SIMD | 482 | | if (jsimd_can_h2v1_upsample()) | 483 | | upsample->methods[ci] = jsimd_h2v1_upsample; | 484 | | else | 485 | | #endif | 486 | 268 | upsample->methods[ci] = h2v1_upsample; | 487 | 268 | } | 488 | 4.24k | } else if (h_in_group == h_out_group && | 489 | 932 | v_in_group * 2 == v_out_group && do_fancy) { | 490 | | /* Non-fancy upsampling is handled by the generic method */ | 491 | | #if defined(WITH_SIMD) && (defined(__arm__) || defined(__aarch64__) || \ | 492 | | defined(_M_ARM) || defined(_M_ARM64)) | 493 | | if (jsimd_can_h1v2_fancy_upsample()) | 494 | | upsample->methods[ci] = jsimd_h1v2_fancy_upsample; | 495 | | else | 496 | | #endif | 497 | 8 | upsample->methods[ci] = h1v2_fancy_upsample; | 498 | 8 | upsample->pub.need_context_rows = TRUE; | 499 | 4.23k | } else if (h_in_group * 2 == h_out_group && | 500 | 2.42k | v_in_group * 2 == v_out_group) { | 501 | | /* Special cases for 2h2v upsampling */ | 502 | 2.32k | if (do_fancy && compptr->downsampled_width > 2) { | 503 | | #ifdef WITH_SIMD | 504 | | if (jsimd_can_h2v2_fancy_upsample()) | 505 | | upsample->methods[ci] = jsimd_h2v2_fancy_upsample; | 506 | | else | 507 | | #endif | 508 | 11 | upsample->methods[ci] = h2v2_fancy_upsample; | 509 | 11 | upsample->pub.need_context_rows = TRUE; | 510 | 2.31k | } else { | 511 | | #ifdef WITH_SIMD | 512 | | if (jsimd_can_h2v2_upsample()) | 513 | | upsample->methods[ci] = jsimd_h2v2_upsample; | 514 | | else | 515 | | #endif | 516 | 2.31k | upsample->methods[ci] = h2v2_upsample; | 517 | 2.31k | } | 518 | 2.32k | } else if ((h_out_group % h_in_group) == 0 && | 519 | 1.90k | (v_out_group % v_in_group) == 0) { | 520 | | /* Generic integral-factors upsampling method */ | 521 | | #if defined(WITH_SIMD) && defined(__mips__) | 522 | | if (jsimd_can_int_upsample()) | 523 | | upsample->methods[ci] = jsimd_int_upsample; | 524 | | else | 525 | | #endif | 526 | 1.89k | upsample->methods[ci] = int_upsample; | 527 | 1.89k | upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group); | 528 | 1.89k | upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group); | 529 | 1.89k | } else | 530 | 14 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); | 531 | 6.76k | if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) { | 532 | 4.50k | upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 533 | 4.50k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 534 | 4.50k | (JDIMENSION)jround_up((long)cinfo->output_width, | 535 | 4.50k | (long)cinfo->max_h_samp_factor), | 536 | 4.50k | (JDIMENSION)cinfo->max_v_samp_factor); | 537 | 4.50k | } | 538 | 6.76k | } | 539 | 2.32k | } |
|
540 | | |
541 | | #endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */ |