123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- #define JPEG_INTERNALS
- #include "jinclude.h"
- #include "jpeglib.h"
- GLOBAL(void)
- jpeg_CreateCompress(j_compress_ptr cinfo, int version, size_t structsize)
- {
- int i;
-
- cinfo->mem = NULL;
- if (version != JPEG_LIB_VERSION)
- ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
- if (structsize != sizeof(struct jpeg_compress_struct))
- ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
- (int)sizeof(struct jpeg_compress_struct), (int)structsize);
-
- {
- struct jpeg_error_mgr *err = cinfo->err;
- void *client_data = cinfo->client_data;
- MEMZERO(cinfo, sizeof(struct jpeg_compress_struct));
- cinfo->err = err;
- cinfo->client_data = client_data;
- }
- cinfo->is_decompressor = FALSE;
-
- jinit_memory_mgr((j_common_ptr)cinfo);
-
- cinfo->progress = NULL;
- cinfo->dest = NULL;
- cinfo->comp_info = NULL;
- for (i = 0; i < NUM_QUANT_TBLS; i++) {
- cinfo->quant_tbl_ptrs[i] = NULL;
- #if JPEG_LIB_VERSION >= 70
- cinfo->q_scale_factor[i] = 100;
- #endif
- }
- for (i = 0; i < NUM_HUFF_TBLS; i++) {
- cinfo->dc_huff_tbl_ptrs[i] = NULL;
- cinfo->ac_huff_tbl_ptrs[i] = NULL;
- }
- #if JPEG_LIB_VERSION >= 80
-
- cinfo->block_size = DCTSIZE;
- cinfo->natural_order = jpeg_natural_order;
- cinfo->lim_Se = DCTSIZE2 - 1;
- #endif
- cinfo->script_space = NULL;
- cinfo->input_gamma = 1.0;
-
- cinfo->global_state = CSTATE_START;
- }
- GLOBAL(void)
- jpeg_destroy_compress(j_compress_ptr cinfo)
- {
- jpeg_destroy((j_common_ptr)cinfo);
- }
- GLOBAL(void)
- jpeg_abort_compress(j_compress_ptr cinfo)
- {
- jpeg_abort((j_common_ptr)cinfo);
- }
- GLOBAL(void)
- jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress)
- {
- int i;
- JQUANT_TBL *qtbl;
- JHUFF_TBL *htbl;
- for (i = 0; i < NUM_QUANT_TBLS; i++) {
- if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
- qtbl->sent_table = suppress;
- }
- for (i = 0; i < NUM_HUFF_TBLS; i++) {
- if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
- htbl->sent_table = suppress;
- if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
- htbl->sent_table = suppress;
- }
- }
- GLOBAL(void)
- jpeg_finish_compress(j_compress_ptr cinfo)
- {
- JDIMENSION iMCU_row;
- if (cinfo->global_state == CSTATE_SCANNING ||
- cinfo->global_state == CSTATE_RAW_OK) {
-
- if (cinfo->next_scanline < cinfo->image_height)
- ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
- (*cinfo->master->finish_pass) (cinfo);
- } else if (cinfo->global_state != CSTATE_WRCOEFS)
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
-
- while (!cinfo->master->is_last_pass) {
- (*cinfo->master->prepare_for_pass) (cinfo);
- for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
- if (cinfo->progress != NULL) {
- cinfo->progress->pass_counter = (long)iMCU_row;
- cinfo->progress->pass_limit = (long)cinfo->total_iMCU_rows;
- (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
- }
-
- if (!(*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE)NULL))
- ERREXIT(cinfo, JERR_CANT_SUSPEND);
- }
- (*cinfo->master->finish_pass) (cinfo);
- }
-
- (*cinfo->marker->write_file_trailer) (cinfo);
- (*cinfo->dest->term_destination) (cinfo);
-
- jpeg_abort((j_common_ptr)cinfo);
- }
- GLOBAL(void)
- jpeg_write_marker(j_compress_ptr cinfo, int marker, const JOCTET *dataptr,
- unsigned int datalen)
- {
- void (*write_marker_byte) (j_compress_ptr info, int val);
- if (cinfo->next_scanline != 0 ||
- (cinfo->global_state != CSTATE_SCANNING &&
- cinfo->global_state != CSTATE_RAW_OK &&
- cinfo->global_state != CSTATE_WRCOEFS))
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
- (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
- write_marker_byte = cinfo->marker->write_marker_byte;
- while (datalen--) {
- (*write_marker_byte) (cinfo, *dataptr);
- dataptr++;
- }
- }
- GLOBAL(void)
- jpeg_write_m_header(j_compress_ptr cinfo, int marker, unsigned int datalen)
- {
- if (cinfo->next_scanline != 0 ||
- (cinfo->global_state != CSTATE_SCANNING &&
- cinfo->global_state != CSTATE_RAW_OK &&
- cinfo->global_state != CSTATE_WRCOEFS))
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
- (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
- }
- GLOBAL(void)
- jpeg_write_m_byte(j_compress_ptr cinfo, int val)
- {
- (*cinfo->marker->write_marker_byte) (cinfo, val);
- }
- GLOBAL(void)
- jpeg_write_tables(j_compress_ptr cinfo)
- {
- if (cinfo->global_state != CSTATE_START)
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
-
- (*cinfo->err->reset_error_mgr) ((j_common_ptr)cinfo);
- (*cinfo->dest->init_destination) (cinfo);
-
- jinit_marker_writer(cinfo);
-
- (*cinfo->marker->write_tables_only) (cinfo);
-
- (*cinfo->dest->term_destination) (cinfo);
-
- }
|