Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

645 lines
19 KiB

  1. #include "stdafx.h"
  2. #pragma hdrstop
  3. /*
  4. * jdphuff.c
  5. *
  6. * Copyright (C) 1995-1996, Thomas G. Lane.
  7. * This file is part of the Independent JPEG Group's software.
  8. * For conditions of distribution and use, see the accompanying README file.
  9. *
  10. * This file contains Huffman entropy decoding routines for progressive JPEG.
  11. *
  12. * Much of the complexity here has to do with supporting input suspension.
  13. * If the data source module demands suspension, we want to be able to back
  14. * up to the start of the current MCU. To do this, we copy state variables
  15. * into local working storage, and update them back to the permanent
  16. * storage only upon successful completion of an MCU.
  17. */
  18. #define JPEG_INTERNALS
  19. #include "jinclude.h"
  20. #include "jpeglib.h"
  21. #include "jdhuff.h" /* Declarations shared with jdhuff.c */
  22. #ifdef D_PROGRESSIVE_SUPPORTED
  23. /*
  24. * Expanded entropy decoder object for progressive Huffman decoding.
  25. *
  26. * The savable_state subrecord contains fields that change within an MCU,
  27. * but must not be updated permanently until we complete the MCU.
  28. */
  29. typedef struct {
  30. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  31. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  32. } savable_state;
  33. /* This macro is to work around compilers with missing or broken
  34. * structure assignment. You'll need to fix this code if you have
  35. * such a compiler and you change MAX_COMPS_IN_SCAN.
  36. */
  37. #ifndef NO_STRUCT_ASSIGN
  38. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  39. #else
  40. #if MAX_COMPS_IN_SCAN == 4
  41. #define ASSIGN_STATE(dest,src) \
  42. ((dest).EOBRUN = (src).EOBRUN, \
  43. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  44. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  45. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  46. (dest).last_dc_val[3] = (src).last_dc_val[3])
  47. #endif
  48. #endif
  49. typedef struct {
  50. struct jpeg_entropy_decoder pub; /* public fields */
  51. /* These fields are loaded into local variables at start of each MCU.
  52. * In case of suspension, we exit WITHOUT updating them.
  53. */
  54. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  55. savable_state saved; /* Other state at start of MCU */
  56. /* These fields are NOT loaded into local working state. */
  57. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  58. /* Pointers to derived tables (these workspaces have image lifespan) */
  59. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  60. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  61. } phuff_entropy_decoder;
  62. typedef phuff_entropy_decoder * phuff_entropy_ptr;
  63. /* Forward declarations */
  64. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  65. JBLOCKROW *MCU_data));
  66. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  67. JBLOCKROW *MCU_data));
  68. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  69. JBLOCKROW *MCU_data));
  70. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  71. JBLOCKROW *MCU_data));
  72. /*
  73. * Initialize for a Huffman-compressed scan.
  74. */
  75. METHODDEF(void)
  76. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  77. {
  78. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  79. boolean is_DC_band, bad;
  80. int ci, coefi, tbl;
  81. int *coef_bit_ptr;
  82. jpeg_component_info * compptr;
  83. is_DC_band = (cinfo->Ss == 0);
  84. /* Validate scan parameters */
  85. bad = FALSE;
  86. if (is_DC_band) {
  87. if (cinfo->Se != 0)
  88. bad = TRUE;
  89. } else {
  90. /* need not check Ss/Se < 0 since they came from unsigned bytes */
  91. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  92. bad = TRUE;
  93. /* AC scans may have only one component */
  94. if (cinfo->comps_in_scan != 1)
  95. bad = TRUE;
  96. }
  97. if (cinfo->Ah != 0) {
  98. /* Successive approximation refinement scan: must have Al = Ah-1. */
  99. if (cinfo->Al != cinfo->Ah-1)
  100. bad = TRUE;
  101. }
  102. if (cinfo->Al > 13) /* need not check for < 0 */
  103. bad = TRUE;
  104. if (bad)
  105. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  106. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  107. /* Update progression status, and verify that scan order is legal.
  108. * Note that inter-scan inconsistencies are treated as warnings
  109. * not fatal errors ... not clear if this is right way to behave.
  110. */
  111. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  112. int cindex = cinfo->cur_comp_info[ci]->component_index;
  113. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  114. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  115. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  116. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  117. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  118. if (cinfo->Ah != expected)
  119. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  120. coef_bit_ptr[coefi] = cinfo->Al;
  121. }
  122. }
  123. /* Select MCU decoding routine */
  124. if (cinfo->Ah == 0) {
  125. if (is_DC_band)
  126. entropy->pub.decode_mcu = decode_mcu_DC_first;
  127. else
  128. entropy->pub.decode_mcu = decode_mcu_AC_first;
  129. } else {
  130. if (is_DC_band)
  131. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  132. else
  133. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  134. }
  135. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  136. compptr = cinfo->cur_comp_info[ci];
  137. /* Make sure requested tables are present, and compute derived tables.
  138. * We may build same derived table more than once, but it's not expensive.
  139. */
  140. if (is_DC_band) {
  141. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  142. tbl = compptr->dc_tbl_no;
  143. if (tbl < 0 || tbl >= NUM_HUFF_TBLS ||
  144. cinfo->dc_huff_tbl_ptrs[tbl] == NULL)
  145. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  146. jpeg_make_d_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[tbl],
  147. & entropy->derived_tbls[tbl]);
  148. }
  149. } else {
  150. tbl = compptr->ac_tbl_no;
  151. if (tbl < 0 || tbl >= NUM_HUFF_TBLS ||
  152. cinfo->ac_huff_tbl_ptrs[tbl] == NULL)
  153. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  154. jpeg_make_d_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[tbl],
  155. & entropy->derived_tbls[tbl]);
  156. /* remember the single active table */
  157. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  158. }
  159. /* Initialize DC predictions to 0 */
  160. entropy->saved.last_dc_val[ci] = 0;
  161. }
  162. /* Initialize bitread state variables */
  163. entropy->bitstate.bits_left = 0;
  164. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  165. entropy->bitstate.printed_eod = FALSE;
  166. /* Initialize private state variables */
  167. entropy->saved.EOBRUN = 0;
  168. /* Initialize restart counter */
  169. entropy->restarts_to_go = cinfo->restart_interval;
  170. }
  171. /*
  172. * Figure F.12: extend sign bit.
  173. * On some machines, a shift and add will be faster than a table lookup.
  174. */
  175. #ifdef AVOID_TABLES
  176. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  177. #else
  178. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  179. static const int extend_test[16] = /* entry n is 2**(n-1) */
  180. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  181. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  182. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  183. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  184. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  185. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  186. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  187. #endif /* AVOID_TABLES */
  188. /*
  189. * Check for a restart marker & resynchronize decoder.
  190. * Returns FALSE if must suspend.
  191. */
  192. LOCAL(boolean)
  193. process_restart (j_decompress_ptr cinfo)
  194. {
  195. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  196. int ci;
  197. /* Throw away any unused bits remaining in bit buffer; */
  198. /* include any full bytes in next_marker's count of discarded bytes */
  199. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  200. entropy->bitstate.bits_left = 0;
  201. /* Advance past the RSTn marker */
  202. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  203. return FALSE;
  204. /* Re-initialize DC predictions to 0 */
  205. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  206. entropy->saved.last_dc_val[ci] = 0;
  207. /* Re-init EOB run count, too */
  208. entropy->saved.EOBRUN = 0;
  209. /* Reset restart counter */
  210. entropy->restarts_to_go = cinfo->restart_interval;
  211. /* Next segment can get another out-of-data warning */
  212. entropy->bitstate.printed_eod = FALSE;
  213. return TRUE;
  214. }
  215. /*
  216. * Huffman MCU decoding.
  217. * Each of these routines decodes and returns one MCU's worth of
  218. * Huffman-compressed coefficients.
  219. * The coefficients are reordered from zigzag order into natural array order,
  220. * but are not dequantized.
  221. *
  222. * The i'th block of the MCU is stored into the block pointed to by
  223. * MCU_data[i]. WE ASSUME THIS AREA IS INITIALLY ZEROED BY THE CALLER.
  224. *
  225. * We return FALSE if data source requested suspension. In that case no
  226. * changes have been made to permanent state. (Exception: some output
  227. * coefficients may already have been assigned. This is harmless for
  228. * spectral selection, since we'll just re-assign them on the next call.
  229. * Successive approximation AC refinement has to be more careful, however.)
  230. */
  231. /*
  232. * MCU decoding for DC initial scan (either spectral selection,
  233. * or first pass of successive approximation).
  234. */
  235. METHODDEF(boolean)
  236. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  237. {
  238. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  239. int Al = cinfo->Al;
  240. register int s, r;
  241. int blkn, ci;
  242. JBLOCKROW block;
  243. BITREAD_STATE_VARS;
  244. savable_state state;
  245. d_derived_tbl * tbl;
  246. jpeg_component_info * compptr;
  247. /* Process restart marker if needed; may have to suspend */
  248. if (cinfo->restart_interval) {
  249. if (entropy->restarts_to_go == 0)
  250. if (! process_restart(cinfo))
  251. return FALSE;
  252. }
  253. /* Load up working state */
  254. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  255. ASSIGN_STATE(state, entropy->saved);
  256. /* Outer loop handles each block in the MCU */
  257. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  258. block = MCU_data[blkn];
  259. ci = cinfo->MCU_membership[blkn];
  260. compptr = cinfo->cur_comp_info[ci];
  261. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  262. /* Decode a single block's worth of coefficients */
  263. /* Section F.2.2.1: decode the DC coefficient difference */
  264. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  265. if (s) {
  266. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  267. r = GET_BITS(s);
  268. s = HUFF_EXTEND(r, s);
  269. }
  270. /* Convert DC difference to actual value, update last_dc_val */
  271. s += state.last_dc_val[ci];
  272. state.last_dc_val[ci] = s;
  273. /* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */
  274. (*block)[0] = (JCOEF) (s << Al);
  275. }
  276. /* Completed MCU, so update state */
  277. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  278. ASSIGN_STATE(entropy->saved, state);
  279. /* Account for restart interval (no-op if not using restarts) */
  280. entropy->restarts_to_go--;
  281. return TRUE;
  282. }
  283. /*
  284. * MCU decoding for AC initial scan (either spectral selection,
  285. * or first pass of successive approximation).
  286. */
  287. METHODDEF(boolean)
  288. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  289. {
  290. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  291. int Se = cinfo->Se;
  292. int Al = cinfo->Al;
  293. register int s, k, r;
  294. unsigned int EOBRUN;
  295. JBLOCKROW block;
  296. BITREAD_STATE_VARS;
  297. d_derived_tbl * tbl;
  298. /* Process restart marker if needed; may have to suspend */
  299. if (cinfo->restart_interval) {
  300. if (entropy->restarts_to_go == 0)
  301. if (! process_restart(cinfo))
  302. return FALSE;
  303. }
  304. /* Load up working state.
  305. * We can avoid loading/saving bitread state if in an EOB run.
  306. */
  307. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we care about */
  308. /* There is always only one block per MCU */
  309. if (EOBRUN > 0) /* if it's a band of zeroes... */
  310. EOBRUN--; /* ...process it now (we do nothing) */
  311. else {
  312. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  313. block = MCU_data[0];
  314. tbl = entropy->ac_derived_tbl;
  315. for (k = cinfo->Ss; k <= Se; k++) {
  316. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  317. r = s >> 4;
  318. s &= 15;
  319. if (s) {
  320. k += r;
  321. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  322. r = GET_BITS(s);
  323. s = HUFF_EXTEND(r, s);
  324. /* Scale and output coefficient in natural (dezigzagged) order */
  325. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  326. } else {
  327. if (r == 15) { /* ZRL */
  328. k += 15; /* skip 15 zeroes in band */
  329. } else { /* EOBr, run length is 2^r + appended bits */
  330. EOBRUN = 1 << r;
  331. if (r) { /* EOBr, r > 0 */
  332. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  333. r = GET_BITS(r);
  334. EOBRUN += r;
  335. }
  336. EOBRUN--; /* this band is processed at this moment */
  337. break; /* force end-of-band */
  338. }
  339. }
  340. }
  341. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  342. }
  343. /* Completed MCU, so update state */
  344. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we care about */
  345. /* Account for restart interval (no-op if not using restarts) */
  346. entropy->restarts_to_go--;
  347. return TRUE;
  348. }
  349. /*
  350. * MCU decoding for DC successive approximation refinement scan.
  351. * Note: we assume such scans can be multi-component, although the spec
  352. * is not very clear on the point.
  353. */
  354. METHODDEF(boolean)
  355. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  356. {
  357. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  358. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  359. int blkn;
  360. JBLOCKROW block;
  361. BITREAD_STATE_VARS;
  362. /* Process restart marker if needed; may have to suspend */
  363. if (cinfo->restart_interval) {
  364. if (entropy->restarts_to_go == 0)
  365. if (! process_restart(cinfo))
  366. return FALSE;
  367. }
  368. /* Load up working state */
  369. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  370. /* Outer loop handles each block in the MCU */
  371. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  372. block = MCU_data[blkn];
  373. /* Encoded data is simply the next bit of the two's-complement DC value */
  374. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  375. if (GET_BITS(1))
  376. (*block)[0] |= p1;
  377. /* Note: since we use |=, repeating the assignment later is safe */
  378. }
  379. /* Completed MCU, so update state */
  380. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  381. /* Account for restart interval (no-op if not using restarts) */
  382. entropy->restarts_to_go--;
  383. return TRUE;
  384. }
  385. /*
  386. * MCU decoding for AC successive approximation refinement scan.
  387. */
  388. METHODDEF(boolean)
  389. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  390. {
  391. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  392. int Se = cinfo->Se;
  393. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  394. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  395. register int s, k, r;
  396. unsigned int EOBRUN;
  397. JBLOCKROW block;
  398. JCOEFPTR thiscoef;
  399. BITREAD_STATE_VARS;
  400. d_derived_tbl * tbl;
  401. int num_newnz;
  402. int newnz_pos[DCTSIZE2];
  403. /* Process restart marker if needed; may have to suspend */
  404. if (cinfo->restart_interval) {
  405. if (entropy->restarts_to_go == 0)
  406. if (! process_restart(cinfo))
  407. return FALSE;
  408. }
  409. /* Load up working state */
  410. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  411. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we care about */
  412. /* There is always only one block per MCU */
  413. block = MCU_data[0];
  414. tbl = entropy->ac_derived_tbl;
  415. /* If we are forced to suspend, we must undo the assignments to any newly
  416. * nonzero coefficients in the block, because otherwise we'd get confused
  417. * next time about which coefficients were already nonzero.
  418. * But we need not undo addition of bits to already-nonzero coefficients;
  419. * instead, we can test the current bit position to see if we already did it.
  420. */
  421. num_newnz = 0;
  422. /* initialize coefficient loop counter to start of band */
  423. k = cinfo->Ss;
  424. if (EOBRUN == 0) {
  425. for (; k <= Se; k++) {
  426. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  427. r = s >> 4;
  428. s &= 15;
  429. if (s) {
  430. if (s != 1) /* size of new coef should always be 1 */
  431. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  432. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  433. if (GET_BITS(1))
  434. s = p1; /* newly nonzero coef is positive */
  435. else
  436. s = m1; /* newly nonzero coef is negative */
  437. } else {
  438. if (r != 15) {
  439. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  440. if (r) {
  441. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  442. r = GET_BITS(r);
  443. EOBRUN += r;
  444. }
  445. break; /* rest of block is handled by EOB logic */
  446. }
  447. /* note s = 0 for processing ZRL */
  448. }
  449. /* Advance over already-nonzero coefs and r still-zero coefs,
  450. * appending correction bits to the nonzeroes. A correction bit is 1
  451. * if the absolute value of the coefficient must be increased.
  452. */
  453. do {
  454. thiscoef = *block + jpeg_natural_order[k];
  455. if (*thiscoef != 0) {
  456. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  457. if (GET_BITS(1)) {
  458. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  459. if (*thiscoef >= 0)
  460. *thiscoef += (JCOEF)p1;
  461. else
  462. *thiscoef += (JCOEF)m1;
  463. }
  464. }
  465. } else {
  466. if (--r < 0)
  467. break; /* reached target zero coefficient */
  468. }
  469. k++;
  470. } while (k <= Se);
  471. if (s) {
  472. int pos = jpeg_natural_order[k];
  473. /* Output newly nonzero coefficient */
  474. (*block)[pos] = (JCOEF) s;
  475. /* Remember its position in case we have to suspend */
  476. newnz_pos[num_newnz++] = pos;
  477. }
  478. }
  479. }
  480. if (EOBRUN > 0) {
  481. /* Scan any remaining coefficient positions after the end-of-band
  482. * (the last newly nonzero coefficient, if any). Append a correction
  483. * bit to each already-nonzero coefficient. A correction bit is 1
  484. * if the absolute value of the coefficient must be increased.
  485. */
  486. for (; k <= Se; k++) {
  487. thiscoef = *block + jpeg_natural_order[k];
  488. if (*thiscoef != 0) {
  489. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  490. if (GET_BITS(1)) {
  491. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  492. if (*thiscoef >= 0)
  493. *thiscoef += (JCOEF)p1;
  494. else
  495. *thiscoef += (JCOEF)m1;
  496. }
  497. }
  498. }
  499. }
  500. /* Count one block completed in EOB run */
  501. EOBRUN--;
  502. }
  503. /* Completed MCU, so update state */
  504. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  505. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we care about */
  506. /* Account for restart interval (no-op if not using restarts) */
  507. entropy->restarts_to_go--;
  508. return TRUE;
  509. undoit:
  510. /* Re-zero any output coefficients that we made newly nonzero */
  511. while (num_newnz > 0)
  512. (*block)[newnz_pos[--num_newnz]] = 0;
  513. return FALSE;
  514. }
  515. /*
  516. * Module initialization routine for progressive Huffman entropy decoding.
  517. */
  518. GLOBAL(void)
  519. jinit_phuff_decoder (j_decompress_ptr cinfo)
  520. {
  521. phuff_entropy_ptr entropy;
  522. int *coef_bit_ptr;
  523. int ci, i;
  524. entropy = (phuff_entropy_ptr)
  525. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  526. SIZEOF(phuff_entropy_decoder));
  527. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  528. entropy->pub.start_pass = start_pass_phuff_decoder;
  529. /* Mark derived tables unallocated */
  530. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  531. entropy->derived_tbls[i] = NULL;
  532. }
  533. /* Create progression status table */
  534. cinfo->coef_bits = (int (*)[DCTSIZE2])
  535. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  536. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  537. coef_bit_ptr = & cinfo->coef_bits[0][0];
  538. for (ci = 0; ci < cinfo->num_components; ci++)
  539. for (i = 0; i < DCTSIZE2; i++)
  540. *coef_bit_ptr++ = -1;
  541. }
  542. #endif /* D_PROGRESSIVE_SUPPORTED */