15 #define JPEG_INTERNALS
20 #ifdef C_PROGRESSIVE_SUPPORTED
70 #define MAX_CORR_BITS 1000
77 #ifdef RIGHT_SHIFT_IS_UNSIGNED
78 #define ISHIFT_TEMPS int ishift_temp;
79 #define IRIGHT_SHIFT(x,shft) \
80 ((ishift_temp = (x)) < 0 ? \
81 (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
82 (ishift_temp >> (shft)))
85 #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
106 start_pass_phuff (
j_compress_ptr cinfo,
boolean gather_statistics)
113 entropy->
cinfo = cinfo;
116 is_DC_band = (cinfo->
Ss == 0);
121 if (cinfo->
Ah == 0) {
138 if (gather_statistics)
158 if (gather_statistics) {
162 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
198 #define emit_byte(entropy,val) \
199 { *(entropy)->next_output_byte++ = (JOCTET) (val); \
200 if (--(entropy)->free_in_buffer == 0) \
201 dump_buffer(entropy); }
210 if (! (*dest->empty_output_buffer) (entropy->cinfo))
211 ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
233 register int put_bits = entropy->put_bits;
237 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
239 if (entropy->gather_statistics)
246 put_buffer <<= 24 - put_bits;
248 put_buffer |= entropy->put_buffer;
250 while (put_bits >= 8) {
251 int c = (
int) ((put_buffer >> 16) & 0xFF);
261 entropy->put_buffer = put_buffer;
262 entropy->put_bits = put_bits;
270 entropy->put_buffer = 0;
271 entropy->put_bits = 0;
283 if (entropy->gather_statistics)
284 entropy->count_ptrs[tbl_no][symbol]++;
300 if (entropy->gather_statistics)
304 emit_bits(entropy, (
unsigned int) (*bufstart), 1);
318 register int temp,
nbits;
320 if (entropy->EOBRUN > 0) {
321 temp = entropy->EOBRUN;
327 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
353 if (! entropy->gather_statistics) {
359 if (entropy->cinfo->Ss == 0) {
361 for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
362 entropy->last_dc_val[ci] = 0;
380 register int temp, temp2;
392 if (cinfo->restart_interval)
397 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
398 block = MCU_data[blkn];
399 ci = cinfo->MCU_membership[blkn];
400 compptr = cinfo->cur_comp_info[ci];
430 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
445 if (cinfo->restart_interval) {
467 register int temp, temp2;
478 if (cinfo->restart_interval)
489 for (k = cinfo->Ss; k <= Se; k++) {
529 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
543 if (entropy->
EOBRUN == 0x7FFF)
551 if (cinfo->restart_interval) {
583 if (cinfo->restart_interval)
588 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
589 block = MCU_data[blkn];
593 emit_bits(entropy, (
unsigned int) (temp >> Al), 1);
600 if (cinfo->restart_interval) {
635 if (cinfo->restart_interval)
646 for (k = cinfo->Ss; k <= Se; k++) {
666 for (k = cinfo->Ss; k <= Se; k++) {
667 if ((temp = absvalues[k]) == 0) {
673 while (r > 15 && k <= EOB) {
692 BR_buffer[BR++] = (char) (temp & 1);
704 emit_bits(entropy, (
unsigned int) temp, 1);
713 if (r > 0 || BR > 0) {
728 if (cinfo->restart_interval) {
779 is_DC_band = (cinfo->Ss == 0);
786 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
787 compptr = cinfo->cur_comp_info[ci];
797 htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
799 htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
800 if (*htblptr == NULL)
823 entropy->
pub.start_pass = start_pass_phuff;