/src/libjpeg-turbo.main/jcsample.c
Line | Count | Source (jump to first uncovered line) |
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, 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 | | #include "jsimd.h" |
59 | | #include "jsamplecomp.h" |
60 | | |
61 | | |
62 | | #if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) |
63 | | |
64 | | /* Pointer to routine to downsample a single component */ |
65 | | typedef void (*downsample1_ptr) (j_compress_ptr cinfo, |
66 | | jpeg_component_info *compptr, |
67 | | _JSAMPARRAY input_data, |
68 | | _JSAMPARRAY output_data); |
69 | | |
70 | | /* Private subobject */ |
71 | | |
72 | | typedef struct { |
73 | | struct jpeg_downsampler pub; /* public fields */ |
74 | | |
75 | | /* Downsampling method pointers, one per component */ |
76 | | downsample1_ptr methods[MAX_COMPONENTS]; |
77 | | } my_downsampler; |
78 | | |
79 | | typedef my_downsampler *my_downsample_ptr; |
80 | | |
81 | | |
82 | | /* |
83 | | * Initialize for a downsampling pass. |
84 | | */ |
85 | | |
86 | | METHODDEF(void) |
87 | | start_pass_downsample(j_compress_ptr cinfo) |
88 | 0 | { |
89 | | /* no work for now */ |
90 | 0 | } |
91 | | |
92 | | |
93 | | /* |
94 | | * Expand a component horizontally from width input_cols to width output_cols, |
95 | | * by duplicating the rightmost samples. |
96 | | */ |
97 | | |
98 | | LOCAL(void) |
99 | | expand_right_edge(_JSAMPARRAY image_data, int num_rows, JDIMENSION input_cols, |
100 | | JDIMENSION output_cols) |
101 | 0 | { |
102 | 0 | register _JSAMPROW ptr; |
103 | 0 | register _JSAMPLE pixval; |
104 | 0 | register int count; |
105 | 0 | int row; |
106 | 0 | int numcols = (int)(output_cols - input_cols); |
107 | |
|
108 | 0 | if (numcols > 0) { |
109 | 0 | for (row = 0; row < num_rows; row++) { |
110 | 0 | ptr = image_data[row] + input_cols; |
111 | 0 | pixval = ptr[-1]; |
112 | 0 | for (count = numcols; count > 0; count--) |
113 | 0 | *ptr++ = pixval; |
114 | 0 | } |
115 | 0 | } |
116 | 0 | } |
117 | | |
118 | | |
119 | | /* |
120 | | * Do downsampling for a whole row group (all components). |
121 | | * |
122 | | * In this version we simply downsample each component independently. |
123 | | */ |
124 | | |
125 | | METHODDEF(void) |
126 | | sep_downsample(j_compress_ptr cinfo, _JSAMPIMAGE input_buf, |
127 | | JDIMENSION in_row_index, _JSAMPIMAGE output_buf, |
128 | | JDIMENSION out_row_group_index) |
129 | 0 | { |
130 | 0 | my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample; |
131 | 0 | int ci; |
132 | 0 | jpeg_component_info *compptr; |
133 | 0 | _JSAMPARRAY in_ptr, out_ptr; |
134 | |
|
135 | 0 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
136 | 0 | ci++, compptr++) { |
137 | 0 | in_ptr = input_buf[ci] + in_row_index; |
138 | 0 | out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor); |
139 | 0 | (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr); |
140 | 0 | } |
141 | 0 | } |
142 | | |
143 | | |
144 | | /* |
145 | | * Downsample pixel values of a single component. |
146 | | * One row group is processed per call. |
147 | | * This version handles arbitrary integral sampling ratios, without smoothing. |
148 | | * Note that this version is not actually used for customary sampling ratios. |
149 | | */ |
150 | | |
151 | | METHODDEF(void) |
152 | | int_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
153 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
154 | 0 | { |
155 | 0 | int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v; |
156 | 0 | JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */ |
157 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
158 | 0 | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
159 | 0 | _JSAMPROW inptr, outptr; |
160 | 0 | JLONG outvalue; |
161 | |
|
162 | 0 | h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor; |
163 | 0 | v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor; |
164 | 0 | numpix = h_expand * v_expand; |
165 | 0 | numpix2 = numpix / 2; |
166 | | |
167 | | /* Expand input data enough to let all the output samples be generated |
168 | | * by the standard loop. Special-casing padded output would be more |
169 | | * efficient. |
170 | | */ |
171 | 0 | expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width, |
172 | 0 | output_cols * h_expand); |
173 | |
|
174 | 0 | inrow = 0; |
175 | 0 | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
176 | 0 | outptr = output_data[outrow]; |
177 | 0 | for (outcol = 0, outcol_h = 0; outcol < output_cols; |
178 | 0 | outcol++, outcol_h += h_expand) { |
179 | 0 | outvalue = 0; |
180 | 0 | for (v = 0; v < v_expand; v++) { |
181 | 0 | inptr = input_data[inrow + v] + outcol_h; |
182 | 0 | for (h = 0; h < h_expand; h++) { |
183 | 0 | outvalue += (JLONG)(*inptr++); |
184 | 0 | } |
185 | 0 | } |
186 | 0 | *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix); |
187 | 0 | } |
188 | 0 | inrow += v_expand; |
189 | 0 | } |
190 | 0 | } |
191 | | |
192 | | |
193 | | /* |
194 | | * Downsample pixel values of a single component. |
195 | | * This version handles the special case of a full-size component, |
196 | | * without smoothing. |
197 | | */ |
198 | | |
199 | | METHODDEF(void) |
200 | | fullsize_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
201 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
202 | 0 | { |
203 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
204 | | |
205 | | /* Copy the data */ |
206 | 0 | _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor, |
207 | 0 | cinfo->image_width); |
208 | | /* Edge-expand */ |
209 | 0 | expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width, |
210 | 0 | compptr->width_in_blocks * data_unit); |
211 | 0 | } |
212 | | |
213 | | |
214 | | /* |
215 | | * Downsample pixel values of a single component. |
216 | | * This version handles the common case of 2:1 horizontal and 1:1 vertical, |
217 | | * without smoothing. |
218 | | * |
219 | | * A note about the "bias" calculations: when rounding fractional values to |
220 | | * integer, we do not want to always round 0.5 up to the next integer. |
221 | | * If we did that, we'd introduce a noticeable bias towards larger values. |
222 | | * Instead, this code is arranged so that 0.5 will be rounded up or down at |
223 | | * alternate pixel locations (a simple ordered dither pattern). |
224 | | */ |
225 | | |
226 | | METHODDEF(void) |
227 | | h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
228 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
229 | 0 | { |
230 | 0 | int outrow; |
231 | 0 | JDIMENSION outcol; |
232 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
233 | 0 | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
234 | 0 | register _JSAMPROW inptr, outptr; |
235 | 0 | register int bias; |
236 | | |
237 | | /* Expand input data enough to let all the output samples be generated |
238 | | * by the standard loop. Special-casing padded output would be more |
239 | | * efficient. |
240 | | */ |
241 | 0 | expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width, |
242 | 0 | output_cols * 2); |
243 | |
|
244 | 0 | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
245 | 0 | outptr = output_data[outrow]; |
246 | 0 | inptr = input_data[outrow]; |
247 | 0 | bias = 0; /* bias = 0,1,0,1,... for successive samples */ |
248 | 0 | for (outcol = 0; outcol < output_cols; outcol++) { |
249 | 0 | *outptr++ = (_JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1); |
250 | 0 | bias ^= 1; /* 0=>1, 1=>0 */ |
251 | 0 | inptr += 2; |
252 | 0 | } |
253 | 0 | } |
254 | 0 | } |
255 | | |
256 | | |
257 | | /* |
258 | | * Downsample pixel values of a single component. |
259 | | * This version handles the standard case of 2:1 horizontal and 2:1 vertical, |
260 | | * without smoothing. |
261 | | */ |
262 | | |
263 | | METHODDEF(void) |
264 | | h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
265 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
266 | 0 | { |
267 | 0 | int inrow, outrow; |
268 | 0 | JDIMENSION outcol; |
269 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
270 | 0 | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
271 | 0 | register _JSAMPROW inptr0, inptr1, outptr; |
272 | 0 | register int bias; |
273 | | |
274 | | /* Expand input data enough to let all the output samples be generated |
275 | | * by the standard loop. Special-casing padded output would be more |
276 | | * efficient. |
277 | | */ |
278 | 0 | expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width, |
279 | 0 | output_cols * 2); |
280 | |
|
281 | 0 | inrow = 0; |
282 | 0 | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
283 | 0 | outptr = output_data[outrow]; |
284 | 0 | inptr0 = input_data[inrow]; |
285 | 0 | inptr1 = input_data[inrow + 1]; |
286 | 0 | bias = 1; /* bias = 1,2,1,2,... for successive samples */ |
287 | 0 | for (outcol = 0; outcol < output_cols; outcol++) { |
288 | 0 | *outptr++ = (_JSAMPLE) |
289 | 0 | ((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2); |
290 | 0 | bias ^= 3; /* 1=>2, 2=>1 */ |
291 | 0 | inptr0 += 2; inptr1 += 2; |
292 | 0 | } |
293 | 0 | inrow += 2; |
294 | 0 | } |
295 | 0 | } |
296 | | |
297 | | |
298 | | #ifdef INPUT_SMOOTHING_SUPPORTED |
299 | | |
300 | | /* |
301 | | * Downsample pixel values of a single component. |
302 | | * This version handles the standard case of 2:1 horizontal and 2:1 vertical, |
303 | | * with smoothing. One row of context is required. |
304 | | */ |
305 | | |
306 | | METHODDEF(void) |
307 | | h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
308 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
309 | 0 | { |
310 | 0 | int inrow, outrow; |
311 | 0 | JDIMENSION colctr; |
312 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
313 | 0 | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
314 | 0 | register _JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr; |
315 | 0 | JLONG membersum, neighsum, memberscale, neighscale; |
316 | | |
317 | | /* Expand input data enough to let all the output samples be generated |
318 | | * by the standard loop. Special-casing padded output would be more |
319 | | * efficient. |
320 | | */ |
321 | 0 | expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, |
322 | 0 | cinfo->image_width, output_cols * 2); |
323 | | |
324 | | /* We don't bother to form the individual "smoothed" input pixel values; |
325 | | * we can directly compute the output which is the average of the four |
326 | | * smoothed values. Each of the four member pixels contributes a fraction |
327 | | * (1-8*SF) to its own smoothed image and a fraction SF to each of the three |
328 | | * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final |
329 | | * output. The four corner-adjacent neighbor pixels contribute a fraction |
330 | | * SF to just one smoothed pixel, or SF/4 to the final output; while the |
331 | | * eight edge-adjacent neighbors contribute SF to each of two smoothed |
332 | | * pixels, or SF/2 overall. In order to use integer arithmetic, these |
333 | | * factors are scaled by 2^16 = 65536. |
334 | | * Also recall that SF = smoothing_factor / 1024. |
335 | | */ |
336 | |
|
337 | 0 | memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */ |
338 | 0 | neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */ |
339 | |
|
340 | 0 | inrow = 0; |
341 | 0 | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
342 | 0 | outptr = output_data[outrow]; |
343 | 0 | inptr0 = input_data[inrow]; |
344 | 0 | inptr1 = input_data[inrow + 1]; |
345 | 0 | above_ptr = input_data[inrow - 1]; |
346 | 0 | below_ptr = input_data[inrow + 2]; |
347 | | |
348 | | /* Special case for first column: pretend column -1 is same as column 0 */ |
349 | 0 | membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1]; |
350 | 0 | neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] + |
351 | 0 | inptr0[0] + inptr0[2] + inptr1[0] + inptr1[2]; |
352 | 0 | neighsum += neighsum; |
353 | 0 | neighsum += above_ptr[0] + above_ptr[2] + below_ptr[0] + below_ptr[2]; |
354 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
355 | 0 | *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16); |
356 | 0 | inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; |
357 | |
|
358 | 0 | for (colctr = output_cols - 2; colctr > 0; colctr--) { |
359 | | /* sum of pixels directly mapped to this output element */ |
360 | 0 | membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1]; |
361 | | /* sum of edge-neighbor pixels */ |
362 | 0 | neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] + |
363 | 0 | inptr0[-1] + inptr0[2] + inptr1[-1] + inptr1[2]; |
364 | | /* The edge-neighbors count twice as much as corner-neighbors */ |
365 | 0 | neighsum += neighsum; |
366 | | /* Add in the corner-neighbors */ |
367 | 0 | neighsum += above_ptr[-1] + above_ptr[2] + below_ptr[-1] + below_ptr[2]; |
368 | | /* form final output scaled up by 2^16 */ |
369 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
370 | | /* round, descale and output it */ |
371 | 0 | *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16); |
372 | 0 | inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; |
373 | 0 | } |
374 | | |
375 | | /* Special case for last column */ |
376 | 0 | membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1]; |
377 | 0 | neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] + |
378 | 0 | inptr0[-1] + inptr0[1] + inptr1[-1] + inptr1[1]; |
379 | 0 | neighsum += neighsum; |
380 | 0 | neighsum += above_ptr[-1] + above_ptr[1] + below_ptr[-1] + below_ptr[1]; |
381 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
382 | 0 | *outptr = (_JSAMPLE)((membersum + 32768) >> 16); |
383 | |
|
384 | 0 | inrow += 2; |
385 | 0 | } |
386 | 0 | } |
387 | | |
388 | | |
389 | | /* |
390 | | * Downsample pixel values of a single component. |
391 | | * This version handles the special case of a full-size component, |
392 | | * with smoothing. One row of context is required. |
393 | | */ |
394 | | |
395 | | METHODDEF(void) |
396 | | fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
397 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
398 | 0 | { |
399 | 0 | int outrow; |
400 | 0 | JDIMENSION colctr; |
401 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
402 | 0 | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
403 | 0 | register _JSAMPROW inptr, above_ptr, below_ptr, outptr; |
404 | 0 | JLONG membersum, neighsum, memberscale, neighscale; |
405 | 0 | int colsum, lastcolsum, nextcolsum; |
406 | | |
407 | | /* Expand input data enough to let all the output samples be generated |
408 | | * by the standard loop. Special-casing padded output would be more |
409 | | * efficient. |
410 | | */ |
411 | 0 | expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, |
412 | 0 | cinfo->image_width, output_cols); |
413 | | |
414 | | /* Each of the eight neighbor pixels contributes a fraction SF to the |
415 | | * smoothed pixel, while the main pixel contributes (1-8*SF). In order |
416 | | * to use integer arithmetic, these factors are multiplied by 2^16 = 65536. |
417 | | * Also recall that SF = smoothing_factor / 1024. |
418 | | */ |
419 | |
|
420 | 0 | memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */ |
421 | 0 | neighscale = cinfo->smoothing_factor * 64; /* scaled SF */ |
422 | |
|
423 | 0 | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
424 | 0 | outptr = output_data[outrow]; |
425 | 0 | inptr = input_data[outrow]; |
426 | 0 | above_ptr = input_data[outrow - 1]; |
427 | 0 | below_ptr = input_data[outrow + 1]; |
428 | | |
429 | | /* Special case for first column */ |
430 | 0 | colsum = (*above_ptr++) + (*below_ptr++) + inptr[0]; |
431 | 0 | membersum = *inptr++; |
432 | 0 | nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0]; |
433 | 0 | neighsum = colsum + (colsum - membersum) + nextcolsum; |
434 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
435 | 0 | *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16); |
436 | 0 | lastcolsum = colsum; colsum = nextcolsum; |
437 | |
|
438 | 0 | for (colctr = output_cols - 2; colctr > 0; colctr--) { |
439 | 0 | membersum = *inptr++; |
440 | 0 | above_ptr++; below_ptr++; |
441 | 0 | nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0]; |
442 | 0 | neighsum = lastcolsum + (colsum - membersum) + nextcolsum; |
443 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
444 | 0 | *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16); |
445 | 0 | lastcolsum = colsum; colsum = nextcolsum; |
446 | 0 | } |
447 | | |
448 | | /* Special case for last column */ |
449 | 0 | membersum = *inptr; |
450 | 0 | neighsum = lastcolsum + (colsum - membersum) + colsum; |
451 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
452 | 0 | *outptr = (_JSAMPLE)((membersum + 32768) >> 16); |
453 | |
|
454 | 0 | } |
455 | 0 | } |
456 | | |
457 | | #endif /* INPUT_SMOOTHING_SUPPORTED */ |
458 | | |
459 | | |
460 | | /* |
461 | | * Module initialization routine for downsampling. |
462 | | * Note that we must select a routine for each component. |
463 | | */ |
464 | | |
465 | | GLOBAL(void) |
466 | | _jinit_downsampler(j_compress_ptr cinfo) |
467 | 0 | { |
468 | 0 | my_downsample_ptr downsample; |
469 | 0 | int ci; |
470 | 0 | jpeg_component_info *compptr; |
471 | 0 | boolean smoothok = TRUE; |
472 | |
|
473 | 0 | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
474 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
475 | |
|
476 | 0 | downsample = (my_downsample_ptr) |
477 | 0 | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
478 | 0 | sizeof(my_downsampler)); |
479 | 0 | cinfo->downsample = (struct jpeg_downsampler *)downsample; |
480 | 0 | downsample->pub.start_pass = start_pass_downsample; |
481 | 0 | downsample->pub._downsample = sep_downsample; |
482 | 0 | downsample->pub.need_context_rows = FALSE; |
483 | |
|
484 | 0 | if (cinfo->CCIR601_sampling) |
485 | 0 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); |
486 | | |
487 | | /* Verify we can handle the sampling factors, and set up method pointers */ |
488 | 0 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
489 | 0 | ci++, compptr++) { |
490 | 0 | if (compptr->h_samp_factor == cinfo->max_h_samp_factor && |
491 | 0 | compptr->v_samp_factor == cinfo->max_v_samp_factor) { |
492 | 0 | #ifdef INPUT_SMOOTHING_SUPPORTED |
493 | 0 | if (cinfo->smoothing_factor) { |
494 | 0 | downsample->methods[ci] = fullsize_smooth_downsample; |
495 | 0 | downsample->pub.need_context_rows = TRUE; |
496 | 0 | } else |
497 | 0 | #endif |
498 | 0 | downsample->methods[ci] = fullsize_downsample; |
499 | 0 | } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && |
500 | 0 | compptr->v_samp_factor == cinfo->max_v_samp_factor) { |
501 | 0 | smoothok = FALSE; |
502 | | #ifdef WITH_SIMD |
503 | 0 | if (jsimd_can_h2v1_downsample()) |
504 | 0 | downsample->methods[ci] = jsimd_h2v1_downsample; |
505 | 0 | else |
506 | 0 | #endif |
507 | 0 | downsample->methods[ci] = h2v1_downsample; |
508 | 0 | } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && |
509 | 0 | compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) { |
510 | 0 | #ifdef INPUT_SMOOTHING_SUPPORTED |
511 | 0 | if (cinfo->smoothing_factor) { |
512 | | #if defined(WITH_SIMD) && defined(__mips__) |
513 | | if (jsimd_can_h2v2_smooth_downsample()) |
514 | | downsample->methods[ci] = jsimd_h2v2_smooth_downsample; |
515 | | else |
516 | | #endif |
517 | 0 | downsample->methods[ci] = h2v2_smooth_downsample; |
518 | 0 | downsample->pub.need_context_rows = TRUE; |
519 | 0 | } else |
520 | 0 | #endif |
521 | 0 | { |
522 | | #ifdef WITH_SIMD |
523 | 0 | if (jsimd_can_h2v2_downsample()) |
524 | 0 | downsample->methods[ci] = jsimd_h2v2_downsample; |
525 | 0 | else |
526 | 0 | #endif |
527 | 0 | downsample->methods[ci] = h2v2_downsample; |
528 | 0 | } |
529 | 0 | } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 && |
530 | 0 | (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) { |
531 | 0 | smoothok = FALSE; |
532 | 0 | downsample->methods[ci] = int_downsample; |
533 | 0 | } else |
534 | 0 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); |
535 | 0 | } |
536 | |
|
537 | 0 | #ifdef INPUT_SMOOTHING_SUPPORTED |
538 | 0 | if (cinfo->smoothing_factor && !smoothok) |
539 | 0 | TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL); |
540 | 0 | #endif |
541 | 0 | } Unexecuted instantiation: jinit_downsampler Unexecuted instantiation: j12init_downsampler Unexecuted instantiation: j16init_downsampler |
542 | | |
543 | | #endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */ |