• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/jrevdct.c

Go to the documentation of this file.
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                     z1 = d7;
00696                     z2 = d5 + d3;
00697                     z3 = d7 + d3;
00698                     z5 = MULTIPLY(z3 + d5, FIX_1_175875602);
00699 
00700                     tmp0 = MULTIPLY(d7, FIX_0_298631336);
00701                     tmp1 = MULTIPLY(d5, FIX_2_053119869);
00702                     tmp2 = MULTIPLY(d3, FIX_3_072711026);
00703                     z1 = MULTIPLY(-d7, FIX_0_899976223);
00704                     z2 = MULTIPLY(-z2, FIX_2_562915447);
00705                     z3 = MULTIPLY(-z3, FIX_1_961570560);
00706                     z4 = MULTIPLY(-d5, FIX_0_390180644);
00707 
00708                     z3 += z5;
00709                     z4 += z5;
00710 
00711                     tmp0 += z1 + z3;
00712                     tmp1 += z2 + z4;
00713                     tmp2 += z2 + z3;
00714                     tmp3 = z1 + z4;
00715                 }
00716             } else {
00717                 if (d1) {
00718                     /* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */
00719                     z1 = d7 + d1;
00720                     z2 = d5;
00721                     z3 = d7;
00722                     z4 = d5 + d1;
00723                     z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
00724 
00725                     tmp0 = MULTIPLY(d7, FIX_0_298631336);
00726                     tmp1 = MULTIPLY(d5, FIX_2_053119869);
00727                     tmp3 = MULTIPLY(d1, FIX_1_501321110);
00728                     z1 = MULTIPLY(-z1, FIX_0_899976223);
00729                     z2 = MULTIPLY(-d5, FIX_2_562915447);
00730                     z3 = MULTIPLY(-d7, FIX_1_961570560);
00731                     z4 = MULTIPLY(-z4, FIX_0_390180644);
00732 
00733                     z3 += z5;
00734                     z4 += z5;
00735 
00736                     tmp0 += z1 + z3;
00737                     tmp1 += z2 + z4;
00738                     tmp2 = z2 + z3;
00739                     tmp3 += z1 + z4;
00740                 } else {
00741                     /* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */
00742                     tmp0 = MULTIPLY(-d7, FIX_0_601344887);
00743                     z1 = MULTIPLY(-d7, FIX_0_899976223);
00744                     z3 = MULTIPLY(-d7, FIX_1_961570560);
00745                     tmp1 = MULTIPLY(-d5, FIX_0_509795579);
00746                     z2 = MULTIPLY(-d5, FIX_2_562915447);
00747                     z4 = MULTIPLY(-d5, FIX_0_390180644);
00748                     z5 = MULTIPLY(d5 + d7, FIX_1_175875602);
00749 
00750                     z3 += z5;
00751                     z4 += z5;
00752 
00753                     tmp0 += z3;
00754                     tmp1 += z4;
00755                     tmp2 = z2 + z3;
00756                     tmp3 = z1 + z4;
00757                 }
00758             }
00759         } else {
00760             if (d3) {
00761                 if (d1) {
00762                     /* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */
00763                     z1 = d7 + d1;
00764                     z3 = d7 + d3;
00765                     z5 = MULTIPLY(z3 + d1, FIX_1_175875602);
00766 
00767                     tmp0 = MULTIPLY(d7, FIX_0_298631336);
00768                     tmp2 = MULTIPLY(d3, FIX_3_072711026);
00769                     tmp3 = MULTIPLY(d1, FIX_1_501321110);
00770                     z1 = MULTIPLY(-z1, FIX_0_899976223);
00771                     z2 = MULTIPLY(-d3, FIX_2_562915447);
00772                     z3 = MULTIPLY(-z3, FIX_1_961570560);
00773                     z4 = MULTIPLY(-d1, FIX_0_390180644);
00774 
00775                     z3 += z5;
00776                     z4 += z5;
00777 
00778                     tmp0 += z1 + z3;
00779                     tmp1 = z2 + z4;
00780                     tmp2 += z2 + z3;
00781                     tmp3 += z1 + z4;
00782                 } else {
00783                     /* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */
00784                     z3 = d7 + d3;
00785 
00786                     tmp0 = MULTIPLY(-d7, FIX_0_601344887);
00787                     z1 = MULTIPLY(-d7, FIX_0_899976223);
00788                     tmp2 = MULTIPLY(d3, FIX_0_509795579);
00789                     z2 = MULTIPLY(-d3, FIX_2_562915447);
00790                     z5 = MULTIPLY(z3, FIX_1_175875602);
00791                     z3 = MULTIPLY(-z3, FIX_0_785694958);
00792 
00793                     tmp0 += z3;
00794                     tmp1 = z2 + z5;
00795                     tmp2 += z3;
00796                     tmp3 = z1 + z5;
00797                 }
00798             } else {
00799                 if (d1) {
00800                     /* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */
00801                     z1 = d7 + d1;
00802                     z5 = MULTIPLY(z1, FIX_1_175875602);
00803 
00804                     z1 = MULTIPLY(z1, FIX_0_275899380);
00805                     z3 = MULTIPLY(-d7, FIX_1_961570560);
00806                     tmp0 = MULTIPLY(-d7, FIX_1_662939225);
00807                     z4 = MULTIPLY(-d1, FIX_0_390180644);
00808                     tmp3 = MULTIPLY(d1, FIX_1_111140466);
00809 
00810                     tmp0 += z1;
00811                     tmp1 = z4 + z5;
00812                     tmp2 = z3 + z5;
00813                     tmp3 += z1;
00814                 } else {
00815                     /* d1 == 0, d3 == 0, d5 == 0, d7 != 0 */
00816                     tmp0 = MULTIPLY(-d7, FIX_1_387039845);
00817                     tmp1 = MULTIPLY(d7, FIX_1_175875602);
00818                     tmp2 = MULTIPLY(-d7, FIX_0_785694958);
00819                     tmp3 = MULTIPLY(d7, FIX_0_275899380);
00820                 }
00821             }
00822         }
00823     } else {
00824         if (d5) {
00825             if (d3) {
00826                 if (d1) {
00827                     /* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */
00828                     z2 = d5 + d3;
00829                     z4 = d5 + d1;
00830                     z5 = MULTIPLY(d3 + z4, FIX_1_175875602);
00831 
00832                     tmp1 = MULTIPLY(d5, FIX_2_053119869);
00833                     tmp2 = MULTIPLY(d3, FIX_3_072711026);
00834                     tmp3 = MULTIPLY(d1, FIX_1_501321110);
00835                     z1 = MULTIPLY(-d1, FIX_0_899976223);
00836                     z2 = MULTIPLY(-z2, FIX_2_562915447);
00837                     z3 = MULTIPLY(-d3, FIX_1_961570560);
00838                     z4 = MULTIPLY(-z4, FIX_0_390180644);
00839 
00840                     z3 += z5;
00841                     z4 += z5;
00842 
00843                     tmp0 = z1 + z3;
00844                     tmp1 += z2 + z4;
00845                     tmp2 += z2 + z3;
00846                     tmp3 += z1 + z4;
00847                 } else {
00848                     /* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */
00849                     z2 = d5 + d3;
00850 
00851                     z5 = MULTIPLY(z2, FIX_1_175875602);
00852                     tmp1 = MULTIPLY(d5, FIX_1_662939225);
00853                     z4 = MULTIPLY(-d5, FIX_0_390180644);
00854                     z2 = MULTIPLY(-z2, FIX_1_387039845);
00855                     tmp2 = MULTIPLY(d3, FIX_1_111140466);
00856                     z3 = MULTIPLY(-d3, FIX_1_961570560);
00857 
00858                     tmp0 = z3 + z5;
00859                     tmp1 += z2;
00860                     tmp2 += z2;
00861                     tmp3 = z4 + z5;
00862                 }
00863             } else {
00864                 if (d1) {
00865                     /* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */
00866                     z4 = d5 + d1;
00867 
00868                     z5 = MULTIPLY(z4, FIX_1_175875602);
00869                     z1 = MULTIPLY(-d1, FIX_0_899976223);
00870                     tmp3 = MULTIPLY(d1, FIX_0_601344887);
00871                     tmp1 = MULTIPLY(-d5, FIX_0_509795579);
00872                     z2 = MULTIPLY(-d5, FIX_2_562915447);
00873                     z4 = MULTIPLY(z4, FIX_0_785694958);
00874 
00875                     tmp0 = z1 + z5;
00876                     tmp1 += z4;
00877                     tmp2 = z2 + z5;
00878                     tmp3 += z4;
00879                 } else {
00880                     /* d1 == 0, d3 == 0, d5 != 0, d7 == 0 */
00881                     tmp0 = MULTIPLY(d5, FIX_1_175875602);
00882                     tmp1 = MULTIPLY(d5, FIX_0_275899380);
00883                     tmp2 = MULTIPLY(-d5, FIX_1_387039845);
00884                     tmp3 = MULTIPLY(d5, FIX_0_785694958);
00885                 }
00886             }
00887         } else {
00888             if (d3) {
00889                 if (d1) {
00890                     /* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */
00891                     z5 = d1 + d3;
00892                     tmp3 = MULTIPLY(d1, FIX_0_211164243);
00893                     tmp2 = MULTIPLY(-d3, FIX_1_451774981);
00894                     z1 = MULTIPLY(d1, FIX_1_061594337);
00895                     z2 = MULTIPLY(-d3, FIX_2_172734803);
00896                     z4 = MULTIPLY(z5, FIX_0_785694958);
00897                     z5 = MULTIPLY(z5, FIX_1_175875602);
00898 
00899                     tmp0 = z1 - z4;
00900                     tmp1 = z2 + z4;
00901                     tmp2 += z5;
00902                     tmp3 += z5;
00903                 } else {
00904                     /* d1 == 0, d3 != 0, d5 == 0, d7 == 0 */
00905                     tmp0 = MULTIPLY(-d3, FIX_0_785694958);
00906                     tmp1 = MULTIPLY(-d3, FIX_1_387039845);
00907                     tmp2 = MULTIPLY(-d3, FIX_0_275899380);
00908                     tmp3 = MULTIPLY(d3, FIX_1_175875602);
00909                 }
00910             } else {
00911                 if (d1) {
00912                     /* d1 != 0, d3 == 0, d5 == 0, d7 == 0 */
00913                     tmp0 = MULTIPLY(d1, FIX_0_275899380);
00914                     tmp1 = MULTIPLY(d1, FIX_0_785694958);
00915                     tmp2 = MULTIPLY(d1, FIX_1_175875602);
00916                     tmp3 = MULTIPLY(d1, FIX_1_387039845);
00917                 } else {
00918                     /* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */
00919                     tmp0 = tmp1 = tmp2 = tmp3 = 0;
00920                 }
00921             }
00922         }
00923     }
00924 
00925     /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
00926 
00927     dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp3,
00928                                            CONST_BITS+PASS1_BITS+3);
00929     dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp10 - tmp3,
00930                                            CONST_BITS+PASS1_BITS+3);
00931     dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp11 + tmp2,
00932                                            CONST_BITS+PASS1_BITS+3);
00933     dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(tmp11 - tmp2,
00934                                            CONST_BITS+PASS1_BITS+3);
00935     dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp12 + tmp1,
00936                                            CONST_BITS+PASS1_BITS+3);
00937     dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12 - tmp1,
00938                                            CONST_BITS+PASS1_BITS+3);
00939     dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp13 + tmp0,
00940                                            CONST_BITS+PASS1_BITS+3);
00941     dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp13 - tmp0,
00942                                            CONST_BITS+PASS1_BITS+3);
00943 
00944     dataptr++;                  /* advance pointer to next column */
00945   }
00946 }
00947 
00948 #undef DCTSIZE
00949 #define DCTSIZE 4
00950 #define DCTSTRIDE 8
00951 
00952 void j_rev_dct4(DCTBLOCK data)
00953 {
00954   int32_t tmp0, tmp1, tmp2, tmp3;
00955   int32_t tmp10, tmp11, tmp12, tmp13;
00956   int32_t z1;
00957   int32_t d0, d2, d4, d6;
00958   register DCTELEM *dataptr;
00959   int rowctr;
00960 
00961   /* Pass 1: process rows. */
00962   /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
00963   /* furthermore, we scale the results by 2**PASS1_BITS. */
00964 
00965   data[0] += 4;
00966 
00967   dataptr = data;
00968 
00969   for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
00970     /* Due to quantization, we will usually find that many of the input
00971      * coefficients are zero, especially the AC terms.  We can exploit this
00972      * by short-circuiting the IDCT calculation for any row in which all
00973      * the AC terms are zero.  In that case each output is equal to the
00974      * DC coefficient (with scale factor as needed).
00975      * With typical images and quantization tables, half or more of the
00976      * row DCT calculations can be simplified this way.
00977      */
00978 
00979     register int *idataptr = (int*)dataptr;
00980 
00981     d0 = dataptr[0];
00982     d2 = dataptr[1];
00983     d4 = dataptr[2];
00984     d6 = dataptr[3];
00985 
00986     if ((d2 | d4 | d6) == 0) {
00987       /* AC terms all zero */
00988       if (d0) {
00989           /* Compute a 32 bit value to assign. */
00990           DCTELEM dcval = (DCTELEM) (d0 << PASS1_BITS);
00991           register int v = (dcval & 0xffff) | ((dcval << 16) & 0xffff0000);
00992 
00993           idataptr[0] = v;
00994           idataptr[1] = v;
00995       }
00996 
00997       dataptr += DCTSTRIDE;     /* advance pointer to next row */
00998       continue;
00999     }
01000 
01001     /* Even part: reverse the even part of the forward DCT. */
01002     /* The rotator is sqrt(2)*c(-6). */
01003     if (d6) {
01004             if (d2) {
01005                     /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
01006                     z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
01007                     tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
01008                     tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
01009 
01010                     tmp0 = (d0 + d4) << CONST_BITS;
01011                     tmp1 = (d0 - d4) << CONST_BITS;
01012 
01013                     tmp10 = tmp0 + tmp3;
01014                     tmp13 = tmp0 - tmp3;
01015                     tmp11 = tmp1 + tmp2;
01016                     tmp12 = tmp1 - tmp2;
01017             } else {
01018                     /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
01019                     tmp2 = MULTIPLY(-d6, FIX_1_306562965);
01020                     tmp3 = MULTIPLY(d6, FIX_0_541196100);
01021 
01022                     tmp0 = (d0 + d4) << CONST_BITS;
01023                     tmp1 = (d0 - d4) << CONST_BITS;
01024 
01025                     tmp10 = tmp0 + tmp3;
01026                     tmp13 = tmp0 - tmp3;
01027                     tmp11 = tmp1 + tmp2;
01028                     tmp12 = tmp1 - tmp2;
01029             }
01030     } else {
01031             if (d2) {
01032                     /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
01033                     tmp2 = MULTIPLY(d2, FIX_0_541196100);
01034                     tmp3 = MULTIPLY(d2, FIX_1_306562965);
01035 
01036                     tmp0 = (d0 + d4) << CONST_BITS;
01037                     tmp1 = (d0 - d4) << CONST_BITS;
01038 
01039                     tmp10 = tmp0 + tmp3;
01040                     tmp13 = tmp0 - tmp3;
01041                     tmp11 = tmp1 + tmp2;
01042                     tmp12 = tmp1 - tmp2;
01043             } else {
01044                     /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
01045                     tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
01046                     tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
01047             }
01048       }
01049 
01050     /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
01051 
01052     dataptr[0] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS);
01053     dataptr[1] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS);
01054     dataptr[2] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS);
01055     dataptr[3] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS);
01056 
01057     dataptr += DCTSTRIDE;       /* advance pointer to next row */
01058   }
01059 
01060   /* Pass 2: process columns. */
01061   /* Note that we must descale the results by a factor of 8 == 2**3, */
01062   /* and also undo the PASS1_BITS scaling. */
01063 
01064   dataptr = data;
01065   for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
01066     /* Columns of zeroes can be exploited in the same way as we did with rows.
01067      * However, the row calculation has created many nonzero AC terms, so the
01068      * simplification applies less often (typically 5% to 10% of the time).
01069      * On machines with very fast multiplication, it's possible that the
01070      * test takes more time than it's worth.  In that case this section
01071      * may be commented out.
01072      */
01073 
01074     d0 = dataptr[DCTSTRIDE*0];
01075     d2 = dataptr[DCTSTRIDE*1];
01076     d4 = dataptr[DCTSTRIDE*2];
01077     d6 = dataptr[DCTSTRIDE*3];
01078 
01079     /* Even part: reverse the even part of the forward DCT. */
01080     /* The rotator is sqrt(2)*c(-6). */
01081     if (d6) {
01082             if (d2) {
01083                     /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
01084                     z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
01085                     tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
01086                     tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
01087 
01088                     tmp0 = (d0 + d4) << CONST_BITS;
01089                     tmp1 = (d0 - d4) << CONST_BITS;
01090 
01091                     tmp10 = tmp0 + tmp3;
01092                     tmp13 = tmp0 - tmp3;
01093                     tmp11 = tmp1 + tmp2;
01094                     tmp12 = tmp1 - tmp2;
01095             } else {
01096                     /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
01097                     tmp2 = MULTIPLY(-d6, FIX_1_306562965);
01098                     tmp3 = MULTIPLY(d6, FIX_0_541196100);
01099 
01100                     tmp0 = (d0 + d4) << CONST_BITS;
01101                     tmp1 = (d0 - d4) << CONST_BITS;
01102 
01103                     tmp10 = tmp0 + tmp3;
01104                     tmp13 = tmp0 - tmp3;
01105                     tmp11 = tmp1 + tmp2;
01106                     tmp12 = tmp1 - tmp2;
01107             }
01108     } else {
01109             if (d2) {
01110                     /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
01111                     tmp2 = MULTIPLY(d2, FIX_0_541196100);
01112                     tmp3 = MULTIPLY(d2, FIX_1_306562965);
01113 
01114                     tmp0 = (d0 + d4) << CONST_BITS;
01115                     tmp1 = (d0 - d4) << CONST_BITS;
01116 
01117                     tmp10 = tmp0 + tmp3;
01118                     tmp13 = tmp0 - tmp3;
01119                     tmp11 = tmp1 + tmp2;
01120                     tmp12 = tmp1 - tmp2;
01121             } else {
01122                     /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
01123                     tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
01124                     tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
01125             }
01126     }
01127 
01128     /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
01129 
01130     dataptr[DCTSTRIDE*0] = tmp10 >> (CONST_BITS+PASS1_BITS+3);
01131     dataptr[DCTSTRIDE*1] = tmp11 >> (CONST_BITS+PASS1_BITS+3);
01132     dataptr[DCTSTRIDE*2] = tmp12 >> (CONST_BITS+PASS1_BITS+3);
01133     dataptr[DCTSTRIDE*3] = tmp13 >> (CONST_BITS+PASS1_BITS+3);
01134 
01135     dataptr++;                  /* advance pointer to next column */
01136   }
01137 }
01138 
01139 void j_rev_dct2(DCTBLOCK data){
01140   int d00, d01, d10, d11;
01141 
01142   data[0] += 4;
01143   d00 = data[0+0*DCTSTRIDE] + data[1+0*DCTSTRIDE];
01144   d01 = data[0+0*DCTSTRIDE] - data[1+0*DCTSTRIDE];
01145   d10 = data[0+1*DCTSTRIDE] + data[1+1*DCTSTRIDE];
01146   d11 = data[0+1*DCTSTRIDE] - data[1+1*DCTSTRIDE];
01147 
01148   data[0+0*DCTSTRIDE]= (d00 + d10)>>3;
01149   data[1+0*DCTSTRIDE]= (d01 + d11)>>3;
01150   data[0+1*DCTSTRIDE]= (d00 - d10)>>3;
01151   data[1+1*DCTSTRIDE]= (d01 - d11)>>3;
01152 }
01153 
01154 void j_rev_dct1(DCTBLOCK data){
01155   data[0] = (data[0] + 4)>>3;
01156 }
01157 
01158 #undef FIX
01159 #undef CONST_BITS

Generated on Tue Nov 4 2014 12:59:22 for ffmpeg by  doxygen 1.7.1