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-11-30 01:36:10 +01:00
|
|
|
#ifndef VP9_COMMON_VP9_TREECODER_H_
|
|
|
|
#define VP9_COMMON_VP9_TREECODER_H_
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-02-06 21:45:28 +01:00
|
|
|
#include "./vpx_config.h"
|
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
|
|
|
#include "vpx/vpx_integer.h"
|
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
typedef uint8_t vp9_prob;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
#define vp9_prob_half ((vp9_prob) 128)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
typedef int8_t vp9_tree_index;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
#define vp9_complement(x) (255 - x)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
/* We build coding trees compactly in arrays.
|
2012-10-31 22:40:53 +01:00
|
|
|
Each node of the tree is a pair of vp9_tree_indices.
|
2010-05-18 17:58:33 +02:00
|
|
|
Array index often references a corresponding probability table.
|
|
|
|
Index <= 0 means done encoding/decoding and value = -Index,
|
|
|
|
Index > 0 means need another bit, specification at index.
|
|
|
|
Nonnegative indices are always even; processing begins at node 0. */
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
typedef const vp9_tree_index vp9_tree[], *vp9_tree_p;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
typedef const struct vp9_token_struct {
|
2012-07-14 00:21:29 +02:00
|
|
|
int value;
|
|
|
|
int Len;
|
2012-10-31 22:40:53 +01:00
|
|
|
} vp9_token;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
/* Construct encoding array from tree. */
|
|
|
|
|
2012-10-31 22:40:53 +01:00
|
|
|
void vp9_tokens_from_tree(struct vp9_token_struct *, vp9_tree);
|
|
|
|
void vp9_tokens_from_tree_offset(struct vp9_token_struct *, vp9_tree,
|
2010-08-09 19:27:26 +02:00
|
|
|
int offset);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
/* Convert array of token occurrence counts into a table of probabilities
|
|
|
|
for the associated binary encoding tree. Also writes count of branches
|
|
|
|
taken for each node on the tree; this facilitiates decisions as to
|
|
|
|
probability updates. */
|
|
|
|
|
2013-03-10 21:39:30 +01:00
|
|
|
void vp9_tree_probs_from_distribution(vp9_tree tree,
|
2012-12-19 00:31:19 +01:00
|
|
|
vp9_prob probs[ /* n - 1 */ ],
|
|
|
|
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);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-02-06 21:45:28 +01:00
|
|
|
static INLINE vp9_prob clip_prob(int p) {
|
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
|
|
|
return (p > 255) ? 255u : (p < 1) ? 1u : p;
|
|
|
|
}
|
|
|
|
|
2013-02-19 19:12:00 +01:00
|
|
|
// int64 is not needed for normal frame level calculations.
|
|
|
|
// However when outputing entropy stats accumulated over many frames
|
|
|
|
// or even clips we can overflow int math.
|
|
|
|
#ifdef ENTROPY_STATS
|
|
|
|
static INLINE vp9_prob get_prob(int num, int den) {
|
|
|
|
return (den == 0) ? 128u : clip_prob(((int64_t)num * 256 + (den >> 1)) / den);
|
|
|
|
}
|
|
|
|
#else
|
2013-02-06 21:45:28 +01:00
|
|
|
static INLINE vp9_prob get_prob(int num, int den) {
|
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
|
|
|
return (den == 0) ? 128u : clip_prob((num * 256 + (den >> 1)) / den);
|
2012-11-16 00:50:07 +01:00
|
|
|
}
|
2013-02-19 19:12:00 +01:00
|
|
|
#endif
|
2012-11-16 00:50:07 +01:00
|
|
|
|
2013-02-06 21:45:28 +01:00
|
|
|
static INLINE vp9_prob get_binary_prob(int n0, int n1) {
|
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
|
|
|
return get_prob(n0, n0 + n1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this function assumes prob1 and prob2 are already within [1,255] range */
|
2013-02-06 21:45:28 +01:00
|
|
|
static INLINE vp9_prob weighted_prob(int prob1, int prob2, int factor) {
|
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
|
|
|
return (prob1 * (256 - factor) + prob2 * factor + 128) >> 8;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
#endif // VP9_COMMON_VP9_TREECODER_H_
|