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