/src/libjpeg-turbo/src/jcsample.c
Line | Count | Source |
1 | | /* |
2 | | * jcsample.c |
3 | | * |
4 | | * This file was part of the Independent JPEG Group's software: |
5 | | * Copyright (C) 1991-1996, Thomas G. Lane. |
6 | | * Lossless JPEG Modifications: |
7 | | * Copyright (C) 1999, Ken Murchison. |
8 | | * libjpeg-turbo Modifications: |
9 | | * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
10 | | * Copyright (C) 2015, 2019, 2022, 2024-2026, D. R. Commander. |
11 | | * For conditions of distribution and use, see the accompanying README.ijg |
12 | | * file. |
13 | | * |
14 | | * This file contains downsampling routines. |
15 | | * |
16 | | * Downsampling input data is counted in "row groups". A row group is defined |
17 | | * to be max_v_samp_factor rows of each component, from which the downsampler |
18 | | * produces v_samp_factor sample rows. A single row group is processed in each |
19 | | * call to the downsampler module. |
20 | | * |
21 | | * The downsampler is responsible for edge-expansion of its output data |
22 | | * to fill an integral number of DCT blocks horizontally. The source buffer |
23 | | * may be modified if it is helpful for this purpose (the source buffer is |
24 | | * allocated wide enough to correspond to the desired output width). |
25 | | * The caller (the prep controller) is responsible for vertical padding. |
26 | | * |
27 | | * The downsampler may request "context rows" by setting need_context_rows |
28 | | * during startup. In this case, the input arrays will contain at least one |
29 | | * row group's worth of components above and below the passed-in data; the |
30 | | * caller will create dummy rows at image top and bottom by replicating the |
31 | | * first or last real component row(s). |
32 | | * |
33 | | * An excellent reference for image resampling is |
34 | | * Digital Image Warping, George Wolberg, 1990. |
35 | | * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. |
36 | | * |
37 | | * The downsampling algorithm used here is a simple average of the source |
38 | | * components covered by the output sample. The hi-falutin sampling literature |
39 | | * refers to this as a "box filter". In general, the characteristics of a box |
40 | | * filter are not very good. However, for the specific cases we normally use |
41 | | * (1:1 and 2:1 ratios), the box is equivalent to a "triangle filter", which is |
42 | | * not nearly so bad. If you intend to use other sampling ratios, you'd be |
43 | | * well advised to improve this code. |
44 | | * |
45 | | * A simple input-smoothing capability is provided. This is mainly intended |
46 | | * for cleaning up color-dithered GIF input files. (If you find it inadequate, |
47 | | * we suggest using an external filtering program such as pnmconvol). When |
48 | | * enabled, each input component C is replaced by a weighted sum of itself and |
49 | | * its eight neighbors. C's weight is 1-8*SF, and each neighbor's weight is |
50 | | * SF, where SF = (smoothing_factor / 1024). |
51 | | * Currently, smoothing is only supported for 2h2v sampling factors. |
52 | | */ |
53 | | |
54 | | #define JPEG_INTERNALS |
55 | | #include "jinclude.h" |
56 | | #include "jpeglib.h" |
57 | | #ifdef WITH_SIMD |
58 | | #include "../simd/jsimd.h" |
59 | | #endif |
60 | | #include "jsamplecomp.h" |
61 | | |
62 | | |
63 | | #if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) |
64 | | |
65 | | /* Pointer to routine to downsample a single component */ |
66 | | typedef void (*downsample1_ptr) (j_compress_ptr cinfo, |
67 | | jpeg_component_info *compptr, |
68 | | _JSAMPARRAY input_data, |
69 | | _JSAMPARRAY output_data); |
70 | | |
71 | | /* Private subobject */ |
72 | | |
73 | | typedef struct { |
74 | | struct jpeg_downsampler pub; /* public fields */ |
75 | | |
76 | | /* Downsampling method pointers, one per component */ |
77 | | downsample1_ptr methods[MAX_COMPONENTS]; |
78 | | } my_downsampler; |
79 | | |
80 | | typedef my_downsampler *my_downsample_ptr; |
81 | | |
82 | | |
83 | | /* |
84 | | * Initialize for a downsampling pass. |
85 | | */ |
86 | | |
87 | | METHODDEF(void) |
88 | | start_pass_downsample(j_compress_ptr cinfo) |
89 | 0 | { |
90 | | /* no work for now */ |
91 | 0 | } Unexecuted instantiation: jcsample-8.c:start_pass_downsample Unexecuted instantiation: jcsample-12.c:start_pass_downsample Unexecuted instantiation: jcsample-16.c:start_pass_downsample |
92 | | |
93 | | |
94 | | /* |
95 | | * Expand a component horizontally from width input_cols to width output_cols, |
96 | | * by duplicating the rightmost samples. |
97 | | */ |
98 | | |
99 | | LOCAL(void) |
100 | | expand_right_edge(_JSAMPARRAY image_data, int num_rows, JDIMENSION input_cols, |
101 | | JDIMENSION output_cols) |
102 | 0 | { |
103 | 0 | register _JSAMPROW ptr; |
104 | 0 | register _JSAMPLE pixval; |
105 | 0 | register int count; |
106 | 0 | int row; |
107 | 0 | int numcols = (int)(output_cols - input_cols); |
108 | |
|
109 | 0 | if (numcols > 0) { |
110 | 0 | for (row = 0; row < num_rows; row++) { |
111 | 0 | ptr = image_data[row] + input_cols; |
112 | 0 | pixval = ptr[-1]; |
113 | 0 | for (count = numcols; count > 0; count--) |
114 | 0 | *ptr++ = pixval; |
115 | 0 | } |
116 | 0 | } |
117 | 0 | } Unexecuted instantiation: jcsample-8.c:expand_right_edge Unexecuted instantiation: jcsample-12.c:expand_right_edge Unexecuted instantiation: jcsample-16.c:expand_right_edge |
118 | | |
119 | | |
120 | | /* |
121 | | * Do downsampling for a whole row group (all components). |
122 | | * |
123 | | * In this version we simply downsample each component independently. |
124 | | */ |
125 | | |
126 | | METHODDEF(void) |
127 | | sep_downsample(j_compress_ptr cinfo, _JSAMPIMAGE input_buf, |
128 | | JDIMENSION in_row_index, _JSAMPIMAGE output_buf, |
129 | | JDIMENSION out_row_group_index) |
130 | 0 | { |
131 | 0 | my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample; |
132 | 0 | int ci; |
133 | 0 | jpeg_component_info *compptr; |
134 | 0 | _JSAMPARRAY in_ptr, out_ptr; |
135 | |
|
136 | 0 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
137 | 0 | ci++, compptr++) { |
138 | 0 | in_ptr = input_buf[ci] + in_row_index; |
139 | 0 | out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor); |
140 | 0 | (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr); |
141 | 0 | } |
142 | 0 | } Unexecuted instantiation: jcsample-8.c:sep_downsample Unexecuted instantiation: jcsample-12.c:sep_downsample Unexecuted instantiation: jcsample-16.c:sep_downsample |
143 | | |
144 | | |
145 | | /* |
146 | | * Downsample components from a single plane. |
147 | | * One row group is processed per call. |
148 | | * This version handles arbitrary integral sampling ratios, without smoothing. |
149 | | * Note that this version is not actually used for customary sampling ratios. |
150 | | */ |
151 | | |
152 | | METHODDEF(void) |
153 | | int_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
154 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
155 | 0 | { |
156 | 0 | int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v; |
157 | 0 | JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */ |
158 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
159 | 0 | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
160 | 0 | _JSAMPROW inptr, outptr; |
161 | 0 | JLONG outvalue; |
162 | |
|
163 | 0 | h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor; |
164 | 0 | v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor; |
165 | 0 | numpix = h_expand * v_expand; |
166 | 0 | numpix2 = numpix / 2; |
167 | | |
168 | | /* Expand input data enough to let all the output samples be generated |
169 | | * by the standard loop. Special-casing padded output would be more |
170 | | * efficient. |
171 | | */ |
172 | 0 | expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width, |
173 | 0 | output_cols * h_expand); |
174 | |
|
175 | 0 | inrow = 0; |
176 | 0 | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
177 | 0 | outptr = output_data[outrow]; |
178 | 0 | for (outcol = 0, outcol_h = 0; outcol < output_cols; |
179 | 0 | outcol++, outcol_h += h_expand) { |
180 | 0 | outvalue = 0; |
181 | 0 | for (v = 0; v < v_expand; v++) { |
182 | 0 | inptr = input_data[inrow + v] + outcol_h; |
183 | 0 | for (h = 0; h < h_expand; h++) { |
184 | 0 | outvalue += (JLONG)(*inptr++); |
185 | 0 | } |
186 | 0 | } |
187 | 0 | *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix); |
188 | 0 | } |
189 | 0 | inrow += v_expand; |
190 | 0 | } |
191 | 0 | } Unexecuted instantiation: jcsample-8.c:int_downsample Unexecuted instantiation: jcsample-12.c:int_downsample Unexecuted instantiation: jcsample-16.c:int_downsample |
192 | | |
193 | | |
194 | | /* |
195 | | * Downsample components from a single plane. |
196 | | * This version handles the special case of a full-size component, |
197 | | * without smoothing. |
198 | | */ |
199 | | |
200 | | METHODDEF(void) |
201 | | fullsize_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
202 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
203 | 0 | { |
204 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
205 | | |
206 | | /* Copy the data */ |
207 | 0 | _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor, |
208 | 0 | cinfo->image_width); |
209 | | /* Edge-expand */ |
210 | 0 | expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width, |
211 | 0 | compptr->width_in_blocks * data_unit); |
212 | 0 | } Unexecuted instantiation: jcsample-8.c:fullsize_downsample Unexecuted instantiation: jcsample-12.c:fullsize_downsample Unexecuted instantiation: jcsample-16.c:fullsize_downsample |
213 | | |
214 | | |
215 | | /* |
216 | | * Downsample components from a single plane. |
217 | | * This version handles the common case of 2:1 horizontal and 1:1 vertical, |
218 | | * without smoothing. |
219 | | * |
220 | | * A note about the "bias" calculations: when rounding fractional values to |
221 | | * integer, we do not want to always round 0.5 up to the next integer. |
222 | | * If we did that, we'd introduce a noticeable bias towards larger values. |
223 | | * Instead, this code is arranged so that 0.5 will be rounded up or down at |
224 | | * alternate pixel locations (a simple ordered dither pattern). |
225 | | */ |
226 | | |
227 | | METHODDEF(void) |
228 | | h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
229 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
230 | 0 | { |
231 | 0 | int outrow; |
232 | 0 | JDIMENSION outcol; |
233 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
234 | 0 | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
235 | 0 | register _JSAMPROW inptr, outptr; |
236 | 0 | register int bias; |
237 | | |
238 | | /* Expand input data enough to let all the output samples be generated |
239 | | * by the standard loop. Special-casing padded output would be more |
240 | | * efficient. |
241 | | */ |
242 | 0 | expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width, |
243 | 0 | output_cols * 2); |
244 | |
|
245 | 0 | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
246 | 0 | outptr = output_data[outrow]; |
247 | 0 | inptr = input_data[outrow]; |
248 | 0 | bias = 0; /* bias = 0,1,0,1,... for successive samples */ |
249 | 0 | for (outcol = 0; outcol < output_cols; outcol++) { |
250 | 0 | *outptr++ = (_JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1); |
251 | 0 | bias ^= 1; /* 0=>1, 1=>0 */ |
252 | 0 | inptr += 2; |
253 | 0 | } |
254 | 0 | } |
255 | 0 | } Unexecuted instantiation: jcsample-8.c:h2v1_downsample Unexecuted instantiation: jcsample-12.c:h2v1_downsample Unexecuted instantiation: jcsample-16.c:h2v1_downsample |
256 | | |
257 | | |
258 | | /* |
259 | | * Downsample components from a single plane. |
260 | | * This version handles the standard case of 2:1 horizontal and 2:1 vertical, |
261 | | * without smoothing. |
262 | | */ |
263 | | |
264 | | METHODDEF(void) |
265 | | h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
266 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
267 | 0 | { |
268 | 0 | int inrow, outrow; |
269 | 0 | JDIMENSION outcol; |
270 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
271 | 0 | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
272 | 0 | register _JSAMPROW inptr0, inptr1, outptr; |
273 | 0 | register int bias; |
274 | | |
275 | | /* Expand input data enough to let all the output samples be generated |
276 | | * by the standard loop. Special-casing padded output would be more |
277 | | * efficient. |
278 | | */ |
279 | 0 | expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width, |
280 | 0 | output_cols * 2); |
281 | |
|
282 | 0 | inrow = 0; |
283 | 0 | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
284 | 0 | outptr = output_data[outrow]; |
285 | 0 | inptr0 = input_data[inrow]; |
286 | 0 | inptr1 = input_data[inrow + 1]; |
287 | 0 | bias = 1; /* bias = 1,2,1,2,... for successive samples */ |
288 | 0 | for (outcol = 0; outcol < output_cols; outcol++) { |
289 | 0 | *outptr++ = (_JSAMPLE) |
290 | 0 | ((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2); |
291 | 0 | bias ^= 3; /* 1=>2, 2=>1 */ |
292 | 0 | inptr0 += 2; inptr1 += 2; |
293 | 0 | } |
294 | 0 | inrow += 2; |
295 | 0 | } |
296 | 0 | } Unexecuted instantiation: jcsample-8.c:h2v2_downsample Unexecuted instantiation: jcsample-12.c:h2v2_downsample Unexecuted instantiation: jcsample-16.c:h2v2_downsample |
297 | | |
298 | | |
299 | | #ifdef INPUT_SMOOTHING_SUPPORTED |
300 | | |
301 | | /* |
302 | | * Downsample components from a single plane. |
303 | | * This version handles the standard case of 2:1 horizontal and 2:1 vertical, |
304 | | * with smoothing. One row of context is required. |
305 | | */ |
306 | | |
307 | | METHODDEF(void) |
308 | | h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
309 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
310 | 0 | { |
311 | 0 | int inrow, outrow; |
312 | 0 | JDIMENSION colctr; |
313 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
314 | 0 | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
315 | 0 | register _JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr; |
316 | 0 | JLONG membersum, neighsum, memberscale, neighscale; |
317 | | |
318 | | /* Expand input data enough to let all the output samples be generated |
319 | | * by the standard loop. Special-casing padded output would be more |
320 | | * efficient. |
321 | | */ |
322 | 0 | expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, |
323 | 0 | cinfo->image_width, output_cols * 2); |
324 | | |
325 | | /* We don't bother to form the individual "smoothed" input component values; |
326 | | * we can directly compute the output which is the average of the four |
327 | | * smoothed values. Each of the four member components contributes a |
328 | | * fraction (1-8*SF) to its own smoothed image and a fraction SF to each of |
329 | | * the three other smoothed components, therefore a total fraction (1-5*SF)/4 |
330 | | * to the final output. The four corner-adjacent neighbor components |
331 | | * contribute a fraction SF to just one smoothed component, or SF/4 to the |
332 | | * final output; while the eight edge-adjacent neighbors contribute SF to |
333 | | * each of two smoothed components, or SF/2 overall. In order to use integer |
334 | | * arithmetic, these factors are scaled by 2^16 = 65536. Also recall that |
335 | | * SF = smoothing_factor / 1024. |
336 | | */ |
337 | |
|
338 | 0 | memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */ |
339 | 0 | neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */ |
340 | |
|
341 | 0 | inrow = 0; |
342 | 0 | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
343 | 0 | outptr = output_data[outrow]; |
344 | 0 | inptr0 = input_data[inrow]; |
345 | 0 | inptr1 = input_data[inrow + 1]; |
346 | 0 | above_ptr = input_data[inrow - 1]; |
347 | 0 | below_ptr = input_data[inrow + 2]; |
348 | | |
349 | | /* Special case for first column: pretend column -1 is same as column 0 */ |
350 | 0 | membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1]; |
351 | 0 | neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] + |
352 | 0 | inptr0[0] + inptr0[2] + inptr1[0] + inptr1[2]; |
353 | 0 | neighsum += neighsum; |
354 | 0 | neighsum += above_ptr[0] + above_ptr[2] + below_ptr[0] + below_ptr[2]; |
355 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
356 | 0 | *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16); |
357 | 0 | inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; |
358 | |
|
359 | 0 | for (colctr = output_cols - 2; colctr > 0; colctr--) { |
360 | | /* sum of components directly mapped to this output element */ |
361 | 0 | membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1]; |
362 | | /* sum of edge-neighbor components */ |
363 | 0 | neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] + |
364 | 0 | inptr0[-1] + inptr0[2] + inptr1[-1] + inptr1[2]; |
365 | | /* The edge-neighbors count twice as much as corner-neighbors */ |
366 | 0 | neighsum += neighsum; |
367 | | /* Add in the corner-neighbors */ |
368 | 0 | neighsum += above_ptr[-1] + above_ptr[2] + below_ptr[-1] + below_ptr[2]; |
369 | | /* form final output scaled up by 2^16 */ |
370 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
371 | | /* round, descale and output it */ |
372 | 0 | *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16); |
373 | 0 | inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; |
374 | 0 | } |
375 | | |
376 | | /* Special case for last column */ |
377 | 0 | membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1]; |
378 | 0 | neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] + |
379 | 0 | inptr0[-1] + inptr0[1] + inptr1[-1] + inptr1[1]; |
380 | 0 | neighsum += neighsum; |
381 | 0 | neighsum += above_ptr[-1] + above_ptr[1] + below_ptr[-1] + below_ptr[1]; |
382 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
383 | 0 | *outptr = (_JSAMPLE)((membersum + 32768) >> 16); |
384 | |
|
385 | 0 | inrow += 2; |
386 | 0 | } |
387 | 0 | } Unexecuted instantiation: jcsample-8.c:h2v2_smooth_downsample Unexecuted instantiation: jcsample-12.c:h2v2_smooth_downsample Unexecuted instantiation: jcsample-16.c:h2v2_smooth_downsample |
388 | | |
389 | | |
390 | | /* |
391 | | * Downsample components from a single plane. |
392 | | * This version handles the special case of a full-size component, |
393 | | * with smoothing. One row of context is required. |
394 | | */ |
395 | | |
396 | | METHODDEF(void) |
397 | | fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
398 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
399 | 0 | { |
400 | 0 | int outrow; |
401 | 0 | JDIMENSION colctr; |
402 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
403 | 0 | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
404 | 0 | register _JSAMPROW inptr, above_ptr, below_ptr, outptr; |
405 | 0 | JLONG membersum, neighsum, memberscale, neighscale; |
406 | 0 | int colsum, lastcolsum, nextcolsum; |
407 | | |
408 | | /* Expand input data enough to let all the output samples be generated |
409 | | * by the standard loop. Special-casing padded output would be more |
410 | | * efficient. |
411 | | */ |
412 | 0 | expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, |
413 | 0 | cinfo->image_width, output_cols); |
414 | | |
415 | | /* Each of the eight neighbor components contributes a fraction SF to the |
416 | | * smoothed component, while the main component contributes (1-8*SF). In |
417 | | * order to use integer arithmetic, these factors are multiplied by |
418 | | * 2^16 = 65536. Also recall that SF = smoothing_factor / 1024. |
419 | | */ |
420 | |
|
421 | 0 | memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */ |
422 | 0 | neighscale = cinfo->smoothing_factor * 64; /* scaled SF */ |
423 | |
|
424 | 0 | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
425 | 0 | outptr = output_data[outrow]; |
426 | 0 | inptr = input_data[outrow]; |
427 | 0 | above_ptr = input_data[outrow - 1]; |
428 | 0 | below_ptr = input_data[outrow + 1]; |
429 | | |
430 | | /* Special case for first column */ |
431 | 0 | colsum = (*above_ptr++) + (*below_ptr++) + inptr[0]; |
432 | 0 | membersum = *inptr++; |
433 | 0 | nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0]; |
434 | 0 | neighsum = colsum + (colsum - membersum) + nextcolsum; |
435 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
436 | 0 | *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16); |
437 | 0 | lastcolsum = colsum; colsum = nextcolsum; |
438 | |
|
439 | 0 | for (colctr = output_cols - 2; colctr > 0; colctr--) { |
440 | 0 | membersum = *inptr++; |
441 | 0 | above_ptr++; below_ptr++; |
442 | 0 | nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0]; |
443 | 0 | neighsum = lastcolsum + (colsum - membersum) + nextcolsum; |
444 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
445 | 0 | *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16); |
446 | 0 | lastcolsum = colsum; colsum = nextcolsum; |
447 | 0 | } |
448 | | |
449 | | /* Special case for last column */ |
450 | 0 | membersum = *inptr; |
451 | 0 | neighsum = lastcolsum + (colsum - membersum) + colsum; |
452 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
453 | 0 | *outptr = (_JSAMPLE)((membersum + 32768) >> 16); |
454 | |
|
455 | 0 | } |
456 | 0 | } Unexecuted instantiation: jcsample-8.c:fullsize_smooth_downsample Unexecuted instantiation: jcsample-12.c:fullsize_smooth_downsample Unexecuted instantiation: jcsample-16.c:fullsize_smooth_downsample |
457 | | |
458 | | #endif /* INPUT_SMOOTHING_SUPPORTED */ |
459 | | |
460 | | |
461 | | /* |
462 | | * Module initialization routine for downsampling. |
463 | | * Note that we must select a routine for each component. |
464 | | */ |
465 | | |
466 | | GLOBAL(void) |
467 | | _jinit_downsampler(j_compress_ptr cinfo) |
468 | 0 | { |
469 | 0 | my_downsample_ptr downsample; |
470 | 0 | int ci; |
471 | 0 | jpeg_component_info *compptr; |
472 | 0 | #ifdef INPUT_SMOOTHING_SUPPORTED |
473 | 0 | boolean smoothok = TRUE; |
474 | 0 | #endif |
475 | |
|
476 | 0 | #ifdef C_LOSSLESS_SUPPORTED |
477 | 0 | if (cinfo->master->lossless) { |
478 | | #if BITS_IN_JSAMPLE == 8 |
479 | 0 | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
480 | | #else |
481 | 0 | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
482 | 0 | cinfo->data_precision < BITS_IN_JSAMPLE - 3) |
483 | 0 | #endif |
484 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
485 | 0 | } else |
486 | 0 | #endif |
487 | 0 | { |
488 | 0 | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
489 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
490 | 0 | } |
491 | |
|
492 | 0 | downsample = (my_downsample_ptr) |
493 | 0 | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
494 | 0 | sizeof(my_downsampler)); |
495 | 0 | cinfo->downsample = (struct jpeg_downsampler *)downsample; |
496 | 0 | downsample->pub.start_pass = start_pass_downsample; |
497 | 0 | downsample->pub._downsample = sep_downsample; |
498 | 0 | downsample->pub.need_context_rows = FALSE; |
499 | |
|
500 | 0 | if (cinfo->CCIR601_sampling) |
501 | 0 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); |
502 | | |
503 | | /* Verify we can handle the sampling factors, and set up method pointers */ |
504 | 0 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
505 | 0 | ci++, compptr++) { |
506 | 0 | if (compptr->h_samp_factor == cinfo->max_h_samp_factor && |
507 | 0 | compptr->v_samp_factor == cinfo->max_v_samp_factor) { |
508 | 0 | #ifdef INPUT_SMOOTHING_SUPPORTED |
509 | 0 | if (cinfo->smoothing_factor) { |
510 | 0 | downsample->methods[ci] = fullsize_smooth_downsample; |
511 | 0 | downsample->pub.need_context_rows = TRUE; |
512 | 0 | } else |
513 | 0 | #endif |
514 | 0 | downsample->methods[ci] = fullsize_downsample; |
515 | 0 | } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && |
516 | 0 | compptr->v_samp_factor == cinfo->max_v_samp_factor) { |
517 | 0 | #ifdef INPUT_SMOOTHING_SUPPORTED |
518 | 0 | smoothok = FALSE; |
519 | 0 | #endif |
520 | | #ifdef WITH_SIMD |
521 | 0 | if (jsimd_set_h2v1_downsample(cinfo)) |
522 | 0 | downsample->methods[ci] = jsimd_h2v1_downsample; |
523 | 0 | else |
524 | 0 | #endif |
525 | 0 | downsample->methods[ci] = h2v1_downsample; |
526 | 0 | } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && |
527 | 0 | compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) { |
528 | 0 | #ifdef INPUT_SMOOTHING_SUPPORTED |
529 | 0 | if (cinfo->smoothing_factor) { |
530 | 0 | downsample->methods[ci] = h2v2_smooth_downsample; |
531 | 0 | downsample->pub.need_context_rows = TRUE; |
532 | 0 | } else |
533 | 0 | #endif |
534 | 0 | { |
535 | | #ifdef WITH_SIMD |
536 | 0 | if (jsimd_set_h2v2_downsample(cinfo)) |
537 | 0 | downsample->methods[ci] = jsimd_h2v2_downsample; |
538 | 0 | else |
539 | 0 | #endif |
540 | 0 | downsample->methods[ci] = h2v2_downsample; |
541 | 0 | } |
542 | 0 | } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 && |
543 | 0 | (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) { |
544 | 0 | #ifdef INPUT_SMOOTHING_SUPPORTED |
545 | 0 | smoothok = FALSE; |
546 | 0 | #endif |
547 | 0 | downsample->methods[ci] = int_downsample; |
548 | 0 | } else |
549 | 0 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); |
550 | 0 | } |
551 | |
|
552 | 0 | #ifdef INPUT_SMOOTHING_SUPPORTED |
553 | 0 | if (cinfo->smoothing_factor && !smoothok) |
554 | 0 | TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL); |
555 | 0 | #endif |
556 | 0 | } Unexecuted instantiation: jinit_downsampler Unexecuted instantiation: j12init_downsampler Unexecuted instantiation: j16init_downsampler |
557 | | |
558 | | #endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */ |