📄 jcmarker.c
字号:
BitstreamPutBits(2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1, 16); /* length */ //emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */#if 1 //pwhsu++:20040113 //BitstreamPutBits(0x4A, 8); //BitstreamPutBits(0x46, 8); BitstreamPutBits(0x4A46, 16); //BitstreamPutBits(0x49, 8); //BitstreamPutBits(0x46, 8); BitstreamPutBits(0x4946, 16); //BitstreamPutBits(0, 8); //BitstreamPutBits(cinfo->JFIF_major_version, 8); BitstreamPutBits(cinfo->JFIF_major_version, 16); //BitstreamPutBits(cinfo->JFIF_minor_version, 8); //BitstreamPutBits(cinfo->density_unit, 8); /* Pixel size information */ BitstreamPutBits( (cinfo->JFIF_minor_version<<8)| cinfo->density_unit, 16); /* Pixel size information */ BitstreamPutBits((int) cinfo->X_density, 16); BitstreamPutBits((int) cinfo->Y_density, 16); //BitstreamPutBits(0, 8); //BitstreamPutBits(0, 8); BitstreamPutBits(0, 16); /* No thumbnail image */#else emit_word(cinfo, 0x4A, 8); /* Identifier: ASCII "JFIF" */ emit_word(cinfo, 0x46, 8); emit_word(cinfo, 0x49, 8); emit_word(cinfo, 0x46, 8); emit_word(cinfo, 0, 8); emit_word(cinfo, cinfo->JFIF_major_version, 8); /* Version fields */ emit_word(cinfo, cinfo->JFIF_minor_version, 8); emit_word(cinfo, cinfo->density_unit, 8); /* Pixel size information */ emit_2bytes(cinfo, (int) cinfo->X_density); emit_2bytes(cinfo, (int) cinfo->Y_density); emit_word(cinfo, 0, 8); /* No thumbnail image */ emit_word(cinfo, 0, 8); emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */ emit_byte(cinfo, 0x46); emit_byte(cinfo, 0x49); emit_byte(cinfo, 0x46); emit_byte(cinfo, 0); emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */ emit_byte(cinfo, cinfo->JFIF_minor_version); emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */ emit_2bytes(cinfo, (int) cinfo->X_density); emit_2bytes(cinfo, (int) cinfo->Y_density); emit_byte(cinfo, 0); /* No thumbnail image */ emit_byte(cinfo, 0);#endif}LOCAL(void)emit_adobe_app14 (j_compress_ptr cinfo)/* Emit an Adobe APP14 marker */{ /* * Length of APP14 block (2 bytes) * Block ID (5 bytes - ASCII "Adobe") * Version Number (2 bytes - currently 100) * Flags0 (2 bytes - currently 0) * Flags1 (2 bytes - currently 0) * Color transform (1 byte) * * Although Adobe TN 5116 mentions Version = 101, all the Adobe files * now in circulation seem to use Version = 100, so that's what we write. * * We write the color transform byte as 1 if the JPEG color space is * YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with * whether the encoder performed a transformation, which is pretty useless. */ emit_marker(cinfo, M_APP14); BitstreamPutBits(2 + 5 + 2 + 2 + 2 + 1, 16); /* length */ //emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */#if 1 //pwhsu++:20040113 //BitstreamPutBits(0x41, 8); //BitstreamPutBits(0x64, 8); BitstreamPutBits(0x4164, 16); //BitstreamPutBits(0x6F, 8); //BitstreamPutBits(0x62, 8); BitstreamPutBits(0x6F62, 16); BitstreamPutBits(0x65, 8); BitstreamPutBits(100, 16); /* Version */ BitstreamPutBits(0, 16); /* Flags0 */ BitstreamPutBits(0, 16); /* Flags1 */ switch (cinfo->jpeg_color_space) { case JCS_YCbCr: BitstreamPutBits(1, 8); /* Color transform = 1 */ break; case JCS_YCCK: BitstreamPutBits(2, 8); /* Color transform = 2 */ break; default: BitstreamPutBits(0, 8); /* Color transform = 0 */ break; }#else emit_word(cinfo, 0x41, 8); /* Identifier: ASCII "Adobe" */ emit_word(cinfo, 0x64, 8); emit_word(cinfo, 0x6F, 8); emit_word(cinfo, 0x62, 8); emit_word(cinfo, 0x65, 8); emit_2bytes(cinfo, 100); /* Version */ emit_2bytes(cinfo, 0); /* Flags0 */ emit_2bytes(cinfo, 0); /* Flags1 */ switch (cinfo->jpeg_color_space) { case JCS_YCbCr: emit_word(cinfo, 1, 8); /* Color transform = 1 */ break; case JCS_YCCK: emit_word(cinfo, 2, 8); /* Color transform = 2 */ break; default: emit_word(cinfo, 0, 8); /* Color transform = 0 */ break; } emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */ emit_byte(cinfo, 0x64); emit_byte(cinfo, 0x6F); emit_byte(cinfo, 0x62); emit_byte(cinfo, 0x65); emit_2bytes(cinfo, 100); /* Version */ emit_2bytes(cinfo, 0); /* Flags0 */ emit_2bytes(cinfo, 0); /* Flags1 */ switch (cinfo->jpeg_color_space) { case JCS_YCbCr: emit_byte(cinfo, 1); /* Color transform = 1 */ break; case JCS_YCCK: emit_byte(cinfo, 2); /* Color transform = 2 */ break; default: emit_byte(cinfo, 0); /* Color transform = 0 */ break; }#endif}voidwrite_marker_header1 (j_compress_ptr cinfo, int marker, unsigned int datalen)/* Emit an arbitrary marker header */{ if (datalen > (unsigned int) 65533) /* safety check */ ERREXIT(cinfo, JERR_BAD_LENGTH); emit_marker(cinfo, (JPEG_MARKER) marker); BitstreamPutBits((int) (datalen + 2), 16); /* total length */ //emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */ }METHODDEF(void)write_marker_byte (j_compress_ptr cinfo, int val)/* Emit one byte of marker parameters following write_marker_header */{ BitstreamPutBits(val, 8); //emit_word(cinfo, val, 8); //pwhsu++:20040113 //emit_byte(cinfo, val);}/* * Write datastream header. * This consists of an SOI and optional APPn markers. * We recommend use of the JFIF marker, but not the Adobe marker, * when using YCbCr or grayscale data. The JFIF marker should NOT * be used for any other JPEG colorspace. The Adobe marker is helpful * to distinguish RGB, CMYK, and YCCK colorspaces. * Note that an application can write additional header markers after * jpeg_start_compress returns. */void write_file_header1 (j_compress_ptr cinfo){ my_marker_ptr marker = (my_marker_ptr) cinfo->marker; emit_marker(cinfo, M_SOI); /* first the SOI */ /* SOI is defined to reset restart interval to 0 */ marker->last_restart_interval = 0; if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */ emit_jfif_app0(cinfo); if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */ emit_adobe_app14(cinfo);}voidwrite_frame_header1 (j_compress_ptr cinfo){ int ci, prec; boolean is_baseline; jpeg_component_info *compptr; /* Emit DQT for each quantization table. * Note that emit_dqt() suppresses any duplicate tables. */ prec = 0; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; ci++, compptr++) { prec += emit_dqt(cinfo, compptr->quant_tbl_no); } /* now prec is nonzero iff there are any 16-bit quant tables. */ /* Check for a non-baseline specification. * Note we assume that Huffman table numbers won't be changed later. */ if (cinfo->arith_code || cinfo->progressive_mode || cinfo->data_precision != 8) { is_baseline = FALSE; } else { is_baseline = TRUE; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; ci++, compptr++) { if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1) is_baseline = FALSE; } if (prec && is_baseline) { is_baseline = FALSE; /* If it's baseline except for quantizer size, warn the user */ TRACEMS(cinfo, 0, JTRC_16BIT_TABLES); } } /* Emit the proper SOF marker */ if (cinfo->arith_code) { emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */ } else { if (cinfo->progressive_mode) emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */ else if (is_baseline) //pwhsu:20031015 execute this one emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */ else emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */ }}/* * Write scan header. * This consists of DHT or DAC markers, optional DRI, and SOS. * Compressed data will be written following the SOS. */voidwrite_scan_header1 (j_compress_ptr cinfo){ my_marker_ptr marker = (my_marker_ptr) cinfo->marker; int i; jpeg_component_info *compptr;#if 0 if (cinfo->arith_code) { /* Emit arith conditioning info. We may have some duplication * if the file has multiple scans, but it's so small it's hardly * worth worrying about. */ emit_dac(cinfo); } else {#endif /* Emit Huffman tables. * Note that emit_dht() suppresses any duplicate tables. */ for (i = 0; i < cinfo->comps_in_scan; i++) { compptr = cinfo->cur_comp_info[i]; if (cinfo->progressive_mode) { /* Progressive mode: only DC or only AC tables are used in one scan */ if (cinfo->Ss == 0) { if (cinfo->Ah == 0) /* DC needs no table for refinement scan */ emit_dht(cinfo, compptr->dc_tbl_no, FALSE); } else { emit_dht(cinfo, compptr->ac_tbl_no, TRUE); } } else { //pwhsu:20031106 Execute this one /* Sequential mode: need both DC and AC tables */ emit_dht(cinfo, compptr->dc_tbl_no, FALSE); emit_dht(cinfo, compptr->ac_tbl_no, TRUE); } } //} /* Emit DRI if required --- note that DRI value could change for each scan. * We avoid wasting space with unnecessary DRIs, however. */ if (cinfo->restart_interval != marker->last_restart_interval) { emit_dri(cinfo); marker->last_restart_interval = cinfo->restart_interval; } emit_sos(cinfo);}/* * Write datastream trailer. */voidwrite_file_trailer1 (j_compress_ptr cinfo){ emit_marker(cinfo, M_EOI);}/* * Initialize the marker writer module. */GLOBAL(void)jinit_marker_writer (j_compress_ptr cinfo){ my_marker_ptr marker; /* Create the subobject */ marker = (my_marker_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_marker_writer)); cinfo->marker = (struct jpeg_marker_writer *) marker; /* Initialize method pointers */// marker->pub.write_file_header = write_file_header;// marker->pub.write_frame_header = write_frame_header;// marker->pub.write_scan_header = write_scan_header;// marker->pub.write_file_trailer = write_file_trailer;// marker->pub.write_marker_header = write_marker_header; marker->pub.write_marker_byte = write_marker_byte; /* Initialize private state */ marker->last_restart_interval = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -