3 { Original : jddctmgr.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
5 { This file contains the inverse-DCT management logic.
6 This code selects a particular IDCT implementation to be used,
7 and it performs related housekeeping chores. No code in this file
8 is executed per IDCT step, only during output pass setup.
10 Note that the IDCT routines are responsible for performing coefficient
11 dequantization as well as the IDCT proper. This module sets up the
12 dequantization multiplier table needed by the IDCT routine. }
14 interface
16 {$I imjconfig.inc}
18 {$N+}
20 uses
21 imjmorecfg,
22 imjinclude,
23 imjdeferr,
24 imjerror,
25 imjpeglib,
27 imjidctfst,
28 {$IFDEF BASM}
29 imjidctasm,
30 {$ELSE}
31 imjidctint,
32 {$ENDIF}
33 imjidctflt,
34 imjidctred;
38 { Initialize IDCT manager. }
40 {GLOBAL}
44 implementation
46 { The decompressor input side (jdinput.c) saves away the appropriate
47 quantization table for each component at the start of the first scan
48 involving that component. (This is necessary in order to correctly
49 decode files that reuse Q-table slots.)
50 When we are ready to make an output pass, the saved Q-table is converted
51 to a multiplier table that will actually be used by the IDCT routine.
52 The multiplier table contents are IDCT-method-dependent. To support
53 application changes in IDCT method between scans, we can remake the
54 multiplier tables if necessary.
55 In buffered-image mode, the first output pass may occur before any data
56 has been seen for some components, and thus before their Q-tables have
57 been saved away. To handle this case, multiplier tables are preset
58 to zeroes; the result of the IDCT will be a neutral gray level. }
61 { Private subobject for this module }
63 type
68 { This array contains the IDCT method code that each multiplier table
69 is currently set up for, or -1 if it's not yet set up.
70 The actual multiplier tables are pointed to by dct_table in the
71 per-component comp_info structures. }
77 { Allocated multiplier tables: big enough for any supported variant }
79 type
83 {$ifdef DCT_IFAST_SUPPORTED}
85 {$endif}
86 {$ifdef DCT_FLOAT_SUPPORTED}
88 {$endif}
92 { The current scaled-IDCT routines require ISLOW-style multiplier tables,
93 so be sure to compile that code if either ISLOW or SCALING is requested. }
95 {$ifdef DCT_ISLOW_SUPPORTED}
96 {$define PROVIDE_ISLOW_TABLES}
97 {$else}
98 {$ifdef IDCT_SCALING_SUPPORTED}
99 {$define PROVIDE_ISLOW_TABLES}
100 {$endif}
101 {$endif}
104 { Prepare for an output pass.
105 Here we select the proper IDCT routine for each component and build
106 a matching multiplier table. }
108 {METHODDEF}
110 var
117 {$ifdef PROVIDE_ISLOW_TABLES}
118 var
120 {$endif}
121 {$ifdef DCT_IFAST_SUPPORTED}
122 const
124 const
135 var
137 {SHIFT_TEMPS}
139 { Descale and correctly round an INT32 value that's scaled by N bits.
140 We assume RIGHT_SHIFT rounds towards minus infinity, so adding
141 the fudge factor is correct for either sign of X. }
144 var
146 begin
147 {$ifdef RIGHT_SHIFT_IS_UNSIGNED}
151 else
153 {$else}
155 {$endif}
158 {$endif}
159 {$ifdef DCT_FLOAT_SUPPORTED}
160 const
164 var
167 {$endif}
168 begin
175 begin
176 { Select the proper IDCT routine for this component's scaling }
178 {$ifdef IDCT_SCALING_SUPPORTED}
191 {$endif}
192 DCTSIZE:
194 {$ifdef DCT_ISLOW_SUPPORTED}
195 JDCT_ISLOW:
196 begin
200 {$endif}
201 {$ifdef DCT_IFAST_SUPPORTED}
202 JDCT_IFAST:
203 begin
207 {$endif}
208 {$ifdef DCT_FLOAT_SUPPORTED}
209 JDCT_FLOAT:
210 begin
214 {$endif}
215 else
218 else
222 { Create multiplier table from quant table.
223 However, we can skip this if the component is uninteresting
224 or if we already built the table. Also, if no quant table
225 has yet been saved for the component, we leave the
226 multiplier table all-zero; we'll be reading zeroes from the
227 coefficient controller's buffer anyway. }
230 continue;
233 continue;
236 {$ifdef PROVIDE_ISLOW_TABLES}
237 JDCT_ISLOW:
238 begin
239 { For LL&M IDCT method, multipliers are equal to raw quantization
240 coefficients, but are stored as ints to ensure access efficiency. }
244 begin
248 {$endif}
249 {$ifdef DCT_IFAST_SUPPORTED}
250 JDCT_IFAST:
251 begin
252 { For AA&N IDCT method, multipliers are equal to quantization
253 coefficients scaled by scalefactor[row]*scalefactor[col], where
254 scalefactor[0] := 1
255 scalefactor[k] := cos(k*PI/16) * sqrt(2) for k=1..7
256 For integer operation, the multiplier table is to be scaled by
257 IFAST_SCALE_BITS. }
262 begin
268 {$endif}
269 {$ifdef DCT_FLOAT_SUPPORTED}
270 JDCT_FLOAT:
271 begin
272 { For float 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 }
281 begin
283 begin
291 {$endif}
292 else
294 break;
301 { Initialize IDCT manager. }
303 {GLOBAL}
305 var
309 begin
318 begin
319 { Allocate and pre-zero a multiplier table for each component }
324 { Mark multiplier table not yet set up for any method }