00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #define JPEG_INTERNALS
00021 #include "jinclude.h"
00022 #include "jpeglib.h"
00023
00024
00025
00026
00027
00028
00029
00030 GLOBAL(void)
00031 jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
00032 {
00033 int i;
00034
00035
00036 cinfo->mem = NULL;
00037 if (version != JPEG_LIB_VERSION)
00038 ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
00039 if (structsize != SIZEOF(struct jpeg_compress_struct))
00040 ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
00041 (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
00042
00043
00044
00045
00046
00047
00048
00049 {
00050 struct jpeg_error_mgr * err = cinfo->err;
00051 void * client_data = cinfo->client_data;
00052 MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
00053 cinfo->err = err;
00054 cinfo->client_data = client_data;
00055 }
00056 cinfo->is_decompressor = FALSE;
00057
00058
00059 jinit_memory_mgr((j_common_ptr) cinfo);
00060
00061
00062 cinfo->progress = NULL;
00063 cinfo->dest = NULL;
00064
00065 cinfo->comp_info = NULL;
00066
00067 for (i = 0; i < NUM_QUANT_TBLS; i++) {
00068 cinfo->quant_tbl_ptrs[i] = NULL;
00069 cinfo->q_scale_factor[i] = 100;
00070 }
00071
00072 for (i = 0; i < NUM_HUFF_TBLS; i++) {
00073 cinfo->dc_huff_tbl_ptrs[i] = NULL;
00074 cinfo->ac_huff_tbl_ptrs[i] = NULL;
00075 }
00076
00077
00078 cinfo->block_size = DCTSIZE;
00079 cinfo->natural_order = jpeg_natural_order;
00080 cinfo->lim_Se = DCTSIZE2-1;
00081
00082 cinfo->script_space = NULL;
00083
00084 cinfo->input_gamma = 1.0;
00085
00086
00087 cinfo->global_state = CSTATE_START;
00088 }
00089
00090
00091
00092
00093
00094
00095 GLOBAL(void)
00096 jpeg_destroy_compress (j_compress_ptr cinfo)
00097 {
00098 jpeg_destroy((j_common_ptr) cinfo);
00099 }
00100
00101
00102
00103
00104
00105
00106
00107 GLOBAL(void)
00108 jpeg_abort_compress (j_compress_ptr cinfo)
00109 {
00110 jpeg_abort((j_common_ptr) cinfo);
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 GLOBAL(void)
00127 jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
00128 {
00129 int i;
00130 JQUANT_TBL * qtbl;
00131 JHUFF_TBL * htbl;
00132
00133 for (i = 0; i < NUM_QUANT_TBLS; i++) {
00134 if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
00135 qtbl->sent_table = suppress;
00136 }
00137
00138 for (i = 0; i < NUM_HUFF_TBLS; i++) {
00139 if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
00140 htbl->sent_table = suppress;
00141 if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
00142 htbl->sent_table = suppress;
00143 }
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 GLOBAL(void)
00155 jpeg_finish_compress (j_compress_ptr cinfo)
00156 {
00157 JDIMENSION iMCU_row;
00158
00159 if (cinfo->global_state == CSTATE_SCANNING ||
00160 cinfo->global_state == CSTATE_RAW_OK) {
00161
00162 if (cinfo->next_scanline < cinfo->image_height)
00163 ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
00164 (*cinfo->master->finish_pass) (cinfo);
00165 } else if (cinfo->global_state != CSTATE_WRCOEFS)
00166 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00167
00168 while (! cinfo->master->is_last_pass) {
00169 (*cinfo->master->prepare_for_pass) (cinfo);
00170 for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
00171 if (cinfo->progress != NULL) {
00172 cinfo->progress->pass_counter = (long) iMCU_row;
00173 cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
00174 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
00175 }
00176
00177
00178
00179 if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
00180 ERREXIT(cinfo, JERR_CANT_SUSPEND);
00181 }
00182 (*cinfo->master->finish_pass) (cinfo);
00183 }
00184
00185 (*cinfo->marker->write_file_trailer) (cinfo);
00186 (*cinfo->dest->term_destination) (cinfo);
00187
00188 jpeg_abort((j_common_ptr) cinfo);
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 GLOBAL(void)
00200 jpeg_write_marker (j_compress_ptr cinfo, int marker,
00201 const JOCTET *dataptr, unsigned int datalen)
00202 {
00203 JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
00204
00205 if (cinfo->next_scanline != 0 ||
00206 (cinfo->global_state != CSTATE_SCANNING &&
00207 cinfo->global_state != CSTATE_RAW_OK &&
00208 cinfo->global_state != CSTATE_WRCOEFS))
00209 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00210
00211 (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
00212 write_marker_byte = cinfo->marker->write_marker_byte;
00213 while (datalen--) {
00214 (*write_marker_byte) (cinfo, *dataptr);
00215 dataptr++;
00216 }
00217 }
00218
00219
00220
00221 GLOBAL(void)
00222 jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
00223 {
00224 if (cinfo->next_scanline != 0 ||
00225 (cinfo->global_state != CSTATE_SCANNING &&
00226 cinfo->global_state != CSTATE_RAW_OK &&
00227 cinfo->global_state != CSTATE_WRCOEFS))
00228 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00229
00230 (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
00231 }
00232
00233 GLOBAL(void)
00234 jpeg_write_m_byte (j_compress_ptr cinfo, int val)
00235 {
00236 (*cinfo->marker->write_marker_byte) (cinfo, val);
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 GLOBAL(void)
00262 jpeg_write_tables (j_compress_ptr cinfo)
00263 {
00264 if (cinfo->global_state != CSTATE_START)
00265 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00266
00267
00268 (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
00269 (*cinfo->dest->init_destination) (cinfo);
00270
00271 jinit_marker_writer(cinfo);
00272
00273 (*cinfo->marker->write_tables_only) (cinfo);
00274
00275 (*cinfo->dest->term_destination) (cinfo);
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 }