* Read a Huffman table out of the bit stream and data stream given. */
| 184 | * Read a Huffman table out of the bit stream and data stream given. |
| 185 | */ |
| 186 | static void read_huftable (huf_table *h, bit_stream *bs, unsigned char **p) { |
| 187 | int i, j, k, num; |
| 188 | int leaflen[32]; |
| 189 | int leafmax; |
| 190 | unsigned long codeb; /* big-endian form of code */ |
| 191 | |
| 192 | num = bit_read (bs, 0x1F, 5, p); |
| 193 | if (!num) |
| 194 | return; |
| 195 | |
| 196 | leafmax = 1; |
| 197 | for (i=0; i<num; i++) { |
| 198 | leaflen[i] = bit_read (bs, 0x0F, 4, p); |
| 199 | if (leafmax < leaflen[i]) |
| 200 | leafmax = leaflen[i]; |
| 201 | } |
| 202 | |
| 203 | codeb = 0L; |
| 204 | k = 0; |
| 205 | for (i=1; i<=leafmax; i++) { |
| 206 | for (j=0; j<num; j++) |
| 207 | if (leaflen[j] == i) { |
| 208 | h->table[k].code = mirror (codeb, i); |
| 209 | h->table[k].codelen = i; |
| 210 | h->table[k].value = j; |
| 211 | codeb++; |
| 212 | k++; |
| 213 | } |
| 214 | codeb <<= 1; |
| 215 | } |
| 216 | |
| 217 | h->num = k; |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | * Read a value out of the bit stream using the given Huffman table. |
no test coverage detected