Doxygen Source Code Documentation
jccoefct.c File Reference
#include "jinclude.h"#include "jpeglib.h"Go to the source code of this file.
Data Structures | |
| struct | my_coef_controller |
Defines | |
| #define | JPEG_INTERNALS |
| #define | FULL_COEF_BUFFER_SUPPORTED |
Typedefs | |
| typedef my_coef_controller * | my_coef_ptr |
Functions | |
| METHODDEF (boolean) compress_data JPP((j_compress_ptr cinfo | |
| start_iMCU_row (j_compress_ptr cinfo) | |
| start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode) | |
| compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf) | |
| compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf) | |
| compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf) | |
| jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer) | |
Variables | |
| JSAMPIMAGE | input_buf |
Define Documentation
|
|
Definition at line 24 of file jccoefct.c. |
|
|
Definition at line 13 of file jccoefct.c. |
Typedef Documentation
|
|
Definition at line 57 of file jccoefct.c. |
Function Documentation
|
||||||||||||
|
Definition at line 143 of file jccoefct.c. References jpeg_compress_struct::coef, jpeg_component_info::component_index, compptr, jpeg_compress_struct::comps_in_scan, jpeg_compress_struct::cur_comp_info, jpeg_compress_struct::entropy, jpeg_compress_struct::fdct, my_coef_controller::iMCU_row_num, JBLOCK, JDIMENSION, JSAMPIMAGE, jzero_far(), jpeg_component_info::last_col_width, jpeg_component_info::last_row_height, my_coef_controller::MCU_buffer, my_coef_controller::mcu_ctr, jpeg_component_info::MCU_height, my_coef_controller::MCU_rows_per_iMCU_row, jpeg_component_info::MCU_sample_width, my_coef_controller::MCU_vert_offset, jpeg_component_info::MCU_width, jpeg_compress_struct::MCUs_per_row, SIZEOF, start_iMCU_row(), and jpeg_compress_struct::total_iMCU_rows. Referenced by start_pass_coef().
00144 {
00145 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
00146 JDIMENSION MCU_col_num; /* index of current MCU within row */
00147 JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
00148 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
00149 int blkn, bi, ci, yindex, yoffset, blockcnt;
00150 JDIMENSION ypos, xpos;
00151 jpeg_component_info *compptr;
00152
00153 /* Loop to write as much as one whole iMCU row */
00154 for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
00155 yoffset++) {
00156 for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
00157 MCU_col_num++) {
00158 /* Determine where data comes from in input_buf and do the DCT thing.
00159 * Each call on forward_DCT processes a horizontal row of DCT blocks
00160 * as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks
00161 * sequentially. Dummy blocks at the right or bottom edge are filled in
00162 * specially. The data in them does not matter for image reconstruction,
00163 * so we fill them with values that will encode to the smallest amount of
00164 * data, viz: all zeroes in the AC entries, DC entries equal to previous
00165 * block's DC value. (Thanks to Thomas Kinsman for this idea.)
00166 */
00167 blkn = 0;
00168 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
00169 compptr = cinfo->cur_comp_info[ci];
00170 blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
00171 : compptr->last_col_width;
00172 xpos = MCU_col_num * compptr->MCU_sample_width;
00173 ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
00174 for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
00175 if (coef->iMCU_row_num < last_iMCU_row ||
00176 yoffset+yindex < compptr->last_row_height) {
00177 (*cinfo->fdct->forward_DCT) (cinfo, compptr,
00178 input_buf[compptr->component_index],
00179 coef->MCU_buffer[blkn],
00180 ypos, xpos, (JDIMENSION) blockcnt);
00181 if (blockcnt < compptr->MCU_width) {
00182 /* Create some dummy blocks at the right edge of the image. */
00183 jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
00184 (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
00185 for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
00186 coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
00187 }
00188 }
00189 } else {
00190 /* Create a row of dummy blocks at the bottom of the image. */
00191 jzero_far((void FAR *) coef->MCU_buffer[blkn],
00192 compptr->MCU_width * SIZEOF(JBLOCK));
00193 for (bi = 0; bi < compptr->MCU_width; bi++) {
00194 coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
00195 }
00196 }
00197 blkn += compptr->MCU_width;
00198 ypos += DCTSIZE;
00199 }
00200 }
00201 /* Try to write the MCU. In event of a suspension failure, we will
00202 * re-DCT the MCU on restart (a bit inefficient, could be fixed...)
00203 */
00204 if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
00205 /* Suspension forced; update state counters and exit */
00206 coef->MCU_vert_offset = yoffset;
00207 coef->mcu_ctr = MCU_col_num;
00208 return FALSE;
00209 }
00210 }
00211 /* Completed an MCU row, but perhaps not an iMCU row */
00212 coef->mcu_ctr = 0;
00213 }
00214 /* Completed the iMCU row, advance counters for next one */
00215 coef->iMCU_row_num++;
00216 start_iMCU_row(cinfo);
00217 return TRUE;
00218 }
|
|
||||||||||||
|
Definition at line 245 of file jccoefct.c. References jpeg_compress_struct::coef, jpeg_compress_struct::comp_info, compptr, compress_output(), jpeg_component_info::h_samp_factor, jpeg_component_info::height_in_blocks, my_coef_controller::iMCU_row_num, JBLOCK, JBLOCKARRAY, JBLOCKROW, JCOEF, JDIMENSION, JSAMPIMAGE, jzero_far(), jpeg_compress_struct::num_components, SIZEOF, jpeg_compress_struct::total_iMCU_rows, jpeg_component_info::v_samp_factor, my_coef_controller::whole_image, and jpeg_component_info::width_in_blocks. Referenced by start_pass_coef().
00246 {
00247 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
00248 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
00249 JDIMENSION blocks_across, MCUs_across, MCUindex;
00250 int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
00251 JCOEF lastDC;
00252 jpeg_component_info *compptr;
00253 JBLOCKARRAY buffer;
00254 JBLOCKROW thisblockrow, lastblockrow;
00255
00256 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00257 ci++, compptr++) {
00258 /* Align the virtual buffer for this component. */
00259 buffer = (*cinfo->mem->access_virt_barray)
00260 ((j_common_ptr) cinfo, coef->whole_image[ci],
00261 coef->iMCU_row_num * compptr->v_samp_factor,
00262 (JDIMENSION) compptr->v_samp_factor, TRUE);
00263 /* Count non-dummy DCT block rows in this iMCU row. */
00264 if (coef->iMCU_row_num < last_iMCU_row)
00265 block_rows = compptr->v_samp_factor;
00266 else {
00267 /* NB: can't use last_row_height here, since may not be set! */
00268 block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
00269 if (block_rows == 0) block_rows = compptr->v_samp_factor;
00270 }
00271 blocks_across = compptr->width_in_blocks;
00272 h_samp_factor = compptr->h_samp_factor;
00273 /* Count number of dummy blocks to be added at the right margin. */
00274 ndummy = (int) (blocks_across % h_samp_factor);
00275 if (ndummy > 0)
00276 ndummy = h_samp_factor - ndummy;
00277 /* Perform DCT for all non-dummy blocks in this iMCU row. Each call
00278 * on forward_DCT processes a complete horizontal row of DCT blocks.
00279 */
00280 for (block_row = 0; block_row < block_rows; block_row++) {
00281 thisblockrow = buffer[block_row];
00282 (*cinfo->fdct->forward_DCT) (cinfo, compptr,
00283 input_buf[ci], thisblockrow,
00284 (JDIMENSION) (block_row * DCTSIZE),
00285 (JDIMENSION) 0, blocks_across);
00286 if (ndummy > 0) {
00287 /* Create dummy blocks at the right edge of the image. */
00288 thisblockrow += blocks_across; /* => first dummy block */
00289 jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
00290 lastDC = thisblockrow[-1][0];
00291 for (bi = 0; bi < ndummy; bi++) {
00292 thisblockrow[bi][0] = lastDC;
00293 }
00294 }
00295 }
00296 /* If at end of image, create dummy block rows as needed.
00297 * The tricky part here is that within each MCU, we want the DC values
00298 * of the dummy blocks to match the last real block's DC value.
00299 * This squeezes a few more bytes out of the resulting file...
00300 */
00301 if (coef->iMCU_row_num == last_iMCU_row) {
00302 blocks_across += ndummy; /* include lower right corner */
00303 MCUs_across = blocks_across / h_samp_factor;
00304 for (block_row = block_rows; block_row < compptr->v_samp_factor;
00305 block_row++) {
00306 thisblockrow = buffer[block_row];
00307 lastblockrow = buffer[block_row-1];
00308 jzero_far((void FAR *) thisblockrow,
00309 (size_t) (blocks_across * SIZEOF(JBLOCK)));
00310 for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
00311 lastDC = lastblockrow[h_samp_factor-1][0];
00312 for (bi = 0; bi < h_samp_factor; bi++) {
00313 thisblockrow[bi][0] = lastDC;
00314 }
00315 thisblockrow += h_samp_factor; /* advance to next MCU in row */
00316 lastblockrow += h_samp_factor;
00317 }
00318 }
00319 }
00320 }
00321 /* NB: compress_output will increment iMCU_row_num if successful.
00322 * A suspension return will result in redoing all the work above next time.
00323 */
00324
00325 /* Emit data to the entropy encoder, sharing code with subsequent passes */
00326 return compress_output(cinfo, input_buf);
00327 }
|
|
||||||||||||
|
Definition at line 341 of file jccoefct.c. References jpeg_compress_struct::coef, jpeg_component_info::component_index, compptr, jpeg_compress_struct::comps_in_scan, jpeg_compress_struct::cur_comp_info, jpeg_compress_struct::entropy, my_coef_controller::iMCU_row_num, JBLOCKARRAY, JBLOCKROW, JDIMENSION, JSAMPIMAGE, MAX_COMPS_IN_SCAN, my_coef_controller::MCU_buffer, my_coef_controller::mcu_ctr, jpeg_component_info::MCU_height, my_coef_controller::MCU_rows_per_iMCU_row, my_coef_controller::MCU_vert_offset, jpeg_component_info::MCU_width, jpeg_compress_struct::MCUs_per_row, start_iMCU_row(), jpeg_component_info::v_samp_factor, and my_coef_controller::whole_image. Referenced by start_pass_coef().
00342 {
00343 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
00344 JDIMENSION MCU_col_num; /* index of current MCU within row */
00345 int blkn, ci, xindex, yindex, yoffset;
00346 JDIMENSION start_col;
00347 JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
00348 JBLOCKROW buffer_ptr;
00349 jpeg_component_info *compptr;
00350
00351 /* Align the virtual buffers for the components used in this scan.
00352 * NB: during first pass, this is safe only because the buffers will
00353 * already be aligned properly, so jmemmgr.c won't need to do any I/O.
00354 */
00355 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
00356 compptr = cinfo->cur_comp_info[ci];
00357 buffer[ci] = (*cinfo->mem->access_virt_barray)
00358 ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
00359 coef->iMCU_row_num * compptr->v_samp_factor,
00360 (JDIMENSION) compptr->v_samp_factor, FALSE);
00361 }
00362
00363 /* Loop to process one whole iMCU row */
00364 for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
00365 yoffset++) {
00366 for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
00367 MCU_col_num++) {
00368 /* Construct list of pointers to DCT blocks belonging to this MCU */
00369 blkn = 0; /* index of current DCT block within MCU */
00370 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
00371 compptr = cinfo->cur_comp_info[ci];
00372 start_col = MCU_col_num * compptr->MCU_width;
00373 for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
00374 buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
00375 for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
00376 coef->MCU_buffer[blkn++] = buffer_ptr++;
00377 }
00378 }
00379 }
00380 /* Try to write the MCU. */
00381 if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
00382 /* Suspension forced; update state counters and exit */
00383 coef->MCU_vert_offset = yoffset;
00384 coef->mcu_ctr = MCU_col_num;
00385 return FALSE;
00386 }
00387 }
00388 /* Completed an MCU row, but perhaps not an iMCU row */
00389 coef->mcu_ctr = 0;
00390 }
00391 /* Completed the iMCU row, advance counters for next one */
00392 coef->iMCU_row_num++;
00393 start_iMCU_row(cinfo);
00394 return TRUE;
00395 }
|
|
||||||||||||
|
Definition at line 405 of file jccoefct.c. References C_MAX_BLOCKS_IN_MCU, compptr, ERREXIT, jpeg_component_info::h_samp_factor, jpeg_component_info::height_in_blocks, i, JBLOCK, JBLOCKROW, JPOOL_IMAGE, jround_up(), need_full_buffer, SIZEOF, start_pass_coef(), jpeg_component_info::v_samp_factor, and jpeg_component_info::width_in_blocks. Referenced by jinit_compress_master().
00406 {
00407 my_coef_ptr coef;
00408
00409 coef = (my_coef_ptr)
00410 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00411 SIZEOF(my_coef_controller));
00412 cinfo->coef = (struct jpeg_c_coef_controller *) coef;
00413 coef->pub.start_pass = start_pass_coef;
00414
00415 /* Create the coefficient buffer. */
00416 if (need_full_buffer) {
00417 #ifdef FULL_COEF_BUFFER_SUPPORTED
00418 /* Allocate a full-image virtual array for each component, */
00419 /* padded to a multiple of samp_factor DCT blocks in each direction. */
00420 int ci;
00421 jpeg_component_info *compptr;
00422
00423 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00424 ci++, compptr++) {
00425 coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
00426 ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
00427 (JDIMENSION) jround_up((long) compptr->width_in_blocks,
00428 (long) compptr->h_samp_factor),
00429 (JDIMENSION) jround_up((long) compptr->height_in_blocks,
00430 (long) compptr->v_samp_factor),
00431 (JDIMENSION) compptr->v_samp_factor);
00432 }
00433 #else
00434 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
00435 #endif
00436 } else {
00437 /* We only need a single-MCU buffer. */
00438 JBLOCKROW buffer;
00439 int i;
00440
00441 buffer = (JBLOCKROW)
00442 (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00443 C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
00444 for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
00445 coef->MCU_buffer[i] = buffer + i;
00446 }
00447 coef->whole_image[0] = NULL; /* flag for no virtual arrays */
00448 }
00449 }
|
|
|
|
|
|
Definition at line 72 of file jccoefct.c. References jpeg_compress_struct::coef, jpeg_compress_struct::comps_in_scan, jpeg_compress_struct::cur_comp_info, my_coef_controller::iMCU_row_num, jpeg_component_info::last_row_height, my_coef_controller::mcu_ctr, my_coef_controller::MCU_rows_per_iMCU_row, my_coef_controller::MCU_vert_offset, jpeg_compress_struct::total_iMCU_rows, and jpeg_component_info::v_samp_factor.
00074 {
00075 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
00076
00077 /* In an interleaved scan, an MCU row is the same as an iMCU row.
00078 * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
00079 * But at the bottom of the image, process only what's left.
00080 */
00081 if (cinfo->comps_in_scan > 1) {
00082 coef->MCU_rows_per_iMCU_row = 1;
00083 } else {
00084 if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
00085 coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
00086 else
00087 coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
00088 }
00089
00090 coef->mcu_ctr = 0;
00091 coef->MCU_vert_offset = 0;
00092 }
|
|
||||||||||||
|
Definition at line 100 of file jccoefct.c. References jpeg_compress_struct::coef, compress_data(), compress_first_pass(), compress_output(), ERREXIT, my_coef_controller::iMCU_row_num, J_BUF_MODE, JBUF_CRANK_DEST, JBUF_PASS_THRU, JBUF_SAVE_AND_PASS, my_coef_controller::pub, start_iMCU_row(), and my_coef_controller::whole_image. Referenced by jinit_c_coef_controller().
00101 {
00102 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
00103
00104 coef->iMCU_row_num = 0;
00105 start_iMCU_row(cinfo);
00106
00107 switch (pass_mode) {
00108 case JBUF_PASS_THRU:
00109 if (coef->whole_image[0] != NULL)
00110 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
00111 coef->pub.compress_data = compress_data;
00112 break;
00113 #ifdef FULL_COEF_BUFFER_SUPPORTED
00114 case JBUF_SAVE_AND_PASS:
00115 if (coef->whole_image[0] == NULL)
00116 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
00117 coef->pub.compress_data = compress_first_pass;
00118 break;
00119 case JBUF_CRANK_DEST:
00120 if (coef->whole_image[0] == NULL)
00121 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
00122 coef->pub.compress_data = compress_output;
00123 break;
00124 #endif
00125 default:
00126 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
00127 break;
00128 }
00129 }
|
Variable Documentation
|
|
Definition at line 61 of file jdpostct.c. Referenced by post_process_1pass(), post_process_2pass(), and post_process_prepass(). |