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