0N/A * DO NOT REMOVE OR ALTER! 0N/A * Copyright (C) 1991-1997, Thomas G. Lane. 2362N/A * This file is part of the Independent JPEG Group's software. 0N/A * For conditions of distribution and use, see the accompanying README file. 0N/A * This file contains master control logic for the JPEG decompressor. 0N/A * These routines are concerned with selecting the modules to be executed 0N/A * and with determining the number of passes and the work to be done in each 0N/A /* Saved references to initialized quantizer modules, 0N/A * in case we need to switch modes. 0N/A * CRUCIAL: this must match the actual capabilities of jdmerge.c! 0N/A /* Merging is the equivalent of plain box-filter upsampling */ 0N/A /* and it only handles 2h1v or 2h2v sampling ratios */ 0N/A /* furthermore, it doesn't work if we've scaled the IDCTs differently */ 0N/A /* ??? also need to test for upsample-time rescaling, when & if supported */ 0N/A return TRUE;
/* by golly, it'll work... */ 0N/A * Compute output image dimensions and related values. 0N/A * NOTE: this is exported for possible use by application. 0N/A * Hence it mustn't do anything that can't be done twice. 0N/A * Also note that it may be called before the master module is initialized! 0N/A/* Do computations that are needed before master selection phase */ 0N/A /* Prevent application from calling me at wrong times */ 0N/A /* Compute actual output image dimensions and DCT scaling choices. */ 0N/A /* Provide 1/8 scaling */ 0N/A /* Provide 1/4 scaling */ 0N/A /* Provide 1/2 scaling */ 0N/A /* Provide 1/1 scaling */ 0N/A /* In selecting the actual DCT scaling for each component, we try to 0N/A * scale up the chroma components via IDCT scaling rather than upsampling. 0N/A * This saves time if the upsampler gets to use 1:1 scaling. 0N/A * Note this code assumes that the supported DCT scalings are powers of 2. 0N/A /* Recompute downsampled dimensions of components; 0N/A * application needs to know these if using raw downsampled data. 0N/A /* Size in samples, after IDCT scaling */ 0N/A#
else /* !IDCT_SCALING_SUPPORTED */ 0N/A /* Hardwire it to "no scaling" */ 0N/A /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE, 0N/A * and has computed unscaled downsampled_width and downsampled_height. #
endif /* IDCT_SCALING_SUPPORTED */ /* Report number of components in selected colorspace. */ /* Probably this should be in the color conversion module... */ #
endif /* else share code with YCbCr */ default:
/* else must be same colorspace as in file */ /* See if upsampler will want to emit more than one row at a time */ * Several decompression processes need to range-limit values to the range * 0..MAXJSAMPLE; the input value may fall somewhat outside this range * due to noise introduced by quantization, roundoff error, etc. These * processes are inner loops and need to be as fast as possible. On most * machines, particularly CPUs with pipelines or instruction prefetch, * a (subscript-check-less) C table lookup * x = sample_range_limit[x]; * is faster than explicit tests * else if (x > MAXJSAMPLE) x = MAXJSAMPLE; * These processes all use a common table prepared by the routine below. * For most steps we can mathematically guarantee that the initial value * of x is within MAXJSAMPLE+1 of the legal range, so a table running from * -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial * limiting step (just after the IDCT), a wildly out-of-range value is * possible if the input data is corrupt. To avoid any chance of indexing * off the end of memory and getting a bad-pointer trap, we perform the * post-IDCT limiting thus: * x = range_limit[x & MASK]; * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit * samples. Under normal circumstances this is more than enough range and * a correct output will be generated; with bogus input data the mask will * cause wraparound, and we will safely generate a bogus-but-in-range output. * For the post-IDCT step, we want to convert the data from signed to unsigned * representation by adding CENTERJSAMPLE at the same time that we limit it. * So the post-IDCT limiting table ends up looking like this: * CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE, * MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times), * 0 (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times), * 0,1,...,CENTERJSAMPLE-1 * Negative inputs select values from the upper half of the table after * We can save some space by overlapping the start of the post-IDCT table * with the simpler range limiting table. The post-IDCT table begins at * sample_range_limit + CENTERJSAMPLE. * Note that the table is allocated in near data space on PCs; it's small * enough and used often enough to justify this. /* Allocate and fill in the sample_range_limit table */ /* First segment of "simple" table: limit[x] = 0 for x < 0 */ /* Main part of "simple" table: limit[x] = x */ /* End of simple table, rest of first half of post-IDCT table */ /* Second half of post-IDCT table */ * Master selection of decompression modules. * This is done once at jpeg_start_decompress time. We determine * which modules will be used and give them appropriate initialization calls. * We also initialize the decompressor input side to begin consuming data. * Since jpeg_read_header has finished, we know what is in the SOF * and (first) SOS markers. We also have all the application parameter /* Initialize dimensions and other stuff */ /* Width of an output scanline must be representable as JDIMENSION. */ /* Initialize my private state */ /* Color quantizer selection */ /* No mode changes if not using buffered-image mode. */ /* 2-pass quantizer only works in 3-component color space. */ /* We use the 2-pass code to map to external colormaps. */ /* If both quantizers are initialized, the 2-pass one is left active; * this is necessary for starting with quantization to an external map. /* Post-processing: in particular, color conversion first */ /* Entropy decoding: either Huffman or arithmetic coding. */ /* Initialize principal buffer controllers. */ /* We can now tell the memory manager to allocate virtual arrays. */ /* Initialize input side of decompressor to consume first scan. */ /* If jpeg_start_decompress will read the whole file, initialize * progress monitoring appropriately. The input step is counted /* Estimate number of scans to set pass_limit. */ /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */ /* For a nonprogressive multiscan file, estimate 1 scan per component. */ /* Count the input pass as done */ #
endif /* D_MULTISCAN_FILES_SUPPORTED */ * This is called at the beginning of each output pass. We determine which * modules will be active during this pass and give them appropriate * start_pass calls. We also set is_dummy_pass to indicate whether this * is a "real" output pass or a dummy pass for color quantization. * (In the latter case, jdapistd.c will crank the pass to completion.) /* Final pass of 2-pass quantization */ #
endif /* QUANT_2PASS_SUPPORTED */ /* Select new quantization method */ /* Set up progress monitor's pass info if present */ /* In buffered-image mode, we assume one more output pass if EOI not * yet reached, but no more passes if EOI has been reached. * Finish up at end of an output pass. * Switch to a new external colormap between output passes. /* Prevent application from calling me at wrong times */ /* Select 2-pass quantizer for external colormap use */ /* Notify quantizer of colormap change */ #
endif /* D_MULTISCAN_FILES_SUPPORTED */ * Initialize master decompression control and select active modules. * This is performed at the start of jpeg_start_decompress.