/src/libjpeg-turbo.dev/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, 2025, D. R. Commander. |
10 | | * For conditions of distribution and use, see the accompanying README.ijg |
11 | | * 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 |
16 | | * is executed per IDCT step, only during output pass setup. |
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" |
26 | | #include "jdct.h" /* Private declarations for DCT subsystem */ |
27 | | #ifdef WITH_SIMD |
28 | | #include "../simd/jsimddct.h" |
29 | | #endif |
30 | | #include "jpegapicomp.h" |
31 | | |
32 | | |
33 | | /* |
34 | | * The decompressor input side (jdinput.c) saves away the appropriate |
35 | | * quantization table for each component at the start of the first scan |
36 | | * involving that component. (This is necessary in order to correctly |
37 | | * decode files that reuse Q-table slots.) |
38 | | * When we are ready to make an output pass, the saved Q-table is converted |
39 | | * to a multiplier table that will actually be used by the IDCT routine. |
40 | | * The multiplier table contents are IDCT-method-dependent. To support |
41 | | * application changes in IDCT method between scans, we can remake the |
42 | | * multiplier tables if necessary. |
43 | | * In buffered-image mode, the first output pass may occur before any data |
44 | | * has been seen for some components, and thus before their Q-tables have |
45 | | * been saved away. To handle this case, multiplier tables are preset |
46 | | * to zeroes; the result of the IDCT will be a neutral gray level. |
47 | | */ |
48 | | |
49 | | |
50 | | /* Private subobject for this module */ |
51 | | |
52 | | typedef struct { |
53 | | struct jpeg_inverse_dct pub; /* public fields */ |
54 | | |
55 | | /* This array contains the IDCT method code that each multiplier table |
56 | | * is currently set up for, or -1 if it's not yet set up. |
57 | | * The actual multiplier tables are pointed to by dct_table in the |
58 | | * per-component comp_info structures. |
59 | | */ |
60 | | int cur_method[MAX_COMPONENTS]; |
61 | | } my_idct_controller; |
62 | | |
63 | | typedef my_idct_controller *my_idct_ptr; |
64 | | |
65 | | |
66 | | /* Allocated multiplier tables: big enough for any supported variant */ |
67 | | |
68 | | typedef union { |
69 | | ISLOW_MULT_TYPE islow_array[DCTSIZE2]; |
70 | | #ifdef DCT_IFAST_SUPPORTED |
71 | | IFAST_MULT_TYPE ifast_array[DCTSIZE2]; |
72 | | #endif |
73 | | #ifdef DCT_FLOAT_SUPPORTED |
74 | | FLOAT_MULT_TYPE float_array[DCTSIZE2]; |
75 | | #endif |
76 | | } multiplier_table; |
77 | | |
78 | | |
79 | | /* The current scaled-IDCT routines require ISLOW-style multiplier tables, |
80 | | * so be sure to compile that code if either ISLOW or SCALING is requested. |
81 | | */ |
82 | | #ifdef DCT_ISLOW_SUPPORTED |
83 | | #define PROVIDE_ISLOW_TABLES |
84 | | #else |
85 | | #ifdef IDCT_SCALING_SUPPORTED |
86 | | #define PROVIDE_ISLOW_TABLES |
87 | | #endif |
88 | | #endif |
89 | | |
90 | | |
91 | | /* |
92 | | * Prepare for an output pass. |
93 | | * Here we select the proper IDCT routine for each component and build |
94 | | * a matching multiplier table. |
95 | | */ |
96 | | |
97 | | METHODDEF(void) |
98 | | start_pass(j_decompress_ptr cinfo) |
99 | 11.3k | { |
100 | 11.3k | my_idct_ptr idct = (my_idct_ptr)cinfo->idct; |
101 | 11.3k | int ci, i; |
102 | 11.3k | jpeg_component_info *compptr; |
103 | 11.3k | int method = 0; |
104 | 11.3k | _inverse_DCT_method_ptr method_ptr = NULL; |
105 | 11.3k | JQUANT_TBL *qtbl; |
106 | | |
107 | 31.5k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
108 | 20.2k | ci++, compptr++) { |
109 | | /* Select the proper IDCT routine for this component's scaling */ |
110 | 20.2k | switch (compptr->_DCT_scaled_size) { |
111 | 0 | #ifdef IDCT_SCALING_SUPPORTED |
112 | 4.01k | case 1: |
113 | 4.01k | method_ptr = _jpeg_idct_1x1; |
114 | 4.01k | method = JDCT_ISLOW; /* jidctred uses islow-style table */ |
115 | 4.01k | break; |
116 | 850 | case 2: |
117 | | #ifdef WITH_SIMD |
118 | 491 | if (jsimd_set_idct_2x2(cinfo)) |
119 | 491 | method_ptr = jsimd_idct_2x2; |
120 | 0 | else |
121 | 0 | #endif |
122 | 359 | method_ptr = _jpeg_idct_2x2; |
123 | 850 | method = JDCT_ISLOW; /* jidctred uses islow-style table */ |
124 | 850 | break; |
125 | 0 | case 3: |
126 | 0 | method_ptr = _jpeg_idct_3x3; |
127 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
128 | 0 | break; |
129 | 4.03k | case 4: |
130 | | #ifdef WITH_SIMD |
131 | 2.40k | if (jsimd_set_idct_4x4(cinfo)) |
132 | 2.40k | method_ptr = jsimd_idct_4x4; |
133 | 0 | else |
134 | 0 | #endif |
135 | 1.62k | method_ptr = _jpeg_idct_4x4; |
136 | 4.03k | method = JDCT_ISLOW; /* jidctred uses islow-style table */ |
137 | 4.03k | break; |
138 | 0 | case 5: |
139 | 0 | method_ptr = _jpeg_idct_5x5; |
140 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
141 | 0 | break; |
142 | 0 | case 6: |
143 | 0 | method_ptr = _jpeg_idct_6x6; |
144 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
145 | 0 | break; |
146 | 0 | case 7: |
147 | 0 | method_ptr = _jpeg_idct_7x7; |
148 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
149 | 0 | break; |
150 | 0 | #endif |
151 | 11.3k | case DCTSIZE: |
152 | 11.3k | switch (cinfo->dct_method) { |
153 | 0 | #ifdef DCT_ISLOW_SUPPORTED |
154 | 6.44k | case JDCT_ISLOW: |
155 | | #ifdef WITH_SIMD |
156 | 3.86k | if (jsimd_set_idct_islow(cinfo)) |
157 | 3.86k | method_ptr = jsimd_idct_islow; |
158 | 0 | else |
159 | 0 | #endif |
160 | 2.57k | method_ptr = _jpeg_idct_islow; |
161 | 6.44k | method = JDCT_ISLOW; |
162 | 6.44k | break; |
163 | 0 | #endif |
164 | 0 | #ifdef DCT_IFAST_SUPPORTED |
165 | 4.92k | case JDCT_IFAST: |
166 | | #ifdef WITH_SIMD |
167 | 2.93k | if (jsimd_set_idct_ifast(cinfo)) |
168 | 2.93k | method_ptr = jsimd_idct_ifast; |
169 | 0 | else |
170 | 0 | #endif |
171 | 1.99k | method_ptr = _jpeg_idct_ifast; |
172 | 4.92k | method = JDCT_IFAST; |
173 | 4.92k | break; |
174 | 0 | #endif |
175 | 0 | #ifdef DCT_FLOAT_SUPPORTED |
176 | 0 | case JDCT_FLOAT: |
177 | | #ifdef WITH_SIMD |
178 | 0 | if (jsimd_set_idct_float(cinfo)) |
179 | 0 | method_ptr = jsimd_idct_float; |
180 | 0 | else |
181 | 0 | #endif |
182 | 0 | method_ptr = _jpeg_idct_float; |
183 | 0 | method = JDCT_FLOAT; |
184 | 0 | break; |
185 | 0 | #endif |
186 | 0 | default: |
187 | 0 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
188 | 0 | break; |
189 | 11.3k | } |
190 | 11.3k | break; |
191 | 11.3k | #ifdef IDCT_SCALING_SUPPORTED |
192 | 11.3k | case 9: |
193 | 0 | method_ptr = _jpeg_idct_9x9; |
194 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
195 | 0 | break; |
196 | 0 | case 10: |
197 | 0 | method_ptr = _jpeg_idct_10x10; |
198 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
199 | 0 | break; |
200 | 0 | case 11: |
201 | 0 | method_ptr = _jpeg_idct_11x11; |
202 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
203 | 0 | break; |
204 | 0 | case 12: |
205 | 0 | method_ptr = _jpeg_idct_12x12; |
206 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
207 | 0 | break; |
208 | 0 | case 13: |
209 | 0 | method_ptr = _jpeg_idct_13x13; |
210 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
211 | 0 | break; |
212 | 0 | case 14: |
213 | 0 | method_ptr = _jpeg_idct_14x14; |
214 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
215 | 0 | break; |
216 | 0 | case 15: |
217 | 0 | method_ptr = _jpeg_idct_15x15; |
218 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
219 | 0 | break; |
220 | 0 | case 16: |
221 | 0 | method_ptr = _jpeg_idct_16x16; |
222 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ |
223 | 0 | break; |
224 | 0 | #endif |
225 | 0 | default: |
226 | 0 | ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->_DCT_scaled_size); |
227 | 0 | break; |
228 | 20.2k | } |
229 | 20.2k | idct->pub._inverse_DCT[ci] = method_ptr; |
230 | | /* Create multiplier table from quant table. |
231 | | * However, we can skip this if the component is uninteresting |
232 | | * or if we already built the table. Also, if no quant table |
233 | | * has yet been saved for the component, we leave the |
234 | | * multiplier table all-zero; we'll be reading zeroes from the |
235 | | * coefficient controller's buffer anyway. |
236 | | */ |
237 | 20.2k | if (!compptr->component_needed || idct->cur_method[ci] == method) |
238 | 2.34k | continue; |
239 | 17.9k | qtbl = compptr->quant_table; |
240 | 17.9k | if (qtbl == NULL) /* happens if no data yet for component */ |
241 | 5.14k | continue; |
242 | 12.7k | idct->cur_method[ci] = method; |
243 | 12.7k | switch (method) { |
244 | 0 | #ifdef PROVIDE_ISLOW_TABLES |
245 | 9.27k | case JDCT_ISLOW: |
246 | 9.27k | { |
247 | | /* For LL&M IDCT method, multipliers are equal to raw quantization |
248 | | * coefficients, but are stored as ints to ensure access efficiency. |
249 | | */ |
250 | 9.27k | ISLOW_MULT_TYPE *ismtbl = (ISLOW_MULT_TYPE *)compptr->dct_table; |
251 | 602k | for (i = 0; i < DCTSIZE2; i++) { |
252 | 593k | ismtbl[i] = (ISLOW_MULT_TYPE)qtbl->quantval[i]; |
253 | 593k | } |
254 | 9.27k | } |
255 | 9.27k | break; |
256 | 0 | #endif |
257 | 0 | #ifdef DCT_IFAST_SUPPORTED |
258 | 3.50k | case JDCT_IFAST: |
259 | 3.50k | { |
260 | | /* For AA&N IDCT method, multipliers are equal to quantization |
261 | | * coefficients scaled by scalefactor[row]*scalefactor[col], where |
262 | | * scalefactor[0] = 1 |
263 | | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 |
264 | | * For integer operation, the multiplier table is to be scaled by |
265 | | * IFAST_SCALE_BITS. |
266 | | */ |
267 | 3.50k | IFAST_MULT_TYPE *ifmtbl = (IFAST_MULT_TYPE *)compptr->dct_table; |
268 | 3.50k | #define CONST_BITS 14 |
269 | 3.50k | static const INT16 aanscales[DCTSIZE2] = { |
270 | | /* precomputed values scaled up by 14 bits */ |
271 | 3.50k | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
272 | 3.50k | 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, |
273 | 3.50k | 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, |
274 | 3.50k | 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, |
275 | 3.50k | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
276 | 3.50k | 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, |
277 | 3.50k | 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, |
278 | 3.50k | 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 |
279 | 3.50k | }; |
280 | 3.50k | SHIFT_TEMPS |
281 | | |
282 | 227k | for (i = 0; i < DCTSIZE2; i++) { |
283 | 224k | ifmtbl[i] = (IFAST_MULT_TYPE) |
284 | 224k | DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i], |
285 | 224k | (JLONG)aanscales[i]), |
286 | 224k | CONST_BITS - IFAST_SCALE_BITS); |
287 | 224k | } |
288 | 3.50k | } |
289 | 3.50k | break; |
290 | 0 | #endif |
291 | 0 | #ifdef DCT_FLOAT_SUPPORTED |
292 | 0 | case JDCT_FLOAT: |
293 | 0 | { |
294 | | /* For float AA&N IDCT method, multipliers are equal to quantization |
295 | | * coefficients scaled by scalefactor[row]*scalefactor[col], where |
296 | | * scalefactor[0] = 1 |
297 | | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 |
298 | | */ |
299 | 0 | FLOAT_MULT_TYPE *fmtbl = (FLOAT_MULT_TYPE *)compptr->dct_table; |
300 | 0 | int row, col; |
301 | 0 | static const double aanscalefactor[DCTSIZE] = { |
302 | 0 | 1.0, 1.387039845, 1.306562965, 1.175875602, |
303 | 0 | 1.0, 0.785694958, 0.541196100, 0.275899379 |
304 | 0 | }; |
305 | |
|
306 | 0 | i = 0; |
307 | 0 | for (row = 0; row < DCTSIZE; row++) { |
308 | 0 | for (col = 0; col < DCTSIZE; col++) { |
309 | 0 | fmtbl[i] = (FLOAT_MULT_TYPE) |
310 | 0 | ((double)qtbl->quantval[i] * |
311 | 0 | aanscalefactor[row] * aanscalefactor[col]); |
312 | 0 | i++; |
313 | 0 | } |
314 | 0 | } |
315 | 0 | } |
316 | 0 | break; |
317 | 0 | #endif |
318 | 0 | default: |
319 | 0 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
320 | 0 | break; |
321 | 12.7k | } |
322 | 12.7k | } |
323 | 11.3k | } Line | Count | Source | 99 | 6.62k | { | 100 | 6.62k | my_idct_ptr idct = (my_idct_ptr)cinfo->idct; | 101 | 6.62k | int ci, i; | 102 | 6.62k | jpeg_component_info *compptr; | 103 | 6.62k | int method = 0; | 104 | 6.62k | _inverse_DCT_method_ptr method_ptr = NULL; | 105 | 6.62k | JQUANT_TBL *qtbl; | 106 | | | 107 | 18.7k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 108 | 12.0k | ci++, compptr++) { | 109 | | /* Select the proper IDCT routine for this component's scaling */ | 110 | 12.0k | switch (compptr->_DCT_scaled_size) { | 111 | 0 | #ifdef IDCT_SCALING_SUPPORTED | 112 | 2.39k | case 1: | 113 | 2.39k | method_ptr = _jpeg_idct_1x1; | 114 | 2.39k | method = JDCT_ISLOW; /* jidctred uses islow-style table */ | 115 | 2.39k | break; | 116 | 491 | case 2: | 117 | 491 | #ifdef WITH_SIMD | 118 | 491 | if (jsimd_set_idct_2x2(cinfo)) | 119 | 491 | method_ptr = jsimd_idct_2x2; | 120 | 0 | else | 121 | 0 | #endif | 122 | 0 | method_ptr = _jpeg_idct_2x2; | 123 | 491 | method = JDCT_ISLOW; /* jidctred uses islow-style table */ | 124 | 491 | break; | 125 | 0 | case 3: | 126 | 0 | method_ptr = _jpeg_idct_3x3; | 127 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 128 | 0 | break; | 129 | 2.40k | case 4: | 130 | 2.40k | #ifdef WITH_SIMD | 131 | 2.40k | if (jsimd_set_idct_4x4(cinfo)) | 132 | 2.40k | method_ptr = jsimd_idct_4x4; | 133 | 0 | else | 134 | 0 | #endif | 135 | 0 | method_ptr = _jpeg_idct_4x4; | 136 | 2.40k | method = JDCT_ISLOW; /* jidctred uses islow-style table */ | 137 | 2.40k | break; | 138 | 0 | case 5: | 139 | 0 | method_ptr = _jpeg_idct_5x5; | 140 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 141 | 0 | break; | 142 | 0 | case 6: | 143 | 0 | method_ptr = _jpeg_idct_6x6; | 144 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 145 | 0 | break; | 146 | 0 | case 7: | 147 | 0 | method_ptr = _jpeg_idct_7x7; | 148 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 149 | 0 | break; | 150 | 0 | #endif | 151 | 6.79k | case DCTSIZE: | 152 | 6.79k | switch (cinfo->dct_method) { | 153 | 0 | #ifdef DCT_ISLOW_SUPPORTED | 154 | 3.86k | case JDCT_ISLOW: | 155 | 3.86k | #ifdef WITH_SIMD | 156 | 3.86k | if (jsimd_set_idct_islow(cinfo)) | 157 | 3.86k | method_ptr = jsimd_idct_islow; | 158 | 0 | else | 159 | 0 | #endif | 160 | 0 | method_ptr = _jpeg_idct_islow; | 161 | 3.86k | method = JDCT_ISLOW; | 162 | 3.86k | break; | 163 | 0 | #endif | 164 | 0 | #ifdef DCT_IFAST_SUPPORTED | 165 | 2.93k | case JDCT_IFAST: | 166 | 2.93k | #ifdef WITH_SIMD | 167 | 2.93k | if (jsimd_set_idct_ifast(cinfo)) | 168 | 2.93k | method_ptr = jsimd_idct_ifast; | 169 | 0 | else | 170 | 0 | #endif | 171 | 0 | method_ptr = _jpeg_idct_ifast; | 172 | 2.93k | method = JDCT_IFAST; | 173 | 2.93k | break; | 174 | 0 | #endif | 175 | 0 | #ifdef DCT_FLOAT_SUPPORTED | 176 | 0 | case JDCT_FLOAT: | 177 | 0 | #ifdef WITH_SIMD | 178 | 0 | if (jsimd_set_idct_float(cinfo)) | 179 | 0 | method_ptr = jsimd_idct_float; | 180 | 0 | else | 181 | 0 | #endif | 182 | 0 | method_ptr = _jpeg_idct_float; | 183 | 0 | method = JDCT_FLOAT; | 184 | 0 | break; | 185 | 0 | #endif | 186 | 0 | default: | 187 | 0 | ERREXIT(cinfo, JERR_NOT_COMPILED); | 188 | 0 | break; | 189 | 6.79k | } | 190 | 6.79k | break; | 191 | 6.79k | #ifdef IDCT_SCALING_SUPPORTED | 192 | 6.79k | case 9: | 193 | 0 | method_ptr = _jpeg_idct_9x9; | 194 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 195 | 0 | break; | 196 | 0 | case 10: | 197 | 0 | method_ptr = _jpeg_idct_10x10; | 198 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 199 | 0 | break; | 200 | 0 | case 11: | 201 | 0 | method_ptr = _jpeg_idct_11x11; | 202 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 203 | 0 | break; | 204 | 0 | case 12: | 205 | 0 | method_ptr = _jpeg_idct_12x12; | 206 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 207 | 0 | break; | 208 | 0 | case 13: | 209 | 0 | method_ptr = _jpeg_idct_13x13; | 210 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 211 | 0 | break; | 212 | 0 | case 14: | 213 | 0 | method_ptr = _jpeg_idct_14x14; | 214 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 215 | 0 | break; | 216 | 0 | case 15: | 217 | 0 | method_ptr = _jpeg_idct_15x15; | 218 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 219 | 0 | break; | 220 | 0 | case 16: | 221 | 0 | method_ptr = _jpeg_idct_16x16; | 222 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 223 | 0 | break; | 224 | 0 | #endif | 225 | 0 | default: | 226 | 0 | ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->_DCT_scaled_size); | 227 | 0 | break; | 228 | 12.0k | } | 229 | 12.0k | idct->pub._inverse_DCT[ci] = method_ptr; | 230 | | /* Create multiplier table from quant table. | 231 | | * However, we can skip this if the component is uninteresting | 232 | | * or if we already built the table. Also, if no quant table | 233 | | * has yet been saved for the component, we leave the | 234 | | * multiplier table all-zero; we'll be reading zeroes from the | 235 | | * coefficient controller's buffer anyway. | 236 | | */ | 237 | 12.0k | if (!compptr->component_needed || idct->cur_method[ci] == method) | 238 | 1.47k | continue; | 239 | 10.6k | qtbl = compptr->quant_table; | 240 | 10.6k | if (qtbl == NULL) /* happens if no data yet for component */ | 241 | 3.52k | continue; | 242 | 7.08k | idct->cur_method[ci] = method; | 243 | 7.08k | switch (method) { | 244 | 0 | #ifdef PROVIDE_ISLOW_TABLES | 245 | 5.12k | case JDCT_ISLOW: | 246 | 5.12k | { | 247 | | /* For LL&M IDCT method, multipliers are equal to raw quantization | 248 | | * coefficients, but are stored as ints to ensure access efficiency. | 249 | | */ | 250 | 5.12k | ISLOW_MULT_TYPE *ismtbl = (ISLOW_MULT_TYPE *)compptr->dct_table; | 251 | 332k | for (i = 0; i < DCTSIZE2; i++) { | 252 | 327k | ismtbl[i] = (ISLOW_MULT_TYPE)qtbl->quantval[i]; | 253 | 327k | } | 254 | 5.12k | } | 255 | 5.12k | break; | 256 | 0 | #endif | 257 | 0 | #ifdef DCT_IFAST_SUPPORTED | 258 | 1.95k | case JDCT_IFAST: | 259 | 1.95k | { | 260 | | /* For AA&N IDCT method, multipliers are equal to quantization | 261 | | * coefficients scaled by scalefactor[row]*scalefactor[col], where | 262 | | * scalefactor[0] = 1 | 263 | | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 | 264 | | * For integer operation, the multiplier table is to be scaled by | 265 | | * IFAST_SCALE_BITS. | 266 | | */ | 267 | 1.95k | IFAST_MULT_TYPE *ifmtbl = (IFAST_MULT_TYPE *)compptr->dct_table; | 268 | 1.95k | #define CONST_BITS 14 | 269 | 1.95k | static const INT16 aanscales[DCTSIZE2] = { | 270 | | /* precomputed values scaled up by 14 bits */ | 271 | 1.95k | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | 272 | 1.95k | 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, | 273 | 1.95k | 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, | 274 | 1.95k | 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, | 275 | 1.95k | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | 276 | 1.95k | 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, | 277 | 1.95k | 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, | 278 | 1.95k | 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 | 279 | 1.95k | }; | 280 | 1.95k | SHIFT_TEMPS | 281 | | | 282 | 127k | for (i = 0; i < DCTSIZE2; i++) { | 283 | 125k | ifmtbl[i] = (IFAST_MULT_TYPE) | 284 | 125k | DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i], | 285 | 125k | (JLONG)aanscales[i]), | 286 | 125k | CONST_BITS - IFAST_SCALE_BITS); | 287 | 125k | } | 288 | 1.95k | } | 289 | 1.95k | break; | 290 | 0 | #endif | 291 | 0 | #ifdef DCT_FLOAT_SUPPORTED | 292 | 0 | case JDCT_FLOAT: | 293 | 0 | { | 294 | | /* For float AA&N IDCT method, multipliers are equal to quantization | 295 | | * coefficients scaled by scalefactor[row]*scalefactor[col], where | 296 | | * scalefactor[0] = 1 | 297 | | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 | 298 | | */ | 299 | 0 | FLOAT_MULT_TYPE *fmtbl = (FLOAT_MULT_TYPE *)compptr->dct_table; | 300 | 0 | int row, col; | 301 | 0 | static const double aanscalefactor[DCTSIZE] = { | 302 | 0 | 1.0, 1.387039845, 1.306562965, 1.175875602, | 303 | 0 | 1.0, 0.785694958, 0.541196100, 0.275899379 | 304 | 0 | }; | 305 | |
| 306 | 0 | i = 0; | 307 | 0 | for (row = 0; row < DCTSIZE; row++) { | 308 | 0 | for (col = 0; col < DCTSIZE; col++) { | 309 | 0 | fmtbl[i] = (FLOAT_MULT_TYPE) | 310 | 0 | ((double)qtbl->quantval[i] * | 311 | 0 | aanscalefactor[row] * aanscalefactor[col]); | 312 | 0 | i++; | 313 | 0 | } | 314 | 0 | } | 315 | 0 | } | 316 | 0 | break; | 317 | 0 | #endif | 318 | 0 | default: | 319 | 0 | ERREXIT(cinfo, JERR_NOT_COMPILED); | 320 | 0 | break; | 321 | 7.08k | } | 322 | 7.08k | } | 323 | 6.62k | } |
Line | Count | Source | 99 | 4.69k | { | 100 | 4.69k | my_idct_ptr idct = (my_idct_ptr)cinfo->idct; | 101 | 4.69k | int ci, i; | 102 | 4.69k | jpeg_component_info *compptr; | 103 | 4.69k | int method = 0; | 104 | 4.69k | _inverse_DCT_method_ptr method_ptr = NULL; | 105 | 4.69k | JQUANT_TBL *qtbl; | 106 | | | 107 | 12.8k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 108 | 8.17k | ci++, compptr++) { | 109 | | /* Select the proper IDCT routine for this component's scaling */ | 110 | 8.17k | switch (compptr->_DCT_scaled_size) { | 111 | 0 | #ifdef IDCT_SCALING_SUPPORTED | 112 | 1.61k | case 1: | 113 | 1.61k | method_ptr = _jpeg_idct_1x1; | 114 | 1.61k | method = JDCT_ISLOW; /* jidctred uses islow-style table */ | 115 | 1.61k | break; | 116 | 359 | case 2: | 117 | | #ifdef WITH_SIMD | 118 | | if (jsimd_set_idct_2x2(cinfo)) | 119 | | method_ptr = jsimd_idct_2x2; | 120 | | else | 121 | | #endif | 122 | 359 | method_ptr = _jpeg_idct_2x2; | 123 | 359 | method = JDCT_ISLOW; /* jidctred uses islow-style table */ | 124 | 359 | break; | 125 | 0 | case 3: | 126 | 0 | method_ptr = _jpeg_idct_3x3; | 127 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 128 | 0 | break; | 129 | 1.62k | case 4: | 130 | | #ifdef WITH_SIMD | 131 | | if (jsimd_set_idct_4x4(cinfo)) | 132 | | method_ptr = jsimd_idct_4x4; | 133 | | else | 134 | | #endif | 135 | 1.62k | method_ptr = _jpeg_idct_4x4; | 136 | 1.62k | method = JDCT_ISLOW; /* jidctred uses islow-style table */ | 137 | 1.62k | break; | 138 | 0 | case 5: | 139 | 0 | method_ptr = _jpeg_idct_5x5; | 140 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 141 | 0 | break; | 142 | 0 | case 6: | 143 | 0 | method_ptr = _jpeg_idct_6x6; | 144 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 145 | 0 | break; | 146 | 0 | case 7: | 147 | 0 | method_ptr = _jpeg_idct_7x7; | 148 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 149 | 0 | break; | 150 | 0 | #endif | 151 | 4.57k | case DCTSIZE: | 152 | 4.57k | switch (cinfo->dct_method) { | 153 | 0 | #ifdef DCT_ISLOW_SUPPORTED | 154 | 2.57k | case JDCT_ISLOW: | 155 | | #ifdef WITH_SIMD | 156 | | if (jsimd_set_idct_islow(cinfo)) | 157 | | method_ptr = jsimd_idct_islow; | 158 | | else | 159 | | #endif | 160 | 2.57k | method_ptr = _jpeg_idct_islow; | 161 | 2.57k | method = JDCT_ISLOW; | 162 | 2.57k | break; | 163 | 0 | #endif | 164 | 0 | #ifdef DCT_IFAST_SUPPORTED | 165 | 1.99k | case JDCT_IFAST: | 166 | | #ifdef WITH_SIMD | 167 | | if (jsimd_set_idct_ifast(cinfo)) | 168 | | method_ptr = jsimd_idct_ifast; | 169 | | else | 170 | | #endif | 171 | 1.99k | method_ptr = _jpeg_idct_ifast; | 172 | 1.99k | method = JDCT_IFAST; | 173 | 1.99k | break; | 174 | 0 | #endif | 175 | 0 | #ifdef DCT_FLOAT_SUPPORTED | 176 | 0 | case JDCT_FLOAT: | 177 | | #ifdef WITH_SIMD | 178 | | if (jsimd_set_idct_float(cinfo)) | 179 | | method_ptr = jsimd_idct_float; | 180 | | else | 181 | | #endif | 182 | 0 | method_ptr = _jpeg_idct_float; | 183 | 0 | method = JDCT_FLOAT; | 184 | 0 | break; | 185 | 0 | #endif | 186 | 0 | default: | 187 | 0 | ERREXIT(cinfo, JERR_NOT_COMPILED); | 188 | 0 | break; | 189 | 4.57k | } | 190 | 4.57k | break; | 191 | 4.57k | #ifdef IDCT_SCALING_SUPPORTED | 192 | 4.57k | case 9: | 193 | 0 | method_ptr = _jpeg_idct_9x9; | 194 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 195 | 0 | break; | 196 | 0 | case 10: | 197 | 0 | method_ptr = _jpeg_idct_10x10; | 198 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 199 | 0 | break; | 200 | 0 | case 11: | 201 | 0 | method_ptr = _jpeg_idct_11x11; | 202 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 203 | 0 | break; | 204 | 0 | case 12: | 205 | 0 | method_ptr = _jpeg_idct_12x12; | 206 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 207 | 0 | break; | 208 | 0 | case 13: | 209 | 0 | method_ptr = _jpeg_idct_13x13; | 210 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 211 | 0 | break; | 212 | 0 | case 14: | 213 | 0 | method_ptr = _jpeg_idct_14x14; | 214 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 215 | 0 | break; | 216 | 0 | case 15: | 217 | 0 | method_ptr = _jpeg_idct_15x15; | 218 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 219 | 0 | break; | 220 | 0 | case 16: | 221 | 0 | method_ptr = _jpeg_idct_16x16; | 222 | 0 | method = JDCT_ISLOW; /* jidctint uses islow-style table */ | 223 | 0 | break; | 224 | 0 | #endif | 225 | 0 | default: | 226 | 0 | ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->_DCT_scaled_size); | 227 | 0 | break; | 228 | 8.17k | } | 229 | 8.17k | idct->pub._inverse_DCT[ci] = method_ptr; | 230 | | /* Create multiplier table from quant table. | 231 | | * However, we can skip this if the component is uninteresting | 232 | | * or if we already built the table. Also, if no quant table | 233 | | * has yet been saved for the component, we leave the | 234 | | * multiplier table all-zero; we'll be reading zeroes from the | 235 | | * coefficient controller's buffer anyway. | 236 | | */ | 237 | 8.17k | if (!compptr->component_needed || idct->cur_method[ci] == method) | 238 | 866 | continue; | 239 | 7.31k | qtbl = compptr->quant_table; | 240 | 7.31k | if (qtbl == NULL) /* happens if no data yet for component */ | 241 | 1.61k | continue; | 242 | 5.69k | idct->cur_method[ci] = method; | 243 | 5.69k | switch (method) { | 244 | 0 | #ifdef PROVIDE_ISLOW_TABLES | 245 | 4.15k | case JDCT_ISLOW: | 246 | 4.15k | { | 247 | | /* For LL&M IDCT method, multipliers are equal to raw quantization | 248 | | * coefficients, but are stored as ints to ensure access efficiency. | 249 | | */ | 250 | 4.15k | ISLOW_MULT_TYPE *ismtbl = (ISLOW_MULT_TYPE *)compptr->dct_table; | 251 | 269k | for (i = 0; i < DCTSIZE2; i++) { | 252 | 265k | ismtbl[i] = (ISLOW_MULT_TYPE)qtbl->quantval[i]; | 253 | 265k | } | 254 | 4.15k | } | 255 | 4.15k | break; | 256 | 0 | #endif | 257 | 0 | #ifdef DCT_IFAST_SUPPORTED | 258 | 1.54k | case JDCT_IFAST: | 259 | 1.54k | { | 260 | | /* For AA&N IDCT method, multipliers are equal to quantization | 261 | | * coefficients scaled by scalefactor[row]*scalefactor[col], where | 262 | | * scalefactor[0] = 1 | 263 | | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 | 264 | | * For integer operation, the multiplier table is to be scaled by | 265 | | * IFAST_SCALE_BITS. | 266 | | */ | 267 | 1.54k | IFAST_MULT_TYPE *ifmtbl = (IFAST_MULT_TYPE *)compptr->dct_table; | 268 | 1.54k | #define CONST_BITS 14 | 269 | 1.54k | static const INT16 aanscales[DCTSIZE2] = { | 270 | | /* precomputed values scaled up by 14 bits */ | 271 | 1.54k | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | 272 | 1.54k | 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, | 273 | 1.54k | 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, | 274 | 1.54k | 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, | 275 | 1.54k | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | 276 | 1.54k | 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, | 277 | 1.54k | 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, | 278 | 1.54k | 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 | 279 | 1.54k | }; | 280 | 1.54k | SHIFT_TEMPS | 281 | | | 282 | 100k | for (i = 0; i < DCTSIZE2; i++) { | 283 | 99.1k | ifmtbl[i] = (IFAST_MULT_TYPE) | 284 | 99.1k | DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i], | 285 | 99.1k | (JLONG)aanscales[i]), | 286 | 99.1k | CONST_BITS - IFAST_SCALE_BITS); | 287 | 99.1k | } | 288 | 1.54k | } | 289 | 1.54k | break; | 290 | 0 | #endif | 291 | 0 | #ifdef DCT_FLOAT_SUPPORTED | 292 | 0 | case JDCT_FLOAT: | 293 | 0 | { | 294 | | /* For float AA&N IDCT method, multipliers are equal to quantization | 295 | | * coefficients scaled by scalefactor[row]*scalefactor[col], where | 296 | | * scalefactor[0] = 1 | 297 | | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 | 298 | | */ | 299 | 0 | FLOAT_MULT_TYPE *fmtbl = (FLOAT_MULT_TYPE *)compptr->dct_table; | 300 | 0 | int row, col; | 301 | 0 | static const double aanscalefactor[DCTSIZE] = { | 302 | 0 | 1.0, 1.387039845, 1.306562965, 1.175875602, | 303 | 0 | 1.0, 0.785694958, 0.541196100, 0.275899379 | 304 | 0 | }; | 305 | |
| 306 | 0 | i = 0; | 307 | 0 | for (row = 0; row < DCTSIZE; row++) { | 308 | 0 | for (col = 0; col < DCTSIZE; col++) { | 309 | 0 | fmtbl[i] = (FLOAT_MULT_TYPE) | 310 | 0 | ((double)qtbl->quantval[i] * | 311 | 0 | aanscalefactor[row] * aanscalefactor[col]); | 312 | 0 | i++; | 313 | 0 | } | 314 | 0 | } | 315 | 0 | } | 316 | 0 | break; | 317 | 0 | #endif | 318 | 0 | default: | 319 | 0 | ERREXIT(cinfo, JERR_NOT_COMPILED); | 320 | 0 | break; | 321 | 5.69k | } | 322 | 5.69k | } | 323 | 4.69k | } |
|
324 | | |
325 | | |
326 | | /* |
327 | | * Initialize IDCT manager. |
328 | | */ |
329 | | |
330 | | GLOBAL(void) |
331 | | _jinit_inverse_dct(j_decompress_ptr cinfo) |
332 | 15.1k | { |
333 | 15.1k | my_idct_ptr idct; |
334 | 15.1k | int ci; |
335 | 15.1k | jpeg_component_info *compptr; |
336 | | |
337 | 15.1k | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
338 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
339 | | |
340 | 15.1k | idct = (my_idct_ptr) |
341 | 15.1k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
342 | 15.1k | sizeof(my_idct_controller)); |
343 | 15.1k | cinfo->idct = (struct jpeg_inverse_dct *)idct; |
344 | 15.1k | idct->pub.start_pass = start_pass; |
345 | | |
346 | 44.2k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
347 | 29.0k | ci++, compptr++) { |
348 | | /* Allocate and pre-zero a multiplier table for each component */ |
349 | 29.0k | compptr->dct_table = |
350 | 29.0k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
351 | 29.0k | sizeof(multiplier_table)); |
352 | 29.0k | memset(compptr->dct_table, 0, sizeof(multiplier_table)); |
353 | | /* Mark multiplier table not yet set up for any method */ |
354 | 29.0k | idct->cur_method[ci] = -1; |
355 | 29.0k | } |
356 | 15.1k | } Line | Count | Source | 332 | 9.68k | { | 333 | 9.68k | my_idct_ptr idct; | 334 | 9.68k | int ci; | 335 | 9.68k | jpeg_component_info *compptr; | 336 | | | 337 | 9.68k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 338 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 339 | | | 340 | 9.68k | idct = (my_idct_ptr) | 341 | 9.68k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 342 | 9.68k | sizeof(my_idct_controller)); | 343 | 9.68k | cinfo->idct = (struct jpeg_inverse_dct *)idct; | 344 | 9.68k | idct->pub.start_pass = start_pass; | 345 | | | 346 | 29.3k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 347 | 19.6k | ci++, compptr++) { | 348 | | /* Allocate and pre-zero a multiplier table for each component */ | 349 | 19.6k | compptr->dct_table = | 350 | 19.6k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 351 | 19.6k | sizeof(multiplier_table)); | 352 | 19.6k | memset(compptr->dct_table, 0, sizeof(multiplier_table)); | 353 | | /* Mark multiplier table not yet set up for any method */ | 354 | 19.6k | idct->cur_method[ci] = -1; | 355 | 19.6k | } | 356 | 9.68k | } |
Line | Count | Source | 332 | 5.51k | { | 333 | 5.51k | my_idct_ptr idct; | 334 | 5.51k | int ci; | 335 | 5.51k | jpeg_component_info *compptr; | 336 | | | 337 | 5.51k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 338 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 339 | | | 340 | 5.51k | idct = (my_idct_ptr) | 341 | 5.51k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 342 | 5.51k | sizeof(my_idct_controller)); | 343 | 5.51k | cinfo->idct = (struct jpeg_inverse_dct *)idct; | 344 | 5.51k | idct->pub.start_pass = start_pass; | 345 | | | 346 | 14.9k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 347 | 9.45k | ci++, compptr++) { | 348 | | /* Allocate and pre-zero a multiplier table for each component */ | 349 | 9.45k | compptr->dct_table = | 350 | 9.45k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 351 | 9.45k | sizeof(multiplier_table)); | 352 | 9.45k | memset(compptr->dct_table, 0, sizeof(multiplier_table)); | 353 | | /* Mark multiplier table not yet set up for any method */ | 354 | 9.45k | idct->cur_method[ci] = -1; | 355 | 9.45k | } | 356 | 5.51k | } |
|