00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #define JPEG_INTERNALS
00036 #include "jinclude.h"
00037 #include "jpeglib.h"
00038 #include "jdct.h"
00039
00040 #ifdef DCT_IFAST_SUPPORTED
00041
00042
00043
00044
00045
00046
00047 #if DCTSIZE != 8
00048 Sorry, this code only copes with 8x8 DCTs.
00049 #endif
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 #if BITS_IN_JSAMPLE == 8
00077 #define CONST_BITS 8
00078 #define PASS1_BITS 2
00079 #else
00080 #define CONST_BITS 8
00081 #define PASS1_BITS 1
00082 #endif
00083
00084
00085
00086
00087
00088
00089
00090
00091 #if CONST_BITS == 8
00092 #define FIX_1_082392200 ((INT32) 277)
00093 #define FIX_1_414213562 ((INT32) 362)
00094 #define FIX_1_847759065 ((INT32) 473)
00095 #define FIX_2_613125930 ((INT32) 669)
00096 #else
00097 #define FIX_1_082392200 FIX(1.082392200)
00098 #define FIX_1_414213562 FIX(1.414213562)
00099 #define FIX_1_847759065 FIX(1.847759065)
00100 #define FIX_2_613125930 FIX(2.613125930)
00101 #endif
00102
00103
00104
00105
00106
00107
00108
00109 #ifndef USE_ACCURATE_ROUNDING
00110 #undef DESCALE
00111 #define DESCALE(x,n) RIGHT_SHIFT(x, n)
00112 #endif
00113
00114
00115
00116
00117
00118
00119 #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
00120
00121
00122
00123
00124
00125
00126
00127
00128 #if BITS_IN_JSAMPLE == 8
00129 #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
00130 #else
00131 #define DEQUANTIZE(coef,quantval) \
00132 DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
00133 #endif
00134
00135
00136
00137
00138
00139
00140 #ifdef RIGHT_SHIFT_IS_UNSIGNED
00141 #define ISHIFT_TEMPS DCTELEM ishift_temp;
00142 #if BITS_IN_JSAMPLE == 8
00143 #define DCTELEMBITS 16
00144 #else
00145 #define DCTELEMBITS 32
00146 #endif
00147 #define IRIGHT_SHIFT(x,shft) \
00148 ((ishift_temp = (x)) < 0 ? \
00149 (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
00150 (ishift_temp >> (shft)))
00151 #else
00152 #define ISHIFT_TEMPS
00153 #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
00154 #endif
00155
00156 #ifdef USE_ACCURATE_ROUNDING
00157 #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
00158 #else
00159 #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
00160 #endif
00161
00162
00163
00164
00165
00166
00167 GLOBAL(void)
00168 jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
00169 JCOEFPTR coef_block,
00170 JSAMPARRAY output_buf, JDIMENSION output_col)
00171 {
00172 DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
00173 DCTELEM tmp10, tmp11, tmp12, tmp13;
00174 DCTELEM z5, z10, z11, z12, z13;
00175 JCOEFPTR inptr;
00176 IFAST_MULT_TYPE * quantptr;
00177 int * wsptr;
00178 JSAMPROW outptr;
00179 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
00180 int ctr;
00181 int workspace[DCTSIZE2];
00182 SHIFT_TEMPS
00183 ISHIFT_TEMPS
00184
00185
00186
00187 inptr = coef_block;
00188 quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
00189 wsptr = workspace;
00190 for (ctr = DCTSIZE; ctr > 0; ctr--) {
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
00201 inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
00202 inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
00203 inptr[DCTSIZE*7] == 0) {
00204
00205 int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
00206
00207 wsptr[DCTSIZE*0] = dcval;
00208 wsptr[DCTSIZE*1] = dcval;
00209 wsptr[DCTSIZE*2] = dcval;
00210 wsptr[DCTSIZE*3] = dcval;
00211 wsptr[DCTSIZE*4] = dcval;
00212 wsptr[DCTSIZE*5] = dcval;
00213 wsptr[DCTSIZE*6] = dcval;
00214 wsptr[DCTSIZE*7] = dcval;
00215
00216 inptr++;
00217 quantptr++;
00218 wsptr++;
00219 continue;
00220 }
00221
00222
00223
00224 tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
00225 tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
00226 tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
00227 tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
00228
00229 tmp10 = tmp0 + tmp2;
00230 tmp11 = tmp0 - tmp2;
00231
00232 tmp13 = tmp1 + tmp3;
00233 tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13;
00234
00235 tmp0 = tmp10 + tmp13;
00236 tmp3 = tmp10 - tmp13;
00237 tmp1 = tmp11 + tmp12;
00238 tmp2 = tmp11 - tmp12;
00239
00240
00241
00242 tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
00243 tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
00244 tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
00245 tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
00246
00247 z13 = tmp6 + tmp5;
00248 z10 = tmp6 - tmp5;
00249 z11 = tmp4 + tmp7;
00250 z12 = tmp4 - tmp7;
00251
00252 tmp7 = z11 + z13;
00253 tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562);
00254
00255 z5 = MULTIPLY(z10 + z12, FIX_1_847759065);
00256 tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5;
00257 tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5;
00258
00259 tmp6 = tmp12 - tmp7;
00260 tmp5 = tmp11 - tmp6;
00261 tmp4 = tmp10 + tmp5;
00262
00263 wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
00264 wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
00265 wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
00266 wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
00267 wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
00268 wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
00269 wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
00270 wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
00271
00272 inptr++;
00273 quantptr++;
00274 wsptr++;
00275 }
00276
00277
00278
00279
00280
00281 wsptr = workspace;
00282 for (ctr = 0; ctr < DCTSIZE; ctr++) {
00283 outptr = output_buf[ctr] + output_col;
00284
00285
00286
00287
00288
00289
00290
00291
00292 #ifndef NO_ZERO_ROW_TEST
00293 if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
00294 wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
00295
00296 JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
00297 & RANGE_MASK];
00298
00299 outptr[0] = dcval;
00300 outptr[1] = dcval;
00301 outptr[2] = dcval;
00302 outptr[3] = dcval;
00303 outptr[4] = dcval;
00304 outptr[5] = dcval;
00305 outptr[6] = dcval;
00306 outptr[7] = dcval;
00307
00308 wsptr += DCTSIZE;
00309 continue;
00310 }
00311 #endif
00312
00313
00314
00315 tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
00316 tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
00317
00318 tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
00319 tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
00320 - tmp13;
00321
00322 tmp0 = tmp10 + tmp13;
00323 tmp3 = tmp10 - tmp13;
00324 tmp1 = tmp11 + tmp12;
00325 tmp2 = tmp11 - tmp12;
00326
00327
00328
00329 z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
00330 z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
00331 z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
00332 z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
00333
00334 tmp7 = z11 + z13;
00335 tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562);
00336
00337 z5 = MULTIPLY(z10 + z12, FIX_1_847759065);
00338 tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5;
00339 tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5;
00340
00341 tmp6 = tmp12 - tmp7;
00342 tmp5 = tmp11 - tmp6;
00343 tmp4 = tmp10 + tmp5;
00344
00345
00346
00347 outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
00348 & RANGE_MASK];
00349 outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
00350 & RANGE_MASK];
00351 outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
00352 & RANGE_MASK];
00353 outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
00354 & RANGE_MASK];
00355 outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
00356 & RANGE_MASK];
00357 outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
00358 & RANGE_MASK];
00359 outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
00360 & RANGE_MASK];
00361 outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
00362 & RANGE_MASK];
00363
00364 wsptr += DCTSIZE;
00365 }
00366 }
00367
00368 #endif