Coverage Report

Created: 2026-06-12 06:28

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