]> granicus.if.org Git - libvpx/commitdiff
Nice looking motion vector clamping functions.
authorDmitry Kovalev <dkovalev@google.com>
Wed, 31 Jul 2013 23:11:03 +0000 (16:11 -0700)
committerDmitry Kovalev <dkovalev@google.com>
Thu, 1 Aug 2013 20:40:26 +0000 (13:40 -0700)
Removing assign_and_clamp_mv function, making implementation of clamp_mv
and clamp_mv2 more clear and consistent.

Change-Id: Iecd08e1c1bf0379f8314ebe01811f8253f4ade58

vp9/common/vp9_findnearmv.c
vp9/common/vp9_findnearmv.h
vp9/decoder/vp9_decodemv.c
vp9/encoder/vp9_mcomp.c
vp9/encoder/vp9_rdopt.c

index cea06b4bd8aed38268dbb121f93f73a353e28a9e..d056dffc92105377da42be85059aed16c83f4b68 100644 (file)
@@ -32,7 +32,7 @@ void vp9_find_best_ref_mvs(MACROBLOCKD *xd,
   // Make sure all the candidates are properly clamped etc
   for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) {
     lower_mv_precision(&mvlist[i], xd->allow_high_precision_mv);
-    clamp_mv2(&mvlist[i], xd);
+    clamp_mv2(&mvlist[i].as_mv, xd);
   }
   *nearest = mvlist[0];
   *near = mvlist[1];
index 907e580cdeb48b7e8394e32ef7a1f91eadba8f38..543351df3b2ffb7eab93112914d2906f9aba7133 100644 (file)
@@ -29,24 +29,17 @@ void vp9_find_best_ref_mvs(MACROBLOCKD *xd,
                            int_mv *near);
 
 // TODO(jingning): this mv clamping function should be block size dependent.
-static void clamp_mv(int_mv *mv,
-                     int mb_to_left_edge,
-                     int mb_to_right_edge,
-                     int mb_to_top_edge,
-                     int mb_to_bottom_edge) {
-  mv->as_mv.col = clamp(mv->as_mv.col, mb_to_left_edge, mb_to_right_edge);
-  mv->as_mv.row = clamp(mv->as_mv.row, mb_to_top_edge, mb_to_bottom_edge);
+static void clamp_mv(MV *mv, int min_col, int max_col,
+                             int min_row, int max_row) {
+  mv->col = clamp(mv->col, min_col, max_col);
+  mv->row = clamp(mv->row, min_row, max_row);
 }
 
-static int clamp_mv2(int_mv *mv, const MACROBLOCKD *xd) {
-  int_mv tmp_mv;
-  tmp_mv.as_int = mv->as_int;
-  clamp_mv(mv,
-           xd->mb_to_left_edge - LEFT_TOP_MARGIN,
-           xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN,
-           xd->mb_to_top_edge - LEFT_TOP_MARGIN,
-           xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN);
-  return tmp_mv.as_int != mv->as_int;
+static void clamp_mv2(MV *mv, const MACROBLOCKD *xd) {
+  clamp_mv(mv, xd->mb_to_left_edge - LEFT_TOP_MARGIN,
+               xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN,
+               xd->mb_to_top_edge - LEFT_TOP_MARGIN,
+               xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN);
 }
 
 void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *pc,
index 6282f944b531ba9e9d53655901534210c97405f4..aa1ebc53e9520066aa35682835a947656d1e2b10 100644 (file)
@@ -366,16 +366,6 @@ static INLINE COMPPREDMODE_TYPE read_comp_pred_mode(vp9_reader *r) {
   return mode;
 }
 
-static INLINE void assign_and_clamp_mv(int_mv *dst, const int_mv *src,
-                                       int mb_to_left_edge,
-                                       int mb_to_right_edge,
-                                       int mb_to_top_edge,
-                                       int mb_to_bottom_edge) {
-  dst->as_int = src->as_int;
-  clamp_mv(dst, mb_to_left_edge, mb_to_right_edge, mb_to_top_edge,
-           mb_to_bottom_edge);
-}
-
 static INLINE INTERPOLATIONFILTERTYPE read_switchable_filter_type(
     VP9D_COMP *pbi, vp9_reader *r) {
   VP9_COMMON *const cm = &pbi->common;
@@ -558,36 +548,25 @@ static void read_inter_block_mode_info(VP9D_COMP *pbi, MODE_INFO *mi,
     mv0->as_int = mi->bmi[3].as_mv[0].as_int;
     mv1->as_int = mi->bmi[3].as_mv[1].as_int;
   } else {
-    const int mb_to_top_edge = xd->mb_to_top_edge - LEFT_TOP_MARGIN;
-    const int mb_to_bottom_edge = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN;
-    const int mb_to_left_edge = xd->mb_to_left_edge - LEFT_TOP_MARGIN;
-    const int mb_to_right_edge = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN;
-
     switch (mbmi->mode) {
       case NEARMV:
-        // Clip "next_nearest" so that it does not extend to far out of image
-        assign_and_clamp_mv(mv0, &nearby, mb_to_left_edge,
-                                          mb_to_right_edge,
-                                          mb_to_top_edge,
-                                          mb_to_bottom_edge);
-        if (ref1 > 0)
-          assign_and_clamp_mv(mv1, &nearby_second, mb_to_left_edge,
-                                                   mb_to_right_edge,
-                                                   mb_to_top_edge,
-                                                   mb_to_bottom_edge);
+        mv0->as_int = nearby.as_int;
+        clamp_mv2(&mv0->as_mv, xd);
+
+        if (ref1 > 0) {
+          mv1->as_int = nearby_second.as_int;
+          clamp_mv2(&mv1->as_mv, xd);
+        }
         break;
 
       case NEARESTMV:
-        // Clip "next_nearest" so that it does not extend to far out of image
-        assign_and_clamp_mv(mv0, &nearest, mb_to_left_edge,
-                                           mb_to_right_edge,
-                                           mb_to_top_edge,
-                                           mb_to_bottom_edge);
-        if (ref1 > 0)
-          assign_and_clamp_mv(mv1, &nearest_second, mb_to_left_edge,
-                                                    mb_to_right_edge,
-                                                    mb_to_top_edge,
-                                                    mb_to_bottom_edge);
+        mv0->as_int = nearest.as_int;
+        clamp_mv2(&mv0->as_mv, xd);
+
+        if (ref1 > 0) {
+          mv1->as_int = nearest_second.as_int;
+          clamp_mv2(&mv1->as_mv, xd);
+        }
         break;
 
       case ZEROMV:
index b2814d93ec0ef7cbc6cebc23047bf830ad7f810f..e3c002b1fe677d69a8f030c81c677ac686c54dcd 100644 (file)
@@ -1319,7 +1319,8 @@ int vp9_hex_search
   fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3;
 
   // adjust ref_mv to make sure it is within MV range
-  clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
+  clamp_mv(&ref_mv->as_mv,
+           x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
   br = ref_mv->as_mv.row;
   bc = ref_mv->as_mv.col;
 
@@ -1475,7 +1476,8 @@ int vp9_diamond_search_sad_c(MACROBLOCK *x,
   fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3;
   fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3;
 
-  clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
+  clamp_mv(&ref_mv->as_mv,
+           x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
   ref_row = ref_mv->as_mv.row;
   ref_col = ref_mv->as_mv.col;
   *num00 = 0;
@@ -1615,7 +1617,8 @@ int vp9_diamond_search_sadx4(MACROBLOCK *x,
   fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3;
   fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3;
 
-  clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
+  clamp_mv(&ref_mv->as_mv,
+           x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
   ref_row = ref_mv->as_mv.row;
   ref_col = ref_mv->as_mv.col;
   *num00 = 0;
index 1303948dd3e3e9244f2f03ea52a238845c087ae2..29bfd23abe2c939c75b702f700c55a94f9a36e4c 100644 (file)
@@ -1973,7 +1973,7 @@ static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x,
           // Should we do a full search (best quality only)
           if (cpi->compressor_speed == 0) {
             /* Check if mvp_full is within the range. */
-            clamp_mv(&mvp_full, x->mv_col_min, x->mv_col_max,
+            clamp_mv(&mvp_full.as_mv, x->mv_col_min, x->mv_col_max,
                      x->mv_row_min, x->mv_row_max);
 
             thissme = cpi->full_search_sad(x, &mvp_full,
@@ -2833,10 +2833,8 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
   for (i = 0; i < num_refs; ++i) {
     cur_mv[i] = frame_mv[refs[i]];
     // Clip "next_nearest" so that it does not extend to far out of image
-    if (this_mode == NEWMV)
-      assert(!clamp_mv2(&cur_mv[i], xd));
-    else
-      clamp_mv2(&cur_mv[i], xd);
+    if (this_mode != NEWMV)
+      clamp_mv2(&cur_mv[i].as_mv, xd);
 
     if (mv_check_bounds(x, &cur_mv[i]))
       return INT64_MAX;