istereo2

annotate libs/libjpeg/jccoefct.c @ 28:74b50b538858

added nexus7 device id for ad testing
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 05 Oct 2015 17:16:31 +0300
parents
children
rev   line source
nuclear@2 1 /*
nuclear@2 2 * jccoefct.c
nuclear@2 3 *
nuclear@2 4 * Copyright (C) 1994-1997, Thomas G. Lane.
nuclear@2 5 * This file is part of the Independent JPEG Group's software.
nuclear@2 6 * For conditions of distribution and use, see the accompanying README file.
nuclear@2 7 *
nuclear@2 8 * This file contains the coefficient buffer controller for compression.
nuclear@2 9 * This controller is the top level of the JPEG compressor proper.
nuclear@2 10 * The coefficient buffer lies between forward-DCT and entropy encoding steps.
nuclear@2 11 */
nuclear@2 12
nuclear@2 13 #define JPEG_INTERNALS
nuclear@2 14 #include "jinclude.h"
nuclear@2 15 #include "jpeglib.h"
nuclear@2 16
nuclear@2 17
nuclear@2 18 /* We use a full-image coefficient buffer when doing Huffman optimization,
nuclear@2 19 * and also for writing multiple-scan JPEG files. In all cases, the DCT
nuclear@2 20 * step is run during the first pass, and subsequent passes need only read
nuclear@2 21 * the buffered coefficients.
nuclear@2 22 */
nuclear@2 23 #ifdef ENTROPY_OPT_SUPPORTED
nuclear@2 24 #define FULL_COEF_BUFFER_SUPPORTED
nuclear@2 25 #else
nuclear@2 26 #ifdef C_MULTISCAN_FILES_SUPPORTED
nuclear@2 27 #define FULL_COEF_BUFFER_SUPPORTED
nuclear@2 28 #endif
nuclear@2 29 #endif
nuclear@2 30
nuclear@2 31
nuclear@2 32 /* Private buffer controller object */
nuclear@2 33
nuclear@2 34 typedef struct {
nuclear@2 35 struct jpeg_c_coef_controller pub; /* public fields */
nuclear@2 36
nuclear@2 37 JDIMENSION iMCU_row_num; /* iMCU row # within image */
nuclear@2 38 JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
nuclear@2 39 int MCU_vert_offset; /* counts MCU rows within iMCU row */
nuclear@2 40 int MCU_rows_per_iMCU_row; /* number of such rows needed */
nuclear@2 41
nuclear@2 42 /* For single-pass compression, it's sufficient to buffer just one MCU
nuclear@2 43 * (although this may prove a bit slow in practice). We allocate a
nuclear@2 44 * workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each
nuclear@2 45 * MCU constructed and sent. (On 80x86, the workspace is FAR even though
nuclear@2 46 * it's not really very big; this is to keep the module interfaces unchanged
nuclear@2 47 * when a large coefficient buffer is necessary.)
nuclear@2 48 * In multi-pass modes, this array points to the current MCU's blocks
nuclear@2 49 * within the virtual arrays.
nuclear@2 50 */
nuclear@2 51 JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
nuclear@2 52
nuclear@2 53 /* In multi-pass modes, we need a virtual block array for each component. */
nuclear@2 54 jvirt_barray_ptr whole_image[MAX_COMPONENTS];
nuclear@2 55 } my_coef_controller;
nuclear@2 56
nuclear@2 57 typedef my_coef_controller * my_coef_ptr;
nuclear@2 58
nuclear@2 59
nuclear@2 60 /* Forward declarations */
nuclear@2 61 METHODDEF(boolean) compress_data
nuclear@2 62 JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
nuclear@2 63 #ifdef FULL_COEF_BUFFER_SUPPORTED
nuclear@2 64 METHODDEF(boolean) compress_first_pass
nuclear@2 65 JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
nuclear@2 66 METHODDEF(boolean) compress_output
nuclear@2 67 JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
nuclear@2 68 #endif
nuclear@2 69
nuclear@2 70
nuclear@2 71 LOCAL(void)
nuclear@2 72 start_iMCU_row (j_compress_ptr cinfo)
nuclear@2 73 /* Reset within-iMCU-row counters for a new row */
nuclear@2 74 {
nuclear@2 75 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
nuclear@2 76
nuclear@2 77 /* In an interleaved scan, an MCU row is the same as an iMCU row.
nuclear@2 78 * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
nuclear@2 79 * But at the bottom of the image, process only what's left.
nuclear@2 80 */
nuclear@2 81 if (cinfo->comps_in_scan > 1) {
nuclear@2 82 coef->MCU_rows_per_iMCU_row = 1;
nuclear@2 83 } else {
nuclear@2 84 if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
nuclear@2 85 coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
nuclear@2 86 else
nuclear@2 87 coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
nuclear@2 88 }
nuclear@2 89
nuclear@2 90 coef->mcu_ctr = 0;
nuclear@2 91 coef->MCU_vert_offset = 0;
nuclear@2 92 }
nuclear@2 93
nuclear@2 94
nuclear@2 95 /*
nuclear@2 96 * Initialize for a processing pass.
nuclear@2 97 */
nuclear@2 98
nuclear@2 99 METHODDEF(void)
nuclear@2 100 start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
nuclear@2 101 {
nuclear@2 102 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
nuclear@2 103
nuclear@2 104 coef->iMCU_row_num = 0;
nuclear@2 105 start_iMCU_row(cinfo);
nuclear@2 106
nuclear@2 107 switch (pass_mode) {
nuclear@2 108 case JBUF_PASS_THRU:
nuclear@2 109 if (coef->whole_image[0] != NULL)
nuclear@2 110 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
nuclear@2 111 coef->pub.compress_data = compress_data;
nuclear@2 112 break;
nuclear@2 113 #ifdef FULL_COEF_BUFFER_SUPPORTED
nuclear@2 114 case JBUF_SAVE_AND_PASS:
nuclear@2 115 if (coef->whole_image[0] == NULL)
nuclear@2 116 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
nuclear@2 117 coef->pub.compress_data = compress_first_pass;
nuclear@2 118 break;
nuclear@2 119 case JBUF_CRANK_DEST:
nuclear@2 120 if (coef->whole_image[0] == NULL)
nuclear@2 121 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
nuclear@2 122 coef->pub.compress_data = compress_output;
nuclear@2 123 break;
nuclear@2 124 #endif
nuclear@2 125 default:
nuclear@2 126 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
nuclear@2 127 break;
nuclear@2 128 }
nuclear@2 129 }
nuclear@2 130
nuclear@2 131
nuclear@2 132 /*
nuclear@2 133 * Process some data in the single-pass case.
nuclear@2 134 * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
nuclear@2 135 * per call, ie, v_samp_factor block rows for each component in the image.
nuclear@2 136 * Returns TRUE if the iMCU row is completed, FALSE if suspended.
nuclear@2 137 *
nuclear@2 138 * NB: input_buf contains a plane for each component in image,
nuclear@2 139 * which we index according to the component's SOF position.
nuclear@2 140 */
nuclear@2 141
nuclear@2 142 METHODDEF(boolean)
nuclear@2 143 compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
nuclear@2 144 {
nuclear@2 145 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
nuclear@2 146 JDIMENSION MCU_col_num; /* index of current MCU within row */
nuclear@2 147 JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
nuclear@2 148 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
nuclear@2 149 int blkn, bi, ci, yindex, yoffset, blockcnt;
nuclear@2 150 JDIMENSION ypos, xpos;
nuclear@2 151 jpeg_component_info *compptr;
nuclear@2 152
nuclear@2 153 /* Loop to write as much as one whole iMCU row */
nuclear@2 154 for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
nuclear@2 155 yoffset++) {
nuclear@2 156 for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
nuclear@2 157 MCU_col_num++) {
nuclear@2 158 /* Determine where data comes from in input_buf and do the DCT thing.
nuclear@2 159 * Each call on forward_DCT processes a horizontal row of DCT blocks
nuclear@2 160 * as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks
nuclear@2 161 * sequentially. Dummy blocks at the right or bottom edge are filled in
nuclear@2 162 * specially. The data in them does not matter for image reconstruction,
nuclear@2 163 * so we fill them with values that will encode to the smallest amount of
nuclear@2 164 * data, viz: all zeroes in the AC entries, DC entries equal to previous
nuclear@2 165 * block's DC value. (Thanks to Thomas Kinsman for this idea.)
nuclear@2 166 */
nuclear@2 167 blkn = 0;
nuclear@2 168 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
nuclear@2 169 compptr = cinfo->cur_comp_info[ci];
nuclear@2 170 blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
nuclear@2 171 : compptr->last_col_width;
nuclear@2 172 xpos = MCU_col_num * compptr->MCU_sample_width;
nuclear@2 173 ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
nuclear@2 174 for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
nuclear@2 175 if (coef->iMCU_row_num < last_iMCU_row ||
nuclear@2 176 yoffset+yindex < compptr->last_row_height) {
nuclear@2 177 (*cinfo->fdct->forward_DCT) (cinfo, compptr,
nuclear@2 178 input_buf[compptr->component_index],
nuclear@2 179 coef->MCU_buffer[blkn],
nuclear@2 180 ypos, xpos, (JDIMENSION) blockcnt);
nuclear@2 181 if (blockcnt < compptr->MCU_width) {
nuclear@2 182 /* Create some dummy blocks at the right edge of the image. */
nuclear@2 183 jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
nuclear@2 184 (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
nuclear@2 185 for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
nuclear@2 186 coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
nuclear@2 187 }
nuclear@2 188 }
nuclear@2 189 } else {
nuclear@2 190 /* Create a row of dummy blocks at the bottom of the image. */
nuclear@2 191 jzero_far((void FAR *) coef->MCU_buffer[blkn],
nuclear@2 192 compptr->MCU_width * SIZEOF(JBLOCK));
nuclear@2 193 for (bi = 0; bi < compptr->MCU_width; bi++) {
nuclear@2 194 coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
nuclear@2 195 }
nuclear@2 196 }
nuclear@2 197 blkn += compptr->MCU_width;
nuclear@2 198 ypos += DCTSIZE;
nuclear@2 199 }
nuclear@2 200 }
nuclear@2 201 /* Try to write the MCU. In event of a suspension failure, we will
nuclear@2 202 * re-DCT the MCU on restart (a bit inefficient, could be fixed...)
nuclear@2 203 */
nuclear@2 204 if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
nuclear@2 205 /* Suspension forced; update state counters and exit */
nuclear@2 206 coef->MCU_vert_offset = yoffset;
nuclear@2 207 coef->mcu_ctr = MCU_col_num;
nuclear@2 208 return FALSE;
nuclear@2 209 }
nuclear@2 210 }
nuclear@2 211 /* Completed an MCU row, but perhaps not an iMCU row */
nuclear@2 212 coef->mcu_ctr = 0;
nuclear@2 213 }
nuclear@2 214 /* Completed the iMCU row, advance counters for next one */
nuclear@2 215 coef->iMCU_row_num++;
nuclear@2 216 start_iMCU_row(cinfo);
nuclear@2 217 return TRUE;
nuclear@2 218 }
nuclear@2 219
nuclear@2 220
nuclear@2 221 #ifdef FULL_COEF_BUFFER_SUPPORTED
nuclear@2 222
nuclear@2 223 /*
nuclear@2 224 * Process some data in the first pass of a multi-pass case.
nuclear@2 225 * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
nuclear@2 226 * per call, ie, v_samp_factor block rows for each component in the image.
nuclear@2 227 * This amount of data is read from the source buffer, DCT'd and quantized,
nuclear@2 228 * and saved into the virtual arrays. We also generate suitable dummy blocks
nuclear@2 229 * as needed at the right and lower edges. (The dummy blocks are constructed
nuclear@2 230 * in the virtual arrays, which have been padded appropriately.) This makes
nuclear@2 231 * it possible for subsequent passes not to worry about real vs. dummy blocks.
nuclear@2 232 *
nuclear@2 233 * We must also emit the data to the entropy encoder. This is conveniently
nuclear@2 234 * done by calling compress_output() after we've loaded the current strip
nuclear@2 235 * of the virtual arrays.
nuclear@2 236 *
nuclear@2 237 * NB: input_buf contains a plane for each component in image. All
nuclear@2 238 * components are DCT'd and loaded into the virtual arrays in this pass.
nuclear@2 239 * However, it may be that only a subset of the components are emitted to
nuclear@2 240 * the entropy encoder during this first pass; be careful about looking
nuclear@2 241 * at the scan-dependent variables (MCU dimensions, etc).
nuclear@2 242 */
nuclear@2 243
nuclear@2 244 METHODDEF(boolean)
nuclear@2 245 compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
nuclear@2 246 {
nuclear@2 247 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
nuclear@2 248 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
nuclear@2 249 JDIMENSION blocks_across, MCUs_across, MCUindex;
nuclear@2 250 int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
nuclear@2 251 JCOEF lastDC;
nuclear@2 252 jpeg_component_info *compptr;
nuclear@2 253 JBLOCKARRAY buffer;
nuclear@2 254 JBLOCKROW thisblockrow, lastblockrow;
nuclear@2 255
nuclear@2 256 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
nuclear@2 257 ci++, compptr++) {
nuclear@2 258 /* Align the virtual buffer for this component. */
nuclear@2 259 buffer = (*cinfo->mem->access_virt_barray)
nuclear@2 260 ((j_common_ptr) cinfo, coef->whole_image[ci],
nuclear@2 261 coef->iMCU_row_num * compptr->v_samp_factor,
nuclear@2 262 (JDIMENSION) compptr->v_samp_factor, TRUE);
nuclear@2 263 /* Count non-dummy DCT block rows in this iMCU row. */
nuclear@2 264 if (coef->iMCU_row_num < last_iMCU_row)
nuclear@2 265 block_rows = compptr->v_samp_factor;
nuclear@2 266 else {
nuclear@2 267 /* NB: can't use last_row_height here, since may not be set! */
nuclear@2 268 block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
nuclear@2 269 if (block_rows == 0) block_rows = compptr->v_samp_factor;
nuclear@2 270 }
nuclear@2 271 blocks_across = compptr->width_in_blocks;
nuclear@2 272 h_samp_factor = compptr->h_samp_factor;
nuclear@2 273 /* Count number of dummy blocks to be added at the right margin. */
nuclear@2 274 ndummy = (int) (blocks_across % h_samp_factor);
nuclear@2 275 if (ndummy > 0)
nuclear@2 276 ndummy = h_samp_factor - ndummy;
nuclear@2 277 /* Perform DCT for all non-dummy blocks in this iMCU row. Each call
nuclear@2 278 * on forward_DCT processes a complete horizontal row of DCT blocks.
nuclear@2 279 */
nuclear@2 280 for (block_row = 0; block_row < block_rows; block_row++) {
nuclear@2 281 thisblockrow = buffer[block_row];
nuclear@2 282 (*cinfo->fdct->forward_DCT) (cinfo, compptr,
nuclear@2 283 input_buf[ci], thisblockrow,
nuclear@2 284 (JDIMENSION) (block_row * DCTSIZE),
nuclear@2 285 (JDIMENSION) 0, blocks_across);
nuclear@2 286 if (ndummy > 0) {
nuclear@2 287 /* Create dummy blocks at the right edge of the image. */
nuclear@2 288 thisblockrow += blocks_across; /* => first dummy block */
nuclear@2 289 jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
nuclear@2 290 lastDC = thisblockrow[-1][0];
nuclear@2 291 for (bi = 0; bi < ndummy; bi++) {
nuclear@2 292 thisblockrow[bi][0] = lastDC;
nuclear@2 293 }
nuclear@2 294 }
nuclear@2 295 }
nuclear@2 296 /* If at end of image, create dummy block rows as needed.
nuclear@2 297 * The tricky part here is that within each MCU, we want the DC values
nuclear@2 298 * of the dummy blocks to match the last real block's DC value.
nuclear@2 299 * This squeezes a few more bytes out of the resulting file...
nuclear@2 300 */
nuclear@2 301 if (coef->iMCU_row_num == last_iMCU_row) {
nuclear@2 302 blocks_across += ndummy; /* include lower right corner */
nuclear@2 303 MCUs_across = blocks_across / h_samp_factor;
nuclear@2 304 for (block_row = block_rows; block_row < compptr->v_samp_factor;
nuclear@2 305 block_row++) {
nuclear@2 306 thisblockrow = buffer[block_row];
nuclear@2 307 lastblockrow = buffer[block_row-1];
nuclear@2 308 jzero_far((void FAR *) thisblockrow,
nuclear@2 309 (size_t) (blocks_across * SIZEOF(JBLOCK)));
nuclear@2 310 for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
nuclear@2 311 lastDC = lastblockrow[h_samp_factor-1][0];
nuclear@2 312 for (bi = 0; bi < h_samp_factor; bi++) {
nuclear@2 313 thisblockrow[bi][0] = lastDC;
nuclear@2 314 }
nuclear@2 315 thisblockrow += h_samp_factor; /* advance to next MCU in row */
nuclear@2 316 lastblockrow += h_samp_factor;
nuclear@2 317 }
nuclear@2 318 }
nuclear@2 319 }
nuclear@2 320 }
nuclear@2 321 /* NB: compress_output will increment iMCU_row_num if successful.
nuclear@2 322 * A suspension return will result in redoing all the work above next time.
nuclear@2 323 */
nuclear@2 324
nuclear@2 325 /* Emit data to the entropy encoder, sharing code with subsequent passes */
nuclear@2 326 return compress_output(cinfo, input_buf);
nuclear@2 327 }
nuclear@2 328
nuclear@2 329
nuclear@2 330 /*
nuclear@2 331 * Process some data in subsequent passes of a multi-pass case.
nuclear@2 332 * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
nuclear@2 333 * per call, ie, v_samp_factor block rows for each component in the scan.
nuclear@2 334 * The data is obtained from the virtual arrays and fed to the entropy coder.
nuclear@2 335 * Returns TRUE if the iMCU row is completed, FALSE if suspended.
nuclear@2 336 *
nuclear@2 337 * NB: input_buf is ignored; it is likely to be a NULL pointer.
nuclear@2 338 */
nuclear@2 339
nuclear@2 340 METHODDEF(boolean)
nuclear@2 341 compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
nuclear@2 342 {
nuclear@2 343 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
nuclear@2 344 JDIMENSION MCU_col_num; /* index of current MCU within row */
nuclear@2 345 int blkn, ci, xindex, yindex, yoffset;
nuclear@2 346 JDIMENSION start_col;
nuclear@2 347 JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
nuclear@2 348 JBLOCKROW buffer_ptr;
nuclear@2 349 jpeg_component_info *compptr;
nuclear@2 350
nuclear@2 351 /* Align the virtual buffers for the components used in this scan.
nuclear@2 352 * NB: during first pass, this is safe only because the buffers will
nuclear@2 353 * already be aligned properly, so jmemmgr.c won't need to do any I/O.
nuclear@2 354 */
nuclear@2 355 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
nuclear@2 356 compptr = cinfo->cur_comp_info[ci];
nuclear@2 357 buffer[ci] = (*cinfo->mem->access_virt_barray)
nuclear@2 358 ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
nuclear@2 359 coef->iMCU_row_num * compptr->v_samp_factor,
nuclear@2 360 (JDIMENSION) compptr->v_samp_factor, FALSE);
nuclear@2 361 }
nuclear@2 362
nuclear@2 363 /* Loop to process one whole iMCU row */
nuclear@2 364 for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
nuclear@2 365 yoffset++) {
nuclear@2 366 for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
nuclear@2 367 MCU_col_num++) {
nuclear@2 368 /* Construct list of pointers to DCT blocks belonging to this MCU */
nuclear@2 369 blkn = 0; /* index of current DCT block within MCU */
nuclear@2 370 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
nuclear@2 371 compptr = cinfo->cur_comp_info[ci];
nuclear@2 372 start_col = MCU_col_num * compptr->MCU_width;
nuclear@2 373 for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
nuclear@2 374 buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
nuclear@2 375 for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
nuclear@2 376 coef->MCU_buffer[blkn++] = buffer_ptr++;
nuclear@2 377 }
nuclear@2 378 }
nuclear@2 379 }
nuclear@2 380 /* Try to write the MCU. */
nuclear@2 381 if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
nuclear@2 382 /* Suspension forced; update state counters and exit */
nuclear@2 383 coef->MCU_vert_offset = yoffset;
nuclear@2 384 coef->mcu_ctr = MCU_col_num;
nuclear@2 385 return FALSE;
nuclear@2 386 }
nuclear@2 387 }
nuclear@2 388 /* Completed an MCU row, but perhaps not an iMCU row */
nuclear@2 389 coef->mcu_ctr = 0;
nuclear@2 390 }
nuclear@2 391 /* Completed the iMCU row, advance counters for next one */
nuclear@2 392 coef->iMCU_row_num++;
nuclear@2 393 start_iMCU_row(cinfo);
nuclear@2 394 return TRUE;
nuclear@2 395 }
nuclear@2 396
nuclear@2 397 #endif /* FULL_COEF_BUFFER_SUPPORTED */
nuclear@2 398
nuclear@2 399
nuclear@2 400 /*
nuclear@2 401 * Initialize coefficient buffer controller.
nuclear@2 402 */
nuclear@2 403
nuclear@2 404 GLOBAL(void)
nuclear@2 405 jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
nuclear@2 406 {
nuclear@2 407 my_coef_ptr coef;
nuclear@2 408
nuclear@2 409 coef = (my_coef_ptr)
nuclear@2 410 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
nuclear@2 411 SIZEOF(my_coef_controller));
nuclear@2 412 cinfo->coef = (struct jpeg_c_coef_controller *) coef;
nuclear@2 413 coef->pub.start_pass = start_pass_coef;
nuclear@2 414
nuclear@2 415 /* Create the coefficient buffer. */
nuclear@2 416 if (need_full_buffer) {
nuclear@2 417 #ifdef FULL_COEF_BUFFER_SUPPORTED
nuclear@2 418 /* Allocate a full-image virtual array for each component, */
nuclear@2 419 /* padded to a multiple of samp_factor DCT blocks in each direction. */
nuclear@2 420 int ci;
nuclear@2 421 jpeg_component_info *compptr;
nuclear@2 422
nuclear@2 423 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
nuclear@2 424 ci++, compptr++) {
nuclear@2 425 coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
nuclear@2 426 ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
nuclear@2 427 (JDIMENSION) jround_up((long) compptr->width_in_blocks,
nuclear@2 428 (long) compptr->h_samp_factor),
nuclear@2 429 (JDIMENSION) jround_up((long) compptr->height_in_blocks,
nuclear@2 430 (long) compptr->v_samp_factor),
nuclear@2 431 (JDIMENSION) compptr->v_samp_factor);
nuclear@2 432 }
nuclear@2 433 #else
nuclear@2 434 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
nuclear@2 435 #endif
nuclear@2 436 } else {
nuclear@2 437 /* We only need a single-MCU buffer. */
nuclear@2 438 JBLOCKROW buffer;
nuclear@2 439 int i;
nuclear@2 440
nuclear@2 441 buffer = (JBLOCKROW)
nuclear@2 442 (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
nuclear@2 443 C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
nuclear@2 444 for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
nuclear@2 445 coef->MCU_buffer[i] = buffer + i;
nuclear@2 446 }
nuclear@2 447 coef->whole_image[0] = NULL; /* flag for no virtual arrays */
nuclear@2 448 }
nuclear@2 449 }