1e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#if !defined(_FX_JPEG_TURBO_) 2e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov/* 3e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * jidctfst.c 4e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * 5e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * Copyright (C) 1994-1998, Thomas G. Lane. 6e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * This file is part of the Independent JPEG Group's software. 7e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * For conditions of distribution and use, see the accompanying README file. 8e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * 9e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * This file contains a fast, not so accurate integer implementation of the 10e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine 11e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * must also perform dequantization of the input coefficients. 12e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * 13e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT 14e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * on each row (or vice versa, but it's more convenient to emit a row at 15e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * a time). Direct algorithms are also available, but they are much more 16e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * complex and seem not to be any faster when reduced to code. 17e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * 18e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * This implementation is based on Arai, Agui, and Nakajima's algorithm for 19e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in 20e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * Japanese, but the algorithm is described in the Pennebaker & Mitchell 21e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * JPEG textbook (see REFERENCES section in file README). The following code 22e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * is based directly on figure 4-8 in P&M. 23e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * While an 8-point DCT cannot be done in less than 11 multiplies, it is 24e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * possible to arrange the computation so that many of the multiplies are 25e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * simple scalings of the final outputs. These multiplies can then be 26e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * folded into the multiplications or divisions by the JPEG quantization 27e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * table entries. The AA&N method leaves only 5 multiplies and 29 adds 28e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * to be done in the DCT itself. 29e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * The primary disadvantage of this method is that with fixed-point math, 30e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * accuracy is lost due to imprecise representation of the scaled 31e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * quantization values. The smaller the quantization table entry, the less 32e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * precise the scaled value, so this implementation does worse with high- 33e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * quality-setting files than with low-quality ones. 34e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov */ 35e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 36e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define JPEG_INTERNALS 37e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#include "jinclude.h" 38e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#include "jpeglib.h" 39e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#include "jdct.h" /* Private declarations for DCT subsystem */ 40e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 41e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#ifdef DCT_IFAST_SUPPORTED 42e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 43e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 44e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov/* 45e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * This module is specialized to the case DCTSIZE = 8. 46e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov */ 47e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 48e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#if DCTSIZE != 8 49e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ 50e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#endif 51e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 52e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 53e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov/* Scaling decisions are generally the same as in the LL&M algorithm; 54e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * see jidctint.c for more details. However, we choose to descale 55e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * (right shift) multiplication products as soon as they are formed, 56e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * rather than carrying additional fractional bits into subsequent additions. 57e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * This compromises accuracy slightly, but it lets us save a few shifts. 58e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples) 59e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * everywhere except in the multiplications proper; this saves a good deal 60e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * of work on 16-bit-int machines. 61e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * 62e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * The dequantized coefficients are not integers because the AA&N scaling 63e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * factors have been incorporated. We represent them scaled up by PASS1_BITS, 64e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * so that the first and second IDCT rounds have the same input scaling. 65e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to 66e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * avoid a descaling shift; this compromises accuracy rather drastically 67e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * for small quantization table entries, but it saves a lot of shifts. 68e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway, 69e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * so we use a much larger scaling factor to preserve accuracy. 70e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * 71e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * A final compromise is to represent the multiplicative constants to only 72e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * 8 fractional bits, rather than 13. This saves some shifting work on some 73e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * machines, and may also reduce the cost of multiplication (since there 74e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * are fewer one-bits in the constants). 75e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov */ 76e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 77e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#if BITS_IN_JSAMPLE == 8 78e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define CONST_BITS 8 79e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define PASS1_BITS 2 80e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#else 81e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define CONST_BITS 8 82e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ 83e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#endif 84e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 85e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus 86e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * causing a lot of useless floating-point operations at run time. 87e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * To get around this we use the following pre-calculated constants. 88e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * If you change CONST_BITS you may want to add appropriate values. 89e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * (With a reasonable C compiler, you can just rely on the FIX() macro...) 90e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov */ 91e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 92e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#if CONST_BITS == 8 93e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */ 94e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */ 95e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */ 96e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */ 97e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#else 98e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define FIX_1_082392200 FIX(1.082392200) 99e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define FIX_1_414213562 FIX(1.414213562) 100e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define FIX_1_847759065 FIX(1.847759065) 101e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define FIX_2_613125930 FIX(2.613125930) 102e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#endif 103e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 104e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 105e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov/* We can gain a little more speed, with a further compromise in accuracy, 106e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * by omitting the addition in a descaling shift. This yields an incorrectly 107e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * rounded result half the time... 108e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov */ 109e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 110e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#ifndef USE_ACCURATE_ROUNDING 111e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#undef DESCALE 112e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define DESCALE(x,n) RIGHT_SHIFT(x, n) 113e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#endif 114e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 115e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 116e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov/* Multiply a DCTELEM variable by an INT32 constant, and immediately 117e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * descale to yield a DCTELEM result. 118e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov */ 119e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 120e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) 121e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 122e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 123e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov/* Dequantize a coefficient by multiplying it by the multiplier-table 124e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * entry; produce a DCTELEM result. For 8-bit data a 16x16->16 125e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * multiplication will do. For 12-bit data, the multiplier table is 126e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * declared INT32, so a 32-bit multiply will be used. 127e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov */ 128e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 129e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#if BITS_IN_JSAMPLE == 8 130e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval)) 131e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#else 132e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define DEQUANTIZE(coef,quantval) \ 133e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS) 134e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#endif 135e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 136e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 137e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov/* Like DESCALE, but applies to a DCTELEM and produces an int. 138e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * We assume that int right shift is unsigned if INT32 right shift is. 139e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov */ 140e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 141e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#ifdef RIGHT_SHIFT_IS_UNSIGNED 142e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define ISHIFT_TEMPS DCTELEM ishift_temp; 143e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#if BITS_IN_JSAMPLE == 8 144e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */ 145e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#else 146e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define DCTELEMBITS 32 /* DCTELEM must be 32 bits */ 147e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#endif 148e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define IRIGHT_SHIFT(x,shft) \ 149e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov ((ishift_temp = (x)) < 0 ? \ 150e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \ 151e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov (ishift_temp >> (shft))) 152e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#else 153e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define ISHIFT_TEMPS 154e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) 155e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#endif 156e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 157e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#ifdef USE_ACCURATE_ROUNDING 158e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n)) 159e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#else 160e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n)) 161e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#endif 162e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 163e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 164e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov/* 165e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * Perform dequantization and inverse DCT on one block of coefficients. 166e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov */ 167e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 168e6986e1e8d4a57987f47c215490cb080a65ee29aSvet GanovGLOBAL(void) 169e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganovjpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr, 170e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov JCOEFPTR coef_block, 171e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov JSAMPARRAY output_buf, JDIMENSION output_col) 172e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov{ 173e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; 174e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov DCTELEM tmp10, tmp11, tmp12, tmp13; 175e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov DCTELEM z5, z10, z11, z12, z13; 176e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov JCOEFPTR inptr; 177e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov IFAST_MULT_TYPE * quantptr; 178e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov int * wsptr; 179e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov JSAMPROW outptr; 180e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov JSAMPLE *range_limit = IDCT_range_limit(cinfo); 181e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov int ctr; 182e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov int workspace[DCTSIZE2]; /* buffers data between passes */ 183e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov SHIFT_TEMPS /* for DESCALE */ 184e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov ISHIFT_TEMPS /* for IDESCALE */ 185e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 186e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* Pass 1: process columns from input, store into work array. */ 187e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 188e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov inptr = coef_block; 189e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov quantptr = (IFAST_MULT_TYPE *) compptr->dct_table; 190e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr = workspace; 191e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov for (ctr = DCTSIZE; ctr > 0; ctr--) { 192e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* Due to quantization, we will usually find that many of the input 193e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * coefficients are zero, especially the AC terms. We can exploit this 194e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * by short-circuiting the IDCT calculation for any column in which all 195e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * the AC terms are zero. In that case each output is equal to the 196e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * DC coefficient (with scale factor as needed). 197e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * With typical images and quantization tables, half or more of the 198e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * column DCT calculations can be simplified this way. 199e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov */ 200e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 201e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && 202e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && 203e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && 204e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov inptr[DCTSIZE*7] == 0) { 205e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* AC terms all zero */ 206e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 207e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 208e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*0] = dcval; 209e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*1] = dcval; 210e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*2] = dcval; 211e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*3] = dcval; 212e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*4] = dcval; 213e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*5] = dcval; 214e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*6] = dcval; 215e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*7] = dcval; 216e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 217e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov inptr++; /* advance pointers to next column */ 218e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov quantptr++; 219e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr++; 220e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov continue; 221e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov } 222e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 223e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* Even part */ 224e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 225e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 226e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); 227e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); 228e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); 229e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 230e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp10 = tmp0 + tmp2; /* phase 3 */ 231e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp11 = tmp0 - tmp2; 232e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 233e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp13 = tmp1 + tmp3; /* phases 5-3 */ 234e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */ 235e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 236e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp0 = tmp10 + tmp13; /* phase 2 */ 237e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp3 = tmp10 - tmp13; 238e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp1 = tmp11 + tmp12; 239e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp2 = tmp11 - tmp12; 240e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 241e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* Odd part */ 242e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 243e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); 244e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); 245e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); 246e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); 247e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 248e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov z13 = tmp6 + tmp5; /* phase 6 */ 249e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov z10 = tmp6 - tmp5; 250e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov z11 = tmp4 + tmp7; 251e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov z12 = tmp4 - tmp7; 252e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 253e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp7 = z11 + z13; /* phase 5 */ 254e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ 255e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 256e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ 257e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ 258e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ 259e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 260e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp6 = tmp12 - tmp7; /* phase 2 */ 261e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp5 = tmp11 - tmp6; 262e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp4 = tmp10 + tmp5; 263e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 264e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7); 265e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7); 266e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6); 267e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6); 268e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5); 269e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5); 270e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4); 271e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4); 272e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 273e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov inptr++; /* advance pointers to next column */ 274e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov quantptr++; 275e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr++; 276e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov } 277e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 278e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* Pass 2: process rows from work array, store into output array. */ 279e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* Note that we must descale the results by a factor of 8 == 2**3, */ 280e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* and also undo the PASS1_BITS scaling. */ 281e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 282e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr = workspace; 283e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov for (ctr = 0; ctr < DCTSIZE; ctr++) { 284e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr = output_buf[ctr] + output_col; 285e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* Rows of zeroes can be exploited in the same way as we did with columns. 286e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * However, the column calculation has created many nonzero AC terms, so 287e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * the simplification applies less often (typically 5% to 10% of the time). 288e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * On machines with very fast multiplication, it's possible that the 289e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * test takes more time than it's worth. In that case this section 290e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov * may be commented out. 291e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov */ 292e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 293e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#ifndef NO_ZERO_ROW_TEST 294e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 && 295e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { 296e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* AC terms all zero */ 297e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3) 298e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov & RANGE_MASK]; 299e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 300e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[0] = dcval; 301e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[1] = dcval; 302e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[2] = dcval; 303e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[3] = dcval; 304e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[4] = dcval; 305e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[5] = dcval; 306e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[6] = dcval; 307e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[7] = dcval; 308e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 309e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr += DCTSIZE; /* advance pointer to next row */ 310e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov continue; 311e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov } 312e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#endif 313e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 314e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* Even part */ 315e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 316e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]); 317e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]); 318e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 319e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]); 320e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562) 321e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov - tmp13; 322e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 323e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp0 = tmp10 + tmp13; 324e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp3 = tmp10 - tmp13; 325e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp1 = tmp11 + tmp12; 326e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp2 = tmp11 - tmp12; 327e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 328e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* Odd part */ 329e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 330e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3]; 331e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3]; 332e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7]; 333e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7]; 334e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 335e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp7 = z11 + z13; /* phase 5 */ 336e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ 337e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 338e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ 339e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ 340e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ 341e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 342e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp6 = tmp12 - tmp7; /* phase 2 */ 343e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp5 = tmp11 - tmp6; 344e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov tmp4 = tmp10 + tmp5; 345e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 346e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov /* Final output stage: scale down by a factor of 8 and range-limit */ 347e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 348e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3) 349e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov & RANGE_MASK]; 350e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3) 351e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov & RANGE_MASK]; 352e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3) 353e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov & RANGE_MASK]; 354e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3) 355e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov & RANGE_MASK]; 356e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3) 357e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov & RANGE_MASK]; 358e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3) 359e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov & RANGE_MASK]; 360e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3) 361e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov & RANGE_MASK]; 362e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3) 363e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov & RANGE_MASK]; 364e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 365e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov wsptr += DCTSIZE; /* advance pointer to next row */ 366e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov } 367e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov} 368e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 369e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#endif /* DCT_IFAST_SUPPORTED */ 370e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov 371e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#endif //_FX_JPEG_TURBO_ 372