[x265] [PATCH] motion: Code clean up for Motion Estimation

gopu at multicorewareinc.com gopu at multicorewareinc.com
Tue Jul 2 08:14:01 CEST 2013


# HG changeset patch
# User ggopu
# Date 1372745553 -19800
# Node ID 6a97823d1060a4a9fae2fd11b506d1c72b62158c
# Parent  936c56e589ec2b4f9f9a5ea8d0fa92fc8dbc8e07
motion: Code clean up for Motion Estimation

diff -r 936c56e589ec -r 6a97823d1060 source/encoder/motion.cpp
--- a/source/encoder/motion.cpp	Mon Jul 01 16:07:56 2013 +0530
+++ b/source/encoder/motion.cpp	Tue Jul 02 11:42:33 2013 +0530
@@ -37,7 +37,7 @@
 using namespace x265;
 
 static int size_scale[NUM_PARTITIONS];
-#define SAD_THRESH(v) (bcost < (((v >> 4) * size_scale[partEnum])))
+#define SAD_THRESH(v) (bcost < (((v >> 4) * size_scale[m_partEnum])))
 
 static void init_scales(void)
 {
@@ -55,29 +55,29 @@
 }
 
 MotionEstimate::MotionEstimate()
-    : searchMethod(3)
-    , subsample(0)
+    : m_searchMethod(3)
+    , m_subsample(0)
 {
     if (size_scale[0] == 0)
         init_scales();
 
     // fenc must be 16 byte aligned
-    fenc = (pixel *)((char*)fenc_buf + ((16 - (size_t)(&fenc_buf[0])) & 15));
+    m_fenc = (pixel*)((char*)m_fenc_buf + ((16 - (size_t)(&m_fenc_buf[0])) & 15));
 }
 
 void MotionEstimate::setSourcePU(int offset, int width, int height)
 {
-    blockOffset = offset;
+    m_blockOffset = offset;
 
     /* copy PU block into cache */
-    primitives.cpyblock(width, height, fenc, FENC_STRIDE, fencplane + offset, fencLumaStride);
+    primitives.cpyblock(width, height, m_fenc, FENC_STRIDE, m_fencplane + offset, m_fencLumaStride);
 
-    partEnum = PartitionFromSizes(width, height);
-    sad = primitives.sad[partEnum];
-    satd = primitives.satd[partEnum];
-    sa8d = primitives.sa8d_inter[partEnum];
-    sad_x3 = primitives.sad_x3[partEnum];
-    sad_x4 = primitives.sad_x4[partEnum];
+    m_partEnum = PartitionFromSizes(width, height);
+    m_sad = primitives.sad[m_partEnum];
+    m_satd = primitives.satd[m_partEnum];
+    m_sa8d = primitives.sa8d_inter[m_partEnum];
+    m_sad_x3 = primitives.sad_x3[m_partEnum];
+    m_sad_x4 = primitives.sad_x4[m_partEnum];
 }
 
 /* radius 2 hexagon. repeated entries are to avoid having to compute mod6 every time. */
@@ -121,7 +121,7 @@
     do \
     { \
         MV tmv(mx, my); \
-        int cost = sad(fenc, FENC_STRIDE, fref + mx + my * stride, stride); \
+        int cost = m_sad(m_fenc, FENC_STRIDE, fref + mx + my * stride, stride); \
         cost += mvcost(tmv << 2); \
         if (cost < bcost) { \
             bcost = cost; \
@@ -134,7 +134,7 @@
 #define COST_MV(mx, my) \
     do \
     { \
-        int cost = sad(fenc, FENC_STRIDE, fref + mx + my * stride, stride); \
+        int cost = m_sad(m_fenc, FENC_STRIDE, fref + mx + my * stride, stride); \
         cost += mvcost(MV(mx, my) << 2); \
         COPY2_IF_LT(bcost, cost, bmv, MV(mx, my)); \
     } while (0)
@@ -143,18 +143,18 @@
     do \
     { \
         MV fmv = qmv >> 2; \
-        pixel *qfref = ref->m_lumaPlane[qmv.x & 3][qmv.y & 3] + blockOffset; \
-        (cost) = sad(fenc, FENC_STRIDE, qfref + fmv.y * stride + fmv.x, stride); \
+        pixel *qfref = ref->m_lumaPlane[qmv.x & 3][qmv.y & 3] + m_blockOffset; \
+        (cost) = m_sad(m_fenc, FENC_STRIDE, qfref + fmv.y * stride + fmv.x, stride); \
     } while (0)
 
 #define COST_MV_X3_DIR(m0x, m0y, m1x, m1y, m2x, m2y, costs) \
     { \
         pixel *pix_base = fref + bmv.x + bmv.y * stride; \
-        sad_x3(fenc, \
-               pix_base + (m0x) + (m0y) * stride, \
-               pix_base + (m1x) + (m1y) * stride, \
-               pix_base + (m2x) + (m2y) * stride, \
-               stride, costs); \
+        m_sad_x3(m_fenc, \
+                 pix_base + (m0x) + (m0y) * stride, \
+                 pix_base + (m1x) + (m1y) * stride, \
+                 pix_base + (m2x) + (m2y) * stride, \
+                 stride, costs); \
         (costs)[0] += mvcost((bmv + MV(m0x, m0y)) << 2); \
         (costs)[1] += mvcost((bmv + MV(m1x, m1y)) << 2); \
         (costs)[2] += mvcost((bmv + MV(m2x, m2y)) << 2); \
@@ -162,12 +162,12 @@
 
 #define COST_MV_PT_DIST_X4(m0x, m0y, p0, d0, m1x, m1y, p1, d1, m2x, m2y, p2, d2, m3x, m3y, p3, d3) \
     { \
-        sad_x4(fenc, \
-               fref + (m0x) + (m0y) * stride, \
-               fref + (m1x) + (m1y) * stride, \
-               fref + (m2x) + (m2y) * stride, \
-               fref + (m3x) + (m3y) * stride, \
-               stride, costs); \
+        m_sad_x4(m_fenc, \
+                 fref + (m0x) + (m0y) * stride, \
+                 fref + (m1x) + (m1y) * stride, \
+                 fref + (m2x) + (m2y) * stride, \
+                 fref + (m3x) + (m3y) * stride, \
+                 stride, costs); \
         costs[0] += mvcost(MV(m0x, m0y) << 2); \
         costs[1] += mvcost(MV(m1x, m1y) << 2); \
         costs[2] += mvcost(MV(m2x, m2y) << 2); \
@@ -180,12 +180,12 @@
 
 #define COST_MV_X4(m0x, m0y, m1x, m1y, m2x, m2y, m3x, m3y) \
     { \
-        sad_x4(fenc, \
-               pix_base + (m0x) + (m0y) * stride, \
-               pix_base + (m1x) + (m1y) * stride, \
-               pix_base + (m2x) + (m2y) * stride, \
-               pix_base + (m3x) + (m3y) * stride, \
-               stride, costs); \
+        m_sad_x4(m_fenc, \
+                 pix_base + (m0x) + (m0y) * stride, \
+                 pix_base + (m1x) + (m1y) * stride, \
+                 pix_base + (m2x) + (m2y) * stride, \
+                 pix_base + (m3x) + (m3y) * stride, \
+                 stride, costs); \
         costs[0] += mvcost((omv + MV(m0x, m0y)) << 2); \
         costs[1] += mvcost((omv + MV(m1x, m1y)) << 2); \
         costs[2] += mvcost((omv + MV(m2x, m2y)) << 2); \
@@ -199,12 +199,12 @@
 #define COST_MV_X4_DIR(m0x, m0y, m1x, m1y, m2x, m2y, m3x, m3y, costs) \
     { \
         pixel *pix_base = fref + bmv.x + bmv.y * stride; \
-        sad_x4(fenc, \
-               pix_base + (m0x) + (m0y) * stride, \
-               pix_base + (m1x) + (m1y) * stride, \
-               pix_base + (m2x) + (m2y) * stride, \
-               pix_base + (m3x) + (m3y) * stride, \
-               stride, costs); \
+        m_sad_x4(m_fenc, \
+                 pix_base + (m0x) + (m0y) * stride, \
+                 pix_base + (m1x) + (m1y) * stride, \
+                 pix_base + (m2x) + (m2y) * stride, \
+                 pix_base + (m3x) + (m3y) * stride, \
+                 stride, costs); \
         (costs)[0] += mvcost((bmv + MV(m0x, m0y)) << 2); \
         (costs)[1] += mvcost((bmv + MV(m1x, m1y)) << 2); \
         (costs)[2] += mvcost((bmv + MV(m2x, m2y)) << 2); \
@@ -244,17 +244,17 @@
     }
 
 int MotionEstimate::motionEstimate(MotionReference *ref,
-                                   const MV &mvmin,
-                                   const MV &mvmax,
-                                   const MV &qmvp,
-                                   int       numCandidates,
-                                   const MV *mvc,
-                                   int       merange,
-                                   MV &      outQMv)
+                                   const MV &       mvmin,
+                                   const MV &       mvmax,
+                                   const MV &       qmvp,
+                                   int              numCandidates,
+                                   const MV *       mvc,
+                                   int              merange,
+                                   MV &             outQMv)
 {
     ALIGN_VAR_16(int, costs[16]);
     size_t stride = ref->m_lumaStride;
-    pixel *fref = ref->m_lumaPlane[0][0] + blockOffset;
+    pixel *fref = ref->m_lumaPlane[0][0] + m_blockOffset;
 
     setMVP(qmvp);
 
@@ -279,13 +279,13 @@
     int bcost = bprecost;
     if (pmv.isSubpel())
     {
-        bcost = sad(fenc, FENC_STRIDE, fref + bmv.x + bmv.y * stride, stride) + mvcost(bmv << 2);
+        bcost = m_sad(m_fenc, FENC_STRIDE, fref + bmv.x + bmv.y * stride, stride) + mvcost(bmv << 2);
     }
 
     // measure SAD cost at MV(0) if MVP is not zero
     if (pmv.notZero())
     {
-        int cost = sad(fenc, FENC_STRIDE, fref, stride) + mvcost(MV(0,0));
+        int cost = m_sad(m_fenc, FENC_STRIDE, fref, stride) + mvcost(MV(0, 0));
         if (cost < bcost)
         {
             bcost = cost;
@@ -313,7 +313,7 @@
     pmv = pmv.roundToFPel();
     MV omv = bmv;  // current search origin or starting point
 
-    switch (searchMethod)
+    switch (m_searchMethod)
     {
     case X265_DIA_SEARCH:
     {
@@ -416,7 +416,7 @@
     {
         int ucost1, ucost2;
         int16_t cross_start = 1;
-        assert(PARTITION_4x4 != partEnum);
+        assert(PARTITION_4x4 != m_partEnum);
 
         /* refine predictors */
         omv = bmv;
@@ -475,7 +475,7 @@
 
             if (numCandidates == 1)
             {
-                if (PARTITION_64x64 == partEnum)
+                if (PARTITION_64x64 == m_partEnum)
                     /* mvc is probably the same as mvp, so the difference isn't meaningful.
                      * but prediction usually isn't too bad, so just use medium range */
                     mvd = 25;
@@ -491,7 +491,7 @@
 
                 denom = numCandidates - 1;
                 mvd = 0;
-                if (partEnum != PARTITION_64x64)
+                if (m_partEnum != PARTITION_64x64)
                 {
                     mvd = abs(qmvp.x - mvc[0].x) + abs(qmvp.y - mvc[0].y);
                     denom++;
@@ -537,12 +537,12 @@
                 pixel *fref_base = fref + omv.x + (omv.y - 4 * i) * stride;
                 size_t dy = (size_t)i * stride;
 #define SADS(k, x0, y0, x1, y1, x2, y2, x3, y3) \
-    sad_x4(fenc, \
-           fref_base x0 * i + (y0 - 2 * k + 4) * dy, \
-           fref_base x1 * i + (y1 - 2 * k + 4) * dy, \
-           fref_base x2 * i + (y2 - 2 * k + 4) * dy, \
-           fref_base x3 * i + (y3 - 2 * k + 4) * dy, \
-           stride, costs + 4 * k); \
+    m_sad_x4(m_fenc, \
+             fref_base x0 * i + (y0 - 2 * k + 4) * dy, \
+             fref_base x1 * i + (y1 - 2 * k + 4) * dy, \
+             fref_base x2 * i + (y2 - 2 * k + 4) * dy, \
+             fref_base x3 * i + (y3 - 2 * k + 4) * dy, \
+             stride, costs + 4 * k); \
     fref_base += 2 * dy;
 #define ADD_MVCOST(k, x, y) costs[k] += p_cost_omvx[x * 4 * i] + p_cost_omvy[y * 4 * i]
 #define MIN_MV(k, x, y)     COPY2_IF_LT(bcost, costs[k], dir, x * 16 + (y & 15))
@@ -648,12 +648,12 @@
                     if (tmv.x + (RasterDistance * 3) <= mvmax.x)
                     {
                         pixel *pix_base = fref + tmv.y * stride + tmv.x;
-                        sad_x4(fenc,
-                               pix_base,
-                               pix_base + RasterDistance,
-                               pix_base + RasterDistance * 2,
-                               pix_base + RasterDistance * 3,
-                               stride, costs);
+                        m_sad_x4(m_fenc,
+                                 pix_base,
+                                 pix_base + RasterDistance,
+                                 pix_base + RasterDistance * 2,
+                                 pix_base + RasterDistance * 3,
+                                 stride, costs);
                         costs[0] += mvcost(tmv << 2);
                         COPY2_IF_LT(bcost, costs[0], bmv, tmv);
                         tmv.x += RasterDistance;
@@ -725,8 +725,8 @@
     {
         MV qmv = bmv + square1[i] * 2;
         MV fmv = qmv >> 2;
-        pixel *qfref = ref->m_lumaPlane[qmv.x & 3][qmv.y & 3] + blockOffset;
-        int cost = satd(fenc, FENC_STRIDE, qfref + fmv.y * stride + fmv.x, stride) + mvcost(qmv);
+        pixel *qfref = ref->m_lumaPlane[qmv.x & 3][qmv.y & 3] + m_blockOffset;
+        int cost = m_satd(m_fenc, FENC_STRIDE, qfref + fmv.y * stride + fmv.x, stride) + mvcost(qmv);
         COPY2_IF_LT(bcost, cost, bdir, i);
     }
 
@@ -738,8 +738,8 @@
     {
         MV qmv = bmv + square1[i];
         MV fmv = qmv >> 2;
-        pixel *qfref = ref->m_lumaPlane[qmv.x & 3][qmv.y & 3] + blockOffset;
-        int cost = satd(fenc, FENC_STRIDE, qfref + fmv.y * stride + fmv.x, stride) + mvcost(qmv);
+        pixel *qfref = ref->m_lumaPlane[qmv.x & 3][qmv.y & 3] + m_blockOffset;
+        int cost = m_satd(m_fenc, FENC_STRIDE, qfref + fmv.y * stride + fmv.x, stride) + mvcost(qmv);
         COPY2_IF_LT(bcost, cost, bdir, i);
     }
 
@@ -751,17 +751,17 @@
 }
 
 void MotionEstimate::StarPatternSearch(MotionReference *ref,
-                                       const MV &mvmin,
-                                       const MV &mvmax,
-                                       MV &bmv,
-                                       int &bcost,
-                                       int &bPointNr,
-                                       int &bDistance,
-                                       int earlyExitIters,
-                                       int merange)
+                                       const MV &       mvmin,
+                                       const MV &       mvmax,
+                                       MV &             bmv,
+                                       int &            bcost,
+                                       int &            bPointNr,
+                                       int &            bDistance,
+                                       int              earlyExitIters,
+                                       int              merange)
 {
     ALIGN_VAR_16(int, costs[16]);
-    pixel *fref = ref->m_lumaPlane[0][0] + blockOffset;
+    pixel *fref = ref->m_lumaPlane[0][0] + m_blockOffset;
     size_t stride = ref->m_lumaStride;
 
     MV omv = bmv;
diff -r 936c56e589ec -r 6a97823d1060 source/encoder/motion.h
--- a/source/encoder/motion.h	Mon Jul 01 16:07:56 2013 +0530
+++ b/source/encoder/motion.h	Tue Jul 02 11:42:33 2013 +0530
@@ -37,22 +37,22 @@
 protected:
 
     /* Aligned copy of original pixels, extra room for manual alignment */
-    pixel  fenc_buf[64 * FENC_STRIDE + 16];
-    pixel *fenc;
+    pixel  m_fenc_buf[64 * FENC_STRIDE + 16];
+    pixel *m_fenc;
 
-    pixel *fencplane;
-    intptr_t fencLumaStride;
+    pixel *m_fencplane;
+    intptr_t m_fencLumaStride;
 
-    pixelcmp sad;
-    pixelcmp satd;
-    pixelcmp sa8d;
-    pixelcmp_x3 sad_x3;
-    pixelcmp_x4 sad_x4;
+    pixelcmp m_sad;
+    pixelcmp m_satd;
+    pixelcmp m_sa8d;
+    pixelcmp_x3 m_sad_x3;
+    pixelcmp_x4 m_sad_x4;
 
-    intptr_t blockOffset;
-    int partEnum;
-    int searchMethod;
-    int subsample;
+    intptr_t m_blockOffset;
+    int m_partEnum;
+    int m_searchMethod;
+    int m_subsample;
 
     MotionEstimate& operator =(const MotionEstimate&);
 
@@ -62,14 +62,14 @@
 
     ~MotionEstimate() {}
 
-    void setSearchMethod(int i) { searchMethod = i; }
+    void setSearchMethod(int i) { m_searchMethod = i; }
 
     /* Methods called at slice setup */
 
     void setSourcePlane(pixel *Y, intptr_t luma)
     {
-        fencplane = Y;
-        fencLumaStride = luma;
+        m_fencplane = Y;
+        m_fencLumaStride = luma;
     }
 
     void setSourcePU(int offset, int pwidth, int pheight);
@@ -77,34 +77,34 @@
     /* buf*() and motionEstimate() methods all use cached fenc pixels and thus
      * require setSourcePU() to be called prior. */
 
-    inline int bufSAD(pixel *fref, intptr_t stride)  { return sad(fenc, FENC_STRIDE, fref, stride); }
+    inline int bufSAD(pixel *fref, intptr_t stride)  { return m_sad(m_fenc, FENC_STRIDE, fref, stride); }
 
-    inline int bufSA8D(pixel *fref, intptr_t stride) { return sa8d(fenc, FENC_STRIDE, fref, stride); }
+    inline int bufSA8D(pixel *fref, intptr_t stride) { return m_sa8d(m_fenc, FENC_STRIDE, fref, stride); }
 
-    inline int bufSATD(pixel *fref, intptr_t stride) { return satd(fenc, FENC_STRIDE, fref, stride); }
+    inline int bufSATD(pixel *fref, intptr_t stride) { return m_satd(m_fenc, FENC_STRIDE, fref, stride); }
 
     int motionEstimate(MotionReference *ref,
-                       const MV &mvmin,
-                       const MV &mvmax,
-                       const MV &qmvp,
-                       int numCandidates,
-                       const MV *mvc,
-                       int merange,
-                       MV &outQMv);
+                       const MV &       mvmin,
+                       const MV &       mvmax,
+                       const MV &       qmvp,
+                       int              numCandidates,
+                       const MV *       mvc,
+                       int              merange,
+                       MV &             outQMv);
 
 protected:
 
     static const int COST_MAX = 1 << 28;
 
     inline void StarPatternSearch(MotionReference *ref,
-                                  const MV &mvmin,
-                                  const MV &mvmax,
-                                  MV &bmv,
-                                  int &bcost,
-                                  int &bPointNr,
-                                  int &bDistance,
-                                  int earlyExitIters,
-                                  int merange);
+                                  const MV &       mvmin,
+                                  const MV &       mvmax,
+                                  MV &             bmv,
+                                  int &            bcost,
+                                  int &            bPointNr,
+                                  int &            bDistance,
+                                  int              earlyExitIters,
+                                  int              merange);
 };
 }
 


More information about the x265-devel mailing list