Removing duplicated code for merging two probabilities.

Adding common merge_probs and merge_probs2 functions. Changing ints to
usigned ints in some places.

Change-Id: Icf088ffdea7cf5b95284a128916409bdd53506b0
This commit is contained in:
Dmitry Kovalev 2013-07-24 17:44:04 -07:00
parent fcc34796d2
commit 40358dc406
4 changed files with 41 additions and 45 deletions

View File

@ -614,7 +614,8 @@ void vp9_coef_tree_initialize() {
#define COEF_MAX_UPDATE_FACTOR_AFTER_KEY 128
static void adapt_coef_probs(VP9_COMMON *cm, TX_SIZE txfm_size,
int count_sat, int update_factor) {
unsigned int count_sat,
unsigned int update_factor) {
FRAME_CONTEXT *pre_fc = &cm->frame_contexts[cm->frame_context_idx];
vp9_coeff_probs_model *dst_coef_probs = cm->fc.coef_probs[txfm_size];
@ -622,8 +623,7 @@ static void adapt_coef_probs(VP9_COMMON *cm, TX_SIZE txfm_size,
vp9_coeff_count_model *coef_counts = cm->counts.coef[txfm_size];
unsigned int (*eob_branch_count)[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS] =
cm->counts.eob_branch[txfm_size];
int t, i, j, k, l, count;
int factor;
int t, i, j, k, l;
unsigned int branch_ct[UNCONSTRAINED_NODES][2];
vp9_prob coef_probs[UNCONSTRAINED_NODES];
int entropy_nodes_adapt = UNCONSTRAINED_NODES;
@ -634,29 +634,23 @@ static void adapt_coef_probs(VP9_COMMON *cm, TX_SIZE txfm_size,
for (l = 0; l < PREV_COEF_CONTEXTS; ++l) {
if (l >= 3 && k == 0)
continue;
vp9_tree_probs_from_distribution(
vp9_coefmodel_tree,
coef_probs, branch_ct,
coef_counts[i][j][k][l], 0);
vp9_tree_probs_from_distribution(vp9_coefmodel_tree, coef_probs,
branch_ct, coef_counts[i][j][k][l],
0);
branch_ct[0][1] = eob_branch_count[i][j][k][l] - branch_ct[0][0];
coef_probs[0] = get_binary_prob(branch_ct[0][0], branch_ct[0][1]);
for (t = 0; t < entropy_nodes_adapt; ++t) {
count = branch_ct[t][0] + branch_ct[t][1];
count = count > count_sat ? count_sat : count;
factor = (update_factor * count / count_sat);
dst_coef_probs[i][j][k][l][t] =
weighted_prob(pre_coef_probs[i][j][k][l][t],
coef_probs[t], factor);
}
for (t = 0; t < entropy_nodes_adapt; ++t)
dst_coef_probs[i][j][k][l][t] = merge_probs(
pre_coef_probs[i][j][k][l][t], coef_probs[t],
branch_ct[t], count_sat, update_factor);
}
}
void vp9_adapt_coef_probs(VP9_COMMON *cm) {
TX_SIZE t;
int count_sat;
int update_factor; /* denominator 256 */
unsigned int count_sat, update_factor;
if ((cm->frame_type == KEY_FRAME) || cm->intra_only) {
if (cm->frame_type == KEY_FRAME || cm->intra_only) {
update_factor = COEF_MAX_UPDATE_FACTOR_KEY;
count_sat = COEF_COUNT_SAT_KEY;
} else if (cm->last_frame_type == KEY_FRAME) {

View File

@ -387,15 +387,12 @@ void vp9_accum_mv_refs(VP9_COMMON *pc,
#define COUNT_SAT 20
#define MAX_UPDATE_FACTOR 128
static int update_ct(vp9_prob pre_prob, vp9_prob prob,
unsigned int ct[2]) {
const int count = MIN(ct[0] + ct[1], COUNT_SAT);
const int factor = MAX_UPDATE_FACTOR * count / COUNT_SAT;
return weighted_prob(pre_prob, prob, factor);
static int update_ct(vp9_prob pre_prob, vp9_prob prob, unsigned int ct[2]) {
return merge_probs(pre_prob, prob, ct, COUNT_SAT, MAX_UPDATE_FACTOR);
}
static int update_ct2(vp9_prob pre_prob, unsigned int ct[2]) {
return update_ct(pre_prob, get_binary_prob(ct[0], ct[1]), ct);
return merge_probs2(pre_prob, ct, COUNT_SAT, MAX_UPDATE_FACTOR);
}
void vp9_adapt_mode_context(VP9_COMMON *pc) {

View File

@ -175,14 +175,7 @@ void vp9_inc_mv(const MV *mv, nmv_context_counts *mvctx) {
}
static void adapt_prob(vp9_prob *dest, vp9_prob prep, unsigned int ct[2]) {
const int count = MIN(ct[0] + ct[1], MV_COUNT_SAT);
if (count) {
const vp9_prob newp = get_binary_prob(ct[0], ct[1]);
const int factor = MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT;
*dest = weighted_prob(prep, newp, factor);
} else {
*dest = prep;
}
*dest = merge_probs2(prep, ct, MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR);
}
void vp9_counts_process(nmv_context_counts *nmv_count, int usehp) {
@ -195,26 +188,20 @@ static unsigned int adapt_probs(unsigned int i,
vp9_prob this_probs[],
const vp9_prob last_probs[],
const unsigned int num_events[]) {
vp9_prob this_prob;
const uint32_t left = tree[i] <= 0
const unsigned int left = tree[i] <= 0
? num_events[-tree[i]]
: adapt_probs(tree[i], tree, this_probs, last_probs, num_events);
const uint32_t right = tree[i + 1] <= 0
const unsigned int right = tree[i + 1] <= 0
? num_events[-tree[i + 1]]
: adapt_probs(tree[i + 1], tree, this_probs, last_probs, num_events);
uint32_t weight = left + right;
if (weight) {
this_prob = get_binary_prob(left, right);
weight = weight > MV_COUNT_SAT ? MV_COUNT_SAT : weight;
this_prob = weighted_prob(last_probs[i >> 1], this_prob,
MV_MAX_UPDATE_FACTOR * weight / MV_COUNT_SAT);
} else {
this_prob = last_probs[i >> 1];
}
this_probs[i >> 1] = this_prob;
const unsigned int ct[2] = { left, right };
this_probs[i >> 1] = merge_probs2(last_probs[i >> 1], ct,
MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR);
return left + right;
}

View File

@ -79,4 +79,22 @@ static INLINE vp9_prob weighted_prob(int prob1, int prob2, int factor) {
return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8);
}
static INLINE vp9_prob merge_probs(vp9_prob pre_prob, vp9_prob prob,
const unsigned int ct[2],
unsigned int count_sat,
unsigned int max_update_factor) {
const unsigned int count = MIN(ct[0] + ct[1], count_sat);
const unsigned int factor = max_update_factor * count / count_sat;
return weighted_prob(pre_prob, prob, factor);
}
static INLINE vp9_prob merge_probs2(vp9_prob pre_prob,
const unsigned int ct[2],
unsigned int count_sat,
unsigned int max_update_factor) {
return merge_probs(pre_prob, get_binary_prob(ct[0], ct[1]), ct, count_sat,
max_update_factor);
}
#endif // VP9_COMMON_VP9_TREECODER_H_