Final 350 project

Dependencies:   uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed

Committer:
shoaib_ahmed
Date:
Mon Jul 31 09:16:35 2017 +0000
Revision:
0:791a779d6220
final project;

Who changed what in which revision?

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