compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf) { j_lossless_c_ptr losslsc = (j_lossless_c_ptr) cinfo->codec; c_diff_ptr diff = (c_diff_ptr) losslsc->diff_private; JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; JDIMENSION samps_across; int ci, samp_row, samp_rows; JSAMPARRAY buffer[MAX_COMPONENTS]; jpeg_component_info *compptr; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; ci++, compptr++) { /* Align the virtual buffers for this component. */ buffer[ci] = (*cinfo->mem->access_virt_sarray) ((j_common_ptr) cinfo, diff->whole_image[ci], diff->iMCU_row_num * compptr->v_samp_factor, (JDIMENSION) compptr->v_samp_factor, TRUE); /* Count non-dummy sample rows in this iMCU row. */ if (diff->iMCU_row_num < last_iMCU_row) samp_rows = compptr->v_samp_factor; else { /* NB: can't use last_row_height here, since may not be set! */ samp_rows = (int) (compptr->height_in_data_units % compptr->v_samp_factor); if (samp_rows == 0) samp_rows = compptr->v_samp_factor; } samps_across = compptr->width_in_data_units; /* Perform point transform scaling and prediction/differencing for all * non-dummy rows in this iMCU row. Each call on these functions * process a complete row of samples. */ for (samp_row = 0; samp_row < samp_rows; samp_row++) { MEMCOPY(buffer[ci][samp_row], input_buf[ci][samp_row], samps_across * SIZEOF(JSAMPLE)); } } /* NB: compress_output will increment iMCU_row_num if successful. * A suspension return will result in redoing all the work above next time. */ /* Emit data to the compressor, sharing code with subsequent passes */ return compress_output(cinfo, input_buf); }
compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf) { my_coef_ptr coef = (my_coef_ptr) cinfo->coef; JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; JDIMENSION blocks_across, MCUs_across, MCUindex; int bi, ci, h_samp_factor, block_row, block_rows, ndummy; JCOEF lastDC; jpeg_component_info *compptr; JBLOCKARRAY buffer; JBLOCKROW thisblockrow, lastblockrow; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; ci++, compptr++) { /* Align the virtual buffer for this component. */ buffer = (*cinfo->mem->access_virt_barray) ((j_common_ptr) cinfo, coef->whole_image[ci], coef->iMCU_row_num * compptr->v_samp_factor, (JDIMENSION) compptr->v_samp_factor, TRUE); /* Count non-dummy DCT block rows in this iMCU row. */ if (coef->iMCU_row_num < last_iMCU_row) block_rows = compptr->v_samp_factor; else { /* NB: can't use last_row_height here, since may not be set! */ block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); if (block_rows == 0) block_rows = compptr->v_samp_factor; } blocks_across = compptr->width_in_blocks; h_samp_factor = compptr->h_samp_factor; /* Count number of dummy blocks to be added at the right margin. */ ndummy = (int) (blocks_across % h_samp_factor); if (ndummy > 0) ndummy = h_samp_factor - ndummy; /* Perform DCT for all non-dummy blocks in this iMCU row. Each call * on forward_DCT processes a complete horizontal row of DCT blocks. */ for (block_row = 0; block_row < block_rows; block_row++) { thisblockrow = buffer[block_row]; (*cinfo->fdct->forward_DCT) (cinfo, compptr, input_buf[ci], thisblockrow, (JDIMENSION) (block_row * DCTSIZE), (JDIMENSION) 0, blocks_across); if (ndummy > 0) { /* Create dummy blocks at the right edge of the image. */ thisblockrow += blocks_across; /* => first dummy block */ jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK)); lastDC = thisblockrow[-1][0]; for (bi = 0; bi < ndummy; bi++) { thisblockrow[bi][0] = lastDC; } } } /* If at end of image, create dummy block rows as needed. * The tricky part here is that within each MCU, we want the DC values * of the dummy blocks to match the last real block's DC value. * This squeezes a few more bytes out of the resulting file... */ if (coef->iMCU_row_num == last_iMCU_row) { blocks_across += ndummy; /* include lower right corner */ MCUs_across = blocks_across / h_samp_factor; for (block_row = block_rows; block_row < compptr->v_samp_factor; block_row++) { thisblockrow = buffer[block_row]; lastblockrow = buffer[block_row-1]; jzero_far((void FAR *) thisblockrow, (size_t) (blocks_across * SIZEOF(JBLOCK))); for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) { lastDC = lastblockrow[h_samp_factor-1][0]; for (bi = 0; bi < h_samp_factor; bi++) { thisblockrow[bi][0] = lastDC; } thisblockrow += h_samp_factor; /* advance to next MCU in row */ lastblockrow += h_samp_factor; } } } } /* NB: compress_output will increment iMCU_row_num if successful. * A suspension return will result in redoing all the work above next time. */ /* Emit data to the entropy encoder, sharing code with subsequent passes */ return compress_output(cinfo, input_buf); }
compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf) { my_coef_ptr coef = (my_coef_ptr) cinfo->coef; JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; JDIMENSION blocks_across, MCUs_across, MCUindex; int bi, ci, h_samp_factor, block_row, block_rows, ndummy; JCOEF lastDC; jpeg_component_info *compptr; JBLOCKARRAY buffer; JBLOCKROW thisblockrow, lastblockrow; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; ci++, compptr++) { buffer = (*cinfo->mem->access_virt_barray) ((j_common_ptr) cinfo, coef->whole_image[ci], coef->iMCU_row_num * compptr->v_samp_factor, (JDIMENSION) compptr->v_samp_factor, TRUE); if (coef->iMCU_row_num < last_iMCU_row) block_rows = compptr->v_samp_factor; else { block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); if (block_rows == 0) block_rows = compptr->v_samp_factor; } blocks_across = compptr->width_in_blocks; h_samp_factor = compptr->h_samp_factor; ndummy = (int) (blocks_across % h_samp_factor); if (ndummy > 0) ndummy = h_samp_factor - ndummy; for (block_row = 0; block_row < block_rows; block_row++) { thisblockrow = buffer[block_row]; (*cinfo->fdct->forward_DCT) (cinfo, compptr, input_buf[ci], thisblockrow, (JDIMENSION) (block_row * DCTSIZE), (JDIMENSION) 0, blocks_across); if (ndummy > 0) { thisblockrow += blocks_across; jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK)); lastDC = thisblockrow[-1][0]; for (bi = 0; bi < ndummy; bi++) { thisblockrow[bi][0] = lastDC; } } } if (coef->iMCU_row_num == last_iMCU_row) { blocks_across += ndummy; MCUs_across = blocks_across / h_samp_factor; for (block_row = block_rows; block_row < compptr->v_samp_factor; block_row++) { thisblockrow = buffer[block_row]; lastblockrow = buffer[block_row-1]; jzero_far((void FAR *) thisblockrow, (size_t) (blocks_across * SIZEOF(JBLOCK))); for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) { lastDC = lastblockrow[h_samp_factor-1][0]; for (bi = 0; bi < h_samp_factor; bi++) { thisblockrow[bi][0] = lastDC; } thisblockrow += h_samp_factor; lastblockrow += h_samp_factor; } } } } return compress_output(cinfo, input_buf); }
compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf) { my_coef_ptr coef = (my_coef_ptr) cinfo->coef; __boundcheck_metadata_store((void *)(&coef),(void *)((size_t)(&coef)+sizeof(coef)*8-1)); JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; __boundcheck_metadata_store((void *)(&last_iMCU_row),(void *)((size_t)(&last_iMCU_row)+sizeof(last_iMCU_row)*8-1)); JDIMENSION blocks_across; __boundcheck_metadata_store((void *)(&blocks_across),(void *)((size_t)(&blocks_across)+sizeof(blocks_across)*8-1)); JDIMENSION MCUs_across; __boundcheck_metadata_store((void *)(&MCUs_across),(void *)((size_t)(&MCUs_across)+sizeof(MCUs_across)*8-1)); JDIMENSION MCUindex; __boundcheck_metadata_store((void *)(&MCUindex),(void *)((size_t)(&MCUindex)+sizeof(MCUindex)*8-1)); int bi; __boundcheck_metadata_store((void *)(&bi),(void *)((size_t)(&bi)+sizeof(bi)*8-1)); int ci; __boundcheck_metadata_store((void *)(&ci),(void *)((size_t)(&ci)+sizeof(ci)*8-1)); int h_samp_factor; __boundcheck_metadata_store((void *)(&h_samp_factor),(void *)((size_t)(&h_samp_factor)+sizeof(h_samp_factor)*8-1)); int block_row; __boundcheck_metadata_store((void *)(&block_row),(void *)((size_t)(&block_row)+sizeof(block_row)*8-1)); int block_rows; __boundcheck_metadata_store((void *)(&block_rows),(void *)((size_t)(&block_rows)+sizeof(block_rows)*8-1)); int ndummy; __boundcheck_metadata_store((void *)(&ndummy),(void *)((size_t)(&ndummy)+sizeof(ndummy)*8-1)); JCOEF lastDC; __boundcheck_metadata_store((void *)(&lastDC),(void *)((size_t)(&lastDC)+sizeof(lastDC)*8-1)); jpeg_component_info *compptr; __boundcheck_metadata_store((void *)(&compptr),(void *)((size_t)(&compptr)+sizeof(compptr)*8-1)); JBLOCKARRAY buffer; __boundcheck_metadata_store((void *)(&buffer),(void *)((size_t)(&buffer)+sizeof(buffer)*8-1)); JBLOCKROW thisblockrow; __boundcheck_metadata_store((void *)(&thisblockrow),(void *)((size_t)(&thisblockrow)+sizeof(thisblockrow)*8-1)); JBLOCKROW lastblockrow; __boundcheck_metadata_store((void *)(&lastblockrow),(void *)((size_t)(&lastblockrow)+sizeof(lastblockrow)*8-1)); for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; ci++, compptr++) { /* Align the virtual buffer for this component. */ buffer = (*(JBLOCKARRAY (*)(j_common_ptr, jvirt_barray_ptr, JDIMENSION, JDIMENSION, boolean))(__boundcheck_ptr_reference(258,28,"compress_first_pass",(void *)(cinfo->mem->access_virt_barray),(void *)cinfo->mem->access_virt_barray))) ((j_common_ptr) cinfo, coef->whole_image[_RV_insert_check(0,10,259,30,"compress_first_pass",ci)], coef->iMCU_row_num * compptr->v_samp_factor, (JDIMENSION) compptr->v_samp_factor, TRUE); /* Count non-dummy DCT block rows in this iMCU row. */ if (coef->iMCU_row_num < last_iMCU_row) block_rows = compptr->v_samp_factor; else { /* NB: can't use last_row_height here, since may not be set! */ block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); if (block_rows == 0) block_rows = compptr->v_samp_factor; } blocks_across = compptr->width_in_blocks; h_samp_factor = compptr->h_samp_factor; /* Count number of dummy blocks to be added at the right margin. */ ndummy = (int) (blocks_across % h_samp_factor); if (ndummy > 0) ndummy = h_samp_factor - ndummy; /* Perform DCT for all non-dummy blocks in this iMCU row. Each call * on forward_DCT processes a complete horizontal row of DCT blocks. */ for (block_row = 0; block_row < block_rows; block_row++) { thisblockrow = (*(JBLOCKROW *)(__boundcheck_ptr_reference(280,22,"compress_first_pass",(void *)(&buffer[0]),(void *)(&buffer[block_row])))); (*(void (*)(j_compress_ptr, jpeg_component_info *, JSAMPARRAY, JBLOCKROW, JDIMENSION, JDIMENSION, JDIMENSION))(__boundcheck_ptr_reference(281,22,"compress_first_pass",(void *)(cinfo->fdct->forward_DCT),(void *)cinfo->fdct->forward_DCT))) (cinfo, compptr, (*(JSAMPARRAY *)(__boundcheck_ptr_reference(282,8,"compress_first_pass",(void *)(&input_buf[0]),(void *)(&input_buf[ci])))), thisblockrow, (JDIMENSION) (block_row * DCTSIZE), (JDIMENSION) 0, blocks_across); if (ndummy > 0) { /* Create dummy blocks at the right edge of the image. */ thisblockrow += blocks_across; /* => first dummy block */ jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK)); lastDC = (*(JCOEF *)(__boundcheck_ptr_reference(289,11,"compress_first_pass",(void *)(&thisblockrow[-1][0]),(void *)(&thisblockrow[-1][0])))); for (bi = 0; bi < ndummy; bi++) { (*(JCOEF *)(__boundcheck_ptr_reference(291,4,"compress_first_pass",(void *)(&thisblockrow[bi][0]),(void *)(&thisblockrow[bi][0])))) = lastDC; } } } /* If at end of image, create dummy block rows as needed. * The tricky part here is that within each MCU, we want the DC values * of the dummy blocks to match the last real block's DC value. * This squeezes a few more bytes out of the resulting file... */ if (coef->iMCU_row_num == last_iMCU_row) { blocks_across += ndummy; /* include lower right corner */ MCUs_across = blocks_across / h_samp_factor; for (block_row = block_rows; block_row < compptr->v_samp_factor; block_row++) { thisblockrow = (*(JBLOCKROW *)(__boundcheck_ptr_reference(305,17,"compress_first_pass",(void *)(&buffer[0]),(void *)(&buffer[block_row])))); lastblockrow = (*(JBLOCKROW *)(__boundcheck_ptr_reference(306,17,"compress_first_pass",(void *)(&buffer[0]),(void *)(&buffer[block_row - 1])))); jzero_far((void FAR *) thisblockrow, (size_t) (blocks_across * SIZEOF(JBLOCK))); for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) { lastDC = (*(JCOEF *)(__boundcheck_ptr_reference(310,13,"compress_first_pass",(void *)(&lastblockrow[h_samp_factor - 1][0]),(void *)(&lastblockrow[h_samp_factor - 1][0])))); for (bi = 0; bi < h_samp_factor; bi++) { (*(JCOEF *)(__boundcheck_ptr_reference(312,6,"compress_first_pass",(void *)(&thisblockrow[bi][0]),(void *)(&thisblockrow[bi][0])))) = lastDC; } thisblockrow += h_samp_factor; /* advance to next MCU in row */ lastblockrow += h_samp_factor; } } } } /* NB: compress_output will increment iMCU_row_num if successful. * A suspension return will result in redoing all the work above next time. */ /* Emit data to the entropy encoder, sharing code with subsequent passes */ return compress_output(cinfo, input_buf); }
compress_trellis_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf) { my_coef_ptr coef = (my_coef_ptr) cinfo->coef; JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; JDIMENSION blocks_across, MCUs_across, MCUindex; int bi, ci, h_samp_factor, block_row, block_rows, ndummy; JCOEF lastDC; jpeg_component_info *compptr; JBLOCKARRAY buffer; JBLOCKROW thisblockrow, lastblockrow; JBLOCKARRAY buffer_dst; for (ci = 0; ci < cinfo->comps_in_scan; ci++) { c_derived_tbl dctbl_data; c_derived_tbl *dctbl = &dctbl_data; c_derived_tbl actbl_data; c_derived_tbl *actbl = &actbl_data; #ifdef C_ARITH_CODING_SUPPORTED arith_rates arith_r_data; arith_rates *arith_r = &arith_r_data; #endif compptr = cinfo->cur_comp_info[ci]; #ifdef C_ARITH_CODING_SUPPORTED if (cinfo->arith_code) jget_arith_rates(cinfo, compptr->dc_tbl_no, compptr->ac_tbl_no, arith_r); else #endif { jpeg_make_c_derived_tbl(cinfo, TRUE, compptr->dc_tbl_no, &dctbl); jpeg_make_c_derived_tbl(cinfo, FALSE, compptr->ac_tbl_no, &actbl); } /* Align the virtual buffer for this component. */ buffer = (*cinfo->mem->access_virt_barray) ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], coef->iMCU_row_num * compptr->v_samp_factor, (JDIMENSION) compptr->v_samp_factor, TRUE); buffer_dst = (*cinfo->mem->access_virt_barray) ((j_common_ptr) cinfo, coef->whole_image_uq[compptr->component_index], coef->iMCU_row_num * compptr->v_samp_factor, (JDIMENSION) compptr->v_samp_factor, TRUE); /* Count non-dummy DCT block rows in this iMCU row. */ if (coef->iMCU_row_num < last_iMCU_row) block_rows = compptr->v_samp_factor; else { /* NB: can't use last_row_height here, since may not be set! */ block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); if (block_rows == 0) block_rows = compptr->v_samp_factor; } blocks_across = compptr->width_in_blocks; h_samp_factor = compptr->h_samp_factor; /* Count number of dummy blocks to be added at the right margin. */ ndummy = (int) (blocks_across % h_samp_factor); if (ndummy > 0) ndummy = h_samp_factor - ndummy; lastDC = 0; /* Perform DCT for all non-dummy blocks in this iMCU row. Each call * on forward_DCT processes a complete horizontal row of DCT blocks. */ for (block_row = 0; block_row < block_rows; block_row++) { thisblockrow = buffer[block_row]; lastblockrow = (block_row > 0) ? buffer[block_row-1] : NULL; #ifdef C_ARITH_CODING_SUPPORTED if (cinfo->arith_code) quantize_trellis_arith(cinfo, arith_r, thisblockrow, buffer_dst[block_row], blocks_across, cinfo->quant_tbl_ptrs[compptr->quant_tbl_no], cinfo->master->norm_src[compptr->quant_tbl_no], cinfo->master->norm_coef[compptr->quant_tbl_no], &lastDC, lastblockrow, buffer_dst[block_row-1]); else #endif quantize_trellis(cinfo, dctbl, actbl, thisblockrow, buffer_dst[block_row], blocks_across, cinfo->quant_tbl_ptrs[compptr->quant_tbl_no], cinfo->master->norm_src[compptr->quant_tbl_no], cinfo->master->norm_coef[compptr->quant_tbl_no], &lastDC, lastblockrow, buffer_dst[block_row-1]); if (ndummy > 0) { /* Create dummy blocks at the right edge of the image. */ thisblockrow += blocks_across; /* => first dummy block */ jzero_far((void *) thisblockrow, ndummy * sizeof(JBLOCK)); lastDC = thisblockrow[-1][0]; for (bi = 0; bi < ndummy; bi++) { thisblockrow[bi][0] = lastDC; } } } /* If at end of image, create dummy block rows as needed. * The tricky part here is that within each MCU, we want the DC values * of the dummy blocks to match the last real block's DC value. * This squeezes a few more bytes out of the resulting file... */ if (coef->iMCU_row_num == last_iMCU_row) { blocks_across += ndummy; /* include lower right corner */ MCUs_across = blocks_across / h_samp_factor; for (block_row = block_rows; block_row < compptr->v_samp_factor; block_row++) { thisblockrow = buffer[block_row]; lastblockrow = buffer[block_row-1]; jzero_far((void *) thisblockrow, (size_t) (blocks_across * sizeof(JBLOCK))); for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) { lastDC = lastblockrow[h_samp_factor-1][0]; for (bi = 0; bi < h_samp_factor; bi++) { thisblockrow[bi][0] = lastDC; } thisblockrow += h_samp_factor; /* advance to next MCU in row */ lastblockrow += h_samp_factor; } } } } /* NB: compress_output will increment iMCU_row_num if successful. * A suspension return will result in redoing all the work above next time. */ /* Emit data to the entropy encoder, sharing code with subsequent passes */ return compress_output(cinfo, input_buf); }