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