19f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/*
29f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * jdapistd.c
39f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project *
49f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Copyright (C) 1994-1996, Thomas G. Lane.
59f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * This file is part of the Independent JPEG Group's software.
69f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * For conditions of distribution and use, see the accompanying README file.
79f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project *
89f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * This file contains application interface code for the decompression half
99f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * of the JPEG library.  These are the "standard" API routines that are
109f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * used in the normal full-decompression case.  They are not used by a
119f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * transcoding-only application.  Note that if an application links in
129f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * jpeg_start_decompress, it will end up linking in the entire decompressor.
139f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * We thus must separate this file from jdapimin.c to avoid linking the
149f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * whole decompression library into a transcoder.
159f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */
169f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
179f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#define JPEG_INTERNALS
189f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#include "jinclude.h"
199f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#include "jpeglib.h"
209f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
219f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
229f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Forward declarations */
239f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectLOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
249f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
259f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
269f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/*
279f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Decompression initialization.
289f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * jpeg_read_header must be completed before calling this.
299f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project *
309f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * If a multipass operating mode was selected, this will do all but the
319f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * last pass, and thus may take a great deal of time.
329f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project *
339f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Returns FALSE if suspended.  The return value need be inspected only if
349f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * a suspending data source is used.
359f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */
369f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
379f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectGLOBAL(boolean)
389f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectjpeg_start_decompress (j_decompress_ptr cinfo)
399f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{
409f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (cinfo->global_state == DSTATE_READY) {
419f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    /* First call: initialize master control, select active modules */
429f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    jinit_master_decompress(cinfo);
439f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    if (cinfo->buffered_image) {
449f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      /* No more work here; expecting jpeg_start_output next */
459f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      cinfo->global_state = DSTATE_BUFIMAGE;
469f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      return TRUE;
479f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    }
489f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    cinfo->global_state = DSTATE_PRELOAD;
499f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  }
509f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (cinfo->global_state == DSTATE_PRELOAD) {
519f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    /* If file has multiple scans, absorb them all into the coef buffer */
529f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    if (cinfo->inputctl->has_multiple_scans) {
539f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#ifdef D_MULTISCAN_FILES_SUPPORTED
549f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      for (;;) {
559f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	int retcode;
569f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	/* Call progress monitor hook if present */
579f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	if (cinfo->progress != NULL)
589f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
599f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	/* Absorb some more input */
609f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	retcode = (*cinfo->inputctl->consume_input) (cinfo);
619f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	if (retcode == JPEG_SUSPENDED)
629f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	  return FALSE;
639f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	if (retcode == JPEG_REACHED_EOI)
649f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	  break;
659f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	/* Advance progress counter if appropriate */
669f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	if (cinfo->progress != NULL &&
679f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	    (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
689f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	  if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
699f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	    /* jdmaster underestimated number of scans; ratchet up one scan */
709f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	    cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
719f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	  }
729f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	}
739f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      }
749f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#else
759f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      ERREXIT(cinfo, JERR_NOT_COMPILED);
769f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#endif /* D_MULTISCAN_FILES_SUPPORTED */
779f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    }
789f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    cinfo->output_scan_number = cinfo->input_scan_number;
799f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  } else if (cinfo->global_state != DSTATE_PRESCAN)
809f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
819f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  /* Perform any dummy output passes, and set up for the final pass */
829f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  return output_pass_setup(cinfo);
839f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project}
849f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
859f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
869f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/*
879f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Set up for an output pass, and perform any dummy pass(es) needed.
889f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Common subroutine for jpeg_start_decompress and jpeg_start_output.
899f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Entry: global_state = DSTATE_PRESCAN only if previously suspended.
909f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Exit: If done, returns TRUE and sets global_state for proper output mode.
919f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project *       If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN.
929f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */
939f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
949f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectLOCAL(boolean)
959f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectoutput_pass_setup (j_decompress_ptr cinfo)
969f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{
979f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (cinfo->global_state != DSTATE_PRESCAN) {
989f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    /* First call: do pass setup */
999f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    (*cinfo->master->prepare_for_output_pass) (cinfo);
1009f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    cinfo->output_scanline = 0;
1019f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    cinfo->global_state = DSTATE_PRESCAN;
1029f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  }
1039f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  /* Loop over any required dummy passes */
1049f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  while (cinfo->master->is_dummy_pass) {
1059f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#ifdef QUANT_2PASS_SUPPORTED
1069f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    /* Crank through the dummy pass */
1079f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    while (cinfo->output_scanline < cinfo->output_height) {
1089f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      JDIMENSION last_scanline;
1099f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      /* Call progress monitor hook if present */
1109f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      if (cinfo->progress != NULL) {
1119f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	cinfo->progress->pass_counter = (long) cinfo->output_scanline;
1129f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	cinfo->progress->pass_limit = (long) cinfo->output_height;
1139f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
1149f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      }
1159f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      /* Process some data */
1169f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      last_scanline = cinfo->output_scanline;
1179f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
1189f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project				    &cinfo->output_scanline, (JDIMENSION) 0);
1199f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      if (cinfo->output_scanline == last_scanline)
1209f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	return FALSE;		/* No progress made, must suspend */
1219f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    }
1229f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    /* Finish up dummy pass, and set up for another one */
1239f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    (*cinfo->master->finish_output_pass) (cinfo);
1249f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    (*cinfo->master->prepare_for_output_pass) (cinfo);
1259f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    cinfo->output_scanline = 0;
1269f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#else
1279f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    ERREXIT(cinfo, JERR_NOT_COMPILED);
1289f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#endif /* QUANT_2PASS_SUPPORTED */
1299f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  }
1309f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  /* Ready for application to drive output pass through
1319f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project   * jpeg_read_scanlines or jpeg_read_raw_data.
1329f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project   */
1339f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
1349f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  return TRUE;
1359f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project}
1369f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
1379f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
1389f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/*
1399f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Read some scanlines of data from the JPEG decompressor.
1409f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project *
1419f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * The return value will be the number of lines actually read.
1429f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * This may be less than the number requested in several cases,
1439f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * including bottom of image, data source suspension, and operating
1449f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * modes that emit multiple scanlines at a time.
1459f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project *
1469f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Note: we warn about excess calls to jpeg_read_scanlines() since
1479f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * this likely signals an application programmer error.  However,
1489f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * an oversize buffer (max_lines > scanlines remaining) is not an error.
1499f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */
1509f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
1519f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectGLOBAL(JDIMENSION)
1529f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectjpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
1539f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project		     JDIMENSION max_lines)
1549f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{
1559f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  JDIMENSION row_ctr;
1569f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
1579f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (cinfo->global_state != DSTATE_SCANNING)
1589f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
1599f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (cinfo->output_scanline >= cinfo->output_height) {
1609f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
1619f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    return 0;
1629f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  }
1639f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
1649f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  /* Call progress monitor hook if present */
1659f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (cinfo->progress != NULL) {
1669f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    cinfo->progress->pass_counter = (long) cinfo->output_scanline;
1679f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    cinfo->progress->pass_limit = (long) cinfo->output_height;
1689f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
1699f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  }
1709f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
1719f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  /* Process some data */
1729f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  row_ctr = 0;
1739f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
1749f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  cinfo->output_scanline += row_ctr;
1759f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  return row_ctr;
1769f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project}
1779f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
1789f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
1799f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/*
1809f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Alternate entry point to read raw data.
1819f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Processes exactly one iMCU row per call, unless suspended.
1829f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */
1839f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
1849f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectGLOBAL(JDIMENSION)
1859f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectjpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
1869f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project		    JDIMENSION max_lines)
1879f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{
1889f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  JDIMENSION lines_per_iMCU_row;
1899f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
1909f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (cinfo->global_state != DSTATE_RAW_OK)
1919f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
1929f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (cinfo->output_scanline >= cinfo->output_height) {
1939f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
1949f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    return 0;
1959f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  }
1969f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
1979f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  /* Call progress monitor hook if present */
1989f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (cinfo->progress != NULL) {
1999f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    cinfo->progress->pass_counter = (long) cinfo->output_scanline;
2009f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    cinfo->progress->pass_limit = (long) cinfo->output_height;
2019f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
2029f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  }
2039f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
2049f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  /* Verify that at least one iMCU row can be returned. */
2059f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
2069f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (max_lines < lines_per_iMCU_row)
2079f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    ERREXIT(cinfo, JERR_BUFFER_SIZE);
2089f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
2099f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  /* Decompress directly into user's buffer. */
2109f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (! (*cinfo->coef->decompress_data) (cinfo, data))
2119f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    return 0;			/* suspension forced, can do nothing more */
2129f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
2139f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  /* OK, we processed one iMCU row. */
2149f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  cinfo->output_scanline += lines_per_iMCU_row;
2159f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  return lines_per_iMCU_row;
2169f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project}
2179f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
2189f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
2199f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Additional entry points for buffered-image mode. */
2209f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
2219f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#ifdef D_MULTISCAN_FILES_SUPPORTED
2229f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
2239f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/*
2249f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Initialize for an output pass in buffered-image mode.
2259f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */
2269f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
2279f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectGLOBAL(boolean)
2289f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectjpeg_start_output (j_decompress_ptr cinfo, int scan_number)
2299f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{
2309f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (cinfo->global_state != DSTATE_BUFIMAGE &&
2319f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      cinfo->global_state != DSTATE_PRESCAN)
2329f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
2339f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  /* Limit scan number to valid range */
2349f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (scan_number <= 0)
2359f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    scan_number = 1;
2369f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if (cinfo->inputctl->eoi_reached &&
2379f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      scan_number > cinfo->input_scan_number)
2389f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    scan_number = cinfo->input_scan_number;
2399f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  cinfo->output_scan_number = scan_number;
2409f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  /* Perform any dummy output passes, and set up for the real pass */
2419f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  return output_pass_setup(cinfo);
2429f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project}
2439f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
2449f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
2459f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/*
2469f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Finish up after an output pass in buffered-image mode.
2479f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project *
2489f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Returns FALSE if suspended.  The return value need be inspected only if
2499f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * a suspending data source is used.
2509f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */
2519f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
2529f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectGLOBAL(boolean)
2539f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectjpeg_finish_output (j_decompress_ptr cinfo)
2549f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{
2559f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  if ((cinfo->global_state == DSTATE_SCANNING ||
2569f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project       cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
2579f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    /* Terminate this pass. */
2589f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    /* We do not require the whole pass to have been completed. */
2599f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    (*cinfo->master->finish_output_pass) (cinfo);
2609f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    cinfo->global_state = DSTATE_BUFPOST;
2619f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  } else if (cinfo->global_state != DSTATE_BUFPOST) {
2629f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    /* BUFPOST = repeat call after a suspension, anything else is error */
2639f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
2649f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  }
2659f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  /* Read markers looking for SOS or EOI */
2669f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
2679f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project	 ! cinfo->inputctl->eoi_reached) {
2689f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
2699f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project      return FALSE;		/* Suspend, come back later */
2709f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  }
2719f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  cinfo->global_state = DSTATE_BUFIMAGE;
2729f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project  return TRUE;
2739f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project}
2749f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project
2759f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#endif /* D_MULTISCAN_FILES_SUPPORTED */
276