-/*\r
-\r
- * jdapistd.c\r
-\r
- *\r
-\r
- * Copyright (C) 1994-1995, Thomas G. Lane.\r
-\r
- * This file is part of the Independent JPEG Group's software.\r
-\r
- * For conditions of distribution and use, see the accompanying README file.\r
-\r
- *\r
-\r
- * This file contains application interface code for the decompression half\r
-\r
- * of the JPEG library. These are the "standard" API routines that are\r
-\r
- * used in the normal full-decompression case. They are not used by a\r
-\r
- * transcoding-only application. Note that if an application links in\r
-\r
- * jpeg_start_decompress, it will end up linking in the entire decompressor.\r
-\r
- * We thus must separate this file from jdapimin.c to avoid linking the\r
-\r
- * whole decompression library into a transcoder.\r
-\r
- */\r
-\r
-\r
-\r
-#define JPEG_INTERNALS\r
-\r
-#include "jinclude.h"\r
-\r
-#include "radiant_jpeglib.h"\r
-\r
-\r
-\r
-\r
-\r
-/* Forward declarations */\r
-\r
-LOCAL boolean output_pass_setup JPP((j_decompress_ptr cinfo));\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * Decompression initialization.\r
-\r
- * jpeg_read_header must be completed before calling this.\r
-\r
- *\r
-\r
- * If a multipass operating mode was selected, this will do all but the\r
-\r
- * last pass, and thus may take a great deal of time.\r
-\r
- *\r
-\r
- * Returns FALSE if suspended. The return value need be inspected only if\r
-\r
- * a suspending data source is used.\r
-\r
- */\r
-\r
-\r
-\r
-GLOBAL boolean\r
-\r
-jpeg_start_decompress (j_decompress_ptr cinfo)\r
-\r
-{\r
-\r
- if (cinfo->global_state == DSTATE_READY) {\r
-\r
- /* First call: initialize master control, select active modules */\r
-\r
- jinit_master_decompress(cinfo);\r
-\r
- if (cinfo->buffered_image) {\r
-\r
- /* No more work here; expecting jpeg_start_output next */\r
-\r
- cinfo->global_state = DSTATE_BUFIMAGE;\r
-\r
- return TRUE;\r
-\r
- }\r
-\r
- cinfo->global_state = DSTATE_PRELOAD;\r
-\r
- }\r
-\r
- if (cinfo->global_state == DSTATE_PRELOAD) {\r
-\r
- /* If file has multiple scans, absorb them all into the coef buffer */\r
-\r
- if (cinfo->inputctl->has_multiple_scans) {\r
-\r
-#ifdef D_MULTISCAN_FILES_SUPPORTED\r
-\r
- for (;;) {\r
-\r
- int retcode;\r
-\r
- /* Call progress monitor hook if present */\r
-\r
- if (cinfo->progress != NULL)\r
-\r
- (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);\r
-\r
- /* Absorb some more input */\r
-\r
- retcode = (*cinfo->inputctl->consume_input) (cinfo);\r
-\r
- if (retcode == JPEG_SUSPENDED)\r
-\r
- return FALSE;\r
-\r
- if (retcode == JPEG_REACHED_EOI)\r
-\r
- break;\r
-\r
- /* Advance progress counter if appropriate */\r
-\r
- if (cinfo->progress != NULL &&\r
-\r
- (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {\r
-\r
- if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {\r
-\r
- /* jdmaster underestimated number of scans; ratchet up one scan */\r
-\r
- cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;\r
-\r
- }\r
-\r
- }\r
-\r
- }\r
-\r
-#else\r
-\r
- ERREXIT(cinfo, JERR_NOT_COMPILED);\r
-\r
-#endif /* D_MULTISCAN_FILES_SUPPORTED */\r
-\r
- }\r
-\r
- cinfo->output_scan_number = cinfo->input_scan_number;\r
-\r
- } else if (cinfo->global_state != DSTATE_PRESCAN)\r
-\r
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\r
-\r
- /* Perform any dummy output passes, and set up for the final pass */\r
-\r
- return output_pass_setup(cinfo);\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * Set up for an output pass, and perform any dummy pass(es) needed.\r
-\r
- * Common subroutine for jpeg_start_decompress and jpeg_start_output.\r
-\r
- * Entry: global_state = DSTATE_PRESCAN only if previously suspended.\r
-\r
- * Exit: If done, returns TRUE and sets global_state for proper output mode.\r
-\r
- * If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN.\r
-\r
- */\r
-\r
-\r
-\r
-LOCAL boolean\r
-\r
-output_pass_setup (j_decompress_ptr cinfo)\r
-\r
-{\r
-\r
- if (cinfo->global_state != DSTATE_PRESCAN) {\r
-\r
- /* First call: do pass setup */\r
-\r
- (*cinfo->master->prepare_for_output_pass) (cinfo);\r
-\r
- cinfo->output_scanline = 0;\r
-\r
- cinfo->global_state = DSTATE_PRESCAN;\r
-\r
- }\r
-\r
- /* Loop over any required dummy passes */\r
-\r
- while (cinfo->master->is_dummy_pass) {\r
-\r
-#ifdef QUANT_2PASS_SUPPORTED\r
-\r
- /* Crank through the dummy pass */\r
-\r
- while (cinfo->output_scanline < cinfo->output_height) {\r
-\r
- JDIMENSION last_scanline;\r
-\r
- /* Call progress monitor hook if present */\r
-\r
- if (cinfo->progress != NULL) {\r
-\r
- cinfo->progress->pass_counter = (long) cinfo->output_scanline;\r
-\r
- cinfo->progress->pass_limit = (long) cinfo->output_height;\r
-\r
- (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);\r
-\r
- }\r
-\r
- /* Process some data */\r
-\r
- last_scanline = cinfo->output_scanline;\r
-\r
- (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,\r
-\r
- &cinfo->output_scanline, (JDIMENSION) 0);\r
-\r
- if (cinfo->output_scanline == last_scanline)\r
-\r
- return FALSE; /* No progress made, must suspend */\r
-\r
- }\r
-\r
- /* Finish up dummy pass, and set up for another one */\r
-\r
- (*cinfo->master->finish_output_pass) (cinfo);\r
-\r
- (*cinfo->master->prepare_for_output_pass) (cinfo);\r
-\r
- cinfo->output_scanline = 0;\r
-\r
-#else\r
-\r
- ERREXIT(cinfo, JERR_NOT_COMPILED);\r
-\r
-#endif /* QUANT_2PASS_SUPPORTED */\r
-\r
- }\r
-\r
- /* Ready for application to drive output pass through\r
-\r
- * jpeg_read_scanlines or jpeg_read_raw_data.\r
-\r
- */\r
-\r
- cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;\r
-\r
- return TRUE;\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * Read some scanlines of data from the JPEG decompressor.\r
-\r
- *\r
-\r
- * The return value will be the number of lines actually read.\r
-\r
- * This may be less than the number requested in several cases,\r
-\r
- * including bottom of image, data source suspension, and operating\r
-\r
- * modes that emit multiple scanlines at a time.\r
-\r
- *\r
-\r
- * Note: we warn about excess calls to jpeg_read_scanlines() since\r
-\r
- * this likely signals an application programmer error. However,\r
-\r
- * an oversize buffer (max_lines > scanlines remaining) is not an error.\r
-\r
- */\r
-\r
-\r
-\r
-GLOBAL JDIMENSION\r
-\r
-jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,\r
-\r
- JDIMENSION max_lines)\r
-\r
-{\r
-\r
- JDIMENSION row_ctr;\r
-\r
-\r
-\r
- if (cinfo->global_state != DSTATE_SCANNING)\r
-\r
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\r
-\r
- if (cinfo->output_scanline >= cinfo->output_height) {\r
-\r
- WARNMS(cinfo, JWRN_TOO_MUCH_DATA);\r
-\r
- return 0;\r
-\r
- }\r
-\r
-\r
-\r
- /* Call progress monitor hook if present */\r
-\r
- if (cinfo->progress != NULL) {\r
-\r
- cinfo->progress->pass_counter = (long) cinfo->output_scanline;\r
-\r
- cinfo->progress->pass_limit = (long) cinfo->output_height;\r
-\r
- (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);\r
-\r
- }\r
-\r
-\r
-\r
- /* Process some data */\r
-\r
- row_ctr = 0;\r
-\r
- (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);\r
-\r
- cinfo->output_scanline += row_ctr;\r
-\r
- return row_ctr;\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * Alternate entry point to read raw data.\r
-\r
- * Processes exactly one iMCU row per call, unless suspended.\r
-\r
- */\r
-\r
-\r
-\r
-GLOBAL JDIMENSION\r
-\r
-jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,\r
-\r
- JDIMENSION max_lines)\r
-\r
-{\r
-\r
- JDIMENSION lines_per_iMCU_row;\r
-\r
-\r
-\r
- if (cinfo->global_state != DSTATE_RAW_OK)\r
-\r
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\r
-\r
- if (cinfo->output_scanline >= cinfo->output_height) {\r
-\r
- WARNMS(cinfo, JWRN_TOO_MUCH_DATA);\r
-\r
- return 0;\r
-\r
- }\r
-\r
-\r
-\r
- /* Call progress monitor hook if present */\r
-\r
- if (cinfo->progress != NULL) {\r
-\r
- cinfo->progress->pass_counter = (long) cinfo->output_scanline;\r
-\r
- cinfo->progress->pass_limit = (long) cinfo->output_height;\r
-\r
- (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);\r
-\r
- }\r
-\r
-\r
-\r
- /* Verify that at least one iMCU row can be returned. */\r
-\r
- lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;\r
-\r
- if (max_lines < lines_per_iMCU_row)\r
-\r
- ERREXIT(cinfo, JERR_BUFFER_SIZE);\r
-\r
-\r
-\r
- /* Decompress directly into user's buffer. */\r
-\r
- if (! (*cinfo->coef->decompress_data) (cinfo, data))\r
-\r
- return 0; /* suspension forced, can do nothing more */\r
-\r
-\r
-\r
- /* OK, we processed one iMCU row. */\r
-\r
- cinfo->output_scanline += lines_per_iMCU_row;\r
-\r
- return lines_per_iMCU_row;\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/* Additional entry points for buffered-image mode. */\r
-\r
-\r
-\r
-#ifdef D_MULTISCAN_FILES_SUPPORTED\r
-\r
-\r
-\r
-/*\r
-\r
- * Initialize for an output pass in buffered-image mode.\r
-\r
- */\r
-\r
-\r
-\r
-GLOBAL boolean\r
-\r
-jpeg_start_output (j_decompress_ptr cinfo, int scan_number)\r
-\r
-{\r
-\r
- if (cinfo->global_state != DSTATE_BUFIMAGE &&\r
-\r
- cinfo->global_state != DSTATE_PRESCAN)\r
-\r
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\r
-\r
- /* Limit scan number to valid range */\r
-\r
- if (scan_number <= 0)\r
-\r
- scan_number = 1;\r
-\r
- if (cinfo->inputctl->eoi_reached &&\r
-\r
- scan_number > cinfo->input_scan_number)\r
-\r
- scan_number = cinfo->input_scan_number;\r
-\r
- cinfo->output_scan_number = scan_number;\r
-\r
- /* Perform any dummy output passes, and set up for the real pass */\r
-\r
- return output_pass_setup(cinfo);\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * Finish up after an output pass in buffered-image mode.\r
-\r
- *\r
-\r
- * Returns FALSE if suspended. The return value need be inspected only if\r
-\r
- * a suspending data source is used.\r
-\r
- */\r
-\r
-\r
-\r
-GLOBAL boolean\r
-\r
-jpeg_finish_output (j_decompress_ptr cinfo)\r
-\r
-{\r
-\r
- if ((cinfo->global_state == DSTATE_SCANNING ||\r
-\r
- cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {\r
-\r
- /* Terminate this pass. */\r
-\r
- /* We do not require the whole pass to have been completed. */\r
-\r
- (*cinfo->master->finish_output_pass) (cinfo);\r
-\r
- cinfo->global_state = DSTATE_BUFPOST;\r
-\r
- } else if (cinfo->global_state != DSTATE_BUFPOST) {\r
-\r
- /* BUFPOST = repeat call after a suspension, anything else is error */\r
-\r
- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\r
-\r
- }\r
-\r
- /* Read markers looking for SOS or EOI */\r
-\r
- while (cinfo->input_scan_number <= cinfo->output_scan_number &&\r
-\r
- ! cinfo->inputctl->eoi_reached) {\r
-\r
- if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)\r
-\r
- return FALSE; /* Suspend, come back later */\r
-\r
- }\r
-\r
- cinfo->global_state = DSTATE_BUFIMAGE;\r
-\r
- return TRUE;\r
-\r
-}\r
-\r
-\r
-\r
-#endif /* D_MULTISCAN_FILES_SUPPORTED */\r
-\r
+/*
+
+ * jdapistd.c
+
+ *
+
+ * Copyright (C) 1994-1995, 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 "standard" API routines that are
+
+ * used in the normal full-decompression case. They are not used by a
+
+ * transcoding-only application. Note that if an application links in
+
+ * jpeg_start_decompress, it will end up linking in the entire decompressor.
+
+ * We thus must separate this file from jdapimin.c to avoid linking the
+
+ * whole decompression library into a transcoder.
+
+ */
+
+
+
+#define JPEG_INTERNALS
+
+#include "jinclude.h"
+
+#include "radiant_jpeglib.h"
+
+
+
+
+
+/* Forward declarations */
+
+LOCAL boolean output_pass_setup JPP((j_decompress_ptr cinfo));
+
+
+
+
+
+/*
+
+ * Decompression initialization.
+
+ * jpeg_read_header must be completed before calling this.
+
+ *
+
+ * If a multipass operating mode was selected, this will do all but the
+
+ * last pass, and thus may take a great deal of time.
+
+ *
+
+ * Returns FALSE if suspended. The return value need be inspected only if
+
+ * a suspending data source is used.
+
+ */
+
+
+
+GLOBAL boolean
+
+jpeg_start_decompress (j_decompress_ptr cinfo)
+
+{
+
+ if (cinfo->global_state == DSTATE_READY) {
+
+ /* First call: initialize master control, select active modules */
+
+ jinit_master_decompress(cinfo);
+
+ if (cinfo->buffered_image) {
+
+ /* No more work here; expecting jpeg_start_output next */
+
+ cinfo->global_state = DSTATE_BUFIMAGE;
+
+ return TRUE;
+
+ }
+
+ cinfo->global_state = DSTATE_PRELOAD;
+
+ }
+
+ if (cinfo->global_state == DSTATE_PRELOAD) {
+
+ /* If file has multiple scans, absorb them all into the coef buffer */
+
+ if (cinfo->inputctl->has_multiple_scans) {
+
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+
+ for (;;) {
+
+ int retcode;
+
+ /* Call progress monitor hook if present */
+
+ if (cinfo->progress != NULL)
+
+ (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
+
+ /* Absorb some more input */
+
+ retcode = (*cinfo->inputctl->consume_input) (cinfo);
+
+ if (retcode == JPEG_SUSPENDED)
+
+ return FALSE;
+
+ if (retcode == JPEG_REACHED_EOI)
+
+ break;
+
+ /* Advance progress counter if appropriate */
+
+ if (cinfo->progress != NULL &&
+
+ (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
+
+ if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
+
+ /* jdmaster underestimated number of scans; ratchet up one scan */
+
+ cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
+
+ }
+
+ }
+
+ }
+
+#else
+
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+
+#endif /* D_MULTISCAN_FILES_SUPPORTED */
+
+ }
+
+ cinfo->output_scan_number = cinfo->input_scan_number;
+
+ } else if (cinfo->global_state != DSTATE_PRESCAN)
+
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ /* Perform any dummy output passes, and set up for the final pass */
+
+ return output_pass_setup(cinfo);
+
+}
+
+
+
+
+
+/*
+
+ * Set up for an output pass, and perform any dummy pass(es) needed.
+
+ * Common subroutine for jpeg_start_decompress and jpeg_start_output.
+
+ * Entry: global_state = DSTATE_PRESCAN only if previously suspended.
+
+ * Exit: If done, returns TRUE and sets global_state for proper output mode.
+
+ * If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN.
+
+ */
+
+
+
+LOCAL boolean
+
+output_pass_setup (j_decompress_ptr cinfo)
+
+{
+
+ if (cinfo->global_state != DSTATE_PRESCAN) {
+
+ /* First call: do pass setup */
+
+ (*cinfo->master->prepare_for_output_pass) (cinfo);
+
+ cinfo->output_scanline = 0;
+
+ cinfo->global_state = DSTATE_PRESCAN;
+
+ }
+
+ /* Loop over any required dummy passes */
+
+ while (cinfo->master->is_dummy_pass) {
+
+#ifdef QUANT_2PASS_SUPPORTED
+
+ /* Crank through the dummy pass */
+
+ while (cinfo->output_scanline < cinfo->output_height) {
+
+ JDIMENSION last_scanline;
+
+ /* Call progress monitor hook if present */
+
+ if (cinfo->progress != NULL) {
+
+ cinfo->progress->pass_counter = (long) cinfo->output_scanline;
+
+ cinfo->progress->pass_limit = (long) cinfo->output_height;
+
+ (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
+
+ }
+
+ /* Process some data */
+
+ last_scanline = cinfo->output_scanline;
+
+ (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
+
+ &cinfo->output_scanline, (JDIMENSION) 0);
+
+ if (cinfo->output_scanline == last_scanline)
+
+ return FALSE; /* No progress made, must suspend */
+
+ }
+
+ /* Finish up dummy pass, and set up for another one */
+
+ (*cinfo->master->finish_output_pass) (cinfo);
+
+ (*cinfo->master->prepare_for_output_pass) (cinfo);
+
+ cinfo->output_scanline = 0;
+
+#else
+
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+
+#endif /* QUANT_2PASS_SUPPORTED */
+
+ }
+
+ /* Ready for application to drive output pass through
+
+ * jpeg_read_scanlines or jpeg_read_raw_data.
+
+ */
+
+ cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
+
+ return TRUE;
+
+}
+
+
+
+
+
+/*
+
+ * Read some scanlines of data from the JPEG decompressor.
+
+ *
+
+ * The return value will be the number of lines actually read.
+
+ * This may be less than the number requested in several cases,
+
+ * including bottom of image, data source suspension, and operating
+
+ * modes that emit multiple scanlines at a time.
+
+ *
+
+ * Note: we warn about excess calls to jpeg_read_scanlines() since
+
+ * this likely signals an application programmer error. However,
+
+ * an oversize buffer (max_lines > scanlines remaining) is not an error.
+
+ */
+
+
+
+GLOBAL JDIMENSION
+
+jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
+
+ JDIMENSION max_lines)
+
+{
+
+ JDIMENSION row_ctr;
+
+
+
+ if (cinfo->global_state != DSTATE_SCANNING)
+
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ if (cinfo->output_scanline >= cinfo->output_height) {
+
+ WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
+
+ return 0;
+
+ }
+
+
+
+ /* Call progress monitor hook if present */
+
+ if (cinfo->progress != NULL) {
+
+ cinfo->progress->pass_counter = (long) cinfo->output_scanline;
+
+ cinfo->progress->pass_limit = (long) cinfo->output_height;
+
+ (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
+
+ }
+
+
+
+ /* Process some data */
+
+ row_ctr = 0;
+
+ (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
+
+ cinfo->output_scanline += row_ctr;
+
+ return row_ctr;
+
+}
+
+
+
+
+
+/*
+
+ * Alternate entry point to read raw data.
+
+ * Processes exactly one iMCU row per call, unless suspended.
+
+ */
+
+
+
+GLOBAL JDIMENSION
+
+jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
+
+ JDIMENSION max_lines)
+
+{
+
+ JDIMENSION lines_per_iMCU_row;
+
+
+
+ if (cinfo->global_state != DSTATE_RAW_OK)
+
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ if (cinfo->output_scanline >= cinfo->output_height) {
+
+ WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
+
+ return 0;
+
+ }
+
+
+
+ /* Call progress monitor hook if present */
+
+ if (cinfo->progress != NULL) {
+
+ cinfo->progress->pass_counter = (long) cinfo->output_scanline;
+
+ cinfo->progress->pass_limit = (long) cinfo->output_height;
+
+ (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
+
+ }
+
+
+
+ /* Verify that at least one iMCU row can be returned. */
+
+ lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
+
+ if (max_lines < lines_per_iMCU_row)
+
+ ERREXIT(cinfo, JERR_BUFFER_SIZE);
+
+
+
+ /* Decompress directly into user's buffer. */
+
+ if (! (*cinfo->coef->decompress_data) (cinfo, data))
+
+ return 0; /* suspension forced, can do nothing more */
+
+
+
+ /* OK, we processed one iMCU row. */
+
+ cinfo->output_scanline += lines_per_iMCU_row;
+
+ return lines_per_iMCU_row;
+
+}
+
+
+
+
+
+/* Additional entry points for buffered-image mode. */
+
+
+
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+
+
+
+/*
+
+ * Initialize for an output pass in buffered-image mode.
+
+ */
+
+
+
+GLOBAL boolean
+
+jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
+
+{
+
+ if (cinfo->global_state != DSTATE_BUFIMAGE &&
+
+ cinfo->global_state != DSTATE_PRESCAN)
+
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ /* Limit scan number to valid range */
+
+ if (scan_number <= 0)
+
+ scan_number = 1;
+
+ if (cinfo->inputctl->eoi_reached &&
+
+ scan_number > cinfo->input_scan_number)
+
+ scan_number = cinfo->input_scan_number;
+
+ cinfo->output_scan_number = scan_number;
+
+ /* Perform any dummy output passes, and set up for the real pass */
+
+ return output_pass_setup(cinfo);
+
+}
+
+
+
+
+
+/*
+
+ * Finish up after an output pass in buffered-image mode.
+
+ *
+
+ * Returns FALSE if suspended. The return value need be inspected only if
+
+ * a suspending data source is used.
+
+ */
+
+
+
+GLOBAL boolean
+
+jpeg_finish_output (j_decompress_ptr cinfo)
+
+{
+
+ if ((cinfo->global_state == DSTATE_SCANNING ||
+
+ cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
+
+ /* Terminate this pass. */
+
+ /* We do not require the whole pass to have been completed. */
+
+ (*cinfo->master->finish_output_pass) (cinfo);
+
+ cinfo->global_state = DSTATE_BUFPOST;
+
+ } else if (cinfo->global_state != DSTATE_BUFPOST) {
+
+ /* BUFPOST = repeat call after a suspension, anything else is error */
+
+ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
+
+ }
+
+ /* Read markers looking for SOS or EOI */
+
+ while (cinfo->input_scan_number <= cinfo->output_scan_number &&
+
+ ! cinfo->inputctl->eoi_reached) {
+
+ if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
+
+ return FALSE; /* Suspend, come back later */
+
+ }
+
+ cinfo->global_state = DSTATE_BUFIMAGE;
+
+ return TRUE;
+
+}
+
+
+
+#endif /* D_MULTISCAN_FILES_SUPPORTED */
+