jdhuff.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /*
  2. * jdhuff.c
  3. *
  4. * Copyright (C) 1991-1995, Thomas G. Lane.
  5. * This file is part of the Independent JPEG Group's software.
  6. * For conditions of distribution and use, see the accompanying README file.
  7. *
  8. * This file contains Huffman entropy decoding routines.
  9. *
  10. * Much of the complexity here has to do with supporting input suspension.
  11. * If the data source module demands suspension, we want to be able to back
  12. * up to the start of the current MCU. To do this, we copy state variables
  13. * into local working storage, and update them back to the permanent
  14. * storage only upon successful completion of an MCU.
  15. */
  16. #define JPEG_INTERNALS
  17. #include "jinclude.h"
  18. #include "jpeglib.h"
  19. #include "jdhuff.h" /* Declarations shared with jdphuff.c */
  20. /*
  21. * Expanded entropy decoder object for Huffman decoding.
  22. *
  23. * The savable_state subrecord contains fields that change within an MCU,
  24. * but must not be updated permanently until we complete the MCU.
  25. */
  26. typedef struct {
  27. int last_dc_val[MAX_COMPS_IN_SCAN];/* last DC coef for each component */
  28. } savable_state;
  29. /* This macro is to work around compilers with missing or broken
  30. * structure assignment. You'll need to fix this code if you have
  31. * such a compiler and you change MAX_COMPS_IN_SCAN.
  32. */
  33. #ifndef NO_STRUCT_ASSIGN
  34. #define ASSIGN_STATE( dest, src ) ( ( dest ) = ( src ) )
  35. #else
  36. #if MAX_COMPS_IN_SCAN == 4
  37. #define ASSIGN_STATE( dest, src ) \
  38. ( ( dest ).last_dc_val[0] = ( src ).last_dc_val[0], \
  39. ( dest ).last_dc_val[1] = ( src ).last_dc_val[1], \
  40. ( dest ).last_dc_val[2] = ( src ).last_dc_val[2], \
  41. ( dest ).last_dc_val[3] = ( src ).last_dc_val[3] )
  42. #endif
  43. #endif
  44. typedef struct {
  45. struct jpeg_entropy_decoder pub;/* public fields */
  46. /* These fields are loaded into local variables at start of each MCU.
  47. * In case of suspension, we exit WITHOUT updating them.
  48. */
  49. bitread_perm_state bitstate;/* Bit buffer at start of MCU */
  50. savable_state saved; /* Other state at start of MCU */
  51. /* These fields are NOT loaded into local working state. */
  52. unsigned int restarts_to_go;/* MCUs left in this restart interval */
  53. /* Pointers to derived tables (these workspaces have image lifespan) */
  54. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  55. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  56. } huff_entropy_decoder;
  57. typedef huff_entropy_decoder * huff_entropy_ptr;
  58. /*
  59. * Initialize for a Huffman-compressed scan.
  60. */
  61. METHODDEF void
  62. start_pass_huff_decoder( j_decompress_ptr cinfo ) {
  63. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  64. int ci, dctbl, actbl;
  65. jpeg_component_info * compptr;
  66. /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
  67. * This ought to be an error condition, but we make it a warning because
  68. * there are some baseline files out there with all zeroes in these bytes.
  69. */
  70. if ( ( cinfo->Ss != 0 ) || ( cinfo->Se != DCTSIZE2 - 1 ) ||
  71. ( cinfo->Ah != 0 ) || ( cinfo->Al != 0 ) ) {
  72. WARNMS( cinfo, JWRN_NOT_SEQUENTIAL );
  73. }
  74. for ( ci = 0; ci < cinfo->comps_in_scan; ci++ ) {
  75. compptr = cinfo->cur_comp_info[ci];
  76. dctbl = compptr->dc_tbl_no;
  77. actbl = compptr->ac_tbl_no;
  78. /* Make sure requested tables are present */
  79. if ( ( dctbl < 0 ) || ( dctbl >= NUM_HUFF_TBLS ) ||
  80. ( cinfo->dc_huff_tbl_ptrs[dctbl] == NULL ) ) {
  81. ERREXIT1( cinfo, JERR_NO_HUFF_TABLE, dctbl );
  82. }
  83. if ( ( actbl < 0 ) || ( actbl >= NUM_HUFF_TBLS ) ||
  84. ( cinfo->ac_huff_tbl_ptrs[actbl] == NULL ) ) {
  85. ERREXIT1( cinfo, JERR_NO_HUFF_TABLE, actbl );
  86. }
  87. /* Compute derived values for Huffman tables */
  88. /* We may do this more than once for a table, but it's not expensive */
  89. jpeg_make_d_derived_tbl( cinfo, cinfo->dc_huff_tbl_ptrs[dctbl],
  90. &entropy->dc_derived_tbls[dctbl] );
  91. jpeg_make_d_derived_tbl( cinfo, cinfo->ac_huff_tbl_ptrs[actbl],
  92. &entropy->ac_derived_tbls[actbl] );
  93. /* Initialize DC predictions to 0 */
  94. entropy->saved.last_dc_val[ci] = 0;
  95. }
  96. /* Initialize bitread state variables */
  97. entropy->bitstate.bits_left = 0;
  98. entropy->bitstate.get_buffer = 0;/* unnecessary, but keeps Purify quiet */
  99. entropy->bitstate.printed_eod = FALSE;
  100. /* Initialize restart counter */
  101. entropy->restarts_to_go = cinfo->restart_interval;
  102. }
  103. /*
  104. * Compute the derived values for a Huffman table.
  105. * Note this is also used by jdphuff.c.
  106. */
  107. GLOBAL void
  108. jpeg_make_d_derived_tbl( j_decompress_ptr cinfo, JHUFF_TBL * htbl,
  109. d_derived_tbl ** pdtbl ) {
  110. d_derived_tbl * dtbl;
  111. int p, i, l, si;
  112. int lookbits, ctr;
  113. char huffsize[257];
  114. unsigned int huffcode[257];
  115. unsigned int code;
  116. /* Allocate a workspace if we haven't already done so. */
  117. if ( *pdtbl == NULL ) {
  118. *pdtbl = (d_derived_tbl *)
  119. ( *cinfo->mem->alloc_small )( (j_common_ptr) cinfo, JPOOL_IMAGE,
  120. SIZEOF( d_derived_tbl ) );
  121. }
  122. dtbl = *pdtbl;
  123. dtbl->pub = htbl; /* fill in back link */
  124. /* Figure C.1: make table of Huffman code length for each symbol */
  125. /* Note that this is in code-length order. */
  126. p = 0;
  127. for ( l = 1; l <= 16; l++ ) {
  128. for ( i = 1; i <= (int) htbl->bits[l]; i++ ) {
  129. huffsize[p++] = (char) l;
  130. }
  131. }
  132. huffsize[p] = 0;
  133. /* Figure C.2: generate the codes themselves */
  134. /* Note that this is in code-length order. */
  135. code = 0;
  136. si = huffsize[0];
  137. p = 0;
  138. while ( huffsize[p] ) {
  139. while ( ( (int) huffsize[p] ) == si ) {
  140. huffcode[p++] = code;
  141. code++;
  142. }
  143. code <<= 1;
  144. si++;
  145. }
  146. /* Figure F.15: generate decoding tables for bit-sequential decoding */
  147. p = 0;
  148. for ( l = 1; l <= 16; l++ ) {
  149. if ( htbl->bits[l] ) {
  150. dtbl->valptr[l] = p;/* huffval[] index of 1st symbol of code length l */
  151. dtbl->mincode[l] = huffcode[p];/* minimum code of length l */
  152. p += htbl->bits[l];
  153. dtbl->maxcode[l] = huffcode[p - 1];/* maximum code of length l */
  154. } else {
  155. dtbl->maxcode[l] = -1;/* -1 if no codes of this length */
  156. }
  157. }
  158. dtbl->maxcode[17] = 0xFFFFFL;/* ensures jpeg_huff_decode terminates */
  159. /* Compute lookahead tables to speed up decoding.
  160. * First we set all the table entries to 0, indicating "too long";
  161. * then we iterate through the Huffman codes that are short enough and
  162. * fill in all the entries that correspond to bit sequences starting
  163. * with that code.
  164. */
  165. MEMZERO( dtbl->look_nbits, SIZEOF( dtbl->look_nbits ) );
  166. p = 0;
  167. for ( l = 1; l <= HUFF_LOOKAHEAD; l++ ) {
  168. for ( i = 1; i <= (int) htbl->bits[l]; i++, p++ ) {
  169. /* l = current code's length, p = its index in huffcode[] & huffval[]. */
  170. /* Generate left-justified code followed by all possible bit sequences */
  171. lookbits = huffcode[p] << ( HUFF_LOOKAHEAD - l );
  172. for ( ctr = 1 << ( HUFF_LOOKAHEAD - l ); ctr > 0; ctr-- ) {
  173. dtbl->look_nbits[lookbits] = l;
  174. dtbl->look_sym[lookbits] = htbl->huffval[p];
  175. lookbits++;
  176. }
  177. }
  178. }
  179. }
  180. /*
  181. * Out-of-line code for bit fetching (shared with jdphuff.c).
  182. * See jdhuff.h for info about usage.
  183. * Note: current values of get_buffer and bits_left are passed as parameters,
  184. * but are returned in the corresponding fields of the state struct.
  185. *
  186. * On most machines MIN_GET_BITS should be 25 to allow the full 32-bit width
  187. * of get_buffer to be used. (On machines with wider words, an even larger
  188. * buffer could be used.) However, on some machines 32-bit shifts are
  189. * quite slow and take time proportional to the number of places shifted.
  190. * (This is true with most PC compilers, for instance.) In this case it may
  191. * be a win to set MIN_GET_BITS to the minimum value of 15. This reduces the
  192. * average shift distance at the cost of more calls to jpeg_fill_bit_buffer.
  193. */
  194. #ifdef SLOW_SHIFT_32
  195. #define MIN_GET_BITS 15 /* minimum allowable value */
  196. #else
  197. #define MIN_GET_BITS ( BIT_BUF_SIZE - 7 )
  198. #endif
  199. GLOBAL boolean
  200. jpeg_fill_bit_buffer( bitread_working_state * state,
  201. register bit_buf_type get_buffer, register int bits_left,
  202. int nbits ) {
  203. /* Load up the bit buffer to a depth of at least nbits */
  204. /* Copy heavily used state fields into locals (hopefully registers) */
  205. register const JOCTET * next_input_byte = state->next_input_byte;
  206. register size_t bytes_in_buffer = state->bytes_in_buffer;
  207. register int c;
  208. /* Attempt to load at least MIN_GET_BITS bits into get_buffer. */
  209. /* (It is assumed that no request will be for more than that many bits.) */
  210. while ( bits_left < MIN_GET_BITS ) {
  211. /* Attempt to read a byte */
  212. if ( state->unread_marker != 0 ) {
  213. goto no_more_data;
  214. } /* can't advance past a marker */
  215. if ( bytes_in_buffer == 0 ) {
  216. if ( !( *state->cinfo->src->fill_input_buffer )( state->cinfo ) ) {
  217. return FALSE;
  218. }
  219. next_input_byte = state->cinfo->src->next_input_byte;
  220. bytes_in_buffer = state->cinfo->src->bytes_in_buffer;
  221. }
  222. bytes_in_buffer--;
  223. c = GETJOCTET( *next_input_byte++ );
  224. /* If it's 0xFF, check and discard stuffed zero byte */
  225. if ( c == 0xFF ) {
  226. do {
  227. if ( bytes_in_buffer == 0 ) {
  228. if ( !( *state->cinfo->src->fill_input_buffer )( state->cinfo ) ) {
  229. return FALSE;
  230. }
  231. next_input_byte = state->cinfo->src->next_input_byte;
  232. bytes_in_buffer = state->cinfo->src->bytes_in_buffer;
  233. }
  234. bytes_in_buffer--;
  235. c = GETJOCTET( *next_input_byte++ );
  236. } while ( c == 0xFF );
  237. if ( c == 0 ) {
  238. /* Found FF/00, which represents an FF data byte */
  239. c = 0xFF;
  240. } else {
  241. /* Oops, it's actually a marker indicating end of compressed data. */
  242. /* Better put it back for use later */
  243. state->unread_marker = c;
  244. no_more_data:
  245. /* There should be enough bits still left in the data segment; */
  246. /* if so, just break out of the outer while loop. */
  247. if ( bits_left >= nbits ) {
  248. break;
  249. }
  250. /* Uh-oh. Report corrupted data to user and stuff zeroes into
  251. * the data stream, so that we can produce some kind of image.
  252. * Note that this code will be repeated for each byte demanded
  253. * for the rest of the segment. We use a nonvolatile flag to ensure
  254. * that only one warning message appears.
  255. */
  256. if ( ! * ( state->printed_eod_ptr ) ) {
  257. WARNMS( state->cinfo, JWRN_HIT_MARKER );
  258. *( state->printed_eod_ptr ) = TRUE;
  259. }
  260. c = 0;/* insert a zero byte into bit buffer */
  261. }
  262. }
  263. /* OK, load c into get_buffer */
  264. get_buffer = ( get_buffer << 8 ) | c;
  265. bits_left += 8;
  266. }
  267. /* Unload the local registers */
  268. state->next_input_byte = next_input_byte;
  269. state->bytes_in_buffer = bytes_in_buffer;
  270. state->get_buffer = get_buffer;
  271. state->bits_left = bits_left;
  272. return TRUE;
  273. }
  274. /*
  275. * Out-of-line code for Huffman code decoding.
  276. * See jdhuff.h for info about usage.
  277. */
  278. GLOBAL int
  279. jpeg_huff_decode( bitread_working_state * state,
  280. register bit_buf_type get_buffer, register int bits_left,
  281. d_derived_tbl * htbl, int min_bits ) {
  282. register int l = min_bits;
  283. register INT32 code;
  284. /* HUFF_DECODE has determined that the code is at least min_bits */
  285. /* bits long, so fetch that many bits in one swoop. */
  286. CHECK_BIT_BUFFER( *state, l, return -1 );
  287. code = GET_BITS( l );
  288. /* Collect the rest of the Huffman code one bit at a time. */
  289. /* This is per Figure F.16 in the JPEG spec. */
  290. while ( code > htbl->maxcode[l] ) {
  291. code <<= 1;
  292. CHECK_BIT_BUFFER( *state, 1, return -1 );
  293. code |= GET_BITS( 1 );
  294. l++;
  295. }
  296. /* Unload the local registers */
  297. state->get_buffer = get_buffer;
  298. state->bits_left = bits_left;
  299. /* With garbage input we may reach the sentinel value l = 17. */
  300. if ( l > 16 ) {
  301. WARNMS( state->cinfo, JWRN_HUFF_BAD_CODE );
  302. return 0; /* fake a zero as the safest result */
  303. }
  304. return htbl->pub->huffval[ htbl->valptr[l] +
  305. ( (int) ( code - htbl->mincode[l] ) ) ];
  306. }
  307. /*
  308. * Figure F.12: extend sign bit.
  309. * On some machines, a shift and add will be faster than a table lookup.
  310. */
  311. #ifdef AVOID_TABLES
  312. #define HUFF_EXTEND( x, s ) ( ( x ) < ( 1 << ( ( s ) - 1 ) ) ? ( x ) + ( ( ( -1 ) << ( s ) ) + 1 ) : ( x ) )
  313. #else
  314. #define HUFF_EXTEND( x, s ) ( ( x ) < extend_test[s] ? ( x ) + extend_offset[s] : ( x ) )
  315. static const int extend_test[16] = /* entry n is 2**(n-1) */
  316. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  317. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  318. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  319. { 0, ( ( -1 ) << 1 ) + 1, ( ( -1 ) << 2 ) + 1, ( ( -1 ) << 3 ) + 1, ( ( -1 ) << 4 ) + 1,
  320. ( ( -1 ) << 5 ) + 1, ( ( -1 ) << 6 ) + 1, ( ( -1 ) << 7 ) + 1, ( ( -1 ) << 8 ) + 1,
  321. ( ( -1 ) << 9 ) + 1, ( ( -1 ) << 10 ) + 1, ( ( -1 ) << 11 ) + 1, ( ( -1 ) << 12 ) + 1,
  322. ( ( -1 ) << 13 ) + 1, ( ( -1 ) << 14 ) + 1, ( ( -1 ) << 15 ) + 1 };
  323. #endif /* AVOID_TABLES */
  324. /*
  325. * Check for a restart marker & resynchronize decoder.
  326. * Returns FALSE if must suspend.
  327. */
  328. LOCAL boolean
  329. process_restart( j_decompress_ptr cinfo ) {
  330. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  331. int ci;
  332. /* Throw away any unused bits remaining in bit buffer; */
  333. /* include any full bytes in next_marker's count of discarded bytes */
  334. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  335. entropy->bitstate.bits_left = 0;
  336. /* Advance past the RSTn marker */
  337. if ( !( *cinfo->marker->read_restart_marker )( cinfo ) ) {
  338. return FALSE;
  339. }
  340. /* Re-initialize DC predictions to 0 */
  341. for ( ci = 0; ci < cinfo->comps_in_scan; ci++ ) {
  342. entropy->saved.last_dc_val[ci] = 0;
  343. }
  344. /* Reset restart counter */
  345. entropy->restarts_to_go = cinfo->restart_interval;
  346. /* Next segment can get another out-of-data warning */
  347. entropy->bitstate.printed_eod = FALSE;
  348. return TRUE;
  349. }
  350. /*
  351. * Decode and return one MCU's worth of Huffman-compressed coefficients.
  352. * The coefficients are reordered from zigzag order into natural array order,
  353. * but are not dequantized.
  354. *
  355. * The i'th block of the MCU is stored into the block pointed to by
  356. * MCU_data[i]. WE ASSUME THIS AREA HAS BEEN ZEROED BY THE CALLER.
  357. * (Wholesale zeroing is usually a little faster than retail...)
  358. *
  359. * Returns FALSE if data source requested suspension. In that case no
  360. * changes have been made to permanent state. (Exception: some output
  361. * coefficients may already have been assigned. This is harmless for
  362. * this module, since we'll just re-assign them on the next call.)
  363. */
  364. METHODDEF boolean
  365. decode_mcu( j_decompress_ptr cinfo, JBLOCKROW * MCU_data ) {
  366. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  367. register int s, k, r;
  368. int blkn, ci;
  369. JBLOCKROW block;
  370. BITREAD_STATE_VARS;
  371. savable_state state;
  372. d_derived_tbl * dctbl;
  373. d_derived_tbl * actbl;
  374. jpeg_component_info * compptr;
  375. /* Process restart marker if needed; may have to suspend */
  376. if ( cinfo->restart_interval ) {
  377. if ( entropy->restarts_to_go == 0 ) {
  378. if ( !process_restart( cinfo ) ) {
  379. return FALSE;
  380. }
  381. }
  382. }
  383. /* Load up working state */
  384. BITREAD_LOAD_STATE( cinfo, entropy->bitstate );
  385. ASSIGN_STATE( state, entropy->saved );
  386. /* Outer loop handles each block in the MCU */
  387. for ( blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++ ) {
  388. block = MCU_data[blkn];
  389. ci = cinfo->MCU_membership[blkn];
  390. compptr = cinfo->cur_comp_info[ci];
  391. dctbl = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  392. actbl = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  393. /* Decode a single block's worth of coefficients */
  394. /* Section F.2.2.1: decode the DC coefficient difference */
  395. HUFF_DECODE( s, br_state, dctbl, return FALSE, label1 );
  396. if ( s ) {
  397. CHECK_BIT_BUFFER( br_state, s, return FALSE );
  398. r = GET_BITS( s );
  399. s = HUFF_EXTEND( r, s );
  400. }
  401. /* Shortcut if component's values are not interesting */
  402. if ( !compptr->component_needed ) {
  403. goto skip_ACs;
  404. }
  405. /* Convert DC difference to actual value, update last_dc_val */
  406. s += state.last_dc_val[ci];
  407. state.last_dc_val[ci] = s;
  408. /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */
  409. ( *block )[0] = (JCOEF) s;
  410. /* Do we need to decode the AC coefficients for this component? */
  411. if ( compptr->DCT_scaled_size > 1 ) {
  412. /* Section F.2.2.2: decode the AC coefficients */
  413. /* Since zeroes are skipped, output area must be cleared beforehand */
  414. for ( k = 1; k < DCTSIZE2; k++ ) {
  415. HUFF_DECODE( s, br_state, actbl, return FALSE, label2 );
  416. r = s >> 4;
  417. s &= 15;
  418. if ( s ) {
  419. k += r;
  420. CHECK_BIT_BUFFER( br_state, s, return FALSE );
  421. r = GET_BITS( s );
  422. s = HUFF_EXTEND( r, s );
  423. /* Output coefficient in natural (dezigzagged) order.
  424. * Note: the extra entries in jpeg_natural_order[] will save us
  425. * if k >= DCTSIZE2, which could happen if the data is corrupted.
  426. */
  427. ( *block )[jpeg_natural_order[k]] = (JCOEF) s;
  428. } else {
  429. if ( r != 15 ) {
  430. break;
  431. }
  432. k += 15;
  433. }
  434. }
  435. } else {
  436. skip_ACs:
  437. /* Section F.2.2.2: decode the AC coefficients */
  438. /* In this path we just discard the values */
  439. for ( k = 1; k < DCTSIZE2; k++ ) {
  440. HUFF_DECODE( s, br_state, actbl, return FALSE, label3 );
  441. r = s >> 4;
  442. s &= 15;
  443. if ( s ) {
  444. k += r;
  445. CHECK_BIT_BUFFER( br_state, s, return FALSE );
  446. DROP_BITS( s );
  447. } else {
  448. if ( r != 15 ) {
  449. break;
  450. }
  451. k += 15;
  452. }
  453. }
  454. }
  455. }
  456. /* Completed MCU, so update state */
  457. BITREAD_SAVE_STATE( cinfo, entropy->bitstate );
  458. ASSIGN_STATE( entropy->saved, state );
  459. /* Account for restart interval (no-op if not using restarts) */
  460. entropy->restarts_to_go--;
  461. return TRUE;
  462. }
  463. /*
  464. * Module initialization routine for Huffman entropy decoding.
  465. */
  466. GLOBAL void
  467. jinit_huff_decoder( j_decompress_ptr cinfo ) {
  468. huff_entropy_ptr entropy;
  469. int i;
  470. entropy = (huff_entropy_ptr)
  471. ( *cinfo->mem->alloc_small )( (j_common_ptr) cinfo, JPOOL_IMAGE,
  472. SIZEOF( huff_entropy_decoder ) );
  473. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  474. entropy->pub.start_pass = start_pass_huff_decoder;
  475. entropy->pub.decode_mcu = decode_mcu;
  476. /* Mark tables unallocated */
  477. for ( i = 0; i < NUM_HUFF_TBLS; i++ ) {
  478. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  479. }
  480. }