History

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.

Andreas Rheinhardt committed 1 year ago

Commit be7495c1 parent e946ba62 files · +12 −7Browse files

Showing the changes to libavcodec (2 of 2 files). Show all

Unified · Split

2 files
  1. libavcodec/huffman.h +0 −1
  2. libavcodec/vp6.c +12 −6
libavcodec/huffman.h+0−1
@@ -38,7 +38,6 @@ typedef struct Node { · 37 unmodified lines
38 38
39#define FF_HUFFMAN_FLAG_HNODE_FIRST 0x0139#define FF_HUFFMAN_FLAG_HNODE_FIRST 0x01
40#define FF_HUFFMAN_FLAG_ZERO_COUNT 0x0240#define FF_HUFFMAN_FLAG_ZERO_COUNT 0x02
41#define FF_HUFFMAN_BITS 10
42 41
43typedef int (*HuffCmp)(const void *va, const void *vb);42typedef int (*HuffCmp)(const void *va, const void *vb);
44int ff_huff_build_tree(void *logctx, VLC *vlc, int nb_codes, int nb_bits,43int ff_huff_build_tree(void *logctx, VLC *vlc, int nb_codes, int nb_bits,
libavcodec/vp6.c+12−6
@@ -41,6 +41,8 @@ · 40 unmodified lines
41#include "vpx_rac.h"41#include "vpx_rac.h"
42 42
43#define VP6_MAX_HUFF_SIZE 1243#define VP6_MAX_HUFF_SIZE 12
44#define AC_DC_HUFF_BITS 10
45#define RUN_HUFF_BITS 8
44 46
45static int vp6_parse_coeff(VP56Context *s);47static int vp6_parse_coeff(VP56Context *s);
46static int vp6_parse_coeff_huffman(VP56Context *s);48static 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
268static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],270static 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 Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size];274 Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size];
272 int a, b, i;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 ff_vlc_free(vlc);286 ff_vlc_free(vlc);
284 /* then build the huffman tree according to probabilities */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 nodes, vp6_huff_cmp,289 nodes, vp6_huff_cmp,
287 FF_HUFFMAN_FLAG_HNODE_FIRST);290 FF_HUFFMAN_FLAG_HNODE_FIRST);
288}291}
@@ -333,15 +336,18 @@ static int vp6_parse_coeff_models(VP56Context *s) · 44 unmodified lines
333 if (s->use_huffman) {336 if (s->use_huffman) {
334 for (pt=0; pt<2; pt++) {337 for (pt=0; pt<2; pt++) {
335 if (vp6_build_huff_tree(s, model->coeff_dccv[pt],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 return -1;341 return -1;
338 if (vp6_build_huff_tree(s, model->coeff_runv[pt],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 return -1;345 return -1;
341 for (ct=0; ct<3; ct++)346 for (ct=0; ct<3; ct++)
342 for (int cg = 0; cg < 4; cg++)347 for (int cg = 0; cg < 4; cg++)
343 if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],348 if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
344 vp6_huff_coeff_map, 12,349 vp6_huff_coeff_map, 12,
350 AC_DC_HUFF_BITS,
345 &s->ract_vlc[pt][ct][cg]))351 &s->ract_vlc[pt][ct][cg]))
346 return -1;352 return -1;
347 }353 }
@@ -433,11 +439,11 @@ static int vp6_parse_coeff_huffman(VP56Context *s) · 85 unmodified lines
433 } else {439 } else {
434 if (get_bits_left(&s->gb) <= 0)440 if (get_bits_left(&s->gb) <= 0)
435 return AVERROR_INVALIDDATA;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 if (coeff == 0) {443 if (coeff == 0) {
438 if (coeff_idx) {444 if (coeff_idx) {
439 int pt = (coeff_idx >= 6);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 if (run >= 9)447 if (run >= 9)
442 run += get_bits(&s->gb, 6);448 run += get_bits(&s->gb, 6);
443 } else449 } else

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t