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