Coverage Report

Created: 2026-09-13 06:54

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
7.42k
{
103
7.42k
  my_idct_ptr idct = (my_idct_ptr)cinfo->idct;
104
7.42k
  int ci, i;
105
7.42k
  jpeg_component_info *compptr;
106
7.42k
  int method = 0;
107
7.42k
  _inverse_DCT_method_ptr method_ptr = NULL;
108
7.42k
  JQUANT_TBL *qtbl;
109
110
18.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
111
11.3k
       ci++, compptr++) {
112
    /* Select the proper IDCT routine for this component's scaling */
113
11.3k
    switch (compptr->_DCT_scaled_size) {
114
0
#ifdef IDCT_SCALING_SUPPORTED
115
0
    case 1:
116
0
      method_ptr = _jpeg_idct_1x1;
117
0
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
118
0
      break;
119
2.11k
    case 2:
120
#ifdef WITH_SIMD
121
1.82k
      if (jsimd_set_idct_2x2(cinfo))
122
1.82k
        method_ptr = jsimd_idct_2x2;
123
0
      else
124
0
#endif
125
293
        method_ptr = _jpeg_idct_2x2;
126
2.11k
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
127
2.11k
      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
394
    case 4:
133
#ifdef WITH_SIMD
134
298
      if (jsimd_set_idct_4x4(cinfo))
135
298
        method_ptr = jsimd_idct_4x4;
136
0
      else
137
0
#endif
138
96
        method_ptr = _jpeg_idct_4x4;
139
394
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
140
394
      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
2.12k
    case 6:
146
2.12k
      method_ptr = _jpeg_idct_6x6;
147
2.12k
      method = JDCT_ISLOW;      /* jidctint uses islow-style table */
148
2.12k
      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
6.28k
    case DCTSIZE:
155
6.28k
      switch (cinfo->dct_method) {
156
0
#ifdef DCT_ISLOW_SUPPORTED
157
2.51k
      case JDCT_ISLOW:
158
#ifdef WITH_SIMD
159
2.12k
        if (jsimd_set_idct_islow(cinfo))
160
2.12k
          method_ptr = jsimd_idct_islow;
161
0
        else
162
0
#endif
163
389
          method_ptr = _jpeg_idct_islow;
164
2.51k
        method = JDCT_ISLOW;
165
2.51k
        break;
166
0
#endif
167
0
#ifdef DCT_IFAST_SUPPORTED
168
3.77k
      case JDCT_IFAST:
169
#ifdef WITH_SIMD
170
3.33k
        if (jsimd_set_idct_ifast(cinfo))
171
3.33k
          method_ptr = jsimd_idct_ifast;
172
0
        else
173
0
#endif
174
440
          method_ptr = _jpeg_idct_ifast;
175
3.77k
        method = JDCT_IFAST;
176
3.77k
        break;
177
0
#endif
178
0
#ifdef DCT_FLOAT_SUPPORTED
179
0
      case JDCT_FLOAT:
180
#ifdef WITH_SIMD
181
0
        if (jsimd_set_idct_float(cinfo))
182
0
          method_ptr = jsimd_idct_float;
183
0
        else
184
0
#endif
185
0
          method_ptr = _jpeg_idct_float;
186
0
        method = JDCT_FLOAT;
187
0
        break;
188
0
#endif
189
0
      default:
190
0
        ERREXIT(cinfo, JERR_NOT_COMPILED);
191
0
        break;
192
6.28k
      }
193
6.28k
      break;
194
6.28k
#ifdef IDCT_SCALING_SUPPORTED
195
6.28k
    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
404
    case 12:
208
404
      method_ptr = _jpeg_idct_12x12;
209
404
      method = JDCT_ISLOW;      /* jidctint uses islow-style table */
210
404
      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
11.3k
    }
232
11.3k
    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
11.3k
    if (!compptr->component_needed || idct->cur_method[ci] == method)
241
0
      continue;
242
11.3k
    qtbl = compptr->quant_table;
243
11.3k
    if (qtbl == NULL)           /* happens if no data yet for component */
244
2.41k
      continue;
245
8.91k
    idct->cur_method[ci] = method;
246
8.91k
    switch (method) {
247
0
#ifdef PROVIDE_ISLOW_TABLES
248
5.98k
    case JDCT_ISLOW:
249
5.98k
      {
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
5.98k
        ISLOW_MULT_TYPE *ismtbl = (ISLOW_MULT_TYPE *)compptr->dct_table;
254
388k
        for (i = 0; i < DCTSIZE2; i++) {
255
382k
          ismtbl[i] = (ISLOW_MULT_TYPE)qtbl->quantval[i];
256
382k
        }
257
5.98k
      }
258
5.98k
      break;
259
0
#endif
260
0
#ifdef DCT_IFAST_SUPPORTED
261
2.93k
    case JDCT_IFAST:
262
2.93k
      {
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
2.93k
        IFAST_MULT_TYPE *ifmtbl = (IFAST_MULT_TYPE *)compptr->dct_table;
271
2.93k
#define CONST_BITS  14
272
2.93k
        static const INT16 aanscales[DCTSIZE2] = {
273
          /* precomputed values scaled up by 14 bits */
274
2.93k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
275
2.93k
          22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,
276
2.93k
          21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,
277
2.93k
          19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,
278
2.93k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
279
2.93k
          12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,
280
2.93k
           8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
281
2.93k
           4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
282
2.93k
        };
283
2.93k
        SHIFT_TEMPS
284
285
190k
        for (i = 0; i < DCTSIZE2; i++) {
286
187k
          ifmtbl[i] = (IFAST_MULT_TYPE)
287
187k
            DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
288
187k
                                  (JLONG)aanscales[i]),
289
187k
                    CONST_BITS - IFAST_SCALE_BITS);
290
187k
        }
291
2.93k
      }
292
2.93k
      break;
293
0
#endif
294
0
#ifdef DCT_FLOAT_SUPPORTED
295
0
    case JDCT_FLOAT:
296
0
      {
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
0
        FLOAT_MULT_TYPE *fmtbl = (FLOAT_MULT_TYPE *)compptr->dct_table;
303
0
        int row, col;
304
0
        static const double aanscalefactor[DCTSIZE] = {
305
0
          1.0, 1.387039845, 1.306562965, 1.175875602,
306
0
          1.0, 0.785694958, 0.541196100, 0.275899379
307
0
        };
308
309
0
        i = 0;
310
0
        for (row = 0; row < DCTSIZE; row++) {
311
0
          for (col = 0; col < DCTSIZE; col++) {
312
0
            fmtbl[i] = (FLOAT_MULT_TYPE)
313
0
              ((double)qtbl->quantval[i] *
314
0
               aanscalefactor[row] * aanscalefactor[col]);
315
0
            i++;
316
0
          }
317
0
        }
318
0
      }
319
0
      break;
320
0
#endif
321
0
    default:
322
0
      ERREXIT(cinfo, JERR_NOT_COMPILED);
323
0
      break;
324
8.91k
    }
325
8.91k
  }
326
7.42k
}
jddctmgr-8.c:start_pass
Line
Count
Source
102
6.42k
{
103
6.42k
  my_idct_ptr idct = (my_idct_ptr)cinfo->idct;
104
6.42k
  int ci, i;
105
6.42k
  jpeg_component_info *compptr;
106
6.42k
  int method = 0;
107
6.42k
  _inverse_DCT_method_ptr method_ptr = NULL;
108
6.42k
  JQUANT_TBL *qtbl;
109
110
16.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
111
9.71k
       ci++, compptr++) {
112
    /* Select the proper IDCT routine for this component's scaling */
113
9.71k
    switch (compptr->_DCT_scaled_size) {
114
0
#ifdef IDCT_SCALING_SUPPORTED
115
0
    case 1:
116
0
      method_ptr = _jpeg_idct_1x1;
117
0
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
118
0
      break;
119
1.82k
    case 2:
120
1.82k
#ifdef WITH_SIMD
121
1.82k
      if (jsimd_set_idct_2x2(cinfo))
122
1.82k
        method_ptr = jsimd_idct_2x2;
123
0
      else
124
0
#endif
125
0
        method_ptr = _jpeg_idct_2x2;
126
1.82k
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
127
1.82k
      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
298
    case 4:
133
298
#ifdef WITH_SIMD
134
298
      if (jsimd_set_idct_4x4(cinfo))
135
298
        method_ptr = jsimd_idct_4x4;
136
0
      else
137
0
#endif
138
0
        method_ptr = _jpeg_idct_4x4;
139
298
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
140
298
      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
1.83k
    case 6:
146
1.83k
      method_ptr = _jpeg_idct_6x6;
147
1.83k
      method = JDCT_ISLOW;      /* jidctint uses islow-style table */
148
1.83k
      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
5.45k
    case DCTSIZE:
155
5.45k
      switch (cinfo->dct_method) {
156
0
#ifdef DCT_ISLOW_SUPPORTED
157
2.12k
      case JDCT_ISLOW:
158
2.12k
#ifdef WITH_SIMD
159
2.12k
        if (jsimd_set_idct_islow(cinfo))
160
2.12k
          method_ptr = jsimd_idct_islow;
161
0
        else
162
0
#endif
163
0
          method_ptr = _jpeg_idct_islow;
164
2.12k
        method = JDCT_ISLOW;
165
2.12k
        break;
166
0
#endif
167
0
#ifdef DCT_IFAST_SUPPORTED
168
3.33k
      case JDCT_IFAST:
169
3.33k
#ifdef WITH_SIMD
170
3.33k
        if (jsimd_set_idct_ifast(cinfo))
171
3.33k
          method_ptr = jsimd_idct_ifast;
172
0
        else
173
0
#endif
174
0
          method_ptr = _jpeg_idct_ifast;
175
3.33k
        method = JDCT_IFAST;
176
3.33k
        break;
177
0
#endif
178
0
#ifdef DCT_FLOAT_SUPPORTED
179
0
      case JDCT_FLOAT:
180
0
#ifdef WITH_SIMD
181
0
        if (jsimd_set_idct_float(cinfo))
182
0
          method_ptr = jsimd_idct_float;
183
0
        else
184
0
#endif
185
0
          method_ptr = _jpeg_idct_float;
186
0
        method = JDCT_FLOAT;
187
0
        break;
188
0
#endif
189
0
      default:
190
0
        ERREXIT(cinfo, JERR_NOT_COMPILED);
191
0
        break;
192
5.45k
      }
193
5.45k
      break;
194
5.45k
#ifdef IDCT_SCALING_SUPPORTED
195
5.45k
    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
308
    case 12:
208
308
      method_ptr = _jpeg_idct_12x12;
209
308
      method = JDCT_ISLOW;      /* jidctint uses islow-style table */
210
308
      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
9.71k
    }
232
9.71k
    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
9.71k
    if (!compptr->component_needed || idct->cur_method[ci] == method)
241
0
      continue;
242
9.71k
    qtbl = compptr->quant_table;
243
9.71k
    if (qtbl == NULL)           /* happens if no data yet for component */
244
2.11k
      continue;
245
7.60k
    idct->cur_method[ci] = method;
246
7.60k
    switch (method) {
247
0
#ifdef PROVIDE_ISLOW_TABLES
248
5.01k
    case JDCT_ISLOW:
249
5.01k
      {
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
5.01k
        ISLOW_MULT_TYPE *ismtbl = (ISLOW_MULT_TYPE *)compptr->dct_table;
254
326k
        for (i = 0; i < DCTSIZE2; i++) {
255
321k
          ismtbl[i] = (ISLOW_MULT_TYPE)qtbl->quantval[i];
256
321k
        }
257
5.01k
      }
258
5.01k
      break;
259
0
#endif
260
0
#ifdef DCT_IFAST_SUPPORTED
261
2.58k
    case JDCT_IFAST:
262
2.58k
      {
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
2.58k
        IFAST_MULT_TYPE *ifmtbl = (IFAST_MULT_TYPE *)compptr->dct_table;
271
2.58k
#define CONST_BITS  14
272
2.58k
        static const INT16 aanscales[DCTSIZE2] = {
273
          /* precomputed values scaled up by 14 bits */
274
2.58k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
275
2.58k
          22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,
276
2.58k
          21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,
277
2.58k
          19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,
278
2.58k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
279
2.58k
          12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,
280
2.58k
           8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
281
2.58k
           4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
282
2.58k
        };
283
2.58k
        SHIFT_TEMPS
284
285
167k
        for (i = 0; i < DCTSIZE2; i++) {
286
165k
          ifmtbl[i] = (IFAST_MULT_TYPE)
287
165k
            DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
288
165k
                                  (JLONG)aanscales[i]),
289
165k
                    CONST_BITS - IFAST_SCALE_BITS);
290
165k
        }
291
2.58k
      }
292
2.58k
      break;
293
0
#endif
294
0
#ifdef DCT_FLOAT_SUPPORTED
295
0
    case JDCT_FLOAT:
296
0
      {
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
0
        FLOAT_MULT_TYPE *fmtbl = (FLOAT_MULT_TYPE *)compptr->dct_table;
303
0
        int row, col;
304
0
        static const double aanscalefactor[DCTSIZE] = {
305
0
          1.0, 1.387039845, 1.306562965, 1.175875602,
306
0
          1.0, 0.785694958, 0.541196100, 0.275899379
307
0
        };
308
309
0
        i = 0;
310
0
        for (row = 0; row < DCTSIZE; row++) {
311
0
          for (col = 0; col < DCTSIZE; col++) {
312
0
            fmtbl[i] = (FLOAT_MULT_TYPE)
313
0
              ((double)qtbl->quantval[i] *
314
0
               aanscalefactor[row] * aanscalefactor[col]);
315
0
            i++;
316
0
          }
317
0
        }
318
0
      }
319
0
      break;
320
0
#endif
321
0
    default:
322
0
      ERREXIT(cinfo, JERR_NOT_COMPILED);
323
0
      break;
324
7.60k
    }
325
7.60k
  }
326
6.42k
}
jddctmgr-12.c:start_pass
Line
Count
Source
102
1.00k
{
103
1.00k
  my_idct_ptr idct = (my_idct_ptr)cinfo->idct;
104
1.00k
  int ci, i;
105
1.00k
  jpeg_component_info *compptr;
106
1.00k
  int method = 0;
107
1.00k
  _inverse_DCT_method_ptr method_ptr = NULL;
108
1.00k
  JQUANT_TBL *qtbl;
109
110
2.61k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
111
1.60k
       ci++, compptr++) {
112
    /* Select the proper IDCT routine for this component's scaling */
113
1.60k
    switch (compptr->_DCT_scaled_size) {
114
0
#ifdef IDCT_SCALING_SUPPORTED
115
0
    case 1:
116
0
      method_ptr = _jpeg_idct_1x1;
117
0
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
118
0
      break;
119
293
    case 2:
120
#ifdef WITH_SIMD
121
      if (jsimd_set_idct_2x2(cinfo))
122
        method_ptr = jsimd_idct_2x2;
123
      else
124
#endif
125
293
        method_ptr = _jpeg_idct_2x2;
126
293
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
127
293
      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
96
    case 4:
133
#ifdef WITH_SIMD
134
      if (jsimd_set_idct_4x4(cinfo))
135
        method_ptr = jsimd_idct_4x4;
136
      else
137
#endif
138
96
        method_ptr = _jpeg_idct_4x4;
139
96
      method = JDCT_ISLOW;      /* jidctred uses islow-style table */
140
96
      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
293
    case 6:
146
293
      method_ptr = _jpeg_idct_6x6;
147
293
      method = JDCT_ISLOW;      /* jidctint uses islow-style table */
148
293
      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
829
    case DCTSIZE:
155
829
      switch (cinfo->dct_method) {
156
0
#ifdef DCT_ISLOW_SUPPORTED
157
389
      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
389
          method_ptr = _jpeg_idct_islow;
164
389
        method = JDCT_ISLOW;
165
389
        break;
166
0
#endif
167
0
#ifdef DCT_IFAST_SUPPORTED
168
440
      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
440
          method_ptr = _jpeg_idct_ifast;
175
440
        method = JDCT_IFAST;
176
440
        break;
177
0
#endif
178
0
#ifdef DCT_FLOAT_SUPPORTED
179
0
      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
0
          method_ptr = _jpeg_idct_float;
186
0
        method = JDCT_FLOAT;
187
0
        break;
188
0
#endif
189
0
      default:
190
0
        ERREXIT(cinfo, JERR_NOT_COMPILED);
191
0
        break;
192
829
      }
193
829
      break;
194
829
#ifdef IDCT_SCALING_SUPPORTED
195
829
    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
96
    case 12:
208
96
      method_ptr = _jpeg_idct_12x12;
209
96
      method = JDCT_ISLOW;      /* jidctint uses islow-style table */
210
96
      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
1.60k
    }
232
1.60k
    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
1.60k
    if (!compptr->component_needed || idct->cur_method[ci] == method)
241
0
      continue;
242
1.60k
    qtbl = compptr->quant_table;
243
1.60k
    if (qtbl == NULL)           /* happens if no data yet for component */
244
296
      continue;
245
1.31k
    idct->cur_method[ci] = method;
246
1.31k
    switch (method) {
247
0
#ifdef PROVIDE_ISLOW_TABLES
248
963
    case JDCT_ISLOW:
249
963
      {
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
963
        ISLOW_MULT_TYPE *ismtbl = (ISLOW_MULT_TYPE *)compptr->dct_table;
254
62.5k
        for (i = 0; i < DCTSIZE2; i++) {
255
61.6k
          ismtbl[i] = (ISLOW_MULT_TYPE)qtbl->quantval[i];
256
61.6k
        }
257
963
      }
258
963
      break;
259
0
#endif
260
0
#ifdef DCT_IFAST_SUPPORTED
261
348
    case JDCT_IFAST:
262
348
      {
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
348
        IFAST_MULT_TYPE *ifmtbl = (IFAST_MULT_TYPE *)compptr->dct_table;
271
348
#define CONST_BITS  14
272
348
        static const INT16 aanscales[DCTSIZE2] = {
273
          /* precomputed values scaled up by 14 bits */
274
348
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
275
348
          22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,
276
348
          21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,
277
348
          19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,
278
348
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
279
348
          12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,
280
348
           8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
281
348
           4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
282
348
        };
283
348
        SHIFT_TEMPS
284
285
22.6k
        for (i = 0; i < DCTSIZE2; i++) {
286
22.2k
          ifmtbl[i] = (IFAST_MULT_TYPE)
287
22.2k
            DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
288
22.2k
                                  (JLONG)aanscales[i]),
289
22.2k
                    CONST_BITS - IFAST_SCALE_BITS);
290
22.2k
        }
291
348
      }
292
348
      break;
293
0
#endif
294
0
#ifdef DCT_FLOAT_SUPPORTED
295
0
    case JDCT_FLOAT:
296
0
      {
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
0
        FLOAT_MULT_TYPE *fmtbl = (FLOAT_MULT_TYPE *)compptr->dct_table;
303
0
        int row, col;
304
0
        static const double aanscalefactor[DCTSIZE] = {
305
0
          1.0, 1.387039845, 1.306562965, 1.175875602,
306
0
          1.0, 0.785694958, 0.541196100, 0.275899379
307
0
        };
308
309
0
        i = 0;
310
0
        for (row = 0; row < DCTSIZE; row++) {
311
0
          for (col = 0; col < DCTSIZE; col++) {
312
0
            fmtbl[i] = (FLOAT_MULT_TYPE)
313
0
              ((double)qtbl->quantval[i] *
314
0
               aanscalefactor[row] * aanscalefactor[col]);
315
0
            i++;
316
0
          }
317
0
        }
318
0
      }
319
0
      break;
320
0
#endif
321
0
    default:
322
0
      ERREXIT(cinfo, JERR_NOT_COMPILED);
323
0
      break;
324
1.31k
    }
325
1.31k
  }
326
1.00k
}
327
328
329
/*
330
 * Initialize IDCT manager.
331
 */
332
333
GLOBAL(void)
334
_jinit_inverse_dct(j_decompress_ptr cinfo)
335
12.6k
{
336
12.6k
  my_idct_ptr idct;
337
12.6k
  int ci;
338
12.6k
  jpeg_component_info *compptr;
339
340
12.6k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
341
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
342
343
12.6k
  idct = (my_idct_ptr)
344
12.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
345
12.6k
                                sizeof(my_idct_controller));
346
12.6k
  cinfo->idct = (struct jpeg_inverse_dct *)idct;
347
12.6k
  idct->pub.start_pass = start_pass;
348
349
32.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
350
20.1k
       ci++, compptr++) {
351
    /* Allocate and pre-zero a multiplier table for each component */
352
20.1k
    compptr->dct_table =
353
20.1k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
354
20.1k
                                  sizeof(multiplier_table));
355
20.1k
    memset(compptr->dct_table, 0, sizeof(multiplier_table));
356
    /* Mark multiplier table not yet set up for any method */
357
20.1k
    idct->cur_method[ci] = -1;
358
20.1k
  }
359
12.6k
}
jinit_inverse_dct
Line
Count
Source
335
11.1k
{
336
11.1k
  my_idct_ptr idct;
337
11.1k
  int ci;
338
11.1k
  jpeg_component_info *compptr;
339
340
11.1k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
341
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
342
343
11.1k
  idct = (my_idct_ptr)
344
11.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
345
11.1k
                                sizeof(my_idct_controller));
346
11.1k
  cinfo->idct = (struct jpeg_inverse_dct *)idct;
347
11.1k
  idct->pub.start_pass = start_pass;
348
349
28.5k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
350
17.4k
       ci++, compptr++) {
351
    /* Allocate and pre-zero a multiplier table for each component */
352
17.4k
    compptr->dct_table =
353
17.4k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
354
17.4k
                                  sizeof(multiplier_table));
355
17.4k
    memset(compptr->dct_table, 0, sizeof(multiplier_table));
356
    /* Mark multiplier table not yet set up for any method */
357
17.4k
    idct->cur_method[ci] = -1;
358
17.4k
  }
359
11.1k
}
j12init_inverse_dct
Line
Count
Source
335
1.47k
{
336
1.47k
  my_idct_ptr idct;
337
1.47k
  int ci;
338
1.47k
  jpeg_component_info *compptr;
339
340
1.47k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
341
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
342
343
1.47k
  idct = (my_idct_ptr)
344
1.47k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
345
1.47k
                                sizeof(my_idct_controller));
346
1.47k
  cinfo->idct = (struct jpeg_inverse_dct *)idct;
347
1.47k
  idct->pub.start_pass = start_pass;
348
349
4.19k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
350
2.72k
       ci++, compptr++) {
351
    /* Allocate and pre-zero a multiplier table for each component */
352
2.72k
    compptr->dct_table =
353
2.72k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
354
2.72k
                                  sizeof(multiplier_table));
355
2.72k
    memset(compptr->dct_table, 0, sizeof(multiplier_table));
356
    /* Mark multiplier table not yet set up for any method */
357
2.72k
    idct->cur_method[ci] = -1;
358
2.72k
  }
359
1.47k
}
360
361
#endif /* defined(DCT_ISLOW_SUPPORTED) || defined(DCT_IFAST_SUPPORTED) ||
362
          defined(DCT_FLOAT_SUPPORTED) */