2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2013-12-16 21:53:09 +01:00
|
|
|
* Copyright (c) 2013 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
|
|
|
*/
|
|
|
|
|
2013-12-16 21:53:09 +01:00
|
|
|
#ifndef VP9_COMMON_VP9_PROB_H_
|
|
|
|
#define VP9_COMMON_VP9_PROB_H_
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-02-06 21:45:28 +01:00
|
|
|
#include "./vpx_config.h"
|
2013-12-16 21:53:09 +01:00
|
|
|
|
|
|
|
#include "vpx_ports/mem.h"
|
|
|
|
|
2013-04-11 20:08:00 +02:00
|
|
|
#include "vp9/common/vp9_common.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
|
|
|
|
2014-01-18 21:16:11 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
typedef uint8_t vp9_prob;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-12-21 00:56:59 +01:00
|
|
|
#define MAX_PROB 255
|
|
|
|
|
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
|
|
|
|
2013-10-12 01:25:50 +02:00
|
|
|
#define TREE_SIZE(leaf_count) (2 * (leaf_count) - 2)
|
|
|
|
|
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. */
|
|
|
|
|
2013-10-11 02:16:20 +02:00
|
|
|
typedef const vp9_tree_index vp9_tree[];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-02-06 21:45:28 +01:00
|
|
|
static INLINE vp9_prob clip_prob(int p) {
|
2014-08-01 15:29:32 +02:00
|
|
|
return (p > 255) ? 255 : (p < 1) ? 1 : 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
|
|
|
}
|
|
|
|
|
2013-02-19 19:12:00 +01:00
|
|
|
static INLINE vp9_prob get_prob(int num, int den) {
|
|
|
|
return (den == 0) ? 128u : clip_prob(((int64_t)num * 256 + (den >> 1)) / den);
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2014-01-15 18:53:03 +01:00
|
|
|
/* 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) {
|
2013-04-11 20:08:00 +02:00
|
|
|
return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8);
|
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
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-11-01 23:09:43 +01:00
|
|
|
static INLINE vp9_prob merge_probs(vp9_prob pre_prob,
|
2013-07-25 02:44:04 +02:00
|
|
|
const unsigned int ct[2],
|
|
|
|
unsigned int count_sat,
|
|
|
|
unsigned int max_update_factor) {
|
2013-11-01 23:09:43 +01:00
|
|
|
const vp9_prob prob = get_binary_prob(ct[0], ct[1]);
|
2013-07-25 02:44:04 +02:00
|
|
|
const unsigned int count = MIN(ct[0] + ct[1], count_sat);
|
|
|
|
const unsigned int factor = max_update_factor * count / count_sat;
|
|
|
|
return weighted_prob(pre_prob, prob, factor);
|
|
|
|
}
|
|
|
|
|
2014-02-10 16:39:12 +01:00
|
|
|
void vp9_tree_merge_probs(const vp9_tree_index *tree, const vp9_prob *pre_probs,
|
|
|
|
const unsigned int *counts, unsigned int count_sat,
|
|
|
|
unsigned int max_update_factor, vp9_prob *probs);
|
2013-11-05 01:12:29 +01:00
|
|
|
|
|
|
|
|
2013-12-16 21:53:09 +01:00
|
|
|
DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]);
|
2013-07-25 02:44:04 +02:00
|
|
|
|
2014-01-18 21:16:11 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2013-12-16 21:53:09 +01:00
|
|
|
#endif // VP9_COMMON_VP9_PROB_H_
|