Deobfuscate ff_huff_build_tree.

I have no idea what the idea was behind the original code,
but the new code is equivalent to it.
In that loop that places the new node nodes[j] contains
always the data of the new node (since the steps are always
in order: FFSWAP copies node[j] to node[j-1], j is decremented).
Thus nodes[j].no == i and nodes[j].sym == HNODE.
make fate still passes and contains VP6 samples which use
FF_HUFFMAN_FLAG_HNODE_FIRST.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
This commit is contained in:
Reimar Döffinger 2012-01-29 21:23:59 +01:00
parent 5f27374c1b
commit 6166bf3cbe
1 changed files with 6 additions and 7 deletions

View File

@ -90,15 +90,14 @@ int ff_huff_build_tree(AVCodecContext *avctx, VLC *vlc, int nb_codes,
cur_node = nb_codes;
nodes[nb_codes*2-1].count = 0;
for(i = 0; i < nb_codes*2-1; i += 2){
uint32_t cur_count = nodes[i].count + nodes[i+1].count;
nodes[cur_node].sym = HNODE;
nodes[cur_node].count = nodes[i].count + nodes[i+1].count;
nodes[cur_node].count = cur_count;
nodes[cur_node].n0 = i;
for(j = cur_node; j > 0; j--){
if(nodes[j].count > nodes[j-1].count ||
(nodes[j].count == nodes[j-1].count &&
(!(flags & FF_HUFFMAN_FLAG_HNODE_FIRST) ||
nodes[j].n0==j-1 || nodes[j].n0==j-2 ||
(nodes[j].sym!=HNODE && nodes[j-1].sym!=HNODE))))
for(j = cur_node; j > i + 2; j--){
if(cur_count > nodes[j-1].count ||
(cur_count == nodes[j-1].count &&
!(flags & FF_HUFFMAN_FLAG_HNODE_FIRST)))
break;
FFSWAP(Node, nodes[j], nodes[j-1]);
}