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