shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * jidctred.c
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * This file was part of the Independent JPEG Group's software:
shun-iwasawa 82a8f5
 * Copyright (C) 1994-1998, Thomas G. Lane.
shun-iwasawa 82a8f5
 * libjpeg-turbo Modifications:
shun-iwasawa 82a8f5
 * Copyright (C) 2015, D. R. Commander.
shun-iwasawa 82a8f5
 * For conditions of distribution and use, see the accompanying README.ijg
shun-iwasawa 82a8f5
 * file.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * This file contains inverse-DCT routines that produce reduced-size output:
shun-iwasawa 82a8f5
 * either 4x4, 2x2, or 1x1 pixels from an 8x8 DCT block.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * The implementation is based on the Loeffler, Ligtenberg and Moschytz (LL&M)
shun-iwasawa 82a8f5
 * algorithm used in jidctint.c.  We simply replace each 8-to-8 1-D IDCT step
shun-iwasawa 82a8f5
 * with an 8-to-4 step that produces the four averages of two adjacent outputs
shun-iwasawa 82a8f5
 * (or an 8-to-2 step producing two averages of four outputs, for 2x2 output).
shun-iwasawa 82a8f5
 * These steps were derived by computing the corresponding values at the end
shun-iwasawa 82a8f5
 * of the normal LL&M code, then simplifying as much as possible.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * 1x1 is trivial: just take the DC coefficient divided by 8.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * See jidctint.c for additional comments.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define JPEG_INTERNALS
shun-iwasawa 82a8f5
#include "jinclude.h"
shun-iwasawa 82a8f5
#include "jpeglib.h"
shun-iwasawa 82a8f5
#include "jdct.h"               /* Private declarations for DCT subsystem */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#ifdef IDCT_SCALING_SUPPORTED
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * This module is specialized to the case DCTSIZE = 8.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#if DCTSIZE != 8
shun-iwasawa 82a8f5
  Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* Scaling is the same as in jidctint.c. */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#if BITS_IN_JSAMPLE == 8
shun-iwasawa 82a8f5
#define CONST_BITS  13
shun-iwasawa 82a8f5
#define PASS1_BITS  2
shun-iwasawa 82a8f5
#else
shun-iwasawa 82a8f5
#define CONST_BITS  13
shun-iwasawa 82a8f5
#define PASS1_BITS  1           /* lose a little precision to avoid overflow */
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
shun-iwasawa 82a8f5
 * causing a lot of useless floating-point operations at run time.
shun-iwasawa 82a8f5
 * To get around this we use the following pre-calculated constants.
shun-iwasawa 82a8f5
 * If you change CONST_BITS you may want to add appropriate values.
shun-iwasawa 82a8f5
 * (With a reasonable C compiler, you can just rely on the FIX() macro...)
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#if CONST_BITS == 13
shun-iwasawa 82a8f5
#define FIX_0_211164243  ((JLONG)1730)          /* FIX(0.211164243) */
shun-iwasawa 82a8f5
#define FIX_0_509795579  ((JLONG)4176)          /* FIX(0.509795579) */
shun-iwasawa 82a8f5
#define FIX_0_601344887  ((JLONG)4926)          /* FIX(0.601344887) */
shun-iwasawa 82a8f5
#define FIX_0_720959822  ((JLONG)5906)          /* FIX(0.720959822) */
shun-iwasawa 82a8f5
#define FIX_0_765366865  ((JLONG)6270)          /* FIX(0.765366865) */
shun-iwasawa 82a8f5
#define FIX_0_850430095  ((JLONG)6967)          /* FIX(0.850430095) */
shun-iwasawa 82a8f5
#define FIX_0_899976223  ((JLONG)7373)          /* FIX(0.899976223) */
shun-iwasawa 82a8f5
#define FIX_1_061594337  ((JLONG)8697)          /* FIX(1.061594337) */
shun-iwasawa 82a8f5
#define FIX_1_272758580  ((JLONG)10426)         /* FIX(1.272758580) */
shun-iwasawa 82a8f5
#define FIX_1_451774981  ((JLONG)11893)         /* FIX(1.451774981) */
shun-iwasawa 82a8f5
#define FIX_1_847759065  ((JLONG)15137)         /* FIX(1.847759065) */
shun-iwasawa 82a8f5
#define FIX_2_172734803  ((JLONG)17799)         /* FIX(2.172734803) */
shun-iwasawa 82a8f5
#define FIX_2_562915447  ((JLONG)20995)         /* FIX(2.562915447) */
shun-iwasawa 82a8f5
#define FIX_3_624509785  ((JLONG)29692)         /* FIX(3.624509785) */
shun-iwasawa 82a8f5
#else
shun-iwasawa 82a8f5
#define FIX_0_211164243  FIX(0.211164243)
shun-iwasawa 82a8f5
#define FIX_0_509795579  FIX(0.509795579)
shun-iwasawa 82a8f5
#define FIX_0_601344887  FIX(0.601344887)
shun-iwasawa 82a8f5
#define FIX_0_720959822  FIX(0.720959822)
shun-iwasawa 82a8f5
#define FIX_0_765366865  FIX(0.765366865)
shun-iwasawa 82a8f5
#define FIX_0_850430095  FIX(0.850430095)
shun-iwasawa 82a8f5
#define FIX_0_899976223  FIX(0.899976223)
shun-iwasawa 82a8f5
#define FIX_1_061594337  FIX(1.061594337)
shun-iwasawa 82a8f5
#define FIX_1_272758580  FIX(1.272758580)
shun-iwasawa 82a8f5
#define FIX_1_451774981  FIX(1.451774981)
shun-iwasawa 82a8f5
#define FIX_1_847759065  FIX(1.847759065)
shun-iwasawa 82a8f5
#define FIX_2_172734803  FIX(2.172734803)
shun-iwasawa 82a8f5
#define FIX_2_562915447  FIX(2.562915447)
shun-iwasawa 82a8f5
#define FIX_3_624509785  FIX(3.624509785)
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* Multiply a JLONG variable by a JLONG constant to yield a JLONG result.
shun-iwasawa 82a8f5
 * For 8-bit samples with the recommended scaling, all the variable
shun-iwasawa 82a8f5
 * and constant values involved are no more than 16 bits wide, so a
shun-iwasawa 82a8f5
 * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
shun-iwasawa 82a8f5
 * For 12-bit samples, a full 32-bit multiplication will be needed.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#if BITS_IN_JSAMPLE == 8
shun-iwasawa 82a8f5
#define MULTIPLY(var, const)  MULTIPLY16C16(var, const)
shun-iwasawa 82a8f5
#else
shun-iwasawa 82a8f5
#define MULTIPLY(var, const)  ((var) * (const))
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* Dequantize a coefficient by multiplying it by the multiplier-table
shun-iwasawa 82a8f5
 * entry; produce an int result.  In this module, both inputs and result
shun-iwasawa 82a8f5
 * are 16 bits or less, so either int or short multiply will work.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define DEQUANTIZE(coef, quantval)  (((ISLOW_MULT_TYPE)(coef)) * (quantval))
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Perform dequantization and inverse DCT on one block of coefficients,
shun-iwasawa 82a8f5
 * producing a reduced-size 4x4 output block.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
GLOBAL(void)
shun-iwasawa 82a8f5
jpeg_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
shun-iwasawa 82a8f5
              JCOEFPTR coef_block, JSAMPARRAY output_buf,
shun-iwasawa 82a8f5
              JDIMENSION output_col)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  JLONG tmp0, tmp2, tmp10, tmp12;
shun-iwasawa 82a8f5
  JLONG z1, z2, z3, z4;
shun-iwasawa 82a8f5
  JCOEFPTR inptr;
shun-iwasawa 82a8f5
  ISLOW_MULT_TYPE *quantptr;
shun-iwasawa 82a8f5
  int *wsptr;
shun-iwasawa 82a8f5
  JSAMPROW outptr;
shun-iwasawa 82a8f5
  JSAMPLE *range_limit = IDCT_range_limit(cinfo);
shun-iwasawa 82a8f5
  int ctr;
shun-iwasawa 82a8f5
  int workspace[DCTSIZE * 4];   /* buffers data between passes */
shun-iwasawa 82a8f5
  SHIFT_TEMPS
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* Pass 1: process columns from input, store into work array. */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  inptr = coef_block;
shun-iwasawa 82a8f5
  quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
shun-iwasawa 82a8f5
  wsptr = workspace;
shun-iwasawa 82a8f5
  for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
shun-iwasawa 82a8f5
    /* Don't bother to process column 4, because second pass won't use it */
shun-iwasawa 82a8f5
    if (ctr == DCTSIZE - 4)
shun-iwasawa 82a8f5
      continue;
shun-iwasawa 82a8f5
    if (inptr[DCTSIZE * 1] == 0 && inptr[DCTSIZE * 2] == 0 &&
shun-iwasawa 82a8f5
        inptr[DCTSIZE * 3] == 0 && inptr[DCTSIZE * 5] == 0 &&
shun-iwasawa 82a8f5
        inptr[DCTSIZE * 6] == 0 && inptr[DCTSIZE * 7] == 0) {
shun-iwasawa 82a8f5
      /* AC terms all zero; we need not examine term 4 for 4x4 output */
shun-iwasawa 82a8f5
      int dcval = LEFT_SHIFT(DEQUANTIZE(inptr[DCTSIZE * 0],
shun-iwasawa 82a8f5
                                        quantptr[DCTSIZE * 0]), PASS1_BITS);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      wsptr[DCTSIZE * 0] = dcval;
shun-iwasawa 82a8f5
      wsptr[DCTSIZE * 1] = dcval;
shun-iwasawa 82a8f5
      wsptr[DCTSIZE * 2] = dcval;
shun-iwasawa 82a8f5
      wsptr[DCTSIZE * 3] = dcval;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      continue;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    /* Even part */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    tmp0 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
shun-iwasawa 82a8f5
    tmp0 = LEFT_SHIFT(tmp0, CONST_BITS + 1);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    z2 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
shun-iwasawa 82a8f5
    z3 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, -FIX_0_765366865);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    tmp10 = tmp0 + tmp2;
shun-iwasawa 82a8f5
    tmp12 = tmp0 - tmp2;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    /* Odd part */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    z1 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
shun-iwasawa 82a8f5
    z2 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
shun-iwasawa 82a8f5
    z3 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
shun-iwasawa 82a8f5
    z4 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    tmp0 = MULTIPLY(z1, -FIX_0_211164243) + /* sqrt(2) * ( c3-c1) */
shun-iwasawa 82a8f5
           MULTIPLY(z2,  FIX_1_451774981) + /* sqrt(2) * ( c3+c7) */
shun-iwasawa 82a8f5
           MULTIPLY(z3, -FIX_2_172734803) + /* sqrt(2) * (-c1-c5) */
shun-iwasawa 82a8f5
           MULTIPLY(z4,  FIX_1_061594337);  /* sqrt(2) * ( c5+c7) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    tmp2 = MULTIPLY(z1, -FIX_0_509795579) + /* sqrt(2) * (c7-c5) */
shun-iwasawa 82a8f5
           MULTIPLY(z2, -FIX_0_601344887) + /* sqrt(2) * (c5-c1) */
shun-iwasawa 82a8f5
           MULTIPLY(z3,  FIX_0_899976223) + /* sqrt(2) * (c3-c7) */
shun-iwasawa 82a8f5
           MULTIPLY(z4,  FIX_2_562915447);  /* sqrt(2) * (c1+c3) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    /* Final output stage */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    wsptr[DCTSIZE * 0] =
shun-iwasawa 82a8f5
      (int)DESCALE(tmp10 + tmp2, CONST_BITS - PASS1_BITS + 1);
shun-iwasawa 82a8f5
    wsptr[DCTSIZE * 3] =
shun-iwasawa 82a8f5
      (int)DESCALE(tmp10 - tmp2, CONST_BITS - PASS1_BITS + 1);
shun-iwasawa 82a8f5
    wsptr[DCTSIZE * 1] =
shun-iwasawa 82a8f5
      (int)DESCALE(tmp12 + tmp0, CONST_BITS - PASS1_BITS + 1);
shun-iwasawa 82a8f5
    wsptr[DCTSIZE * 2] =
shun-iwasawa 82a8f5
      (int)DESCALE(tmp12 - tmp0, CONST_BITS - PASS1_BITS + 1);
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* Pass 2: process 4 rows from work array, store into output array. */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  wsptr = workspace;
shun-iwasawa 82a8f5
  for (ctr = 0; ctr < 4; ctr++) {
shun-iwasawa 82a8f5
    outptr = output_buf[ctr] + output_col;
shun-iwasawa 82a8f5
    /* It's not clear whether a zero row test is worthwhile here ... */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#ifndef NO_ZERO_ROW_TEST
shun-iwasawa 82a8f5
    if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
shun-iwasawa 82a8f5
        wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
shun-iwasawa 82a8f5
      /* AC terms all zero */
shun-iwasawa 82a8f5
      JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
shun-iwasawa 82a8f5
                                               PASS1_BITS + 3) & RANGE_MASK];
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      outptr[0] = dcval;
shun-iwasawa 82a8f5
      outptr[1] = dcval;
shun-iwasawa 82a8f5
      outptr[2] = dcval;
shun-iwasawa 82a8f5
      outptr[3] = dcval;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      wsptr += DCTSIZE;         /* advance pointer to next row */
shun-iwasawa 82a8f5
      continue;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    /* Even part */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    tmp0 = LEFT_SHIFT((JLONG)wsptr[0], CONST_BITS + 1);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    tmp2 = MULTIPLY((JLONG)wsptr[2],  FIX_1_847759065) +
shun-iwasawa 82a8f5
           MULTIPLY((JLONG)wsptr[6], -FIX_0_765366865);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    tmp10 = tmp0 + tmp2;
shun-iwasawa 82a8f5
    tmp12 = tmp0 - tmp2;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    /* Odd part */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    z1 = (JLONG)wsptr[7];
shun-iwasawa 82a8f5
    z2 = (JLONG)wsptr[5];
shun-iwasawa 82a8f5
    z3 = (JLONG)wsptr[3];
shun-iwasawa 82a8f5
    z4 = (JLONG)wsptr[1];
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    tmp0 = MULTIPLY(z1, -FIX_0_211164243) + /* sqrt(2) * ( c3-c1) */
shun-iwasawa 82a8f5
           MULTIPLY(z2,  FIX_1_451774981) + /* sqrt(2) * ( c3+c7) */
shun-iwasawa 82a8f5
           MULTIPLY(z3, -FIX_2_172734803) + /* sqrt(2) * (-c1-c5) */
shun-iwasawa 82a8f5
           MULTIPLY(z4,  FIX_1_061594337);  /* sqrt(2) * ( c5+c7) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    tmp2 = MULTIPLY(z1, -FIX_0_509795579) + /* sqrt(2) * (c7-c5) */
shun-iwasawa 82a8f5
           MULTIPLY(z2, -FIX_0_601344887) + /* sqrt(2) * (c5-c1) */
shun-iwasawa 82a8f5
           MULTIPLY(z3, FIX_0_899976223) +  /* sqrt(2) * (c3-c7) */
shun-iwasawa 82a8f5
           MULTIPLY(z4, FIX_2_562915447);   /* sqrt(2) * (c1+c3) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    /* Final output stage */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    outptr[0] = range_limit[(int)DESCALE(tmp10 + tmp2,
shun-iwasawa 82a8f5
                                         CONST_BITS + PASS1_BITS + 3 + 1) &
shun-iwasawa 82a8f5
                            RANGE_MASK];
shun-iwasawa 82a8f5
    outptr[3] = range_limit[(int)DESCALE(tmp10 - tmp2,
shun-iwasawa 82a8f5
                                         CONST_BITS + PASS1_BITS + 3 + 1) &
shun-iwasawa 82a8f5
                            RANGE_MASK];
shun-iwasawa 82a8f5
    outptr[1] = range_limit[(int)DESCALE(tmp12 + tmp0,
shun-iwasawa 82a8f5
                                         CONST_BITS + PASS1_BITS + 3 + 1) &
shun-iwasawa 82a8f5
                            RANGE_MASK];
shun-iwasawa 82a8f5
    outptr[2] = range_limit[(int)DESCALE(tmp12 - tmp0,
shun-iwasawa 82a8f5
                                         CONST_BITS + PASS1_BITS + 3 + 1) &
shun-iwasawa 82a8f5
                            RANGE_MASK];
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    wsptr += DCTSIZE;           /* advance pointer to next row */
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Perform dequantization and inverse DCT on one block of coefficients,
shun-iwasawa 82a8f5
 * producing a reduced-size 2x2 output block.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
GLOBAL(void)
shun-iwasawa 82a8f5
jpeg_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
shun-iwasawa 82a8f5
              JCOEFPTR coef_block, JSAMPARRAY output_buf,
shun-iwasawa 82a8f5
              JDIMENSION output_col)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  JLONG tmp0, tmp10, z1;
shun-iwasawa 82a8f5
  JCOEFPTR inptr;
shun-iwasawa 82a8f5
  ISLOW_MULT_TYPE *quantptr;
shun-iwasawa 82a8f5
  int *wsptr;
shun-iwasawa 82a8f5
  JSAMPROW outptr;
shun-iwasawa 82a8f5
  JSAMPLE *range_limit = IDCT_range_limit(cinfo);
shun-iwasawa 82a8f5
  int ctr;
shun-iwasawa 82a8f5
  int workspace[DCTSIZE * 2];   /* buffers data between passes */
shun-iwasawa 82a8f5
  SHIFT_TEMPS
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* Pass 1: process columns from input, store into work array. */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  inptr = coef_block;
shun-iwasawa 82a8f5
  quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
shun-iwasawa 82a8f5
  wsptr = workspace;
shun-iwasawa 82a8f5
  for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
shun-iwasawa 82a8f5
    /* Don't bother to process columns 2,4,6 */
shun-iwasawa 82a8f5
    if (ctr == DCTSIZE - 2 || ctr == DCTSIZE - 4 || ctr == DCTSIZE - 6)
shun-iwasawa 82a8f5
      continue;
shun-iwasawa 82a8f5
    if (inptr[DCTSIZE * 1] == 0 && inptr[DCTSIZE * 3] == 0 &&
shun-iwasawa 82a8f5
        inptr[DCTSIZE * 5] == 0 && inptr[DCTSIZE * 7] == 0) {
shun-iwasawa 82a8f5
      /* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */
shun-iwasawa 82a8f5
      int dcval = LEFT_SHIFT(DEQUANTIZE(inptr[DCTSIZE * 0],
shun-iwasawa 82a8f5
                             quantptr[DCTSIZE * 0]), PASS1_BITS);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      wsptr[DCTSIZE * 0] = dcval;
shun-iwasawa 82a8f5
      wsptr[DCTSIZE * 1] = dcval;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      continue;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    /* Even part */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    z1 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
shun-iwasawa 82a8f5
    tmp10 = LEFT_SHIFT(z1, CONST_BITS + 2);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    /* Odd part */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    z1 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
shun-iwasawa 82a8f5
    tmp0 = MULTIPLY(z1, -FIX_0_720959822);  /* sqrt(2) * ( c7-c5+c3-c1) */
shun-iwasawa 82a8f5
    z1 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
shun-iwasawa 82a8f5
    tmp0 += MULTIPLY(z1, FIX_0_850430095);  /* sqrt(2) * (-c1+c3+c5+c7) */
shun-iwasawa 82a8f5
    z1 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
shun-iwasawa 82a8f5
    tmp0 += MULTIPLY(z1, -FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
shun-iwasawa 82a8f5
    z1 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
shun-iwasawa 82a8f5
    tmp0 += MULTIPLY(z1, FIX_3_624509785);  /* sqrt(2) * ( c1+c3+c5+c7) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    /* Final output stage */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    wsptr[DCTSIZE * 0] =
shun-iwasawa 82a8f5
      (int)DESCALE(tmp10 + tmp0, CONST_BITS - PASS1_BITS + 2);
shun-iwasawa 82a8f5
    wsptr[DCTSIZE * 1] =
shun-iwasawa 82a8f5
      (int)DESCALE(tmp10 - tmp0, CONST_BITS - PASS1_BITS + 2);
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* Pass 2: process 2 rows from work array, store into output array. */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  wsptr = workspace;
shun-iwasawa 82a8f5
  for (ctr = 0; ctr < 2; ctr++) {
shun-iwasawa 82a8f5
    outptr = output_buf[ctr] + output_col;
shun-iwasawa 82a8f5
    /* It's not clear whether a zero row test is worthwhile here ... */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#ifndef NO_ZERO_ROW_TEST
shun-iwasawa 82a8f5
    if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
shun-iwasawa 82a8f5
      /* AC terms all zero */
shun-iwasawa 82a8f5
      JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
shun-iwasawa 82a8f5
                                               PASS1_BITS + 3) & RANGE_MASK];
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      outptr[0] = dcval;
shun-iwasawa 82a8f5
      outptr[1] = dcval;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      wsptr += DCTSIZE;         /* advance pointer to next row */
shun-iwasawa 82a8f5
      continue;
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    /* Even part */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    tmp10 = LEFT_SHIFT((JLONG)wsptr[0], CONST_BITS + 2);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    /* Odd part */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    tmp0 = MULTIPLY((JLONG)wsptr[7], -FIX_0_720959822) + /* sqrt(2) * ( c7-c5+c3-c1) */
shun-iwasawa 82a8f5
           MULTIPLY((JLONG)wsptr[5],  FIX_0_850430095) + /* sqrt(2) * (-c1+c3+c5+c7) */
shun-iwasawa 82a8f5
           MULTIPLY((JLONG)wsptr[3], -FIX_1_272758580) + /* sqrt(2) * (-c1+c3-c5-c7) */
shun-iwasawa 82a8f5
           MULTIPLY((JLONG)wsptr[1],  FIX_3_624509785);  /* sqrt(2) * ( c1+c3+c5+c7) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    /* Final output stage */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    outptr[0] = range_limit[(int)DESCALE(tmp10 + tmp0,
shun-iwasawa 82a8f5
                                         CONST_BITS + PASS1_BITS + 3 + 2) &
shun-iwasawa 82a8f5
                            RANGE_MASK];
shun-iwasawa 82a8f5
    outptr[1] = range_limit[(int)DESCALE(tmp10 - tmp0,
shun-iwasawa 82a8f5
                                         CONST_BITS + PASS1_BITS + 3 + 2) &
shun-iwasawa 82a8f5
                            RANGE_MASK];
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    wsptr += DCTSIZE;           /* advance pointer to next row */
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Perform dequantization and inverse DCT on one block of coefficients,
shun-iwasawa 82a8f5
 * producing a reduced-size 1x1 output block.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
GLOBAL(void)
shun-iwasawa 82a8f5
jpeg_idct_1x1(j_decompress_ptr cinfo, jpeg_component_info *compptr,
shun-iwasawa 82a8f5
              JCOEFPTR coef_block, JSAMPARRAY output_buf,
shun-iwasawa 82a8f5
              JDIMENSION output_col)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  int dcval;
shun-iwasawa 82a8f5
  ISLOW_MULT_TYPE *quantptr;
shun-iwasawa 82a8f5
  JSAMPLE *range_limit = IDCT_range_limit(cinfo);
shun-iwasawa 82a8f5
  SHIFT_TEMPS
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* We hardly need an inverse DCT routine for this: just take the
shun-iwasawa 82a8f5
   * average pixel value, which is one-eighth of the DC coefficient.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
shun-iwasawa 82a8f5
  dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
shun-iwasawa 82a8f5
  dcval = (int)DESCALE((JLONG)dcval, 3);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#endif /* IDCT_SCALING_SUPPORTED */