13 #define JPEG_INTERNALS
24 const unsigned int *basic_table,
25 int scale_factor,
boolean force_baseline)
38 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
44 temp = ((long) basic_table[i] * scale_factor + 50
L) / 100
L;
46 if (temp <= 0
L) temp = 1
L;
47 if (temp > 32767
L) temp = 32767
L;
48 if (force_baseline && temp > 255
L)
50 (*qtblptr)->quantval[
i] = (
UINT16) temp;
54 (*qtblptr)->sent_table =
FALSE;
60 boolean force_baseline)
72 static const unsigned int std_luminance_quant_tbl[
DCTSIZE2] = {
73 16, 11, 12, 14, 12, 10, 16, 14,
74 13, 14, 18, 17, 16, 19, 24, 40,
75 26, 24, 22, 22, 24, 49, 35, 37,
76 29, 40, 58, 51, 61, 60, 57, 51,
77 56, 55, 64, 72, 92, 78, 64, 68,
78 87, 69, 55, 56, 80, 109, 81, 87,
79 95, 98, 103, 104, 103, 62, 77, 113,
80 121, 112, 100, 120, 92, 101, 103, 99
82 static const unsigned int std_chrominance_quant_tbl[
DCTSIZE2] = {
83 17, 18, 18, 24, 21, 24, 47, 26,
84 26, 47, 99, 66, 56, 66, 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 99, 99, 99, 99, 99, 99, 99, 99,
89 99, 99, 99, 99, 99, 99, 99, 99,
90 99, 99, 99, 99, 99, 99, 99, 99
95 scale_factor, force_baseline);
97 scale_factor, force_baseline);
109 if (quality <= 0) quality = 1;
110 if (quality > 100) quality = 100;
119 quality = 5000 / quality;
121 quality = 200 - quality*2;
152 if (*htblptr ==
NULL)
156 MEMCOPY((*htblptr)->huffval, val,
SIZEOF((*htblptr)->huffval));
159 (*htblptr)->sent_table =
FALSE;
168 static const UINT8 bits_dc_luminance[17] =
169 { 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
170 static const UINT8 val_dc_luminance[] =
171 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
173 static const UINT8 bits_dc_chrominance[17] =
174 { 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
175 static const UINT8 val_dc_chrominance[] =
176 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
178 static const UINT8 bits_ac_luminance[17] =
179 { 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
180 static const UINT8 val_ac_luminance[] =
181 { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
182 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
183 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
184 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
185 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
186 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
187 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
188 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
189 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
190 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
191 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
192 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
193 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
194 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
195 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
196 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
197 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
198 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
199 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
200 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
203 static const UINT8 bits_ac_chrominance[17] =
204 { 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
205 static const UINT8 val_ac_chrominance[] =
206 { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
207 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
208 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
209 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
210 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
211 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
212 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
213 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
214 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
215 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
216 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
217 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
218 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
219 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
220 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
221 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
222 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
223 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
224 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
225 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
229 bits_dc_luminance, val_dc_luminance);
231 bits_ac_luminance, val_ac_luminance);
233 bits_dc_chrominance, val_dc_chrominance);
235 bits_ac_chrominance, val_ac_chrominance);
256 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
355 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
370 #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
371 (compptr = &cinfo->comp_info[index], \
372 compptr->component_id = (id), \
373 compptr->h_samp_factor = (hsamp), \
374 compptr->v_samp_factor = (vsamp), \
375 compptr->quant_tbl_no = (quant), \
376 compptr->dc_tbl_no = (dctbl), \
377 compptr->ac_tbl_no = (actbl) )
381 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
392 switch (colorspace) {
441 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
446 #ifdef C_PROGRESSIVE_SUPPORTED
450 int Ss,
int Se,
int Ah,
int Al)
465 int Ss,
int Se,
int Ah,
int Al)
470 for (ci = 0; ci < ncomps; ci++) {
491 for (ci = 0; ci < ncomps; ci++)
493 scanptr->
Ss = scanptr->
Se = 0;
499 scanptr =
fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
519 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
530 nscans = 2 + 4 * ncomps;
565 scanptr =
fill_scans(scanptr, ncomps, 1, 5, 0, 2);
566 scanptr =
fill_scans(scanptr, ncomps, 6, 63, 0, 2);
568 scanptr =
fill_scans(scanptr, ncomps, 1, 63, 2, 1);
571 scanptr =
fill_scans(scanptr, ncomps, 1, 63, 1, 0);
boolean write_Adobe_marker
LOCAL void std_huff_tables(j_compress_ptr cinfo)
UINT8 arith_ac_K[NUM_ARITH_TBLS]
JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]
J_COLOR_SPACE jpeg_color_space
struct jpeg_common_struct * j_common_ptr
LOCAL jpeg_scan_info * fill_a_scan(jpeg_scan_info *scanptr, int ci, int Ss, int Se, int Ah, int Al)
const jpeg_scan_info * scan_info
GLOBAL JHUFF_TBL * jpeg_alloc_huff_table(j_common_ptr cinfo)
#define ERREXIT(cinfo, code)
JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]
GLOBAL void jpeg_set_linear_quality(j_compress_ptr cinfo, int scale_factor, boolean force_baseline)
boolean write_JFIF_header
int component_index[MAX_COMPS_IN_SCAN]
J_COLOR_SPACE in_color_space
#define MEMCOPY(dest, src, size)
UINT8 arith_dc_U[NUM_ARITH_TBLS]
GLOBAL void jpeg_set_colorspace(j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
GLOBAL void jpeg_default_colorspace(j_compress_ptr cinfo)
GLOBAL void jpeg_set_quality(j_compress_ptr cinfo, int quality, boolean force_baseline)
unsigned int restart_interval
LOCAL jpeg_scan_info * fill_scans(jpeg_scan_info *scanptr, int ncomps, int Ss, int Se, int Ah, int Al)
#define ERREXIT1(cinfo, code, p1)
JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]
GLOBAL void jpeg_add_quant_table(j_compress_ptr cinfo, int which_tbl, const unsigned int *basic_table, int scale_factor, boolean force_baseline)
GLOBAL int jpeg_quality_scaling(int quality)
LOCAL void add_huff_table(j_compress_ptr cinfo, JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
UINT8 arith_dc_L[NUM_ARITH_TBLS]
GLOBAL JQUANT_TBL * jpeg_alloc_quant_table(j_common_ptr cinfo)
GLOBAL void jpeg_set_defaults(j_compress_ptr cinfo)
#define ERREXIT2(cinfo, code, p1, p2)
#define SET_COMP(index, id, hsamp, vsamp, quant, dctbl, actbl)
LOCAL jpeg_scan_info * fill_dc_scans(jpeg_scan_info *scanptr, int ncomps, int Ah, int Al)
GLOBAL void jpeg_simple_progression(j_compress_ptr cinfo)
#define MAX_COMPS_IN_SCAN
jpeg_component_info * comp_info