2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "vp9/encoder/vp9_treewriter.h"
13 static void tree2tok(struct vp9_token
*tokens
, const vp9_tree_index
*tree
,
14 int i
, int v
, int l
) {
19 const vp9_tree_index j
= tree
[i
++];
24 tree2tok(tokens
, tree
, j
, v
, l
);
29 void vp9_tokens_from_tree(struct vp9_token
*tokens
,
30 const vp9_tree_index
*tree
) {
31 tree2tok(tokens
, tree
, 0, 0, 0);
34 static unsigned int convert_distribution(unsigned int i
, vp9_tree tree
,
35 unsigned int branch_ct
[][2],
36 const unsigned int num_events
[]) {
37 unsigned int left
, right
;
40 left
= num_events
[-tree
[i
]];
42 left
= convert_distribution(tree
[i
], tree
, branch_ct
, num_events
);
45 right
= num_events
[-tree
[i
+ 1]];
47 right
= convert_distribution(tree
[i
+ 1], tree
, branch_ct
, num_events
);
49 branch_ct
[i
>> 1][0] = left
;
50 branch_ct
[i
>> 1][1] = right
;
54 void vp9_tree_probs_from_distribution(vp9_tree tree
,
55 unsigned int branch_ct
[/* n-1 */][2],
56 const unsigned int num_events
[/* n */]) {
57 convert_distribution(0, tree
, branch_ct
, num_events
);