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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2013-06-28 19:36:20 +02:00
|
|
|
#include "./vpx_config.h"
|
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;
|
2013-09-30 04:37:11 +02:00
|
|
|
} else {
|
2013-04-11 22:01:52 +02:00
|
|
|
tree2tok(p, t, j, v, l);
|
2013-09-30 04:37:11 +02:00
|
|
|
}
|
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-11-01 23:09:43 +01:00
|
|
|
static unsigned int convert_distribution(unsigned int i, vp9_tree tree,
|
2013-03-10 21:39:30 +01:00
|
|
|
unsigned int branch_ct[][2],
|
2013-11-05 20:58:57 +01:00
|
|
|
const unsigned int num_events[]) {
|
2013-03-10 21:39:30 +01:00
|
|
|
unsigned int left, right;
|
|
|
|
|
2013-11-05 20:58:57 +01:00
|
|
|
if (tree[i] <= 0)
|
|
|
|
left = num_events[-tree[i]];
|
|
|
|
else
|
|
|
|
left = convert_distribution(tree[i], tree, branch_ct, num_events);
|
|
|
|
|
2013-05-01 01:39:07 +02:00
|
|
|
if (tree[i + 1] <= 0)
|
2013-11-05 20:58:57 +01:00
|
|
|
right = num_events[-tree[i + 1]];
|
2013-05-01 01:39:07 +02:00
|
|
|
else
|
2013-11-05 20:58:57 +01:00
|
|
|
right = convert_distribution(tree[i + 1], tree, branch_ct, num_events);
|
2013-05-01 01:39:07 +02:00
|
|
|
|
2013-11-01 23:09:43 +01:00
|
|
|
branch_ct[i >> 1][0] = left;
|
|
|
|
branch_ct[i >> 1][1] = right;
|
2013-03-10 21:39:30 +01:00
|
|
|
return left + right;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-11-01 23:09:43 +01:00
|
|
|
void vp9_tree_probs_from_distribution(vp9_tree tree,
|
2013-09-30 04:37:11 +02:00
|
|
|
unsigned int branch_ct[/* n-1 */][2],
|
2013-11-05 20:58:57 +01:00
|
|
|
const unsigned int num_events[/* n */]) {
|
|
|
|
convert_distribution(0, tree, branch_ct, num_events);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2013-11-01 23:09:43 +01:00
|
|
|
|
|
|
|
|