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