34#if BITS_IN_JSAMPLE == 8
35#define MAX_COEF_BITS 10
37#define MAX_COEF_BITS 14
43 unsigned int ehufco[256];
66#ifndef NO_STRUCT_ASSIGN
67#define ASSIGN_STATE(dest,src) ((dest) = (src))
69#if MAX_COMPS_IN_SCAN == 4
70#define ASSIGN_STATE(dest,src) \
71 ((dest).put_buffer = (src).put_buffer, \
72 (dest).put_bits = (src).put_bits, \
73 (dest).last_dc_val[0] = (src).last_dc_val[0], \
74 (dest).last_dc_val[1] = (src).last_dc_val[1], \
75 (dest).last_dc_val[2] = (src).last_dc_val[2], \
76 (dest).last_dc_val[3] = (src).last_dc_val[3])
136#define MAX_CORR_BITS 1000
143#ifdef RIGHT_SHIFT_IS_UNSIGNED
144#define ISHIFT_TEMPS int ishift_temp;
145#define IRIGHT_SHIFT(x,shft) \
146 ((ishift_temp = (x)) < 0 ? \
147 (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
148 (ishift_temp >> (shft)))
151#define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
166 int p,
i,
l, lastp, si, maxsymbol;
168 unsigned int huffcode[257];
179 isDC ? cinfo->dc_huff_tbl_ptrs[
tblno] : cinfo->ac_huff_tbl_ptrs[
tblno];
192 for (
l = 1;
l <= 16;
l++) {
194 if (i < 0 || p + i > 256)
195 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
208 while (huffsize[
p]) {
209 while (((
int) huffsize[
p]) == si) {
210 huffcode[
p++] =
code;
217 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
236 maxsymbol =
isDC ? 15 : 255;
238 for (
p = 0;
p < lastp;
p++) {
240 if (i < 0 || i > maxsymbol || dtbl->
ehufsi[
i])
241 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
254#define emit_byte_s(state,val,action) \
255 { *(state)->next_output_byte++ = (JOCTET) (val); \
256 if (--(state)->free_in_buffer == 0) \
257 if (! dump_buffer_s(state)) \
261#define emit_byte_e(entropy,val) \
262 { *(entropy)->next_output_byte++ = (JOCTET) (val); \
263 if (--(entropy)->free_in_buffer == 0) \
264 dump_buffer_e(entropy); }
273 if (! (*
dest->empty_output_buffer) (
state->cinfo))
276 state->next_output_byte =
dest->next_output_byte;
277 state->free_in_buffer =
dest->free_in_buffer;
288 if (! (*
dest->empty_output_buffer) (entropy->cinfo))
289 ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
291 entropy->next_output_byte =
dest->next_output_byte;
292 entropy->free_in_buffer =
dest->free_in_buffer;
310 register INT32 put_buffer;
311 register int put_bits;
323 put_buffer <<= 24 - put_bits;
326 put_buffer |=
state->cur.put_buffer;
328 while (put_bits >= 8) {
329 int c = (
int) ((put_buffer >> 16) & 0xFF);
339 state->cur.put_buffer = put_buffer;
340 state->cur.put_bits = put_bits;
352 register INT32 put_buffer;
353 register int put_bits;
357 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
359 if (entropy->gather_statistics)
366 put_bits =
size + entropy->saved.put_bits;
368 put_buffer <<= 24 - put_bits;
371 put_buffer |= entropy->saved.put_buffer;
373 while (put_bits >= 8) {
374 int c = (
int) ((put_buffer >> 16) & 0xFF);
384 entropy->saved.put_buffer = put_buffer;
385 entropy->saved.put_bits = put_bits;
394 state->cur.put_buffer = 0;
395 state->cur.put_bits = 0;
404 entropy->saved.put_buffer = 0;
405 entropy->saved.put_bits = 0;
417 if (entropy->gather_statistics)
418 entropy->dc_count_ptrs[tbl_no][symbol]++;
430 if (entropy->gather_statistics)
431 entropy->ac_count_ptrs[tbl_no][symbol]++;
447 if (entropy->gather_statistics)
451 emit_bits_e(entropy, (
unsigned int) (*bufstart), 1);
465 register int temp, nbits;
467 if (entropy->EOBRUN > 0) {
468 temp = entropy->EOBRUN;
474 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
505 for (ci = 0; ci <
state->cinfo->comps_in_scan; ci++)
506 state->cur.last_dc_val[ci] = 0;
521 if (! entropy->gather_statistics) {
527 if (entropy->cinfo->Ss == 0) {
529 for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
530 entropy->saved.last_dc_val[ci] = 0;
548 register int temp, temp2;
557 if (cinfo->restart_interval)
562 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
563 ci = cinfo->MCU_membership[blkn];
564 tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;
594 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
609 if (cinfo->restart_interval) {
631 const int * natural_order;
633 register int temp, temp2;
642 if (cinfo->restart_interval)
648 natural_order = cinfo->natural_order;
657 for (
k = cinfo->Ss;
k <= Se;
k++) {
658 if ((
temp = (*
block)[natural_order[
k]]) == 0) {
697 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
711 if (entropy->
EOBRUN == 0x7FFF)
719 if (cinfo->restart_interval) {
748 if (cinfo->restart_interval)
755 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
757 emit_bits_e(entropy, (
unsigned int) (MCU_data[blkn][0][0] >> Al), 1);
764 if (cinfo->restart_interval) {
785 const int * natural_order;
799 if (cinfo->restart_interval)
805 natural_order = cinfo->natural_order;
814 for (
k = cinfo->Ss;
k <= Se;
k++) {
815 temp = (*block)[natural_order[
k]];
834 for (
k = cinfo->Ss;
k <= Se;
k++) {
835 if ((
temp = absvalues[
k]) == 0) {
841 while (
r > 15 &&
k <= EOB) {
860 BR_buffer[BR++] = (
char) (
temp & 1);
871 temp = ((*block)[natural_order[
k]] < 0) ? 0 : 1;
881 if (
r > 0 || BR > 0) {
896 if (cinfo->restart_interval) {
915 register int temp, temp2;
918 int Se =
state->cinfo->lim_Se;
919 const int * natural_order =
state->cinfo->natural_order;
958 for (
k = 1;
k <= Se;
k++) {
959 if ((temp2 =
block[natural_order[
k]]) == 0) {
985 temp = (
r << 4) + nbits;
1020 state.next_output_byte = cinfo->dest->next_output_byte;
1021 state.free_in_buffer = cinfo->dest->free_in_buffer;
1023 state.cinfo = cinfo;
1026 if (cinfo->restart_interval) {
1033 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
1034 ci = cinfo->MCU_membership[blkn];
1035 compptr = cinfo->cur_comp_info[ci];
1037 MCU_data[blkn][0],
state.cur.last_dc_val[ci],
1042 state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
1046 cinfo->dest->next_output_byte =
state.next_output_byte;
1047 cinfo->dest->free_in_buffer =
state.free_in_buffer;
1051 if (cinfo->restart_interval) {
1074 if (cinfo->progressive_mode) {
1086 state.next_output_byte = cinfo->dest->next_output_byte;
1087 state.free_in_buffer = cinfo->dest->free_in_buffer;
1089 state.cinfo = cinfo;
1093 ERREXIT(cinfo, JERR_CANT_SUSPEND);
1096 cinfo->dest->next_output_byte =
state.next_output_byte;
1097 cinfo->dest->free_in_buffer =
state.free_in_buffer;
1119 long dc_counts[],
long ac_counts[])
1124 int Se = cinfo->lim_Se;
1125 const int * natural_order = cinfo->natural_order;
1143 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
1152 for (
k = 1;
k <= Se;
k++) {
1168 while ((
temp >>= 1))
1172 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
1175 ac_counts[(
r << 4) + nbits]++;
1200 if (cinfo->restart_interval) {
1203 for (ci = 0; ci < cinfo->comps_in_scan; ci++)
1211 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
1212 ci = cinfo->MCU_membership[blkn];
1213 compptr = cinfo->cur_comp_info[ci];
1270#ifndef DONT_USE_FANCY_HUFF_OPT
1316 while ((c1 = others[256]) >= 0) {
1320 while ((c2 = others[c1]) >= 0) {
1328 others[
j] = others[
i];
1338 for (
i = 0;
i < 257;
i++)
1348 for (
i = 0;
i <= 256;
i++) {
1349 if (freq[
i] && freq[
i] <=
v) {
1359 for (
i = 0;
i <= 256;
i++) {
1360 if (freq[
i] && freq[
i] <=
v &&
i != c1) {
1371 freq[c1] += freq[c2];
1376 while (others[c1] >= 0) {
1385 while (others[c2] >= 0) {
1392 for (
i = 0;
i <= 256;
i++) {
1397 ERREXIT(cinfo, JERR_HUFF_CLEN_OUTOFBOUNDS);
1399 bits[codesize[
i]]++;
1415 while (
bits[
i] > 0) {
1417 while (
bits[
j] == 0) {
1419 ERREXIT(cinfo, JERR_HUFF_CLEN_OUTOFBOUNDS);
1431 while (
bits[
i] == 0)
1438#ifdef DONT_USE_FANCY_HUFF_OPT
1446 for (
j = 0;
j <= 255;
j++) {
1447 if (codesize[
j] ==
i) {
1456 htbl->sent_table =
FALSE;
1474 if (cinfo->progressive_mode)
1484 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
1485 compptr = cinfo->cur_comp_info[ci];
1487 if (cinfo->Ss == 0 && cinfo->Ah == 0) {
1489 if (! did_dc[tbl]) {
1490 htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
1491 if (*htblptr ==
NULL)
1500 if (! did_ac[tbl]) {
1501 htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
1502 if (*htblptr ==
NULL)
1525 if (gather_statistics)
1530 if (cinfo->progressive_mode) {
1531 entropy->
cinfo = cinfo;
1537 if (cinfo->Ah == 0) {
1549 entropy->
bit_buffer = (
char *) (*cinfo->mem->alloc_small)
1555 entropy->
ac_tbl_no = cinfo->cur_comp_info[0]->ac_tbl_no;
1559 if (gather_statistics)
1565 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
1566 compptr = cinfo->cur_comp_info[ci];
1568 if (cinfo->Ss == 0 && cinfo->Ah == 0) {
1570 if (gather_statistics) {
1574 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
1578 entropy->
dc_count_ptrs[tbl] = (
long *) (*cinfo->mem->alloc_small)
1593 if (gather_statistics) {
1595 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
1597 entropy->
ac_count_ptrs[tbl] = (
long *) (*cinfo->mem->alloc_small)
1629 cinfo->entropy = &entropy->
pub;
1638 if (cinfo->progressive_mode)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
GLdouble GLdouble GLdouble r
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
htest_one_block(j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val, long dc_counts[], long ac_counts[])
INLINE emit_ac_symbol(huff_entropy_ptr entropy, int tbl_no, int symbol)
#define ASSIGN_STATE(dest, src)
encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
dump_buffer_e(huff_entropy_ptr entropy)
encode_mcu_DC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
encode_mcu_gather(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
#define emit_byte_e(entropy, val)
jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
encode_mcu_DC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
jpeg_make_c_derived_tbl(j_compress_ptr cinfo, boolean isDC, int tblno, c_derived_tbl **pdtbl)
jinit_huff_encoder(j_compress_ptr cinfo)
dump_buffer_s(working_state *state)
emit_restart_e(huff_entropy_ptr entropy, int restart_num)
#define IRIGHT_SHIFT(x, shft)
#define emit_byte_s(state, val, action)
finish_pass_gather(j_compress_ptr cinfo)
INLINE emit_bits_e(huff_entropy_ptr entropy, unsigned int code, int size)
INLINE emit_bits_s(working_state *state, unsigned int code, int size)
flush_bits_s(working_state *state)
INLINE emit_dc_symbol(huff_entropy_ptr entropy, int tbl_no, int symbol)
finish_pass_huff(j_compress_ptr cinfo)
emit_buffered_bits(huff_entropy_ptr entropy, char *bufstart, unsigned int nbits)
emit_eobrun(huff_entropy_ptr entropy)
flush_bits_e(huff_entropy_ptr entropy)
encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val, c_derived_tbl *dctbl, c_derived_tbl *actbl)
start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics)
emit_restart_s(working_state *state, int restart_num)
encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
huff_entropy_encoder * huff_entropy_ptr
jpeg_std_huff_table(j_common_ptr cinfo, boolean isDC, int tblno)
jpeg_alloc_huff_table(j_common_ptr cinfo)
jpeg_component_info * compptr
#define ERREXIT1(cinfo, code, p1)
#define MEMCOPY(dest, src, size)
struct jpeg_common_struct * j_common_ptr
#define MAX_COMPS_IN_SCAN
c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS]
struct jpeg_entropy_encoder pub
c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]
unsigned int restarts_to_go
boolean gather_statistics
long * ac_count_ptrs[NUM_HUFF_TBLS]
JOCTET * next_output_byte
long * dc_count_ptrs[NUM_HUFF_TBLS]
int last_dc_val[MAX_COMPS_IN_SCAN]
JOCTET * next_output_byte
#define MEMZERO(addr, type, size)
static unsigned int block