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