Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * jdcoefct.c |
| 3 | * |
DRC | a73e870 | 2012-12-31 02:52:30 +0000 | [diff] [blame] | 4 | * This file was part of the Independent JPEG Group's software: |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 5 | * Copyright (C) 1994-1997, Thomas G. Lane. |
DRC | a6ef282 | 2013-09-28 03:23:49 +0000 | [diff] [blame] | 6 | * libjpeg-turbo Modifications: |
DRC | eb32cc1 | 2015-06-25 03:44:36 +0000 | [diff] [blame] | 7 | * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
DRC | ce0dd94 | 2016-02-06 12:18:44 -0600 | [diff] [blame] | 8 | * Copyright (C) 2010, 2015-2016, D. R. Commander. |
DRC | 7e3acc0 | 2015-10-10 10:25:46 -0500 | [diff] [blame] | 9 | * For conditions of distribution and use, see the accompanying README.ijg |
| 10 | * file. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 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. |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 15 | * |
| 16 | * In buffered-image mode, this controller is the interface between |
| 17 | * input-oriented processing and output-oriented processing. |
| 18 | * Also, the input side (only) is used when reading a file for transcoding. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
DRC | ce0dd94 | 2016-02-06 12:18:44 -0600 | [diff] [blame] | 21 | #include "jinclude.h" |
DRC | eb32cc1 | 2015-06-25 03:44:36 +0000 | [diff] [blame] | 22 | #include "jdcoefct.h" |
DRC | 36a6eec | 2010-10-08 08:05:44 +0000 | [diff] [blame] | 23 | #include "jpegcomp.h" |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 24 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 25 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 26 | /* Forward declarations */ |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 27 | METHODDEF(int) decompress_onepass |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 28 | (j_decompress_ptr cinfo, JSAMPIMAGE output_buf); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 29 | #ifdef D_MULTISCAN_FILES_SUPPORTED |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 30 | METHODDEF(int) decompress_data |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 31 | (j_decompress_ptr cinfo, JSAMPIMAGE output_buf); |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 32 | #endif |
| 33 | #ifdef BLOCK_SMOOTHING_SUPPORTED |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 34 | LOCAL(boolean) smoothing_ok (j_decompress_ptr cinfo); |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 35 | METHODDEF(int) decompress_smooth_data |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 36 | (j_decompress_ptr cinfo, JSAMPIMAGE output_buf); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 37 | #endif |
| 38 | |
| 39 | |
| 40 | /* |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 41 | * Initialize for an input processing pass. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 42 | */ |
| 43 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 44 | METHODDEF(void) |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 45 | start_input_pass (j_decompress_ptr cinfo) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 46 | { |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 47 | cinfo->input_iMCU_row = 0; |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 48 | start_iMCU_row(cinfo); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | |
| 52 | /* |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 53 | * Initialize for an output processing pass. |
| 54 | */ |
| 55 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 56 | METHODDEF(void) |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 57 | start_output_pass (j_decompress_ptr cinfo) |
| 58 | { |
| 59 | #ifdef BLOCK_SMOOTHING_SUPPORTED |
| 60 | my_coef_ptr coef = (my_coef_ptr) cinfo->coef; |
| 61 | |
| 62 | /* If multipass, check to see whether to use block smoothing on this pass */ |
| 63 | if (coef->pub.coef_arrays != NULL) { |
| 64 | if (cinfo->do_block_smoothing && smoothing_ok(cinfo)) |
| 65 | coef->pub.decompress_data = decompress_smooth_data; |
| 66 | else |
| 67 | coef->pub.decompress_data = decompress_data; |
| 68 | } |
| 69 | #endif |
| 70 | cinfo->output_iMCU_row = 0; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | /* |
| 75 | * Decompress and return some data in the single-pass case. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 76 | * Always attempts to emit one fully interleaved MCU row ("iMCU" row). |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 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. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 79 | * |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 80 | * NB: output_buf contains a plane for each component in image, |
| 81 | * which we index according to the component's SOF position. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 82 | */ |
| 83 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 84 | METHODDEF(int) |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 85 | decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 86 | { |
| 87 | my_coef_ptr coef = (my_coef_ptr) cinfo->coef; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 88 | JDIMENSION MCU_col_num; /* index of current MCU within row */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 89 | JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 90 | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
| 91 | int blkn, ci, xindex, yindex, yoffset, useful_width; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 92 | JSAMPARRAY output_ptr; |
| 93 | JDIMENSION start_col, output_col; |
| 94 | jpeg_component_info *compptr; |
| 95 | inverse_DCT_method_ptr inverse_DCT; |
| 96 | |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 97 | /* Loop to process as much as one whole iMCU row */ |
| 98 | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; |
| 99 | yoffset++) { |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 100 | for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 101 | MCU_col_num++) { |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 102 | /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ |
DRC | 5033f3e | 2014-05-18 18:33:44 +0000 | [diff] [blame] | 103 | jzero_far((void *) coef->MCU_buffer[0], |
DRC | 5de454b | 2014-05-18 19:04:03 +0000 | [diff] [blame] | 104 | (size_t) (cinfo->blocks_in_MCU * sizeof(JBLOCK))); |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 105 | if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 106 | /* Suspension forced; update state counters and exit */ |
| 107 | coef->MCU_vert_offset = yoffset; |
| 108 | coef->MCU_ctr = MCU_col_num; |
| 109 | return JPEG_SUSPENDED; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 110 | } |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 111 | /* Determine where data should go in output_buf and do the IDCT thing. |
| 112 | * We skip dummy blocks at the right and bottom edges (but blkn gets |
| 113 | * incremented past them!). Note the inner loop relies on having |
| 114 | * allocated the MCU_buffer[] blocks sequentially. |
| 115 | */ |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 116 | blkn = 0; /* index of current DCT block within MCU */ |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 117 | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 118 | compptr = cinfo->cur_comp_info[ci]; |
| 119 | /* Don't bother to IDCT an uninteresting component. */ |
| 120 | if (! compptr->component_needed) { |
| 121 | blkn += compptr->MCU_blocks; |
| 122 | continue; |
| 123 | } |
| 124 | inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index]; |
| 125 | useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width |
| 126 | : compptr->last_col_width; |
| 127 | output_ptr = output_buf[compptr->component_index] + |
| 128 | yoffset * compptr->_DCT_scaled_size; |
| 129 | start_col = MCU_col_num * compptr->MCU_sample_width; |
| 130 | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { |
| 131 | if (cinfo->input_iMCU_row < last_iMCU_row || |
| 132 | yoffset+yindex < compptr->last_row_height) { |
| 133 | output_col = start_col; |
| 134 | for (xindex = 0; xindex < useful_width; xindex++) { |
| 135 | (*inverse_DCT) (cinfo, compptr, |
| 136 | (JCOEFPTR) coef->MCU_buffer[blkn+xindex], |
| 137 | output_ptr, output_col); |
| 138 | output_col += compptr->_DCT_scaled_size; |
| 139 | } |
| 140 | } |
| 141 | blkn += compptr->MCU_width; |
| 142 | output_ptr += compptr->_DCT_scaled_size; |
| 143 | } |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 144 | } |
| 145 | } |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 146 | /* Completed an MCU row, but perhaps not an iMCU row */ |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 147 | coef->MCU_ctr = 0; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 148 | } |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 149 | /* Completed the iMCU row, advance counters for next one */ |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 150 | cinfo->output_iMCU_row++; |
| 151 | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { |
| 152 | start_iMCU_row(cinfo); |
| 153 | return JPEG_ROW_COMPLETED; |
| 154 | } |
| 155 | /* Completed the scan */ |
| 156 | (*cinfo->inputctl->finish_input_pass) (cinfo); |
| 157 | return JPEG_SCAN_COMPLETED; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | /* |
| 162 | * Dummy consume-input routine for single-pass operation. |
| 163 | */ |
| 164 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 165 | METHODDEF(int) |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 166 | dummy_consume_data (j_decompress_ptr cinfo) |
| 167 | { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 168 | return JPEG_SUSPENDED; /* Always indicate nothing was done */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | |
| 172 | #ifdef D_MULTISCAN_FILES_SUPPORTED |
| 173 | |
| 174 | /* |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 175 | * Consume input data and store it in the full-image coefficient buffer. |
| 176 | * We read as much as one fully interleaved MCU row ("iMCU" row) per call, |
| 177 | * ie, v_samp_factor block rows for each component in the scan. |
| 178 | * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 179 | */ |
| 180 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 181 | METHODDEF(int) |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 182 | consume_data (j_decompress_ptr cinfo) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 183 | { |
| 184 | my_coef_ptr coef = (my_coef_ptr) cinfo->coef; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 185 | JDIMENSION MCU_col_num; /* index of current MCU within row */ |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 186 | int blkn, ci, xindex, yindex, yoffset; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 187 | JDIMENSION start_col; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 188 | JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; |
| 189 | JBLOCKROW buffer_ptr; |
| 190 | jpeg_component_info *compptr; |
| 191 | |
| 192 | /* Align the virtual buffers for the components used in this scan. */ |
| 193 | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
| 194 | compptr = cinfo->cur_comp_info[ci]; |
| 195 | buffer[ci] = (*cinfo->mem->access_virt_barray) |
| 196 | ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 197 | cinfo->input_iMCU_row * compptr->v_samp_factor, |
| 198 | (JDIMENSION) compptr->v_samp_factor, TRUE); |
| 199 | /* Note: entropy decoder expects buffer to be zeroed, |
| 200 | * but this is handled automatically by the memory manager |
| 201 | * because we requested a pre-zeroed array. |
| 202 | */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 205 | /* Loop to process one whole iMCU row */ |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 206 | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; |
| 207 | yoffset++) { |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 208 | for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 209 | MCU_col_num++) { |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 210 | /* Construct list of pointers to DCT blocks belonging to this MCU */ |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 211 | blkn = 0; /* index of current DCT block within MCU */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 212 | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 213 | compptr = cinfo->cur_comp_info[ci]; |
| 214 | start_col = MCU_col_num * compptr->MCU_width; |
| 215 | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { |
| 216 | buffer_ptr = buffer[ci][yindex+yoffset] + start_col; |
| 217 | for (xindex = 0; xindex < compptr->MCU_width; xindex++) { |
| 218 | coef->MCU_buffer[blkn++] = buffer_ptr++; |
| 219 | } |
| 220 | } |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 221 | } |
| 222 | /* Try to fetch the MCU. */ |
| 223 | if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 224 | /* Suspension forced; update state counters and exit */ |
| 225 | coef->MCU_vert_offset = yoffset; |
| 226 | coef->MCU_ctr = MCU_col_num; |
| 227 | return JPEG_SUSPENDED; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 228 | } |
| 229 | } |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 230 | /* Completed an MCU row, but perhaps not an iMCU row */ |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 231 | coef->MCU_ctr = 0; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 232 | } |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 233 | /* Completed the iMCU row, advance counters for next one */ |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 234 | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { |
| 235 | start_iMCU_row(cinfo); |
| 236 | return JPEG_ROW_COMPLETED; |
| 237 | } |
| 238 | /* Completed the scan */ |
| 239 | (*cinfo->inputctl->finish_input_pass) (cinfo); |
| 240 | return JPEG_SCAN_COMPLETED; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | |
| 244 | /* |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 245 | * Decompress and return some data in the multi-pass case. |
| 246 | * Always attempts to emit one fully interleaved MCU row ("iMCU" row). |
| 247 | * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 248 | * |
| 249 | * NB: output_buf contains a plane for each component in image. |
| 250 | */ |
| 251 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 252 | METHODDEF(int) |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 253 | decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 254 | { |
| 255 | my_coef_ptr coef = (my_coef_ptr) cinfo->coef; |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 256 | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 257 | JDIMENSION block_num; |
| 258 | int ci, block_row, block_rows; |
| 259 | JBLOCKARRAY buffer; |
| 260 | JBLOCKROW buffer_ptr; |
| 261 | JSAMPARRAY output_ptr; |
| 262 | JDIMENSION output_col; |
| 263 | jpeg_component_info *compptr; |
| 264 | inverse_DCT_method_ptr inverse_DCT; |
| 265 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 266 | /* Force some input to be done if we are getting ahead of the input. */ |
| 267 | while (cinfo->input_scan_number < cinfo->output_scan_number || |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 268 | (cinfo->input_scan_number == cinfo->output_scan_number && |
| 269 | cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 270 | if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) |
| 271 | return JPEG_SUSPENDED; |
| 272 | } |
| 273 | |
| 274 | /* OK, output from the virtual arrays. */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 275 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 276 | ci++, compptr++) { |
| 277 | /* Don't bother to IDCT an uninteresting component. */ |
| 278 | if (! compptr->component_needed) |
| 279 | continue; |
| 280 | /* Align the virtual buffer for this component. */ |
| 281 | buffer = (*cinfo->mem->access_virt_barray) |
| 282 | ((j_common_ptr) cinfo, coef->whole_image[ci], |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 283 | cinfo->output_iMCU_row * compptr->v_samp_factor, |
| 284 | (JDIMENSION) compptr->v_samp_factor, FALSE); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 285 | /* Count non-dummy DCT block rows in this iMCU row. */ |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 286 | if (cinfo->output_iMCU_row < last_iMCU_row) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 287 | block_rows = compptr->v_samp_factor; |
| 288 | else { |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 289 | /* NB: can't use last_row_height here; it is input-side-dependent! */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 290 | block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); |
| 291 | if (block_rows == 0) block_rows = compptr->v_samp_factor; |
| 292 | } |
| 293 | inverse_DCT = cinfo->idct->inverse_DCT[ci]; |
| 294 | output_ptr = output_buf[ci]; |
| 295 | /* Loop over all DCT blocks to be processed. */ |
| 296 | for (block_row = 0; block_row < block_rows; block_row++) { |
| 297 | buffer_ptr = buffer[block_row]; |
| 298 | output_col = 0; |
| 299 | for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 300 | (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr, |
| 301 | output_ptr, output_col); |
| 302 | buffer_ptr++; |
| 303 | output_col += compptr->_DCT_scaled_size; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 304 | } |
DRC | 49967cd | 2010-10-09 19:57:51 +0000 | [diff] [blame] | 305 | output_ptr += compptr->_DCT_scaled_size; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 309 | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) |
| 310 | return JPEG_ROW_COMPLETED; |
| 311 | return JPEG_SCAN_COMPLETED; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | #endif /* D_MULTISCAN_FILES_SUPPORTED */ |
| 315 | |
| 316 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 317 | #ifdef BLOCK_SMOOTHING_SUPPORTED |
| 318 | |
| 319 | /* |
| 320 | * This code applies interblock smoothing as described by section K.8 |
| 321 | * of the JPEG standard: the first 5 AC coefficients are estimated from |
| 322 | * the DC values of a DCT block and its 8 neighboring blocks. |
| 323 | * We apply smoothing only for progressive JPEG decoding, and only if |
| 324 | * the coefficients it can estimate are not yet known to full precision. |
| 325 | */ |
| 326 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 327 | /* Natural-order array positions of the first 5 zigzag-order coefficients */ |
| 328 | #define Q01_POS 1 |
| 329 | #define Q10_POS 8 |
| 330 | #define Q20_POS 16 |
| 331 | #define Q11_POS 9 |
| 332 | #define Q02_POS 2 |
| 333 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 334 | /* |
| 335 | * Determine whether block smoothing is applicable and safe. |
| 336 | * We also latch the current states of the coef_bits[] entries for the |
| 337 | * AC coefficients; otherwise, if the input side of the decompressor |
| 338 | * advances into a new scan, we might think the coefficients are known |
| 339 | * more accurately than they really are. |
| 340 | */ |
| 341 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 342 | LOCAL(boolean) |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 343 | smoothing_ok (j_decompress_ptr cinfo) |
| 344 | { |
| 345 | my_coef_ptr coef = (my_coef_ptr) cinfo->coef; |
| 346 | boolean smoothing_useful = FALSE; |
| 347 | int ci, coefi; |
| 348 | jpeg_component_info *compptr; |
| 349 | JQUANT_TBL * qtable; |
| 350 | int * coef_bits; |
| 351 | int * coef_bits_latch; |
| 352 | |
| 353 | if (! cinfo->progressive_mode || cinfo->coef_bits == NULL) |
| 354 | return FALSE; |
| 355 | |
| 356 | /* Allocate latch area if not already done */ |
| 357 | if (coef->coef_bits_latch == NULL) |
| 358 | coef->coef_bits_latch = (int *) |
| 359 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 360 | cinfo->num_components * |
DRC | 5de454b | 2014-05-18 19:04:03 +0000 | [diff] [blame] | 361 | (SAVED_COEFS * sizeof(int))); |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 362 | coef_bits_latch = coef->coef_bits_latch; |
| 363 | |
| 364 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 365 | ci++, compptr++) { |
| 366 | /* All components' quantization values must already be latched. */ |
| 367 | if ((qtable = compptr->quant_table) == NULL) |
| 368 | return FALSE; |
| 369 | /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */ |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 370 | if (qtable->quantval[0] == 0 || |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 371 | qtable->quantval[Q01_POS] == 0 || |
| 372 | qtable->quantval[Q10_POS] == 0 || |
| 373 | qtable->quantval[Q20_POS] == 0 || |
| 374 | qtable->quantval[Q11_POS] == 0 || |
| 375 | qtable->quantval[Q02_POS] == 0) |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 376 | return FALSE; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 377 | /* DC values must be at least partly known for all components. */ |
| 378 | coef_bits = cinfo->coef_bits[ci]; |
| 379 | if (coef_bits[0] < 0) |
| 380 | return FALSE; |
| 381 | /* Block smoothing is helpful if some AC coefficients remain inaccurate. */ |
| 382 | for (coefi = 1; coefi <= 5; coefi++) { |
| 383 | coef_bits_latch[coefi] = coef_bits[coefi]; |
| 384 | if (coef_bits[coefi] != 0) |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 385 | smoothing_useful = TRUE; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 386 | } |
| 387 | coef_bits_latch += SAVED_COEFS; |
| 388 | } |
| 389 | |
| 390 | return smoothing_useful; |
| 391 | } |
| 392 | |
| 393 | |
| 394 | /* |
| 395 | * Variant of decompress_data for use when doing block smoothing. |
| 396 | */ |
| 397 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 398 | METHODDEF(int) |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 399 | decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) |
| 400 | { |
| 401 | my_coef_ptr coef = (my_coef_ptr) cinfo->coef; |
| 402 | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
| 403 | JDIMENSION block_num, last_block_column; |
| 404 | int ci, block_row, block_rows, access_rows; |
| 405 | JBLOCKARRAY buffer; |
| 406 | JBLOCKROW buffer_ptr, prev_block_row, next_block_row; |
| 407 | JSAMPARRAY output_ptr; |
| 408 | JDIMENSION output_col; |
| 409 | jpeg_component_info *compptr; |
| 410 | inverse_DCT_method_ptr inverse_DCT; |
| 411 | boolean first_row, last_row; |
Pierre Ossman | 35c4719 | 2009-03-09 13:29:37 +0000 | [diff] [blame] | 412 | JCOEF * workspace; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 413 | int *coef_bits; |
| 414 | JQUANT_TBL *quanttbl; |
DRC | 1e32fe3 | 2015-10-14 17:32:39 -0500 | [diff] [blame] | 415 | JLONG Q00,Q01,Q02,Q10,Q11,Q20, num; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 416 | int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9; |
| 417 | int Al, pred; |
| 418 | |
Pierre Ossman | 35c4719 | 2009-03-09 13:29:37 +0000 | [diff] [blame] | 419 | /* Keep a local variable to avoid looking it up more than once */ |
| 420 | workspace = coef->workspace; |
| 421 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 422 | /* Force some input to be done if we are getting ahead of the input. */ |
| 423 | while (cinfo->input_scan_number <= cinfo->output_scan_number && |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 424 | ! cinfo->inputctl->eoi_reached) { |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 425 | if (cinfo->input_scan_number == cinfo->output_scan_number) { |
| 426 | /* If input is working on current scan, we ordinarily want it to |
| 427 | * have completed the current row. But if input scan is DC, |
| 428 | * we want it to keep one row ahead so that next block row's DC |
| 429 | * values are up to date. |
| 430 | */ |
| 431 | JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0; |
| 432 | if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta) |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 433 | break; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 434 | } |
| 435 | if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) |
| 436 | return JPEG_SUSPENDED; |
| 437 | } |
| 438 | |
| 439 | /* OK, output from the virtual arrays. */ |
| 440 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 441 | ci++, compptr++) { |
| 442 | /* Don't bother to IDCT an uninteresting component. */ |
| 443 | if (! compptr->component_needed) |
| 444 | continue; |
| 445 | /* Count non-dummy DCT block rows in this iMCU row. */ |
| 446 | if (cinfo->output_iMCU_row < last_iMCU_row) { |
| 447 | block_rows = compptr->v_samp_factor; |
| 448 | access_rows = block_rows * 2; /* this and next iMCU row */ |
| 449 | last_row = FALSE; |
| 450 | } else { |
| 451 | /* NB: can't use last_row_height here; it is input-side-dependent! */ |
| 452 | block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); |
| 453 | if (block_rows == 0) block_rows = compptr->v_samp_factor; |
| 454 | access_rows = block_rows; /* this iMCU row only */ |
| 455 | last_row = TRUE; |
| 456 | } |
| 457 | /* Align the virtual buffer for this component. */ |
| 458 | if (cinfo->output_iMCU_row > 0) { |
| 459 | access_rows += compptr->v_samp_factor; /* prior iMCU row too */ |
| 460 | buffer = (*cinfo->mem->access_virt_barray) |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 461 | ((j_common_ptr) cinfo, coef->whole_image[ci], |
| 462 | (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor, |
| 463 | (JDIMENSION) access_rows, FALSE); |
| 464 | buffer += compptr->v_samp_factor; /* point to current iMCU row */ |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 465 | first_row = FALSE; |
| 466 | } else { |
| 467 | buffer = (*cinfo->mem->access_virt_barray) |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 468 | ((j_common_ptr) cinfo, coef->whole_image[ci], |
| 469 | (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE); |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 470 | first_row = TRUE; |
| 471 | } |
| 472 | /* Fetch component-dependent info */ |
| 473 | coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS); |
| 474 | quanttbl = compptr->quant_table; |
| 475 | Q00 = quanttbl->quantval[0]; |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 476 | Q01 = quanttbl->quantval[Q01_POS]; |
| 477 | Q10 = quanttbl->quantval[Q10_POS]; |
| 478 | Q20 = quanttbl->quantval[Q20_POS]; |
| 479 | Q11 = quanttbl->quantval[Q11_POS]; |
| 480 | Q02 = quanttbl->quantval[Q02_POS]; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 481 | inverse_DCT = cinfo->idct->inverse_DCT[ci]; |
| 482 | output_ptr = output_buf[ci]; |
| 483 | /* Loop over all DCT blocks to be processed. */ |
| 484 | for (block_row = 0; block_row < block_rows; block_row++) { |
| 485 | buffer_ptr = buffer[block_row]; |
| 486 | if (first_row && block_row == 0) |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 487 | prev_block_row = buffer_ptr; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 488 | else |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 489 | prev_block_row = buffer[block_row-1]; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 490 | if (last_row && block_row == block_rows-1) |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 491 | next_block_row = buffer_ptr; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 492 | else |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 493 | next_block_row = buffer[block_row+1]; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 494 | /* We fetch the surrounding DC values using a sliding-register approach. |
| 495 | * Initialize all nine here so as to do the right thing on narrow pics. |
| 496 | */ |
| 497 | DC1 = DC2 = DC3 = (int) prev_block_row[0][0]; |
| 498 | DC4 = DC5 = DC6 = (int) buffer_ptr[0][0]; |
| 499 | DC7 = DC8 = DC9 = (int) next_block_row[0][0]; |
| 500 | output_col = 0; |
| 501 | last_block_column = compptr->width_in_blocks - 1; |
| 502 | for (block_num = 0; block_num <= last_block_column; block_num++) { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 503 | /* Fetch current DCT block into workspace so we can modify it. */ |
| 504 | jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1); |
| 505 | /* Update DC values */ |
| 506 | if (block_num < last_block_column) { |
| 507 | DC3 = (int) prev_block_row[1][0]; |
| 508 | DC6 = (int) buffer_ptr[1][0]; |
| 509 | DC9 = (int) next_block_row[1][0]; |
| 510 | } |
| 511 | /* Compute coefficient estimates per K.8. |
| 512 | * An estimate is applied only if coefficient is still zero, |
| 513 | * and is not known to be fully accurate. |
| 514 | */ |
| 515 | /* AC01 */ |
| 516 | if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) { |
| 517 | num = 36 * Q00 * (DC4 - DC6); |
| 518 | if (num >= 0) { |
| 519 | pred = (int) (((Q01<<7) + num) / (Q01<<8)); |
| 520 | if (Al > 0 && pred >= (1<<Al)) |
| 521 | pred = (1<<Al)-1; |
| 522 | } else { |
| 523 | pred = (int) (((Q01<<7) - num) / (Q01<<8)); |
| 524 | if (Al > 0 && pred >= (1<<Al)) |
| 525 | pred = (1<<Al)-1; |
| 526 | pred = -pred; |
| 527 | } |
| 528 | workspace[1] = (JCOEF) pred; |
| 529 | } |
| 530 | /* AC10 */ |
| 531 | if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) { |
| 532 | num = 36 * Q00 * (DC2 - DC8); |
| 533 | if (num >= 0) { |
| 534 | pred = (int) (((Q10<<7) + num) / (Q10<<8)); |
| 535 | if (Al > 0 && pred >= (1<<Al)) |
| 536 | pred = (1<<Al)-1; |
| 537 | } else { |
| 538 | pred = (int) (((Q10<<7) - num) / (Q10<<8)); |
| 539 | if (Al > 0 && pred >= (1<<Al)) |
| 540 | pred = (1<<Al)-1; |
| 541 | pred = -pred; |
| 542 | } |
| 543 | workspace[8] = (JCOEF) pred; |
| 544 | } |
| 545 | /* AC20 */ |
| 546 | if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) { |
| 547 | num = 9 * Q00 * (DC2 + DC8 - 2*DC5); |
| 548 | if (num >= 0) { |
| 549 | pred = (int) (((Q20<<7) + num) / (Q20<<8)); |
| 550 | if (Al > 0 && pred >= (1<<Al)) |
| 551 | pred = (1<<Al)-1; |
| 552 | } else { |
| 553 | pred = (int) (((Q20<<7) - num) / (Q20<<8)); |
| 554 | if (Al > 0 && pred >= (1<<Al)) |
| 555 | pred = (1<<Al)-1; |
| 556 | pred = -pred; |
| 557 | } |
| 558 | workspace[16] = (JCOEF) pred; |
| 559 | } |
| 560 | /* AC11 */ |
| 561 | if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) { |
| 562 | num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9); |
| 563 | if (num >= 0) { |
| 564 | pred = (int) (((Q11<<7) + num) / (Q11<<8)); |
| 565 | if (Al > 0 && pred >= (1<<Al)) |
| 566 | pred = (1<<Al)-1; |
| 567 | } else { |
| 568 | pred = (int) (((Q11<<7) - num) / (Q11<<8)); |
| 569 | if (Al > 0 && pred >= (1<<Al)) |
| 570 | pred = (1<<Al)-1; |
| 571 | pred = -pred; |
| 572 | } |
| 573 | workspace[9] = (JCOEF) pred; |
| 574 | } |
| 575 | /* AC02 */ |
| 576 | if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) { |
| 577 | num = 9 * Q00 * (DC4 + DC6 - 2*DC5); |
| 578 | if (num >= 0) { |
| 579 | pred = (int) (((Q02<<7) + num) / (Q02<<8)); |
| 580 | if (Al > 0 && pred >= (1<<Al)) |
| 581 | pred = (1<<Al)-1; |
| 582 | } else { |
| 583 | pred = (int) (((Q02<<7) - num) / (Q02<<8)); |
| 584 | if (Al > 0 && pred >= (1<<Al)) |
| 585 | pred = (1<<Al)-1; |
| 586 | pred = -pred; |
| 587 | } |
| 588 | workspace[2] = (JCOEF) pred; |
| 589 | } |
| 590 | /* OK, do the IDCT */ |
| 591 | (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace, |
| 592 | output_ptr, output_col); |
| 593 | /* Advance for next column */ |
| 594 | DC1 = DC2; DC2 = DC3; |
| 595 | DC4 = DC5; DC5 = DC6; |
| 596 | DC7 = DC8; DC8 = DC9; |
| 597 | buffer_ptr++, prev_block_row++, next_block_row++; |
| 598 | output_col += compptr->_DCT_scaled_size; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 599 | } |
DRC | 49967cd | 2010-10-09 19:57:51 +0000 | [diff] [blame] | 600 | output_ptr += compptr->_DCT_scaled_size; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | |
| 604 | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) |
| 605 | return JPEG_ROW_COMPLETED; |
| 606 | return JPEG_SCAN_COMPLETED; |
| 607 | } |
| 608 | |
| 609 | #endif /* BLOCK_SMOOTHING_SUPPORTED */ |
| 610 | |
| 611 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 612 | /* |
| 613 | * Initialize coefficient buffer controller. |
| 614 | */ |
| 615 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 616 | GLOBAL(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 617 | jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer) |
| 618 | { |
| 619 | my_coef_ptr coef; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 620 | |
| 621 | coef = (my_coef_ptr) |
| 622 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
DRC | 5de454b | 2014-05-18 19:04:03 +0000 | [diff] [blame] | 623 | sizeof(my_coef_controller)); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 624 | cinfo->coef = (struct jpeg_d_coef_controller *) coef; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 625 | coef->pub.start_input_pass = start_input_pass; |
| 626 | coef->pub.start_output_pass = start_output_pass; |
| 627 | #ifdef BLOCK_SMOOTHING_SUPPORTED |
| 628 | coef->coef_bits_latch = NULL; |
| 629 | #endif |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 630 | |
| 631 | /* Create the coefficient buffer. */ |
| 632 | if (need_full_buffer) { |
| 633 | #ifdef D_MULTISCAN_FILES_SUPPORTED |
| 634 | /* Allocate a full-image virtual array for each component, */ |
| 635 | /* padded to a multiple of samp_factor DCT blocks in each direction. */ |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 636 | /* Note we ask for a pre-zeroed array. */ |
| 637 | int ci, access_rows; |
| 638 | jpeg_component_info *compptr; |
| 639 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 640 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 641 | ci++, compptr++) { |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 642 | access_rows = compptr->v_samp_factor; |
| 643 | #ifdef BLOCK_SMOOTHING_SUPPORTED |
| 644 | /* If block smoothing could be used, need a bigger window */ |
| 645 | if (cinfo->progressive_mode) |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 646 | access_rows *= 3; |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 647 | #endif |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 648 | coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 649 | ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE, |
| 650 | (JDIMENSION) jround_up((long) compptr->width_in_blocks, |
| 651 | (long) compptr->h_samp_factor), |
| 652 | (JDIMENSION) jround_up((long) compptr->height_in_blocks, |
| 653 | (long) compptr->v_samp_factor), |
| 654 | (JDIMENSION) access_rows); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 655 | } |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 656 | coef->pub.consume_data = consume_data; |
| 657 | coef->pub.decompress_data = decompress_data; |
| 658 | coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 659 | #else |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 660 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 661 | #endif |
| 662 | } else { |
| 663 | /* We only need a single-MCU buffer. */ |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 664 | JBLOCKROW buffer; |
| 665 | int i; |
| 666 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 667 | buffer = (JBLOCKROW) |
| 668 | (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
DRC | 5de454b | 2014-05-18 19:04:03 +0000 | [diff] [blame] | 669 | D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK)); |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 670 | for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 671 | coef->MCU_buffer[i] = buffer + i; |
| 672 | } |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 673 | coef->pub.consume_data = dummy_consume_data; |
| 674 | coef->pub.decompress_data = decompress_onepass; |
| 675 | coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 676 | } |
Pierre Ossman | 35c4719 | 2009-03-09 13:29:37 +0000 | [diff] [blame] | 677 | |
| 678 | /* Allocate the workspace buffer */ |
| 679 | coef->workspace = (JCOEF *) |
| 680 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
DRC | 5de454b | 2014-05-18 19:04:03 +0000 | [diff] [blame] | 681 | sizeof(JCOEF) * DCTSIZE2); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 682 | } |