de233ec996ec712ada9f184b3e9a633038a98203
[reactos.git] / dll / 3rdparty / libjpeg / jidctint.c
1 /*
2 * jidctint.c
3 *
4 * Copyright (C) 1991-1998, Thomas G. Lane.
5 * Modification developed 2002-2015 by Guido Vollbeding.
6 * This file is part of the Independent JPEG Group's software.
7 * For conditions of distribution and use, see the accompanying README file.
8 *
9 * This file contains a slow-but-accurate integer implementation of the
10 * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
11 * must also perform dequantization of the input coefficients.
12 *
13 * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
14 * on each row (or vice versa, but it's more convenient to emit a row at
15 * a time). Direct algorithms are also available, but they are much more
16 * complex and seem not to be any faster when reduced to code.
17 *
18 * This implementation is based on an algorithm described in
19 * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
20 * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
21 * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
22 * The primary algorithm described there uses 11 multiplies and 29 adds.
23 * We use their alternate method with 12 multiplies and 32 adds.
24 * The advantage of this method is that no data path contains more than one
25 * multiplication; this allows a very simple and accurate implementation in
26 * scaled fixed-point arithmetic, with a minimal number of shifts.
27 *
28 * We also provide IDCT routines with various output sample block sizes for
29 * direct resolution reduction or enlargement and for direct resolving the
30 * common 2x1 and 1x2 subsampling cases without additional resampling: NxN
31 * (N=1...16), 2NxN, and Nx2N (N=1...8) pixels for one 8x8 input DCT block.
32 *
33 * For N<8 we simply take the corresponding low-frequency coefficients of
34 * the 8x8 input DCT block and apply an NxN point IDCT on the sub-block
35 * to yield the downscaled outputs.
36 * This can be seen as direct low-pass downsampling from the DCT domain
37 * point of view rather than the usual spatial domain point of view,
38 * yielding significant computational savings and results at least
39 * as good as common bilinear (averaging) spatial downsampling.
40 *
41 * For N>8 we apply a partial NxN IDCT on the 8 input coefficients as
42 * lower frequencies and higher frequencies assumed to be zero.
43 * It turns out that the computational effort is similar to the 8x8 IDCT
44 * regarding the output size.
45 * Furthermore, the scaling and descaling is the same for all IDCT sizes.
46 *
47 * CAUTION: We rely on the FIX() macro except for the N=1,2,4,8 cases
48 * since there would be too many additional constants to pre-calculate.
49 */
50
51 #define JPEG_INTERNALS
52 #include "jinclude.h"
53 #include "jpeglib.h"
54 #include "jdct.h" /* Private declarations for DCT subsystem */
55
56 #ifdef DCT_ISLOW_SUPPORTED
57
58
59 /*
60 * This module is specialized to the case DCTSIZE = 8.
61 */
62
63 #if DCTSIZE != 8
64 Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */
65 #endif
66
67
68 /*
69 * The poop on this scaling stuff is as follows:
70 *
71 * Each 1-D IDCT step produces outputs which are a factor of sqrt(N)
72 * larger than the true IDCT outputs. The final outputs are therefore
73 * a factor of N larger than desired; since N=8 this can be cured by
74 * a simple right shift at the end of the algorithm. The advantage of
75 * this arrangement is that we save two multiplications per 1-D IDCT,
76 * because the y0 and y4 inputs need not be divided by sqrt(N).
77 *
78 * We have to do addition and subtraction of the integer inputs, which
79 * is no problem, and multiplication by fractional constants, which is
80 * a problem to do in integer arithmetic. We multiply all the constants
81 * by CONST_SCALE and convert them to integer constants (thus retaining
82 * CONST_BITS bits of precision in the constants). After doing a
83 * multiplication we have to divide the product by CONST_SCALE, with proper
84 * rounding, to produce the correct output. This division can be done
85 * cheaply as a right shift of CONST_BITS bits. We postpone shifting
86 * as long as possible so that partial sums can be added together with
87 * full fractional precision.
88 *
89 * The outputs of the first pass are scaled up by PASS1_BITS bits so that
90 * they are represented to better-than-integral precision. These outputs
91 * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
92 * with the recommended scaling. (To scale up 12-bit sample data further, an
93 * intermediate INT32 array would be needed.)
94 *
95 * To avoid overflow of the 32-bit intermediate results in pass 2, we must
96 * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
97 * shows that the values given below are the most effective.
98 */
99
100 #if BITS_IN_JSAMPLE == 8
101 #define CONST_BITS 13
102 #define PASS1_BITS 2
103 #else
104 #define CONST_BITS 13
105 #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
106 #endif
107
108 /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
109 * causing a lot of useless floating-point operations at run time.
110 * To get around this we use the following pre-calculated constants.
111 * If you change CONST_BITS you may want to add appropriate values.
112 * (With a reasonable C compiler, you can just rely on the FIX() macro...)
113 */
114
115 #if CONST_BITS == 13
116 #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
117 #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
118 #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
119 #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
120 #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
121 #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
122 #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
123 #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
124 #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
125 #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
126 #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
127 #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
128 #else
129 #define FIX_0_298631336 FIX(0.298631336)
130 #define FIX_0_390180644 FIX(0.390180644)
131 #define FIX_0_541196100 FIX(0.541196100)
132 #define FIX_0_765366865 FIX(0.765366865)
133 #define FIX_0_899976223 FIX(0.899976223)
134 #define FIX_1_175875602 FIX(1.175875602)
135 #define FIX_1_501321110 FIX(1.501321110)
136 #define FIX_1_847759065 FIX(1.847759065)
137 #define FIX_1_961570560 FIX(1.961570560)
138 #define FIX_2_053119869 FIX(2.053119869)
139 #define FIX_2_562915447 FIX(2.562915447)
140 #define FIX_3_072711026 FIX(3.072711026)
141 #endif
142
143
144 /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
145 * For 8-bit samples with the recommended scaling, all the variable
146 * and constant values involved are no more than 16 bits wide, so a
147 * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
148 * For 12-bit samples, a full 32-bit multiplication will be needed.
149 */
150
151 #if BITS_IN_JSAMPLE == 8
152 #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
153 #else
154 #define MULTIPLY(var,const) ((var) * (const))
155 #endif
156
157
158 /* Dequantize a coefficient by multiplying it by the multiplier-table
159 * entry; produce an int result. In this module, both inputs and result
160 * are 16 bits or less, so either int or short multiply will work.
161 */
162
163 #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
164
165
166 /*
167 * Perform dequantization and inverse DCT on one block of coefficients.
168 *
169 * cK represents sqrt(2) * cos(K*pi/16).
170 */
171
172 GLOBAL(void)
173 jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
174 JCOEFPTR coef_block,
175 JSAMPARRAY output_buf, JDIMENSION output_col)
176 {
177 INT32 tmp0, tmp1, tmp2, tmp3;
178 INT32 tmp10, tmp11, tmp12, tmp13;
179 INT32 z1, z2, z3;
180 JCOEFPTR inptr;
181 ISLOW_MULT_TYPE * quantptr;
182 int * wsptr;
183 JSAMPROW outptr;
184 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
185 int ctr;
186 int workspace[DCTSIZE2]; /* buffers data between passes */
187 SHIFT_TEMPS
188
189 /* Pass 1: process columns from input, store into work array.
190 * Note results are scaled up by sqrt(8) compared to a true IDCT;
191 * furthermore, we scale the results by 2**PASS1_BITS.
192 */
193
194 inptr = coef_block;
195 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
196 wsptr = workspace;
197 for (ctr = DCTSIZE; ctr > 0; ctr--) {
198 /* Due to quantization, we will usually find that many of the input
199 * coefficients are zero, especially the AC terms. We can exploit this
200 * by short-circuiting the IDCT calculation for any column in which all
201 * the AC terms are zero. In that case each output is equal to the
202 * DC coefficient (with scale factor as needed).
203 * With typical images and quantization tables, half or more of the
204 * column DCT calculations can be simplified this way.
205 */
206
207 if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
208 inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
209 inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
210 inptr[DCTSIZE*7] == 0) {
211 /* AC terms all zero */
212 int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
213
214 wsptr[DCTSIZE*0] = dcval;
215 wsptr[DCTSIZE*1] = dcval;
216 wsptr[DCTSIZE*2] = dcval;
217 wsptr[DCTSIZE*3] = dcval;
218 wsptr[DCTSIZE*4] = dcval;
219 wsptr[DCTSIZE*5] = dcval;
220 wsptr[DCTSIZE*6] = dcval;
221 wsptr[DCTSIZE*7] = dcval;
222
223 inptr++; /* advance pointers to next column */
224 quantptr++;
225 wsptr++;
226 continue;
227 }
228
229 /* Even part: reverse the even part of the forward DCT.
230 * The rotator is c(-6).
231 */
232
233 z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
234 z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
235 z2 <<= CONST_BITS;
236 z3 <<= CONST_BITS;
237 /* Add fudge factor here for final descale. */
238 z2 += ONE << (CONST_BITS-PASS1_BITS-1);
239
240 tmp0 = z2 + z3;
241 tmp1 = z2 - z3;
242
243 z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
244 z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
245
246 z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
247 tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
248 tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
249
250 tmp10 = tmp0 + tmp2;
251 tmp13 = tmp0 - tmp2;
252 tmp11 = tmp1 + tmp3;
253 tmp12 = tmp1 - tmp3;
254
255 /* Odd part per figure 8; the matrix is unitary and hence its
256 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
257 */
258
259 tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
260 tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
261 tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
262 tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
263
264 z2 = tmp0 + tmp2;
265 z3 = tmp1 + tmp3;
266
267 z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* c3 */
268 z2 = MULTIPLY(z2, - FIX_1_961570560); /* -c3-c5 */
269 z3 = MULTIPLY(z3, - FIX_0_390180644); /* -c3+c5 */
270 z2 += z1;
271 z3 += z1;
272
273 z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
274 tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* -c1+c3+c5-c7 */
275 tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* c1+c3-c5-c7 */
276 tmp0 += z1 + z2;
277 tmp3 += z1 + z3;
278
279 z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
280 tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* c1+c3-c5+c7 */
281 tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* c1+c3+c5-c7 */
282 tmp1 += z1 + z3;
283 tmp2 += z1 + z2;
284
285 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
286
287 wsptr[DCTSIZE*0] = (int) RIGHT_SHIFT(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
288 wsptr[DCTSIZE*7] = (int) RIGHT_SHIFT(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
289 wsptr[DCTSIZE*1] = (int) RIGHT_SHIFT(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
290 wsptr[DCTSIZE*6] = (int) RIGHT_SHIFT(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
291 wsptr[DCTSIZE*2] = (int) RIGHT_SHIFT(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
292 wsptr[DCTSIZE*5] = (int) RIGHT_SHIFT(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
293 wsptr[DCTSIZE*3] = (int) RIGHT_SHIFT(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
294 wsptr[DCTSIZE*4] = (int) RIGHT_SHIFT(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
295
296 inptr++; /* advance pointers to next column */
297 quantptr++;
298 wsptr++;
299 }
300
301 /* Pass 2: process rows from work array, store into output array.
302 * Note that we must descale the results by a factor of 8 == 2**3,
303 * and also undo the PASS1_BITS scaling.
304 */
305
306 wsptr = workspace;
307 for (ctr = 0; ctr < DCTSIZE; ctr++) {
308 outptr = output_buf[ctr] + output_col;
309
310 /* Add range center and fudge factor for final descale and range-limit. */
311 z2 = (INT32) wsptr[0] +
312 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
313 (ONE << (PASS1_BITS+2)));
314
315 /* Rows of zeroes can be exploited in the same way as we did with columns.
316 * However, the column calculation has created many nonzero AC terms, so
317 * the simplification applies less often (typically 5% to 10% of the time).
318 * On machines with very fast multiplication, it's possible that the
319 * test takes more time than it's worth. In that case this section
320 * may be commented out.
321 */
322
323 #ifndef NO_ZERO_ROW_TEST
324 if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
325 wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
326 /* AC terms all zero */
327 JSAMPLE dcval = range_limit[(int) RIGHT_SHIFT(z2, PASS1_BITS+3)
328 & RANGE_MASK];
329
330 outptr[0] = dcval;
331 outptr[1] = dcval;
332 outptr[2] = dcval;
333 outptr[3] = dcval;
334 outptr[4] = dcval;
335 outptr[5] = dcval;
336 outptr[6] = dcval;
337 outptr[7] = dcval;
338
339 wsptr += DCTSIZE; /* advance pointer to next row */
340 continue;
341 }
342 #endif
343
344 /* Even part: reverse the even part of the forward DCT.
345 * The rotator is c(-6).
346 */
347
348 z3 = (INT32) wsptr[4];
349
350 tmp0 = (z2 + z3) << CONST_BITS;
351 tmp1 = (z2 - z3) << CONST_BITS;
352
353 z2 = (INT32) wsptr[2];
354 z3 = (INT32) wsptr[6];
355
356 z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
357 tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
358 tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
359
360 tmp10 = tmp0 + tmp2;
361 tmp13 = tmp0 - tmp2;
362 tmp11 = tmp1 + tmp3;
363 tmp12 = tmp1 - tmp3;
364
365 /* Odd part per figure 8; the matrix is unitary and hence its
366 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
367 */
368
369 tmp0 = (INT32) wsptr[7];
370 tmp1 = (INT32) wsptr[5];
371 tmp2 = (INT32) wsptr[3];
372 tmp3 = (INT32) wsptr[1];
373
374 z2 = tmp0 + tmp2;
375 z3 = tmp1 + tmp3;
376
377 z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* c3 */
378 z2 = MULTIPLY(z2, - FIX_1_961570560); /* -c3-c5 */
379 z3 = MULTIPLY(z3, - FIX_0_390180644); /* -c3+c5 */
380 z2 += z1;
381 z3 += z1;
382
383 z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
384 tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* -c1+c3+c5-c7 */
385 tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* c1+c3-c5-c7 */
386 tmp0 += z1 + z2;
387 tmp3 += z1 + z3;
388
389 z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
390 tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* c1+c3-c5+c7 */
391 tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* c1+c3+c5-c7 */
392 tmp1 += z1 + z3;
393 tmp2 += z1 + z2;
394
395 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
396
397 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp3,
398 CONST_BITS+PASS1_BITS+3)
399 & RANGE_MASK];
400 outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp3,
401 CONST_BITS+PASS1_BITS+3)
402 & RANGE_MASK];
403 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp2,
404 CONST_BITS+PASS1_BITS+3)
405 & RANGE_MASK];
406 outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp2,
407 CONST_BITS+PASS1_BITS+3)
408 & RANGE_MASK];
409 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp1,
410 CONST_BITS+PASS1_BITS+3)
411 & RANGE_MASK];
412 outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp1,
413 CONST_BITS+PASS1_BITS+3)
414 & RANGE_MASK];
415 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp13 + tmp0,
416 CONST_BITS+PASS1_BITS+3)
417 & RANGE_MASK];
418 outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp13 - tmp0,
419 CONST_BITS+PASS1_BITS+3)
420 & RANGE_MASK];
421
422 wsptr += DCTSIZE; /* advance pointer to next row */
423 }
424 }
425
426 #ifdef IDCT_SCALING_SUPPORTED
427
428
429 /*
430 * Perform dequantization and inverse DCT on one block of coefficients,
431 * producing a 7x7 output block.
432 *
433 * Optimized algorithm with 12 multiplications in the 1-D kernel.
434 * cK represents sqrt(2) * cos(K*pi/14).
435 */
436
437 GLOBAL(void)
438 jpeg_idct_7x7 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
439 JCOEFPTR coef_block,
440 JSAMPARRAY output_buf, JDIMENSION output_col)
441 {
442 INT32 tmp0, tmp1, tmp2, tmp10, tmp11, tmp12, tmp13;
443 INT32 z1, z2, z3;
444 JCOEFPTR inptr;
445 ISLOW_MULT_TYPE * quantptr;
446 int * wsptr;
447 JSAMPROW outptr;
448 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
449 int ctr;
450 int workspace[7*7]; /* buffers data between passes */
451 SHIFT_TEMPS
452
453 /* Pass 1: process columns from input, store into work array. */
454
455 inptr = coef_block;
456 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
457 wsptr = workspace;
458 for (ctr = 0; ctr < 7; ctr++, inptr++, quantptr++, wsptr++) {
459 /* Even part */
460
461 tmp13 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
462 tmp13 <<= CONST_BITS;
463 /* Add fudge factor here for final descale. */
464 tmp13 += ONE << (CONST_BITS-PASS1_BITS-1);
465
466 z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
467 z2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
468 z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
469
470 tmp10 = MULTIPLY(z2 - z3, FIX(0.881747734)); /* c4 */
471 tmp12 = MULTIPLY(z1 - z2, FIX(0.314692123)); /* c6 */
472 tmp11 = tmp10 + tmp12 + tmp13 - MULTIPLY(z2, FIX(1.841218003)); /* c2+c4-c6 */
473 tmp0 = z1 + z3;
474 z2 -= tmp0;
475 tmp0 = MULTIPLY(tmp0, FIX(1.274162392)) + tmp13; /* c2 */
476 tmp10 += tmp0 - MULTIPLY(z3, FIX(0.077722536)); /* c2-c4-c6 */
477 tmp12 += tmp0 - MULTIPLY(z1, FIX(2.470602249)); /* c2+c4+c6 */
478 tmp13 += MULTIPLY(z2, FIX(1.414213562)); /* c0 */
479
480 /* Odd part */
481
482 z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
483 z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
484 z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
485
486 tmp1 = MULTIPLY(z1 + z2, FIX(0.935414347)); /* (c3+c1-c5)/2 */
487 tmp2 = MULTIPLY(z1 - z2, FIX(0.170262339)); /* (c3+c5-c1)/2 */
488 tmp0 = tmp1 - tmp2;
489 tmp1 += tmp2;
490 tmp2 = MULTIPLY(z2 + z3, - FIX(1.378756276)); /* -c1 */
491 tmp1 += tmp2;
492 z2 = MULTIPLY(z1 + z3, FIX(0.613604268)); /* c5 */
493 tmp0 += z2;
494 tmp2 += z2 + MULTIPLY(z3, FIX(1.870828693)); /* c3+c1-c5 */
495
496 /* Final output stage */
497
498 wsptr[7*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);
499 wsptr[7*6] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);
500 wsptr[7*1] = (int) RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS-PASS1_BITS);
501 wsptr[7*5] = (int) RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS-PASS1_BITS);
502 wsptr[7*2] = (int) RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS-PASS1_BITS);
503 wsptr[7*4] = (int) RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS-PASS1_BITS);
504 wsptr[7*3] = (int) RIGHT_SHIFT(tmp13, CONST_BITS-PASS1_BITS);
505 }
506
507 /* Pass 2: process 7 rows from work array, store into output array. */
508
509 wsptr = workspace;
510 for (ctr = 0; ctr < 7; ctr++) {
511 outptr = output_buf[ctr] + output_col;
512
513 /* Even part */
514
515 /* Add range center and fudge factor for final descale and range-limit. */
516 tmp13 = (INT32) wsptr[0] +
517 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
518 (ONE << (PASS1_BITS+2)));
519 tmp13 <<= CONST_BITS;
520
521 z1 = (INT32) wsptr[2];
522 z2 = (INT32) wsptr[4];
523 z3 = (INT32) wsptr[6];
524
525 tmp10 = MULTIPLY(z2 - z3, FIX(0.881747734)); /* c4 */
526 tmp12 = MULTIPLY(z1 - z2, FIX(0.314692123)); /* c6 */
527 tmp11 = tmp10 + tmp12 + tmp13 - MULTIPLY(z2, FIX(1.841218003)); /* c2+c4-c6 */
528 tmp0 = z1 + z3;
529 z2 -= tmp0;
530 tmp0 = MULTIPLY(tmp0, FIX(1.274162392)) + tmp13; /* c2 */
531 tmp10 += tmp0 - MULTIPLY(z3, FIX(0.077722536)); /* c2-c4-c6 */
532 tmp12 += tmp0 - MULTIPLY(z1, FIX(2.470602249)); /* c2+c4+c6 */
533 tmp13 += MULTIPLY(z2, FIX(1.414213562)); /* c0 */
534
535 /* Odd part */
536
537 z1 = (INT32) wsptr[1];
538 z2 = (INT32) wsptr[3];
539 z3 = (INT32) wsptr[5];
540
541 tmp1 = MULTIPLY(z1 + z2, FIX(0.935414347)); /* (c3+c1-c5)/2 */
542 tmp2 = MULTIPLY(z1 - z2, FIX(0.170262339)); /* (c3+c5-c1)/2 */
543 tmp0 = tmp1 - tmp2;
544 tmp1 += tmp2;
545 tmp2 = MULTIPLY(z2 + z3, - FIX(1.378756276)); /* -c1 */
546 tmp1 += tmp2;
547 z2 = MULTIPLY(z1 + z3, FIX(0.613604268)); /* c5 */
548 tmp0 += z2;
549 tmp2 += z2 + MULTIPLY(z3, FIX(1.870828693)); /* c3+c1-c5 */
550
551 /* Final output stage */
552
553 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,
554 CONST_BITS+PASS1_BITS+3)
555 & RANGE_MASK];
556 outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,
557 CONST_BITS+PASS1_BITS+3)
558 & RANGE_MASK];
559 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1,
560 CONST_BITS+PASS1_BITS+3)
561 & RANGE_MASK];
562 outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1,
563 CONST_BITS+PASS1_BITS+3)
564 & RANGE_MASK];
565 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,
566 CONST_BITS+PASS1_BITS+3)
567 & RANGE_MASK];
568 outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,
569 CONST_BITS+PASS1_BITS+3)
570 & RANGE_MASK];
571 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp13,
572 CONST_BITS+PASS1_BITS+3)
573 & RANGE_MASK];
574
575 wsptr += 7; /* advance pointer to next row */
576 }
577 }
578
579
580 /*
581 * Perform dequantization and inverse DCT on one block of coefficients,
582 * producing a reduced-size 6x6 output block.
583 *
584 * Optimized algorithm with 3 multiplications in the 1-D kernel.
585 * cK represents sqrt(2) * cos(K*pi/12).
586 */
587
588 GLOBAL(void)
589 jpeg_idct_6x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
590 JCOEFPTR coef_block,
591 JSAMPARRAY output_buf, JDIMENSION output_col)
592 {
593 INT32 tmp0, tmp1, tmp2, tmp10, tmp11, tmp12;
594 INT32 z1, z2, z3;
595 JCOEFPTR inptr;
596 ISLOW_MULT_TYPE * quantptr;
597 int * wsptr;
598 JSAMPROW outptr;
599 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
600 int ctr;
601 int workspace[6*6]; /* buffers data between passes */
602 SHIFT_TEMPS
603
604 /* Pass 1: process columns from input, store into work array. */
605
606 inptr = coef_block;
607 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
608 wsptr = workspace;
609 for (ctr = 0; ctr < 6; ctr++, inptr++, quantptr++, wsptr++) {
610 /* Even part */
611
612 tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
613 tmp0 <<= CONST_BITS;
614 /* Add fudge factor here for final descale. */
615 tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);
616 tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
617 tmp10 = MULTIPLY(tmp2, FIX(0.707106781)); /* c4 */
618 tmp1 = tmp0 + tmp10;
619 tmp11 = RIGHT_SHIFT(tmp0 - tmp10 - tmp10, CONST_BITS-PASS1_BITS);
620 tmp10 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
621 tmp0 = MULTIPLY(tmp10, FIX(1.224744871)); /* c2 */
622 tmp10 = tmp1 + tmp0;
623 tmp12 = tmp1 - tmp0;
624
625 /* Odd part */
626
627 z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
628 z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
629 z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
630 tmp1 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */
631 tmp0 = tmp1 + ((z1 + z2) << CONST_BITS);
632 tmp2 = tmp1 + ((z3 - z2) << CONST_BITS);
633 tmp1 = (z1 - z2 - z3) << PASS1_BITS;
634
635 /* Final output stage */
636
637 wsptr[6*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);
638 wsptr[6*5] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);
639 wsptr[6*1] = (int) (tmp11 + tmp1);
640 wsptr[6*4] = (int) (tmp11 - tmp1);
641 wsptr[6*2] = (int) RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS-PASS1_BITS);
642 wsptr[6*3] = (int) RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS-PASS1_BITS);
643 }
644
645 /* Pass 2: process 6 rows from work array, store into output array. */
646
647 wsptr = workspace;
648 for (ctr = 0; ctr < 6; ctr++) {
649 outptr = output_buf[ctr] + output_col;
650
651 /* Even part */
652
653 /* Add range center and fudge factor for final descale and range-limit. */
654 tmp0 = (INT32) wsptr[0] +
655 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
656 (ONE << (PASS1_BITS+2)));
657 tmp0 <<= CONST_BITS;
658 tmp2 = (INT32) wsptr[4];
659 tmp10 = MULTIPLY(tmp2, FIX(0.707106781)); /* c4 */
660 tmp1 = tmp0 + tmp10;
661 tmp11 = tmp0 - tmp10 - tmp10;
662 tmp10 = (INT32) wsptr[2];
663 tmp0 = MULTIPLY(tmp10, FIX(1.224744871)); /* c2 */
664 tmp10 = tmp1 + tmp0;
665 tmp12 = tmp1 - tmp0;
666
667 /* Odd part */
668
669 z1 = (INT32) wsptr[1];
670 z2 = (INT32) wsptr[3];
671 z3 = (INT32) wsptr[5];
672 tmp1 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */
673 tmp0 = tmp1 + ((z1 + z2) << CONST_BITS);
674 tmp2 = tmp1 + ((z3 - z2) << CONST_BITS);
675 tmp1 = (z1 - z2 - z3) << CONST_BITS;
676
677 /* Final output stage */
678
679 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,
680 CONST_BITS+PASS1_BITS+3)
681 & RANGE_MASK];
682 outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,
683 CONST_BITS+PASS1_BITS+3)
684 & RANGE_MASK];
685 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1,
686 CONST_BITS+PASS1_BITS+3)
687 & RANGE_MASK];
688 outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1,
689 CONST_BITS+PASS1_BITS+3)
690 & RANGE_MASK];
691 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,
692 CONST_BITS+PASS1_BITS+3)
693 & RANGE_MASK];
694 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,
695 CONST_BITS+PASS1_BITS+3)
696 & RANGE_MASK];
697
698 wsptr += 6; /* advance pointer to next row */
699 }
700 }
701
702
703 /*
704 * Perform dequantization and inverse DCT on one block of coefficients,
705 * producing a reduced-size 5x5 output block.
706 *
707 * Optimized algorithm with 5 multiplications in the 1-D kernel.
708 * cK represents sqrt(2) * cos(K*pi/10).
709 */
710
711 GLOBAL(void)
712 jpeg_idct_5x5 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
713 JCOEFPTR coef_block,
714 JSAMPARRAY output_buf, JDIMENSION output_col)
715 {
716 INT32 tmp0, tmp1, tmp10, tmp11, tmp12;
717 INT32 z1, z2, z3;
718 JCOEFPTR inptr;
719 ISLOW_MULT_TYPE * quantptr;
720 int * wsptr;
721 JSAMPROW outptr;
722 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
723 int ctr;
724 int workspace[5*5]; /* buffers data between passes */
725 SHIFT_TEMPS
726
727 /* Pass 1: process columns from input, store into work array. */
728
729 inptr = coef_block;
730 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
731 wsptr = workspace;
732 for (ctr = 0; ctr < 5; ctr++, inptr++, quantptr++, wsptr++) {
733 /* Even part */
734
735 tmp12 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
736 tmp12 <<= CONST_BITS;
737 /* Add fudge factor here for final descale. */
738 tmp12 += ONE << (CONST_BITS-PASS1_BITS-1);
739 tmp0 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
740 tmp1 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
741 z1 = MULTIPLY(tmp0 + tmp1, FIX(0.790569415)); /* (c2+c4)/2 */
742 z2 = MULTIPLY(tmp0 - tmp1, FIX(0.353553391)); /* (c2-c4)/2 */
743 z3 = tmp12 + z2;
744 tmp10 = z3 + z1;
745 tmp11 = z3 - z1;
746 tmp12 -= z2 << 2;
747
748 /* Odd part */
749
750 z2 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
751 z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
752
753 z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c3 */
754 tmp0 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c1-c3 */
755 tmp1 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c1+c3 */
756
757 /* Final output stage */
758
759 wsptr[5*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);
760 wsptr[5*4] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);
761 wsptr[5*1] = (int) RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS-PASS1_BITS);
762 wsptr[5*3] = (int) RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS-PASS1_BITS);
763 wsptr[5*2] = (int) RIGHT_SHIFT(tmp12, CONST_BITS-PASS1_BITS);
764 }
765
766 /* Pass 2: process 5 rows from work array, store into output array. */
767
768 wsptr = workspace;
769 for (ctr = 0; ctr < 5; ctr++) {
770 outptr = output_buf[ctr] + output_col;
771
772 /* Even part */
773
774 /* Add range center and fudge factor for final descale and range-limit. */
775 tmp12 = (INT32) wsptr[0] +
776 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
777 (ONE << (PASS1_BITS+2)));
778 tmp12 <<= CONST_BITS;
779 tmp0 = (INT32) wsptr[2];
780 tmp1 = (INT32) wsptr[4];
781 z1 = MULTIPLY(tmp0 + tmp1, FIX(0.790569415)); /* (c2+c4)/2 */
782 z2 = MULTIPLY(tmp0 - tmp1, FIX(0.353553391)); /* (c2-c4)/2 */
783 z3 = tmp12 + z2;
784 tmp10 = z3 + z1;
785 tmp11 = z3 - z1;
786 tmp12 -= z2 << 2;
787
788 /* Odd part */
789
790 z2 = (INT32) wsptr[1];
791 z3 = (INT32) wsptr[3];
792
793 z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c3 */
794 tmp0 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c1-c3 */
795 tmp1 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c1+c3 */
796
797 /* Final output stage */
798
799 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,
800 CONST_BITS+PASS1_BITS+3)
801 & RANGE_MASK];
802 outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,
803 CONST_BITS+PASS1_BITS+3)
804 & RANGE_MASK];
805 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1,
806 CONST_BITS+PASS1_BITS+3)
807 & RANGE_MASK];
808 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1,
809 CONST_BITS+PASS1_BITS+3)
810 & RANGE_MASK];
811 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12,
812 CONST_BITS+PASS1_BITS+3)
813 & RANGE_MASK];
814
815 wsptr += 5; /* advance pointer to next row */
816 }
817 }
818
819
820 /*
821 * Perform dequantization and inverse DCT on one block of coefficients,
822 * producing a reduced-size 4x4 output block.
823 *
824 * Optimized algorithm with 3 multiplications in the 1-D kernel.
825 * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point IDCT].
826 */
827
828 GLOBAL(void)
829 jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
830 JCOEFPTR coef_block,
831 JSAMPARRAY output_buf, JDIMENSION output_col)
832 {
833 INT32 tmp0, tmp2, tmp10, tmp12;
834 INT32 z1, z2, z3;
835 JCOEFPTR inptr;
836 ISLOW_MULT_TYPE * quantptr;
837 int * wsptr;
838 JSAMPROW outptr;
839 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
840 int ctr;
841 int workspace[4*4]; /* buffers data between passes */
842 SHIFT_TEMPS
843
844 /* Pass 1: process columns from input, store into work array. */
845
846 inptr = coef_block;
847 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
848 wsptr = workspace;
849 for (ctr = 0; ctr < 4; ctr++, inptr++, quantptr++, wsptr++) {
850 /* Even part */
851
852 tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
853 tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
854
855 tmp10 = (tmp0 + tmp2) << PASS1_BITS;
856 tmp12 = (tmp0 - tmp2) << PASS1_BITS;
857
858 /* Odd part */
859 /* Same rotation as in the even part of the 8x8 LL&M IDCT */
860
861 z2 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
862 z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
863
864 z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
865 /* Add fudge factor here for final descale. */
866 z1 += ONE << (CONST_BITS-PASS1_BITS-1);
867 tmp0 = RIGHT_SHIFT(z1 + MULTIPLY(z2, FIX_0_765366865), /* c2-c6 */
868 CONST_BITS-PASS1_BITS);
869 tmp2 = RIGHT_SHIFT(z1 - MULTIPLY(z3, FIX_1_847759065), /* c2+c6 */
870 CONST_BITS-PASS1_BITS);
871
872 /* Final output stage */
873
874 wsptr[4*0] = (int) (tmp10 + tmp0);
875 wsptr[4*3] = (int) (tmp10 - tmp0);
876 wsptr[4*1] = (int) (tmp12 + tmp2);
877 wsptr[4*2] = (int) (tmp12 - tmp2);
878 }
879
880 /* Pass 2: process 4 rows from work array, store into output array. */
881
882 wsptr = workspace;
883 for (ctr = 0; ctr < 4; ctr++) {
884 outptr = output_buf[ctr] + output_col;
885
886 /* Even part */
887
888 /* Add range center and fudge factor for final descale and range-limit. */
889 tmp0 = (INT32) wsptr[0] +
890 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
891 (ONE << (PASS1_BITS+2)));
892 tmp2 = (INT32) wsptr[2];
893
894 tmp10 = (tmp0 + tmp2) << CONST_BITS;
895 tmp12 = (tmp0 - tmp2) << CONST_BITS;
896
897 /* Odd part */
898 /* Same rotation as in the even part of the 8x8 LL&M IDCT */
899
900 z2 = (INT32) wsptr[1];
901 z3 = (INT32) wsptr[3];
902
903 z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
904 tmp0 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
905 tmp2 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
906
907 /* Final output stage */
908
909 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,
910 CONST_BITS+PASS1_BITS+3)
911 & RANGE_MASK];
912 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,
913 CONST_BITS+PASS1_BITS+3)
914 & RANGE_MASK];
915 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,
916 CONST_BITS+PASS1_BITS+3)
917 & RANGE_MASK];
918 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,
919 CONST_BITS+PASS1_BITS+3)
920 & RANGE_MASK];
921
922 wsptr += 4; /* advance pointer to next row */
923 }
924 }
925
926
927 /*
928 * Perform dequantization and inverse DCT on one block of coefficients,
929 * producing a reduced-size 3x3 output block.
930 *
931 * Optimized algorithm with 2 multiplications in the 1-D kernel.
932 * cK represents sqrt(2) * cos(K*pi/6).
933 */
934
935 GLOBAL(void)
936 jpeg_idct_3x3 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
937 JCOEFPTR coef_block,
938 JSAMPARRAY output_buf, JDIMENSION output_col)
939 {
940 INT32 tmp0, tmp2, tmp10, tmp12;
941 JCOEFPTR inptr;
942 ISLOW_MULT_TYPE * quantptr;
943 int * wsptr;
944 JSAMPROW outptr;
945 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
946 int ctr;
947 int workspace[3*3]; /* buffers data between passes */
948 SHIFT_TEMPS
949
950 /* Pass 1: process columns from input, store into work array. */
951
952 inptr = coef_block;
953 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
954 wsptr = workspace;
955 for (ctr = 0; ctr < 3; ctr++, inptr++, quantptr++, wsptr++) {
956 /* Even part */
957
958 tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
959 tmp0 <<= CONST_BITS;
960 /* Add fudge factor here for final descale. */
961 tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);
962 tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
963 tmp12 = MULTIPLY(tmp2, FIX(0.707106781)); /* c2 */
964 tmp10 = tmp0 + tmp12;
965 tmp2 = tmp0 - tmp12 - tmp12;
966
967 /* Odd part */
968
969 tmp12 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
970 tmp0 = MULTIPLY(tmp12, FIX(1.224744871)); /* c1 */
971
972 /* Final output stage */
973
974 wsptr[3*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);
975 wsptr[3*2] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);
976 wsptr[3*1] = (int) RIGHT_SHIFT(tmp2, CONST_BITS-PASS1_BITS);
977 }
978
979 /* Pass 2: process 3 rows from work array, store into output array. */
980
981 wsptr = workspace;
982 for (ctr = 0; ctr < 3; ctr++) {
983 outptr = output_buf[ctr] + output_col;
984
985 /* Even part */
986
987 /* Add range center and fudge factor for final descale and range-limit. */
988 tmp0 = (INT32) wsptr[0] +
989 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
990 (ONE << (PASS1_BITS+2)));
991 tmp0 <<= CONST_BITS;
992 tmp2 = (INT32) wsptr[2];
993 tmp12 = MULTIPLY(tmp2, FIX(0.707106781)); /* c2 */
994 tmp10 = tmp0 + tmp12;
995 tmp2 = tmp0 - tmp12 - tmp12;
996
997 /* Odd part */
998
999 tmp12 = (INT32) wsptr[1];
1000 tmp0 = MULTIPLY(tmp12, FIX(1.224744871)); /* c1 */
1001
1002 /* Final output stage */
1003
1004 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,
1005 CONST_BITS+PASS1_BITS+3)
1006 & RANGE_MASK];
1007 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,
1008 CONST_BITS+PASS1_BITS+3)
1009 & RANGE_MASK];
1010 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp2,
1011 CONST_BITS+PASS1_BITS+3)
1012 & RANGE_MASK];
1013
1014 wsptr += 3; /* advance pointer to next row */
1015 }
1016 }
1017
1018
1019 /*
1020 * Perform dequantization and inverse DCT on one block of coefficients,
1021 * producing a reduced-size 2x2 output block.
1022 *
1023 * Multiplication-less algorithm.
1024 */
1025
1026 GLOBAL(void)
1027 jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
1028 JCOEFPTR coef_block,
1029 JSAMPARRAY output_buf, JDIMENSION output_col)
1030 {
1031 DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
1032 ISLOW_MULT_TYPE * quantptr;
1033 JSAMPROW outptr;
1034 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
1035 ISHIFT_TEMPS
1036
1037 /* Pass 1: process columns from input. */
1038
1039 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
1040
1041 /* Column 0 */
1042 tmp4 = DEQUANTIZE(coef_block[DCTSIZE*0], quantptr[DCTSIZE*0]);
1043 tmp5 = DEQUANTIZE(coef_block[DCTSIZE*1], quantptr[DCTSIZE*1]);
1044 /* Add range center and fudge factor for final descale and range-limit. */
1045 tmp4 += (((DCTELEM) RANGE_CENTER) << 3) + (1 << 2);
1046
1047 tmp0 = tmp4 + tmp5;
1048 tmp2 = tmp4 - tmp5;
1049
1050 /* Column 1 */
1051 tmp4 = DEQUANTIZE(coef_block[DCTSIZE*0+1], quantptr[DCTSIZE*0+1]);
1052 tmp5 = DEQUANTIZE(coef_block[DCTSIZE*1+1], quantptr[DCTSIZE*1+1]);
1053
1054 tmp1 = tmp4 + tmp5;
1055 tmp3 = tmp4 - tmp5;
1056
1057 /* Pass 2: process 2 rows, store into output array. */
1058
1059 /* Row 0 */
1060 outptr = output_buf[0] + output_col;
1061
1062 outptr[0] = range_limit[(int) IRIGHT_SHIFT(tmp0 + tmp1, 3) & RANGE_MASK];
1063 outptr[1] = range_limit[(int) IRIGHT_SHIFT(tmp0 - tmp1, 3) & RANGE_MASK];
1064
1065 /* Row 1 */
1066 outptr = output_buf[1] + output_col;
1067
1068 outptr[0] = range_limit[(int) IRIGHT_SHIFT(tmp2 + tmp3, 3) & RANGE_MASK];
1069 outptr[1] = range_limit[(int) IRIGHT_SHIFT(tmp2 - tmp3, 3) & RANGE_MASK];
1070 }
1071
1072
1073 /*
1074 * Perform dequantization and inverse DCT on one block of coefficients,
1075 * producing a reduced-size 1x1 output block.
1076 *
1077 * We hardly need an inverse DCT routine for this: just take the
1078 * average pixel value, which is one-eighth of the DC coefficient.
1079 */
1080
1081 GLOBAL(void)
1082 jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
1083 JCOEFPTR coef_block,
1084 JSAMPARRAY output_buf, JDIMENSION output_col)
1085 {
1086 DCTELEM dcval;
1087 ISLOW_MULT_TYPE * quantptr;
1088 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
1089 ISHIFT_TEMPS
1090
1091 /* 1x1 is trivial: just take the DC coefficient divided by 8. */
1092
1093 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
1094
1095 dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
1096 /* Add range center and fudge factor for descale and range-limit. */
1097 dcval += (((DCTELEM) RANGE_CENTER) << 3) + (1 << 2);
1098
1099 output_buf[0][output_col] =
1100 range_limit[(int) IRIGHT_SHIFT(dcval, 3) & RANGE_MASK];
1101 }
1102
1103
1104 /*
1105 * Perform dequantization and inverse DCT on one block of coefficients,
1106 * producing a 9x9 output block.
1107 *
1108 * Optimized algorithm with 10 multiplications in the 1-D kernel.
1109 * cK represents sqrt(2) * cos(K*pi/18).
1110 */
1111
1112 GLOBAL(void)
1113 jpeg_idct_9x9 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
1114 JCOEFPTR coef_block,
1115 JSAMPARRAY output_buf, JDIMENSION output_col)
1116 {
1117 INT32 tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13, tmp14;
1118 INT32 z1, z2, z3, z4;
1119 JCOEFPTR inptr;
1120 ISLOW_MULT_TYPE * quantptr;
1121 int * wsptr;
1122 JSAMPROW outptr;
1123 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
1124 int ctr;
1125 int workspace[8*9]; /* buffers data between passes */
1126 SHIFT_TEMPS
1127
1128 /* Pass 1: process columns from input, store into work array. */
1129
1130 inptr = coef_block;
1131 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
1132 wsptr = workspace;
1133 for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
1134 /* Even part */
1135
1136 tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
1137 tmp0 <<= CONST_BITS;
1138 /* Add fudge factor here for final descale. */
1139 tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);
1140
1141 z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
1142 z2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
1143 z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
1144
1145 tmp3 = MULTIPLY(z3, FIX(0.707106781)); /* c6 */
1146 tmp1 = tmp0 + tmp3;
1147 tmp2 = tmp0 - tmp3 - tmp3;
1148
1149 tmp0 = MULTIPLY(z1 - z2, FIX(0.707106781)); /* c6 */
1150 tmp11 = tmp2 + tmp0;
1151 tmp14 = tmp2 - tmp0 - tmp0;
1152
1153 tmp0 = MULTIPLY(z1 + z2, FIX(1.328926049)); /* c2 */
1154 tmp2 = MULTIPLY(z1, FIX(1.083350441)); /* c4 */
1155 tmp3 = MULTIPLY(z2, FIX(0.245575608)); /* c8 */
1156
1157 tmp10 = tmp1 + tmp0 - tmp3;
1158 tmp12 = tmp1 - tmp0 + tmp2;
1159 tmp13 = tmp1 - tmp2 + tmp3;
1160
1161 /* Odd part */
1162
1163 z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
1164 z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
1165 z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
1166 z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
1167
1168 z2 = MULTIPLY(z2, - FIX(1.224744871)); /* -c3 */
1169
1170 tmp2 = MULTIPLY(z1 + z3, FIX(0.909038955)); /* c5 */
1171 tmp3 = MULTIPLY(z1 + z4, FIX(0.483689525)); /* c7 */
1172 tmp0 = tmp2 + tmp3 - z2;
1173 tmp1 = MULTIPLY(z3 - z4, FIX(1.392728481)); /* c1 */
1174 tmp2 += z2 - tmp1;
1175 tmp3 += z2 + tmp1;
1176 tmp1 = MULTIPLY(z1 - z3 - z4, FIX(1.224744871)); /* c3 */
1177
1178 /* Final output stage */
1179
1180 wsptr[8*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);
1181 wsptr[8*8] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);
1182 wsptr[8*1] = (int) RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS-PASS1_BITS);
1183 wsptr[8*7] = (int) RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS-PASS1_BITS);
1184 wsptr[8*2] = (int) RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS-PASS1_BITS);
1185 wsptr[8*6] = (int) RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS-PASS1_BITS);
1186 wsptr[8*3] = (int) RIGHT_SHIFT(tmp13 + tmp3, CONST_BITS-PASS1_BITS);
1187 wsptr[8*5] = (int) RIGHT_SHIFT(tmp13 - tmp3, CONST_BITS-PASS1_BITS);
1188 wsptr[8*4] = (int) RIGHT_SHIFT(tmp14, CONST_BITS-PASS1_BITS);
1189 }
1190
1191 /* Pass 2: process 9 rows from work array, store into output array. */
1192
1193 wsptr = workspace;
1194 for (ctr = 0; ctr < 9; ctr++) {
1195 outptr = output_buf[ctr] + output_col;
1196
1197 /* Even part */
1198
1199 /* Add range center and fudge factor for final descale and range-limit. */
1200 tmp0 = (INT32) wsptr[0] +
1201 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
1202 (ONE << (PASS1_BITS+2)));
1203 tmp0 <<= CONST_BITS;
1204
1205 z1 = (INT32) wsptr[2];
1206 z2 = (INT32) wsptr[4];
1207 z3 = (INT32) wsptr[6];
1208
1209 tmp3 = MULTIPLY(z3, FIX(0.707106781)); /* c6 */
1210 tmp1 = tmp0 + tmp3;
1211 tmp2 = tmp0 - tmp3 - tmp3;
1212
1213 tmp0 = MULTIPLY(z1 - z2, FIX(0.707106781)); /* c6 */
1214 tmp11 = tmp2 + tmp0;
1215 tmp14 = tmp2 - tmp0 - tmp0;
1216
1217 tmp0 = MULTIPLY(z1 + z2, FIX(1.328926049)); /* c2 */
1218 tmp2 = MULTIPLY(z1, FIX(1.083350441)); /* c4 */
1219 tmp3 = MULTIPLY(z2, FIX(0.245575608)); /* c8 */
1220
1221 tmp10 = tmp1 + tmp0 - tmp3;
1222 tmp12 = tmp1 - tmp0 + tmp2;
1223 tmp13 = tmp1 - tmp2 + tmp3;
1224
1225 /* Odd part */
1226
1227 z1 = (INT32) wsptr[1];
1228 z2 = (INT32) wsptr[3];
1229 z3 = (INT32) wsptr[5];
1230 z4 = (INT32) wsptr[7];
1231
1232 z2 = MULTIPLY(z2, - FIX(1.224744871)); /* -c3 */
1233
1234 tmp2 = MULTIPLY(z1 + z3, FIX(0.909038955)); /* c5 */
1235 tmp3 = MULTIPLY(z1 + z4, FIX(0.483689525)); /* c7 */
1236 tmp0 = tmp2 + tmp3 - z2;
1237 tmp1 = MULTIPLY(z3 - z4, FIX(1.392728481)); /* c1 */
1238 tmp2 += z2 - tmp1;
1239 tmp3 += z2 + tmp1;
1240 tmp1 = MULTIPLY(z1 - z3 - z4, FIX(1.224744871)); /* c3 */
1241
1242 /* Final output stage */
1243
1244 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,
1245 CONST_BITS+PASS1_BITS+3)
1246 & RANGE_MASK];
1247 outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,
1248 CONST_BITS+PASS1_BITS+3)
1249 & RANGE_MASK];
1250 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1,
1251 CONST_BITS+PASS1_BITS+3)
1252 & RANGE_MASK];
1253 outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1,
1254 CONST_BITS+PASS1_BITS+3)
1255 & RANGE_MASK];
1256 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,
1257 CONST_BITS+PASS1_BITS+3)
1258 & RANGE_MASK];
1259 outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,
1260 CONST_BITS+PASS1_BITS+3)
1261 & RANGE_MASK];
1262 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp13 + tmp3,
1263 CONST_BITS+PASS1_BITS+3)
1264 & RANGE_MASK];
1265 outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp13 - tmp3,
1266 CONST_BITS+PASS1_BITS+3)
1267 & RANGE_MASK];
1268 outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp14,
1269 CONST_BITS+PASS1_BITS+3)
1270 & RANGE_MASK];
1271
1272 wsptr += 8; /* advance pointer to next row */
1273 }
1274 }
1275
1276
1277 /*
1278 * Perform dequantization and inverse DCT on one block of coefficients,
1279 * producing a 10x10 output block.
1280 *
1281 * Optimized algorithm with 12 multiplications in the 1-D kernel.
1282 * cK represents sqrt(2) * cos(K*pi/20).
1283 */
1284
1285 GLOBAL(void)
1286 jpeg_idct_10x10 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
1287 JCOEFPTR coef_block,
1288 JSAMPARRAY output_buf, JDIMENSION output_col)
1289 {
1290 INT32 tmp10, tmp11, tmp12, tmp13, tmp14;
1291 INT32 tmp20, tmp21, tmp22, tmp23, tmp24;
1292 INT32 z1, z2, z3, z4, z5;
1293 JCOEFPTR inptr;
1294 ISLOW_MULT_TYPE * quantptr;
1295 int * wsptr;
1296 JSAMPROW outptr;
1297 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
1298 int ctr;
1299 int workspace[8*10]; /* buffers data between passes */
1300 SHIFT_TEMPS
1301
1302 /* Pass 1: process columns from input, store into work array. */
1303
1304 inptr = coef_block;
1305 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
1306 wsptr = workspace;
1307 for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
1308 /* Even part */
1309
1310 z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
1311 z3 <<= CONST_BITS;
1312 /* Add fudge factor here for final descale. */
1313 z3 += ONE << (CONST_BITS-PASS1_BITS-1);
1314 z4 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
1315 z1 = MULTIPLY(z4, FIX(1.144122806)); /* c4 */
1316 z2 = MULTIPLY(z4, FIX(0.437016024)); /* c8 */
1317 tmp10 = z3 + z1;
1318 tmp11 = z3 - z2;
1319
1320 tmp22 = RIGHT_SHIFT(z3 - ((z1 - z2) << 1), /* c0 = (c4-c8)*2 */
1321 CONST_BITS-PASS1_BITS);
1322
1323 z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
1324 z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
1325
1326 z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c6 */
1327 tmp12 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c2-c6 */
1328 tmp13 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c2+c6 */
1329
1330 tmp20 = tmp10 + tmp12;
1331 tmp24 = tmp10 - tmp12;
1332 tmp21 = tmp11 + tmp13;
1333 tmp23 = tmp11 - tmp13;
1334
1335 /* Odd part */
1336
1337 z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
1338 z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
1339 z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
1340 z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
1341
1342 tmp11 = z2 + z4;
1343 tmp13 = z2 - z4;
1344
1345 tmp12 = MULTIPLY(tmp13, FIX(0.309016994)); /* (c3-c7)/2 */
1346 z5 = z3 << CONST_BITS;
1347
1348 z2 = MULTIPLY(tmp11, FIX(0.951056516)); /* (c3+c7)/2 */
1349 z4 = z5 + tmp12;
1350
1351 tmp10 = MULTIPLY(z1, FIX(1.396802247)) + z2 + z4; /* c1 */
1352 tmp14 = MULTIPLY(z1, FIX(0.221231742)) - z2 + z4; /* c9 */
1353
1354 z2 = MULTIPLY(tmp11, FIX(0.587785252)); /* (c1-c9)/2 */
1355 z4 = z5 - tmp12 - (tmp13 << (CONST_BITS - 1));
1356
1357 tmp12 = (z1 - tmp13 - z3) << PASS1_BITS;
1358
1359 tmp11 = MULTIPLY(z1, FIX(1.260073511)) - z2 - z4; /* c3 */
1360 tmp13 = MULTIPLY(z1, FIX(0.642039522)) - z2 + z4; /* c7 */
1361
1362 /* Final output stage */
1363
1364 wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);
1365 wsptr[8*9] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);
1366 wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);
1367 wsptr[8*8] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);
1368 wsptr[8*2] = (int) (tmp22 + tmp12);
1369 wsptr[8*7] = (int) (tmp22 - tmp12);
1370 wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS);
1371 wsptr[8*6] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS);
1372 wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);
1373 wsptr[8*5] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);
1374 }
1375
1376 /* Pass 2: process 10 rows from work array, store into output array. */
1377
1378 wsptr = workspace;
1379 for (ctr = 0; ctr < 10; ctr++) {
1380 outptr = output_buf[ctr] + output_col;
1381
1382 /* Even part */
1383
1384 /* Add range center and fudge factor for final descale and range-limit. */
1385 z3 = (INT32) wsptr[0] +
1386 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
1387 (ONE << (PASS1_BITS+2)));
1388 z3 <<= CONST_BITS;
1389 z4 = (INT32) wsptr[4];
1390 z1 = MULTIPLY(z4, FIX(1.144122806)); /* c4 */
1391 z2 = MULTIPLY(z4, FIX(0.437016024)); /* c8 */
1392 tmp10 = z3 + z1;
1393 tmp11 = z3 - z2;
1394
1395 tmp22 = z3 - ((z1 - z2) << 1); /* c0 = (c4-c8)*2 */
1396
1397 z2 = (INT32) wsptr[2];
1398 z3 = (INT32) wsptr[6];
1399
1400 z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c6 */
1401 tmp12 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c2-c6 */
1402 tmp13 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c2+c6 */
1403
1404 tmp20 = tmp10 + tmp12;
1405 tmp24 = tmp10 - tmp12;
1406 tmp21 = tmp11 + tmp13;
1407 tmp23 = tmp11 - tmp13;
1408
1409 /* Odd part */
1410
1411 z1 = (INT32) wsptr[1];
1412 z2 = (INT32) wsptr[3];
1413 z3 = (INT32) wsptr[5];
1414 z3 <<= CONST_BITS;
1415 z4 = (INT32) wsptr[7];
1416
1417 tmp11 = z2 + z4;
1418 tmp13 = z2 - z4;
1419
1420 tmp12 = MULTIPLY(tmp13, FIX(0.309016994)); /* (c3-c7)/2 */
1421
1422 z2 = MULTIPLY(tmp11, FIX(0.951056516)); /* (c3+c7)/2 */
1423 z4 = z3 + tmp12;
1424
1425 tmp10 = MULTIPLY(z1, FIX(1.396802247)) + z2 + z4; /* c1 */
1426 tmp14 = MULTIPLY(z1, FIX(0.221231742)) - z2 + z4; /* c9 */
1427
1428 z2 = MULTIPLY(tmp11, FIX(0.587785252)); /* (c1-c9)/2 */
1429 z4 = z3 - tmp12 - (tmp13 << (CONST_BITS - 1));
1430
1431 tmp12 = ((z1 - tmp13) << CONST_BITS) - z3;
1432
1433 tmp11 = MULTIPLY(z1, FIX(1.260073511)) - z2 - z4; /* c3 */
1434 tmp13 = MULTIPLY(z1, FIX(0.642039522)) - z2 + z4; /* c7 */
1435
1436 /* Final output stage */
1437
1438 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,
1439 CONST_BITS+PASS1_BITS+3)
1440 & RANGE_MASK];
1441 outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,
1442 CONST_BITS+PASS1_BITS+3)
1443 & RANGE_MASK];
1444 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,
1445 CONST_BITS+PASS1_BITS+3)
1446 & RANGE_MASK];
1447 outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,
1448 CONST_BITS+PASS1_BITS+3)
1449 & RANGE_MASK];
1450 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,
1451 CONST_BITS+PASS1_BITS+3)
1452 & RANGE_MASK];
1453 outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,
1454 CONST_BITS+PASS1_BITS+3)
1455 & RANGE_MASK];
1456 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,
1457 CONST_BITS+PASS1_BITS+3)
1458 & RANGE_MASK];
1459 outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,
1460 CONST_BITS+PASS1_BITS+3)
1461 & RANGE_MASK];
1462 outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,
1463 CONST_BITS+PASS1_BITS+3)
1464 & RANGE_MASK];
1465 outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,
1466 CONST_BITS+PASS1_BITS+3)
1467 & RANGE_MASK];
1468
1469 wsptr += 8; /* advance pointer to next row */
1470 }
1471 }
1472
1473
1474 /*
1475 * Perform dequantization and inverse DCT on one block of coefficients,
1476 * producing a 11x11 output block.
1477 *
1478 * Optimized algorithm with 24 multiplications in the 1-D kernel.
1479 * cK represents sqrt(2) * cos(K*pi/22).
1480 */
1481
1482 GLOBAL(void)
1483 jpeg_idct_11x11 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
1484 JCOEFPTR coef_block,
1485 JSAMPARRAY output_buf, JDIMENSION output_col)
1486 {
1487 INT32 tmp10, tmp11, tmp12, tmp13, tmp14;
1488 INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25;
1489 INT32 z1, z2, z3, z4;
1490 JCOEFPTR inptr;
1491 ISLOW_MULT_TYPE * quantptr;
1492 int * wsptr;
1493 JSAMPROW outptr;
1494 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
1495 int ctr;
1496 int workspace[8*11]; /* buffers data between passes */
1497 SHIFT_TEMPS
1498
1499 /* Pass 1: process columns from input, store into work array. */
1500
1501 inptr = coef_block;
1502 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
1503 wsptr = workspace;
1504 for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
1505 /* Even part */
1506
1507 tmp10 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
1508 tmp10 <<= CONST_BITS;
1509 /* Add fudge factor here for final descale. */
1510 tmp10 += ONE << (CONST_BITS-PASS1_BITS-1);
1511
1512 z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
1513 z2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
1514 z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
1515
1516 tmp20 = MULTIPLY(z2 - z3, FIX(2.546640132)); /* c2+c4 */
1517 tmp23 = MULTIPLY(z2 - z1, FIX(0.430815045)); /* c2-c6 */
1518 z4 = z1 + z3;
1519 tmp24 = MULTIPLY(z4, - FIX(1.155664402)); /* -(c2-c10) */
1520 z4 -= z2;
1521 tmp25 = tmp10 + MULTIPLY(z4, FIX(1.356927976)); /* c2 */
1522 tmp21 = tmp20 + tmp23 + tmp25 -
1523 MULTIPLY(z2, FIX(1.821790775)); /* c2+c4+c10-c6 */
1524 tmp20 += tmp25 + MULTIPLY(z3, FIX(2.115825087)); /* c4+c6 */
1525 tmp23 += tmp25 - MULTIPLY(z1, FIX(1.513598477)); /* c6+c8 */
1526 tmp24 += tmp25;
1527 tmp22 = tmp24 - MULTIPLY(z3, FIX(0.788749120)); /* c8+c10 */
1528 tmp24 += MULTIPLY(z2, FIX(1.944413522)) - /* c2+c8 */
1529 MULTIPLY(z1, FIX(1.390975730)); /* c4+c10 */
1530 tmp25 = tmp10 - MULTIPLY(z4, FIX(1.414213562)); /* c0 */
1531
1532 /* Odd part */
1533
1534 z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
1535 z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
1536 z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
1537 z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
1538
1539 tmp11 = z1 + z2;
1540 tmp14 = MULTIPLY(tmp11 + z3 + z4, FIX(0.398430003)); /* c9 */
1541 tmp11 = MULTIPLY(tmp11, FIX(0.887983902)); /* c3-c9 */
1542 tmp12 = MULTIPLY(z1 + z3, FIX(0.670361295)); /* c5-c9 */
1543 tmp13 = tmp14 + MULTIPLY(z1 + z4, FIX(0.366151574)); /* c7-c9 */
1544 tmp10 = tmp11 + tmp12 + tmp13 -
1545 MULTIPLY(z1, FIX(0.923107866)); /* c7+c5+c3-c1-2*c9 */
1546 z1 = tmp14 - MULTIPLY(z2 + z3, FIX(1.163011579)); /* c7+c9 */
1547 tmp11 += z1 + MULTIPLY(z2, FIX(2.073276588)); /* c1+c7+3*c9-c3 */
1548 tmp12 += z1 - MULTIPLY(z3, FIX(1.192193623)); /* c3+c5-c7-c9 */
1549 z1 = MULTIPLY(z2 + z4, - FIX(1.798248910)); /* -(c1+c9) */
1550 tmp11 += z1;
1551 tmp13 += z1 + MULTIPLY(z4, FIX(2.102458632)); /* c1+c5+c9-c7 */
1552 tmp14 += MULTIPLY(z2, - FIX(1.467221301)) + /* -(c5+c9) */
1553 MULTIPLY(z3, FIX(1.001388905)) - /* c1-c9 */
1554 MULTIPLY(z4, FIX(1.684843907)); /* c3+c9 */
1555
1556 /* Final output stage */
1557
1558 wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);
1559 wsptr[8*10] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);
1560 wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);
1561 wsptr[8*9] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);
1562 wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);
1563 wsptr[8*8] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);
1564 wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS);
1565 wsptr[8*7] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS);
1566 wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);
1567 wsptr[8*6] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);
1568 wsptr[8*5] = (int) RIGHT_SHIFT(tmp25, CONST_BITS-PASS1_BITS);
1569 }
1570
1571 /* Pass 2: process 11 rows from work array, store into output array. */
1572
1573 wsptr = workspace;
1574 for (ctr = 0; ctr < 11; ctr++) {
1575 outptr = output_buf[ctr] + output_col;
1576
1577 /* Even part */
1578
1579 /* Add range center and fudge factor for final descale and range-limit. */
1580 tmp10 = (INT32) wsptr[0] +
1581 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
1582 (ONE << (PASS1_BITS+2)));
1583 tmp10 <<= CONST_BITS;
1584
1585 z1 = (INT32) wsptr[2];
1586 z2 = (INT32) wsptr[4];
1587 z3 = (INT32) wsptr[6];
1588
1589 tmp20 = MULTIPLY(z2 - z3, FIX(2.546640132)); /* c2+c4 */
1590 tmp23 = MULTIPLY(z2 - z1, FIX(0.430815045)); /* c2-c6 */
1591 z4 = z1 + z3;
1592 tmp24 = MULTIPLY(z4, - FIX(1.155664402)); /* -(c2-c10) */
1593 z4 -= z2;
1594 tmp25 = tmp10 + MULTIPLY(z4, FIX(1.356927976)); /* c2 */
1595 tmp21 = tmp20 + tmp23 + tmp25 -
1596 MULTIPLY(z2, FIX(1.821790775)); /* c2+c4+c10-c6 */
1597 tmp20 += tmp25 + MULTIPLY(z3, FIX(2.115825087)); /* c4+c6 */
1598 tmp23 += tmp25 - MULTIPLY(z1, FIX(1.513598477)); /* c6+c8 */
1599 tmp24 += tmp25;
1600 tmp22 = tmp24 - MULTIPLY(z3, FIX(0.788749120)); /* c8+c10 */
1601 tmp24 += MULTIPLY(z2, FIX(1.944413522)) - /* c2+c8 */
1602 MULTIPLY(z1, FIX(1.390975730)); /* c4+c10 */
1603 tmp25 = tmp10 - MULTIPLY(z4, FIX(1.414213562)); /* c0 */
1604
1605 /* Odd part */
1606
1607 z1 = (INT32) wsptr[1];
1608 z2 = (INT32) wsptr[3];
1609 z3 = (INT32) wsptr[5];
1610 z4 = (INT32) wsptr[7];
1611
1612 tmp11 = z1 + z2;
1613 tmp14 = MULTIPLY(tmp11 + z3 + z4, FIX(0.398430003)); /* c9 */
1614 tmp11 = MULTIPLY(tmp11, FIX(0.887983902)); /* c3-c9 */
1615 tmp12 = MULTIPLY(z1 + z3, FIX(0.670361295)); /* c5-c9 */
1616 tmp13 = tmp14 + MULTIPLY(z1 + z4, FIX(0.366151574)); /* c7-c9 */
1617 tmp10 = tmp11 + tmp12 + tmp13 -
1618 MULTIPLY(z1, FIX(0.923107866)); /* c7+c5+c3-c1-2*c9 */
1619 z1 = tmp14 - MULTIPLY(z2 + z3, FIX(1.163011579)); /* c7+c9 */
1620 tmp11 += z1 + MULTIPLY(z2, FIX(2.073276588)); /* c1+c7+3*c9-c3 */
1621 tmp12 += z1 - MULTIPLY(z3, FIX(1.192193623)); /* c3+c5-c7-c9 */
1622 z1 = MULTIPLY(z2 + z4, - FIX(1.798248910)); /* -(c1+c9) */
1623 tmp11 += z1;
1624 tmp13 += z1 + MULTIPLY(z4, FIX(2.102458632)); /* c1+c5+c9-c7 */
1625 tmp14 += MULTIPLY(z2, - FIX(1.467221301)) + /* -(c5+c9) */
1626 MULTIPLY(z3, FIX(1.001388905)) - /* c1-c9 */
1627 MULTIPLY(z4, FIX(1.684843907)); /* c3+c9 */
1628
1629 /* Final output stage */
1630
1631 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,
1632 CONST_BITS+PASS1_BITS+3)
1633 & RANGE_MASK];
1634 outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,
1635 CONST_BITS+PASS1_BITS+3)
1636 & RANGE_MASK];
1637 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,
1638 CONST_BITS+PASS1_BITS+3)
1639 & RANGE_MASK];
1640 outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,
1641 CONST_BITS+PASS1_BITS+3)
1642 & RANGE_MASK];
1643 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,
1644 CONST_BITS+PASS1_BITS+3)
1645 & RANGE_MASK];
1646 outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,
1647 CONST_BITS+PASS1_BITS+3)
1648 & RANGE_MASK];
1649 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,
1650 CONST_BITS+PASS1_BITS+3)
1651 & RANGE_MASK];
1652 outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,
1653 CONST_BITS+PASS1_BITS+3)
1654 & RANGE_MASK];
1655 outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,
1656 CONST_BITS+PASS1_BITS+3)
1657 & RANGE_MASK];
1658 outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,
1659 CONST_BITS+PASS1_BITS+3)
1660 & RANGE_MASK];
1661 outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp25,
1662 CONST_BITS+PASS1_BITS+3)
1663 & RANGE_MASK];
1664
1665 wsptr += 8; /* advance pointer to next row */
1666 }
1667 }
1668
1669
1670 /*
1671 * Perform dequantization and inverse DCT on one block of coefficients,
1672 * producing a 12x12 output block.
1673 *
1674 * Optimized algorithm with 15 multiplications in the 1-D kernel.
1675 * cK represents sqrt(2) * cos(K*pi/24).
1676 */
1677
1678 GLOBAL(void)
1679 jpeg_idct_12x12 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
1680 JCOEFPTR coef_block,
1681 JSAMPARRAY output_buf, JDIMENSION output_col)
1682 {
1683 INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
1684 INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25;
1685 INT32 z1, z2, z3, z4;
1686 JCOEFPTR inptr;
1687 ISLOW_MULT_TYPE * quantptr;
1688 int * wsptr;
1689 JSAMPROW outptr;
1690 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
1691 int ctr;
1692 int workspace[8*12]; /* buffers data between passes */
1693 SHIFT_TEMPS
1694
1695 /* Pass 1: process columns from input, store into work array. */
1696
1697 inptr = coef_block;
1698 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
1699 wsptr = workspace;
1700 for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
1701 /* Even part */
1702
1703 z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
1704 z3 <<= CONST_BITS;
1705 /* Add fudge factor here for final descale. */
1706 z3 += ONE << (CONST_BITS-PASS1_BITS-1);
1707
1708 z4 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
1709 z4 = MULTIPLY(z4, FIX(1.224744871)); /* c4 */
1710
1711 tmp10 = z3 + z4;
1712 tmp11 = z3 - z4;
1713
1714 z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
1715 z4 = MULTIPLY(z1, FIX(1.366025404)); /* c2 */
1716 z1 <<= CONST_BITS;
1717 z2 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
1718 z2 <<= CONST_BITS;
1719
1720 tmp12 = z1 - z2;
1721
1722 tmp21 = z3 + tmp12;
1723 tmp24 = z3 - tmp12;
1724
1725 tmp12 = z4 + z2;
1726
1727 tmp20 = tmp10 + tmp12;
1728 tmp25 = tmp10 - tmp12;
1729
1730 tmp12 = z4 - z1 - z2;
1731
1732 tmp22 = tmp11 + tmp12;
1733 tmp23 = tmp11 - tmp12;
1734
1735 /* Odd part */
1736
1737 z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
1738 z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
1739 z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
1740 z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
1741
1742 tmp11 = MULTIPLY(z2, FIX(1.306562965)); /* c3 */
1743 tmp14 = MULTIPLY(z2, - FIX_0_541196100); /* -c9 */
1744
1745 tmp10 = z1 + z3;
1746 tmp15 = MULTIPLY(tmp10 + z4, FIX(0.860918669)); /* c7 */
1747 tmp12 = tmp15 + MULTIPLY(tmp10, FIX(0.261052384)); /* c5-c7 */
1748 tmp10 = tmp12 + tmp11 + MULTIPLY(z1, FIX(0.280143716)); /* c1-c5 */
1749 tmp13 = MULTIPLY(z3 + z4, - FIX(1.045510580)); /* -(c7+c11) */
1750 tmp12 += tmp13 + tmp14 - MULTIPLY(z3, FIX(1.478575242)); /* c1+c5-c7-c11 */
1751 tmp13 += tmp15 - tmp11 + MULTIPLY(z4, FIX(1.586706681)); /* c1+c11 */
1752 tmp15 += tmp14 - MULTIPLY(z1, FIX(0.676326758)) - /* c7-c11 */
1753 MULTIPLY(z4, FIX(1.982889723)); /* c5+c7 */
1754
1755 z1 -= z4;
1756 z2 -= z3;
1757 z3 = MULTIPLY(z1 + z2, FIX_0_541196100); /* c9 */
1758 tmp11 = z3 + MULTIPLY(z1, FIX_0_765366865); /* c3-c9 */
1759 tmp14 = z3 - MULTIPLY(z2, FIX_1_847759065); /* c3+c9 */
1760
1761 /* Final output stage */
1762
1763 wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);
1764 wsptr[8*11] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);
1765 wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);
1766 wsptr[8*10] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);
1767 wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);
1768 wsptr[8*9] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);
1769 wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS);
1770 wsptr[8*8] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS);
1771 wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);
1772 wsptr[8*7] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);
1773 wsptr[8*5] = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS);
1774 wsptr[8*6] = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS);
1775 }
1776
1777 /* Pass 2: process 12 rows from work array, store into output array. */
1778
1779 wsptr = workspace;
1780 for (ctr = 0; ctr < 12; ctr++) {
1781 outptr = output_buf[ctr] + output_col;
1782
1783 /* Even part */
1784
1785 /* Add range center and fudge factor for final descale and range-limit. */
1786 z3 = (INT32) wsptr[0] +
1787 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
1788 (ONE << (PASS1_BITS+2)));
1789 z3 <<= CONST_BITS;
1790
1791 z4 = (INT32) wsptr[4];
1792 z4 = MULTIPLY(z4, FIX(1.224744871)); /* c4 */
1793
1794 tmp10 = z3 + z4;
1795 tmp11 = z3 - z4;
1796
1797 z1 = (INT32) wsptr[2];
1798 z4 = MULTIPLY(z1, FIX(1.366025404)); /* c2 */
1799 z1 <<= CONST_BITS;
1800 z2 = (INT32) wsptr[6];
1801 z2 <<= CONST_BITS;
1802
1803 tmp12 = z1 - z2;
1804
1805 tmp21 = z3 + tmp12;
1806 tmp24 = z3 - tmp12;
1807
1808 tmp12 = z4 + z2;
1809
1810 tmp20 = tmp10 + tmp12;
1811 tmp25 = tmp10 - tmp12;
1812
1813 tmp12 = z4 - z1 - z2;
1814
1815 tmp22 = tmp11 + tmp12;
1816 tmp23 = tmp11 - tmp12;
1817
1818 /* Odd part */
1819
1820 z1 = (INT32) wsptr[1];
1821 z2 = (INT32) wsptr[3];
1822 z3 = (INT32) wsptr[5];
1823 z4 = (INT32) wsptr[7];
1824
1825 tmp11 = MULTIPLY(z2, FIX(1.306562965)); /* c3 */
1826 tmp14 = MULTIPLY(z2, - FIX_0_541196100); /* -c9 */
1827
1828 tmp10 = z1 + z3;
1829 tmp15 = MULTIPLY(tmp10 + z4, FIX(0.860918669)); /* c7 */
1830 tmp12 = tmp15 + MULTIPLY(tmp10, FIX(0.261052384)); /* c5-c7 */
1831 tmp10 = tmp12 + tmp11 + MULTIPLY(z1, FIX(0.280143716)); /* c1-c5 */
1832 tmp13 = MULTIPLY(z3 + z4, - FIX(1.045510580)); /* -(c7+c11) */
1833 tmp12 += tmp13 + tmp14 - MULTIPLY(z3, FIX(1.478575242)); /* c1+c5-c7-c11 */
1834 tmp13 += tmp15 - tmp11 + MULTIPLY(z4, FIX(1.586706681)); /* c1+c11 */
1835 tmp15 += tmp14 - MULTIPLY(z1, FIX(0.676326758)) - /* c7-c11 */
1836 MULTIPLY(z4, FIX(1.982889723)); /* c5+c7 */
1837
1838 z1 -= z4;
1839 z2 -= z3;
1840 z3 = MULTIPLY(z1 + z2, FIX_0_541196100); /* c9 */
1841 tmp11 = z3 + MULTIPLY(z1, FIX_0_765366865); /* c3-c9 */
1842 tmp14 = z3 - MULTIPLY(z2, FIX_1_847759065); /* c3+c9 */
1843
1844 /* Final output stage */
1845
1846 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,
1847 CONST_BITS+PASS1_BITS+3)
1848 & RANGE_MASK];
1849 outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,
1850 CONST_BITS+PASS1_BITS+3)
1851 & RANGE_MASK];
1852 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,
1853 CONST_BITS+PASS1_BITS+3)
1854 & RANGE_MASK];
1855 outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,
1856 CONST_BITS+PASS1_BITS+3)
1857 & RANGE_MASK];
1858 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,
1859 CONST_BITS+PASS1_BITS+3)
1860 & RANGE_MASK];
1861 outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,
1862 CONST_BITS+PASS1_BITS+3)
1863 & RANGE_MASK];
1864 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,
1865 CONST_BITS+PASS1_BITS+3)
1866 & RANGE_MASK];
1867 outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,
1868 CONST_BITS+PASS1_BITS+3)
1869 & RANGE_MASK];
1870 outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,
1871 CONST_BITS+PASS1_BITS+3)
1872 & RANGE_MASK];
1873 outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,
1874 CONST_BITS+PASS1_BITS+3)
1875 & RANGE_MASK];
1876 outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15,
1877 CONST_BITS+PASS1_BITS+3)
1878 & RANGE_MASK];
1879 outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15,
1880 CONST_BITS+PASS1_BITS+3)
1881 & RANGE_MASK];
1882
1883 wsptr += 8; /* advance pointer to next row */
1884 }
1885 }
1886
1887
1888 /*
1889 * Perform dequantization and inverse DCT on one block of coefficients,
1890 * producing a 13x13 output block.
1891 *
1892 * Optimized algorithm with 29 multiplications in the 1-D kernel.
1893 * cK represents sqrt(2) * cos(K*pi/26).
1894 */
1895
1896 GLOBAL(void)
1897 jpeg_idct_13x13 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
1898 JCOEFPTR coef_block,
1899 JSAMPARRAY output_buf, JDIMENSION output_col)
1900 {
1901 INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
1902 INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26;
1903 INT32 z1, z2, z3, z4;
1904 JCOEFPTR inptr;
1905 ISLOW_MULT_TYPE * quantptr;
1906 int * wsptr;
1907 JSAMPROW outptr;
1908 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
1909 int ctr;
1910 int workspace[8*13]; /* buffers data between passes */
1911 SHIFT_TEMPS
1912
1913 /* Pass 1: process columns from input, store into work array. */
1914
1915 inptr = coef_block;
1916 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
1917 wsptr = workspace;
1918 for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
1919 /* Even part */
1920
1921 z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
1922 z1 <<= CONST_BITS;
1923 /* Add fudge factor here for final descale. */
1924 z1 += ONE << (CONST_BITS-PASS1_BITS-1);
1925
1926 z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
1927 z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
1928 z4 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
1929
1930 tmp10 = z3 + z4;
1931 tmp11 = z3 - z4;
1932
1933 tmp12 = MULTIPLY(tmp10, FIX(1.155388986)); /* (c4+c6)/2 */
1934 tmp13 = MULTIPLY(tmp11, FIX(0.096834934)) + z1; /* (c4-c6)/2 */
1935
1936 tmp20 = MULTIPLY(z2, FIX(1.373119086)) + tmp12 + tmp13; /* c2 */
1937 tmp22 = MULTIPLY(z2, FIX(0.501487041)) - tmp12 + tmp13; /* c10 */
1938
1939 tmp12 = MULTIPLY(tmp10, FIX(0.316450131)); /* (c8-c12)/2 */
1940 tmp13 = MULTIPLY(tmp11, FIX(0.486914739)) + z1; /* (c8+c12)/2 */
1941
1942 tmp21 = MULTIPLY(z2, FIX(1.058554052)) - tmp12 + tmp13; /* c6 */
1943 tmp25 = MULTIPLY(z2, - FIX(1.252223920)) + tmp12 + tmp13; /* c4 */
1944
1945 tmp12 = MULTIPLY(tmp10, FIX(0.435816023)); /* (c2-c10)/2 */
1946 tmp13 = MULTIPLY(tmp11, FIX(0.937303064)) - z1; /* (c2+c10)/2 */
1947
1948 tmp23 = MULTIPLY(z2, - FIX(0.170464608)) - tmp12 - tmp13; /* c12 */
1949 tmp24 = MULTIPLY(z2, - FIX(0.803364869)) + tmp12 - tmp13; /* c8 */
1950
1951 tmp26 = MULTIPLY(tmp11 - z2, FIX(1.414213562)) + z1; /* c0 */
1952
1953 /* Odd part */
1954
1955 z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
1956 z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
1957 z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
1958 z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
1959
1960 tmp11 = MULTIPLY(z1 + z2, FIX(1.322312651)); /* c3 */
1961 tmp12 = MULTIPLY(z1 + z3, FIX(1.163874945)); /* c5 */
1962 tmp15 = z1 + z4;
1963 tmp13 = MULTIPLY(tmp15, FIX(0.937797057)); /* c7 */
1964 tmp10 = tmp11 + tmp12 + tmp13 -
1965 MULTIPLY(z1, FIX(2.020082300)); /* c7+c5+c3-c1 */
1966 tmp14 = MULTIPLY(z2 + z3, - FIX(0.338443458)); /* -c11 */
1967 tmp11 += tmp14 + MULTIPLY(z2, FIX(0.837223564)); /* c5+c9+c11-c3 */
1968 tmp12 += tmp14 - MULTIPLY(z3, FIX(1.572116027)); /* c1+c5-c9-c11 */
1969 tmp14 = MULTIPLY(z2 + z4, - FIX(1.163874945)); /* -c5 */
1970 tmp11 += tmp14;
1971 tmp13 += tmp14 + MULTIPLY(z4, FIX(2.205608352)); /* c3+c5+c9-c7 */
1972 tmp14 = MULTIPLY(z3 + z4, - FIX(0.657217813)); /* -c9 */
1973 tmp12 += tmp14;
1974 tmp13 += tmp14;
1975 tmp15 = MULTIPLY(tmp15, FIX(0.338443458)); /* c11 */
1976 tmp14 = tmp15 + MULTIPLY(z1, FIX(0.318774355)) - /* c9-c11 */
1977 MULTIPLY(z2, FIX(0.466105296)); /* c1-c7 */
1978 z1 = MULTIPLY(z3 - z2, FIX(0.937797057)); /* c7 */
1979 tmp14 += z1;
1980 tmp15 += z1 + MULTIPLY(z3, FIX(0.384515595)) - /* c3-c7 */
1981 MULTIPLY(z4, FIX(1.742345811)); /* c1+c11 */
1982
1983 /* Final output stage */
1984
1985 wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);
1986 wsptr[8*12] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);
1987 wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);
1988 wsptr[8*11] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);
1989 wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);
1990 wsptr[8*10] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);
1991 wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS);
1992 wsptr[8*9] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS);
1993 wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);
1994 wsptr[8*8] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);
1995 wsptr[8*5] = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS);
1996 wsptr[8*7] = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS);
1997 wsptr[8*6] = (int) RIGHT_SHIFT(tmp26, CONST_BITS-PASS1_BITS);
1998 }
1999
2000 /* Pass 2: process 13 rows from work array, store into output array. */
2001
2002 wsptr = workspace;
2003 for (ctr = 0; ctr < 13; ctr++) {
2004 outptr = output_buf[ctr] + output_col;
2005
2006 /* Even part */
2007
2008 /* Add range center and fudge factor for final descale and range-limit. */
2009 z1 = (INT32) wsptr[0] +
2010 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
2011 (ONE << (PASS1_BITS+2)));
2012 z1 <<= CONST_BITS;
2013
2014 z2 = (INT32) wsptr[2];
2015 z3 = (INT32) wsptr[4];
2016 z4 = (INT32) wsptr[6];
2017
2018 tmp10 = z3 + z4;
2019 tmp11 = z3 - z4;
2020
2021 tmp12 = MULTIPLY(tmp10, FIX(1.155388986)); /* (c4+c6)/2 */
2022 tmp13 = MULTIPLY(tmp11, FIX(0.096834934)) + z1; /* (c4-c6)/2 */
2023
2024 tmp20 = MULTIPLY(z2, FIX(1.373119086)) + tmp12 + tmp13; /* c2 */
2025 tmp22 = MULTIPLY(z2, FIX(0.501487041)) - tmp12 + tmp13; /* c10 */
2026
2027 tmp12 = MULTIPLY(tmp10, FIX(0.316450131)); /* (c8-c12)/2 */
2028 tmp13 = MULTIPLY(tmp11, FIX(0.486914739)) + z1; /* (c8+c12)/2 */
2029
2030 tmp21 = MULTIPLY(z2, FIX(1.058554052)) - tmp12 + tmp13; /* c6 */
2031 tmp25 = MULTIPLY(z2, - FIX(1.252223920)) + tmp12 + tmp13; /* c4 */
2032
2033 tmp12 = MULTIPLY(tmp10, FIX(0.435816023)); /* (c2-c10)/2 */
2034 tmp13 = MULTIPLY(tmp11, FIX(0.937303064)) - z1; /* (c2+c10)/2 */
2035
2036 tmp23 = MULTIPLY(z2, - FIX(0.170464608)) - tmp12 - tmp13; /* c12 */
2037 tmp24 = MULTIPLY(z2, - FIX(0.803364869)) + tmp12 - tmp13; /* c8 */
2038
2039 tmp26 = MULTIPLY(tmp11 - z2, FIX(1.414213562)) + z1; /* c0 */
2040
2041 /* Odd part */
2042
2043 z1 = (INT32) wsptr[1];
2044 z2 = (INT32) wsptr[3];
2045 z3 = (INT32) wsptr[5];
2046 z4 = (INT32) wsptr[7];
2047
2048 tmp11 = MULTIPLY(z1 + z2, FIX(1.322312651)); /* c3 */
2049 tmp12 = MULTIPLY(z1 + z3, FIX(1.163874945)); /* c5 */
2050 tmp15 = z1 + z4;
2051 tmp13 = MULTIPLY(tmp15, FIX(0.937797057)); /* c7 */
2052 tmp10 = tmp11 + tmp12 + tmp13 -
2053 MULTIPLY(z1, FIX(2.020082300)); /* c7+c5+c3-c1 */
2054 tmp14 = MULTIPLY(z2 + z3, - FIX(0.338443458)); /* -c11 */
2055 tmp11 += tmp14 + MULTIPLY(z2, FIX(0.837223564)); /* c5+c9+c11-c3 */
2056 tmp12 += tmp14 - MULTIPLY(z3, FIX(1.572116027)); /* c1+c5-c9-c11 */
2057 tmp14 = MULTIPLY(z2 + z4, - FIX(1.163874945)); /* -c5 */
2058 tmp11 += tmp14;
2059 tmp13 += tmp14 + MULTIPLY(z4, FIX(2.205608352)); /* c3+c5+c9-c7 */
2060 tmp14 = MULTIPLY(z3 + z4, - FIX(0.657217813)); /* -c9 */
2061 tmp12 += tmp14;
2062 tmp13 += tmp14;
2063 tmp15 = MULTIPLY(tmp15, FIX(0.338443458)); /* c11 */
2064 tmp14 = tmp15 + MULTIPLY(z1, FIX(0.318774355)) - /* c9-c11 */
2065 MULTIPLY(z2, FIX(0.466105296)); /* c1-c7 */
2066 z1 = MULTIPLY(z3 - z2, FIX(0.937797057)); /* c7 */
2067 tmp14 += z1;
2068 tmp15 += z1 + MULTIPLY(z3, FIX(0.384515595)) - /* c3-c7 */
2069 MULTIPLY(z4, FIX(1.742345811)); /* c1+c11 */
2070
2071 /* Final output stage */
2072
2073 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,
2074 CONST_BITS+PASS1_BITS+3)
2075 & RANGE_MASK];
2076 outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,
2077 CONST_BITS+PASS1_BITS+3)
2078 & RANGE_MASK];
2079 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,
2080 CONST_BITS+PASS1_BITS+3)
2081 & RANGE_MASK];
2082 outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,
2083 CONST_BITS+PASS1_BITS+3)
2084 & RANGE_MASK];
2085 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,
2086 CONST_BITS+PASS1_BITS+3)
2087 & RANGE_MASK];
2088 outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,
2089 CONST_BITS+PASS1_BITS+3)
2090 & RANGE_MASK];
2091 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,
2092 CONST_BITS+PASS1_BITS+3)
2093 & RANGE_MASK];
2094 outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,
2095 CONST_BITS+PASS1_BITS+3)
2096 & RANGE_MASK];
2097 outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,
2098 CONST_BITS+PASS1_BITS+3)
2099 & RANGE_MASK];
2100 outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,
2101 CONST_BITS+PASS1_BITS+3)
2102 & RANGE_MASK];
2103 outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15,
2104 CONST_BITS+PASS1_BITS+3)
2105 & RANGE_MASK];
2106 outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15,
2107 CONST_BITS+PASS1_BITS+3)
2108 & RANGE_MASK];
2109 outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp26,
2110 CONST_BITS+PASS1_BITS+3)
2111 & RANGE_MASK];
2112
2113 wsptr += 8; /* advance pointer to next row */
2114 }
2115 }
2116
2117
2118 /*
2119 * Perform dequantization and inverse DCT on one block of coefficients,
2120 * producing a 14x14 output block.
2121 *
2122 * Optimized algorithm with 20 multiplications in the 1-D kernel.
2123 * cK represents sqrt(2) * cos(K*pi/28).
2124 */
2125
2126 GLOBAL(void)
2127 jpeg_idct_14x14 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
2128 JCOEFPTR coef_block,
2129 JSAMPARRAY output_buf, JDIMENSION output_col)
2130 {
2131 INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
2132 INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26;
2133 INT32 z1, z2, z3, z4;
2134 JCOEFPTR inptr;
2135 ISLOW_MULT_TYPE * quantptr;
2136 int * wsptr;
2137 JSAMPROW outptr;
2138 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
2139 int ctr;
2140 int workspace[8*14]; /* buffers data between passes */
2141 SHIFT_TEMPS
2142
2143 /* Pass 1: process columns from input, store into work array. */
2144
2145 inptr = coef_block;
2146 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
2147 wsptr = workspace;
2148 for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
2149 /* Even part */
2150
2151 z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
2152 z1 <<= CONST_BITS;
2153 /* Add fudge factor here for final descale. */
2154 z1 += ONE << (CONST_BITS-PASS1_BITS-1);
2155 z4 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
2156 z2 = MULTIPLY(z4, FIX(1.274162392)); /* c4 */
2157 z3 = MULTIPLY(z4, FIX(0.314692123)); /* c12 */
2158 z4 = MULTIPLY(z4, FIX(0.881747734)); /* c8 */
2159
2160 tmp10 = z1 + z2;
2161 tmp11 = z1 + z3;
2162 tmp12 = z1 - z4;
2163
2164 tmp23 = RIGHT_SHIFT(z1 - ((z2 + z3 - z4) << 1), /* c0 = (c4+c12-c8)*2 */
2165 CONST_BITS-PASS1_BITS);
2166
2167 z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
2168 z2 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
2169
2170 z3 = MULTIPLY(z1 + z2, FIX(1.105676686)); /* c6 */
2171
2172 tmp13 = z3 + MULTIPLY(z1, FIX(0.273079590)); /* c2-c6 */
2173 tmp14 = z3 - MULTIPLY(z2, FIX(1.719280954)); /* c6+c10 */
2174 tmp15 = MULTIPLY(z1, FIX(0.613604268)) - /* c10 */
2175 MULTIPLY(z2, FIX(1.378756276)); /* c2 */
2176
2177 tmp20 = tmp10 + tmp13;
2178 tmp26 = tmp10 - tmp13;
2179 tmp21 = tmp11 + tmp14;
2180 tmp25 = tmp11 - tmp14;
2181 tmp22 = tmp12 + tmp15;
2182 tmp24 = tmp12 - tmp15;
2183
2184 /* Odd part */
2185
2186 z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
2187 z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
2188 z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
2189 z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
2190 tmp13 = z4 << CONST_BITS;
2191
2192 tmp14 = z1 + z3;
2193 tmp11 = MULTIPLY(z1 + z2, FIX(1.334852607)); /* c3 */
2194 tmp12 = MULTIPLY(tmp14, FIX(1.197448846)); /* c5 */
2195 tmp10 = tmp11 + tmp12 + tmp13 - MULTIPLY(z1, FIX(1.126980169)); /* c3+c5-c1 */
2196 tmp14 = MULTIPLY(tmp14, FIX(0.752406978)); /* c9 */
2197 tmp16 = tmp14 - MULTIPLY(z1, FIX(1.061150426)); /* c9+c11-c13 */
2198 z1 -= z2;
2199 tmp15 = MULTIPLY(z1, FIX(0.467085129)) - tmp13; /* c11 */
2200 tmp16 += tmp15;
2201 z1 += z4;
2202 z4 = MULTIPLY(z2 + z3, - FIX(0.158341681)) - tmp13; /* -c13 */
2203 tmp11 += z4 - MULTIPLY(z2, FIX(0.424103948)); /* c3-c9-c13 */
2204 tmp12 += z4 - MULTIPLY(z3, FIX(2.373959773)); /* c3+c5-c13 */
2205 z4 = MULTIPLY(z3 - z2, FIX(1.405321284)); /* c1 */
2206 tmp14 += z4 + tmp13 - MULTIPLY(z3, FIX(1.6906431334)); /* c1+c9-c11 */
2207 tmp15 += z4 + MULTIPLY(z2, FIX(0.674957567)); /* c1+c11-c5 */
2208
2209 tmp13 = (z1 - z3) << PASS1_BITS;
2210
2211 /* Final output stage */
2212
2213 wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);
2214 wsptr[8*13] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);
2215 wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);
2216 wsptr[8*12] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);
2217 wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);
2218 wsptr[8*11] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);
2219 wsptr[8*3] = (int) (tmp23 + tmp13);
2220 wsptr[8*10] = (int) (tmp23 - tmp13);
2221 wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);
2222 wsptr[8*9] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);
2223 wsptr[8*5] = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS);
2224 wsptr[8*8] = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS);
2225 wsptr[8*6] = (int) RIGHT_SHIFT(tmp26 + tmp16, CONST_BITS-PASS1_BITS);
2226 wsptr[8*7] = (int) RIGHT_SHIFT(tmp26 - tmp16, CONST_BITS-PASS1_BITS);
2227 }
2228
2229 /* Pass 2: process 14 rows from work array, store into output array. */
2230
2231 wsptr = workspace;
2232 for (ctr = 0; ctr < 14; ctr++) {
2233 outptr = output_buf[ctr] + output_col;
2234
2235 /* Even part */
2236
2237 /* Add range center and fudge factor for final descale and range-limit. */
2238 z1 = (INT32) wsptr[0] +
2239 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
2240 (ONE << (PASS1_BITS+2)));
2241 z1 <<= CONST_BITS;
2242 z4 = (INT32) wsptr[4];
2243 z2 = MULTIPLY(z4, FIX(1.274162392)); /* c4 */
2244 z3 = MULTIPLY(z4, FIX(0.314692123)); /* c12 */
2245 z4 = MULTIPLY(z4, FIX(0.881747734)); /* c8 */
2246
2247 tmp10 = z1 + z2;
2248 tmp11 = z1 + z3;
2249 tmp12 = z1 - z4;
2250
2251 tmp23 = z1 - ((z2 + z3 - z4) << 1); /* c0 = (c4+c12-c8)*2 */
2252
2253 z1 = (INT32) wsptr[2];
2254 z2 = (INT32) wsptr[6];
2255
2256 z3 = MULTIPLY(z1 + z2, FIX(1.105676686)); /* c6 */
2257
2258 tmp13 = z3 + MULTIPLY(z1, FIX(0.273079590)); /* c2-c6 */
2259 tmp14 = z3 - MULTIPLY(z2, FIX(1.719280954)); /* c6+c10 */
2260 tmp15 = MULTIPLY(z1, FIX(0.613604268)) - /* c10 */
2261 MULTIPLY(z2, FIX(1.378756276)); /* c2 */
2262
2263 tmp20 = tmp10 + tmp13;
2264 tmp26 = tmp10 - tmp13;
2265 tmp21 = tmp11 + tmp14;
2266 tmp25 = tmp11 - tmp14;
2267 tmp22 = tmp12 + tmp15;
2268 tmp24 = tmp12 - tmp15;
2269
2270 /* Odd part */
2271
2272 z1 = (INT32) wsptr[1];
2273 z2 = (INT32) wsptr[3];
2274 z3 = (INT32) wsptr[5];
2275 z4 = (INT32) wsptr[7];
2276 z4 <<= CONST_BITS;
2277
2278 tmp14 = z1 + z3;
2279 tmp11 = MULTIPLY(z1 + z2, FIX(1.334852607)); /* c3 */
2280 tmp12 = MULTIPLY(tmp14, FIX(1.197448846)); /* c5 */
2281 tmp10 = tmp11 + tmp12 + z4 - MULTIPLY(z1, FIX(1.126980169)); /* c3+c5-c1 */
2282 tmp14 = MULTIPLY(tmp14, FIX(0.752406978)); /* c9 */
2283 tmp16 = tmp14 - MULTIPLY(z1, FIX(1.061150426)); /* c9+c11-c13 */
2284 z1 -= z2;
2285 tmp15 = MULTIPLY(z1, FIX(0.467085129)) - z4; /* c11 */
2286 tmp16 += tmp15;
2287 tmp13 = MULTIPLY(z2 + z3, - FIX(0.158341681)) - z4; /* -c13 */
2288 tmp11 += tmp13 - MULTIPLY(z2, FIX(0.424103948)); /* c3-c9-c13 */
2289 tmp12 += tmp13 - MULTIPLY(z3, FIX(2.373959773)); /* c3+c5-c13 */
2290 tmp13 = MULTIPLY(z3 - z2, FIX(1.405321284)); /* c1 */
2291 tmp14 += tmp13 + z4 - MULTIPLY(z3, FIX(1.6906431334)); /* c1+c9-c11 */
2292 tmp15 += tmp13 + MULTIPLY(z2, FIX(0.674957567)); /* c1+c11-c5 */
2293
2294 tmp13 = ((z1 - z3) << CONST_BITS) + z4;
2295
2296 /* Final output stage */
2297
2298 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,
2299 CONST_BITS+PASS1_BITS+3)
2300 & RANGE_MASK];
2301 outptr[13] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,
2302 CONST_BITS+PASS1_BITS+3)
2303 & RANGE_MASK];
2304 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,
2305 CONST_BITS+PASS1_BITS+3)
2306 & RANGE_MASK];
2307 outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,
2308 CONST_BITS+PASS1_BITS+3)
2309 & RANGE_MASK];
2310 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,
2311 CONST_BITS+PASS1_BITS+3)
2312 & RANGE_MASK];
2313 outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,
2314 CONST_BITS+PASS1_BITS+3)
2315 & RANGE_MASK];
2316 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,
2317 CONST_BITS+PASS1_BITS+3)
2318 & RANGE_MASK];
2319 outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,
2320 CONST_BITS+PASS1_BITS+3)
2321 & RANGE_MASK];
2322 outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,
2323 CONST_BITS+PASS1_BITS+3)
2324 & RANGE_MASK];
2325 outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,
2326 CONST_BITS+PASS1_BITS+3)
2327 & RANGE_MASK];
2328 outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15,
2329 CONST_BITS+PASS1_BITS+3)
2330 & RANGE_MASK];
2331 outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15,
2332 CONST_BITS+PASS1_BITS+3)
2333 & RANGE_MASK];
2334 outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp26 + tmp16,
2335 CONST_BITS+PASS1_BITS+3)
2336 & RANGE_MASK];
2337 outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp26 - tmp16,
2338 CONST_BITS+PASS1_BITS+3)
2339 & RANGE_MASK];
2340
2341 wsptr += 8; /* advance pointer to next row */
2342 }
2343 }
2344
2345
2346 /*
2347 * Perform dequantization and inverse DCT on one block of coefficients,
2348 * producing a 15x15 output block.
2349 *
2350 * Optimized algorithm with 22 multiplications in the 1-D kernel.
2351 * cK represents sqrt(2) * cos(K*pi/30).
2352 */
2353
2354 GLOBAL(void)
2355 jpeg_idct_15x15 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
2356 JCOEFPTR coef_block,
2357 JSAMPARRAY output_buf, JDIMENSION output_col)
2358 {
2359 INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
2360 INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;
2361 INT32 z1, z2, z3, z4;
2362 JCOEFPTR inptr;
2363 ISLOW_MULT_TYPE * quantptr;
2364 int * wsptr;
2365 JSAMPROW outptr;
2366 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
2367 int ctr;
2368 int workspace[8*15]; /* buffers data between passes */
2369 SHIFT_TEMPS
2370
2371 /* Pass 1: process columns from input, store into work array. */
2372
2373 inptr = coef_block;
2374 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
2375 wsptr = workspace;
2376 for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
2377 /* Even part */
2378
2379 z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
2380 z1 <<= CONST_BITS;
2381 /* Add fudge factor here for final descale. */
2382 z1 += ONE << (CONST_BITS-PASS1_BITS-1);
2383
2384 z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
2385 z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
2386 z4 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
2387
2388 tmp10 = MULTIPLY(z4, FIX(0.437016024)); /* c12 */
2389 tmp11 = MULTIPLY(z4, FIX(1.144122806)); /* c6 */
2390
2391 tmp12 = z1 - tmp10;
2392 tmp13 = z1 + tmp11;
2393 z1 -= (tmp11 - tmp10) << 1; /* c0 = (c6-c12)*2 */
2394
2395 z4 = z2 - z3;
2396 z3 += z2;
2397 tmp10 = MULTIPLY(z3, FIX(1.337628990)); /* (c2+c4)/2 */
2398 tmp11 = MULTIPLY(z4, FIX(0.045680613)); /* (c2-c4)/2 */
2399 z2 = MULTIPLY(z2, FIX(1.439773946)); /* c4+c14 */
2400
2401 tmp20 = tmp13 + tmp10 + tmp11;
2402 tmp23 = tmp12 - tmp10 + tmp11 + z2;
2403
2404 tmp10 = MULTIPLY(z3, FIX(0.547059574)); /* (c8+c14)/2 */
2405 tmp11 = MULTIPLY(z4, FIX(0.399234004)); /* (c8-c14)/2 */
2406
2407 tmp25 = tmp13 - tmp10 - tmp11;
2408 tmp26 = tmp12 + tmp10 - tmp11 - z2;
2409
2410 tmp10 = MULTIPLY(z3, FIX(0.790569415)); /* (c6+c12)/2 */
2411 tmp11 = MULTIPLY(z4, FIX(0.353553391)); /* (c6-c12)/2 */
2412
2413 tmp21 = tmp12 + tmp10 + tmp11;
2414 tmp24 = tmp13 - tmp10 + tmp11;
2415 tmp11 += tmp11;
2416 tmp22 = z1 + tmp11; /* c10 = c6-c12 */
2417 tmp27 = z1 - tmp11 - tmp11; /* c0 = (c6-c12)*2 */
2418
2419 /* Odd part */
2420
2421 z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
2422 z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
2423 z4 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
2424 z3 = MULTIPLY(z4, FIX(1.224744871)); /* c5 */
2425 z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
2426
2427 tmp13 = z2 - z4;
2428 tmp15 = MULTIPLY(z1 + tmp13, FIX(0.831253876)); /* c9 */
2429 tmp11 = tmp15 + MULTIPLY(z1, FIX(0.513743148)); /* c3-c9 */
2430 tmp14 = tmp15 - MULTIPLY(tmp13, FIX(2.176250899)); /* c3+c9 */
2431
2432 tmp13 = MULTIPLY(z2, - FIX(0.831253876)); /* -c9 */
2433 tmp15 = MULTIPLY(z2, - FIX(1.344997024)); /* -c3 */
2434 z2 = z1 - z4;
2435 tmp12 = z3 + MULTIPLY(z2, FIX(1.406466353)); /* c1 */
2436
2437 tmp10 = tmp12 + MULTIPLY(z4, FIX(2.457431844)) - tmp15; /* c1+c7 */
2438 tmp16 = tmp12 - MULTIPLY(z1, FIX(1.112434820)) + tmp13; /* c1-c13 */
2439 tmp12 = MULTIPLY(z2, FIX(1.224744871)) - z3; /* c5 */
2440 z2 = MULTIPLY(z1 + z4, FIX(0.575212477)); /* c11 */
2441 tmp13 += z2 + MULTIPLY(z1, FIX(0.475753014)) - z3; /* c7-c11 */
2442 tmp15 += z2 - MULTIPLY(z4, FIX(0.869244010)) + z3; /* c11+c13 */
2443
2444 /* Final output stage */
2445
2446 wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);
2447 wsptr[8*14] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);
2448 wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);
2449 wsptr[8*13] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);
2450 wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);
2451 wsptr[8*12] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);
2452 wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS);
2453 wsptr[8*11] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS);
2454 wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);
2455 wsptr[8*10] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);
2456 wsptr[8*5] = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS);
2457 wsptr[8*9] = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS);
2458 wsptr[8*6] = (int) RIGHT_SHIFT(tmp26 + tmp16, CONST_BITS-PASS1_BITS);
2459 wsptr[8*8] = (int) RIGHT_SHIFT(tmp26 - tmp16, CONST_BITS-PASS1_BITS);
2460 wsptr[8*7] = (int) RIGHT_SHIFT(tmp27, CONST_BITS-PASS1_BITS);
2461 }
2462
2463 /* Pass 2: process 15 rows from work array, store into output array. */
2464
2465 wsptr = workspace;
2466 for (ctr = 0; ctr < 15; ctr++) {
2467 outptr = output_buf[ctr] + output_col;
2468
2469 /* Even part */
2470
2471 /* Add range center and fudge factor for final descale and range-limit. */
2472 z1 = (INT32) wsptr[0] +
2473 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
2474 (ONE << (PASS1_BITS+2)));
2475 z1 <<= CONST_BITS;
2476
2477 z2 = (INT32) wsptr[2];
2478 z3 = (INT32) wsptr[4];
2479 z4 = (INT32) wsptr[6];
2480
2481 tmp10 = MULTIPLY(z4, FIX(0.437016024)); /* c12 */
2482 tmp11 = MULTIPLY(z4, FIX(1.144122806)); /* c6 */
2483
2484 tmp12 = z1 - tmp10;
2485 tmp13 = z1 + tmp11;
2486 z1 -= (tmp11 - tmp10) << 1; /* c0 = (c6-c12)*2 */
2487
2488 z4 = z2 - z3;
2489 z3 += z2;
2490 tmp10 = MULTIPLY(z3, FIX(1.337628990)); /* (c2+c4)/2 */
2491 tmp11 = MULTIPLY(z4, FIX(0.045680613)); /* (c2-c4)/2 */
2492 z2 = MULTIPLY(z2, FIX(1.439773946)); /* c4+c14 */
2493
2494 tmp20 = tmp13 + tmp10 + tmp11;
2495 tmp23 = tmp12 - tmp10 + tmp11 + z2;
2496
2497 tmp10 = MULTIPLY(z3, FIX(0.547059574)); /* (c8+c14)/2 */
2498 tmp11 = MULTIPLY(z4, FIX(0.399234004)); /* (c8-c14)/2 */
2499
2500 tmp25 = tmp13 - tmp10 - tmp11;
2501 tmp26 = tmp12 + tmp10 - tmp11 - z2;
2502
2503 tmp10 = MULTIPLY(z3, FIX(0.790569415)); /* (c6+c12)/2 */
2504 tmp11 = MULTIPLY(z4, FIX(0.353553391)); /* (c6-c12)/2 */
2505
2506 tmp21 = tmp12 + tmp10 + tmp11;
2507 tmp24 = tmp13 - tmp10 + tmp11;
2508 tmp11 += tmp11;
2509 tmp22 = z1 + tmp11; /* c10 = c6-c12 */
2510 tmp27 = z1 - tmp11 - tmp11; /* c0 = (c6-c12)*2 */
2511
2512 /* Odd part */
2513
2514 z1 = (INT32) wsptr[1];
2515 z2 = (INT32) wsptr[3];
2516 z4 = (INT32) wsptr[5];
2517 z3 = MULTIPLY(z4, FIX(1.224744871)); /* c5 */
2518 z4 = (INT32) wsptr[7];
2519
2520 tmp13 = z2 - z4;
2521 tmp15 = MULTIPLY(z1 + tmp13, FIX(0.831253876)); /* c9 */
2522 tmp11 = tmp15 + MULTIPLY(z1, FIX(0.513743148)); /* c3-c9 */
2523 tmp14 = tmp15 - MULTIPLY(tmp13, FIX(2.176250899)); /* c3+c9 */
2524
2525 tmp13 = MULTIPLY(z2, - FIX(0.831253876)); /* -c9 */
2526 tmp15 = MULTIPLY(z2, - FIX(1.344997024)); /* -c3 */
2527 z2 = z1 - z4;
2528 tmp12 = z3 + MULTIPLY(z2, FIX(1.406466353)); /* c1 */
2529
2530 tmp10 = tmp12 + MULTIPLY(z4, FIX(2.457431844)) - tmp15; /* c1+c7 */
2531 tmp16 = tmp12 - MULTIPLY(z1, FIX(1.112434820)) + tmp13; /* c1-c13 */
2532 tmp12 = MULTIPLY(z2, FIX(1.224744871)) - z3; /* c5 */
2533 z2 = MULTIPLY(z1 + z4, FIX(0.575212477)); /* c11 */
2534 tmp13 += z2 + MULTIPLY(z1, FIX(0.475753014)) - z3; /* c7-c11 */
2535 tmp15 += z2 - MULTIPLY(z4, FIX(0.869244010)) + z3; /* c11+c13 */
2536
2537 /* Final output stage */
2538
2539 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,
2540 CONST_BITS+PASS1_BITS+3)
2541 & RANGE_MASK];
2542 outptr[14] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,
2543 CONST_BITS+PASS1_BITS+3)
2544 & RANGE_MASK];
2545 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,
2546 CONST_BITS+PASS1_BITS+3)
2547 & RANGE_MASK];
2548 outptr[13] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,
2549 CONST_BITS+PASS1_BITS+3)
2550 & RANGE_MASK];
2551 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,
2552 CONST_BITS+PASS1_BITS+3)
2553 & RANGE_MASK];
2554 outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,
2555 CONST_BITS+PASS1_BITS+3)
2556 & RANGE_MASK];
2557 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,
2558 CONST_BITS+PASS1_BITS+3)
2559 & RANGE_MASK];
2560 outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,
2561 CONST_BITS+PASS1_BITS+3)
2562 & RANGE_MASK];
2563 outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,
2564 CONST_BITS+PASS1_BITS+3)
2565 & RANGE_MASK];
2566 outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,
2567 CONST_BITS+PASS1_BITS+3)
2568 & RANGE_MASK];
2569 outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15,
2570 CONST_BITS+PASS1_BITS+3)
2571 & RANGE_MASK];
2572 outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15,
2573 CONST_BITS+PASS1_BITS+3)
2574 & RANGE_MASK];
2575 outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp26 + tmp16,
2576 CONST_BITS+PASS1_BITS+3)
2577 & RANGE_MASK];
2578 outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp26 - tmp16,
2579 CONST_BITS+PASS1_BITS+3)
2580 & RANGE_MASK];
2581 outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp27,
2582 CONST_BITS+PASS1_BITS+3)
2583 & RANGE_MASK];
2584
2585 wsptr += 8; /* advance pointer to next row */
2586 }
2587 }
2588
2589
2590 /*
2591 * Perform dequantization and inverse DCT on one block of coefficients,
2592 * producing a 16x16 output block.
2593 *
2594 * Optimized algorithm with 28 multiplications in the 1-D kernel.
2595 * cK represents sqrt(2) * cos(K*pi/32).
2596 */
2597
2598 GLOBAL(void)
2599 jpeg_idct_16x16 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
2600 JCOEFPTR coef_block,
2601 JSAMPARRAY output_buf, JDIMENSION output_col)
2602 {
2603 INT32 tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13;
2604 INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;
2605 INT32 z1, z2, z3, z4;
2606 JCOEFPTR inptr;
2607 ISLOW_MULT_TYPE * quantptr;
2608 int * wsptr;
2609 JSAMPROW outptr;
2610 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
2611 int ctr;
2612 int workspace[8*16]; /* buffers data between passes */
2613 SHIFT_TEMPS
2614
2615 /* Pass 1: process columns from input, store into work array. */
2616
2617 inptr = coef_block;
2618 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
2619 wsptr = workspace;
2620 for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
2621 /* Even part */
2622
2623 tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
2624 tmp0 <<= CONST_BITS;
2625 /* Add fudge factor here for final descale. */
2626 tmp0 += 1 << (CONST_BITS-PASS1_BITS-1);
2627
2628 z1 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
2629 tmp1 = MULTIPLY(z1, FIX(1.306562965)); /* c4[16] = c2[8] */
2630 tmp2 = MULTIPLY(z1, FIX_0_541196100); /* c12[16] = c6[8] */
2631
2632 tmp10 = tmp0 + tmp1;
2633 tmp11 = tmp0 - tmp1;
2634 tmp12 = tmp0 + tmp2;
2635 tmp13 = tmp0 - tmp2;
2636
2637 z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
2638 z2 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
2639 z3 = z1 - z2;
2640 z4 = MULTIPLY(z3, FIX(0.275899379)); /* c14[16] = c7[8] */
2641 z3 = MULTIPLY(z3, FIX(1.387039845)); /* c2[16] = c1[8] */
2642
2643 tmp0 = z3 + MULTIPLY(z2, FIX_2_562915447); /* (c6+c2)[16] = (c3+c1)[8] */
2644 tmp1 = z4 + MULTIPLY(z1, FIX_0_899976223); /* (c6-c14)[16] = (c3-c7)[8] */
2645 tmp2 = z3 - MULTIPLY(z1, FIX(0.601344887)); /* (c2-c10)[16] = (c1-c5)[8] */
2646 tmp3 = z4 - MULTIPLY(z2, FIX(0.509795579)); /* (c10-c14)[16] = (c5-c7)[8] */
2647
2648 tmp20 = tmp10 + tmp0;
2649 tmp27 = tmp10 - tmp0;
2650 tmp21 = tmp12 + tmp1;
2651 tmp26 = tmp12 - tmp1;
2652 tmp22 = tmp13 + tmp2;
2653 tmp25 = tmp13 - tmp2;
2654 tmp23 = tmp11 + tmp3;
2655 tmp24 = tmp11 - tmp3;
2656
2657 /* Odd part */
2658
2659 z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
2660 z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
2661 z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
2662 z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
2663
2664 tmp11 = z1 + z3;
2665
2666 tmp1 = MULTIPLY(z1 + z2, FIX(1.353318001)); /* c3 */
2667 tmp2 = MULTIPLY(tmp11, FIX(1.247225013)); /* c5 */
2668 tmp3 = MULTIPLY(z1 + z4, FIX(1.093201867)); /* c7 */
2669 tmp10 = MULTIPLY(z1 - z4, FIX(0.897167586)); /* c9 */
2670 tmp11 = MULTIPLY(tmp11, FIX(0.666655658)); /* c11 */
2671 tmp12 = MULTIPLY(z1 - z2, FIX(0.410524528)); /* c13 */
2672 tmp0 = tmp1 + tmp2 + tmp3 -
2673 MULTIPLY(z1, FIX(2.286341144)); /* c7+c5+c3-c1 */
2674 tmp13 = tmp10 + tmp11 + tmp12 -
2675 MULTIPLY(z1, FIX(1.835730603)); /* c9+c11+c13-c15 */
2676 z1 = MULTIPLY(z2 + z3, FIX(0.138617169)); /* c15 */
2677 tmp1 += z1 + MULTIPLY(z2, FIX(0.071888074)); /* c9+c11-c3-c15 */
2678 tmp2 += z1 - MULTIPLY(z3, FIX(1.125726048)); /* c5+c7+c15-c3 */
2679 z1 = MULTIPLY(z3 - z2, FIX(1.407403738)); /* c1 */
2680 tmp11 += z1 - MULTIPLY(z3, FIX(0.766367282)); /* c1+c11-c9-c13 */
2681 tmp12 += z1 + MULTIPLY(z2, FIX(1.971951411)); /* c1+c5+c13-c7 */
2682 z2 += z4;
2683 z1 = MULTIPLY(z2, - FIX(0.666655658)); /* -c11 */
2684 tmp1 += z1;
2685 tmp3 += z1 + MULTIPLY(z4, FIX(1.065388962)); /* c3+c11+c15-c7 */
2686 z2 = MULTIPLY(z2, - FIX(1.247225013)); /* -c5 */
2687 tmp10 += z2 + MULTIPLY(z4, FIX(3.141271809)); /* c1+c5+c9-c13 */
2688 tmp12 += z2;
2689 z2 = MULTIPLY(z3 + z4, - FIX(1.353318001)); /* -c3 */
2690 tmp2 += z2;
2691 tmp3 += z2;
2692 z2 = MULTIPLY(z4 - z3, FIX(0.410524528)); /* c13 */
2693 tmp10 += z2;
2694 tmp11 += z2;
2695
2696 /* Final output stage */
2697
2698 wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp0, CONST_BITS-PASS1_BITS);
2699 wsptr[8*15] = (int) RIGHT_SHIFT(tmp20 - tmp0, CONST_BITS-PASS1_BITS);
2700 wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp1, CONST_BITS-PASS1_BITS);
2701 wsptr[8*14] = (int) RIGHT_SHIFT(tmp21 - tmp1, CONST_BITS-PASS1_BITS);
2702 wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp2, CONST_BITS-PASS1_BITS);
2703 wsptr[8*13] = (int) RIGHT_SHIFT(tmp22 - tmp2, CONST_BITS-PASS1_BITS);
2704 wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp3, CONST_BITS-PASS1_BITS);
2705 wsptr[8*12] = (int) RIGHT_SHIFT(tmp23 - tmp3, CONST_BITS-PASS1_BITS);
2706 wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp10, CONST_BITS-PASS1_BITS);
2707 wsptr[8*11] = (int) RIGHT_SHIFT(tmp24 - tmp10, CONST_BITS-PASS1_BITS);
2708 wsptr[8*5] = (int) RIGHT_SHIFT(tmp25 + tmp11, CONST_BITS-PASS1_BITS);
2709 wsptr[8*10] = (int) RIGHT_SHIFT(tmp25 - tmp11, CONST_BITS-PASS1_BITS);
2710 wsptr[8*6] = (int) RIGHT_SHIFT(tmp26 + tmp12, CONST_BITS-PASS1_BITS);
2711 wsptr[8*9] = (int) RIGHT_SHIFT(tmp26 - tmp12, CONST_BITS-PASS1_BITS);
2712 wsptr[8*7] = (int) RIGHT_SHIFT(tmp27 + tmp13, CONST_BITS-PASS1_BITS);
2713 wsptr[8*8] = (int) RIGHT_SHIFT(tmp27 - tmp13, CONST_BITS-PASS1_BITS);
2714 }
2715
2716 /* Pass 2: process 16 rows from work array, store into output array. */
2717
2718 wsptr = workspace;
2719 for (ctr = 0; ctr < 16; ctr++) {
2720 outptr = output_buf[ctr] + output_col;
2721
2722 /* Even part */
2723
2724 /* Add range center and fudge factor for final descale and range-limit. */
2725 tmp0 = (INT32) wsptr[0] +
2726 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
2727 (ONE << (PASS1_BITS+2)));
2728 tmp0 <<= CONST_BITS;
2729
2730 z1 = (INT32) wsptr[4];
2731 tmp1 = MULTIPLY(z1, FIX(1.306562965)); /* c4[16] = c2[8] */
2732 tmp2 = MULTIPLY(z1, FIX_0_541196100); /* c12[16] = c6[8] */
2733
2734 tmp10 = tmp0 + tmp1;
2735 tmp11 = tmp0 - tmp1;
2736 tmp12 = tmp0 + tmp2;
2737 tmp13 = tmp0 - tmp2;
2738
2739 z1 = (INT32) wsptr[2];
2740 z2 = (INT32) wsptr[6];
2741 z3 = z1 - z2;
2742 z4 = MULTIPLY(z3, FIX(0.275899379)); /* c14[16] = c7[8] */
2743 z3 = MULTIPLY(z3, FIX(1.387039845)); /* c2[16] = c1[8] */
2744
2745 tmp0 = z3 + MULTIPLY(z2, FIX_2_562915447); /* (c6+c2)[16] = (c3+c1)[8] */
2746 tmp1 = z4 + MULTIPLY(z1, FIX_0_899976223); /* (c6-c14)[16] = (c3-c7)[8] */
2747 tmp2 = z3 - MULTIPLY(z1, FIX(0.601344887)); /* (c2-c10)[16] = (c1-c5)[8] */
2748 tmp3 = z4 - MULTIPLY(z2, FIX(0.509795579)); /* (c10-c14)[16] = (c5-c7)[8] */
2749
2750 tmp20 = tmp10 + tmp0;
2751 tmp27 = tmp10 - tmp0;
2752 tmp21 = tmp12 + tmp1;
2753 tmp26 = tmp12 - tmp1;
2754 tmp22 = tmp13 + tmp2;
2755 tmp25 = tmp13 - tmp2;
2756 tmp23 = tmp11 + tmp3;
2757 tmp24 = tmp11 - tmp3;
2758
2759 /* Odd part */
2760
2761 z1 = (INT32) wsptr[1];
2762 z2 = (INT32) wsptr[3];
2763 z3 = (INT32) wsptr[5];
2764 z4 = (INT32) wsptr[7];
2765
2766 tmp11 = z1 + z3;
2767
2768 tmp1 = MULTIPLY(z1 + z2, FIX(1.353318001)); /* c3 */
2769 tmp2 = MULTIPLY(tmp11, FIX(1.247225013)); /* c5 */
2770 tmp3 = MULTIPLY(z1 + z4, FIX(1.093201867)); /* c7 */
2771 tmp10 = MULTIPLY(z1 - z4, FIX(0.897167586)); /* c9 */
2772 tmp11 = MULTIPLY(tmp11, FIX(0.666655658)); /* c11 */
2773 tmp12 = MULTIPLY(z1 - z2, FIX(0.410524528)); /* c13 */
2774 tmp0 = tmp1 + tmp2 + tmp3 -
2775 MULTIPLY(z1, FIX(2.286341144)); /* c7+c5+c3-c1 */
2776 tmp13 = tmp10 + tmp11 + tmp12 -
2777 MULTIPLY(z1, FIX(1.835730603)); /* c9+c11+c13-c15 */
2778 z1 = MULTIPLY(z2 + z3, FIX(0.138617169)); /* c15 */
2779 tmp1 += z1 + MULTIPLY(z2, FIX(0.071888074)); /* c9+c11-c3-c15 */
2780 tmp2 += z1 - MULTIPLY(z3, FIX(1.125726048)); /* c5+c7+c15-c3 */
2781 z1 = MULTIPLY(z3 - z2, FIX(1.407403738)); /* c1 */
2782 tmp11 += z1 - MULTIPLY(z3, FIX(0.766367282)); /* c1+c11-c9-c13 */
2783 tmp12 += z1 + MULTIPLY(z2, FIX(1.971951411)); /* c1+c5+c13-c7 */
2784 z2 += z4;
2785 z1 = MULTIPLY(z2, - FIX(0.666655658)); /* -c11 */
2786 tmp1 += z1;
2787 tmp3 += z1 + MULTIPLY(z4, FIX(1.065388962)); /* c3+c11+c15-c7 */
2788 z2 = MULTIPLY(z2, - FIX(1.247225013)); /* -c5 */
2789 tmp10 += z2 + MULTIPLY(z4, FIX(3.141271809)); /* c1+c5+c9-c13 */
2790 tmp12 += z2;
2791 z2 = MULTIPLY(z3 + z4, - FIX(1.353318001)); /* -c3 */
2792 tmp2 += z2;
2793 tmp3 += z2;
2794 z2 = MULTIPLY(z4 - z3, FIX(0.410524528)); /* c13 */
2795 tmp10 += z2;
2796 tmp11 += z2;
2797
2798 /* Final output stage */
2799
2800 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp0,
2801 CONST_BITS+PASS1_BITS+3)
2802 & RANGE_MASK];
2803 outptr[15] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp0,
2804 CONST_BITS+PASS1_BITS+3)
2805 & RANGE_MASK];
2806 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp1,
2807 CONST_BITS+PASS1_BITS+3)
2808 & RANGE_MASK];
2809 outptr[14] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp1,
2810 CONST_BITS+PASS1_BITS+3)
2811 & RANGE_MASK];
2812 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp2,
2813 CONST_BITS+PASS1_BITS+3)
2814 & RANGE_MASK];
2815 outptr[13] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp2,
2816 CONST_BITS+PASS1_BITS+3)
2817 & RANGE_MASK];
2818 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp3,
2819 CONST_BITS+PASS1_BITS+3)
2820 & RANGE_MASK];
2821 outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp3,
2822 CONST_BITS+PASS1_BITS+3)
2823 & RANGE_MASK];
2824 outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp10,
2825 CONST_BITS+PASS1_BITS+3)
2826 & RANGE_MASK];
2827 outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp10,
2828 CONST_BITS+PASS1_BITS+3)
2829 & RANGE_MASK];
2830 outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp11,
2831 CONST_BITS+PASS1_BITS+3)
2832 & RANGE_MASK];
2833 outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp11,
2834 CONST_BITS+PASS1_BITS+3)
2835 & RANGE_MASK];
2836 outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp26 + tmp12,
2837 CONST_BITS+PASS1_BITS+3)
2838 & RANGE_MASK];
2839 outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp26 - tmp12,
2840 CONST_BITS+PASS1_BITS+3)
2841 & RANGE_MASK];
2842 outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp27 + tmp13,
2843 CONST_BITS+PASS1_BITS+3)
2844 & RANGE_MASK];
2845 outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp27 - tmp13,
2846 CONST_BITS+PASS1_BITS+3)
2847 & RANGE_MASK];
2848
2849 wsptr += 8; /* advance pointer to next row */
2850 }
2851 }
2852
2853
2854 /*
2855 * Perform dequantization and inverse DCT on one block of coefficients,
2856 * producing a 16x8 output block.
2857 *
2858 * 8-point IDCT in pass 1 (columns), 16-point in pass 2 (rows).
2859 */
2860
2861 GLOBAL(void)
2862 jpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
2863 JCOEFPTR coef_block,
2864 JSAMPARRAY output_buf, JDIMENSION output_col)
2865 {
2866 INT32 tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13;
2867 INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;
2868 INT32 z1, z2, z3, z4;
2869 JCOEFPTR inptr;
2870 ISLOW_MULT_TYPE * quantptr;
2871 int * wsptr;
2872 JSAMPROW outptr;
2873 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
2874 int ctr;
2875 int workspace[8*8]; /* buffers data between passes */
2876 SHIFT_TEMPS
2877
2878 /* Pass 1: process columns from input, store into work array.
2879 * Note results are scaled up by sqrt(8) compared to a true IDCT;
2880 * furthermore, we scale the results by 2**PASS1_BITS.
2881 * 8-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
2882 */
2883
2884 inptr = coef_block;
2885 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
2886 wsptr = workspace;
2887 for (ctr = DCTSIZE; ctr > 0; ctr--) {
2888 /* Due to quantization, we will usually find that many of the input
2889 * coefficients are zero, especially the AC terms. We can exploit this
2890 * by short-circuiting the IDCT calculation for any column in which all
2891 * the AC terms are zero. In that case each output is equal to the
2892 * DC coefficient (with scale factor as needed).
2893 * With typical images and quantization tables, half or more of the
2894 * column DCT calculations can be simplified this way.
2895 */
2896
2897 if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
2898 inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
2899 inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
2900 inptr[DCTSIZE*7] == 0) {
2901 /* AC terms all zero */
2902 int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
2903
2904 wsptr[DCTSIZE*0] = dcval;
2905 wsptr[DCTSIZE*1] = dcval;
2906 wsptr[DCTSIZE*2] = dcval;
2907 wsptr[DCTSIZE*3] = dcval;
2908 wsptr[DCTSIZE*4] = dcval;
2909 wsptr[DCTSIZE*5] = dcval;
2910 wsptr[DCTSIZE*6] = dcval;
2911 wsptr[DCTSIZE*7] = dcval;
2912
2913 inptr++; /* advance pointers to next column */
2914 quantptr++;
2915 wsptr++;
2916 continue;
2917 }
2918
2919 /* Even part: reverse the even part of the forward DCT.
2920 * The rotator is c(-6).
2921 */
2922
2923 z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
2924 z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
2925
2926 z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
2927 tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
2928 tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
2929
2930 z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
2931 z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
2932 z2 <<= CONST_BITS;
2933 z3 <<= CONST_BITS;
2934 /* Add fudge factor here for final descale. */
2935 z2 += ONE << (CONST_BITS-PASS1_BITS-1);
2936
2937 tmp0 = z2 + z3;
2938 tmp1 = z2 - z3;
2939
2940 tmp10 = tmp0 + tmp2;
2941 tmp13 = tmp0 - tmp2;
2942 tmp11 = tmp1 + tmp3;
2943 tmp12 = tmp1 - tmp3;
2944
2945 /* Odd part per figure 8; the matrix is unitary and hence its
2946 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
2947 */
2948
2949 tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
2950 tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
2951 tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
2952 tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
2953
2954 z2 = tmp0 + tmp2;
2955 z3 = tmp1 + tmp3;
2956
2957 z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* c3 */
2958 z2 = MULTIPLY(z2, - FIX_1_961570560); /* -c3-c5 */
2959 z3 = MULTIPLY(z3, - FIX_0_390180644); /* -c3+c5 */
2960 z2 += z1;
2961 z3 += z1;
2962
2963 z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
2964 tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* -c1+c3+c5-c7 */
2965 tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* c1+c3-c5-c7 */
2966 tmp0 += z1 + z2;
2967 tmp3 += z1 + z3;
2968
2969 z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
2970 tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* c1+c3-c5+c7 */
2971 tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* c1+c3+c5-c7 */
2972 tmp1 += z1 + z3;
2973 tmp2 += z1 + z2;
2974
2975 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
2976
2977 wsptr[DCTSIZE*0] = (int) RIGHT_SHIFT(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
2978 wsptr[DCTSIZE*7] = (int) RIGHT_SHIFT(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
2979 wsptr[DCTSIZE*1] = (int) RIGHT_SHIFT(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
2980 wsptr[DCTSIZE*6] = (int) RIGHT_SHIFT(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
2981 wsptr[DCTSIZE*2] = (int) RIGHT_SHIFT(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
2982 wsptr[DCTSIZE*5] = (int) RIGHT_SHIFT(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
2983 wsptr[DCTSIZE*3] = (int) RIGHT_SHIFT(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
2984 wsptr[DCTSIZE*4] = (int) RIGHT_SHIFT(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
2985
2986 inptr++; /* advance pointers to next column */
2987 quantptr++;
2988 wsptr++;
2989 }
2990
2991 /* Pass 2: process 8 rows from work array, store into output array.
2992 * 16-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/32).
2993 */
2994
2995 wsptr = workspace;
2996 for (ctr = 0; ctr < 8; ctr++) {
2997 outptr = output_buf[ctr] + output_col;
2998
2999 /* Even part */
3000
3001 /* Add range center and fudge factor for final descale and range-limit. */
3002 tmp0 = (INT32) wsptr[0] +
3003 ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +
3004 (ONE << (PASS1_BITS+2)));
3005 tmp0 <<= CONST_BITS;
3006
3007 z1 = (INT32) wsptr[4];
3008 tmp1 = MULTIPLY(z1, FIX(1.306562965)); /* c4[16] = c2[8] */
3009 tmp2 = MULTIPLY(z1, FIX_0_541196100); /* c12[16] = c6[8] */
3010
3011 tmp10 = tmp0 + tmp1;
3012 tmp11 = tmp0 - tmp1;
3013 tmp12 = tmp0 + tmp2;
3014 tmp13 = tmp0 - tmp2;
3015
3016 z1 = (INT32) wsptr[2];
3017 z2 = (INT32) wsptr[6];
3018 z3 = z1 - z2;
3019 z4 = MULTIPLY(z3, FIX(0.275899379)); /* c14[16] = c7[8] */
3020 z3 = MULTIPLY(z3, FIX(1.387039845)); /* c2[16] = c1[8] */
3021
3022 tmp0 = z3 + MULTIPLY(z2, FIX_2_562915447); /* (c6+c2)[16] = (c3+c1)[8] */
3023 tmp1 = z4 + MULTIPLY(z1, FIX_0_899976223); /* (c6-c14)[16] = (c3-c7)[8] */
3024 tmp2 = z3 - MULTIPLY(z1, FIX(0.601344887)); /* (c2-c10)[16] = (c1-c5)[8] */
3025 tmp3 = z4 - MULTIPLY(z2, FIX(0.509795579)); /* (c10-c14)[16] = (c5-c7)[8] */
3026
3027 tmp20 = tmp10 + tmp0;
3028 tmp27 = tmp10 - tmp0;
3029 tmp21 = tmp12 + tmp1;
3030 tmp26 = tmp12 - tmp1;
3031 tmp22 = tmp13 + tmp2;
3032 tmp25 = tmp13 - tmp2;
3033 tmp23 = tmp11 + tmp3;
3034 tmp24 = tmp11 - tmp3;
3035
3036 /* Odd part */
3037
3038 z1 = (INT32) wsptr[1];
3039 z2 = (INT32) wsptr[3];
3040 z3 = (INT32) wsptr[5];
3041 z4 = (INT32) wsptr[7];
3042
3043 tmp11 = z1 + z3;
3044
3045 tmp1 = MULTIPLY(z1 + z2, FIX(1.353318001)); /* c3 */
3046 tmp2 = MULTIPLY(tmp11, FIX(1.247225013)); /* c5 */
3047 tmp3 = MULTIPLY(z1 + z4, FIX(1.093201867)); /* c7 */
3048 tmp10 = MULTIPLY(z1 - z4, FIX(0.897167586)); /* c9 */
3049 tmp11 = MULTIPLY(tmp11, FIX(0.666655658)); /* c11 */
3050 tmp12 = MULTIPLY(z1 - z2, FIX(0.410524528)); /* c13 */
3051 tmp0 = tmp1 + tmp2 + tmp3 -
3052 MULTIPLY(z1, FIX(2.286341144)); /* c7+c5+c3-c1 */
3053 tmp13 = tmp10 + tmp11 + tmp12 -
3054 MULTIPLY(z1, FIX(1.835730603)); /* c9+c11+c13-c15 */
3055 z1 = MULTIPLY(z2 + z3, FIX(0.138617169)); /* c15 */
3056 tmp1 += z1 + MULTIPLY(z2, FIX(0.071888074)); /* c9+c11-c3-c15 */
3057 tmp2 += z1 - MULTIPLY(z3, FIX(1.125726048)); /* c5+c7+c15-c3 */
3058 z1 = MULTIPLY(z3 - z2, FIX(1.407403738)); /* c1 */
3059 tmp11 += z1 - MULTIPLY(z3, FIX(0.766367282)); /* c1+c11-c9-c13 */
3060 tmp12 += z1 + MULTIPLY(z2, FIX(1.971951411)); /* c1+c5+c13-c7 */
3061 z2 += z4;
3062 z1 = MULTIPLY(z2, - FIX(0.666655658)); /* -c11 */
3063 tmp1 += z1;
3064 tmp3 += z1 + MULTIPLY(z4, FIX(1.065388962)); /* c3+c11+c15-c7 */
3065 z2 = MULTIPLY(z2, - FIX(1.247225013)); /* -c5 */
3066 tmp10 += z2 + MULTIPLY(z4, FIX(3.141271809)); /* c1+c5+c9-c13 */
3067 tmp12 += z2;
3068 z2 = MULTIPLY(z3 + z4, - FIX(1.353318001)); /* -c3 */
3069 tmp2 += z2;
3070 tmp3 += z2;
3071 z2 = MULTIPLY(z4 - z3, FIX(0.410524528)); /* c13 */
3072 tmp10 += z2;
3073 tmp11 += z2;
3074
3075 /* Final output stage */
3076
3077 outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp0,
3078 CONST_BITS+PASS1_BITS+3)
3079 & RANGE_MASK];
3080 outptr[15] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp0,
3081 CONST_BITS+PASS1_BITS+3)
3082 & RANGE_MASK];
3083 outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp1,
3084 CONST_BITS+PASS1_BITS+3)
3085 & RANGE_MASK];
3086 outptr[14] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp1,
3087 CONST_BITS+PASS1_BITS+3)
3088 & RANGE_MASK];
3089 outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp2,
3090 CONST_BITS+PASS1_BITS+3)
3091 & RANGE_MASK];
3092 outptr[13] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp2,
3093 CONST_BITS+PASS1_BITS+3)
3094 & RANGE_MASK];
3095 outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp3,
3096 CONST_BITS+PASS1_BITS+3)
3097 & RANGE_MASK];
3098 outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp3,
3099 CONST_BITS+PASS1_BITS+3)
3100 & RANGE_MASK];
3101 outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp10,
3102 CONST_BITS+PASS1_BITS+3)
3103 & RANGE_MASK];
3104 outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp10,
3105 CONST_BITS+PASS1_BITS+3)
3106 & RANGE_MASK];
3107 outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp11,
3108 CONST_BITS+PASS1_BITS+3)
3109 & RANGE_MASK];
3110 outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp11,
3111 CONST_BITS+PASS1_BITS+3)
3112 & RANGE_MASK];
3113 outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp26 + tmp12,
3114 CONST_BITS+PASS1_BITS+3)
3115 & RANGE_MASK];
3116 outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp26 - tmp12,
3117 CONST_BITS+PASS1_BITS+3)
3118 & RANGE_MASK];
3119 outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp27 + tmp13,
3120 CONST_BITS+PASS1_BITS+3)
3121 & RANGE_MASK];