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