Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #define JPEG_INTERNALS
00018 #include "jinclude.h"
00019 #include "jpeglib.h"
00020
00021
00022
00023 LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 GLOBAL(boolean)
00038 jpeg_start_decompress (j_decompress_ptr cinfo)
00039 {
00040 if (cinfo->global_state == DSTATE_READY) {
00041
00042 jinit_master_decompress(cinfo);
00043 if (cinfo->buffered_image) {
00044
00045 cinfo->global_state = DSTATE_BUFIMAGE;
00046 return TRUE;
00047 }
00048 cinfo->global_state = DSTATE_PRELOAD;
00049 }
00050 if (cinfo->global_state == DSTATE_PRELOAD) {
00051
00052 if (cinfo->inputctl->has_multiple_scans) {
00053 #ifdef D_MULTISCAN_FILES_SUPPORTED
00054 for (;;) {
00055 int retcode;
00056
00057 if (cinfo->progress != NULL)
00058 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
00059
00060 retcode = (*cinfo->inputctl->consume_input) (cinfo);
00061 if (retcode == JPEG_SUSPENDED)
00062 return FALSE;
00063 if (retcode == JPEG_REACHED_EOI)
00064 break;
00065
00066 if (cinfo->progress != NULL &&
00067 (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
00068 if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
00069
00070 cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
00071 }
00072 }
00073 }
00074 #else
00075 ERREXIT(cinfo, JERR_NOT_COMPILED);
00076 #endif
00077 }
00078 cinfo->output_scan_number = cinfo->input_scan_number;
00079 } else if (cinfo->global_state != DSTATE_PRESCAN)
00080 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00081
00082 return output_pass_setup(cinfo);
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 LOCAL(boolean)
00095 output_pass_setup (j_decompress_ptr cinfo)
00096 {
00097 if (cinfo->global_state != DSTATE_PRESCAN) {
00098
00099 (*cinfo->master->prepare_for_output_pass) (cinfo);
00100 cinfo->output_scanline = 0;
00101 cinfo->global_state = DSTATE_PRESCAN;
00102 }
00103
00104 while (cinfo->master->is_dummy_pass) {
00105 #ifdef QUANT_2PASS_SUPPORTED
00106
00107 while (cinfo->output_scanline < cinfo->output_height) {
00108 JDIMENSION last_scanline;
00109
00110 if (cinfo->progress != NULL) {
00111 cinfo->progress->pass_counter = (long) cinfo->output_scanline;
00112 cinfo->progress->pass_limit = (long) cinfo->output_height;
00113 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
00114 }
00115
00116 last_scanline = cinfo->output_scanline;
00117 (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
00118 &cinfo->output_scanline, (JDIMENSION) 0);
00119 if (cinfo->output_scanline == last_scanline)
00120 return FALSE;
00121 }
00122
00123 (*cinfo->master->finish_output_pass) (cinfo);
00124 (*cinfo->master->prepare_for_output_pass) (cinfo);
00125 cinfo->output_scanline = 0;
00126 #else
00127 ERREXIT(cinfo, JERR_NOT_COMPILED);
00128 #endif
00129 }
00130
00131
00132
00133 cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
00134 return TRUE;
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 GLOBAL(JDIMENSION)
00152 jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
00153 JDIMENSION max_lines)
00154 {
00155 JDIMENSION row_ctr;
00156
00157 if (cinfo->global_state != DSTATE_SCANNING)
00158 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00159 if (cinfo->output_scanline >= cinfo->output_height) {
00160 WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
00161 return 0;
00162 }
00163
00164
00165 if (cinfo->progress != NULL) {
00166 cinfo->progress->pass_counter = (long) cinfo->output_scanline;
00167 cinfo->progress->pass_limit = (long) cinfo->output_height;
00168 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
00169 }
00170
00171
00172 row_ctr = 0;
00173 (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
00174 cinfo->output_scanline += row_ctr;
00175 return row_ctr;
00176 }
00177
00178
00179
00180
00181
00182
00183
00184 GLOBAL(JDIMENSION)
00185 jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
00186 JDIMENSION max_lines)
00187 {
00188 JDIMENSION lines_per_iMCU_row;
00189
00190 if (cinfo->global_state != DSTATE_RAW_OK)
00191 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00192 if (cinfo->output_scanline >= cinfo->output_height) {
00193 WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
00194 return 0;
00195 }
00196
00197
00198 if (cinfo->progress != NULL) {
00199 cinfo->progress->pass_counter = (long) cinfo->output_scanline;
00200 cinfo->progress->pass_limit = (long) cinfo->output_height;
00201 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
00202 }
00203
00204
00205 lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
00206 if (max_lines < lines_per_iMCU_row)
00207 ERREXIT(cinfo, JERR_BUFFER_SIZE);
00208
00209
00210 if (! (*cinfo->coef->decompress_data) (cinfo, data))
00211 return 0;
00212
00213
00214 cinfo->output_scanline += lines_per_iMCU_row;
00215 return lines_per_iMCU_row;
00216 }
00217
00218
00219
00220
00221 #ifdef D_MULTISCAN_FILES_SUPPORTED
00222
00223
00224
00225
00226
00227 GLOBAL(boolean)
00228 jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
00229 {
00230 if (cinfo->global_state != DSTATE_BUFIMAGE &&
00231 cinfo->global_state != DSTATE_PRESCAN)
00232 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00233
00234 if (scan_number <= 0)
00235 scan_number = 1;
00236 if (cinfo->inputctl->eoi_reached &&
00237 scan_number > cinfo->input_scan_number)
00238 scan_number = cinfo->input_scan_number;
00239 cinfo->output_scan_number = scan_number;
00240
00241 return output_pass_setup(cinfo);
00242 }
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 GLOBAL(boolean)
00253 jpeg_finish_output (j_decompress_ptr cinfo)
00254 {
00255 if ((cinfo->global_state == DSTATE_SCANNING ||
00256 cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
00257
00258
00259 (*cinfo->master->finish_output_pass) (cinfo);
00260 cinfo->global_state = DSTATE_BUFPOST;
00261 } else if (cinfo->global_state != DSTATE_BUFPOST) {
00262
00263 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00264 }
00265
00266 while (cinfo->input_scan_number <= cinfo->output_scan_number &&
00267 ! cinfo->inputctl->eoi_reached) {
00268 if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
00269 return FALSE;
00270 }
00271 cinfo->global_state = DSTATE_BUFIMAGE;
00272 return TRUE;
00273 }
00274
00275 #endif