Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed
jidctflt.c
00001 /* 00002 * jidctflt.c 00003 * 00004 * Copyright (C) 1994-1998, Thomas G. Lane. 00005 * Modified 2010-2015 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 * cK represents cos(K*pi/16). 00068 */ 00069 00070 GLOBAL(void) 00071 jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr, 00072 JCOEFPTR coef_block, 00073 JSAMPARRAY output_buf, JDIMENSION output_col) 00074 { 00075 FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; 00076 FAST_FLOAT tmp10, tmp11, tmp12, tmp13; 00077 FAST_FLOAT z5, z10, z11, z12, z13; 00078 JCOEFPTR inptr; 00079 FLOAT_MULT_TYPE * quantptr; 00080 FAST_FLOAT * wsptr; 00081 JSAMPROW outptr; 00082 JSAMPLE *range_limit = IDCT_range_limit(cinfo); 00083 int ctr; 00084 FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */ 00085 00086 /* Pass 1: process columns from input, store into work array. */ 00087 00088 inptr = coef_block; 00089 quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table; 00090 wsptr = workspace; 00091 for (ctr = DCTSIZE; ctr > 0; ctr--) { 00092 /* Due to quantization, we will usually find that many of the input 00093 * coefficients are zero, especially the AC terms. We can exploit this 00094 * by short-circuiting the IDCT calculation for any column in which all 00095 * the AC terms are zero. In that case each output is equal to the 00096 * DC coefficient (with scale factor as needed). 00097 * With typical images and quantization tables, half or more of the 00098 * column DCT calculations can be simplified this way. 00099 */ 00100 00101 if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && 00102 inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && 00103 inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && 00104 inptr[DCTSIZE*7] == 0) { 00105 /* AC terms all zero */ 00106 FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 00107 00108 wsptr[DCTSIZE*0] = dcval; 00109 wsptr[DCTSIZE*1] = dcval; 00110 wsptr[DCTSIZE*2] = dcval; 00111 wsptr[DCTSIZE*3] = dcval; 00112 wsptr[DCTSIZE*4] = dcval; 00113 wsptr[DCTSIZE*5] = dcval; 00114 wsptr[DCTSIZE*6] = dcval; 00115 wsptr[DCTSIZE*7] = dcval; 00116 00117 inptr++; /* advance pointers to next column */ 00118 quantptr++; 00119 wsptr++; 00120 continue; 00121 } 00122 00123 /* Even part */ 00124 00125 tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 00126 tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); 00127 tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); 00128 tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); 00129 00130 tmp10 = tmp0 + tmp2; /* phase 3 */ 00131 tmp11 = tmp0 - tmp2; 00132 00133 tmp13 = tmp1 + tmp3; /* phases 5-3 */ 00134 tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */ 00135 00136 tmp0 = tmp10 + tmp13; /* phase 2 */ 00137 tmp3 = tmp10 - tmp13; 00138 tmp1 = tmp11 + tmp12; 00139 tmp2 = tmp11 - tmp12; 00140 00141 /* Odd part */ 00142 00143 tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); 00144 tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); 00145 tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); 00146 tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); 00147 00148 z13 = tmp6 + tmp5; /* phase 6 */ 00149 z10 = tmp6 - tmp5; 00150 z11 = tmp4 + tmp7; 00151 z12 = tmp4 - tmp7; 00152 00153 tmp7 = z11 + z13; /* phase 5 */ 00154 tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */ 00155 00156 z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ 00157 tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */ 00158 tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */ 00159 00160 tmp6 = tmp12 - tmp7; /* phase 2 */ 00161 tmp5 = tmp11 - tmp6; 00162 tmp4 = tmp10 - tmp5; 00163 00164 wsptr[DCTSIZE*0] = tmp0 + tmp7; 00165 wsptr[DCTSIZE*7] = tmp0 - tmp7; 00166 wsptr[DCTSIZE*1] = tmp1 + tmp6; 00167 wsptr[DCTSIZE*6] = tmp1 - tmp6; 00168 wsptr[DCTSIZE*2] = tmp2 + tmp5; 00169 wsptr[DCTSIZE*5] = tmp2 - tmp5; 00170 wsptr[DCTSIZE*3] = tmp3 + tmp4; 00171 wsptr[DCTSIZE*4] = tmp3 - tmp4; 00172 00173 inptr++; /* advance pointers to next column */ 00174 quantptr++; 00175 wsptr++; 00176 } 00177 00178 /* Pass 2: process rows from work array, store into output array. */ 00179 00180 wsptr = workspace; 00181 for (ctr = 0; ctr < DCTSIZE; ctr++) { 00182 outptr = output_buf[ctr] + output_col; 00183 /* Rows of zeroes can be exploited in the same way as we did with columns. 00184 * However, the column calculation has created many nonzero AC terms, so 00185 * the simplification applies less often (typically 5% to 10% of the time). 00186 * And testing floats for zero is relatively expensive, so we don't bother. 00187 */ 00188 00189 /* Even part */ 00190 00191 /* Prepare range-limit and float->int conversion */ 00192 z5 = wsptr[0] + (((FAST_FLOAT) RANGE_CENTER) + ((FAST_FLOAT) 0.5)); 00193 tmp10 = z5 + wsptr[4]; 00194 tmp11 = z5 - wsptr[4]; 00195 00196 tmp13 = wsptr[2] + wsptr[6]; 00197 tmp12 = (wsptr[2] - wsptr[6]) * 00198 ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */ 00199 00200 tmp0 = tmp10 + tmp13; 00201 tmp3 = tmp10 - tmp13; 00202 tmp1 = tmp11 + tmp12; 00203 tmp2 = tmp11 - tmp12; 00204 00205 /* Odd part */ 00206 00207 z13 = wsptr[5] + wsptr[3]; 00208 z10 = wsptr[5] - wsptr[3]; 00209 z11 = wsptr[1] + wsptr[7]; 00210 z12 = wsptr[1] - wsptr[7]; 00211 00212 tmp7 = z11 + z13; /* phase 5 */ 00213 tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */ 00214 00215 z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ 00216 tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */ 00217 tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */ 00218 00219 tmp6 = tmp12 - tmp7; /* phase 2 */ 00220 tmp5 = tmp11 - tmp6; 00221 tmp4 = tmp10 - tmp5; 00222 00223 /* Final output stage: float->int conversion and range-limit */ 00224 00225 outptr[0] = range_limit[(int) (tmp0 + tmp7) & RANGE_MASK]; 00226 outptr[7] = range_limit[(int) (tmp0 - tmp7) & RANGE_MASK]; 00227 outptr[1] = range_limit[(int) (tmp1 + tmp6) & RANGE_MASK]; 00228 outptr[6] = range_limit[(int) (tmp1 - tmp6) & RANGE_MASK]; 00229 outptr[2] = range_limit[(int) (tmp2 + tmp5) & RANGE_MASK]; 00230 outptr[5] = range_limit[(int) (tmp2 - tmp5) & RANGE_MASK]; 00231 outptr[3] = range_limit[(int) (tmp3 + tmp4) & RANGE_MASK]; 00232 outptr[4] = range_limit[(int) (tmp3 - tmp4) & RANGE_MASK]; 00233 00234 wsptr += DCTSIZE; /* advance pointer to next row */ 00235 } 00236 } 00237 00238 #endif /* DCT_FLOAT_SUPPORTED */
Generated on Wed Jul 13 2022 18:56:09 by
