1 /*
2 * jddctmgr.c
3 *
4 * Copyright (C) 1994-1996, Thomas G. Lane.
5 * This file is part of the Independent JPEG Group's software.
6 * For conditions of distribution and use, see the accompanying README file.
7 *
8 * This file contains the inverse-DCT management logic.
9 * This code selects a particular IDCT implementation to be used,
10 * and it performs related housekeeping chores. No code in this file
11 * is executed per IDCT step, only during output pass setup.
12 *
13 * Note that the IDCT routines are responsible for performing coefficient
14 * dequantization as well as the IDCT proper. This module sets up the
15 * dequantization multiplier table needed by the IDCT routine.
16 */
17
18 #define JPEG_INTERNALS
19 #include "jinclude.h"
20 #include "jpeglib.h"
21 #include "jdct.h" /* Private declarations for DCT subsystem */
22
23
24 /*
307 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
308 };
309 SHIFT_TEMPS
310
311 for (i = 0; i < DCTSIZE2; i++) {
312 ifmtbl[i] = (IFAST_MULT_TYPE)
313 DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
314 (INT32) aanscales[i]),
315 CONST_BITS-IFAST_SCALE_BITS);
316 }
317 }
318 break;
319 #endif
320 #ifdef DCT_FLOAT_SUPPORTED
321 case JDCT_FLOAT:
322 {
323 /* For float AA&N IDCT method, multipliers are equal to quantization
324 * coefficients scaled by scalefactor[row]*scalefactor[col], where
325 * scalefactor[0] = 1
326 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
327 */
328 FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
329 int row, col;
330 static const double aanscalefactor[DCTSIZE] = {
331 1.0, 1.387039845, 1.306562965, 1.175875602,
332 1.0, 0.785694958, 0.541196100, 0.275899379
333 };
334
335 i = 0;
336 for (row = 0; row < DCTSIZE; row++) {
337 for (col = 0; col < DCTSIZE; col++) {
338 fmtbl[i] = (FLOAT_MULT_TYPE)
339 ((double) qtbl->quantval[i] *
340 aanscalefactor[row] * aanscalefactor[col]);
341 i++;
342 }
343 }
344 }
345 break;
346 #endif
347 default:
348 ERREXIT(cinfo, JERR_NOT_COMPILED);
349 break;
350 }
351 }
352 }
353
354
355 /*
356 * Initialize IDCT manager.
357 */
358
359 GLOBAL(void)
360 jinit_inverse_dct (j_decompress_ptr cinfo)
361 {
362 my_idct_ptr idct;
363 int ci;
364 jpeg_component_info *compptr;
365
366 idct = (my_idct_ptr)
367 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
368 SIZEOF(my_idct_controller));
369 cinfo->idct = (struct jpeg_inverse_dct *) idct;
370 idct->pub.start_pass = start_pass;
371
372 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
373 ci++, compptr++) {
374 /* Allocate and pre-zero a multiplier table for each component */
375 compptr->dct_table =
376 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
377 SIZEOF(multiplier_table));
378 MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
379 /* Mark multiplier table not yet set up for any method */
380 idct->cur_method[ci] = -1;
381 }
382 }
|
1 /*
2 * jddctmgr.c
3 *
4 * Copyright (C) 1994-1996, Thomas G. Lane.
5 * Modified 2002-2013 by Guido Vollbeding.
6 * This file is part of the Independent JPEG Group's software.
7 * For conditions of distribution and use, see the accompanying README file.
8 *
9 * This file contains the inverse-DCT management logic.
10 * This code selects a particular IDCT implementation to be used,
11 * and it performs related housekeeping chores. No code in this file
12 * is executed per IDCT step, only during output pass setup.
13 *
14 * Note that the IDCT routines are responsible for performing coefficient
15 * dequantization as well as the IDCT proper. This module sets up the
16 * dequantization multiplier table needed by the IDCT routine.
17 */
18
19 #define JPEG_INTERNALS
20 #include "jinclude.h"
21 #include "jpeglib.h"
22 #include "jdct.h" /* Private declarations for DCT subsystem */
23
24
25 /*
308 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
309 };
310 SHIFT_TEMPS
311
312 for (i = 0; i < DCTSIZE2; i++) {
313 ifmtbl[i] = (IFAST_MULT_TYPE)
314 DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
315 (INT32) aanscales[i]),
316 CONST_BITS-IFAST_SCALE_BITS);
317 }
318 }
319 break;
320 #endif
321 #ifdef DCT_FLOAT_SUPPORTED
322 case JDCT_FLOAT:
323 {
324 /* For float AA&N IDCT method, multipliers are equal to quantization
325 * coefficients scaled by scalefactor[row]*scalefactor[col], where
326 * scalefactor[0] = 1
327 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
328 * We apply a further scale factor of 1/8.
329 */
330 FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
331 int row, col;
332 static const double aanscalefactor[DCTSIZE] = {
333 1.0, 1.387039845, 1.306562965, 1.175875602,
334 1.0, 0.785694958, 0.541196100, 0.275899379
335 };
336
337 i = 0;
338 for (row = 0; row < DCTSIZE; row++) {
339 for (col = 0; col < DCTSIZE; col++) {
340 fmtbl[i] = (FLOAT_MULT_TYPE)
341 ((double) qtbl->quantval[i] *
342 aanscalefactor[row] * aanscalefactor[col] * 0.125);
343 i++;
344 }
345 }
346 }
347 break;
348 #endif
349 default:
350 ERREXIT(cinfo, JERR_NOT_COMPILED);
351 break;
352 }
353 }
354 }
355
356
357 /*
358 * Initialize IDCT manager.
359 */
360
361 GLOBAL(void)
362 jinit_inverse_dct (j_decompress_ptr cinfo)
363 {
364 my_idct_ptr idct;
365 int ci;
366 jpeg_component_info *compptr;
367
368 idct = (my_idct_ptr)
369 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
370 SIZEOF(my_idct_controller));
371 cinfo->idct = &idct->pub;
372 idct->pub.start_pass = start_pass;
373
374 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
375 ci++, compptr++) {
376 /* Allocate and pre-zero a multiplier table for each component */
377 compptr->dct_table =
378 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
379 SIZEOF(multiplier_table));
380 MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
381 /* Mark multiplier table not yet set up for any method */
382 idct->cur_method[ci] = -1;
383 }
384 }
|