Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * jidctred.c |
michael@0 | 3 | * |
michael@0 | 4 | * Copyright (C) 1994-1998, Thomas G. Lane. |
michael@0 | 5 | * This file is part of the Independent JPEG Group's software. |
michael@0 | 6 | * For conditions of distribution and use, see the accompanying README file. |
michael@0 | 7 | * |
michael@0 | 8 | * This file contains inverse-DCT routines that produce reduced-size output: |
michael@0 | 9 | * either 4x4, 2x2, or 1x1 pixels from an 8x8 DCT block. |
michael@0 | 10 | * |
michael@0 | 11 | * The implementation is based on the Loeffler, Ligtenberg and Moschytz (LL&M) |
michael@0 | 12 | * algorithm used in jidctint.c. We simply replace each 8-to-8 1-D IDCT step |
michael@0 | 13 | * with an 8-to-4 step that produces the four averages of two adjacent outputs |
michael@0 | 14 | * (or an 8-to-2 step producing two averages of four outputs, for 2x2 output). |
michael@0 | 15 | * These steps were derived by computing the corresponding values at the end |
michael@0 | 16 | * of the normal LL&M code, then simplifying as much as possible. |
michael@0 | 17 | * |
michael@0 | 18 | * 1x1 is trivial: just take the DC coefficient divided by 8. |
michael@0 | 19 | * |
michael@0 | 20 | * See jidctint.c for additional comments. |
michael@0 | 21 | */ |
michael@0 | 22 | |
michael@0 | 23 | #define JPEG_INTERNALS |
michael@0 | 24 | #include "jinclude.h" |
michael@0 | 25 | #include "jpeglib.h" |
michael@0 | 26 | #include "jdct.h" /* Private declarations for DCT subsystem */ |
michael@0 | 27 | |
michael@0 | 28 | #ifdef IDCT_SCALING_SUPPORTED |
michael@0 | 29 | |
michael@0 | 30 | |
michael@0 | 31 | /* |
michael@0 | 32 | * This module is specialized to the case DCTSIZE = 8. |
michael@0 | 33 | */ |
michael@0 | 34 | |
michael@0 | 35 | #if DCTSIZE != 8 |
michael@0 | 36 | Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ |
michael@0 | 37 | #endif |
michael@0 | 38 | |
michael@0 | 39 | |
michael@0 | 40 | /* Scaling is the same as in jidctint.c. */ |
michael@0 | 41 | |
michael@0 | 42 | #if BITS_IN_JSAMPLE == 8 |
michael@0 | 43 | #define CONST_BITS 13 |
michael@0 | 44 | #define PASS1_BITS 2 |
michael@0 | 45 | #else |
michael@0 | 46 | #define CONST_BITS 13 |
michael@0 | 47 | #define PASS1_BITS 1 /* lose a little precision to avoid overflow */ |
michael@0 | 48 | #endif |
michael@0 | 49 | |
michael@0 | 50 | /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus |
michael@0 | 51 | * causing a lot of useless floating-point operations at run time. |
michael@0 | 52 | * To get around this we use the following pre-calculated constants. |
michael@0 | 53 | * If you change CONST_BITS you may want to add appropriate values. |
michael@0 | 54 | * (With a reasonable C compiler, you can just rely on the FIX() macro...) |
michael@0 | 55 | */ |
michael@0 | 56 | |
michael@0 | 57 | #if CONST_BITS == 13 |
michael@0 | 58 | #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */ |
michael@0 | 59 | #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */ |
michael@0 | 60 | #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */ |
michael@0 | 61 | #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */ |
michael@0 | 62 | #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */ |
michael@0 | 63 | #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */ |
michael@0 | 64 | #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */ |
michael@0 | 65 | #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */ |
michael@0 | 66 | #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */ |
michael@0 | 67 | #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */ |
michael@0 | 68 | #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */ |
michael@0 | 69 | #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */ |
michael@0 | 70 | #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */ |
michael@0 | 71 | #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */ |
michael@0 | 72 | #else |
michael@0 | 73 | #define FIX_0_211164243 FIX(0.211164243) |
michael@0 | 74 | #define FIX_0_509795579 FIX(0.509795579) |
michael@0 | 75 | #define FIX_0_601344887 FIX(0.601344887) |
michael@0 | 76 | #define FIX_0_720959822 FIX(0.720959822) |
michael@0 | 77 | #define FIX_0_765366865 FIX(0.765366865) |
michael@0 | 78 | #define FIX_0_850430095 FIX(0.850430095) |
michael@0 | 79 | #define FIX_0_899976223 FIX(0.899976223) |
michael@0 | 80 | #define FIX_1_061594337 FIX(1.061594337) |
michael@0 | 81 | #define FIX_1_272758580 FIX(1.272758580) |
michael@0 | 82 | #define FIX_1_451774981 FIX(1.451774981) |
michael@0 | 83 | #define FIX_1_847759065 FIX(1.847759065) |
michael@0 | 84 | #define FIX_2_172734803 FIX(2.172734803) |
michael@0 | 85 | #define FIX_2_562915447 FIX(2.562915447) |
michael@0 | 86 | #define FIX_3_624509785 FIX(3.624509785) |
michael@0 | 87 | #endif |
michael@0 | 88 | |
michael@0 | 89 | |
michael@0 | 90 | /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. |
michael@0 | 91 | * For 8-bit samples with the recommended scaling, all the variable |
michael@0 | 92 | * and constant values involved are no more than 16 bits wide, so a |
michael@0 | 93 | * 16x16->32 bit multiply can be used instead of a full 32x32 multiply. |
michael@0 | 94 | * For 12-bit samples, a full 32-bit multiplication will be needed. |
michael@0 | 95 | */ |
michael@0 | 96 | |
michael@0 | 97 | #if BITS_IN_JSAMPLE == 8 |
michael@0 | 98 | #define MULTIPLY(var,const) MULTIPLY16C16(var,const) |
michael@0 | 99 | #else |
michael@0 | 100 | #define MULTIPLY(var,const) ((var) * (const)) |
michael@0 | 101 | #endif |
michael@0 | 102 | |
michael@0 | 103 | |
michael@0 | 104 | /* Dequantize a coefficient by multiplying it by the multiplier-table |
michael@0 | 105 | * entry; produce an int result. In this module, both inputs and result |
michael@0 | 106 | * are 16 bits or less, so either int or short multiply will work. |
michael@0 | 107 | */ |
michael@0 | 108 | |
michael@0 | 109 | #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval)) |
michael@0 | 110 | |
michael@0 | 111 | |
michael@0 | 112 | /* |
michael@0 | 113 | * Perform dequantization and inverse DCT on one block of coefficients, |
michael@0 | 114 | * producing a reduced-size 4x4 output block. |
michael@0 | 115 | */ |
michael@0 | 116 | |
michael@0 | 117 | GLOBAL(void) |
michael@0 | 118 | jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
michael@0 | 119 | JCOEFPTR coef_block, |
michael@0 | 120 | JSAMPARRAY output_buf, JDIMENSION output_col) |
michael@0 | 121 | { |
michael@0 | 122 | INT32 tmp0, tmp2, tmp10, tmp12; |
michael@0 | 123 | INT32 z1, z2, z3, z4; |
michael@0 | 124 | JCOEFPTR inptr; |
michael@0 | 125 | ISLOW_MULT_TYPE * quantptr; |
michael@0 | 126 | int * wsptr; |
michael@0 | 127 | JSAMPROW outptr; |
michael@0 | 128 | JSAMPLE *range_limit = IDCT_range_limit(cinfo); |
michael@0 | 129 | int ctr; |
michael@0 | 130 | int workspace[DCTSIZE*4]; /* buffers data between passes */ |
michael@0 | 131 | SHIFT_TEMPS |
michael@0 | 132 | |
michael@0 | 133 | /* Pass 1: process columns from input, store into work array. */ |
michael@0 | 134 | |
michael@0 | 135 | inptr = coef_block; |
michael@0 | 136 | quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; |
michael@0 | 137 | wsptr = workspace; |
michael@0 | 138 | for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) { |
michael@0 | 139 | /* Don't bother to process column 4, because second pass won't use it */ |
michael@0 | 140 | if (ctr == DCTSIZE-4) |
michael@0 | 141 | continue; |
michael@0 | 142 | if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && |
michael@0 | 143 | inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 && |
michael@0 | 144 | inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) { |
michael@0 | 145 | /* AC terms all zero; we need not examine term 4 for 4x4 output */ |
michael@0 | 146 | int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; |
michael@0 | 147 | |
michael@0 | 148 | wsptr[DCTSIZE*0] = dcval; |
michael@0 | 149 | wsptr[DCTSIZE*1] = dcval; |
michael@0 | 150 | wsptr[DCTSIZE*2] = dcval; |
michael@0 | 151 | wsptr[DCTSIZE*3] = dcval; |
michael@0 | 152 | |
michael@0 | 153 | continue; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | /* Even part */ |
michael@0 | 157 | |
michael@0 | 158 | tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); |
michael@0 | 159 | tmp0 <<= (CONST_BITS+1); |
michael@0 | 160 | |
michael@0 | 161 | z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); |
michael@0 | 162 | z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); |
michael@0 | 163 | |
michael@0 | 164 | tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865); |
michael@0 | 165 | |
michael@0 | 166 | tmp10 = tmp0 + tmp2; |
michael@0 | 167 | tmp12 = tmp0 - tmp2; |
michael@0 | 168 | |
michael@0 | 169 | /* Odd part */ |
michael@0 | 170 | |
michael@0 | 171 | z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); |
michael@0 | 172 | z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); |
michael@0 | 173 | z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); |
michael@0 | 174 | z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); |
michael@0 | 175 | |
michael@0 | 176 | tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */ |
michael@0 | 177 | + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */ |
michael@0 | 178 | + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */ |
michael@0 | 179 | + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */ |
michael@0 | 180 | |
michael@0 | 181 | tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */ |
michael@0 | 182 | + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */ |
michael@0 | 183 | + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */ |
michael@0 | 184 | + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */ |
michael@0 | 185 | |
michael@0 | 186 | /* Final output stage */ |
michael@0 | 187 | |
michael@0 | 188 | wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1); |
michael@0 | 189 | wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1); |
michael@0 | 190 | wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1); |
michael@0 | 191 | wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1); |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | /* Pass 2: process 4 rows from work array, store into output array. */ |
michael@0 | 195 | |
michael@0 | 196 | wsptr = workspace; |
michael@0 | 197 | for (ctr = 0; ctr < 4; ctr++) { |
michael@0 | 198 | outptr = output_buf[ctr] + output_col; |
michael@0 | 199 | /* It's not clear whether a zero row test is worthwhile here ... */ |
michael@0 | 200 | |
michael@0 | 201 | #ifndef NO_ZERO_ROW_TEST |
michael@0 | 202 | if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && |
michael@0 | 203 | wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { |
michael@0 | 204 | /* AC terms all zero */ |
michael@0 | 205 | JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3) |
michael@0 | 206 | & RANGE_MASK]; |
michael@0 | 207 | |
michael@0 | 208 | outptr[0] = dcval; |
michael@0 | 209 | outptr[1] = dcval; |
michael@0 | 210 | outptr[2] = dcval; |
michael@0 | 211 | outptr[3] = dcval; |
michael@0 | 212 | |
michael@0 | 213 | wsptr += DCTSIZE; /* advance pointer to next row */ |
michael@0 | 214 | continue; |
michael@0 | 215 | } |
michael@0 | 216 | #endif |
michael@0 | 217 | |
michael@0 | 218 | /* Even part */ |
michael@0 | 219 | |
michael@0 | 220 | tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1); |
michael@0 | 221 | |
michael@0 | 222 | tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065) |
michael@0 | 223 | + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865); |
michael@0 | 224 | |
michael@0 | 225 | tmp10 = tmp0 + tmp2; |
michael@0 | 226 | tmp12 = tmp0 - tmp2; |
michael@0 | 227 | |
michael@0 | 228 | /* Odd part */ |
michael@0 | 229 | |
michael@0 | 230 | z1 = (INT32) wsptr[7]; |
michael@0 | 231 | z2 = (INT32) wsptr[5]; |
michael@0 | 232 | z3 = (INT32) wsptr[3]; |
michael@0 | 233 | z4 = (INT32) wsptr[1]; |
michael@0 | 234 | |
michael@0 | 235 | tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */ |
michael@0 | 236 | + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */ |
michael@0 | 237 | + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */ |
michael@0 | 238 | + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */ |
michael@0 | 239 | |
michael@0 | 240 | tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */ |
michael@0 | 241 | + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */ |
michael@0 | 242 | + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */ |
michael@0 | 243 | + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */ |
michael@0 | 244 | |
michael@0 | 245 | /* Final output stage */ |
michael@0 | 246 | |
michael@0 | 247 | outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2, |
michael@0 | 248 | CONST_BITS+PASS1_BITS+3+1) |
michael@0 | 249 | & RANGE_MASK]; |
michael@0 | 250 | outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2, |
michael@0 | 251 | CONST_BITS+PASS1_BITS+3+1) |
michael@0 | 252 | & RANGE_MASK]; |
michael@0 | 253 | outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0, |
michael@0 | 254 | CONST_BITS+PASS1_BITS+3+1) |
michael@0 | 255 | & RANGE_MASK]; |
michael@0 | 256 | outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0, |
michael@0 | 257 | CONST_BITS+PASS1_BITS+3+1) |
michael@0 | 258 | & RANGE_MASK]; |
michael@0 | 259 | |
michael@0 | 260 | wsptr += DCTSIZE; /* advance pointer to next row */ |
michael@0 | 261 | } |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | |
michael@0 | 265 | /* |
michael@0 | 266 | * Perform dequantization and inverse DCT on one block of coefficients, |
michael@0 | 267 | * producing a reduced-size 2x2 output block. |
michael@0 | 268 | */ |
michael@0 | 269 | |
michael@0 | 270 | GLOBAL(void) |
michael@0 | 271 | jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
michael@0 | 272 | JCOEFPTR coef_block, |
michael@0 | 273 | JSAMPARRAY output_buf, JDIMENSION output_col) |
michael@0 | 274 | { |
michael@0 | 275 | INT32 tmp0, tmp10, z1; |
michael@0 | 276 | JCOEFPTR inptr; |
michael@0 | 277 | ISLOW_MULT_TYPE * quantptr; |
michael@0 | 278 | int * wsptr; |
michael@0 | 279 | JSAMPROW outptr; |
michael@0 | 280 | JSAMPLE *range_limit = IDCT_range_limit(cinfo); |
michael@0 | 281 | int ctr; |
michael@0 | 282 | int workspace[DCTSIZE*2]; /* buffers data between passes */ |
michael@0 | 283 | SHIFT_TEMPS |
michael@0 | 284 | |
michael@0 | 285 | /* Pass 1: process columns from input, store into work array. */ |
michael@0 | 286 | |
michael@0 | 287 | inptr = coef_block; |
michael@0 | 288 | quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; |
michael@0 | 289 | wsptr = workspace; |
michael@0 | 290 | for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) { |
michael@0 | 291 | /* Don't bother to process columns 2,4,6 */ |
michael@0 | 292 | if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6) |
michael@0 | 293 | continue; |
michael@0 | 294 | if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 && |
michael@0 | 295 | inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) { |
michael@0 | 296 | /* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */ |
michael@0 | 297 | int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; |
michael@0 | 298 | |
michael@0 | 299 | wsptr[DCTSIZE*0] = dcval; |
michael@0 | 300 | wsptr[DCTSIZE*1] = dcval; |
michael@0 | 301 | |
michael@0 | 302 | continue; |
michael@0 | 303 | } |
michael@0 | 304 | |
michael@0 | 305 | /* Even part */ |
michael@0 | 306 | |
michael@0 | 307 | z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); |
michael@0 | 308 | tmp10 = z1 << (CONST_BITS+2); |
michael@0 | 309 | |
michael@0 | 310 | /* Odd part */ |
michael@0 | 311 | |
michael@0 | 312 | z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); |
michael@0 | 313 | tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */ |
michael@0 | 314 | z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); |
michael@0 | 315 | tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */ |
michael@0 | 316 | z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); |
michael@0 | 317 | tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */ |
michael@0 | 318 | z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); |
michael@0 | 319 | tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */ |
michael@0 | 320 | |
michael@0 | 321 | /* Final output stage */ |
michael@0 | 322 | |
michael@0 | 323 | wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2); |
michael@0 | 324 | wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2); |
michael@0 | 325 | } |
michael@0 | 326 | |
michael@0 | 327 | /* Pass 2: process 2 rows from work array, store into output array. */ |
michael@0 | 328 | |
michael@0 | 329 | wsptr = workspace; |
michael@0 | 330 | for (ctr = 0; ctr < 2; ctr++) { |
michael@0 | 331 | outptr = output_buf[ctr] + output_col; |
michael@0 | 332 | /* It's not clear whether a zero row test is worthwhile here ... */ |
michael@0 | 333 | |
michael@0 | 334 | #ifndef NO_ZERO_ROW_TEST |
michael@0 | 335 | if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) { |
michael@0 | 336 | /* AC terms all zero */ |
michael@0 | 337 | JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3) |
michael@0 | 338 | & RANGE_MASK]; |
michael@0 | 339 | |
michael@0 | 340 | outptr[0] = dcval; |
michael@0 | 341 | outptr[1] = dcval; |
michael@0 | 342 | |
michael@0 | 343 | wsptr += DCTSIZE; /* advance pointer to next row */ |
michael@0 | 344 | continue; |
michael@0 | 345 | } |
michael@0 | 346 | #endif |
michael@0 | 347 | |
michael@0 | 348 | /* Even part */ |
michael@0 | 349 | |
michael@0 | 350 | tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2); |
michael@0 | 351 | |
michael@0 | 352 | /* Odd part */ |
michael@0 | 353 | |
michael@0 | 354 | tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */ |
michael@0 | 355 | + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */ |
michael@0 | 356 | + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */ |
michael@0 | 357 | + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */ |
michael@0 | 358 | |
michael@0 | 359 | /* Final output stage */ |
michael@0 | 360 | |
michael@0 | 361 | outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0, |
michael@0 | 362 | CONST_BITS+PASS1_BITS+3+2) |
michael@0 | 363 | & RANGE_MASK]; |
michael@0 | 364 | outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0, |
michael@0 | 365 | CONST_BITS+PASS1_BITS+3+2) |
michael@0 | 366 | & RANGE_MASK]; |
michael@0 | 367 | |
michael@0 | 368 | wsptr += DCTSIZE; /* advance pointer to next row */ |
michael@0 | 369 | } |
michael@0 | 370 | } |
michael@0 | 371 | |
michael@0 | 372 | |
michael@0 | 373 | /* |
michael@0 | 374 | * Perform dequantization and inverse DCT on one block of coefficients, |
michael@0 | 375 | * producing a reduced-size 1x1 output block. |
michael@0 | 376 | */ |
michael@0 | 377 | |
michael@0 | 378 | GLOBAL(void) |
michael@0 | 379 | jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
michael@0 | 380 | JCOEFPTR coef_block, |
michael@0 | 381 | JSAMPARRAY output_buf, JDIMENSION output_col) |
michael@0 | 382 | { |
michael@0 | 383 | int dcval; |
michael@0 | 384 | ISLOW_MULT_TYPE * quantptr; |
michael@0 | 385 | JSAMPLE *range_limit = IDCT_range_limit(cinfo); |
michael@0 | 386 | SHIFT_TEMPS |
michael@0 | 387 | |
michael@0 | 388 | /* We hardly need an inverse DCT routine for this: just take the |
michael@0 | 389 | * average pixel value, which is one-eighth of the DC coefficient. |
michael@0 | 390 | */ |
michael@0 | 391 | quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; |
michael@0 | 392 | dcval = DEQUANTIZE(coef_block[0], quantptr[0]); |
michael@0 | 393 | dcval = (int) DESCALE((INT32) dcval, 3); |
michael@0 | 394 | |
michael@0 | 395 | output_buf[0][output_col] = range_limit[dcval & RANGE_MASK]; |
michael@0 | 396 | } |
michael@0 | 397 | |
michael@0 | 398 | #endif /* IDCT_SCALING_SUPPORTED */ |