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

shazeb at multicorewareinc.com shazeb at multicorewareinc.com
Mon Sep 30 13:01:26 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 cc94f1a5c6ab1975502f6a0edfc4aa4233733597
# Parent  55edc34e253c14d3eccb83a7d1db43774349ff9a
Generating weighted full-pels in compressCTURows

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

diff -r 55edc34e253c -r cc94f1a5c6ab source/Lib/TLibCommon/TComPicYuv.cpp
--- a/source/Lib/TLibCommon/TComPicYuv.cpp	Sat Sep 28 22:54:44 2013 -0500
+++ b/source/Lib/TLibCommon/TComPicYuv.cpp	Fri Sep 27 18:14:33 2013 +0530
@@ -250,7 +250,8 @@
         else if (mref->isWeighted == false)
             return mref;
     }
-    mref = new MotionReference(this, w);
+    mref = new MotionReference();
+    mref->init(this, w);
     mref->m_next = m_refList;
     m_refList = mref;
     return mref;
diff -r 55edc34e253c -r cc94f1a5c6ab source/Lib/TLibCommon/TComWeightPrediction.cpp
--- a/source/Lib/TLibCommon/TComWeightPrediction.cpp	Sat Sep 28 22:54:44 2013 -0500
+++ b/source/Lib/TLibCommon/TComWeightPrediction.cpp	Fri Sep 27 18:14:33 2013 +0530
@@ -431,7 +431,7 @@
         srcStride = srcYuv0->m_width;
         dstStride  = outDstYuv->getStride();
 
-        primitives.weightpUni(srcY0, dstY, srcStride, dstStride, width, height, w0, round, shift, offset);
+        primitives.weightpUniShort(srcY0, dstY, srcStride, dstStride, width, height, w0, round, shift, offset, 0);
     }
 
     // Chroma U : --------------------------------------------
@@ -447,7 +447,7 @@
     width  >>= 1;
     height >>= 1;
 
-    primitives.weightpUni(srcU0, dstU, srcStride, dstStride, width, height, w0, round, shift, offset);
+    primitives.weightpUniShort(srcU0, dstU, srcStride, dstStride, width, height, w0, round, shift, offset, 0);
 
     // Chroma V : --------------------------------------------
     w0      = wp0[2].w;
@@ -455,7 +455,7 @@
     shift   = wp0[2].shift + shiftNum;
     round   = shift ? (1 << (shift - 1)) : 0;
 
-    primitives.weightpUni(srcV0, dstV, srcStride, dstStride, width, height, w0, round, shift, offset);
+    primitives.weightpUniShort(srcV0, dstV, srcStride, dstStride, width, height, w0, round, shift, offset, 0);
 }
 
 //=======================================================
diff -r 55edc34e253c -r cc94f1a5c6ab source/common/pixel.cpp
--- a/source/common/pixel.cpp	Sat Sep 28 22:54:44 2013 -0500
+++ b/source/common/pixel.cpp	Fri Sep 27 18:14:33 2013 +0530
@@ -514,17 +514,19 @@
     }
 }
 
-void weightUnidir(short *src, pixel *dst, intptr_t srcStride, intptr_t dstStride, int width, int height, int w0, int round, int shift, int offset)
+template <typename T>
+void weightUnidir(void *srcAbstract, pixel *dst, intptr_t srcStride, intptr_t dstStride, int width, int height, int w0, int round, int shift, int offset, int startHeight)
 {
+    T *src = static_cast<T *>(srcAbstract);
     int x, y;
-    for (y = height - 1; y >= 0; y--)
+    for (y = height - 1; y >= startHeight; y--)
     {
         for (x = width - 1; x >= 0; )
         {
             // note: luma min width is 4
-            dst[x] = (pixel) Clip3(0, ((1 << X265_DEPTH) - 1), ((w0 * (src[x] + IF_INTERNAL_OFFS) + round) >> shift) + offset);
+            dst[x] = (pixel) Clip3(0, ((1 << X265_DEPTH) - 1), ((w0 * (uint16_t) (src[x] + IF_INTERNAL_OFFS) + round) >> shift) + offset);
             x--;
-            dst[x] = (pixel) Clip3(0, ((1 << X265_DEPTH) - 1), ((w0 * (src[x] + IF_INTERNAL_OFFS) + round) >> shift) + offset);
+            dst[x] = (pixel) Clip3(0, ((1 << X265_DEPTH) - 1), ((w0 * (uint16_t) (src[x] + IF_INTERNAL_OFFS) + round) >> shift) + offset);
             x--;
         }
 
@@ -842,7 +844,8 @@
     p.transpose[3] = transpose<32>;
     p.transpose[4] = transpose<64>;
 
-    p.weightpUni = weightUnidir;
+    p.weightpUniPixel = weightUnidir<pixel>;
+    p.weightpUniShort = weightUnidir<short>;
 
     p.pixelsub_sp = pixelsub_sp_c;
     p.pixeladd_pp = pixeladd_pp_c;
diff -r 55edc34e253c -r cc94f1a5c6ab source/common/primitives.h
--- a/source/common/primitives.h	Sat Sep 28 22:54:44 2013 -0500
+++ b/source/common/primitives.h	Fri Sep 27 18:14:33 2013 +0530
@@ -228,8 +228,7 @@
 typedef void (*filterRowV_N_t)(short *midA, intptr_t midStride, pixel *dstA, pixel *dstB, pixel *dstC, intptr_t dstStride, int width, int height, int marginX, int marginY, int row, int isLastRow);
 typedef void (*extendCURowBorder_t)(pixel* txt, intptr_t stride, int width, int height, int marginX);
 
-
-typedef void (*weightpUni_t)(short *src, pixel *dst, intptr_t srcStride, intptr_t dstStride, int width, int height, int w0, int round, int shift, int offset);
+typedef void (*weightpUni_t)(void *src, pixel *dst, intptr_t srcStride, intptr_t dstStride, int width, int height, int w0, int round, int shift, int offset, int startHeight);
 typedef void (*scale_t)(pixel *dst, pixel *src, intptr_t stride);
 typedef void (*downscale_t)(pixel *src0, pixel *dstf, pixel *dsth, pixel *dstv, pixel *dstc,
                             intptr_t src_stride, intptr_t dst_stride, int width, int height);
@@ -286,7 +285,8 @@
     calcrecon_t     calcrecon[NUM_SQUARE_BLOCKS];
     transpose_t     transpose[NUM_SQUARE_BLOCKS];
 
-    weightpUni_t    weightpUni;
+    weightpUni_t    weightpUniPixel;
+    weightpUni_t    weightpUniShort;
     pixelsub_sp_t   pixelsub_sp;
     pixeladd_ss_t   pixeladd_ss;
     pixeladd_pp_t   pixeladd_pp;
diff -r 55edc34e253c -r cc94f1a5c6ab source/common/reference.cpp
--- a/source/common/reference.cpp	Sat Sep 28 22:54:44 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"
@@ -51,12 +52,17 @@
     return false;
 }
 
-MotionReference::MotionReference(TComPicYuv* pic, wpScalingParam *w)
+MotionReference::MotionReference()
+{}
+
+int MotionReference::init(TComPicYuv* pic, wpScalingParam *w)
 {
     m_reconPic = pic;
     lumaStride = pic->getStride();
     m_startPad = pic->m_lumaMarginY * lumaStride + pic->m_lumaMarginX;
     m_next = NULL;
+    isWeighted = false;
+    m_numWeightedRows = 0;
 
     if (w)
     {
@@ -66,17 +72,66 @@
         size_t padheight = height + pic->m_lumaMarginY * 2;
 
         setWeight(*w);
-        fpelPlane = (pixel*)X265_MALLOC(pixel,  padwidth * padheight) + m_startPad;
+        fpelPlane = (pixel*)X265_MALLOC(pixel,  padwidth * padheight);
+        if (fpelPlane) fpelPlane += m_startPad;
+        else return -1;
     }
     else
     {
         /* directly reference the pre-extended integer pel plane */
         fpelPlane = pic->m_picBufY + m_startPad;
     }
+    return 0;
 }
 
 MotionReference::~MotionReference()
 {
     if (isWeighted)
-        X265_FREE(fpelPlane);
+        X265_FREE(fpelPlane - m_startPad);
 }
+
+void MotionReference::applyWeight(TComPic* ref, int rows, int numRows)
+{
+    TComPicYuv* pic = ref->getPicYuvRec();
+    int marginX = pic->m_lumaMarginX;
+    int marginY = pic->m_lumaMarginY;
+
+    int width = pic->getWidth();
+    int height = ((rows - m_numWeightedRows) * g_maxCUHeight);
+    if (rows == 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;
+
+    primitives.weightpUniPixel((pixel*) pic->getLumaAddr(), fpelPlane, lumaStride, dstStride, width, height, weight, round, shift, offset,  m_numWeightedRows * (int)g_maxCUHeight);
+
+    // Extending Left & Right
+    primitives.extendRowBorder(fpelPlane, dstStride, width, height, marginX);
+
+    // Extending Above
+    if (m_numWeightedRows == 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 == (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));
+        }
+    }
+    m_numWeightedRows = rows;
+}
diff -r 55edc34e253c -r cc94f1a5c6ab source/common/reference.h
--- a/source/common/reference.h	Sat Sep 28 22:54:44 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;
 
@@ -56,12 +57,17 @@
 {
 public:
 
-    MotionReference(TComPicYuv*, wpScalingParam* w = NULL);
+    MotionReference();
 
     ~MotionReference();
 
+    void applyWeight(TComPic* src, int rows, int numRows);
+    void extendRow(TComPic* pic, int row);
+    int  init(TComPicYuv*, wpScalingParam* w = NULL);
+
     MotionReference *m_next;
     TComPicYuv      *m_reconPic;
+    int              m_numWeightedRows;
 
 protected:
 
diff -r 55edc34e253c -r cc94f1a5c6ab source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Sat Sep 28 22:54:44 2013 -0500
+++ b/source/encoder/frameencoder.cpp	Fri Sep 27 18:14:33 2013 +0530
@@ -914,6 +914,10 @@
                     {
                         refpic->m_reconRowWait.wait();
                     }
+                    if(slice->getPPS()->getUseWP())
+                    {
+                        slice->m_mref[list][ref]->applyWeight(refpic, row + refLagRows, m_numRows);
+                    }
                 }
             }
 
diff -r 55edc34e253c -r cc94f1a5c6ab source/x265opts.h
--- a/source/x265opts.h	Sat Sep 28 22:54:44 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