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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 } | 94 } |
95 | 95 |
96 | 96 |
97 void vp9_tree_probs_from_distribution( | 97 void vp9_tree_probs_from_distribution( |
98 int n, /* n = size of alphabet */ | 98 int n, /* n = size of alphabet */ |
99 vp9_token tok [ /* n */ ], | 99 vp9_token tok [ /* n */ ], |
100 vp9_tree tree, | 100 vp9_tree tree, |
101 vp9_prob probs [ /* n-1 */ ], | 101 vp9_prob probs [ /* n-1 */ ], |
102 unsigned int branch_ct [ /* n-1 */ ] [2], | 102 unsigned int branch_ct [ /* n-1 */ ] [2], |
103 const unsigned int num_events[ /* n */ ], | 103 const unsigned int num_events[ /* n */ ] |
104 unsigned int Pfac, | |
105 int rd | |
106 ) { | 104 ) { |
107 const int tree_len = n - 1; | 105 const int tree_len = n - 1; |
108 int t = 0; | 106 int t = 0; |
109 | 107 |
110 branch_counts(n, tok, tree, branch_ct, num_events); | 108 branch_counts(n, tok, tree, branch_ct, num_events); |
111 | 109 |
112 do { | 110 do { |
113 const unsigned int *const c = branch_ct[t]; | 111 probs[t] = get_binary_prob(branch_ct[t][0], branch_ct[t][1]); |
114 const unsigned int tot = c[0] + c[1]; | |
115 | |
116 #if CONFIG_DEBUG | |
117 assert(tot < (1 << 24)); /* no overflow below */ | |
118 #endif | |
119 | |
120 if (tot) { | |
121 const unsigned int p = ((c[0] * Pfac) + (rd ? tot >> 1 : 0)) / tot; | |
122 probs[t] = p < 256 ? (p ? p : 1) : 255; /* agree w/old version for now */ | |
123 } else | |
124 probs[t] = vp9_prob_half; | |
125 } while (++t < tree_len); | 112 } while (++t < tree_len); |
126 } | 113 } |
127 | |
128 vp9_prob vp9_bin_prob_from_distribution(const unsigned int counts[2]) { | |
129 int tot_count = counts[0] + counts[1]; | |
130 vp9_prob prob; | |
131 if (tot_count) { | |
132 prob = (counts[0] * 255 + (tot_count >> 1)) / tot_count; | |
133 prob += !prob; | |
134 } else { | |
135 prob = 128; | |
136 } | |
137 return prob; | |
138 } | |
OLD | NEW |