/src/ghostpdl/obj/jcdctmgr.c
Line | Count | Source |
1 | | /* |
2 | | * jcdctmgr.c |
3 | | * |
4 | | * Copyright (C) 1994-1996, Thomas G. Lane. |
5 | | * Modified 2003-2025 by Guido Vollbeding. |
6 | | * This file is part of the Independent JPEG Group's software. |
7 | | * For conditions of distribution and use, see the accompanying README file. |
8 | | * |
9 | | * This file contains the forward-DCT management logic. |
10 | | * This code selects a particular DCT implementation to be used, |
11 | | * and it performs related housekeeping chores including coefficient |
12 | | * quantization. |
13 | | */ |
14 | | |
15 | | #define JPEG_INTERNALS |
16 | | #include "jinclude.h" |
17 | | #include "jpeglib.h" |
18 | | #include "jdct.h" /* Private declarations for DCT subsystem */ |
19 | | |
20 | | |
21 | | /* Private subobject for this module */ |
22 | | |
23 | | typedef struct { |
24 | | struct jpeg_forward_dct pub; /* public fields */ |
25 | | |
26 | | /* Pointer to the DCT routine actually in use */ |
27 | | forward_DCT_method_ptr do_dct[MAX_COMPONENTS]; |
28 | | |
29 | | #ifdef DCT_FLOAT_SUPPORTED |
30 | | /* Same as above for the floating-point case. */ |
31 | | float_DCT_method_ptr do_float_dct[MAX_COMPONENTS]; |
32 | | #endif |
33 | | } my_fdct_controller; |
34 | | |
35 | | typedef my_fdct_controller * my_fdct_ptr; |
36 | | |
37 | | |
38 | | /* The allocated post-DCT divisor tables -- big enough for any |
39 | | * supported variant and not identical to the quant table entries, |
40 | | * because of scaling (especially for an unnormalized DCT) -- |
41 | | * are pointed to by dct_table in the per-component comp_info |
42 | | * structures. Each table is given in normal array order. |
43 | | */ |
44 | | |
45 | | typedef union { |
46 | | DCTELEM int_array[DCTSIZE2]; |
47 | | #ifdef DCT_FLOAT_SUPPORTED |
48 | | FAST_FLOAT float_array[DCTSIZE2]; |
49 | | #endif |
50 | | } divisor_table; |
51 | | |
52 | | |
53 | | /* |
54 | | * Perform forward DCT on one or more blocks of a component. |
55 | | * |
56 | | * The input samples are taken from the sample_data[] array starting at |
57 | | * position start_col, and moving to the right for any additional blocks. |
58 | | * The quantized coefficients are returned in coef_blocks[]. |
59 | | */ |
60 | | |
61 | | METHODDEF(void) |
62 | | forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr, |
63 | | JSAMPARRAY sample_data, JBLOCKROW coef_blocks, |
64 | | JDIMENSION start_col, JDIMENSION num_blocks) |
65 | | /* This version is used for integer DCT implementations. */ |
66 | 1.60M | { |
67 | | /* This routine is heavily used, so it's worth coding it tightly. */ |
68 | 1.60M | my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; |
69 | 1.60M | forward_DCT_method_ptr do_dct = fdct->do_dct[compptr->component_index]; |
70 | 1.60M | DCTELEM * divisors = (DCTELEM *) compptr->dct_table; |
71 | 1.60M | DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */ |
72 | 1.60M | JDIMENSION bi; |
73 | | |
74 | 3.96M | for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) { |
75 | | /* Perform the DCT */ |
76 | 2.35M | (*do_dct) (workspace, sample_data, start_col); |
77 | | |
78 | | /* Quantize/descale the coefficients, and store into coef_blocks[] */ |
79 | 2.35M | { register DCTELEM temp, qval; |
80 | 2.35M | register int i; |
81 | 2.35M | register JCOEFPTR output_ptr = coef_blocks[bi]; |
82 | | |
83 | 152M | for (i = 0; i < DCTSIZE2; i++) { |
84 | 150M | qval = divisors[i]; |
85 | 150M | temp = workspace[i]; |
86 | | /* Divide the coefficient value by qval, ensuring proper rounding. |
87 | | * Since C does not specify the direction of rounding for negative |
88 | | * quotients, we have to force the dividend positive for portability. |
89 | | * |
90 | | * In most files, at least half of the output values will be zero |
91 | | * (at default quantization settings, more like three-quarters...) |
92 | | * so we should ensure that this case is fast. On many machines, |
93 | | * a comparison is enough cheaper than a divide to make a special |
94 | | * test a win. Since both inputs will be nonnegative, we need |
95 | | * only test for a < b to discover whether a/b is 0. |
96 | | * If your machine's division is fast enough, define FAST_DIVIDE. |
97 | | */ |
98 | | #ifdef FAST_DIVIDE |
99 | | #define DIVIDE_BY(a,b) a /= b |
100 | | #else |
101 | 150M | #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0 |
102 | 150M | #endif |
103 | 150M | if (temp < 0) { |
104 | 12.6M | temp = -temp; |
105 | 12.6M | temp += qval>>1; /* for rounding */ |
106 | 12.6M | DIVIDE_BY(temp, qval); |
107 | 12.6M | temp = -temp; |
108 | 137M | } else { |
109 | 137M | temp += qval>>1; /* for rounding */ |
110 | 137M | DIVIDE_BY(temp, qval); |
111 | 137M | } |
112 | 150M | output_ptr[i] = (JCOEF) temp; |
113 | 150M | } |
114 | 2.35M | } |
115 | 2.35M | } |
116 | 1.60M | } |
117 | | |
118 | | |
119 | | #ifdef DCT_FLOAT_SUPPORTED |
120 | | |
121 | | METHODDEF(void) |
122 | | forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr, |
123 | | JSAMPARRAY sample_data, JBLOCKROW coef_blocks, |
124 | | JDIMENSION start_col, JDIMENSION num_blocks) |
125 | | /* This version is used for floating-point DCT implementations. */ |
126 | | { |
127 | | /* This routine is heavily used, so it's worth coding it tightly. */ |
128 | | my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; |
129 | | float_DCT_method_ptr do_dct = fdct->do_float_dct[compptr->component_index]; |
130 | | FAST_FLOAT * divisors = (FAST_FLOAT *) compptr->dct_table; |
131 | | FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */ |
132 | | JDIMENSION bi; |
133 | | |
134 | | for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) { |
135 | | /* Perform the DCT */ |
136 | | (*do_dct) (workspace, sample_data, start_col); |
137 | | |
138 | | /* Quantize/descale the coefficients, and store into coef_blocks[] */ |
139 | | { register FAST_FLOAT temp; |
140 | | register int i; |
141 | | register JCOEFPTR output_ptr = coef_blocks[bi]; |
142 | | |
143 | | for (i = 0; i < DCTSIZE2; i++) { |
144 | | /* Apply the quantization and scaling factor */ |
145 | | temp = workspace[i] * divisors[i]; |
146 | | /* Round to nearest integer. |
147 | | * Since C does not specify the direction of rounding for negative |
148 | | * quotients, we have to force the dividend positive for portability. |
149 | | * The maximum coefficient size is +-16K (for 12-bit data), so this |
150 | | * code should work for either 16-bit or 32-bit ints. |
151 | | */ |
152 | | output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384); |
153 | | } |
154 | | } |
155 | | } |
156 | | } |
157 | | |
158 | | #endif /* DCT_FLOAT_SUPPORTED */ |
159 | | |
160 | | |
161 | | /* |
162 | | * Initialize for a processing pass. |
163 | | * Verify that all referenced Q-tables are present, and set up |
164 | | * the divisor table for each one. |
165 | | * In the current implementation, DCT of all components is done during |
166 | | * the first pass, even if only some components will be output in the |
167 | | * first scan. Hence all components should be examined here. |
168 | | */ |
169 | | |
170 | | METHODDEF(void) |
171 | | start_pass_fdctmgr (j_compress_ptr cinfo) |
172 | 6.05k | { |
173 | 6.05k | my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; |
174 | 6.05k | int ci, qtblno, i; |
175 | 6.05k | jpeg_component_info *compptr; |
176 | 6.05k | J_DCT_METHOD method = JDCT_DEFAULT; |
177 | 6.05k | JQUANT_TBL * qtbl; |
178 | 6.05k | DCTELEM * dtbl; |
179 | | |
180 | 18.6k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
181 | 12.5k | ci++, compptr++) { |
182 | | /* Select the proper DCT routine for this component's scaling */ |
183 | 12.5k | switch ((compptr->DCT_h_scaled_size << 8) + compptr->DCT_v_scaled_size) { |
184 | 0 | #ifdef DCT_SCALING_SUPPORTED |
185 | | /* |
186 | | * The current scaled-DCT routines require ISLOW-style divisor tables, |
187 | | * so be sure to compile that code if either ISLOW or SCALING is requested. |
188 | | */ |
189 | 0 | #ifndef PROVIDE_ISLOW_TABLES |
190 | 0 | #define PROVIDE_ISLOW_TABLES |
191 | 0 | #endif |
192 | 0 | case ((1 << 8) + 1): |
193 | 0 | fdct->do_dct[ci] = jpeg_fdct_1x1; |
194 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
195 | 0 | break; |
196 | 0 | case ((2 << 8) + 2): |
197 | 0 | fdct->do_dct[ci] = jpeg_fdct_2x2; |
198 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
199 | 0 | break; |
200 | 0 | case ((3 << 8) + 3): |
201 | 0 | fdct->do_dct[ci] = jpeg_fdct_3x3; |
202 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
203 | 0 | break; |
204 | 0 | case ((4 << 8) + 4): |
205 | 0 | fdct->do_dct[ci] = jpeg_fdct_4x4; |
206 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
207 | 0 | break; |
208 | 0 | case ((5 << 8) + 5): |
209 | 0 | fdct->do_dct[ci] = jpeg_fdct_5x5; |
210 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
211 | 0 | break; |
212 | 0 | case ((6 << 8) + 6): |
213 | 0 | fdct->do_dct[ci] = jpeg_fdct_6x6; |
214 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
215 | 0 | break; |
216 | 0 | case ((7 << 8) + 7): |
217 | 0 | fdct->do_dct[ci] = jpeg_fdct_7x7; |
218 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
219 | 0 | break; |
220 | 0 | case ((9 << 8) + 9): |
221 | 0 | fdct->do_dct[ci] = jpeg_fdct_9x9; |
222 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
223 | 0 | break; |
224 | 0 | case ((10 << 8) + 10): |
225 | 0 | fdct->do_dct[ci] = jpeg_fdct_10x10; |
226 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
227 | 0 | break; |
228 | 0 | case ((11 << 8) + 11): |
229 | 0 | fdct->do_dct[ci] = jpeg_fdct_11x11; |
230 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
231 | 0 | break; |
232 | 0 | case ((12 << 8) + 12): |
233 | 0 | fdct->do_dct[ci] = jpeg_fdct_12x12; |
234 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
235 | 0 | break; |
236 | 0 | case ((13 << 8) + 13): |
237 | 0 | fdct->do_dct[ci] = jpeg_fdct_13x13; |
238 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
239 | 0 | break; |
240 | 0 | case ((14 << 8) + 14): |
241 | 0 | fdct->do_dct[ci] = jpeg_fdct_14x14; |
242 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
243 | 0 | break; |
244 | 0 | case ((15 << 8) + 15): |
245 | 0 | fdct->do_dct[ci] = jpeg_fdct_15x15; |
246 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
247 | 0 | break; |
248 | 6.49k | case ((16 << 8) + 16): |
249 | 6.49k | fdct->do_dct[ci] = jpeg_fdct_16x16; |
250 | 6.49k | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
251 | 6.49k | break; |
252 | 0 | case ((16 << 8) + 8): |
253 | 0 | fdct->do_dct[ci] = jpeg_fdct_16x8; |
254 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
255 | 0 | break; |
256 | 0 | case ((14 << 8) + 7): |
257 | 0 | fdct->do_dct[ci] = jpeg_fdct_14x7; |
258 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
259 | 0 | break; |
260 | 0 | case ((12 << 8) + 6): |
261 | 0 | fdct->do_dct[ci] = jpeg_fdct_12x6; |
262 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
263 | 0 | break; |
264 | 0 | case ((10 << 8) + 5): |
265 | 0 | fdct->do_dct[ci] = jpeg_fdct_10x5; |
266 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
267 | 0 | break; |
268 | 0 | case ((8 << 8) + 4): |
269 | 0 | fdct->do_dct[ci] = jpeg_fdct_8x4; |
270 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
271 | 0 | break; |
272 | 0 | case ((6 << 8) + 3): |
273 | 0 | fdct->do_dct[ci] = jpeg_fdct_6x3; |
274 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
275 | 0 | break; |
276 | 0 | case ((4 << 8) + 2): |
277 | 0 | fdct->do_dct[ci] = jpeg_fdct_4x2; |
278 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
279 | 0 | break; |
280 | 0 | case ((2 << 8) + 1): |
281 | 0 | fdct->do_dct[ci] = jpeg_fdct_2x1; |
282 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
283 | 0 | break; |
284 | 0 | case ((8 << 8) + 16): |
285 | 0 | fdct->do_dct[ci] = jpeg_fdct_8x16; |
286 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
287 | 0 | break; |
288 | 0 | case ((7 << 8) + 14): |
289 | 0 | fdct->do_dct[ci] = jpeg_fdct_7x14; |
290 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
291 | 0 | break; |
292 | 0 | case ((6 << 8) + 12): |
293 | 0 | fdct->do_dct[ci] = jpeg_fdct_6x12; |
294 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
295 | 0 | break; |
296 | 0 | case ((5 << 8) + 10): |
297 | 0 | fdct->do_dct[ci] = jpeg_fdct_5x10; |
298 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
299 | 0 | break; |
300 | 0 | case ((4 << 8) + 8): |
301 | 0 | fdct->do_dct[ci] = jpeg_fdct_4x8; |
302 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
303 | 0 | break; |
304 | 0 | case ((3 << 8) + 6): |
305 | 0 | fdct->do_dct[ci] = jpeg_fdct_3x6; |
306 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
307 | 0 | break; |
308 | 0 | case ((2 << 8) + 4): |
309 | 0 | fdct->do_dct[ci] = jpeg_fdct_2x4; |
310 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
311 | 0 | break; |
312 | 0 | case ((1 << 8) + 2): |
313 | 0 | fdct->do_dct[ci] = jpeg_fdct_1x2; |
314 | 0 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
315 | 0 | break; |
316 | 0 | #endif |
317 | 6.07k | case ((DCTSIZE << 8) + DCTSIZE): |
318 | 6.07k | switch (cinfo->dct_method) { |
319 | 0 | #ifdef DCT_ISLOW_SUPPORTED |
320 | 6.07k | case JDCT_ISLOW: |
321 | | #ifndef PROVIDE_ISLOW_TABLES |
322 | | #define PROVIDE_ISLOW_TABLES |
323 | | #endif |
324 | 6.07k | fdct->do_dct[ci] = jpeg_fdct_islow; |
325 | 6.07k | method = JDCT_ISLOW; |
326 | 6.07k | break; |
327 | 0 | #endif |
328 | | #ifdef DCT_IFAST_SUPPORTED |
329 | | case JDCT_IFAST: |
330 | | #if BITS_IN_JSAMPLE < JPEG_DATA_PRECISION || \ |
331 | | BITS_IN_JSAMPLE > JPEG_DATA_PRECISION + 8 |
332 | | /* |
333 | | * Adjustment of divisor tables in JDCT_IFAST |
334 | | * below doesn't work well in this condition. |
335 | | * Use JDCT_ISLOW instead. |
336 | | */ |
337 | | #ifndef PROVIDE_ISLOW_TABLES |
338 | | #define PROVIDE_ISLOW_TABLES |
339 | | #endif |
340 | | fdct->do_dct[ci] = jpeg_fdct_islow; |
341 | | method = JDCT_ISLOW; |
342 | | #else |
343 | | #ifndef PROVIDE_IFAST_TABLES |
344 | | #define PROVIDE_IFAST_TABLES |
345 | | #endif |
346 | | fdct->do_dct[ci] = jpeg_fdct_ifast; |
347 | | method = JDCT_IFAST; |
348 | | #endif |
349 | | break; |
350 | | #endif |
351 | | #ifdef DCT_FLOAT_SUPPORTED |
352 | | case JDCT_FLOAT: |
353 | | fdct->do_float_dct[ci] = jpeg_fdct_float; |
354 | | method = JDCT_FLOAT; |
355 | | break; |
356 | | #endif |
357 | 0 | default: |
358 | 0 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
359 | 6.07k | } |
360 | 6.07k | break; |
361 | 6.07k | default: |
362 | 0 | ERREXIT2(cinfo, JERR_BAD_DCTSIZE, |
363 | 12.5k | compptr->DCT_h_scaled_size, compptr->DCT_v_scaled_size); |
364 | 12.5k | } |
365 | 12.5k | qtblno = compptr->quant_tbl_no; |
366 | | /* Make sure specified quantization table is present */ |
367 | 12.5k | if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || |
368 | 12.5k | cinfo->quant_tbl_ptrs[qtblno] == NULL) |
369 | 0 | ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); |
370 | 12.5k | qtbl = cinfo->quant_tbl_ptrs[qtblno]; |
371 | | /* Create divisor table from quant table */ |
372 | 12.5k | switch (method) { |
373 | 0 | #ifdef PROVIDE_ISLOW_TABLES |
374 | 12.5k | case JDCT_ISLOW: |
375 | | /* For LL&M FDCT method, divisors are equal to raw quantization |
376 | | * coefficients multiplied by 8 (to counteract scaling). |
377 | | */ |
378 | 12.5k | dtbl = (DCTELEM *) compptr->dct_table; |
379 | 816k | for (i = 0; i < DCTSIZE2; i++) { |
380 | 804k | dtbl[i] = |
381 | 804k | ((DCTELEM) qtbl->quantval[i]) << (compptr->component_needed ? 4 : 3); |
382 | 804k | } |
383 | 12.5k | fdct->pub.forward_DCT[ci] = forward_DCT; |
384 | 12.5k | break; |
385 | 0 | #endif |
386 | | #ifdef PROVIDE_IFAST_TABLES |
387 | | case JDCT_IFAST: |
388 | | { |
389 | | /* For AA&N FDCT method, divisors are equal to quantization |
390 | | * coefficients scaled by scalefactor[row]*scalefactor[col], where |
391 | | * scalefactor[0] = 1 |
392 | | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 |
393 | | * We apply a further scale factor of 8 |
394 | | * with adjustment if necessary. |
395 | | */ |
396 | | #define CONST_BITS 14 |
397 | | static const INT16 aanscales[DCTSIZE2] = { |
398 | | /* precomputed values scaled up by 14 bits */ |
399 | | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
400 | | 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, |
401 | | 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, |
402 | | 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, |
403 | | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
404 | | 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, |
405 | | 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, |
406 | | 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 |
407 | | }; |
408 | | SHIFT_TEMPS |
409 | | |
410 | | dtbl = (DCTELEM *) compptr->dct_table; |
411 | | if (compptr->component_needed) { |
412 | | for (i = 0; i < DCTSIZE2; i++) { |
413 | | dtbl[i] = (DCTELEM) |
414 | | DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], |
415 | | (INT32) aanscales[i]), |
416 | | CONST_BITS+JPEG_DATA_PRECISION-BITS_IN_JSAMPLE-4); |
417 | | } |
418 | | } else { |
419 | | for (i = 0; i < DCTSIZE2; i++) { |
420 | | dtbl[i] = (DCTELEM) |
421 | | DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], |
422 | | (INT32) aanscales[i]), |
423 | | CONST_BITS+JPEG_DATA_PRECISION-BITS_IN_JSAMPLE-3); |
424 | | } |
425 | | } |
426 | | } |
427 | | fdct->pub.forward_DCT[ci] = forward_DCT; |
428 | | break; |
429 | | #endif |
430 | | #ifdef DCT_FLOAT_SUPPORTED |
431 | | case JDCT_FLOAT: |
432 | | { |
433 | | /* For float AA&N FDCT method, divisors are equal to quantization |
434 | | * coefficients scaled by scalefactor[row]*scalefactor[col], where |
435 | | * scalefactor[0] = 1 |
436 | | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 |
437 | | * We apply a further scale factor of 8 |
438 | | * with adjustment if necessary. |
439 | | * What's actually stored is 1/divisor so that the inner loop can |
440 | | * use a multiplication rather than a division. |
441 | | */ |
442 | | FAST_FLOAT * fdtbl = (FAST_FLOAT *) compptr->dct_table; |
443 | | int row, col; |
444 | | static const double aanscalefactor[DCTSIZE] = { |
445 | | 1.0, 1.387039845, 1.306562965, 1.175875602, |
446 | | 1.0, 0.785694958, 0.541196100, 0.275899379 |
447 | | }; |
448 | | #if BITS_IN_JSAMPLE == JPEG_DATA_PRECISION |
449 | | |
450 | | i = 0; |
451 | | for (row = 0; row < DCTSIZE; row++) { |
452 | | for (col = 0; col < DCTSIZE; col++) { |
453 | | fdtbl[i] = (FAST_FLOAT) |
454 | | (1.0 / ((double) qtbl->quantval[i] * |
455 | | aanscalefactor[row] * aanscalefactor[col] * |
456 | | (compptr->component_needed ? 16.0 : 8.0))); |
457 | | #else |
458 | | double extrafactor = compptr->component_needed ? 16.0 : 8.0; |
459 | | |
460 | | /* Adjust extra factor */ |
461 | | #if BITS_IN_JSAMPLE < JPEG_DATA_PRECISION |
462 | | i = JPEG_DATA_PRECISION - BITS_IN_JSAMPLE; |
463 | | do { extrafactor *= 0.5; } while (--i); |
464 | | #else |
465 | | i = BITS_IN_JSAMPLE - JPEG_DATA_PRECISION; |
466 | | do { extrafactor *= 2.0; } while (--i); |
467 | | #endif |
468 | | |
469 | | i = 0; |
470 | | for (row = 0; row < DCTSIZE; row++) { |
471 | | for (col = 0; col < DCTSIZE; col++) { |
472 | | fdtbl[i] = (FAST_FLOAT) |
473 | | (1.0 / ((double) qtbl->quantval[i] * |
474 | | aanscalefactor[row] * aanscalefactor[col] * |
475 | | extrafactor)); |
476 | | #endif |
477 | | i++; |
478 | | } |
479 | | } |
480 | | } |
481 | | fdct->pub.forward_DCT[ci] = forward_DCT_float; |
482 | | break; |
483 | | #endif |
484 | 0 | default: |
485 | 0 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
486 | 12.5k | } |
487 | 12.5k | } |
488 | 6.05k | } |
489 | | |
490 | | |
491 | | /* |
492 | | * Initialize FDCT manager. |
493 | | */ |
494 | | |
495 | | GLOBAL(void) |
496 | | jinit_forward_dct (j_compress_ptr cinfo) |
497 | 6.05k | { |
498 | 6.05k | my_fdct_ptr fdct; |
499 | 6.05k | int ci; |
500 | 6.05k | jpeg_component_info *compptr; |
501 | | |
502 | 6.05k | fdct = (my_fdct_ptr) (*cinfo->mem->alloc_small) |
503 | 6.05k | ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_fdct_controller)); |
504 | 6.05k | cinfo->fdct = &fdct->pub; |
505 | 6.05k | fdct->pub.start_pass = start_pass_fdctmgr; |
506 | | |
507 | 18.6k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
508 | 12.5k | ci++, compptr++) { |
509 | | /* Allocate a divisor table for each component */ |
510 | 12.5k | compptr->dct_table = (*cinfo->mem->alloc_small) |
511 | 12.5k | ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(divisor_table)); |
512 | 12.5k | } |
513 | 6.05k | } |