MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / huf_read

Function huf_read

Source/Amiga/dernc.cpp:223–244  ·  view source on GitHub ↗

* Read a value out of the bit stream using the given Huffman table. */

Source from the content-addressed store, hash-verified

221 * Read a value out of the bit stream using the given Huffman table.
222 */
223static unsigned long huf_read (huf_table *h, bit_stream *bs,
224 unsigned char **p) {
225 int i;
226 unsigned long val;
227
228 for (i=0; i<h->num; i++) {
229 unsigned long mask = (1 << h->table[i].codelen) - 1;
230 if (bit_peek(bs, mask) == h->table[i].code)
231 break;
232 }
233 if (i == h->num)
234 return -1;
235 bit_advance (bs, h->table[i].codelen, p);
236
237 val = h->table[i].value;
238
239 if (val >= 2) {
240 val = 1 << (val-1);
241 val |= bit_read (bs, val-1, h->table[i].value - 1, p);
242 }
243 return val;
244}
245
246/*
247 * Initialises a bit stream with the first two bytes of the packed

Callers 1

rnc_unpackFunction · 0.85

Calls 3

bit_peekFunction · 0.85
bit_advanceFunction · 0.85
bit_readFunction · 0.85

Tested by

no test coverage detected