2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-08-14 01:50:03 +02:00
|
|
|
#include "vpx_config.h"
|
|
|
|
|
2012-08-14 23:12:00 +02:00
|
|
|
#if defined(CONFIG_DEBUG) && CONFIG_DEBUG
|
2010-05-18 17:58:33 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#endif
|
|
|
|
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/common/vp9_treecoder.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-11 22:01:52 +02:00
|
|
|
static void tree2tok(struct vp9_token *const p, vp9_tree t,
|
|
|
|
int i, int v, int l) {
|
2012-07-14 00:21:29 +02:00
|
|
|
v += v;
|
2013-04-11 22:01:52 +02:00
|
|
|
++l;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
do {
|
2012-10-31 22:40:53 +01:00
|
|
|
const vp9_tree_index j = t[i++];
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
if (j <= 0) {
|
|
|
|
p[-j].value = v;
|
2013-04-11 22:01:52 +02:00
|
|
|
p[-j].len = l;
|
2012-07-14 00:21:29 +02:00
|
|
|
} else
|
2013-04-11 22:01:52 +02:00
|
|
|
tree2tok(p, t, j, v, l);
|
2012-07-14 00:21:29 +02:00
|
|
|
} while (++v & 1);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-04-11 22:01:52 +02:00
|
|
|
void vp9_tokens_from_tree(struct vp9_token *p, vp9_tree t) {
|
2012-07-14 00:21:29 +02:00
|
|
|
tree2tok(p, t, 0, 0, 0);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-04-11 22:01:52 +02:00
|
|
|
void vp9_tokens_from_tree_offset(struct vp9_token *p, vp9_tree t,
|
2012-07-14 00:21:29 +02:00
|
|
|
int offset) {
|
|
|
|
tree2tok(p - offset, t, 0, 0, 0);
|
2010-08-09 19:27:26 +02:00
|
|
|
}
|
|
|
|
|
2013-03-10 21:39:30 +01:00
|
|
|
static unsigned int convert_distribution(unsigned int i,
|
|
|
|
vp9_tree tree,
|
|
|
|
vp9_prob probs[],
|
|
|
|
unsigned int branch_ct[][2],
|
|
|
|
const unsigned int num_events[],
|
|
|
|
unsigned int tok0_offset) {
|
|
|
|
unsigned int left, right;
|
|
|
|
|
|
|
|
if (tree[i] <= 0) {
|
|
|
|
left = num_events[-tree[i] - tok0_offset];
|
|
|
|
} else {
|
|
|
|
left = convert_distribution(tree[i], tree, probs, branch_ct,
|
|
|
|
num_events, tok0_offset);
|
|
|
|
}
|
2013-05-01 01:39:07 +02:00
|
|
|
if (tree[i + 1] <= 0)
|
2013-03-10 21:39:30 +01:00
|
|
|
right = num_events[-tree[i + 1] - tok0_offset];
|
2013-05-01 01:39:07 +02:00
|
|
|
else
|
2013-03-10 21:39:30 +01:00
|
|
|
right = convert_distribution(tree[i + 1], tree, probs, branch_ct,
|
2013-05-01 01:39:07 +02:00
|
|
|
num_events, tok0_offset);
|
|
|
|
|
2013-03-10 21:39:30 +01:00
|
|
|
probs[i>>1] = get_binary_prob(left, right);
|
|
|
|
branch_ct[i>>1][0] = left;
|
|
|
|
branch_ct[i>>1][1] = right;
|
|
|
|
return left + right;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 00:25:53 +01:00
|
|
|
void vp9_tree_probs_from_distribution(
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_tree tree,
|
|
|
|
vp9_prob probs [ /* n-1 */ ],
|
2012-07-14 00:21:29 +02:00
|
|
|
unsigned int branch_ct [ /* n-1 */ ] [2],
|
2013-03-10 21:39:30 +01:00
|
|
|
const unsigned int num_events[ /* n */ ],
|
|
|
|
unsigned int tok0_offset) {
|
|
|
|
convert_distribution(0, tree, probs, branch_ct, num_events, tok0_offset);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|