2010-05-18 11:58:33 -04:00
|
|
|
/*
|
2013-12-16 12:53:09 -08:00
|
|
|
* Copyright (c) 2013 The WebM project authors. All Rights Reserved.
|
2010-05-18 11:58:33 -04:00
|
|
|
*
|
2010-06-18 12:39:21 -04:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 16:19:40 -04: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 12:39:21 -04:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 16:19:40 -04:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 11:58:33 -04:00
|
|
|
*/
|
|
|
|
|
2015-07-17 14:09:05 -07:00
|
|
|
#ifndef VPX_DSP_PROB_H_
|
|
|
|
#define VPX_DSP_PROB_H_
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2013-02-06 12:45:28 -08:00
|
|
|
#include "./vpx_config.h"
|
2015-07-17 13:38:54 -07:00
|
|
|
#include "./vpx_dsp_common.h"
|
2013-12-16 12:53:09 -08:00
|
|
|
|
|
|
|
#include "vpx_ports/mem.h"
|
|
|
|
|
2014-01-18 12:16:11 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-07-20 13:49:15 -07:00
|
|
|
typedef uint8_t vpx_prob;
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2013-12-20 15:56:59 -08:00
|
|
|
#define MAX_PROB 255
|
|
|
|
|
2015-07-20 13:49:15 -07:00
|
|
|
#define vpx_prob_half ((vpx_prob) 128)
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2015-07-20 14:04:21 -07:00
|
|
|
typedef int8_t vpx_tree_index;
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2013-10-11 16:25:50 -07:00
|
|
|
#define TREE_SIZE(leaf_count) (2 * (leaf_count) - 2)
|
|
|
|
|
2015-07-20 14:04:21 -07:00
|
|
|
#define vpx_complement(x) (255 - x)
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2015-01-22 15:27:43 -08:00
|
|
|
#define MODE_MV_COUNT_SAT 20
|
|
|
|
|
2010-05-18 11:58:33 -04:00
|
|
|
/* We build coding trees compactly in arrays.
|
2015-07-20 14:04:21 -07:00
|
|
|
Each node of the tree is a pair of vpx_tree_indices.
|
2010-05-18 11:58:33 -04: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. */
|
|
|
|
|
2015-07-20 14:04:21 -07:00
|
|
|
typedef const vpx_tree_index vpx_tree[];
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2015-07-20 13:49:15 -07:00
|
|
|
static INLINE vpx_prob clip_prob(int p) {
|
2014-08-01 06:29:32 -07: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 12:09:07 -08:00
|
|
|
}
|
|
|
|
|
2015-07-20 13:49:15 -07:00
|
|
|
static INLINE vpx_prob get_prob(int num, int den) {
|
2013-02-19 10:12:00 -08:00
|
|
|
return (den == 0) ? 128u : clip_prob(((int64_t)num * 256 + (den >> 1)) / den);
|
|
|
|
}
|
2012-11-15 15:50:07 -08:00
|
|
|
|
2015-07-20 13:49:15 -07:00
|
|
|
static INLINE vpx_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 12:09:07 -08:00
|
|
|
return get_prob(n0, n0 + n1);
|
|
|
|
}
|
|
|
|
|
2014-01-15 09:53:03 -08:00
|
|
|
/* This function assumes prob1 and prob2 are already within [1,255] range. */
|
2015-07-20 13:49:15 -07:00
|
|
|
static INLINE vpx_prob weighted_prob(int prob1, int prob2, int factor) {
|
2013-04-11 11:08:00 -07: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 12:09:07 -08:00
|
|
|
}
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2015-07-20 13:49:15 -07:00
|
|
|
static INLINE vpx_prob merge_probs(vpx_prob pre_prob,
|
2013-07-24 17:44:04 -07:00
|
|
|
const unsigned int ct[2],
|
|
|
|
unsigned int count_sat,
|
|
|
|
unsigned int max_update_factor) {
|
2015-07-20 13:49:15 -07:00
|
|
|
const vpx_prob prob = get_binary_prob(ct[0], ct[1]);
|
2015-08-17 18:19:22 -07:00
|
|
|
const unsigned int count = VPXMIN(ct[0] + ct[1], count_sat);
|
2013-07-24 17:44:04 -07:00
|
|
|
const unsigned int factor = max_update_factor * count / count_sat;
|
|
|
|
return weighted_prob(pre_prob, prob, factor);
|
|
|
|
}
|
|
|
|
|
2015-01-22 15:27:43 -08:00
|
|
|
// MODE_MV_MAX_UPDATE_FACTOR (128) * count / MODE_MV_COUNT_SAT;
|
|
|
|
static const int count_to_update_factor[MODE_MV_COUNT_SAT + 1] = {
|
|
|
|
0, 6, 12, 19, 25, 32, 38, 44, 51, 57, 64,
|
|
|
|
70, 76, 83, 89, 96, 102, 108, 115, 121, 128
|
|
|
|
};
|
|
|
|
|
2015-07-20 13:49:15 -07:00
|
|
|
static INLINE vpx_prob mode_mv_merge_probs(vpx_prob pre_prob,
|
2015-01-22 15:27:43 -08:00
|
|
|
const unsigned int ct[2]) {
|
|
|
|
const unsigned int den = ct[0] + ct[1];
|
|
|
|
if (den == 0) {
|
|
|
|
return pre_prob;
|
|
|
|
} else {
|
2015-08-17 18:19:22 -07:00
|
|
|
const unsigned int count = VPXMIN(den, MODE_MV_COUNT_SAT);
|
2015-01-22 15:27:43 -08:00
|
|
|
const unsigned int factor = count_to_update_factor[count];
|
2015-07-20 13:49:15 -07:00
|
|
|
const vpx_prob prob =
|
2015-01-22 15:27:43 -08:00
|
|
|
clip_prob(((int64_t)(ct[0]) * 256 + (den >> 1)) / den);
|
|
|
|
return weighted_prob(pre_prob, prob, factor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-20 14:04:21 -07:00
|
|
|
void vpx_tree_merge_probs(const vpx_tree_index *tree, const vpx_prob *pre_probs,
|
2015-07-20 13:49:15 -07:00
|
|
|
const unsigned int *counts, vpx_prob *probs);
|
2013-11-04 16:12:29 -08:00
|
|
|
|
|
|
|
|
2015-07-20 14:04:21 -07:00
|
|
|
DECLARE_ALIGNED(16, extern const uint8_t, vpx_norm[256]);
|
2013-07-24 17:44:04 -07:00
|
|
|
|
2014-01-18 12:16:11 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2015-07-17 14:09:05 -07:00
|
|
|
#endif // VPX_DSP_PROB_H_
|