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

Unified · Split

libavcodec/huffman.c+10−14
@@ -115,40 +115,36 @@ end: · 114 unmodified lines
115 return ret;115 return ret;
116}116}
117 117
118static void get_tree_codes(uint32_t *bits, int16_t *lens, uint8_t *xlat,118static void get_tree_codes(int8_t *lens, uint8_t *xlat,
119 Node *nodes, int node,119 Node *nodes, int node, int pl, int *pos, int no_zero_count)
120 uint32_t pfx, int pl, int *pos, int no_zero_count)
121{120{
122 int s;121 int s;
123 122
124 s = nodes[node].sym;123 s = nodes[node].sym;
125 if (s != HNODE || (no_zero_count && !nodes[node].count)) {124 if (s != HNODE || (no_zero_count && !nodes[node].count)) {
126 bits[*pos] = pfx;
127 lens[*pos] = pl;125 lens[*pos] = pl;
128 xlat[*pos] = s;126 xlat[*pos] = s;
129 (*pos)++;127 (*pos)++;
130 } else {128 } else {
131 pfx <<= 1;
132 pl++;129 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,
134 pos, no_zero_count);131 pos, no_zero_count);
135 pfx |= 1;132 get_tree_codes(lens, xlat, nodes, nodes[node].n0 + 1, pl,
136 get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0 + 1, pfx, pl,
137 pos, no_zero_count);133 pos, no_zero_count);
138 }134 }
139}135}
140 136
141static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags, int nb_bits)137static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags, int nb_bits, void *logctx)
142{138{
143 int no_zero_count = !(flags & FF_HUFFMAN_FLAG_ZERO_COUNT);139 int no_zero_count = !(flags & FF_HUFFMAN_FLAG_ZERO_COUNT);
144 uint32_t bits[256];140 int8_t lens[256];
145 int16_t lens[256];
146 uint8_t xlat[256];141 uint8_t xlat[256];
147 int pos = 0;142 int pos = 0;
148 143
149 get_tree_codes(bits, lens, xlat, nodes, head, 0, 0,144 get_tree_codes(lens, xlat, nodes, head, 0,
150 &pos, no_zero_count);145 &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);
152}148}
153 149
154 150
@@ -194,7 +190,7 @@ int ff_huff_build_tree(void *logctx, VLC *vlc, int nb_codes, int nb_bits, · 39 unmodified lines
194 nodes[j].n0 = i;190 nodes[j].n0 = i;
195 cur_node++;191 cur_node++;
196 }192 }
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) {
198 av_log(logctx, AV_LOG_ERROR, "Error building tree\n");194 av_log(logctx, AV_LOG_ERROR, "Error building tree\n");
199 return -1;195 return -1;
200 }196 }

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