/src/libjpeg-turbo.main/jdapimin.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * jdapimin.c | 
| 3 |  |  * | 
| 4 |  |  * This file was part of the Independent JPEG Group's software: | 
| 5 |  |  * Copyright (C) 1994-1998, Thomas G. Lane. | 
| 6 |  |  * Lossless JPEG Modifications: | 
| 7 |  |  * Copyright (C) 1999, Ken Murchison. | 
| 8 |  |  * libjpeg-turbo Modifications: | 
| 9 |  |  * Copyright (C) 2016, 2022, D. R. Commander. | 
| 10 |  |  * For conditions of distribution and use, see the accompanying README.ijg | 
| 11 |  |  * file. | 
| 12 |  |  * | 
| 13 |  |  * This file contains application interface code for the decompression half | 
| 14 |  |  * of the JPEG library.  These are the "minimum" API routines that may be | 
| 15 |  |  * needed in either the normal full-decompression case or the | 
| 16 |  |  * transcoding-only case. | 
| 17 |  |  * | 
| 18 |  |  * Most of the routines intended to be called directly by an application | 
| 19 |  |  * are in this file or in jdapistd.c.  But also see jcomapi.c for routines | 
| 20 |  |  * shared by compression and decompression, and jdtrans.c for the transcoding | 
| 21 |  |  * case. | 
| 22 |  |  */ | 
| 23 |  |  | 
| 24 |  | #define JPEG_INTERNALS | 
| 25 |  | #include "jinclude.h" | 
| 26 |  | #include "jpeglib.h" | 
| 27 |  | #include "jdmaster.h" | 
| 28 |  |  | 
| 29 |  |  | 
| 30 |  | /* | 
| 31 |  |  * Initialization of a JPEG decompression object. | 
| 32 |  |  * The error manager must already be set up (in case memory manager fails). | 
| 33 |  |  */ | 
| 34 |  |  | 
| 35 |  | GLOBAL(void) | 
| 36 |  | jpeg_CreateDecompress(j_decompress_ptr cinfo, int version, size_t structsize) | 
| 37 | 5.67k | { | 
| 38 | 5.67k |   int i; | 
| 39 |  |  | 
| 40 |  |   /* Guard against version mismatches between library and caller. */ | 
| 41 | 5.67k |   cinfo->mem = NULL;            /* so jpeg_destroy knows mem mgr not called */ | 
| 42 | 5.67k |   if (version != JPEG_LIB_VERSION) | 
| 43 | 0 |     ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); | 
| 44 | 5.67k |   if (structsize != sizeof(struct jpeg_decompress_struct)) | 
| 45 | 0 |     ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, | 
| 46 | 5.67k |              (int)sizeof(struct jpeg_decompress_struct), (int)structsize); | 
| 47 |  |  | 
| 48 |  |   /* For debugging purposes, we zero the whole master structure. | 
| 49 |  |    * But the application has already set the err pointer, and may have set | 
| 50 |  |    * client_data, so we have to save and restore those fields. | 
| 51 |  |    * Note: if application hasn't set client_data, tools like Purify may | 
| 52 |  |    * complain here. | 
| 53 |  |    */ | 
| 54 | 5.67k |   { | 
| 55 | 5.67k |     struct jpeg_error_mgr *err = cinfo->err; | 
| 56 | 5.67k |     void *client_data = cinfo->client_data; /* ignore Purify complaint here */ | 
| 57 | 5.67k |     memset(cinfo, 0, sizeof(struct jpeg_decompress_struct)); | 
| 58 | 5.67k |     cinfo->err = err; | 
| 59 | 5.67k |     cinfo->client_data = client_data; | 
| 60 | 5.67k |   } | 
| 61 | 5.67k |   cinfo->is_decompressor = TRUE; | 
| 62 |  |  | 
| 63 |  |   /* Initialize a memory manager instance for this object */ | 
| 64 | 5.67k |   jinit_memory_mgr((j_common_ptr)cinfo); | 
| 65 |  |  | 
| 66 |  |   /* Zero out pointers to permanent structures. */ | 
| 67 | 5.67k |   cinfo->progress = NULL; | 
| 68 | 5.67k |   cinfo->src = NULL; | 
| 69 |  |  | 
| 70 | 28.3k |   for (i = 0; i < NUM_QUANT_TBLS; i++) | 
| 71 | 22.6k |     cinfo->quant_tbl_ptrs[i] = NULL; | 
| 72 |  |  | 
| 73 | 28.3k |   for (i = 0; i < NUM_HUFF_TBLS; i++) { | 
| 74 | 22.6k |     cinfo->dc_huff_tbl_ptrs[i] = NULL; | 
| 75 | 22.6k |     cinfo->ac_huff_tbl_ptrs[i] = NULL; | 
| 76 | 22.6k |   } | 
| 77 |  |  | 
| 78 |  |   /* Initialize marker processor so application can override methods | 
| 79 |  |    * for COM, APPn markers before calling jpeg_read_header. | 
| 80 |  |    */ | 
| 81 | 5.67k |   cinfo->marker_list = NULL; | 
| 82 | 5.67k |   jinit_marker_reader(cinfo); | 
| 83 |  |  | 
| 84 |  |   /* And initialize the overall input controller. */ | 
| 85 | 5.67k |   jinit_input_controller(cinfo); | 
| 86 |  |  | 
| 87 | 5.67k |   cinfo->data_precision = BITS_IN_JSAMPLE; | 
| 88 |  |  | 
| 89 |  |   /* OK, I'm ready */ | 
| 90 | 5.67k |   cinfo->global_state = DSTATE_START; | 
| 91 |  |  | 
| 92 |  |   /* The master struct is used to store extension parameters, so we allocate it | 
| 93 |  |    * here. | 
| 94 |  |    */ | 
| 95 | 5.67k |   cinfo->master = (struct jpeg_decomp_master *) | 
| 96 | 5.67k |     (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT, | 
| 97 | 5.67k |                                 sizeof(my_decomp_master)); | 
| 98 | 5.67k |   memset(cinfo->master, 0, sizeof(my_decomp_master)); | 
| 99 | 5.67k | } | 
| 100 |  |  | 
| 101 |  |  | 
| 102 |  | /* | 
| 103 |  |  * Destruction of a JPEG decompression object | 
| 104 |  |  */ | 
| 105 |  |  | 
| 106 |  | GLOBAL(void) | 
| 107 |  | jpeg_destroy_decompress(j_decompress_ptr cinfo) | 
| 108 | 5.67k | { | 
| 109 | 5.67k |   jpeg_destroy((j_common_ptr)cinfo); /* use common routine */ | 
| 110 | 5.67k | } | 
| 111 |  |  | 
| 112 |  |  | 
| 113 |  | /* | 
| 114 |  |  * Abort processing of a JPEG decompression operation, | 
| 115 |  |  * but don't destroy the object itself. | 
| 116 |  |  */ | 
| 117 |  |  | 
| 118 |  | GLOBAL(void) | 
| 119 |  | jpeg_abort_decompress(j_decompress_ptr cinfo) | 
| 120 | 7.30k | { | 
| 121 | 7.30k |   jpeg_abort((j_common_ptr)cinfo); /* use common routine */ | 
| 122 | 7.30k | } | 
| 123 |  |  | 
| 124 |  |  | 
| 125 |  | /* | 
| 126 |  |  * Set default decompression parameters. | 
| 127 |  |  */ | 
| 128 |  |  | 
| 129 |  | LOCAL(void) | 
| 130 |  | default_decompress_parms(j_decompress_ptr cinfo) | 
| 131 | 9.60k | { | 
| 132 |  |   /* Guess the input colorspace, and set output colorspace accordingly. */ | 
| 133 |  |   /* (Wish JPEG committee had provided a real way to specify this...) */ | 
| 134 |  |   /* Note application may override our guesses. */ | 
| 135 | 9.60k |   switch (cinfo->num_components) { | 
| 136 | 4.85k |   case 1: | 
| 137 | 4.85k |     cinfo->jpeg_color_space = JCS_GRAYSCALE; | 
| 138 | 4.85k |     cinfo->out_color_space = JCS_GRAYSCALE; | 
| 139 | 4.85k |     break; | 
| 140 |  |  | 
| 141 | 4.70k |   case 3: | 
| 142 | 4.70k |     if (cinfo->saw_JFIF_marker) { | 
| 143 | 104 |       cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */ | 
| 144 | 4.60k |     } else if (cinfo->saw_Adobe_marker) { | 
| 145 | 213 |       switch (cinfo->Adobe_transform) { | 
| 146 | 193 |       case 0: | 
| 147 | 193 |         cinfo->jpeg_color_space = JCS_RGB; | 
| 148 | 193 |         break; | 
| 149 | 16 |       case 1: | 
| 150 | 16 |         cinfo->jpeg_color_space = JCS_YCbCr; | 
| 151 | 16 |         break; | 
| 152 | 4 |       default: | 
| 153 | 4 |         WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); | 
| 154 | 4 |         cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ | 
| 155 | 4 |         break; | 
| 156 | 213 |       } | 
| 157 | 4.38k |     } else { | 
| 158 |  |       /* Saw no special markers, try to guess from the component IDs */ | 
| 159 | 4.38k |       int cid0 = cinfo->comp_info[0].component_id; | 
| 160 | 4.38k |       int cid1 = cinfo->comp_info[1].component_id; | 
| 161 | 4.38k |       int cid2 = cinfo->comp_info[2].component_id; | 
| 162 |  |  | 
| 163 | 4.38k |       if (cid0 == 1 && cid1 == 2 && cid2 == 3) | 
| 164 | 1.00k |         cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */ | 
| 165 | 3.38k |       else if (cid0 == 82 && cid1 == 71 && cid2 == 66) | 
| 166 | 15 |         cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */ | 
| 167 | 3.37k |       else { | 
| 168 | 3.37k |         TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2); | 
| 169 | 3.37k |         if (cinfo->master->lossless) | 
| 170 | 2.22k |           cinfo->jpeg_color_space = JCS_RGB; /* assume it's RGB */ | 
| 171 | 1.14k |         else | 
| 172 | 1.14k |           cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ | 
| 173 | 3.37k |       } | 
| 174 | 4.38k |     } | 
| 175 |  |     /* Always guess RGB is proper output colorspace. */ | 
| 176 | 4.70k |     cinfo->out_color_space = JCS_RGB; | 
| 177 | 4.70k |     break; | 
| 178 |  |  | 
| 179 | 37 |   case 4: | 
| 180 | 37 |     if (cinfo->saw_Adobe_marker) { | 
| 181 | 13 |       switch (cinfo->Adobe_transform) { | 
| 182 | 3 |       case 0: | 
| 183 | 3 |         cinfo->jpeg_color_space = JCS_CMYK; | 
| 184 | 3 |         break; | 
| 185 | 5 |       case 2: | 
| 186 | 5 |         cinfo->jpeg_color_space = JCS_YCCK; | 
| 187 | 5 |         break; | 
| 188 | 5 |       default: | 
| 189 | 5 |         WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); | 
| 190 | 5 |         cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */ | 
| 191 | 5 |         break; | 
| 192 | 13 |       } | 
| 193 | 24 |     } else { | 
| 194 |  |       /* No special markers, assume straight CMYK. */ | 
| 195 | 24 |       cinfo->jpeg_color_space = JCS_CMYK; | 
| 196 | 24 |     } | 
| 197 | 37 |     cinfo->out_color_space = JCS_CMYK; | 
| 198 | 37 |     break; | 
| 199 |  |  | 
| 200 | 7 |   default: | 
| 201 | 7 |     cinfo->jpeg_color_space = JCS_UNKNOWN; | 
| 202 | 7 |     cinfo->out_color_space = JCS_UNKNOWN; | 
| 203 | 7 |     break; | 
| 204 | 9.60k |   } | 
| 205 |  |  | 
| 206 |  |   /* Set defaults for other decompression parameters. */ | 
| 207 | 9.60k |   cinfo->scale_num = 1;         /* 1:1 scaling */ | 
| 208 | 9.60k |   cinfo->scale_denom = 1; | 
| 209 | 9.60k |   cinfo->output_gamma = 1.0; | 
| 210 | 9.60k |   cinfo->buffered_image = FALSE; | 
| 211 | 9.60k |   cinfo->raw_data_out = FALSE; | 
| 212 | 9.60k |   cinfo->dct_method = JDCT_DEFAULT; | 
| 213 | 9.60k |   cinfo->do_fancy_upsampling = TRUE; | 
| 214 | 9.60k |   cinfo->do_block_smoothing = TRUE; | 
| 215 | 9.60k |   cinfo->quantize_colors = FALSE; | 
| 216 |  |   /* We set these in case application only sets quantize_colors. */ | 
| 217 | 9.60k |   cinfo->dither_mode = JDITHER_FS; | 
| 218 | 9.60k | #ifdef QUANT_2PASS_SUPPORTED | 
| 219 | 9.60k |   cinfo->two_pass_quantize = TRUE; | 
| 220 |  | #else | 
| 221 |  |   cinfo->two_pass_quantize = FALSE; | 
| 222 |  | #endif | 
| 223 | 9.60k |   cinfo->desired_number_of_colors = 256; | 
| 224 | 9.60k |   cinfo->colormap = NULL; | 
| 225 |  |   /* Initialize for no mode change in buffered-image mode. */ | 
| 226 | 9.60k |   cinfo->enable_1pass_quant = FALSE; | 
| 227 | 9.60k |   cinfo->enable_external_quant = FALSE; | 
| 228 | 9.60k |   cinfo->enable_2pass_quant = FALSE; | 
| 229 | 9.60k | } | 
| 230 |  |  | 
| 231 |  |  | 
| 232 |  | /* | 
| 233 |  |  * Decompression startup: read start of JPEG datastream to see what's there. | 
| 234 |  |  * Need only initialize JPEG object and supply a data source before calling. | 
| 235 |  |  * | 
| 236 |  |  * This routine will read as far as the first SOS marker (ie, actual start of | 
| 237 |  |  * compressed data), and will save all tables and parameters in the JPEG | 
| 238 |  |  * object.  It will also initialize the decompression parameters to default | 
| 239 |  |  * values, and finally return JPEG_HEADER_OK.  On return, the application may | 
| 240 |  |  * adjust the decompression parameters and then call jpeg_start_decompress. | 
| 241 |  |  * (Or, if the application only wanted to determine the image parameters, | 
| 242 |  |  * the data need not be decompressed.  In that case, call jpeg_abort or | 
| 243 |  |  * jpeg_destroy to release any temporary space.) | 
| 244 |  |  * If an abbreviated (tables only) datastream is presented, the routine will | 
| 245 |  |  * return JPEG_HEADER_TABLES_ONLY upon reaching EOI.  The application may then | 
| 246 |  |  * re-use the JPEG object to read the abbreviated image datastream(s). | 
| 247 |  |  * It is unnecessary (but OK) to call jpeg_abort in this case. | 
| 248 |  |  * The JPEG_SUSPENDED return code only occurs if the data source module | 
| 249 |  |  * requests suspension of the decompressor.  In this case the application | 
| 250 |  |  * should load more source data and then re-call jpeg_read_header to resume | 
| 251 |  |  * processing. | 
| 252 |  |  * If a non-suspending data source is used and require_image is TRUE, then the | 
| 253 |  |  * return code need not be inspected since only JPEG_HEADER_OK is possible. | 
| 254 |  |  * | 
| 255 |  |  * This routine is now just a front end to jpeg_consume_input, with some | 
| 256 |  |  * extra error checking. | 
| 257 |  |  */ | 
| 258 |  |  | 
| 259 |  | GLOBAL(int) | 
| 260 |  | jpeg_read_header(j_decompress_ptr cinfo, boolean require_image) | 
| 261 | 11.0k | { | 
| 262 | 11.0k |   int retcode; | 
| 263 |  |  | 
| 264 | 11.0k |   if (cinfo->global_state != DSTATE_START && | 
| 265 | 11.0k |       cinfo->global_state != DSTATE_INHEADER) | 
| 266 | 0 |     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 
| 267 |  |  | 
| 268 | 11.0k |   retcode = jpeg_consume_input(cinfo); | 
| 269 |  |  | 
| 270 | 11.0k |   switch (retcode) { | 
| 271 | 9.60k |   case JPEG_REACHED_SOS: | 
| 272 | 9.60k |     retcode = JPEG_HEADER_OK; | 
| 273 | 9.60k |     break; | 
| 274 | 704 |   case JPEG_REACHED_EOI: | 
| 275 | 704 |     if (require_image)          /* Complain if application wanted an image */ | 
| 276 | 0 |       ERREXIT(cinfo, JERR_NO_IMAGE); | 
| 277 |  |     /* Reset to start state; it would be safer to require the application to | 
| 278 |  |      * call jpeg_abort, but we can't change it now for compatibility reasons. | 
| 279 |  |      * A side effect is to free any temporary memory (there shouldn't be any). | 
| 280 |  |      */ | 
| 281 | 704 |     jpeg_abort((j_common_ptr)cinfo); /* sets state = DSTATE_START */ | 
| 282 | 704 |     retcode = JPEG_HEADER_TABLES_ONLY; | 
| 283 | 704 |     break; | 
| 284 | 0 |   case JPEG_SUSPENDED: | 
| 285 |  |     /* no work */ | 
| 286 | 0 |     break; | 
| 287 | 11.0k |   } | 
| 288 |  |  | 
| 289 | 10.3k |   return retcode; | 
| 290 | 11.0k | } | 
| 291 |  |  | 
| 292 |  |  | 
| 293 |  | /* | 
| 294 |  |  * Consume data in advance of what the decompressor requires. | 
| 295 |  |  * This can be called at any time once the decompressor object has | 
| 296 |  |  * been created and a data source has been set up. | 
| 297 |  |  * | 
| 298 |  |  * This routine is essentially a state machine that handles a couple | 
| 299 |  |  * of critical state-transition actions, namely initial setup and | 
| 300 |  |  * transition from header scanning to ready-for-start_decompress. | 
| 301 |  |  * All the actual input is done via the input controller's consume_input | 
| 302 |  |  * method. | 
| 303 |  |  */ | 
| 304 |  |  | 
| 305 |  | GLOBAL(int) | 
| 306 |  | jpeg_consume_input(j_decompress_ptr cinfo) | 
| 307 | 11.0k | { | 
| 308 | 11.0k |   int retcode = JPEG_SUSPENDED; | 
| 309 |  |  | 
| 310 |  |   /* NB: every possible DSTATE value should be listed in this switch */ | 
| 311 | 11.0k |   switch (cinfo->global_state) { | 
| 312 | 11.0k |   case DSTATE_START: | 
| 313 |  |     /* Start-of-datastream actions: reset appropriate modules */ | 
| 314 | 11.0k |     (*cinfo->inputctl->reset_input_controller) (cinfo); | 
| 315 |  |     /* Initialize application's data source module */ | 
| 316 | 11.0k |     (*cinfo->src->init_source) (cinfo); | 
| 317 | 11.0k |     cinfo->global_state = DSTATE_INHEADER; | 
| 318 |  |     FALLTHROUGH                 /*FALLTHROUGH*/ | 
| 319 | 11.0k |   case DSTATE_INHEADER: | 
| 320 | 11.0k |     retcode = (*cinfo->inputctl->consume_input) (cinfo); | 
| 321 | 11.0k |     if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */ | 
| 322 |  |       /* Set up default parameters based on header data */ | 
| 323 | 9.60k |       default_decompress_parms(cinfo); | 
| 324 |  |       /* Set global state: ready for start_decompress */ | 
| 325 | 9.60k |       cinfo->global_state = DSTATE_READY; | 
| 326 | 9.60k |     } | 
| 327 | 11.0k |     break; | 
| 328 | 0 |   case DSTATE_READY: | 
| 329 |  |     /* Can't advance past first SOS until start_decompress is called */ | 
| 330 | 0 |     retcode = JPEG_REACHED_SOS; | 
| 331 | 0 |     break; | 
| 332 | 0 |   case DSTATE_PRELOAD: | 
| 333 | 0 |   case DSTATE_PRESCAN: | 
| 334 | 0 |   case DSTATE_SCANNING: | 
| 335 | 0 |   case DSTATE_RAW_OK: | 
| 336 | 0 |   case DSTATE_BUFIMAGE: | 
| 337 | 0 |   case DSTATE_BUFPOST: | 
| 338 | 0 |   case DSTATE_STOPPING: | 
| 339 | 0 |     retcode = (*cinfo->inputctl->consume_input) (cinfo); | 
| 340 | 0 |     break; | 
| 341 | 0 |   default: | 
| 342 | 0 |     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 
| 343 | 11.0k |   } | 
| 344 | 10.3k |   return retcode; | 
| 345 | 11.0k | } | 
| 346 |  |  | 
| 347 |  |  | 
| 348 |  | /* | 
| 349 |  |  * Have we finished reading the input file? | 
| 350 |  |  */ | 
| 351 |  |  | 
| 352 |  | GLOBAL(boolean) | 
| 353 |  | jpeg_input_complete(j_decompress_ptr cinfo) | 
| 354 | 0 | { | 
| 355 |  |   /* Check for valid jpeg object */ | 
| 356 | 0 |   if (cinfo->global_state < DSTATE_START || | 
| 357 | 0 |       cinfo->global_state > DSTATE_STOPPING) | 
| 358 | 0 |     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 
| 359 | 0 |   return cinfo->inputctl->eoi_reached; | 
| 360 | 0 | } | 
| 361 |  |  | 
| 362 |  |  | 
| 363 |  | /* | 
| 364 |  |  * Is there more than one scan? | 
| 365 |  |  */ | 
| 366 |  |  | 
| 367 |  | GLOBAL(boolean) | 
| 368 |  | jpeg_has_multiple_scans(j_decompress_ptr cinfo) | 
| 369 | 0 | { | 
| 370 |  |   /* Only valid after jpeg_read_header completes */ | 
| 371 | 0 |   if (cinfo->global_state < DSTATE_READY || | 
| 372 | 0 |       cinfo->global_state > DSTATE_STOPPING) | 
| 373 | 0 |     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 
| 374 | 0 |   return cinfo->inputctl->has_multiple_scans; | 
| 375 | 0 | } | 
| 376 |  |  | 
| 377 |  |  | 
| 378 |  | /* | 
| 379 |  |  * Finish JPEG decompression. | 
| 380 |  |  * | 
| 381 |  |  * This will normally just verify the file trailer and release temp storage. | 
| 382 |  |  * | 
| 383 |  |  * Returns FALSE if suspended.  The return value need be inspected only if | 
| 384 |  |  * a suspending data source is used. | 
| 385 |  |  */ | 
| 386 |  |  | 
| 387 |  | GLOBAL(boolean) | 
| 388 |  | jpeg_finish_decompress(j_decompress_ptr cinfo) | 
| 389 | 2.65k | { | 
| 390 | 2.65k |   if ((cinfo->global_state == DSTATE_SCANNING || | 
| 391 | 2.65k |        cinfo->global_state == DSTATE_RAW_OK) && !cinfo->buffered_image) { | 
| 392 |  |     /* Terminate final pass of non-buffered mode */ | 
| 393 | 2.65k |     if (cinfo->output_scanline < cinfo->output_height) | 
| 394 | 0 |       ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); | 
| 395 | 2.65k |     (*cinfo->master->finish_output_pass) (cinfo); | 
| 396 | 2.65k |     cinfo->global_state = DSTATE_STOPPING; | 
| 397 | 2.65k |   } else if (cinfo->global_state == DSTATE_BUFIMAGE) { | 
| 398 |  |     /* Finishing after a buffered-image operation */ | 
| 399 | 0 |     cinfo->global_state = DSTATE_STOPPING; | 
| 400 | 0 |   } else if (cinfo->global_state != DSTATE_STOPPING) { | 
| 401 |  |     /* STOPPING = repeat call after a suspension, anything else is error */ | 
| 402 | 0 |     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 
| 403 | 0 |   } | 
| 404 |  |   /* Read until EOI */ | 
| 405 | 3.30k |   while (!cinfo->inputctl->eoi_reached) { | 
| 406 | 651 |     if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) | 
| 407 | 0 |       return FALSE;             /* Suspend, come back later */ | 
| 408 | 651 |   } | 
| 409 |  |   /* Do final cleanup */ | 
| 410 | 2.65k |   (*cinfo->src->term_source) (cinfo); | 
| 411 |  |   /* We can use jpeg_abort to release memory and reset global_state */ | 
| 412 | 2.65k |   jpeg_abort((j_common_ptr)cinfo); | 
| 413 | 2.65k |   return TRUE; | 
| 414 | 2.65k | } |