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]) 61 unsigned int restarts_to_go;
68 #ifdef ENTROPY_OPT_SUPPORTED 72 } huff_entropy_encoder;
82 size_t free_in_buffer;
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);
138 if (entropy->dc_count_ptrs[dctbl] ==
NULL)
139 entropy->dc_count_ptrs[dctbl] = (
long *)
143 if (entropy->ac_count_ptrs[actbl] ==
NULL)
144 entropy->ac_count_ptrs[actbl] = (
long *)
153 & entropy->dc_derived_tbls[dctbl]);
155 & entropy->ac_derived_tbls[actbl]);
158 entropy->saved.last_dc_val[ci] = 0;
162 entropy->saved.put_buffer = 0;
163 entropy->saved.put_bits = 0;
167 entropy->next_restart_num = 0;
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) {
491 if (entropy->restarts_to_go == 0)
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) {
516 if (entropy->restarts_to_go == 0) {
517 entropy->restarts_to_go = cinfo->restart_interval;
518 entropy->next_restart_num++;
519 entropy->next_restart_num &= 7;
521 entropy->restarts_to_go--;
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) {
653 if (entropy->restarts_to_go == 0) {
655 for (ci = 0; ci < cinfo->comps_in_scan; ci++)
656 entropy->saved.last_dc_val[ci] = 0;
658 entropy->restarts_to_go = cinfo->restart_interval;
660 entropy->restarts_to_go--;
663 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
664 ci = cinfo->MCU_membership[blkn];
665 compptr = cinfo->cur_comp_info[ci];
666 htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
669 entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
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;
898 SIZEOF(huff_entropy_encoder));
900 entropy->pub.start_pass = start_pass_huff;
904 entropy->dc_derived_tbls[
i] = entropy->ac_derived_tbls[
i] =
NULL;
905 #ifdef ENTROPY_OPT_SUPPORTED 906 entropy->dc_count_ptrs[
i] = entropy->ac_count_ptrs[
i] =
NULL;
boolean int c_derived_tbl ** pdtbl
dump_buffer(working_state *state)
huff_entropy_encoder * huff_entropy_ptr
const int jpeg_natural_order[]
struct jpeg_common_struct * j_common_ptr
#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
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)
GLdouble GLdouble GLdouble r
htest_one_block(j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val, long dc_counts[], long ac_counts[])
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)
if(!abbox) return FT_THROW(Invalid_Argument)
jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]
jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
encode_mcu_gather(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
finish_pass_gather(j_compress_ptr cinfo)
JOCTET * next_output_byte
emit_restart(working_state *state, int restart_num)
#define MAX_COMPS_IN_SCAN
#define MEMZERO(target, size)
#define emit_byte(state, val, action)
flush_bits(working_state *state)