| 1 | /*
|
|---|
| 2 | * jdapistd.c
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright (C) 1994-1996, Thomas G. Lane.
|
|---|
| 5 | * This file is part of the Independent JPEG Group's software.
|
|---|
| 6 | * For conditions of distribution and use, see the accompanying README file.
|
|---|
| 7 | *
|
|---|
| 8 | * This file contains application interface code for the decompression half
|
|---|
| 9 | * of the JPEG library. These are the "standard" API routines that are
|
|---|
| 10 | * used in the normal full-decompression case. They are not used by a
|
|---|
| 11 | * transcoding-only application. Note that if an application links in
|
|---|
| 12 | * jpeg_start_decompress, it will end up linking in the entire decompressor.
|
|---|
| 13 | * We thus must separate this file from jdapimin.c to avoid linking the
|
|---|
| 14 | * whole decompression library into a transcoder.
|
|---|
| 15 | */
|
|---|
| 16 |
|
|---|
| 17 | #define JPEG_INTERNALS
|
|---|
| 18 | #include "jinclude.h"
|
|---|
| 19 | #include "jpeglib.h"
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | /* Forward declarations */
|
|---|
| 23 | LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | /*
|
|---|
| 27 | * Decompression initialization.
|
|---|
| 28 | * jpeg_read_header must be completed before calling this.
|
|---|
| 29 | *
|
|---|
| 30 | * If a multipass operating mode was selected, this will do all but the
|
|---|
| 31 | * last pass, and thus may take a great deal of time.
|
|---|
| 32 | *
|
|---|
| 33 | * Returns FALSE if suspended. The return value need be inspected only if
|
|---|
| 34 | * a suspending data source is used.
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | GLOBAL(boolean)
|
|---|
| 38 | jpeg_start_decompress (j_decompress_ptr cinfo)
|
|---|
| 39 | {
|
|---|
| 40 | if (cinfo->global_state == DSTATE_READY) {
|
|---|
| 41 | /* First call: initialize master control, select active modules */
|
|---|
| 42 | jinit_master_decompress(cinfo);
|
|---|
| 43 | if (cinfo->buffered_image) {
|
|---|
| 44 | /* No more work here; expecting jpeg_start_output next */
|
|---|
| 45 | cinfo->global_state = DSTATE_BUFIMAGE;
|
|---|
| 46 | return TRUE;
|
|---|
| 47 | }
|
|---|
| 48 | cinfo->global_state = DSTATE_PRELOAD;
|
|---|
| 49 | }
|
|---|
| 50 | if (cinfo->global_state == DSTATE_PRELOAD) {
|
|---|
| 51 | /* If file has multiple scans, absorb them all into the coef buffer */
|
|---|
| 52 | if (cinfo->inputctl->has_multiple_scans) {
|
|---|
| 53 | #ifdef D_MULTISCAN_FILES_SUPPORTED
|
|---|
| 54 | for (;;) {
|
|---|
| 55 | int retcode;
|
|---|
| 56 | /* Call progress monitor hook if present */
|
|---|
| 57 | if (cinfo->progress != NULL)
|
|---|
| 58 | (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
|
|---|
| 59 | /* Absorb some more input */
|
|---|
| 60 | retcode = (*cinfo->inputctl->consume_input) (cinfo);
|
|---|
| 61 | if (retcode == JPEG_SUSPENDED)
|
|---|
| 62 | return FALSE;
|
|---|
| 63 | if (retcode == JPEG_REACHED_EOI)
|
|---|
| 64 | break;
|
|---|
| 65 | /* Advance progress counter if appropriate */
|
|---|
| 66 | if (cinfo->progress != NULL &&
|
|---|
| 67 | (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
|
|---|
| 68 | if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
|
|---|
| 69 | /* jdmaster underestimated number of scans; ratchet up one scan */
|
|---|
| 70 | cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
|
|---|
| 71 | }
|
|---|
| 72 | }
|
|---|
| 73 | }
|
|---|
| 74 | #else
|
|---|
| 75 | ERREXIT(cinfo, JERR_NOT_COMPILED);
|
|---|
| 76 | #endif /* D_MULTISCAN_FILES_SUPPORTED */
|
|---|
| 77 | }
|
|---|
| 78 | cinfo->output_scan_number = cinfo->input_scan_number;
|
|---|
| 79 | } else if (cinfo->global_state != DSTATE_PRESCAN)
|
|---|
| 80 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
|---|
| 81 | /* Perform any dummy output passes, and set up for the final pass */
|
|---|
| 82 | return output_pass_setup(cinfo);
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | /*
|
|---|
| 87 | * Set up for an output pass, and perform any dummy pass(es) needed.
|
|---|
| 88 | * Common subroutine for jpeg_start_decompress and jpeg_start_output.
|
|---|
| 89 | * Entry: global_state = DSTATE_PRESCAN only if previously suspended.
|
|---|
| 90 | * Exit: If done, returns TRUE and sets global_state for proper output mode.
|
|---|
| 91 | * If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN.
|
|---|
| 92 | */
|
|---|
| 93 |
|
|---|
| 94 | LOCAL(boolean)
|
|---|
| 95 | output_pass_setup (j_decompress_ptr cinfo)
|
|---|
| 96 | {
|
|---|
| 97 | if (cinfo->global_state != DSTATE_PRESCAN) {
|
|---|
| 98 | /* First call: do pass setup */
|
|---|
| 99 | (*cinfo->master->prepare_for_output_pass) (cinfo);
|
|---|
|
|---|