/* A note about the "bias" calculations: when rounding fractional values to integer, we do not want to always round 0.5 up to the next integer. If we did that, we'd introduce a noticeable bias towards larger values. Instead, this code is arranged so that 0.5 will be rounded up or down at alternate pixel locations (a simple ordered dither pattern).  */
h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY output_data)
/* A note about the "bias" calculations: when rounding fractional values to integer, we do not want to always round 0.5 up to the next integer. If we did that, we'd introduce a noticeable bias towards larger values. Instead, this code is arranged so that 0.5 will be rounded up or down at alternate pixel locations (a simple ordered dither pattern).  */
h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY output_data)
{
  int inrow;
  JDIMENSION outcol;
  JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
  register JSAMPROW inptr, outptr;
  register int bias;
  expand_right_edge(input_data, cinfo->max_v_samp_factor,
		    cinfo->image_width, output_cols * 2);
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
    outptr = output_data[inrow];
    inptr = input_data[inrow];
    bias = 0;
    for (outcol = 0; outcol < output_cols; outcol++) {
      *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
			      + bias) >> 1);
      bias ^= 1;
      inptr += 2;
    }
  }
}