10 #define JPEG_INTERNALS 32 #ifndef NO_STRUCT_ASSIGN 33 #define ASSIGN_STATE(dest, src) ((dest) = (src)) 35 #if MAX_COMPS_IN_SCAN == 4 36 #define ASSIGN_STATE(dest, src) \ 37 ((dest).last_dc_val[0] = (src).last_dc_val[0], \ 38 (dest).last_dc_val[1] = (src).last_dc_val[1], \ 39 (dest).last_dc_val[2] = (src).last_dc_val[2], \ 40 (dest).last_dc_val[3] = (src).last_dc_val[3]) 81 int ci, blkn, dctbl, actbl;
88 if (cinfo->Ss != 0 || cinfo->Se !=
DCTSIZE2 - 1 || cinfo->Ah != 0 ||
90 WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
92 for (ci = 0; ci < cinfo->comps_in_scan; ci++)
94 compptr = cinfo->cur_comp_info[ci];
108 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++)
110 ci = cinfo->MCU_membership[blkn];
111 compptr = cinfo->cur_comp_info[ci];
113 entropy->dc_cur_tbls[blkn] =
115 entropy->ac_cur_tbls[blkn] =
120 entropy->dc_needed[blkn] =
TRUE;
126 entropy->dc_needed[blkn] = entropy->ac_needed[blkn] =
FALSE;
131 entropy->bitstate.bits_left = 0;
132 entropy->bitstate.get_buffer = 0;
133 entropy->
pub.insufficient_data =
FALSE;
152 int p, i, l, si, numsymbols;
155 unsigned int huffcode[257];
164 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
166 isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
167 if (htbl ==
nullptr)
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
170 if (*pdtbl ==
nullptr)
179 for (l = 1; l <= 16; l++)
181 i = (int)htbl->
bits[l];
182 if (i < 0 || p + i > 256)
183 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
184 while (i--) huffsize[
p++] = (char)l;
197 while (((
int)huffsize[
p]) == si)
199 huffcode[
p++] =
code;
207 ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
215 for (l = 1; l <= 16; l++)
245 for (i = 1; i <= (int)htbl->
bits[l]; i++,
p++)
269 for (i = 0; i < numsymbols; i++)
272 if (sym < 0 || sym > 15)
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
293 #define MIN_GET_BITS 15 295 #define MIN_GET_BITS (BIT_BUF_SIZE - 7) 305 const JOCTET* next_input_byte = state->next_input_byte;
306 size_t bytes_in_buffer = state->bytes_in_buffer;
320 if (bytes_in_buffer == 0)
322 if (!(*cinfo->
src->fill_input_buffer)(cinfo))
return FALSE;
342 if (bytes_in_buffer == 0)
344 if (!(*cinfo->
src->fill_input_buffer)(cinfo))
381 get_buffer = (get_buffer << 8) |
c;
392 if (nbits > bits_left)
401 WARNMS(cinfo, JWRN_HIT_MARKER);
411 state->next_input_byte = next_input_byte;
412 state->bytes_in_buffer = bytes_in_buffer;
413 state->get_buffer = get_buffer;
414 state->bits_left = bits_left;
441 while (
code > htbl->maxcode[l])
450 state->get_buffer = get_buffer;
451 state->bits_left = bits_left;
457 WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
461 return htbl->pub->huffval[(int)(
code + htbl->valoffset[l])];
471 #define HUFF_EXTEND(x, s) \ 472 ((x) < (1 << ((s)-1)) ? (x) + (((-1) << (s)) + 1) : (x)) 476 #define HUFF_EXTEND(x, s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x)) 479 {0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040,
480 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000};
483 {0, -1, -3, -7, -15, -31, -63, -127,
484 -255, -511, -1023, -2047, -4095, -8191, -16383, -32767};
501 cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
502 entropy->bitstate.bits_left = 0;
505 if (!(*cinfo->marker->read_restart_marker)(cinfo))
return FALSE;
508 for (ci = 0; ci < cinfo->comps_in_scan; ci++)
519 if (cinfo->unread_marker == 0) entropy->
pub.insufficient_data =
FALSE;
548 if (cinfo->restart_interval)
557 if (!entropy->
pub.insufficient_data)
565 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++)
583 if (entropy->dc_needed[blkn])
586 int ci = cinfo->MCU_membership[blkn];
587 s += state.last_dc_val[ci];
588 state.last_dc_val[ci] =
s;
594 if (entropy->ac_needed[blkn])
#define HUFF_EXTEND(x, s)
#define BITREAD_STATE_VARS
#define ASSIGN_STATE(dest, src)
unsigned int restarts_to_go
UINT8 look_sym[1<< HUFF_LOOKAHEAD]
static const int extend_test[16]
jpeg_huff_decode(bitread_working_state *state, bit_buf_type get_buffer, int bits_left, d_derived_tbl *htbl, int min_bits)
int look_nbits[1<< HUFF_LOOKAHEAD]
#define MAX_COMPS_IN_SCAN
jpeg_fill_bit_buffer(bitread_working_state *state, bit_buf_type get_buffer, int bits_left, int nbits)
static const int extend_offset[16]
#define D_MAX_BLOCKS_IN_MCU
const int jpeg_natural_order[]
start_pass_huff_decoder(j_decompress_ptr cinfo)
struct jpeg_common_struct * j_common_ptr
#define ERREXIT(cinfo, code)
#define HUFF_DECODE(result, state, htbl, failaction, slowlabel)
bitread_perm_state bitstate
c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS]
jinit_huff_decoder(j_decompress_ptr cinfo)
#define CHECK_BIT_BUFFER(state, nbits, action)
struct jpeg_entropy_encoder pub
#define WARNMS(cinfo, code)
huff_entropy_decoder * huff_entropy_ptr
#define ERREXIT1(cinfo, code, p1)
#define BITREAD_SAVE_STATE(cinfop, permstate)
GLdouble GLdouble GLdouble r
struct jpeg_source_mgr * src
decode_mcu(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
jpeg_make_d_derived_tbl(j_decompress_ptr cinfo, boolean isDC, int tblno, d_derived_tbl **pdtbl)
int last_dc_val[MAX_COMPS_IN_SCAN]
#define BITREAD_LOAD_STATE(cinfop, permstate)
unsigned int restarts_to_go
boolean insufficient_data
const JOCTET * next_input_byte
c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]
struct jpeg_entropy_decoder * entropy
process_restart(j_decompress_ptr cinfo)
#define MEMZERO(target, size)
jpeg_component_info * compptr