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]) 66 unsigned int restarts_to_go;
72 } phuff_entropy_decoder;
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) {
170 & entropy->derived_tbls[tbl]);
175 & entropy->derived_tbls[tbl]);
177 entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
180 entropy->saved.last_dc_val[ci] = 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)) 209 static const int extend_test[16] =
210 { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
211 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
213 static const int extend_offset[16] =
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++)
244 entropy->saved.last_dc_val[ci] = 0;
246 entropy->saved.EOBRUN = 0;
249 entropy->restarts_to_go = cinfo->restart_interval;
256 if (cinfo->unread_marker == 0)
257 entropy->pub.insufficient_data =
FALSE;
299 if (cinfo->restart_interval) {
300 if (entropy->restarts_to_go == 0)
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);
345 entropy->restarts_to_go--;
362 register int s, k,
r;
369 if (cinfo->restart_interval) {
370 if (entropy->restarts_to_go == 0)
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;
429 entropy->restarts_to_go--;
445 int p1 = 1 << cinfo->Al;
451 if (cinfo->restart_interval) {
452 if (entropy->restarts_to_go == 0)
466 for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
467 block = MCU_data[blkn];
480 entropy->restarts_to_go--;
495 int p1 = 1 << cinfo->Al;
496 int m1 = (-1) << cinfo->Al;
497 register int s, k,
r;
507 if (cinfo->restart_interval) {
508 if (entropy->restarts_to_go == 0)
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;
623 entropy->restarts_to_go--;
629 while (num_newnz > 0)
630 (*block)[newnz_pos[--num_newnz]] = 0;
649 SIZEOF(phuff_entropy_decoder));
651 entropy->pub.start_pass = start_pass_phuff_decoder;
655 entropy->derived_tbls[
i] =
NULL;
662 coef_bit_ptr = & cinfo->coef_bits[0][0];
663 for (ci = 0; ci < cinfo->num_components; ci++)
665 *coef_bit_ptr++ = -1;
#define BITREAD_STATE_VARS
decode_mcu_DC_refine(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]
const int jpeg_natural_order[]
struct jpeg_common_struct * j_common_ptr
decode_mcu_DC_first(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
#define HUFF_DECODE(result, state, htbl, failaction, slowlabel)
#define ASSIGN_STATE(dest, src)
jpeg_component_info * compptr
#define WARNMS2(cinfo, code, p1, p2)
#define ERREXIT4(cinfo, code, p1, p2, p3, p4)
process_restart(j_decompress_ptr cinfo)
jpeg_make_d_derived_tbl(j_decompress_ptr cinfo, boolean isDC, int tblno, d_derived_tbl **pdtbl)
decode_mcu_AC_first(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
#define HUFF_EXTEND(x, s)
unsigned int restart_interval
GLdouble GLdouble GLdouble r
phuff_entropy_decoder * phuff_entropy_ptr
#define CHECK_BIT_BUFFER(state, nbits, action)
phuff_entropy_encoder * phuff_entropy_ptr
#define WARNMS(cinfo, code)
jinit_phuff_decoder(j_decompress_ptr cinfo)
#define BITREAD_SAVE_STATE(cinfop, permstate)
if(!abbox) return FT_THROW(Invalid_Argument)
decode_mcu_AC_refine(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
#define BITREAD_LOAD_STATE(cinfop, permstate)
int(* coef_bits)[DCTSIZE2]
struct jpeg_entropy_decoder * entropy
#define MAX_COMPS_IN_SCAN