]> git.sesse.net Git - x264/commitdiff
faster subpel motion search.
authorLoren Merritt <pengvado@videolan.org>
Sat, 3 Dec 2005 01:50:52 +0000 (01:50 +0000)
committerLoren Merritt <pengvado@videolan.org>
Sat, 3 Dec 2005 01:50:52 +0000 (01:50 +0000)
patch by Alex Wright.

git-svn-id: svn://svn.videolan.org/x264/trunk@381 df754926-b1dd-0310-bc7b-ec298dee348c

encoder/me.c

index 765457dd7441f43085aadcd9cdd2572a3a6b6e23..7f107637671796b4addb29e66475a5221dfcf6e7 100644 (file)
@@ -40,7 +40,7 @@ static const int subpel_iterations[][4] =
     {0,2,1,0},
     {0,2,1,1},
     {0,2,1,2},
-    {0,0,2,3}};
+    {0,0,2,2}};
 
 static void refine_subpel( x264_t *h, x264_me_t *m, int hpel_iters, int qpel_iters, int *p_halfpel_thresh, int b_refine_qpel );
 
@@ -303,7 +303,8 @@ void x264_me_refine_qpel( x264_t *h, x264_me_t *m )
     refine_subpel( h, m, hpel, qpel, NULL, 1 );
 }
 
-#define COST_MV_SAD( mx, my ) \
+#define COST_MV_SAD( mx, my, dir ) \
+if( b_refine_qpel || (dir^1) != odir ) \
 { \
     int stride = 16; \
     uint8_t *src = h->mc.get_ref( m->p_fref, m->i_stride[0], pix, &stride, mx, my, bw, bh ); \
@@ -314,6 +315,7 @@ void x264_me_refine_qpel( x264_t *h, x264_me_t *m )
         bcost = cost;  \
         bmx = mx;      \
         bmy = my;      \
+        bdir = dir;    \
     } \
 }
 
@@ -362,25 +364,26 @@ static void refine_subpel( x264_t *h, x264_me_t *m, int hpel_iters, int qpel_ite
     int odir = -1, bdir;
 
 
-    /* try the subpel component of the predicted mv if it's close to
-     * the result of the fullpel search */
+    /* try the subpel component of the predicted mv */
     if( hpel_iters )
     {
         int mx = x264_clip3( m->mvp[0], h->mb.mv_min[0], h->mb.mv_max[0] );
         int my = x264_clip3( m->mvp[1], h->mb.mv_min[1], h->mb.mv_max[1] );
         if( mx != bmx || my != bmy )
-            COST_MV_SAD( mx, my );
+            COST_MV_SAD( mx, my, -1 );
     }
     
     /* hpel search */
+    bdir = -1;
     for( i = hpel_iters; i > 0; i-- )
     {
+        odir = bdir;
         omx = bmx;
         omy = bmy;
-        COST_MV_SAD( omx, omy - 2 );
-        COST_MV_SAD( omx, omy + 2 );
-        COST_MV_SAD( omx - 2, omy );
-        COST_MV_SAD( omx + 2, omy );
+        COST_MV_SAD( omx, omy - 2, 0 );
+        COST_MV_SAD( omx, omy + 2, 1 );
+        COST_MV_SAD( omx - 2, omy, 2 );
+        COST_MV_SAD( omx + 2, omy, 3 );
         if( bmx == omx && bmy == omy )
             break;
     }