136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* 236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * jidctfst.c 336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * 45ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane * Copyright (C) 1994-1998, Thomas G. Lane. 536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * This file is part of the Independent JPEG Group's software. 636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * For conditions of distribution and use, see the accompanying README file. 736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * 836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * This file contains a fast, not so accurate integer implementation of the 936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine 1036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * must also perform dequantization of the input coefficients. 1136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * 1236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT 1336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * on each row (or vice versa, but it's more convenient to emit a row at 1436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * a time). Direct algorithms are also available, but they are much more 1536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * complex and seem not to be any faster when reduced to code. 1636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * 1736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * This implementation is based on Arai, Agui, and Nakajima's algorithm for 1836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in 1936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * Japanese, but the algorithm is described in the Pennebaker & Mitchell 2036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * JPEG textbook (see REFERENCES section in file README). The following code 2136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * is based directly on figure 4-8 in P&M. 2236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * While an 8-point DCT cannot be done in less than 11 multiplies, it is 2336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * possible to arrange the computation so that many of the multiplies are 2436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * simple scalings of the final outputs. These multiplies can then be 2536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * folded into the multiplications or divisions by the JPEG quantization 2636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * table entries. The AA&N method leaves only 5 multiplies and 29 adds 2736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * to be done in the DCT itself. 2836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * The primary disadvantage of this method is that with fixed-point math, 2936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * accuracy is lost due to imprecise representation of the scaled 3036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * quantization values. The smaller the quantization table entry, the less 3136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * precise the scaled value, so this implementation does worse with high- 3236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * quality-setting files than with low-quality ones. 3336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */ 3436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 3536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define JPEG_INTERNALS 3636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#include "jinclude.h" 3736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#include "jpeglib.h" 38e5eaf37440b8e337ab150c017df7c03faf846c51DRC#include "jdct.h" /* Private declarations for DCT subsystem */ 3936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 4036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#ifdef DCT_IFAST_SUPPORTED 4136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 4236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 4336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* 4436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * This module is specialized to the case DCTSIZE = 8. 4536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */ 4636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 4736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#if DCTSIZE != 8 4836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ 4936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif 5036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 5136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 5236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Scaling decisions are generally the same as in the LL&M algorithm; 5336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * see jidctint.c for more details. However, we choose to descale 5436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * (right shift) multiplication products as soon as they are formed, 5536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * rather than carrying additional fractional bits into subsequent additions. 5636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * This compromises accuracy slightly, but it lets us save a few shifts. 5736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples) 5836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * everywhere except in the multiplications proper; this saves a good deal 5936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * of work on 16-bit-int machines. 6036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * 6136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * The dequantized coefficients are not integers because the AA&N scaling 6236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * factors have been incorporated. We represent them scaled up by PASS1_BITS, 6336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * so that the first and second IDCT rounds have the same input scaling. 6436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to 6536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * avoid a descaling shift; this compromises accuracy rather drastically 6636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * for small quantization table entries, but it saves a lot of shifts. 6736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway, 6836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * so we use a much larger scaling factor to preserve accuracy. 6936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * 7036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * A final compromise is to represent the multiplicative constants to only 7136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * 8 fractional bits, rather than 13. This saves some shifting work on some 7236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * machines, and may also reduce the cost of multiplication (since there 7336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * are fewer one-bits in the constants). 7436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */ 7536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 7636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#if BITS_IN_JSAMPLE == 8 7736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define CONST_BITS 8 7836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define PASS1_BITS 2 7936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#else 8036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define CONST_BITS 8 81e5eaf37440b8e337ab150c017df7c03faf846c51DRC#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ 8236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif 8336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 8436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus 8536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * causing a lot of useless floating-point operations at run time. 8636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * To get around this we use the following pre-calculated constants. 8736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * If you change CONST_BITS you may want to add appropriate values. 8836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * (With a reasonable C compiler, you can just rely on the FIX() macro...) 8936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */ 9036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 9136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#if CONST_BITS == 8 92e5eaf37440b8e337ab150c017df7c03faf846c51DRC#define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */ 93e5eaf37440b8e337ab150c017df7c03faf846c51DRC#define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */ 94e5eaf37440b8e337ab150c017df7c03faf846c51DRC#define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */ 95e5eaf37440b8e337ab150c017df7c03faf846c51DRC#define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */ 9636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#else 9736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define FIX_1_082392200 FIX(1.082392200) 9836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define FIX_1_414213562 FIX(1.414213562) 9936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define FIX_1_847759065 FIX(1.847759065) 10036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define FIX_2_613125930 FIX(2.613125930) 10136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif 10236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 10336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 10436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* We can gain a little more speed, with a further compromise in accuracy, 10536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * by omitting the addition in a descaling shift. This yields an incorrectly 10636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * rounded result half the time... 10736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */ 10836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 10936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#ifndef USE_ACCURATE_ROUNDING 11036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#undef DESCALE 11136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define DESCALE(x,n) RIGHT_SHIFT(x, n) 11236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif 11336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 11436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 11536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Multiply a DCTELEM variable by an INT32 constant, and immediately 11636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * descale to yield a DCTELEM result. 11736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */ 11836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 11936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) 12036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 12136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 12236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Dequantize a coefficient by multiplying it by the multiplier-table 12336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * entry; produce a DCTELEM result. For 8-bit data a 16x16->16 12436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * multiplication will do. For 12-bit data, the multiplier table is 12536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * declared INT32, so a 32-bit multiply will be used. 12636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */ 12736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 12836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#if BITS_IN_JSAMPLE == 8 12936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval)) 13036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#else 13136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define DEQUANTIZE(coef,quantval) \ 132e5eaf37440b8e337ab150c017df7c03faf846c51DRC DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS) 13336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif 13436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 13536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 13636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Like DESCALE, but applies to a DCTELEM and produces an int. 13736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * We assume that int right shift is unsigned if INT32 right shift is. 13836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */ 13936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 14036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#ifdef RIGHT_SHIFT_IS_UNSIGNED 141e5eaf37440b8e337ab150c017df7c03faf846c51DRC#define ISHIFT_TEMPS DCTELEM ishift_temp; 142bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane#if BITS_IN_JSAMPLE == 8 143e5eaf37440b8e337ab150c017df7c03faf846c51DRC#define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */ 144bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane#else 145e5eaf37440b8e337ab150c017df7c03faf846c51DRC#define DCTELEMBITS 32 /* DCTELEM must be 32 bits */ 146bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane#endif 14736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define IRIGHT_SHIFT(x,shft) \ 148bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane ((ishift_temp = (x)) < 0 ? \ 149bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \ 150bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane (ishift_temp >> (shft))) 15136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#else 15236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define ISHIFT_TEMPS 153e5eaf37440b8e337ab150c017df7c03faf846c51DRC#define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) 15436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif 15536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 15636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#ifdef USE_ACCURATE_ROUNDING 15736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n)) 15836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#else 15936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n)) 16036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif 16136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 16236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 16336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* 16436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * Perform dequantization and inverse DCT on one block of coefficients. 16536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */ 16636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 167489583f5165e05d37302e8eeec58104ea0109127Thomas G. LaneGLOBAL(void) 16836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanejpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr, 169e5eaf37440b8e337ab150c017df7c03faf846c51DRC JCOEFPTR coef_block, 170e5eaf37440b8e337ab150c017df7c03faf846c51DRC JSAMPARRAY output_buf, JDIMENSION output_col) 17136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane{ 17236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; 17336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane DCTELEM tmp10, tmp11, tmp12, tmp13; 17436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane DCTELEM z5, z10, z11, z12, z13; 17536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane JCOEFPTR inptr; 17636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane IFAST_MULT_TYPE * quantptr; 17736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane int * wsptr; 17836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane JSAMPROW outptr; 17936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane JSAMPLE *range_limit = IDCT_range_limit(cinfo); 18036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane int ctr; 181e5eaf37440b8e337ab150c017df7c03faf846c51DRC int workspace[DCTSIZE2]; /* buffers data between passes */ 182e5eaf37440b8e337ab150c017df7c03faf846c51DRC SHIFT_TEMPS /* for DESCALE */ 183e5eaf37440b8e337ab150c017df7c03faf846c51DRC ISHIFT_TEMPS /* for IDESCALE */ 18436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 18536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane /* Pass 1: process columns from input, store into work array. */ 18636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 18736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane inptr = coef_block; 18836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane quantptr = (IFAST_MULT_TYPE *) compptr->dct_table; 18936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr = workspace; 19036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane for (ctr = DCTSIZE; ctr > 0; ctr--) { 19136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane /* Due to quantization, we will usually find that many of the input 19236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * coefficients are zero, especially the AC terms. We can exploit this 19336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * by short-circuiting the IDCT calculation for any column in which all 19436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * the AC terms are zero. In that case each output is equal to the 19536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * DC coefficient (with scale factor as needed). 19636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * With typical images and quantization tables, half or more of the 19736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * column DCT calculations can be simplified this way. 19836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */ 199e5eaf37440b8e337ab150c017df7c03faf846c51DRC 2005ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && 201e5eaf37440b8e337ab150c017df7c03faf846c51DRC inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && 202e5eaf37440b8e337ab150c017df7c03faf846c51DRC inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && 203e5eaf37440b8e337ab150c017df7c03faf846c51DRC inptr[DCTSIZE*7] == 0) { 20436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane /* AC terms all zero */ 20536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 20636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 20736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*0] = dcval; 20836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*1] = dcval; 20936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*2] = dcval; 21036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*3] = dcval; 21136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*4] = dcval; 21236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*5] = dcval; 21336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*6] = dcval; 21436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*7] = dcval; 215e5eaf37440b8e337ab150c017df7c03faf846c51DRC 216e5eaf37440b8e337ab150c017df7c03faf846c51DRC inptr++; /* advance pointers to next column */ 21736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane quantptr++; 21836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr++; 21936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane continue; 22036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane } 221e5eaf37440b8e337ab150c017df7c03faf846c51DRC 22236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane /* Even part */ 22336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 22436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 22536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); 22636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); 22736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); 22836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 229e5eaf37440b8e337ab150c017df7c03faf846c51DRC tmp10 = tmp0 + tmp2; /* phase 3 */ 23036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp11 = tmp0 - tmp2; 23136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 232e5eaf37440b8e337ab150c017df7c03faf846c51DRC tmp13 = tmp1 + tmp3; /* phases 5-3 */ 23336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */ 23436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 235e5eaf37440b8e337ab150c017df7c03faf846c51DRC tmp0 = tmp10 + tmp13; /* phase 2 */ 23636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp3 = tmp10 - tmp13; 23736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp1 = tmp11 + tmp12; 23836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp2 = tmp11 - tmp12; 239e5eaf37440b8e337ab150c017df7c03faf846c51DRC 24036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane /* Odd part */ 24136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 24236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); 24336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); 24436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); 24536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); 24636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 247e5eaf37440b8e337ab150c017df7c03faf846c51DRC z13 = tmp6 + tmp5; /* phase 6 */ 24836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane z10 = tmp6 - tmp5; 24936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane z11 = tmp4 + tmp7; 25036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane z12 = tmp4 - tmp7; 25136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 252e5eaf37440b8e337ab150c017df7c03faf846c51DRC tmp7 = z11 + z13; /* phase 5 */ 25336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ 25436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 25536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ 25636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ 25736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ 25836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 259e5eaf37440b8e337ab150c017df7c03faf846c51DRC tmp6 = tmp12 - tmp7; /* phase 2 */ 26036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp5 = tmp11 - tmp6; 26136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp4 = tmp10 + tmp5; 26236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 26336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7); 26436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7); 26536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6); 26636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6); 26736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5); 26836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5); 26936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4); 27036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4); 27136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 272e5eaf37440b8e337ab150c017df7c03faf846c51DRC inptr++; /* advance pointers to next column */ 27336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane quantptr++; 27436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr++; 27536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane } 276e5eaf37440b8e337ab150c017df7c03faf846c51DRC 27736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane /* Pass 2: process rows from work array, store into output array. */ 27836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane /* Note that we must descale the results by a factor of 8 == 2**3, */ 27936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane /* and also undo the PASS1_BITS scaling. */ 28036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 28136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane wsptr = workspace; 28236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane for (ctr = 0; ctr < DCTSIZE; ctr++) { 28336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr = output_buf[ctr] + output_col; 28436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane /* Rows of zeroes can be exploited in the same way as we did with columns. 28536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * However, the column calculation has created many nonzero AC terms, so 28636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * the simplification applies less often (typically 5% to 10% of the time). 28736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * On machines with very fast multiplication, it's possible that the 28836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * test takes more time than it's worth. In that case this section 28936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * may be commented out. 29036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */ 291e5eaf37440b8e337ab150c017df7c03faf846c51DRC 29236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#ifndef NO_ZERO_ROW_TEST 2935ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 && 294e5eaf37440b8e337ab150c017df7c03faf846c51DRC wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { 29536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane /* AC terms all zero */ 29636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3) 297e5eaf37440b8e337ab150c017df7c03faf846c51DRC & RANGE_MASK]; 298e5eaf37440b8e337ab150c017df7c03faf846c51DRC 29936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[0] = dcval; 30036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[1] = dcval; 30136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[2] = dcval; 30236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[3] = dcval; 30336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[4] = dcval; 30436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[5] = dcval; 30536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[6] = dcval; 30636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[7] = dcval; 30736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 308e5eaf37440b8e337ab150c017df7c03faf846c51DRC wsptr += DCTSIZE; /* advance pointer to next row */ 30936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane continue; 31036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane } 31136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif 312e5eaf37440b8e337ab150c017df7c03faf846c51DRC 31336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane /* Even part */ 31436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 31536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]); 31636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]); 31736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 31836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]); 31936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562) 320e5eaf37440b8e337ab150c017df7c03faf846c51DRC - tmp13; 32136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 32236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp0 = tmp10 + tmp13; 32336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp3 = tmp10 - tmp13; 32436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp1 = tmp11 + tmp12; 32536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp2 = tmp11 - tmp12; 32636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 32736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane /* Odd part */ 32836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 32936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3]; 33036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3]; 33136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7]; 33236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7]; 33336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 334e5eaf37440b8e337ab150c017df7c03faf846c51DRC tmp7 = z11 + z13; /* phase 5 */ 33536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ 33636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 33736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ 33836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ 33936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ 34036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 341e5eaf37440b8e337ab150c017df7c03faf846c51DRC tmp6 = tmp12 - tmp7; /* phase 2 */ 34236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp5 = tmp11 - tmp6; 34336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane tmp4 = tmp10 + tmp5; 34436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 34536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane /* Final output stage: scale down by a factor of 8 and range-limit */ 34636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 34736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3) 348e5eaf37440b8e337ab150c017df7c03faf846c51DRC & RANGE_MASK]; 34936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3) 350e5eaf37440b8e337ab150c017df7c03faf846c51DRC & RANGE_MASK]; 35136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3) 352e5eaf37440b8e337ab150c017df7c03faf846c51DRC & RANGE_MASK]; 35336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3) 354e5eaf37440b8e337ab150c017df7c03faf846c51DRC & RANGE_MASK]; 35536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3) 356e5eaf37440b8e337ab150c017df7c03faf846c51DRC & RANGE_MASK]; 35736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3) 358e5eaf37440b8e337ab150c017df7c03faf846c51DRC & RANGE_MASK]; 35936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3) 360e5eaf37440b8e337ab150c017df7c03faf846c51DRC & RANGE_MASK]; 36136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3) 362e5eaf37440b8e337ab150c017df7c03faf846c51DRC & RANGE_MASK]; 36336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 364e5eaf37440b8e337ab150c017df7c03faf846c51DRC wsptr += DCTSIZE; /* advance pointer to next row */ 36536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane } 36636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane} 36736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane 36836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif /* DCT_IFAST_SUPPORTED */ 369