[x265] [PATCH] interpolate: fix bug that generate error interpolate pixel in border area

Min Chen chenm003 at 163.com
Thu Aug 29 11:56:20 CEST 2013


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1377769253 -28800
# Node ID f5a77ff45760c04080a5873cae88986cc2a8ce0e
# Parent  1ce2c5c87b19b980055933fe31973ffc8bff54d3
interpolate: fix bug that generate error interpolate pixel in border area

diff -r 1ce2c5c87b19 -r f5a77ff45760 source/common/ipfilter.cpp
--- a/source/common/ipfilter.cpp	Wed Aug 28 23:26:45 2013 -0500
+++ b/source/common/ipfilter.cpp	Thu Aug 29 17:40:53 2013 +0800
@@ -591,17 +591,36 @@
             ::memcpy(src - marginX + (height + y) * srcStride, src - marginX + (height - 1) * srcStride, sizeof(pixel) * (width + (marginX << 1)));
         }
     }
-    filterHorizontal_p_s<8>(src, srcStride, midA, midStride, width, height, g_lumaFilter[1]);
-    filterHorizontal_p_s<8>(src, srcStride, midB, midStride, width, height, g_lumaFilter[2]);
-    filterHorizontal_p_s<8>(src, srcStride, midC, midStride, width, height, g_lumaFilter[3]);
-    filterConvertShortToPel(midA, midStride, dstA, srcStride, width, height);
-    filterConvertShortToPel(midB, midStride, dstB, srcStride, width, height);
-    filterConvertShortToPel(midC, midStride, dstC, srcStride, width, height);
+
+    filterHorizontal_p_s<8>(src - 4, srcStride, midA - 4, midStride, width + 7, height, g_lumaFilter[1]);
+    filterHorizontal_p_s<8>(src - 4, srcStride, midB - 4, midStride, width + 7, height, g_lumaFilter[2]);
+    filterHorizontal_p_s<8>(src - 4, srcStride, midC - 4, midStride, width + 7, height, g_lumaFilter[3]);
+    filterConvertShortToPel(midA - 4, midStride, dstA - 4, srcStride, width + 7, height);
+    filterConvertShortToPel(midB - 4, midStride, dstB - 4, srcStride, width + 7, height);
+    filterConvertShortToPel(midC - 4, midStride, dstC - 4, srcStride, width + 7, height);
 
     // Extend SubPel Left and Right
-    extendCURowColBorder(dstA, srcStride, width, height, marginX);
-    extendCURowColBorder(dstB, srcStride, width, height, marginX);
-    extendCURowColBorder(dstC, srcStride, width, height, marginX);
+    for(int y = 0; y < height; y++)
+    {
+        for(int x = 0; x < marginX; x++)
+        {
+            // Left
+            if (x < marginX - 4)
+            {
+                dstA[y * srcStride - marginX + x] = dstA[y * srcStride - 4];
+                dstB[y * srcStride - marginX + x] = dstB[y * srcStride - 4];
+                dstC[y * srcStride - marginX + x] = dstC[y * srcStride - 4];
+            }
+
+            // Right
+            if (x > 2)
+            {
+                dstA[y * srcStride + width + x] = dstA[y * srcStride + width + 2];
+                dstB[y * srcStride + width + x] = dstB[y * srcStride + width + 2];
+                dstC[y * srcStride + width + x] = dstC[y * srcStride + width + 2];
+            }
+        }
+    }
 
     if (row == 0)
     {
@@ -613,8 +632,8 @@
             ::memcpy(dstC - marginX - (y + 1) * srcStride, dstC - marginX, sizeof(pixel) * srcStride);
         }
 
-        // Extend midPel Top(only 3 rows)
-        for(int y = 0; y < 3; y++)
+        // Extend midPel Top(7 rows)
+        for(int y = 0; y < 7; y++)
         {
             ::memcpy(midA - (y + 1) * midStride, midA, midStride * sizeof(short));
             ::memcpy(midB - (y + 1) * midStride, midB, midStride * sizeof(short));
@@ -632,8 +651,8 @@
             ::memcpy(dstC - marginX + (height + y) * srcStride, dstC - marginX + (height - 1) * srcStride, sizeof(pixel) * srcStride);
         }
 
-        // Extend midPel Bottom(only 4 rows)
-        for(int y = 0; y < 4; y++)
+        // Extend midPel Bottom(7 rows)
+        for(int y = 0; y < 7; y++)
         {
             ::memcpy(midA + (height + y) * midStride, midA + (height - 1) * midStride, midStride * sizeof(short));
             ::memcpy(midB + (height + y) * midStride, midB + (height - 1) * midStride, midStride * sizeof(short));
@@ -644,68 +663,92 @@
 
 void filterRowV_0(pixel *src, int srcStride, pixel *dstA, pixel *dstB, pixel *dstC, int width, int height, int marginX, int marginY, int row, int isLastRow)
 {
-    filterVertical_p_p<8>(src, srcStride, dstA, srcStride, width, height, g_lumaFilter[1]);
-    filterVertical_p_p<8>(src, srcStride, dstB, srcStride, width, height, g_lumaFilter[2]);
-    filterVertical_p_p<8>(src, srcStride, dstC, srcStride, width, height, g_lumaFilter[3]);
+    int row_first = (row == 0 ? 7 : 0);
+    int row_last = (isLastRow ? 7 : 0);
+
+    filterVertical_p_p<8>(src - row_first * srcStride, srcStride, dstA - row_first * srcStride, srcStride, width, height + row_first + row_last, g_lumaFilter[1]);
+    filterVertical_p_p<8>(src - row_first * srcStride, srcStride, dstB - row_first * srcStride, srcStride, width, height + row_first + row_last, g_lumaFilter[2]);
+    filterVertical_p_p<8>(src - row_first * srcStride, srcStride, dstC - row_first * srcStride, srcStride, width, height + row_first + row_last, g_lumaFilter[3]);
 
     // Extend SubPel Left and Right
-    extendCURowColBorder(dstA, srcStride, width, height, marginX);
-    extendCURowColBorder(dstB, srcStride, width, height, marginX);
-    extendCURowColBorder(dstC, srcStride, width, height, marginX);
+    extendCURowColBorder(dstA - row_first * srcStride, srcStride, width, height + row_first + row_last, marginX);
+    extendCURowColBorder(dstB - row_first * srcStride, srcStride, width, height + row_first + row_last, marginX);
+    extendCURowColBorder(dstC - row_first * srcStride, srcStride, width, height + row_first + row_last, marginX);
 
     if (row == 0)
     {
         // Extend SubPel Top
-        for(int y = 0; y < marginY; y++)
+        for(int y = 7; y < marginY; y++)
         {
-            ::memcpy(dstA - marginX - (y + 1) * srcStride, dstA - marginX, sizeof(pixel) * srcStride);
-            ::memcpy(dstB - marginX - (y + 1) * srcStride, dstB - marginX, sizeof(pixel) * srcStride);
-            ::memcpy(dstC - marginX - (y + 1) * srcStride, dstC - marginX, sizeof(pixel) * srcStride);
+            ::memcpy(dstA - marginX - (y + 1) * srcStride, dstA - marginX - 7 * srcStride, sizeof(pixel) * srcStride);
+            ::memcpy(dstB - marginX - (y + 1) * srcStride, dstB - marginX - 7 * srcStride, sizeof(pixel) * srcStride);
+            ::memcpy(dstC - marginX - (y + 1) * srcStride, dstC - marginX - 7 * srcStride, sizeof(pixel) * srcStride);
         }
     }
 
     if (isLastRow)
     {
         // Extend SubPel Bottom
-        for(int y = 0; y < marginY; y++)
+        for(int y = 7; y < marginY; y++)
         {
-            ::memcpy(dstA - marginX + (height + y) * srcStride, dstA - marginX + (height - 1) * srcStride, sizeof(pixel) * srcStride);
-            ::memcpy(dstB - marginX + (height + y) * srcStride, dstB - marginX + (height - 1) * srcStride, sizeof(pixel) * srcStride);
-            ::memcpy(dstC - marginX + (height + y) * srcStride, dstC - marginX + (height - 1) * srcStride, sizeof(pixel) * srcStride);
+            ::memcpy(dstA - marginX + (height + y) * srcStride, dstA - marginX + (height - 1 + 7) * srcStride, sizeof(pixel) * srcStride);
+            ::memcpy(dstB - marginX + (height + y) * srcStride, dstB - marginX + (height - 1 + 7) * srcStride, sizeof(pixel) * srcStride);
+            ::memcpy(dstC - marginX + (height + y) * srcStride, dstC - marginX + (height - 1 + 7) * srcStride, sizeof(pixel) * srcStride);
         }
     }
 }
 
 void filterRowV_N(short *midA, int midStride, pixel *dstA, pixel *dstB, pixel *dstC, int dstStride, int width, int height, int marginX, int marginY, int row, int isLastRow)
 {
-    filterVertical_s_p<8>(midA, midStride, dstA, dstStride, width, height, g_lumaFilter[1]);
-    filterVertical_s_p<8>(midA, midStride, dstB, dstStride, width, height, g_lumaFilter[2]);
-    filterVertical_s_p<8>(midA, midStride, dstC, dstStride, width, height, g_lumaFilter[3]);
+    int row_first = (row == 0 ? 7 : 0);
+    int row_last = (isLastRow ? 7 : 0);
+
+    filterVertical_s_p<8>(midA - 4 - row_first * midStride, midStride, dstA - 4 - row_first * dstStride, dstStride, width + 7, height + row_first + row_last, g_lumaFilter[1]);
+    filterVertical_s_p<8>(midA - 4 - row_first * midStride, midStride, dstB - 4 - row_first * dstStride, dstStride, width + 7, height + row_first + row_last, g_lumaFilter[2]);
+    filterVertical_s_p<8>(midA - 4 - row_first * midStride, midStride, dstC - 4 - row_first * dstStride, dstStride, width + 7, height + row_first + row_last, g_lumaFilter[3]);
 
     // Extend SubPel Left and Right
-    extendCURowColBorder(dstA, dstStride, width, height, marginX);
-    extendCURowColBorder(dstB, dstStride, width, height, marginX);
-    extendCURowColBorder(dstC, dstStride, width, height, marginX);
+    for(int y = 0; y < height + row_first + row_last; y++)
+    {
+        for(int x = 0; x < marginX; x++)
+        {
+            // Left
+            if (x < marginX - 4)
+            {
+                dstA[(y - row_first) * dstStride - marginX + x] = dstA[(y - row_first) * dstStride - 4];
+                dstB[(y - row_first) * dstStride - marginX + x] = dstB[(y - row_first) * dstStride - 4];
+                dstC[(y - row_first) * dstStride - marginX + x] = dstC[(y - row_first) * dstStride - 4];
+            }
+
+            // Right
+            if (x > 2)
+            {
+                dstA[(y - row_first) * dstStride + width + x] = dstA[(y - row_first) * dstStride + width + 2];
+                dstB[(y - row_first) * dstStride + width + x] = dstB[(y - row_first) * dstStride + width + 2];
+                dstC[(y - row_first) * dstStride + width + x] = dstC[(y - row_first) * dstStride + width + 2];
+            }
+        }
+    }
 
     if (row == 0)
     {
         // Extend SubPel Top
-        for(int y = 0; y < marginY; y++)
+        for(int y = 7; y < marginY; y++)
         {
-            ::memcpy(dstA - marginX - (y + 1) * dstStride, dstA - marginX, sizeof(pixel) * dstStride);
-            ::memcpy(dstB - marginX - (y + 1) * dstStride, dstB - marginX, sizeof(pixel) * dstStride);
-            ::memcpy(dstC - marginX - (y + 1) * dstStride, dstC - marginX, sizeof(pixel) * dstStride);
+            ::memcpy(dstA - marginX - (y + 1) * dstStride, dstA - marginX - 7 * dstStride, sizeof(pixel) * dstStride);
+            ::memcpy(dstB - marginX - (y + 1) * dstStride, dstB - marginX - 7 * dstStride, sizeof(pixel) * dstStride);
+            ::memcpy(dstC - marginX - (y + 1) * dstStride, dstC - marginX - 7 * dstStride, sizeof(pixel) * dstStride);
         }
     }
 
     if (isLastRow)
     {
         // Extend SubPel Bottom
-        for(int y = 0; y < marginY; y++)
+        for(int y = 7; y < marginY; y++)
         {
-            ::memcpy(dstA - marginX + (height + y) * dstStride, dstA - marginX + (height - 1) * dstStride, sizeof(pixel) * dstStride);
-            ::memcpy(dstB - marginX + (height + y) * dstStride, dstB - marginX + (height - 1) * dstStride, sizeof(pixel) * dstStride);
-            ::memcpy(dstC - marginX + (height + y) * dstStride, dstC - marginX + (height - 1) * dstStride, sizeof(pixel) * dstStride);
+            ::memcpy(dstA - marginX + (height + y) * dstStride, dstA - marginX + (height - 1 + 7) * dstStride, sizeof(pixel) * dstStride);
+            ::memcpy(dstB - marginX + (height + y) * dstStride, dstB - marginX + (height - 1 + 7) * dstStride, sizeof(pixel) * dstStride);
+            ::memcpy(dstC - marginX + (height + y) * dstStride, dstC - marginX + (height - 1 + 7) * dstStride, sizeof(pixel) * dstStride);
         }
     }
 }
diff -r 1ce2c5c87b19 -r f5a77ff45760 source/common/reference.cpp
--- a/source/common/reference.cpp	Wed Aug 28 23:26:45 2013 -0500
+++ b/source/common/reference.cpp	Thu Aug 29 17:40:53 2013 +0800
@@ -82,8 +82,8 @@
     for (int i = 0; i < 4; i++)
     {
         // TODO: I am not sure [0] need space when weight, for safe I alloc either, but I DON'T FILL [0] anymore
-        m_midBuf[i] = new short[width * (height + 3 + 4)];  // middle buffer extend size: left(0), right(0), top(3), bottom(4)
-        m_midBuf[i] += 3 * width;
+        m_midBuf[i] = new short[(width + 7) * (height + 7 + 7)];  // middle buffer extend size: left(4), right(3), top(7), bottom(7)
+        m_midBuf[i] += 7 * (width + 7);
     }
 
     if (w) 
@@ -122,7 +122,7 @@
 
     for (int i = 0; i < 4; i++)
     {
-        m_midBuf[i] -= 3 * width;
+        m_midBuf[i] -= 7 * (width + 7);
         if (m_midBuf[i])
         {
             delete[] m_midBuf[i];
@@ -173,7 +173,7 @@
        }
        else
        {
-            int midStride = m_reconPic->getWidth();
+            int midStride = m_reconPic->getWidth() + 7;
             int height = g_maxCUHeight;
             for(int i = 0; i < m_reconPic->m_numCuInHeight; i++ )
             {
@@ -271,7 +271,7 @@
     }
     else
     {
-        int midStride = m_reconPic->getWidth();
+        int midStride = m_reconPic->getWidth() + 7;
         int height = g_maxCUHeight;
         for(int i = 0; i < m_reconPic->m_numCuInHeight; i++ )
         {



More information about the x265-devel mailing list