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