OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | |
3 * | |
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. | |
9 */ | |
10 | |
11 | |
12 #include <assert.h> | |
13 | |
14 #include "./vpx_config.h" | |
15 #include "vp9/common/vp9_treecoder.h" | |
16 | |
17 static void tree2tok(struct vp9_token *const p, vp9_tree t, | |
18 int i, int v, int l) { | |
19 v += v; | |
20 ++l; | |
21 | |
22 do { | |
23 const vp9_tree_index j = t[i++]; | |
24 | |
25 if (j <= 0) { | |
26 p[-j].value = v; | |
27 p[-j].len = l; | |
28 } else { | |
29 tree2tok(p, t, j, v, l); | |
30 } | |
31 } while (++v & 1); | |
32 } | |
33 | |
34 void vp9_tokens_from_tree(struct vp9_token *p, vp9_tree t) { | |
35 tree2tok(p, t, 0, 0, 0); | |
36 } | |
37 | |
38 void vp9_tokens_from_tree_offset(struct vp9_token *p, vp9_tree t, | |
39 int offset) { | |
40 tree2tok(p - offset, t, 0, 0, 0); | |
41 } | |
42 | |
43 static unsigned int convert_distribution(unsigned int i, | |
44 vp9_tree tree, | |
45 vp9_prob probs[], | |
46 unsigned int branch_ct[][2], | |
47 const unsigned int num_events[], | |
48 unsigned int tok0_offset) { | |
49 unsigned int left, right; | |
50 | |
51 if (tree[i] <= 0) { | |
52 left = num_events[-tree[i] - tok0_offset]; | |
53 } else { | |
54 left = convert_distribution(tree[i], tree, probs, branch_ct, | |
55 num_events, tok0_offset); | |
56 } | |
57 if (tree[i + 1] <= 0) | |
58 right = num_events[-tree[i + 1] - tok0_offset]; | |
59 else | |
60 right = convert_distribution(tree[i + 1], tree, probs, branch_ct, | |
61 num_events, tok0_offset); | |
62 | |
63 probs[i>>1] = get_binary_prob(left, right); | |
64 branch_ct[i>>1][0] = left; | |
65 branch_ct[i>>1][1] = right; | |
66 return left + right; | |
67 } | |
68 | |
69 void vp9_tree_probs_from_distribution(vp9_tree tree, vp9_prob probs[/* n-1 */], | |
70 unsigned int branch_ct[/* n-1 */][2], | |
71 const unsigned int num_events[/* n */], | |
72 unsigned int tok0_offset) { | |
73 convert_distribution(0, tree, probs, branch_ct, num_events, tok0_offset); | |
74 } | |
OLD | NEW |