istereo

annotate libs/libjpeg/jccoefct.c @ 39:ff055bff6a15

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