Line data Source code
1 : /*
2 : * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 : *
4 : * This source code is subject to the terms of the BSD 2 Clause License and
5 : * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 : * was not distributed with this source code in the LICENSE file, you can
7 : * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 : * Media Patent License 1.0 was not distributed with this source code in the
9 : * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 : */
11 :
12 : #include "av1/encoder/treewriter.h"
13 :
14 0 : static void tree2tok(struct av1_token *tokens, const aom_tree_index *tree,
15 : int i, int v, int l) {
16 0 : v += v;
17 0 : ++l;
18 :
19 : do {
20 0 : const aom_tree_index j = tree[i++];
21 0 : if (j <= 0) {
22 0 : tokens[-j].value = v;
23 0 : tokens[-j].len = l;
24 : } else {
25 0 : tree2tok(tokens, tree, j, v, l);
26 : }
27 0 : } while (++v & 1);
28 0 : }
29 :
30 0 : void av1_tokens_from_tree(struct av1_token *tokens,
31 : const aom_tree_index *tree) {
32 0 : tree2tok(tokens, tree, 0, 0, 0);
33 0 : }
34 :
35 0 : static unsigned int convert_distribution(unsigned int i, aom_tree tree,
36 : unsigned int branch_ct[][2],
37 : const unsigned int num_events[]) {
38 : unsigned int left, right;
39 :
40 0 : if (tree[i] <= 0)
41 0 : left = num_events[-tree[i]];
42 : else
43 0 : left = convert_distribution(tree[i], tree, branch_ct, num_events);
44 :
45 0 : if (tree[i + 1] <= 0)
46 0 : right = num_events[-tree[i + 1]];
47 : else
48 0 : right = convert_distribution(tree[i + 1], tree, branch_ct, num_events);
49 :
50 0 : branch_ct[i >> 1][0] = left;
51 0 : branch_ct[i >> 1][1] = right;
52 0 : return left + right;
53 : }
54 :
55 0 : void av1_tree_probs_from_distribution(aom_tree tree,
56 : unsigned int branch_ct[/* n-1 */][2],
57 : const unsigned int num_events[/* n */]) {
58 0 : convert_distribution(0, tree, branch_ct, num_events);
59 0 : }
|