shithub: libvpx

Download patch

ref: e5c236c21011c668c6b521dc4e554dbf91a161fe
parent: 4ce6928d5b048ce5f82a97cd3d56267432fdc634
author: Yunqing Wang <yunqingwang@google.com>
date: Thu Jun 2 13:33:17 EDT 2011

Adjust bounds checking for hex search in real-time mode

Currently, hex search couldn't guarantee the motion vector(MV)
found is within the limit of maximum MV. Therefore, very large
motion vectors resulted from big motion in the video could cause
encoding artifacts. This change adjusted hex search bounds
checking to make sure the resulted motion vector won't go out
of the range. James Berry, thank you for finding the bug.

Change-Id: If2c55edd9019e72444ad9b4b8688969eef610c55

--- a/vp8/encoder/pickinter.c
+++ b/vp8/encoder/pickinter.c
@@ -736,26 +736,26 @@
                 //adjust search range according to sr from mv prediction
                 if(sr > step_param)
                     step_param = sr;
-
-                col_min = (best_ref_mv.as_mv.col - MAX_FULL_PEL_VAL) >>3;
-                col_max = (best_ref_mv.as_mv.col + MAX_FULL_PEL_VAL) >>3;
-                row_min = (best_ref_mv.as_mv.row - MAX_FULL_PEL_VAL) >>3;
-                row_max = (best_ref_mv.as_mv.row + MAX_FULL_PEL_VAL) >>3;
-
-                // Get intersection of UMV window and valid MV window to reduce # of checks in diamond search.
-                if (x->mv_col_min < col_min )
-                    x->mv_col_min = col_min;
-                if (x->mv_col_max > col_max )
-                    x->mv_col_max = col_max;
-                if (x->mv_row_min < row_min )
-                    x->mv_row_min = row_min;
-                if (x->mv_row_max > row_max )
-                    x->mv_row_max = row_max;
             }else
             {
                 mvp.as_int = best_ref_mv.as_int;
             }
 
+            col_min = (best_ref_mv.as_mv.col - MAX_FULL_PEL_VAL) >>3;
+            col_max = (best_ref_mv.as_mv.col + MAX_FULL_PEL_VAL) >>3;
+            row_min = (best_ref_mv.as_mv.row - MAX_FULL_PEL_VAL) >>3;
+            row_max = (best_ref_mv.as_mv.row + MAX_FULL_PEL_VAL) >>3;
+
+            // Get intersection of UMV window and valid MV window to reduce # of checks in diamond search.
+            if (x->mv_col_min < col_min )
+                x->mv_col_min = col_min;
+            if (x->mv_col_max > col_max )
+                x->mv_col_max = col_max;
+            if (x->mv_row_min < row_min )
+                x->mv_row_min = row_min;
+            if (x->mv_row_max > row_max )
+                x->mv_row_max = row_max;
+
             further_steps = (cpi->Speed >= 8)? 0: (cpi->sf.max_step_search_steps - 1 - step_param);
 
             if (cpi->sf.search_method == HEX)
@@ -808,13 +808,10 @@
                 }
             }
 
-            if(cpi->sf.improved_mv_pred)
-            {
-                x->mv_col_min = tmp_col_min;
-                x->mv_col_max = tmp_col_max;
-                x->mv_row_min = tmp_row_min;
-                x->mv_row_max = tmp_row_max;
-            }
+            x->mv_col_min = tmp_col_min;
+            x->mv_col_max = tmp_col_max;
+            x->mv_row_min = tmp_row_min;
+            x->mv_row_max = tmp_row_max;
 
             if (bestsme < INT_MAX)
                 cpi->find_fractional_mv_step(x, b, d, &d->bmi.mv, &best_ref_mv,