[x265] [PATCH REVIEW] Generating weighted full-pels in compressCTURows

shazeb at multicorewareinc.com shazeb at multicorewareinc.com
Fri Sep 27 14:45:05 CEST 2013


# HG changeset patch
# User Shazeb Nawaz Khan <shazeb at multicorewareinc.com>
# Date 1380285873 -19800
#      Fri Sep 27 18:14:33 2013 +0530
# Node ID 0cc42fd8c556e317ef6d5adaa407f372576bfe2d
# Parent  4014edcf215747ba4ac8147b1168f8edc6f5d64c
Generating weighted full-pels in compressCTURows

We are re-enabling weightP after introduction of frame parallelism. Not yet using the weighted pixels.

diff -r 4014edcf2157 -r 0cc42fd8c556 source/common/reference.cpp
--- a/source/common/reference.cpp	Fri Sep 27 02:18:36 2013 -0500
+++ b/source/common/reference.cpp	Fri Sep 27 18:14:33 2013 +0530
@@ -24,6 +24,7 @@
 
 #include "TLibCommon/TypeDef.h"
 #include "TLibCommon/TComPicYuv.h"
+#include "TLibCommon/TComPic.h"
 #include "TLibCommon/TComSlice.h"
 #include "primitives.h"
 #include "reference.h"
@@ -57,6 +58,8 @@
     lumaStride = pic->getStride();
     m_startPad = pic->m_lumaMarginY * lumaStride + pic->m_lumaMarginX;
     m_next = NULL;
+    isWeighted = false;
+    numWghtdRows = 0;
 
     if (w)
     {
@@ -78,5 +81,67 @@
 MotionReference::~MotionReference()
 {
     if (isWeighted)
-        X265_FREE(fpelPlane);
+        X265_FREE(fpelPlane - m_startPad);
 }
+
+void MotionReference::applyWeight(TComPic* ref, int rows)
+{
+    TComPicYuv* pic = ref->getPicYuvRec();
+    pixel *src = (pixel*) pic->getLumaAddr();
+    pixel *dst = fpelPlane;
+    int marginX = pic->m_lumaMarginX;
+    int marginY = pic->m_lumaMarginY;
+
+    int width = pic->getWidth();
+    int height = ((rows - numWghtdRows) * g_maxCUHeight);
+    if (rows == m_numRows - 1) height = ((pic->getHeight() % g_maxCUHeight) ? (pic->getHeight() % g_maxCUHeight) : g_maxCUHeight);
+
+    size_t dstStride = lumaStride;
+
+    // Computing weighted CU rows
+    int shiftNum = IF_INTERNAL_PREC - X265_DEPTH;
+    shift = shift + shiftNum;
+    round = shift ? (1 << (shift - 1)) : 0;
+
+    int x, y;
+    for (y = height - 1; y >= numWghtdRows * (int)g_maxCUHeight; y--)
+    {
+        for (x = width - 1; x >= 0; )
+        {
+            // note: luma min width is 4
+            dst[x] = (pixel)Clip3(0, ((1 << X265_DEPTH) - 1), ((weight * (src[x] + IF_INTERNAL_OFFS) + round) >> shift) + offset);
+            x--;
+            dst[x] = (pixel)Clip3(0, ((1 << X265_DEPTH) - 1), ((weight * (src[x] + IF_INTERNAL_OFFS) + round) >> shift) + offset);
+            x--;
+        }
+
+        src += lumaStride;
+        dst += dstStride;
+    }
+
+    // Extending Left & Right
+    primitives.extendRowBorder(fpelPlane, dstStride, width, height, marginX);
+
+    // Extending Above
+    if (numWghtdRows == 0)
+    {
+        pixel *pixY = fpelPlane - marginX;
+
+        for (int y = 0; y < marginY; y++)
+        {
+            memcpy(pixY - (y + 1) * dstStride, pixY, dstStride * sizeof(pixel));
+        }
+    }
+
+    // Extending Bottom
+    if (rows == (m_numRows - 1))
+    {
+        pixel *pixY = fpelPlane - marginX + (pic->getHeight() - 1) * dstStride;
+
+        for (int y = 0; y < marginY; y++)
+        {
+            memcpy(pixY + (y + 1) * dstStride, pixY, dstStride * sizeof(pixel));
+        }
+    }
+    numWghtdRows = rows;
+}
\ No newline at end of file
diff -r 4014edcf2157 -r 0cc42fd8c556 source/common/reference.h
--- a/source/common/reference.h	Fri Sep 27 02:18:36 2013 -0500
+++ b/source/common/reference.h	Fri Sep 27 18:14:33 2013 +0530
@@ -30,6 +30,7 @@
 // private x265 namespace
 
 class TComPicYuv;
+class TComPic;
 struct WpScalingParam;
 typedef WpScalingParam wpScalingParam;
 
@@ -60,8 +61,13 @@
 
     ~MotionReference();
 
+    void applyWeight(TComPic* src, int rows);
+    void extendRow(TComPic* pic, int row);
+
     MotionReference *m_next;
     TComPicYuv      *m_reconPic;
+    int              numWghtdRows;
+    int              m_numRows;
 
 protected:
 
diff -r 4014edcf2157 -r 0cc42fd8c556 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Fri Sep 27 02:18:36 2013 -0500
+++ b/source/encoder/frameencoder.cpp	Fri Sep 27 18:14:33 2013 +0530
@@ -914,6 +914,11 @@
                     {
                         refpic->m_reconRowWait.wait();
                     }
+                    if(slice->getPPS()->getUseWP())
+                    {
+                        slice->m_mref[list][ref]->m_numRows = m_numRows;
+                        slice->m_mref[list][ref]->applyWeight(refpic, row + refLagRows);
+                    }
                 }
             }
 
diff -r 4014edcf2157 -r 0cc42fd8c556 source/x265opts.h
--- a/source/x265opts.h	Fri Sep 27 02:18:36 2013 -0500
+++ b/source/x265opts.h	Fri Sep 27 18:14:33 2013 +0530
@@ -69,8 +69,8 @@
 OPT("ref",             param->maxNumReferences,       required_argument, 0, "max number of L0 references to be allowed  (1 .. 16)")
 // Disabled because weighted uni-prediction was busted by not using
 // pre-generated planes in motion compensation
-//OPT("no-weightp",      param->bEnableWeightedPred,          no_argument, 0, "Disable weighted prediction in P slices")
-//OPT("weightp",         param->bEnableWeightedPred,          no_argument, 'w', "Enable weighted prediction in P slices")
+OPT("no-weightp",      param->bEnableWeightedPred,          no_argument, 0, "Disable weighted prediction in P slices")
+OPT("weightp",         param->bEnableWeightedPred,          no_argument, 'w', "Enable weighted prediction in P slices")
 // Disabled because weighted bi prediction is busted
 //OPT("no-weightbp",     param->bEnableWeightedBiPred,        no_argument, 0, "Disable weighted (bidirectional) prediction in B slices")
 //OPT("weightbp",        param->bEnableWeightedBiPred,        no_argument, 0, "Enable weighted (bidirectional) prediction in B slices")


More information about the x265-devel mailing list