00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #define JPEG_INTERNALS
00020 #include "jinclude.h"
00021 #include "jpeglib.h"
00022
00023
00024
00025
00026
00027
00028
00029 GLOBAL void
00030 jpeg_create_compress (j_compress_ptr cinfo)
00031 {
00032 int i;
00033
00034
00035
00036
00037 {
00038 struct jpeg_error_mgr * err = cinfo->err;
00039 MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
00040 cinfo->err = err;
00041 }
00042 cinfo->is_decompressor = FALSE;
00043
00044
00045 jinit_memory_mgr((j_common_ptr) cinfo);
00046
00047
00048 cinfo->progress = NULL;
00049 cinfo->dest = NULL;
00050
00051 cinfo->comp_info = NULL;
00052
00053 for (i = 0; i < NUM_QUANT_TBLS; i++)
00054 cinfo->quant_tbl_ptrs[i] = NULL;
00055
00056 for (i = 0; i < NUM_HUFF_TBLS; i++) {
00057 cinfo->dc_huff_tbl_ptrs[i] = NULL;
00058 cinfo->ac_huff_tbl_ptrs[i] = NULL;
00059 }
00060
00061 cinfo->input_gamma = 1.0;
00062
00063
00064 cinfo->global_state = CSTATE_START;
00065 }
00066
00067
00068
00069
00070
00071
00072 GLOBAL void
00073 jpeg_destroy_compress (j_compress_ptr cinfo)
00074 {
00075 jpeg_destroy((j_common_ptr) cinfo);
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 GLOBAL void
00085 jpeg_abort_compress (j_compress_ptr cinfo)
00086 {
00087 jpeg_abort((j_common_ptr) cinfo);
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 GLOBAL void
00104 jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
00105 {
00106 int i;
00107 JQUANT_TBL * qtbl;
00108 JHUFF_TBL * htbl;
00109
00110 for (i = 0; i < NUM_QUANT_TBLS; i++) {
00111 if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
00112 qtbl->sent_table = suppress;
00113 }
00114
00115 for (i = 0; i < NUM_HUFF_TBLS; i++) {
00116 if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
00117 htbl->sent_table = suppress;
00118 if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
00119 htbl->sent_table = suppress;
00120 }
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 GLOBAL void
00132 jpeg_finish_compress (j_compress_ptr cinfo)
00133 {
00134 JDIMENSION iMCU_row;
00135
00136 if (cinfo->global_state == CSTATE_SCANNING ||
00137 cinfo->global_state == CSTATE_RAW_OK) {
00138
00139 if (cinfo->next_scanline < cinfo->image_height)
00140 ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
00141 (*cinfo->master->finish_pass) (cinfo);
00142 } else if (cinfo->global_state != CSTATE_WRCOEFS)
00143 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00144
00145 while (! cinfo->master->is_last_pass) {
00146 (*cinfo->master->prepare_for_pass) (cinfo);
00147 for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
00148 if (cinfo->progress != NULL) {
00149 cinfo->progress->pass_counter = (long) iMCU_row;
00150 cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
00151 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
00152 }
00153
00154
00155
00156 if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
00157 ERREXIT(cinfo, JERR_CANT_SUSPEND);
00158 }
00159 (*cinfo->master->finish_pass) (cinfo);
00160 }
00161
00162 (*cinfo->marker->write_file_trailer) (cinfo);
00163 (*cinfo->dest->term_destination) (cinfo);
00164
00165 jpeg_abort((j_common_ptr) cinfo);
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 GLOBAL void
00177 jpeg_write_marker (j_compress_ptr cinfo, int marker,
00178 const JOCTET *dataptr, unsigned int datalen)
00179 {
00180 if (cinfo->next_scanline != 0 ||
00181 (cinfo->global_state != CSTATE_SCANNING &&
00182 cinfo->global_state != CSTATE_RAW_OK &&
00183 cinfo->global_state != CSTATE_WRCOEFS))
00184 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00185
00186 (*cinfo->marker->write_any_marker) (cinfo, marker, dataptr, datalen);
00187 }
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 GLOBAL void
00212 jpeg_write_tables (j_compress_ptr cinfo)
00213 {
00214 if (cinfo->global_state != CSTATE_START)
00215 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00216
00217
00218 (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
00219 (*cinfo->dest->init_destination) (cinfo);
00220
00221 jinit_marker_writer(cinfo);
00222
00223 (*cinfo->marker->write_tables_only) (cinfo);
00224
00225 (*cinfo->dest->term_destination) (cinfo);
00226
00227 jpeg_abort((j_common_ptr) cinfo);
00228 }