]> granicus.if.org Git - libvpx/commitdiff
Encoder code cleanup.
authorDmitry Kovalev <dkovalev@google.com>
Thu, 11 Apr 2013 18:08:00 +0000 (11:08 -0700)
committerDmitry Kovalev <dkovalev@google.com>
Thu, 11 Apr 2013 18:08:00 +0000 (11:08 -0700)
Removing duplicated code from vp9_encodemv.c and reusing ROUND_POWER_OF_TWO
macro definitions.

Change-Id: I9caf0c17f761ada7905cb99a3e2a31f871fef0f9

vp9/common/vp9_treecoder.h
vp9/encoder/vp9_encodemv.c
vp9/encoder/vp9_mcomp.c

index 9297d5280157691ec8b490508079a44566d511a1..133764856709b0d6cb372a43e0866b8cae086e82 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "./vpx_config.h"
 #include "vpx/vpx_integer.h"
+#include "vp9/common/vp9_common.h"
 
 typedef uint8_t vp9_prob;
 
@@ -76,7 +77,7 @@ static INLINE vp9_prob get_binary_prob(int n0, int n1) {
 
 /* this function assumes prob1 and prob2 are already within [1,255] range */
 static INLINE vp9_prob weighted_prob(int prob1, int prob2, int factor) {
-  return (prob1 * (256 - factor) + prob2 * factor + 128) >> 8;
+  return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8);
 }
 
 #endif  // VP9_COMMON_VP9_TREECODER_H_
index 9431f078105cb56aa11ae60ccbf633e03f6b7257..918a0bd7dd6eef91ce821ce926745f2582ba5911 100644 (file)
@@ -603,59 +603,33 @@ void vp9_update_nmv_count(VP9_COMP *cpi, MACROBLOCK *x,
 
   if (mbmi->mode == SPLITMV) {
     int i;
-
-    for (i = 0; i < x->partition_info->count; i++) {
-      if (x->partition_info->bmi[i].mode == NEW4X4) {
-        if (x->e_mbd.allow_high_precision_mv) {
-          mv.row = (x->partition_info->bmi[i].mv.as_mv.row
-                    - best_ref_mv->as_mv.row);
-          mv.col = (x->partition_info->bmi[i].mv.as_mv.col
-                    - best_ref_mv->as_mv.col);
-          vp9_increment_nmv(&mv, &best_ref_mv->as_mv, &cpi->NMVcount, 1);
-          if (x->e_mbd.mode_info_context->mbmi.second_ref_frame > 0) {
-            mv.row = (x->partition_info->bmi[i].second_mv.as_mv.row
-                      - second_best_ref_mv->as_mv.row);
-            mv.col = (x->partition_info->bmi[i].second_mv.as_mv.col
-                      - second_best_ref_mv->as_mv.col);
-            vp9_increment_nmv(&mv, &second_best_ref_mv->as_mv,
-                              &cpi->NMVcount, 1);
-          }
-        } else {
-          mv.row = (x->partition_info->bmi[i].mv.as_mv.row
-                    - best_ref_mv->as_mv.row);
-          mv.col = (x->partition_info->bmi[i].mv.as_mv.col
-                    - best_ref_mv->as_mv.col);
-          vp9_increment_nmv(&mv, &best_ref_mv->as_mv, &cpi->NMVcount, 0);
-          if (x->e_mbd.mode_info_context->mbmi.second_ref_frame > 0) {
-            mv.row = (x->partition_info->bmi[i].second_mv.as_mv.row
-                      - second_best_ref_mv->as_mv.row);
-            mv.col = (x->partition_info->bmi[i].second_mv.as_mv.col
-                      - second_best_ref_mv->as_mv.col);
-            vp9_increment_nmv(&mv, &second_best_ref_mv->as_mv,
-                              &cpi->NMVcount, 0);
-          }
+    PARTITION_INFO *pi = x->partition_info;
+    for (i = 0; i < pi->count; i++) {
+      if (pi->bmi[i].mode == NEW4X4) {
+        mv.row = (pi->bmi[i].mv.as_mv.row - best_ref_mv->as_mv.row);
+        mv.col = (pi->bmi[i].mv.as_mv.col - best_ref_mv->as_mv.col);
+        vp9_increment_nmv(&mv, &best_ref_mv->as_mv, &cpi->NMVcount,
+                          x->e_mbd.allow_high_precision_mv);
+        if (x->e_mbd.mode_info_context->mbmi.second_ref_frame > 0) {
+          mv.row = pi->bmi[i].second_mv.as_mv.row -
+                       second_best_ref_mv->as_mv.row;
+          mv.col = pi->bmi[i].second_mv.as_mv.col -
+                       second_best_ref_mv->as_mv.col;
+          vp9_increment_nmv(&mv, &second_best_ref_mv->as_mv, &cpi->NMVcount,
+                            x->e_mbd.allow_high_precision_mv);
         }
       }
     }
   } else if (mbmi->mode == NEWMV) {
-    if (x->e_mbd.allow_high_precision_mv) {
-      mv.row = (mbmi->mv[0].as_mv.row - best_ref_mv->as_mv.row);
-      mv.col = (mbmi->mv[0].as_mv.col - best_ref_mv->as_mv.col);
-      vp9_increment_nmv(&mv, &best_ref_mv->as_mv, &cpi->NMVcount, 1);
-      if (mbmi->second_ref_frame > 0) {
-        mv.row = (mbmi->mv[1].as_mv.row - second_best_ref_mv->as_mv.row);
-        mv.col = (mbmi->mv[1].as_mv.col - second_best_ref_mv->as_mv.col);
-        vp9_increment_nmv(&mv, &second_best_ref_mv->as_mv, &cpi->NMVcount, 1);
-      }
-    } else {
-      mv.row = (mbmi->mv[0].as_mv.row - best_ref_mv->as_mv.row);
-      mv.col = (mbmi->mv[0].as_mv.col - best_ref_mv->as_mv.col);
-      vp9_increment_nmv(&mv, &best_ref_mv->as_mv, &cpi->NMVcount, 0);
-      if (mbmi->second_ref_frame > 0) {
-        mv.row = (mbmi->mv[1].as_mv.row - second_best_ref_mv->as_mv.row);
-        mv.col = (mbmi->mv[1].as_mv.col - second_best_ref_mv->as_mv.col);
-        vp9_increment_nmv(&mv, &second_best_ref_mv->as_mv, &cpi->NMVcount, 0);
-      }
+    mv.row = (mbmi->mv[0].as_mv.row - best_ref_mv->as_mv.row);
+    mv.col = (mbmi->mv[0].as_mv.col - best_ref_mv->as_mv.col);
+    vp9_increment_nmv(&mv, &best_ref_mv->as_mv, &cpi->NMVcount,
+                      x->e_mbd.allow_high_precision_mv);
+    if (mbmi->second_ref_frame > 0) {
+      mv.row = (mbmi->mv[1].as_mv.row - second_best_ref_mv->as_mv.row);
+      mv.col = (mbmi->mv[1].as_mv.col - second_best_ref_mv->as_mv.col);
+      vp9_increment_nmv(&mv, &second_best_ref_mv->as_mv, &cpi->NMVcount,
+                        x->e_mbd.allow_high_precision_mv);
     }
   }
 }
index e642b7487b3218a39a2e180e5c9999b5f8bfdbd6..1649ccade648dc3d7fed1ebd7e8069dd5d601761 100644 (file)
@@ -79,9 +79,10 @@ static int mvsad_err_cost(int_mv *mv, int_mv *ref, int *mvjsadcost,
     MV v;
     v.row = mv->as_mv.row - ref->as_mv.row;
     v.col = mv->as_mv.col - ref->as_mv.col;
-    return ((mvjsadcost[vp9_get_mv_joint(v)] +
-             mvsadcost[0][v.row] + mvsadcost[1][v.col]) *
-            error_per_bit + 128) >> 8;
+
+    return ROUND_POWER_OF_TWO((mvjsadcost[vp9_get_mv_joint(v)] +
+                                   mvsadcost[0][v.row] + mvsadcost[1][v.col]) *
+                                       error_per_bit, 8);
   }
   return 0;
 }