Libav
|
00001 /* 00002 * jrevdct.c 00003 * 00004 * This file is part of the Independent JPEG Group's software. 00005 * 00006 * The authors make NO WARRANTY or representation, either express or implied, 00007 * with respect to this software, its quality, accuracy, merchantability, or 00008 * fitness for a particular purpose. This software is provided "AS IS", and 00009 * you, its user, assume the entire risk as to its quality and accuracy. 00010 * 00011 * This software is copyright (C) 1991, 1992, Thomas G. Lane. 00012 * All Rights Reserved except as specified below. 00013 * 00014 * Permission is hereby granted to use, copy, modify, and distribute this 00015 * software (or portions thereof) for any purpose, without fee, subject to 00016 * these conditions: 00017 * (1) If any part of the source code for this software is distributed, then 00018 * this README file must be included, with this copyright and no-warranty 00019 * notice unaltered; and any additions, deletions, or changes to the original 00020 * files must be clearly indicated in accompanying documentation. 00021 * (2) If only executable code is distributed, then the accompanying 00022 * documentation must state that "this software is based in part on the work 00023 * of the Independent JPEG Group". 00024 * (3) Permission for use of this software is granted only if the user accepts 00025 * full responsibility for any undesirable consequences; the authors accept 00026 * NO LIABILITY for damages of any kind. 00027 * 00028 * These conditions apply to any software derived from or based on the IJG 00029 * code, not just to the unmodified library. If you use our work, you ought 00030 * to acknowledge us. 00031 * 00032 * Permission is NOT granted for the use of any IJG author's name or company 00033 * name in advertising or publicity relating to this software or products 00034 * derived from it. This software may be referred to only as "the Independent 00035 * JPEG Group's software". 00036 * 00037 * We specifically permit and encourage the use of this software as the basis 00038 * of commercial products, provided that all warranty or liability claims are 00039 * assumed by the product vendor. 00040 * 00041 * This file contains the basic inverse-DCT transformation subroutine. 00042 * 00043 * This implementation is based on an algorithm described in 00044 * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT 00045 * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics, 00046 * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991. 00047 * The primary algorithm described there uses 11 multiplies and 29 adds. 00048 * We use their alternate method with 12 multiplies and 32 adds. 00049 * The advantage of this method is that no data path contains more than one 00050 * multiplication; this allows a very simple and accurate implementation in 00051 * scaled fixed-point arithmetic, with a minimal number of shifts. 00052 * 00053 * I've made lots of modifications to attempt to take advantage of the 00054 * sparse nature of the DCT matrices we're getting. Although the logic 00055 * is cumbersome, it's straightforward and the resulting code is much 00056 * faster. 00057 * 00058 * A better way to do this would be to pass in the DCT block as a sparse 00059 * matrix, perhaps with the difference cases encoded. 00060 */ 00061 00067 #include "libavutil/common.h" 00068 #include "dsputil.h" 00069 00070 #define EIGHT_BIT_SAMPLES 00071 00072 #define DCTSIZE 8 00073 #define DCTSIZE2 64 00074 00075 #define GLOBAL 00076 00077 #define RIGHT_SHIFT(x, n) ((x) >> (n)) 00078 00079 typedef DCTELEM DCTBLOCK[DCTSIZE2]; 00080 00081 #define CONST_BITS 13 00082 00083 /* 00084 * This routine is specialized to the case DCTSIZE = 8. 00085 */ 00086 00087 #if DCTSIZE != 8 00088 Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ 00089 #endif 00090 00091 00092 /* 00093 * A 2-D IDCT can be done by 1-D IDCT on each row followed by 1-D IDCT 00094 * on each column. Direct algorithms are also available, but they are 00095 * much more complex and seem not to be any faster when reduced to code. 00096 * 00097 * The poop on this scaling stuff is as follows: 00098 * 00099 * Each 1-D IDCT step produces outputs which are a factor of sqrt(N) 00100 * larger than the true IDCT outputs. The final outputs are therefore 00101 * a factor of N larger than desired; since N=8 this can be cured by 00102 * a simple right shift at the end of the algorithm. The advantage of 00103 * this arrangement is that we save two multiplications per 1-D IDCT, 00104 * because the y0 and y4 inputs need not be divided by sqrt(N). 00105 * 00106 * We have to do addition and subtraction of the integer inputs, which 00107 * is no problem, and multiplication by fractional constants, which is 00108 * a problem to do in integer arithmetic. We multiply all the constants 00109 * by CONST_SCALE and convert them to integer constants (thus retaining 00110 * CONST_BITS bits of precision in the constants). After doing a 00111 * multiplication we have to divide the product by CONST_SCALE, with proper 00112 * rounding, to produce the correct output. This division can be done 00113 * cheaply as a right shift of CONST_BITS bits. We postpone shifting 00114 * as long as possible so that partial sums can be added together with 00115 * full fractional precision. 00116 * 00117 * The outputs of the first pass are scaled up by PASS1_BITS bits so that 00118 * they are represented to better-than-integral precision. These outputs 00119 * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word 00120 * with the recommended scaling. (To scale up 12-bit sample data further, an 00121 * intermediate int32 array would be needed.) 00122 * 00123 * To avoid overflow of the 32-bit intermediate results in pass 2, we must 00124 * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis 00125 * shows that the values given below are the most effective. 00126 */ 00127 00128 #ifdef EIGHT_BIT_SAMPLES 00129 #define PASS1_BITS 2 00130 #else 00131 #define PASS1_BITS 1 /* lose a little precision to avoid overflow */ 00132 #endif 00133 00134 #define ONE ((int32_t) 1) 00135 00136 #define CONST_SCALE (ONE << CONST_BITS) 00137 00138 /* Convert a positive real constant to an integer scaled by CONST_SCALE. 00139 * IMPORTANT: if your compiler doesn't do this arithmetic at compile time, 00140 * you will pay a significant penalty in run time. In that case, figure 00141 * the correct integer constant values and insert them by hand. 00142 */ 00143 00144 /* Actually FIX is no longer used, we precomputed them all */ 00145 #define FIX(x) ((int32_t) ((x) * CONST_SCALE + 0.5)) 00146 00147 /* Descale and correctly round an int32_t value that's scaled by N bits. 00148 * We assume RIGHT_SHIFT rounds towards minus infinity, so adding 00149 * the fudge factor is correct for either sign of X. 00150 */ 00151 00152 #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) 00153 00154 /* Multiply an int32_t variable by an int32_t constant to yield an int32_t result. 00155 * For 8-bit samples with the recommended scaling, all the variable 00156 * and constant values involved are no more than 16 bits wide, so a 00157 * 16x16->32 bit multiply can be used instead of a full 32x32 multiply; 00158 * this provides a useful speedup on many machines. 00159 * There is no way to specify a 16x16->32 multiply in portable C, but 00160 * some C compilers will do the right thing if you provide the correct 00161 * combination of casts. 00162 * NB: for 12-bit samples, a full 32-bit multiplication will be needed. 00163 */ 00164 00165 #ifdef EIGHT_BIT_SAMPLES 00166 #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ 00167 #define MULTIPLY(var,const) (((int16_t) (var)) * ((int16_t) (const))) 00168 #endif 00169 #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */ 00170 #define MULTIPLY(var,const) (((int16_t) (var)) * ((int32_t) (const))) 00171 #endif 00172 #endif 00173 00174 #ifndef MULTIPLY /* default definition */ 00175 #define MULTIPLY(var,const) ((var) * (const)) 00176 #endif 00177 00178 00179 /* 00180 Unlike our decoder where we approximate the FIXes, we need to use exact 00181 ones here or successive P-frames will drift too much with Reference frame coding 00182 */ 00183 #define FIX_0_211164243 1730 00184 #define FIX_0_275899380 2260 00185 #define FIX_0_298631336 2446 00186 #define FIX_0_390180644 3196 00187 #define FIX_0_509795579 4176 00188 #define FIX_0_541196100 4433 00189 #define FIX_0_601344887 4926 00190 #define FIX_0_765366865 6270 00191 #define FIX_0_785694958 6436 00192 #define FIX_0_899976223 7373 00193 #define FIX_1_061594337 8697 00194 #define FIX_1_111140466 9102 00195 #define FIX_1_175875602 9633 00196 #define FIX_1_306562965 10703 00197 #define FIX_1_387039845 11363 00198 #define FIX_1_451774981 11893 00199 #define FIX_1_501321110 12299 00200 #define FIX_1_662939225 13623 00201 #define FIX_1_847759065 15137 00202 #define FIX_1_961570560 16069 00203 #define FIX_2_053119869 16819 00204 #define FIX_2_172734803 17799 00205 #define FIX_2_562915447 20995 00206 #define FIX_3_072711026 25172 00207 00208 /* 00209 * Perform the inverse DCT on one block of coefficients. 00210 */ 00211 00212 void j_rev_dct(DCTBLOCK data) 00213 { 00214 int32_t tmp0, tmp1, tmp2, tmp3; 00215 int32_t tmp10, tmp11, tmp12, tmp13; 00216 int32_t z1, z2, z3, z4, z5; 00217 int32_t d0, d1, d2, d3, d4, d5, d6, d7; 00218 register DCTELEM *dataptr; 00219 int rowctr; 00220 00221 /* Pass 1: process rows. */ 00222 /* Note results are scaled up by sqrt(8) compared to a true IDCT; */ 00223 /* furthermore, we scale the results by 2**PASS1_BITS. */ 00224 00225 dataptr = data; 00226 00227 for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) { 00228 /* Due to quantization, we will usually find that many of the input 00229 * coefficients are zero, especially the AC terms. We can exploit this 00230 * by short-circuiting the IDCT calculation for any row in which all 00231 * the AC terms are zero. In that case each output is equal to the 00232 * DC coefficient (with scale factor as needed). 00233 * With typical images and quantization tables, half or more of the 00234 * row DCT calculations can be simplified this way. 00235 */ 00236 00237 register int *idataptr = (int*)dataptr; 00238 00239 /* WARNING: we do the same permutation as MMX idct to simplify the 00240 video core */ 00241 d0 = dataptr[0]; 00242 d2 = dataptr[1]; 00243 d4 = dataptr[2]; 00244 d6 = dataptr[3]; 00245 d1 = dataptr[4]; 00246 d3 = dataptr[5]; 00247 d5 = dataptr[6]; 00248 d7 = dataptr[7]; 00249 00250 if ((d1 | d2 | d3 | d4 | d5 | d6 | d7) == 0) { 00251 /* AC terms all zero */ 00252 if (d0) { 00253 /* Compute a 32 bit value to assign. */ 00254 DCTELEM dcval = (DCTELEM) (d0 << PASS1_BITS); 00255 register int v = (dcval & 0xffff) | ((dcval << 16) & 0xffff0000); 00256 00257 idataptr[0] = v; 00258 idataptr[1] = v; 00259 idataptr[2] = v; 00260 idataptr[3] = v; 00261 } 00262 00263 dataptr += DCTSIZE; /* advance pointer to next row */ 00264 continue; 00265 } 00266 00267 /* Even part: reverse the even part of the forward DCT. */ 00268 /* The rotator is sqrt(2)*c(-6). */ 00269 { 00270 if (d6) { 00271 if (d2) { 00272 /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */ 00273 z1 = MULTIPLY(d2 + d6, FIX_0_541196100); 00274 tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065); 00275 tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865); 00276 00277 tmp0 = (d0 + d4) << CONST_BITS; 00278 tmp1 = (d0 - d4) << CONST_BITS; 00279 00280 tmp10 = tmp0 + tmp3; 00281 tmp13 = tmp0 - tmp3; 00282 tmp11 = tmp1 + tmp2; 00283 tmp12 = tmp1 - tmp2; 00284 } else { 00285 /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */ 00286 tmp2 = MULTIPLY(-d6, FIX_1_306562965); 00287 tmp3 = MULTIPLY(d6, FIX_0_541196100); 00288 00289 tmp0 = (d0 + d4) << CONST_BITS; 00290 tmp1 = (d0 - d4) << CONST_BITS; 00291 00292 tmp10 = tmp0 + tmp3; 00293 tmp13 = tmp0 - tmp3; 00294 tmp11 = tmp1 + tmp2; 00295 tmp12 = tmp1 - tmp2; 00296 } 00297 } else { 00298 if (d2) { 00299 /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */ 00300 tmp2 = MULTIPLY(d2, FIX_0_541196100); 00301 tmp3 = MULTIPLY(d2, FIX_1_306562965); 00302 00303 tmp0 = (d0 + d4) << CONST_BITS; 00304 tmp1 = (d0 - d4) << CONST_BITS; 00305 00306 tmp10 = tmp0 + tmp3; 00307 tmp13 = tmp0 - tmp3; 00308 tmp11 = tmp1 + tmp2; 00309 tmp12 = tmp1 - tmp2; 00310 } else { 00311 /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */ 00312 tmp10 = tmp13 = (d0 + d4) << CONST_BITS; 00313 tmp11 = tmp12 = (d0 - d4) << CONST_BITS; 00314 } 00315 } 00316 00317 /* Odd part per figure 8; the matrix is unitary and hence its 00318 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. 00319 */ 00320 00321 if (d7) { 00322 if (d5) { 00323 if (d3) { 00324 if (d1) { 00325 /* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */ 00326 z1 = d7 + d1; 00327 z2 = d5 + d3; 00328 z3 = d7 + d3; 00329 z4 = d5 + d1; 00330 z5 = MULTIPLY(z3 + z4, FIX_1_175875602); 00331 00332 tmp0 = MULTIPLY(d7, FIX_0_298631336); 00333 tmp1 = MULTIPLY(d5, FIX_2_053119869); 00334 tmp2 = MULTIPLY(d3, FIX_3_072711026); 00335 tmp3 = MULTIPLY(d1, FIX_1_501321110); 00336 z1 = MULTIPLY(-z1, FIX_0_899976223); 00337 z2 = MULTIPLY(-z2, FIX_2_562915447); 00338 z3 = MULTIPLY(-z3, FIX_1_961570560); 00339 z4 = MULTIPLY(-z4, FIX_0_390180644); 00340 00341 z3 += z5; 00342 z4 += z5; 00343 00344 tmp0 += z1 + z3; 00345 tmp1 += z2 + z4; 00346 tmp2 += z2 + z3; 00347 tmp3 += z1 + z4; 00348 } else { 00349 /* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */ 00350 z2 = d5 + d3; 00351 z3 = d7 + d3; 00352 z5 = MULTIPLY(z3 + d5, FIX_1_175875602); 00353 00354 tmp0 = MULTIPLY(d7, FIX_0_298631336); 00355 tmp1 = MULTIPLY(d5, FIX_2_053119869); 00356 tmp2 = MULTIPLY(d3, FIX_3_072711026); 00357 z1 = MULTIPLY(-d7, FIX_0_899976223); 00358 z2 = MULTIPLY(-z2, FIX_2_562915447); 00359 z3 = MULTIPLY(-z3, FIX_1_961570560); 00360 z4 = MULTIPLY(-d5, FIX_0_390180644); 00361 00362 z3 += z5; 00363 z4 += z5; 00364 00365 tmp0 += z1 + z3; 00366 tmp1 += z2 + z4; 00367 tmp2 += z2 + z3; 00368 tmp3 = z1 + z4; 00369 } 00370 } else { 00371 if (d1) { 00372 /* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */ 00373 z1 = d7 + d1; 00374 z4 = d5 + d1; 00375 z5 = MULTIPLY(d7 + z4, FIX_1_175875602); 00376 00377 tmp0 = MULTIPLY(d7, FIX_0_298631336); 00378 tmp1 = MULTIPLY(d5, FIX_2_053119869); 00379 tmp3 = MULTIPLY(d1, FIX_1_501321110); 00380 z1 = MULTIPLY(-z1, FIX_0_899976223); 00381 z2 = MULTIPLY(-d5, FIX_2_562915447); 00382 z3 = MULTIPLY(-d7, FIX_1_961570560); 00383 z4 = MULTIPLY(-z4, FIX_0_390180644); 00384 00385 z3 += z5; 00386 z4 += z5; 00387 00388 tmp0 += z1 + z3; 00389 tmp1 += z2 + z4; 00390 tmp2 = z2 + z3; 00391 tmp3 += z1 + z4; 00392 } else { 00393 /* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */ 00394 tmp0 = MULTIPLY(-d7, FIX_0_601344887); 00395 z1 = MULTIPLY(-d7, FIX_0_899976223); 00396 z3 = MULTIPLY(-d7, FIX_1_961570560); 00397 tmp1 = MULTIPLY(-d5, FIX_0_509795579); 00398 z2 = MULTIPLY(-d5, FIX_2_562915447); 00399 z4 = MULTIPLY(-d5, FIX_0_390180644); 00400 z5 = MULTIPLY(d5 + d7, FIX_1_175875602); 00401 00402 z3 += z5; 00403 z4 += z5; 00404 00405 tmp0 += z3; 00406 tmp1 += z4; 00407 tmp2 = z2 + z3; 00408 tmp3 = z1 + z4; 00409 } 00410 } 00411 } else { 00412 if (d3) { 00413 if (d1) { 00414 /* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */ 00415 z1 = d7 + d1; 00416 z3 = d7 + d3; 00417 z5 = MULTIPLY(z3 + d1, FIX_1_175875602); 00418 00419 tmp0 = MULTIPLY(d7, FIX_0_298631336); 00420 tmp2 = MULTIPLY(d3, FIX_3_072711026); 00421 tmp3 = MULTIPLY(d1, FIX_1_501321110); 00422 z1 = MULTIPLY(-z1, FIX_0_899976223); 00423 z2 = MULTIPLY(-d3, FIX_2_562915447); 00424 z3 = MULTIPLY(-z3, FIX_1_961570560); 00425 z4 = MULTIPLY(-d1, FIX_0_390180644); 00426 00427 z3 += z5; 00428 z4 += z5; 00429 00430 tmp0 += z1 + z3; 00431 tmp1 = z2 + z4; 00432 tmp2 += z2 + z3; 00433 tmp3 += z1 + z4; 00434 } else { 00435 /* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */ 00436 z3 = d7 + d3; 00437 00438 tmp0 = MULTIPLY(-d7, FIX_0_601344887); 00439 z1 = MULTIPLY(-d7, FIX_0_899976223); 00440 tmp2 = MULTIPLY(d3, FIX_0_509795579); 00441 z2 = MULTIPLY(-d3, FIX_2_562915447); 00442 z5 = MULTIPLY(z3, FIX_1_175875602); 00443 z3 = MULTIPLY(-z3, FIX_0_785694958); 00444 00445 tmp0 += z3; 00446 tmp1 = z2 + z5; 00447 tmp2 += z3; 00448 tmp3 = z1 + z5; 00449 } 00450 } else { 00451 if (d1) { 00452 /* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */ 00453 z1 = d7 + d1; 00454 z5 = MULTIPLY(z1, FIX_1_175875602); 00455 00456 z1 = MULTIPLY(z1, FIX_0_275899380); 00457 z3 = MULTIPLY(-d7, FIX_1_961570560); 00458 tmp0 = MULTIPLY(-d7, FIX_1_662939225); 00459 z4 = MULTIPLY(-d1, FIX_0_390180644); 00460 tmp3 = MULTIPLY(d1, FIX_1_111140466); 00461 00462 tmp0 += z1; 00463 tmp1 = z4 + z5; 00464 tmp2 = z3 + z5; 00465 tmp3 += z1; 00466 } else { 00467 /* d1 == 0, d3 == 0, d5 == 0, d7 != 0 */ 00468 tmp0 = MULTIPLY(-d7, FIX_1_387039845); 00469 tmp1 = MULTIPLY(d7, FIX_1_175875602); 00470 tmp2 = MULTIPLY(-d7, FIX_0_785694958); 00471 tmp3 = MULTIPLY(d7, FIX_0_275899380); 00472 } 00473 } 00474 } 00475 } else { 00476 if (d5) { 00477 if (d3) { 00478 if (d1) { 00479 /* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */ 00480 z2 = d5 + d3; 00481 z4 = d5 + d1; 00482 z5 = MULTIPLY(d3 + z4, FIX_1_175875602); 00483 00484 tmp1 = MULTIPLY(d5, FIX_2_053119869); 00485 tmp2 = MULTIPLY(d3, FIX_3_072711026); 00486 tmp3 = MULTIPLY(d1, FIX_1_501321110); 00487 z1 = MULTIPLY(-d1, FIX_0_899976223); 00488 z2 = MULTIPLY(-z2, FIX_2_562915447); 00489 z3 = MULTIPLY(-d3, FIX_1_961570560); 00490 z4 = MULTIPLY(-z4, FIX_0_390180644); 00491 00492 z3 += z5; 00493 z4 += z5; 00494 00495 tmp0 = z1 + z3; 00496 tmp1 += z2 + z4; 00497 tmp2 += z2 + z3; 00498 tmp3 += z1 + z4; 00499 } else { 00500 /* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */ 00501 z2 = d5 + d3; 00502 00503 z5 = MULTIPLY(z2, FIX_1_175875602); 00504 tmp1 = MULTIPLY(d5, FIX_1_662939225); 00505 z4 = MULTIPLY(-d5, FIX_0_390180644); 00506 z2 = MULTIPLY(-z2, FIX_1_387039845); 00507 tmp2 = MULTIPLY(d3, FIX_1_111140466); 00508 z3 = MULTIPLY(-d3, FIX_1_961570560); 00509 00510 tmp0 = z3 + z5; 00511 tmp1 += z2; 00512 tmp2 += z2; 00513 tmp3 = z4 + z5; 00514 } 00515 } else { 00516 if (d1) { 00517 /* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */ 00518 z4 = d5 + d1; 00519 00520 z5 = MULTIPLY(z4, FIX_1_175875602); 00521 z1 = MULTIPLY(-d1, FIX_0_899976223); 00522 tmp3 = MULTIPLY(d1, FIX_0_601344887); 00523 tmp1 = MULTIPLY(-d5, FIX_0_509795579); 00524 z2 = MULTIPLY(-d5, FIX_2_562915447); 00525 z4 = MULTIPLY(z4, FIX_0_785694958); 00526 00527 tmp0 = z1 + z5; 00528 tmp1 += z4; 00529 tmp2 = z2 + z5; 00530 tmp3 += z4; 00531 } else { 00532 /* d1 == 0, d3 == 0, d5 != 0, d7 == 0 */ 00533 tmp0 = MULTIPLY(d5, FIX_1_175875602); 00534 tmp1 = MULTIPLY(d5, FIX_0_275899380); 00535 tmp2 = MULTIPLY(-d5, FIX_1_387039845); 00536 tmp3 = MULTIPLY(d5, FIX_0_785694958); 00537 } 00538 } 00539 } else { 00540 if (d3) { 00541 if (d1) { 00542 /* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */ 00543 z5 = d1 + d3; 00544 tmp3 = MULTIPLY(d1, FIX_0_211164243); 00545 tmp2 = MULTIPLY(-d3, FIX_1_451774981); 00546 z1 = MULTIPLY(d1, FIX_1_061594337); 00547 z2 = MULTIPLY(-d3, FIX_2_172734803); 00548 z4 = MULTIPLY(z5, FIX_0_785694958); 00549 z5 = MULTIPLY(z5, FIX_1_175875602); 00550 00551 tmp0 = z1 - z4; 00552 tmp1 = z2 + z4; 00553 tmp2 += z5; 00554 tmp3 += z5; 00555 } else { 00556 /* d1 == 0, d3 != 0, d5 == 0, d7 == 0 */ 00557 tmp0 = MULTIPLY(-d3, FIX_0_785694958); 00558 tmp1 = MULTIPLY(-d3, FIX_1_387039845); 00559 tmp2 = MULTIPLY(-d3, FIX_0_275899380); 00560 tmp3 = MULTIPLY(d3, FIX_1_175875602); 00561 } 00562 } else { 00563 if (d1) { 00564 /* d1 != 0, d3 == 0, d5 == 0, d7 == 0 */ 00565 tmp0 = MULTIPLY(d1, FIX_0_275899380); 00566 tmp1 = MULTIPLY(d1, FIX_0_785694958); 00567 tmp2 = MULTIPLY(d1, FIX_1_175875602); 00568 tmp3 = MULTIPLY(d1, FIX_1_387039845); 00569 } else { 00570 /* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */ 00571 tmp0 = tmp1 = tmp2 = tmp3 = 0; 00572 } 00573 } 00574 } 00575 } 00576 } 00577 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ 00578 00579 dataptr[0] = (DCTELEM) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS); 00580 dataptr[7] = (DCTELEM) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS); 00581 dataptr[1] = (DCTELEM) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS); 00582 dataptr[6] = (DCTELEM) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS); 00583 dataptr[2] = (DCTELEM) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS); 00584 dataptr[5] = (DCTELEM) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS); 00585 dataptr[3] = (DCTELEM) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS); 00586 dataptr[4] = (DCTELEM) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS); 00587 00588 dataptr += DCTSIZE; /* advance pointer to next row */ 00589 } 00590 00591 /* Pass 2: process columns. */ 00592 /* Note that we must descale the results by a factor of 8 == 2**3, */ 00593 /* and also undo the PASS1_BITS scaling. */ 00594 00595 dataptr = data; 00596 for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) { 00597 /* Columns of zeroes can be exploited in the same way as we did with rows. 00598 * However, the row calculation has created many nonzero AC terms, so the 00599 * simplification applies less often (typically 5% to 10% of the time). 00600 * On machines with very fast multiplication, it's possible that the 00601 * test takes more time than it's worth. In that case this section 00602 * may be commented out. 00603 */ 00604 00605 d0 = dataptr[DCTSIZE*0]; 00606 d1 = dataptr[DCTSIZE*1]; 00607 d2 = dataptr[DCTSIZE*2]; 00608 d3 = dataptr[DCTSIZE*3]; 00609 d4 = dataptr[DCTSIZE*4]; 00610 d5 = dataptr[DCTSIZE*5]; 00611 d6 = dataptr[DCTSIZE*6]; 00612 d7 = dataptr[DCTSIZE*7]; 00613 00614 /* Even part: reverse the even part of the forward DCT. */ 00615 /* The rotator is sqrt(2)*c(-6). */ 00616 if (d6) { 00617 if (d2) { 00618 /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */ 00619 z1 = MULTIPLY(d2 + d6, FIX_0_541196100); 00620 tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065); 00621 tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865); 00622 00623 tmp0 = (d0 + d4) << CONST_BITS; 00624 tmp1 = (d0 - d4) << CONST_BITS; 00625 00626 tmp10 = tmp0 + tmp3; 00627 tmp13 = tmp0 - tmp3; 00628 tmp11 = tmp1 + tmp2; 00629 tmp12 = tmp1 - tmp2; 00630 } else { 00631 /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */ 00632 tmp2 = MULTIPLY(-d6, FIX_1_306562965); 00633 tmp3 = MULTIPLY(d6, FIX_0_541196100); 00634 00635 tmp0 = (d0 + d4) << CONST_BITS; 00636 tmp1 = (d0 - d4) << CONST_BITS; 00637 00638 tmp10 = tmp0 + tmp3; 00639 tmp13 = tmp0 - tmp3; 00640 tmp11 = tmp1 + tmp2; 00641 tmp12 = tmp1 - tmp2; 00642 } 00643 } else { 00644 if (d2) { 00645 /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */ 00646 tmp2 = MULTIPLY(d2, FIX_0_541196100); 00647 tmp3 = MULTIPLY(d2, FIX_1_306562965); 00648 00649 tmp0 = (d0 + d4) << CONST_BITS; 00650 tmp1 = (d0 - d4) << CONST_BITS; 00651 00652 tmp10 = tmp0 + tmp3; 00653 tmp13 = tmp0 - tmp3; 00654 tmp11 = tmp1 + tmp2; 00655 tmp12 = tmp1 - tmp2; 00656 } else { 00657 /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */ 00658 tmp10 = tmp13 = (d0 + d4) << CONST_BITS; 00659 tmp11 = tmp12 = (d0 - d4) << CONST_BITS; 00660 } 00661 } 00662 00663 /* Odd part per figure 8; the matrix is unitary and hence its 00664 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. 00665 */ 00666 if (d7) { 00667 if (d5) { 00668 if (d3) { 00669 if (d1) { 00670 /* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */ 00671 z1 = d7 + d1; 00672 z2 = d5 + d3; 00673 z3 = d7 + d3; 00674 z4 = d5 + d1; 00675 z5 = MULTIPLY(z3 + z4, FIX_1_175875602); 00676 00677 tmp0 = MULTIPLY(d7, FIX_0_298631336); 00678 tmp1 = MULTIPLY(d5, FIX_2_053119869); 00679 tmp2 = MULTIPLY(d3, FIX_3_072711026); 00680 tmp3 = MULTIPLY(d1, FIX_1_501321110); 00681 z1 = MULTIPLY(-z1, FIX_0_899976223); 00682 z2 = MULTIPLY(-z2, FIX_2_562915447); 00683 z3 = MULTIPLY(-z3, FIX_1_961570560); 00684 z4 = MULTIPLY(-z4, FIX_0_390180644); 00685 00686 z3 += z5; 00687 z4 += z5; 00688 00689 tmp0 += z1 + z3; 00690 tmp1 += z2 + z4; 00691 tmp2 += z2 + z3; 00692 tmp3 += z1 + z4; 00693 } else { 00694 /* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */ 00695 z2 = d5 + d3; 00696 z3 = d7 + d3; 00697 z5 = MULTIPLY(z3 + d5, FIX_1_175875602); 00698 00699 tmp0 = MULTIPLY(d7, FIX_0_298631336); 00700 tmp1 = MULTIPLY(d5, FIX_2_053119869); 00701 tmp2 = MULTIPLY(d3, FIX_3_072711026); 00702 z1 = MULTIPLY(-d7, FIX_0_899976223); 00703 z2 = MULTIPLY(-z2, FIX_2_562915447); 00704 z3 = MULTIPLY(-z3, FIX_1_961570560); 00705 z4 = MULTIPLY(-d5, FIX_0_390180644); 00706 00707 z3 += z5; 00708 z4 += z5; 00709 00710 tmp0 += z1 + z3; 00711 tmp1 += z2 + z4; 00712 tmp2 += z2 + z3; 00713 tmp3 = z1 + z4; 00714 } 00715 } else { 00716 if (d1) { 00717 /* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */ 00718 z1 = d7 + d1; 00719 z3 = d7; 00720 z4 = d5 + d1; 00721 z5 = MULTIPLY(z3 + z4, FIX_1_175875602); 00722 00723 tmp0 = MULTIPLY(d7, FIX_0_298631336); 00724 tmp1 = MULTIPLY(d5, FIX_2_053119869); 00725 tmp3 = MULTIPLY(d1, FIX_1_501321110); 00726 z1 = MULTIPLY(-z1, FIX_0_899976223); 00727 z2 = MULTIPLY(-d5, FIX_2_562915447); 00728 z3 = MULTIPLY(-d7, FIX_1_961570560); 00729 z4 = MULTIPLY(-z4, FIX_0_390180644); 00730 00731 z3 += z5; 00732 z4 += z5; 00733 00734 tmp0 += z1 + z3; 00735 tmp1 += z2 + z4; 00736 tmp2 = z2 + z3; 00737 tmp3 += z1 + z4; 00738 } else { 00739 /* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */ 00740 tmp0 = MULTIPLY(-d7, FIX_0_601344887); 00741 z1 = MULTIPLY(-d7, FIX_0_899976223); 00742 z3 = MULTIPLY(-d7, FIX_1_961570560); 00743 tmp1 = MULTIPLY(-d5, FIX_0_509795579); 00744 z2 = MULTIPLY(-d5, FIX_2_562915447); 00745 z4 = MULTIPLY(-d5, FIX_0_390180644); 00746 z5 = MULTIPLY(d5 + d7, FIX_1_175875602); 00747 00748 z3 += z5; 00749 z4 += z5; 00750 00751 tmp0 += z3; 00752 tmp1 += z4; 00753 tmp2 = z2 + z3; 00754 tmp3 = z1 + z4; 00755 } 00756 } 00757 } else { 00758 if (d3) { 00759 if (d1) { 00760 /* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */ 00761 z1 = d7 + d1; 00762 z3 = d7 + d3; 00763 z5 = MULTIPLY(z3 + d1, FIX_1_175875602); 00764 00765 tmp0 = MULTIPLY(d7, FIX_0_298631336); 00766 tmp2 = MULTIPLY(d3, FIX_3_072711026); 00767 tmp3 = MULTIPLY(d1, FIX_1_501321110); 00768 z1 = MULTIPLY(-z1, FIX_0_899976223); 00769 z2 = MULTIPLY(-d3, FIX_2_562915447); 00770 z3 = MULTIPLY(-z3, FIX_1_961570560); 00771 z4 = MULTIPLY(-d1, FIX_0_390180644); 00772 00773 z3 += z5; 00774 z4 += z5; 00775 00776 tmp0 += z1 + z3; 00777 tmp1 = z2 + z4; 00778 tmp2 += z2 + z3; 00779 tmp3 += z1 + z4; 00780 } else { 00781 /* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */ 00782 z3 = d7 + d3; 00783 00784 tmp0 = MULTIPLY(-d7, FIX_0_601344887); 00785 z1 = MULTIPLY(-d7, FIX_0_899976223); 00786 tmp2 = MULTIPLY(d3, FIX_0_509795579); 00787 z2 = MULTIPLY(-d3, FIX_2_562915447); 00788 z5 = MULTIPLY(z3, FIX_1_175875602); 00789 z3 = MULTIPLY(-z3, FIX_0_785694958); 00790 00791 tmp0 += z3; 00792 tmp1 = z2 + z5; 00793 tmp2 += z3; 00794 tmp3 = z1 + z5; 00795 } 00796 } else { 00797 if (d1) { 00798 /* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */ 00799 z1 = d7 + d1; 00800 z5 = MULTIPLY(z1, FIX_1_175875602); 00801 00802 z1 = MULTIPLY(z1, FIX_0_275899380); 00803 z3 = MULTIPLY(-d7, FIX_1_961570560); 00804 tmp0 = MULTIPLY(-d7, FIX_1_662939225); 00805 z4 = MULTIPLY(-d1, FIX_0_390180644); 00806 tmp3 = MULTIPLY(d1, FIX_1_111140466); 00807 00808 tmp0 += z1; 00809 tmp1 = z4 + z5; 00810 tmp2 = z3 + z5; 00811 tmp3 += z1; 00812 } else { 00813 /* d1 == 0, d3 == 0, d5 == 0, d7 != 0 */ 00814 tmp0 = MULTIPLY(-d7, FIX_1_387039845); 00815 tmp1 = MULTIPLY(d7, FIX_1_175875602); 00816 tmp2 = MULTIPLY(-d7, FIX_0_785694958); 00817 tmp3 = MULTIPLY(d7, FIX_0_275899380); 00818 } 00819 } 00820 } 00821 } else { 00822 if (d5) { 00823 if (d3) { 00824 if (d1) { 00825 /* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */ 00826 z2 = d5 + d3; 00827 z4 = d5 + d1; 00828 z5 = MULTIPLY(d3 + z4, FIX_1_175875602); 00829 00830 tmp1 = MULTIPLY(d5, FIX_2_053119869); 00831 tmp2 = MULTIPLY(d3, FIX_3_072711026); 00832 tmp3 = MULTIPLY(d1, FIX_1_501321110); 00833 z1 = MULTIPLY(-d1, FIX_0_899976223); 00834 z2 = MULTIPLY(-z2, FIX_2_562915447); 00835 z3 = MULTIPLY(-d3, FIX_1_961570560); 00836 z4 = MULTIPLY(-z4, FIX_0_390180644); 00837 00838 z3 += z5; 00839 z4 += z5; 00840 00841 tmp0 = z1 + z3; 00842 tmp1 += z2 + z4; 00843 tmp2 += z2 + z3; 00844 tmp3 += z1 + z4; 00845 } else { 00846 /* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */ 00847 z2 = d5 + d3; 00848 00849 z5 = MULTIPLY(z2, FIX_1_175875602); 00850 tmp1 = MULTIPLY(d5, FIX_1_662939225); 00851 z4 = MULTIPLY(-d5, FIX_0_390180644); 00852 z2 = MULTIPLY(-z2, FIX_1_387039845); 00853 tmp2 = MULTIPLY(d3, FIX_1_111140466); 00854 z3 = MULTIPLY(-d3, FIX_1_961570560); 00855 00856 tmp0 = z3 + z5; 00857 tmp1 += z2; 00858 tmp2 += z2; 00859 tmp3 = z4 + z5; 00860 } 00861 } else { 00862 if (d1) { 00863 /* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */ 00864 z4 = d5 + d1; 00865 00866 z5 = MULTIPLY(z4, FIX_1_175875602); 00867 z1 = MULTIPLY(-d1, FIX_0_899976223); 00868 tmp3 = MULTIPLY(d1, FIX_0_601344887); 00869 tmp1 = MULTIPLY(-d5, FIX_0_509795579); 00870 z2 = MULTIPLY(-d5, FIX_2_562915447); 00871 z4 = MULTIPLY(z4, FIX_0_785694958); 00872 00873 tmp0 = z1 + z5; 00874 tmp1 += z4; 00875 tmp2 = z2 + z5; 00876 tmp3 += z4; 00877 } else { 00878 /* d1 == 0, d3 == 0, d5 != 0, d7 == 0 */ 00879 tmp0 = MULTIPLY(d5, FIX_1_175875602); 00880 tmp1 = MULTIPLY(d5, FIX_0_275899380); 00881 tmp2 = MULTIPLY(-d5, FIX_1_387039845); 00882 tmp3 = MULTIPLY(d5, FIX_0_785694958); 00883 } 00884 } 00885 } else { 00886 if (d3) { 00887 if (d1) { 00888 /* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */ 00889 z5 = d1 + d3; 00890 tmp3 = MULTIPLY(d1, FIX_0_211164243); 00891 tmp2 = MULTIPLY(-d3, FIX_1_451774981); 00892 z1 = MULTIPLY(d1, FIX_1_061594337); 00893 z2 = MULTIPLY(-d3, FIX_2_172734803); 00894 z4 = MULTIPLY(z5, FIX_0_785694958); 00895 z5 = MULTIPLY(z5, FIX_1_175875602); 00896 00897 tmp0 = z1 - z4; 00898 tmp1 = z2 + z4; 00899 tmp2 += z5; 00900 tmp3 += z5; 00901 } else { 00902 /* d1 == 0, d3 != 0, d5 == 0, d7 == 0 */ 00903 tmp0 = MULTIPLY(-d3, FIX_0_785694958); 00904 tmp1 = MULTIPLY(-d3, FIX_1_387039845); 00905 tmp2 = MULTIPLY(-d3, FIX_0_275899380); 00906 tmp3 = MULTIPLY(d3, FIX_1_175875602); 00907 } 00908 } else { 00909 if (d1) { 00910 /* d1 != 0, d3 == 0, d5 == 0, d7 == 0 */ 00911 tmp0 = MULTIPLY(d1, FIX_0_275899380); 00912 tmp1 = MULTIPLY(d1, FIX_0_785694958); 00913 tmp2 = MULTIPLY(d1, FIX_1_175875602); 00914 tmp3 = MULTIPLY(d1, FIX_1_387039845); 00915 } else { 00916 /* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */ 00917 tmp0 = tmp1 = tmp2 = tmp3 = 0; 00918 } 00919 } 00920 } 00921 } 00922 00923 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ 00924 00925 dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp3, 00926 CONST_BITS+PASS1_BITS+3); 00927 dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp10 - tmp3, 00928 CONST_BITS+PASS1_BITS+3); 00929 dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp11 + tmp2, 00930 CONST_BITS+PASS1_BITS+3); 00931 dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(tmp11 - tmp2, 00932 CONST_BITS+PASS1_BITS+3); 00933 dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp12 + tmp1, 00934 CONST_BITS+PASS1_BITS+3); 00935 dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12 - tmp1, 00936 CONST_BITS+PASS1_BITS+3); 00937 dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp13 + tmp0, 00938 CONST_BITS+PASS1_BITS+3); 00939 dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp13 - tmp0, 00940 CONST_BITS+PASS1_BITS+3); 00941 00942 dataptr++; /* advance pointer to next column */ 00943 } 00944 } 00945 00946 #undef DCTSIZE 00947 #define DCTSIZE 4 00948 #define DCTSTRIDE 8 00949 00950 void j_rev_dct4(DCTBLOCK data) 00951 { 00952 int32_t tmp0, tmp1, tmp2, tmp3; 00953 int32_t tmp10, tmp11, tmp12, tmp13; 00954 int32_t z1; 00955 int32_t d0, d2, d4, d6; 00956 register DCTELEM *dataptr; 00957 int rowctr; 00958 00959 /* Pass 1: process rows. */ 00960 /* Note results are scaled up by sqrt(8) compared to a true IDCT; */ 00961 /* furthermore, we scale the results by 2**PASS1_BITS. */ 00962 00963 data[0] += 4; 00964 00965 dataptr = data; 00966 00967 for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) { 00968 /* Due to quantization, we will usually find that many of the input 00969 * coefficients are zero, especially the AC terms. We can exploit this 00970 * by short-circuiting the IDCT calculation for any row in which all 00971 * the AC terms are zero. In that case each output is equal to the 00972 * DC coefficient (with scale factor as needed). 00973 * With typical images and quantization tables, half or more of the 00974 * row DCT calculations can be simplified this way. 00975 */ 00976 00977 register int *idataptr = (int*)dataptr; 00978 00979 d0 = dataptr[0]; 00980 d2 = dataptr[1]; 00981 d4 = dataptr[2]; 00982 d6 = dataptr[3]; 00983 00984 if ((d2 | d4 | d6) == 0) { 00985 /* AC terms all zero */ 00986 if (d0) { 00987 /* Compute a 32 bit value to assign. */ 00988 DCTELEM dcval = (DCTELEM) (d0 << PASS1_BITS); 00989 register int v = (dcval & 0xffff) | ((dcval << 16) & 0xffff0000); 00990 00991 idataptr[0] = v; 00992 idataptr[1] = v; 00993 } 00994 00995 dataptr += DCTSTRIDE; /* advance pointer to next row */ 00996 continue; 00997 } 00998 00999 /* Even part: reverse the even part of the forward DCT. */ 01000 /* The rotator is sqrt(2)*c(-6). */ 01001 if (d6) { 01002 if (d2) { 01003 /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */ 01004 z1 = MULTIPLY(d2 + d6, FIX_0_541196100); 01005 tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065); 01006 tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865); 01007 01008 tmp0 = (d0 + d4) << CONST_BITS; 01009 tmp1 = (d0 - d4) << CONST_BITS; 01010 01011 tmp10 = tmp0 + tmp3; 01012 tmp13 = tmp0 - tmp3; 01013 tmp11 = tmp1 + tmp2; 01014 tmp12 = tmp1 - tmp2; 01015 } else { 01016 /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */ 01017 tmp2 = MULTIPLY(-d6, FIX_1_306562965); 01018 tmp3 = MULTIPLY(d6, FIX_0_541196100); 01019 01020 tmp0 = (d0 + d4) << CONST_BITS; 01021 tmp1 = (d0 - d4) << CONST_BITS; 01022 01023 tmp10 = tmp0 + tmp3; 01024 tmp13 = tmp0 - tmp3; 01025 tmp11 = tmp1 + tmp2; 01026 tmp12 = tmp1 - tmp2; 01027 } 01028 } else { 01029 if (d2) { 01030 /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */ 01031 tmp2 = MULTIPLY(d2, FIX_0_541196100); 01032 tmp3 = MULTIPLY(d2, FIX_1_306562965); 01033 01034 tmp0 = (d0 + d4) << CONST_BITS; 01035 tmp1 = (d0 - d4) << CONST_BITS; 01036 01037 tmp10 = tmp0 + tmp3; 01038 tmp13 = tmp0 - tmp3; 01039 tmp11 = tmp1 + tmp2; 01040 tmp12 = tmp1 - tmp2; 01041 } else { 01042 /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */ 01043 tmp10 = tmp13 = (d0 + d4) << CONST_BITS; 01044 tmp11 = tmp12 = (d0 - d4) << CONST_BITS; 01045 } 01046 } 01047 01048 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ 01049 01050 dataptr[0] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS); 01051 dataptr[1] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS); 01052 dataptr[2] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS); 01053 dataptr[3] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS); 01054 01055 dataptr += DCTSTRIDE; /* advance pointer to next row */ 01056 } 01057 01058 /* Pass 2: process columns. */ 01059 /* Note that we must descale the results by a factor of 8 == 2**3, */ 01060 /* and also undo the PASS1_BITS scaling. */ 01061 01062 dataptr = data; 01063 for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) { 01064 /* Columns of zeroes can be exploited in the same way as we did with rows. 01065 * However, the row calculation has created many nonzero AC terms, so the 01066 * simplification applies less often (typically 5% to 10% of the time). 01067 * On machines with very fast multiplication, it's possible that the 01068 * test takes more time than it's worth. In that case this section 01069 * may be commented out. 01070 */ 01071 01072 d0 = dataptr[DCTSTRIDE*0]; 01073 d2 = dataptr[DCTSTRIDE*1]; 01074 d4 = dataptr[DCTSTRIDE*2]; 01075 d6 = dataptr[DCTSTRIDE*3]; 01076 01077 /* Even part: reverse the even part of the forward DCT. */ 01078 /* The rotator is sqrt(2)*c(-6). */ 01079 if (d6) { 01080 if (d2) { 01081 /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */ 01082 z1 = MULTIPLY(d2 + d6, FIX_0_541196100); 01083 tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065); 01084 tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865); 01085 01086 tmp0 = (d0 + d4) << CONST_BITS; 01087 tmp1 = (d0 - d4) << CONST_BITS; 01088 01089 tmp10 = tmp0 + tmp3; 01090 tmp13 = tmp0 - tmp3; 01091 tmp11 = tmp1 + tmp2; 01092 tmp12 = tmp1 - tmp2; 01093 } else { 01094 /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */ 01095 tmp2 = MULTIPLY(-d6, FIX_1_306562965); 01096 tmp3 = MULTIPLY(d6, FIX_0_541196100); 01097 01098 tmp0 = (d0 + d4) << CONST_BITS; 01099 tmp1 = (d0 - d4) << CONST_BITS; 01100 01101 tmp10 = tmp0 + tmp3; 01102 tmp13 = tmp0 - tmp3; 01103 tmp11 = tmp1 + tmp2; 01104 tmp12 = tmp1 - tmp2; 01105 } 01106 } else { 01107 if (d2) { 01108 /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */ 01109 tmp2 = MULTIPLY(d2, FIX_0_541196100); 01110 tmp3 = MULTIPLY(d2, FIX_1_306562965); 01111 01112 tmp0 = (d0 + d4) << CONST_BITS; 01113 tmp1 = (d0 - d4) << CONST_BITS; 01114 01115 tmp10 = tmp0 + tmp3; 01116 tmp13 = tmp0 - tmp3; 01117 tmp11 = tmp1 + tmp2; 01118 tmp12 = tmp1 - tmp2; 01119 } else { 01120 /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */ 01121 tmp10 = tmp13 = (d0 + d4) << CONST_BITS; 01122 tmp11 = tmp12 = (d0 - d4) << CONST_BITS; 01123 } 01124 } 01125 01126 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ 01127 01128 dataptr[DCTSTRIDE*0] = tmp10 >> (CONST_BITS+PASS1_BITS+3); 01129 dataptr[DCTSTRIDE*1] = tmp11 >> (CONST_BITS+PASS1_BITS+3); 01130 dataptr[DCTSTRIDE*2] = tmp12 >> (CONST_BITS+PASS1_BITS+3); 01131 dataptr[DCTSTRIDE*3] = tmp13 >> (CONST_BITS+PASS1_BITS+3); 01132 01133 dataptr++; /* advance pointer to next column */ 01134 } 01135 } 01136 01137 void j_rev_dct2(DCTBLOCK data){ 01138 int d00, d01, d10, d11; 01139 01140 data[0] += 4; 01141 d00 = data[0+0*DCTSTRIDE] + data[1+0*DCTSTRIDE]; 01142 d01 = data[0+0*DCTSTRIDE] - data[1+0*DCTSTRIDE]; 01143 d10 = data[0+1*DCTSTRIDE] + data[1+1*DCTSTRIDE]; 01144 d11 = data[0+1*DCTSTRIDE] - data[1+1*DCTSTRIDE]; 01145 01146 data[0+0*DCTSTRIDE]= (d00 + d10)>>3; 01147 data[1+0*DCTSTRIDE]= (d01 + d11)>>3; 01148 data[0+1*DCTSTRIDE]= (d00 - d10)>>3; 01149 data[1+1*DCTSTRIDE]= (d01 - d11)>>3; 01150 } 01151 01152 void j_rev_dct1(DCTBLOCK data){ 01153 data[0] = (data[0] + 4)>>3; 01154 } 01155 01156 #undef FIX 01157 #undef CONST_BITS