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
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/common/vp9_treecoder.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
static void tree2tok(
|
2012-10-31 22:40:53 +01:00
|
|
|
struct vp9_token_struct *const p,
|
|
|
|
vp9_tree t,
|
2012-07-14 00:21:29 +02:00
|
|
|
int i,
|
|
|
|
int v,
|
|
|
|
int L
|
|
|
|
) {
|
|
|
|
v += v;
|
|
|
|
++L;
|
|
|
|
|
|
|
|
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;
|
|
|
|
p[-j].Len = L;
|
|
|
|
} else
|
|
|
|
tree2tok(p, t, j, v, L);
|
|
|
|
} while (++v & 1);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
void vp9_tokens_from_tree(struct vp9_token_struct *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
|
|
|
}
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
void vp9_tokens_from_tree_offset(struct vp9_token_struct *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
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
static void branch_counts(
|
2012-07-14 00:21:29 +02:00
|
|
|
int n, /* n = size of alphabet */
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_token tok [ /* n */ ],
|
|
|
|
vp9_tree tree,
|
2012-07-14 00:21:29 +02:00
|
|
|
unsigned int branch_ct [ /* n-1 */ ] [2],
|
|
|
|
const unsigned int num_events[ /* n */ ]
|
|
|
|
) {
|
|
|
|
const int tree_len = n - 1;
|
|
|
|
int t = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#if CONFIG_DEBUG
|
2012-07-14 00:21:29 +02:00
|
|
|
assert(tree_len);
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
do {
|
|
|
|
branch_ct[t][0] = branch_ct[t][1] = 0;
|
|
|
|
} while (++t < tree_len);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
t = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
do {
|
|
|
|
int L = tok[t].Len;
|
|
|
|
const int enc = tok[t].value;
|
|
|
|
const unsigned int ct = num_events[t];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_tree_index i = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
do {
|
|
|
|
const int b = (enc >> --L) & 1;
|
|
|
|
const int j = i >> 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
#if CONFIG_DEBUG
|
2012-07-14 00:21:29 +02:00
|
|
|
assert(j < tree_len && 0 <= L);
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
branch_ct [j] [b] += ct;
|
|
|
|
i = tree[ i + b];
|
|
|
|
} while (i > 0);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#if CONFIG_DEBUG
|
2012-07-14 00:21:29 +02:00
|
|
|
assert(!L);
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
2012-07-14 00:21:29 +02:00
|
|
|
} while (++t < n);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-31 00:25:53 +01:00
|
|
|
void vp9_tree_probs_from_distribution(
|
2012-07-14 00:21:29 +02:00
|
|
|
int n, /* n = size of alphabet */
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_token tok [ /* n */ ],
|
|
|
|
vp9_tree tree,
|
|
|
|
vp9_prob probs [ /* n-1 */ ],
|
2012-07-14 00:21:29 +02:00
|
|
|
unsigned int branch_ct [ /* n-1 */ ] [2],
|
Consistently use get_prob(), clip_prob() and newly added clip_pixel().
Add a function clip_pixel() to clip a pixel value to the [0,255] range
of allowed values, and use this where-ever appropriate (e.g. prediction,
reconstruction). Likewise, consistently use the recently added function
clip_prob(), which calculates a binary probability in the [1,255] range.
If possible, try to use get_prob() or its sister get_binary_prob() to
calculate binary probabilities, for consistency.
Since in some places, this means that binary probability calculations
are changed (we use {255,256}*count0/(total) in a range of places,
and all of these are now changed to use 256*count0+(total>>1)/total),
this changes the encoding result, so this patch warrants some extensive
testing.
Change-Id: Ibeeff8d886496839b8e0c0ace9ccc552351f7628
2012-12-10 21:09:07 +01:00
|
|
|
const unsigned int num_events[ /* n */ ]
|
2012-07-14 00:21:29 +02:00
|
|
|
) {
|
|
|
|
const int tree_len = n - 1;
|
|
|
|
int t = 0;
|
|
|
|
|
|
|
|
branch_counts(n, tok, tree, branch_ct, num_events);
|
|
|
|
|
|
|
|
do {
|
Consistently use get_prob(), clip_prob() and newly added clip_pixel().
Add a function clip_pixel() to clip a pixel value to the [0,255] range
of allowed values, and use this where-ever appropriate (e.g. prediction,
reconstruction). Likewise, consistently use the recently added function
clip_prob(), which calculates a binary probability in the [1,255] range.
If possible, try to use get_prob() or its sister get_binary_prob() to
calculate binary probabilities, for consistency.
Since in some places, this means that binary probability calculations
are changed (we use {255,256}*count0/(total) in a range of places,
and all of these are now changed to use 256*count0+(total>>1)/total),
this changes the encoding result, so this patch warrants some extensive
testing.
Change-Id: Ibeeff8d886496839b8e0c0ace9ccc552351f7628
2012-12-10 21:09:07 +01:00
|
|
|
probs[t] = get_binary_prob(branch_ct[t][0], branch_ct[t][1]);
|
2012-07-14 00:21:29 +02:00
|
|
|
} while (++t < tree_len);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|