/src/libjpeg-turbo.main/src/jdsample.c
Line | Count | Source (jump to first uncovered line) |
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, 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 | | #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 | 1.73k | { |
44 | 1.73k | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; |
45 | | |
46 | | /* Mark the conversion buffer empty */ |
47 | 1.73k | upsample->next_row_out = cinfo->max_v_samp_factor; |
48 | | /* Initialize total-height counter for detecting bottom of image */ |
49 | 1.73k | upsample->rows_to_go = cinfo->output_height; |
50 | 1.73k | } jdsample-8.c:start_pass_upsample Line | Count | Source | 43 | 1.18k | { | 44 | 1.18k | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; | 45 | | | 46 | | /* Mark the conversion buffer empty */ | 47 | 1.18k | upsample->next_row_out = cinfo->max_v_samp_factor; | 48 | | /* Initialize total-height counter for detecting bottom of image */ | 49 | 1.18k | upsample->rows_to_go = cinfo->output_height; | 50 | 1.18k | } |
jdsample-12.c:start_pass_upsample Line | Count | Source | 43 | 295 | { | 44 | 295 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; | 45 | | | 46 | | /* Mark the conversion buffer empty */ | 47 | 295 | upsample->next_row_out = cinfo->max_v_samp_factor; | 48 | | /* Initialize total-height counter for detecting bottom of image */ | 49 | 295 | upsample->rows_to_go = cinfo->output_height; | 50 | 295 | } |
jdsample-16.c:start_pass_upsample Line | Count | Source | 43 | 258 | { | 44 | 258 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; | 45 | | | 46 | | /* Mark the conversion buffer empty */ | 47 | 258 | upsample->next_row_out = cinfo->max_v_samp_factor; | 48 | | /* Initialize total-height counter for detecting bottom of image */ | 49 | 258 | upsample->rows_to_go = cinfo->output_height; | 50 | 258 | } |
|
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 | 2.05M | { |
67 | 2.05M | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; |
68 | 2.05M | int ci; |
69 | 2.05M | jpeg_component_info *compptr; |
70 | 2.05M | JDIMENSION num_rows; |
71 | | |
72 | | /* Fill the conversion buffer, if it's empty */ |
73 | 2.05M | if (upsample->next_row_out >= cinfo->max_v_samp_factor) { |
74 | 5.48M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
75 | 3.42M | 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 | 3.42M | (*upsample->methods[ci]) (cinfo, compptr, |
80 | 3.42M | input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]), |
81 | 3.42M | upsample->color_buf + ci); |
82 | 3.42M | } |
83 | 2.05M | upsample->next_row_out = 0; |
84 | 2.05M | } |
85 | | |
86 | | /* Color-convert and emit rows */ |
87 | | |
88 | | /* How many we have in the buffer: */ |
89 | 2.05M | 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 | 2.05M | if (num_rows > upsample->rows_to_go) |
94 | 138 | num_rows = upsample->rows_to_go; |
95 | | /* And not more than what the client can accept: */ |
96 | 2.05M | out_rows_avail -= *out_row_ctr; |
97 | 2.05M | if (num_rows > out_rows_avail) |
98 | 0 | num_rows = out_rows_avail; |
99 | | |
100 | 2.05M | (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf, |
101 | 2.05M | (JDIMENSION)upsample->next_row_out, |
102 | 2.05M | output_buf + *out_row_ctr, |
103 | 2.05M | (int)num_rows); |
104 | | |
105 | | /* Adjust counts */ |
106 | 2.05M | *out_row_ctr += num_rows; |
107 | 2.05M | upsample->rows_to_go -= num_rows; |
108 | 2.05M | upsample->next_row_out += num_rows; |
109 | | /* When the buffer is emptied, declare this input row group consumed */ |
110 | 2.05M | if (upsample->next_row_out >= cinfo->max_v_samp_factor) |
111 | 2.05M | (*in_row_group_ctr)++; |
112 | 2.05M | } jdsample-8.c:sep_upsample Line | Count | Source | 66 | 2.05M | { | 67 | 2.05M | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; | 68 | 2.05M | int ci; | 69 | 2.05M | jpeg_component_info *compptr; | 70 | 2.05M | JDIMENSION num_rows; | 71 | | | 72 | | /* Fill the conversion buffer, if it's empty */ | 73 | 2.05M | if (upsample->next_row_out >= cinfo->max_v_samp_factor) { | 74 | 5.48M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 75 | 3.42M | 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 | 3.42M | (*upsample->methods[ci]) (cinfo, compptr, | 80 | 3.42M | input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]), | 81 | 3.42M | upsample->color_buf + ci); | 82 | 3.42M | } | 83 | 2.05M | upsample->next_row_out = 0; | 84 | 2.05M | } | 85 | | | 86 | | /* Color-convert and emit rows */ | 87 | | | 88 | | /* How many we have in the buffer: */ | 89 | 2.05M | 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 | 2.05M | if (num_rows > upsample->rows_to_go) | 94 | 138 | num_rows = upsample->rows_to_go; | 95 | | /* And not more than what the client can accept: */ | 96 | 2.05M | out_rows_avail -= *out_row_ctr; | 97 | 2.05M | if (num_rows > out_rows_avail) | 98 | 0 | num_rows = out_rows_avail; | 99 | | | 100 | 2.05M | (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf, | 101 | 2.05M | (JDIMENSION)upsample->next_row_out, | 102 | 2.05M | output_buf + *out_row_ctr, | 103 | 2.05M | (int)num_rows); | 104 | | | 105 | | /* Adjust counts */ | 106 | 2.05M | *out_row_ctr += num_rows; | 107 | 2.05M | upsample->rows_to_go -= num_rows; | 108 | 2.05M | upsample->next_row_out += num_rows; | 109 | | /* When the buffer is emptied, declare this input row group consumed */ | 110 | 2.05M | if (upsample->next_row_out >= cinfo->max_v_samp_factor) | 111 | 2.05M | (*in_row_group_ctr)++; | 112 | 2.05M | } |
Unexecuted instantiation: jdsample-12.c:sep_upsample Unexecuted instantiation: jdsample-16.c:sep_upsample |
113 | | |
114 | | |
115 | | /* |
116 | | * These are the routines invoked by sep_upsample to upsample pixel values |
117 | | * of a 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 | 2.19M | { |
132 | 2.19M | *output_data_ptr = input_data; |
133 | 2.19M | } jdsample-8.c:fullsize_upsample Line | Count | Source | 131 | 2.19M | { | 132 | 2.19M | *output_data_ptr = input_data; | 133 | 2.19M | } |
Unexecuted instantiation: jdsample-12.c:fullsize_upsample Unexecuted instantiation: jdsample-16.c:fullsize_upsample |
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 | 799k | { |
145 | 799k | *output_data_ptr = NULL; /* safety check */ |
146 | 799k | } jdsample-8.c:noop_upsample Line | Count | Source | 144 | 799k | { | 145 | 799k | *output_data_ptr = NULL; /* safety check */ | 146 | 799k | } |
Unexecuted instantiation: jdsample-12.c:noop_upsample Unexecuted instantiation: jdsample-16.c:noop_upsample |
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. |
152 | | * Nor, for that matter, is it particularly accurate: the algorithm is |
153 | | * simple replication of the input pixel onto the corresponding output |
154 | | * pixels. The hi-falutin sampling literature refers to this as a |
155 | | * "box filter". A box filter tends to introduce visible artifacts, |
156 | | * so if you are actually going to use 3:1 or 4:1 sampling ratios |
157 | | * you would be well advised to improve this 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 | 426k | { |
164 | 426k | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; |
165 | 426k | _JSAMPARRAY output_data = *output_data_ptr; |
166 | 426k | register _JSAMPROW inptr, outptr; |
167 | 426k | register _JSAMPLE invalue; |
168 | 426k | register int h; |
169 | 426k | _JSAMPROW outend; |
170 | 426k | int h_expand, v_expand; |
171 | 426k | int inrow, outrow; |
172 | | |
173 | 426k | h_expand = upsample->h_expand[compptr->component_index]; |
174 | 426k | v_expand = upsample->v_expand[compptr->component_index]; |
175 | | |
176 | 426k | inrow = outrow = 0; |
177 | 853k | while (outrow < cinfo->max_v_samp_factor) { |
178 | | /* Generate one output row with proper horizontal expansion */ |
179 | 426k | inptr = input_data[inrow]; |
180 | 426k | outptr = output_data[outrow]; |
181 | 426k | outend = outptr + cinfo->output_width; |
182 | 35.4M | while (outptr < outend) { |
183 | 35.0M | invalue = *inptr++; |
184 | 78.5M | for (h = h_expand; h > 0; h--) { |
185 | 43.5M | *outptr++ = invalue; |
186 | 43.5M | } |
187 | 35.0M | } |
188 | | /* Generate any additional output rows by duplicating the first one */ |
189 | 426k | if (v_expand > 1) { |
190 | 221k | _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, |
191 | 221k | v_expand - 1, cinfo->output_width); |
192 | 221k | } |
193 | 426k | inrow++; |
194 | 426k | outrow += v_expand; |
195 | 426k | } |
196 | 426k | } jdsample-8.c:int_upsample Line | Count | Source | 163 | 426k | { | 164 | 426k | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; | 165 | 426k | _JSAMPARRAY output_data = *output_data_ptr; | 166 | 426k | register _JSAMPROW inptr, outptr; | 167 | 426k | register _JSAMPLE invalue; | 168 | 426k | register int h; | 169 | 426k | _JSAMPROW outend; | 170 | 426k | int h_expand, v_expand; | 171 | 426k | int inrow, outrow; | 172 | | | 173 | 426k | h_expand = upsample->h_expand[compptr->component_index]; | 174 | 426k | v_expand = upsample->v_expand[compptr->component_index]; | 175 | | | 176 | 426k | inrow = outrow = 0; | 177 | 853k | while (outrow < cinfo->max_v_samp_factor) { | 178 | | /* Generate one output row with proper horizontal expansion */ | 179 | 426k | inptr = input_data[inrow]; | 180 | 426k | outptr = output_data[outrow]; | 181 | 426k | outend = outptr + cinfo->output_width; | 182 | 35.4M | while (outptr < outend) { | 183 | 35.0M | invalue = *inptr++; | 184 | 78.5M | for (h = h_expand; h > 0; h--) { | 185 | 43.5M | *outptr++ = invalue; | 186 | 43.5M | } | 187 | 35.0M | } | 188 | | /* Generate any additional output rows by duplicating the first one */ | 189 | 426k | if (v_expand > 1) { | 190 | 221k | _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, | 191 | 221k | v_expand - 1, cinfo->output_width); | 192 | 221k | } | 193 | 426k | inrow++; | 194 | 426k | outrow += v_expand; | 195 | 426k | } | 196 | 426k | } |
Unexecuted instantiation: jdsample-12.c:int_upsample Unexecuted instantiation: jdsample-16.c:int_upsample |
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 | 0 | { |
208 | 0 | _JSAMPARRAY output_data = *output_data_ptr; |
209 | 0 | register _JSAMPROW inptr, outptr; |
210 | 0 | register _JSAMPLE invalue; |
211 | 0 | _JSAMPROW outend; |
212 | 0 | int inrow; |
213 | |
|
214 | 0 | for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) { |
215 | 0 | inptr = input_data[inrow]; |
216 | 0 | outptr = output_data[inrow]; |
217 | 0 | outend = outptr + cinfo->output_width; |
218 | 0 | while (outptr < outend) { |
219 | 0 | invalue = *inptr++; |
220 | 0 | *outptr++ = invalue; |
221 | 0 | *outptr++ = invalue; |
222 | 0 | } |
223 | 0 | } |
224 | 0 | } Unexecuted instantiation: jdsample-8.c:h2v1_upsample Unexecuted instantiation: jdsample-12.c:h2v1_upsample Unexecuted instantiation: jdsample-16.c:h2v1_upsample |
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 | 0 | { |
236 | 0 | _JSAMPARRAY output_data = *output_data_ptr; |
237 | 0 | register _JSAMPROW inptr, outptr; |
238 | 0 | register _JSAMPLE invalue; |
239 | 0 | _JSAMPROW outend; |
240 | 0 | int inrow, outrow; |
241 | |
|
242 | 0 | inrow = outrow = 0; |
243 | 0 | while (outrow < cinfo->max_v_samp_factor) { |
244 | 0 | inptr = input_data[inrow]; |
245 | 0 | outptr = output_data[outrow]; |
246 | 0 | outend = outptr + cinfo->output_width; |
247 | 0 | while (outptr < outend) { |
248 | 0 | invalue = *inptr++; |
249 | 0 | *outptr++ = invalue; |
250 | 0 | *outptr++ = invalue; |
251 | 0 | } |
252 | 0 | _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1, |
253 | 0 | cinfo->output_width); |
254 | 0 | inrow++; |
255 | 0 | outrow += 2; |
256 | 0 | } |
257 | 0 | } Unexecuted instantiation: jdsample-8.c:h2v2_upsample Unexecuted instantiation: jdsample-12.c:h2v2_upsample Unexecuted instantiation: jdsample-16.c:h2v2_upsample |
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 pixel centers, |
264 | | * also known as a "triangle filter". This is a good compromise between |
265 | | * speed and visual quality. The centers of the output pixels are 1/4 and 3/4 |
266 | | * of the way between input pixel 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 | 0 | { |
279 | 0 | _JSAMPARRAY output_data = *output_data_ptr; |
280 | 0 | register _JSAMPROW inptr, outptr; |
281 | 0 | register int invalue; |
282 | 0 | register JDIMENSION colctr; |
283 | 0 | int inrow; |
284 | |
|
285 | 0 | for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) { |
286 | 0 | inptr = input_data[inrow]; |
287 | 0 | outptr = output_data[inrow]; |
288 | | /* Special case for first column */ |
289 | 0 | invalue = *inptr++; |
290 | 0 | *outptr++ = (_JSAMPLE)invalue; |
291 | 0 | *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2); |
292 | |
|
293 | 0 | for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { |
294 | | /* General case: 3/4 * nearer pixel + 1/4 * further pixel */ |
295 | 0 | invalue = (*inptr++) * 3; |
296 | 0 | *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2); |
297 | 0 | *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2); |
298 | 0 | } |
299 | | |
300 | | /* Special case for last column */ |
301 | 0 | invalue = *inptr; |
302 | 0 | *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2); |
303 | 0 | *outptr++ = (_JSAMPLE)invalue; |
304 | 0 | } |
305 | 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 |
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 | 0 | { |
319 | 0 | _JSAMPARRAY output_data = *output_data_ptr; |
320 | 0 | _JSAMPROW inptr0, inptr1, outptr; |
321 | | #if BITS_IN_JSAMPLE == 8 |
322 | | int thiscolsum, bias; |
323 | | #else |
324 | | JLONG thiscolsum, bias; |
325 | | #endif |
326 | 0 | JDIMENSION colctr; |
327 | 0 | int inrow, outrow, v; |
328 | |
|
329 | 0 | inrow = outrow = 0; |
330 | 0 | while (outrow < cinfo->max_v_samp_factor) { |
331 | 0 | for (v = 0; v < 2; v++) { |
332 | | /* inptr0 points to nearest input row, inptr1 points to next nearest */ |
333 | 0 | inptr0 = input_data[inrow]; |
334 | 0 | if (v == 0) { /* next nearest is row above */ |
335 | 0 | inptr1 = input_data[inrow - 1]; |
336 | 0 | bias = 1; |
337 | 0 | } else { /* next nearest is row below */ |
338 | 0 | inptr1 = input_data[inrow + 1]; |
339 | 0 | bias = 2; |
340 | 0 | } |
341 | 0 | outptr = output_data[outrow++]; |
342 | |
|
343 | 0 | for (colctr = 0; colctr < compptr->downsampled_width; colctr++) { |
344 | 0 | thiscolsum = (*inptr0++) * 3 + (*inptr1++); |
345 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2); |
346 | 0 | } |
347 | 0 | } |
348 | 0 | inrow++; |
349 | 0 | } |
350 | 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 |
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 | 0 | { |
365 | 0 | _JSAMPARRAY output_data = *output_data_ptr; |
366 | 0 | register _JSAMPROW inptr0, inptr1, outptr; |
367 | | #if BITS_IN_JSAMPLE == 8 |
368 | | register int thiscolsum, lastcolsum, nextcolsum; |
369 | | #else |
370 | | register JLONG thiscolsum, lastcolsum, nextcolsum; |
371 | | #endif |
372 | 0 | register JDIMENSION colctr; |
373 | 0 | int inrow, outrow, v; |
374 | |
|
375 | 0 | inrow = outrow = 0; |
376 | 0 | while (outrow < cinfo->max_v_samp_factor) { |
377 | 0 | for (v = 0; v < 2; v++) { |
378 | | /* inptr0 points to nearest input row, inptr1 points to next nearest */ |
379 | 0 | inptr0 = input_data[inrow]; |
380 | 0 | if (v == 0) /* next nearest is row above */ |
381 | 0 | inptr1 = input_data[inrow - 1]; |
382 | 0 | else /* next nearest is row below */ |
383 | 0 | inptr1 = input_data[inrow + 1]; |
384 | 0 | outptr = output_data[outrow++]; |
385 | | |
386 | | /* Special case for first column */ |
387 | 0 | thiscolsum = (*inptr0++) * 3 + (*inptr1++); |
388 | 0 | nextcolsum = (*inptr0++) * 3 + (*inptr1++); |
389 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4); |
390 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4); |
391 | 0 | lastcolsum = thiscolsum; thiscolsum = nextcolsum; |
392 | |
|
393 | 0 | for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { |
394 | | /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */ |
395 | | /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */ |
396 | 0 | nextcolsum = (*inptr0++) * 3 + (*inptr1++); |
397 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4); |
398 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4); |
399 | 0 | lastcolsum = thiscolsum; thiscolsum = nextcolsum; |
400 | 0 | } |
401 | | |
402 | | /* Special case for last column */ |
403 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4); |
404 | 0 | *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4); |
405 | 0 | } |
406 | 0 | inrow++; |
407 | 0 | } |
408 | 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 |
409 | | |
410 | | |
411 | | /* |
412 | | * Module initialization routine for upsampling. |
413 | | */ |
414 | | |
415 | | GLOBAL(void) |
416 | | _jinit_upsampler(j_decompress_ptr cinfo) |
417 | 2.20k | { |
418 | 2.20k | my_upsample_ptr upsample; |
419 | 2.20k | int ci; |
420 | 2.20k | jpeg_component_info *compptr; |
421 | 2.20k | boolean need_buffer, do_fancy; |
422 | 2.20k | int h_in_group, v_in_group, h_out_group, v_out_group; |
423 | | |
424 | 2.20k | #ifdef D_LOSSLESS_SUPPORTED |
425 | 2.20k | if (cinfo->master->lossless) { |
426 | | #if BITS_IN_JSAMPLE == 8 |
427 | 516 | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
428 | | #else |
429 | 818 | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
430 | 818 | cinfo->data_precision < BITS_IN_JSAMPLE - 3) |
431 | 0 | #endif |
432 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
433 | 1.33k | } else |
434 | 874 | #endif |
435 | 874 | { |
436 | 874 | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
437 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
438 | 874 | } |
439 | | |
440 | 2.20k | if (!cinfo->master->jinit_upsampler_no_alloc) { |
441 | 2.20k | upsample = (my_upsample_ptr) |
442 | 2.20k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
443 | 2.20k | sizeof(my_upsampler)); |
444 | 2.20k | cinfo->upsample = (struct jpeg_upsampler *)upsample; |
445 | 2.20k | upsample->pub.start_pass = start_pass_upsample; |
446 | 2.20k | upsample->pub._upsample = sep_upsample; |
447 | 2.20k | upsample->pub.need_context_rows = FALSE; /* until we find out differently */ |
448 | 2.20k | } else |
449 | 0 | upsample = (my_upsample_ptr)cinfo->upsample; |
450 | | |
451 | 2.20k | if (cinfo->CCIR601_sampling) /* this isn't supported */ |
452 | 0 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); |
453 | | |
454 | | /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, |
455 | | * so don't ask for it. |
456 | | */ |
457 | 2.20k | do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1; |
458 | | |
459 | | /* Verify we can handle the sampling factors, select per-component methods, |
460 | | * and create storage as needed. |
461 | | */ |
462 | 7.72k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
463 | 5.51k | ci++, compptr++) { |
464 | | /* Compute size of an "input group" after IDCT scaling. This many samples |
465 | | * are to be converted to max_h_samp_factor * max_v_samp_factor pixels. |
466 | | */ |
467 | 5.51k | h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) / |
468 | 5.51k | cinfo->_min_DCT_scaled_size; |
469 | 5.51k | v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / |
470 | 5.51k | cinfo->_min_DCT_scaled_size; |
471 | 5.51k | h_out_group = cinfo->max_h_samp_factor; |
472 | 5.51k | v_out_group = cinfo->max_v_samp_factor; |
473 | 5.51k | upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ |
474 | 5.51k | need_buffer = TRUE; |
475 | 5.51k | if (!compptr->component_needed) { |
476 | | /* Don't bother to upsample an uninteresting component. */ |
477 | 318 | upsample->methods[ci] = noop_upsample; |
478 | 318 | need_buffer = FALSE; |
479 | 5.20k | } else if (h_in_group == h_out_group && v_in_group == v_out_group) { |
480 | | /* Fullsize components can be processed without any work. */ |
481 | 2.49k | upsample->methods[ci] = fullsize_upsample; |
482 | 2.49k | need_buffer = FALSE; |
483 | 2.71k | } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) { |
484 | | /* Special cases for 2h1v upsampling */ |
485 | 310 | if (do_fancy && compptr->downsampled_width > 2) { |
486 | | #ifdef WITH_SIMD |
487 | 0 | if (jsimd_can_h2v1_fancy_upsample()) |
488 | 0 | upsample->methods[ci] = jsimd_h2v1_fancy_upsample; |
489 | 0 | else |
490 | 0 | #endif |
491 | 0 | upsample->methods[ci] = h2v1_fancy_upsample; |
492 | 310 | } else { |
493 | | #ifdef WITH_SIMD |
494 | 106 | if (jsimd_can_h2v1_upsample()) |
495 | 106 | upsample->methods[ci] = jsimd_h2v1_upsample; |
496 | 0 | else |
497 | 0 | #endif |
498 | 0 | upsample->methods[ci] = h2v1_upsample; |
499 | 310 | } |
500 | 2.40k | } else if (h_in_group == h_out_group && |
501 | 2.40k | v_in_group * 2 == v_out_group && do_fancy) { |
502 | | /* Non-fancy upsampling is handled by the generic method */ |
503 | | #if defined(WITH_SIMD) && (defined(__arm__) || defined(__aarch64__) || \ |
504 | | defined(_M_ARM) || defined(_M_ARM64)) |
505 | | if (jsimd_can_h1v2_fancy_upsample()) |
506 | | upsample->methods[ci] = jsimd_h1v2_fancy_upsample; |
507 | | else |
508 | | #endif |
509 | 0 | upsample->methods[ci] = h1v2_fancy_upsample; |
510 | 0 | upsample->pub.need_context_rows = TRUE; |
511 | 2.40k | } else if (h_in_group * 2 == h_out_group && |
512 | 2.40k | v_in_group * 2 == v_out_group) { |
513 | | /* Special cases for 2h2v upsampling */ |
514 | 1.95k | if (do_fancy && compptr->downsampled_width > 2) { |
515 | | #ifdef WITH_SIMD |
516 | 0 | if (jsimd_can_h2v2_fancy_upsample()) |
517 | 0 | upsample->methods[ci] = jsimd_h2v2_fancy_upsample; |
518 | 0 | else |
519 | 0 | #endif |
520 | 0 | upsample->methods[ci] = h2v2_fancy_upsample; |
521 | 0 | upsample->pub.need_context_rows = TRUE; |
522 | 1.95k | } else { |
523 | | #ifdef WITH_SIMD |
524 | 822 | if (jsimd_can_h2v2_upsample()) |
525 | 822 | upsample->methods[ci] = jsimd_h2v2_upsample; |
526 | 0 | else |
527 | 0 | #endif |
528 | 0 | upsample->methods[ci] = h2v2_upsample; |
529 | 1.95k | } |
530 | 1.95k | } else if ((h_out_group % h_in_group) == 0 && |
531 | 444 | (v_out_group % v_in_group) == 0) { |
532 | | /* Generic integral-factors upsampling method */ |
533 | | #if defined(WITH_SIMD) && defined(__mips__) |
534 | | if (jsimd_can_int_upsample()) |
535 | | upsample->methods[ci] = jsimd_int_upsample; |
536 | | else |
537 | | #endif |
538 | 444 | upsample->methods[ci] = int_upsample; |
539 | 444 | upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group); |
540 | 444 | upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group); |
541 | 444 | } else |
542 | 0 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); |
543 | 5.51k | if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) { |
544 | 2.71k | upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) |
545 | 2.71k | ((j_common_ptr)cinfo, JPOOL_IMAGE, |
546 | 2.71k | (JDIMENSION)jround_up((long)cinfo->output_width, |
547 | 2.71k | (long)cinfo->max_h_samp_factor), |
548 | 2.71k | (JDIMENSION)cinfo->max_v_samp_factor); |
549 | 2.71k | } |
550 | 5.51k | } |
551 | 2.20k | } Line | Count | Source | 417 | 1.39k | { | 418 | 1.39k | my_upsample_ptr upsample; | 419 | 1.39k | int ci; | 420 | 1.39k | jpeg_component_info *compptr; | 421 | 1.39k | boolean need_buffer, do_fancy; | 422 | 1.39k | int h_in_group, v_in_group, h_out_group, v_out_group; | 423 | | | 424 | 1.39k | #ifdef D_LOSSLESS_SUPPORTED | 425 | 1.39k | if (cinfo->master->lossless) { | 426 | 516 | #if BITS_IN_JSAMPLE == 8 | 427 | 516 | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 428 | | #else | 429 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 430 | | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 431 | | #endif | 432 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 433 | 516 | } else | 434 | 874 | #endif | 435 | 874 | { | 436 | 874 | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 437 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 438 | 874 | } | 439 | | | 440 | 1.39k | if (!cinfo->master->jinit_upsampler_no_alloc) { | 441 | 1.39k | upsample = (my_upsample_ptr) | 442 | 1.39k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 443 | 1.39k | sizeof(my_upsampler)); | 444 | 1.39k | cinfo->upsample = (struct jpeg_upsampler *)upsample; | 445 | 1.39k | upsample->pub.start_pass = start_pass_upsample; | 446 | 1.39k | upsample->pub._upsample = sep_upsample; | 447 | 1.39k | upsample->pub.need_context_rows = FALSE; /* until we find out differently */ | 448 | 1.39k | } else | 449 | 0 | upsample = (my_upsample_ptr)cinfo->upsample; | 450 | | | 451 | 1.39k | if (cinfo->CCIR601_sampling) /* this isn't supported */ | 452 | 0 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); | 453 | | | 454 | | /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, | 455 | | * so don't ask for it. | 456 | | */ | 457 | 1.39k | do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1; | 458 | | | 459 | | /* Verify we can handle the sampling factors, select per-component methods, | 460 | | * and create storage as needed. | 461 | | */ | 462 | 4.54k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 463 | 3.15k | ci++, compptr++) { | 464 | | /* Compute size of an "input group" after IDCT scaling. This many samples | 465 | | * are to be converted to max_h_samp_factor * max_v_samp_factor pixels. | 466 | | */ | 467 | 3.15k | h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) / | 468 | 3.15k | cinfo->_min_DCT_scaled_size; | 469 | 3.15k | v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / | 470 | 3.15k | cinfo->_min_DCT_scaled_size; | 471 | 3.15k | h_out_group = cinfo->max_h_samp_factor; | 472 | 3.15k | v_out_group = cinfo->max_v_samp_factor; | 473 | 3.15k | upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ | 474 | 3.15k | need_buffer = TRUE; | 475 | 3.15k | if (!compptr->component_needed) { | 476 | | /* Don't bother to upsample an uninteresting component. */ | 477 | 318 | upsample->methods[ci] = noop_upsample; | 478 | 318 | need_buffer = FALSE; | 479 | 2.83k | } else if (h_in_group == h_out_group && v_in_group == v_out_group) { | 480 | | /* Fullsize components can be processed without any work. */ | 481 | 1.56k | upsample->methods[ci] = fullsize_upsample; | 482 | 1.56k | need_buffer = FALSE; | 483 | 1.56k | } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) { | 484 | | /* Special cases for 2h1v upsampling */ | 485 | 106 | if (do_fancy && compptr->downsampled_width > 2) { | 486 | 0 | #ifdef WITH_SIMD | 487 | 0 | if (jsimd_can_h2v1_fancy_upsample()) | 488 | 0 | upsample->methods[ci] = jsimd_h2v1_fancy_upsample; | 489 | 0 | else | 490 | 0 | #endif | 491 | 0 | upsample->methods[ci] = h2v1_fancy_upsample; | 492 | 106 | } else { | 493 | 106 | #ifdef WITH_SIMD | 494 | 106 | if (jsimd_can_h2v1_upsample()) | 495 | 106 | upsample->methods[ci] = jsimd_h2v1_upsample; | 496 | 0 | else | 497 | 0 | #endif | 498 | 0 | upsample->methods[ci] = h2v1_upsample; | 499 | 106 | } | 500 | 1.16k | } else if (h_in_group == h_out_group && | 501 | 1.16k | v_in_group * 2 == v_out_group && do_fancy) { | 502 | | /* Non-fancy upsampling is handled by the generic method */ | 503 | | #if defined(WITH_SIMD) && (defined(__arm__) || defined(__aarch64__) || \ | 504 | | defined(_M_ARM) || defined(_M_ARM64)) | 505 | | if (jsimd_can_h1v2_fancy_upsample()) | 506 | | upsample->methods[ci] = jsimd_h1v2_fancy_upsample; | 507 | | else | 508 | | #endif | 509 | 0 | upsample->methods[ci] = h1v2_fancy_upsample; | 510 | 0 | upsample->pub.need_context_rows = TRUE; | 511 | 1.16k | } else if (h_in_group * 2 == h_out_group && | 512 | 1.16k | v_in_group * 2 == v_out_group) { | 513 | | /* Special cases for 2h2v upsampling */ | 514 | 822 | if (do_fancy && compptr->downsampled_width > 2) { | 515 | 0 | #ifdef WITH_SIMD | 516 | 0 | if (jsimd_can_h2v2_fancy_upsample()) | 517 | 0 | upsample->methods[ci] = jsimd_h2v2_fancy_upsample; | 518 | 0 | else | 519 | 0 | #endif | 520 | 0 | upsample->methods[ci] = h2v2_fancy_upsample; | 521 | 0 | upsample->pub.need_context_rows = TRUE; | 522 | 822 | } else { | 523 | 822 | #ifdef WITH_SIMD | 524 | 822 | if (jsimd_can_h2v2_upsample()) | 525 | 822 | upsample->methods[ci] = jsimd_h2v2_upsample; | 526 | 0 | else | 527 | 0 | #endif | 528 | 0 | upsample->methods[ci] = h2v2_upsample; | 529 | 822 | } | 530 | 822 | } else if ((h_out_group % h_in_group) == 0 && | 531 | 338 | (v_out_group % v_in_group) == 0) { | 532 | | /* Generic integral-factors upsampling method */ | 533 | | #if defined(WITH_SIMD) && defined(__mips__) | 534 | | if (jsimd_can_int_upsample()) | 535 | | upsample->methods[ci] = jsimd_int_upsample; | 536 | | else | 537 | | #endif | 538 | 338 | upsample->methods[ci] = int_upsample; | 539 | 338 | upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group); | 540 | 338 | upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group); | 541 | 338 | } else | 542 | 0 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); | 543 | 3.15k | if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) { | 544 | 1.26k | upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 545 | 1.26k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 546 | 1.26k | (JDIMENSION)jround_up((long)cinfo->output_width, | 547 | 1.26k | (long)cinfo->max_h_samp_factor), | 548 | 1.26k | (JDIMENSION)cinfo->max_v_samp_factor); | 549 | 1.26k | } | 550 | 3.15k | } | 551 | 1.39k | } |
Line | Count | Source | 417 | 430 | { | 418 | 430 | my_upsample_ptr upsample; | 419 | 430 | int ci; | 420 | 430 | jpeg_component_info *compptr; | 421 | 430 | boolean need_buffer, do_fancy; | 422 | 430 | int h_in_group, v_in_group, h_out_group, v_out_group; | 423 | | | 424 | 430 | #ifdef D_LOSSLESS_SUPPORTED | 425 | 430 | if (cinfo->master->lossless) { | 426 | | #if BITS_IN_JSAMPLE == 8 | 427 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 428 | | #else | 429 | 430 | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 430 | 430 | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 431 | 0 | #endif | 432 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 433 | 430 | } else | 434 | 0 | #endif | 435 | 0 | { | 436 | 0 | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 437 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 438 | 0 | } | 439 | | | 440 | 430 | if (!cinfo->master->jinit_upsampler_no_alloc) { | 441 | 430 | upsample = (my_upsample_ptr) | 442 | 430 | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 443 | 430 | sizeof(my_upsampler)); | 444 | 430 | cinfo->upsample = (struct jpeg_upsampler *)upsample; | 445 | 430 | upsample->pub.start_pass = start_pass_upsample; | 446 | 430 | upsample->pub._upsample = sep_upsample; | 447 | 430 | upsample->pub.need_context_rows = FALSE; /* until we find out differently */ | 448 | 430 | } else | 449 | 0 | upsample = (my_upsample_ptr)cinfo->upsample; | 450 | | | 451 | 430 | if (cinfo->CCIR601_sampling) /* this isn't supported */ | 452 | 0 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); | 453 | | | 454 | | /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, | 455 | | * so don't ask for it. | 456 | | */ | 457 | 430 | do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1; | 458 | | | 459 | | /* Verify we can handle the sampling factors, select per-component methods, | 460 | | * and create storage as needed. | 461 | | */ | 462 | 1.67k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 463 | 1.24k | ci++, compptr++) { | 464 | | /* Compute size of an "input group" after IDCT scaling. This many samples | 465 | | * are to be converted to max_h_samp_factor * max_v_samp_factor pixels. | 466 | | */ | 467 | 1.24k | h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) / | 468 | 1.24k | cinfo->_min_DCT_scaled_size; | 469 | 1.24k | v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / | 470 | 1.24k | cinfo->_min_DCT_scaled_size; | 471 | 1.24k | h_out_group = cinfo->max_h_samp_factor; | 472 | 1.24k | v_out_group = cinfo->max_v_samp_factor; | 473 | 1.24k | upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ | 474 | 1.24k | need_buffer = TRUE; | 475 | 1.24k | if (!compptr->component_needed) { | 476 | | /* Don't bother to upsample an uninteresting component. */ | 477 | 0 | upsample->methods[ci] = noop_upsample; | 478 | 0 | need_buffer = FALSE; | 479 | 1.24k | } else if (h_in_group == h_out_group && v_in_group == v_out_group) { | 480 | | /* Fullsize components can be processed without any work. */ | 481 | 484 | upsample->methods[ci] = fullsize_upsample; | 482 | 484 | need_buffer = FALSE; | 483 | 758 | } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) { | 484 | | /* Special cases for 2h1v upsampling */ | 485 | 90 | if (do_fancy && compptr->downsampled_width > 2) { | 486 | | #ifdef WITH_SIMD | 487 | | if (jsimd_can_h2v1_fancy_upsample()) | 488 | | upsample->methods[ci] = jsimd_h2v1_fancy_upsample; | 489 | | else | 490 | | #endif | 491 | 0 | upsample->methods[ci] = h2v1_fancy_upsample; | 492 | 90 | } else { | 493 | | #ifdef WITH_SIMD | 494 | | if (jsimd_can_h2v1_upsample()) | 495 | | upsample->methods[ci] = jsimd_h2v1_upsample; | 496 | | else | 497 | | #endif | 498 | 90 | upsample->methods[ci] = h2v1_upsample; | 499 | 90 | } | 500 | 668 | } else if (h_in_group == h_out_group && | 501 | 668 | v_in_group * 2 == v_out_group && do_fancy) { | 502 | | /* Non-fancy upsampling is handled by the generic method */ | 503 | | #if defined(WITH_SIMD) && (defined(__arm__) || defined(__aarch64__) || \ | 504 | | defined(_M_ARM) || defined(_M_ARM64)) | 505 | | if (jsimd_can_h1v2_fancy_upsample()) | 506 | | upsample->methods[ci] = jsimd_h1v2_fancy_upsample; | 507 | | else | 508 | | #endif | 509 | 0 | upsample->methods[ci] = h1v2_fancy_upsample; | 510 | 0 | upsample->pub.need_context_rows = TRUE; | 511 | 668 | } else if (h_in_group * 2 == h_out_group && | 512 | 668 | v_in_group * 2 == v_out_group) { | 513 | | /* Special cases for 2h2v upsampling */ | 514 | 624 | if (do_fancy && compptr->downsampled_width > 2) { | 515 | | #ifdef WITH_SIMD | 516 | | if (jsimd_can_h2v2_fancy_upsample()) | 517 | | upsample->methods[ci] = jsimd_h2v2_fancy_upsample; | 518 | | else | 519 | | #endif | 520 | 0 | upsample->methods[ci] = h2v2_fancy_upsample; | 521 | 0 | upsample->pub.need_context_rows = TRUE; | 522 | 624 | } else { | 523 | | #ifdef WITH_SIMD | 524 | | if (jsimd_can_h2v2_upsample()) | 525 | | upsample->methods[ci] = jsimd_h2v2_upsample; | 526 | | else | 527 | | #endif | 528 | 624 | upsample->methods[ci] = h2v2_upsample; | 529 | 624 | } | 530 | 624 | } else if ((h_out_group % h_in_group) == 0 && | 531 | 44 | (v_out_group % v_in_group) == 0) { | 532 | | /* Generic integral-factors upsampling method */ | 533 | | #if defined(WITH_SIMD) && defined(__mips__) | 534 | | if (jsimd_can_int_upsample()) | 535 | | upsample->methods[ci] = jsimd_int_upsample; | 536 | | else | 537 | | #endif | 538 | 44 | upsample->methods[ci] = int_upsample; | 539 | 44 | upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group); | 540 | 44 | upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group); | 541 | 44 | } else | 542 | 0 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); | 543 | 1.24k | if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) { | 544 | 758 | upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 545 | 758 | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 546 | 758 | (JDIMENSION)jround_up((long)cinfo->output_width, | 547 | 758 | (long)cinfo->max_h_samp_factor), | 548 | 758 | (JDIMENSION)cinfo->max_v_samp_factor); | 549 | 758 | } | 550 | 1.24k | } | 551 | 430 | } |
Line | Count | Source | 417 | 388 | { | 418 | 388 | my_upsample_ptr upsample; | 419 | 388 | int ci; | 420 | 388 | jpeg_component_info *compptr; | 421 | 388 | boolean need_buffer, do_fancy; | 422 | 388 | int h_in_group, v_in_group, h_out_group, v_out_group; | 423 | | | 424 | 388 | #ifdef D_LOSSLESS_SUPPORTED | 425 | 388 | if (cinfo->master->lossless) { | 426 | | #if BITS_IN_JSAMPLE == 8 | 427 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 428 | | #else | 429 | 388 | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 430 | 388 | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 431 | 0 | #endif | 432 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 433 | 388 | } else | 434 | 0 | #endif | 435 | 0 | { | 436 | 0 | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 437 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 438 | 0 | } | 439 | | | 440 | 388 | if (!cinfo->master->jinit_upsampler_no_alloc) { | 441 | 388 | upsample = (my_upsample_ptr) | 442 | 388 | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 443 | 388 | sizeof(my_upsampler)); | 444 | 388 | cinfo->upsample = (struct jpeg_upsampler *)upsample; | 445 | 388 | upsample->pub.start_pass = start_pass_upsample; | 446 | 388 | upsample->pub._upsample = sep_upsample; | 447 | 388 | upsample->pub.need_context_rows = FALSE; /* until we find out differently */ | 448 | 388 | } else | 449 | 0 | upsample = (my_upsample_ptr)cinfo->upsample; | 450 | | | 451 | 388 | if (cinfo->CCIR601_sampling) /* this isn't supported */ | 452 | 0 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); | 453 | | | 454 | | /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, | 455 | | * so don't ask for it. | 456 | | */ | 457 | 388 | do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1; | 458 | | | 459 | | /* Verify we can handle the sampling factors, select per-component methods, | 460 | | * and create storage as needed. | 461 | | */ | 462 | 1.51k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 463 | 1.12k | ci++, compptr++) { | 464 | | /* Compute size of an "input group" after IDCT scaling. This many samples | 465 | | * are to be converted to max_h_samp_factor * max_v_samp_factor pixels. | 466 | | */ | 467 | 1.12k | h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) / | 468 | 1.12k | cinfo->_min_DCT_scaled_size; | 469 | 1.12k | v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / | 470 | 1.12k | cinfo->_min_DCT_scaled_size; | 471 | 1.12k | h_out_group = cinfo->max_h_samp_factor; | 472 | 1.12k | v_out_group = cinfo->max_v_samp_factor; | 473 | 1.12k | upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ | 474 | 1.12k | need_buffer = TRUE; | 475 | 1.12k | if (!compptr->component_needed) { | 476 | | /* Don't bother to upsample an uninteresting component. */ | 477 | 0 | upsample->methods[ci] = noop_upsample; | 478 | 0 | need_buffer = FALSE; | 479 | 1.12k | } else if (h_in_group == h_out_group && v_in_group == v_out_group) { | 480 | | /* Fullsize components can be processed without any work. */ | 481 | 438 | upsample->methods[ci] = fullsize_upsample; | 482 | 438 | need_buffer = FALSE; | 483 | 686 | } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) { | 484 | | /* Special cases for 2h1v upsampling */ | 485 | 114 | if (do_fancy && compptr->downsampled_width > 2) { | 486 | | #ifdef WITH_SIMD | 487 | | if (jsimd_can_h2v1_fancy_upsample()) | 488 | | upsample->methods[ci] = jsimd_h2v1_fancy_upsample; | 489 | | else | 490 | | #endif | 491 | 0 | upsample->methods[ci] = h2v1_fancy_upsample; | 492 | 114 | } else { | 493 | | #ifdef WITH_SIMD | 494 | | if (jsimd_can_h2v1_upsample()) | 495 | | upsample->methods[ci] = jsimd_h2v1_upsample; | 496 | | else | 497 | | #endif | 498 | 114 | upsample->methods[ci] = h2v1_upsample; | 499 | 114 | } | 500 | 572 | } else if (h_in_group == h_out_group && | 501 | 572 | v_in_group * 2 == v_out_group && do_fancy) { | 502 | | /* Non-fancy upsampling is handled by the generic method */ | 503 | | #if defined(WITH_SIMD) && (defined(__arm__) || defined(__aarch64__) || \ | 504 | | defined(_M_ARM) || defined(_M_ARM64)) | 505 | | if (jsimd_can_h1v2_fancy_upsample()) | 506 | | upsample->methods[ci] = jsimd_h1v2_fancy_upsample; | 507 | | else | 508 | | #endif | 509 | 0 | upsample->methods[ci] = h1v2_fancy_upsample; | 510 | 0 | upsample->pub.need_context_rows = TRUE; | 511 | 572 | } else if (h_in_group * 2 == h_out_group && | 512 | 572 | v_in_group * 2 == v_out_group) { | 513 | | /* Special cases for 2h2v upsampling */ | 514 | 510 | if (do_fancy && compptr->downsampled_width > 2) { | 515 | | #ifdef WITH_SIMD | 516 | | if (jsimd_can_h2v2_fancy_upsample()) | 517 | | upsample->methods[ci] = jsimd_h2v2_fancy_upsample; | 518 | | else | 519 | | #endif | 520 | 0 | upsample->methods[ci] = h2v2_fancy_upsample; | 521 | 0 | upsample->pub.need_context_rows = TRUE; | 522 | 510 | } else { | 523 | | #ifdef WITH_SIMD | 524 | | if (jsimd_can_h2v2_upsample()) | 525 | | upsample->methods[ci] = jsimd_h2v2_upsample; | 526 | | else | 527 | | #endif | 528 | 510 | upsample->methods[ci] = h2v2_upsample; | 529 | 510 | } | 530 | 510 | } else if ((h_out_group % h_in_group) == 0 && | 531 | 62 | (v_out_group % v_in_group) == 0) { | 532 | | /* Generic integral-factors upsampling method */ | 533 | | #if defined(WITH_SIMD) && defined(__mips__) | 534 | | if (jsimd_can_int_upsample()) | 535 | | upsample->methods[ci] = jsimd_int_upsample; | 536 | | else | 537 | | #endif | 538 | 62 | upsample->methods[ci] = int_upsample; | 539 | 62 | upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group); | 540 | 62 | upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group); | 541 | 62 | } else | 542 | 0 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); | 543 | 1.12k | if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) { | 544 | 686 | upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 545 | 686 | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 546 | 686 | (JDIMENSION)jround_up((long)cinfo->output_width, | 547 | 686 | (long)cinfo->max_h_samp_factor), | 548 | 686 | (JDIMENSION)cinfo->max_v_samp_factor); | 549 | 686 | } | 550 | 1.12k | } | 551 | 388 | } |
|
552 | | |
553 | | #endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */ |