1994-09-24 04:00:00 +04:00
|
|
|
/*
|
1995-08-02 04:00:00 +04:00
|
|
|
* jdapimin.c
|
1994-09-24 04:00:00 +04:00
|
|
|
*
|
2014-05-18 23:04:03 +04:00
|
|
|
* This file was part of the Independent JPEG Group's software:
|
1998-03-27 03:00:00 +03:00
|
|
|
* Copyright (C) 1994-1998, Thomas G. Lane.
|
2016-02-20 03:32:10 +03:00
|
|
|
* libjpeg-turbo Modifications:
|
2022-01-06 18:17:30 +03:00
|
|
|
* Copyright (C) 2016, 2022, D. R. Commander.
|
2015-10-10 18:25:46 +03:00
|
|
|
* For conditions of distribution and use, see the accompanying README.ijg
|
|
|
|
* file.
|
1994-09-24 04:00:00 +04:00
|
|
|
*
|
1995-08-02 04:00:00 +04:00
|
|
|
* This file contains application interface code for the decompression half
|
|
|
|
* of the JPEG library. These are the "minimum" API routines that may be
|
|
|
|
* needed in either the normal full-decompression case or the
|
|
|
|
* transcoding-only case.
|
|
|
|
*
|
|
|
|
* Most of the routines intended to be called directly by an application
|
|
|
|
* are in this file or in jdapistd.c. But also see jcomapi.c for routines
|
|
|
|
* shared by compression and decompression, and jdtrans.c for the transcoding
|
|
|
|
* case.
|
1994-09-24 04:00:00 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define JPEG_INTERNALS
|
|
|
|
#include "jinclude.h"
|
|
|
|
#include "jpeglib.h"
|
2016-02-20 03:32:10 +03:00
|
|
|
#include "jdmaster.h"
|
1994-09-24 04:00:00 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization of a JPEG decompression object.
|
|
|
|
* The error manager must already be set up (in case memory manager fails).
|
|
|
|
*/
|
|
|
|
|
1996-02-08 03:00:00 +03:00
|
|
|
GLOBAL(void)
|
|
|
|
jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
|
1994-09-24 04:00:00 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1996-02-08 03:00:00 +03:00
|
|
|
/* Guard against version mismatches between library and caller. */
|
2014-05-09 22:00:32 +04:00
|
|
|
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
|
1996-02-08 03:00:00 +03:00
|
|
|
if (version != JPEG_LIB_VERSION)
|
|
|
|
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
|
2014-05-18 23:04:03 +04:00
|
|
|
if (structsize != sizeof(struct jpeg_decompress_struct))
|
2014-05-09 22:00:32 +04:00
|
|
|
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
|
2014-05-18 23:04:03 +04:00
|
|
|
(int) sizeof(struct jpeg_decompress_struct), (int) structsize);
|
1996-02-08 03:00:00 +03:00
|
|
|
|
1998-03-27 03:00:00 +03:00
|
|
|
/* For debugging purposes, we zero the whole master structure.
|
|
|
|
* But the application has already set the err pointer, and may have set
|
|
|
|
* client_data, so we have to save and restore those fields.
|
|
|
|
* Note: if application hasn't set client_data, tools like Purify may
|
|
|
|
* complain here.
|
1994-09-24 04:00:00 +04:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
struct jpeg_error_mgr * err = cinfo->err;
|
1998-03-27 03:00:00 +03:00
|
|
|
void * client_data = cinfo->client_data; /* ignore Purify complaint here */
|
2022-01-06 18:17:30 +03:00
|
|
|
memset(cinfo, 0, sizeof(struct jpeg_decompress_struct));
|
1994-09-24 04:00:00 +04:00
|
|
|
cinfo->err = err;
|
1998-03-27 03:00:00 +03:00
|
|
|
cinfo->client_data = client_data;
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
cinfo->is_decompressor = TRUE;
|
|
|
|
|
|
|
|
/* Initialize a memory manager instance for this object */
|
|
|
|
jinit_memory_mgr((j_common_ptr) cinfo);
|
|
|
|
|
|
|
|
/* Zero out pointers to permanent structures. */
|
|
|
|
cinfo->progress = NULL;
|
|
|
|
cinfo->src = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_QUANT_TBLS; i++)
|
|
|
|
cinfo->quant_tbl_ptrs[i] = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
|
|
|
cinfo->dc_huff_tbl_ptrs[i] = NULL;
|
|
|
|
cinfo->ac_huff_tbl_ptrs[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize marker processor so application can override methods
|
|
|
|
* for COM, APPn markers before calling jpeg_read_header.
|
|
|
|
*/
|
1998-03-27 03:00:00 +03:00
|
|
|
cinfo->marker_list = NULL;
|
1994-09-24 04:00:00 +04:00
|
|
|
jinit_marker_reader(cinfo);
|
|
|
|
|
1995-08-02 04:00:00 +04:00
|
|
|
/* And initialize the overall input controller. */
|
|
|
|
jinit_input_controller(cinfo);
|
|
|
|
|
1994-09-24 04:00:00 +04:00
|
|
|
/* OK, I'm ready */
|
|
|
|
cinfo->global_state = DSTATE_START;
|
2016-02-20 03:32:10 +03:00
|
|
|
|
|
|
|
/* The master struct is used to store extension parameters, so we allocate it
|
|
|
|
* here.
|
|
|
|
*/
|
|
|
|
cinfo->master = (struct jpeg_decomp_master *)
|
|
|
|
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
Improve code formatting consistency
With rare exceptions ...
- Always separate line continuation characters by one space from
preceding code.
- Always use two-space indentation. Never use tabs.
- Always use K&R-style conditional blocks.
- Always surround operators with spaces, except in raw assembly code.
- Always put a space after, but not before, a comma.
- Never put a space between type casts and variables/function calls.
- Never put a space between the function name and the argument list in
function declarations and prototypes.
- Always surround braces ('{' and '}') with spaces.
- Always surround statements (if, for, else, catch, while, do, switch)
with spaces.
- Always attach pointer symbols ('*' and '**') to the variable or
function name.
- Always precede pointer symbols ('*' and '**') by a space in type
casts.
- Use the MIN() macro from jpegint.h within the libjpeg and TurboJPEG
API libraries (using min() from tjutil.h is still necessary for
TJBench.)
- Where it makes sense (particularly in the TurboJPEG code), put a blank
line after variable declaration blocks.
- Always separate statements in one-liners by two spaces.
The purpose of this was to ease maintenance on my part and also to make
it easier for contributors to figure out how to format patch
submissions. This was admittedly confusing (even to me sometimes) when
we had 3 or 4 different style conventions in the same source tree. The
new convention is more consistent with the formatting of other OSS code
bases.
This commit corrects deviations from the chosen formatting style in the
libjpeg API code and reformats the TurboJPEG API code such that it
conforms to the same standard.
NOTES:
- Although it is no longer necessary for the function name in function
declarations to begin in Column 1 (this was historically necessary
because of the ansi2knr utility, which allowed libjpeg to be built
with non-ANSI compilers), we retain that formatting for the libjpeg
code because it improves readability when using libjpeg's function
attribute macros (GLOBAL(), etc.)
- This reformatting project was accomplished with the help of AStyle and
Uncrustify, although neither was completely up to the task, and thus
a great deal of manual tweaking was required. Note to developers of
code formatting utilities: the libjpeg-turbo code base is an
excellent test bed, because AFAICT, it breaks every single one of the
utilities that are currently available.
- The legacy (MMX, SSE, 3DNow!) assembly code for i386 has been
formatted to match the SSE2 code (refer to
ff5685d5344273df321eb63a005eaae19d2496e3.) I hadn't intended to
bother with this, but the Loongson MMI implementation demonstrated
that there is still academic value to the MMX implementation, as an
algorithmic model for other 64-bit vector implementations. Thus, it
is desirable to improve its readability in the same manner as that of
the SSE2 implementation.
2018-03-08 19:55:20 +03:00
|
|
|
sizeof(my_decomp_master));
|
2022-01-06 18:17:30 +03:00
|
|
|
memset(cinfo->master, 0, sizeof(my_decomp_master));
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destruction of a JPEG decompression object
|
|
|
|
*/
|
|
|
|
|
1996-02-08 03:00:00 +03:00
|
|
|
GLOBAL(void)
|
1994-09-24 04:00:00 +04:00
|
|
|
jpeg_destroy_decompress (j_decompress_ptr cinfo)
|
|
|
|
{
|
|
|
|
jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-08-02 04:00:00 +04:00
|
|
|
/*
|
|
|
|
* Abort processing of a JPEG decompression operation,
|
|
|
|
* but don't destroy the object itself.
|
|
|
|
*/
|
|
|
|
|
1996-02-08 03:00:00 +03:00
|
|
|
GLOBAL(void)
|
1995-08-02 04:00:00 +04:00
|
|
|
jpeg_abort_decompress (j_decompress_ptr cinfo)
|
|
|
|
{
|
|
|
|
jpeg_abort((j_common_ptr) cinfo); /* use common routine */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-09-24 04:00:00 +04:00
|
|
|
/*
|
|
|
|
* Set default decompression parameters.
|
|
|
|
*/
|
|
|
|
|
1996-02-08 03:00:00 +03:00
|
|
|
LOCAL(void)
|
1994-09-24 04:00:00 +04:00
|
|
|
default_decompress_parms (j_decompress_ptr cinfo)
|
|
|
|
{
|
|
|
|
/* Guess the input colorspace, and set output colorspace accordingly. */
|
|
|
|
/* (Wish JPEG committee had provided a real way to specify this...) */
|
|
|
|
/* Note application may override our guesses. */
|
|
|
|
switch (cinfo->num_components) {
|
|
|
|
case 1:
|
|
|
|
cinfo->jpeg_color_space = JCS_GRAYSCALE;
|
|
|
|
cinfo->out_color_space = JCS_GRAYSCALE;
|
|
|
|
break;
|
2014-05-09 22:00:32 +04:00
|
|
|
|
1994-09-24 04:00:00 +04:00
|
|
|
case 3:
|
|
|
|
if (cinfo->saw_JFIF_marker) {
|
|
|
|
cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
|
|
|
|
} else if (cinfo->saw_Adobe_marker) {
|
|
|
|
switch (cinfo->Adobe_transform) {
|
|
|
|
case 0:
|
2014-05-09 22:00:32 +04:00
|
|
|
cinfo->jpeg_color_space = JCS_RGB;
|
|
|
|
break;
|
1994-09-24 04:00:00 +04:00
|
|
|
case 1:
|
2014-05-09 22:00:32 +04:00
|
|
|
cinfo->jpeg_color_space = JCS_YCbCr;
|
|
|
|
break;
|
1994-09-24 04:00:00 +04:00
|
|
|
default:
|
2014-05-09 22:00:32 +04:00
|
|
|
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
|
|
|
|
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
|
|
|
|
break;
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Saw no special markers, try to guess from the component IDs */
|
|
|
|
int cid0 = cinfo->comp_info[0].component_id;
|
|
|
|
int cid1 = cinfo->comp_info[1].component_id;
|
|
|
|
int cid2 = cinfo->comp_info[2].component_id;
|
|
|
|
|
|
|
|
if (cid0 == 1 && cid1 == 2 && cid2 == 3)
|
2014-05-09 22:00:32 +04:00
|
|
|
cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
|
1994-09-24 04:00:00 +04:00
|
|
|
else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
|
2014-05-09 22:00:32 +04:00
|
|
|
cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
|
1994-09-24 04:00:00 +04:00
|
|
|
else {
|
2014-05-09 22:00:32 +04:00
|
|
|
TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
|
|
|
|
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Always guess RGB is proper output colorspace. */
|
|
|
|
cinfo->out_color_space = JCS_RGB;
|
|
|
|
break;
|
2014-05-09 22:00:32 +04:00
|
|
|
|
1994-09-24 04:00:00 +04:00
|
|
|
case 4:
|
|
|
|
if (cinfo->saw_Adobe_marker) {
|
|
|
|
switch (cinfo->Adobe_transform) {
|
|
|
|
case 0:
|
2014-05-09 22:00:32 +04:00
|
|
|
cinfo->jpeg_color_space = JCS_CMYK;
|
|
|
|
break;
|
1994-09-24 04:00:00 +04:00
|
|
|
case 2:
|
2014-05-09 22:00:32 +04:00
|
|
|
cinfo->jpeg_color_space = JCS_YCCK;
|
|
|
|
break;
|
1994-09-24 04:00:00 +04:00
|
|
|
default:
|
2014-05-09 22:00:32 +04:00
|
|
|
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
|
|
|
|
cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
|
|
|
|
break;
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* No special markers, assume straight CMYK. */
|
|
|
|
cinfo->jpeg_color_space = JCS_CMYK;
|
|
|
|
}
|
|
|
|
cinfo->out_color_space = JCS_CMYK;
|
|
|
|
break;
|
2014-05-09 22:00:32 +04:00
|
|
|
|
1994-09-24 04:00:00 +04:00
|
|
|
default:
|
|
|
|
cinfo->jpeg_color_space = JCS_UNKNOWN;
|
|
|
|
cinfo->out_color_space = JCS_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set defaults for other decompression parameters. */
|
2014-05-09 22:00:32 +04:00
|
|
|
cinfo->scale_num = 1; /* 1:1 scaling */
|
1994-09-24 04:00:00 +04:00
|
|
|
cinfo->scale_denom = 1;
|
|
|
|
cinfo->output_gamma = 1.0;
|
1995-08-02 04:00:00 +04:00
|
|
|
cinfo->buffered_image = FALSE;
|
1994-09-24 04:00:00 +04:00
|
|
|
cinfo->raw_data_out = FALSE;
|
1995-08-02 04:00:00 +04:00
|
|
|
cinfo->dct_method = JDCT_DEFAULT;
|
|
|
|
cinfo->do_fancy_upsampling = TRUE;
|
|
|
|
cinfo->do_block_smoothing = TRUE;
|
1994-09-24 04:00:00 +04:00
|
|
|
cinfo->quantize_colors = FALSE;
|
|
|
|
/* We set these in case application only sets quantize_colors. */
|
|
|
|
cinfo->dither_mode = JDITHER_FS;
|
1995-08-02 04:00:00 +04:00
|
|
|
#ifdef QUANT_2PASS_SUPPORTED
|
|
|
|
cinfo->two_pass_quantize = TRUE;
|
|
|
|
#else
|
|
|
|
cinfo->two_pass_quantize = FALSE;
|
|
|
|
#endif
|
1994-09-24 04:00:00 +04:00
|
|
|
cinfo->desired_number_of_colors = 256;
|
|
|
|
cinfo->colormap = NULL;
|
1995-08-02 04:00:00 +04:00
|
|
|
/* Initialize for no mode change in buffered-image mode. */
|
|
|
|
cinfo->enable_1pass_quant = FALSE;
|
|
|
|
cinfo->enable_external_quant = FALSE;
|
|
|
|
cinfo->enable_2pass_quant = FALSE;
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decompression startup: read start of JPEG datastream to see what's there.
|
|
|
|
* Need only initialize JPEG object and supply a data source before calling.
|
|
|
|
*
|
|
|
|
* This routine will read as far as the first SOS marker (ie, actual start of
|
|
|
|
* compressed data), and will save all tables and parameters in the JPEG
|
|
|
|
* object. It will also initialize the decompression parameters to default
|
|
|
|
* values, and finally return JPEG_HEADER_OK. On return, the application may
|
|
|
|
* adjust the decompression parameters and then call jpeg_start_decompress.
|
|
|
|
* (Or, if the application only wanted to determine the image parameters,
|
|
|
|
* the data need not be decompressed. In that case, call jpeg_abort or
|
|
|
|
* jpeg_destroy to release any temporary space.)
|
|
|
|
* If an abbreviated (tables only) datastream is presented, the routine will
|
|
|
|
* return JPEG_HEADER_TABLES_ONLY upon reaching EOI. The application may then
|
|
|
|
* re-use the JPEG object to read the abbreviated image datastream(s).
|
|
|
|
* It is unnecessary (but OK) to call jpeg_abort in this case.
|
|
|
|
* The JPEG_SUSPENDED return code only occurs if the data source module
|
|
|
|
* requests suspension of the decompressor. In this case the application
|
|
|
|
* should load more source data and then re-call jpeg_read_header to resume
|
|
|
|
* processing.
|
|
|
|
* If a non-suspending data source is used and require_image is TRUE, then the
|
|
|
|
* return code need not be inspected since only JPEG_HEADER_OK is possible.
|
1995-08-02 04:00:00 +04:00
|
|
|
*
|
|
|
|
* This routine is now just a front end to jpeg_consume_input, with some
|
|
|
|
* extra error checking.
|
1994-09-24 04:00:00 +04:00
|
|
|
*/
|
|
|
|
|
1996-02-08 03:00:00 +03:00
|
|
|
GLOBAL(int)
|
1994-09-24 04:00:00 +04:00
|
|
|
jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
|
|
|
|
{
|
|
|
|
int retcode;
|
|
|
|
|
1995-08-02 04:00:00 +04:00
|
|
|
if (cinfo->global_state != DSTATE_START &&
|
|
|
|
cinfo->global_state != DSTATE_INHEADER)
|
1994-09-24 04:00:00 +04:00
|
|
|
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
|
|
|
|
1995-08-02 04:00:00 +04:00
|
|
|
retcode = jpeg_consume_input(cinfo);
|
1994-09-24 04:00:00 +04:00
|
|
|
|
|
|
|
switch (retcode) {
|
1995-08-02 04:00:00 +04:00
|
|
|
case JPEG_REACHED_SOS:
|
|
|
|
retcode = JPEG_HEADER_OK;
|
1994-09-24 04:00:00 +04:00
|
|
|
break;
|
1995-08-02 04:00:00 +04:00
|
|
|
case JPEG_REACHED_EOI:
|
2014-05-09 22:00:32 +04:00
|
|
|
if (require_image) /* Complain if application wanted an image */
|
1994-09-24 04:00:00 +04:00
|
|
|
ERREXIT(cinfo, JERR_NO_IMAGE);
|
1995-08-02 04:00:00 +04:00
|
|
|
/* Reset to start state; it would be safer to require the application to
|
|
|
|
* call jpeg_abort, but we can't change it now for compatibility reasons.
|
|
|
|
* A side effect is to free any temporary memory (there shouldn't be any).
|
1994-09-24 04:00:00 +04:00
|
|
|
*/
|
1995-08-02 04:00:00 +04:00
|
|
|
jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
|
|
|
|
retcode = JPEG_HEADER_TABLES_ONLY;
|
1994-09-24 04:00:00 +04:00
|
|
|
break;
|
1995-08-02 04:00:00 +04:00
|
|
|
case JPEG_SUSPENDED:
|
1994-09-24 04:00:00 +04:00
|
|
|
/* no work */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1995-08-02 04:00:00 +04:00
|
|
|
* Consume data in advance of what the decompressor requires.
|
|
|
|
* This can be called at any time once the decompressor object has
|
|
|
|
* been created and a data source has been set up.
|
1994-09-24 04:00:00 +04:00
|
|
|
*
|
1995-08-02 04:00:00 +04:00
|
|
|
* This routine is essentially a state machine that handles a couple
|
|
|
|
* of critical state-transition actions, namely initial setup and
|
|
|
|
* transition from header scanning to ready-for-start_decompress.
|
|
|
|
* All the actual input is done via the input controller's consume_input
|
|
|
|
* method.
|
1994-09-24 04:00:00 +04:00
|
|
|
*/
|
|
|
|
|
1996-02-08 03:00:00 +03:00
|
|
|
GLOBAL(int)
|
1995-08-02 04:00:00 +04:00
|
|
|
jpeg_consume_input (j_decompress_ptr cinfo)
|
1994-09-24 04:00:00 +04:00
|
|
|
{
|
1995-08-02 04:00:00 +04:00
|
|
|
int retcode = JPEG_SUSPENDED;
|
|
|
|
|
|
|
|
/* NB: every possible DSTATE value should be listed in this switch */
|
|
|
|
switch (cinfo->global_state) {
|
|
|
|
case DSTATE_START:
|
|
|
|
/* Start-of-datastream actions: reset appropriate modules */
|
|
|
|
(*cinfo->inputctl->reset_input_controller) (cinfo);
|
|
|
|
/* Initialize application's data source module */
|
|
|
|
(*cinfo->src->init_source) (cinfo);
|
|
|
|
cinfo->global_state = DSTATE_INHEADER;
|
2021-06-27 02:22:21 +03:00
|
|
|
FALLTHROUGH /*FALLTHROUGH*/
|
1995-08-02 04:00:00 +04:00
|
|
|
case DSTATE_INHEADER:
|
|
|
|
retcode = (*cinfo->inputctl->consume_input) (cinfo);
|
|
|
|
if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
|
|
|
|
/* Set up default parameters based on header data */
|
|
|
|
default_decompress_parms(cinfo);
|
|
|
|
/* Set global state: ready for start_decompress */
|
|
|
|
cinfo->global_state = DSTATE_READY;
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
1995-08-02 04:00:00 +04:00
|
|
|
break;
|
|
|
|
case DSTATE_READY:
|
|
|
|
/* Can't advance past first SOS until start_decompress is called */
|
|
|
|
retcode = JPEG_REACHED_SOS;
|
|
|
|
break;
|
|
|
|
case DSTATE_PRELOAD:
|
|
|
|
case DSTATE_PRESCAN:
|
|
|
|
case DSTATE_SCANNING:
|
|
|
|
case DSTATE_RAW_OK:
|
|
|
|
case DSTATE_BUFIMAGE:
|
|
|
|
case DSTATE_BUFPOST:
|
|
|
|
case DSTATE_STOPPING:
|
|
|
|
retcode = (*cinfo->inputctl->consume_input) (cinfo);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
1995-08-02 04:00:00 +04:00
|
|
|
return retcode;
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1995-08-02 04:00:00 +04:00
|
|
|
* Have we finished reading the input file?
|
1994-09-24 04:00:00 +04:00
|
|
|
*/
|
|
|
|
|
1996-02-08 03:00:00 +03:00
|
|
|
GLOBAL(boolean)
|
2015-01-24 19:27:46 +03:00
|
|
|
jpeg_input_complete (const j_decompress_ptr cinfo)
|
1994-09-24 04:00:00 +04:00
|
|
|
{
|
1995-08-02 04:00:00 +04:00
|
|
|
/* Check for valid jpeg object */
|
|
|
|
if (cinfo->global_state < DSTATE_START ||
|
|
|
|
cinfo->global_state > DSTATE_STOPPING)
|
1994-09-24 04:00:00 +04:00
|
|
|
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
1995-08-02 04:00:00 +04:00
|
|
|
return cinfo->inputctl->eoi_reached;
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1995-08-02 04:00:00 +04:00
|
|
|
* Is there more than one scan?
|
1994-09-24 04:00:00 +04:00
|
|
|
*/
|
|
|
|
|
1996-02-08 03:00:00 +03:00
|
|
|
GLOBAL(boolean)
|
2015-01-24 19:27:46 +03:00
|
|
|
jpeg_has_multiple_scans (const j_decompress_ptr cinfo)
|
1994-09-24 04:00:00 +04:00
|
|
|
{
|
1995-08-02 04:00:00 +04:00
|
|
|
/* Only valid after jpeg_read_header completes */
|
|
|
|
if (cinfo->global_state < DSTATE_READY ||
|
|
|
|
cinfo->global_state > DSTATE_STOPPING)
|
1994-09-24 04:00:00 +04:00
|
|
|
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
1995-08-02 04:00:00 +04:00
|
|
|
return cinfo->inputctl->has_multiple_scans;
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finish JPEG decompression.
|
|
|
|
*
|
|
|
|
* This will normally just verify the file trailer and release temp storage.
|
|
|
|
*
|
|
|
|
* Returns FALSE if suspended. The return value need be inspected only if
|
|
|
|
* a suspending data source is used.
|
|
|
|
*/
|
|
|
|
|
1996-02-08 03:00:00 +03:00
|
|
|
GLOBAL(boolean)
|
1994-09-24 04:00:00 +04:00
|
|
|
jpeg_finish_decompress (j_decompress_ptr cinfo)
|
|
|
|
{
|
1995-08-02 04:00:00 +04:00
|
|
|
if ((cinfo->global_state == DSTATE_SCANNING ||
|
|
|
|
cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
|
|
|
|
/* Terminate final pass of non-buffered mode */
|
1994-09-24 04:00:00 +04:00
|
|
|
if (cinfo->output_scanline < cinfo->output_height)
|
|
|
|
ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
|
1995-08-02 04:00:00 +04:00
|
|
|
(*cinfo->master->finish_output_pass) (cinfo);
|
|
|
|
cinfo->global_state = DSTATE_STOPPING;
|
|
|
|
} else if (cinfo->global_state == DSTATE_BUFIMAGE) {
|
|
|
|
/* Finishing after a buffered-image operation */
|
1994-09-24 04:00:00 +04:00
|
|
|
cinfo->global_state = DSTATE_STOPPING;
|
|
|
|
} else if (cinfo->global_state != DSTATE_STOPPING) {
|
1995-08-02 04:00:00 +04:00
|
|
|
/* STOPPING = repeat call after a suspension, anything else is error */
|
1994-09-24 04:00:00 +04:00
|
|
|
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
|
|
|
}
|
1995-08-02 04:00:00 +04:00
|
|
|
/* Read until EOI */
|
|
|
|
while (! cinfo->inputctl->eoi_reached) {
|
|
|
|
if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
|
2014-05-09 22:00:32 +04:00
|
|
|
return FALSE; /* Suspend, come back later */
|
1994-09-24 04:00:00 +04:00
|
|
|
}
|
|
|
|
/* Do final cleanup */
|
|
|
|
(*cinfo->src->term_source) (cinfo);
|
|
|
|
/* We can use jpeg_abort to release memory and reset global_state */
|
|
|
|
jpeg_abort((j_common_ptr) cinfo);
|
|
|
|
return TRUE;
|
|
|
|
}
|