summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/libjpeg/jdapimin.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libjpeg/jdapimin.c')
-rw-r--r--src/lib/libjpeg/jdapimin.c450
1 files changed, 225 insertions, 225 deletions
diff --git a/src/lib/libjpeg/jdapimin.c b/src/lib/libjpeg/jdapimin.c
index 8b4032b7f07..4c9520aba97 100644
--- a/src/lib/libjpeg/jdapimin.c
+++ b/src/lib/libjpeg/jdapimin.c
@@ -30,57 +30,57 @@
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;
+ 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;
}
@@ -91,7 +91,7 @@ jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
GLOBAL(void)
jpeg_destroy_decompress (j_decompress_ptr cinfo)
{
- jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
+ jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
}
@@ -103,7 +103,7 @@ jpeg_destroy_decompress (j_decompress_ptr cinfo)
GLOBAL(void)
jpeg_abort_decompress (j_decompress_ptr cinfo)
{
- jpeg_abort((j_common_ptr) cinfo); /* use common routine */
+ jpeg_abort((j_common_ptr) cinfo); /* use common routine */
}
@@ -114,100 +114,100 @@ jpeg_abort_decompress (j_decompress_ptr cinfo)
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:
+ /* 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:
+ case 1:
cinfo->jpeg_color_space = JCS_YCbCr;
break;
- default:
+ 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)
+ }
+ } 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)
+ else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
- else {
+ 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:
+ }
+ }
+ /* 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:
+ case 2:
cinfo->jpeg_color_space = JCS_YCCK;
break;
- default:
+ 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 = cinfo->block_size; /* 1:1 scaling */
- cinfo->scale_denom = cinfo->block_size;
- 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;
+ }
+ } 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 = cinfo->block_size; /* 1:1 scaling */
+ cinfo->scale_denom = cinfo->block_size;
+ 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;
+ cinfo->two_pass_quantize = TRUE;
#else
- cinfo->two_pass_quantize = FALSE;
+ 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;
+ 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;
}
@@ -241,34 +241,34 @@ default_decompress_parms (j_decompress_ptr cinfo)
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;
+ 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;
}
@@ -287,43 +287,43 @@ jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
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;
+ 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;
}
@@ -334,11 +334,11 @@ jpeg_consume_input (j_decompress_ptr cinfo)
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;
+ /* 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;
}
@@ -349,11 +349,11 @@ jpeg_input_complete (j_decompress_ptr cinfo)
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;
+ /* 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;
}
@@ -369,28 +369,28 @@ jpeg_has_multiple_scans (j_decompress_ptr cinfo)
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;
+ 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;
}