<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">2014/1/3  <span dir="ltr"><<a href="mailto:ashok@multicorewareinc.com" target="_blank">ashok@multicorewareinc.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
# HG changeset patch<br>
# User <a href="mailto:ashok@multicorewareinc.com">ashok@multicorewareinc.com</a><br>
# Date 1388753602 -19800<br>
#      Fri Jan 03 18:23:22 2014 +0530<br>
# Node ID 6a602378d31b983db4f4293621c35e73f91f9922<br>
# Parent  98e238489f843ff233c512570c1fab75b2ff801a<br>
Modify TEncSearch structure to support multiple color space formats<br>
<br>
diff -r 98e238489f84 -r 6a602378d31b source/Lib/TLibEncoder/TEncSearch.cpp<br>
--- a/source/Lib/TLibEncoder/TEncSearch.cpp     Fri Jan 03 18:21:41 2014 +0530<br>
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp     Fri Jan 03 18:23:22 2014 +0530<br>
@@ -229,13 +229,10 @@<br>
<br>
     if (bChroma)<br>
     {<br>
-        if (trSizeLog2 > 2)<br>
-        {<br>
-            if (trDepth == 0 || cu->getCbf(absPartIdx, TEXT_CHROMA_U, trDepth - 1))<br>
-                m_entropyCoder->encodeQtCbf(cu, absPartIdx, TEXT_CHROMA_U, trDepth);<br>
-            if (trDepth == 0 || cu->getCbf(absPartIdx, TEXT_CHROMA_V, trDepth - 1))<br>
-                m_entropyCoder->encodeQtCbf(cu, absPartIdx, TEXT_CHROMA_V, trDepth);<br>
-        }<br>
+        if (trDepth == 0 || cu->getCbf(absPartIdx, TEXT_CHROMA_U, trDepth - 1))<br>
+            m_entropyCoder->encodeQtCbf(cu, absPartIdx, TEXT_CHROMA_U, trDepth);<br>
+        if (trDepth == 0 || cu->getCbf(absPartIdx, TEXT_CHROMA_V, trDepth - 1))<br>
+            m_entropyCoder->encodeQtCbf(cu, absPartIdx, TEXT_CHROMA_V, trDepth);<br>
     }<br>
<br>
     if (subdiv)<br>
@@ -275,7 +272,7 @@<br>
         return;<br>
     }<br>
<br>
-    if (ttype != TEXT_LUMA && trSizeLog2 == 2)<br>
+    if ( (ttype != TEXT_LUMA) && (trSizeLog2 == 2) && !(cu->getChromaFormat() == CHROMA_444))<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>
         assert(trDepth > 0);<br>
         trDepth--;<br>
@@ -288,9 +285,11 @@<br>
     }<br>
<br>
     //===== coefficients =====<br>
-    uint32_t width = cu->getWidth(0) >> (trDepth + chroma);<br>
-    uint32_t height = cu->getHeight(0) >> (trDepth + chroma);<br>
-    uint32_t coeffOffset = (cu->getPic()->getMinCUWidth() * cu->getPic()->getMinCUHeight() * absPartIdx) >> (chroma << 1);<br>
+    int cspx = chroma ? m_hChromaShift : 0;<br>
+    int cspy = chroma ? m_vChromaShift : 0;<br>
+    uint32_t width = cu->getWidth(0) >> (trDepth + cspx);<br>
+    uint32_t height = cu->getHeight(0) >> (trDepth + cspy);<br>
+    uint32_t coeffOffset = (cu->getPic()->getMinCUWidth() >> cspx) * (cu->getPic()->getMinCUHeight() >> cspy) * absPartIdx;<br>
     uint32_t qtLayer = cu->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - trSizeLog2;<br>
     TCoeff* coeff = 0;<br>
     switch (ttype)<br>
@@ -363,12 +362,23 @@<br>
             }<br>
         }<br>
     }<br>
+<br>
     if (bChroma)<br>
     {<br>
         // chroma prediction mode<br>
-        if (absPartIdx == 0)<br>
+        if ((cu->getPartitionSize(0) == SIZE_2Nx2N) || !(cu->getChromaFormat() == CHROMA_444))<br>
         {<br>
-            m_entropyCoder->encodeIntraDirModeChroma(cu, 0, true);<br>
+            if (absPartIdx == 0)<br>
+            {<br>
+                m_entropyCoder->encodeIntraDirModeChroma(cu, absPartIdx, true);<br>
+            }<br>
+        }<br>
+        else<br>
+        {<br>
+            uint32_t qtNumParts = cu->getTotalNumPart() >> 2;<br>
+            assert(trDepth > 0);<br>
+            if ((absPartIdx%qtNumParts) == 0)<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">
+                m_entropyCoder->encodeIntraDirModeChroma(cu, absPartIdx, true);<br>
         }<br>
     }<br>
 }<br>
@@ -475,7 +485,7 @@<br>
     int lastPos = -1;<br>
     cu->setTrIdxSubParts(trDepth, absPartIdx, fullDepth);<br>
<br>
-    m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0);<br>
+    m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());<br>
     m_trQuant->selectLambda(TEXT_LUMA);<br>
<br>
     absSum = m_trQuant->transformNxN(cu, residual, stride, coeff, width, height, TEXT_LUMA, absPartIdx, &lastPos, useTransformSkip);<br>
@@ -520,7 +530,7 @@<br>
     uint32_t fullDepth   = cu->getDepth(0) + trDepth;<br>
     uint32_t trSizeLog2  = g_convertToBit[cu->getSlice()->getSPS()->getMaxCUWidth() >> fullDepth] + 2;<br>
<br>
-    if (trSizeLog2 == 2)<br>
+    if ((trSizeLog2 == 2) && !(cu->getChromaFormat() == CHROMA_444))<br>
     {<br>
         assert(trDepth > 0);<br>
         trDepth--;<br>
@@ -534,7 +544,7 @@<br>
<br>
     TextType ttype          = (chromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U);<br>
     uint32_t chromaPredMode = cu->getChromaIntraDir(absPartIdx);<br>
-    uint32_t width          = cu->getWidth(0) >> (trDepth + m_hChromaShift);<br>
+    uint32_t width          = cu->getWidth(0)  >> (trDepth + m_hChromaShift);<br>
     uint32_t height         = cu->getHeight(0) >> (trDepth + m_vChromaShift);<br>
     uint32_t stride         = fencYuv->getCStride();<br>
     Pel*     fenc           = (chromaId > 0 ? fencYuv->getCrAddr(absPartIdx) : fencYuv->getCbAddr(absPartIdx));<br>
@@ -543,10 +553,10 @@<br>
     Pel*     recon          = (chromaId > 0 ? predYuv->getCrAddr(absPartIdx) : predYuv->getCbAddr(absPartIdx));<br>
<br>
     uint32_t qtlayer        = cu->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - trSizeLog2;<br>
-    uint32_t numCoeffPerInc = (cu->getSlice()->getSPS()->getMaxCUWidth() * cu->getSlice()->getSPS()->getMaxCUHeight() >> (cu->getSlice()->getSPS()->getMaxCUDepth() << 1)) >> 2;<br>

+    uint32_t numCoeffPerInc = (cu->getSlice()->getSPS()->getMaxCUWidth() * cu->getSlice()->getSPS()->getMaxCUHeight() >> (cu->getSlice()->getSPS()->getMaxCUDepth() << 1)) >> (m_hChromaShift + m_vChromaShift);<br>

     TCoeff*  coeff          = (chromaId > 0 ? m_qtTempCoeffCr[qtlayer] : m_qtTempCoeffCb[qtlayer]) + numCoeffPerInc * absPartIdx;<br>
     int16_t* reconQt        = (chromaId > 0 ? m_qtTempTComYuv[qtlayer].getCrAddr(absPartIdx) : m_qtTempTComYuv[qtlayer].getCbAddr(absPartIdx));<br>
-    assert(m_qtTempTComYuv[qtlayer].m_cwidth == MAX_CU_SIZE / 2);<br>
+    uint32_t reconQtStride  = m_qtTempTComYuv[qtlayer].m_cwidth;<br>
<br>
     uint32_t zorder           = cu->getZorderIdxInCU() + absPartIdx;<br>
     Pel*     reconIPred       = (chromaId > 0 ? cu->getPic()->getPicYuvRec()->getCrAddr(cu->getAddr(), zorder) : cu->getPic()->getPicYuvRec()->getCbAddr(cu->getAddr(), zorder));<br>
@@ -557,7 +567,7 @@<br>
     //===== update chroma mode =====<br>
     if (chromaPredMode == DM_CHROMA_IDX)<br>
     {<br>
-        chromaPredMode = cu->getLumaIntraDir(0);<br>
+        chromaPredMode = cu->getLumaIntraDir(absPartIdx);<br>
     }<br>
<br>
     //===== init availability pattern =====<br>
@@ -565,11 +575,11 @@<br>
     {<br>
         cu->getPattern()->initPattern(cu, trDepth, absPartIdx);<br>
<br>
-        cu->getPattern()->initAdiPatternChroma(cu, absPartIdx, trDepth, m_predBuf, m_predBufStride, m_predBufHeight);<br>
+        cu->getPattern()->initAdiPatternChroma(cu, absPartIdx, trDepth, m_predBuf, m_predBufStride, m_predBufHeight, chromaId);<br>
         Pel* chromaPred = (chromaId > 0 ? cu->getPattern()->getAdiCrBuf(width, height, m_predBuf) : cu->getPattern()->getAdiCbBuf(width, height, m_predBuf));<br>
<br>
         //===== get prediction signal =====<br>
-        predIntraChromaAng(chromaPred, chromaPredMode, pred, stride, width);<br>
+        predIntraChromaAng(chromaPred, chromaPredMode, pred, stride, width, height, cu->getChromaFormat());<br></blockquote><div><br></div><div>we should cache the chroma format in TComPrediction</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
         // save prediction<br>
         if (default0Save1Load2 == 1)<br>
@@ -612,7 +622,7 @@<br>
         {<br>
             curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();<br>
         }<br>
-        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
<br>
         m_trQuant->selectLambda(TEXT_CHROMA);<br>
<br>
@@ -639,7 +649,7 @@<br>
     //===== reconstruction =====<br>
     assert(((uint32_t)(size_t)residual & (width - 1)) == 0);<br>
     assert(width <= 32);<br>
-    primitives.calcrecon[size](pred, residual, recon, reconQt, reconIPred, stride, MAX_CU_SIZE / 2, reconIPredStride);<br>
+    primitives.calcrecon[size](pred, residual, recon, reconQt, reconIPred, stride, reconQtStride, reconIPredStride);<br>
<br>
     //===== update distortion =====<br>
     uint32_t dist = primitives.sse_pp[part](fenc, stride, recon, stride);<br>
@@ -702,11 +712,11 @@<br>
     uint32_t singleCbfY  = 0;<br>
     uint32_t singleCbfU  = 0;<br>
     uint32_t singleCbfV  = 0;<br>
-    bool   checkTransformSkip  = cu->getSlice()->getPPS()->getUseTransformSkip();<br>
+    bool     checkTransformSkip  = cu->getSlice()->getPPS()->getUseTransformSkip();<br>
     uint32_t widthTransformSkip  = cu->getWidth(0) >> trDepth;<br>
     uint32_t heightTransformSkip = cu->getHeight(0) >> trDepth;<br>
-    int    bestModeId    = 0;<br>
-    int    bestModeIdUV[2] = { 0, 0 };<br>
+    int      bestModeId          = 0;<br>
+    int      bestModeIdUV[2]     = { 0, 0 };<br>
<br>
     checkTransformSkip &= (widthTransformSkip == 4 && heightTransformSkip == 4);<br>
     checkTransformSkip &= (!cu->getCUTransquantBypass(0));<br>
@@ -729,8 +739,8 @@<br>
             uint32_t singleCbfUTmp      = 0;<br>
             uint32_t singleCbfVTmp      = 0;<br>
             uint64_t singleCostTmp      = 0;<br>
-            int    default0Save1Load2 = 0;<br>
-            int    firstCheckId       = 0;<br>
+            int      default0Save1Load2 = 0;<br>
+            int      firstCheckId       = 0;<br>
<br>
             uint32_t qpdiv = cu->getPic()->getNumPartInCU() >> ((cu->getDepth(0) + (trDepth - 1)) << 1);<br>
             bool   bFirstQ = ((absPartIdx % qpdiv) == 0);<br>
@@ -964,17 +974,17 @@<br>
<br>
         if (!bLumaOnly)<br>
         {<br>
-            width >>= 1;<br>
-            height >>= 1;<br>
+            width  >>= m_hChromaShift;<br>
+            height >>= m_vChromaShift;<br>
             src       = m_qtTempTComYuv[qtLayer].getCbAddr(absPartIdx);<br>
-            assert(m_qtTempTComYuv[qtLayer].m_cwidth == MAX_CU_SIZE / 2);<br>
+            uint32_t srcstride = m_qtTempTComYuv[qtLayer].m_cwidth;<br>
             dst       = cu->getPic()->getPicYuvRec()->getCbAddr(cu->getAddr(), zorder);<br>
             dststride = cu->getPic()->getPicYuvRec()->getCStride();<br>
-            primitives.blockcpy_ps(width, height, dst, dststride, src, MAX_CU_SIZE / 2);<br>
+            primitives.blockcpy_ps(width, height, dst, dststride, src, srcstride);<br>
<br>
             src = m_qtTempTComYuv[qtLayer].getCrAddr(absPartIdx);<br>
             dst = cu->getPic()->getPicYuvRec()->getCrAddr(cu->getAddr(), zorder);<br>
-            primitives.blockcpy_ps(width, height, dst, dststride, src, MAX_CU_SIZE / 2);<br>
+            primitives.blockcpy_ps(width, height, dst, dststride, src, srcstride);<br>
         }<br>
     }<br>
<br>
@@ -1049,7 +1059,7 @@<br>
         int lastPos = -1;<br>
         cu->setTrIdxSubParts(trDepth, absPartIdx, fullDepth);<br>
<br>
-        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0);<br>
+        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());<br>
         m_trQuant->selectLambda(TEXT_LUMA);<br>
         absSum = m_trQuant->transformNxN(cu, residual, stride, coeff, width, height, TEXT_LUMA, absPartIdx, &lastPos, useTransformSkip);<br>
<br>
@@ -1081,7 +1091,6 @@<br>
     if (bCheckSplit && !bCheckFull)<br>
     {<br>
         //----- code splitted block -----<br>
-<br>
         uint32_t qPartsDiv     = cu->getPic()->getNumPartInCU() >> ((fullDepth + 1) << 1);<br>
         uint32_t absPartIdxSub = absPartIdx;<br>
         uint32_t splitCbfY = 0;<br>
@@ -1267,12 +1276,12 @@<br>
         reconIPred = cu->getPic()->getPicYuvRec()->getCbAddr(cu->getAddr(), zOrder);<br>
         reconIPredStride = cu->getPic()->getPicYuvRec()->getCStride();<br>
         reconQt = m_qtTempTComYuv[qtlayer].getCbAddr(absPartIdx);<br>
-        assert(m_qtTempTComYuv[qtlayer].m_cwidth == MAX_CU_SIZE / 2);<br>
-        primitives.blockcpy_ps(width, height, reconIPred, reconIPredStride, reconQt, MAX_CU_SIZE / 2);<br>
+        uint32_t reconQtStride = m_qtTempTComYuv[qtlayer].m_cwidth;<br>
+        primitives.blockcpy_ps(width, height, reconIPred, reconIPredStride, reconQt, reconQtStride);<br>
<br>
         reconIPred = cu->getPic()->getPicYuvRec()->getCrAddr(cu->getAddr(), zOrder);<br>
         reconQt    = m_qtTempTComYuv[qtlayer].getCrAddr(absPartIdx);<br>
-        primitives.blockcpy_ps(width, height, reconIPred, reconIPredStride, reconQt, MAX_CU_SIZE / 2);<br>
+        primitives.blockcpy_ps(width, height, reconIPred, reconIPredStride, reconQt, reconQtStride);<br>
     }<br>
 }<br>
<br>
@@ -1376,20 +1385,20 @@<br>
         uint32_t zorder           = cu->getZorderIdxInCU() + absPartIdx;<br>
         uint32_t width            = cu->getWidth(0) >> (trDepth + 1);<br>
         uint32_t height           = cu->getHeight(0) >> (trDepth + 1);<br>
-        assert(m_qtTempTComYuv[qtlayer].m_cwidth == MAX_CU_SIZE / 2);<br>
+        uint32_t reconQtStride    = m_qtTempTComYuv[qtlayer].m_cwidth;<br>
         uint32_t reconIPredStride = cu->getPic()->getPicYuvRec()->getCStride();<br>
<br>
         if (stateU0V1Both2 == 0 || stateU0V1Both2 == 2)<br>
         {<br>
             Pel* reconIPred = cu->getPic()->getPicYuvRec()->getCbAddr(cu->getAddr(), zorder);<br>
             int16_t* reconQt  = m_qtTempTComYuv[qtlayer].getCbAddr(absPartIdx);<br>
-            primitives.blockcpy_ps(width, height, reconIPred, reconIPredStride, reconQt, MAX_CU_SIZE / 2);<br>
+            primitives.blockcpy_ps(width, height, reconIPred, reconIPredStride, reconQt, reconQtStride);<br>
         }<br>
         if (stateU0V1Both2 == 1 || stateU0V1Both2 == 2)<br>
         {<br>
             Pel* reconIPred = cu->getPic()->getPicYuvRec()->getCrAddr(cu->getAddr(), zorder);<br>
             int16_t* reconQt  = m_qtTempTComYuv[qtlayer].getCrAddr(absPartIdx);<br>
-            primitives.blockcpy_ps(width, height, reconIPred, reconIPredStride, reconQt, MAX_CU_SIZE / 2);<br>
+            primitives.blockcpy_ps(width, height, reconIPred, reconIPredStride, reconQt, reconQtStride);<br>
         }<br>
     }<br>
 }<br>
@@ -1411,7 +1420,7 @@<br>
         uint32_t trSizeLog2 = g_convertToBit[cu->getSlice()->getSPS()->getMaxCUWidth() >> fullDepth] + 2;<br>
<br>
         uint32_t actualTrDepth = trDepth;<br>
-        if (trSizeLog2 == 2)<br>
+        if ((trSizeLog2 == 2) && !(cu->getChromaFormat() == CHROMA_444))<br>
         {<br>
             assert(trDepth > 0);<br>
             actualTrDepth--;<br>
@@ -1557,7 +1566,7 @@<br>
         uint32_t qtlayer    = cu->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - trSizeLog2;<br>
<br>
         bool bChromaSame  = false;<br>
-        if (trSizeLog2 == 2)<br>
+        if ((trSizeLog2 == 2) && !(cu->getChromaFormat() == CHROMA_444))<br>
         {<br>
             assert(trDepth > 0);<br>
             uint32_t qpdiv = cu->getPic()->getNumPartInCU() >> ((cu->getDepth(0) + trDepth - 1) << 1);<br>
@@ -1572,9 +1581,11 @@<br>
         uint32_t numCoeffC = (cu->getSlice()->getSPS()->getMaxCUWidth() * cu->getSlice()->getSPS()->getMaxCUHeight()) >> (fullDepth << 1);<br>
         if (!bChromaSame)<br>
         {<br>
-            numCoeffC >>= 2;<br>
+            numCoeffC = ((cu->getSlice()->getSPS()->getMaxCUWidth() >> m_hChromaShift) * (cu->getSlice()->getSPS()->getMaxCUHeight() >> m_vChromaShift)) >> (fullDepth << 1);<br>

         }<br>
-        uint32_t numCoeffIncC = (cu->getSlice()->getSPS()->getMaxCUWidth() * cu->getSlice()->getSPS()->getMaxCUHeight()) >> ((cu->getSlice()->getSPS()->getMaxCUDepth() << 1) + 2);<br>

+<br>
+        uint32_t numCoeffIncC = ((cu->getSlice()->getSPS()->getMaxCUWidth() >> m_hChromaShift) * (cu->getSlice()->getSPS()->getMaxCUHeight() >> m_vChromaShift)) >> (cu->getSlice()->getSPS()->getMaxCUDepth() << 1);<br>

+<br>
         TCoeff* coeffSrcU = m_qtTempCoeffCb[qtlayer] + (numCoeffIncC * absPartIdx);<br>
         TCoeff* coeffSrcV = m_qtTempCoeffCr[qtlayer] + (numCoeffIncC * absPartIdx);<br>
         TCoeff* coeffDstU = cu->getCoeffCb()         + (numCoeffIncC * absPartIdx);<br>
@@ -1583,7 +1594,7 @@<br>
         ::memcpy(coeffDstV, coeffSrcV, sizeof(TCoeff) * numCoeffC);<br>
<br>
         //===== copy reconstruction =====<br>
-        uint32_t trSizeCLog2 = (bChromaSame ? trSizeLog2 : trSizeLog2 - 1);<br>
+        uint32_t trSizeCLog2 = (bChromaSame || (cu->getChromaFormat() == CHROMA_444))  ? trSizeLog2 : trSizeLog2 - 1;<br>
         m_qtTempTComYuv[qtlayer].copyPartToPartChroma(reconYuv, absPartIdx, 1 << trSizeCLog2, 1 << trSizeCLog2);<br>
     }<br>
     else<br>
@@ -1650,11 +1661,11 @@<br>
             }<br>
             //===== init availability pattern =====<br>
             cu->getPattern()->initPattern(cu, trDepth, absPartIdx);<br>
-            cu->getPattern()->initAdiPatternChroma(cu, absPartIdx, trDepth, m_predBuf, m_predBufStride, m_predBufHeight);<br>
+            cu->getPattern()->initAdiPatternChroma(cu, absPartIdx, trDepth, m_predBuf, m_predBufStride, m_predBufHeight, chromaId);<br>
             Pel* chromaPred = (chromaId > 0 ? cu->getPattern()->getAdiCrBuf(width, height, m_predBuf) : cu->getPattern()->getAdiCbBuf(width, height, m_predBuf));<br>
<br>
             //===== get prediction signal =====<br>
-            predIntraChromaAng(chromaPred, chromaPredMode, pred, stride, width);<br>
+            predIntraChromaAng(chromaPred, chromaPredMode, pred, stride, width, height, cu->getChromaFormat());<br>
<br>
             //===== get residual signal =====<br>
             assert(!((uint32_t)(size_t)fenc & (width - 1)));<br>
@@ -1676,7 +1687,7 @@<br>
             {<br>
                 curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();<br>
             }<br>
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
<br>
             m_trQuant->selectLambda(TEXT_CHROMA);<br>
<br>
@@ -1741,7 +1752,8 @@<br>
     //===== init pattern =====<br>
     assert(width == height);<br>
     cu->getPattern()->initPattern(cu, 0, 0);<br>
-    cu->getPattern()->initAdiPatternChroma(cu, 0, 0, m_predBuf, m_predBufStride, m_predBufHeight);<br>
+    cu->getPattern()->initAdiPatternChroma(cu, 0, 0, m_predBuf, m_predBufStride, m_predBufHeight, 0/*chromaId*/);<br>
+    cu->getPattern()->initAdiPatternChroma(cu, 0, 0, m_predBuf, m_predBufStride, m_predBufHeight, 1/*chromaId*/);<br>
     Pel* patChromaU = cu->getPattern()->getAdiCbBuf(width, height, m_predBuf);<br>
     Pel* patChromaV = cu->getPattern()->getAdiCrBuf(width, height, m_predBuf);<br>
<br>
@@ -1754,8 +1766,8 @@<br>
     for (uint32_t mode = minMode; mode < maxMode; mode++)<br>
     {<br>
         //--- get prediction ---<br>
-        predIntraChromaAng(patChromaU, mode, predU, stride, width);<br>
-        predIntraChromaAng(patChromaV, mode, predV, stride, width);<br>
+        predIntraChromaAng(patChromaU, mode, predU, stride, width, height, cu->getChromaFormat());<br>
+        predIntraChromaAng(patChromaV, mode, predV, stride, width, height, cu->getChromaFormat());<br>
<br>
         //--- get SAD ---<br>
         uint32_t sad = sa8d(fencU, stride, predU, stride) + sa8d(fencV, stride, predV, stride);<br>
@@ -2131,13 +2143,14 @@<br>
<br>
     if (width > 32)<br>
     {<br>
-        scaleWidth = 32;<br>
-        scaleStride = 32;<br>
+        scaleWidth     = 32;<br>
+        scaleStride    = 32;<br>
         costMultiplier = 4;<br>
     }<br>
<br>
     cu->getPattern()->initPattern(cu, trDepth, absPartIdx);<br>
-    cu->getPattern()->initAdiPatternChroma(cu, absPartIdx, trDepth, m_predBuf, m_predBufStride, m_predBufHeight);<br>
+    cu->getPattern()->initAdiPatternChroma(cu, absPartIdx, trDepth, m_predBuf, m_predBufStride, m_predBufHeight, 0);<br>
+    cu->getPattern()->initAdiPatternChroma(cu, absPartIdx, trDepth, m_predBuf, m_predBufStride, m_predBufHeight, 1);<br>
<br>
     cu->getAllowedChromaDir(0, modeList);<br>
     //----- check chroma modes -----<br>
@@ -2156,7 +2169,7 @@<br>
             Pel* chromaPred = (chromaId > 0 ? cu->getPattern()->getAdiCrBuf(width, height, m_predBuf) : cu->getPattern()->getAdiCbBuf(width, height, m_predBuf));<br>
<br>
             //===== get prediction signal =====<br>
-            predIntraChromaAng(chromaPred, chromaPredMode, pred, stride, width);<br>
+            predIntraChromaAng(chromaPred, chromaPredMode, pred, stride, width, height, cu->getChromaFormat());<br>
             int log2SizeMinus2 = g_convertToBit[scaleWidth];<br>
             pixelcmp_t sa8d = primitives.sa8d[log2SizeMinus2];<br>
             sad = costMultiplier * sa8d(fenc, scaleStride, pred, scaleStride);<br>
@@ -2174,6 +2187,27 @@<br>
     cu->setChromIntraDirSubParts(bestMode, 0, depth);<br>
 }<br>
<br></blockquote><div><br></div><div>do these belong here?  perhaps TEncCu?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+bool TEncSearch::isNextSection()<br>
+{<br>
+    if (m_splitMode == DONT_SPLIT)<br>
+    {<br>
+        m_section++;<br>
+        return false;<br>
+    }<br>
+    else<br>
+    {<br>
+        m_absPartIdxTURelCU += m_absPartIdxStep;<br>
+<br>
+        m_section++;<br>
+        return m_section< (1 << m_splitMode);<br>
+    }<br>
+}<br>
+<br>
+bool TEncSearch::isLastSection()<br>
+{<br>
+    return (m_section+1) >= (1<<m_splitMode);<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>
+<br>
 void TEncSearch::estIntraPredChromaQT(TComDataCU* cu,<br>
                                       TComYuv*    fencYuv,<br>
                                       TComYuv*    predYuv,<br>
@@ -2181,60 +2215,109 @@<br>
                                       TComYuv*    reconYuv,<br>
                                       uint32_t    preCalcDistC)<br>
 {<br>
-    uint32_t depth     = cu->getDepth(0);<br>
-    uint32_t bestMode  = 0;<br>
-    uint32_t bestDist  = 0;<br>
-    uint64_t bestCost  = MAX_INT64;<br>
-<br>
-    //----- init mode list -----<br>
-    uint32_t minMode = 0;<br>
-    uint32_t maxMode = NUM_CHROMA_MODE;<br>
-    uint32_t modeList[NUM_CHROMA_MODE];<br>
-<br>
-    cu->getAllowedChromaDir(0, modeList);<br>
-<br>
-    //----- check chroma modes -----<br>
-    for (uint32_t mode = minMode; mode < maxMode; mode++)<br>
+    uint32_t depth              = cu->getDepth(0);<br>
+    uint32_t initTrDepth        = (cu->getPartitionSize(0) != SIZE_2Nx2N) && (cu->getChromaFormat() == CHROMA_444 ? 1 : 0);<br>
+    m_splitMode                 = (initTrDepth == 0) ? DONT_SPLIT : QUAD_SPLIT;<br>
+    m_absPartIdxStep            = (cu->getPic()->getNumPartInCU() >> (depth << 1)) >> partIdxStepShift[m_splitMode];<br>
+    m_partOffset                = 0;<br>
+    m_section                   = 0;<br>
+    m_absPartIdxTURelCU         = 0;<br>
+<br>
+    do<br>
     {<br>
-        //----- restore context models -----<br>
-        m_rdGoOnSbacCoder->load(m_rdSbacCoders[depth][CI_CURR_BEST]);<br>
-<br>
-        //----- chroma coding -----<br>
-        uint32_t dist = 0;<br>
-        cu->setChromIntraDirSubParts(modeList[mode], 0, depth);<br>
-        xRecurIntraChromaCodingQT(cu, 0, 0, fencYuv, predYuv, resiYuv, dist);<br>
-        if (cu->getSlice()->getPPS()->getUseTransformSkip())<br>
+        uint32_t bestMode           = 0;<br>
+        uint32_t bestDist           = 0;<br>
+        uint64_t bestCost           = MAX_INT64;<br>
+<br>
+        //----- init mode list -----<br>
+        uint32_t minMode = 0;<br>
+        uint32_t maxMode = NUM_CHROMA_MODE;<br>
+        uint32_t modeList[NUM_CHROMA_MODE];<br>
+<br>
+        m_partOffset = m_absPartIdxTURelCU;<br>
+<br>
+        cu->getAllowedChromaDir(m_partOffset, modeList);<br>
+<br>
+        //----- check chroma modes -----<br>
+        for (uint32_t mode = minMode; mode < maxMode; mode++)<br>
         {<br>
+            //----- restore context models -----<br>
             m_rdGoOnSbacCoder->load(m_rdSbacCoders[depth][CI_CURR_BEST]);<br>
+<br>
+            //----- chroma coding -----<br>
+            uint32_t dist = 0;<br>
+<br>
+            cu->setChromIntraDirSubParts(modeList[mode], m_partOffset, depth + initTrDepth);<br>
+<br>
+            xRecurIntraChromaCodingQT(cu, initTrDepth, m_absPartIdxTURelCU, fencYuv, predYuv, resiYuv, dist);<br>
+<br>
+            if (cu->getSlice()->getPPS()->getUseTransformSkip())<br>
+            {<br>
+                m_rdGoOnSbacCoder->load(m_rdSbacCoders[depth][CI_CURR_BEST]);<br>
+            }<br>
+<br>
+            uint32_t bits = xGetIntraBitsQT(cu, initTrDepth, m_absPartIdxTURelCU, false, true);<br>
+            uint64_t cost = m_rdCost->calcRdCost(dist, bits);<br>
+<br>
+            //----- compare -----<br>
+            if (cost < bestCost)<br>
+            {<br>
+                bestCost = cost;<br>
+                bestDist = dist;<br>
+                bestMode = modeList[mode];<br>
+                xSetIntraResultChromaQT(cu, initTrDepth, m_absPartIdxTURelCU, reconYuv);<br>
+                ::memcpy(m_qtTempCbf[1], cu->getCbf(TEXT_CHROMA_U) + m_partOffset, m_absPartIdxStep * sizeof(UChar));<br>
+                ::memcpy(m_qtTempCbf[2], cu->getCbf(TEXT_CHROMA_V) + m_partOffset, m_absPartIdxStep * sizeof(UChar));<br>
+                ::memcpy(m_qtTempTransformSkipFlag[1], cu->getTransformSkip(TEXT_CHROMA_U) + m_partOffset, m_absPartIdxStep * sizeof(UChar));<br>
+                ::memcpy(m_qtTempTransformSkipFlag[2], cu->getTransformSkip(TEXT_CHROMA_V) + m_partOffset, m_absPartIdxStep * sizeof(UChar));<br>
+            }<br>
         }<br>
<br>
-        uint32_t bits = xGetIntraBitsQT(cu, 0, 0, false, true);<br>
-        uint64_t cost = m_rdCost->calcRdCost(dist, bits);<br>
-<br>
-        //----- compare -----<br>
-        if (cost < bestCost)<br>
+        if (!isLastSection())<br>
         {<br>
-            bestCost = cost;<br>
-            bestDist = dist;<br>
-            bestMode = modeList[mode];<br>
-            uint32_t qpn = cu->getPic()->getNumPartInCU() >> (depth << 1);<br>
-            xSetIntraResultChromaQT(cu, 0, 0, reconYuv);<br>
-            ::memcpy(m_qtTempCbf[1], cu->getCbf(TEXT_CHROMA_U), qpn * sizeof(UChar));<br>
-            ::memcpy(m_qtTempCbf[2], cu->getCbf(TEXT_CHROMA_V), qpn * sizeof(UChar));<br>
-            ::memcpy(m_qtTempTransformSkipFlag[1], cu->getTransformSkip(TEXT_CHROMA_U), qpn * sizeof(UChar));<br>
-            ::memcpy(m_qtTempTransformSkipFlag[2], cu->getTransformSkip(TEXT_CHROMA_V), qpn * sizeof(UChar));<br>
+            uint32_t compWidth   = (cu->getWidth(0) >> m_hChromaShift)  >> initTrDepth;<br>
+            uint32_t compHeight  = (cu->getHeight(0) >> m_vChromaShift) >> initTrDepth;<br>
+            uint32_t zorder      = cu->getZorderIdxInCU() + m_partOffset;<br>
+            Pel*     dst         = cu->getPic()->getPicYuvRec()->getCbAddr(cu->getAddr(), zorder);<br>
+            uint32_t dststride   = cu->getPic()->getPicYuvRec()->getCStride();<br>
+            Pel*     src         = reconYuv->getCbAddr(m_partOffset);<br>
+            uint32_t srcstride   = reconYuv->getCStride();<br>
+<br>
+            primitives.blockcpy_pp(compWidth, compHeight, dst, dststride, src, srcstride);<br>
+<br>
+            dst                 = cu->getPic()->getPicYuvRec()->getCrAddr(cu->getAddr(), zorder);<br>
+            src                 = reconYuv->getCrAddr(m_partOffset);<br>
+            primitives.blockcpy_pp(compWidth, compHeight, dst, dststride, src, srcstride);<br>
+        }<br>
+<br>
+        //----- set data -----<br>
+        ::memcpy(cu->getCbf(TEXT_CHROMA_U) + m_partOffset, m_qtTempCbf[1], m_absPartIdxStep * sizeof(UChar));<br>
+        ::memcpy(cu->getCbf(TEXT_CHROMA_V) + m_partOffset, m_qtTempCbf[2], m_absPartIdxStep * sizeof(UChar));<br>
+        ::memcpy(cu->getTransformSkip(TEXT_CHROMA_U) + m_partOffset, m_qtTempTransformSkipFlag[1], m_absPartIdxStep * sizeof(UChar));<br>
+        ::memcpy(cu->getTransformSkip(TEXT_CHROMA_V) + m_partOffset, m_qtTempTransformSkipFlag[2], m_absPartIdxStep * sizeof(UChar));<br>
+        cu->setChromIntraDirSubParts(bestMode, m_partOffset, depth + initTrDepth);<br>
+        cu->m_totalDistortion += bestDist - preCalcDistC;<br>
+<br>
+    } while(isNextSection());<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>
+    //----- restore context models -----<br>
+    if (initTrDepth != 0)<br>
+    {   // set Cbf for all blocks<br>
+        uint32_t uiCombCbfU = 0;<br>
+        uint32_t uiCombCbfV = 0;<br>
+        uint32_t uiPartIdx  = 0;<br>
+        for (uint32_t uiPart = 0; uiPart < 4; uiPart++, uiPartIdx += m_absPartIdxStep)<br>
+        {<br>
+            uiCombCbfU |= cu->getCbf(uiPartIdx, TEXT_CHROMA_U, 1);<br>
+            uiCombCbfV |= cu->getCbf(uiPartIdx, TEXT_CHROMA_V, 1);<br>
+        }<br>
+        for (uint32_t uiOffs = 0; uiOffs < 4 * m_absPartIdxStep; uiOffs++)<br>
+        {<br>
+            cu->getCbf( TEXT_CHROMA_U )[ uiOffs ] |= uiCombCbfU;<br>
+            cu->getCbf( TEXT_CHROMA_V )[ uiOffs ] |= uiCombCbfV;<br>
         }<br>
     }<br>
<br>
-    //----- set data -----<br>
-    uint32_t qpn = cu->getPic()->getNumPartInCU() >> (depth << 1);<br>
-    ::memcpy(cu->getCbf(TEXT_CHROMA_U), m_qtTempCbf[1], qpn * sizeof(UChar));<br>
-    ::memcpy(cu->getCbf(TEXT_CHROMA_V), m_qtTempCbf[2], qpn * sizeof(UChar));<br>
-    ::memcpy(cu->getTransformSkip(TEXT_CHROMA_U), m_qtTempTransformSkipFlag[1], qpn * sizeof(UChar));<br>
-    ::memcpy(cu->getTransformSkip(TEXT_CHROMA_V), m_qtTempTransformSkipFlag[2], qpn * sizeof(UChar));<br>
-    cu->setChromIntraDirSubParts(bestMode, 0, depth);<br>
-    cu->m_totalDistortion += bestDist - preCalcDistC;<br>
-<br>
     //----- restore context models -----<br>
     m_rdGoOnSbacCoder->load(m_rdSbacCoders[depth][CI_CURR_BEST]);<br>
 }<br>
@@ -3085,10 +3168,11 @@<br>
         outResiYuv->clear();<br>
<br>
         predYuv->copyToPartYuv(outReconYuv, 0);<br>
-<br>
+        //Luma<br>
         int part = partitionFromSizes(width, height);<br>
         distortion = primitives.sse_pp[part](fencYuv->getLumaAddr(), fencYuv->getStride(), outReconYuv->getLumaAddr(), outReconYuv->getStride());<br>
-        part = partitionFromSizes(width >> 1, height >> 1);<br>
+        //Chroma<br>
+        part = partitionFromSizes(width >> m_hChromaShift, height >> m_vChromaShift);<br>
         distortion += m_rdCost->scaleChromaDistCb(primitives.sse_pp[part](fencYuv->getCbAddr(), fencYuv->getCStride(), outReconYuv->getCbAddr(), outReconYuv->getCStride()));<br>
         distortion += m_rdCost->scaleChromaDistCr(primitives.sse_pp[part](fencYuv->getCrAddr(), fencYuv->getCStride(), outReconYuv->getCrAddr(), outReconYuv->getCStride()));<br>
<br>
@@ -3208,7 +3292,7 @@<br>
     // update with clipped distortion and cost (qp estimation loop uses unclipped values)<br>
     int part = partitionFromSizes(width, height);<br>
     bdist = primitives.sse_pp[part](fencYuv->getLumaAddr(), fencYuv->getStride(), outReconYuv->getLumaAddr(), outReconYuv->getStride());<br>
-    part = partitionFromSizes(width >> 1, height >> 1);<br>
+    part = partitionFromSizes(width >> cu->getHorzChromaShift(), height >> cu->getVertChromaShift());<br>
     bdist += m_rdCost->scaleChromaDistCb(primitives.sse_pp[part](fencYuv->getCbAddr(), fencYuv->getCStride(), outReconYuv->getCbAddr(), outReconYuv->getCStride()));<br>
     bdist += m_rdCost->scaleChromaDistCr(primitives.sse_pp[part](fencYuv->getCrAddr(), fencYuv->getCStride(), outReconYuv->getCrAddr(), outReconYuv->getCStride()));<br>
     bcost = m_rdCost->calcRdCost(bdist, bestBits);<br>
@@ -3311,7 +3395,7 @@<br>
             cu->setTransformSkipSubParts(0, TEXT_CHROMA_V, absPartIdx, cu->getDepth(0) + trModeC);<br>
         }<br>
<br>
-        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0);<br>
+        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());<br>
         m_trQuant->selectLambda(TEXT_LUMA);<br>
<br>
         absSumY = m_trQuant->transformNxN(cu, resiYuv->getLumaAddr(absTUPartIdx), resiYuv->m_width, coeffCurY,<br>
@@ -3322,7 +3406,7 @@<br>
         if (bCodeChroma)<br>
         {<br>
             int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();<br>
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
<br>
             m_trQuant->selectLambda(TEXT_CHROMA);<br>
<br>
@@ -3330,7 +3414,7 @@<br>
                                               trWidthC, trHeightC, TEXT_CHROMA_U, absPartIdx, &lastPosU, false, curuseRDOQ);<br>
<br>
             curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();<br>
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
             absSumV = m_trQuant->transformNxN(cu, resiYuv->getCrAddr(absTUPartIdxC), resiYuv->m_cwidth, coeffCurV,<br>
                                               trWidthC, trHeightC, TEXT_CHROMA_V, absPartIdx, &lastPosV, false, curuseRDOQ);<br>
<br>
@@ -3342,7 +3426,7 @@<br>
         {<br>
             int16_t *curResiY = resiYuv->getLumaAddr(absTUPartIdx);<br>
<br>
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0);<br>
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());<br>
<br>
             int scalingListType = 3 + g_eTTable[(int)TEXT_LUMA];<br>
             assert(scalingListType < 6);<br>
@@ -3362,7 +3446,7 @@<br>
                 int16_t *pcResiCurrU = resiYuv->getCbAddr(absTUPartIdxC);<br>
<br>
                 int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();<br>
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
<br>
                 int scalingListType = 3 + g_eTTable[(int)TEXT_CHROMA_U];<br>
                 assert(scalingListType < 6);<br>
@@ -3378,7 +3462,7 @@<br>
             {<br>
                 int16_t *curResiV = resiYuv->getCrAddr(absTUPartIdxC);<br>
                 int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();<br>
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
<br>
                 int scalingListType = 3 + g_eTTable[(int)TEXT_CHROMA_V];<br>
                 assert(scalingListType < 6);<br>
@@ -3453,6 +3537,7 @@<br>
     assert(cu->getDepth(0) == cu->getDepth(absPartIdx));<br>
     const uint32_t trMode = depth - cu->getDepth(0);<br>
     const uint32_t trSizeLog2 = g_convertToBit[cu->getSlice()->getSPS()->getMaxCUWidth() >> depth] + 2;<br>
+    uint32_t  trSizeCLog2 = g_convertToBit[(cu->getSlice()->getSPS()->getMaxCUWidth() >> m_hChromaShift) >> depth] + 2;;<br>
<br>
     bool bSplitFlag = ((cu->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && cu->getPredictionMode(absPartIdx) == MODE_INTER && (cu->getPartitionSize(absPartIdx) != SIZE_2Nx2N));<br>

     bool bCheckFull;<br>
@@ -3465,12 +3550,11 @@<br>
<br>
     bool  bCodeChroma = true;<br>
     uint32_t  trModeC     = trMode;<br>
-    uint32_t  trSizeCLog2 = trSizeLog2 - 1;<br>
-    if (trSizeLog2 == 2)<br>
+    if ((trSizeLog2 == 2) && !(cu->getChromaFormat() == CHROMA_444))<br>
     {<br>
         trSizeCLog2++;<br>
         trModeC--;<br>
-        uint32_t qpdiv = cu->getPic()->getNumPartInCU() >> ((cu->getDepth(0) + trModeC) << 1);<br>
+        uint32_t qpdiv = cu->getPic()->getNumPartInCU() >> ((depth - 1) << 1);<br>
         bCodeChroma = ((absPartIdx % qpdiv) == 0);<br>
     }<br>
<br>
@@ -3490,8 +3574,8 @@<br>
         const uint32_t numCoeffPerAbsPartIdxIncrement = cu->getSlice()->getSPS()->getMaxCUWidth() * cu->getSlice()->getSPS()->getMaxCUHeight() >> (cu->getSlice()->getSPS()->getMaxCUDepth() << 1);<br>

         const uint32_t qtlayer = cu->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - trSizeLog2;<br>
         TCoeff *coeffCurY = m_qtTempCoeffY[qtlayer] + (numCoeffPerAbsPartIdxIncrement * absPartIdx);<br>
-        TCoeff *coeffCurU = m_qtTempCoeffCb[qtlayer] + (numCoeffPerAbsPartIdxIncrement * absPartIdx >> 2);<br>
-        TCoeff *coeffCurV = m_qtTempCoeffCr[qtlayer] + (numCoeffPerAbsPartIdxIncrement * absPartIdx >> 2);<br>
+        TCoeff *coeffCurU = m_qtTempCoeffCb[qtlayer] + (numCoeffPerAbsPartIdxIncrement * absPartIdx >> (m_hChromaShift + m_vChromaShift));<br>
+        TCoeff *coeffCurV = m_qtTempCoeffCr[qtlayer] + (numCoeffPerAbsPartIdxIncrement * absPartIdx >> (m_hChromaShift + m_vChromaShift));<br>
<br>
         int trWidth = 0, trHeight = 0, trWidthC = 0, trHeightC = 0;<br>
         uint32_t absTUPartIdxC = absPartIdx;<br>
@@ -3520,7 +3604,7 @@<br>
             m_entropyCoder->estimateBit(m_trQuant->m_estBitsSbac, trWidth, trHeight, TEXT_LUMA);<br>
         }<br>
<br>
-        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0);<br>
+        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());<br>
         m_trQuant->selectLambda(TEXT_LUMA);<br>
<br>
         absSumY = m_trQuant->transformNxN(cu, resiYuv->getLumaAddr(absTUPartIdx), resiYuv->m_width, coeffCurY,<br>
@@ -3534,17 +3618,17 @@<br>
             {<br>
                 m_entropyCoder->estimateBit(m_trQuant->m_estBitsSbac, trWidthC, trHeightC, TEXT_CHROMA);<br>
             }<br>
-<br>
+            //Cb transform<br>
             int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();<br>
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
<br>
             m_trQuant->selectLambda(TEXT_CHROMA);<br>
<br>
             absSumU = m_trQuant->transformNxN(cu, resiYuv->getCbAddr(absTUPartIdxC), resiYuv->m_cwidth, coeffCurU,<br>
                                               trWidthC, trHeightC, TEXT_CHROMA_U, absPartIdx, &lastPosU, false, curuseRDOQ);<br>
-<br>
+            //Cr transform<br>
             curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();<br>
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
             absSumV = m_trQuant->transformNxN(cu, resiYuv->getCrAddr(absTUPartIdxC), resiYuv->m_cwidth, coeffCurV,<br>
                                               trWidthC, trHeightC, TEXT_CHROMA_V, absPartIdx, &lastPosV, false, curuseRDOQ);<br>
<br>
@@ -3586,7 +3670,7 @@<br>
         {<br>
             int16_t *curResiY = m_qtTempTComYuv[qtlayer].getLumaAddr(absTUPartIdx);<br>
<br>
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0);<br>
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());<br>
<br>
             int scalingListType = 3 + g_eTTable[(int)TEXT_LUMA];<br>
             assert(scalingListType < 6);<br>
@@ -3658,16 +3742,15 @@<br>
                 int16_t *pcResiCurrU = m_qtTempTComYuv[qtlayer].getCbAddr(absTUPartIdxC);<br>
<br>
                 int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();<br>
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
<br>
                 int scalingListType = 3 + g_eTTable[(int)TEXT_CHROMA_U];<br>
                 assert(scalingListType < 6);<br>
-                assert(m_qtTempTComYuv[qtlayer].m_cwidth == MAX_CU_SIZE / 2);<br>
-                m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, pcResiCurrU, MAX_CU_SIZE / 2, coeffCurU, trWidthC, trHeightC, scalingListType, false, lastPosU);<br>
+                m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, pcResiCurrU, m_qtTempTComYuv[qtlayer].m_cwidth, coeffCurU, trWidthC, trHeightC, scalingListType, false, lastPosU);<br>
<br>
                 uint32_t dist = primitives.sse_ss[partSizeC](resiYuv->getCbAddr(absTUPartIdxC), resiYuv->m_cwidth,<br>
                                                              m_qtTempTComYuv[qtlayer].getCbAddr(absTUPartIdxC),<br>
-                                                             MAX_CU_SIZE / 2);<br>
+                                                             m_qtTempTComYuv[qtlayer].m_cwidth);<br>
                 const uint32_t nonZeroDistU = m_rdCost->scaleChromaDistCb(dist);<br>
<br>
                 if (cu->isLosslessCoded(0))<br>
@@ -3710,10 +3793,10 @@<br>
             if (!absSumU)<br>
             {<br>
                 int16_t *ptr = m_qtTempTComYuv[qtlayer].getCbAddr(absTUPartIdxC);<br>
-                assert(m_qtTempTComYuv[qtlayer].m_cwidth == MAX_CU_SIZE / 2);<br>
+                const uint32_t stride = m_qtTempTComYuv[qtlayer].m_cwidth;<br>
<br>
                 assert(trWidthC == trHeightC);<br>
-                primitives.blockfill_s[(int)g_convertToBit[trWidthC]](ptr, MAX_CU_SIZE / 2, 0);<br>
+                primitives.blockfill_s[(int)g_convertToBit[trWidthC]](ptr, stride, 0);<br>
             }<br>
<br>
             distV = m_rdCost->scaleChromaDistCr(primitives.sse_sp[partSizeC](resiYuv->getCrAddr(absTUPartIdxC), resiYuv->m_cwidth, m_tempPel, trWidthC));<br>
@@ -3725,16 +3808,15 @@<br>
             {<br>
                 int16_t *curResiV = m_qtTempTComYuv[qtlayer].getCrAddr(absTUPartIdxC);<br>
                 int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();<br>
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
<br>
                 int scalingListType = 3 + g_eTTable[(int)TEXT_CHROMA_V];<br>
                 assert(scalingListType < 6);<br>
-                assert(m_qtTempTComYuv[qtlayer].m_cwidth == MAX_CU_SIZE / 2);<br>
-                m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, curResiV, MAX_CU_SIZE / 2, coeffCurV, trWidthC, trHeightC, scalingListType, false, lastPosV);<br>
+                m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, curResiV, m_qtTempTComYuv[qtlayer].m_cwidth, coeffCurV, trWidthC, trHeightC, scalingListType, false, lastPosV);<br>
<br>
                 uint32_t dist = primitives.sse_ss[partSizeC](resiYuv->getCrAddr(absTUPartIdxC), resiYuv->m_cwidth,<br>
                                                              m_qtTempTComYuv[qtlayer].getCrAddr(absTUPartIdxC),<br>
-                                                             MAX_CU_SIZE / 2);<br>
+                                                             m_qtTempTComYuv[qtlayer].m_cwidth);<br>
                 const uint32_t nonZeroDistV = m_rdCost->scaleChromaDistCr(dist);<br>
<br>
                 if (cu->isLosslessCoded(0))<br>
@@ -3777,10 +3859,10 @@<br>
             if (!absSumV)<br>
             {<br>
                 int16_t *ptr =  m_qtTempTComYuv[qtlayer].getCrAddr(absTUPartIdxC);<br>
-                assert(m_qtTempTComYuv[qtlayer].m_cwidth == MAX_CU_SIZE / 2);<br>
+                const uint32_t stride = m_qtTempTComYuv[qtlayer].m_cwidth;<br>
<br>
                 assert(trWidthC == trHeightC);<br>
-                primitives.blockfill_s[(int)g_convertToBit[trWidthC]](ptr, MAX_CU_SIZE / 2, 0);<br>
+                primitives.blockfill_s[(int)g_convertToBit[trWidthC]](ptr, stride, 0);<br>
             }<br>
         }<br>
         cu->setCbfSubParts(absSumY ? setCbf : 0, TEXT_LUMA, absPartIdx, depth);<br>
@@ -3817,7 +3899,7 @@<br>
                 m_entropyCoder->estimateBit(m_trQuant->m_estBitsSbac, trWidth, trHeight, TEXT_LUMA);<br>
             }<br>
<br>
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0);<br>
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());<br>
<br>
             m_trQuant->selectLambda(TEXT_LUMA);<br>
             absSumTransformSkipY = m_trQuant->transformNxN(cu, resiYuv->getLumaAddr(absTUPartIdx), resiYuv->m_width, coeffCurY,<br>
@@ -3831,7 +3913,7 @@<br>
                 m_entropyCoder->encodeCoeffNxN(cu, coeffCurY, absPartIdx, trWidth, trHeight, depth, TEXT_LUMA);<br>
                 const uint32_t skipSingleBitsY = m_entropyCoder->getNumberOfWrittenBits();<br>
<br>
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0);<br>
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());<br>
<br>
                 int scalingListType = 3 + g_eTTable[(int)TEXT_LUMA];<br>
                 assert(scalingListType < 6);<br>
@@ -3874,7 +3956,7 @@<br>
<br>
             int16_t *curResiU = m_qtTempTComYuv[qtlayer].getCbAddr(absTUPartIdxC);<br>
             int16_t *curResiV = m_qtTempTComYuv[qtlayer].getCrAddr(absTUPartIdxC);<br>
-            assert(m_qtTempTComYuv[qtlayer].m_cwidth == MAX_CU_SIZE / 2);<br>
+            uint32_t stride = m_qtTempTComYuv[qtlayer].m_cwidth;<br>
<br>
             TCoeff bestCoeffU[32 * 32], bestCoeffV[32 * 32];<br>
             memcpy(bestCoeffU, coeffCurU, sizeof(TCoeff) * numSamplesChroma);<br>
@@ -3883,8 +3965,8 @@<br>
             int16_t bestResiU[32 * 32], bestResiV[32 * 32];<br>
             for (int i = 0; i < trHeightC; ++i)<br>
             {<br>
-                memcpy(&bestResiU[i * trWidthC], curResiU + i * (MAX_CU_SIZE / 2), sizeof(int16_t) * trWidthC);<br>
-                memcpy(&bestResiV[i * trWidthC], curResiV + i * (MAX_CU_SIZE / 2), sizeof(int16_t) * trWidthC);<br>
+                memcpy(&bestResiU[i * trWidthC], curResiU + i * stride, sizeof(int16_t) * trWidthC);<br>
+                memcpy(&bestResiV[i * trWidthC], curResiV + i * stride, sizeof(int16_t) * trWidthC);<br>
             }<br>
<br>
             m_rdGoOnSbacCoder->load(m_rdSbacCoders[depth][CI_QT_TRAFO_ROOT]);<br>
@@ -3898,13 +3980,13 @@<br>
             }<br>
<br>
             int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();<br>
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
             m_trQuant->selectLambda(TEXT_CHROMA);<br>
<br>
             absSumTransformSkipU = m_trQuant->transformNxN(cu, resiYuv->getCbAddr(absTUPartIdxC), resiYuv->m_cwidth, coeffCurU,<br>
                                                            trWidthC, trHeightC, TEXT_CHROMA_U, absPartIdx, &lastPosTransformSkipU, true, curuseRDOQ);<br>
             curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();<br>
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
             absSumTransformSkipV = m_trQuant->transformNxN(cu, resiYuv->getCrAddr(absTUPartIdxC), resiYuv->m_cwidth, coeffCurV,<br>
                                                            trWidthC, trHeightC, TEXT_CHROMA_V, absPartIdx, &lastPosTransformSkipV, true, curuseRDOQ);<br>
<br>
@@ -3922,17 +4004,15 @@<br>
                 singleBitsU = m_entropyCoder->getNumberOfWrittenBits();<br>
<br>
                 curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();<br>
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
<br>
                 int scalingListType = 3 + g_eTTable[(int)TEXT_CHROMA_U];<br>
                 assert(scalingListType < 6);<br>
-                assert(m_qtTempTComYuv[qtlayer].m_cwidth == MAX_CU_SIZE / 2);<br>
-<br>
-                m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, curResiU, MAX_CU_SIZE / 2, coeffCurU, trWidthC, trHeightC, scalingListType, true, lastPosTransformSkipU);<br>
+                m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, curResiU, m_qtTempTComYuv[qtlayer].m_cwidth, coeffCurU, trWidthC, trHeightC, scalingListType, true, lastPosTransformSkipU);<br>

<br>
                 uint32_t dist = primitives.sse_ss[partSizeC](resiYuv->getCbAddr(absTUPartIdxC), resiYuv->m_cwidth,<br>
                                                              m_qtTempTComYuv[qtlayer].getCbAddr(absTUPartIdxC),<br>
-                                                             MAX_CU_SIZE / 2);<br>
+                                                             m_qtTempTComYuv[qtlayer].m_cwidth);<br>
                 nonZeroDistU = m_rdCost->scaleChromaDistCb(dist);<br>
                 singleCostU = m_rdCost->calcRdCost(nonZeroDistU, singleBitsU);<br>
             }<br>
@@ -3944,7 +4024,7 @@<br>
                 memcpy(coeffCurU, bestCoeffU, sizeof(TCoeff) * numSamplesChroma);<br>
                 for (int i = 0; i < trHeightC; ++i)<br>
                 {<br>
-                    memcpy(curResiU + i * (MAX_CU_SIZE / 2), &bestResiU[i * trWidthC], sizeof(int16_t) * trWidthC);<br>
+                    memcpy(curResiU + i * stride, &bestResiU[i * trWidthC], sizeof(int16_t) * trWidthC);<br>
                 }<br>
             }<br>
             else<br>
@@ -3961,17 +4041,15 @@<br>
                 singleBitsV = m_entropyCoder->getNumberOfWrittenBits() - singleBitsU;<br>
<br>
                 curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();<br>
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset);<br>
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());<br>
<br>
                 int scalingListType = 3 + g_eTTable[(int)TEXT_CHROMA_V];<br>
                 assert(scalingListType < 6);<br>
-                assert(m_qtTempTComYuv[qtlayer].m_cwidth == MAX_CU_SIZE / 2);<br>
-<br>
-                m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, curResiV, MAX_CU_SIZE / 2, coeffCurV, trWidthC, trHeightC, scalingListType, true, lastPosTransformSkipV);<br>
+                m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, curResiV, m_qtTempTComYuv[qtlayer].m_cwidth, coeffCurV, trWidthC, trHeightC, scalingListType, true, lastPosTransformSkipV);<br>

<br>
                 uint32_t dist = primitives.sse_ss[partSizeC](resiYuv->getCrAddr(absTUPartIdxC), resiYuv->m_cwidth,<br>
                                                              m_qtTempTComYuv[qtlayer].getCrAddr(absTUPartIdxC),<br>
-                                                             MAX_CU_SIZE / 2);<br>
+                                                             m_qtTempTComYuv[qtlayer].m_cwidth);<br>
                 nonZeroDistV = m_rdCost->scaleChromaDistCr(dist);<br>
                 singleCostV = m_rdCost->calcRdCost(nonZeroDistV, singleBitsV);<br>
             }<br>
@@ -3983,7 +4061,7 @@<br>
                 memcpy(coeffCurV, bestCoeffV, sizeof(TCoeff) * numSamplesChroma);<br>
                 for (int i = 0; i < trHeightC; ++i)<br>
                 {<br>
-                    memcpy(curResiV + i * (MAX_CU_SIZE / 2), &bestResiV[i * trWidthC], sizeof(int16_t) * trWidthC);<br>
+                    memcpy(curResiV + i * stride, &bestResiV[i * trWidthC], sizeof(int16_t) * trWidthC);<br>
                 }<br>
             }<br>
             else<br>
@@ -4115,6 +4193,7 @@<br>
     const uint32_t trMode = cu->getTransformIdx(absPartIdx);<br>
     const bool bSubdiv = curTrMode != trMode;<br>
     const uint32_t trSizeLog2 = g_convertToBit[cu->getSlice()->getSPS()->getMaxCUWidth() >> depth] + 2;<br>
+    uint32_t  trSizeCLog2 = g_convertToBit[(cu->getSlice()->getSPS()->getMaxCUWidth() >> m_hChromaShift) >> depth] + 2;<br>
<br>
     if (bSubdivAndCbf && trSizeLog2 <= cu->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() && trSizeLog2 > cu->getQuadtreeTULog2MinSizeInCU(absPartIdx))<br>
     {<br>
@@ -4122,10 +4201,23 @@<br>
     }<br>
<br>
     assert(cu->getPredictionMode(absPartIdx) != MODE_INTRA);<br>
+<br>
+    bool mCodeAll = true;<br>
+    if ((ttype == TEXT_CHROMA_U) || (ttype == TEXT_CHROMA_V))<br>
+    {<br>
+        int width  = 1 << trSizeLog2;<br>
+        int height = 1 << trSizeLog2;<br>
+        const uint32_t numPels = (width >> cu->getHorzChromaShift()) * (height >> cu->getHorzChromaShift());<br>
+        if(numPels < (MIN_TU_SIZE * MIN_TU_SIZE))<br>
+        {<br>
+            mCodeAll = false;<br>
+        }<br>
+    }<br>
+<br>
     if (bSubdivAndCbf)<br>
     {<br>
         const bool bFirstCbfOfCU = curTrMode == 0;<br>
-        if (bFirstCbfOfCU || trSizeLog2 > 2)<br>
+        if (bFirstCbfOfCU || mCodeAll)<br>
         {<br>
             if (bFirstCbfOfCU || cu->getCbf(absPartIdx, TEXT_CHROMA_U, curTrMode - 1))<br>
             {<br>
@@ -4136,7 +4228,7 @@<br>
                 m_entropyCoder->encodeQtCbf(cu, absPartIdx, TEXT_CHROMA_V, curTrMode);<br>
             }<br>
         }<br>
-        else if (trSizeLog2 == 2)<br>
+        else<br>
         {<br>
             assert(cu->getCbf(absPartIdx, TEXT_CHROMA_U, curTrMode) == cu->getCbf(absPartIdx, TEXT_CHROMA_U, curTrMode - 1));<br>
             assert(cu->getCbf(absPartIdx, TEXT_CHROMA_V, curTrMode) == cu->getCbf(absPartIdx, TEXT_CHROMA_V, curTrMode - 1));<br>
@@ -4145,21 +4237,20 @@<br>
<br>
     if (!bSubdiv)<br>
     {<br>
+        //Luma<br>
         const uint32_t numCoeffPerAbsPartIdxIncrement = cu->getSlice()->getSPS()->getMaxCUWidth() * cu->getSlice()->getSPS()->getMaxCUHeight() >> (cu->getSlice()->getSPS()->getMaxCUDepth() << 1);<br>

-        //assert( 16 == uiNumCoeffPerAbsPartIdxIncrement ); // check<br>
         const uint32_t qtlayer = cu->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - trSizeLog2;<br>
         TCoeff *coeffCurY = m_qtTempCoeffY[qtlayer] +  numCoeffPerAbsPartIdxIncrement * absPartIdx;<br>
-        TCoeff *coeffCurU = m_qtTempCoeffCb[qtlayer] + (numCoeffPerAbsPartIdxIncrement * absPartIdx >> 2);<br>
-        TCoeff *coeffCurV = m_qtTempCoeffCr[qtlayer] + (numCoeffPerAbsPartIdxIncrement * absPartIdx >> 2);<br>
+<br>
+        //Chroma<br>
+        TCoeff *coeffCurU = m_qtTempCoeffCb[qtlayer] + (numCoeffPerAbsPartIdxIncrement * absPartIdx >> (m_hChromaShift + m_vChromaShift));<br>
+        TCoeff *coeffCurV = m_qtTempCoeffCr[qtlayer] + (numCoeffPerAbsPartIdxIncrement * absPartIdx >> (m_hChromaShift + m_vChromaShift));<br>
<br>
         bool  bCodeChroma = true;<br>
-        uint32_t  trModeC     = trMode;<br>
-        uint32_t  trSizeCLog2 = trSizeLog2 - 1;<br>
-        if (trSizeLog2 == 2)<br>
+        if ((trSizeLog2 == 2) && !(cu->getChromaFormat() == CHROMA_444))<br>
         {<br>
             trSizeCLog2++;<br>
-            trModeC--;<br>
-            uint32_t qpdiv = cu->getPic()->getNumPartInCU() >> ((cu->getDepth(0) + trModeC) << 1);<br>
+            uint32_t qpdiv = cu->getPic()->getNumPartInCU() >> ((depth - 1) << 1);<br>
             bCodeChroma = ((absPartIdx % qpdiv) == 0);<br>
         }<br>
<br>
@@ -4171,21 +4262,18 @@<br>
         {<br>
             if (ttype == TEXT_LUMA && cu->getCbf(absPartIdx, TEXT_LUMA, trMode))<br>
             {<br>
-                int trWidth  = 1 << trSizeLog2;<br>
-                int trHeight = 1 << trSizeLog2;<br>
-                m_entropyCoder->encodeCoeffNxN(cu, coeffCurY, absPartIdx, trWidth, trHeight, depth, TEXT_LUMA);<br>
+                m_entropyCoder->encodeCoeffNxN(cu, coeffCurY, absPartIdx, 1 << trSizeLog2, 1 << trSizeLog2, depth, TEXT_LUMA);<br>
             }<br>
+<br>
             if (bCodeChroma)<br>
             {<br>
-                int trWidth  = 1 << trSizeCLog2;<br>
-                int trHeight = 1 << trSizeCLog2;<br>
                 if (ttype == TEXT_CHROMA_U && cu->getCbf(absPartIdx, TEXT_CHROMA_U, trMode))<br>
                 {<br>
-                    m_entropyCoder->encodeCoeffNxN(cu, coeffCurU, absPartIdx, trWidth, trHeight, depth, TEXT_CHROMA_U);<br>
+                    m_entropyCoder->encodeCoeffNxN(cu, coeffCurU, absPartIdx, 1 << trSizeCLog2, 1 << trSizeCLog2, depth, TEXT_CHROMA_U);<br>
                 }<br>
                 if (ttype == TEXT_CHROMA_V && cu->getCbf(absPartIdx, TEXT_CHROMA_V, trMode))<br>
                 {<br>
-                    m_entropyCoder->encodeCoeffNxN(cu, coeffCurV, absPartIdx, trWidth, trHeight, depth, TEXT_CHROMA_V);<br>
+                    m_entropyCoder->encodeCoeffNxN(cu, coeffCurV, absPartIdx, 1 << trSizeCLog2, 1 << trSizeCLog2, depth, TEXT_CHROMA_V);<br>
                 }<br>
             }<br>
         }<br>
@@ -4211,13 +4299,13 @@<br>
<br>
     if (curTrMode == trMode)<br>
     {<br>
-        const uint32_t trSizeLog2 = g_convertToBit[cu->getSlice()->getSPS()->getMaxCUWidth() >> depth] + 2;<br>
+        const uint32_t trSizeLog2   = g_convertToBit[cu->getSlice()->getSPS()->getMaxCUWidth() >> depth] + 2;<br>
+        uint32_t  trSizeCLog2 = g_convertToBit[(cu->getSlice()->getSPS()->getMaxCUWidth() >> cu->getHorzChromaShift()) >> depth] + 2;;<br>
         const uint32_t qtlayer = cu->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - trSizeLog2;<br>
<br>
         bool  bCodeChroma   = true;<br>
         uint32_t  trModeC     = trMode;<br>
-        uint32_t  trSizeCLog2 = trSizeLog2 - 1;<br>
-        if (trSizeLog2 == 2)<br>
+        if((trSizeLog2 == 2) && !(cu->getChromaFormat() == CHROMA_444))<br>
         {<br>
             trSizeCLog2++;<br>
             trModeC--;<br>
@@ -4246,10 +4334,10 @@<br>
             if (bCodeChroma)<br>
             {<br>
                 uint32_t    uiNumCoeffC = (1 << (trSizeCLog2 << 1));<br>
-                TCoeff* pcCoeffSrcU = m_qtTempCoeffCb[qtlayer] + (uiNumCoeffPerAbsPartIdxIncrement * absPartIdx >> 2);<br>
-                TCoeff* pcCoeffSrcV = m_qtTempCoeffCr[qtlayer] + (uiNumCoeffPerAbsPartIdxIncrement * absPartIdx >> 2);<br>
-                TCoeff* pcCoeffDstU = cu->getCoeffCb() + (uiNumCoeffPerAbsPartIdxIncrement * absPartIdx >> 2);<br>
-                TCoeff* pcCoeffDstV = cu->getCoeffCr() + (uiNumCoeffPerAbsPartIdxIncrement * absPartIdx >> 2);<br>
+                TCoeff* pcCoeffSrcU = m_qtTempCoeffCb[qtlayer] + (uiNumCoeffPerAbsPartIdxIncrement * absPartIdx >> (m_hChromaShift + m_vChromaShift));<br>
+                TCoeff* pcCoeffSrcV = m_qtTempCoeffCr[qtlayer] + (uiNumCoeffPerAbsPartIdxIncrement * absPartIdx >> (m_hChromaShift + m_vChromaShift));<br>
+                TCoeff* pcCoeffDstU = cu->getCoeffCb() + (uiNumCoeffPerAbsPartIdxIncrement * absPartIdx >> (m_hChromaShift + m_vChromaShift));<br>
+                TCoeff* pcCoeffDstV = cu->getCoeffCr() + (uiNumCoeffPerAbsPartIdxIncrement * absPartIdx >> (m_hChromaShift + m_vChromaShift));<br>
                 ::memcpy(pcCoeffDstU, pcCoeffSrcU, sizeof(TCoeff) * uiNumCoeffC);<br>
                 ::memcpy(pcCoeffDstV, pcCoeffSrcV, sizeof(TCoeff) * uiNumCoeffC);<br>
             }<br>
diff -r 98e238489f84 -r 6a602378d31b source/Lib/TLibEncoder/TEncSearch.h<br>
--- a/source/Lib/TLibEncoder/TEncSearch.h       Fri Jan 03 18:21:41 2014 +0530<br>
+++ b/source/Lib/TLibEncoder/TEncSearch.h       Fri Jan 03 18:23:22 2014 +0530<br>
@@ -59,6 +59,13 @@<br>
 namespace x265 {<br>
 // private namespace<br>
<br>
+#define DONT_SPLIT            0<br>
+#define VERTICAL_SPLIT        1<br>
+#define QUAD_SPLIT            2<br>
+#define NUMBER_OF_SPLIT_MODES 3<br>
+<br>
+static const uint32_t partIdxStepShift[NUMBER_OF_SPLIT_MODES] = { 0, 1, 2 };<br>
+<br>
 class TEncCu;<br>
<br>
 // ====================================================================================================================<br>
@@ -113,6 +120,12 @@<br>
     int             m_hChromaShift;<br>
     int             m_vChromaShift;<br>
<br>
+    uint32_t        m_section;<br>
+    uint32_t        m_splitMode;<br>
+    uint32_t        m_absPartIdxTURelCU;<br>
+    uint32_t        m_absPartIdxStep;<br>
+    uint32_t        m_partOffset;<br>
+<br>
 public:<br>
<br>
     TEncSbac***     m_rdSbacCoders;<br>
@@ -184,6 +197,9 @@<br>
<br>
     uint32_t xSymbolBitsInter(TComDataCU* cu);<br>
<br>
+    bool isNextSection();<br>
+    bool isLastSection();<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>