00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #define JPEG_INTERNALS
00020 #include "jinclude.h"
00021 #include "jpeglib.h"
00022 #include "jdct.h"
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 typedef struct {
00045 struct jpeg_inverse_dct pub;
00046
00047
00048
00049
00050
00051
00052 int cur_method[MAX_COMPONENTS];
00053 } my_idct_controller;
00054
00055 typedef my_idct_controller * my_idct_ptr;
00056
00057
00058
00059
00060 typedef union {
00061 ISLOW_MULT_TYPE islow_array[DCTSIZE2];
00062 #ifdef DCT_IFAST_SUPPORTED
00063 IFAST_MULT_TYPE ifast_array[DCTSIZE2];
00064 #endif
00065 #ifdef DCT_FLOAT_SUPPORTED
00066 FLOAT_MULT_TYPE float_array[DCTSIZE2];
00067 #endif
00068 } multiplier_table;
00069
00070
00071
00072
00073
00074 #ifdef DCT_ISLOW_SUPPORTED
00075 #define PROVIDE_ISLOW_TABLES
00076 #else
00077 #ifdef IDCT_SCALING_SUPPORTED
00078 #define PROVIDE_ISLOW_TABLES
00079 #endif
00080 #endif
00081
00082
00083
00084
00085
00086
00087
00088
00089 METHODDEF(void)
00090 start_pass (j_decompress_ptr cinfo)
00091 {
00092 my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
00093 int ci, i;
00094 jpeg_component_info *compptr;
00095 int method = 0;
00096 inverse_DCT_method_ptr method_ptr = NULL;
00097 JQUANT_TBL * qtbl;
00098
00099 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00100 ci++, compptr++) {
00101
00102 switch ((compptr->DCT_h_scaled_size << 8) + compptr->DCT_v_scaled_size) {
00103 #ifdef IDCT_SCALING_SUPPORTED
00104 case ((1 << 8) + 1):
00105 method_ptr = jpeg_idct_1x1;
00106 method = JDCT_ISLOW;
00107 break;
00108 case ((2 << 8) + 2):
00109 method_ptr = jpeg_idct_2x2;
00110 method = JDCT_ISLOW;
00111 break;
00112 case ((3 << 8) + 3):
00113 method_ptr = jpeg_idct_3x3;
00114 method = JDCT_ISLOW;
00115 break;
00116 case ((4 << 8) + 4):
00117 method_ptr = jpeg_idct_4x4;
00118 method = JDCT_ISLOW;
00119 break;
00120 case ((5 << 8) + 5):
00121 method_ptr = jpeg_idct_5x5;
00122 method = JDCT_ISLOW;
00123 break;
00124 case ((6 << 8) + 6):
00125 method_ptr = jpeg_idct_6x6;
00126 method = JDCT_ISLOW;
00127 break;
00128 case ((7 << 8) + 7):
00129 method_ptr = jpeg_idct_7x7;
00130 method = JDCT_ISLOW;
00131 break;
00132 case ((9 << 8) + 9):
00133 method_ptr = jpeg_idct_9x9;
00134 method = JDCT_ISLOW;
00135 break;
00136 case ((10 << 8) + 10):
00137 method_ptr = jpeg_idct_10x10;
00138 method = JDCT_ISLOW;
00139 break;
00140 case ((11 << 8) + 11):
00141 method_ptr = jpeg_idct_11x11;
00142 method = JDCT_ISLOW;
00143 break;
00144 case ((12 << 8) + 12):
00145 method_ptr = jpeg_idct_12x12;
00146 method = JDCT_ISLOW;
00147 break;
00148 case ((13 << 8) + 13):
00149 method_ptr = jpeg_idct_13x13;
00150 method = JDCT_ISLOW;
00151 break;
00152 case ((14 << 8) + 14):
00153 method_ptr = jpeg_idct_14x14;
00154 method = JDCT_ISLOW;
00155 break;
00156 case ((15 << 8) + 15):
00157 method_ptr = jpeg_idct_15x15;
00158 method = JDCT_ISLOW;
00159 break;
00160 case ((16 << 8) + 16):
00161 method_ptr = jpeg_idct_16x16;
00162 method = JDCT_ISLOW;
00163 break;
00164 case ((16 << 8) + 8):
00165 method_ptr = jpeg_idct_16x8;
00166 method = JDCT_ISLOW;
00167 break;
00168 case ((14 << 8) + 7):
00169 method_ptr = jpeg_idct_14x7;
00170 method = JDCT_ISLOW;
00171 break;
00172 case ((12 << 8) + 6):
00173 method_ptr = jpeg_idct_12x6;
00174 method = JDCT_ISLOW;
00175 break;
00176 case ((10 << 8) + 5):
00177 method_ptr = jpeg_idct_10x5;
00178 method = JDCT_ISLOW;
00179 break;
00180 case ((8 << 8) + 4):
00181 method_ptr = jpeg_idct_8x4;
00182 method = JDCT_ISLOW;
00183 break;
00184 case ((6 << 8) + 3):
00185 method_ptr = jpeg_idct_6x3;
00186 method = JDCT_ISLOW;
00187 break;
00188 case ((4 << 8) + 2):
00189 method_ptr = jpeg_idct_4x2;
00190 method = JDCT_ISLOW;
00191 break;
00192 case ((2 << 8) + 1):
00193 method_ptr = jpeg_idct_2x1;
00194 method = JDCT_ISLOW;
00195 break;
00196 case ((8 << 8) + 16):
00197 method_ptr = jpeg_idct_8x16;
00198 method = JDCT_ISLOW;
00199 break;
00200 case ((7 << 8) + 14):
00201 method_ptr = jpeg_idct_7x14;
00202 method = JDCT_ISLOW;
00203 break;
00204 case ((6 << 8) + 12):
00205 method_ptr = jpeg_idct_6x12;
00206 method = JDCT_ISLOW;
00207 break;
00208 case ((5 << 8) + 10):
00209 method_ptr = jpeg_idct_5x10;
00210 method = JDCT_ISLOW;
00211 break;
00212 case ((4 << 8) + 8):
00213 method_ptr = jpeg_idct_4x8;
00214 method = JDCT_ISLOW;
00215 break;
00216 case ((3 << 8) + 6):
00217 method_ptr = jpeg_idct_3x6;
00218 method = JDCT_ISLOW;
00219 break;
00220 case ((2 << 8) + 4):
00221 method_ptr = jpeg_idct_2x4;
00222 method = JDCT_ISLOW;
00223 break;
00224 case ((1 << 8) + 2):
00225 method_ptr = jpeg_idct_1x2;
00226 method = JDCT_ISLOW;
00227 break;
00228 #endif
00229 case ((DCTSIZE << 8) + DCTSIZE):
00230 switch (cinfo->dct_method) {
00231 #ifdef DCT_ISLOW_SUPPORTED
00232 case JDCT_ISLOW:
00233 method_ptr = jpeg_idct_islow;
00234 method = JDCT_ISLOW;
00235 break;
00236 #endif
00237 #ifdef DCT_IFAST_SUPPORTED
00238 case JDCT_IFAST:
00239 method_ptr = jpeg_idct_ifast;
00240 method = JDCT_IFAST;
00241 break;
00242 #endif
00243 #ifdef DCT_FLOAT_SUPPORTED
00244 case JDCT_FLOAT:
00245 method_ptr = jpeg_idct_float;
00246 method = JDCT_FLOAT;
00247 break;
00248 #endif
00249 default:
00250 ERREXIT(cinfo, JERR_NOT_COMPILED);
00251 break;
00252 }
00253 break;
00254 default:
00255 ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
00256 compptr->DCT_h_scaled_size, compptr->DCT_v_scaled_size);
00257 break;
00258 }
00259 idct->pub.inverse_DCT[ci] = method_ptr;
00260
00261
00262
00263
00264
00265
00266
00267 if (! compptr->component_needed || idct->cur_method[ci] == method)
00268 continue;
00269 qtbl = compptr->quant_table;
00270 if (qtbl == NULL)
00271 continue;
00272 idct->cur_method[ci] = method;
00273 switch (method) {
00274 #ifdef PROVIDE_ISLOW_TABLES
00275 case JDCT_ISLOW:
00276 {
00277
00278
00279
00280 ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
00281 for (i = 0; i < DCTSIZE2; i++) {
00282 ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
00283 }
00284 }
00285 break;
00286 #endif
00287 #ifdef DCT_IFAST_SUPPORTED
00288 case JDCT_IFAST:
00289 {
00290
00291
00292
00293
00294
00295
00296
00297 IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
00298 #define CONST_BITS 14
00299 static const INT16 aanscales[DCTSIZE2] = {
00300
00301 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
00302 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
00303 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
00304 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
00305 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
00306 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
00307 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
00308 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
00309 };
00310 SHIFT_TEMPS
00311
00312 for (i = 0; i < DCTSIZE2; i++) {
00313 ifmtbl[i] = (IFAST_MULT_TYPE)
00314 DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
00315 (INT32) aanscales[i]),
00316 CONST_BITS-IFAST_SCALE_BITS);
00317 }
00318 }
00319 break;
00320 #endif
00321 #ifdef DCT_FLOAT_SUPPORTED
00322 case JDCT_FLOAT:
00323 {
00324
00325
00326
00327
00328
00329
00330 FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
00331 int row, col;
00332 static const double aanscalefactor[DCTSIZE] = {
00333 1.0, 1.387039845, 1.306562965, 1.175875602,
00334 1.0, 0.785694958, 0.541196100, 0.275899379
00335 };
00336
00337 i = 0;
00338 for (row = 0; row < DCTSIZE; row++) {
00339 for (col = 0; col < DCTSIZE; col++) {
00340 fmtbl[i] = (FLOAT_MULT_TYPE)
00341 ((double) qtbl->quantval[i] *
00342 aanscalefactor[row] * aanscalefactor[col] * 0.125);
00343 i++;
00344 }
00345 }
00346 }
00347 break;
00348 #endif
00349 default:
00350 ERREXIT(cinfo, JERR_NOT_COMPILED);
00351 break;
00352 }
00353 }
00354 }
00355
00356
00357
00358
00359
00360
00361 GLOBAL(void)
00362 jinit_inverse_dct (j_decompress_ptr cinfo)
00363 {
00364 my_idct_ptr idct;
00365 int ci;
00366 jpeg_component_info *compptr;
00367
00368 idct = (my_idct_ptr)
00369 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00370 SIZEOF(my_idct_controller));
00371 cinfo->idct = (struct jpeg_inverse_dct *) idct;
00372 idct->pub.start_pass = start_pass;
00373
00374 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00375 ci++, compptr++) {
00376
00377 compptr->dct_table =
00378 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00379 SIZEOF(multiplier_table));
00380 MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
00381
00382 idct->cur_method[ci] = -1;
00383 }
00384 }