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]) 62 unsigned int restarts_to_go;
76 } huff_entropy_decoder;
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];
107 & entropy->dc_derived_tbls[dctbl]);
109 & entropy->ac_derived_tbls[actbl]);
111 entropy->saved.last_dc_val[ci] = 0;
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;
137 entropy->restarts_to_go = cinfo->restart_interval;
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++) {
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]) {
428 WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
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)) 449 static const int extend_test[16] =
450 { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
451 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
453 static const int extend_offset[16] =
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++)
484 entropy->saved.last_dc_val[ci] = 0;
487 entropy->restarts_to_go = cinfo->restart_interval;
494 if (cinfo->unread_marker == 0)
495 entropy->pub.insufficient_data =
FALSE;
525 if (cinfo->restart_interval) {
526 if (entropy->restarts_to_go == 0)
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);
624 entropy->restarts_to_go--;
642 SIZEOF(huff_entropy_decoder));
649 entropy->dc_derived_tbls[
i] = entropy->ac_derived_tbls[
i] =
NULL;
#define BITREAD_STATE_VARS
#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
huff_entropy_encoder * huff_entropy_ptr
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
register bit_buf_type register int d_derived_tbl int min_bits
jpeg_make_d_derived_tbl(j_decompress_ptr cinfo, boolean isDC, int tblno, d_derived_tbl **pdtbl)
GLdouble GLdouble GLdouble r
#define CHECK_BIT_BUFFER(state, nbits, action)
decode_mcu(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
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
if(!abbox) return FT_THROW(Invalid_Argument)
#define D_MAX_BLOCKS_IN_MCU
process_restart(j_decompress_ptr cinfo)
#define BITREAD_LOAD_STATE(cinfop, permstate)
boolean insufficient_data
register bit_buf_type get_buffer
const JOCTET * next_input_byte
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)