10 #define JPEG_INTERNALS 33 #ifndef NO_STRUCT_ASSIGN 34 #define ASSIGN_STATE(dest,src) ((dest) = (src)) 36 #if MAX_COMPS_IN_SCAN == 4 37 #define ASSIGN_STATE(dest,src) \ 38 ((dest).put_buffer = (src).put_buffer, \ 39 (dest).put_bits = (src).put_bits, \ 40 (dest).last_dc_val[0] = (src).last_dc_val[0], \ 41 (dest).last_dc_val[1] = (src).last_dc_val[1], \ 42 (dest).last_dc_val[2] = (src).last_dc_val[2], \ 43 (dest).last_dc_val[3] = (src).last_dc_val[3]) 61 #ifdef ENTROPY_OPT_SUPPORTED 85 #ifdef ENTROPY_OPT_SUPPORTED 102 int ci, dctbl, actbl;
105 if (gather_statistics) {
106 #ifdef ENTROPY_OPT_SUPPORTED 110 ERREXIT(cinfo, JERR_NOT_COMPILED);
117 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
118 compptr = cinfo->cur_comp_info[ci];
121 if (gather_statistics) {
122 #ifdef ENTROPY_OPT_SUPPORTED 126 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
128 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
177 int p, i, l, lastp, si, maxsymbol;
179 unsigned int huffcode[257];
190 isDC ? cinfo->dc_huff_tbl_ptrs[
tblno] : cinfo->ac_huff_tbl_ptrs[
tblno];
204 for (l = 1; l <= 16; l++) {
206 if (i < 0 || p + i > 256)
207 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
209 huffsize[
p++] = (char) l;
220 while (huffsize[
p]) {
221 while (((
int) huffsize[
p]) == si) {
222 huffcode[
p++] =
code;
229 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
248 maxsymbol =
isDC ? 15 : 255;
250 for (
p = 0;
p < lastp;
p++) {
252 if (i < 0 || i > maxsymbol || dtbl->
ehufsi[i])
253 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
263 #define emit_byte(state,val,action) \ 264 { *(state)->next_output_byte++ = (JOCTET) (val); \ 265 if (--(state)->free_in_buffer == 0) \ 266 if (! dump_buffer(state)) \ 276 if (! (*dest->empty_output_buffer) (state->cinfo))
300 int put_bits = state->cur.put_bits;
304 ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
310 put_buffer <<= 24 - put_bits;
312 put_buffer |= state->cur.put_buffer;
314 while (put_bits >= 8) {
315 int c = (int) ((put_buffer >> 16) & 0xFF);
325 state->cur.put_buffer = put_buffer;
326 state->cur.put_bits = put_bits;
337 state->cur.put_buffer = 0;
338 state->cur.put_bits = 0;
355 temp = temp2 = block[0] - last_dc_val;
374 ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
396 if (!
emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
414 ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
418 if (!
emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
432 if (!
emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
455 for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
456 state->cur.last_dc_val[ci] = 0;
477 state.next_output_byte = cinfo->dest->next_output_byte;
478 state.free_in_buffer = cinfo->dest->free_in_buffer;
483 if (cinfo->restart_interval) {
490 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
491 ci = cinfo->MCU_membership[blkn];
492 compptr = cinfo->cur_comp_info[ci];
494 MCU_data[blkn][0], state.cur.last_dc_val[ci],
499 state.cur.last_dc_val[ci] =
MCU_data[blkn][0][0];
503 cinfo->dest->next_output_byte = state.next_output_byte;
504 cinfo->dest->free_in_buffer = state.free_in_buffer;
508 if (cinfo->restart_interval) {
533 state.free_in_buffer = cinfo->dest->free_in_buffer;
539 ERREXIT(cinfo, JERR_CANT_SUSPEND);
542 cinfo->dest->next_output_byte = state.next_output_byte;
543 cinfo->dest->free_in_buffer = state.free_in_buffer;
559 #ifdef ENTROPY_OPT_SUPPORTED 566 long dc_counts[],
long ac_counts[])
574 temp = block[0] - last_dc_val;
588 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
617 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
620 ac_counts[(
r << 4) +
nbits]++;
645 if (cinfo->restart_interval) {
648 for (ci = 0; ci < cinfo->comps_in_scan; ci++)
656 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
657 ci = cinfo->MCU_membership[blkn];
658 compptr = cinfo->cur_comp_info[ci];
712 for (i = 0; i < 257; i++)
728 for (i = 0; i <= 256; i++) {
739 for (i = 0; i <= 256; i++) {
740 if (
freq[i] &&
freq[i] <=
v && i != c1) {
756 while (others[c1] >= 0) {
765 while (others[c2] >= 0) {
772 for (i = 0; i <= 256; i++) {
777 ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
795 while (bits[i] > 0) {
821 for (j = 0; j <= 255; j++) {
822 if (codesize[j] == i) {
842 int ci, dctbl, actbl;
854 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
855 compptr = cinfo->cur_comp_info[ci];
858 if (! did_dc[dctbl]) {
859 htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
860 if (*htblptr == NULL)
863 did_dc[dctbl] =
TRUE;
865 if (! did_ac[actbl]) {
866 htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
867 if (*htblptr == NULL)
870 did_ac[actbl] =
TRUE;
898 #ifdef ENTROPY_OPT_SUPPORTED
boolean int c_derived_tbl ** pdtbl
#define emit_byte(state, val, action)
long * ac_count_ptrs[NUM_HUFF_TBLS]
#define MAX_COMPS_IN_SCAN
jpeg_make_c_derived_tbl(j_compress_ptr cinfo, boolean isDC, int tblno, c_derived_tbl **pdtbl)
const int jpeg_natural_order[]
JOCTET * next_output_byte
struct jpeg_common_struct * j_common_ptr
encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val, c_derived_tbl *dctbl, c_derived_tbl *actbl)
#define ERREXIT(cinfo, code)
htest_one_block(j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val, long dc_counts[], long ac_counts[])
jpeg_component_info * compptr
encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
finish_pass_gather(j_compress_ptr cinfo)
c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS]
INLINE emit_bits(working_state *state, unsigned int code, int size)
flush_bits(working_state *state)
encode_mcu_gather(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
jinit_huff_encoder(j_compress_ptr cinfo)
#define MEMCOPY(dest, src, size)
jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
bit_buf_type int int nbits
huff_entropy_encoder * huff_entropy_ptr
jpeg_alloc_huff_table(j_common_ptr cinfo)
struct jpeg_entropy_encoder pub
#define ASSIGN_STATE(dest, src)
emit_restart(working_state *state, int restart_num)
METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo
#define ERREXIT1(cinfo, code, p1)
GLdouble GLdouble GLdouble r
finish_pass_huff(j_compress_ptr cinfo)
int last_dc_val[MAX_COMPS_IN_SCAN]
unsigned int restarts_to_go
dump_buffer(working_state *state)
c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]
JOCTET * next_output_byte
start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics)
#define MEMZERO(target, size)
long * dc_count_ptrs[NUM_HUFF_TBLS]