|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* jcdctmgr.c
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* Copyright (C) 1994-1996, Thomas G. Lane.
|
|
kusano |
7d535a |
* This file is part of the Independent JPEG Group's software.
|
|
kusano |
7d535a |
* For conditions of distribution and use, see the accompanying README file.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* This file contains the forward-DCT management logic.
|
|
kusano |
7d535a |
* This code selects a particular DCT implementation to be used,
|
|
kusano |
7d535a |
* and it performs related housekeeping chores including coefficient
|
|
kusano |
7d535a |
* quantization.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#define JPEG_INTERNALS
|
|
kusano |
7d535a |
#include "jinclude.h"
|
|
kusano |
7d535a |
#include "jpeglib.h"
|
|
kusano |
7d535a |
#include "jdct.h" /* Private declarations for DCT subsystem */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Private subobject for this module */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef struct {
|
|
kusano |
7d535a |
struct jpeg_forward_dct pub; /* public fields */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Pointer to the DCT routine actually in use */
|
|
kusano |
7d535a |
forward_DCT_method_ptr do_dct[MAX_COMPONENTS];
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* The actual post-DCT divisors --- not identical to the quant table
|
|
kusano |
7d535a |
* entries, because of scaling (especially for an unnormalized DCT).
|
|
kusano |
7d535a |
* Each table is given in normal array order.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
DCTELEM * divisors[NUM_QUANT_TBLS];
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifdef DCT_FLOAT_SUPPORTED
|
|
kusano |
7d535a |
/* Same as above for the floating-point case. */
|
|
kusano |
7d535a |
float_DCT_method_ptr do_float_dct[MAX_COMPONENTS];
|
|
kusano |
7d535a |
FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
} my_fdct_controller;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
typedef my_fdct_controller * my_fdct_ptr;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* The current scaled-DCT routines require ISLOW-style divisor tables,
|
|
kusano |
7d535a |
* so be sure to compile that code if either ISLOW or SCALING is requested.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
#ifdef DCT_ISLOW_SUPPORTED
|
|
kusano |
7d535a |
#define PROVIDE_ISLOW_TABLES
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
#ifdef DCT_SCALING_SUPPORTED
|
|
kusano |
7d535a |
#define PROVIDE_ISLOW_TABLES
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Perform forward DCT on one or more blocks of a component.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* The input samples are taken from the sample_data[] array starting at
|
|
kusano |
7d535a |
* position start_row/start_col, and moving to the right for any additional
|
|
kusano |
7d535a |
* blocks. The quantized coefficients are returned in coef_blocks[].
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
METHODDEF(void)
|
|
kusano |
7d535a |
forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
|
kusano |
7d535a |
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
|
kusano |
7d535a |
JDIMENSION start_row, JDIMENSION start_col,
|
|
kusano |
7d535a |
JDIMENSION num_blocks)
|
|
kusano |
7d535a |
/* This version is used for integer DCT implementations. */
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
/* This routine is heavily used, so it's worth coding it tightly. */
|
|
kusano |
7d535a |
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
|
|
kusano |
7d535a |
forward_DCT_method_ptr do_dct = fdct->do_dct[compptr->component_index];
|
|
kusano |
7d535a |
DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
|
|
kusano |
7d535a |
DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
|
|
kusano |
7d535a |
JDIMENSION bi;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
sample_data += start_row; /* fold in the vertical offset once */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {
|
|
kusano |
7d535a |
/* Perform the DCT */
|
|
kusano |
7d535a |
(*do_dct) (workspace, sample_data, start_col);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Quantize/descale the coefficients, and store into coef_blocks[] */
|
|
kusano |
7d535a |
{ register DCTELEM temp, qval;
|
|
kusano |
7d535a |
register int i;
|
|
kusano |
7d535a |
register JCOEFPTR output_ptr = coef_blocks[bi];
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
for (i = 0; i < DCTSIZE2; i++) {
|
|
kusano |
7d535a |
qval = divisors[i];
|
|
kusano |
7d535a |
temp = workspace[i];
|
|
kusano |
7d535a |
/* Divide the coefficient value by qval, ensuring proper rounding.
|
|
kusano |
7d535a |
* Since C does not specify the direction of rounding for negative
|
|
kusano |
7d535a |
* quotients, we have to force the dividend positive for portability.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* In most files, at least half of the output values will be zero
|
|
kusano |
7d535a |
* (at default quantization settings, more like three-quarters...)
|
|
kusano |
7d535a |
* so we should ensure that this case is fast. On many machines,
|
|
kusano |
7d535a |
* a comparison is enough cheaper than a divide to make a special test
|
|
kusano |
7d535a |
* a win. Since both inputs will be nonnegative, we need only test
|
|
kusano |
7d535a |
* for a < b to discover whether a/b is 0.
|
|
kusano |
7d535a |
* If your machine's division is fast enough, define FAST_DIVIDE.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
#ifdef FAST_DIVIDE
|
|
kusano |
7d535a |
#define DIVIDE_BY(a,b) a /= b
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
#define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
if (temp < 0) {
|
|
kusano |
7d535a |
temp = -temp;
|
|
kusano |
7d535a |
temp += qval>>1; /* for rounding */
|
|
kusano |
7d535a |
DIVIDE_BY(temp, qval);
|
|
kusano |
7d535a |
temp = -temp;
|
|
kusano |
7d535a |
} else {
|
|
kusano |
7d535a |
temp += qval>>1; /* for rounding */
|
|
kusano |
7d535a |
DIVIDE_BY(temp, qval);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
output_ptr[i] = (JCOEF) temp;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifdef DCT_FLOAT_SUPPORTED
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
METHODDEF(void)
|
|
kusano |
7d535a |
forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
|
kusano |
7d535a |
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
|
kusano |
7d535a |
JDIMENSION start_row, JDIMENSION start_col,
|
|
kusano |
7d535a |
JDIMENSION num_blocks)
|
|
kusano |
7d535a |
/* This version is used for floating-point DCT implementations. */
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
/* This routine is heavily used, so it's worth coding it tightly. */
|
|
kusano |
7d535a |
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
|
|
kusano |
7d535a |
float_DCT_method_ptr do_dct = fdct->do_float_dct[compptr->component_index];
|
|
kusano |
7d535a |
FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
|
|
kusano |
7d535a |
FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
|
|
kusano |
7d535a |
JDIMENSION bi;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
sample_data += start_row; /* fold in the vertical offset once */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {
|
|
kusano |
7d535a |
/* Perform the DCT */
|
|
kusano |
7d535a |
(*do_dct) (workspace, sample_data, start_col);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Quantize/descale the coefficients, and store into coef_blocks[] */
|
|
kusano |
7d535a |
{ register FAST_FLOAT temp;
|
|
kusano |
7d535a |
register int i;
|
|
kusano |
7d535a |
register JCOEFPTR output_ptr = coef_blocks[bi];
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
for (i = 0; i < DCTSIZE2; i++) {
|
|
kusano |
7d535a |
/* Apply the quantization and scaling factor */
|
|
kusano |
7d535a |
temp = workspace[i] * divisors[i];
|
|
kusano |
7d535a |
/* Round to nearest integer.
|
|
kusano |
7d535a |
* Since C does not specify the direction of rounding for negative
|
|
kusano |
7d535a |
* quotients, we have to force the dividend positive for portability.
|
|
kusano |
7d535a |
* The maximum coefficient size is +-16K (for 12-bit data), so this
|
|
kusano |
7d535a |
* code should work for either 16-bit or 32-bit ints.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#endif /* DCT_FLOAT_SUPPORTED */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Initialize for a processing pass.
|
|
kusano |
7d535a |
* Verify that all referenced Q-tables are present, and set up
|
|
kusano |
7d535a |
* the divisor table for each one.
|
|
kusano |
7d535a |
* In the current implementation, DCT of all components is done during
|
|
kusano |
7d535a |
* the first pass, even if only some components will be output in the
|
|
kusano |
7d535a |
* first scan. Hence all components should be examined here.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
METHODDEF(void)
|
|
kusano |
7d535a |
start_pass_fdctmgr (j_compress_ptr cinfo)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
|
|
kusano |
7d535a |
int ci, qtblno, i;
|
|
kusano |
7d535a |
jpeg_component_info *compptr;
|
|
kusano |
7d535a |
int method = 0;
|
|
kusano |
7d535a |
JQUANT_TBL * qtbl;
|
|
kusano |
7d535a |
DCTELEM * dtbl;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
|
kusano |
7d535a |
ci++, compptr++) {
|
|
kusano |
7d535a |
/* Select the proper DCT routine for this component's scaling */
|
|
kusano |
7d535a |
switch ((compptr->DCT_h_scaled_size << 8) + compptr->DCT_v_scaled_size) {
|
|
kusano |
7d535a |
#ifdef DCT_SCALING_SUPPORTED
|
|
kusano |
7d535a |
case ((1 << 8) + 1):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_1x1;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((2 << 8) + 2):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_2x2;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((3 << 8) + 3):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_3x3;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((4 << 8) + 4):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_4x4;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((5 << 8) + 5):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_5x5;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((6 << 8) + 6):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_6x6;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((7 << 8) + 7):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_7x7;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((9 << 8) + 9):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_9x9;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((10 << 8) + 10):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_10x10;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((11 << 8) + 11):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_11x11;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((12 << 8) + 12):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_12x12;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((13 << 8) + 13):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_13x13;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((14 << 8) + 14):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_14x14;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((15 << 8) + 15):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_15x15;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((16 << 8) + 16):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_16x16;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((16 << 8) + 8):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_16x8;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((14 << 8) + 7):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_14x7;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((12 << 8) + 6):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_12x6;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((10 << 8) + 5):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_10x5;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((8 << 8) + 4):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_8x4;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((6 << 8) + 3):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_6x3;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((4 << 8) + 2):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_4x2;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((2 << 8) + 1):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_2x1;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((8 << 8) + 16):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_8x16;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((7 << 8) + 14):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_7x14;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((6 << 8) + 12):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_6x12;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((5 << 8) + 10):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_5x10;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((4 << 8) + 8):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_4x8;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((3 << 8) + 6):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_3x6;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((2 << 8) + 4):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_2x4;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case ((1 << 8) + 2):
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_1x2;
|
|
kusano |
7d535a |
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
case ((DCTSIZE << 8) + DCTSIZE):
|
|
kusano |
7d535a |
switch (cinfo->dct_method) {
|
|
kusano |
7d535a |
#ifdef DCT_ISLOW_SUPPORTED
|
|
kusano |
7d535a |
case JDCT_ISLOW:
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_islow;
|
|
kusano |
7d535a |
method = JDCT_ISLOW;
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#ifdef DCT_IFAST_SUPPORTED
|
|
kusano |
7d535a |
case JDCT_IFAST:
|
|
kusano |
7d535a |
fdct->do_dct[ci] = jpeg_fdct_ifast;
|
|
kusano |
7d535a |
method = JDCT_IFAST;
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#ifdef DCT_FLOAT_SUPPORTED
|
|
kusano |
7d535a |
case JDCT_FLOAT:
|
|
kusano |
7d535a |
fdct->do_float_dct[ci] = jpeg_fdct_float;
|
|
kusano |
7d535a |
method = JDCT_FLOAT;
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
default:
|
|
kusano |
7d535a |
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
default:
|
|
kusano |
7d535a |
ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
|
|
kusano |
7d535a |
compptr->DCT_h_scaled_size, compptr->DCT_v_scaled_size);
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
qtblno = compptr->quant_tbl_no;
|
|
kusano |
7d535a |
/* Make sure specified quantization table is present */
|
|
kusano |
7d535a |
if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
|
|
kusano |
7d535a |
cinfo->quant_tbl_ptrs[qtblno] == NULL)
|
|
kusano |
7d535a |
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
|
|
kusano |
7d535a |
qtbl = cinfo->quant_tbl_ptrs[qtblno];
|
|
kusano |
7d535a |
/* Compute divisors for this quant table */
|
|
kusano |
7d535a |
/* We may do this more than once for same table, but it's not a big deal */
|
|
kusano |
7d535a |
switch (method) {
|
|
kusano |
7d535a |
#ifdef PROVIDE_ISLOW_TABLES
|
|
kusano |
7d535a |
case JDCT_ISLOW:
|
|
kusano |
7d535a |
/* For LL&M IDCT method, divisors are equal to raw quantization
|
|
kusano |
7d535a |
* coefficients multiplied by 8 (to counteract scaling).
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
if (fdct->divisors[qtblno] == NULL) {
|
|
kusano |
7d535a |
fdct->divisors[qtblno] = (DCTELEM *)
|
|
kusano |
7d535a |
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
kusano |
7d535a |
DCTSIZE2 * SIZEOF(DCTELEM));
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
dtbl = fdct->divisors[qtblno];
|
|
kusano |
7d535a |
for (i = 0; i < DCTSIZE2; i++) {
|
|
kusano |
7d535a |
dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
fdct->pub.forward_DCT[ci] = forward_DCT;
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#ifdef DCT_IFAST_SUPPORTED
|
|
kusano |
7d535a |
case JDCT_IFAST:
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
/* For AA&N IDCT method, divisors are equal to quantization
|
|
kusano |
7d535a |
* coefficients scaled by scalefactor[row]*scalefactor[col], where
|
|
kusano |
7d535a |
* scalefactor[0] = 1
|
|
kusano |
7d535a |
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
|
|
kusano |
7d535a |
* We apply a further scale factor of 8.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
#define CONST_BITS 14
|
|
kusano |
7d535a |
static const INT16 aanscales[DCTSIZE2] = {
|
|
kusano |
7d535a |
/* precomputed values scaled up by 14 bits */
|
|
kusano |
7d535a |
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
|
|
kusano |
7d535a |
22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
|
|
kusano |
7d535a |
21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
|
|
kusano |
7d535a |
19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
|
|
kusano |
7d535a |
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
|
|
kusano |
7d535a |
12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
|
|
kusano |
7d535a |
8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
|
|
kusano |
7d535a |
4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
|
|
kusano |
7d535a |
};
|
|
kusano |
7d535a |
SHIFT_TEMPS
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if (fdct->divisors[qtblno] == NULL) {
|
|
kusano |
7d535a |
fdct->divisors[qtblno] = (DCTELEM *)
|
|
kusano |
7d535a |
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
kusano |
7d535a |
DCTSIZE2 * SIZEOF(DCTELEM));
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
dtbl = fdct->divisors[qtblno];
|
|
kusano |
7d535a |
for (i = 0; i < DCTSIZE2; i++) {
|
|
kusano |
7d535a |
dtbl[i] = (DCTELEM)
|
|
kusano |
7d535a |
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
|
|
kusano |
7d535a |
(INT32) aanscales[i]),
|
|
kusano |
7d535a |
CONST_BITS-3);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
fdct->pub.forward_DCT[ci] = forward_DCT;
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#ifdef DCT_FLOAT_SUPPORTED
|
|
kusano |
7d535a |
case JDCT_FLOAT:
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
/* For float AA&N IDCT method, divisors are equal to quantization
|
|
kusano |
7d535a |
* coefficients scaled by scalefactor[row]*scalefactor[col], where
|
|
kusano |
7d535a |
* scalefactor[0] = 1
|
|
kusano |
7d535a |
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
|
|
kusano |
7d535a |
* We apply a further scale factor of 8.
|
|
kusano |
7d535a |
* What's actually stored is 1/divisor so that the inner loop can
|
|
kusano |
7d535a |
* use a multiplication rather than a division.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
FAST_FLOAT * fdtbl;
|
|
kusano |
7d535a |
int row, col;
|
|
kusano |
7d535a |
static const double aanscalefactor[DCTSIZE] = {
|
|
kusano |
7d535a |
1.0, 1.387039845, 1.306562965, 1.175875602,
|
|
kusano |
7d535a |
1.0, 0.785694958, 0.541196100, 0.275899379
|
|
kusano |
7d535a |
};
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if (fdct->float_divisors[qtblno] == NULL) {
|
|
kusano |
7d535a |
fdct->float_divisors[qtblno] = (FAST_FLOAT *)
|
|
kusano |
7d535a |
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
kusano |
7d535a |
DCTSIZE2 * SIZEOF(FAST_FLOAT));
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
fdtbl = fdct->float_divisors[qtblno];
|
|
kusano |
7d535a |
i = 0;
|
|
kusano |
7d535a |
for (row = 0; row < DCTSIZE; row++) {
|
|
kusano |
7d535a |
for (col = 0; col < DCTSIZE; col++) {
|
|
kusano |
7d535a |
fdtbl[i] = (FAST_FLOAT)
|
|
kusano |
7d535a |
(1.0 / (((double) qtbl->quantval[i] *
|
|
kusano |
7d535a |
aanscalefactor[row] * aanscalefactor[col] * 8.0)));
|
|
kusano |
7d535a |
i++;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
fdct->pub.forward_DCT[ci] = forward_DCT_float;
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
default:
|
|
kusano |
7d535a |
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Initialize FDCT manager.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
GLOBAL(void)
|
|
kusano |
7d535a |
jinit_forward_dct (j_compress_ptr cinfo)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
my_fdct_ptr fdct;
|
|
kusano |
7d535a |
int i;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
fdct = (my_fdct_ptr)
|
|
kusano |
7d535a |
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
kusano |
7d535a |
SIZEOF(my_fdct_controller));
|
|
kusano |
7d535a |
cinfo->fdct = (struct jpeg_forward_dct *) fdct;
|
|
kusano |
7d535a |
fdct->pub.start_pass = start_pass_fdctmgr;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Mark divisor tables unallocated */
|
|
kusano |
7d535a |
for (i = 0; i < NUM_QUANT_TBLS; i++) {
|
|
kusano |
7d535a |
fdct->divisors[i] = NULL;
|
|
kusano |
7d535a |
#ifdef DCT_FLOAT_SUPPORTED
|
|
kusano |
7d535a |
fdct->float_divisors[i] = NULL;
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|