10 #define JPEG_INTERNALS 15 #ifdef C_PROGRESSIVE_SUPPORTED 66 #define MAX_CORR_BITS 1000 73 #ifdef RIGHT_SHIFT_IS_UNSIGNED 74 #define ISHIFT_TEMPS int ishift_temp; 75 #define IRIGHT_SHIFT(x, shft) \ 76 ((ishift_temp = (x)) < 0 \ 77 ? (ishift_temp >> (shft)) | ((~0) << (16 - (shft))) \ 78 : (ishift_temp >> (shft))) 81 #define IRIGHT_SHIFT(x, shft) ((x) >> (shft)) 108 entropy->
cinfo = cinfo;
111 is_DC_band = (cinfo->Ss == 0);
132 entropy->
bit_buffer = (
char*)(*cinfo->mem->alloc_small)(
137 if (gather_statistics)
145 for (ci = 0; ci < cinfo->comps_in_scan; ci++)
147 compptr = cinfo->cur_comp_info[ci];
161 if (gather_statistics)
166 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
171 entropy->
count_ptrs[tbl] = (
long*)(*cinfo->mem->alloc_small)(
204 #define emit_byte(entropy, val) \ 206 *(entropy)->next_output_byte++ = (JOCTET)(val); \ 207 if (--(entropy)->free_in_buffer == 0) dump_buffer(entropy); \ 216 if (!(*dest->empty_output_buffer)(entropy->cinfo))
217 ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
238 int put_bits = entropy->put_bits;
241 if (
size == 0)
ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
243 if (entropy->gather_statistics)
251 put_buffer <<= 24 - put_bits;
253 put_buffer |= entropy->put_buffer;
255 while (put_bits >= 8)
257 int c = (int)((put_buffer >> 16) & 0xFF);
268 entropy->put_buffer = put_buffer;
269 entropy->put_bits = put_bits;
276 entropy->put_buffer = 0;
277 entropy->put_bits = 0;
288 if (entropy->gather_statistics)
289 entropy->count_ptrs[tbl_no][symbol]++;
305 if (entropy->gather_statistics)
return;
309 emit_bits(entropy, (
unsigned int)(*bufstart), 1);
324 if (entropy->EOBRUN > 0)
326 temp = entropy->EOBRUN;
328 while ((temp >>= 1)) nbits++;
330 if (nbits > 14)
ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
332 emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
333 if (nbits)
emit_bits(entropy, entropy->EOBRUN, nbits);
354 if (!entropy->gather_statistics)
361 if (entropy->cinfo->Ss == 0)
364 for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
365 entropy->last_dc_val[ci] = 0;
396 if (cinfo->restart_interval)
401 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++)
403 block = MCU_data[blkn];
404 ci = cinfo->MCU_membership[blkn];
405 compptr = cinfo->cur_comp_info[ci];
446 emit_bits(entropy, (
unsigned int)temp2, nbits);
453 if (cinfo->restart_interval)
487 if (cinfo->restart_interval)
498 for (k = cinfo->Ss; k <= Se; k++)
542 while ((temp >>= 1)) nbits++;
551 emit_bits(entropy, (
unsigned int)temp2, nbits);
559 if (entropy->
EOBRUN == 0x7FFF)
567 if (cinfo->restart_interval)
600 if (cinfo->restart_interval)
605 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++)
607 block = MCU_data[blkn];
611 emit_bits(entropy, (
unsigned int)(temp >> Al), 1);
618 if (cinfo->restart_interval)
654 if (cinfo->restart_interval)
665 for (k = cinfo->Ss; k <= Se; k++)
672 if (temp < 0) temp = -temp;
675 if (temp == 1) EOB = k;
684 for (k = cinfo->Ss; k <= Se; k++)
686 if ((temp = absvalues[k]) == 0)
693 while (
r > 15 && k <= EOB)
715 BR_buffer[BR++] = (char)(temp & 1);
727 emit_bits(entropy, (
unsigned int)temp, 1);
745 if (entropy->
EOBRUN == 0x7FFF ||
754 if (cinfo->restart_interval)
805 is_DC_band = (cinfo->Ss == 0);
812 for (ci = 0; ci < cinfo->comps_in_scan; ci++)
814 compptr = cinfo->cur_comp_info[ci];
828 htblptr = &cinfo->dc_huff_tbl_ptrs[tbl];
830 htblptr = &cinfo->ac_huff_tbl_ptrs[tbl];
831 if (*htblptr ==
nullptr)
unsigned int restarts_to_go
encode_mcu_DC_first JPP((j_compress_ptr cinfo, JBLOCKROW *MCU_data))
encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
INLINE emit_symbol(phuff_entropy_ptr entropy, int tbl_no, int symbol)
#define MAX_COMPS_IN_SCAN
jpeg_make_c_derived_tbl(j_compress_ptr cinfo, boolean isDC, int tblno, c_derived_tbl **pdtbl)
const int jpeg_natural_order[]
encode_mcu_DC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
struct jpeg_common_struct * j_common_ptr
phuff_entropy_encoder * phuff_entropy_ptr
#define ERREXIT(cinfo, code)
encode_mcu_DC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
c_derived_tbl * derived_tbls[NUM_HUFF_TBLS]
JOCTET * next_output_byte
jinit_phuff_encoder(j_compress_ptr cinfo)
start_pass_phuff(j_compress_ptr cinfo, boolean gather_statistics)
INLINE emit_bits(phuff_entropy_ptr entropy, unsigned int code, int size)
jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
struct jpeg_entropy_encoder pub
emit_eobrun(phuff_entropy_ptr entropy)
flush_bits(phuff_entropy_ptr entropy)
jpeg_alloc_huff_table(j_common_ptr cinfo)
finish_pass_phuff(j_compress_ptr cinfo)
#define IRIGHT_SHIFT(x, shft)
encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
#define ERREXIT1(cinfo, code, p1)
GLdouble GLdouble GLdouble r
METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo))
emit_restart(phuff_entropy_ptr entropy, int restart_num)
dump_buffer(phuff_entropy_ptr entropy)
boolean gather_statistics
int last_dc_val[MAX_COMPS_IN_SCAN]
#define emit_byte(entropy, val)
emit_buffered_bits(phuff_entropy_ptr entropy, char *bufstart, unsigned int nbits)
JOCTET * next_output_byte
long * count_ptrs[NUM_HUFF_TBLS]
finish_pass_gather_phuff(j_compress_ptr cinfo)
#define MEMZERO(target, size)
jpeg_component_info * compptr