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);
127 actbl = compptr->ac_tbl_no;
132 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
135 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
136 if (gather_statistics) {
137 #ifdef ENTROPY_OPT_SUPPORTED
183 int p,
i,
l, lastp, si;
185 unsigned int huffcode[257];
199 for (l = 1; l <= 16; l++) {
200 for (i = 1; i <= (
int) htbl->
bits[l]; i++)
201 huffsize[p++] = (char) l;
212 while (huffsize[p]) {
213 while (((
int) huffsize[
p]) == si) {
214 huffcode[p++] = code;
229 for (p = 0; p < lastp; p++) {
239 #define emit_byte(state,val,action) \
240 { *(state)->next_output_byte++ = (JOCTET) (val); \
241 if (--(state)->free_in_buffer == 0) \
242 if (! dump_buffer(state)) \
252 if (! (*dest->empty_output_buffer) (state->
cinfo))
286 put_buffer <<= 24 - put_bits;
290 while (put_bits >= 8) {
291 int c = (
int) ((put_buffer >> 16) & 0xFF);
325 register int temp, temp2;
327 register int k,
r,
i;
331 temp = temp2 = block[0] - last_dc_val;
354 if (!
emit_bits(state, (
unsigned int) temp2, nbits))
385 i = (r << 4) + nbits;
391 if (!
emit_bits(state, (
unsigned int) temp2, nbits))
462 MCU_data[blkn][0], state.cur.last_dc_val[ci],
467 state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
507 ERREXIT(cinfo, JERR_CANT_SUSPEND);
534 #ifdef ENTROPY_OPT_SUPPORTED
541 long dc_counts[],
long ac_counts[])
549 temp = block[0] - last_dc_val;
587 ac_counts[(r << 4) + nbits]++;
656 for (i = 0; i < 257; i++)
672 for (i = 0; i <= 256; i++) {
673 if (freq[i] && freq[i] <= v) {
683 for (i = 0; i <= 256; i++) {
684 if (freq[i] && freq[i] <= v && i != c1) {
695 freq[c1] += freq[c2];
700 while (others[c1] >= 0) {
709 while (others[c2] >= 0) {
716 for (i = 0; i <= 256; i++) {
721 ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
739 while (bits[i] > 0) {
765 for (j = 0; j <= 255; j++) {
766 if (codesize[j] == i) {
786 int ci, dctbl, actbl;
801 actbl = compptr->ac_tbl_no;
802 if (! did_dc[dctbl]) {
804 if (*htblptr ==
NULL)
807 did_dc[dctbl] =
TRUE;
809 if (! did_ac[actbl]) {
811 if (*htblptr ==
NULL)
814 did_ac[actbl] =
TRUE;
842 #ifdef ENTROPY_OPT_SUPPORTED
JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]
METHODDEF void finish_pass_gather(j_compress_ptr cinfo)
METHODDEF boolean encode_mcu_gather(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
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)
GLOBAL JHUFF_TBL * jpeg_alloc_huff_table(j_common_ptr cinfo)
#define ERREXIT(cinfo, code)
JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]
struct jpeg_entropy_encoder * entropy
int MCU_membership[C_MAX_BLOCKS_IN_MCU]
METHODDEF void start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics)
LOCAL boolean flush_bits(working_state *state)
c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS]
#define MEMCOPY(dest, src, size)
INLINE LOCAL boolean emit_bits(working_state *state, unsigned int code, int size)
METHODDEF boolean encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
LOCAL boolean encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val, c_derived_tbl *dctbl, c_derived_tbl *actbl)
struct jpeg_entropy_encoder pub
struct jpeg_destination_mgr * dest
GLOBAL void jinit_huff_encoder(j_compress_ptr cinfo)
LOCAL boolean emit_restart(working_state *state, int restart_num)
unsigned int restart_interval
METHODDEF void finish_pass_huff(j_compress_ptr cinfo)
#define ERREXIT1(cinfo, code, p1)
GLdouble GLdouble GLdouble r
METHODDEF boolean encode_mcu_huff JPP((j_compress_ptr cinfo, JBLOCKROW *MCU_data))
jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]
int last_dc_val[MAX_COMPS_IN_SCAN]
unsigned int restarts_to_go
LOCAL boolean dump_buffer(working_state *state)
if(!ValidDisplayID(prefInfo.prefDisplayID)) prefInfo.prefDisplayID
LOCAL void htest_one_block(JCOEFPTR block, int last_dc_val, long dc_counts[], long ac_counts[])
c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]
JOCTET * next_output_byte
GLOBAL void jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
GLOBAL void jpeg_make_c_derived_tbl(j_compress_ptr cinfo, JHUFF_TBL *htbl, c_derived_tbl **pdtbl)
#define MAX_COMPS_IN_SCAN
#define MEMZERO(target, size)
long * dc_count_ptrs[NUM_HUFF_TBLS]
#define emit_byte(state, val, action)