Commit bfcef95c authored by Dmitry Kovalev's avatar Dmitry Kovalev
Browse files

Adding update_tx_ct function, removing duplicated code.

Change-Id: I8882fe3cd247a5a8304ab8ab2ee9abdb92830133
Showing with 32 additions and 49 deletions
...@@ -304,14 +304,24 @@ void vp9_adapt_mode_context(VP9_COMMON *pc) { ...@@ -304,14 +304,24 @@ void vp9_adapt_mode_context(VP9_COMMON *pc) {
#define MODE_COUNT_SAT 20 #define MODE_COUNT_SAT 20
#define MODE_MAX_UPDATE_FACTOR 128 #define MODE_MAX_UPDATE_FACTOR 128
static int update_mode_ct(vp9_prob pre_prob, vp9_prob prob, static int update_mode_ct(vp9_prob pre_prob, vp9_prob prob,
unsigned int branch_ct[2]) { unsigned int ct[2]) {
int factor, count = branch_ct[0] + branch_ct[1]; const int count = MIN(ct[0] + ct[1], MODE_COUNT_SAT);
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; const int factor = MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
return weighted_prob(pre_prob, prob, factor); return weighted_prob(pre_prob, prob, factor);
} }
static int update_mode_ct2(vp9_prob pre_prob, unsigned int ct[2]) {
return update_mode_ct(pre_prob, get_binary_prob(ct[0], ct[1]), ct);
}
static vp9_prob update_tx_ct(vp9_prob prob, unsigned int ct[2]) {
const int count = MIN(ct[0] + ct[1], MODE_COUNT_SAT);
const int factor = count * MODE_MAX_UPDATE_FACTOR / MODE_COUNT_SAT;
return weighted_prob(prob, get_binary_prob(ct[0], ct[1]), factor);
}
static void update_mode_probs(int n_modes, static void update_mode_probs(int n_modes,
const vp9_tree_index *tree, unsigned int *cnt, const vp9_tree_index *tree, unsigned int *cnt,
vp9_prob *pre_probs, vp9_prob *dst_probs, vp9_prob *pre_probs, vp9_prob *dst_probs,
...@@ -327,11 +337,6 @@ static void update_mode_probs(int n_modes, ...@@ -327,11 +337,6 @@ static void update_mode_probs(int n_modes,
dst_probs[t] = update_mode_ct(pre_probs[t], probs[t], branch_ct[t]); dst_probs[t] = update_mode_ct(pre_probs[t], probs[t], branch_ct[t]);
} }
static int update_mode_ct2(vp9_prob pre_prob, unsigned int branch_ct[2]) {
return update_mode_ct(pre_prob, get_binary_prob(branch_ct[0],
branch_ct[1]), branch_ct);
}
// #define MODE_COUNT_TESTING // #define MODE_COUNT_TESTING
void vp9_adapt_mode_probs(VP9_COMMON *cm) { void vp9_adapt_mode_probs(VP9_COMMON *cm) {
int i, j; int i, j;
...@@ -400,61 +405,39 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) { ...@@ -400,61 +405,39 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) {
fc->partition_prob[INTER_FRAME][i], 0); fc->partition_prob[INTER_FRAME][i], 0);
if (cm->mcomp_filter_type == SWITCHABLE) { if (cm->mcomp_filter_type == SWITCHABLE) {
for (i = 0; i <= VP9_SWITCHABLE_FILTERS; i++) { for (i = 0; i <= VP9_SWITCHABLE_FILTERS; i++)
update_mode_probs(VP9_SWITCHABLE_FILTERS, vp9_switchable_interp_tree, update_mode_probs(VP9_SWITCHABLE_FILTERS, vp9_switchable_interp_tree,
fc->switchable_interp_count[i], fc->switchable_interp_count[i],
fc->pre_switchable_interp_prob[i], fc->pre_switchable_interp_prob[i],
fc->switchable_interp_prob[i], 0); fc->switchable_interp_prob[i], 0);
}
} }
if (cm->txfm_mode == TX_MODE_SELECT) { if (cm->txfm_mode == TX_MODE_SELECT) {
int j; int j;
unsigned int branch_ct_8x8p[TX_SIZE_MAX_SB - 3][2]; unsigned int branch_ct_8x8p[TX_SIZE_MAX_SB - 3][2];
unsigned int branch_ct_16x16p[TX_SIZE_MAX_SB - 2][2]; unsigned int branch_ct_16x16p[TX_SIZE_MAX_SB - 2][2];
unsigned int branch_ct_32x32p[TX_SIZE_MAX_SB - 1][2]; unsigned int branch_ct_32x32p[TX_SIZE_MAX_SB - 1][2];
for (i = 0; i < TX_SIZE_CONTEXTS; ++i) { for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
tx_counts_to_branch_counts_8x8(cm->fc.tx_count_8x8p[i], tx_counts_to_branch_counts_8x8(fc->tx_count_8x8p[i], branch_ct_8x8p);
branch_ct_8x8p); for (j = 0; j < TX_SIZE_MAX_SB - 3; ++j)
for (j = 0; j < TX_SIZE_MAX_SB - 3; ++j) { fc->tx_probs_8x8p[i][j] = update_tx_ct(fc->pre_tx_probs_8x8p[i][j],
int factor; branch_ct_8x8p[j]);
int count = branch_ct_8x8p[j][0] + branch_ct_8x8p[j][1];
vp9_prob prob = get_binary_prob(branch_ct_8x8p[j][0], tx_counts_to_branch_counts_16x16(fc->tx_count_16x16p[i],
branch_ct_8x8p[j][1]);
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
cm->fc.tx_probs_8x8p[i][j] = weighted_prob(
cm->fc.pre_tx_probs_8x8p[i][j], prob, factor);
}
}
for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
tx_counts_to_branch_counts_16x16(cm->fc.tx_count_16x16p[i],
branch_ct_16x16p); branch_ct_16x16p);
for (j = 0; j < TX_SIZE_MAX_SB - 2; ++j) { for (j = 0; j < TX_SIZE_MAX_SB - 2; ++j)
int factor; fc->tx_probs_16x16p[i][j] = update_tx_ct(fc->pre_tx_probs_16x16p[i][j],
int count = branch_ct_16x16p[j][0] + branch_ct_16x16p[j][1]; branch_ct_16x16p[j]);
vp9_prob prob = get_binary_prob(branch_ct_16x16p[j][0],
branch_ct_16x16p[j][1]); tx_counts_to_branch_counts_32x32(fc->tx_count_32x32p[i],
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
cm->fc.tx_probs_16x16p[i][j] = weighted_prob(
cm->fc.pre_tx_probs_16x16p[i][j], prob, factor);
}
}
for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
tx_counts_to_branch_counts_32x32(cm->fc.tx_count_32x32p[i],
branch_ct_32x32p); branch_ct_32x32p);
for (j = 0; j < TX_SIZE_MAX_SB - 1; ++j) { for (j = 0; j < TX_SIZE_MAX_SB - 1; ++j)
int factor; fc->tx_probs_32x32p[i][j] = update_tx_ct(fc->pre_tx_probs_32x32p[i][j],
int count = branch_ct_32x32p[j][0] + branch_ct_32x32p[j][1]; branch_ct_32x32p[j]);
vp9_prob prob = get_binary_prob(branch_ct_32x32p[j][0],
branch_ct_32x32p[j][1]);
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
cm->fc.tx_probs_32x32p[i][j] = weighted_prob(
cm->fc.pre_tx_probs_32x32p[i][j], prob, factor);
}
} }
} }
for (i = 0; i < MBSKIP_CONTEXTS; ++i) for (i = 0; i < MBSKIP_CONTEXTS; ++i)
fc->mbskip_probs[i] = update_mode_ct2(fc->pre_mbskip_probs[i], fc->mbskip_probs[i] = update_mode_ct2(fc->pre_mbskip_probs[i],
fc->mbskip_count[i]); fc->mbskip_count[i]);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment