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

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
3838
3939 #define FF_HUFFMAN_FLAG_HNODE_FIRST 0x01
4040 #define FF_HUFFMAN_FLAG_ZERO_COUNT 0x02
41−#define FF_HUFFMAN_BITS 10
4241
4342 typedef int (*HuffCmp)(const void *va, const void *vb);
4443 int 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
4141 #include "vpx_rac.h"
4242
4343 #define VP6_MAX_HUFF_SIZE 12
44+#define AC_DC_HUFF_BITS 10
45+#define RUN_HUFF_BITS 8
4446
4547 static int vp6_parse_coeff(VP56Context *s);
4648 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
266268 }
267269
268270 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)
270273 {
271274 Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size];
272275 int a, b, i;
@@ -282,7 +285,7 @@ static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[], · 9 unmodified lines
282285
283286 ff_vlc_free(vlc);
284287 /* 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,
286289 nodes, vp6_huff_cmp,
287290 FF_HUFFMAN_FLAG_HNODE_FIRST);
288291 }
@@ -333,15 +336,18 @@ static int vp6_parse_coeff_models(VP56Context *s) · 44 unmodified lines
333336 if (s->use_huffman) {
334337 for (pt=0; pt<2; pt++) {
335338 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]))
337341 return -1;
338342 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]))
340345 return -1;
341346 for (ct=0; ct<3; ct++)
342347 for (int cg = 0; cg < 4; cg++)
343348 if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
344349 vp6_huff_coeff_map, 12,
350+ AC_DC_HUFF_BITS,
345351 &s->ract_vlc[pt][ct][cg]))
346352 return -1;
347353 }
@@ -433,11 +439,11 @@ static int vp6_parse_coeff_huffman(VP56Context *s) · 85 unmodified lines
433439 } else {
434440 if (get_bits_left(&s->gb) <= 0)
435441 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);
437443 if (coeff == 0) {
438444 if (coeff_idx) {
439445 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);
441447 if (run >= 9)
442448 run += get_bits(&s->gb, 6);
443449 } 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