MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / read_tree

Function read_tree

libavcodec/bink.c:247–283  ·  view source on GitHub ↗

* Read information about Huffman tree used to decode data. * * @param gb context for reading bits * @param tree pointer for storing tree data */

Source from the content-addressed store, hash-verified

245 * @param tree pointer for storing tree data
246 */
247static int read_tree(GetBitContext *gb, Tree *tree)
248{
249 uint8_t tmp1[16] = { 0 }, tmp2[16], *in = tmp1, *out = tmp2;
250 int i, t, len;
251
252 if (get_bits_left(gb) < 4)
253 return AVERROR_INVALIDDATA;
254
255 tree->vlc_num = get_bits(gb, 4);
256 if (!tree->vlc_num) {
257 for (i = 0; i < 16; i++)
258 tree->syms[i] = i;
259 return 0;
260 }
261 if (get_bits1(gb)) {
262 len = get_bits(gb, 3);
263 for (i = 0; i <= len; i++) {
264 tree->syms[i] = get_bits(gb, 4);
265 tmp1[tree->syms[i]] = 1;
266 }
267 for (i = 0; i < 16 && len < 16 - 1; i++)
268 if (!tmp1[i])
269 tree->syms[++len] = i;
270 } else {
271 len = get_bits(gb, 2);
272 for (i = 0; i < 16; i++)
273 in[i] = i;
274 for (i = 0; i <= len; i++) {
275 int size = 1 << i;
276 for (t = 0; t < 16; t += size << 1)
277 merge(gb, out + t, in + t, size);
278 FFSWAP(uint8_t*, in, out);
279 }
280 memcpy(tree->syms, in, 16);
281 }
282 return 0;
283}
284
285/**
286 * Prepare bundle for decoding data.

Callers 1

read_bundleFunction · 0.85

Calls 4

get_bits_leftFunction · 0.85
get_bits1Function · 0.85
mergeFunction · 0.85
get_bitsFunction · 0.70

Tested by

no test coverage detected