summaryrefslogtreecommitdiff
path: root/vp9/common/vp9_entropymv.c
diff options
context:
space:
mode:
Diffstat (limited to 'vp9/common/vp9_entropymv.c')
-rw-r--r--vp9/common/vp9_entropymv.c84
1 files changed, 46 insertions, 38 deletions
diff --git a/vp9/common/vp9_entropymv.c b/vp9/common/vp9_entropymv.c
index a4a9d5465..8330befbe 100644
--- a/vp9/common/vp9_entropymv.c
+++ b/vp9/common/vp9_entropymv.c
@@ -88,10 +88,14 @@ const nmv_context vp9_default_nmv_context = {
};
MV_JOINT_TYPE vp9_get_mv_joint(MV mv) {
- if (mv.row == 0 && mv.col == 0) return MV_JOINT_ZERO;
- else if (mv.row == 0 && mv.col != 0) return MV_JOINT_HNZVZ;
- else if (mv.row != 0 && mv.col == 0) return MV_JOINT_HZVNZ;
- else return MV_JOINT_HNZVNZ;
+ if (mv.row == 0 && mv.col == 0)
+ return MV_JOINT_ZERO;
+ else if (mv.row == 0 && mv.col != 0)
+ return MV_JOINT_HNZVZ;
+ else if (mv.row != 0 && mv.col == 0)
+ return MV_JOINT_HZVNZ;
+ else
+ return MV_JOINT_HNZVNZ;
}
#define mv_class_base(c) ((c) ? (CLASS0_SIZE << (c + 2)) : 0)
@@ -137,7 +141,8 @@ static void increment_nmv_component(int v,
int incr,
int usehp) {
int s, z, c, o, d, e, f;
- if (!incr) return;
+ if (!incr)
+ return;
assert (v != 0); /* should not be zero */
s = v < 0;
mvcomp->sign[s] += incr;
@@ -152,8 +157,8 @@ static void increment_nmv_component(int v,
if (c == MV_CLASS_0) {
mvcomp->class0[d] += incr;
} else {
- int i, b;
- b = c + CLASS0_BITS - 1; /* number of bits */
+ int i;
+ int b = c + CLASS0_BITS - 1; // number of bits
for (i = 0; i < b; ++i)
mvcomp->bits[i][((d >> i) & 1)] += incr;
}
@@ -204,25 +209,22 @@ static void counts_to_context(nmv_component_counts *mvcomp, int usehp) {
void vp9_increment_nmv(const MV *mv, const MV *ref, nmv_context_counts *mvctx,
int usehp) {
- MV_JOINT_TYPE j = vp9_get_mv_joint(*mv);
- mvctx->joints[j]++;
+ const MV_JOINT_TYPE type = vp9_get_mv_joint(*mv);
+ mvctx->joints[type]++;
usehp = usehp && vp9_use_nmv_hp(ref);
- if (j == MV_JOINT_HZVNZ || j == MV_JOINT_HNZVNZ) {
+ if (type == MV_JOINT_HZVNZ || type == MV_JOINT_HNZVNZ)
increment_nmv_component_count(mv->row, &mvctx->comps[0], 1, usehp);
- }
- if (j == MV_JOINT_HNZVZ || j == MV_JOINT_HNZVNZ) {
+
+ if (type == MV_JOINT_HNZVZ || type == MV_JOINT_HNZVNZ)
increment_nmv_component_count(mv->col, &mvctx->comps[1], 1, usehp);
- }
}
-static void adapt_prob(vp9_prob *dest, vp9_prob prep,
- unsigned int ct[2]) {
- int count = ct[0] + ct[1];
+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) {
- vp9_prob newp = get_binary_prob(ct[0], ct[1]);
- count = count > MV_COUNT_SAT ? MV_COUNT_SAT : count;
- *dest = weighted_prob(prep, newp,
- MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT);
+ 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;
}
@@ -253,10 +255,12 @@ void vp9_counts_to_nmv_context(
branch_ct_joint,
nmv_count->joints, 0);
for (i = 0; i < 2; ++i) {
- prob->comps[i].sign = get_binary_prob(nmv_count->comps[i].sign[0],
- nmv_count->comps[i].sign[1]);
- branch_ct_sign[i][0] = nmv_count->comps[i].sign[0];
- branch_ct_sign[i][1] = nmv_count->comps[i].sign[1];
+ const uint32_t s0 = nmv_count->comps[i].sign[0];
+ const uint32_t s1 = nmv_count->comps[i].sign[1];
+
+ prob->comps[i].sign = get_binary_prob(s0, s1);
+ branch_ct_sign[i][0] = s0;
+ branch_ct_sign[i][1] = s1;
vp9_tree_probs_from_distribution(vp9_mv_class_tree,
prob->comps[i].classes,
branch_ct_classes[i],
@@ -266,10 +270,12 @@ void vp9_counts_to_nmv_context(
branch_ct_class0[i],
nmv_count->comps[i].class0, 0);
for (j = 0; j < MV_OFFSET_BITS; ++j) {
- prob->comps[i].bits[j] = get_binary_prob(nmv_count->comps[i].bits[j][0],
- nmv_count->comps[i].bits[j][1]);
- branch_ct_bits[i][j][0] = nmv_count->comps[i].bits[j][0];
- branch_ct_bits[i][j][1] = nmv_count->comps[i].bits[j][1];
+ const uint32_t b0 = nmv_count->comps[i].bits[j][0];
+ const uint32_t b1 = nmv_count->comps[i].bits[j][1];
+
+ prob->comps[i].bits[j] = get_binary_prob(b0, b1);
+ branch_ct_bits[i][j][0] = b0;
+ branch_ct_bits[i][j][1] = b1;
}
}
for (i = 0; i < 2; ++i) {
@@ -286,16 +292,18 @@ void vp9_counts_to_nmv_context(
}
if (usehp) {
for (i = 0; i < 2; ++i) {
- prob->comps[i].class0_hp =
- get_binary_prob(nmv_count->comps[i].class0_hp[0],
- nmv_count->comps[i].class0_hp[1]);
- branch_ct_class0_hp[i][0] = nmv_count->comps[i].class0_hp[0];
- branch_ct_class0_hp[i][1] = nmv_count->comps[i].class0_hp[1];
-
- prob->comps[i].hp = get_binary_prob(nmv_count->comps[i].hp[0],
- nmv_count->comps[i].hp[1]);
- branch_ct_hp[i][0] = nmv_count->comps[i].hp[0];
- branch_ct_hp[i][1] = nmv_count->comps[i].hp[1];
+ const uint32_t c0_hp0 = nmv_count->comps[i].class0_hp[0];
+ const uint32_t c0_hp1 = nmv_count->comps[i].class0_hp[1];
+ const uint32_t hp0 = nmv_count->comps[i].hp[0];
+ const uint32_t hp1 = nmv_count->comps[i].hp[1];
+
+ prob->comps[i].class0_hp = get_binary_prob(c0_hp0, c0_hp1);
+ branch_ct_class0_hp[i][0] = c0_hp0;
+ branch_ct_class0_hp[i][1] = c0_hp1;
+
+ prob->comps[i].hp = get_binary_prob(hp0, hp1);
+ branch_ct_hp[i][0] = hp0;
+ branch_ct_hp[i][1] = hp1;
}
}
}