]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/jpeg6/jdct.h
get the basics of a new scons build system together
[xonotic/netradiant.git] / libs / jpeg6 / jdct.h
1 /*\r
2 \r
3  * jdct.h\r
4 \r
5  *\r
6 \r
7  * Copyright (C) 1994, Thomas G. Lane.\r
8 \r
9  * This file is part of the Independent JPEG Group's software.\r
10 \r
11  * For conditions of distribution and use, see the accompanying README file.\r
12 \r
13  *\r
14 \r
15  * This include file contains common declarations for the forward and\r
16 \r
17  * inverse DCT modules.  These declarations are private to the DCT managers\r
18 \r
19  * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms.\r
20 \r
21  * The individual DCT algorithms are kept in separate files to ease \r
22 \r
23  * machine-dependent tuning (e.g., assembly coding).\r
24 \r
25  */\r
26 \r
27 \r
28 \r
29 \r
30 \r
31 /*\r
32 \r
33  * A forward DCT routine is given a pointer to a work area of type DCTELEM[];\r
34 \r
35  * the DCT is to be performed in-place in that buffer.  Type DCTELEM is int\r
36 \r
37  * for 8-bit samples, INT32 for 12-bit samples.  (NOTE: Floating-point DCT\r
38 \r
39  * implementations use an array of type FAST_FLOAT, instead.)\r
40 \r
41  * The DCT inputs are expected to be signed (range +-CENTERJSAMPLE).\r
42 \r
43  * The DCT outputs are returned scaled up by a factor of 8; they therefore\r
44 \r
45  * have a range of +-8K for 8-bit data, +-128K for 12-bit data.  This\r
46 \r
47  * convention improves accuracy in integer implementations and saves some\r
48 \r
49  * work in floating-point ones.\r
50 \r
51  * Quantization of the output coefficients is done by jcdctmgr.c.\r
52 \r
53  */\r
54 \r
55 \r
56 \r
57 #if BITS_IN_JSAMPLE == 8\r
58 \r
59 typedef int DCTELEM;            /* 16 or 32 bits is fine */\r
60 \r
61 #else\r
62 \r
63 typedef INT32 DCTELEM;          /* must have 32 bits */\r
64 \r
65 #endif\r
66 \r
67 \r
68 \r
69 typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));\r
70 \r
71 typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));\r
72 \r
73 \r
74 \r
75 \r
76 \r
77 /*\r
78 \r
79  * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer\r
80 \r
81  * to an output sample array.  The routine must dequantize the input data as\r
82 \r
83  * well as perform the IDCT; for dequantization, it uses the multiplier table\r
84 \r
85  * pointed to by compptr->dct_table.  The output data is to be placed into the\r
86 \r
87  * sample array starting at a specified column.  (Any row offset needed will\r
88 \r
89  * be applied to the array pointer before it is passed to the IDCT code.)\r
90 \r
91  * Note that the number of samples emitted by the IDCT routine is\r
92 \r
93  * DCT_scaled_size * DCT_scaled_size.\r
94 \r
95  */\r
96 \r
97 \r
98 \r
99 /* typedef inverse_DCT_method_ptr is declared in jpegint.h */\r
100 \r
101 \r
102 \r
103 /*\r
104 \r
105  * Each IDCT routine has its own ideas about the best dct_table element type.\r
106 \r
107  */\r
108 \r
109 \r
110 \r
111 typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */\r
112 \r
113 #if BITS_IN_JSAMPLE == 8\r
114 \r
115 typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */\r
116 \r
117 #define IFAST_SCALE_BITS  2     /* fractional bits in scale factors */\r
118 \r
119 #else\r
120 \r
121 typedef INT32 IFAST_MULT_TYPE;  /* need 32 bits for scaled quantizers */\r
122 \r
123 #define IFAST_SCALE_BITS  13    /* fractional bits in scale factors */\r
124 \r
125 #endif\r
126 \r
127 typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */\r
128 \r
129 \r
130 \r
131 \r
132 \r
133 /*\r
134 \r
135  * Each IDCT routine is responsible for range-limiting its results and\r
136 \r
137  * converting them to unsigned form (0..MAXJSAMPLE).  The raw outputs could\r
138 \r
139  * be quite far out of range if the input data is corrupt, so a bulletproof\r
140 \r
141  * range-limiting step is required.  We use a mask-and-table-lookup method\r
142 \r
143  * to do the combined operations quickly.  See the comments with\r
144 \r
145  * prepare_range_limit_table (in jdmaster.c) for more info.\r
146 \r
147  */\r
148 \r
149 \r
150 \r
151 #define IDCT_range_limit(cinfo)  ((cinfo)->sample_range_limit + CENTERJSAMPLE)\r
152 \r
153 \r
154 \r
155 #define RANGE_MASK  (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */\r
156 \r
157 \r
158 \r
159 \r
160 \r
161 /* Short forms of external names for systems with brain-damaged linkers. */\r
162 \r
163 \r
164 \r
165 #ifdef NEED_SHORT_EXTERNAL_NAMES\r
166 \r
167 #define jpeg_fdct_islow         jFDislow\r
168 \r
169 #define jpeg_fdct_ifast         jFDifast\r
170 \r
171 #define jpeg_fdct_float         jFDfloat\r
172 \r
173 #define jpeg_idct_islow         jRDislow\r
174 \r
175 #define jpeg_idct_ifast         jRDifast\r
176 \r
177 #define jpeg_idct_float         jRDfloat\r
178 \r
179 #define jpeg_idct_4x4           jRD4x4\r
180 \r
181 #define jpeg_idct_2x2           jRD2x2\r
182 \r
183 #define jpeg_idct_1x1           jRD1x1\r
184 \r
185 #endif /* NEED_SHORT_EXTERNAL_NAMES */\r
186 \r
187 \r
188 \r
189 /* Extern declarations for the forward and inverse DCT routines. */\r
190 \r
191 \r
192 \r
193 EXTERN void jpeg_fdct_islow JPP((DCTELEM * data));\r
194 \r
195 EXTERN void jpeg_fdct_ifast JPP((DCTELEM * data));\r
196 \r
197 EXTERN void jpeg_fdct_float JPP((FAST_FLOAT * data));\r
198 \r
199 \r
200 \r
201 EXTERN void jpeg_idct_islow\r
202 \r
203     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\r
204 \r
205          JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\r
206 \r
207 EXTERN void jpeg_idct_ifast\r
208 \r
209     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\r
210 \r
211          JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\r
212 \r
213 EXTERN void jpeg_idct_float\r
214 \r
215     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\r
216 \r
217          JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\r
218 \r
219 EXTERN void jpeg_idct_4x4\r
220 \r
221     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\r
222 \r
223          JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\r
224 \r
225 EXTERN void jpeg_idct_2x2\r
226 \r
227     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\r
228 \r
229          JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\r
230 \r
231 EXTERN void jpeg_idct_1x1\r
232 \r
233     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\r
234 \r
235          JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\r
236 \r
237 \r
238 \r
239 \r
240 \r
241 /*\r
242 \r
243  * Macros for handling fixed-point arithmetic; these are used by many\r
244 \r
245  * but not all of the DCT/IDCT modules.\r
246 \r
247  *\r
248 \r
249  * All values are expected to be of type INT32.\r
250 \r
251  * Fractional constants are scaled left by CONST_BITS bits.\r
252 \r
253  * CONST_BITS is defined within each module using these macros,\r
254 \r
255  * and may differ from one module to the next.\r
256 \r
257  */\r
258 \r
259 \r
260 \r
261 #define ONE     ((INT32) 1)\r
262 \r
263 #define CONST_SCALE (ONE << CONST_BITS)\r
264 \r
265 \r
266 \r
267 /* Convert a positive real constant to an integer scaled by CONST_SCALE.\r
268 \r
269  * Caution: some C compilers fail to reduce "FIX(constant)" at compile time,\r
270 \r
271  * thus causing a lot of useless floating-point operations at run time.\r
272 \r
273  */\r
274 \r
275 \r
276 \r
277 #define FIX(x)  ((INT32) ((x) * CONST_SCALE + 0.5))\r
278 \r
279 \r
280 \r
281 /* Descale and correctly round an INT32 value that's scaled by N bits.\r
282 \r
283  * We assume RIGHT_SHIFT rounds towards minus infinity, so adding\r
284 \r
285  * the fudge factor is correct for either sign of X.\r
286 \r
287  */\r
288 \r
289 \r
290 \r
291 #define DESCALE(x,n)  RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)\r
292 \r
293 \r
294 \r
295 /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.\r
296 \r
297  * This macro is used only when the two inputs will actually be no more than\r
298 \r
299  * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a\r
300 \r
301  * full 32x32 multiply.  This provides a useful speedup on many machines.\r
302 \r
303  * Unfortunately there is no way to specify a 16x16->32 multiply portably\r
304 \r
305  * in C, but some C compilers will do the right thing if you provide the\r
306 \r
307  * correct combination of casts.\r
308 \r
309  */\r
310 \r
311 \r
312 \r
313 #ifdef SHORTxSHORT_32           /* may work if 'int' is 32 bits */\r
314 \r
315 #define MULTIPLY16C16(var,const)  (((INT16) (var)) * ((INT16) (const)))\r
316 \r
317 #endif\r
318 \r
319 #ifdef SHORTxLCONST_32          /* known to work with Microsoft C 6.0 */\r
320 \r
321 #define MULTIPLY16C16(var,const)  (((INT16) (var)) * ((INT32) (const)))\r
322 \r
323 #endif\r
324 \r
325 \r
326 \r
327 #ifndef MULTIPLY16C16           /* default definition */\r
328 \r
329 #define MULTIPLY16C16(var,const)  ((var) * (const))\r
330 \r
331 #endif\r
332 \r
333 \r
334 \r
335 /* Same except both inputs are variables. */\r
336 \r
337 \r
338 \r
339 #ifdef SHORTxSHORT_32           /* may work if 'int' is 32 bits */\r
340 \r
341 #define MULTIPLY16V16(var1,var2)  (((INT16) (var1)) * ((INT16) (var2)))\r
342 \r
343 #endif\r
344 \r
345 \r
346 \r
347 #ifndef MULTIPLY16V16           /* default definition */\r
348 \r
349 #define MULTIPLY16V16(var1,var2)  ((var1) * (var2))\r
350 \r
351 #endif\r
352 \r