Final 350 project

Dependencies:   uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed

Committer:
shoaib_ahmed
Date:
Mon Jul 31 09:16:35 2017 +0000
Revision:
0:791a779d6220
final project;

Who changed what in which revision?

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