<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Sep 22, 2013 at 11:40 PM, Min Chen <span dir="ltr"><<a href="mailto:chenm003@163.com" target="_blank">chenm003@163.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 Min Chen <<a href="mailto:chenm003@163.com">chenm003@163.com</a>><br>
# Date 1379911059 -28800<br>
# Node ID b009957b4443ef790936c80f9df538e75d742306<br>
# Parent cec05efee900c68cb09ddd4135133836bb2e9c3b<br>
Reduce half HPEL interpolate works by merge nest point<br></blockquote><div><br></div><div>This is interesting, but it needs a better commit message, probably some more comments, and definitely a better method name. I can probably clean this up pretty quickly on my end, just need to discuss a few details with you.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
diff -r cec05efee900 -r b009957b4443 source/common/vec/ipfilter8.inc<br>
--- a/source/common/vec/ipfilter8.inc Mon Sep 23 12:37:26 2013 +0800<br>
+++ b/source/common/vec/ipfilter8.inc Mon Sep 23 12:37:39 2013 +0800<br>
@@ -679,7 +679,8 @@<br>
<br>
int row, col;<br>
<br>
- assert(height % 2 == 0);<br>
+ if (N == 4)<br>
+ assert(height % 2 == 0);<br>
<br>
uint32_t leftCols = (8 - (width & 7)) * 8;<br>
uint32_t mask_shift = ((uint32_t)~0 >> leftCols);<br>
diff -r cec05efee900 -r b009957b4443 source/encoder/motion.cpp<br>
--- a/source/encoder/motion.cpp Mon Sep 23 12:37:26 2013 +0800<br>
+++ b/source/encoder/motion.cpp Mon Sep 23 12:37:39 2013 +0800<br>
@@ -87,8 +87,8 @@<br>
init_scales();<br>
<br>
fenc = (pixel*)X265_MALLOC(pixel, MAX_CU_SIZE * MAX_CU_SIZE);<br>
- subpelbuf = (pixel*)X265_MALLOC(pixel, MAX_CU_SIZE * MAX_CU_SIZE);<br>
- immedVal = (short*)X265_MALLOC(short, MAX_CU_SIZE * (MAX_CU_SIZE + NTAPS_LUMA - 1));<br>
+ subpelbuf = (pixel*)X265_MALLOC(pixel, (MAX_CU_SIZE + 1) * (MAX_CU_SIZE + 1));<br>
+ immedVal = (short*)X265_MALLOC(short, (MAX_CU_SIZE + 1) * (MAX_CU_SIZE + 1 + NTAPS_LUMA - 1));<br>
}<br>
<br>
MotionEstimate::~MotionEstimate()<br>
@@ -122,6 +122,7 @@<br>
static const MV hex2[8] = { MV(-1, -2), MV(-2, 0), MV(-1, 2), MV(1, 2), MV(2, 0), MV(1, -2), MV(-1, -2), MV(-2, 0) };<br>
static const uint8_t mod6m1[8] = { 5, 0, 1, 2, 3, 4, 5, 0 }; /* (x-1)%6 */<br>
static const MV square1[9] = { MV(0, 0), MV(0, -1), MV(0, 1), MV(-1, 0), MV(1, 0), MV(-1, -1), MV(-1, 1), MV(1, -1), MV(1, 1) };<br>
+static const int square1_dir[9] = { 0, 1, 1, 2, 2, 1, 1, 1, 1 };<br>
static const MV hex4[16] =<br>
{<br>
MV(0, -4), MV(0, 4), MV(-2, -3), MV(2, -3),<br>
@@ -793,17 +794,55 @@<br>
else<br>
hpelcomp = sad;<br>
<br>
- for (int iter = 0; iter < wl.hpel_iters; iter++)<br>
+ if (ref->isLowres)<br>
{<br>
- int bdir = 0, cost;<br>
- for (int i = 1; i <= wl.hpel_dirs; i++)<br>
+ for (int iter = 0; iter < wl.hpel_iters; iter++)<br>
{<br>
- MV qmv = bmv + square1[i] * 2;<br>
- cost = subpelCompare(ref, qmv, hpelcomp) + mvcost(qmv);<br>
- COPY2_IF_LT(bcost, cost, bdir, i);<br>
+ int bdir = 0, cost;<br>
+ for (int i = 1; i <= wl.hpel_dirs; i++)<br>
+ {<br>
+ MV qmv = bmv + square1[i] * 2;<br>
+ cost = subpelCompare(ref, qmv, hpelcomp) + mvcost(qmv);<br>
+ COPY2_IF_LT(bcost, cost, bdir, i+0);<br>
+ }<br>
+ bmv += square1[bdir] * 2;<br>
}<br>
+ }<br>
+ else<br>
+ {<br>
+ for (int iter = 0; iter < wl.hpel_iters; iter++)<br>
+ {<br>
+ int bdir = 0, cost0, cost1;<br>
+ for (int i = 1; i <= wl.hpel_dirs; i+=2)<br>
+ {<br>
+ MV qmv0 = bmv + square1[i ] * 2;<br>
+ MV qmv1 = bmv + square1[i+1] * 2;<br>
+ int mvcost0 = mvcost(qmv0);<br>
+ int mvcost1 = mvcost(qmv1);<br>
+ int dir = square1_dir[i];<br>
<br>
- bmv += square1[bdir] * 2;<br>
+ pixel *fref = ref->fpelPlane + blockOffset + (qmv0.x >> 2) + (qmv0.y >> 2) * ref->lumaStride;<br>
+ int xFrac = qmv0.x & 0x3;<br>
+ int yFrac = qmv0.y & 0x3;<br>
+<br>
+ // TODO: sad_x2<br>
+ if (xFrac == 0 && yFrac == 0)<br>
+ {<br>
+ intptr_t offset = (dir == 2) + (dir == 1 ? ref->lumaStride : 0);<br>
+ cost0 = hpelcomp(fenc, FENC_STRIDE, fref, ref->lumaStride) + mvcost0;<br>
+ cost1 = hpelcomp(fenc, FENC_STRIDE, fref + offset, ref->lumaStride) + mvcost1;<br>
+ }<br>
+ else<br>
+ {<br>
+ subpelInterpolate2(fref, ref->lumaStride, xFrac, yFrac, dir);<br>
+ cost0 = hpelcomp(fenc, FENC_STRIDE, subpelbuf, FENC_STRIDE + (dir == 2)) + mvcost0;<br>
+ cost1 = hpelcomp(fenc, FENC_STRIDE, subpelbuf + (dir == 2) + (dir == 1 ? FENC_STRIDE : 0), FENC_STRIDE + (dir == 2)) + mvcost1;<br>
+ }<br>
+ COPY2_IF_LT(bcost, cost0, bdir, i+0);<br>
+ COPY2_IF_LT(bcost, cost1, bdir, i+1);<br>
+ }<br>
+ bmv += square1[bdir] * 2;<br>
+ }<br>
}<br>
/* if HPEL search used SAD, remeasure with SATD before QPEL */<br>
if (!wl.hpel_satd)<br>
@@ -1125,3 +1164,28 @@<br>
return cmp(fenc, FENC_STRIDE, subpelbuf, FENC_STRIDE);<br>
}<br>
}<br>
+<br>
+void MotionEstimate::subpelInterpolate2(pixel *fref, intptr_t lumaStride, int xFrac, int yFrac, int dir)<br>
+{<br>
+ assert(yFrac | xFrac);<br>
+<br>
+ int realWidth = blockwidth + (dir == 2);<br>
+ int realHeight = blockheight + (dir == 1);<br>
+ intptr_t realStride = FENC_STRIDE + (dir == 2);<br>
+<br>
+ if (yFrac == 0)<br>
+ {<br>
+ primitives.ipfilter_pp[FILTER_H_P_P_8](fref, lumaStride, subpelbuf, realStride, realWidth, realHeight, g_lumaFilter[xFrac]);<br>
+ }<br>
+ else if (xFrac == 0)<br>
+ {<br>
+ primitives.ipfilter_pp[FILTER_V_P_P_8](fref, lumaStride, subpelbuf, realStride, realWidth, realHeight, g_lumaFilter[yFrac]);<br>
+ }<br>
+ else<br>
+ {<br>
+ int filterSize = NTAPS_LUMA;<br>
+ int halfFilterSize = (filterSize >> 1);<br>
+ primitives.ipfilter_ps[FILTER_H_P_S_8](fref - (halfFilterSize - 1) * lumaStride, lumaStride, immedVal, realWidth, realWidth, realHeight + filterSize - 1, g_lumaFilter[xFrac]);<br>
+ primitives.ipfilter_sp[FILTER_V_S_P_8](immedVal + (halfFilterSize - 1) * realWidth, realWidth, subpelbuf, realStride, realWidth, realHeight, g_lumaFilter[yFrac]);<br>
+ }<br>
+}<br>
diff -r cec05efee900 -r b009957b4443 source/encoder/motion.h<br>
--- a/source/encoder/motion.h Mon Sep 23 12:37:26 2013 +0800<br>
+++ b/source/encoder/motion.h Mon Sep 23 12:37:39 2013 +0800<br>
@@ -95,6 +95,7 @@<br>
int motionEstimate(ReferencePlanes *ref, const MV & mvmin, const MV & mvmax, const MV & qmvp, int numCandidates, const MV * mvc, int merange, MV & outQMv);<br>
<br>
int subpelCompare(ReferencePlanes *ref, const MV & qmv, pixelcmp_t);<br>
+ void subpelInterpolate2(pixel *fref, intptr_t lumaStride, int xFrac, int yFrac, int dir);<br>
<br>
protected:<br>
<br>
<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>