michael@0: /* michael@0: * jcsample.c michael@0: * michael@0: * Copyright (C) 1991-1996, Thomas G. Lane. michael@0: * Copyright 2009 Pierre Ossman for Cendio AB michael@0: * This file is part of the Independent JPEG Group's software. michael@0: * For conditions of distribution and use, see the accompanying README file. michael@0: * michael@0: * This file contains downsampling routines. michael@0: * michael@0: * Downsampling input data is counted in "row groups". A row group michael@0: * is defined to be max_v_samp_factor pixel rows of each component, michael@0: * from which the downsampler produces v_samp_factor sample rows. michael@0: * A single row group is processed in each call to the downsampler module. michael@0: * michael@0: * The downsampler is responsible for edge-expansion of its output data michael@0: * to fill an integral number of DCT blocks horizontally. The source buffer michael@0: * may be modified if it is helpful for this purpose (the source buffer is michael@0: * allocated wide enough to correspond to the desired output width). michael@0: * The caller (the prep controller) is responsible for vertical padding. michael@0: * michael@0: * The downsampler may request "context rows" by setting need_context_rows michael@0: * during startup. In this case, the input arrays will contain at least michael@0: * one row group's worth of pixels above and below the passed-in data; michael@0: * the caller will create dummy rows at image top and bottom by replicating michael@0: * the first or last real pixel row. michael@0: * michael@0: * An excellent reference for image resampling is michael@0: * Digital Image Warping, George Wolberg, 1990. michael@0: * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. michael@0: * michael@0: * The downsampling algorithm used here is a simple average of the source michael@0: * pixels covered by the output pixel. The hi-falutin sampling literature michael@0: * refers to this as a "box filter". In general the characteristics of a box michael@0: * filter are not very good, but for the specific cases we normally use (1:1 michael@0: * and 2:1 ratios) the box is equivalent to a "triangle filter" which is not michael@0: * nearly so bad. If you intend to use other sampling ratios, you'd be well michael@0: * advised to improve this code. michael@0: * michael@0: * A simple input-smoothing capability is provided. This is mainly intended michael@0: * for cleaning up color-dithered GIF input files (if you find it inadequate, michael@0: * we suggest using an external filtering program such as pnmconvol). When michael@0: * enabled, each input pixel P is replaced by a weighted sum of itself and its michael@0: * eight neighbors. P's weight is 1-8*SF and each neighbor's weight is SF, michael@0: * where SF = (smoothing_factor / 1024). michael@0: * Currently, smoothing is only supported for 2h2v sampling factors. michael@0: */ michael@0: michael@0: #define JPEG_INTERNALS michael@0: #include "jinclude.h" michael@0: #include "jpeglib.h" michael@0: #include "jsimd.h" michael@0: michael@0: michael@0: /* Pointer to routine to downsample a single component */ michael@0: typedef JMETHOD(void, downsample1_ptr, michael@0: (j_compress_ptr cinfo, jpeg_component_info * compptr, michael@0: JSAMPARRAY input_data, JSAMPARRAY output_data)); michael@0: michael@0: /* Private subobject */ michael@0: michael@0: typedef struct { michael@0: struct jpeg_downsampler pub; /* public fields */ michael@0: michael@0: /* Downsampling method pointers, one per component */ michael@0: downsample1_ptr methods[MAX_COMPONENTS]; michael@0: } my_downsampler; michael@0: michael@0: typedef my_downsampler * my_downsample_ptr; michael@0: michael@0: michael@0: /* michael@0: * Initialize for a downsampling pass. michael@0: */ michael@0: michael@0: METHODDEF(void) michael@0: start_pass_downsample (j_compress_ptr cinfo) michael@0: { michael@0: /* no work for now */ michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Expand a component horizontally from width input_cols to width output_cols, michael@0: * by duplicating the rightmost samples. michael@0: */ michael@0: michael@0: LOCAL(void) michael@0: expand_right_edge (JSAMPARRAY image_data, int num_rows, michael@0: JDIMENSION input_cols, JDIMENSION output_cols) michael@0: { michael@0: register JSAMPROW ptr; michael@0: register JSAMPLE pixval; michael@0: register int count; michael@0: int row; michael@0: int numcols = (int) (output_cols - input_cols); michael@0: michael@0: if (numcols > 0) { michael@0: for (row = 0; row < num_rows; row++) { michael@0: ptr = image_data[row] + input_cols; michael@0: pixval = ptr[-1]; /* don't need GETJSAMPLE() here */ michael@0: for (count = numcols; count > 0; count--) michael@0: *ptr++ = pixval; michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Do downsampling for a whole row group (all components). michael@0: * michael@0: * In this version we simply downsample each component independently. michael@0: */ michael@0: michael@0: METHODDEF(void) michael@0: sep_downsample (j_compress_ptr cinfo, michael@0: JSAMPIMAGE input_buf, JDIMENSION in_row_index, michael@0: JSAMPIMAGE output_buf, JDIMENSION out_row_group_index) michael@0: { michael@0: my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample; michael@0: int ci; michael@0: jpeg_component_info * compptr; michael@0: JSAMPARRAY in_ptr, out_ptr; michael@0: michael@0: for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; michael@0: ci++, compptr++) { michael@0: in_ptr = input_buf[ci] + in_row_index; michael@0: out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor); michael@0: (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr); michael@0: } michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Downsample pixel values of a single component. michael@0: * One row group is processed per call. michael@0: * This version handles arbitrary integral sampling ratios, without smoothing. michael@0: * Note that this version is not actually used for customary sampling ratios. michael@0: */ michael@0: michael@0: METHODDEF(void) michael@0: int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, michael@0: JSAMPARRAY input_data, JSAMPARRAY output_data) michael@0: { michael@0: int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v; michael@0: JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */ michael@0: JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; michael@0: JSAMPROW inptr, outptr; michael@0: INT32 outvalue; michael@0: michael@0: h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor; michael@0: v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor; michael@0: numpix = h_expand * v_expand; michael@0: numpix2 = numpix/2; michael@0: michael@0: /* Expand input data enough to let all the output samples be generated michael@0: * by the standard loop. Special-casing padded output would be more michael@0: * efficient. michael@0: */ michael@0: expand_right_edge(input_data, cinfo->max_v_samp_factor, michael@0: cinfo->image_width, output_cols * h_expand); michael@0: michael@0: inrow = 0; michael@0: for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { michael@0: outptr = output_data[outrow]; michael@0: for (outcol = 0, outcol_h = 0; outcol < output_cols; michael@0: outcol++, outcol_h += h_expand) { michael@0: outvalue = 0; michael@0: for (v = 0; v < v_expand; v++) { michael@0: inptr = input_data[inrow+v] + outcol_h; michael@0: for (h = 0; h < h_expand; h++) { michael@0: outvalue += (INT32) GETJSAMPLE(*inptr++); michael@0: } michael@0: } michael@0: *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix); michael@0: } michael@0: inrow += v_expand; michael@0: } michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Downsample pixel values of a single component. michael@0: * This version handles the special case of a full-size component, michael@0: * without smoothing. michael@0: */ michael@0: michael@0: METHODDEF(void) michael@0: fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, michael@0: JSAMPARRAY input_data, JSAMPARRAY output_data) michael@0: { michael@0: /* Copy the data */ michael@0: jcopy_sample_rows(input_data, 0, output_data, 0, michael@0: cinfo->max_v_samp_factor, cinfo->image_width); michael@0: /* Edge-expand */ michael@0: expand_right_edge(output_data, cinfo->max_v_samp_factor, michael@0: cinfo->image_width, compptr->width_in_blocks * DCTSIZE); michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Downsample pixel values of a single component. michael@0: * This version handles the common case of 2:1 horizontal and 1:1 vertical, michael@0: * without smoothing. michael@0: * michael@0: * A note about the "bias" calculations: when rounding fractional values to michael@0: * integer, we do not want to always round 0.5 up to the next integer. michael@0: * If we did that, we'd introduce a noticeable bias towards larger values. michael@0: * Instead, this code is arranged so that 0.5 will be rounded up or down at michael@0: * alternate pixel locations (a simple ordered dither pattern). michael@0: */ michael@0: michael@0: METHODDEF(void) michael@0: h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, michael@0: JSAMPARRAY input_data, JSAMPARRAY output_data) michael@0: { michael@0: int outrow; michael@0: JDIMENSION outcol; michael@0: JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; michael@0: register JSAMPROW inptr, outptr; michael@0: register int bias; michael@0: michael@0: /* Expand input data enough to let all the output samples be generated michael@0: * by the standard loop. Special-casing padded output would be more michael@0: * efficient. michael@0: */ michael@0: expand_right_edge(input_data, cinfo->max_v_samp_factor, michael@0: cinfo->image_width, output_cols * 2); michael@0: michael@0: for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { michael@0: outptr = output_data[outrow]; michael@0: inptr = input_data[outrow]; michael@0: bias = 0; /* bias = 0,1,0,1,... for successive samples */ michael@0: for (outcol = 0; outcol < output_cols; outcol++) { michael@0: *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1]) michael@0: + bias) >> 1); michael@0: bias ^= 1; /* 0=>1, 1=>0 */ michael@0: inptr += 2; michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Downsample pixel values of a single component. michael@0: * This version handles the standard case of 2:1 horizontal and 2:1 vertical, michael@0: * without smoothing. michael@0: */ michael@0: michael@0: METHODDEF(void) michael@0: h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, michael@0: JSAMPARRAY input_data, JSAMPARRAY output_data) michael@0: { michael@0: int inrow, outrow; michael@0: JDIMENSION outcol; michael@0: JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; michael@0: register JSAMPROW inptr0, inptr1, outptr; michael@0: register int bias; michael@0: michael@0: /* Expand input data enough to let all the output samples be generated michael@0: * by the standard loop. Special-casing padded output would be more michael@0: * efficient. michael@0: */ michael@0: expand_right_edge(input_data, cinfo->max_v_samp_factor, michael@0: cinfo->image_width, output_cols * 2); michael@0: michael@0: inrow = 0; michael@0: for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { michael@0: outptr = output_data[outrow]; michael@0: inptr0 = input_data[inrow]; michael@0: inptr1 = input_data[inrow+1]; michael@0: bias = 1; /* bias = 1,2,1,2,... for successive samples */ michael@0: for (outcol = 0; outcol < output_cols; outcol++) { michael@0: *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + michael@0: GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]) michael@0: + bias) >> 2); michael@0: bias ^= 3; /* 1=>2, 2=>1 */ michael@0: inptr0 += 2; inptr1 += 2; michael@0: } michael@0: inrow += 2; michael@0: } michael@0: } michael@0: michael@0: michael@0: #ifdef INPUT_SMOOTHING_SUPPORTED michael@0: michael@0: /* michael@0: * Downsample pixel values of a single component. michael@0: * This version handles the standard case of 2:1 horizontal and 2:1 vertical, michael@0: * with smoothing. One row of context is required. michael@0: */ michael@0: michael@0: METHODDEF(void) michael@0: h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, michael@0: JSAMPARRAY input_data, JSAMPARRAY output_data) michael@0: { michael@0: int inrow, outrow; michael@0: JDIMENSION colctr; michael@0: JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; michael@0: register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr; michael@0: INT32 membersum, neighsum, memberscale, neighscale; michael@0: michael@0: /* Expand input data enough to let all the output samples be generated michael@0: * by the standard loop. Special-casing padded output would be more michael@0: * efficient. michael@0: */ michael@0: expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, michael@0: cinfo->image_width, output_cols * 2); michael@0: michael@0: /* We don't bother to form the individual "smoothed" input pixel values; michael@0: * we can directly compute the output which is the average of the four michael@0: * smoothed values. Each of the four member pixels contributes a fraction michael@0: * (1-8*SF) to its own smoothed image and a fraction SF to each of the three michael@0: * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final michael@0: * output. The four corner-adjacent neighbor pixels contribute a fraction michael@0: * SF to just one smoothed pixel, or SF/4 to the final output; while the michael@0: * eight edge-adjacent neighbors contribute SF to each of two smoothed michael@0: * pixels, or SF/2 overall. In order to use integer arithmetic, these michael@0: * factors are scaled by 2^16 = 65536. michael@0: * Also recall that SF = smoothing_factor / 1024. michael@0: */ michael@0: michael@0: memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */ michael@0: neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */ michael@0: michael@0: inrow = 0; michael@0: for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { michael@0: outptr = output_data[outrow]; michael@0: inptr0 = input_data[inrow]; michael@0: inptr1 = input_data[inrow+1]; michael@0: above_ptr = input_data[inrow-1]; michael@0: below_ptr = input_data[inrow+2]; michael@0: michael@0: /* Special case for first column: pretend column -1 is same as column 0 */ michael@0: membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + michael@0: GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); michael@0: neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + michael@0: GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + michael@0: GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) + michael@0: GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]); michael@0: neighsum += neighsum; michael@0: neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) + michael@0: GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]); michael@0: membersum = membersum * memberscale + neighsum * neighscale; michael@0: *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); michael@0: inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; michael@0: michael@0: for (colctr = output_cols - 2; colctr > 0; colctr--) { michael@0: /* sum of pixels directly mapped to this output element */ michael@0: membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + michael@0: GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); michael@0: /* sum of edge-neighbor pixels */ michael@0: neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + michael@0: GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + michael@0: GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) + michael@0: GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]); michael@0: /* The edge-neighbors count twice as much as corner-neighbors */ michael@0: neighsum += neighsum; michael@0: /* Add in the corner-neighbors */ michael@0: neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) + michael@0: GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]); michael@0: /* form final output scaled up by 2^16 */ michael@0: membersum = membersum * memberscale + neighsum * neighscale; michael@0: /* round, descale and output it */ michael@0: *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); michael@0: inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; michael@0: } michael@0: michael@0: /* Special case for last column */ michael@0: membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + michael@0: GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); michael@0: neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + michael@0: GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + michael@0: GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) + michael@0: GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]); michael@0: neighsum += neighsum; michael@0: neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) + michael@0: GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]); michael@0: membersum = membersum * memberscale + neighsum * neighscale; michael@0: *outptr = (JSAMPLE) ((membersum + 32768) >> 16); michael@0: michael@0: inrow += 2; michael@0: } michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Downsample pixel values of a single component. michael@0: * This version handles the special case of a full-size component, michael@0: * with smoothing. One row of context is required. michael@0: */ michael@0: michael@0: METHODDEF(void) michael@0: fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr, michael@0: JSAMPARRAY input_data, JSAMPARRAY output_data) michael@0: { michael@0: int outrow; michael@0: JDIMENSION colctr; michael@0: JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; michael@0: register JSAMPROW inptr, above_ptr, below_ptr, outptr; michael@0: INT32 membersum, neighsum, memberscale, neighscale; michael@0: int colsum, lastcolsum, nextcolsum; michael@0: michael@0: /* Expand input data enough to let all the output samples be generated michael@0: * by the standard loop. Special-casing padded output would be more michael@0: * efficient. michael@0: */ michael@0: expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, michael@0: cinfo->image_width, output_cols); michael@0: michael@0: /* Each of the eight neighbor pixels contributes a fraction SF to the michael@0: * smoothed pixel, while the main pixel contributes (1-8*SF). In order michael@0: * to use integer arithmetic, these factors are multiplied by 2^16 = 65536. michael@0: * Also recall that SF = smoothing_factor / 1024. michael@0: */ michael@0: michael@0: memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */ michael@0: neighscale = cinfo->smoothing_factor * 64; /* scaled SF */ michael@0: michael@0: for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { michael@0: outptr = output_data[outrow]; michael@0: inptr = input_data[outrow]; michael@0: above_ptr = input_data[outrow-1]; michael@0: below_ptr = input_data[outrow+1]; michael@0: michael@0: /* Special case for first column */ michael@0: colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) + michael@0: GETJSAMPLE(*inptr); michael@0: membersum = GETJSAMPLE(*inptr++); michael@0: nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) + michael@0: GETJSAMPLE(*inptr); michael@0: neighsum = colsum + (colsum - membersum) + nextcolsum; michael@0: membersum = membersum * memberscale + neighsum * neighscale; michael@0: *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); michael@0: lastcolsum = colsum; colsum = nextcolsum; michael@0: michael@0: for (colctr = output_cols - 2; colctr > 0; colctr--) { michael@0: membersum = GETJSAMPLE(*inptr++); michael@0: above_ptr++; below_ptr++; michael@0: nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) + michael@0: GETJSAMPLE(*inptr); michael@0: neighsum = lastcolsum + (colsum - membersum) + nextcolsum; michael@0: membersum = membersum * memberscale + neighsum * neighscale; michael@0: *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); michael@0: lastcolsum = colsum; colsum = nextcolsum; michael@0: } michael@0: michael@0: /* Special case for last column */ michael@0: membersum = GETJSAMPLE(*inptr); michael@0: neighsum = lastcolsum + (colsum - membersum) + colsum; michael@0: membersum = membersum * memberscale + neighsum * neighscale; michael@0: *outptr = (JSAMPLE) ((membersum + 32768) >> 16); michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif /* INPUT_SMOOTHING_SUPPORTED */ michael@0: michael@0: michael@0: /* michael@0: * Module initialization routine for downsampling. michael@0: * Note that we must select a routine for each component. michael@0: */ michael@0: michael@0: GLOBAL(void) michael@0: jinit_downsampler (j_compress_ptr cinfo) michael@0: { michael@0: my_downsample_ptr downsample; michael@0: int ci; michael@0: jpeg_component_info * compptr; michael@0: boolean smoothok = TRUE; michael@0: michael@0: downsample = (my_downsample_ptr) michael@0: (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, michael@0: SIZEOF(my_downsampler)); michael@0: cinfo->downsample = (struct jpeg_downsampler *) downsample; michael@0: downsample->pub.start_pass = start_pass_downsample; michael@0: downsample->pub.downsample = sep_downsample; michael@0: downsample->pub.need_context_rows = FALSE; michael@0: michael@0: if (cinfo->CCIR601_sampling) michael@0: ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); michael@0: michael@0: /* Verify we can handle the sampling factors, and set up method pointers */ michael@0: for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; michael@0: ci++, compptr++) { michael@0: if (compptr->h_samp_factor == cinfo->max_h_samp_factor && michael@0: compptr->v_samp_factor == cinfo->max_v_samp_factor) { michael@0: #ifdef INPUT_SMOOTHING_SUPPORTED michael@0: if (cinfo->smoothing_factor) { michael@0: downsample->methods[ci] = fullsize_smooth_downsample; michael@0: downsample->pub.need_context_rows = TRUE; michael@0: } else michael@0: #endif michael@0: downsample->methods[ci] = fullsize_downsample; michael@0: } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && michael@0: compptr->v_samp_factor == cinfo->max_v_samp_factor) { michael@0: smoothok = FALSE; michael@0: if (jsimd_can_h2v1_downsample()) michael@0: downsample->methods[ci] = jsimd_h2v1_downsample; michael@0: else michael@0: downsample->methods[ci] = h2v1_downsample; michael@0: } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && michael@0: compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) { michael@0: #ifdef INPUT_SMOOTHING_SUPPORTED michael@0: if (cinfo->smoothing_factor) { michael@0: downsample->methods[ci] = h2v2_smooth_downsample; michael@0: downsample->pub.need_context_rows = TRUE; michael@0: } else michael@0: #endif michael@0: if (jsimd_can_h2v2_downsample()) michael@0: downsample->methods[ci] = jsimd_h2v2_downsample; michael@0: else michael@0: downsample->methods[ci] = h2v2_downsample; michael@0: } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 && michael@0: (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) { michael@0: smoothok = FALSE; michael@0: downsample->methods[ci] = int_downsample; michael@0: } else michael@0: ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); michael@0: } michael@0: michael@0: #ifdef INPUT_SMOOTHING_SUPPORTED michael@0: if (cinfo->smoothing_factor && !smoothok) michael@0: TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL); michael@0: #endif michael@0: }