7 * Copyright (C) 1995, Thomas G. Lane.
\r
9 * This file is part of the Independent JPEG Group's software.
\r
11 * For conditions of distribution and use, see the accompanying README file.
\r
15 * This file contains library routines for transcoding decompression,
\r
17 * that is, reading raw DCT coefficient arrays from an input JPEG file.
\r
19 * The routines in jdapimin.c will also be needed by a transcoder.
\r
25 #define JPEG_INTERNALS
\r
27 #include "jinclude.h"
\r
29 #include "radiant_jpeglib.h"
\r
35 /* Forward declarations */
\r
37 LOCAL void transdecode_master_selection JPP((j_decompress_ptr cinfo));
\r
45 * Read the coefficient arrays from a JPEG file.
\r
47 * jpeg_read_header must be completed before calling this.
\r
51 * The entire image is read into a set of virtual coefficient-block arrays,
\r
53 * one per component. The return value is a pointer to the array of
\r
55 * virtual-array descriptors. These can be manipulated directly via the
\r
57 * JPEG memory manager, or handed off to jpeg_write_coefficients().
\r
59 * To release the memory occupied by the virtual arrays, call
\r
61 * jpeg_finish_decompress() when done with the data.
\r
65 * Returns NULL if suspended. This case need be checked only if
\r
67 * a suspending data source is used.
\r
73 GLOBAL jvirt_barray_ptr *
\r
75 jpeg_read_coefficients (j_decompress_ptr cinfo)
\r
79 if (cinfo->global_state == DSTATE_READY) {
\r
81 /* First call: initialize active modules */
\r
83 transdecode_master_selection(cinfo);
\r
85 cinfo->global_state = DSTATE_RDCOEFS;
\r
87 } else if (cinfo->global_state != DSTATE_RDCOEFS)
\r
89 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
\r
91 /* Absorb whole file into the coef buffer */
\r
97 /* Call progress monitor hook if present */
\r
99 if (cinfo->progress != NULL)
\r
101 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
\r
103 /* Absorb some more input */
\r
105 retcode = (*cinfo->inputctl->consume_input) (cinfo);
\r
107 if (retcode == JPEG_SUSPENDED)
\r
111 if (retcode == JPEG_REACHED_EOI)
\r
115 /* Advance progress counter if appropriate */
\r
117 if (cinfo->progress != NULL &&
\r
119 (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
\r
121 if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
\r
123 /* startup underestimated number of scans; ratchet up one scan */
\r
125 cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
\r
133 /* Set state so that jpeg_finish_decompress does the right thing */
\r
135 cinfo->global_state = DSTATE_STOPPING;
\r
137 return cinfo->coef->coef_arrays;
\r
147 * Master selection of decompression modules for transcoding.
\r
149 * This substitutes for jdmaster.c's initialization of the full decompressor.
\r
157 transdecode_master_selection (j_decompress_ptr cinfo)
\r
161 /* Entropy decoding: either Huffman or arithmetic coding. */
\r
163 if (cinfo->arith_code) {
\r
165 ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
\r
169 if (cinfo->progressive_mode) {
\r
171 #ifdef D_PROGRESSIVE_SUPPORTED
\r
173 jinit_phuff_decoder(cinfo);
\r
177 ERREXIT(cinfo, JERR_NOT_COMPILED);
\r
183 jinit_huff_decoder(cinfo);
\r
189 /* Always get a full-image coefficient buffer. */
\r
191 jinit_d_coef_controller(cinfo, TRUE);
\r
195 /* We can now tell the memory manager to allocate virtual arrays. */
\r
197 (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
\r
201 /* Initialize input side of decompressor to consume first scan. */
\r
203 (*cinfo->inputctl->start_input_pass) (cinfo);
\r
207 /* Initialize progress monitoring. */
\r
209 if (cinfo->progress != NULL) {
\r
213 /* Estimate number of scans to set pass_limit. */
\r
215 if (cinfo->progressive_mode) {
\r
217 /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
\r
219 nscans = 2 + 3 * cinfo->num_components;
\r
221 } else if (cinfo->inputctl->has_multiple_scans) {
\r
223 /* For a nonprogressive multiscan file, estimate 1 scan per component. */
\r
225 nscans = cinfo->num_components;
\r
233 cinfo->progress->pass_counter = 0L;
\r
235 cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
\r
237 cinfo->progress->completed_passes = 0;
\r
239 cinfo->progress->total_passes = 1;
\r