dbf-halloween2015

annotate libs/libjpeg/jdtrans.c @ 4:4316c0c879e9

fixed RUN script for macosx
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 01 Nov 2015 06:18:18 +0200
parents
children
rev   line source
nuclear@1 1 /*
nuclear@1 2 * jdtrans.c
nuclear@1 3 *
nuclear@1 4 * Copyright (C) 1995-1997, Thomas G. Lane.
nuclear@1 5 * This file is part of the Independent JPEG Group's software.
nuclear@1 6 * For conditions of distribution and use, see the accompanying README file.
nuclear@1 7 *
nuclear@1 8 * This file contains library routines for transcoding decompression,
nuclear@1 9 * that is, reading raw DCT coefficient arrays from an input JPEG file.
nuclear@1 10 * The routines in jdapimin.c will also be needed by a transcoder.
nuclear@1 11 */
nuclear@1 12
nuclear@1 13 #define JPEG_INTERNALS
nuclear@1 14 #include "jinclude.h"
nuclear@1 15 #include "jpeglib.h"
nuclear@1 16
nuclear@1 17
nuclear@1 18 /* Forward declarations */
nuclear@1 19 LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
nuclear@1 20
nuclear@1 21
nuclear@1 22 /*
nuclear@1 23 * Read the coefficient arrays from a JPEG file.
nuclear@1 24 * jpeg_read_header must be completed before calling this.
nuclear@1 25 *
nuclear@1 26 * The entire image is read into a set of virtual coefficient-block arrays,
nuclear@1 27 * one per component. The return value is a pointer to the array of
nuclear@1 28 * virtual-array descriptors. These can be manipulated directly via the
nuclear@1 29 * JPEG memory manager, or handed off to jpeg_write_coefficients().
nuclear@1 30 * To release the memory occupied by the virtual arrays, call
nuclear@1 31 * jpeg_finish_decompress() when done with the data.
nuclear@1 32 *
nuclear@1 33 * An alternative usage is to simply obtain access to the coefficient arrays
nuclear@1 34 * during a buffered-image-mode decompression operation. This is allowed
nuclear@1 35 * after any jpeg_finish_output() call. The arrays can be accessed until
nuclear@1 36 * jpeg_finish_decompress() is called. (Note that any call to the library
nuclear@1 37 * may reposition the arrays, so don't rely on access_virt_barray() results
nuclear@1 38 * to stay valid across library calls.)
nuclear@1 39 *
nuclear@1 40 * Returns NULL if suspended. This case need be checked only if
nuclear@1 41 * a suspending data source is used.
nuclear@1 42 */
nuclear@1 43
nuclear@1 44 GLOBAL(jvirt_barray_ptr *)
nuclear@1 45 jpeg_read_coefficients (j_decompress_ptr cinfo)
nuclear@1 46 {
nuclear@1 47 if (cinfo->global_state == DSTATE_READY) {
nuclear@1 48 /* First call: initialize active modules */
nuclear@1 49 transdecode_master_selection(cinfo);
nuclear@1 50 cinfo->global_state = DSTATE_RDCOEFS;
nuclear@1 51 }
nuclear@1 52 if (cinfo->global_state == DSTATE_RDCOEFS) {
nuclear@1 53 /* Absorb whole file into the coef buffer */
nuclear@1 54 for (;;) {
nuclear@1 55 int retcode;
nuclear@1 56 /* Call progress monitor hook if present */
nuclear@1 57 if (cinfo->progress != NULL)
nuclear@1 58 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
nuclear@1 59 /* Absorb some more input */
nuclear@1 60 retcode = (*cinfo->inputctl->consume_input) (cinfo);
nuclear@1 61 if (retcode == JPEG_SUSPENDED)
nuclear@1 62 return NULL;
nuclear@1 63 if (retcode == JPEG_REACHED_EOI)
nuclear@1 64 break;
nuclear@1 65 /* Advance progress counter if appropriate */
nuclear@1 66 if (cinfo->progress != NULL &&
nuclear@1 67 (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
nuclear@1 68 if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
nuclear@1 69 /* startup underestimated number of scans; ratchet up one scan */
nuclear@1 70 cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
nuclear@1 71 }
nuclear@1 72 }
nuclear@1 73 }
nuclear@1 74 /* Set state so that jpeg_finish_decompress does the right thing */
nuclear@1 75 cinfo->global_state = DSTATE_STOPPING;
nuclear@1 76 }
nuclear@1 77 /* At this point we should be in state DSTATE_STOPPING if being used
nuclear@1 78 * standalone, or in state DSTATE_BUFIMAGE if being invoked to get access
nuclear@1 79 * to the coefficients during a full buffered-image-mode decompression.
nuclear@1 80 */
nuclear@1 81 if ((cinfo->global_state == DSTATE_STOPPING ||
nuclear@1 82 cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
nuclear@1 83 return cinfo->coef->coef_arrays;
nuclear@1 84 }
nuclear@1 85 /* Oops, improper usage */
nuclear@1 86 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
nuclear@1 87 return NULL; /* keep compiler happy */
nuclear@1 88 }
nuclear@1 89
nuclear@1 90
nuclear@1 91 /*
nuclear@1 92 * Master selection of decompression modules for transcoding.
nuclear@1 93 * This substitutes for jdmaster.c's initialization of the full decompressor.
nuclear@1 94 */
nuclear@1 95
nuclear@1 96 LOCAL(void)
nuclear@1 97 transdecode_master_selection (j_decompress_ptr cinfo)
nuclear@1 98 {
nuclear@1 99 /* This is effectively a buffered-image operation. */
nuclear@1 100 cinfo->buffered_image = TRUE;
nuclear@1 101
nuclear@1 102 /* Entropy decoding: either Huffman or arithmetic coding. */
nuclear@1 103 if (cinfo->arith_code) {
nuclear@1 104 ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
nuclear@1 105 } else {
nuclear@1 106 if (cinfo->progressive_mode) {
nuclear@1 107 #ifdef D_PROGRESSIVE_SUPPORTED
nuclear@1 108 jinit_phuff_decoder(cinfo);
nuclear@1 109 #else
nuclear@1 110 ERREXIT(cinfo, JERR_NOT_COMPILED);
nuclear@1 111 #endif
nuclear@1 112 } else
nuclear@1 113 jinit_huff_decoder(cinfo);
nuclear@1 114 }
nuclear@1 115
nuclear@1 116 /* Always get a full-image coefficient buffer. */
nuclear@1 117 jinit_d_coef_controller(cinfo, TRUE);
nuclear@1 118
nuclear@1 119 /* We can now tell the memory manager to allocate virtual arrays. */
nuclear@1 120 (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
nuclear@1 121
nuclear@1 122 /* Initialize input side of decompressor to consume first scan. */
nuclear@1 123 (*cinfo->inputctl->start_input_pass) (cinfo);
nuclear@1 124
nuclear@1 125 /* Initialize progress monitoring. */
nuclear@1 126 if (cinfo->progress != NULL) {
nuclear@1 127 int nscans;
nuclear@1 128 /* Estimate number of scans to set pass_limit. */
nuclear@1 129 if (cinfo->progressive_mode) {
nuclear@1 130 /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
nuclear@1 131 nscans = 2 + 3 * cinfo->num_components;
nuclear@1 132 } else if (cinfo->inputctl->has_multiple_scans) {
nuclear@1 133 /* For a nonprogressive multiscan file, estimate 1 scan per component. */
nuclear@1 134 nscans = cinfo->num_components;
nuclear@1 135 } else {
nuclear@1 136 nscans = 1;
nuclear@1 137 }
nuclear@1 138 cinfo->progress->pass_counter = 0L;
nuclear@1 139 cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
nuclear@1 140 cinfo->progress->completed_passes = 0;
nuclear@1 141 cinfo->progress->total_passes = 1;
nuclear@1 142 }
nuclear@1 143 }