kusano 7d535a
/*
kusano 7d535a
 * jdmerge.c
kusano 7d535a
 *
kusano 7d535a
 * Copyright (C) 1994-1996, Thomas G. Lane.
kusano 7d535a
 * This file is part of the Independent JPEG Group's software.
kusano 7d535a
 * For conditions of distribution and use, see the accompanying README file.
kusano 7d535a
 *
kusano 7d535a
 * This file contains code for merged upsampling/color conversion.
kusano 7d535a
 *
kusano 7d535a
 * This file combines functions from jdsample.c and jdcolor.c;
kusano 7d535a
 * read those files first to understand what's going on.
kusano 7d535a
 *
kusano 7d535a
 * When the chroma components are to be upsampled by simple replication
kusano 7d535a
 * (ie, box filtering), we can save some work in color conversion by
kusano 7d535a
 * calculating all the output pixels corresponding to a pair of chroma
kusano 7d535a
 * samples at one time.  In the conversion equations
kusano 7d535a
 *	R = Y           + K1 * Cr
kusano 7d535a
 *	G = Y + K2 * Cb + K3 * Cr
kusano 7d535a
 *	B = Y + K4 * Cb
kusano 7d535a
 * only the Y term varies among the group of pixels corresponding to a pair
kusano 7d535a
 * of chroma samples, so the rest of the terms can be calculated just once.
kusano 7d535a
 * At typical sampling ratios, this eliminates half or three-quarters of the
kusano 7d535a
 * multiplications needed for color conversion.
kusano 7d535a
 *
kusano 7d535a
 * This file currently provides implementations for the following cases:
kusano 7d535a
 *	YCbCr => RGB color conversion only.
kusano 7d535a
 *	Sampling ratios of 2h1v or 2h2v.
kusano 7d535a
 *	No scaling needed at upsample time.
kusano 7d535a
 *	Corner-aligned (non-CCIR601) sampling alignment.
kusano 7d535a
 * Other special cases could be added, but in most applications these are
kusano 7d535a
 * the only common cases.  (For uncommon cases we fall back on the more
kusano 7d535a
 * general code in jdsample.c and jdcolor.c.)
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#define JPEG_INTERNALS
kusano 7d535a
#include "jinclude.h"
kusano 7d535a
#include "jpeglib.h"
kusano 7d535a
kusano 7d535a
#ifdef UPSAMPLE_MERGING_SUPPORTED
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* Private subobject */
kusano 7d535a
kusano 7d535a
typedef struct {
kusano 7d535a
  struct jpeg_upsampler pub;	/* public fields */
kusano 7d535a
kusano 7d535a
  /* Pointer to routine to do actual upsampling/conversion of one row group */
kusano 7d535a
  JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
kusano 7d535a
			   JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
kusano 7d535a
			   JSAMPARRAY output_buf));
kusano 7d535a
kusano 7d535a
  /* Private state for YCC->RGB conversion */
kusano 7d535a
  int * Cr_r_tab;		/* => table for Cr to R conversion */
kusano 7d535a
  int * Cb_b_tab;		/* => table for Cb to B conversion */
kusano 7d535a
  INT32 * Cr_g_tab;		/* => table for Cr to G conversion */
kusano 7d535a
  INT32 * Cb_g_tab;		/* => table for Cb to G conversion */
kusano 7d535a
kusano 7d535a
  /* For 2:1 vertical sampling, we produce two output rows at a time.
kusano 7d535a
   * We need a "spare" row buffer to hold the second output row if the
kusano 7d535a
   * application provides just a one-row buffer; we also use the spare
kusano 7d535a
   * to discard the dummy last row if the image height is odd.
kusano 7d535a
   */
kusano 7d535a
  JSAMPROW spare_row;
kusano 7d535a
  boolean spare_full;		/* T if spare buffer is occupied */
kusano 7d535a
kusano 7d535a
  JDIMENSION out_row_width;	/* samples per output row */
kusano 7d535a
  JDIMENSION rows_to_go;	/* counts rows remaining in image */
kusano 7d535a
} my_upsampler;
kusano 7d535a
kusano 7d535a
typedef my_upsampler * my_upsample_ptr;
kusano 7d535a
kusano 7d535a
#define SCALEBITS	16	/* speediest right-shift on some machines */
kusano 7d535a
#define ONE_HALF	((INT32) 1 << (SCALEBITS-1))
kusano 7d535a
#define FIX(x)		((INT32) ((x) * (1L<
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * Initialize tables for YCC->RGB colorspace conversion.
kusano 7d535a
 * This is taken directly from jdcolor.c; see that file for more info.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
LOCAL(void)
kusano 7d535a
build_ycc_rgb_table (j_decompress_ptr cinfo)
kusano 7d535a
{
kusano 7d535a
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
kusano 7d535a
  int i;
kusano 7d535a
  INT32 x;
kusano 7d535a
  SHIFT_TEMPS
kusano 7d535a
kusano 7d535a
  upsample->Cr_r_tab = (int *)
kusano 7d535a
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
kusano 7d535a
				(MAXJSAMPLE+1) * SIZEOF(int));
kusano 7d535a
  upsample->Cb_b_tab = (int *)
kusano 7d535a
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
kusano 7d535a
				(MAXJSAMPLE+1) * SIZEOF(int));
kusano 7d535a
  upsample->Cr_g_tab = (INT32 *)
kusano 7d535a
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
kusano 7d535a
				(MAXJSAMPLE+1) * SIZEOF(INT32));
kusano 7d535a
  upsample->Cb_g_tab = (INT32 *)
kusano 7d535a
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
kusano 7d535a
				(MAXJSAMPLE+1) * SIZEOF(INT32));
kusano 7d535a
kusano 7d535a
  for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
kusano 7d535a
    /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
kusano 7d535a
    /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
kusano 7d535a
    /* Cr=>R value is nearest int to 1.40200 * x */
kusano 7d535a
    upsample->Cr_r_tab[i] = (int)
kusano 7d535a
		    RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
kusano 7d535a
    /* Cb=>B value is nearest int to 1.77200 * x */
kusano 7d535a
    upsample->Cb_b_tab[i] = (int)
kusano 7d535a
		    RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
kusano 7d535a
    /* Cr=>G value is scaled-up -0.71414 * x */
kusano 7d535a
    upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
kusano 7d535a
    /* Cb=>G value is scaled-up -0.34414 * x */
kusano 7d535a
    /* We also add in ONE_HALF so that need not do it in inner loop */
kusano 7d535a
    upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
kusano 7d535a
  }
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * Initialize for an upsampling pass.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
METHODDEF(void)
kusano 7d535a
start_pass_merged_upsample (j_decompress_ptr cinfo)
kusano 7d535a
{
kusano 7d535a
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
kusano 7d535a
kusano 7d535a
  /* Mark the spare buffer empty */
kusano 7d535a
  upsample->spare_full = FALSE;
kusano 7d535a
  /* Initialize total-height counter for detecting bottom of image */
kusano 7d535a
  upsample->rows_to_go = cinfo->output_height;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * Control routine to do upsampling (and color conversion).
kusano 7d535a
 *
kusano 7d535a
 * The control routine just handles the row buffering considerations.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
METHODDEF(void)
kusano 7d535a
merged_2v_upsample (j_decompress_ptr cinfo,
kusano 7d535a
		    JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
kusano 7d535a
		    JDIMENSION in_row_groups_avail,
kusano 7d535a
		    JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
kusano 7d535a
		    JDIMENSION out_rows_avail)
kusano 7d535a
/* 2:1 vertical sampling case: may need a spare row. */
kusano 7d535a
{
kusano 7d535a
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
kusano 7d535a
  JSAMPROW work_ptrs[2];
kusano 7d535a
  JDIMENSION num_rows;		/* number of rows returned to caller */
kusano 7d535a
kusano 7d535a
  if (upsample->spare_full) {
kusano 7d535a
    /* If we have a spare row saved from a previous cycle, just return it. */
kusano 7d535a
    jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
kusano 7d535a
		      1, upsample->out_row_width);
kusano 7d535a
    num_rows = 1;
kusano 7d535a
    upsample->spare_full = FALSE;
kusano 7d535a
  } else {
kusano 7d535a
    /* Figure number of rows to return to caller. */
kusano 7d535a
    num_rows = 2;
kusano 7d535a
    /* Not more than the distance to the end of the image. */
kusano 7d535a
    if (num_rows > upsample->rows_to_go)
kusano 7d535a
      num_rows = upsample->rows_to_go;
kusano 7d535a
    /* And not more than what the client can accept: */
kusano 7d535a
    out_rows_avail -= *out_row_ctr;
kusano 7d535a
    if (num_rows > out_rows_avail)
kusano 7d535a
      num_rows = out_rows_avail;
kusano 7d535a
    /* Create output pointer array for upsampler. */
kusano 7d535a
    work_ptrs[0] = output_buf[*out_row_ctr];
kusano 7d535a
    if (num_rows > 1) {
kusano 7d535a
      work_ptrs[1] = output_buf[*out_row_ctr + 1];
kusano 7d535a
    } else {
kusano 7d535a
      work_ptrs[1] = upsample->spare_row;
kusano 7d535a
      upsample->spare_full = TRUE;
kusano 7d535a
    }
kusano 7d535a
    /* Now do the upsampling. */
kusano 7d535a
    (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
kusano 7d535a
  }
kusano 7d535a
kusano 7d535a
  /* Adjust counts */
kusano 7d535a
  *out_row_ctr += num_rows;
kusano 7d535a
  upsample->rows_to_go -= num_rows;
kusano 7d535a
  /* When the buffer is emptied, declare this input row group consumed */
kusano 7d535a
  if (! upsample->spare_full)
kusano 7d535a
    (*in_row_group_ctr)++;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
METHODDEF(void)
kusano 7d535a
merged_1v_upsample (j_decompress_ptr cinfo,
kusano 7d535a
		    JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
kusano 7d535a
		    JDIMENSION in_row_groups_avail,
kusano 7d535a
		    JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
kusano 7d535a
		    JDIMENSION out_rows_avail)
kusano 7d535a
/* 1:1 vertical sampling case: much easier, never need a spare row. */
kusano 7d535a
{
kusano 7d535a
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
kusano 7d535a
kusano 7d535a
  /* Just do the upsampling. */
kusano 7d535a
  (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
kusano 7d535a
			 output_buf + *out_row_ctr);
kusano 7d535a
  /* Adjust counts */
kusano 7d535a
  (*out_row_ctr)++;
kusano 7d535a
  (*in_row_group_ctr)++;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * These are the routines invoked by the control routines to do
kusano 7d535a
 * the actual upsampling/conversion.  One row group is processed per call.
kusano 7d535a
 *
kusano 7d535a
 * Note: since we may be writing directly into application-supplied buffers,
kusano 7d535a
 * we have to be honest about the output width; we can't assume the buffer
kusano 7d535a
 * has been rounded up to an even width.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
METHODDEF(void)
kusano 7d535a
h2v1_merged_upsample (j_decompress_ptr cinfo,
kusano 7d535a
		      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
kusano 7d535a
		      JSAMPARRAY output_buf)
kusano 7d535a
{
kusano 7d535a
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
kusano 7d535a
  register int y, cred, cgreen, cblue;
kusano 7d535a
  int cb, cr;
kusano 7d535a
  register JSAMPROW outptr;
kusano 7d535a
  JSAMPROW inptr0, inptr1, inptr2;
kusano 7d535a
  JDIMENSION col;
kusano 7d535a
  /* copy these pointers into registers if possible */
kusano 7d535a
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
kusano 7d535a
  int * Crrtab = upsample->Cr_r_tab;
kusano 7d535a
  int * Cbbtab = upsample->Cb_b_tab;
kusano 7d535a
  INT32 * Crgtab = upsample->Cr_g_tab;
kusano 7d535a
  INT32 * Cbgtab = upsample->Cb_g_tab;
kusano 7d535a
  SHIFT_TEMPS
kusano 7d535a
kusano 7d535a
  inptr0 = input_buf[0][in_row_group_ctr];
kusano 7d535a
  inptr1 = input_buf[1][in_row_group_ctr];
kusano 7d535a
  inptr2 = input_buf[2][in_row_group_ctr];
kusano 7d535a
  outptr = output_buf[0];
kusano 7d535a
  /* Loop for each pair of output pixels */
kusano 7d535a
  for (col = cinfo->output_width >> 1; col > 0; col--) {
kusano 7d535a
    /* Do the chroma part of the calculation */
kusano 7d535a
    cb = GETJSAMPLE(*inptr1++);
kusano 7d535a
    cr = GETJSAMPLE(*inptr2++);
kusano 7d535a
    cred = Crrtab[cr];
kusano 7d535a
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
kusano 7d535a
    cblue = Cbbtab[cb];
kusano 7d535a
    /* Fetch 2 Y values and emit 2 pixels */
kusano 7d535a
    y  = GETJSAMPLE(*inptr0++);
kusano 7d535a
    outptr[RGB_RED] =   range_limit[y + cred];
kusano 7d535a
    outptr[RGB_GREEN] = range_limit[y + cgreen];
kusano 7d535a
    outptr[RGB_BLUE] =  range_limit[y + cblue];
kusano 7d535a
    outptr += RGB_PIXELSIZE;
kusano 7d535a
    y  = GETJSAMPLE(*inptr0++);
kusano 7d535a
    outptr[RGB_RED] =   range_limit[y + cred];
kusano 7d535a
    outptr[RGB_GREEN] = range_limit[y + cgreen];
kusano 7d535a
    outptr[RGB_BLUE] =  range_limit[y + cblue];
kusano 7d535a
    outptr += RGB_PIXELSIZE;
kusano 7d535a
  }
kusano 7d535a
  /* If image width is odd, do the last output column separately */
kusano 7d535a
  if (cinfo->output_width & 1) {
kusano 7d535a
    cb = GETJSAMPLE(*inptr1);
kusano 7d535a
    cr = GETJSAMPLE(*inptr2);
kusano 7d535a
    cred = Crrtab[cr];
kusano 7d535a
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
kusano 7d535a
    cblue = Cbbtab[cb];
kusano 7d535a
    y  = GETJSAMPLE(*inptr0);
kusano 7d535a
    outptr[RGB_RED] =   range_limit[y + cred];
kusano 7d535a
    outptr[RGB_GREEN] = range_limit[y + cgreen];
kusano 7d535a
    outptr[RGB_BLUE] =  range_limit[y + cblue];
kusano 7d535a
  }
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
METHODDEF(void)
kusano 7d535a
h2v2_merged_upsample (j_decompress_ptr cinfo,
kusano 7d535a
		      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
kusano 7d535a
		      JSAMPARRAY output_buf)
kusano 7d535a
{
kusano 7d535a
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
kusano 7d535a
  register int y, cred, cgreen, cblue;
kusano 7d535a
  int cb, cr;
kusano 7d535a
  register JSAMPROW outptr0, outptr1;
kusano 7d535a
  JSAMPROW inptr00, inptr01, inptr1, inptr2;
kusano 7d535a
  JDIMENSION col;
kusano 7d535a
  /* copy these pointers into registers if possible */
kusano 7d535a
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
kusano 7d535a
  int * Crrtab = upsample->Cr_r_tab;
kusano 7d535a
  int * Cbbtab = upsample->Cb_b_tab;
kusano 7d535a
  INT32 * Crgtab = upsample->Cr_g_tab;
kusano 7d535a
  INT32 * Cbgtab = upsample->Cb_g_tab;
kusano 7d535a
  SHIFT_TEMPS
kusano 7d535a
kusano 7d535a
  inptr00 = input_buf[0][in_row_group_ctr*2];
kusano 7d535a
  inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
kusano 7d535a
  inptr1 = input_buf[1][in_row_group_ctr];
kusano 7d535a
  inptr2 = input_buf[2][in_row_group_ctr];
kusano 7d535a
  outptr0 = output_buf[0];
kusano 7d535a
  outptr1 = output_buf[1];
kusano 7d535a
  /* Loop for each group of output pixels */
kusano 7d535a
  for (col = cinfo->output_width >> 1; col > 0; col--) {
kusano 7d535a
    /* Do the chroma part of the calculation */
kusano 7d535a
    cb = GETJSAMPLE(*inptr1++);
kusano 7d535a
    cr = GETJSAMPLE(*inptr2++);
kusano 7d535a
    cred = Crrtab[cr];
kusano 7d535a
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
kusano 7d535a
    cblue = Cbbtab[cb];
kusano 7d535a
    /* Fetch 4 Y values and emit 4 pixels */
kusano 7d535a
    y  = GETJSAMPLE(*inptr00++);
kusano 7d535a
    outptr0[RGB_RED] =   range_limit[y + cred];
kusano 7d535a
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
kusano 7d535a
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
kusano 7d535a
    outptr0 += RGB_PIXELSIZE;
kusano 7d535a
    y  = GETJSAMPLE(*inptr00++);
kusano 7d535a
    outptr0[RGB_RED] =   range_limit[y + cred];
kusano 7d535a
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
kusano 7d535a
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
kusano 7d535a
    outptr0 += RGB_PIXELSIZE;
kusano 7d535a
    y  = GETJSAMPLE(*inptr01++);
kusano 7d535a
    outptr1[RGB_RED] =   range_limit[y + cred];
kusano 7d535a
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
kusano 7d535a
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
kusano 7d535a
    outptr1 += RGB_PIXELSIZE;
kusano 7d535a
    y  = GETJSAMPLE(*inptr01++);
kusano 7d535a
    outptr1[RGB_RED] =   range_limit[y + cred];
kusano 7d535a
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
kusano 7d535a
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
kusano 7d535a
    outptr1 += RGB_PIXELSIZE;
kusano 7d535a
  }
kusano 7d535a
  /* If image width is odd, do the last output column separately */
kusano 7d535a
  if (cinfo->output_width & 1) {
kusano 7d535a
    cb = GETJSAMPLE(*inptr1);
kusano 7d535a
    cr = GETJSAMPLE(*inptr2);
kusano 7d535a
    cred = Crrtab[cr];
kusano 7d535a
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
kusano 7d535a
    cblue = Cbbtab[cb];
kusano 7d535a
    y  = GETJSAMPLE(*inptr00);
kusano 7d535a
    outptr0[RGB_RED] =   range_limit[y + cred];
kusano 7d535a
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
kusano 7d535a
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
kusano 7d535a
    y  = GETJSAMPLE(*inptr01);
kusano 7d535a
    outptr1[RGB_RED] =   range_limit[y + cred];
kusano 7d535a
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
kusano 7d535a
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
kusano 7d535a
  }
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * Module initialization routine for merged upsampling/color conversion.
kusano 7d535a
 *
kusano 7d535a
 * NB: this is called under the conditions determined by use_merged_upsample()
kusano 7d535a
 * in jdmaster.c.  That routine MUST correspond to the actual capabilities
kusano 7d535a
 * of this module; no safety checks are made here.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
GLOBAL(void)
kusano 7d535a
jinit_merged_upsampler (j_decompress_ptr cinfo)
kusano 7d535a
{
kusano 7d535a
  my_upsample_ptr upsample;
kusano 7d535a
kusano 7d535a
  upsample = (my_upsample_ptr)
kusano 7d535a
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
kusano 7d535a
				SIZEOF(my_upsampler));
kusano 7d535a
  cinfo->upsample = (struct jpeg_upsampler *) upsample;
kusano 7d535a
  upsample->pub.start_pass = start_pass_merged_upsample;
kusano 7d535a
  upsample->pub.need_context_rows = FALSE;
kusano 7d535a
kusano 7d535a
  upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
kusano 7d535a
kusano 7d535a
  if (cinfo->max_v_samp_factor == 2) {
kusano 7d535a
    upsample->pub.upsample = merged_2v_upsample;
kusano 7d535a
    upsample->upmethod = h2v2_merged_upsample;
kusano 7d535a
    /* Allocate a spare row buffer */
kusano 7d535a
    upsample->spare_row = (JSAMPROW)
kusano 7d535a
      (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
kusano 7d535a
		(size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
kusano 7d535a
  } else {
kusano 7d535a
    upsample->pub.upsample = merged_1v_upsample;
kusano 7d535a
    upsample->upmethod = h2v1_merged_upsample;
kusano 7d535a
    /* No spare row needed */
kusano 7d535a
    upsample->spare_row = NULL;
kusano 7d535a
  }
kusano 7d535a
kusano 7d535a
  build_ycc_rgb_table(cinfo);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
#endif /* UPSAMPLE_MERGING_SUPPORTED */