1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avcodec/vp6: Use fewer number of bits in run VLCs

Given that these trees have only nine elements and are complete,
their depth is <= eight.

Also remove the now unused FF_HUFFMAN_BITS constant.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-04-17 20:13:56 +02:00
parent e946ba64bf
commit be7495c32c
2 changed files with 12 additions and 7 deletions

View File

@ -38,7 +38,6 @@ typedef struct Node {
#define FF_HUFFMAN_FLAG_HNODE_FIRST 0x01 #define FF_HUFFMAN_FLAG_HNODE_FIRST 0x01
#define FF_HUFFMAN_FLAG_ZERO_COUNT 0x02 #define FF_HUFFMAN_FLAG_ZERO_COUNT 0x02
#define FF_HUFFMAN_BITS 10
typedef int (*HuffCmp)(const void *va, const void *vb); typedef int (*HuffCmp)(const void *va, const void *vb);
int ff_huff_build_tree(void *logctx, VLC *vlc, int nb_codes, int nb_bits, int ff_huff_build_tree(void *logctx, VLC *vlc, int nb_codes, int nb_bits,

View File

@ -41,6 +41,8 @@
#include "vpx_rac.h" #include "vpx_rac.h"
#define VP6_MAX_HUFF_SIZE 12 #define VP6_MAX_HUFF_SIZE 12
#define AC_DC_HUFF_BITS 10
#define RUN_HUFF_BITS 8
static int vp6_parse_coeff(VP56Context *s); static int vp6_parse_coeff(VP56Context *s);
static int vp6_parse_coeff_huffman(VP56Context *s); static int vp6_parse_coeff_huffman(VP56Context *s);
@ -266,7 +268,8 @@ static int vp6_huff_cmp(const void *va, const void *vb)
} }
static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[], static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
const uint8_t *map, unsigned size, VLC *vlc) const uint8_t *map, unsigned size,
int nb_bits, VLC *vlc)
{ {
Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size]; Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size];
int a, b, i; int a, b, i;
@ -282,7 +285,7 @@ static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
ff_vlc_free(vlc); ff_vlc_free(vlc);
/* then build the huffman tree according to probabilities */ /* then build the huffman tree according to probabilities */
return ff_huff_build_tree(s->avctx, vlc, size, FF_HUFFMAN_BITS, return ff_huff_build_tree(s->avctx, vlc, size, nb_bits,
nodes, vp6_huff_cmp, nodes, vp6_huff_cmp,
FF_HUFFMAN_FLAG_HNODE_FIRST); FF_HUFFMAN_FLAG_HNODE_FIRST);
} }
@ -333,15 +336,18 @@ static int vp6_parse_coeff_models(VP56Context *s)
if (s->use_huffman) { if (s->use_huffman) {
for (pt=0; pt<2; pt++) { for (pt=0; pt<2; pt++) {
if (vp6_build_huff_tree(s, model->coeff_dccv[pt], if (vp6_build_huff_tree(s, model->coeff_dccv[pt],
vp6_huff_coeff_map, 12, &s->dccv_vlc[pt])) vp6_huff_coeff_map, 12, AC_DC_HUFF_BITS,
&s->dccv_vlc[pt]))
return -1; return -1;
if (vp6_build_huff_tree(s, model->coeff_runv[pt], if (vp6_build_huff_tree(s, model->coeff_runv[pt],
vp6_huff_run_map, 9, &s->runv_vlc[pt])) vp6_huff_run_map, 9, RUN_HUFF_BITS,
&s->runv_vlc[pt]))
return -1; return -1;
for (ct=0; ct<3; ct++) for (ct=0; ct<3; ct++)
for (int cg = 0; cg < 4; cg++) for (int cg = 0; cg < 4; cg++)
if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg], if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
vp6_huff_coeff_map, 12, vp6_huff_coeff_map, 12,
AC_DC_HUFF_BITS,
&s->ract_vlc[pt][ct][cg])) &s->ract_vlc[pt][ct][cg]))
return -1; return -1;
} }
@ -433,11 +439,11 @@ static int vp6_parse_coeff_huffman(VP56Context *s)
} else { } else {
if (get_bits_left(&s->gb) <= 0) if (get_bits_left(&s->gb) <= 0)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
int coeff = get_vlc2(&s->gb, vlc_coeff->table, FF_HUFFMAN_BITS, 2); int coeff = get_vlc2(&s->gb, vlc_coeff->table, AC_DC_HUFF_BITS, 2);
if (coeff == 0) { if (coeff == 0) {
if (coeff_idx) { if (coeff_idx) {
int pt = (coeff_idx >= 6); int pt = (coeff_idx >= 6);
run += get_vlc2(&s->gb, s->runv_vlc[pt].table, FF_HUFFMAN_BITS, 1); run += get_vlc2(&s->gb, s->runv_vlc[pt].table, RUN_HUFF_BITS, 1);
if (run >= 9) if (run >= 9)
run += get_bits(&s->gb, 6); run += get_bits(&s->gb, 6);
} else } else