OLD | NEW |
1 /* | 1 /* |
2 * jcdctmgr.c | 2 * jcdctmgr.c |
3 * | 3 * |
4 * Copyright (C) 1994-1996, Thomas G. Lane. | 4 * Copyright (C) 1994-1996, Thomas G. Lane. |
5 * Copyright (C) 1999-2006, MIYASAKA Masaru. | 5 * Copyright (C) 1999-2006, MIYASAKA Masaru. |
6 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB | 6 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
| 7 * Copyright (C) 2011 D. R. Commander |
7 * This file is part of the Independent JPEG Group's software. | 8 * This file is part of the Independent JPEG Group's software. |
8 * For conditions of distribution and use, see the accompanying README file. | 9 * For conditions of distribution and use, see the accompanying README file. |
9 * | 10 * |
10 * This file contains the forward-DCT management logic. | 11 * This file contains the forward-DCT management logic. |
11 * This code selects a particular DCT implementation to be used, | 12 * This code selects a particular DCT implementation to be used, |
12 * and it performs related housekeeping chores including coefficient | 13 * and it performs related housekeeping chores including coefficient |
13 * quantization. | 14 * quantization. |
14 */ | 15 */ |
15 | 16 |
16 #define JPEG_INTERNALS | 17 #define JPEG_INTERNALS |
(...skipping 15 matching lines...) Expand all Loading... |
32 (JSAMPARRAY sample_data, JDIMENSION start_col, | 33 (JSAMPARRAY sample_data, JDIMENSION start_col, |
33 FAST_FLOAT *workspace)); | 34 FAST_FLOAT *workspace)); |
34 | 35 |
35 typedef JMETHOD(void, quantize_method_ptr, | 36 typedef JMETHOD(void, quantize_method_ptr, |
36 (JCOEFPTR coef_block, DCTELEM * divisors, | 37 (JCOEFPTR coef_block, DCTELEM * divisors, |
37 DCTELEM * workspace)); | 38 DCTELEM * workspace)); |
38 typedef JMETHOD(void, float_quantize_method_ptr, | 39 typedef JMETHOD(void, float_quantize_method_ptr, |
39 (JCOEFPTR coef_block, FAST_FLOAT * divisors, | 40 (JCOEFPTR coef_block, FAST_FLOAT * divisors, |
40 FAST_FLOAT * workspace)); | 41 FAST_FLOAT * workspace)); |
41 | 42 |
| 43 METHODDEF(void) quantize (JCOEFPTR, DCTELEM *, DCTELEM *); |
| 44 |
42 typedef struct { | 45 typedef struct { |
43 struct jpeg_forward_dct pub; /* public fields */ | 46 struct jpeg_forward_dct pub; /* public fields */ |
44 | 47 |
45 /* Pointer to the DCT routine actually in use */ | 48 /* Pointer to the DCT routine actually in use */ |
46 forward_DCT_method_ptr dct; | 49 forward_DCT_method_ptr dct; |
47 convsamp_method_ptr convsamp; | 50 convsamp_method_ptr convsamp; |
48 quantize_method_ptr quantize; | 51 quantize_method_ptr quantize; |
49 | 52 |
50 /* The actual post-DCT divisors --- not identical to the quant table | 53 /* The actual post-DCT divisors --- not identical to the quant table |
51 * entries, because of scaling (especially for an unnormalized DCT). | 54 * entries, because of scaling (especially for an unnormalized DCT). |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 * isn't member wise (e.g. MMX). | 156 * isn't member wise (e.g. MMX). |
154 * | 157 * |
155 * The reason dctbl[2] and dctbl[3] reduce the shift with (word size) | 158 * The reason dctbl[2] and dctbl[3] reduce the shift with (word size) |
156 * is that most SIMD implementations have a "multiply and store top | 159 * is that most SIMD implementations have a "multiply and store top |
157 * half" operation. | 160 * half" operation. |
158 * | 161 * |
159 * Lastly, we store each of the values in their own table instead | 162 * Lastly, we store each of the values in their own table instead |
160 * of in a consecutive manner, yet again in order to allow SIMD | 163 * of in a consecutive manner, yet again in order to allow SIMD |
161 * routines. | 164 * routines. |
162 */ | 165 */ |
163 LOCAL(void) | 166 LOCAL(int) |
164 compute_reciprocal (UINT16 divisor, DCTELEM * dtbl) | 167 compute_reciprocal (UINT16 divisor, DCTELEM * dtbl) |
165 { | 168 { |
166 UDCTELEM2 fq, fr; | 169 UDCTELEM2 fq, fr; |
167 UDCTELEM c; | 170 UDCTELEM c; |
168 int b, r; | 171 int b, r; |
169 | 172 |
170 b = flss(divisor) - 1; | 173 b = flss(divisor) - 1; |
171 r = sizeof(DCTELEM) * 8 + b; | 174 r = sizeof(DCTELEM) * 8 + b; |
172 | 175 |
173 fq = ((UDCTELEM2)1 << r) / divisor; | 176 fq = ((UDCTELEM2)1 << r) / divisor; |
174 fr = ((UDCTELEM2)1 << r) % divisor; | 177 fr = ((UDCTELEM2)1 << r) % divisor; |
175 | 178 |
176 c = divisor / 2; /* for rounding */ | 179 c = divisor / 2; /* for rounding */ |
177 | 180 |
178 if (fr == 0) { /* divisor is power of two */ | 181 if (fr == 0) { /* divisor is power of two */ |
179 /* fq will be one bit too large to fit in DCTELEM, so adjust */ | 182 /* fq will be one bit too large to fit in DCTELEM, so adjust */ |
180 fq >>= 1; | 183 fq >>= 1; |
181 r--; | 184 r--; |
182 } else if (fr <= (divisor / 2)) { /* fractional part is < 0.5 */ | 185 } else if (fr <= (divisor / 2)) { /* fractional part is < 0.5 */ |
183 c++; | 186 c++; |
184 } else { /* fractional part is > 0.5 */ | 187 } else { /* fractional part is > 0.5 */ |
185 fq++; | 188 fq++; |
186 } | 189 } |
187 | 190 |
188 dtbl[DCTSIZE2 * 0] = (DCTELEM) fq; /* reciprocal */ | 191 dtbl[DCTSIZE2 * 0] = (DCTELEM) fq; /* reciprocal */ |
189 dtbl[DCTSIZE2 * 1] = (DCTELEM) c; /* correction + roundfactor */ | 192 dtbl[DCTSIZE2 * 1] = (DCTELEM) c; /* correction + roundfactor */ |
190 dtbl[DCTSIZE2 * 2] = (DCTELEM) (1 << (sizeof(DCTELEM)*8*2 - r)); /* scale */ | 193 dtbl[DCTSIZE2 * 2] = (DCTELEM) (1 << (sizeof(DCTELEM)*8*2 - r)); /* scale */ |
191 dtbl[DCTSIZE2 * 3] = (DCTELEM) r - sizeof(DCTELEM)*8; /* shift */ | 194 dtbl[DCTSIZE2 * 3] = (DCTELEM) r - sizeof(DCTELEM)*8; /* shift */ |
| 195 |
| 196 if(r <= 16) return 0; |
| 197 else return 1; |
192 } | 198 } |
193 | 199 |
194 /* | 200 /* |
195 * Initialize for a processing pass. | 201 * Initialize for a processing pass. |
196 * Verify that all referenced Q-tables are present, and set up | 202 * Verify that all referenced Q-tables are present, and set up |
197 * the divisor table for each one. | 203 * the divisor table for each one. |
198 * In the current implementation, DCT of all components is done during | 204 * In the current implementation, DCT of all components is done during |
199 * the first pass, even if only some components will be output in the | 205 * the first pass, even if only some components will be output in the |
200 * first scan. Hence all components should be examined here. | 206 * first scan. Hence all components should be examined here. |
201 */ | 207 */ |
(...skipping 23 matching lines...) Expand all Loading... |
225 /* For LL&M IDCT method, divisors are equal to raw quantization | 231 /* For LL&M IDCT method, divisors are equal to raw quantization |
226 * coefficients multiplied by 8 (to counteract scaling). | 232 * coefficients multiplied by 8 (to counteract scaling). |
227 */ | 233 */ |
228 if (fdct->divisors[qtblno] == NULL) { | 234 if (fdct->divisors[qtblno] == NULL) { |
229 fdct->divisors[qtblno] = (DCTELEM *) | 235 fdct->divisors[qtblno] = (DCTELEM *) |
230 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 236 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
231 (DCTSIZE2 * 4) * SIZEOF(DCTELEM)); | 237 (DCTSIZE2 * 4) * SIZEOF(DCTELEM)); |
232 } | 238 } |
233 dtbl = fdct->divisors[qtblno]; | 239 dtbl = fdct->divisors[qtblno]; |
234 for (i = 0; i < DCTSIZE2; i++) { | 240 for (i = 0; i < DCTSIZE2; i++) { |
235 » compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]); | 241 » if(!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]) |
| 242 » && fdct->quantize == jsimd_quantize) |
| 243 » fdct->quantize = quantize; |
236 } | 244 } |
237 break; | 245 break; |
238 #endif | 246 #endif |
239 #ifdef DCT_IFAST_SUPPORTED | 247 #ifdef DCT_IFAST_SUPPORTED |
240 case JDCT_IFAST: | 248 case JDCT_IFAST: |
241 { | 249 { |
242 /* For AA&N IDCT method, divisors are equal to quantization | 250 /* For AA&N IDCT method, divisors are equal to quantization |
243 * coefficients scaled by scalefactor[row]*scalefactor[col], where | 251 * coefficients scaled by scalefactor[row]*scalefactor[col], where |
244 * scalefactor[0] = 1 | 252 * scalefactor[0] = 1 |
245 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 | 253 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 |
(...skipping 13 matching lines...) Expand all Loading... |
259 }; | 267 }; |
260 SHIFT_TEMPS | 268 SHIFT_TEMPS |
261 | 269 |
262 if (fdct->divisors[qtblno] == NULL) { | 270 if (fdct->divisors[qtblno] == NULL) { |
263 fdct->divisors[qtblno] = (DCTELEM *) | 271 fdct->divisors[qtblno] = (DCTELEM *) |
264 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 272 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
265 (DCTSIZE2 * 4) * SIZEOF(DCTELEM)); | 273 (DCTSIZE2 * 4) * SIZEOF(DCTELEM)); |
266 } | 274 } |
267 dtbl = fdct->divisors[qtblno]; | 275 dtbl = fdct->divisors[qtblno]; |
268 for (i = 0; i < DCTSIZE2; i++) { | 276 for (i = 0; i < DCTSIZE2; i++) { |
269 » compute_reciprocal( | 277 » if(!compute_reciprocal( |
270 DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], | 278 DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], |
271 (INT32) aanscales[i]), | 279 (INT32) aanscales[i]), |
272 » » CONST_BITS-3), &dtbl[i]); | 280 » » CONST_BITS-3), &dtbl[i]) |
| 281 » && fdct->quantize == jsimd_quantize) |
| 282 » fdct->quantize = quantize; |
273 } | 283 } |
274 } | 284 } |
275 break; | 285 break; |
276 #endif | 286 #endif |
277 #ifdef DCT_FLOAT_SUPPORTED | 287 #ifdef DCT_FLOAT_SUPPORTED |
278 case JDCT_FLOAT: | 288 case JDCT_FLOAT: |
279 { | 289 { |
280 /* For float AA&N IDCT method, divisors are equal to quantization | 290 /* For float AA&N IDCT method, divisors are equal to quantization |
281 * coefficients scaled by scalefactor[row]*scalefactor[col], where | 291 * coefficients scaled by scalefactor[row]*scalefactor[col], where |
282 * scalefactor[0] = 1 | 292 * scalefactor[0] = 1 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 SIZEOF(DCTELEM) * DCTSIZE2); | 633 SIZEOF(DCTELEM) * DCTSIZE2); |
624 | 634 |
625 /* Mark divisor tables unallocated */ | 635 /* Mark divisor tables unallocated */ |
626 for (i = 0; i < NUM_QUANT_TBLS; i++) { | 636 for (i = 0; i < NUM_QUANT_TBLS; i++) { |
627 fdct->divisors[i] = NULL; | 637 fdct->divisors[i] = NULL; |
628 #ifdef DCT_FLOAT_SUPPORTED | 638 #ifdef DCT_FLOAT_SUPPORTED |
629 fdct->float_divisors[i] = NULL; | 639 fdct->float_divisors[i] = NULL; |
630 #endif | 640 #endif |
631 } | 641 } |
632 } | 642 } |
OLD | NEW |