blob: 4598698ffc3a5efbfe0d8e10076e933a2262260f [file] [log] [blame]
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +00001/*
2 * jidctred.c
3 *
DRC8e9cef22015-09-21 12:57:41 -05004 * This file was part of the Independent JPEG Group's software.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +00005 * Copyright (C) 1994-1998, Thomas G. Lane.
DRC8e9cef22015-09-21 12:57:41 -05006 * libjpeg-turbo Modifications:
7 * Copyright (C) 2015, D. R. Commander
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +00008 * For conditions of distribution and use, see the accompanying README file.
9 *
10 * This file contains inverse-DCT routines that produce reduced-size output:
11 * either 4x4, 2x2, or 1x1 pixels from an 8x8 DCT block.
12 *
13 * The implementation is based on the Loeffler, Ligtenberg and Moschytz (LL&M)
14 * algorithm used in jidctint.c. We simply replace each 8-to-8 1-D IDCT step
15 * with an 8-to-4 step that produces the four averages of two adjacent outputs
16 * (or an 8-to-2 step producing two averages of four outputs, for 2x2 output).
17 * These steps were derived by computing the corresponding values at the end
18 * of the normal LL&M code, then simplifying as much as possible.
19 *
20 * 1x1 is trivial: just take the DC coefficient divided by 8.
21 *
22 * See jidctint.c for additional comments.
23 */
24
25#define JPEG_INTERNALS
26#include "jinclude.h"
27#include "jpeglib.h"
DRCe5eaf372014-05-09 18:00:32 +000028#include "jdct.h" /* Private declarations for DCT subsystem */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000029
30#ifdef IDCT_SCALING_SUPPORTED
31
32
33/*
34 * This module is specialized to the case DCTSIZE = 8.
35 */
36
37#if DCTSIZE != 8
38 Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
39#endif
40
41
42/* Scaling is the same as in jidctint.c. */
43
44#if BITS_IN_JSAMPLE == 8
45#define CONST_BITS 13
46#define PASS1_BITS 2
47#else
48#define CONST_BITS 13
DRCe5eaf372014-05-09 18:00:32 +000049#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000050#endif
51
52/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
53 * causing a lot of useless floating-point operations at run time.
54 * To get around this we use the following pre-calculated constants.
55 * If you change CONST_BITS you may want to add appropriate values.
56 * (With a reasonable C compiler, you can just rely on the FIX() macro...)
57 */
58
59#if CONST_BITS == 13
DRCe5eaf372014-05-09 18:00:32 +000060#define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
61#define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
62#define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
63#define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
64#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
65#define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
66#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
67#define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
68#define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
69#define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
70#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
71#define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
72#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
73#define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000074#else
75#define FIX_0_211164243 FIX(0.211164243)
76#define FIX_0_509795579 FIX(0.509795579)
77#define FIX_0_601344887 FIX(0.601344887)
78#define FIX_0_720959822 FIX(0.720959822)
79#define FIX_0_765366865 FIX(0.765366865)
80#define FIX_0_850430095 FIX(0.850430095)
81#define FIX_0_899976223 FIX(0.899976223)
82#define FIX_1_061594337 FIX(1.061594337)
83#define FIX_1_272758580 FIX(1.272758580)
84#define FIX_1_451774981 FIX(1.451774981)
85#define FIX_1_847759065 FIX(1.847759065)
86#define FIX_2_172734803 FIX(2.172734803)
87#define FIX_2_562915447 FIX(2.562915447)
88#define FIX_3_624509785 FIX(3.624509785)
89#endif
90
91
92/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
93 * For 8-bit samples with the recommended scaling, all the variable
94 * and constant values involved are no more than 16 bits wide, so a
95 * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
96 * For 12-bit samples, a full 32-bit multiplication will be needed.
97 */
98
99#if BITS_IN_JSAMPLE == 8
100#define MULTIPLY(var,const) MULTIPLY16C16(var,const)
101#else
102#define MULTIPLY(var,const) ((var) * (const))
103#endif
104
105
106/* Dequantize a coefficient by multiplying it by the multiplier-table
107 * entry; produce an int result. In this module, both inputs and result
108 * are 16 bits or less, so either int or short multiply will work.
109 */
110
111#define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
112
113
114/*
115 * Perform dequantization and inverse DCT on one block of coefficients,
116 * producing a reduced-size 4x4 output block.
117 */
118
Thomas G. Lane489583f1996-02-07 00:00:00 +0000119GLOBAL(void)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000120jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
DRCe5eaf372014-05-09 18:00:32 +0000121 JCOEFPTR coef_block,
122 JSAMPARRAY output_buf, JDIMENSION output_col)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000123{
124 INT32 tmp0, tmp2, tmp10, tmp12;
125 INT32 z1, z2, z3, z4;
126 JCOEFPTR inptr;
127 ISLOW_MULT_TYPE * quantptr;
128 int * wsptr;
129 JSAMPROW outptr;
130 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
131 int ctr;
DRCe5eaf372014-05-09 18:00:32 +0000132 int workspace[DCTSIZE*4]; /* buffers data between passes */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000133 SHIFT_TEMPS
134
135 /* Pass 1: process columns from input, store into work array. */
136
137 inptr = coef_block;
138 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
139 wsptr = workspace;
140 for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
141 /* Don't bother to process column 4, because second pass won't use it */
142 if (ctr == DCTSIZE-4)
143 continue;
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000144 if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
DRCe5eaf372014-05-09 18:00:32 +0000145 inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
146 inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000147 /* AC terms all zero; we need not examine term 4 for 4x4 output */
DRC8e9cef22015-09-21 12:57:41 -0500148 int dcval = LEFT_SHIFT(DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]),
149 PASS1_BITS);
DRCe5eaf372014-05-09 18:00:32 +0000150
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000151 wsptr[DCTSIZE*0] = dcval;
152 wsptr[DCTSIZE*1] = dcval;
153 wsptr[DCTSIZE*2] = dcval;
154 wsptr[DCTSIZE*3] = dcval;
DRCe5eaf372014-05-09 18:00:32 +0000155
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000156 continue;
157 }
DRCe5eaf372014-05-09 18:00:32 +0000158
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000159 /* Even part */
DRCe5eaf372014-05-09 18:00:32 +0000160
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000161 tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
DRC8e9cef22015-09-21 12:57:41 -0500162 tmp0 = LEFT_SHIFT(tmp0, CONST_BITS+1);
DRCe5eaf372014-05-09 18:00:32 +0000163
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000164 z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
165 z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
166
167 tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
DRCe5eaf372014-05-09 18:00:32 +0000168
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000169 tmp10 = tmp0 + tmp2;
170 tmp12 = tmp0 - tmp2;
DRCe5eaf372014-05-09 18:00:32 +0000171
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000172 /* Odd part */
DRCe5eaf372014-05-09 18:00:32 +0000173
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000174 z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
175 z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
176 z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
177 z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
DRCe5eaf372014-05-09 18:00:32 +0000178
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000179 tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
DRCe5eaf372014-05-09 18:00:32 +0000180 + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
181 + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
182 + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
183
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000184 tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
DRCe5eaf372014-05-09 18:00:32 +0000185 + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
186 + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
187 + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000188
189 /* Final output stage */
DRCe5eaf372014-05-09 18:00:32 +0000190
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000191 wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
192 wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
193 wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
194 wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
195 }
DRCe5eaf372014-05-09 18:00:32 +0000196
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000197 /* Pass 2: process 4 rows from work array, store into output array. */
198
199 wsptr = workspace;
200 for (ctr = 0; ctr < 4; ctr++) {
201 outptr = output_buf[ctr] + output_col;
202 /* It's not clear whether a zero row test is worthwhile here ... */
203
204#ifndef NO_ZERO_ROW_TEST
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000205 if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
DRCe5eaf372014-05-09 18:00:32 +0000206 wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000207 /* AC terms all zero */
208 JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
DRCe5eaf372014-05-09 18:00:32 +0000209 & RANGE_MASK];
210
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000211 outptr[0] = dcval;
212 outptr[1] = dcval;
213 outptr[2] = dcval;
214 outptr[3] = dcval;
DRCe5eaf372014-05-09 18:00:32 +0000215
216 wsptr += DCTSIZE; /* advance pointer to next row */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000217 continue;
218 }
219#endif
DRCe5eaf372014-05-09 18:00:32 +0000220
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000221 /* Even part */
DRCe5eaf372014-05-09 18:00:32 +0000222
DRC8e9cef22015-09-21 12:57:41 -0500223 tmp0 = LEFT_SHIFT((INT32) wsptr[0], CONST_BITS+1);
DRCe5eaf372014-05-09 18:00:32 +0000224
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000225 tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
DRCe5eaf372014-05-09 18:00:32 +0000226 + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
227
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000228 tmp10 = tmp0 + tmp2;
229 tmp12 = tmp0 - tmp2;
DRCe5eaf372014-05-09 18:00:32 +0000230
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000231 /* Odd part */
DRCe5eaf372014-05-09 18:00:32 +0000232
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000233 z1 = (INT32) wsptr[7];
234 z2 = (INT32) wsptr[5];
235 z3 = (INT32) wsptr[3];
236 z4 = (INT32) wsptr[1];
DRCe5eaf372014-05-09 18:00:32 +0000237
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000238 tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
DRCe5eaf372014-05-09 18:00:32 +0000239 + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
240 + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
241 + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
242
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000243 tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
DRCe5eaf372014-05-09 18:00:32 +0000244 + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
245 + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
246 + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000247
248 /* Final output stage */
DRCe5eaf372014-05-09 18:00:32 +0000249
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000250 outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
DRCe5eaf372014-05-09 18:00:32 +0000251 CONST_BITS+PASS1_BITS+3+1)
252 & RANGE_MASK];
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000253 outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
DRCe5eaf372014-05-09 18:00:32 +0000254 CONST_BITS+PASS1_BITS+3+1)
255 & RANGE_MASK];
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000256 outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
DRCe5eaf372014-05-09 18:00:32 +0000257 CONST_BITS+PASS1_BITS+3+1)
258 & RANGE_MASK];
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000259 outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
DRCe5eaf372014-05-09 18:00:32 +0000260 CONST_BITS+PASS1_BITS+3+1)
261 & RANGE_MASK];
262
263 wsptr += DCTSIZE; /* advance pointer to next row */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000264 }
265}
266
267
268/*
269 * Perform dequantization and inverse DCT on one block of coefficients,
270 * producing a reduced-size 2x2 output block.
271 */
272
Thomas G. Lane489583f1996-02-07 00:00:00 +0000273GLOBAL(void)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000274jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
DRCe5eaf372014-05-09 18:00:32 +0000275 JCOEFPTR coef_block,
276 JSAMPARRAY output_buf, JDIMENSION output_col)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000277{
278 INT32 tmp0, tmp10, z1;
279 JCOEFPTR inptr;
280 ISLOW_MULT_TYPE * quantptr;
281 int * wsptr;
282 JSAMPROW outptr;
283 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
284 int ctr;
DRCe5eaf372014-05-09 18:00:32 +0000285 int workspace[DCTSIZE*2]; /* buffers data between passes */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000286 SHIFT_TEMPS
287
288 /* Pass 1: process columns from input, store into work array. */
289
290 inptr = coef_block;
291 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
292 wsptr = workspace;
293 for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
294 /* Don't bother to process columns 2,4,6 */
295 if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
296 continue;
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000297 if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
DRCe5eaf372014-05-09 18:00:32 +0000298 inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000299 /* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */
DRC8e9cef22015-09-21 12:57:41 -0500300 int dcval = LEFT_SHIFT(DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]),
301 PASS1_BITS);
DRCe5eaf372014-05-09 18:00:32 +0000302
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000303 wsptr[DCTSIZE*0] = dcval;
304 wsptr[DCTSIZE*1] = dcval;
DRCe5eaf372014-05-09 18:00:32 +0000305
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000306 continue;
307 }
DRCe5eaf372014-05-09 18:00:32 +0000308
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000309 /* Even part */
DRCe5eaf372014-05-09 18:00:32 +0000310
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000311 z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
DRC8e9cef22015-09-21 12:57:41 -0500312 tmp10 = LEFT_SHIFT(z1, CONST_BITS+2);
DRCe5eaf372014-05-09 18:00:32 +0000313
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000314 /* Odd part */
315
316 z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
317 tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
318 z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
319 tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
320 z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
321 tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
322 z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
323 tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
324
325 /* Final output stage */
DRCe5eaf372014-05-09 18:00:32 +0000326
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000327 wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
328 wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
329 }
DRCe5eaf372014-05-09 18:00:32 +0000330
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000331 /* Pass 2: process 2 rows from work array, store into output array. */
332
333 wsptr = workspace;
334 for (ctr = 0; ctr < 2; ctr++) {
335 outptr = output_buf[ctr] + output_col;
336 /* It's not clear whether a zero row test is worthwhile here ... */
337
338#ifndef NO_ZERO_ROW_TEST
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000339 if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000340 /* AC terms all zero */
341 JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
DRCe5eaf372014-05-09 18:00:32 +0000342 & RANGE_MASK];
343
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000344 outptr[0] = dcval;
345 outptr[1] = dcval;
DRCe5eaf372014-05-09 18:00:32 +0000346
347 wsptr += DCTSIZE; /* advance pointer to next row */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000348 continue;
349 }
350#endif
DRCe5eaf372014-05-09 18:00:32 +0000351
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000352 /* Even part */
DRCe5eaf372014-05-09 18:00:32 +0000353
DRC8e9cef22015-09-21 12:57:41 -0500354 tmp10 = LEFT_SHIFT((INT32) wsptr[0], CONST_BITS+2);
DRCe5eaf372014-05-09 18:00:32 +0000355
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000356 /* Odd part */
357
358 tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
DRCe5eaf372014-05-09 18:00:32 +0000359 + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
360 + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
361 + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000362
363 /* Final output stage */
DRCe5eaf372014-05-09 18:00:32 +0000364
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000365 outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
DRCe5eaf372014-05-09 18:00:32 +0000366 CONST_BITS+PASS1_BITS+3+2)
367 & RANGE_MASK];
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000368 outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
DRCe5eaf372014-05-09 18:00:32 +0000369 CONST_BITS+PASS1_BITS+3+2)
370 & RANGE_MASK];
371
372 wsptr += DCTSIZE; /* advance pointer to next row */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000373 }
374}
375
376
377/*
378 * Perform dequantization and inverse DCT on one block of coefficients,
379 * producing a reduced-size 1x1 output block.
380 */
381
Thomas G. Lane489583f1996-02-07 00:00:00 +0000382GLOBAL(void)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000383jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
DRCe5eaf372014-05-09 18:00:32 +0000384 JCOEFPTR coef_block,
385 JSAMPARRAY output_buf, JDIMENSION output_col)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000386{
387 int dcval;
388 ISLOW_MULT_TYPE * quantptr;
389 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
390 SHIFT_TEMPS
391
392 /* We hardly need an inverse DCT routine for this: just take the
393 * average pixel value, which is one-eighth of the DC coefficient.
394 */
395 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
396 dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
397 dcval = (int) DESCALE((INT32) dcval, 3);
398
399 output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
400}
401
402#endif /* IDCT_SCALING_SUPPORTED */