34 static void get_tree_codes(uint32_t *
bits, int16_t *lens, uint8_t *xlat,
Node *nodes,
int node, uint32_t pfx,
int pl,
int *pos,
int no_zero_count)
39 if(s !=
HNODE || (no_zero_count && !nodes[node].count)){
47 get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0, pfx, pl, pos,
50 get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0+1, pfx, pl, pos,
63 get_tree_codes(bits, lens, xlat, nodes, head, 0, 0, &pos, no_zero_count);
64 return ff_init_vlc_sparse(vlc, 9, pos, lens, 2, 2, bits, 4, 4, xlat, 1, 1, 0);
79 for(i = 0; i < nb_codes; i++){
82 sum += nodes[i].
count;
86 av_log(avctx,
AV_LOG_ERROR,
"Too high symbol frequencies. Tree construction is not possible\n");
89 qsort(nodes, nb_codes,
sizeof(
Node), cmp);
91 nodes[nb_codes*2-1].
count = 0;
92 for(i = 0; i < nb_codes*2-1; i += 2){
95 nodes[cur_node].
n0 = i;
96 for(j = cur_node; j > 0; j--){
97 if(nodes[j].count > nodes[j-1].count ||
98 (nodes[j].count == nodes[j-1].count &&
100 nodes[j].n0==j-1 || nodes[j].n0==j-2 ||
101 (nodes[j].sym!=
HNODE && nodes[j-1].sym!=
HNODE))))
#define FF_HUFFMAN_FLAG_HNODE_FIRST
static void get_tree_codes(uint32_t *bits, int16_t *lens, uint8_t *xlat, Node *nodes, int node, uint32_t pfx, int pl, int *pos, int no_zero_count)
int ff_huff_build_tree(AVCodecContext *avctx, VLC *vlc, int nb_codes, Node *nodes, HuffCmp cmp, int flags)
nodes size must be 2*nb_codes first nb_codes nodes.count must be set
int(* HuffCmp)(const void *va, const void *vb)
int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
bitstream reader API header.
#define FF_HUFFMAN_FLAG_ZERO_COUNT
void av_log(void *avcl, int level, const char *fmt,...)
static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags)
main external API structure.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
huffman tree builder and VLC generator
#define FFSWAP(type, a, b)