shithub: libvpx

Download patch

ref: be00d3970dbe4efc3d537e374774269ff2bb0621
parent: d604914f0976f50ecb0b267c4793bc6db8c083fb
parent: 40358dc406cf9ae46d063b170b6ddf84a754a87d
author: Dmitry Kovalev <dkovalev@google.com>
date: Thu Jul 25 08:52:26 EDT 2013

Merge "Removing duplicated code for merging two probabilities."

--- a/vp9/common/vp9_entropy.c
+++ b/vp9/common/vp9_entropy.c
@@ -614,7 +614,8 @@
 #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 @@
   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 @@
         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) {
--- a/vp9/common/vp9_entropymode.c
+++ b/vp9/common/vp9_entropymode.c
@@ -382,15 +382,12 @@
 #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);
 }
 
 static void update_mode_probs(int n_modes,
--- a/vp9/common/vp9_entropymv.c
+++ b/vp9/common/vp9_entropymv.c
@@ -170,14 +170,7 @@
 }
 
 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) {
@@ -190,26 +183,20 @@
                                 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;
 }
 
--- a/vp9/common/vp9_treecoder.h
+++ b/vp9/common/vp9_treecoder.h
@@ -79,4 +79,22 @@
   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_