mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 22:55:23 +00:00
2d0b90011e
--HG-- rename : jpeg/MOZCHANGES => media/libjpeg/MOZCHANGES rename : jpeg/Makefile.in => media/libjpeg/Makefile.in rename : jpeg/README => media/libjpeg/README rename : jpeg/README-turbo.txt => media/libjpeg/README-turbo.txt rename : jpeg/cderror.h => media/libjpeg/cderror.h rename : jpeg/cdjpeg.h => media/libjpeg/cdjpeg.h rename : jpeg/jaricom.c => media/libjpeg/jaricom.c rename : jpeg/jcapimin.c => media/libjpeg/jcapimin.c rename : jpeg/jcapistd.c => media/libjpeg/jcapistd.c rename : jpeg/jcarith.c => media/libjpeg/jcarith.c rename : jpeg/jccoefct.c => media/libjpeg/jccoefct.c rename : jpeg/jccolor.c => media/libjpeg/jccolor.c rename : jpeg/jcdctmgr.c => media/libjpeg/jcdctmgr.c rename : jpeg/jchuff.c => media/libjpeg/jchuff.c rename : jpeg/jchuff.h => media/libjpeg/jchuff.h rename : jpeg/jcinit.c => media/libjpeg/jcinit.c rename : jpeg/jcmainct.c => media/libjpeg/jcmainct.c rename : jpeg/jcmarker.c => media/libjpeg/jcmarker.c rename : jpeg/jcmaster.c => media/libjpeg/jcmaster.c rename : jpeg/jcomapi.c => media/libjpeg/jcomapi.c rename : jpeg/jconfig.h => media/libjpeg/jconfig.h rename : jpeg/jconfig.h.in => media/libjpeg/jconfig.h.in rename : jpeg/jcparam.c => media/libjpeg/jcparam.c rename : jpeg/jcphuff.c => media/libjpeg/jcphuff.c rename : jpeg/jcprepct.c => media/libjpeg/jcprepct.c rename : jpeg/jcsample.c => media/libjpeg/jcsample.c rename : jpeg/jdapimin.c => media/libjpeg/jdapimin.c rename : jpeg/jdapistd.c => media/libjpeg/jdapistd.c rename : jpeg/jdarith.c => media/libjpeg/jdarith.c rename : jpeg/jdatadst.c => media/libjpeg/jdatadst.c rename : jpeg/jdatasrc.c => media/libjpeg/jdatasrc.c rename : jpeg/jdcoefct.c => media/libjpeg/jdcoefct.c rename : jpeg/jdcolor.c => media/libjpeg/jdcolor.c rename : jpeg/jdct.h => media/libjpeg/jdct.h rename : jpeg/jddctmgr.c => media/libjpeg/jddctmgr.c rename : jpeg/jdhuff.c => media/libjpeg/jdhuff.c rename : jpeg/jdhuff.h => media/libjpeg/jdhuff.h rename : jpeg/jdinput.c => media/libjpeg/jdinput.c rename : jpeg/jdmainct.c => media/libjpeg/jdmainct.c rename : jpeg/jdmarker.c => media/libjpeg/jdmarker.c rename : jpeg/jdmaster.c => media/libjpeg/jdmaster.c rename : jpeg/jdmerge.c => media/libjpeg/jdmerge.c rename : jpeg/jdphuff.c => media/libjpeg/jdphuff.c rename : jpeg/jdpostct.c => media/libjpeg/jdpostct.c rename : jpeg/jdsample.c => media/libjpeg/jdsample.c rename : jpeg/jdtrans.c => media/libjpeg/jdtrans.c rename : jpeg/jerror.c => media/libjpeg/jerror.c rename : jpeg/jerror.h => media/libjpeg/jerror.h rename : jpeg/jfdctflt.c => media/libjpeg/jfdctflt.c rename : jpeg/jfdctfst.c => media/libjpeg/jfdctfst.c rename : jpeg/jfdctint.c => media/libjpeg/jfdctint.c rename : jpeg/jidctflt.c => media/libjpeg/jidctflt.c rename : jpeg/jidctfst.c => media/libjpeg/jidctfst.c rename : jpeg/jidctint.c => media/libjpeg/jidctint.c rename : jpeg/jidctred.c => media/libjpeg/jidctred.c rename : jpeg/jinclude.h => media/libjpeg/jinclude.h rename : jpeg/jmemmgr.c => media/libjpeg/jmemmgr.c rename : jpeg/jmemnobs.c => media/libjpeg/jmemnobs.c rename : jpeg/jmemsys.h => media/libjpeg/jmemsys.h rename : jpeg/jmorecfg.h => media/libjpeg/jmorecfg.h rename : jpeg/jpegcomp.h => media/libjpeg/jpegcomp.h rename : jpeg/jpegint.h => media/libjpeg/jpegint.h rename : jpeg/jpeglib.h => media/libjpeg/jpeglib.h rename : jpeg/jquant1.c => media/libjpeg/jquant1.c rename : jpeg/jquant2.c => media/libjpeg/jquant2.c rename : jpeg/jsimd.h => media/libjpeg/jsimd.h rename : jpeg/jsimd_none.c => media/libjpeg/jsimd_none.c rename : jpeg/jsimddct.h => media/libjpeg/jsimddct.h rename : jpeg/jutils.c => media/libjpeg/jutils.c rename : jpeg/jversion.h => media/libjpeg/jversion.h rename : jpeg/simd/Makefile.in => media/libjpeg/simd/Makefile.in rename : jpeg/simd/jcclrmmx.asm => media/libjpeg/simd/jcclrmmx.asm rename : jpeg/simd/jcclrss2-64.asm => media/libjpeg/simd/jcclrss2-64.asm rename : jpeg/simd/jcclrss2.asm => media/libjpeg/simd/jcclrss2.asm rename : jpeg/simd/jccolmmx.asm => media/libjpeg/simd/jccolmmx.asm rename : jpeg/simd/jccolss2-64.asm => media/libjpeg/simd/jccolss2-64.asm rename : jpeg/simd/jccolss2.asm => media/libjpeg/simd/jccolss2.asm rename : jpeg/simd/jcolsamp.inc => media/libjpeg/simd/jcolsamp.inc rename : jpeg/simd/jcqnt3dn.asm => media/libjpeg/simd/jcqnt3dn.asm rename : jpeg/simd/jcqntmmx.asm => media/libjpeg/simd/jcqntmmx.asm rename : jpeg/simd/jcqnts2f-64.asm => media/libjpeg/simd/jcqnts2f-64.asm rename : jpeg/simd/jcqnts2f.asm => media/libjpeg/simd/jcqnts2f.asm rename : jpeg/simd/jcqnts2i-64.asm => media/libjpeg/simd/jcqnts2i-64.asm rename : jpeg/simd/jcqnts2i.asm => media/libjpeg/simd/jcqnts2i.asm rename : jpeg/simd/jcqntsse.asm => media/libjpeg/simd/jcqntsse.asm rename : jpeg/simd/jcsammmx.asm => media/libjpeg/simd/jcsammmx.asm rename : jpeg/simd/jcsamss2-64.asm => media/libjpeg/simd/jcsamss2-64.asm rename : jpeg/simd/jcsamss2.asm => media/libjpeg/simd/jcsamss2.asm rename : jpeg/simd/jdclrmmx.asm => media/libjpeg/simd/jdclrmmx.asm rename : jpeg/simd/jdclrss2-64.asm => media/libjpeg/simd/jdclrss2-64.asm rename : jpeg/simd/jdclrss2.asm => media/libjpeg/simd/jdclrss2.asm rename : jpeg/simd/jdcolmmx.asm => media/libjpeg/simd/jdcolmmx.asm rename : jpeg/simd/jdcolss2-64.asm => media/libjpeg/simd/jdcolss2-64.asm rename : jpeg/simd/jdcolss2.asm => media/libjpeg/simd/jdcolss2.asm rename : jpeg/simd/jdct.inc => media/libjpeg/simd/jdct.inc rename : jpeg/simd/jdmermmx.asm => media/libjpeg/simd/jdmermmx.asm rename : jpeg/simd/jdmerss2-64.asm => media/libjpeg/simd/jdmerss2-64.asm rename : jpeg/simd/jdmerss2.asm => media/libjpeg/simd/jdmerss2.asm rename : jpeg/simd/jdmrgmmx.asm => media/libjpeg/simd/jdmrgmmx.asm rename : jpeg/simd/jdmrgss2-64.asm => media/libjpeg/simd/jdmrgss2-64.asm rename : jpeg/simd/jdmrgss2.asm => media/libjpeg/simd/jdmrgss2.asm rename : jpeg/simd/jdsammmx.asm => media/libjpeg/simd/jdsammmx.asm rename : jpeg/simd/jdsamss2-64.asm => media/libjpeg/simd/jdsamss2-64.asm rename : jpeg/simd/jdsamss2.asm => media/libjpeg/simd/jdsamss2.asm rename : jpeg/simd/jf3dnflt.asm => media/libjpeg/simd/jf3dnflt.asm rename : jpeg/simd/jfmmxfst.asm => media/libjpeg/simd/jfmmxfst.asm rename : jpeg/simd/jfmmxint.asm => media/libjpeg/simd/jfmmxint.asm rename : jpeg/simd/jfss2fst-64.asm => media/libjpeg/simd/jfss2fst-64.asm rename : jpeg/simd/jfss2fst.asm => media/libjpeg/simd/jfss2fst.asm rename : jpeg/simd/jfss2int-64.asm => media/libjpeg/simd/jfss2int-64.asm rename : jpeg/simd/jfss2int.asm => media/libjpeg/simd/jfss2int.asm rename : jpeg/simd/jfsseflt-64.asm => media/libjpeg/simd/jfsseflt-64.asm rename : jpeg/simd/jfsseflt.asm => media/libjpeg/simd/jfsseflt.asm rename : jpeg/simd/ji3dnflt.asm => media/libjpeg/simd/ji3dnflt.asm rename : jpeg/simd/jimmxfst.asm => media/libjpeg/simd/jimmxfst.asm rename : jpeg/simd/jimmxint.asm => media/libjpeg/simd/jimmxint.asm rename : jpeg/simd/jimmxred.asm => media/libjpeg/simd/jimmxred.asm rename : jpeg/simd/jiss2flt-64.asm => media/libjpeg/simd/jiss2flt-64.asm rename : jpeg/simd/jiss2flt.asm => media/libjpeg/simd/jiss2flt.asm rename : jpeg/simd/jiss2fst-64.asm => media/libjpeg/simd/jiss2fst-64.asm rename : jpeg/simd/jiss2fst.asm => media/libjpeg/simd/jiss2fst.asm rename : jpeg/simd/jiss2int-64.asm => media/libjpeg/simd/jiss2int-64.asm rename : jpeg/simd/jiss2int.asm => media/libjpeg/simd/jiss2int.asm rename : jpeg/simd/jiss2red-64.asm => media/libjpeg/simd/jiss2red-64.asm rename : jpeg/simd/jiss2red.asm => media/libjpeg/simd/jiss2red.asm rename : jpeg/simd/jisseflt.asm => media/libjpeg/simd/jisseflt.asm rename : jpeg/simd/jsimd.h => media/libjpeg/simd/jsimd.h rename : jpeg/simd/jsimd_i386.c => media/libjpeg/simd/jsimd_i386.c rename : jpeg/simd/jsimd_x86_64.c => media/libjpeg/simd/jsimd_x86_64.c rename : jpeg/simd/jsimdcfg.inc => media/libjpeg/simd/jsimdcfg.inc rename : jpeg/simd/jsimdcfg.inc.h => media/libjpeg/simd/jsimdcfg.inc.h rename : jpeg/simd/jsimdcpu.asm => media/libjpeg/simd/jsimdcpu.asm rename : jpeg/simd/jsimdext.inc => media/libjpeg/simd/jsimdext.inc rename : jpeg/transupp.h => media/libjpeg/transupp.h
396 lines
12 KiB
C
396 lines
12 KiB
C
/*
|
|
* jdapimin.c
|
|
*
|
|
* Copyright (C) 1994-1998, Thomas G. Lane.
|
|
* This file is part of the Independent JPEG Group's software.
|
|
* For conditions of distribution and use, see the accompanying README file.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#define JPEG_INTERNALS
|
|
#include "jinclude.h"
|
|
#include "jpeglib.h"
|
|
|
|
|
|
/*
|
|
* Initialization of a JPEG decompression object.
|
|
* The error manager must already be set up (in case memory manager fails).
|
|
*/
|
|
|
|
GLOBAL(void)
|
|
jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
|
|
{
|
|
int i;
|
|
|
|
/* Guard against version mismatches between library and caller. */
|
|
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
|
|
if (version != JPEG_LIB_VERSION)
|
|
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
|
|
if (structsize != SIZEOF(struct jpeg_decompress_struct))
|
|
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
|
|
(int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
|
|
|
|
/* 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.
|
|
*/
|
|
{
|
|
struct jpeg_error_mgr * err = cinfo->err;
|
|
void * client_data = cinfo->client_data; /* ignore Purify complaint here */
|
|
MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
|
|
cinfo->err = err;
|
|
cinfo->client_data = client_data;
|
|
}
|
|
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.
|
|
*/
|
|
cinfo->marker_list = NULL;
|
|
jinit_marker_reader(cinfo);
|
|
|
|
/* And initialize the overall input controller. */
|
|
jinit_input_controller(cinfo);
|
|
|
|
/* OK, I'm ready */
|
|
cinfo->global_state = DSTATE_START;
|
|
}
|
|
|
|
|
|
/*
|
|
* Destruction of a JPEG decompression object
|
|
*/
|
|
|
|
GLOBAL(void)
|
|
jpeg_destroy_decompress (j_decompress_ptr cinfo)
|
|
{
|
|
jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
|
|
}
|
|
|
|
|
|
/*
|
|
* Abort processing of a JPEG decompression operation,
|
|
* but don't destroy the object itself.
|
|
*/
|
|
|
|
GLOBAL(void)
|
|
jpeg_abort_decompress (j_decompress_ptr cinfo)
|
|
{
|
|
jpeg_abort((j_common_ptr) cinfo); /* use common routine */
|
|
}
|
|
|
|
|
|
/*
|
|
* Set default decompression parameters.
|
|
*/
|
|
|
|
LOCAL(void)
|
|
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;
|
|
|
|
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:
|
|
cinfo->jpeg_color_space = JCS_RGB;
|
|
break;
|
|
case 1:
|
|
cinfo->jpeg_color_space = JCS_YCbCr;
|
|
break;
|
|
default:
|
|
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
|
|
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
|
|
break;
|
|
}
|
|
} 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)
|
|
cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
|
|
else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
|
|
cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
|
|
else {
|
|
TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
|
|
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
|
|
}
|
|
}
|
|
/* Always guess RGB is proper output colorspace. */
|
|
cinfo->out_color_space = JCS_RGB;
|
|
break;
|
|
|
|
case 4:
|
|
if (cinfo->saw_Adobe_marker) {
|
|
switch (cinfo->Adobe_transform) {
|
|
case 0:
|
|
cinfo->jpeg_color_space = JCS_CMYK;
|
|
break;
|
|
case 2:
|
|
cinfo->jpeg_color_space = JCS_YCCK;
|
|
break;
|
|
default:
|
|
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
|
|
cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
|
|
break;
|
|
}
|
|
} else {
|
|
/* No special markers, assume straight CMYK. */
|
|
cinfo->jpeg_color_space = JCS_CMYK;
|
|
}
|
|
cinfo->out_color_space = JCS_CMYK;
|
|
break;
|
|
|
|
default:
|
|
cinfo->jpeg_color_space = JCS_UNKNOWN;
|
|
cinfo->out_color_space = JCS_UNKNOWN;
|
|
break;
|
|
}
|
|
|
|
/* Set defaults for other decompression parameters. */
|
|
cinfo->scale_num = 1; /* 1:1 scaling */
|
|
cinfo->scale_denom = 1;
|
|
cinfo->output_gamma = 1.0;
|
|
cinfo->buffered_image = FALSE;
|
|
cinfo->raw_data_out = FALSE;
|
|
cinfo->dct_method = JDCT_DEFAULT;
|
|
cinfo->do_fancy_upsampling = TRUE;
|
|
cinfo->do_block_smoothing = TRUE;
|
|
cinfo->quantize_colors = FALSE;
|
|
/* We set these in case application only sets quantize_colors. */
|
|
cinfo->dither_mode = JDITHER_FS;
|
|
#ifdef QUANT_2PASS_SUPPORTED
|
|
cinfo->two_pass_quantize = TRUE;
|
|
#else
|
|
cinfo->two_pass_quantize = FALSE;
|
|
#endif
|
|
cinfo->desired_number_of_colors = 256;
|
|
cinfo->colormap = NULL;
|
|
/* Initialize for no mode change in buffered-image mode. */
|
|
cinfo->enable_1pass_quant = FALSE;
|
|
cinfo->enable_external_quant = FALSE;
|
|
cinfo->enable_2pass_quant = FALSE;
|
|
}
|
|
|
|
|
|
/*
|
|
* 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.
|
|
*
|
|
* This routine is now just a front end to jpeg_consume_input, with some
|
|
* extra error checking.
|
|
*/
|
|
|
|
GLOBAL(int)
|
|
jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
|
|
{
|
|
int retcode;
|
|
|
|
if (cinfo->global_state != DSTATE_START &&
|
|
cinfo->global_state != DSTATE_INHEADER)
|
|
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
|
|
|
retcode = jpeg_consume_input(cinfo);
|
|
|
|
switch (retcode) {
|
|
case JPEG_REACHED_SOS:
|
|
retcode = JPEG_HEADER_OK;
|
|
break;
|
|
case JPEG_REACHED_EOI:
|
|
if (require_image) /* Complain if application wanted an image */
|
|
ERREXIT(cinfo, JERR_NO_IMAGE);
|
|
/* 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).
|
|
*/
|
|
jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
|
|
retcode = JPEG_HEADER_TABLES_ONLY;
|
|
break;
|
|
case JPEG_SUSPENDED:
|
|
/* no work */
|
|
break;
|
|
}
|
|
|
|
return retcode;
|
|
}
|
|
|
|
|
|
/*
|
|
* 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.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
GLOBAL(int)
|
|
jpeg_consume_input (j_decompress_ptr cinfo)
|
|
{
|
|
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;
|
|
/*FALLTHROUGH*/
|
|
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;
|
|
}
|
|
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);
|
|
}
|
|
return retcode;
|
|
}
|
|
|
|
|
|
/*
|
|
* Have we finished reading the input file?
|
|
*/
|
|
|
|
GLOBAL(boolean)
|
|
jpeg_input_complete (j_decompress_ptr cinfo)
|
|
{
|
|
/* Check for valid jpeg object */
|
|
if (cinfo->global_state < DSTATE_START ||
|
|
cinfo->global_state > DSTATE_STOPPING)
|
|
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
|
return cinfo->inputctl->eoi_reached;
|
|
}
|
|
|
|
|
|
/*
|
|
* Is there more than one scan?
|
|
*/
|
|
|
|
GLOBAL(boolean)
|
|
jpeg_has_multiple_scans (j_decompress_ptr cinfo)
|
|
{
|
|
/* Only valid after jpeg_read_header completes */
|
|
if (cinfo->global_state < DSTATE_READY ||
|
|
cinfo->global_state > DSTATE_STOPPING)
|
|
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
|
return cinfo->inputctl->has_multiple_scans;
|
|
}
|
|
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
|
|
GLOBAL(boolean)
|
|
jpeg_finish_decompress (j_decompress_ptr cinfo)
|
|
{
|
|
if ((cinfo->global_state == DSTATE_SCANNING ||
|
|
cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
|
|
/* Terminate final pass of non-buffered mode */
|
|
if (cinfo->output_scanline < cinfo->output_height)
|
|
ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
|
|
(*cinfo->master->finish_output_pass) (cinfo);
|
|
cinfo->global_state = DSTATE_STOPPING;
|
|
} else if (cinfo->global_state == DSTATE_BUFIMAGE) {
|
|
/* Finishing after a buffered-image operation */
|
|
cinfo->global_state = DSTATE_STOPPING;
|
|
} else if (cinfo->global_state != DSTATE_STOPPING) {
|
|
/* STOPPING = repeat call after a suspension, anything else is error */
|
|
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
|
}
|
|
/* Read until EOI */
|
|
while (! cinfo->inputctl->eoi_reached) {
|
|
if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
|
|
return FALSE; /* Suspend, come back later */
|
|
}
|
|
/* 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;
|
|
}
|