Path: blob/master/3rdparty/libjpeg-turbo/src/jdcoefct.c
16337 views
/*1* jdcoefct.c2*3* This file was part of the Independent JPEG Group's software:4* Copyright (C) 1994-1997, Thomas G. Lane.5* libjpeg-turbo Modifications:6* Copyright 2009 Pierre Ossman <[email protected]> for Cendio AB7* Copyright (C) 2010, 2015-2016, D. R. Commander.8* Copyright (C) 2015, Google, Inc.9* For conditions of distribution and use, see the accompanying README.ijg10* file.11*12* This file contains the coefficient buffer controller for decompression.13* This controller is the top level of the JPEG decompressor proper.14* The coefficient buffer lies between entropy decoding and inverse-DCT steps.15*16* In buffered-image mode, this controller is the interface between17* input-oriented processing and output-oriented processing.18* Also, the input side (only) is used when reading a file for transcoding.19*/2021#include "jinclude.h"22#include "jdcoefct.h"23#include "jpegcomp.h"242526/* Forward declarations */27METHODDEF(int) decompress_onepass28(j_decompress_ptr cinfo, JSAMPIMAGE output_buf);29#ifdef D_MULTISCAN_FILES_SUPPORTED30METHODDEF(int) decompress_data31(j_decompress_ptr cinfo, JSAMPIMAGE output_buf);32#endif33#ifdef BLOCK_SMOOTHING_SUPPORTED34LOCAL(boolean) smoothing_ok (j_decompress_ptr cinfo);35METHODDEF(int) decompress_smooth_data36(j_decompress_ptr cinfo, JSAMPIMAGE output_buf);37#endif383940/*41* Initialize for an input processing pass.42*/4344METHODDEF(void)45start_input_pass (j_decompress_ptr cinfo)46{47cinfo->input_iMCU_row = 0;48start_iMCU_row(cinfo);49}505152/*53* Initialize for an output processing pass.54*/5556METHODDEF(void)57start_output_pass (j_decompress_ptr cinfo)58{59#ifdef BLOCK_SMOOTHING_SUPPORTED60my_coef_ptr coef = (my_coef_ptr) cinfo->coef;6162/* If multipass, check to see whether to use block smoothing on this pass */63if (coef->pub.coef_arrays != NULL) {64if (cinfo->do_block_smoothing && smoothing_ok(cinfo))65coef->pub.decompress_data = decompress_smooth_data;66else67coef->pub.decompress_data = decompress_data;68}69#endif70cinfo->output_iMCU_row = 0;71}727374/*75* Decompress and return some data in the single-pass case.76* Always attempts to emit one fully interleaved MCU row ("iMCU" row).77* Input and output must run in lockstep since we have only a one-MCU buffer.78* Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.79*80* NB: output_buf contains a plane for each component in image,81* which we index according to the component's SOF position.82*/8384METHODDEF(int)85decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)86{87my_coef_ptr coef = (my_coef_ptr) cinfo->coef;88JDIMENSION MCU_col_num; /* index of current MCU within row */89JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;90JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;91int blkn, ci, xindex, yindex, yoffset, useful_width;92JSAMPARRAY output_ptr;93JDIMENSION start_col, output_col;94jpeg_component_info *compptr;95inverse_DCT_method_ptr inverse_DCT;9697/* Loop to process as much as one whole iMCU row */98for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;99yoffset++) {100for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;101MCU_col_num++) {102/* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */103jzero_far((void *) coef->MCU_buffer[0],104(size_t) (cinfo->blocks_in_MCU * sizeof(JBLOCK)));105if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {106/* Suspension forced; update state counters and exit */107coef->MCU_vert_offset = yoffset;108coef->MCU_ctr = MCU_col_num;109return JPEG_SUSPENDED;110}111112/* Only perform the IDCT on blocks that are contained within the desired113* cropping region.114*/115if (MCU_col_num >= cinfo->master->first_iMCU_col &&116MCU_col_num <= cinfo->master->last_iMCU_col) {117/* Determine where data should go in output_buf and do the IDCT thing.118* We skip dummy blocks at the right and bottom edges (but blkn gets119* incremented past them!). Note the inner loop relies on having120* allocated the MCU_buffer[] blocks sequentially.121*/122blkn = 0; /* index of current DCT block within MCU */123for (ci = 0; ci < cinfo->comps_in_scan; ci++) {124compptr = cinfo->cur_comp_info[ci];125/* Don't bother to IDCT an uninteresting component. */126if (! compptr->component_needed) {127blkn += compptr->MCU_blocks;128continue;129}130inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];131useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width132: compptr->last_col_width;133output_ptr = output_buf[compptr->component_index] +134yoffset * compptr->_DCT_scaled_size;135start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *136compptr->MCU_sample_width;137for (yindex = 0; yindex < compptr->MCU_height; yindex++) {138if (cinfo->input_iMCU_row < last_iMCU_row ||139yoffset+yindex < compptr->last_row_height) {140output_col = start_col;141for (xindex = 0; xindex < useful_width; xindex++) {142(*inverse_DCT) (cinfo, compptr,143(JCOEFPTR) coef->MCU_buffer[blkn+xindex],144output_ptr, output_col);145output_col += compptr->_DCT_scaled_size;146}147}148blkn += compptr->MCU_width;149output_ptr += compptr->_DCT_scaled_size;150}151}152}153}154/* Completed an MCU row, but perhaps not an iMCU row */155coef->MCU_ctr = 0;156}157/* Completed the iMCU row, advance counters for next one */158cinfo->output_iMCU_row++;159if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {160start_iMCU_row(cinfo);161return JPEG_ROW_COMPLETED;162}163/* Completed the scan */164(*cinfo->inputctl->finish_input_pass) (cinfo);165return JPEG_SCAN_COMPLETED;166}167168169/*170* Dummy consume-input routine for single-pass operation.171*/172173METHODDEF(int)174dummy_consume_data (j_decompress_ptr cinfo)175{176return JPEG_SUSPENDED; /* Always indicate nothing was done */177}178179180#ifdef D_MULTISCAN_FILES_SUPPORTED181182/*183* Consume input data and store it in the full-image coefficient buffer.184* We read as much as one fully interleaved MCU row ("iMCU" row) per call,185* ie, v_samp_factor block rows for each component in the scan.186* Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.187*/188189METHODDEF(int)190consume_data (j_decompress_ptr cinfo)191{192my_coef_ptr coef = (my_coef_ptr) cinfo->coef;193JDIMENSION MCU_col_num; /* index of current MCU within row */194int blkn, ci, xindex, yindex, yoffset;195JDIMENSION start_col;196JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];197JBLOCKROW buffer_ptr;198jpeg_component_info *compptr;199200/* Align the virtual buffers for the components used in this scan. */201for (ci = 0; ci < cinfo->comps_in_scan; ci++) {202compptr = cinfo->cur_comp_info[ci];203buffer[ci] = (*cinfo->mem->access_virt_barray)204((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],205cinfo->input_iMCU_row * compptr->v_samp_factor,206(JDIMENSION) compptr->v_samp_factor, TRUE);207/* Note: entropy decoder expects buffer to be zeroed,208* but this is handled automatically by the memory manager209* because we requested a pre-zeroed array.210*/211}212213/* Loop to process one whole iMCU row */214for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;215yoffset++) {216for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;217MCU_col_num++) {218/* Construct list of pointers to DCT blocks belonging to this MCU */219blkn = 0; /* index of current DCT block within MCU */220for (ci = 0; ci < cinfo->comps_in_scan; ci++) {221compptr = cinfo->cur_comp_info[ci];222start_col = MCU_col_num * compptr->MCU_width;223for (yindex = 0; yindex < compptr->MCU_height; yindex++) {224buffer_ptr = buffer[ci][yindex+yoffset] + start_col;225for (xindex = 0; xindex < compptr->MCU_width; xindex++) {226coef->MCU_buffer[blkn++] = buffer_ptr++;227}228}229}230/* Try to fetch the MCU. */231if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {232/* Suspension forced; update state counters and exit */233coef->MCU_vert_offset = yoffset;234coef->MCU_ctr = MCU_col_num;235return JPEG_SUSPENDED;236}237}238/* Completed an MCU row, but perhaps not an iMCU row */239coef->MCU_ctr = 0;240}241/* Completed the iMCU row, advance counters for next one */242if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {243start_iMCU_row(cinfo);244return JPEG_ROW_COMPLETED;245}246/* Completed the scan */247(*cinfo->inputctl->finish_input_pass) (cinfo);248return JPEG_SCAN_COMPLETED;249}250251252/*253* Decompress and return some data in the multi-pass case.254* Always attempts to emit one fully interleaved MCU row ("iMCU" row).255* Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.256*257* NB: output_buf contains a plane for each component in image.258*/259260METHODDEF(int)261decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)262{263my_coef_ptr coef = (my_coef_ptr) cinfo->coef;264JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;265JDIMENSION block_num;266int ci, block_row, block_rows;267JBLOCKARRAY buffer;268JBLOCKROW buffer_ptr;269JSAMPARRAY output_ptr;270JDIMENSION output_col;271jpeg_component_info *compptr;272inverse_DCT_method_ptr inverse_DCT;273274/* Force some input to be done if we are getting ahead of the input. */275while (cinfo->input_scan_number < cinfo->output_scan_number ||276(cinfo->input_scan_number == cinfo->output_scan_number &&277cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {278if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)279return JPEG_SUSPENDED;280}281282/* OK, output from the virtual arrays. */283for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;284ci++, compptr++) {285/* Don't bother to IDCT an uninteresting component. */286if (! compptr->component_needed)287continue;288/* Align the virtual buffer for this component. */289buffer = (*cinfo->mem->access_virt_barray)290((j_common_ptr) cinfo, coef->whole_image[ci],291cinfo->output_iMCU_row * compptr->v_samp_factor,292(JDIMENSION) compptr->v_samp_factor, FALSE);293/* Count non-dummy DCT block rows in this iMCU row. */294if (cinfo->output_iMCU_row < last_iMCU_row)295block_rows = compptr->v_samp_factor;296else {297/* NB: can't use last_row_height here; it is input-side-dependent! */298block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);299if (block_rows == 0) block_rows = compptr->v_samp_factor;300}301inverse_DCT = cinfo->idct->inverse_DCT[ci];302output_ptr = output_buf[ci];303/* Loop over all DCT blocks to be processed. */304for (block_row = 0; block_row < block_rows; block_row++) {305buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];306output_col = 0;307for (block_num = cinfo->master->first_MCU_col[ci];308block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {309(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,310output_ptr, output_col);311buffer_ptr++;312output_col += compptr->_DCT_scaled_size;313}314output_ptr += compptr->_DCT_scaled_size;315}316}317318if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)319return JPEG_ROW_COMPLETED;320return JPEG_SCAN_COMPLETED;321}322323#endif /* D_MULTISCAN_FILES_SUPPORTED */324325326#ifdef BLOCK_SMOOTHING_SUPPORTED327328/*329* This code applies interblock smoothing as described by section K.8330* of the JPEG standard: the first 5 AC coefficients are estimated from331* the DC values of a DCT block and its 8 neighboring blocks.332* We apply smoothing only for progressive JPEG decoding, and only if333* the coefficients it can estimate are not yet known to full precision.334*/335336/* Natural-order array positions of the first 5 zigzag-order coefficients */337#define Q01_POS 1338#define Q10_POS 8339#define Q20_POS 16340#define Q11_POS 9341#define Q02_POS 2342343/*344* Determine whether block smoothing is applicable and safe.345* We also latch the current states of the coef_bits[] entries for the346* AC coefficients; otherwise, if the input side of the decompressor347* advances into a new scan, we might think the coefficients are known348* more accurately than they really are.349*/350351LOCAL(boolean)352smoothing_ok (j_decompress_ptr cinfo)353{354my_coef_ptr coef = (my_coef_ptr) cinfo->coef;355boolean smoothing_useful = FALSE;356int ci, coefi;357jpeg_component_info *compptr;358JQUANT_TBL *qtable;359int *coef_bits;360int *coef_bits_latch;361362if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)363return FALSE;364365/* Allocate latch area if not already done */366if (coef->coef_bits_latch == NULL)367coef->coef_bits_latch = (int *)368(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,369cinfo->num_components *370(SAVED_COEFS * sizeof(int)));371coef_bits_latch = coef->coef_bits_latch;372373for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;374ci++, compptr++) {375/* All components' quantization values must already be latched. */376if ((qtable = compptr->quant_table) == NULL)377return FALSE;378/* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */379if (qtable->quantval[0] == 0 ||380qtable->quantval[Q01_POS] == 0 ||381qtable->quantval[Q10_POS] == 0 ||382qtable->quantval[Q20_POS] == 0 ||383qtable->quantval[Q11_POS] == 0 ||384qtable->quantval[Q02_POS] == 0)385return FALSE;386/* DC values must be at least partly known for all components. */387coef_bits = cinfo->coef_bits[ci];388if (coef_bits[0] < 0)389return FALSE;390/* Block smoothing is helpful if some AC coefficients remain inaccurate. */391for (coefi = 1; coefi <= 5; coefi++) {392coef_bits_latch[coefi] = coef_bits[coefi];393if (coef_bits[coefi] != 0)394smoothing_useful = TRUE;395}396coef_bits_latch += SAVED_COEFS;397}398399return smoothing_useful;400}401402403/*404* Variant of decompress_data for use when doing block smoothing.405*/406407METHODDEF(int)408decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)409{410my_coef_ptr coef = (my_coef_ptr) cinfo->coef;411JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;412JDIMENSION block_num, last_block_column;413int ci, block_row, block_rows, access_rows;414JBLOCKARRAY buffer;415JBLOCKROW buffer_ptr, prev_block_row, next_block_row;416JSAMPARRAY output_ptr;417JDIMENSION output_col;418jpeg_component_info *compptr;419inverse_DCT_method_ptr inverse_DCT;420boolean first_row, last_row;421JCOEF *workspace;422int *coef_bits;423JQUANT_TBL *quanttbl;424JLONG Q00,Q01,Q02,Q10,Q11,Q20, num;425int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;426int Al, pred;427428/* Keep a local variable to avoid looking it up more than once */429workspace = coef->workspace;430431/* Force some input to be done if we are getting ahead of the input. */432while (cinfo->input_scan_number <= cinfo->output_scan_number &&433! cinfo->inputctl->eoi_reached) {434if (cinfo->input_scan_number == cinfo->output_scan_number) {435/* If input is working on current scan, we ordinarily want it to436* have completed the current row. But if input scan is DC,437* we want it to keep one row ahead so that next block row's DC438* values are up to date.439*/440JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;441if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)442break;443}444if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)445return JPEG_SUSPENDED;446}447448/* OK, output from the virtual arrays. */449for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;450ci++, compptr++) {451/* Don't bother to IDCT an uninteresting component. */452if (! compptr->component_needed)453continue;454/* Count non-dummy DCT block rows in this iMCU row. */455if (cinfo->output_iMCU_row < last_iMCU_row) {456block_rows = compptr->v_samp_factor;457access_rows = block_rows * 2; /* this and next iMCU row */458last_row = FALSE;459} else {460/* NB: can't use last_row_height here; it is input-side-dependent! */461block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);462if (block_rows == 0) block_rows = compptr->v_samp_factor;463access_rows = block_rows; /* this iMCU row only */464last_row = TRUE;465}466/* Align the virtual buffer for this component. */467if (cinfo->output_iMCU_row > 0) {468access_rows += compptr->v_samp_factor; /* prior iMCU row too */469buffer = (*cinfo->mem->access_virt_barray)470((j_common_ptr) cinfo, coef->whole_image[ci],471(cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,472(JDIMENSION) access_rows, FALSE);473buffer += compptr->v_samp_factor; /* point to current iMCU row */474first_row = FALSE;475} else {476buffer = (*cinfo->mem->access_virt_barray)477((j_common_ptr) cinfo, coef->whole_image[ci],478(JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);479first_row = TRUE;480}481/* Fetch component-dependent info */482coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);483quanttbl = compptr->quant_table;484Q00 = quanttbl->quantval[0];485Q01 = quanttbl->quantval[Q01_POS];486Q10 = quanttbl->quantval[Q10_POS];487Q20 = quanttbl->quantval[Q20_POS];488Q11 = quanttbl->quantval[Q11_POS];489Q02 = quanttbl->quantval[Q02_POS];490inverse_DCT = cinfo->idct->inverse_DCT[ci];491output_ptr = output_buf[ci];492/* Loop over all DCT blocks to be processed. */493for (block_row = 0; block_row < block_rows; block_row++) {494buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];495if (first_row && block_row == 0)496prev_block_row = buffer_ptr;497else498prev_block_row = buffer[block_row-1];499if (last_row && block_row == block_rows-1)500next_block_row = buffer_ptr;501else502next_block_row = buffer[block_row+1];503/* We fetch the surrounding DC values using a sliding-register approach.504* Initialize all nine here so as to do the right thing on narrow pics.505*/506DC1 = DC2 = DC3 = (int) prev_block_row[0][0];507DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];508DC7 = DC8 = DC9 = (int) next_block_row[0][0];509output_col = 0;510last_block_column = compptr->width_in_blocks - 1;511for (block_num = cinfo->master->first_MCU_col[ci];512block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {513/* Fetch current DCT block into workspace so we can modify it. */514jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);515/* Update DC values */516if (block_num < last_block_column) {517DC3 = (int) prev_block_row[1][0];518DC6 = (int) buffer_ptr[1][0];519DC9 = (int) next_block_row[1][0];520}521/* Compute coefficient estimates per K.8.522* An estimate is applied only if coefficient is still zero,523* and is not known to be fully accurate.524*/525/* AC01 */526if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {527num = 36 * Q00 * (DC4 - DC6);528if (num >= 0) {529pred = (int) (((Q01<<7) + num) / (Q01<<8));530if (Al > 0 && pred >= (1<<Al))531pred = (1<<Al)-1;532} else {533pred = (int) (((Q01<<7) - num) / (Q01<<8));534if (Al > 0 && pred >= (1<<Al))535pred = (1<<Al)-1;536pred = -pred;537}538workspace[1] = (JCOEF) pred;539}540/* AC10 */541if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {542num = 36 * Q00 * (DC2 - DC8);543if (num >= 0) {544pred = (int) (((Q10<<7) + num) / (Q10<<8));545if (Al > 0 && pred >= (1<<Al))546pred = (1<<Al)-1;547} else {548pred = (int) (((Q10<<7) - num) / (Q10<<8));549if (Al > 0 && pred >= (1<<Al))550pred = (1<<Al)-1;551pred = -pred;552}553workspace[8] = (JCOEF) pred;554}555/* AC20 */556if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {557num = 9 * Q00 * (DC2 + DC8 - 2*DC5);558if (num >= 0) {559pred = (int) (((Q20<<7) + num) / (Q20<<8));560if (Al > 0 && pred >= (1<<Al))561pred = (1<<Al)-1;562} else {563pred = (int) (((Q20<<7) - num) / (Q20<<8));564if (Al > 0 && pred >= (1<<Al))565pred = (1<<Al)-1;566pred = -pred;567}568workspace[16] = (JCOEF) pred;569}570/* AC11 */571if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {572num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);573if (num >= 0) {574pred = (int) (((Q11<<7) + num) / (Q11<<8));575if (Al > 0 && pred >= (1<<Al))576pred = (1<<Al)-1;577} else {578pred = (int) (((Q11<<7) - num) / (Q11<<8));579if (Al > 0 && pred >= (1<<Al))580pred = (1<<Al)-1;581pred = -pred;582}583workspace[9] = (JCOEF) pred;584}585/* AC02 */586if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {587num = 9 * Q00 * (DC4 + DC6 - 2*DC5);588if (num >= 0) {589pred = (int) (((Q02<<7) + num) / (Q02<<8));590if (Al > 0 && pred >= (1<<Al))591pred = (1<<Al)-1;592} else {593pred = (int) (((Q02<<7) - num) / (Q02<<8));594if (Al > 0 && pred >= (1<<Al))595pred = (1<<Al)-1;596pred = -pred;597}598workspace[2] = (JCOEF) pred;599}600/* OK, do the IDCT */601(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,602output_ptr, output_col);603/* Advance for next column */604DC1 = DC2; DC2 = DC3;605DC4 = DC5; DC5 = DC6;606DC7 = DC8; DC8 = DC9;607buffer_ptr++, prev_block_row++, next_block_row++;608output_col += compptr->_DCT_scaled_size;609}610output_ptr += compptr->_DCT_scaled_size;611}612}613614if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)615return JPEG_ROW_COMPLETED;616return JPEG_SCAN_COMPLETED;617}618619#endif /* BLOCK_SMOOTHING_SUPPORTED */620621622/*623* Initialize coefficient buffer controller.624*/625626GLOBAL(void)627jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)628{629my_coef_ptr coef;630631coef = (my_coef_ptr)632(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,633sizeof(my_coef_controller));634cinfo->coef = (struct jpeg_d_coef_controller *) coef;635coef->pub.start_input_pass = start_input_pass;636coef->pub.start_output_pass = start_output_pass;637#ifdef BLOCK_SMOOTHING_SUPPORTED638coef->coef_bits_latch = NULL;639#endif640641/* Create the coefficient buffer. */642if (need_full_buffer) {643#ifdef D_MULTISCAN_FILES_SUPPORTED644/* Allocate a full-image virtual array for each component, */645/* padded to a multiple of samp_factor DCT blocks in each direction. */646/* Note we ask for a pre-zeroed array. */647int ci, access_rows;648jpeg_component_info *compptr;649650for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;651ci++, compptr++) {652access_rows = compptr->v_samp_factor;653#ifdef BLOCK_SMOOTHING_SUPPORTED654/* If block smoothing could be used, need a bigger window */655if (cinfo->progressive_mode)656access_rows *= 3;657#endif658coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)659((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,660(JDIMENSION) jround_up((long) compptr->width_in_blocks,661(long) compptr->h_samp_factor),662(JDIMENSION) jround_up((long) compptr->height_in_blocks,663(long) compptr->v_samp_factor),664(JDIMENSION) access_rows);665}666coef->pub.consume_data = consume_data;667coef->pub.decompress_data = decompress_data;668coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */669#else670ERREXIT(cinfo, JERR_NOT_COMPILED);671#endif672} else {673/* We only need a single-MCU buffer. */674JBLOCKROW buffer;675int i;676677buffer = (JBLOCKROW)678(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,679D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));680for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {681coef->MCU_buffer[i] = buffer + i;682}683coef->pub.consume_data = dummy_consume_data;684coef->pub.decompress_data = decompress_onepass;685coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */686}687688/* Allocate the workspace buffer */689coef->workspace = (JCOEF *)690(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,691sizeof(JCOEF) * DCTSIZE2);692}693694695