1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libjpeg/jcsample.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,527 @@ 1.4 +/* 1.5 + * jcsample.c 1.6 + * 1.7 + * Copyright (C) 1991-1996, Thomas G. Lane. 1.8 + * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB 1.9 + * This file is part of the Independent JPEG Group's software. 1.10 + * For conditions of distribution and use, see the accompanying README file. 1.11 + * 1.12 + * This file contains downsampling routines. 1.13 + * 1.14 + * Downsampling input data is counted in "row groups". A row group 1.15 + * is defined to be max_v_samp_factor pixel rows of each component, 1.16 + * from which the downsampler produces v_samp_factor sample rows. 1.17 + * A single row group is processed in each call to the downsampler module. 1.18 + * 1.19 + * The downsampler is responsible for edge-expansion of its output data 1.20 + * to fill an integral number of DCT blocks horizontally. The source buffer 1.21 + * may be modified if it is helpful for this purpose (the source buffer is 1.22 + * allocated wide enough to correspond to the desired output width). 1.23 + * The caller (the prep controller) is responsible for vertical padding. 1.24 + * 1.25 + * The downsampler may request "context rows" by setting need_context_rows 1.26 + * during startup. In this case, the input arrays will contain at least 1.27 + * one row group's worth of pixels above and below the passed-in data; 1.28 + * the caller will create dummy rows at image top and bottom by replicating 1.29 + * the first or last real pixel row. 1.30 + * 1.31 + * An excellent reference for image resampling is 1.32 + * Digital Image Warping, George Wolberg, 1990. 1.33 + * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. 1.34 + * 1.35 + * The downsampling algorithm used here is a simple average of the source 1.36 + * pixels covered by the output pixel. The hi-falutin sampling literature 1.37 + * refers to this as a "box filter". In general the characteristics of a box 1.38 + * filter are not very good, but for the specific cases we normally use (1:1 1.39 + * and 2:1 ratios) the box is equivalent to a "triangle filter" which is not 1.40 + * nearly so bad. If you intend to use other sampling ratios, you'd be well 1.41 + * advised to improve this code. 1.42 + * 1.43 + * A simple input-smoothing capability is provided. This is mainly intended 1.44 + * for cleaning up color-dithered GIF input files (if you find it inadequate, 1.45 + * we suggest using an external filtering program such as pnmconvol). When 1.46 + * enabled, each input pixel P is replaced by a weighted sum of itself and its 1.47 + * eight neighbors. P's weight is 1-8*SF and each neighbor's weight is SF, 1.48 + * where SF = (smoothing_factor / 1024). 1.49 + * Currently, smoothing is only supported for 2h2v sampling factors. 1.50 + */ 1.51 + 1.52 +#define JPEG_INTERNALS 1.53 +#include "jinclude.h" 1.54 +#include "jpeglib.h" 1.55 +#include "jsimd.h" 1.56 + 1.57 + 1.58 +/* Pointer to routine to downsample a single component */ 1.59 +typedef JMETHOD(void, downsample1_ptr, 1.60 + (j_compress_ptr cinfo, jpeg_component_info * compptr, 1.61 + JSAMPARRAY input_data, JSAMPARRAY output_data)); 1.62 + 1.63 +/* Private subobject */ 1.64 + 1.65 +typedef struct { 1.66 + struct jpeg_downsampler pub; /* public fields */ 1.67 + 1.68 + /* Downsampling method pointers, one per component */ 1.69 + downsample1_ptr methods[MAX_COMPONENTS]; 1.70 +} my_downsampler; 1.71 + 1.72 +typedef my_downsampler * my_downsample_ptr; 1.73 + 1.74 + 1.75 +/* 1.76 + * Initialize for a downsampling pass. 1.77 + */ 1.78 + 1.79 +METHODDEF(void) 1.80 +start_pass_downsample (j_compress_ptr cinfo) 1.81 +{ 1.82 + /* no work for now */ 1.83 +} 1.84 + 1.85 + 1.86 +/* 1.87 + * Expand a component horizontally from width input_cols to width output_cols, 1.88 + * by duplicating the rightmost samples. 1.89 + */ 1.90 + 1.91 +LOCAL(void) 1.92 +expand_right_edge (JSAMPARRAY image_data, int num_rows, 1.93 + JDIMENSION input_cols, JDIMENSION output_cols) 1.94 +{ 1.95 + register JSAMPROW ptr; 1.96 + register JSAMPLE pixval; 1.97 + register int count; 1.98 + int row; 1.99 + int numcols = (int) (output_cols - input_cols); 1.100 + 1.101 + if (numcols > 0) { 1.102 + for (row = 0; row < num_rows; row++) { 1.103 + ptr = image_data[row] + input_cols; 1.104 + pixval = ptr[-1]; /* don't need GETJSAMPLE() here */ 1.105 + for (count = numcols; count > 0; count--) 1.106 + *ptr++ = pixval; 1.107 + } 1.108 + } 1.109 +} 1.110 + 1.111 + 1.112 +/* 1.113 + * Do downsampling for a whole row group (all components). 1.114 + * 1.115 + * In this version we simply downsample each component independently. 1.116 + */ 1.117 + 1.118 +METHODDEF(void) 1.119 +sep_downsample (j_compress_ptr cinfo, 1.120 + JSAMPIMAGE input_buf, JDIMENSION in_row_index, 1.121 + JSAMPIMAGE output_buf, JDIMENSION out_row_group_index) 1.122 +{ 1.123 + my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample; 1.124 + int ci; 1.125 + jpeg_component_info * compptr; 1.126 + JSAMPARRAY in_ptr, out_ptr; 1.127 + 1.128 + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 1.129 + ci++, compptr++) { 1.130 + in_ptr = input_buf[ci] + in_row_index; 1.131 + out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor); 1.132 + (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr); 1.133 + } 1.134 +} 1.135 + 1.136 + 1.137 +/* 1.138 + * Downsample pixel values of a single component. 1.139 + * One row group is processed per call. 1.140 + * This version handles arbitrary integral sampling ratios, without smoothing. 1.141 + * Note that this version is not actually used for customary sampling ratios. 1.142 + */ 1.143 + 1.144 +METHODDEF(void) 1.145 +int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, 1.146 + JSAMPARRAY input_data, JSAMPARRAY output_data) 1.147 +{ 1.148 + int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v; 1.149 + JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */ 1.150 + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; 1.151 + JSAMPROW inptr, outptr; 1.152 + INT32 outvalue; 1.153 + 1.154 + h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor; 1.155 + v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor; 1.156 + numpix = h_expand * v_expand; 1.157 + numpix2 = numpix/2; 1.158 + 1.159 + /* Expand input data enough to let all the output samples be generated 1.160 + * by the standard loop. Special-casing padded output would be more 1.161 + * efficient. 1.162 + */ 1.163 + expand_right_edge(input_data, cinfo->max_v_samp_factor, 1.164 + cinfo->image_width, output_cols * h_expand); 1.165 + 1.166 + inrow = 0; 1.167 + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { 1.168 + outptr = output_data[outrow]; 1.169 + for (outcol = 0, outcol_h = 0; outcol < output_cols; 1.170 + outcol++, outcol_h += h_expand) { 1.171 + outvalue = 0; 1.172 + for (v = 0; v < v_expand; v++) { 1.173 + inptr = input_data[inrow+v] + outcol_h; 1.174 + for (h = 0; h < h_expand; h++) { 1.175 + outvalue += (INT32) GETJSAMPLE(*inptr++); 1.176 + } 1.177 + } 1.178 + *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix); 1.179 + } 1.180 + inrow += v_expand; 1.181 + } 1.182 +} 1.183 + 1.184 + 1.185 +/* 1.186 + * Downsample pixel values of a single component. 1.187 + * This version handles the special case of a full-size component, 1.188 + * without smoothing. 1.189 + */ 1.190 + 1.191 +METHODDEF(void) 1.192 +fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, 1.193 + JSAMPARRAY input_data, JSAMPARRAY output_data) 1.194 +{ 1.195 + /* Copy the data */ 1.196 + jcopy_sample_rows(input_data, 0, output_data, 0, 1.197 + cinfo->max_v_samp_factor, cinfo->image_width); 1.198 + /* Edge-expand */ 1.199 + expand_right_edge(output_data, cinfo->max_v_samp_factor, 1.200 + cinfo->image_width, compptr->width_in_blocks * DCTSIZE); 1.201 +} 1.202 + 1.203 + 1.204 +/* 1.205 + * Downsample pixel values of a single component. 1.206 + * This version handles the common case of 2:1 horizontal and 1:1 vertical, 1.207 + * without smoothing. 1.208 + * 1.209 + * A note about the "bias" calculations: when rounding fractional values to 1.210 + * integer, we do not want to always round 0.5 up to the next integer. 1.211 + * If we did that, we'd introduce a noticeable bias towards larger values. 1.212 + * Instead, this code is arranged so that 0.5 will be rounded up or down at 1.213 + * alternate pixel locations (a simple ordered dither pattern). 1.214 + */ 1.215 + 1.216 +METHODDEF(void) 1.217 +h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, 1.218 + JSAMPARRAY input_data, JSAMPARRAY output_data) 1.219 +{ 1.220 + int outrow; 1.221 + JDIMENSION outcol; 1.222 + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; 1.223 + register JSAMPROW inptr, outptr; 1.224 + register int bias; 1.225 + 1.226 + /* Expand input data enough to let all the output samples be generated 1.227 + * by the standard loop. Special-casing padded output would be more 1.228 + * efficient. 1.229 + */ 1.230 + expand_right_edge(input_data, cinfo->max_v_samp_factor, 1.231 + cinfo->image_width, output_cols * 2); 1.232 + 1.233 + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { 1.234 + outptr = output_data[outrow]; 1.235 + inptr = input_data[outrow]; 1.236 + bias = 0; /* bias = 0,1,0,1,... for successive samples */ 1.237 + for (outcol = 0; outcol < output_cols; outcol++) { 1.238 + *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1]) 1.239 + + bias) >> 1); 1.240 + bias ^= 1; /* 0=>1, 1=>0 */ 1.241 + inptr += 2; 1.242 + } 1.243 + } 1.244 +} 1.245 + 1.246 + 1.247 +/* 1.248 + * Downsample pixel values of a single component. 1.249 + * This version handles the standard case of 2:1 horizontal and 2:1 vertical, 1.250 + * without smoothing. 1.251 + */ 1.252 + 1.253 +METHODDEF(void) 1.254 +h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, 1.255 + JSAMPARRAY input_data, JSAMPARRAY output_data) 1.256 +{ 1.257 + int inrow, outrow; 1.258 + JDIMENSION outcol; 1.259 + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; 1.260 + register JSAMPROW inptr0, inptr1, outptr; 1.261 + register int bias; 1.262 + 1.263 + /* Expand input data enough to let all the output samples be generated 1.264 + * by the standard loop. Special-casing padded output would be more 1.265 + * efficient. 1.266 + */ 1.267 + expand_right_edge(input_data, cinfo->max_v_samp_factor, 1.268 + cinfo->image_width, output_cols * 2); 1.269 + 1.270 + inrow = 0; 1.271 + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { 1.272 + outptr = output_data[outrow]; 1.273 + inptr0 = input_data[inrow]; 1.274 + inptr1 = input_data[inrow+1]; 1.275 + bias = 1; /* bias = 1,2,1,2,... for successive samples */ 1.276 + for (outcol = 0; outcol < output_cols; outcol++) { 1.277 + *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + 1.278 + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]) 1.279 + + bias) >> 2); 1.280 + bias ^= 3; /* 1=>2, 2=>1 */ 1.281 + inptr0 += 2; inptr1 += 2; 1.282 + } 1.283 + inrow += 2; 1.284 + } 1.285 +} 1.286 + 1.287 + 1.288 +#ifdef INPUT_SMOOTHING_SUPPORTED 1.289 + 1.290 +/* 1.291 + * Downsample pixel values of a single component. 1.292 + * This version handles the standard case of 2:1 horizontal and 2:1 vertical, 1.293 + * with smoothing. One row of context is required. 1.294 + */ 1.295 + 1.296 +METHODDEF(void) 1.297 +h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, 1.298 + JSAMPARRAY input_data, JSAMPARRAY output_data) 1.299 +{ 1.300 + int inrow, outrow; 1.301 + JDIMENSION colctr; 1.302 + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; 1.303 + register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr; 1.304 + INT32 membersum, neighsum, memberscale, neighscale; 1.305 + 1.306 + /* Expand input data enough to let all the output samples be generated 1.307 + * by the standard loop. Special-casing padded output would be more 1.308 + * efficient. 1.309 + */ 1.310 + expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, 1.311 + cinfo->image_width, output_cols * 2); 1.312 + 1.313 + /* We don't bother to form the individual "smoothed" input pixel values; 1.314 + * we can directly compute the output which is the average of the four 1.315 + * smoothed values. Each of the four member pixels contributes a fraction 1.316 + * (1-8*SF) to its own smoothed image and a fraction SF to each of the three 1.317 + * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final 1.318 + * output. The four corner-adjacent neighbor pixels contribute a fraction 1.319 + * SF to just one smoothed pixel, or SF/4 to the final output; while the 1.320 + * eight edge-adjacent neighbors contribute SF to each of two smoothed 1.321 + * pixels, or SF/2 overall. In order to use integer arithmetic, these 1.322 + * factors are scaled by 2^16 = 65536. 1.323 + * Also recall that SF = smoothing_factor / 1024. 1.324 + */ 1.325 + 1.326 + memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */ 1.327 + neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */ 1.328 + 1.329 + inrow = 0; 1.330 + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { 1.331 + outptr = output_data[outrow]; 1.332 + inptr0 = input_data[inrow]; 1.333 + inptr1 = input_data[inrow+1]; 1.334 + above_ptr = input_data[inrow-1]; 1.335 + below_ptr = input_data[inrow+2]; 1.336 + 1.337 + /* Special case for first column: pretend column -1 is same as column 0 */ 1.338 + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + 1.339 + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); 1.340 + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + 1.341 + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + 1.342 + GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) + 1.343 + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]); 1.344 + neighsum += neighsum; 1.345 + neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) + 1.346 + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]); 1.347 + membersum = membersum * memberscale + neighsum * neighscale; 1.348 + *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); 1.349 + inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; 1.350 + 1.351 + for (colctr = output_cols - 2; colctr > 0; colctr--) { 1.352 + /* sum of pixels directly mapped to this output element */ 1.353 + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + 1.354 + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); 1.355 + /* sum of edge-neighbor pixels */ 1.356 + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + 1.357 + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + 1.358 + GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) + 1.359 + GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]); 1.360 + /* The edge-neighbors count twice as much as corner-neighbors */ 1.361 + neighsum += neighsum; 1.362 + /* Add in the corner-neighbors */ 1.363 + neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) + 1.364 + GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]); 1.365 + /* form final output scaled up by 2^16 */ 1.366 + membersum = membersum * memberscale + neighsum * neighscale; 1.367 + /* round, descale and output it */ 1.368 + *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); 1.369 + inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; 1.370 + } 1.371 + 1.372 + /* Special case for last column */ 1.373 + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + 1.374 + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); 1.375 + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + 1.376 + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + 1.377 + GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) + 1.378 + GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]); 1.379 + neighsum += neighsum; 1.380 + neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) + 1.381 + GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]); 1.382 + membersum = membersum * memberscale + neighsum * neighscale; 1.383 + *outptr = (JSAMPLE) ((membersum + 32768) >> 16); 1.384 + 1.385 + inrow += 2; 1.386 + } 1.387 +} 1.388 + 1.389 + 1.390 +/* 1.391 + * Downsample pixel values of a single component. 1.392 + * This version handles the special case of a full-size component, 1.393 + * with smoothing. One row of context is required. 1.394 + */ 1.395 + 1.396 +METHODDEF(void) 1.397 +fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr, 1.398 + JSAMPARRAY input_data, JSAMPARRAY output_data) 1.399 +{ 1.400 + int outrow; 1.401 + JDIMENSION colctr; 1.402 + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; 1.403 + register JSAMPROW inptr, above_ptr, below_ptr, outptr; 1.404 + INT32 membersum, neighsum, memberscale, neighscale; 1.405 + int colsum, lastcolsum, nextcolsum; 1.406 + 1.407 + /* Expand input data enough to let all the output samples be generated 1.408 + * by the standard loop. Special-casing padded output would be more 1.409 + * efficient. 1.410 + */ 1.411 + expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, 1.412 + cinfo->image_width, output_cols); 1.413 + 1.414 + /* Each of the eight neighbor pixels contributes a fraction SF to the 1.415 + * smoothed pixel, while the main pixel contributes (1-8*SF). In order 1.416 + * to use integer arithmetic, these factors are multiplied by 2^16 = 65536. 1.417 + * Also recall that SF = smoothing_factor / 1024. 1.418 + */ 1.419 + 1.420 + memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */ 1.421 + neighscale = cinfo->smoothing_factor * 64; /* scaled SF */ 1.422 + 1.423 + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { 1.424 + outptr = output_data[outrow]; 1.425 + inptr = input_data[outrow]; 1.426 + above_ptr = input_data[outrow-1]; 1.427 + below_ptr = input_data[outrow+1]; 1.428 + 1.429 + /* Special case for first column */ 1.430 + colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) + 1.431 + GETJSAMPLE(*inptr); 1.432 + membersum = GETJSAMPLE(*inptr++); 1.433 + nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) + 1.434 + GETJSAMPLE(*inptr); 1.435 + neighsum = colsum + (colsum - membersum) + nextcolsum; 1.436 + membersum = membersum * memberscale + neighsum * neighscale; 1.437 + *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); 1.438 + lastcolsum = colsum; colsum = nextcolsum; 1.439 + 1.440 + for (colctr = output_cols - 2; colctr > 0; colctr--) { 1.441 + membersum = GETJSAMPLE(*inptr++); 1.442 + above_ptr++; below_ptr++; 1.443 + nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) + 1.444 + GETJSAMPLE(*inptr); 1.445 + neighsum = lastcolsum + (colsum - membersum) + nextcolsum; 1.446 + membersum = membersum * memberscale + neighsum * neighscale; 1.447 + *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); 1.448 + lastcolsum = colsum; colsum = nextcolsum; 1.449 + } 1.450 + 1.451 + /* Special case for last column */ 1.452 + membersum = GETJSAMPLE(*inptr); 1.453 + neighsum = lastcolsum + (colsum - membersum) + colsum; 1.454 + membersum = membersum * memberscale + neighsum * neighscale; 1.455 + *outptr = (JSAMPLE) ((membersum + 32768) >> 16); 1.456 + 1.457 + } 1.458 +} 1.459 + 1.460 +#endif /* INPUT_SMOOTHING_SUPPORTED */ 1.461 + 1.462 + 1.463 +/* 1.464 + * Module initialization routine for downsampling. 1.465 + * Note that we must select a routine for each component. 1.466 + */ 1.467 + 1.468 +GLOBAL(void) 1.469 +jinit_downsampler (j_compress_ptr cinfo) 1.470 +{ 1.471 + my_downsample_ptr downsample; 1.472 + int ci; 1.473 + jpeg_component_info * compptr; 1.474 + boolean smoothok = TRUE; 1.475 + 1.476 + downsample = (my_downsample_ptr) 1.477 + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 1.478 + SIZEOF(my_downsampler)); 1.479 + cinfo->downsample = (struct jpeg_downsampler *) downsample; 1.480 + downsample->pub.start_pass = start_pass_downsample; 1.481 + downsample->pub.downsample = sep_downsample; 1.482 + downsample->pub.need_context_rows = FALSE; 1.483 + 1.484 + if (cinfo->CCIR601_sampling) 1.485 + ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); 1.486 + 1.487 + /* Verify we can handle the sampling factors, and set up method pointers */ 1.488 + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 1.489 + ci++, compptr++) { 1.490 + if (compptr->h_samp_factor == cinfo->max_h_samp_factor && 1.491 + compptr->v_samp_factor == cinfo->max_v_samp_factor) { 1.492 +#ifdef INPUT_SMOOTHING_SUPPORTED 1.493 + if (cinfo->smoothing_factor) { 1.494 + downsample->methods[ci] = fullsize_smooth_downsample; 1.495 + downsample->pub.need_context_rows = TRUE; 1.496 + } else 1.497 +#endif 1.498 + downsample->methods[ci] = fullsize_downsample; 1.499 + } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && 1.500 + compptr->v_samp_factor == cinfo->max_v_samp_factor) { 1.501 + smoothok = FALSE; 1.502 + if (jsimd_can_h2v1_downsample()) 1.503 + downsample->methods[ci] = jsimd_h2v1_downsample; 1.504 + else 1.505 + downsample->methods[ci] = h2v1_downsample; 1.506 + } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && 1.507 + compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) { 1.508 +#ifdef INPUT_SMOOTHING_SUPPORTED 1.509 + if (cinfo->smoothing_factor) { 1.510 + downsample->methods[ci] = h2v2_smooth_downsample; 1.511 + downsample->pub.need_context_rows = TRUE; 1.512 + } else 1.513 +#endif 1.514 + if (jsimd_can_h2v2_downsample()) 1.515 + downsample->methods[ci] = jsimd_h2v2_downsample; 1.516 + else 1.517 + downsample->methods[ci] = h2v2_downsample; 1.518 + } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 && 1.519 + (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) { 1.520 + smoothok = FALSE; 1.521 + downsample->methods[ci] = int_downsample; 1.522 + } else 1.523 + ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); 1.524 + } 1.525 + 1.526 +#ifdef INPUT_SMOOTHING_SUPPORTED 1.527 + if (cinfo->smoothing_factor && !smoothok) 1.528 + TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL); 1.529 +#endif 1.530 +}