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