* Read a value out of the bit stream using the given Huffman table. */
| 221 | * Read a value out of the bit stream using the given Huffman table. |
| 222 | */ |
| 223 | static 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 |
no test coverage detected