Coverage Report

Created: 2026-12-01 06:32

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