OLD | NEW |
1 /* | 1 /* |
2 * jcparam.c | 2 * jcparam.c |
3 * | 3 * |
4 * Copyright (C) 1991-1998, Thomas G. Lane. | 4 * Copyright (C) 1991-1998, Thomas G. Lane. |
5 * Copyright (C) 2009, D. R. Commander. | 5 * Modified 2003-2008 by Guido Vollbeding. |
| 6 * Copyright (C) 2009-2010, D. R. Commander. |
6 * This file is part of the Independent JPEG Group's software. | 7 * This file is part of the Independent JPEG Group's software. |
7 * For conditions of distribution and use, see the accompanying README file. | 8 * For conditions of distribution and use, see the accompanying README file. |
8 * | 9 * |
9 * This file contains optional default-setting code for the JPEG compressor. | 10 * This file contains optional default-setting code for the JPEG compressor. |
10 * Applications do not have to use this file, but those that don't use it | 11 * Applications do not have to use this file, but those that don't use it |
11 * must know a lot more about the innards of the JPEG code. | 12 * must know a lot more about the innards of the JPEG code. |
12 */ | 13 */ |
13 | 14 |
14 #define JPEG_INTERNALS | 15 #define JPEG_INTERNALS |
15 #include "jinclude.h" | 16 #include "jinclude.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 if (force_baseline && temp > 255L) | 55 if (force_baseline && temp > 255L) |
55 temp = 255L; /* limit to baseline range if requested */ | 56 temp = 255L; /* limit to baseline range if requested */ |
56 (*qtblptr)->quantval[i] = (UINT16) temp; | 57 (*qtblptr)->quantval[i] = (UINT16) temp; |
57 } | 58 } |
58 | 59 |
59 /* Initialize sent_table FALSE so table will be written to JPEG file. */ | 60 /* Initialize sent_table FALSE so table will be written to JPEG file. */ |
60 (*qtblptr)->sent_table = FALSE; | 61 (*qtblptr)->sent_table = FALSE; |
61 } | 62 } |
62 | 63 |
63 | 64 |
| 65 /* These are the sample quantization tables given in JPEG spec section K.1. |
| 66 * The spec says that the values given produce "good" quality, and |
| 67 * when divided by 2, "very good" quality. |
| 68 */ |
| 69 static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = { |
| 70 16, 11, 10, 16, 24, 40, 51, 61, |
| 71 12, 12, 14, 19, 26, 58, 60, 55, |
| 72 14, 13, 16, 24, 40, 57, 69, 56, |
| 73 14, 17, 22, 29, 51, 87, 80, 62, |
| 74 18, 22, 37, 56, 68, 109, 103, 77, |
| 75 24, 35, 55, 64, 81, 104, 113, 92, |
| 76 49, 64, 78, 87, 103, 121, 120, 101, |
| 77 72, 92, 95, 98, 112, 100, 103, 99 |
| 78 }; |
| 79 static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = { |
| 80 17, 18, 24, 47, 99, 99, 99, 99, |
| 81 18, 21, 26, 66, 99, 99, 99, 99, |
| 82 24, 26, 56, 99, 99, 99, 99, 99, |
| 83 47, 66, 99, 99, 99, 99, 99, 99, |
| 84 99, 99, 99, 99, 99, 99, 99, 99, |
| 85 99, 99, 99, 99, 99, 99, 99, 99, |
| 86 99, 99, 99, 99, 99, 99, 99, 99, |
| 87 99, 99, 99, 99, 99, 99, 99, 99 |
| 88 }; |
| 89 |
| 90 |
| 91 #if JPEG_LIB_VERSION >= 70 |
| 92 GLOBAL(void) |
| 93 jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline) |
| 94 /* Set or change the 'quality' (quantization) setting, using default tables |
| 95 * and straight percentage-scaling quality scales. |
| 96 * This entry point allows different scalings for luminance and chrominance. |
| 97 */ |
| 98 { |
| 99 /* Set up two quantization tables using the specified scaling */ |
| 100 jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, |
| 101 cinfo->q_scale_factor[0], force_baseline); |
| 102 jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, |
| 103 cinfo->q_scale_factor[1], force_baseline); |
| 104 } |
| 105 #endif |
| 106 |
| 107 |
64 GLOBAL(void) | 108 GLOBAL(void) |
65 jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, | 109 jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, |
66 boolean force_baseline) | 110 boolean force_baseline) |
67 /* Set or change the 'quality' (quantization) setting, using default tables | 111 /* Set or change the 'quality' (quantization) setting, using default tables |
68 * and a straight percentage-scaling quality scale. In most cases it's better | 112 * and a straight percentage-scaling quality scale. In most cases it's better |
69 * to use jpeg_set_quality (below); this entry point is provided for | 113 * to use jpeg_set_quality (below); this entry point is provided for |
70 * applications that insist on a linear percentage scaling. | 114 * applications that insist on a linear percentage scaling. |
71 */ | 115 */ |
72 { | 116 { |
73 /* These are the sample quantization tables given in JPEG spec section K.1. | |
74 * The spec says that the values given produce "good" quality, and | |
75 * when divided by 2, "very good" quality. | |
76 */ | |
77 static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = { | |
78 16, 11, 10, 16, 24, 40, 51, 61, | |
79 12, 12, 14, 19, 26, 58, 60, 55, | |
80 14, 13, 16, 24, 40, 57, 69, 56, | |
81 14, 17, 22, 29, 51, 87, 80, 62, | |
82 18, 22, 37, 56, 68, 109, 103, 77, | |
83 24, 35, 55, 64, 81, 104, 113, 92, | |
84 49, 64, 78, 87, 103, 121, 120, 101, | |
85 72, 92, 95, 98, 112, 100, 103, 99 | |
86 }; | |
87 static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = { | |
88 17, 18, 24, 47, 99, 99, 99, 99, | |
89 18, 21, 26, 66, 99, 99, 99, 99, | |
90 24, 26, 56, 99, 99, 99, 99, 99, | |
91 47, 66, 99, 99, 99, 99, 99, 99, | |
92 99, 99, 99, 99, 99, 99, 99, 99, | |
93 99, 99, 99, 99, 99, 99, 99, 99, | |
94 99, 99, 99, 99, 99, 99, 99, 99, | |
95 99, 99, 99, 99, 99, 99, 99, 99 | |
96 }; | |
97 | |
98 /* Set up two quantization tables using the specified scaling */ | 117 /* Set up two quantization tables using the specified scaling */ |
99 jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, | 118 jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, |
100 scale_factor, force_baseline); | 119 scale_factor, force_baseline); |
101 jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, | 120 jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, |
102 scale_factor, force_baseline); | 121 scale_factor, force_baseline); |
103 } | 122 } |
104 | 123 |
105 | 124 |
106 GLOBAL(int) | 125 GLOBAL(int) |
107 jpeg_quality_scaling (int quality) | 126 jpeg_quality_scaling (int quality) |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 * Array is made permanent in case application wants to compress | 297 * Array is made permanent in case application wants to compress |
279 * multiple images at same param settings. | 298 * multiple images at same param settings. |
280 */ | 299 */ |
281 if (cinfo->comp_info == NULL) | 300 if (cinfo->comp_info == NULL) |
282 cinfo->comp_info = (jpeg_component_info *) | 301 cinfo->comp_info = (jpeg_component_info *) |
283 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, | 302 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, |
284 MAX_COMPONENTS * SIZEOF(jpeg_component_info)); | 303 MAX_COMPONENTS * SIZEOF(jpeg_component_info)); |
285 | 304 |
286 /* Initialize everything not dependent on the color space */ | 305 /* Initialize everything not dependent on the color space */ |
287 | 306 |
| 307 #if JPEG_LIB_VERSION >= 70 |
| 308 cinfo->scale_num = 1; /* 1:1 scaling */ |
| 309 cinfo->scale_denom = 1; |
| 310 #endif |
288 cinfo->data_precision = BITS_IN_JSAMPLE; | 311 cinfo->data_precision = BITS_IN_JSAMPLE; |
289 /* Set up two quantization tables using default quality of 75 */ | 312 /* Set up two quantization tables using default quality of 75 */ |
290 jpeg_set_quality(cinfo, 75, TRUE); | 313 jpeg_set_quality(cinfo, 75, TRUE); |
291 /* Set up two Huffman tables */ | 314 /* Set up two Huffman tables */ |
292 std_huff_tables(cinfo); | 315 std_huff_tables(cinfo); |
293 | 316 |
294 /* Initialize default arithmetic coding conditioning */ | 317 /* Initialize default arithmetic coding conditioning */ |
295 for (i = 0; i < NUM_ARITH_TBLS; i++) { | 318 for (i = 0; i < NUM_ARITH_TBLS; i++) { |
296 cinfo->arith_dc_L[i] = 0; | 319 cinfo->arith_dc_L[i] = 0; |
297 cinfo->arith_dc_U[i] = 1; | 320 cinfo->arith_dc_U[i] = 1; |
(...skipping 16 matching lines...) Expand all Loading... |
314 * If the precision is higher, force optimization on so that usable | 337 * If the precision is higher, force optimization on so that usable |
315 * tables will be computed. This test can be removed if default tables | 338 * tables will be computed. This test can be removed if default tables |
316 * are supplied that are valid for the desired precision. | 339 * are supplied that are valid for the desired precision. |
317 */ | 340 */ |
318 if (cinfo->data_precision > 8) | 341 if (cinfo->data_precision > 8) |
319 cinfo->optimize_coding = TRUE; | 342 cinfo->optimize_coding = TRUE; |
320 | 343 |
321 /* By default, use the simpler non-cosited sampling alignment */ | 344 /* By default, use the simpler non-cosited sampling alignment */ |
322 cinfo->CCIR601_sampling = FALSE; | 345 cinfo->CCIR601_sampling = FALSE; |
323 | 346 |
| 347 #if JPEG_LIB_VERSION >= 70 |
| 348 /* By default, apply fancy downsampling */ |
| 349 cinfo->do_fancy_downsampling = TRUE; |
| 350 #endif |
| 351 |
324 /* No input smoothing */ | 352 /* No input smoothing */ |
325 cinfo->smoothing_factor = 0; | 353 cinfo->smoothing_factor = 0; |
326 | 354 |
327 /* DCT algorithm preference */ | 355 /* DCT algorithm preference */ |
328 cinfo->dct_method = JDCT_DEFAULT; | 356 cinfo->dct_method = JDCT_DEFAULT; |
329 | 357 |
330 /* No restart markers */ | 358 /* No restart markers */ |
331 cinfo->restart_interval = 0; | 359 cinfo->restart_interval = 0; |
332 cinfo->restart_in_rows = 0; | 360 cinfo->restart_in_rows = 0; |
333 | 361 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2); | 636 scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2); |
609 /* Successive approximation second pass */ | 637 /* Successive approximation second pass */ |
610 scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1); | 638 scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1); |
611 /* Successive approximation final pass */ | 639 /* Successive approximation final pass */ |
612 scanptr = fill_dc_scans(scanptr, ncomps, 1, 0); | 640 scanptr = fill_dc_scans(scanptr, ncomps, 1, 0); |
613 scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0); | 641 scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0); |
614 } | 642 } |
615 } | 643 } |
616 | 644 |
617 #endif /* C_PROGRESSIVE_SUPPORTED */ | 645 #endif /* C_PROGRESSIVE_SUPPORTED */ |
OLD | NEW |