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