15 #define JPEG_INTERNALS 20 #ifdef C_PROGRESSIVE_SUPPORTED 28 boolean gather_statistics;
34 size_t free_in_buffer;
49 unsigned int restarts_to_go;
60 } phuff_entropy_encoder;
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;
114 entropy->gather_statistics = gather_statistics;
116 is_DC_band = (cinfo->
Ss == 0);
121 if (cinfo->
Ah == 0) {
132 if (entropy->bit_buffer ==
NULL)
133 entropy->bit_buffer = (
char *)
138 if (gather_statistics)
149 entropy->last_dc_val[ci] = 0;
158 if (gather_statistics) {
162 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
165 if (entropy->count_ptrs[tbl] ==
NULL)
166 entropy->count_ptrs[tbl] = (
long *)
174 & entropy->derived_tbls[tbl]);
183 entropy->put_buffer = 0;
184 entropy->put_bits = 0;
188 entropy->next_restart_num = 0;
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);
329 emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
331 emit_bits(entropy, entropy->EOBRUN, nbits);
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;
388 entropy->next_output_byte = cinfo->dest->next_output_byte;
389 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
392 if (cinfo->restart_interval)
393 if (entropy->restarts_to_go == 0)
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];
408 temp = temp2 - entropy->last_dc_val[ci];
409 entropy->last_dc_val[ci] = temp2;
430 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
441 cinfo->dest->next_output_byte = entropy->next_output_byte;
442 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
445 if (cinfo->restart_interval) {
446 if (entropy->restarts_to_go == 0) {
447 entropy->restarts_to_go = cinfo->restart_interval;
448 entropy->next_restart_num++;
449 entropy->next_restart_num &= 7;
451 entropy->restarts_to_go--;
467 register int temp, temp2;
474 entropy->next_output_byte = cinfo->dest->next_output_byte;
475 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
478 if (cinfo->restart_interval)
479 if (entropy->restarts_to_go == 0)
489 for (k = cinfo->Ss; k <= Se; k++) {
515 if (entropy->EOBRUN > 0)
529 ERREXIT(cinfo, JERR_BAD_DCT_COEF);
543 if (entropy->EOBRUN == 0x7FFF)
547 cinfo->dest->next_output_byte = entropy->next_output_byte;
548 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
551 if (cinfo->restart_interval) {
552 if (entropy->restarts_to_go == 0) {
553 entropy->restarts_to_go = cinfo->restart_interval;
554 entropy->next_restart_num++;
555 entropy->next_restart_num &= 7;
557 entropy->restarts_to_go--;
579 entropy->next_output_byte = cinfo->dest->next_output_byte;
580 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
583 if (cinfo->restart_interval)
584 if (entropy->restarts_to_go == 0)
588 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
589 block = MCU_data[blkn];
593 emit_bits(entropy, (
unsigned int) (temp >> Al), 1);
596 cinfo->dest->next_output_byte = entropy->next_output_byte;
597 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
600 if (cinfo->restart_interval) {
601 if (entropy->restarts_to_go == 0) {
602 entropy->restarts_to_go = cinfo->restart_interval;
603 entropy->next_restart_num++;
604 entropy->next_restart_num &= 7;
606 entropy->restarts_to_go--;
631 entropy->next_output_byte = cinfo->dest->next_output_byte;
632 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
635 if (cinfo->restart_interval)
636 if (entropy->restarts_to_go == 0)
646 for (k = cinfo->Ss; k <= Se; k++) {
664 BR_buffer = entropy->bit_buffer + entropy->BE;
666 for (k = cinfo->Ss; k <= Se; k++) {
667 if ((temp = absvalues[k]) == 0) {
673 while (r > 15 && k <= EOB) {
681 BR_buffer = entropy->bit_buffer;
692 BR_buffer[BR++] = (char) (temp & 1);
700 emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
704 emit_bits(entropy, (
unsigned int) temp, 1);
708 BR_buffer = entropy->bit_buffer;
713 if (r > 0 || BR > 0) {
724 cinfo->dest->next_output_byte = entropy->next_output_byte;
725 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
728 if (cinfo->restart_interval) {
729 if (entropy->restarts_to_go == 0) {
730 entropy->restarts_to_go = cinfo->restart_interval;
731 entropy->next_restart_num++;
732 entropy->next_restart_num &= 7;
734 entropy->restarts_to_go--;
750 entropy->next_output_byte = cinfo->dest->next_output_byte;
751 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
757 cinfo->dest->next_output_byte = entropy->next_output_byte;
758 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
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)
821 SIZEOF(phuff_entropy_encoder));
823 entropy->pub.start_pass = start_pass_phuff;
827 entropy->derived_tbls[
i] =
NULL;
828 entropy->count_ptrs[
i] =
NULL;
830 entropy->bit_buffer =
NULL;
#define emit_byte(entropy, val)
emit_buffered_bits(phuff_entropy_ptr entropy, char *bufstart, unsigned int nbits)
const int jpeg_natural_order[]
struct jpeg_common_struct * j_common_ptr
encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
#define ERREXIT(cinfo, code)
jpeg_alloc_huff_table(j_common_ptr cinfo)
encode_mcu_DC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
finish_pass_gather_phuff(j_compress_ptr cinfo)
emit_eobrun(phuff_entropy_ptr entropy)
struct jpeg_entropy_encoder * entropy
#define IRIGHT_SHIFT(x, shft)
jpeg_component_info * compptr
finish_pass_phuff(j_compress_ptr cinfo)
INLINE emit_bits(phuff_entropy_ptr entropy, unsigned int code, int size)
flush_bits(phuff_entropy_ptr entropy)
GLdouble GLdouble GLdouble r
phuff_entropy_encoder * phuff_entropy_ptr
register bit_buf_type register int int nbits
jinit_phuff_encoder(j_compress_ptr cinfo)
jpeg_make_c_derived_tbl(j_compress_ptr cinfo, boolean isDC, int tblno, c_derived_tbl **pdtbl)
unsigned int restart_interval
#define ERREXIT1(cinfo, code, p1)
if(!abbox) return FT_THROW(Invalid_Argument)
emit_restart(phuff_entropy_ptr entropy, int restart_num)
jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]
jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
encode_mcu_DC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
INLINE emit_symbol(phuff_entropy_ptr entropy, int tbl_no, int symbol)
dump_buffer(phuff_entropy_ptr entropy)
JOCTET * next_output_byte
#define MAX_COMPS_IN_SCAN
#define MEMZERO(target, size)