istereo2

diff libs/libjpeg/jcsample.c @ 2:81d35769f546

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