17 #define JPEG_INTERNALS
23 #ifdef D_PROGRESSIVE_SUPPORTED
42 #ifndef NO_STRUCT_ASSIGN
43 #define ASSIGN_STATE(dest,src) ((dest) = (src))
45 #if MAX_COMPS_IN_SCAN == 4
46 #define ASSIGN_STATE(dest,src) \
47 ((dest).EOBRUN = (src).EOBRUN, \
48 (dest).last_dc_val[0] = (src).last_dc_val[0], \
49 (dest).last_dc_val[1] = (src).last_dc_val[1], \
50 (dest).last_dc_val[2] = (src).last_dc_val[2], \
51 (dest).last_dc_val[3] = (src).last_dc_val[3])
95 boolean is_DC_band, bad;
100 is_DC_band = (cinfo->
Ss == 0);
115 if (cinfo->
Ah != 0) {
117 if (cinfo->
Al != cinfo->
Ah-1)
129 ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
130 cinfo->
Ss, cinfo->
Se, cinfo->
Ah, cinfo->
Al);
137 coef_bit_ptr = & cinfo->
coef_bits[cindex][0];
138 if (!is_DC_band && coef_bit_ptr[0] < 0)
139 WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
140 for (coefi = cinfo->
Ss; coefi <= cinfo->Se; coefi++) {
141 int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
142 if (cinfo->
Ah != expected)
143 WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
144 coef_bit_ptr[coefi] = cinfo->
Al;
149 if (cinfo->
Ah == 0) {
167 if (cinfo->
Ah == 0) {
184 entropy->bitstate.bits_left = 0;
185 entropy->bitstate.get_buffer = 0;
186 entropy->
pub.insufficient_data =
FALSE;
189 entropy->saved.
EOBRUN = 0;
203 #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
207 #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
210 { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
211 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
214 { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
215 ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
216 ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
217 ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
235 cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
236 entropy->bitstate.bits_left = 0;
239 if (! (*cinfo->marker->read_restart_marker) (cinfo))
243 for (ci = 0; ci < cinfo->comps_in_scan; ci++)
246 entropy->saved.
EOBRUN = 0;
256 if (cinfo->unread_marker == 0)
257 entropy->
pub.insufficient_data =
FALSE;
299 if (cinfo->restart_interval) {
308 if (! entropy->
pub.insufficient_data) {
316 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
317 block = MCU_data[blkn];
318 ci = cinfo->MCU_membership[blkn];
319 compptr = cinfo->cur_comp_info[ci];
333 s += state.last_dc_val[ci];
334 state.last_dc_val[ci] = s;
336 (*block)[0] = (
JCOEF) (s << Al);
362 register int s, k, r;
369 if (cinfo->restart_interval) {
378 if (! entropy->
pub.insufficient_data) {
383 EOBRUN = entropy->saved.
EOBRUN;
392 tbl = entropy->ac_derived_tbl;
394 for (k = cinfo->Ss; k <= Se; k++) {
425 entropy->saved.
EOBRUN = EOBRUN;
445 int p1 = 1 << cinfo->Al;
451 if (cinfo->restart_interval) {
466 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
467 block = MCU_data[blkn];
495 int p1 = 1 << cinfo->Al;
496 int m1 = (-1) << cinfo->Al;
497 register int s, k, r;
507 if (cinfo->restart_interval) {
515 if (! entropy->
pub.insufficient_data) {
519 EOBRUN = entropy->saved.
EOBRUN;
523 tbl = entropy->ac_derived_tbl;
537 for (; k <= Se; k++) {
538 HUFF_DECODE(s, br_state, tbl,
goto undoit, label3);
543 WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
567 if (*thiscoef != 0) {
570 if ((*thiscoef & p1) == 0) {
586 (*block)[pos] = (
JCOEF) s;
588 newnz_pos[num_newnz++] = pos;
599 for (; k <= Se; k++) {
601 if (*thiscoef != 0) {
604 if ((*thiscoef & p1) == 0) {
619 entropy->saved.
EOBRUN = EOBRUN;
629 while (num_newnz > 0)
630 (*block)[newnz_pos[--num_newnz]] = 0;
651 entropy->
pub.start_pass = start_pass_phuff_decoder;
662 coef_bit_ptr = & cinfo->coef_bits[0][0];
663 for (ci = 0; ci < cinfo->num_components; ci++)
665 *coef_bit_ptr++ = -1;