00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #define JPEG_INTERNALS
00019 #include "jinclude.h"
00020 #include "jpeglib.h"
00021 #include "jdct.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 typedef struct {
00044 struct jpeg_inverse_dct pub;
00045
00046
00047
00048
00049
00050
00051 int cur_method[MAX_COMPONENTS];
00052 } my_idct_controller;
00053
00054 typedef my_idct_controller * my_idct_ptr;
00055
00056
00057
00058
00059 typedef union {
00060 ISLOW_MULT_TYPE islow_array[DCTSIZE2];
00061 #ifdef DCT_IFAST_SUPPORTED
00062 IFAST_MULT_TYPE ifast_array[DCTSIZE2];
00063 #endif
00064 #ifdef DCT_FLOAT_SUPPORTED
00065 FLOAT_MULT_TYPE float_array[DCTSIZE2];
00066 #endif
00067 } multiplier_table;
00068
00069
00070
00071
00072
00073 #ifdef DCT_ISLOW_SUPPORTED
00074 #define PROVIDE_ISLOW_TABLES
00075 #else
00076 #ifdef IDCT_SCALING_SUPPORTED
00077 #define PROVIDE_ISLOW_TABLES
00078 #endif
00079 #endif
00080
00081
00082
00083
00084
00085
00086
00087
00088 METHODDEF(void)
00089 start_pass (j_decompress_ptr cinfo)
00090 {
00091 my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
00092 int ci, i;
00093 jpeg_component_info *compptr;
00094 int method = 0;
00095 inverse_DCT_method_ptr method_ptr = NULL;
00096 JQUANT_TBL * qtbl;
00097
00098 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00099 ci++, compptr++) {
00100
00101 switch (compptr->DCT_scaled_size) {
00102 #ifdef IDCT_SCALING_SUPPORTED
00103 case 1:
00104 method_ptr = jpeg_idct_1x1;
00105 method = JDCT_ISLOW;
00106 break;
00107 case 2:
00108 method_ptr = jpeg_idct_2x2;
00109 method = JDCT_ISLOW;
00110 break;
00111 case 4:
00112 method_ptr = jpeg_idct_4x4;
00113 method = JDCT_ISLOW;
00114 break;
00115 #endif
00116 case DCTSIZE:
00117 switch (cinfo->dct_method) {
00118 #ifdef DCT_ISLOW_SUPPORTED
00119 case JDCT_ISLOW:
00120 method_ptr = jpeg_idct_islow;
00121 method = JDCT_ISLOW;
00122 break;
00123 #endif
00124 #ifdef DCT_IFAST_SUPPORTED
00125 case JDCT_IFAST:
00126 method_ptr = jpeg_idct_ifast;
00127 method = JDCT_IFAST;
00128 break;
00129 #endif
00130 #ifdef DCT_FLOAT_SUPPORTED
00131 case JDCT_FLOAT:
00132 method_ptr = jpeg_idct_float;
00133 method = JDCT_FLOAT;
00134 break;
00135 #endif
00136 default:
00137 ERREXIT(cinfo, JERR_NOT_COMPILED);
00138 break;
00139 }
00140 break;
00141 default:
00142 ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
00143 break;
00144 }
00145 idct->pub.inverse_DCT[ci] = method_ptr;
00146
00147
00148
00149
00150
00151
00152
00153 if (! compptr->component_needed || idct->cur_method[ci] == method)
00154 continue;
00155 qtbl = compptr->quant_table;
00156 if (qtbl == NULL)
00157 continue;
00158 idct->cur_method[ci] = method;
00159 switch (method) {
00160 #ifdef PROVIDE_ISLOW_TABLES
00161 case JDCT_ISLOW:
00162 {
00163
00164
00165
00166 ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
00167 for (i = 0; i < DCTSIZE2; i++) {
00168 ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
00169 }
00170 }
00171 break;
00172 #endif
00173 #ifdef DCT_IFAST_SUPPORTED
00174 case JDCT_IFAST:
00175 {
00176
00177
00178
00179
00180
00181
00182
00183 IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
00184 #define CONST_BITS 14
00185 static const INT16 aanscales[DCTSIZE2] = {
00186
00187 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
00188 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
00189 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
00190 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
00191 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
00192 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
00193 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
00194 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
00195 };
00196 SHIFT_TEMPS
00197
00198 for (i = 0; i < DCTSIZE2; i++) {
00199 ifmtbl[i] = (IFAST_MULT_TYPE)
00200 DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
00201 (INT32) aanscales[i]),
00202 CONST_BITS-IFAST_SCALE_BITS);
00203 }
00204 }
00205 break;
00206 #endif
00207 #ifdef DCT_FLOAT_SUPPORTED
00208 case JDCT_FLOAT:
00209 {
00210
00211
00212
00213
00214
00215 FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
00216 int row, col;
00217 static const double aanscalefactor[DCTSIZE] = {
00218 1.0, 1.387039845, 1.306562965, 1.175875602,
00219 1.0, 0.785694958, 0.541196100, 0.275899379
00220 };
00221
00222 i = 0;
00223 for (row = 0; row < DCTSIZE; row++) {
00224 for (col = 0; col < DCTSIZE; col++) {
00225 fmtbl[i] = (FLOAT_MULT_TYPE)
00226 ((double) qtbl->quantval[i] *
00227 aanscalefactor[row] * aanscalefactor[col]);
00228 i++;
00229 }
00230 }
00231 }
00232 break;
00233 #endif
00234 default:
00235 ERREXIT(cinfo, JERR_NOT_COMPILED);
00236 break;
00237 }
00238 }
00239 }
00240
00241
00242
00243
00244
00245
00246 GLOBAL(void)
00247 jinit_inverse_dct (j_decompress_ptr cinfo)
00248 {
00249 my_idct_ptr idct;
00250 int ci;
00251 jpeg_component_info *compptr;
00252
00253 idct = (my_idct_ptr)
00254 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00255 SIZEOF(my_idct_controller));
00256 cinfo->idct = (struct jpeg_inverse_dct *) idct;
00257 idct->pub.start_pass = start_pass;
00258
00259 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00260 ci++, compptr++) {
00261
00262 compptr->dct_table =
00263 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00264 SIZEOF(multiplier_table));
00265 MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
00266
00267 idct->cur_method[ci] = -1;
00268 }
00269 }