OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 void vp9_cost_tokens(int *costs, const vp9_prob *probs, vp9_tree tree) { | 29 void vp9_cost_tokens(int *costs, const vp9_prob *probs, vp9_tree tree) { |
30 cost(costs, tree, probs, 0, 0); | 30 cost(costs, tree, probs, 0, 0); |
31 } | 31 } |
32 | 32 |
33 void vp9_cost_tokens_skip(int *costs, const vp9_prob *probs, vp9_tree tree) { | 33 void vp9_cost_tokens_skip(int *costs, const vp9_prob *probs, vp9_tree tree) { |
34 assert(tree[0] <= 0 && tree[1] > 0); | 34 assert(tree[0] <= 0 && tree[1] > 0); |
35 | 35 |
36 costs[-tree[0]] = vp9_cost_bit(probs[0], 0); | 36 costs[-tree[0]] = vp9_cost_bit(probs[0], 0); |
37 cost(costs, tree, probs, 2, 0); | 37 cost(costs, tree, probs, 2, 0); |
38 } | 38 } |
| 39 |
| 40 static void tree2tok(struct vp9_token *tokens, const vp9_tree_index *tree, |
| 41 int i, int v, int l) { |
| 42 v += v; |
| 43 ++l; |
| 44 |
| 45 do { |
| 46 const vp9_tree_index j = tree[i++]; |
| 47 if (j <= 0) { |
| 48 tokens[-j].value = v; |
| 49 tokens[-j].len = l; |
| 50 } else { |
| 51 tree2tok(tokens, tree, j, v, l); |
| 52 } |
| 53 } while (++v & 1); |
| 54 } |
| 55 |
| 56 void vp9_tokens_from_tree(struct vp9_token *tokens, |
| 57 const vp9_tree_index *tree) { |
| 58 tree2tok(tokens, tree, 0, 0, 0); |
| 59 } |
| 60 |
| 61 static unsigned int convert_distribution(unsigned int i, vp9_tree tree, |
| 62 unsigned int branch_ct[][2], |
| 63 const unsigned int num_events[]) { |
| 64 unsigned int left, right; |
| 65 |
| 66 if (tree[i] <= 0) |
| 67 left = num_events[-tree[i]]; |
| 68 else |
| 69 left = convert_distribution(tree[i], tree, branch_ct, num_events); |
| 70 |
| 71 if (tree[i + 1] <= 0) |
| 72 right = num_events[-tree[i + 1]]; |
| 73 else |
| 74 right = convert_distribution(tree[i + 1], tree, branch_ct, num_events); |
| 75 |
| 76 branch_ct[i >> 1][0] = left; |
| 77 branch_ct[i >> 1][1] = right; |
| 78 return left + right; |
| 79 } |
| 80 |
| 81 void vp9_tree_probs_from_distribution(vp9_tree tree, |
| 82 unsigned int branch_ct[/* n-1 */][2], |
| 83 const unsigned int num_events[/* n */]) { |
| 84 convert_distribution(0, tree, branch_ct, num_events); |
| 85 } |
OLD | NEW |