ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

jidctflt.c
Go to the documentation of this file.
00001 /*
00002  * jidctflt.c
00003  *
00004  * Copyright (C) 1994-1998, Thomas G. Lane.
00005  * Modified 2010 by Guido Vollbeding.
00006  * This file is part of the Independent JPEG Group's software.
00007  * For conditions of distribution and use, see the accompanying README file.
00008  *
00009  * This file contains a floating-point implementation of the
00010  * inverse DCT (Discrete Cosine Transform).  In the IJG code, this routine
00011  * must also perform dequantization of the input coefficients.
00012  *
00013  * This implementation should be more accurate than either of the integer
00014  * IDCT implementations.  However, it may not give the same results on all
00015  * machines because of differences in roundoff behavior.  Speed will depend
00016  * on the hardware's floating point capacity.
00017  *
00018  * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
00019  * on each row (or vice versa, but it's more convenient to emit a row at
00020  * a time).  Direct algorithms are also available, but they are much more
00021  * complex and seem not to be any faster when reduced to code.
00022  *
00023  * This implementation is based on Arai, Agui, and Nakajima's algorithm for
00024  * scaled DCT.  Their original paper (Trans. IEICE E-71(11):1095) is in
00025  * Japanese, but the algorithm is described in the Pennebaker & Mitchell
00026  * JPEG textbook (see REFERENCES section in file README).  The following code
00027  * is based directly on figure 4-8 in P&M.
00028  * While an 8-point DCT cannot be done in less than 11 multiplies, it is
00029  * possible to arrange the computation so that many of the multiplies are
00030  * simple scalings of the final outputs.  These multiplies can then be
00031  * folded into the multiplications or divisions by the JPEG quantization
00032  * table entries.  The AA&N method leaves only 5 multiplies and 29 adds
00033  * to be done in the DCT itself.
00034  * The primary disadvantage of this method is that with a fixed-point
00035  * implementation, accuracy is lost due to imprecise representation of the
00036  * scaled quantization values.  However, that problem does not arise if
00037  * we use floating point arithmetic.
00038  */
00039 
00040 #define JPEG_INTERNALS
00041 #include "jinclude.h"
00042 #include "jpeglib.h"
00043 #include "jdct.h"       /* Private declarations for DCT subsystem */
00044 
00045 #ifdef DCT_FLOAT_SUPPORTED
00046 
00047 
00048 /*
00049  * This module is specialized to the case DCTSIZE = 8.
00050  */
00051 
00052 #if DCTSIZE != 8
00053   Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
00054 #endif
00055 
00056 
00057 /* Dequantize a coefficient by multiplying it by the multiplier-table
00058  * entry; produce a float result.
00059  */
00060 
00061 #define DEQUANTIZE(coef,quantval)  (((FAST_FLOAT) (coef)) * (quantval))
00062 
00063 
00064 /*
00065  * Perform dequantization and inverse DCT on one block of coefficients.
00066  */
00067 
00068 GLOBAL(void)
00069 jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
00070          JCOEFPTR coef_block,
00071          JSAMPARRAY output_buf, JDIMENSION output_col)
00072 {
00073   FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
00074   FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
00075   FAST_FLOAT z5, z10, z11, z12, z13;
00076   JCOEFPTR inptr;
00077   FLOAT_MULT_TYPE * quantptr;
00078   FAST_FLOAT * wsptr;
00079   JSAMPROW outptr;
00080   JSAMPLE *range_limit = cinfo->sample_range_limit;
00081   int ctr;
00082   FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
00083 
00084   /* Pass 1: process columns from input, store into work array. */
00085 
00086   inptr = coef_block;
00087   quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
00088   wsptr = workspace;
00089   for (ctr = DCTSIZE; ctr > 0; ctr--) {
00090     /* Due to quantization, we will usually find that many of the input
00091      * coefficients are zero, especially the AC terms.  We can exploit this
00092      * by short-circuiting the IDCT calculation for any column in which all
00093      * the AC terms are zero.  In that case each output is equal to the
00094      * DC coefficient (with scale factor as needed).
00095      * With typical images and quantization tables, half or more of the
00096      * column DCT calculations can be simplified this way.
00097      */
00098     
00099     if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
00100     inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
00101     inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
00102     inptr[DCTSIZE*7] == 0) {
00103       /* AC terms all zero */
00104       FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
00105       
00106       wsptr[DCTSIZE*0] = dcval;
00107       wsptr[DCTSIZE*1] = dcval;
00108       wsptr[DCTSIZE*2] = dcval;
00109       wsptr[DCTSIZE*3] = dcval;
00110       wsptr[DCTSIZE*4] = dcval;
00111       wsptr[DCTSIZE*5] = dcval;
00112       wsptr[DCTSIZE*6] = dcval;
00113       wsptr[DCTSIZE*7] = dcval;
00114       
00115       inptr++;          /* advance pointers to next column */
00116       quantptr++;
00117       wsptr++;
00118       continue;
00119     }
00120     
00121     /* Even part */
00122 
00123     tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
00124     tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
00125     tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
00126     tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
00127 
00128     tmp10 = tmp0 + tmp2;    /* phase 3 */
00129     tmp11 = tmp0 - tmp2;
00130 
00131     tmp13 = tmp1 + tmp3;    /* phases 5-3 */
00132     tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
00133 
00134     tmp0 = tmp10 + tmp13;   /* phase 2 */
00135     tmp3 = tmp10 - tmp13;
00136     tmp1 = tmp11 + tmp12;
00137     tmp2 = tmp11 - tmp12;
00138     
00139     /* Odd part */
00140 
00141     tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
00142     tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
00143     tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
00144     tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
00145 
00146     z13 = tmp6 + tmp5;      /* phase 6 */
00147     z10 = tmp6 - tmp5;
00148     z11 = tmp4 + tmp7;
00149     z12 = tmp4 - tmp7;
00150 
00151     tmp7 = z11 + z13;       /* phase 5 */
00152     tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
00153 
00154     z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
00155     tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */
00156     tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */
00157 
00158     tmp6 = tmp12 - tmp7;    /* phase 2 */
00159     tmp5 = tmp11 - tmp6;
00160     tmp4 = tmp10 - tmp5;
00161 
00162     wsptr[DCTSIZE*0] = tmp0 + tmp7;
00163     wsptr[DCTSIZE*7] = tmp0 - tmp7;
00164     wsptr[DCTSIZE*1] = tmp1 + tmp6;
00165     wsptr[DCTSIZE*6] = tmp1 - tmp6;
00166     wsptr[DCTSIZE*2] = tmp2 + tmp5;
00167     wsptr[DCTSIZE*5] = tmp2 - tmp5;
00168     wsptr[DCTSIZE*3] = tmp3 + tmp4;
00169     wsptr[DCTSIZE*4] = tmp3 - tmp4;
00170 
00171     inptr++;            /* advance pointers to next column */
00172     quantptr++;
00173     wsptr++;
00174   }
00175   
00176   /* Pass 2: process rows from work array, store into output array. */
00177 
00178   wsptr = workspace;
00179   for (ctr = 0; ctr < DCTSIZE; ctr++) {
00180     outptr = output_buf[ctr] + output_col;
00181     /* Rows of zeroes can be exploited in the same way as we did with columns.
00182      * However, the column calculation has created many nonzero AC terms, so
00183      * the simplification applies less often (typically 5% to 10% of the time).
00184      * And testing floats for zero is relatively expensive, so we don't bother.
00185      */
00186     
00187     /* Even part */
00188 
00189     /* Apply signed->unsigned and prepare float->int conversion */
00190     z5 = wsptr[0] + ((FAST_FLOAT) CENTERJSAMPLE + (FAST_FLOAT) 0.5);
00191     tmp10 = z5 + wsptr[4];
00192     tmp11 = z5 - wsptr[4];
00193 
00194     tmp13 = wsptr[2] + wsptr[6];
00195     tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
00196 
00197     tmp0 = tmp10 + tmp13;
00198     tmp3 = tmp10 - tmp13;
00199     tmp1 = tmp11 + tmp12;
00200     tmp2 = tmp11 - tmp12;
00201 
00202     /* Odd part */
00203 
00204     z13 = wsptr[5] + wsptr[3];
00205     z10 = wsptr[5] - wsptr[3];
00206     z11 = wsptr[1] + wsptr[7];
00207     z12 = wsptr[1] - wsptr[7];
00208 
00209     tmp7 = z11 + z13;
00210     tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
00211 
00212     z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
00213     tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */
00214     tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */
00215 
00216     tmp6 = tmp12 - tmp7;
00217     tmp5 = tmp11 - tmp6;
00218     tmp4 = tmp10 - tmp5;
00219 
00220     /* Final output stage: float->int conversion and range-limit */
00221 
00222     outptr[0] = range_limit[((int) (tmp0 + tmp7)) & RANGE_MASK];
00223     outptr[7] = range_limit[((int) (tmp0 - tmp7)) & RANGE_MASK];
00224     outptr[1] = range_limit[((int) (tmp1 + tmp6)) & RANGE_MASK];
00225     outptr[6] = range_limit[((int) (tmp1 - tmp6)) & RANGE_MASK];
00226     outptr[2] = range_limit[((int) (tmp2 + tmp5)) & RANGE_MASK];
00227     outptr[5] = range_limit[((int) (tmp2 - tmp5)) & RANGE_MASK];
00228     outptr[3] = range_limit[((int) (tmp3 + tmp4)) & RANGE_MASK];
00229     outptr[4] = range_limit[((int) (tmp3 - tmp4)) & RANGE_MASK];
00230     
00231     wsptr += DCTSIZE;       /* advance pointer to next row */
00232   }
00233 }
00234 
00235 #endif /* DCT_FLOAT_SUPPORTED */

Generated on Sun May 27 2012 04:19:26 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.