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

libavcodec/jrevdct.c

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