2010-05-18 19:58:33 +04:00
|
|
|
/*
|
2016-09-02 00:32:49 +03:00
|
|
|
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
2010-05-18 19:58:33 +04:00
|
|
|
*
|
2016-09-02 00:32:49 +03:00
|
|
|
* This source code is subject to the terms of the BSD 2 Clause License and
|
|
|
|
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
|
|
|
|
* was not distributed with this source code in the LICENSE file, you can
|
|
|
|
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
|
|
|
|
* Media Patent License 1.0 was not distributed with this source code in the
|
|
|
|
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
|
2010-05-18 19:58:33 +04:00
|
|
|
*/
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
#ifndef AOM_DSP_PROB_H_
|
|
|
|
#define AOM_DSP_PROB_H_
|
2010-05-18 19:58:33 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
#include "./aom_config.h"
|
|
|
|
#include "./aom_dsp_common.h"
|
2013-12-17 00:53:09 +04:00
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
#include "aom_ports/mem.h"
|
2013-12-17 00:53:09 +04:00
|
|
|
|
2014-01-19 00:16:11 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
typedef uint8_t aom_prob;
|
2010-05-18 19:58:33 +04:00
|
|
|
|
2013-12-21 03:56:59 +04:00
|
|
|
#define MAX_PROB 255
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
#define aom_prob_half ((aom_prob)128)
|
2010-05-18 19:58:33 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
typedef int8_t aom_tree_index;
|
2010-05-18 19:58:33 +04:00
|
|
|
|
2016-08-09 08:59:08 +03:00
|
|
|
#define TREE_SIZE(leaf_count) (2 * (leaf_count)-2)
|
2013-10-12 03:25:50 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
#define aom_complement(x) (255 - x)
|
2010-05-18 19:58:33 +04:00
|
|
|
|
2015-01-23 02:27:43 +03:00
|
|
|
#define MODE_MV_COUNT_SAT 20
|
|
|
|
|
2010-05-18 19:58:33 +04:00
|
|
|
/* We build coding trees compactly in arrays.
|
2016-08-31 00:01:10 +03:00
|
|
|
Each node of the tree is a pair of aom_tree_indices.
|
2010-05-18 19: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. */
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
typedef const aom_tree_index aom_tree[];
|
2010-05-18 19:58:33 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
static INLINE aom_prob clip_prob(int p) {
|
2014-08-01 17:29:32 +04: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-11 00:09:07 +04:00
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
static INLINE aom_prob get_prob(int num, int den) {
|
2013-02-19 22:12:00 +04:00
|
|
|
return (den == 0) ? 128u : clip_prob(((int64_t)num * 256 + (den >> 1)) / den);
|
|
|
|
}
|
2012-11-16 03:50:07 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
static INLINE aom_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-11 00:09:07 +04:00
|
|
|
return get_prob(n0, n0 + n1);
|
|
|
|
}
|
|
|
|
|
2014-01-15 21:53:03 +04:00
|
|
|
/* This function assumes prob1 and prob2 are already within [1,255] range. */
|
2016-08-31 00:01:10 +03:00
|
|
|
static INLINE aom_prob weighted_prob(int prob1, int prob2, int factor) {
|
2013-04-11 22:08:00 +04: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-11 00:09:07 +04:00
|
|
|
}
|
2010-05-18 19:58:33 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
static INLINE aom_prob merge_probs(aom_prob pre_prob, const unsigned int ct[2],
|
2013-07-25 04:44:04 +04:00
|
|
|
unsigned int count_sat,
|
|
|
|
unsigned int max_update_factor) {
|
2016-08-31 00:01:10 +03:00
|
|
|
const aom_prob prob = get_binary_prob(ct[0], ct[1]);
|
|
|
|
const unsigned int count = AOMMIN(ct[0] + ct[1], count_sat);
|
2013-07-25 04:44:04 +04:00
|
|
|
const unsigned int factor = max_update_factor * count / count_sat;
|
|
|
|
return weighted_prob(pre_prob, prob, factor);
|
|
|
|
}
|
|
|
|
|
2015-01-23 02:27:43 +03:00
|
|
|
// MODE_MV_MAX_UPDATE_FACTOR (128) * count / MODE_MV_COUNT_SAT;
|
|
|
|
static const int count_to_update_factor[MODE_MV_COUNT_SAT + 1] = {
|
2016-08-09 08:59:08 +03:00
|
|
|
0, 6, 12, 19, 25, 32, 38, 44, 51, 57, 64,
|
2015-01-23 02:27:43 +03:00
|
|
|
70, 76, 83, 89, 96, 102, 108, 115, 121, 128
|
|
|
|
};
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
static INLINE aom_prob mode_mv_merge_probs(aom_prob pre_prob,
|
2015-01-23 02:27:43 +03:00
|
|
|
const unsigned int ct[2]) {
|
|
|
|
const unsigned int den = ct[0] + ct[1];
|
|
|
|
if (den == 0) {
|
|
|
|
return pre_prob;
|
|
|
|
} else {
|
2016-08-31 00:01:10 +03:00
|
|
|
const unsigned int count = AOMMIN(den, MODE_MV_COUNT_SAT);
|
2015-01-23 02:27:43 +03:00
|
|
|
const unsigned int factor = count_to_update_factor[count];
|
2016-08-31 00:01:10 +03:00
|
|
|
const aom_prob prob =
|
2015-01-23 02:27:43 +03:00
|
|
|
clip_prob(((int64_t)(ct[0]) * 256 + (den >> 1)) / den);
|
|
|
|
return weighted_prob(pre_prob, prob, factor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
void aom_tree_merge_probs(const aom_tree_index *tree, const aom_prob *pre_probs,
|
|
|
|
const unsigned int *counts, aom_prob *probs);
|
2013-11-05 04:12:29 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
DECLARE_ALIGNED(16, extern const uint8_t, aom_norm[256]);
|
2013-07-25 04:44:04 +04:00
|
|
|
|
2014-01-19 00:16:11 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
#endif // AOM_DSP_PROB_H_
|