17 #define JPEG_INTERNALS 40 #ifndef NO_STRUCT_ASSIGN 41 #define ASSIGN_STATE(dest,src) ((dest) = (src)) 43 #if MAX_COMPS_IN_SCAN == 4 44 #define ASSIGN_STATE(dest,src) \ 45 ((dest).put_buffer = (src).put_buffer, \ 46 (dest).put_bits = (src).put_bits, \ 47 (dest).last_dc_val[0] = (src).last_dc_val[0], \ 48 (dest).last_dc_val[1] = (src).last_dc_val[1], \ 49 (dest).last_dc_val[2] = (src).last_dc_val[2], \ 50 (dest).last_dc_val[3] = (src).last_dc_val[3]) 68 #ifdef ENTROPY_OPT_SUPPORTED 92 #ifdef ENTROPY_OPT_SUPPORTED 109 int ci, dctbl, actbl;
112 if (gather_statistics) {
113 #ifdef ENTROPY_OPT_SUPPORTED 117 ERREXIT(cinfo, JERR_NOT_COMPILED);
128 if (gather_statistics) {
129 #ifdef ENTROPY_OPT_SUPPORTED 133 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
135 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
184 int p,
i, l, lastp, si, maxsymbol;
186 unsigned int huffcode[257];
195 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
197 isDC ? cinfo->dc_huff_tbl_ptrs[
tblno] : cinfo->ac_huff_tbl_ptrs[
tblno];
199 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
211 for (l = 1; l <= 16; l++) {
213 if (i < 0 || p + i > 256)
214 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
216 huffsize[p++] = (char) l;
227 while (huffsize[p]) {
228 while (((
int) huffsize[p]) == si) {
229 huffcode[p++] =
code;
236 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
255 maxsymbol = isDC ? 15 : 255;
257 for (p = 0; p < lastp; p++) {
259 if (i < 0 || i > maxsymbol || dtbl->
ehufsi[i])
260 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
270 #define emit_byte(state,val,action) \ 271 { *(state)->next_output_byte++ = (JOCTET) (val); \ 272 if (--(state)->free_in_buffer == 0) \ 273 if (! dump_buffer(state)) \ 283 if (! (*dest->empty_output_buffer) (state->cinfo))
307 register int put_bits = state->cur.put_bits;
311 ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
317 put_buffer <<= 24 - put_bits;
319 put_buffer |= state->cur.put_buffer;
321 while (put_bits >= 8) {
322 int c = (
int) ((put_buffer >> 16) & 0xFF);
332 state->cur.put_buffer = put_buffer;
333 state->cur.put_bits = put_bits;
344 state->cur.put_buffer = 0;
345 state->cur.put_bits = 0;
356 register int temp, temp2;
358 register int k, r,
i;
362 temp = temp2 = block[0] - last_dc_val;
381 ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
384 if (!
emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
390 if (!
emit_bits(state, (
unsigned int) temp2, nbits))
403 if (!
emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
421 ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
424 i = (r << 4) + nbits;
425 if (!
emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
430 if (!
emit_bits(state, (
unsigned int) temp2, nbits))
439 if (!
emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
462 for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
463 state->cur.last_dc_val[ci] = 0;
484 state.next_output_byte = cinfo->dest->next_output_byte;
485 state.free_in_buffer = cinfo->dest->free_in_buffer;
490 if (cinfo->restart_interval) {
497 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
498 ci = cinfo->MCU_membership[blkn];
499 compptr = cinfo->cur_comp_info[ci];
501 MCU_data[blkn][0],
state.cur.last_dc_val[ci],
506 state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
510 cinfo->dest->next_output_byte =
state.next_output_byte;
511 cinfo->dest->free_in_buffer =
state.free_in_buffer;
515 if (cinfo->restart_interval) {
539 state.next_output_byte = cinfo->dest->next_output_byte;
540 state.free_in_buffer = cinfo->dest->free_in_buffer;
546 ERREXIT(cinfo, JERR_CANT_SUSPEND);
549 cinfo->dest->next_output_byte =
state.next_output_byte;
550 cinfo->dest->free_in_buffer =
state.free_in_buffer;
566 #ifdef ENTROPY_OPT_SUPPORTED 573 long dc_counts[],
long ac_counts[])
581 temp = block[0] - last_dc_val;
595 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
624 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
627 ac_counts[(r << 4) + nbits]++;
652 if (cinfo->restart_interval) {
655 for (ci = 0; ci < cinfo->comps_in_scan; ci++)
663 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
664 ci = cinfo->MCU_membership[blkn];
665 compptr = cinfo->cur_comp_info[ci];
719 for (i = 0; i < 257; i++)
735 for (i = 0; i <= 256; i++) {
736 if (freq[i] && freq[i] <= v) {
746 for (i = 0; i <= 256; i++) {
747 if (freq[i] && freq[i] <= v && i != c1) {
758 freq[c1] += freq[c2];
763 while (others[c1] >= 0) {
772 while (others[c2] >= 0) {
779 for (i = 0; i <= 256; i++) {
784 ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
802 while (bits[i] > 0) {
828 for (j = 0; j <= 255; j++) {
829 if (codesize[j] == i) {
830 htbl->huffval[p] = (
UINT8) j;
837 htbl->sent_table =
FALSE;
849 int ci, dctbl, actbl;
861 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
862 compptr = cinfo->cur_comp_info[ci];
865 if (! did_dc[dctbl]) {
866 htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
867 if (*htblptr == NULL)
870 did_dc[dctbl] =
TRUE;
872 if (! did_ac[actbl]) {
873 htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
874 if (*htblptr == NULL)
877 did_ac[actbl] =
TRUE;
900 entropy->
pub.start_pass = start_pass_huff;
905 #ifdef ENTROPY_OPT_SUPPORTED
boolean int c_derived_tbl ** pdtbl
dump_buffer(working_state *state)
huff_entropy_encoder * huff_entropy_ptr
long * ac_count_ptrs[NUM_HUFF_TBLS]
const int jpeg_natural_order[]
struct jpeg_common_struct * j_common_ptr
JOCTET * next_output_byte
#define ASSIGN_STATE(dest, src)
#define ERREXIT(cinfo, code)
jpeg_alloc_huff_table(j_common_ptr cinfo)
struct jpeg_entropy_encoder * entropy
jpeg_component_info * compptr
c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS]
encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val, c_derived_tbl *dctbl, c_derived_tbl *actbl)
#define MEMCOPY(dest, src, size)
htest_one_block(j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val, long dc_counts[], long ac_counts[])
struct jpeg_entropy_encoder pub
finish_pass_huff(j_compress_ptr cinfo)
register bit_buf_type register int int nbits
jpeg_make_c_derived_tbl(j_compress_ptr cinfo, boolean isDC, int tblno, c_derived_tbl **pdtbl)
unsigned int restart_interval
jinit_huff_encoder(j_compress_ptr cinfo)
#define ERREXIT1(cinfo, code, p1)
encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
INLINE emit_bits(working_state *state, unsigned int code, int size)
jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]
int last_dc_val[MAX_COMPS_IN_SCAN]
jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
unsigned int restarts_to_go
encode_mcu_gather(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
finish_pass_gather(j_compress_ptr cinfo)
c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]
JOCTET * next_output_byte
emit_restart(working_state *state, int restart_num)
#define MAX_COMPS_IN_SCAN
#define MEMZERO(target, size)
long * dc_count_ptrs[NUM_HUFF_TBLS]
#define emit_byte(state, val, action)
flush_bits(working_state *state)