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