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
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
#ifndef VP9_COMMON_VP9_TREECODER_H_
|
||||
#define VP9_COMMON_VP9_TREECODER_H_
|
||||
|
||||
#include "vpx/vpx_integer.h"
|
||||
|
||||
typedef unsigned char vp9_prob;
|
||||
|
||||
#define vp9_prob_half ( (vp9_prob) 128)
|
||||
@@ -65,19 +67,24 @@ void vp9_tree_probs_from_distribution(
|
||||
vp9_tree tree,
|
||||
vp9_prob probs [ /* n-1 */ ],
|
||||
unsigned int branch_ct [ /* n-1 */ ] [2],
|
||||
const unsigned int num_events[ /* n */ ],
|
||||
unsigned int Pfactor,
|
||||
int Round
|
||||
const unsigned int num_events[ /* n */ ]
|
||||
);
|
||||
|
||||
static __inline int clip_prob(int p) {
|
||||
if (p > 255)
|
||||
return 255;
|
||||
else if (p < 1)
|
||||
return 1;
|
||||
return p;
|
||||
static __inline vp9_prob clip_prob(int p) {
|
||||
return (p > 255) ? 255u : (p < 1) ? 1u : p;
|
||||
}
|
||||
|
||||
vp9_prob vp9_bin_prob_from_distribution(const unsigned int counts[2]);
|
||||
static __inline vp9_prob get_prob(int num, int den) {
|
||||
return (den == 0) ? 128u : clip_prob((num * 256 + (den >> 1)) / den);
|
||||
}
|
||||
|
||||
static __inline vp9_prob get_binary_prob(int n0, int n1) {
|
||||
return get_prob(n0, n0 + n1);
|
||||
}
|
||||
|
||||
/* this function assumes prob1 and prob2 are already within [1,255] range */
|
||||
static __inline vp9_prob weighted_prob(int prob1, int prob2, int factor) {
|
||||
return (prob1 * (256 - factor) + prob2 * factor + 128) >> 8;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user