0N/A * reserved comment block 0N/A * DO NOT REMOVE OR ALTER! 0N/A * Copyright (C) 1991-1998, Thomas G. Lane. 0N/A * This file is part of the Independent JPEG Group's software. 0N/A * For conditions of distribution and use, see the accompanying README file. 0N/A * This file contains optional default-setting code for the JPEG compressor. 0N/A * Applications do not have to use this file, but those that don't use it 0N/A * must know a lot more about the innards of the JPEG code. 0N/A * Quantization table setup routines 0N/A/* Define a quantization table equal to the basic_table times 0N/A * a scale factor (given as a percentage). 0N/A * If force_baseline is TRUE, the computed quantization table entries 0N/A * are limited to 1..255 for JPEG baseline compatibility. 0N/A /* Safety check to ensure start_compress not called yet. */ 0N/A /* limit the values to the valid range */ 0N/A if (
temp >
32767L)
temp =
32767L;
/* max quantizer needed for 12 bits */ 0N/A temp =
255L;
/* limit to baseline range if requested */ 0N/A /* Initialize sent_table FALSE so table will be written to JPEG file. */ 0N/A/* Set or change the 'quality' (quantization) setting, using default tables 0N/A * and a straight percentage-scaling quality scale. In most cases it's better 0N/A * to use jpeg_set_quality (below); this entry point is provided for 0N/A * applications that insist on a linear percentage scaling. 0N/A /* These are the sample quantization tables given in JPEG spec section K.1. 0N/A * The spec says that the values given produce "good" quality, and 0N/A * when divided by 2, "very good" quality. 0N/A 16,
11,
10,
16,
24,
40,
51,
61,
0N/A 12,
12,
14,
19,
26,
58,
60,
55,
0N/A 14,
13,
16,
24,
40,
57,
69,
56,
0N/A 14,
17,
22,
29,
51,
87,
80,
62,
0N/A 18,
22,
37,
56,
68,
109,
103,
77,
0N/A 24,
35,
55,
64,
81,
104,
113,
92,
0N/A 49,
64,
78,
87,
103,
121,
120,
101,
0N/A 72,
92,
95,
98,
112,
100,
103,
99 0N/A 17,
18,
24,
47,
99,
99,
99,
99,
0N/A 18,
21,
26,
66,
99,
99,
99,
99,
0N/A 24,
26,
56,
99,
99,
99,
99,
99,
0N/A 47,
66,
99,
99,
99,
99,
99,
99,
0N/A 99,
99,
99,
99,
99,
99,
99,
99,
0N/A 99,
99,
99,
99,
99,
99,
99,
99,
0N/A 99,
99,
99,
99,
99,
99,
99,
99,
0N/A 99,
99,
99,
99,
99,
99,
99,
99 0N/A /* Set up two quantization tables using the specified scaling */ 0N/A/* Convert a user-specified quality rating to a percentage scaling factor 0N/A * for an underlying quantization table, using our recommended scaling curve. 0N/A * The input 'quality' factor should be 0 (terrible) to 100 (very good). 0N/A /* Safety limit on quality factor. Convert 0 to 1 to avoid zero divide. */ 0N/A /* The basic table is used as-is (scaling 100) for a quality of 50. 0N/A * Qualities 50..100 are converted to scaling percentage 200 - 2*Q; 0N/A * note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table 0N/A * to make all the table entries 1 (hence, minimum quantization loss). 0N/A * Qualities 1..50 are converted to scaling percentage 5000/Q. 0N/A/* Set or change the 'quality' (quantization) setting, using default tables. 0N/A * This is the standard quality-adjusting entry point for typical user 0N/A * interfaces; only those who want detailed control over quantization tables 0N/A * would use the preceding three routines directly. 0N/A /* Convert user 0-100 rating to percentage scaling */ 0N/A /* Set up standard quality tables */ 0N/A * Huffman table setup routines 0N/A/* Define a Huffman table */ 0N/A /* Copy the number-of-symbols-of-each-code-length counts */ 0N/A /* Validate the counts. We do this here mainly so we can copy the right 0N/A * number of symbols from the val[] array, without risking marching off 0N/A * the end of memory. jchuff.c will do a more thorough test later. 0N/A /* Initialize sent_table FALSE so table will be written to JPEG file. */ 0N/A/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */ 0N/A/* IMPORTANT: these are only valid for 8-bit data precision! */ 0N/A {
/* 0-base */ 0, 0,
1,
5,
1,
1,
1,
1,
1,
1, 0, 0, 0, 0, 0, 0, 0 };
0N/A { 0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11 };
0N/A {
/* 0-base */ 0, 0,
3,
1,
1,
1,
1,
1,
1,
1,
1,
1, 0, 0, 0, 0, 0 };
0N/A { 0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11 };
0N/A {
/* 0-base */ 0, 0,
2,
1,
3,
3,
2,
4,
3,
5,
5,
4,
4, 0, 0,
1,
0x7d };
0N/A {
0x01,
0x02,
0x03,
0x00,
0x04,
0x11,
0x05,
0x12,
0N/A 0x21,
0x31,
0x41,
0x06,
0x13,
0x51,
0x61,
0x07,
0N/A 0x22,
0x71,
0x14,
0x32,
0x81,
0x91,
0xa1,
0x08,
0N/A 0x23,
0x42,
0xb1,
0xc1,
0x15,
0x52,
0xd1,
0xf0,
0N/A 0x24,
0x33,
0x62,
0x72,
0x82,
0x09,
0x0a,
0x16,
0N/A 0x17,
0x18,
0x19,
0x1a,
0x25,
0x26,
0x27,
0x28,
0N/A 0x29,
0x2a,
0x34,
0x35,
0x36,
0x37,
0x38,
0x39,
0N/A 0x3a,
0x43,
0x44,
0x45,
0x46,
0x47,
0x48,
0x49,
0N/A 0x4a,
0x53,
0x54,
0x55,
0x56,
0x57,
0x58,
0x59,
0N/A 0x5a,
0x63,
0x64,
0x65,
0x66,
0x67,
0x68,
0x69,
0N/A 0x6a,
0x73,
0x74,
0x75,
0x76,
0x77,
0x78,
0x79,
0N/A 0x7a,
0x83,
0x84,
0x85,
0x86,
0x87,
0x88,
0x89,
0N/A 0x8a,
0x92,
0x93,
0x94,
0x95,
0x96,
0x97,
0x98,
0N/A 0x99,
0x9a,
0xa2,
0xa3,
0xa4,
0xa5,
0xa6,
0xa7,
0N/A 0xa8,
0xa9,
0xaa,
0xb2,
0xb3,
0xb4,
0xb5,
0xb6,
0N/A 0xb7,
0xb8,
0xb9,
0xba,
0xc2,
0xc3,
0xc4,
0xc5,
0N/A 0xc6,
0xc7,
0xc8,
0xc9,
0xca,
0xd2,
0xd3,
0xd4,
0N/A 0xd5,
0xd6,
0xd7,
0xd8,
0xd9,
0xda,
0xe1,
0xe2,
0N/A 0xe3,
0xe4,
0xe5,
0xe6,
0xe7,
0xe8,
0xe9,
0xea,
0N/A 0xf1,
0xf2,
0xf3,
0xf4,
0xf5,
0xf6,
0xf7,
0xf8,
0N/A {
/* 0-base */ 0, 0,
2,
1,
2,
4,
4,
3,
4,
7,
5,
4,
4, 0,
1,
2,
0x77 };
0N/A {
0x00,
0x01,
0x02,
0x03,
0x11,
0x04,
0x05,
0x21,
0N/A 0x31,
0x06,
0x12,
0x41,
0x51,
0x07,
0x61,
0x71,
0N/A 0x13,
0x22,
0x32,
0x81,
0x08,
0x14,
0x42,
0x91,
0N/A 0xa1,
0xb1,
0xc1,
0x09,
0x23,
0x33,
0x52,
0xf0,
0N/A 0x15,
0x62,
0x72,
0xd1,
0x0a,
0x16,
0x24,
0x34,
0N/A 0xe1,
0x25,
0xf1,
0x17,
0x18,
0x19,
0x1a,
0x26,
0N/A 0x27,
0x28,
0x29,
0x2a,
0x35,
0x36,
0x37,
0x38,
0N/A 0x39,
0x3a,
0x43,
0x44,
0x45,
0x46,
0x47,
0x48,
0N/A 0x49,
0x4a,
0x53,
0x54,
0x55,
0x56,
0x57,
0x58,
0N/A 0x59,
0x5a,
0x63,
0x64,
0x65,
0x66,
0x67,
0x68,
0N/A 0x69,
0x6a,
0x73,
0x74,
0x75,
0x76,
0x77,
0x78,
0N/A 0x79,
0x7a,
0x82,
0x83,
0x84,
0x85,
0x86,
0x87,
0N/A 0x88,
0x89,
0x8a,
0x92,
0x93,
0x94,
0x95,
0x96,
0N/A 0x97,
0x98,
0x99,
0x9a,
0xa2,
0xa3,
0xa4,
0xa5,
0N/A 0xa6,
0xa7,
0xa8,
0xa9,
0xaa,
0xb2,
0xb3,
0xb4,
0N/A 0xb5,
0xb6,
0xb7,
0xb8,
0xb9,
0xba,
0xc2,
0xc3,
0N/A 0xc4,
0xc5,
0xc6,
0xc7,
0xc8,
0xc9,
0xca,
0xd2,
0N/A 0xd3,
0xd4,
0xd5,
0xd6,
0xd7,
0xd8,
0xd9,
0xda,
0N/A 0xe2,
0xe3,
0xe4,
0xe5,
0xe6,
0xe7,
0xe8,
0xe9,
0N/A 0xea,
0xf2,
0xf3,
0xf4,
0xf5,
0xf6,
0xf7,
0xf8,
0N/A * Default parameter setup for compression. 0N/A * Applications that don't choose to use this routine must do their 0N/A * own setup of all these parameters. Alternately, you can call this 0N/A * to establish defaults and then alter parameters selectively. This 0N/A * is the recommended approach since, if we add any new parameters, 0N/A * your code will still work (they'll be set to reasonable defaults). 0N/A /* Safety check to ensure start_compress not called yet. */ 0N/A /* Allocate comp_info array large enough for maximum component count. 0N/A * Array is made permanent in case application wants to compress 0N/A * multiple images at same param settings. 0N/A /* Initialize everything not dependent on the color space */ 0N/A /* Set up two quantization tables using default quality of 75 */ 0N/A /* Set up two Huffman tables */ 0N/A /* Initialize default arithmetic coding conditioning */ 0N/A /* Default is no multiple-scan output */ 0N/A /* Expect normal source image, not raw downsampled data */ 0N/A /* Use Huffman coding, not arithmetic coding, by default */ 0N/A /* By default, don't do extra passes to optimize entropy coding */ 0N/A /* The standard Huffman tables are only valid for 8-bit data precision. 0N/A * If the precision is higher, force optimization on so that usable 0N/A * tables will be computed. This test can be removed if default tables 0N/A * are supplied that are valid for the desired precision. 0N/A /* By default, use the simpler non-cosited sampling alignment */ 0N/A /* No input smoothing */ 0N/A /* DCT algorithm preference */ 0N/A /* No restart markers */ 0N/A /* Fill in default JFIF marker parameters. Note that whether the marker 0N/A * will actually be written is determined by jpeg_set_colorspace. 0N/A * By default, the library emits JFIF version code 1.01. 0N/A * An application that wants to emit JFIF 1.02 extension markers should set 0N/A * JFIF_minor_version to 2. We could probably get away with just defaulting 0N/A * to 1.02, but there may still be some decoders in use that will complain 0N/A * about that; saying 1.01 should minimize compatibility problems. 0N/A /* Choose JPEG colorspace based on input space, set defaults accordingly */ 0N/A * Select an appropriate JPEG colorspace for in_color_space. 0N/A * Set the JPEG colorspace, and choose colorspace-dependent default values. 0N/A /* Safety check to ensure start_compress not called yet. */ 0N/A /* For all colorspaces, we use Q and Huff tables 0 for luminance components, 0N/A * tables 1 for chrominance components. 0N/A /* JFIF specifies component ID 1 */ 0N/A /* JFIF specifies component IDs 1,2,3 */ 0N/A /* We default to 2x2 subsamples of chrominance */ 0N/A/* Support routine: generate one scan for specified component */ 0N/A/* Support routine: generate one scan for each component */ 0N/A/* Support routine: generate interleaved DC scan if possible, else N scans */ 0N/A /* Single interleaved DC scan */ 0N/A /* Noninterleaved DC scan for each component */ 0N/A * Create a recommended progressive-JPEG script. 0N/A * cinfo->num_components and cinfo->jpeg_color_space must be correct. 0N/A /* Safety check to ensure start_compress not called yet. */ 0N/A /* Figure space needed for script. Calculation must match code below! */ 0N/A /* Custom script for YCbCr color images. */ 0N/A /* All-purpose script for other color spaces. */ 0N/A /* Allocate space for script. 0N/A * We need to put it in the permanent pool in case the application performs 0N/A * multiple compressions without changing the settings. To avoid a memory 0N/A * leak if jpeg_simple_progression is called repeatedly for the same JPEG 0N/A * object, we try to re-use previously allocated space, and we allocate 0N/A * enough space to handle YCbCr even if initially asked for grayscale. 0N/A /* Custom script for YCbCr color images. */ 0N/A /* Initial DC scan */ 0N/A /* Initial AC scan: get some luma data out in a hurry */ 0N/A /* Chroma data is too small to be worth expending many scans on */ 0N/A /* Complete spectral selection for luma AC */ 0N/A /* Refine next bit of luma AC */ 0N/A /* Finish DC successive approximation */ 0N/A /* Finish AC successive approximation */ 0N/A /* Luma bottom bit comes last since it's usually largest scan */ 0N/A /* All-purpose script for other color spaces. */ 0N/A /* Successive approximation first pass */ 0N/A /* Successive approximation second pass */ 0N/A /* Successive approximation final pass */ 0N/A#
endif /* C_PROGRESSIVE_SUPPORTED */