10 #define JPEG_INTERNALS 20 j_compress_ptr cinfo,
int which_tbl, const
unsigned int* basic_table,
21 int scale_factor,
boolean force_baseline)
34 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
37 ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
39 qtblptr = &cinfo->quant_tbl_ptrs[which_tbl];
41 if (*qtblptr ==
nullptr)
46 temp = ((long)basic_table[i] * scale_factor + 50L) / 100L;
48 if (temp <= 0L) temp = 1L;
49 if (temp > 32767L) temp = 32767L;
50 if (force_baseline && temp > 255L)
52 (*qtblptr)->quantval[i] = (
UINT16)temp;
56 (*qtblptr)->sent_table =
FALSE;
72 static const unsigned int std_luminance_quant_tbl[
DCTSIZE2] = {
73 16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19, 26, 58, 60, 55,
74 14, 13, 16, 24, 40, 57, 69, 56, 14, 17, 22, 29, 51, 87, 80, 62,
75 18, 22, 37, 56, 68, 109, 103, 77, 24, 35, 55, 64, 81, 104, 113, 92,
76 49, 64, 78, 87, 103, 121, 120, 101, 72, 92, 95, 98, 112, 100, 103, 99};
77 static const unsigned int std_chrominance_quant_tbl[
DCTSIZE2] = {
78 17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99,
79 24, 26, 56, 99, 99, 99, 99, 99, 47, 66, 99, 99, 99, 99, 99, 99,
80 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
81 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99};
85 cinfo, 0, std_luminance_quant_tbl, scale_factor, force_baseline);
87 cinfo, 1, std_chrominance_quant_tbl, scale_factor, force_baseline);
98 if (quality <= 0) quality = 1;
99 if (quality > 100) quality = 100;
109 quality = 5000 / quality;
111 quality = 200 - quality * 2;
143 if (*htblptr ==
nullptr)
155 if (nsymbols < 1 || nsymbols > 256)
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
160 (*htblptr)->sent_table =
FALSE;
168 static const UINT8 bits_dc_luminance[17] = { 0,
185 static const UINT8 val_dc_luminance[] = {0, 1, 2, 3, 4, 5,
188 static const UINT8 bits_dc_chrominance[17] = { 0,
205 static const UINT8 val_dc_chrominance[] = {0, 1, 2, 3, 4, 5,
208 static const UINT8 bits_ac_luminance[17] = { 0,
225 static const UINT8 val_ac_luminance[] = {
226 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06,
227 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
228 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72,
229 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
230 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45,
231 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
232 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75,
233 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
234 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3,
235 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
236 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
237 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
238 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4,
239 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa};
241 static const UINT8 bits_ac_chrominance[17] = { 0,
258 static const UINT8 val_ac_chrominance[] = {
259 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41,
260 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
261 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1,
262 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
263 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44,
264 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
265 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74,
266 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
267 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a,
268 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
269 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
270 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
271 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4,
272 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa};
275 cinfo, &cinfo->dc_huff_tbl_ptrs[0], bits_dc_luminance,
278 cinfo, &cinfo->ac_huff_tbl_ptrs[0], bits_ac_luminance,
281 cinfo, &cinfo->dc_huff_tbl_ptrs[1], bits_dc_chrominance,
284 cinfo, &cinfo->ac_huff_tbl_ptrs[1], bits_ac_chrominance,
305 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
311 if (cinfo->comp_info ==
nullptr)
327 cinfo->arith_dc_L[i] = 0;
328 cinfo->arith_dc_U[i] = 1;
329 cinfo->arith_ac_K[i] = 5;
333 cinfo->scan_info =
nullptr;
334 cinfo->num_scans = 0;
337 cinfo->raw_data_in =
FALSE;
340 cinfo->arith_code =
FALSE;
343 cinfo->optimize_coding =
FALSE;
349 if (cinfo->data_precision > 8) cinfo->optimize_coding =
TRUE;
352 cinfo->CCIR601_sampling =
FALSE;
355 cinfo->smoothing_factor = 0;
361 cinfo->restart_interval = 0;
362 cinfo->restart_in_rows = 0;
373 cinfo->JFIF_major_version = 1;
374 cinfo->JFIF_minor_version = 1;
375 cinfo->density_unit = 0;
376 cinfo->X_density = 1;
377 cinfo->Y_density = 1;
391 switch (cinfo->in_color_space)
413 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
427 #define SET_COMP(index, id, hsamp, vsamp, quant, dctbl, actbl) \ 428 (compptr = &cinfo->comp_info[index], compptr->component_id = (id), \ 429 compptr->h_samp_factor = (hsamp), compptr->v_samp_factor = (vsamp), \ 430 compptr->quant_tbl_no = (quant), compptr->dc_tbl_no = (dctbl), \ 431 compptr->ac_tbl_no = (actbl)) 435 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
441 cinfo->jpeg_color_space = colorspace;
443 cinfo->write_JFIF_header =
FALSE;
444 cinfo->write_Adobe_marker =
FALSE;
449 cinfo->write_JFIF_header =
TRUE;
450 cinfo->num_components = 1;
455 cinfo->write_Adobe_marker =
457 cinfo->num_components = 3;
463 cinfo->write_JFIF_header =
TRUE;
464 cinfo->num_components = 3;
472 cinfo->write_Adobe_marker =
474 cinfo->num_components = 4;
481 cinfo->write_Adobe_marker =
483 cinfo->num_components = 4;
490 cinfo->num_components = cinfo->input_components;
491 if (cinfo->num_components < 1 ||
494 cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
496 for (ci = 0; ci < cinfo->num_components; ci++)
502 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
506 #ifdef C_PROGRESSIVE_SUPPORTED 512 scanptr->comps_in_scan = 1;
513 scanptr->component_index[0] = ci;
528 for (ci = 0; ci < ncomps; ci++)
530 scanptr->comps_in_scan = 1;
531 scanptr->component_index[0] = ci;
550 scanptr->comps_in_scan = ncomps;
551 for (ci = 0; ci < ncomps; ci++) scanptr->component_index[ci] = ci;
552 scanptr->Ss = scanptr->Se = 0;
560 scanptr =
fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
573 int ncomps = cinfo->num_components;
579 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
582 if (ncomps == 3 && cinfo->jpeg_color_space ==
JCS_YCbCr)
593 nscans = 2 + 4 * ncomps;
603 if (cinfo->script_space ==
nullptr || cinfo->script_space_size < nscans)
605 cinfo->script_space_size =
MAX(nscans, 10);
606 cinfo->script_space = (
jpeg_scan_info*)(*cinfo->mem->alloc_small)(
610 scanptr = cinfo->script_space;
611 cinfo->scan_info = scanptr;
612 cinfo->num_scans = nscans;
614 if (ncomps == 3 && cinfo->jpeg_color_space ==
JCS_YCbCr)
641 scanptr =
fill_scans(scanptr, ncomps, 1, 5, 0, 2);
642 scanptr =
fill_scans(scanptr, ncomps, 6, 63, 0, 2);
644 scanptr =
fill_scans(scanptr, ncomps, 1, 63, 2, 1);
647 scanptr =
fill_scans(scanptr, ncomps, 1, 63, 1, 0);
fill_dc_scans(jpeg_scan_info *scanptr, int ncomps, int Ah, int Al)
fill_a_scan(jpeg_scan_info *scanptr, int ci, int Ss, int Se, int Ah, int Al)
jpeg_set_quality(j_compress_ptr cinfo, int quality, boolean force_baseline)
add_huff_table(j_compress_ptr cinfo, JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
#define SET_COMP(index, id, hsamp, vsamp, quant, dctbl, actbl)
jpeg_set_linear_quality(j_compress_ptr cinfo, int scale_factor, boolean force_baseline)
#define MAX_COMPS_IN_SCAN
jpeg_set_defaults(j_compress_ptr cinfo)
struct jpeg_common_struct * j_common_ptr
std_huff_tables(j_compress_ptr cinfo)
#define ERREXIT(cinfo, code)
#define MEMCOPY(dest, src, size)
jpeg_set_colorspace(j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
jpeg_alloc_huff_table(j_common_ptr cinfo)
jpeg_alloc_quant_table(j_common_ptr cinfo)
#define ERREXIT1(cinfo, code, p1)
jpeg_simple_progression(j_compress_ptr cinfo)
fill_scans(jpeg_scan_info *scanptr, int ncomps, int Ss, int Se, int Ah, int Al)
jpeg_default_colorspace(j_compress_ptr cinfo)
#define ERREXIT2(cinfo, code, p1, p2)
jpeg_add_quant_table(j_compress_ptr cinfo, int which_tbl, const unsigned int *basic_table, int scale_factor, boolean force_baseline)
jpeg_component_info * compptr
jpeg_quality_scaling(int quality)