Coverage Report

Created: 2026-03-12 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/src/jcdctmgr.c
Line
Count
Source
1
/*
2
 * jcdctmgr.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1996, Thomas G. Lane.
6
 * libjpeg-turbo Modifications:
7
 * Copyright (C) 1999-2006, MIYASAKA Masaru.
8
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
9
 * Copyright (C) 2011, 2014-2015, 2022, 2024-2026, D. R. Commander.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the forward-DCT management logic.
14
 * This code selects a particular DCT implementation to be used,
15
 * and it performs related housekeeping chores including coefficient
16
 * quantization.
17
 */
18
19
#define JPEG_INTERNALS
20
#include "jinclude.h"
21
#include "jpeglib.h"
22
#include "jdct.h"               /* Private declarations for DCT subsystem */
23
#ifdef WITH_SIMD
24
#include "../simd/jsimddct.h"
25
#endif
26
#ifdef WITH_PROFILE
27
#include "tjutil.h"
28
#endif
29
30
31
/* Private subobject for this module */
32
33
METHODDEF(void) quantize(JCOEFPTR, DCTELEM *, DCTELEM *);
34
35
typedef struct {
36
  struct jpeg_forward_dct pub;  /* public fields */
37
38
  /* Pointer to the DCT routine actually in use */
39
  forward_DCT_method_ptr dct;
40
  convsamp_method_ptr convsamp;
41
  quantize_method_ptr quantize;
42
43
  /* The actual post-DCT divisors --- not identical to the quant table
44
   * entries, because of scaling (especially for an unnormalized DCT).
45
   * Each table is given in normal array order.
46
   */
47
  DCTELEM *divisors[NUM_QUANT_TBLS];
48
49
  /* work area for FDCT subroutine */
50
  DCTELEM *workspace;
51
52
#ifdef DCT_FLOAT_SUPPORTED
53
  /* Same as above for the floating-point case. */
54
  float_DCT_method_ptr float_dct;
55
  float_convsamp_method_ptr float_convsamp;
56
  float_quantize_method_ptr float_quantize;
57
  FAST_FLOAT *float_divisors[NUM_QUANT_TBLS];
58
  FAST_FLOAT *float_workspace;
59
#endif
60
} my_fdct_controller;
61
62
typedef my_fdct_controller *my_fdct_ptr;
63
64
65
#if BITS_IN_JSAMPLE == 8
66
67
/*
68
 * Find the highest bit in an integer through binary search.
69
 */
70
71
LOCAL(int)
72
flss(UINT16 val)
73
1.49M
{
74
1.49M
  int bit;
75
76
1.49M
  bit = 16;
77
78
1.49M
  if (!val)
79
0
    return 0;
80
81
1.49M
  if (!(val & 0xff00)) {
82
808k
    bit -= 8;
83
808k
    val <<= 8;
84
808k
  }
85
1.49M
  if (!(val & 0xf000)) {
86
993k
    bit -= 4;
87
993k
    val <<= 4;
88
993k
  }
89
1.49M
  if (!(val & 0xc000)) {
90
740k
    bit -= 2;
91
740k
    val <<= 2;
92
740k
  }
93
1.49M
  if (!(val & 0x8000)) {
94
603k
    bit -= 1;
95
603k
    val <<= 1;
96
603k
  }
97
98
1.49M
  return bit;
99
1.49M
}
100
101
102
/*
103
 * Compute values to do a division using reciprocal.
104
 *
105
 * This implementation is based on an algorithm described in
106
 *   "Optimizing subroutines in assembly language:
107
 *   An optimization guide for x86 platforms" (https://agner.org/optimize).
108
 * More information about the basic algorithm can be found in
109
 * the paper "Integer Division Using Reciprocals" by Robert Alverson.
110
 *
111
 * The basic idea is to replace x/d by x * d^-1. In order to store
112
 * d^-1 with enough precision we shift it left a few places. It turns
113
 * out that this algoright gives just enough precision, and also fits
114
 * into DCTELEM:
115
 *
116
 *   b = (the number of significant bits in divisor) - 1
117
 *   r = (word size) + b
118
 *   f = 2^r / divisor
119
 *
120
 * f will not be an integer for most cases, so we need to compensate
121
 * for the rounding error introduced:
122
 *
123
 *   no fractional part:
124
 *
125
 *       result = input >> r
126
 *
127
 *   fractional part of f < 0.5:
128
 *
129
 *       round f down to nearest integer
130
 *       result = ((input + 1) * f) >> r
131
 *
132
 *   fractional part of f > 0.5:
133
 *
134
 *       round f up to nearest integer
135
 *       result = (input * f) >> r
136
 *
137
 * This is the original algorithm that gives truncated results. But we
138
 * want properly rounded results, so we replace "input" with
139
 * "input + divisor/2".
140
 *
141
 * In order to allow SIMD implementations we also tweak the values to
142
 * allow the same calculation to be made at all times:
143
 *
144
 *   dctbl[0] = f rounded to nearest integer
145
 *   dctbl[1] = divisor / 2 (+ 1 if fractional part of f < 0.5)
146
 *   dctbl[2] = 1 << ((word size) * 2 - r)
147
 *   dctbl[3] = r - (word size)
148
 *
149
 * dctbl[2] is for stupid instruction sets where the shift operation
150
 * isn't member wise (e.g. MMX).
151
 *
152
 * The reason dctbl[2] and dctbl[3] reduce the shift with (word size)
153
 * is that most SIMD implementations have a "multiply and store top
154
 * half" operation.
155
 *
156
 * Lastly, we store each of the values in their own table instead
157
 * of in a consecutive manner, yet again in order to allow SIMD
158
 * routines.
159
 */
160
161
LOCAL(int)
162
compute_reciprocal(UINT16 divisor, DCTELEM *dtbl)
163
1.50M
{
164
1.50M
  UDCTELEM2 fq, fr;
165
1.50M
  UDCTELEM c;
166
1.50M
  int b, r;
167
168
1.50M
  if (divisor <= 1) {
169
    /* divisor == 1 means unquantized, so these reciprocal/correction/shift
170
     * values will cause the C quantization algorithm to act like the
171
     * identity function.  Since only the C quantization algorithm is used in
172
     * these cases, the scale value is irrelevant.
173
     *
174
     * divisor == 0 can never happen in a normal program, because
175
     * jpeg_add_quant_table() clamps values < 1.  However, a program could
176
     * abuse the API by manually modifying the exposed quantization table just
177
     * before calling jpeg_start_compress().  Thus, we effectively clamp
178
     * values < 1 here as well, to avoid dividing by 0.
179
     */
180
15.1k
    dtbl[DCTSIZE2 * 0] = (DCTELEM)1;                        /* reciprocal */
181
15.1k
    dtbl[DCTSIZE2 * 1] = (DCTELEM)0;                        /* correction */
182
15.1k
    dtbl[DCTSIZE2 * 2] = (DCTELEM)1;                        /* scale */
183
15.1k
    dtbl[DCTSIZE2 * 3] = -(DCTELEM)(sizeof(DCTELEM) * 8);   /* shift */
184
15.1k
    return 0;
185
15.1k
  }
186
187
1.49M
  b = flss(divisor) - 1;
188
1.49M
  r  = sizeof(DCTELEM) * 8 + b;
189
190
1.49M
  fq = ((UDCTELEM2)1 << r) / divisor;
191
1.49M
  fr = ((UDCTELEM2)1 << r) % divisor;
192
193
1.49M
  c = divisor / 2;                      /* for rounding */
194
195
1.49M
  if (fr == 0) {                        /* divisor is power of two */
196
    /* fq will be one bit too large to fit in DCTELEM, so adjust */
197
143k
    fq >>= 1;
198
143k
    r--;
199
1.35M
  } else if (fr <= (divisor / 2U)) {    /* fractional part is < 0.5 */
200
497k
    c++;
201
854k
  } else {                              /* fractional part is > 0.5 */
202
854k
    fq++;
203
854k
  }
204
205
1.49M
  dtbl[DCTSIZE2 * 0] = (DCTELEM)fq;     /* reciprocal */
206
1.49M
  dtbl[DCTSIZE2 * 1] = (DCTELEM)c;      /* correction + roundfactor */
207
1.49M
#ifdef WITH_SIMD
208
1.49M
  dtbl[DCTSIZE2 * 2] = (DCTELEM)(1 << (sizeof(DCTELEM) * 8 * 2 - r)); /* scale */
209
#else
210
  dtbl[DCTSIZE2 * 2] = 1;
211
#endif
212
1.49M
  dtbl[DCTSIZE2 * 3] = (DCTELEM)r - sizeof(DCTELEM) * 8; /* shift */
213
214
1.49M
  if (r <= 16) return 0;
215
1.45M
  else return 1;
216
1.49M
}
217
218
#endif
219
220
221
/*
222
 * Initialize for a processing pass.
223
 * Verify that all referenced Q-tables are present, and set up
224
 * the divisor table for each one.
225
 * In the current implementation, DCT of all components is done during
226
 * the first pass, even if only some components will be output in the
227
 * first scan.  Hence all components should be examined here.
228
 */
229
230
METHODDEF(void)
231
start_pass_fdctmgr(j_compress_ptr cinfo)
232
10.0k
{
233
10.0k
  my_fdct_ptr fdct = (my_fdct_ptr)cinfo->fdct;
234
10.0k
  int ci, qtblno, i;
235
10.0k
  jpeg_component_info *compptr;
236
10.0k
  JQUANT_TBL *qtbl;
237
10.0k
  DCTELEM *dtbl;
238
239
33.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
240
23.5k
       ci++, compptr++) {
241
23.5k
    qtblno = compptr->quant_tbl_no;
242
    /* Make sure specified quantization table is present */
243
23.5k
    if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
244
23.5k
        cinfo->quant_tbl_ptrs[qtblno] == NULL)
245
0
      ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
246
23.5k
    qtbl = cinfo->quant_tbl_ptrs[qtblno];
247
    /* Compute divisors for this quant table */
248
    /* We may do this more than once for same table, but it's not a big deal */
249
23.5k
    switch (cinfo->dct_method) {
250
0
#ifdef DCT_ISLOW_SUPPORTED
251
16.9k
    case JDCT_ISLOW:
252
      /* For LL&M IDCT method, divisors are equal to raw quantization
253
       * coefficients multiplied by 8 (to counteract scaling).
254
       */
255
16.9k
      if (fdct->divisors[qtblno] == NULL) {
256
11.8k
        fdct->divisors[qtblno] = (DCTELEM *)
257
11.8k
          (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
258
11.8k
                                      (DCTSIZE2 * 4) * sizeof(DCTELEM));
259
11.8k
      }
260
16.9k
      dtbl = fdct->divisors[qtblno];
261
1.09M
      for (i = 0; i < DCTSIZE2; i++) {
262
#if BITS_IN_JSAMPLE == 8
263
#ifdef WITH_SIMD
264
1.08M
        if (!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]) &&
265
0
            fdct->quantize != quantize)
266
0
          fdct->quantize = quantize;
267
#else
268
        compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]);
269
#endif
270
#else
271
        dtbl[i] = ((DCTELEM)qtbl->quantval[i]) << 3;
272
#endif
273
1.08M
      }
274
16.9k
      break;
275
0
#endif
276
0
#ifdef DCT_IFAST_SUPPORTED
277
6.69k
    case JDCT_IFAST:
278
6.69k
      {
279
        /* For AA&N IDCT method, divisors are equal to quantization
280
         * coefficients scaled by scalefactor[row]*scalefactor[col], where
281
         *   scalefactor[0] = 1
282
         *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
283
         * We apply a further scale factor of 8.
284
         */
285
6.69k
#define CONST_BITS  14
286
6.69k
        static const INT16 aanscales[DCTSIZE2] = {
287
          /* precomputed values scaled up by 14 bits */
288
6.69k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
289
6.69k
          22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,
290
6.69k
          21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,
291
6.69k
          19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,
292
6.69k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
293
6.69k
          12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,
294
6.69k
           8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
295
6.69k
           4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
296
6.69k
        };
297
6.69k
        SHIFT_TEMPS
298
299
6.69k
        if (fdct->divisors[qtblno] == NULL) {
300
5.00k
          fdct->divisors[qtblno] = (DCTELEM *)
301
5.00k
            (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
302
5.00k
                                        (DCTSIZE2 * 4) * sizeof(DCTELEM));
303
5.00k
        }
304
6.69k
        dtbl = fdct->divisors[qtblno];
305
434k
        for (i = 0; i < DCTSIZE2; i++) {
306
#if BITS_IN_JSAMPLE == 8
307
#ifdef WITH_SIMD
308
428k
          if (!compute_reciprocal(
309
428k
                DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
310
428k
                                      (JLONG)aanscales[i]),
311
428k
                        CONST_BITS - 3), &dtbl[i]) &&
312
50.4k
              fdct->quantize != quantize)
313
1.68k
            fdct->quantize = quantize;
314
#else
315
          compute_reciprocal(
316
            DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
317
                                  (JLONG)aanscales[i]),
318
                    CONST_BITS-3), &dtbl[i]);
319
#endif
320
#else
321
          dtbl[i] = (DCTELEM)
322
0
            DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
323
                                  (JLONG)aanscales[i]),
324
                    CONST_BITS - 3);
325
#endif
326
428k
        }
327
6.69k
      }
328
6.69k
      break;
329
0
#endif
330
0
#ifdef DCT_FLOAT_SUPPORTED
331
0
    case JDCT_FLOAT:
332
0
      {
333
        /* For float AA&N IDCT method, divisors are equal to quantization
334
         * coefficients scaled by scalefactor[row]*scalefactor[col], where
335
         *   scalefactor[0] = 1
336
         *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
337
         * We apply a further scale factor of 8.
338
         * What's actually stored is 1/divisor so that the inner loop can
339
         * use a multiplication rather than a division.
340
         */
341
0
        FAST_FLOAT *fdtbl;
342
0
        int row, col;
343
0
        static const double aanscalefactor[DCTSIZE] = {
344
0
          1.0, 1.387039845, 1.306562965, 1.175875602,
345
0
          1.0, 0.785694958, 0.541196100, 0.275899379
346
0
        };
347
348
0
        if (fdct->float_divisors[qtblno] == NULL) {
349
0
          fdct->float_divisors[qtblno] = (FAST_FLOAT *)
350
0
            (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
351
0
                                        DCTSIZE2 * sizeof(FAST_FLOAT));
352
0
        }
353
0
        fdtbl = fdct->float_divisors[qtblno];
354
0
        i = 0;
355
0
        for (row = 0; row < DCTSIZE; row++) {
356
0
          for (col = 0; col < DCTSIZE; col++) {
357
0
            fdtbl[i] = (FAST_FLOAT)
358
0
              (1.0 / (((double)qtbl->quantval[i] *
359
0
                       aanscalefactor[row] * aanscalefactor[col] * 8.0)));
360
0
            i++;
361
0
          }
362
0
        }
363
0
      }
364
0
      break;
365
0
#endif
366
0
    default:
367
0
      ERREXIT(cinfo, JERR_NOT_COMPILED);
368
0
      break;
369
23.5k
    }
370
23.5k
  }
371
10.0k
}
jcdctmgr-8.c:start_pass_fdctmgr
Line
Count
Source
232
10.0k
{
233
10.0k
  my_fdct_ptr fdct = (my_fdct_ptr)cinfo->fdct;
234
10.0k
  int ci, qtblno, i;
235
10.0k
  jpeg_component_info *compptr;
236
10.0k
  JQUANT_TBL *qtbl;
237
10.0k
  DCTELEM *dtbl;
238
239
33.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
240
23.5k
       ci++, compptr++) {
241
23.5k
    qtblno = compptr->quant_tbl_no;
242
    /* Make sure specified quantization table is present */
243
23.5k
    if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
244
23.5k
        cinfo->quant_tbl_ptrs[qtblno] == NULL)
245
0
      ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
246
23.5k
    qtbl = cinfo->quant_tbl_ptrs[qtblno];
247
    /* Compute divisors for this quant table */
248
    /* We may do this more than once for same table, but it's not a big deal */
249
23.5k
    switch (cinfo->dct_method) {
250
0
#ifdef DCT_ISLOW_SUPPORTED
251
16.9k
    case JDCT_ISLOW:
252
      /* For LL&M IDCT method, divisors are equal to raw quantization
253
       * coefficients multiplied by 8 (to counteract scaling).
254
       */
255
16.9k
      if (fdct->divisors[qtblno] == NULL) {
256
11.8k
        fdct->divisors[qtblno] = (DCTELEM *)
257
11.8k
          (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
258
11.8k
                                      (DCTSIZE2 * 4) * sizeof(DCTELEM));
259
11.8k
      }
260
16.9k
      dtbl = fdct->divisors[qtblno];
261
1.09M
      for (i = 0; i < DCTSIZE2; i++) {
262
1.08M
#if BITS_IN_JSAMPLE == 8
263
1.08M
#ifdef WITH_SIMD
264
1.08M
        if (!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]) &&
265
0
            fdct->quantize != quantize)
266
0
          fdct->quantize = quantize;
267
#else
268
        compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]);
269
#endif
270
#else
271
        dtbl[i] = ((DCTELEM)qtbl->quantval[i]) << 3;
272
#endif
273
1.08M
      }
274
16.9k
      break;
275
0
#endif
276
0
#ifdef DCT_IFAST_SUPPORTED
277
6.69k
    case JDCT_IFAST:
278
6.69k
      {
279
        /* For AA&N IDCT method, divisors are equal to quantization
280
         * coefficients scaled by scalefactor[row]*scalefactor[col], where
281
         *   scalefactor[0] = 1
282
         *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
283
         * We apply a further scale factor of 8.
284
         */
285
6.69k
#define CONST_BITS  14
286
6.69k
        static const INT16 aanscales[DCTSIZE2] = {
287
          /* precomputed values scaled up by 14 bits */
288
6.69k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
289
6.69k
          22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,
290
6.69k
          21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,
291
6.69k
          19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,
292
6.69k
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
293
6.69k
          12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,
294
6.69k
           8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
295
6.69k
           4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
296
6.69k
        };
297
6.69k
        SHIFT_TEMPS
298
299
6.69k
        if (fdct->divisors[qtblno] == NULL) {
300
5.00k
          fdct->divisors[qtblno] = (DCTELEM *)
301
5.00k
            (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
302
5.00k
                                        (DCTSIZE2 * 4) * sizeof(DCTELEM));
303
5.00k
        }
304
6.69k
        dtbl = fdct->divisors[qtblno];
305
434k
        for (i = 0; i < DCTSIZE2; i++) {
306
428k
#if BITS_IN_JSAMPLE == 8
307
428k
#ifdef WITH_SIMD
308
428k
          if (!compute_reciprocal(
309
428k
                DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
310
428k
                                      (JLONG)aanscales[i]),
311
428k
                        CONST_BITS - 3), &dtbl[i]) &&
312
50.4k
              fdct->quantize != quantize)
313
1.68k
            fdct->quantize = quantize;
314
#else
315
          compute_reciprocal(
316
            DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
317
                                  (JLONG)aanscales[i]),
318
                    CONST_BITS-3), &dtbl[i]);
319
#endif
320
#else
321
          dtbl[i] = (DCTELEM)
322
            DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
323
                                  (JLONG)aanscales[i]),
324
                    CONST_BITS - 3);
325
#endif
326
428k
        }
327
6.69k
      }
328
6.69k
      break;
329
0
#endif
330
0
#ifdef DCT_FLOAT_SUPPORTED
331
0
    case JDCT_FLOAT:
332
0
      {
333
        /* For float AA&N IDCT method, divisors are equal to quantization
334
         * coefficients scaled by scalefactor[row]*scalefactor[col], where
335
         *   scalefactor[0] = 1
336
         *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
337
         * We apply a further scale factor of 8.
338
         * What's actually stored is 1/divisor so that the inner loop can
339
         * use a multiplication rather than a division.
340
         */
341
0
        FAST_FLOAT *fdtbl;
342
0
        int row, col;
343
0
        static const double aanscalefactor[DCTSIZE] = {
344
0
          1.0, 1.387039845, 1.306562965, 1.175875602,
345
0
          1.0, 0.785694958, 0.541196100, 0.275899379
346
0
        };
347
348
0
        if (fdct->float_divisors[qtblno] == NULL) {
349
0
          fdct->float_divisors[qtblno] = (FAST_FLOAT *)
350
0
            (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
351
0
                                        DCTSIZE2 * sizeof(FAST_FLOAT));
352
0
        }
353
0
        fdtbl = fdct->float_divisors[qtblno];
354
0
        i = 0;
355
0
        for (row = 0; row < DCTSIZE; row++) {
356
0
          for (col = 0; col < DCTSIZE; col++) {
357
0
            fdtbl[i] = (FAST_FLOAT)
358
0
              (1.0 / (((double)qtbl->quantval[i] *
359
0
                       aanscalefactor[row] * aanscalefactor[col] * 8.0)));
360
0
            i++;
361
0
          }
362
0
        }
363
0
      }
364
0
      break;
365
0
#endif
366
0
    default:
367
0
      ERREXIT(cinfo, JERR_NOT_COMPILED);
368
0
      break;
369
23.5k
    }
370
23.5k
  }
371
10.0k
}
Unexecuted instantiation: jcdctmgr-12.c:start_pass_fdctmgr
372
373
374
/*
375
 * Load data into workspace, applying unsigned->signed conversion.
376
 */
377
378
METHODDEF(void)
379
convsamp(_JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace)
380
0
{
381
0
  register DCTELEM *workspaceptr;
382
0
  register _JSAMPROW elemptr;
383
0
  register int elemr;
384
385
0
  workspaceptr = workspace;
386
0
  for (elemr = 0; elemr < DCTSIZE; elemr++) {
387
0
    elemptr = sample_data[elemr] + start_col;
388
389
0
#if DCTSIZE == 8                /* unroll the inner loop */
390
0
    *workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
391
0
    *workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
392
0
    *workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
393
0
    *workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
394
0
    *workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
395
0
    *workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
396
0
    *workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
397
0
    *workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
398
#else
399
    {
400
      register int elemc;
401
      for (elemc = DCTSIZE; elemc > 0; elemc--)
402
        *workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
403
    }
404
#endif
405
0
  }
406
0
}
Unexecuted instantiation: jcdctmgr-8.c:convsamp
Unexecuted instantiation: jcdctmgr-12.c:convsamp
407
408
409
/*
410
 * Quantize/descale the coefficients, and store into coef_blocks[].
411
 */
412
413
METHODDEF(void)
414
quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
415
3.77M
{
416
3.77M
  int i;
417
3.77M
  DCTELEM temp;
418
3.77M
  JCOEFPTR output_ptr = coef_block;
419
420
#if BITS_IN_JSAMPLE == 8
421
422
  UDCTELEM recip, corr;
423
  int shift;
424
  UDCTELEM2 product;
425
426
245M
  for (i = 0; i < DCTSIZE2; i++) {
427
241M
    temp = workspace[i];
428
241M
    recip = divisors[i + DCTSIZE2 * 0];
429
241M
    corr =  divisors[i + DCTSIZE2 * 1];
430
241M
    shift = divisors[i + DCTSIZE2 * 3];
431
432
241M
    if (temp < 0) {
433
12.8M
      temp = -temp;
434
12.8M
      product = (UDCTELEM2)(temp + corr) * recip;
435
12.8M
      product >>= shift + sizeof(DCTELEM) * 8;
436
12.8M
      temp = (DCTELEM)product;
437
12.8M
      temp = -temp;
438
228M
    } else {
439
228M
      product = (UDCTELEM2)(temp + corr) * recip;
440
228M
      product >>= shift + sizeof(DCTELEM) * 8;
441
228M
      temp = (DCTELEM)product;
442
228M
    }
443
241M
    output_ptr[i] = (JCOEF)temp;
444
241M
  }
445
446
#else
447
448
  register DCTELEM qval;
449
450
0
  for (i = 0; i < DCTSIZE2; i++) {
451
0
    qval = divisors[i];
452
0
    temp = workspace[i];
453
    /* Divide the coefficient value by qval, ensuring proper rounding.
454
     * Since C does not specify the direction of rounding for negative
455
     * quotients, we have to force the dividend positive for portability.
456
     *
457
     * In most files, at least half of the output values will be zero
458
     * (at default quantization settings, more like three-quarters...)
459
     * so we should ensure that this case is fast.  On many machines,
460
     * a comparison is enough cheaper than a divide to make a special test
461
     * a win.  Since both inputs will be nonnegative, we need only test
462
     * for a < b to discover whether a/b is 0.
463
     * If your machine's division is fast enough, define FAST_DIVIDE.
464
     */
465
#ifdef FAST_DIVIDE
466
#define DIVIDE_BY(a, b)  a /= b
467
#else
468
0
#define DIVIDE_BY(a, b)  if (a >= b) a /= b;  else a = 0
469
0
#endif
470
0
    if (temp < 0) {
471
0
      temp = -temp;
472
0
      temp += qval >> 1;        /* for rounding */
473
0
      DIVIDE_BY(temp, qval);
474
0
      temp = -temp;
475
0
    } else {
476
0
      temp += qval >> 1;        /* for rounding */
477
0
      DIVIDE_BY(temp, qval);
478
0
    }
479
0
    output_ptr[i] = (JCOEF)temp;
480
0
  }
481
482
#endif
483
484
3.77M
}
jcdctmgr-8.c:quantize
Line
Count
Source
415
3.77M
{
416
3.77M
  int i;
417
3.77M
  DCTELEM temp;
418
3.77M
  JCOEFPTR output_ptr = coef_block;
419
420
3.77M
#if BITS_IN_JSAMPLE == 8
421
422
3.77M
  UDCTELEM recip, corr;
423
3.77M
  int shift;
424
3.77M
  UDCTELEM2 product;
425
426
245M
  for (i = 0; i < DCTSIZE2; i++) {
427
241M
    temp = workspace[i];
428
241M
    recip = divisors[i + DCTSIZE2 * 0];
429
241M
    corr =  divisors[i + DCTSIZE2 * 1];
430
241M
    shift = divisors[i + DCTSIZE2 * 3];
431
432
241M
    if (temp < 0) {
433
12.8M
      temp = -temp;
434
12.8M
      product = (UDCTELEM2)(temp + corr) * recip;
435
12.8M
      product >>= shift + sizeof(DCTELEM) * 8;
436
12.8M
      temp = (DCTELEM)product;
437
12.8M
      temp = -temp;
438
228M
    } else {
439
228M
      product = (UDCTELEM2)(temp + corr) * recip;
440
228M
      product >>= shift + sizeof(DCTELEM) * 8;
441
228M
      temp = (DCTELEM)product;
442
228M
    }
443
241M
    output_ptr[i] = (JCOEF)temp;
444
241M
  }
445
446
#else
447
448
  register DCTELEM qval;
449
450
  for (i = 0; i < DCTSIZE2; i++) {
451
    qval = divisors[i];
452
    temp = workspace[i];
453
    /* Divide the coefficient value by qval, ensuring proper rounding.
454
     * Since C does not specify the direction of rounding for negative
455
     * quotients, we have to force the dividend positive for portability.
456
     *
457
     * In most files, at least half of the output values will be zero
458
     * (at default quantization settings, more like three-quarters...)
459
     * so we should ensure that this case is fast.  On many machines,
460
     * a comparison is enough cheaper than a divide to make a special test
461
     * a win.  Since both inputs will be nonnegative, we need only test
462
     * for a < b to discover whether a/b is 0.
463
     * If your machine's division is fast enough, define FAST_DIVIDE.
464
     */
465
#ifdef FAST_DIVIDE
466
#define DIVIDE_BY(a, b)  a /= b
467
#else
468
#define DIVIDE_BY(a, b)  if (a >= b) a /= b;  else a = 0
469
#endif
470
    if (temp < 0) {
471
      temp = -temp;
472
      temp += qval >> 1;        /* for rounding */
473
      DIVIDE_BY(temp, qval);
474
      temp = -temp;
475
    } else {
476
      temp += qval >> 1;        /* for rounding */
477
      DIVIDE_BY(temp, qval);
478
    }
479
    output_ptr[i] = (JCOEF)temp;
480
  }
481
482
#endif
483
484
3.77M
}
Unexecuted instantiation: jcdctmgr-12.c:quantize
485
486
487
/*
488
 * Perform forward DCT on one or more blocks of a component.
489
 *
490
 * The input samples are taken from the sample_data[] array starting at
491
 * position start_row/start_col, and moving to the right for any additional
492
 * blocks. The quantized coefficients are returned in coef_blocks[].
493
 */
494
495
METHODDEF(void)
496
forward_DCT(j_compress_ptr cinfo, jpeg_component_info *compptr,
497
            _JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
498
            JDIMENSION start_row, JDIMENSION start_col, JDIMENSION num_blocks)
499
/* This version is used for integer DCT implementations. */
500
13.2M
{
501
  /* This routine is heavily used, so it's worth coding it tightly. */
502
13.2M
  my_fdct_ptr fdct = (my_fdct_ptr)cinfo->fdct;
503
13.2M
  DCTELEM *divisors = fdct->divisors[compptr->quant_tbl_no];
504
13.2M
  DCTELEM *workspace;
505
13.2M
  JDIMENSION bi;
506
507
  /* Make sure the compiler doesn't look up these every pass */
508
13.2M
  forward_DCT_method_ptr do_dct = fdct->dct;
509
13.2M
  convsamp_method_ptr do_convsamp = fdct->convsamp;
510
13.2M
  quantize_method_ptr do_quantize = fdct->quantize;
511
13.2M
  workspace = fdct->workspace;
512
513
13.2M
  sample_data += start_row;     /* fold in the vertical offset once */
514
515
28.4M
  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
516
    /* Load data into workspace, applying unsigned->signed conversion */
517
#ifdef WITH_PROFILE
518
    cinfo->master->start = getTime();
519
#endif
520
15.2M
    (*do_convsamp) (sample_data, start_col, workspace);
521
#ifdef WITH_PROFILE
522
    cinfo->master->convsamp_elapsed += getTime() - cinfo->master->start;
523
    cinfo->master->convsamp_msamples += (double)DCTSIZE2 / 1000000.;
524
#endif
525
526
    /* Perform the DCT */
527
#ifdef WITH_PROFILE
528
    cinfo->master->start = getTime();
529
#endif
530
15.2M
    (*do_dct) (workspace);
531
#ifdef WITH_PROFILE
532
    cinfo->master->fdct_elapsed += getTime() - cinfo->master->start;
533
    cinfo->master->fdct_mcoeffs += (double)DCTSIZE2 / 1000000.;
534
#endif
535
536
    /* Quantize/descale the coefficients, and store into coef_blocks[] */
537
#ifdef WITH_PROFILE
538
    cinfo->master->start = getTime();
539
#endif
540
15.2M
    (*do_quantize) (coef_blocks[bi], divisors, workspace);
541
#ifdef WITH_PROFILE
542
    cinfo->master->quantize_elapsed += getTime() - cinfo->master->start;
543
    cinfo->master->quantize_mcoeffs += (double)DCTSIZE2 / 1000000.;
544
#endif
545
15.2M
  }
546
13.2M
}
jcdctmgr-8.c:forward_DCT
Line
Count
Source
500
13.2M
{
501
  /* This routine is heavily used, so it's worth coding it tightly. */
502
13.2M
  my_fdct_ptr fdct = (my_fdct_ptr)cinfo->fdct;
503
13.2M
  DCTELEM *divisors = fdct->divisors[compptr->quant_tbl_no];
504
13.2M
  DCTELEM *workspace;
505
13.2M
  JDIMENSION bi;
506
507
  /* Make sure the compiler doesn't look up these every pass */
508
13.2M
  forward_DCT_method_ptr do_dct = fdct->dct;
509
13.2M
  convsamp_method_ptr do_convsamp = fdct->convsamp;
510
13.2M
  quantize_method_ptr do_quantize = fdct->quantize;
511
13.2M
  workspace = fdct->workspace;
512
513
13.2M
  sample_data += start_row;     /* fold in the vertical offset once */
514
515
28.4M
  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
516
    /* Load data into workspace, applying unsigned->signed conversion */
517
#ifdef WITH_PROFILE
518
    cinfo->master->start = getTime();
519
#endif
520
15.2M
    (*do_convsamp) (sample_data, start_col, workspace);
521
#ifdef WITH_PROFILE
522
    cinfo->master->convsamp_elapsed += getTime() - cinfo->master->start;
523
    cinfo->master->convsamp_msamples += (double)DCTSIZE2 / 1000000.;
524
#endif
525
526
    /* Perform the DCT */
527
#ifdef WITH_PROFILE
528
    cinfo->master->start = getTime();
529
#endif
530
15.2M
    (*do_dct) (workspace);
531
#ifdef WITH_PROFILE
532
    cinfo->master->fdct_elapsed += getTime() - cinfo->master->start;
533
    cinfo->master->fdct_mcoeffs += (double)DCTSIZE2 / 1000000.;
534
#endif
535
536
    /* Quantize/descale the coefficients, and store into coef_blocks[] */
537
#ifdef WITH_PROFILE
538
    cinfo->master->start = getTime();
539
#endif
540
15.2M
    (*do_quantize) (coef_blocks[bi], divisors, workspace);
541
#ifdef WITH_PROFILE
542
    cinfo->master->quantize_elapsed += getTime() - cinfo->master->start;
543
    cinfo->master->quantize_mcoeffs += (double)DCTSIZE2 / 1000000.;
544
#endif
545
15.2M
  }
546
13.2M
}
Unexecuted instantiation: jcdctmgr-12.c:forward_DCT
547
548
549
#ifdef DCT_FLOAT_SUPPORTED
550
551
METHODDEF(void)
552
convsamp_float(_JSAMPARRAY sample_data, JDIMENSION start_col,
553
               FAST_FLOAT *workspace)
554
0
{
555
0
  register FAST_FLOAT *workspaceptr;
556
0
  register _JSAMPROW elemptr;
557
0
  register int elemr;
558
559
0
  workspaceptr = workspace;
560
0
  for (elemr = 0; elemr < DCTSIZE; elemr++) {
561
0
    elemptr = sample_data[elemr] + start_col;
562
0
#if DCTSIZE == 8                /* unroll the inner loop */
563
0
    *workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
564
0
    *workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
565
0
    *workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
566
0
    *workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
567
0
    *workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
568
0
    *workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
569
0
    *workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
570
0
    *workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
571
#else
572
    {
573
      register int elemc;
574
      for (elemc = DCTSIZE; elemc > 0; elemc--)
575
        *workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
576
    }
577
#endif
578
0
  }
579
0
}
Unexecuted instantiation: jcdctmgr-8.c:convsamp_float
Unexecuted instantiation: jcdctmgr-12.c:convsamp_float
580
581
582
METHODDEF(void)
583
quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
584
               FAST_FLOAT *workspace)
585
0
{
586
0
  register FAST_FLOAT temp;
587
0
  register int i;
588
0
  register JCOEFPTR output_ptr = coef_block;
589
590
0
  for (i = 0; i < DCTSIZE2; i++) {
591
    /* Apply the quantization and scaling factor */
592
0
    temp = workspace[i] * divisors[i];
593
594
    /* Round to nearest integer.
595
     * Since C does not specify the direction of rounding for negative
596
     * quotients, we have to force the dividend positive for portability.
597
     * The maximum coefficient size is +-16K (for 12-bit data), so this
598
     * code should work for either 16-bit or 32-bit ints.
599
     */
600
0
    output_ptr[i] = (JCOEF)((int)(temp + (FAST_FLOAT)16384.5) - 16384);
601
0
  }
602
0
}
Unexecuted instantiation: jcdctmgr-8.c:quantize_float
Unexecuted instantiation: jcdctmgr-12.c:quantize_float
603
604
605
METHODDEF(void)
606
forward_DCT_float(j_compress_ptr cinfo, jpeg_component_info *compptr,
607
                  _JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
608
                  JDIMENSION start_row, JDIMENSION start_col,
609
                  JDIMENSION num_blocks)
610
/* This version is used for floating-point DCT implementations. */
611
0
{
612
  /* This routine is heavily used, so it's worth coding it tightly. */
613
0
  my_fdct_ptr fdct = (my_fdct_ptr)cinfo->fdct;
614
0
  FAST_FLOAT *divisors = fdct->float_divisors[compptr->quant_tbl_no];
615
0
  FAST_FLOAT *workspace;
616
0
  JDIMENSION bi;
617
618
619
  /* Make sure the compiler doesn't look up these every pass */
620
0
  float_DCT_method_ptr do_dct = fdct->float_dct;
621
0
  float_convsamp_method_ptr do_convsamp = fdct->float_convsamp;
622
0
  float_quantize_method_ptr do_quantize = fdct->float_quantize;
623
0
  workspace = fdct->float_workspace;
624
625
0
  sample_data += start_row;     /* fold in the vertical offset once */
626
627
0
  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
628
    /* Load data into workspace, applying unsigned->signed conversion */
629
#ifdef WITH_PROFILE
630
    cinfo->master->start = getTime();
631
#endif
632
0
    (*do_convsamp) (sample_data, start_col, workspace);
633
#ifdef WITH_PROFILE
634
    cinfo->master->convsamp_elapsed += getTime() - cinfo->master->start;
635
    cinfo->master->convsamp_msamples += (double)DCTSIZE2 / 1000000.;
636
#endif
637
638
    /* Perform the DCT */
639
#ifdef WITH_PROFILE
640
    cinfo->master->start = getTime();
641
#endif
642
0
    (*do_dct) (workspace);
643
#ifdef WITH_PROFILE
644
    cinfo->master->fdct_elapsed += getTime() - cinfo->master->start;
645
    cinfo->master->fdct_mcoeffs += (double)DCTSIZE2 / 1000000.;
646
#endif
647
648
    /* Quantize/descale the coefficients, and store into coef_blocks[] */
649
#ifdef WITH_PROFILE
650
    cinfo->master->start = getTime();
651
#endif
652
0
    (*do_quantize) (coef_blocks[bi], divisors, workspace);
653
#ifdef WITH_PROFILE
654
    cinfo->master->quantize_elapsed += getTime() - cinfo->master->start;
655
    cinfo->master->quantize_mcoeffs += (double)DCTSIZE2 / 1000000.;
656
#endif
657
0
  }
658
0
}
Unexecuted instantiation: jcdctmgr-8.c:forward_DCT_float
Unexecuted instantiation: jcdctmgr-12.c:forward_DCT_float
659
660
#endif /* DCT_FLOAT_SUPPORTED */
661
662
663
/*
664
 * Initialize FDCT manager.
665
 */
666
667
GLOBAL(void)
668
_jinit_forward_dct(j_compress_ptr cinfo)
669
10.0k
{
670
10.0k
  my_fdct_ptr fdct;
671
10.0k
  int i;
672
673
10.0k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
674
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
675
676
10.0k
  fdct = (my_fdct_ptr)
677
10.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
678
10.0k
                                sizeof(my_fdct_controller));
679
10.0k
  cinfo->fdct = (struct jpeg_forward_dct *)fdct;
680
10.0k
  fdct->pub.start_pass = start_pass_fdctmgr;
681
682
  /* First determine the DCT... */
683
10.0k
  switch (cinfo->dct_method) {
684
0
#ifdef DCT_ISLOW_SUPPORTED
685
6.76k
  case JDCT_ISLOW:
686
6.76k
    fdct->pub._forward_DCT = forward_DCT;
687
#ifdef WITH_SIMD
688
6.76k
    if (!jsimd_set_fdct_islow(cinfo, &fdct->dct))
689
0
#endif
690
0
      fdct->dct = _jpeg_fdct_islow;
691
6.76k
    break;
692
0
#endif
693
0
#ifdef DCT_IFAST_SUPPORTED
694
3.32k
  case JDCT_IFAST:
695
3.32k
    fdct->pub._forward_DCT = forward_DCT;
696
#ifdef WITH_SIMD
697
3.32k
    if (!jsimd_set_fdct_ifast(cinfo, &fdct->dct))
698
0
#endif
699
0
      fdct->dct = _jpeg_fdct_ifast;
700
3.32k
    break;
701
0
#endif
702
0
#ifdef DCT_FLOAT_SUPPORTED
703
0
  case JDCT_FLOAT:
704
0
    fdct->pub._forward_DCT = forward_DCT_float;
705
#ifdef WITH_SIMD
706
0
    if (!jsimd_set_fdct_float(cinfo, &fdct->float_dct))
707
0
#endif
708
0
      fdct->float_dct = jpeg_fdct_float;
709
0
    break;
710
0
#endif
711
0
  default:
712
0
    ERREXIT(cinfo, JERR_NOT_COMPILED);
713
0
    break;
714
10.0k
  }
715
716
  /* ...then the supporting stages. */
717
10.0k
  switch (cinfo->dct_method) {
718
0
#ifdef DCT_ISLOW_SUPPORTED
719
6.76k
  case JDCT_ISLOW:
720
6.76k
#endif
721
6.76k
#ifdef DCT_IFAST_SUPPORTED
722
10.0k
  case JDCT_IFAST:
723
10.0k
#endif
724
10.0k
#if defined(DCT_ISLOW_SUPPORTED) || defined(DCT_IFAST_SUPPORTED)
725
#ifdef WITH_SIMD
726
10.0k
    if (!jsimd_set_convsamp(cinfo, &fdct->convsamp))
727
0
#endif
728
0
      fdct->convsamp = convsamp;
729
#ifdef WITH_SIMD
730
10.0k
    if (!jsimd_set_quantize(cinfo, &fdct->quantize))
731
0
#endif
732
0
      fdct->quantize = quantize;
733
10.0k
    break;
734
0
#endif
735
0
#ifdef DCT_FLOAT_SUPPORTED
736
0
  case JDCT_FLOAT:
737
#ifdef WITH_SIMD
738
0
    if (!jsimd_set_convsamp_float(cinfo, &fdct->float_convsamp))
739
0
#endif
740
0
      fdct->float_convsamp = convsamp_float;
741
#ifdef WITH_SIMD
742
0
    if (!jsimd_set_quantize_float(cinfo, &fdct->float_quantize))
743
0
#endif
744
0
      fdct->float_quantize = quantize_float;
745
0
    break;
746
0
#endif
747
0
  default:
748
0
    ERREXIT(cinfo, JERR_NOT_COMPILED);
749
0
    break;
750
10.0k
  }
751
752
  /* Allocate workspace memory */
753
10.0k
#ifdef DCT_FLOAT_SUPPORTED
754
10.0k
  if (cinfo->dct_method == JDCT_FLOAT)
755
0
    fdct->float_workspace = (FAST_FLOAT *)
756
0
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
757
0
                                  sizeof(FAST_FLOAT) * DCTSIZE2);
758
10.0k
  else
759
10.0k
#endif
760
10.0k
    fdct->workspace = (DCTELEM *)
761
10.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
762
10.0k
                                  sizeof(DCTELEM) * DCTSIZE2);
763
764
  /* Mark divisor tables unallocated */
765
50.4k
  for (i = 0; i < NUM_QUANT_TBLS; i++) {
766
40.3k
    fdct->divisors[i] = NULL;
767
40.3k
#ifdef DCT_FLOAT_SUPPORTED
768
    fdct->float_divisors[i] = NULL;
769
40.3k
#endif
770
40.3k
  }
771
10.0k
}
jinit_forward_dct
Line
Count
Source
669
10.0k
{
670
10.0k
  my_fdct_ptr fdct;
671
10.0k
  int i;
672
673
10.0k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
674
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
675
676
10.0k
  fdct = (my_fdct_ptr)
677
10.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
678
10.0k
                                sizeof(my_fdct_controller));
679
10.0k
  cinfo->fdct = (struct jpeg_forward_dct *)fdct;
680
10.0k
  fdct->pub.start_pass = start_pass_fdctmgr;
681
682
  /* First determine the DCT... */
683
10.0k
  switch (cinfo->dct_method) {
684
0
#ifdef DCT_ISLOW_SUPPORTED
685
6.76k
  case JDCT_ISLOW:
686
6.76k
    fdct->pub._forward_DCT = forward_DCT;
687
6.76k
#ifdef WITH_SIMD
688
6.76k
    if (!jsimd_set_fdct_islow(cinfo, &fdct->dct))
689
0
#endif
690
0
      fdct->dct = _jpeg_fdct_islow;
691
6.76k
    break;
692
0
#endif
693
0
#ifdef DCT_IFAST_SUPPORTED
694
3.32k
  case JDCT_IFAST:
695
3.32k
    fdct->pub._forward_DCT = forward_DCT;
696
3.32k
#ifdef WITH_SIMD
697
3.32k
    if (!jsimd_set_fdct_ifast(cinfo, &fdct->dct))
698
0
#endif
699
0
      fdct->dct = _jpeg_fdct_ifast;
700
3.32k
    break;
701
0
#endif
702
0
#ifdef DCT_FLOAT_SUPPORTED
703
0
  case JDCT_FLOAT:
704
0
    fdct->pub._forward_DCT = forward_DCT_float;
705
0
#ifdef WITH_SIMD
706
0
    if (!jsimd_set_fdct_float(cinfo, &fdct->float_dct))
707
0
#endif
708
0
      fdct->float_dct = jpeg_fdct_float;
709
0
    break;
710
0
#endif
711
0
  default:
712
0
    ERREXIT(cinfo, JERR_NOT_COMPILED);
713
0
    break;
714
10.0k
  }
715
716
  /* ...then the supporting stages. */
717
10.0k
  switch (cinfo->dct_method) {
718
0
#ifdef DCT_ISLOW_SUPPORTED
719
6.76k
  case JDCT_ISLOW:
720
6.76k
#endif
721
6.76k
#ifdef DCT_IFAST_SUPPORTED
722
10.0k
  case JDCT_IFAST:
723
10.0k
#endif
724
10.0k
#if defined(DCT_ISLOW_SUPPORTED) || defined(DCT_IFAST_SUPPORTED)
725
10.0k
#ifdef WITH_SIMD
726
10.0k
    if (!jsimd_set_convsamp(cinfo, &fdct->convsamp))
727
0
#endif
728
0
      fdct->convsamp = convsamp;
729
10.0k
#ifdef WITH_SIMD
730
10.0k
    if (!jsimd_set_quantize(cinfo, &fdct->quantize))
731
0
#endif
732
0
      fdct->quantize = quantize;
733
10.0k
    break;
734
0
#endif
735
0
#ifdef DCT_FLOAT_SUPPORTED
736
0
  case JDCT_FLOAT:
737
0
#ifdef WITH_SIMD
738
0
    if (!jsimd_set_convsamp_float(cinfo, &fdct->float_convsamp))
739
0
#endif
740
0
      fdct->float_convsamp = convsamp_float;
741
0
#ifdef WITH_SIMD
742
0
    if (!jsimd_set_quantize_float(cinfo, &fdct->float_quantize))
743
0
#endif
744
0
      fdct->float_quantize = quantize_float;
745
0
    break;
746
0
#endif
747
0
  default:
748
0
    ERREXIT(cinfo, JERR_NOT_COMPILED);
749
0
    break;
750
10.0k
  }
751
752
  /* Allocate workspace memory */
753
10.0k
#ifdef DCT_FLOAT_SUPPORTED
754
10.0k
  if (cinfo->dct_method == JDCT_FLOAT)
755
0
    fdct->float_workspace = (FAST_FLOAT *)
756
0
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
757
0
                                  sizeof(FAST_FLOAT) * DCTSIZE2);
758
10.0k
  else
759
10.0k
#endif
760
10.0k
    fdct->workspace = (DCTELEM *)
761
10.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
762
10.0k
                                  sizeof(DCTELEM) * DCTSIZE2);
763
764
  /* Mark divisor tables unallocated */
765
50.4k
  for (i = 0; i < NUM_QUANT_TBLS; i++) {
766
40.3k
    fdct->divisors[i] = NULL;
767
40.3k
#ifdef DCT_FLOAT_SUPPORTED
768
    fdct->float_divisors[i] = NULL;
769
40.3k
#endif
770
40.3k
  }
771
10.0k
}
Unexecuted instantiation: j12init_forward_dct