Coverage Report

Created: 2026-02-26 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
104k
{
100
104k
  my_idct_ptr idct = (my_idct_ptr)cinfo->idct;
101
104k
  int ci, i;
102
104k
  jpeg_component_info *compptr;
103
104k
  int method = 0;
104
104k
  _inverse_DCT_method_ptr method_ptr = NULL;
105
104k
  JQUANT_TBL *qtbl;
106
107
334k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
108
230k
       ci++, compptr++) {
109
    /* Select the proper IDCT routine for this component's scaling */
110
230k
    switch (compptr->_DCT_scaled_size) {
111
0
#ifdef IDCT_SCALING_SUPPORTED
112
7.66k
    case 1:
113
7.66k
      method_ptr = _jpeg_idct_1x1;
114
7.66k
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
115
7.66k
      break;
116
5.74k
    case 2:
117
#ifdef WITH_SIMD
118
4.47k
      if (jsimd_set_idct_2x2(cinfo))
119
4.47k
        method_ptr = jsimd_idct_2x2;
120
0
      else
121
0
#endif
122
1.26k
        method_ptr = _jpeg_idct_2x2;
123
5.74k
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
124
5.74k
      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
8.87k
    case 4:
130
#ifdef WITH_SIMD
131
5.25k
      if (jsimd_set_idct_4x4(cinfo))
132
5.25k
        method_ptr = jsimd_idct_4x4;
133
0
      else
134
0
#endif
135
3.62k
        method_ptr = _jpeg_idct_4x4;
136
8.87k
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
137
8.87k
      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
4.28k
    case 6:
143
4.28k
      method_ptr = _jpeg_idct_6x6;
144
4.28k
      method = JDCT_ISLOW;      /* jidctint uses islow-style table */
145
4.28k
      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
202k
    case DCTSIZE:
152
202k
      switch (cinfo->dct_method) {
153
0
#ifdef DCT_ISLOW_SUPPORTED
154
19.2k
      case JDCT_ISLOW:
155
#ifdef WITH_SIMD
156
12.4k
        if (jsimd_set_idct_islow(cinfo))
157
12.4k
          method_ptr = jsimd_idct_islow;
158
0
        else
159
0
#endif
160
6.79k
          method_ptr = _jpeg_idct_islow;
161
19.2k
        method = JDCT_ISLOW;
162
19.2k
        break;
163
0
#endif
164
0
#ifdef DCT_IFAST_SUPPORTED
165
15.0k
      case JDCT_IFAST:
166
#ifdef WITH_SIMD
167
10.1k
        if (jsimd_set_idct_ifast(cinfo))
168
10.1k
          method_ptr = jsimd_idct_ifast;
169
0
        else
170
0
#endif
171
4.94k
          method_ptr = _jpeg_idct_ifast;
172
15.0k
        method = JDCT_IFAST;
173
15.0k
        break;
174
0
#endif
175
0
#ifdef DCT_FLOAT_SUPPORTED
176
167k
      case JDCT_FLOAT:
177
#ifdef WITH_SIMD
178
167k
        if (jsimd_set_idct_float(cinfo))
179
167k
          method_ptr = jsimd_idct_float;
180
0
        else
181
0
#endif
182
313
          method_ptr = _jpeg_idct_float;
183
167k
        method = JDCT_FLOAT;
184
167k
        break;
185
0
#endif
186
0
      default:
187
0
        ERREXIT(cinfo, JERR_NOT_COMPILED);
188
0
        break;
189
202k
      }
190
202k
      break;
191
202k
#ifdef IDCT_SCALING_SUPPORTED
192
202k
    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
1.17k
    case 12:
205
1.17k
      method_ptr = _jpeg_idct_12x12;
206
1.17k
      method = JDCT_ISLOW;      /* jidctint uses islow-style table */
207
1.17k
      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
230k
    }
229
230k
    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
230k
    if (!compptr->component_needed || idct->cur_method[ci] == method)
238
84.2k
      continue;
239
145k
    qtbl = compptr->quant_table;
240
145k
    if (qtbl == NULL)           /* happens if no data yet for component */
241
61.8k
      continue;
242
83.9k
    idct->cur_method[ci] = method;
243
83.9k
    switch (method) {
244
0
#ifdef PROVIDE_ISLOW_TABLES
245
31.3k
    case JDCT_ISLOW:
246
31.3k
      {
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
31.3k
        ISLOW_MULT_TYPE *ismtbl = (ISLOW_MULT_TYPE *)compptr->dct_table;
251
2.03M
        for (i = 0; i < DCTSIZE2; i++) {
252
2.00M
          ismtbl[i] = (ISLOW_MULT_TYPE)qtbl->quantval[i];
253
2.00M
        }
254
31.3k
      }
255
31.3k
      break;
256
0
#endif
257
0
#ifdef DCT_IFAST_SUPPORTED
258
11.3k
    case JDCT_IFAST:
259
11.3k
      {
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
11.3k
        IFAST_MULT_TYPE *ifmtbl = (IFAST_MULT_TYPE *)compptr->dct_table;
268
11.3k
#define CONST_BITS  14
269
11.3k
        static const INT16 aanscales[DCTSIZE2] = {
270
          /* precomputed values scaled up by 14 bits */
271
11.3k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
272
11.3k
          22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,
273
11.3k
          21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,
274
11.3k
          19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,
275
11.3k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
276
11.3k
          12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,
277
11.3k
           8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
278
11.3k
           4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
279
11.3k
        };
280
11.3k
        SHIFT_TEMPS
281
282
734k
        for (i = 0; i < DCTSIZE2; i++) {
283
723k
          ifmtbl[i] = (IFAST_MULT_TYPE)
284
723k
            DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
285
723k
                                  (JLONG)aanscales[i]),
286
723k
                    CONST_BITS - IFAST_SCALE_BITS);
287
723k
        }
288
11.3k
      }
289
11.3k
      break;
290
0
#endif
291
0
#ifdef DCT_FLOAT_SUPPORTED
292
41.2k
    case JDCT_FLOAT:
293
41.2k
      {
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
41.2k
        FLOAT_MULT_TYPE *fmtbl = (FLOAT_MULT_TYPE *)compptr->dct_table;
300
41.2k
        int row, col;
301
41.2k
        static const double aanscalefactor[DCTSIZE] = {
302
41.2k
          1.0, 1.387039845, 1.306562965, 1.175875602,
303
41.2k
          1.0, 0.785694958, 0.541196100, 0.275899379
304
41.2k
        };
305
306
41.2k
        i = 0;
307
371k
        for (row = 0; row < DCTSIZE; row++) {
308
2.97M
          for (col = 0; col < DCTSIZE; col++) {
309
2.64M
            fmtbl[i] = (FLOAT_MULT_TYPE)
310
2.64M
              ((double)qtbl->quantval[i] *
311
2.64M
               aanscalefactor[row] * aanscalefactor[col]);
312
2.64M
            i++;
313
2.64M
          }
314
330k
        }
315
41.2k
      }
316
41.2k
      break;
317
0
#endif
318
0
    default:
319
0
      ERREXIT(cinfo, JERR_NOT_COMPILED);
320
0
      break;
321
83.9k
    }
322
83.9k
  }
323
104k
}
jddctmgr-8.c:start_pass
Line
Count
Source
99
92.2k
{
100
92.2k
  my_idct_ptr idct = (my_idct_ptr)cinfo->idct;
101
92.2k
  int ci, i;
102
92.2k
  jpeg_component_info *compptr;
103
92.2k
  int method = 0;
104
92.2k
  _inverse_DCT_method_ptr method_ptr = NULL;
105
92.2k
  JQUANT_TBL *qtbl;
106
107
301k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
108
209k
       ci++, compptr++) {
109
    /* Select the proper IDCT routine for this component's scaling */
110
209k
    switch (compptr->_DCT_scaled_size) {
111
0
#ifdef IDCT_SCALING_SUPPORTED
112
4.23k
    case 1:
113
4.23k
      method_ptr = _jpeg_idct_1x1;
114
4.23k
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
115
4.23k
      break;
116
4.47k
    case 2:
117
4.47k
#ifdef WITH_SIMD
118
4.47k
      if (jsimd_set_idct_2x2(cinfo))
119
4.47k
        method_ptr = jsimd_idct_2x2;
120
0
      else
121
0
#endif
122
0
        method_ptr = _jpeg_idct_2x2;
123
4.47k
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
124
4.47k
      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
5.25k
    case 4:
130
5.25k
#ifdef WITH_SIMD
131
5.25k
      if (jsimd_set_idct_4x4(cinfo))
132
5.25k
        method_ptr = jsimd_idct_4x4;
133
0
      else
134
0
#endif
135
0
        method_ptr = _jpeg_idct_4x4;
136
5.25k
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
137
5.25k
      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
3.85k
    case 6:
143
3.85k
      method_ptr = _jpeg_idct_6x6;
144
3.85k
      method = JDCT_ISLOW;      /* jidctint uses islow-style table */
145
3.85k
      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
190k
    case DCTSIZE:
152
190k
      switch (cinfo->dct_method) {
153
0
#ifdef DCT_ISLOW_SUPPORTED
154
12.4k
      case JDCT_ISLOW:
155
12.4k
#ifdef WITH_SIMD
156
12.4k
        if (jsimd_set_idct_islow(cinfo))
157
12.4k
          method_ptr = jsimd_idct_islow;
158
0
        else
159
0
#endif
160
0
          method_ptr = _jpeg_idct_islow;
161
12.4k
        method = JDCT_ISLOW;
162
12.4k
        break;
163
0
#endif
164
0
#ifdef DCT_IFAST_SUPPORTED
165
10.1k
      case JDCT_IFAST:
166
10.1k
#ifdef WITH_SIMD
167
10.1k
        if (jsimd_set_idct_ifast(cinfo))
168
10.1k
          method_ptr = jsimd_idct_ifast;
169
0
        else
170
0
#endif
171
0
          method_ptr = _jpeg_idct_ifast;
172
10.1k
        method = JDCT_IFAST;
173
10.1k
        break;
174
0
#endif
175
0
#ifdef DCT_FLOAT_SUPPORTED
176
167k
      case JDCT_FLOAT:
177
167k
#ifdef WITH_SIMD
178
167k
        if (jsimd_set_idct_float(cinfo))
179
167k
          method_ptr = jsimd_idct_float;
180
0
        else
181
0
#endif
182
0
          method_ptr = _jpeg_idct_float;
183
167k
        method = JDCT_FLOAT;
184
167k
        break;
185
0
#endif
186
0
      default:
187
0
        ERREXIT(cinfo, JERR_NOT_COMPILED);
188
0
        break;
189
190k
      }
190
190k
      break;
191
190k
#ifdef IDCT_SCALING_SUPPORTED
192
190k
    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
994
    case 12:
205
994
      method_ptr = _jpeg_idct_12x12;
206
994
      method = JDCT_ISLOW;      /* jidctint uses islow-style table */
207
994
      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
209k
    }
229
209k
    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
209k
    if (!compptr->component_needed || idct->cur_method[ci] == method)
238
82.2k
      continue;
239
126k
    qtbl = compptr->quant_table;
240
126k
    if (qtbl == NULL)           /* happens if no data yet for component */
241
56.8k
      continue;
242
69.8k
    idct->cur_method[ci] = method;
243
69.8k
    switch (method) {
244
0
#ifdef PROVIDE_ISLOW_TABLES
245
21.1k
    case JDCT_ISLOW:
246
21.1k
      {
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
21.1k
        ISLOW_MULT_TYPE *ismtbl = (ISLOW_MULT_TYPE *)compptr->dct_table;
251
1.37M
        for (i = 0; i < DCTSIZE2; i++) {
252
1.35M
          ismtbl[i] = (ISLOW_MULT_TYPE)qtbl->quantval[i];
253
1.35M
        }
254
21.1k
      }
255
21.1k
      break;
256
0
#endif
257
0
#ifdef DCT_IFAST_SUPPORTED
258
7.61k
    case JDCT_IFAST:
259
7.61k
      {
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
7.61k
        IFAST_MULT_TYPE *ifmtbl = (IFAST_MULT_TYPE *)compptr->dct_table;
268
7.61k
#define CONST_BITS  14
269
7.61k
        static const INT16 aanscales[DCTSIZE2] = {
270
          /* precomputed values scaled up by 14 bits */
271
7.61k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
272
7.61k
          22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,
273
7.61k
          21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,
274
7.61k
          19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,
275
7.61k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
276
7.61k
          12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,
277
7.61k
           8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
278
7.61k
           4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
279
7.61k
        };
280
7.61k
        SHIFT_TEMPS
281
282
495k
        for (i = 0; i < DCTSIZE2; i++) {
283
487k
          ifmtbl[i] = (IFAST_MULT_TYPE)
284
487k
            DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
285
487k
                                  (JLONG)aanscales[i]),
286
487k
                    CONST_BITS - IFAST_SCALE_BITS);
287
487k
        }
288
7.61k
      }
289
7.61k
      break;
290
0
#endif
291
0
#ifdef DCT_FLOAT_SUPPORTED
292
41.0k
    case JDCT_FLOAT:
293
41.0k
      {
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
41.0k
        FLOAT_MULT_TYPE *fmtbl = (FLOAT_MULT_TYPE *)compptr->dct_table;
300
41.0k
        int row, col;
301
41.0k
        static const double aanscalefactor[DCTSIZE] = {
302
41.0k
          1.0, 1.387039845, 1.306562965, 1.175875602,
303
41.0k
          1.0, 0.785694958, 0.541196100, 0.275899379
304
41.0k
        };
305
306
41.0k
        i = 0;
307
369k
        for (row = 0; row < DCTSIZE; row++) {
308
2.95M
          for (col = 0; col < DCTSIZE; col++) {
309
2.62M
            fmtbl[i] = (FLOAT_MULT_TYPE)
310
2.62M
              ((double)qtbl->quantval[i] *
311
2.62M
               aanscalefactor[row] * aanscalefactor[col]);
312
2.62M
            i++;
313
2.62M
          }
314
328k
        }
315
41.0k
      }
316
41.0k
      break;
317
0
#endif
318
0
    default:
319
0
      ERREXIT(cinfo, JERR_NOT_COMPILED);
320
0
      break;
321
69.8k
    }
322
69.8k
  }
323
92.2k
}
jddctmgr-12.c:start_pass
Line
Count
Source
99
11.8k
{
100
11.8k
  my_idct_ptr idct = (my_idct_ptr)cinfo->idct;
101
11.8k
  int ci, i;
102
11.8k
  jpeg_component_info *compptr;
103
11.8k
  int method = 0;
104
11.8k
  _inverse_DCT_method_ptr method_ptr = NULL;
105
11.8k
  JQUANT_TBL *qtbl;
106
107
32.8k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
108
20.9k
       ci++, compptr++) {
109
    /* Select the proper IDCT routine for this component's scaling */
110
20.9k
    switch (compptr->_DCT_scaled_size) {
111
0
#ifdef IDCT_SCALING_SUPPORTED
112
3.42k
    case 1:
113
3.42k
      method_ptr = _jpeg_idct_1x1;
114
3.42k
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
115
3.42k
      break;
116
1.26k
    case 2:
117
#ifdef WITH_SIMD
118
      if (jsimd_set_idct_2x2(cinfo))
119
        method_ptr = jsimd_idct_2x2;
120
      else
121
#endif
122
1.26k
        method_ptr = _jpeg_idct_2x2;
123
1.26k
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
124
1.26k
      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
3.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
3.62k
        method_ptr = _jpeg_idct_4x4;
136
3.62k
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
137
3.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
436
    case 6:
143
436
      method_ptr = _jpeg_idct_6x6;
144
436
      method = JDCT_ISLOW;      /* jidctint uses islow-style table */
145
436
      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
12.0k
    case DCTSIZE:
152
12.0k
      switch (cinfo->dct_method) {
153
0
#ifdef DCT_ISLOW_SUPPORTED
154
6.79k
      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
6.79k
          method_ptr = _jpeg_idct_islow;
161
6.79k
        method = JDCT_ISLOW;
162
6.79k
        break;
163
0
#endif
164
0
#ifdef DCT_IFAST_SUPPORTED
165
4.94k
      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
4.94k
          method_ptr = _jpeg_idct_ifast;
172
4.94k
        method = JDCT_IFAST;
173
4.94k
        break;
174
0
#endif
175
0
#ifdef DCT_FLOAT_SUPPORTED
176
313
      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
313
          method_ptr = _jpeg_idct_float;
183
313
        method = JDCT_FLOAT;
184
313
        break;
185
0
#endif
186
0
      default:
187
0
        ERREXIT(cinfo, JERR_NOT_COMPILED);
188
0
        break;
189
12.0k
      }
190
12.0k
      break;
191
12.0k
#ifdef IDCT_SCALING_SUPPORTED
192
12.0k
    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
178
    case 12:
205
178
      method_ptr = _jpeg_idct_12x12;
206
178
      method = JDCT_ISLOW;      /* jidctint uses islow-style table */
207
178
      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.9k
    }
229
20.9k
    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.9k
    if (!compptr->component_needed || idct->cur_method[ci] == method)
238
1.94k
      continue;
239
19.0k
    qtbl = compptr->quant_table;
240
19.0k
    if (qtbl == NULL)           /* happens if no data yet for component */
241
4.96k
      continue;
242
14.0k
    idct->cur_method[ci] = method;
243
14.0k
    switch (method) {
244
0
#ifdef PROVIDE_ISLOW_TABLES
245
10.1k
    case JDCT_ISLOW:
246
10.1k
      {
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
10.1k
        ISLOW_MULT_TYPE *ismtbl = (ISLOW_MULT_TYPE *)compptr->dct_table;
251
662k
        for (i = 0; i < DCTSIZE2; i++) {
252
652k
          ismtbl[i] = (ISLOW_MULT_TYPE)qtbl->quantval[i];
253
652k
        }
254
10.1k
      }
255
10.1k
      break;
256
0
#endif
257
0
#ifdef DCT_IFAST_SUPPORTED
258
3.68k
    case JDCT_IFAST:
259
3.68k
      {
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.68k
        IFAST_MULT_TYPE *ifmtbl = (IFAST_MULT_TYPE *)compptr->dct_table;
268
3.68k
#define CONST_BITS  14
269
3.68k
        static const INT16 aanscales[DCTSIZE2] = {
270
          /* precomputed values scaled up by 14 bits */
271
3.68k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
272
3.68k
          22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,
273
3.68k
          21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,
274
3.68k
          19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,
275
3.68k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
276
3.68k
          12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,
277
3.68k
           8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
278
3.68k
           4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
279
3.68k
        };
280
3.68k
        SHIFT_TEMPS
281
282
239k
        for (i = 0; i < DCTSIZE2; i++) {
283
235k
          ifmtbl[i] = (IFAST_MULT_TYPE)
284
235k
            DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
285
235k
                                  (JLONG)aanscales[i]),
286
235k
                    CONST_BITS - IFAST_SCALE_BITS);
287
235k
        }
288
3.68k
      }
289
3.68k
      break;
290
0
#endif
291
0
#ifdef DCT_FLOAT_SUPPORTED
292
196
    case JDCT_FLOAT:
293
196
      {
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
196
        FLOAT_MULT_TYPE *fmtbl = (FLOAT_MULT_TYPE *)compptr->dct_table;
300
196
        int row, col;
301
196
        static const double aanscalefactor[DCTSIZE] = {
302
196
          1.0, 1.387039845, 1.306562965, 1.175875602,
303
196
          1.0, 0.785694958, 0.541196100, 0.275899379
304
196
        };
305
306
196
        i = 0;
307
1.76k
        for (row = 0; row < DCTSIZE; row++) {
308
14.1k
          for (col = 0; col < DCTSIZE; col++) {
309
12.5k
            fmtbl[i] = (FLOAT_MULT_TYPE)
310
12.5k
              ((double)qtbl->quantval[i] *
311
12.5k
               aanscalefactor[row] * aanscalefactor[col]);
312
12.5k
            i++;
313
12.5k
          }
314
1.56k
        }
315
196
      }
316
196
      break;
317
0
#endif
318
0
    default:
319
0
      ERREXIT(cinfo, JERR_NOT_COMPILED);
320
0
      break;
321
14.0k
    }
322
14.0k
  }
323
11.8k
}
324
325
326
/*
327
 * Initialize IDCT manager.
328
 */
329
330
GLOBAL(void)
331
_jinit_inverse_dct(j_decompress_ptr cinfo)
332
109k
{
333
109k
  my_idct_ptr idct;
334
109k
  int ci;
335
109k
  jpeg_component_info *compptr;
336
337
109k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
338
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
339
340
109k
  idct = (my_idct_ptr)
341
109k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
342
109k
                                sizeof(my_idct_controller));
343
109k
  cinfo->idct = (struct jpeg_inverse_dct *)idct;
344
109k
  idct->pub.start_pass = start_pass;
345
346
320k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
347
211k
       ci++, compptr++) {
348
    /* Allocate and pre-zero a multiplier table for each component */
349
211k
    compptr->dct_table =
350
211k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
351
211k
                                  sizeof(multiplier_table));
352
211k
    memset(compptr->dct_table, 0, sizeof(multiplier_table));
353
    /* Mark multiplier table not yet set up for any method */
354
211k
    idct->cur_method[ci] = -1;
355
211k
  }
356
109k
}
jinit_inverse_dct
Line
Count
Source
332
87.8k
{
333
87.8k
  my_idct_ptr idct;
334
87.8k
  int ci;
335
87.8k
  jpeg_component_info *compptr;
336
337
87.8k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
338
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
339
340
87.8k
  idct = (my_idct_ptr)
341
87.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
342
87.8k
                                sizeof(my_idct_controller));
343
87.8k
  cinfo->idct = (struct jpeg_inverse_dct *)idct;
344
87.8k
  idct->pub.start_pass = start_pass;
345
346
261k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
347
173k
       ci++, compptr++) {
348
    /* Allocate and pre-zero a multiplier table for each component */
349
173k
    compptr->dct_table =
350
173k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
351
173k
                                  sizeof(multiplier_table));
352
173k
    memset(compptr->dct_table, 0, sizeof(multiplier_table));
353
    /* Mark multiplier table not yet set up for any method */
354
173k
    idct->cur_method[ci] = -1;
355
173k
  }
356
87.8k
}
j12init_inverse_dct
Line
Count
Source
332
21.2k
{
333
21.2k
  my_idct_ptr idct;
334
21.2k
  int ci;
335
21.2k
  jpeg_component_info *compptr;
336
337
21.2k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
338
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
339
340
21.2k
  idct = (my_idct_ptr)
341
21.2k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
342
21.2k
                                sizeof(my_idct_controller));
343
21.2k
  cinfo->idct = (struct jpeg_inverse_dct *)idct;
344
21.2k
  idct->pub.start_pass = start_pass;
345
346
59.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
347
38.3k
       ci++, compptr++) {
348
    /* Allocate and pre-zero a multiplier table for each component */
349
38.3k
    compptr->dct_table =
350
38.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
351
38.3k
                                  sizeof(multiplier_table));
352
38.3k
    memset(compptr->dct_table, 0, sizeof(multiplier_table));
353
    /* Mark multiplier table not yet set up for any method */
354
38.3k
    idct->cur_method[ci] = -1;
355
38.3k
  }
356
21.2k
}