dbf-halloween2015
diff libs/libjpeg/jdtrans.c @ 1:c3f5c32cb210
barfed all the libraries in the source tree to make porting easier
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 01 Nov 2015 00:36:56 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/libjpeg/jdtrans.c Sun Nov 01 00:36:56 2015 +0200 1.3 @@ -0,0 +1,143 @@ 1.4 +/* 1.5 + * jdtrans.c 1.6 + * 1.7 + * Copyright (C) 1995-1997, Thomas G. Lane. 1.8 + * This file is part of the Independent JPEG Group's software. 1.9 + * For conditions of distribution and use, see the accompanying README file. 1.10 + * 1.11 + * This file contains library routines for transcoding decompression, 1.12 + * that is, reading raw DCT coefficient arrays from an input JPEG file. 1.13 + * The routines in jdapimin.c will also be needed by a transcoder. 1.14 + */ 1.15 + 1.16 +#define JPEG_INTERNALS 1.17 +#include "jinclude.h" 1.18 +#include "jpeglib.h" 1.19 + 1.20 + 1.21 +/* Forward declarations */ 1.22 +LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo)); 1.23 + 1.24 + 1.25 +/* 1.26 + * Read the coefficient arrays from a JPEG file. 1.27 + * jpeg_read_header must be completed before calling this. 1.28 + * 1.29 + * The entire image is read into a set of virtual coefficient-block arrays, 1.30 + * one per component. The return value is a pointer to the array of 1.31 + * virtual-array descriptors. These can be manipulated directly via the 1.32 + * JPEG memory manager, or handed off to jpeg_write_coefficients(). 1.33 + * To release the memory occupied by the virtual arrays, call 1.34 + * jpeg_finish_decompress() when done with the data. 1.35 + * 1.36 + * An alternative usage is to simply obtain access to the coefficient arrays 1.37 + * during a buffered-image-mode decompression operation. This is allowed 1.38 + * after any jpeg_finish_output() call. The arrays can be accessed until 1.39 + * jpeg_finish_decompress() is called. (Note that any call to the library 1.40 + * may reposition the arrays, so don't rely on access_virt_barray() results 1.41 + * to stay valid across library calls.) 1.42 + * 1.43 + * Returns NULL if suspended. This case need be checked only if 1.44 + * a suspending data source is used. 1.45 + */ 1.46 + 1.47 +GLOBAL(jvirt_barray_ptr *) 1.48 +jpeg_read_coefficients (j_decompress_ptr cinfo) 1.49 +{ 1.50 + if (cinfo->global_state == DSTATE_READY) { 1.51 + /* First call: initialize active modules */ 1.52 + transdecode_master_selection(cinfo); 1.53 + cinfo->global_state = DSTATE_RDCOEFS; 1.54 + } 1.55 + if (cinfo->global_state == DSTATE_RDCOEFS) { 1.56 + /* Absorb whole file into the coef buffer */ 1.57 + for (;;) { 1.58 + int retcode; 1.59 + /* Call progress monitor hook if present */ 1.60 + if (cinfo->progress != NULL) 1.61 + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 1.62 + /* Absorb some more input */ 1.63 + retcode = (*cinfo->inputctl->consume_input) (cinfo); 1.64 + if (retcode == JPEG_SUSPENDED) 1.65 + return NULL; 1.66 + if (retcode == JPEG_REACHED_EOI) 1.67 + break; 1.68 + /* Advance progress counter if appropriate */ 1.69 + if (cinfo->progress != NULL && 1.70 + (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { 1.71 + if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { 1.72 + /* startup underestimated number of scans; ratchet up one scan */ 1.73 + cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows; 1.74 + } 1.75 + } 1.76 + } 1.77 + /* Set state so that jpeg_finish_decompress does the right thing */ 1.78 + cinfo->global_state = DSTATE_STOPPING; 1.79 + } 1.80 + /* At this point we should be in state DSTATE_STOPPING if being used 1.81 + * standalone, or in state DSTATE_BUFIMAGE if being invoked to get access 1.82 + * to the coefficients during a full buffered-image-mode decompression. 1.83 + */ 1.84 + if ((cinfo->global_state == DSTATE_STOPPING || 1.85 + cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) { 1.86 + return cinfo->coef->coef_arrays; 1.87 + } 1.88 + /* Oops, improper usage */ 1.89 + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 1.90 + return NULL; /* keep compiler happy */ 1.91 +} 1.92 + 1.93 + 1.94 +/* 1.95 + * Master selection of decompression modules for transcoding. 1.96 + * This substitutes for jdmaster.c's initialization of the full decompressor. 1.97 + */ 1.98 + 1.99 +LOCAL(void) 1.100 +transdecode_master_selection (j_decompress_ptr cinfo) 1.101 +{ 1.102 + /* This is effectively a buffered-image operation. */ 1.103 + cinfo->buffered_image = TRUE; 1.104 + 1.105 + /* Entropy decoding: either Huffman or arithmetic coding. */ 1.106 + if (cinfo->arith_code) { 1.107 + ERREXIT(cinfo, JERR_ARITH_NOTIMPL); 1.108 + } else { 1.109 + if (cinfo->progressive_mode) { 1.110 +#ifdef D_PROGRESSIVE_SUPPORTED 1.111 + jinit_phuff_decoder(cinfo); 1.112 +#else 1.113 + ERREXIT(cinfo, JERR_NOT_COMPILED); 1.114 +#endif 1.115 + } else 1.116 + jinit_huff_decoder(cinfo); 1.117 + } 1.118 + 1.119 + /* Always get a full-image coefficient buffer. */ 1.120 + jinit_d_coef_controller(cinfo, TRUE); 1.121 + 1.122 + /* We can now tell the memory manager to allocate virtual arrays. */ 1.123 + (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); 1.124 + 1.125 + /* Initialize input side of decompressor to consume first scan. */ 1.126 + (*cinfo->inputctl->start_input_pass) (cinfo); 1.127 + 1.128 + /* Initialize progress monitoring. */ 1.129 + if (cinfo->progress != NULL) { 1.130 + int nscans; 1.131 + /* Estimate number of scans to set pass_limit. */ 1.132 + if (cinfo->progressive_mode) { 1.133 + /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */ 1.134 + nscans = 2 + 3 * cinfo->num_components; 1.135 + } else if (cinfo->inputctl->has_multiple_scans) { 1.136 + /* For a nonprogressive multiscan file, estimate 1 scan per component. */ 1.137 + nscans = cinfo->num_components; 1.138 + } else { 1.139 + nscans = 1; 1.140 + } 1.141 + cinfo->progress->pass_counter = 0L; 1.142 + cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans; 1.143 + cinfo->progress->completed_passes = 0; 1.144 + cinfo->progress->total_passes = 1; 1.145 + } 1.146 +}