00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define JPEG_INTERNALS
00024 #include "jinclude.h"
00025 #include "jpeglib.h"
00026 #include "jdct.h"
00027
00028 #ifdef IDCT_SCALING_SUPPORTED
00029
00030
00031
00032
00033
00034
00035 #if DCTSIZE != 8
00036 Sorry, this code only copes with 8x8 DCTs.
00037 #endif
00038
00039
00040
00041
00042 #if BITS_IN_JSAMPLE == 8
00043 #define CONST_BITS 13
00044 #define PASS1_BITS 2
00045 #else
00046 #define CONST_BITS 13
00047 #define PASS1_BITS 1
00048 #endif
00049
00050
00051
00052
00053
00054
00055
00056
00057 #if CONST_BITS == 13
00058 #define FIX_0_211164243 ((INT32) 1730)
00059 #define FIX_0_509795579 ((INT32) 4176)
00060 #define FIX_0_601344887 ((INT32) 4926)
00061 #define FIX_0_720959822 ((INT32) 5906)
00062 #define FIX_0_765366865 ((INT32) 6270)
00063 #define FIX_0_850430095 ((INT32) 6967)
00064 #define FIX_0_899976223 ((INT32) 7373)
00065 #define FIX_1_061594337 ((INT32) 8697)
00066 #define FIX_1_272758580 ((INT32) 10426)
00067 #define FIX_1_451774981 ((INT32) 11893)
00068 #define FIX_1_847759065 ((INT32) 15137)
00069 #define FIX_2_172734803 ((INT32) 17799)
00070 #define FIX_2_562915447 ((INT32) 20995)
00071 #define FIX_3_624509785 ((INT32) 29692)
00072 #else
00073 #define FIX_0_211164243 FIX(0.211164243)
00074 #define FIX_0_509795579 FIX(0.509795579)
00075 #define FIX_0_601344887 FIX(0.601344887)
00076 #define FIX_0_720959822 FIX(0.720959822)
00077 #define FIX_0_765366865 FIX(0.765366865)
00078 #define FIX_0_850430095 FIX(0.850430095)
00079 #define FIX_0_899976223 FIX(0.899976223)
00080 #define FIX_1_061594337 FIX(1.061594337)
00081 #define FIX_1_272758580 FIX(1.272758580)
00082 #define FIX_1_451774981 FIX(1.451774981)
00083 #define FIX_1_847759065 FIX(1.847759065)
00084 #define FIX_2_172734803 FIX(2.172734803)
00085 #define FIX_2_562915447 FIX(2.562915447)
00086 #define FIX_3_624509785 FIX(3.624509785)
00087 #endif
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 #if BITS_IN_JSAMPLE == 8
00098 #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
00099 #else
00100 #define MULTIPLY(var,const) ((var) * (const))
00101 #endif
00102
00103
00104
00105
00106
00107
00108
00109 #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
00110
00111
00112
00113
00114
00115
00116
00117 GLOBAL(void)
00118 jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
00119 JCOEFPTR coef_block,
00120 JSAMPARRAY output_buf, JDIMENSION output_col)
00121 {
00122 INT32 tmp0, tmp2, tmp10, tmp12;
00123 INT32 z1, z2, z3, z4;
00124 JCOEFPTR inptr;
00125 ISLOW_MULT_TYPE * quantptr;
00126 int * wsptr;
00127 JSAMPROW outptr;
00128 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
00129 int ctr;
00130 int workspace[DCTSIZE*4];
00131 SHIFT_TEMPS
00132
00133
00134
00135 inptr = coef_block;
00136 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
00137 wsptr = workspace;
00138 for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
00139
00140 if (ctr == DCTSIZE-4)
00141 continue;
00142 if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
00143 inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
00144 inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
00145
00146 int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
00147
00148 wsptr[DCTSIZE*0] = dcval;
00149 wsptr[DCTSIZE*1] = dcval;
00150 wsptr[DCTSIZE*2] = dcval;
00151 wsptr[DCTSIZE*3] = dcval;
00152
00153 continue;
00154 }
00155
00156
00157
00158 tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
00159 tmp0 <<= (CONST_BITS+1);
00160
00161 z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
00162 z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
00163
00164 tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
00165
00166 tmp10 = tmp0 + tmp2;
00167 tmp12 = tmp0 - tmp2;
00168
00169
00170
00171 z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
00172 z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
00173 z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
00174 z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
00175
00176 tmp0 = MULTIPLY(z1, - FIX_0_211164243)
00177 + MULTIPLY(z2, FIX_1_451774981)
00178 + MULTIPLY(z3, - FIX_2_172734803)
00179 + MULTIPLY(z4, FIX_1_061594337);
00180
00181 tmp2 = MULTIPLY(z1, - FIX_0_509795579)
00182 + MULTIPLY(z2, - FIX_0_601344887)
00183 + MULTIPLY(z3, FIX_0_899976223)
00184 + MULTIPLY(z4, FIX_2_562915447);
00185
00186
00187
00188 wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
00189 wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
00190 wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
00191 wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
00192 }
00193
00194
00195
00196 wsptr = workspace;
00197 for (ctr = 0; ctr < 4; ctr++) {
00198 outptr = output_buf[ctr] + output_col;
00199
00200
00201 #ifndef NO_ZERO_ROW_TEST
00202 if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
00203 wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
00204
00205 JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
00206 & RANGE_MASK];
00207
00208 outptr[0] = dcval;
00209 outptr[1] = dcval;
00210 outptr[2] = dcval;
00211 outptr[3] = dcval;
00212
00213 wsptr += DCTSIZE;
00214 continue;
00215 }
00216 #endif
00217
00218
00219
00220 tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
00221
00222 tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
00223 + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
00224
00225 tmp10 = tmp0 + tmp2;
00226 tmp12 = tmp0 - tmp2;
00227
00228
00229
00230 z1 = (INT32) wsptr[7];
00231 z2 = (INT32) wsptr[5];
00232 z3 = (INT32) wsptr[3];
00233 z4 = (INT32) wsptr[1];
00234
00235 tmp0 = MULTIPLY(z1, - FIX_0_211164243)
00236 + MULTIPLY(z2, FIX_1_451774981)
00237 + MULTIPLY(z3, - FIX_2_172734803)
00238 + MULTIPLY(z4, FIX_1_061594337);
00239
00240 tmp2 = MULTIPLY(z1, - FIX_0_509795579)
00241 + MULTIPLY(z2, - FIX_0_601344887)
00242 + MULTIPLY(z3, FIX_0_899976223)
00243 + MULTIPLY(z4, FIX_2_562915447);
00244
00245
00246
00247 outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
00248 CONST_BITS+PASS1_BITS+3+1)
00249 & RANGE_MASK];
00250 outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
00251 CONST_BITS+PASS1_BITS+3+1)
00252 & RANGE_MASK];
00253 outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
00254 CONST_BITS+PASS1_BITS+3+1)
00255 & RANGE_MASK];
00256 outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
00257 CONST_BITS+PASS1_BITS+3+1)
00258 & RANGE_MASK];
00259
00260 wsptr += DCTSIZE;
00261 }
00262 }
00263
00264
00265
00266
00267
00268
00269
00270 GLOBAL(void)
00271 jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
00272 JCOEFPTR coef_block,
00273 JSAMPARRAY output_buf, JDIMENSION output_col)
00274 {
00275 INT32 tmp0, tmp10, z1;
00276 JCOEFPTR inptr;
00277 ISLOW_MULT_TYPE * quantptr;
00278 int * wsptr;
00279 JSAMPROW outptr;
00280 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
00281 int ctr;
00282 int workspace[DCTSIZE*2];
00283 SHIFT_TEMPS
00284
00285
00286
00287 inptr = coef_block;
00288 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
00289 wsptr = workspace;
00290 for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
00291
00292 if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
00293 continue;
00294 if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
00295 inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
00296
00297 int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
00298
00299 wsptr[DCTSIZE*0] = dcval;
00300 wsptr[DCTSIZE*1] = dcval;
00301
00302 continue;
00303 }
00304
00305
00306
00307 z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
00308 tmp10 = z1 << (CONST_BITS+2);
00309
00310
00311
00312 z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
00313 tmp0 = MULTIPLY(z1, - FIX_0_720959822);
00314 z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
00315 tmp0 += MULTIPLY(z1, FIX_0_850430095);
00316 z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
00317 tmp0 += MULTIPLY(z1, - FIX_1_272758580);
00318 z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
00319 tmp0 += MULTIPLY(z1, FIX_3_624509785);
00320
00321
00322
00323 wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
00324 wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
00325 }
00326
00327
00328
00329 wsptr = workspace;
00330 for (ctr = 0; ctr < 2; ctr++) {
00331 outptr = output_buf[ctr] + output_col;
00332
00333
00334 #ifndef NO_ZERO_ROW_TEST
00335 if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
00336
00337 JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
00338 & RANGE_MASK];
00339
00340 outptr[0] = dcval;
00341 outptr[1] = dcval;
00342
00343 wsptr += DCTSIZE;
00344 continue;
00345 }
00346 #endif
00347
00348
00349
00350 tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
00351
00352
00353
00354 tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822)
00355 + MULTIPLY((INT32) wsptr[5], FIX_0_850430095)
00356 + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580)
00357 + MULTIPLY((INT32) wsptr[1], FIX_3_624509785);
00358
00359
00360
00361 outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
00362 CONST_BITS+PASS1_BITS+3+2)
00363 & RANGE_MASK];
00364 outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
00365 CONST_BITS+PASS1_BITS+3+2)
00366 & RANGE_MASK];
00367
00368 wsptr += DCTSIZE;
00369 }
00370 }
00371
00372
00373
00374
00375
00376
00377
00378 GLOBAL(void)
00379 jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
00380 JCOEFPTR coef_block,
00381 JSAMPARRAY output_buf, JDIMENSION output_col)
00382 {
00383 int dcval;
00384 ISLOW_MULT_TYPE * quantptr;
00385 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
00386 SHIFT_TEMPS
00387
00388
00389
00390
00391 quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
00392 dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
00393 dcval = (int) DESCALE((INT32) dcval, 3);
00394
00395 output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
00396 }
00397
00398 #endif