diff options
Diffstat (limited to 'vp9/common/vp9_treecoder.h')
-rw-r--r-- | vp9/common/vp9_treecoder.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/vp9/common/vp9_treecoder.h b/vp9/common/vp9_treecoder.h index 8eca8a8bc..f9f1d135e 100644 --- a/vp9/common/vp9_treecoder.h +++ b/vp9/common/vp9_treecoder.h @@ -58,9 +58,18 @@ static INLINE vp9_prob clip_prob(int p) { return (p > 255) ? 255u : (p < 1) ? 1u : p; } +// 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 static INLINE vp9_prob get_prob(int num, int den) { return (den == 0) ? 128u : clip_prob((num * 256 + (den >> 1)) / den); } +#endif static INLINE vp9_prob get_binary_prob(int n0, int n1) { return get_prob(n0, n0 + n1); |