17 #define JPEG_INTERNALS 39 #ifndef NO_STRUCT_ASSIGN 40 #define ASSIGN_STATE(dest,src) ((dest) = (src)) 42 #if MAX_COMPS_IN_SCAN == 4 43 #define ASSIGN_STATE(dest,src) \ 44 ((dest).last_dc_val[0] = (src).last_dc_val[0], \ 45 (dest).last_dc_val[1] = (src).last_dc_val[1], \ 46 (dest).last_dc_val[2] = (src).last_dc_val[2], \ 47 (dest).last_dc_val[3] = (src).last_dc_val[3]) 89 int ci, blkn, dctbl, actbl;
96 if (cinfo->Ss != 0 || cinfo->Se !=
DCTSIZE2-1 ||
97 cinfo->Ah != 0 || cinfo->Al != 0)
98 WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
100 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
101 compptr = cinfo->cur_comp_info[ci];
115 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
116 ci = cinfo->MCU_membership[blkn];
117 compptr = cinfo->cur_comp_info[ci];
123 entropy->dc_needed[blkn] =
TRUE;
127 entropy->dc_needed[blkn] = entropy->ac_needed[blkn] =
FALSE;
132 entropy->bitstate.bits_left = 0;
133 entropy->bitstate.get_buffer = 0;
134 entropy->
pub.insufficient_data =
FALSE;
154 int p,
i, l, si, numsymbols;
157 unsigned int huffcode[257];
168 isDC ? cinfo->dc_huff_tbl_ptrs[
tblno] : cinfo->ac_huff_tbl_ptrs[
tblno];
183 for (l = 1; l <= 16; l++) {
185 if (i < 0 || p + i > 256)
186 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
188 huffsize[p++] = (char) l;
199 while (huffsize[p]) {
200 while (((
int) huffsize[p]) == si) {
201 huffcode[p++] =
code;
208 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
216 for (l = 1; l <= 16; l++) {
223 dtbl->
maxcode[l] = huffcode[p-1];
241 for (
i = 1;
i <= (
int) htbl->
bits[l];
i++, p++) {
260 for (
i = 0;
i < numsymbols;
i++) {
262 if (sym < 0 || sym > 15)
263 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
285 #define MIN_GET_BITS 15 287 #define MIN_GET_BITS (BIT_BUF_SIZE-7) 298 register const JOCTET * next_input_byte = state->next_input_byte;
299 register size_t bytes_in_buffer = state->bytes_in_buffer;
311 if (bytes_in_buffer == 0) {
312 if (! (*cinfo->
src->fill_input_buffer) (cinfo))
328 if (bytes_in_buffer == 0) {
329 if (! (*cinfo->
src->fill_input_buffer) (cinfo))
357 get_buffer = (get_buffer << 8) | c;
366 if (nbits > bits_left) {
373 WARNMS(cinfo, JWRN_HIT_MARKER);
383 state->next_input_byte = next_input_byte;
384 state->bytes_in_buffer = bytes_in_buffer;
414 while (
code > htbl->maxcode[l]) {
443 #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x)) 447 #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x)) 450 { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
451 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
454 { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
455 ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
456 ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
457 ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
475 cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
476 entropy->bitstate.bits_left = 0;
479 if (! (*cinfo->marker->read_restart_marker) (cinfo))
483 for (ci = 0; ci < cinfo->comps_in_scan; ci++)
494 if (cinfo->unread_marker == 0)
495 entropy->
pub.insufficient_data =
FALSE;
525 if (cinfo->restart_interval) {
534 if (! entropy->
pub.insufficient_data) {
542 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
546 register int s, k, r;
558 if (entropy->dc_needed[blkn]) {
560 int ci = cinfo->MCU_membership[blkn];
561 s +=
state.last_dc_val[ci];
562 state.last_dc_val[ci] = s;
564 (*block)[0] = (
JCOEF) s;
567 if (entropy->ac_needed[blkn]) {
572 HUFF_DECODE(s, br_state, actbl,
return FALSE, label2);
599 HUFF_DECODE(s, br_state, actbl,
return FALSE, label3);
#define BITREAD_STATE_VARS
unsigned int restarts_to_go
#define HUFF_EXTEND(x, s)
UINT8 look_sym[1<< HUFF_LOOKAHEAD]
jpeg_huff_decode(bitread_working_state *state, register bit_buf_type get_buffer, register int bits_left, d_derived_tbl *htbl, int min_bits)
boolean int c_derived_tbl ** pdtbl
int look_nbits[1<< HUFF_LOOKAHEAD]
const int jpeg_natural_order[]
struct jpeg_common_struct * j_common_ptr
huff_entropy_decoder * huff_entropy_ptr
#define ERREXIT(cinfo, code)
#define HUFF_DECODE(result, state, htbl, failaction, slowlabel)
jpeg_component_info * compptr
bitread_perm_state bitstate
register bit_buf_type register int d_derived_tbl int min_bits
c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS]
jpeg_make_d_derived_tbl(j_decompress_ptr cinfo, boolean isDC, int tblno, d_derived_tbl **pdtbl)
#define CHECK_BIT_BUFFER(state, nbits, action)
decode_mcu(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
struct jpeg_entropy_encoder pub
start_pass_huff_decoder(j_decompress_ptr cinfo)
register bit_buf_type register int int nbits
#define WARNMS(cinfo, code)
#define ERREXIT1(cinfo, code, p1)
#define BITREAD_SAVE_STATE(cinfop, permstate)
jpeg_fill_bit_buffer(bitread_working_state *state, register bit_buf_type get_buffer, register int bits_left, int nbits)
#define ASSIGN_STATE(dest, src)
struct jpeg_source_mgr * src
static const int extend_test[16]
#define D_MAX_BLOCKS_IN_MCU
process_restart(j_decompress_ptr cinfo)
static const int extend_offset[16]
int last_dc_val[MAX_COMPS_IN_SCAN]
#define BITREAD_LOAD_STATE(cinfop, permstate)
unsigned int restarts_to_go
boolean insufficient_data
register bit_buf_type get_buffer
const JOCTET * next_input_byte
c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]
register bit_buf_type register int bits_left
struct jpeg_entropy_decoder * entropy
#define MAX_COMPS_IN_SCAN
#define MEMZERO(target, size)
jinit_huff_decoder(j_decompress_ptr cinfo)