shithub: libvpx

Download patch

ref: ec299e2092c51d60d487109366b982b1eadcf7fc
parent: 38d79453457e12ddc735243a701c980c068c0d0b
author: Dmitry Kovalev <dkovalev@google.com>
date: Thu Apr 11 07:08:00 EDT 2013

Encoder code cleanup.

Removing duplicated code from vp9_encodemv.c and reusing ROUND_POWER_OF_TWO
macro definitions.

Change-Id: I9caf0c17f761ada7905cb99a3e2a31f871fef0f9

--- a/vp9/common/vp9_treecoder.h
+++ b/vp9/common/vp9_treecoder.h
@@ -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 @@
 
 /* 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_
--- a/vp9/encoder/vp9_encodemv.c
+++ b/vp9/encoder/vp9_encodemv.c
@@ -603,59 +603,33 @@
 
   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);
     }
   }
 }
--- a/vp9/encoder/vp9_mcomp.c
+++ b/vp9/encoder/vp9_mcomp.c
@@ -79,9 +79,10 @@
     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;
 }