<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 16, 2014 at 4:49 PM, <span dir="ltr"><<a href="mailto:deepthi@multicorewareinc.com" target="_blank">deepthi@multicorewareinc.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"># HG changeset patch<br>
# User Deepthi Nandakumar <<a href="mailto:deepthi@multicorewareinc.com">deepthi@multicorewareinc.com</a>><br>
# Date 1402916716 -19800<br>
# Mon Jun 16 16:35:16 2014 +0530<br>
# Node ID 4d76a9c8b5abbf143e5869d55cf80a8816d99a68<br>
# Parent ff3a85f715d43e2c21aec295426ae9dbe7c03d75<br>
lambda: change chroma lambda distortion weighting to resemble x264.<br>
<br>
1. x264 scales the chroma distortion by a factor derived from a lambda offset table<br>
when psyRd is enabled.<br>
<br>
2. This patch also removes the separate Cb and Cr distortion weights that were carried over from HM,<br>
and replaces it with 256 when psy-rd is disabled, and the above-mentioned lambda offset when it is enabled.<br>
<br>
diff -r ff3a85f715d4 -r 4d76a9c8b5ab source/Lib/TLibEncoder/TEncSearch.cpp<br>
--- a/source/Lib/TLibEncoder/TEncSearch.cpp Mon Jun 16 16:12:00 2014 +0530<br>
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp Mon Jun 16 16:35:16 2014 +0530<br>
@@ -143,16 +143,22 @@<br>
return false;<br>
}<br>
<br>
-void TEncSearch::setQP(int qp, double crWeight, double cbWeight)<br>
+void TEncSearch::setQP(int qp)<br>
{<br>
- double lambda2 = x265_lambda2_tab[qp];<br>
- double chromaLambda = lambda2 / crWeight;<br>
+ double lambda2 = x265_lambda2_tab[qp];<br>
+<br>
+#define SPEC_QP(x) X265_MIN(x, QP_MAX_SPEC)<br></blockquote><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+ int effective_chroma_qp = chroma_qp_table[SPEC_QP(qp)] + X265_MAX(qp - QP_MAX_SPEC, 0);<br>
+ double chromaLambda = x265_lambda2_tab[effective_chroma_qp];<br>
+ int chroma_offset_idx = X265_MIN (qp - effective_chroma_qp + 12, MAX_CHROMA_LAMBDA_OFFSET);<br>
+ uint64_t chromaWeight = m_rdCost->psyRdEnabled() ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256;<br>
+#undef SPEC_QP<br></blockquote><div> </div><div>Luma to chroma qp mapping should be done as mentioned in the HEVC standards. the array chroma_qp_table[] is written according to H.264 spec. We cant be using that for HEVC.</div>
<div>g_chromaScale[chFmt][qpc]) - gives the correct mapping of chroma qp as per HEVC spec. chroma qp needs to be obtained from luma qp (0-69) before it can be clipped to QP_MAX_SPEC for HEVC.<br></div><div><br></div><div>
<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
m_me.setQP(qp);<br>
m_trQuant->setLambda(lambda2, chromaLambda);<br>
m_rdCost->setLambda(lambda2, x265_lambda_tab[qp]);<br>
- m_rdCost->setCbDistortionWeight(cbWeight);<br>
- m_rdCost->setCrDistortionWeight(crWeight);<br>
+ m_rdCost->setCbDistortionWeight(chromaWeight);<br>
+ m_rdCost->setCrDistortionWeight(chromaWeight);<br>
}<br>
<br>
void TEncSearch::xEncSubdivCbfQT(TComDataCU* cu, uint32_t trDepth, uint32_t absPartIdx, uint32_t absPartIdxStep, uint32_t width, uint32_t height, bool bLuma, bool bChroma)<br>
diff -r ff3a85f715d4 -r 4d76a9c8b5ab source/Lib/TLibEncoder/TEncSearch.h<br>
--- a/source/Lib/TLibEncoder/TEncSearch.h Mon Jun 16 16:12:00 2014 +0530<br>
+++ b/source/Lib/TLibEncoder/TEncSearch.h Mon Jun 16 16:35:16 2014 +0530<br>
@@ -142,7 +142,7 @@<br>
<br>
void setRDGoOnSbacCoder(TEncSbac* rdGoOnSbacCoder) { m_rdGoOnSbacCoder = rdGoOnSbacCoder; }<br>
<br>
- void setQP(int QP, double crWeight, double cbWeight);<br>
+ void setQP(int QP);<br>
<br>
TEncSearch();<br>
virtual ~TEncSearch();<br>
diff -r ff3a85f715d4 -r 4d76a9c8b5ab source/encoder/frameencoder.cpp<br>
--- a/source/encoder/frameencoder.cpp Mon Jun 16 16:12:00 2014 +0530<br>
+++ b/source/encoder/frameencoder.cpp Mon Jun 16 16:35:16 2014 +0530<br>
@@ -363,22 +363,8 @@<br>
}<br>
<br>
void FrameEncoder::setLambda(int qp, int row)<br>
-{<br>
- TComSlice* slice = m_pic->getSlice();<br>
- int chFmt = slice->getSPS()->getChromaFormatIdc();<br>
-<br>
- // for RDO<br>
- // in RdCost there is only one lambda because the luma and chroma bits are not separated,<br>
- // instead we weight the distortion of chroma.<br>
- int chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb();<br>
- int qpc = Clip3(0, MAX_MAX_QP, qp + chromaQPOffset);<br>
- double cbWeight = pow(2.0, (qp - g_chromaScale[chFmt][qpc]) / 3.0); // takes into account of the chroma qp mapping and chroma qp Offset<br>
-<br>
- chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr();<br>
- qpc = Clip3(0, MAX_MAX_QP, qp + chromaQPOffset);<br>
- double crWeight = pow(2.0, (qp - g_chromaScale[chFmt][qpc]) / 3.0); // takes into account of the chroma qp mapping and chroma qp Offset<br>
-<br>
- m_rows[row].m_search.setQP(qp, crWeight, cbWeight);<br>
+{<br>
+ m_rows[row].m_search.setQP(qp);<br>
}<br>
<br>
void FrameEncoder::compressFrame()<br>
@@ -387,7 +373,6 @@<br>
int64_t startCompressTime = x265_mdate();<br>
TEncEntropy* entropyCoder = getEntropyCoder(0);<br>
TComSlice* slice = m_pic->getSlice();<br>
- int chFmt = slice->getSPS()->getChromaFormatIdc();<br>
int totalCoded = (int)m_top->m_encodedFrameNum - 1;<br>
<br>
m_nalCount = 0;<br>
@@ -515,21 +500,13 @@<br>
}<br>
<br>
int qp = slice->getSliceQp();<br>
-<br>
- // for RDO<br>
- // in RdCost there is only one lambda because the luma and chroma bits are not separated,<br>
- // instead we weight the distortion of chroma.<br>
- int qpc;<br>
- int chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb();<br>
- qpc = Clip3(0, MAX_MAX_QP, qp + chromaQPOffset);<br>
- double cbWeight = pow(2.0, (qp - g_chromaScale[chFmt][qpc]) / 3.0); // takes into account of the chroma qp mapping and chroma qp Offset<br>
-<br>
- chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr();<br>
- qpc = Clip3(0, MAX_MAX_QP, qp + chromaQPOffset);<br>
- double crWeight = pow(2.0, (qp - g_chromaScale[chFmt][qpc]) / 3.0); // takes into account of the chroma qp mapping and chroma qp Offset<br>
-<br>
+<br>
double lambda = x265_lambda2_tab[qp];<br>
- double chromaLambda = lambda / crWeight;<br>
+<br>
+#define SPEC_QP(x) X265_MIN(x, QP_MAX_SPEC)<br>
+ int effective_chroma_qp = chroma_qp_table[SPEC_QP(qp)] + X265_MAX(qp - QP_MAX_SPEC, 0);<br>
+ double chromaLambda = x265_lambda2_tab[effective_chroma_qp];<br>
+#undef SPEC_QP<br>
<br>
// NOTE: set SAO lambda every Frame<br>
m_frameFilter.m_sao.lumaLambda = lambda;<br>
@@ -539,7 +516,7 @@<br>
for (int i = 0; i < m_numRows; i++)<br>
{<br>
m_rows[i].m_search.m_me.setSourcePlane(fenc->getLumaAddr(), fenc->getStride());<br>
- m_rows[i].m_search.setQP(qp, crWeight, cbWeight);<br>
+ m_rows[i].m_search.setQP(qp);<br>
}<br>
<br>
// Clip qps back to 0-51 range before encoding<br>
diff -r ff3a85f715d4 -r 4d76a9c8b5ab source/encoder/rdcost.h<br>
--- a/source/encoder/rdcost.h Mon Jun 16 16:12:00 2014 +0530<br>
+++ b/source/encoder/rdcost.h Mon Jun 16 16:35:16 2014 +0530<br>
@@ -53,14 +53,14 @@<br>
m_lambdaSAD = (uint64_t)floor(256.0 * lambda);<br>
}<br>
<br>
- void setCbDistortionWeight(double cbDistortionWeight)<br>
+ void setCbDistortionWeight(uint64_t cbDistortionWeight)<br>
{<br>
- m_cbDistortionWeight = (uint64_t)floor(256.0 * cbDistortionWeight);<br>
+ m_cbDistortionWeight = cbDistortionWeight;<br>
}<br>
<br>
- void setCrDistortionWeight(double crDistortionWeight)<br>
+ void setCrDistortionWeight(uint64_t crDistortionWeight)<br>
{<br>
- m_crDistortionWeight = (uint64_t)floor(256.0 * crDistortionWeight);<br>
+ m_crDistortionWeight = crDistortionWeight;<br>
}<br>
<br>
void setPsyRdScale(double scale)<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></div></div>