History

avcodec/huffman: Switch to ff_vlc_init_from_lengths()

Avoids having to create the codes ourselves.

Andreas Rheinhardt committed 1 year ago

Commit 3e21df21 parent e73c59c1 file · +10 −14Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/huffman.c+10−14
@@ -115,40 +115,36 @@ end: · 114 unmodified lines
115115 return ret;
116116 }
117117
118−static void get_tree_codes(uint32_t *bits, int16_t *lens, uint8_t *xlat,
119− Node *nodes, int node,
120− uint32_t pfx, int pl, int *pos, int no_zero_count)
118+static void get_tree_codes(int8_t *lens, uint8_t *xlat,
119+ Node *nodes, int node, int pl, int *pos, int no_zero_count)
121120 {
122121 int s;
123122
124123 s = nodes[node].sym;
125124 if (s != HNODE || (no_zero_count && !nodes[node].count)) {
126− bits[*pos] = pfx;
127125 lens[*pos] = pl;
128126 xlat[*pos] = s;
129127 (*pos)++;
130128 } else {
131− pfx <<= 1;
132129 pl++;
133− get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0, pfx, pl,
130+ get_tree_codes(lens, xlat, nodes, nodes[node].n0, pl,
134131 pos, no_zero_count);
135− pfx |= 1;
136− get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0 + 1, pfx, pl,
132+ get_tree_codes(lens, xlat, nodes, nodes[node].n0 + 1, pl,
137133 pos, no_zero_count);
138134 }
139135 }
140136
141−static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags, int nb_bits)
137+static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags, int nb_bits, void *logctx)
142138 {
143139 int no_zero_count = !(flags & FF_HUFFMAN_FLAG_ZERO_COUNT);
144− uint32_t bits[256];
145− int16_t lens[256];
140+ int8_t lens[256];
146141 uint8_t xlat[256];
147142 int pos = 0;
148143
149− get_tree_codes(bits, lens, xlat, nodes, head, 0, 0,
144+ get_tree_codes(lens, xlat, nodes, head, 0,
150145 &pos, no_zero_count);
151− return ff_vlc_init_sparse(vlc, nb_bits, pos, lens, 2, 2, bits, 4, 4, xlat, 1, 1, 0);
146+ return ff_vlc_init_from_lengths(vlc, nb_bits, pos, lens, 1,
147+ xlat, 1, 1, 0, 0, logctx);
152148 }
153149
154150
@@ -194,7 +190,7 @@ int ff_huff_build_tree(void *logctx, VLC *vlc, int nb_codes, int nb_bits, · 39 unmodified lines
194190 nodes[j].n0 = i;
195191 cur_node++;
196192 }
197− if (build_huff_tree(vlc, nodes, nb_codes * 2 - 2, flags, nb_bits) < 0) {
193+ if (build_huff_tree(vlc, nodes, nb_codes * 2 - 2, flags, nb_bits, logctx) < 0) {
198194 av_log(logctx, AV_LOG_ERROR, "Error building tree\n");
199195 return -1;
200196 }

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