<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Oct 18, 2013 at 6:57 AM, Gopu Govindaswamy <span dir="ltr"><<a href="mailto:gopu@multicorewareinc.com" target="_blank">gopu@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 Gopu Govindaswamy <<a href="mailto:gopu@multicorewareinc.com">gopu@multicorewareinc.com</a>><br>
# Date 1382097422 -19800<br>
# Node ID bb56d24edc2b2565bad644719b5e0194cf3fa845<br>
# Parent 48afd41e075345cc485ffbe14b33fafc87a4e1ba<br>
encoder:auto-padding to min CU size and set conformance window<br>
<br>
diff -r 48afd41e0753 -r bb56d24edc2b source/Lib/TLibCommon/TComPicYuv.cpp<br>
--- a/source/Lib/TLibCommon/TComPicYuv.cpp Fri Oct 18 10:29:53 2013 +0530<br>
+++ b/source/Lib/TLibCommon/TComPicYuv.cpp Fri Oct 18 17:27:02 2013 +0530<br>
@@ -74,7 +74,7 @@<br>
m_cuWidth = maxCUWidth;<br>
m_cuHeight = maxCUHeight;<br>
<br>
- int numCuInWidth = (m_picWidth + m_cuWidth - 1) / m_cuWidth;<br>
+ int numCuInWidth = (m_picWidth + m_cuWidth - 1) / m_cuWidth;<br>
int numCuInHeight = (m_picHeight + m_cuHeight - 1) / m_cuHeight;<br>
<br>
m_numCuInWidth = numCuInWidth;<br>
@@ -88,9 +88,9 @@<br>
m_chromaMarginY = m_lumaMarginY >> 1;<br>
m_strideC = (m_picWidth >> 1) + (m_chromaMarginX << 1);<br>
<br>
- m_picBufY = (Pel*)X265_MALLOC(Pel, (m_picWidth + (m_lumaMarginX << 1)) * (m_picHeight + (m_lumaMarginY << 1)));<br>
- m_picBufU = (Pel*)X265_MALLOC(Pel, ((m_picWidth >> 1) + (m_chromaMarginX << 1)) * ((m_picHeight >> 1) + (m_chromaMarginY << 1)));<br>
- m_picBufV = (Pel*)X265_MALLOC(Pel, ((m_picWidth >> 1) + (m_chromaMarginX << 1)) * ((m_picHeight >> 1) + (m_chromaMarginY << 1)));<br>
+ m_picBufY = (Pel*)X265_MALLOC(Pel, (m_picWidth + (m_lumaMarginX << 1)) * (m_picHeight + (m_lumaMarginY << 1)) + (m_picHeight * m_picWidth));<br>
+ m_picBufU = (Pel*)X265_MALLOC(Pel, ((m_picWidth >> 1) + (m_chromaMarginX << 1)) * ((m_picHeight >> 1) + (m_chromaMarginY << 1)) + (m_picHeight * m_picWidth));<br>
+ m_picBufV = (Pel*)X265_MALLOC(Pel, ((m_picWidth >> 1) + (m_chromaMarginX << 1)) * ((m_picHeight >> 1) + (m_chromaMarginY << 1)) + (m_picHeight * m_picWidth));<br></blockquote><div><br></div><div>
<br></div><div>this is doubling the size of each picture malloc, and is completely unnecessary. m_picWidth and m_picHeight are already padded,</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
m_picOrgY = m_picBufY + m_lumaMarginY * getStride() + m_lumaMarginX;<br>
m_picOrgU = m_picBufU + m_chromaMarginY * getCStride() + m_chromaMarginX;<br>
@@ -357,7 +357,7 @@<br>
* Upscale pixels from 8bits to 16 bits when required, but do not modify pixels.<br>
* This new routine is GPL<br>
*/<br>
-void TComPicYuv::copyFromPicture(const x265_picture_t& pic)<br>
+void TComPicYuv::copyFromPicture(const x265_picture_t& pic, uint32_t hpad)<br>
{<br>
Pel *Y = getLumaAddr();<br>
Pel *U = getCbAddr();<br>
@@ -402,25 +402,52 @@<br>
#endif // if HIGH_BIT_DEPTH<br>
{<br>
int width = m_picWidth * (pic.bitDepth > 8 ? 2 : 1);<br>
+ int height = m_picHeight - hpad;<br>
+ uint32_t pady = width - pic.stride[0];<br></blockquote><div><br></div><div>you can't make any assumptions that pic.stride[0] is the same as the param.inputWidth the user passed in. You need to pass both x and y pad into this function. hpad and pady are an odd pair of names. how does pady relate to the horizontal (or X) padding?</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ // copy pixels by row into encoder's buffer<br>
+ for (int r = 0; r < height; r++)<br>
+ {<br>
+ memcpy(Y, y, pic.stride[0]);<br>
+ /* Extend the row at right is not multiple of the minimum CU size */<br>
+ if (pady)<br>
+ ::memset(Y + pic.stride[0], Y[pic.stride[0] - 1], pady);<br>
<br>
- // copy pixels by row into encoder's buffer<br>
- for (int r = 0; r < m_picHeight; r++)<br>
- {<br>
- memcpy(Y, y, width);<br>
-<br>
- Y += getStride();<br>
+ Y += getStride(); //width + margin + padsize<br>
y += pic.stride[0];<br>
}<br>
<br>
- for (int r = 0; r < m_picHeight >> 1; r++)<br>
+ uint32_t padu = (width >> 1) - pic.stride[1];<br>
+ uint32_t padv = (width >> 1) - pic.stride[2];<br></blockquote><div><br></div><div>ditto here</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ for (int r = 0; r < height >> 1; r++)<br>
{<br>
- memcpy(U, u, width >> 1);<br>
- memcpy(V, v, width >> 1);<br>
+ memcpy(U, u, pic.stride[1]);<br>
+ memcpy(V, v, pic.stride[2]);<br>
+ /* Extend the row at right is not multiple of the minimum CU size */<br>
+ if (padu)<br>
+ ::memset(U + pic.stride[1], U[pic.stride[1] - 1], padu);<br>
+ if (padv)<br>
+ ::memset(V + pic.stride[2], V[pic.stride[2] - 1], padv);<br>
<br>
U += getCStride();<br>
V += getCStride();<br>
u += pic.stride[1];<br>
v += pic.stride[2];<br>
}<br>
+<br>
+ /* extend the top if height is not multiple of the minimum CU size */<br>
+ if (hpad)<br>
+ {<br>
+ Pel *Y = getLumaAddr();<br>
+ Pel *U = getCbAddr();<br>
+ Pel *V = getCrAddr();<br>
+ for (uint32_t i = 0; i < hpad; i++)<br>
+ memcpy(Y - (i + 1) * getStride(), Y, getStride() * sizeof(pixel));<br>
+<br>
+ for (uint32_t y = 0; y < hpad; y++)<br>
+ {<br>
+ memcpy(U - (y + 1) * getCStride(), U, getCStride() * sizeof(pixel));<br>
+ memcpy(V - (y + 1) * getCStride(), V, getCStride() * sizeof(pixel));<br>
+ }<br>
+ }<br>
}<br>
}<br>
diff -r 48afd41e0753 -r bb56d24edc2b source/Lib/TLibCommon/TComPicYuv.h<br>
--- a/source/Lib/TLibCommon/TComPicYuv.h Fri Oct 18 10:29:53 2013 +0530<br>
+++ b/source/Lib/TLibCommon/TComPicYuv.h Fri Oct 18 17:27:02 2013 +0530<br>
@@ -178,7 +178,7 @@<br>
void copyToPicLuma(TComPicYuv* destYuv);<br>
void copyToPicCb(TComPicYuv* destYuv);<br>
void copyToPicCr(TComPicYuv* destYuv);<br>
- void copyFromPicture(const x265_picture_t&);<br>
+ void copyFromPicture(const x265_picture_t&, uint32_t hpad);<br>
<br>
MotionReference* generateMotionReference(wpScalingParam *w);<br>
<br>
diff -r 48afd41e0753 -r bb56d24edc2b source/common/common.cpp<br>
--- a/source/common/common.cpp Fri Oct 18 10:29:53 2013 +0530<br>
+++ b/source/common/common.cpp Fri Oct 18 17:27:02 2013 +0530<br>
@@ -250,10 +250,6 @@<br>
"Minimum partition width size should be larger than or equal to 8");<br>
CHECK(param->maxCUSize < 16,<br>
"Maximum partition width size should be larger than or equal to 16");<br>
- CHECK((param->sourceWidth % (param->maxCUSize >> (maxCUDepth - 1))) != 0,<br>
- "Resulting coded frame width must be a multiple of the minimum CU size");<br>
- CHECK((param->sourceHeight % (param->maxCUSize >> (maxCUDepth - 1))) != 0,<br>
- "Resulting coded frame height must be a multiple of the minimum CU size");<br>
<br>
CHECK((1u << tuQTMaxLog2Size) > param->maxCUSize,<br>
"QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller.");<br>
diff -r 48afd41e0753 -r bb56d24edc2b source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp Fri Oct 18 10:29:53 2013 +0530<br>
+++ b/source/encoder/encoder.cpp Fri Oct 18 17:27:02 2013 +0530<br>
@@ -179,7 +179,7 @@<br>
<br>
/* Copy input picture into a TComPic, send to lookahead */<br>
pic->getSlice()->setPOC(++m_pocLast);<br>
- pic->getPicYuvOrg()->copyFromPicture(*pic_in);<br>
+ pic->getPicYuvOrg()->copyFromPicture(*pic_in, getPad(1));<br></blockquote><div><br></div><div>you could just pass m_pad</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
pic->m_userData = pic_in->userData;<br>
pic->m_pts = pic_in->pts;<br>
<br>
@@ -971,9 +971,30 @@<br>
m_maxCuDQPDepth = 0;<br>
m_maxNumOffsetsPerPic = 2048;<br>
m_log2ParallelMergeLevelMinus2 = 0;<br>
- m_conformanceWindow.setWindow(0, 0, 0, 0);<br>
- int nullpad[2] = { 0, 0 };<br>
- setPad(nullpad);<br>
+ int pad[2] = { 0, 0 };<br>
+<br>
+ //======== set pad size if width is not multiple of the minimum CU size =========<br>
+ uint32_t maxCUDepth = (uint32_t)g_convertToBit[_param->maxCUSize];<br></blockquote><div> </div><div>making a tempvar here for minCUdepth would make this more clear </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ if ((_param->sourceWidth % (_param->maxCUSize >> (maxCUDepth - 1))) != 0)<br>
+ {<br>
+ uint32_t padsize = 0;<br>
+ uint32_t rem = _param->sourceWidth % (_param->maxCUSize >> (maxCUDepth - 1));<br>
+ padsize = (_param->maxCUSize >> (maxCUDepth - 1)) - rem;<br>
+ _param->sourceWidth += padsize;<br>
+ pad[0] = padsize;<br>
+ }<br>
+<br>
+ //======== set pad size if height is not multiple of the minimum CU size =========<br>
+ if ((_param->sourceHeight % (_param->maxCUSize >> (maxCUDepth - 1))) != 0)<br>
+ {<br>
+ uint32_t padsize = 0;<br>
+ uint32_t rem = _param->sourceHeight % (_param->maxCUSize >> (maxCUDepth - 1));<br>
+ padsize = (_param->maxCUSize >> (maxCUDepth - 1)) - rem;<br>
+ _param->sourceHeight += padsize;<br>
+ pad[1] = padsize;<br>
+ }<br>
+ setPad(pad);<br></blockquote><div><br></div><div>this is ok; logic wise, but you might as well directly operate on m_pad from TEncCfg and remove the setPad()/getPad() methods</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ m_conformanceWindow.setWindow(0, getPad(0), getPad(1), 0);<br></blockquote><div><br></div><div>And directly set m_conformanceWindow and remove the set/get methods</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
m_progressiveSourceFlag = true;<br>
m_interlacedSourceFlag = false;<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>