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_CreateDecompress (j_decompress_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_decompress_struct))
00039 ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
00040 (int) SIZEOF(struct jpeg_decompress_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_decompress_struct));
00052 cinfo->err = err;
00053 cinfo->client_data = client_data;
00054 }
00055 cinfo->is_decompressor = TRUE;
00056
00057
00058 jinit_memory_mgr((j_common_ptr) cinfo);
00059
00060
00061 cinfo->progress = NULL;
00062 cinfo->src = NULL;
00063
00064 for (i = 0; i < NUM_QUANT_TBLS; i++)
00065 cinfo->quant_tbl_ptrs[i] = NULL;
00066
00067 for (i = 0; i < NUM_HUFF_TBLS; i++) {
00068 cinfo->dc_huff_tbl_ptrs[i] = NULL;
00069 cinfo->ac_huff_tbl_ptrs[i] = NULL;
00070 }
00071
00072
00073
00074
00075 cinfo->marker_list = NULL;
00076 jinit_marker_reader(cinfo);
00077
00078
00079 jinit_input_controller(cinfo);
00080
00081
00082 cinfo->global_state = DSTATE_START;
00083 }
00084
00085
00086
00087
00088
00089
00090 GLOBAL(void)
00091 jpeg_destroy_decompress (j_decompress_ptr cinfo)
00092 {
00093 jpeg_destroy((j_common_ptr) cinfo);
00094 }
00095
00096
00097
00098
00099
00100
00101
00102 GLOBAL(void)
00103 jpeg_abort_decompress (j_decompress_ptr cinfo)
00104 {
00105 jpeg_abort((j_common_ptr) cinfo);
00106 }
00107
00108
00109
00110
00111
00112
00113 LOCAL(void)
00114 default_decompress_parms (j_decompress_ptr cinfo)
00115 {
00116
00117
00118
00119 switch (cinfo->num_components) {
00120 case 1:
00121 cinfo->jpeg_color_space = JCS_GRAYSCALE;
00122 cinfo->out_color_space = JCS_GRAYSCALE;
00123 break;
00124
00125 case 3:
00126 if (cinfo->saw_JFIF_marker) {
00127 cinfo->jpeg_color_space = JCS_YCbCr;
00128 } else if (cinfo->saw_Adobe_marker) {
00129 switch (cinfo->Adobe_transform) {
00130 case 0:
00131 cinfo->jpeg_color_space = JCS_RGB;
00132 break;
00133 case 1:
00134 cinfo->jpeg_color_space = JCS_YCbCr;
00135 break;
00136 default:
00137 WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
00138 cinfo->jpeg_color_space = JCS_YCbCr;
00139 break;
00140 }
00141 } else {
00142
00143 int cid0 = cinfo->comp_info[0].component_id;
00144 int cid1 = cinfo->comp_info[1].component_id;
00145 int cid2 = cinfo->comp_info[2].component_id;
00146
00147 if (cid0 == 1 && cid1 == 2 && cid2 == 3)
00148 cinfo->jpeg_color_space = JCS_YCbCr;
00149 else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
00150 cinfo->jpeg_color_space = JCS_RGB;
00151 else {
00152 TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
00153 cinfo->jpeg_color_space = JCS_YCbCr;
00154 }
00155 }
00156
00157 cinfo->out_color_space = JCS_RGB;
00158 break;
00159
00160 case 4:
00161 if (cinfo->saw_Adobe_marker) {
00162 switch (cinfo->Adobe_transform) {
00163 case 0:
00164 cinfo->jpeg_color_space = JCS_CMYK;
00165 break;
00166 case 2:
00167 cinfo->jpeg_color_space = JCS_YCCK;
00168 break;
00169 default:
00170 WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
00171 cinfo->jpeg_color_space = JCS_YCCK;
00172 break;
00173 }
00174 } else {
00175
00176 cinfo->jpeg_color_space = JCS_CMYK;
00177 }
00178 cinfo->out_color_space = JCS_CMYK;
00179 break;
00180
00181 default:
00182 cinfo->jpeg_color_space = JCS_UNKNOWN;
00183 cinfo->out_color_space = JCS_UNKNOWN;
00184 break;
00185 }
00186
00187
00188 cinfo->scale_num = 1;
00189 cinfo->scale_denom = 1;
00190 cinfo->output_gamma = 1.0;
00191 cinfo->buffered_image = FALSE;
00192 cinfo->raw_data_out = FALSE;
00193 cinfo->dct_method = JDCT_DEFAULT;
00194 cinfo->do_fancy_upsampling = TRUE;
00195 cinfo->do_block_smoothing = TRUE;
00196 cinfo->quantize_colors = FALSE;
00197
00198 cinfo->dither_mode = JDITHER_FS;
00199 #ifdef QUANT_2PASS_SUPPORTED
00200 cinfo->two_pass_quantize = TRUE;
00201 #else
00202 cinfo->two_pass_quantize = FALSE;
00203 #endif
00204 cinfo->desired_number_of_colors = 256;
00205 cinfo->colormap = NULL;
00206
00207 cinfo->enable_1pass_quant = FALSE;
00208 cinfo->enable_external_quant = FALSE;
00209 cinfo->enable_2pass_quant = FALSE;
00210 }
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 GLOBAL(int)
00241 jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
00242 {
00243 int retcode;
00244
00245 if (cinfo->global_state != DSTATE_START &&
00246 cinfo->global_state != DSTATE_INHEADER)
00247 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00248
00249 retcode = jpeg_consume_input(cinfo);
00250
00251 switch (retcode) {
00252 case JPEG_REACHED_SOS:
00253 retcode = JPEG_HEADER_OK;
00254 break;
00255 case JPEG_REACHED_EOI:
00256 if (require_image)
00257 ERREXIT(cinfo, JERR_NO_IMAGE);
00258
00259
00260
00261
00262 jpeg_abort((j_common_ptr) cinfo);
00263 retcode = JPEG_HEADER_TABLES_ONLY;
00264 break;
00265 case JPEG_SUSPENDED:
00266
00267 break;
00268 }
00269
00270 return retcode;
00271 }
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 GLOBAL(int)
00287 jpeg_consume_input (j_decompress_ptr cinfo)
00288 {
00289 int retcode = JPEG_SUSPENDED;
00290
00291
00292 switch (cinfo->global_state) {
00293 case DSTATE_START:
00294
00295 (*cinfo->inputctl->reset_input_controller) (cinfo);
00296
00297 (*cinfo->src->init_source) (cinfo);
00298 cinfo->global_state = DSTATE_INHEADER;
00299
00300 case DSTATE_INHEADER:
00301 retcode = (*cinfo->inputctl->consume_input) (cinfo);
00302 if (retcode == JPEG_REACHED_SOS) {
00303
00304 default_decompress_parms(cinfo);
00305
00306 cinfo->global_state = DSTATE_READY;
00307 }
00308 break;
00309 case DSTATE_READY:
00310
00311 retcode = JPEG_REACHED_SOS;
00312 break;
00313 case DSTATE_PRELOAD:
00314 case DSTATE_PRESCAN:
00315 case DSTATE_SCANNING:
00316 case DSTATE_RAW_OK:
00317 case DSTATE_BUFIMAGE:
00318 case DSTATE_BUFPOST:
00319 case DSTATE_STOPPING:
00320 retcode = (*cinfo->inputctl->consume_input) (cinfo);
00321 break;
00322 default:
00323 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00324 }
00325 return retcode;
00326 }
00327
00328
00329
00330
00331
00332
00333 GLOBAL(boolean)
00334 jpeg_input_complete (j_decompress_ptr cinfo)
00335 {
00336
00337 if (cinfo->global_state < DSTATE_START ||
00338 cinfo->global_state > DSTATE_STOPPING)
00339 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00340 return cinfo->inputctl->eoi_reached;
00341 }
00342
00343
00344
00345
00346
00347
00348 GLOBAL(boolean)
00349 jpeg_has_multiple_scans (j_decompress_ptr cinfo)
00350 {
00351
00352 if (cinfo->global_state < DSTATE_READY ||
00353 cinfo->global_state > DSTATE_STOPPING)
00354 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00355 return cinfo->inputctl->has_multiple_scans;
00356 }
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368 GLOBAL(boolean)
00369 jpeg_finish_decompress (j_decompress_ptr cinfo)
00370 {
00371 if ((cinfo->global_state == DSTATE_SCANNING ||
00372 cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
00373
00374 if (cinfo->output_scanline < cinfo->output_height)
00375 ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
00376 (*cinfo->master->finish_output_pass) (cinfo);
00377 cinfo->global_state = DSTATE_STOPPING;
00378 } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
00379
00380 cinfo->global_state = DSTATE_STOPPING;
00381 } else if (cinfo->global_state != DSTATE_STOPPING) {
00382
00383 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00384 }
00385
00386 while (! cinfo->inputctl->eoi_reached) {
00387 if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
00388 return FALSE;
00389 }
00390
00391 (*cinfo->src->term_source) (cinfo);
00392
00393 jpeg_abort((j_common_ptr) cinfo);
00394 return TRUE;
00395 }