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];
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))
373 WARNMS(cinfo, JWRN_HIT_MARKER);
383 state->next_input_byte = next_input_byte;
384 state->bytes_in_buffer = bytes_in_buffer;
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))
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]) {