Given that these trees have only nine elements and are complete, their depth is <= eight. Also remove the now unused FF_HUFFMAN_BITS constant.
Unified · Split
| @@ -38,7 +38,6 @@ typedef struct Node { · 37 unmodified lines | ||
| 38 | 38 | |
| 39 | 39 | #define FF_HUFFMAN_FLAG_HNODE_FIRST 0x01 |
| 40 | 40 | #define FF_HUFFMAN_FLAG_ZERO_COUNT 0x02 |
| 41 | −#define FF_HUFFMAN_BITS 10 | |
| 42 | 41 | |
| 43 | 42 | typedef int (*HuffCmp)(const void *va, const void *vb); |
| 44 | 43 | int ff_huff_build_tree(void *logctx, VLC *vlc, int nb_codes, int nb_bits, |
| @@ -41,6 +41,8 @@ · 40 unmodified lines | ||
| 41 | 41 | #include "vpx_rac.h" |
| 42 | 42 | |
| 43 | 43 | #define VP6_MAX_HUFF_SIZE 12 |
| 44 | +#define AC_DC_HUFF_BITS 10 | |
| 45 | +#define RUN_HUFF_BITS 8 | |
| 44 | 46 | |
| 45 | 47 | static int vp6_parse_coeff(VP56Context *s); |
| 46 | 48 | static int vp6_parse_coeff_huffman(VP56Context *s); |
| @@ -266,7 +268,8 @@ static int vp6_huff_cmp(const void *va, const void *vb) · 219 unmodified lines | ||
| 266 | 268 | } |
| 267 | 269 | |
| 268 | 270 | static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[], |
| 269 | − const uint8_t *map, unsigned size, VLC *vlc) | |
| 271 | + const uint8_t *map, unsigned size, | |
| 272 | + int nb_bits, VLC *vlc) | |
| 270 | 273 | { |
| 271 | 274 | Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size]; |
| 272 | 275 | int a, b, i; |
| @@ -282,7 +285,7 @@ static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[], · 9 unmodified lines | ||
| 282 | 285 | |
| 283 | 286 | ff_vlc_free(vlc); |
| 284 | 287 | /* then build the huffman tree according to probabilities */ |
| 285 | − return ff_huff_build_tree(s->avctx, vlc, size, FF_HUFFMAN_BITS, | |
| 288 | + return ff_huff_build_tree(s->avctx, vlc, size, nb_bits, | |
| 286 | 289 | nodes, vp6_huff_cmp, |
| 287 | 290 | FF_HUFFMAN_FLAG_HNODE_FIRST); |
| 288 | 291 | } |
| @@ -333,15 +336,18 @@ static int vp6_parse_coeff_models(VP56Context *s) · 44 unmodified lines | ||
| 333 | 336 | if (s->use_huffman) { |
| 334 | 337 | for (pt=0; pt<2; pt++) { |
| 335 | 338 | if (vp6_build_huff_tree(s, model->coeff_dccv[pt], |
| 336 | − vp6_huff_coeff_map, 12, &s->dccv_vlc[pt])) | |
| 339 | + vp6_huff_coeff_map, 12, AC_DC_HUFF_BITS, | |
| 340 | + &s->dccv_vlc[pt])) | |
| 337 | 341 | return -1; |
| 338 | 342 | if (vp6_build_huff_tree(s, model->coeff_runv[pt], |
| 339 | − vp6_huff_run_map, 9, &s->runv_vlc[pt])) | |
| 343 | + vp6_huff_run_map, 9, RUN_HUFF_BITS, | |
| 344 | + &s->runv_vlc[pt])) | |
| 340 | 345 | return -1; |
| 341 | 346 | for (ct=0; ct<3; ct++) |
| 342 | 347 | for (int cg = 0; cg < 4; cg++) |
| 343 | 348 | if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg], |
| 344 | 349 | vp6_huff_coeff_map, 12, |
| 350 | + AC_DC_HUFF_BITS, | |
| 345 | 351 | &s->ract_vlc[pt][ct][cg])) |
| 346 | 352 | return -1; |
| 347 | 353 | } |
| @@ -433,11 +439,11 @@ static int vp6_parse_coeff_huffman(VP56Context *s) · 85 unmodified lines | ||
| 433 | 439 | } else { |
| 434 | 440 | if (get_bits_left(&s->gb) <= 0) |
| 435 | 441 | return AVERROR_INVALIDDATA; |
| 436 | − int coeff = get_vlc2(&s->gb, vlc_coeff->table, FF_HUFFMAN_BITS, 2); | |
| 442 | + int coeff = get_vlc2(&s->gb, vlc_coeff->table, AC_DC_HUFF_BITS, 2); | |
| 437 | 443 | if (coeff == 0) { |
| 438 | 444 | if (coeff_idx) { |
| 439 | 445 | int pt = (coeff_idx >= 6); |
| 440 | − run += get_vlc2(&s->gb, s->runv_vlc[pt].table, FF_HUFFMAN_BITS, 1); | |
| 446 | + run += get_vlc2(&s->gb, s->runv_vlc[pt].table, RUN_HUFF_BITS, 1); | |
| 441 | 447 | if (run >= 9) |
| 442 | 448 | run += get_bits(&s->gb, 6); |
| 443 | 449 | } else |