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