<div dir="ltr">Thanks, pushed.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 23, 2014 at 2:13 PM, Satoshi Nakagawa <span dir="ltr"><<a href="mailto:nakagawa424@oki.com" target="_blank">nakagawa424@oki.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 Satoshi Nakagawa <<a href="mailto:nakagawa424@oki.com">nakagawa424@oki.com</a>><br>
# Date 1419324053 -32400<br>
#      Tue Dec 23 17:40:53 2014 +0900<br>
# Node ID 36bde0fab6510684879e6ad996ab7d5acab86a5e<br>
# Parent  9fdab427a1918939293539f07b49ce77c5104912<br>
rdcost: unify scaleChromaDist*()<br>
<br>
diff -r 9fdab427a191 -r 36bde0fab651 source/encoder/rdcost.h<br>
--- a/source/encoder/rdcost.h   Tue Dec 23 12:17:08 2014 +0530<br>
+++ b/source/encoder/rdcost.h   Tue Dec 23 17:40:53 2014 +0900<br>
@@ -37,15 +37,12 @@<br>
     /* all weights and factors stored as FIX8 */<br>
     uint64_t  m_lambda2;<br>
     uint64_t  m_lambda;<br>
-    uint64_t  m_cbDistortionWeight;<br>
-    uint64_t  m_crDistortionWeight;<br>
+    uint32_t  m_chromaDistWeight[2];<br>
     uint32_t  m_psyRdBase;<br>
     uint32_t  m_psyRd;<br>
     int       m_qp;<br>
<br>
     void setPsyRdScale(double scale)                { m_psyRdBase = (uint32_t)floor(256.0 * scale * 0.33); }<br>
-    void setCbDistortionWeight(uint16_t weightFix8) { m_cbDistortionWeight = weightFix8; }<br>
-    void setCrDistortionWeight(uint16_t weightFix8) { m_crDistortionWeight = weightFix8; }<br>
<br>
     void setQP(const Slice& slice, int qp)<br>
     {<br>
@@ -62,7 +59,7 @@<br>
             qpCb = X265_MIN(qp + slice.m_pps->chromaQpOffset[0], QP_MAX_SPEC);<br>
         int chroma_offset_idx = X265_MIN(qp - qpCb + 12, MAX_CHROMA_LAMBDA_OFFSET);<br>
         uint16_t lambdaOffset = m_psyRd ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256;<br>
-        setCbDistortionWeight(lambdaOffset);<br>
+        m_chromaDistWeight[0] = lambdaOffset;<br>
<br>
         if (slice.m_sps->chromaFormatIdc == X265_CSP_I420)<br>
             qpCr = Clip3(QP_MIN, QP_MAX_MAX, (int)g_chromaScale[qp + slice.m_pps->chromaQpOffset[0]]);<br>
@@ -70,7 +67,7 @@<br>
             qpCr = X265_MIN(qp + slice.m_pps->chromaQpOffset[0], QP_MAX_SPEC);<br>
         chroma_offset_idx = X265_MIN(qp - qpCr + 12, MAX_CHROMA_LAMBDA_OFFSET);<br>
         lambdaOffset = m_psyRd ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256;<br>
-        setCrDistortionWeight(lambdaOffset);<br>
+        m_chromaDistWeight[1] = lambdaOffset;<br>
     }<br>
<br>
     void setLambda(double lambda2, double lambda)<br>
@@ -82,7 +79,7 @@<br>
     inline uint64_t calcRdCost(uint32_t distortion, uint32_t bits) const<br>
     {<br>
         X265_CHECK(bits <= (UINT64_MAX - 128) / m_lambda2,<br>
-                   "calcRdCost wrap detected dist: %d, bits %d, lambda: %d\n", distortion, bits, (int)m_lambda2);<br>
+                   "calcRdCost wrap detected dist: %u, bits %u, lambda: "X265_LL"\n", distortion, bits, m_lambda2);<br>
         return distortion + ((bits * m_lambda2 + 128) >> 8);<br>
     }<br>
<br>
@@ -107,22 +104,15 @@<br>
     inline uint64_t calcRdSADCost(uint32_t sadCost, uint32_t bits) const<br>
     {<br>
         X265_CHECK(bits <= (UINT64_MAX - 128) / m_lambda,<br>
-                   "calcRdSADCost wrap detected dist: %d, bits %d, lambda: "X265_LL"\n", sadCost, bits, m_lambda);<br>
+                   "calcRdSADCost wrap detected dist: %u, bits %u, lambda: "X265_LL"\n", sadCost, bits, m_lambda);<br>
         return sadCost + ((bits * m_lambda + 128) >> 8);<br>
     }<br>
<br>
-    inline uint32_t scaleChromaDistCb(uint32_t dist) const<br>
+    inline uint32_t scaleChromaDist(uint32_t plane, uint32_t dist) const<br>
     {<br>
-        X265_CHECK(dist <= (UINT64_MAX - 128) / m_cbDistortionWeight,<br>
-                   "scaleChromaDistCb wrap detected dist: %d, lambda: "X265_LL"\n", dist, m_cbDistortionWeight);<br>
-        return (uint32_t)(((dist * m_cbDistortionWeight) + 128) >> 8);<br>
-    }<br>
-<br>
-    inline uint32_t scaleChromaDistCr(uint32_t dist) const<br>
-    {<br>
-        X265_CHECK(dist <= (UINT64_MAX - 128) / m_crDistortionWeight,<br>
-                   "scaleChromaDistCr wrap detected dist: %d, lambda: "X265_LL"\n", dist, m_crDistortionWeight);<br>
-        return (uint32_t)(((dist * m_crDistortionWeight) + 128) >> 8);<br>
+        X265_CHECK(dist <= (UINT64_MAX - 128) / m_chromaDistWeight[plane - 1],<br>
+                   "scaleChromaDist wrap detected dist: %u, lambda: %u\n", dist, m_chromaDistWeight[plane - 1]);<br>
+        return (uint32_t)((dist * (uint64_t)m_chromaDistWeight[plane - 1] + 128) >> 8);<br>
     }<br>
<br>
     inline uint32_t getCost(uint32_t bits) const<br>
diff -r 9fdab427a191 -r 36bde0fab651 source/encoder/search.cpp<br>
--- a/source/encoder/search.cpp Tue Dec 23 12:17:08 2014 +0530<br>
+++ b/source/encoder/search.cpp Tue Dec 23 17:40:53 2014 +0900<br>
@@ -813,7 +813,6 @@<br>
<br>
             primitives.calcresidual[sizeIdxC](fenc, pred, residual, stride);<br>
             uint32_t numSig = m_quant.transformNxN(cu, fenc, stride, residual, stride, coeffC, log2TrSizeC, ttype, absPartIdxC, false);<br>
-            uint32_t tmpDist;<br>
             if (numSig)<br>
             {<br>
                 m_quant.invtransformNxN(cu.m_tqBypass[0], residual, stride, coeffC, log2TrSizeC, ttype, true, false, numSig);<br>
@@ -827,8 +826,7 @@<br>
                 cu.setCbfPartRange(0, ttype, absPartIdxC, tuIterator.absPartIdxStep);<br>
             }<br>
<br>
-            tmpDist = primitives.sse_pp[sizeIdxC](reconQt, reconQtStride, fenc, stride);<br>
-            outDist += (ttype == TEXT_CHROMA_U) ? m_rdCost.scaleChromaDistCb(tmpDist) : m_rdCost.scaleChromaDistCr(tmpDist);<br>
+            outDist += m_rdCost.scaleChromaDist(chromaId, primitives.sse_pp[sizeIdxC](reconQt, reconQtStride, fenc, stride));<br>
<br>
             if (m_rdCost.m_psyRd)<br>
                 psyEnergy += m_rdCost.psyCost(sizeIdxC, fenc, stride, picReconC, picStride);<br>
@@ -932,7 +930,7 @@<br>
                     cu.setCbfPartRange(0, ttype, absPartIdxC, tuIterator.absPartIdxStep);<br>
                 }<br>
                 uint32_t tmpDist = primitives.sse_pp[sizeIdxC](recon, reconStride, fenc, stride);<br>
-                tmpDist = (ttype == TEXT_CHROMA_U) ? m_rdCost.scaleChromaDistCb(tmpDist) : m_rdCost.scaleChromaDistCr(tmpDist);<br>
+                tmpDist = m_rdCost.scaleChromaDist(chromaId, tmpDist);<br>
<br>
                 cu.setTransformSkipPartRange(useTSkip, ttype, absPartIdxC, tuIterator.absPartIdxStep);<br>
<br>
@@ -2442,8 +2440,8 @@<br>
     interMode.distortion = primitives.sse_pp[part](fencYuv->m_buf[0], fencYuv->m_size, reconYuv->m_buf[0], reconYuv->m_size);<br>
     // Chroma<br>
     part = partitionFromSizes(cuSize >> m_hChromaShift, cuSize >> m_vChromaShift);<br>
-    interMode.distortion += m_rdCost.scaleChromaDistCb(primitives.sse_pp[part](fencYuv->m_buf[1], fencYuv->m_csize, reconYuv->m_buf[1], reconYuv->m_csize));<br>
-    interMode.distortion += m_rdCost.scaleChromaDistCr(primitives.sse_pp[part](fencYuv->m_buf[2], fencYuv->m_csize, reconYuv->m_buf[2], reconYuv->m_csize));<br>
+    interMode.distortion += m_rdCost.scaleChromaDist(1, primitives.sse_pp[part](fencYuv->m_buf[1], fencYuv->m_csize, reconYuv->m_buf[1], reconYuv->m_csize));<br>
+    interMode.distortion += m_rdCost.scaleChromaDist(2, primitives.sse_pp[part](fencYuv->m_buf[2], fencYuv->m_csize, reconYuv->m_buf[2], reconYuv->m_csize));<br>
<br>
     m_entropyCoder.load(m_rqt[depth].cur);<br>
     m_entropyCoder.resetBits();<br>
@@ -2496,8 +2494,8 @@<br>
     if (!cu.m_tqBypass[0])<br>
     {<br>
         uint32_t cbf0Dist = primitives.sse_pp[part](fencYuv->m_buf[0], fencYuv->m_size, predYuv->m_buf[0], predYuv->m_size);<br>
-        cbf0Dist += m_rdCost.scaleChromaDistCb(primitives.sse_pp[cpart](fencYuv->m_buf[1], predYuv->m_csize, predYuv->m_buf[1], predYuv->m_csize));<br>
-        cbf0Dist += m_rdCost.scaleChromaDistCr(primitives.sse_pp[cpart](fencYuv->m_buf[2], predYuv->m_csize, predYuv->m_buf[2], predYuv->m_csize));<br>
+        cbf0Dist += m_rdCost.scaleChromaDist(1, primitives.sse_pp[cpart](fencYuv->m_buf[1], predYuv->m_csize, predYuv->m_buf[1], predYuv->m_csize));<br>
+        cbf0Dist += m_rdCost.scaleChromaDist(2, primitives.sse_pp[cpart](fencYuv->m_buf[2], predYuv->m_csize, predYuv->m_buf[2], predYuv->m_csize));<br>
<br>
         /* Consider the RD cost of not signaling any residual */<br>
         m_entropyCoder.load(m_rqt[depth].cur);<br>
@@ -2569,8 +2567,8 @@<br>
<br>
     // update with clipped distortion and cost (qp estimation loop uses unclipped values)<br>
     uint32_t bestDist = primitives.sse_pp[part](fencYuv->m_buf[0], fencYuv->m_size, reconYuv->m_buf[0], reconYuv->m_size);<br>
-    bestDist += m_rdCost.scaleChromaDistCb(primitives.sse_pp[cpart](fencYuv->m_buf[1], fencYuv->m_csize, reconYuv->m_buf[1], reconYuv->m_csize));<br>
-    bestDist += m_rdCost.scaleChromaDistCr(primitives.sse_pp[cpart](fencYuv->m_buf[2], fencYuv->m_csize, reconYuv->m_buf[2], reconYuv->m_csize));<br>
+    bestDist += m_rdCost.scaleChromaDist(1, primitives.sse_pp[cpart](fencYuv->m_buf[1], fencYuv->m_csize, reconYuv->m_buf[1], reconYuv->m_csize));<br>
+    bestDist += m_rdCost.scaleChromaDist(2, primitives.sse_pp[cpart](fencYuv->m_buf[2], fencYuv->m_csize, reconYuv->m_buf[2], reconYuv->m_csize));<br>
     if (m_rdCost.m_psyRd)<br>
         interMode.psyEnergy = m_rdCost.psyCost(log2CUSize - 2, fencYuv->m_buf[0], fencYuv->m_size, reconYuv->m_buf[0], reconYuv->m_size);<br>
<br>
@@ -2918,7 +2916,7 @@<br>
                     singleBitsPrev = newBits;<br>
<br>
                     int16_t* curResiC = m_rqt[qtLayer].resiQtYuv.getChromaAddr(chromaId, absPartIdxC);<br>
-                    distC = m_rdCost.scaleChromaDistCb(primitives.ssd_s[log2TrSizeC - 2](resiYuv.getChromaAddr(chromaId, absPartIdxC), resiYuv.m_csize));<br>
+                    distC = m_rdCost.scaleChromaDist(chromaId, primitives.ssd_s[log2TrSizeC - 2](resiYuv.getChromaAddr(chromaId, absPartIdxC), resiYuv.m_csize));<br>
<br>
                     if (cbfFlag[chromaId][tuIterator.section])<br>
                     {<br>
@@ -2929,7 +2927,7 @@<br>
                         // finally we have to encode correct cbf after comparing with null cost<br>
                         uint32_t dist = primitives.sse_ss[partSizeC](resiYuv.getChromaAddr(chromaId, absPartIdxC), resiYuv.m_csize, curResiC, strideResiC);<br>
                         uint32_t nzCbfBitsC = m_entropyCoder.estimateCbfBits(cbfFlag[chromaId][tuIterator.section], (TextType)chromaId, tuDepth);<br>
-                        uint32_t nonZeroDistC = m_rdCost.scaleChromaDistCb(dist);<br>
+                        uint32_t nonZeroDistC = m_rdCost.scaleChromaDist(chromaId, dist);<br>
                         uint32_t nonZeroPsyEnergyC = 0; uint64_t singleCostC = 0;<br>
                         if (m_rdCost.m_psyRd)<br>
                         {<br>
@@ -3088,7 +3086,7 @@<br>
                         m_quant.invtransformNxN(cu.m_tqBypass[absPartIdxC], tsResiC, trSizeC, tsCoeffC,<br>
                                                 log2TrSizeC, (TextType)chromaId, false, true, numSigTSkipC);<br>
                         uint32_t dist = primitives.sse_ss[partSizeC](resiYuv.getChromaAddr(chromaId, absPartIdxC), resiYuv.m_csize, tsResiC, trSizeC);<br>
-                        nonZeroDistC = m_rdCost.scaleChromaDistCb(dist);<br>
+                        nonZeroDistC = m_rdCost.scaleChromaDist(chromaId, dist);<br>
                         if (m_rdCost.m_psyRd)<br>
                         {<br>
                             nonZeroPsyEnergyC = m_rdCost.psyCost(partSizeC, resiYuv.getChromaAddr(chromaId, absPartIdxC), resiYuv.m_csize, tsResiC, trSizeC);<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>