Doxygen Source Code Documentation
jcphuff.c File Reference
#include "jinclude.h"#include "jpeglib.h"#include "jchuff.h"Go to the source code of this file.
Define Documentation
|
|
Value: { *(entropy)->next_output_byte++ = (JOCTET) (val); \
if (--(entropy)->free_in_buffer == 0) \
dump_buffer(entropy); } |
|
|
Definition at line 85 of file jcphuff.c. Referenced by encode_mcu_DC_first(). |
|
|
Definition at line 84 of file jcphuff.c. Referenced by encode_mcu_DC_first(). |
|
|
|
|
|
Definition at line 70 of file jcphuff.c. Referenced by encode_mcu_AC_refine(), and start_pass_phuff(). |
Typedef Documentation
|
|
|
Function Documentation
|
|
Definition at line 205 of file jcphuff.c. References ERREXIT, jpeg_destination_mgr::free_in_buffer, and jpeg_destination_mgr::next_output_byte.
00207 {
00208 struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
00209
00210 if (! (*dest->empty_output_buffer) (entropy->cinfo))
00211 ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
00212 /* After a successful buffer dump, must reset buffer pointers */
00213 entropy->next_output_byte = dest->next_output_byte;
00214 entropy->free_in_buffer = dest->free_in_buffer;
00215 }
|
|
||||||||||||||||
|
Definition at line 228 of file jcphuff.c. References c, emit_byte, ERREXIT, and INT32. Referenced by emit_buffered_bits(), emit_eobrun(), emit_symbol(), encode_mcu_AC_first(), encode_mcu_AC_refine(), encode_mcu_DC_first(), encode_mcu_DC_refine(), encode_one_block(), and flush_bits().
00230 {
00231 /* This routine is heavily used, so it's worth coding tightly. */
00232 register INT32 put_buffer = (INT32) code;
00233 register int put_bits = entropy->put_bits;
00234
00235 /* if size is 0, caller used an invalid Huffman table entry */
00236 if (size == 0)
00237 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
00238
00239 if (entropy->gather_statistics)
00240 return; /* do nothing if we're only getting stats */
00241
00242 put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
00243
00244 put_bits += size; /* new number of bits in buffer */
00245
00246 put_buffer <<= 24 - put_bits; /* align incoming bits */
00247
00248 put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
00249
00250 while (put_bits >= 8) {
00251 int c = (int) ((put_buffer >> 16) & 0xFF);
00252
00253 emit_byte(entropy, c);
00254 if (c == 0xFF) { /* need to stuff a zero byte? */
00255 emit_byte(entropy, 0);
00256 }
00257 put_buffer <<= 8;
00258 put_bits -= 8;
00259 }
00260
00261 entropy->put_buffer = put_buffer; /* update variables */
00262 entropy->put_bits = put_bits;
00263 }
|
|
||||||||||||||||
|
Definition at line 297 of file jcphuff.c. References emit_bits(). Referenced by emit_eobrun(), and encode_mcu_AC_refine().
00299 {
00300 if (entropy->gather_statistics)
00301 return; /* no real work */
00302
00303 while (nbits > 0) {
00304 emit_bits(entropy, (unsigned int) (*bufstart), 1);
00305 bufstart++;
00306 nbits--;
00307 }
00308 }
|
|
|
Definition at line 316 of file jcphuff.c. References emit_bits(), emit_buffered_bits(), emit_symbol(), and ERREXIT. Referenced by emit_restart(), encode_mcu_AC_first(), encode_mcu_AC_refine(), finish_pass_gather_phuff(), and finish_pass_phuff().
00317 {
00318 register int temp, nbits;
00319
00320 if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
00321 temp = entropy->EOBRUN;
00322 nbits = 0;
00323 while ((temp >>= 1))
00324 nbits++;
00325 /* safety check: shouldn't happen given limited correction-bit buffer */
00326 if (nbits > 14)
00327 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
00328
00329 emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
00330 if (nbits)
00331 emit_bits(entropy, entropy->EOBRUN, nbits);
00332
00333 entropy->EOBRUN = 0;
00334
00335 /* Emit any buffered correction bits */
00336 emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
00337 entropy->BE = 0;
00338 }
00339 }
|
|
||||||||||||
|
Definition at line 347 of file jcphuff.c. References emit_byte, emit_eobrun(), flush_bits(), and JPEG_RST0. Referenced by encode_mcu_AC_first(), encode_mcu_AC_refine(), encode_mcu_DC_first(), encode_mcu_DC_refine(), and encode_mcu_huff().
00348 {
00349 int ci;
00350
00351 emit_eobrun(entropy);
00352
00353 if (! entropy->gather_statistics) {
00354 flush_bits(entropy);
00355 emit_byte(entropy, 0xFF);
00356 emit_byte(entropy, JPEG_RST0 + restart_num);
00357 }
00358
00359 if (entropy->cinfo->Ss == 0) {
00360 /* Re-initialize DC predictions to 0 */
00361 for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
00362 entropy->last_dc_val[ci] = 0;
00363 } else {
00364 /* Re-initialize all AC-related fields to 0 */
00365 entropy->EOBRUN = 0;
00366 entropy->BE = 0;
00367 }
00368 }
|
|
||||||||||||||||
|
Definition at line 281 of file jcphuff.c. References phuff_entropy_decoder::derived_tbls, c_derived_tbl::ehufco, c_derived_tbl::ehufsi, and emit_bits(). Referenced by emit_eobrun(), encode_mcu_AC_first(), encode_mcu_AC_refine(), and encode_mcu_DC_first().
00282 {
00283 if (entropy->gather_statistics)
00284 entropy->count_ptrs[tbl_no][symbol]++;
00285 else {
00286 c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
00287 emit_bits(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
00288 }
00289 }
|
|
||||||||||||
|
Definition at line 464 of file jcphuff.c. References jpeg_compress_struct::Al, jpeg_compress_struct::dest, emit_bits(), emit_eobrun(), emit_restart(), emit_symbol(), jpeg_compress_struct::entropy, ERREXIT, jpeg_destination_mgr::free_in_buffer, JBLOCKROW, MAX_COEF_BITS, MCU_data, jpeg_destination_mgr::next_output_byte, r, jpeg_compress_struct::restart_interval, phuff_entropy_decoder::restarts_to_go, jpeg_compress_struct::Se, and jpeg_compress_struct::Ss. Referenced by start_pass_phuff().
00465 {
00466 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
00467 register int temp, temp2;
00468 register int nbits;
00469 register int r, k;
00470 int Se = cinfo->Se;
00471 int Al = cinfo->Al;
00472 JBLOCKROW block;
00473
00474 entropy->next_output_byte = cinfo->dest->next_output_byte;
00475 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
00476
00477 /* Emit restart marker if needed */
00478 if (cinfo->restart_interval)
00479 if (entropy->restarts_to_go == 0)
00480 emit_restart(entropy, entropy->next_restart_num);
00481
00482 /* Encode the MCU data block */
00483 block = MCU_data[0];
00484
00485 /* Encode the AC coefficients per section G.1.2.2, fig. G.3 */
00486
00487 r = 0; /* r = run length of zeros */
00488
00489 for (k = cinfo->Ss; k <= Se; k++) {
00490 if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
00491 r++;
00492 continue;
00493 }
00494 /* We must apply the point transform by Al. For AC coefficients this
00495 * is an integer division with rounding towards 0. To do this portably
00496 * in C, we shift after obtaining the absolute value; so the code is
00497 * interwoven with finding the abs value (temp) and output bits (temp2).
00498 */
00499 if (temp < 0) {
00500 temp = -temp; /* temp is abs value of input */
00501 temp >>= Al; /* apply the point transform */
00502 /* For a negative coef, want temp2 = bitwise complement of abs(coef) */
00503 temp2 = ~temp;
00504 } else {
00505 temp >>= Al; /* apply the point transform */
00506 temp2 = temp;
00507 }
00508 /* Watch out for case that nonzero coef is zero after point transform */
00509 if (temp == 0) {
00510 r++;
00511 continue;
00512 }
00513
00514 /* Emit any pending EOBRUN */
00515 if (entropy->EOBRUN > 0)
00516 emit_eobrun(entropy);
00517 /* if run length > 15, must emit special run-length-16 codes (0xF0) */
00518 while (r > 15) {
00519 emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
00520 r -= 16;
00521 }
00522
00523 /* Find the number of bits needed for the magnitude of the coefficient */
00524 nbits = 1; /* there must be at least one 1 bit */
00525 while ((temp >>= 1))
00526 nbits++;
00527 /* Check for out-of-range coefficient values */
00528 if (nbits > MAX_COEF_BITS)
00529 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
00530
00531 /* Count/emit Huffman symbol for run length / number of bits */
00532 emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
00533
00534 /* Emit that number of bits of the value, if positive, */
00535 /* or the complement of its magnitude, if negative. */
00536 emit_bits(entropy, (unsigned int) temp2, nbits);
00537
00538 r = 0; /* reset zero run length */
00539 }
00540
00541 if (r > 0) { /* If there are trailing zeroes, */
00542 entropy->EOBRUN++; /* count an EOB */
00543 if (entropy->EOBRUN == 0x7FFF)
00544 emit_eobrun(entropy); /* force it out to avoid overflow */
00545 }
00546
00547 cinfo->dest->next_output_byte = entropy->next_output_byte;
00548 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
00549
00550 /* Update restart-interval state too */
00551 if (cinfo->restart_interval) {
00552 if (entropy->restarts_to_go == 0) {
00553 entropy->restarts_to_go = cinfo->restart_interval;
00554 entropy->next_restart_num++;
00555 entropy->next_restart_num &= 7;
00556 }
00557 entropy->restarts_to_go--;
00558 }
00559
00560 return TRUE;
00561 }
|
|
||||||||||||
|
Definition at line 618 of file jcphuff.c. References jpeg_compress_struct::Al, jpeg_compress_struct::dest, emit_bits(), emit_buffered_bits(), emit_eobrun(), emit_restart(), emit_symbol(), jpeg_compress_struct::entropy, jpeg_destination_mgr::free_in_buffer, JBLOCKROW, MAX_CORR_BITS, MCU_data, jpeg_destination_mgr::next_output_byte, r, jpeg_compress_struct::restart_interval, phuff_entropy_decoder::restarts_to_go, jpeg_compress_struct::Se, and jpeg_compress_struct::Ss. Referenced by start_pass_phuff().
00619 {
00620 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
00621 register int temp;
00622 register int r, k;
00623 int EOB;
00624 char *BR_buffer;
00625 unsigned int BR;
00626 int Se = cinfo->Se;
00627 int Al = cinfo->Al;
00628 JBLOCKROW block;
00629 int absvalues[DCTSIZE2];
00630
00631 entropy->next_output_byte = cinfo->dest->next_output_byte;
00632 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
00633
00634 /* Emit restart marker if needed */
00635 if (cinfo->restart_interval)
00636 if (entropy->restarts_to_go == 0)
00637 emit_restart(entropy, entropy->next_restart_num);
00638
00639 /* Encode the MCU data block */
00640 block = MCU_data[0];
00641
00642 /* It is convenient to make a pre-pass to determine the transformed
00643 * coefficients' absolute values and the EOB position.
00644 */
00645 EOB = 0;
00646 for (k = cinfo->Ss; k <= Se; k++) {
00647 temp = (*block)[jpeg_natural_order[k]];
00648 /* We must apply the point transform by Al. For AC coefficients this
00649 * is an integer division with rounding towards 0. To do this portably
00650 * in C, we shift after obtaining the absolute value.
00651 */
00652 if (temp < 0)
00653 temp = -temp; /* temp is abs value of input */
00654 temp >>= Al; /* apply the point transform */
00655 absvalues[k] = temp; /* save abs value for main pass */
00656 if (temp == 1)
00657 EOB = k; /* EOB = index of last newly-nonzero coef */
00658 }
00659
00660 /* Encode the AC coefficients per section G.1.2.3, fig. G.7 */
00661
00662 r = 0; /* r = run length of zeros */
00663 BR = 0; /* BR = count of buffered bits added now */
00664 BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
00665
00666 for (k = cinfo->Ss; k <= Se; k++) {
00667 if ((temp = absvalues[k]) == 0) {
00668 r++;
00669 continue;
00670 }
00671
00672 /* Emit any required ZRLs, but not if they can be folded into EOB */
00673 while (r > 15 && k <= EOB) {
00674 /* emit any pending EOBRUN and the BE correction bits */
00675 emit_eobrun(entropy);
00676 /* Emit ZRL */
00677 emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
00678 r -= 16;
00679 /* Emit buffered correction bits that must be associated with ZRL */
00680 emit_buffered_bits(entropy, BR_buffer, BR);
00681 BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
00682 BR = 0;
00683 }
00684
00685 /* If the coef was previously nonzero, it only needs a correction bit.
00686 * NOTE: a straight translation of the spec's figure G.7 would suggest
00687 * that we also need to test r > 15. But if r > 15, we can only get here
00688 * if k > EOB, which implies that this coefficient is not 1.
00689 */
00690 if (temp > 1) {
00691 /* The correction bit is the next bit of the absolute value. */
00692 BR_buffer[BR++] = (char) (temp & 1);
00693 continue;
00694 }
00695
00696 /* Emit any pending EOBRUN and the BE correction bits */
00697 emit_eobrun(entropy);
00698
00699 /* Count/emit Huffman symbol for run length / number of bits */
00700 emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
00701
00702 /* Emit output bit for newly-nonzero coef */
00703 temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
00704 emit_bits(entropy, (unsigned int) temp, 1);
00705
00706 /* Emit buffered correction bits that must be associated with this code */
00707 emit_buffered_bits(entropy, BR_buffer, BR);
00708 BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
00709 BR = 0;
00710 r = 0; /* reset zero run length */
00711 }
00712
00713 if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
00714 entropy->EOBRUN++; /* count an EOB */
00715 entropy->BE += BR; /* concat my correction bits to older ones */
00716 /* We force out the EOB if we risk either:
00717 * 1. overflow of the EOB counter;
00718 * 2. overflow of the correction bit buffer during the next MCU.
00719 */
00720 if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
00721 emit_eobrun(entropy);
00722 }
00723
00724 cinfo->dest->next_output_byte = entropy->next_output_byte;
00725 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
00726
00727 /* Update restart-interval state too */
00728 if (cinfo->restart_interval) {
00729 if (entropy->restarts_to_go == 0) {
00730 entropy->restarts_to_go = cinfo->restart_interval;
00731 entropy->next_restart_num++;
00732 entropy->next_restart_num &= 7;
00733 }
00734 entropy->restarts_to_go--;
00735 }
00736
00737 return TRUE;
00738 }
|
|
||||||||||||
|
Definition at line 377 of file jcphuff.c. References jpeg_compress_struct::Al, jpeg_compress_struct::blocks_in_MCU, compptr, jpeg_compress_struct::cur_comp_info, jpeg_component_info::dc_tbl_no, jpeg_compress_struct::dest, emit_bits(), emit_restart(), emit_symbol(), jpeg_compress_struct::entropy, ERREXIT, jpeg_destination_mgr::free_in_buffer, IRIGHT_SHIFT, ISHIFT_TEMPS, JBLOCKROW, MAX_COEF_BITS, MCU_data, jpeg_compress_struct::MCU_membership, jpeg_destination_mgr::next_output_byte, jpeg_compress_struct::restart_interval, and phuff_entropy_decoder::restarts_to_go. Referenced by start_pass_phuff().
00378 {
00379 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
00380 register int temp, temp2;
00381 register int nbits;
00382 int blkn, ci;
00383 int Al = cinfo->Al;
00384 JBLOCKROW block;
00385 jpeg_component_info * compptr;
00386 ISHIFT_TEMPS
00387
00388 entropy->next_output_byte = cinfo->dest->next_output_byte;
00389 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
00390
00391 /* Emit restart marker if needed */
00392 if (cinfo->restart_interval)
00393 if (entropy->restarts_to_go == 0)
00394 emit_restart(entropy, entropy->next_restart_num);
00395
00396 /* Encode the MCU data blocks */
00397 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
00398 block = MCU_data[blkn];
00399 ci = cinfo->MCU_membership[blkn];
00400 compptr = cinfo->cur_comp_info[ci];
00401
00402 /* Compute the DC value after the required point transform by Al.
00403 * This is simply an arithmetic right shift.
00404 */
00405 temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
00406
00407 /* DC differences are figured on the point-transformed values. */
00408 temp = temp2 - entropy->last_dc_val[ci];
00409 entropy->last_dc_val[ci] = temp2;
00410
00411 /* Encode the DC coefficient difference per section G.1.2.1 */
00412 temp2 = temp;
00413 if (temp < 0) {
00414 temp = -temp; /* temp is abs value of input */
00415 /* For a negative input, want temp2 = bitwise complement of abs(input) */
00416 /* This code assumes we are on a two's complement machine */
00417 temp2--;
00418 }
00419
00420 /* Find the number of bits needed for the magnitude of the coefficient */
00421 nbits = 0;
00422 while (temp) {
00423 nbits++;
00424 temp >>= 1;
00425 }
00426 /* Check for out-of-range coefficient values.
00427 * Since we're encoding a difference, the range limit is twice as much.
00428 */
00429 if (nbits > MAX_COEF_BITS+1)
00430 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
00431
00432 /* Count/emit the Huffman-coded symbol for the number of bits */
00433 emit_symbol(entropy, compptr->dc_tbl_no, nbits);
00434
00435 /* Emit that number of bits of the value, if positive, */
00436 /* or the complement of its magnitude, if negative. */
00437 if (nbits) /* emit_bits rejects calls with size 0 */
00438 emit_bits(entropy, (unsigned int) temp2, nbits);
00439 }
00440
00441 cinfo->dest->next_output_byte = entropy->next_output_byte;
00442 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
00443
00444 /* Update restart-interval state too */
00445 if (cinfo->restart_interval) {
00446 if (entropy->restarts_to_go == 0) {
00447 entropy->restarts_to_go = cinfo->restart_interval;
00448 entropy->next_restart_num++;
00449 entropy->next_restart_num &= 7;
00450 }
00451 entropy->restarts_to_go--;
00452 }
00453
00454 return TRUE;
00455 }
|
|
||||||||||||
|
Definition at line 571 of file jcphuff.c. References jpeg_compress_struct::Al, jpeg_compress_struct::blocks_in_MCU, jpeg_compress_struct::dest, emit_bits(), emit_restart(), jpeg_compress_struct::entropy, jpeg_destination_mgr::free_in_buffer, JBLOCKROW, MCU_data, jpeg_destination_mgr::next_output_byte, jpeg_compress_struct::restart_interval, and phuff_entropy_decoder::restarts_to_go. Referenced by start_pass_phuff().
00572 {
00573 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
00574 register int temp;
00575 int blkn;
00576 int Al = cinfo->Al;
00577 JBLOCKROW block;
00578
00579 entropy->next_output_byte = cinfo->dest->next_output_byte;
00580 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
00581
00582 /* Emit restart marker if needed */
00583 if (cinfo->restart_interval)
00584 if (entropy->restarts_to_go == 0)
00585 emit_restart(entropy, entropy->next_restart_num);
00586
00587 /* Encode the MCU data blocks */
00588 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
00589 block = MCU_data[blkn];
00590
00591 /* We simply emit the Al'th bit of the DC coefficient value. */
00592 temp = (*block)[0];
00593 emit_bits(entropy, (unsigned int) (temp >> Al), 1);
00594 }
00595
00596 cinfo->dest->next_output_byte = entropy->next_output_byte;
00597 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
00598
00599 /* Update restart-interval state too */
00600 if (cinfo->restart_interval) {
00601 if (entropy->restarts_to_go == 0) {
00602 entropy->restarts_to_go = cinfo->restart_interval;
00603 entropy->next_restart_num++;
00604 entropy->next_restart_num &= 7;
00605 }
00606 entropy->restarts_to_go--;
00607 }
00608
00609 return TRUE;
00610 }
|
|
|
Definition at line 767 of file jcphuff.c. References jpeg_compress_struct::ac_huff_tbl_ptrs, jpeg_component_info::ac_tbl_no, jpeg_compress_struct::Ah, compptr, jpeg_compress_struct::comps_in_scan, jpeg_compress_struct::cur_comp_info, jpeg_compress_struct::dc_huff_tbl_ptrs, jpeg_component_info::dc_tbl_no, emit_eobrun(), jpeg_compress_struct::entropy, jpeg_alloc_huff_table(), jpeg_gen_optimal_table(), MEMZERO, NUM_HUFF_TBLS, SIZEOF, and jpeg_compress_struct::Ss. Referenced by start_pass_phuff().
00768 {
00769 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
00770 boolean is_DC_band;
00771 int ci, tbl;
00772 jpeg_component_info * compptr;
00773 JHUFF_TBL **htblptr;
00774 boolean did[NUM_HUFF_TBLS];
00775
00776 /* Flush out buffered data (all we care about is counting the EOB symbol) */
00777 emit_eobrun(entropy);
00778
00779 is_DC_band = (cinfo->Ss == 0);
00780
00781 /* It's important not to apply jpeg_gen_optimal_table more than once
00782 * per table, because it clobbers the input frequency counts!
00783 */
00784 MEMZERO(did, SIZEOF(did));
00785
00786 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
00787 compptr = cinfo->cur_comp_info[ci];
00788 if (is_DC_band) {
00789 if (cinfo->Ah != 0) /* DC refinement needs no table */
00790 continue;
00791 tbl = compptr->dc_tbl_no;
00792 } else {
00793 tbl = compptr->ac_tbl_no;
00794 }
00795 if (! did[tbl]) {
00796 if (is_DC_band)
00797 htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
00798 else
00799 htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
00800 if (*htblptr == NULL)
00801 *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
00802 jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
00803 did[tbl] = TRUE;
00804 }
00805 }
00806 }
|
|
|
Definition at line 746 of file jcphuff.c. References jpeg_compress_struct::dest, emit_eobrun(), jpeg_compress_struct::entropy, flush_bits(), jpeg_destination_mgr::free_in_buffer, and jpeg_destination_mgr::next_output_byte. Referenced by start_pass_phuff().
00747 {
00748 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
00749
00750 entropy->next_output_byte = cinfo->dest->next_output_byte;
00751 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
00752
00753 /* Flush out any buffered data */
00754 emit_eobrun(entropy);
00755 flush_bits(entropy);
00756
00757 cinfo->dest->next_output_byte = entropy->next_output_byte;
00758 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
00759 }
|
|
|
Definition at line 267 of file jcphuff.c. References emit_bits(). Referenced by emit_restart(), finish_pass_huff(), and finish_pass_phuff().
00268 {
00269 emit_bits(entropy, 0x7F, 7); /* fill any partial byte with ones */
00270 entropy->put_buffer = 0; /* and reset bit-buffer to empty */
00271 entropy->put_bits = 0;
00272 }
|
|
|
Definition at line 814 of file jcphuff.c. References i, JPOOL_IMAGE, NUM_HUFF_TBLS, SIZEOF, and start_pass_phuff(). Referenced by jinit_compress_master(), and transencode_master_selection().
00815 {
00816 phuff_entropy_ptr entropy;
00817 int i;
00818
00819 entropy = (phuff_entropy_ptr)
00820 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00821 SIZEOF(phuff_entropy_encoder));
00822 cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
00823 entropy->pub.start_pass = start_pass_phuff;
00824
00825 /* Mark tables unallocated */
00826 for (i = 0; i < NUM_HUFF_TBLS; i++) {
00827 entropy->derived_tbls[i] = NULL;
00828 entropy->count_ptrs[i] = NULL;
00829 }
00830 entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
00831 }
|
|
|
|
|
|
|
|
||||||||||||
|
Definition at line 106 of file jcphuff.c. References jpeg_component_info::ac_tbl_no, jpeg_compress_struct::Ah, compptr, jpeg_compress_struct::comps_in_scan, jpeg_compress_struct::cur_comp_info, jpeg_component_info::dc_tbl_no, phuff_entropy_decoder::derived_tbls, encode_mcu_AC_first(), encode_mcu_AC_refine(), encode_mcu_DC_first(), encode_mcu_DC_refine(), jpeg_compress_struct::entropy, ERREXIT1, finish_pass_gather_phuff(), finish_pass_phuff(), jpeg_make_c_derived_tbl(), JPOOL_IMAGE, MAX_CORR_BITS, MEMZERO, NUM_HUFF_TBLS, phuff_entropy_decoder::pub, jpeg_compress_struct::restart_interval, phuff_entropy_decoder::restarts_to_go, SIZEOF, and jpeg_compress_struct::Ss. Referenced by jinit_phuff_encoder().
00107 {
00108 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
00109 boolean is_DC_band;
00110 int ci, tbl;
00111 jpeg_component_info * compptr;
00112
00113 entropy->cinfo = cinfo;
00114 entropy->gather_statistics = gather_statistics;
00115
00116 is_DC_band = (cinfo->Ss == 0);
00117
00118 /* We assume jcmaster.c already validated the scan parameters. */
00119
00120 /* Select execution routines */
00121 if (cinfo->Ah == 0) {
00122 if (is_DC_band)
00123 entropy->pub.encode_mcu = encode_mcu_DC_first;
00124 else
00125 entropy->pub.encode_mcu = encode_mcu_AC_first;
00126 } else {
00127 if (is_DC_band)
00128 entropy->pub.encode_mcu = encode_mcu_DC_refine;
00129 else {
00130 entropy->pub.encode_mcu = encode_mcu_AC_refine;
00131 /* AC refinement needs a correction bit buffer */
00132 if (entropy->bit_buffer == NULL)
00133 entropy->bit_buffer = (char *)
00134 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00135 MAX_CORR_BITS * SIZEOF(char));
00136 }
00137 }
00138 if (gather_statistics)
00139 entropy->pub.finish_pass = finish_pass_gather_phuff;
00140 else
00141 entropy->pub.finish_pass = finish_pass_phuff;
00142
00143 /* Only DC coefficients may be interleaved, so cinfo->comps_in_scan = 1
00144 * for AC coefficients.
00145 */
00146 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
00147 compptr = cinfo->cur_comp_info[ci];
00148 /* Initialize DC predictions to 0 */
00149 entropy->last_dc_val[ci] = 0;
00150 /* Get table index */
00151 if (is_DC_band) {
00152 if (cinfo->Ah != 0) /* DC refinement needs no table */
00153 continue;
00154 tbl = compptr->dc_tbl_no;
00155 } else {
00156 entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
00157 }
00158 if (gather_statistics) {
00159 /* Check for invalid table index */
00160 /* (make_c_derived_tbl does this in the other path) */
00161 if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
00162 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
00163 /* Allocate and zero the statistics tables */
00164 /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
00165 if (entropy->count_ptrs[tbl] == NULL)
00166 entropy->count_ptrs[tbl] = (long *)
00167 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00168 257 * SIZEOF(long));
00169 MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
00170 } else {
00171 /* Compute derived values for Huffman table */
00172 /* We may do this more than once for a table, but it's not expensive */
00173 jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
00174 & entropy->derived_tbls[tbl]);
00175 }
00176 }
00177
00178 /* Initialize AC stuff */
00179 entropy->EOBRUN = 0;
00180 entropy->BE = 0;
00181
00182 /* Initialize bit buffer to empty */
00183 entropy->put_buffer = 0;
00184 entropy->put_bits = 0;
00185
00186 /* Initialize restart stuff */
00187 entropy->restarts_to_go = cinfo->restart_interval;
00188 entropy->next_restart_num = 0;
00189 }
|
Variable Documentation
|
|
Definition at line 96 of file jcphuff.c. Referenced by encode_mcu_AC_first(), encode_mcu_AC_refine(), encode_mcu_DC_first(), and encode_mcu_DC_refine(). |