Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * jddctmgr.c |
| 3 | * |
DRC | a73e870 | 2012-12-31 02:52:30 +0000 | [diff] [blame] | 4 | * This file was part of the Independent JPEG Group's software: |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 5 | * Copyright (C) 1994-1996, Thomas G. Lane. |
Guido Vollbeding | f18f81b | 2010-02-28 00:00:00 +0000 | [diff] [blame] | 6 | * Modified 2002-2010 by Guido Vollbeding. |
DRC | a6ef282 | 2013-09-28 03:23:49 +0000 | [diff] [blame] | 7 | * libjpeg-turbo Modifications: |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 8 | * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
DRC | 36a6eec | 2010-10-08 08:05:44 +0000 | [diff] [blame] | 9 | * Copyright (C) 2010, D. R. Commander. |
DRC | 5ef4630 | 2014-05-18 20:04:47 +0000 | [diff] [blame] | 10 | * Copyright (C) 2013, MIPS Technologies, Inc., California |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 11 | * For conditions of distribution and use, see the accompanying README file. |
| 12 | * |
| 13 | * This file contains the inverse-DCT management logic. |
| 14 | * This code selects a particular IDCT implementation to be used, |
| 15 | * and it performs related housekeeping chores. No code in this file |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 16 | * is executed per IDCT step, only during output pass setup. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 17 | * |
| 18 | * Note that the IDCT routines are responsible for performing coefficient |
| 19 | * dequantization as well as the IDCT proper. This module sets up the |
| 20 | * dequantization multiplier table needed by the IDCT routine. |
| 21 | */ |
| 22 | |
| 23 | #define JPEG_INTERNALS |
| 24 | #include "jinclude.h" |
| 25 | #include "jpeglib.h" |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 26 | #include "jdct.h" /* Private declarations for DCT subsystem */ |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 27 | #include "jsimddct.h" |
DRC | 36a6eec | 2010-10-08 08:05:44 +0000 | [diff] [blame] | 28 | #include "jpegcomp.h" |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 29 | |
| 30 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 31 | /* |
| 32 | * The decompressor input side (jdinput.c) saves away the appropriate |
| 33 | * quantization table for each component at the start of the first scan |
| 34 | * involving that component. (This is necessary in order to correctly |
| 35 | * decode files that reuse Q-table slots.) |
| 36 | * When we are ready to make an output pass, the saved Q-table is converted |
| 37 | * to a multiplier table that will actually be used by the IDCT routine. |
| 38 | * The multiplier table contents are IDCT-method-dependent. To support |
| 39 | * application changes in IDCT method between scans, we can remake the |
| 40 | * multiplier tables if necessary. |
| 41 | * In buffered-image mode, the first output pass may occur before any data |
| 42 | * has been seen for some components, and thus before their Q-tables have |
| 43 | * been saved away. To handle this case, multiplier tables are preset |
| 44 | * to zeroes; the result of the IDCT will be a neutral gray level. |
| 45 | */ |
| 46 | |
| 47 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 48 | /* Private subobject for this module */ |
| 49 | |
| 50 | typedef struct { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 51 | struct jpeg_inverse_dct pub; /* public fields */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 52 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 53 | /* This array contains the IDCT method code that each multiplier table |
| 54 | * is currently set up for, or -1 if it's not yet set up. |
| 55 | * The actual multiplier tables are pointed to by dct_table in the |
| 56 | * per-component comp_info structures. |
| 57 | */ |
| 58 | int cur_method[MAX_COMPONENTS]; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 59 | } my_idct_controller; |
| 60 | |
| 61 | typedef my_idct_controller * my_idct_ptr; |
| 62 | |
| 63 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 64 | /* Allocated multiplier tables: big enough for any supported variant */ |
| 65 | |
| 66 | typedef union { |
| 67 | ISLOW_MULT_TYPE islow_array[DCTSIZE2]; |
| 68 | #ifdef DCT_IFAST_SUPPORTED |
| 69 | IFAST_MULT_TYPE ifast_array[DCTSIZE2]; |
| 70 | #endif |
| 71 | #ifdef DCT_FLOAT_SUPPORTED |
| 72 | FLOAT_MULT_TYPE float_array[DCTSIZE2]; |
| 73 | #endif |
| 74 | } multiplier_table; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 75 | |
| 76 | |
| 77 | /* The current scaled-IDCT routines require ISLOW-style multiplier tables, |
| 78 | * so be sure to compile that code if either ISLOW or SCALING is requested. |
| 79 | */ |
| 80 | #ifdef DCT_ISLOW_SUPPORTED |
| 81 | #define PROVIDE_ISLOW_TABLES |
| 82 | #else |
| 83 | #ifdef IDCT_SCALING_SUPPORTED |
| 84 | #define PROVIDE_ISLOW_TABLES |
| 85 | #endif |
| 86 | #endif |
| 87 | |
| 88 | |
| 89 | /* |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 90 | * Prepare for an output pass. |
| 91 | * Here we select the proper IDCT routine for each component and build |
| 92 | * a matching multiplier table. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 93 | */ |
| 94 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 95 | METHODDEF(void) |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 96 | start_pass (j_decompress_ptr cinfo) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 97 | { |
| 98 | my_idct_ptr idct = (my_idct_ptr) cinfo->idct; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 99 | int ci, i; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 100 | jpeg_component_info *compptr; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 101 | int method = 0; |
| 102 | inverse_DCT_method_ptr method_ptr = NULL; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 103 | JQUANT_TBL * qtbl; |
| 104 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 105 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 106 | ci++, compptr++) { |
| 107 | /* Select the proper IDCT routine for this component's scaling */ |
DRC | 49967cd | 2010-10-09 19:57:51 +0000 | [diff] [blame] | 108 | switch (compptr->_DCT_scaled_size) { |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 109 | #ifdef IDCT_SCALING_SUPPORTED |
| 110 | case 1: |
| 111 | method_ptr = jpeg_idct_1x1; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 112 | method = JDCT_ISLOW; /* jidctred uses islow-style table */ |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 113 | break; |
| 114 | case 2: |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 115 | if (jsimd_can_idct_2x2()) |
| 116 | method_ptr = jsimd_idct_2x2; |
| 117 | else |
| 118 | method_ptr = jpeg_idct_2x2; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 119 | method = JDCT_ISLOW; /* jidctred uses islow-style table */ |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 120 | break; |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 121 | case 3: |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 122 | method_ptr = jpeg_idct_3x3; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 123 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 124 | break; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 125 | case 4: |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 126 | if (jsimd_can_idct_4x4()) |
| 127 | method_ptr = jsimd_idct_4x4; |
| 128 | else |
| 129 | method_ptr = jpeg_idct_4x4; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 130 | method = JDCT_ISLOW; /* jidctred uses islow-style table */ |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 131 | break; |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 132 | case 5: |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 133 | method_ptr = jpeg_idct_5x5; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 134 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 135 | break; |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 136 | case 6: |
DRC | e500591 | 2013-09-27 17:51:08 +0000 | [diff] [blame] | 137 | #if defined(__mips__) |
| 138 | if (jsimd_can_idct_6x6()) |
| 139 | method_ptr = jsimd_idct_6x6; |
| 140 | else |
| 141 | #endif |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 142 | method_ptr = jpeg_idct_6x6; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 143 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 144 | break; |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 145 | case 7: |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 146 | method_ptr = jpeg_idct_7x7; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 147 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 148 | break; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 149 | #endif |
| 150 | case DCTSIZE: |
| 151 | switch (cinfo->dct_method) { |
| 152 | #ifdef DCT_ISLOW_SUPPORTED |
| 153 | case JDCT_ISLOW: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 154 | if (jsimd_can_idct_islow()) |
| 155 | method_ptr = jsimd_idct_islow; |
| 156 | else |
| 157 | method_ptr = jpeg_idct_islow; |
| 158 | method = JDCT_ISLOW; |
| 159 | break; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 160 | #endif |
| 161 | #ifdef DCT_IFAST_SUPPORTED |
| 162 | case JDCT_IFAST: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 163 | if (jsimd_can_idct_ifast()) |
| 164 | method_ptr = jsimd_idct_ifast; |
| 165 | else |
| 166 | method_ptr = jpeg_idct_ifast; |
| 167 | method = JDCT_IFAST; |
| 168 | break; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 169 | #endif |
| 170 | #ifdef DCT_FLOAT_SUPPORTED |
| 171 | case JDCT_FLOAT: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 172 | if (jsimd_can_idct_float()) |
| 173 | method_ptr = jsimd_idct_float; |
| 174 | else |
| 175 | method_ptr = jpeg_idct_float; |
| 176 | method = JDCT_FLOAT; |
| 177 | break; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 178 | #endif |
| 179 | default: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 180 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
| 181 | break; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 182 | } |
| 183 | break; |
DRC | a3deac1 | 2015-07-14 20:51:53 +0000 | [diff] [blame^] | 184 | #ifdef IDCT_SCALING_SUPPORTED |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 185 | case 9: |
| 186 | method_ptr = jpeg_idct_9x9; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 187 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 188 | break; |
| 189 | case 10: |
| 190 | method_ptr = jpeg_idct_10x10; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 191 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 192 | break; |
| 193 | case 11: |
| 194 | method_ptr = jpeg_idct_11x11; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 195 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 196 | break; |
| 197 | case 12: |
DRC | e500591 | 2013-09-27 17:51:08 +0000 | [diff] [blame] | 198 | #if defined(__mips__) |
| 199 | if (jsimd_can_idct_12x12()) |
| 200 | method_ptr = jsimd_idct_12x12; |
| 201 | else |
| 202 | #endif |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 203 | method_ptr = jpeg_idct_12x12; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 204 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 205 | break; |
| 206 | case 13: |
| 207 | method_ptr = jpeg_idct_13x13; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 208 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 209 | break; |
| 210 | case 14: |
| 211 | method_ptr = jpeg_idct_14x14; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 212 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 213 | break; |
| 214 | case 15: |
| 215 | method_ptr = jpeg_idct_15x15; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 216 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 217 | break; |
| 218 | case 16: |
| 219 | method_ptr = jpeg_idct_16x16; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 220 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
DRC | 27fb3fc | 2012-01-28 01:48:07 +0000 | [diff] [blame] | 221 | break; |
DRC | a3deac1 | 2015-07-14 20:51:53 +0000 | [diff] [blame^] | 222 | #endif |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 223 | default: |
DRC | 49967cd | 2010-10-09 19:57:51 +0000 | [diff] [blame] | 224 | ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->_DCT_scaled_size); |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 225 | break; |
| 226 | } |
| 227 | idct->pub.inverse_DCT[ci] = method_ptr; |
| 228 | /* Create multiplier table from quant table. |
| 229 | * However, we can skip this if the component is uninteresting |
| 230 | * or if we already built the table. Also, if no quant table |
| 231 | * has yet been saved for the component, we leave the |
| 232 | * multiplier table all-zero; we'll be reading zeroes from the |
| 233 | * coefficient controller's buffer anyway. |
| 234 | */ |
| 235 | if (! compptr->component_needed || idct->cur_method[ci] == method) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 236 | continue; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 237 | qtbl = compptr->quant_table; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 238 | if (qtbl == NULL) /* happens if no data yet for component */ |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 239 | continue; |
| 240 | idct->cur_method[ci] = method; |
| 241 | switch (method) { |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 242 | #ifdef PROVIDE_ISLOW_TABLES |
| 243 | case JDCT_ISLOW: |
| 244 | { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 245 | /* For LL&M IDCT method, multipliers are equal to raw quantization |
| 246 | * coefficients, but are stored as ints to ensure access efficiency. |
| 247 | */ |
| 248 | ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table; |
| 249 | for (i = 0; i < DCTSIZE2; i++) { |
| 250 | ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i]; |
| 251 | } |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 252 | } |
| 253 | break; |
| 254 | #endif |
| 255 | #ifdef DCT_IFAST_SUPPORTED |
| 256 | case JDCT_IFAST: |
| 257 | { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 258 | /* For AA&N IDCT method, multipliers are equal to quantization |
| 259 | * coefficients scaled by scalefactor[row]*scalefactor[col], where |
| 260 | * scalefactor[0] = 1 |
| 261 | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 |
| 262 | * For integer operation, the multiplier table is to be scaled by |
| 263 | * IFAST_SCALE_BITS. |
| 264 | */ |
| 265 | IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 266 | #define CONST_BITS 14 |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 267 | static const INT16 aanscales[DCTSIZE2] = { |
| 268 | /* precomputed values scaled up by 14 bits */ |
| 269 | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
| 270 | 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, |
| 271 | 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, |
| 272 | 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, |
| 273 | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
| 274 | 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, |
| 275 | 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, |
| 276 | 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 |
| 277 | }; |
| 278 | SHIFT_TEMPS |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 279 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 280 | for (i = 0; i < DCTSIZE2; i++) { |
| 281 | ifmtbl[i] = (IFAST_MULT_TYPE) |
| 282 | DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], |
| 283 | (INT32) aanscales[i]), |
| 284 | CONST_BITS-IFAST_SCALE_BITS); |
| 285 | } |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 286 | } |
| 287 | break; |
| 288 | #endif |
| 289 | #ifdef DCT_FLOAT_SUPPORTED |
| 290 | case JDCT_FLOAT: |
| 291 | { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 292 | /* For float AA&N IDCT method, multipliers are equal to quantization |
| 293 | * coefficients scaled by scalefactor[row]*scalefactor[col], where |
| 294 | * scalefactor[0] = 1 |
| 295 | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 |
| 296 | */ |
| 297 | FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table; |
| 298 | int row, col; |
| 299 | static const double aanscalefactor[DCTSIZE] = { |
| 300 | 1.0, 1.387039845, 1.306562965, 1.175875602, |
| 301 | 1.0, 0.785694958, 0.541196100, 0.275899379 |
| 302 | }; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 303 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 304 | i = 0; |
| 305 | for (row = 0; row < DCTSIZE; row++) { |
| 306 | for (col = 0; col < DCTSIZE; col++) { |
| 307 | fmtbl[i] = (FLOAT_MULT_TYPE) |
| 308 | ((double) qtbl->quantval[i] * |
| 309 | aanscalefactor[row] * aanscalefactor[col]); |
| 310 | i++; |
| 311 | } |
| 312 | } |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 313 | } |
| 314 | break; |
| 315 | #endif |
| 316 | default: |
| 317 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
| 318 | break; |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | |
| 324 | /* |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 325 | * Initialize IDCT manager. |
| 326 | */ |
| 327 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 328 | GLOBAL(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 329 | jinit_inverse_dct (j_decompress_ptr cinfo) |
| 330 | { |
| 331 | my_idct_ptr idct; |
| 332 | int ci; |
| 333 | jpeg_component_info *compptr; |
| 334 | |
| 335 | idct = (my_idct_ptr) |
| 336 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
DRC | 5de454b | 2014-05-18 19:04:03 +0000 | [diff] [blame] | 337 | sizeof(my_idct_controller)); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 338 | cinfo->idct = (struct jpeg_inverse_dct *) idct; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 339 | idct->pub.start_pass = start_pass; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 340 | |
| 341 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 342 | ci++, compptr++) { |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 343 | /* Allocate and pre-zero a multiplier table for each component */ |
| 344 | compptr->dct_table = |
| 345 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
DRC | 5de454b | 2014-05-18 19:04:03 +0000 | [diff] [blame] | 346 | sizeof(multiplier_table)); |
| 347 | MEMZERO(compptr->dct_table, sizeof(multiplier_table)); |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 348 | /* Mark multiplier table not yet set up for any method */ |
| 349 | idct->cur_method[ci] = -1; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 350 | } |
| 351 | } |