Lines Matching full:entropy
14 * This file contains Huffman entropy encoding routines for progressive JPEG.
77 /* Expanded entropy encoder object for progressive Huffman encoding. */
208 phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy; in start_pass_phuff() local
213 entropy->cinfo = cinfo; in start_pass_phuff()
214 entropy->gather_statistics = gather_statistics; in start_pass_phuff()
223 entropy->pub.encode_mcu = encode_mcu_DC_first; in start_pass_phuff()
225 entropy->pub.encode_mcu = encode_mcu_AC_first; in start_pass_phuff()
227 entropy->AC_first_prepare = jsimd_encode_mcu_AC_first_prepare; in start_pass_phuff()
229 entropy->AC_first_prepare = encode_mcu_AC_first_prepare; in start_pass_phuff()
232 entropy->pub.encode_mcu = encode_mcu_DC_refine; in start_pass_phuff()
234 entropy->pub.encode_mcu = encode_mcu_AC_refine; in start_pass_phuff()
236 entropy->AC_refine_prepare = jsimd_encode_mcu_AC_refine_prepare; in start_pass_phuff()
238 entropy->AC_refine_prepare = encode_mcu_AC_refine_prepare; in start_pass_phuff()
240 if (entropy->bit_buffer == NULL) in start_pass_phuff()
241 entropy->bit_buffer = (char *) in start_pass_phuff()
247 entropy->pub.finish_pass = finish_pass_gather_phuff; in start_pass_phuff()
249 entropy->pub.finish_pass = finish_pass_phuff; in start_pass_phuff()
257 entropy->last_dc_val[ci] = 0; in start_pass_phuff()
264 entropy->ac_tbl_no = tbl = compptr->ac_tbl_no; in start_pass_phuff()
273 if (entropy->count_ptrs[tbl] == NULL) in start_pass_phuff()
274 entropy->count_ptrs[tbl] = (long *) in start_pass_phuff()
277 memset(entropy->count_ptrs[tbl], 0, 257 * sizeof(long)); in start_pass_phuff()
282 &entropy->derived_tbls[tbl]); in start_pass_phuff()
287 entropy->EOBRUN = 0; in start_pass_phuff()
288 entropy->BE = 0; in start_pass_phuff()
291 entropy->put_buffer = 0; in start_pass_phuff()
292 entropy->put_bits = 0; in start_pass_phuff()
295 entropy->restarts_to_go = cinfo->restart_interval; in start_pass_phuff()
296 entropy->next_restart_num = 0; in start_pass_phuff()
302 * that is, entropy->gather_statistics == FALSE.
306 #define emit_byte(entropy, val) { \ argument
307 *(entropy)->next_output_byte++ = (JOCTET)(val); \
308 if (--(entropy)->free_in_buffer == 0) \
309 dump_buffer(entropy); \
314 dump_buffer(phuff_entropy_ptr entropy) in dump_buffer() argument
317 struct jpeg_destination_mgr *dest = entropy->cinfo->dest; in dump_buffer()
319 if (!(*dest->empty_output_buffer) (entropy->cinfo)) in dump_buffer()
320 ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND); in dump_buffer()
322 entropy->next_output_byte = dest->next_output_byte; in dump_buffer()
323 entropy->free_in_buffer = dest->free_in_buffer; in dump_buffer()
336 emit_bits(phuff_entropy_ptr entropy, unsigned int code, int size) in emit_bits() argument
341 register int put_bits = entropy->put_bits; in emit_bits()
345 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE); in emit_bits()
347 if (entropy->gather_statistics) in emit_bits()
356 put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */ in emit_bits()
361 emit_byte(entropy, c); in emit_bits()
363 emit_byte(entropy, 0); in emit_bits()
369 entropy->put_buffer = put_buffer; /* update variables */ in emit_bits()
370 entropy->put_bits = put_bits; in emit_bits()
375 flush_bits(phuff_entropy_ptr entropy) in flush_bits() argument
377 emit_bits(entropy, 0x7F, 7); /* fill any partial byte with ones */ in flush_bits()
378 entropy->put_buffer = 0; /* and reset bit-buffer to empty */ in flush_bits()
379 entropy->put_bits = 0; in flush_bits()
388 emit_symbol(phuff_entropy_ptr entropy, int tbl_no, int symbol) in emit_symbol() argument
390 if (entropy->gather_statistics) in emit_symbol()
391 entropy->count_ptrs[tbl_no][symbol]++; in emit_symbol()
393 c_derived_tbl *tbl = entropy->derived_tbls[tbl_no]; in emit_symbol()
394 emit_bits(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]); in emit_symbol()
404 emit_buffered_bits(phuff_entropy_ptr entropy, char *bufstart, in emit_buffered_bits() argument
407 if (entropy->gather_statistics) in emit_buffered_bits()
411 emit_bits(entropy, (unsigned int)(*bufstart), 1); in emit_buffered_bits()
423 emit_eobrun(phuff_entropy_ptr entropy) in emit_eobrun() argument
427 if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */ in emit_eobrun()
428 temp = entropy->EOBRUN; in emit_eobrun()
432 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE); in emit_eobrun()
434 emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4); in emit_eobrun()
436 emit_bits(entropy, entropy->EOBRUN, nbits); in emit_eobrun()
438 entropy->EOBRUN = 0; in emit_eobrun()
441 emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE); in emit_eobrun()
442 entropy->BE = 0; in emit_eobrun()
452 emit_restart(phuff_entropy_ptr entropy, int restart_num) in emit_restart() argument
456 emit_eobrun(entropy); in emit_restart()
458 if (!entropy->gather_statistics) { in emit_restart()
459 flush_bits(entropy); in emit_restart()
460 emit_byte(entropy, 0xFF); in emit_restart()
461 emit_byte(entropy, JPEG_RST0 + restart_num); in emit_restart()
464 if (entropy->cinfo->Ss == 0) { in emit_restart()
466 for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++) in emit_restart()
467 entropy->last_dc_val[ci] = 0; in emit_restart()
470 entropy->EOBRUN = 0; in emit_restart()
471 entropy->BE = 0; in emit_restart()
484 phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy; in encode_mcu_DC_first() local
493 entropy->next_output_byte = cinfo->dest->next_output_byte; in encode_mcu_DC_first()
494 entropy->free_in_buffer = cinfo->dest->free_in_buffer; in encode_mcu_DC_first()
498 if (entropy->restarts_to_go == 0) in encode_mcu_DC_first()
499 emit_restart(entropy, entropy->next_restart_num); in encode_mcu_DC_first()
513 temp = temp2 - entropy->last_dc_val[ci]; in encode_mcu_DC_first()
514 entropy->last_dc_val[ci] = temp2; in encode_mcu_DC_first()
538 emit_symbol(entropy, compptr->dc_tbl_no, nbits); in encode_mcu_DC_first()
543 emit_bits(entropy, (unsigned int)temp2, nbits); in encode_mcu_DC_first()
546 cinfo->dest->next_output_byte = entropy->next_output_byte; in encode_mcu_DC_first()
547 cinfo->dest->free_in_buffer = entropy->free_in_buffer; in encode_mcu_DC_first()
551 if (entropy->restarts_to_go == 0) { in encode_mcu_DC_first()
552 entropy->restarts_to_go = cinfo->restart_interval; in encode_mcu_DC_first()
553 entropy->next_restart_num++; in encode_mcu_DC_first()
554 entropy->next_restart_num &= 7; in encode_mcu_DC_first()
556 entropy->restarts_to_go--; in encode_mcu_DC_first()
638 emit_symbol(entropy, entropy->ac_tbl_no, 0xF0); \
649 emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits); \
653 emit_bits(entropy, (unsigned int)temp2, nbits); \
663 phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy; in encode_mcu_AC_first() local
674 entropy->next_output_byte = cinfo->dest->next_output_byte; in encode_mcu_AC_first()
675 entropy->free_in_buffer = cinfo->dest->free_in_buffer; in encode_mcu_AC_first()
679 if (entropy->restarts_to_go == 0) in encode_mcu_AC_first()
680 emit_restart(entropy, entropy->next_restart_num); in encode_mcu_AC_first()
690 entropy->AC_first_prepare(MCU_data[0][0], jpeg_natural_order + cinfo->Ss, in encode_mcu_AC_first()
699 if (zerobits && (entropy->EOBRUN > 0)) in encode_mcu_AC_first()
700 emit_eobrun(entropy); in encode_mcu_AC_first()
724 entropy->EOBRUN++; /* count an EOB */ in encode_mcu_AC_first()
725 if (entropy->EOBRUN == 0x7FFF) in encode_mcu_AC_first()
726 emit_eobrun(entropy); /* force it out to avoid overflow */ in encode_mcu_AC_first()
729 cinfo->dest->next_output_byte = entropy->next_output_byte; in encode_mcu_AC_first()
730 cinfo->dest->free_in_buffer = entropy->free_in_buffer; in encode_mcu_AC_first()
734 if (entropy->restarts_to_go == 0) { in encode_mcu_AC_first()
735 entropy->restarts_to_go = cinfo->restart_interval; in encode_mcu_AC_first()
736 entropy->next_restart_num++; in encode_mcu_AC_first()
737 entropy->next_restart_num &= 7; in encode_mcu_AC_first()
739 entropy->restarts_to_go--; in encode_mcu_AC_first()
755 phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy; in encode_mcu_DC_refine() local
761 entropy->next_output_byte = cinfo->dest->next_output_byte; in encode_mcu_DC_refine()
762 entropy->free_in_buffer = cinfo->dest->free_in_buffer; in encode_mcu_DC_refine()
766 if (entropy->restarts_to_go == 0) in encode_mcu_DC_refine()
767 emit_restart(entropy, entropy->next_restart_num); in encode_mcu_DC_refine()
775 emit_bits(entropy, (unsigned int)(temp >> Al), 1); in encode_mcu_DC_refine()
778 cinfo->dest->next_output_byte = entropy->next_output_byte; in encode_mcu_DC_refine()
779 cinfo->dest->free_in_buffer = entropy->free_in_buffer; in encode_mcu_DC_refine()
783 if (entropy->restarts_to_go == 0) { in encode_mcu_DC_refine()
784 entropy->restarts_to_go = cinfo->restart_interval; in encode_mcu_DC_refine()
785 entropy->next_restart_num++; in encode_mcu_DC_refine()
786 entropy->next_restart_num &= 7; in encode_mcu_DC_refine()
788 entropy->restarts_to_go--; in encode_mcu_DC_refine()
879 emit_eobrun(entropy); \
881 emit_symbol(entropy, entropy->ac_tbl_no, 0xF0); \
884 emit_buffered_bits(entropy, BR_buffer, BR); \
885 BR_buffer = entropy->bit_buffer; /* BE bits are gone now */ \
905 emit_eobrun(entropy); \
908 emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1); \
912 emit_bits(entropy, (unsigned int)temp, 1); \
915 emit_buffered_bits(entropy, BR_buffer, BR); \
916 BR_buffer = entropy->bit_buffer; /* BE bits are gone now */ \
927 phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy; in encode_mcu_AC_refine() local
939 entropy->next_output_byte = cinfo->dest->next_output_byte; in encode_mcu_AC_refine()
940 entropy->free_in_buffer = cinfo->dest->free_in_buffer; in encode_mcu_AC_refine()
944 if (entropy->restarts_to_go == 0) in encode_mcu_AC_refine()
945 emit_restart(entropy, entropy->next_restart_num); in encode_mcu_AC_refine()
956 entropy->AC_refine_prepare(MCU_data[0][0], jpeg_natural_order + cinfo->Ss, in encode_mcu_AC_refine()
963 BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */ in encode_mcu_AC_refine()
993 entropy->EOBRUN++; /* count an EOB */ in encode_mcu_AC_refine()
994 entropy->BE += BR; /* concat my correction bits to older ones */ in encode_mcu_AC_refine()
999 if (entropy->EOBRUN == 0x7FFF || in encode_mcu_AC_refine()
1000 entropy->BE > (MAX_CORR_BITS - DCTSIZE2 + 1)) in encode_mcu_AC_refine()
1001 emit_eobrun(entropy); in encode_mcu_AC_refine()
1004 cinfo->dest->next_output_byte = entropy->next_output_byte; in encode_mcu_AC_refine()
1005 cinfo->dest->free_in_buffer = entropy->free_in_buffer; in encode_mcu_AC_refine()
1009 if (entropy->restarts_to_go == 0) { in encode_mcu_AC_refine()
1010 entropy->restarts_to_go = cinfo->restart_interval; in encode_mcu_AC_refine()
1011 entropy->next_restart_num++; in encode_mcu_AC_refine()
1012 entropy->next_restart_num &= 7; in encode_mcu_AC_refine()
1014 entropy->restarts_to_go--; in encode_mcu_AC_refine()
1028 phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy; in finish_pass_phuff() local
1030 entropy->next_output_byte = cinfo->dest->next_output_byte; in finish_pass_phuff()
1031 entropy->free_in_buffer = cinfo->dest->free_in_buffer; in finish_pass_phuff()
1034 emit_eobrun(entropy); in finish_pass_phuff()
1035 flush_bits(entropy); in finish_pass_phuff()
1037 cinfo->dest->next_output_byte = entropy->next_output_byte; in finish_pass_phuff()
1038 cinfo->dest->free_in_buffer = entropy->free_in_buffer; in finish_pass_phuff()
1049 phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy; in finish_pass_gather_phuff() local
1057 emit_eobrun(entropy); in finish_pass_gather_phuff()
1082 jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]); in finish_pass_gather_phuff()
1090 * Module initialization routine for progressive Huffman entropy encoding.
1096 phuff_entropy_ptr entropy; in jinit_phuff_encoder() local
1099 entropy = (phuff_entropy_ptr) in jinit_phuff_encoder()
1102 cinfo->entropy = (struct jpeg_entropy_encoder *)entropy; in jinit_phuff_encoder()
1103 entropy->pub.start_pass = start_pass_phuff; in jinit_phuff_encoder()
1107 entropy->derived_tbls[i] = NULL; in jinit_phuff_encoder()
1108 entropy->count_ptrs[i] = NULL; in jinit_phuff_encoder()
1110 entropy->bit_buffer = NULL; /* needed only in AC refinement scan */ in jinit_phuff_encoder()