<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Nov 13, 2013 at 6:40 AM,  <span dir="ltr"><<a href="mailto:shazeb@multicorewareinc.com" target="_blank">shazeb@multicorewareinc.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Shazeb Nawaz Khan <<a href="mailto:shazeb@multicorewareinc.com">shazeb@multicorewareinc.com</a>><br>
# Date 1384346304 -19800<br>
#      Wed Nov 13 18:08:24 2013 +0530<br>
# Node ID a7b6c5a45c69814e35473af81a5d2a0299d634ca<br>
# Parent  213808a2069d21c49a4d5e99d71ad71b8af344b8<br>
Using weighted lowres ref frames in cost estimation in lookahead<br>
<br>
diff -r 213808a2069d -r a7b6c5a45c69 source/common/lowres.cpp<br>
--- a/source/common/lowres.cpp  Wed Nov 13 18:03:02 2013 +0530<br>
+++ b/source/common/lowres.cpp  Wed Nov 13 18:08:24 2013 +0530<br>
@@ -40,6 +40,7 @@<br>
     int cuWidth = (width + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;<br>
     int cuHeight = (lines + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;<br>
     int cuCount = cuWidth * cuHeight;<br>
+    bufferSize = lumaStride * (lines + 2 * orig->getLumaMarginY());<br></blockquote><div><br></div><div>it seems bufferSize is only used below to know the number of lines to weight?  this could be done more efficiently </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
     /* rounding the width to multiple of lowres CU size */<br>
     width = cuWidth * X265_LOWRES_CU_SIZE;<br>
@@ -115,6 +116,18 @@<br>
     X265_FREE(invQscaleFactor);<br>
 }<br>
<br>
+void Lowres::initWeighted(Lowres *ref, wpScalingParam *w)<br>
+{<br>
+    isWeighted = true;<br>
+    int correction = (IF_INTERNAL_PREC - X265_DEPTH);<br>
+    for (int i = 0; i < 4; i++)<br>
+    {<br>
+        //Adding (IF_INTERNAL_PREC - X265_DEPTH) to cancel effect of pixel to short conversion inside the primitive<br></blockquote><div><br></div><div>space after //</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+        primitives.weightpUniPixel(ref->buffer[i], this->buffer[i], lumaStride, lumaStride, lumaStride, (int) bufferSize / lumaStride, w->inputWeight, (1<<(w->log2WeightDenom - 1 + correction)), (w->log2WeightDenom + correction), w->inputOffset);<br>
</blockquote><div><br></div><div>white-space</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+    }<br>
+    fpelPlane = lowresPlane[0];<br>
+}<br>
+<br>
 // (re) initialize lowres state<br>
 void Lowres::init(TComPicYuv *orig, int poc, int type, int bframes)<br>
 {<br>
diff -r 213808a2069d -r a7b6c5a45c69 source/common/lowres.h<br>
--- a/source/common/lowres.h    Wed Nov 13 18:03:02 2013 +0530<br>
+++ b/source/common/lowres.h    Wed Nov 13 18:08:24 2013 +0530<br>
@@ -33,6 +33,7 @@<br>
<br>
 class TComPic;<br>
 class TComPicYuv;<br>
+typedef struct WpScalingParam wpScalingParam;<br>
<br>
 struct ReferencePlanes<br>
 {<br>
@@ -100,6 +101,7 @@<br>
 struct Lowres : public ReferencePlanes<br>
 {<br>
     pixel *buffer[4];<br>
+    int bufferSize;<br>
<br>
     int    frameNum;         // Presentation frame number<br>
     int    sliceType;        // Slice type decided by lookahead<br>
@@ -132,6 +134,7 @@<br>
     void create(TComPic *pic, int bframes, int32_t *aqMode);<br>
     void destroy(int bframes);<br>
     void init(TComPicYuv *orig, int poc, int sliceType, int bframes);<br>
+    void initWeighted(Lowres *ref, wpScalingParam *w);<br>
 };<br>
 }<br>
<br>
diff -r 213808a2069d -r a7b6c5a45c69 source/encoder/slicetype.cpp<br>
--- a/source/encoder/slicetype.cpp      Wed Nov 13 18:03:02 2013 +0530<br>
+++ b/source/encoder/slicetype.cpp      Wed Nov 13 18:08:24 2013 +0530<br>
@@ -79,12 +79,16 @@<br>
     widthInCU = ((cfg->param.sourceWidth / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;<br>
     heightInCU = ((cfg->param.sourceHeight / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;<br>
<br>
+    weightedRef.buffer[0] = NULL;<br>
+<br>
     lhrows = new LookaheadRow[heightInCU];<br>
     for (int i = 0; i < heightInCU; i++)<br>
     {<br>
         lhrows[i].widthInCU = widthInCU;<br>
         lhrows[i].heightInCU = heightInCU;<br>
         lhrows[i].frames = frames;<br>
+        lhrows[i].weightedRef = &weightedRef;<br>
+        lhrows[i].cfg = cfg;<br></blockquote><div><br></div><div>lookahead rows should not need cfg</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

     }<br>
 }<br>
<br>
@@ -127,7 +131,11 @@<br>
 void Lookahead::addPicture(TComPic *pic, int sliceType)<br>
 {<br>
     pic->m_lowres.init(pic->getPicYuvOrg(), pic->getSlice()->getPOC(), sliceType, cfg->param.bframes);<br>
-<br>
+    if (weightedRef.buffer[0] == NULL)<br></blockquote><div><br></div><div>drop "== NULL"</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+    {<br>
+        // Just using width/height data from the pic to create a standalone Lowres object<br>
+        weightedRef.create(pic, cfg->param.bframes, &cfg->param.rc.aqMode);<br>
+    }<br>
     inputQueue.pushBack(*pic);<br>
     if (inputQueue.size() >= cfg->param.lookaheadDepth)<br>
         slicetypeDecide();<br>
@@ -347,6 +355,14 @@<br>
             if( cfg->param.bEnableWeightedPred && b==p1)<br>
             {<br>
                 weightsAnalyse(b, p0, 1, &wp);<br>
+                if (wp.bPresentFlag)<br>
+                {<br>
+                    weightedRef.initWeighted(frames[p0], &wp);<br></blockquote><div><br></div><div>weightsAnalyze should call this function directly.  Actually, wp could be a stack variable in weightsAnalyze()</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+                }<br>
+                else<br>
+                {<br>
+                    weightedRef.isWeighted = false;<br>
+                }<br>
             }<br>
             bDoSearch[0] = b != p0 && fenc->lowresMvs[0][b - p0 - 1][0].x == 0x7FFF;<br>
             bDoSearch[1] = b != p1 && fenc->lowresMvs[1][p1 - b - 1][0].x == 0x7FFF;<br>
@@ -437,6 +453,11 @@<br>
     Lowres *fref1 = frames[p1];<br>
     Lowres *fenc  = frames[b];<br>
<br>
+    if (weightedRef->isWeighted)<br>
+    {<br>
+        fref0 = weightedRef;<br>
+    }<br>
+<br>
     const int bBidir = (b < p1);<br>
     const int cuXY = cux + cuy * widthInCU;<br>
     const int cuSize = X265_LOWRES_CU_SIZE;<br>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Steve Borho
</div></div>