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