blob: 2b385f86cca0900d0800aeec16d9ae8ffc59ecbd [file] [log] [blame]
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +00001/*
2 * jidctred.c
3 *
Thomas G. Lane5ead57a1998-03-27 00:00:00 +00004 * Copyright (C) 1994-1998, Thomas G. Lane.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +00005 * This file is part of the Independent JPEG Group's software.
6 * For conditions of distribution and use, see the accompanying README file.
7 *
8 * This file contains inverse-DCT routines that produce reduced-size output:
9 * either 4x4, 2x2, or 1x1 pixels from an 8x8 DCT block.
10 *
11 * The implementation is based on the Loeffler, Ligtenberg and Moschytz (LL&M)
12 * algorithm used in jidctint.c. We simply replace each 8-to-8 1-D IDCT step
13 * with an 8-to-4 step that produces the four averages of two adjacent outputs
14 * (or an 8-to-2 step producing two averages of four outputs, for 2x2 output).
15 * These steps were derived by computing the corresponding values at the end
16 * of the normal LL&M code, then simplifying as much as possible.
17 *
18 * 1x1 is trivial: just take the DC coefficient divided by 8.
19 *
20 * See jidctint.c for additional comments.
21 */
22
23#define JPEG_INTERNALS
24#include "jinclude.h"
25#include "jpeglib.h"
DRCe5eaf372014-05-09 18:00:32 +000026#include "jdct.h" /* Private declarations for DCT subsystem */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000027
28#ifdef IDCT_SCALING_SUPPORTED
29
30
31/*
32 * This module is specialized to the case DCTSIZE = 8.
33 */
34
35#if DCTSIZE != 8
36 Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
37#endif
38
39
40/* Scaling is the same as in jidctint.c. */
41
42#if BITS_IN_JSAMPLE == 8
43#define CONST_BITS 13
44#define PASS1_BITS 2
45#else
46#define CONST_BITS 13
DRCe5eaf372014-05-09 18:00:32 +000047#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000048#endif
49
50/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
51 * causing a lot of useless floating-point operations at run time.
52 * To get around this we use the following pre-calculated constants.
53 * If you change CONST_BITS you may want to add appropriate values.
54 * (With a reasonable C compiler, you can just rely on the FIX() macro...)
55 */
56
57#if CONST_BITS == 13
DRCe5eaf372014-05-09 18:00:32 +000058#define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
59#define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
60#define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
61#define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
62#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
63#define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
64#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
65#define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
66#define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
67#define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
68#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
69#define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
70#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
71#define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000072#else
73#define FIX_0_211164243 FIX(0.211164243)
74#define FIX_0_509795579 FIX(0.509795579)
75#define FIX_0_601344887 FIX(0.601344887)
76#define FIX_0_720959822 FIX(0.720959822)
77#define FIX_0_765366865 FIX(0.765366865)
78#define FIX_0_850430095 FIX(0.850430095)
79#define FIX_0_899976223 FIX(0.899976223)
80#define FIX_1_061594337 FIX(1.061594337)
81#define FIX_1_272758580 FIX(1.272758580)
82#define FIX_1_451774981 FIX(1.451774981)
83#define FIX_1_847759065 FIX(1.847759065)
84#define FIX_2_172734803 FIX(2.172734803)
85#define FIX_2_562915447 FIX(2.562915447)
86#define FIX_3_624509785 FIX(3.624509785)
87#endif
88
89
90/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
91 * For 8-bit samples with the recommended scaling, all the variable
92 * and constant values involved are no more than 16 bits wide, so a
93 * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
94 * For 12-bit samples, a full 32-bit multiplication will be needed.
95 */
96
97#if BITS_IN_JSAMPLE == 8
98#define MULTIPLY(var,const) MULTIPLY16C16(var,const)
99#else
100#define MULTIPLY(var,const) ((var) * (const))
101#endif
102
103
104/* Dequantize a coefficient by multiplying it by the multiplier-table
105 * entry; produce an int result. In this module, both inputs and result
106 * are 16 bits or less, so either int or short multiply will work.
107 */
108
109#define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
110
111
112/*
113 * Perform dequantization and inverse DCT on one block of coefficients,
114 * producing a reduced-size 4x4 output block.
115 */
116
Thomas G. Lane489583f1996-02-07 00:00:00 +0000117GLOBAL(void)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000118jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
DRCe5eaf372014-05-09 18:00:32 +0000119 JCOEFPTR coef_block,
120 JSAMPARRAY output_buf, JDIMENSION output_col)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000121{
122 INT32 tmp0, tmp2, tmp10, tmp12;
123 INT32 z1, z2, z3, z4;
124 JCOEFPTR inptr;
125 ISLOW_MULT_TYPE * quantptr;
126 int * wsptr;
127 JSAMPROW outptr;
128 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
129 int ctr;
DRCe5eaf372014-05-09 18:00:32 +0000130 int workspace[DCTSIZE*4]; /* buffers data between passes */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000131 SHIFT_TEMPS
132
133 /* Pass 1: process columns from input, store into work array. */
134
135 inptr = coef_block;
136 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
137 wsptr = workspace;
138 for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
139 /* Don't bother to process column 4, because second pass won't use it */
140 if (ctr == DCTSIZE-4)
141 continue;
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000142 if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
DRCe5eaf372014-05-09 18:00:32 +0000143 inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
144 inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000145 /* AC terms all zero; we need not examine term 4 for 4x4 output */
146 int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
DRCe5eaf372014-05-09 18:00:32 +0000147
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000148 wsptr[DCTSIZE*0] = dcval;
149 wsptr[DCTSIZE*1] = dcval;
150 wsptr[DCTSIZE*2] = dcval;
151 wsptr[DCTSIZE*3] = dcval;
DRCe5eaf372014-05-09 18:00:32 +0000152
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000153 continue;
154 }
DRCe5eaf372014-05-09 18:00:32 +0000155
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000156 /* Even part */
DRCe5eaf372014-05-09 18:00:32 +0000157
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000158 tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
159 tmp0 <<= (CONST_BITS+1);
DRCe5eaf372014-05-09 18:00:32 +0000160
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000161 z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
162 z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
163
164 tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
DRCe5eaf372014-05-09 18:00:32 +0000165
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000166 tmp10 = tmp0 + tmp2;
167 tmp12 = tmp0 - tmp2;
DRCe5eaf372014-05-09 18:00:32 +0000168
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000169 /* Odd part */
DRCe5eaf372014-05-09 18:00:32 +0000170
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000171 z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
172 z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
173 z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
174 z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
DRCe5eaf372014-05-09 18:00:32 +0000175
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000176 tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
DRCe5eaf372014-05-09 18:00:32 +0000177 + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
178 + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
179 + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
180
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000181 tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
DRCe5eaf372014-05-09 18:00:32 +0000182 + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
183 + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
184 + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000185
186 /* Final output stage */
DRCe5eaf372014-05-09 18:00:32 +0000187
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000188 wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
189 wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
190 wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
191 wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
192 }
DRCe5eaf372014-05-09 18:00:32 +0000193
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000194 /* Pass 2: process 4 rows from work array, store into output array. */
195
196 wsptr = workspace;
197 for (ctr = 0; ctr < 4; ctr++) {
198 outptr = output_buf[ctr] + output_col;
199 /* It's not clear whether a zero row test is worthwhile here ... */
200
201#ifndef NO_ZERO_ROW_TEST
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000202 if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
DRCe5eaf372014-05-09 18:00:32 +0000203 wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000204 /* AC terms all zero */
205 JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
DRCe5eaf372014-05-09 18:00:32 +0000206 & RANGE_MASK];
207
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000208 outptr[0] = dcval;
209 outptr[1] = dcval;
210 outptr[2] = dcval;
211 outptr[3] = dcval;
DRCe5eaf372014-05-09 18:00:32 +0000212
213 wsptr += DCTSIZE; /* advance pointer to next row */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000214 continue;
215 }
216#endif
DRCe5eaf372014-05-09 18:00:32 +0000217
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000218 /* Even part */
DRCe5eaf372014-05-09 18:00:32 +0000219
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000220 tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
DRCe5eaf372014-05-09 18:00:32 +0000221
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000222 tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
DRCe5eaf372014-05-09 18:00:32 +0000223 + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
224
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000225 tmp10 = tmp0 + tmp2;
226 tmp12 = tmp0 - tmp2;
DRCe5eaf372014-05-09 18:00:32 +0000227
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000228 /* Odd part */
DRCe5eaf372014-05-09 18:00:32 +0000229
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000230 z1 = (INT32) wsptr[7];
231 z2 = (INT32) wsptr[5];
232 z3 = (INT32) wsptr[3];
233 z4 = (INT32) wsptr[1];
DRCe5eaf372014-05-09 18:00:32 +0000234
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000235 tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
DRCe5eaf372014-05-09 18:00:32 +0000236 + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
237 + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
238 + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
239
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000240 tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
DRCe5eaf372014-05-09 18:00:32 +0000241 + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
242 + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
243 + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000244
245 /* Final output stage */
DRCe5eaf372014-05-09 18:00:32 +0000246
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000247 outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
DRCe5eaf372014-05-09 18:00:32 +0000248 CONST_BITS+PASS1_BITS+3+1)
249 & RANGE_MASK];
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000250 outptr[3] = 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[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
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[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
DRCe5eaf372014-05-09 18:00:32 +0000257 CONST_BITS+PASS1_BITS+3+1)
258 & RANGE_MASK];
259
260 wsptr += DCTSIZE; /* advance pointer to next row */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000261 }
262}
263
264
265/*
266 * Perform dequantization and inverse DCT on one block of coefficients,
267 * producing a reduced-size 2x2 output block.
268 */
269
Thomas G. Lane489583f1996-02-07 00:00:00 +0000270GLOBAL(void)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000271jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
DRCe5eaf372014-05-09 18:00:32 +0000272 JCOEFPTR coef_block,
273 JSAMPARRAY output_buf, JDIMENSION output_col)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000274{
275 INT32 tmp0, tmp10, z1;
276 JCOEFPTR inptr;
277 ISLOW_MULT_TYPE * quantptr;
278 int * wsptr;
279 JSAMPROW outptr;
280 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
281 int ctr;
DRCe5eaf372014-05-09 18:00:32 +0000282 int workspace[DCTSIZE*2]; /* buffers data between passes */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000283 SHIFT_TEMPS
284
285 /* Pass 1: process columns from input, store into work array. */
286
287 inptr = coef_block;
288 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
289 wsptr = workspace;
290 for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
291 /* Don't bother to process columns 2,4,6 */
292 if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
293 continue;
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000294 if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
DRCe5eaf372014-05-09 18:00:32 +0000295 inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000296 /* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */
297 int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
DRCe5eaf372014-05-09 18:00:32 +0000298
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000299 wsptr[DCTSIZE*0] = dcval;
300 wsptr[DCTSIZE*1] = dcval;
DRCe5eaf372014-05-09 18:00:32 +0000301
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000302 continue;
303 }
DRCe5eaf372014-05-09 18:00:32 +0000304
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000305 /* Even part */
DRCe5eaf372014-05-09 18:00:32 +0000306
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000307 z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
308 tmp10 = z1 << (CONST_BITS+2);
DRCe5eaf372014-05-09 18:00:32 +0000309
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000310 /* Odd part */
311
312 z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
313 tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
314 z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
315 tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
316 z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
317 tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
318 z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
319 tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
320
321 /* Final output stage */
DRCe5eaf372014-05-09 18:00:32 +0000322
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000323 wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
324 wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
325 }
DRCe5eaf372014-05-09 18:00:32 +0000326
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000327 /* Pass 2: process 2 rows from work array, store into output array. */
328
329 wsptr = workspace;
330 for (ctr = 0; ctr < 2; ctr++) {
331 outptr = output_buf[ctr] + output_col;
332 /* It's not clear whether a zero row test is worthwhile here ... */
333
334#ifndef NO_ZERO_ROW_TEST
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000335 if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000336 /* AC terms all zero */
337 JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
DRCe5eaf372014-05-09 18:00:32 +0000338 & RANGE_MASK];
339
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000340 outptr[0] = dcval;
341 outptr[1] = dcval;
DRCe5eaf372014-05-09 18:00:32 +0000342
343 wsptr += DCTSIZE; /* advance pointer to next row */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000344 continue;
345 }
346#endif
DRCe5eaf372014-05-09 18:00:32 +0000347
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000348 /* Even part */
DRCe5eaf372014-05-09 18:00:32 +0000349
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000350 tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
DRCe5eaf372014-05-09 18:00:32 +0000351
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000352 /* Odd part */
353
354 tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
DRCe5eaf372014-05-09 18:00:32 +0000355 + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
356 + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
357 + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000358
359 /* Final output stage */
DRCe5eaf372014-05-09 18:00:32 +0000360
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000361 outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
DRCe5eaf372014-05-09 18:00:32 +0000362 CONST_BITS+PASS1_BITS+3+2)
363 & RANGE_MASK];
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000364 outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
DRCe5eaf372014-05-09 18:00:32 +0000365 CONST_BITS+PASS1_BITS+3+2)
366 & RANGE_MASK];
367
368 wsptr += DCTSIZE; /* advance pointer to next row */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000369 }
370}
371
372
373/*
374 * Perform dequantization and inverse DCT on one block of coefficients,
375 * producing a reduced-size 1x1 output block.
376 */
377
Thomas G. Lane489583f1996-02-07 00:00:00 +0000378GLOBAL(void)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000379jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
DRCe5eaf372014-05-09 18:00:32 +0000380 JCOEFPTR coef_block,
381 JSAMPARRAY output_buf, JDIMENSION output_col)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000382{
383 int dcval;
384 ISLOW_MULT_TYPE * quantptr;
385 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
386 SHIFT_TEMPS
387
388 /* We hardly need an inverse DCT routine for this: just take the
389 * average pixel value, which is one-eighth of the DC coefficient.
390 */
391 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
392 dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
393 dcval = (int) DESCALE((INT32) dcval, 3);
394
395 output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
396}
397
398#endif /* IDCT_SCALING_SUPPORTED */