[x265] [PATCH] Modifications to address review comments to support multiple color space format

ashok at multicorewareinc.com ashok at multicorewareinc.com
Fri Jan 10 15:38:05 CET 2014


# HG changeset patch
# User ashok at multicorewareinc.com
# Date 1389364599 -19800
#      Fri Jan 10 20:06:39 2014 +0530
# Node ID fd3dde2aa2960b801c0927301eb836eddc2443cb
# Parent  c95b1f7269df342ea0d8172af0df1d54b981281a
Modifications to address review comments to support multiple color space format

diff -r c95b1f7269df -r fd3dde2aa296 source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp	Fri Jan 10 14:57:18 2014 +0530
+++ b/source/Lib/TLibCommon/TComDataCU.cpp	Fri Jan 10 20:06:39 2014 +0530
@@ -628,6 +628,7 @@
     uint32_t tmp2 = m_absIdxInLCU * m_pic->getMinCUWidth() * m_pic->getMinCUHeight();
     memcpy(rpcCU->getCoeffY()     + tmp2, m_trCoeffY,    sizeof(TCoeff) * tmp);
     memcpy(rpcCU->getPCMSampleY() + tmp2, m_iPCMSampleY, sizeof(Pel) * tmp);
+
     tmp  = ((g_maxCUWidth >> m_hChromaShift) * (g_maxCUHeight >> m_vChromaShift)) >> (uhDepth << 1);
     tmp2 = m_absIdxInLCU * (m_pic->getMinCUWidth() >> m_hChromaShift) * (m_pic->getMinCUHeight() >> m_vChromaShift);
     memcpy(rpcCU->getCoeffCb() + tmp2, m_trCoeffCb, sizeof(TCoeff) * tmp);
@@ -2957,14 +2958,17 @@
                                        + (partHeight / m_pic->getMinCUHeight()) / 2 * m_pic->getNumPartInWidth()
                                        + (partWidth / m_pic->getMinCUWidth()) / 2];
 }
+
 uint32_t TComDataCU::getCoefScanIdx(uint32_t absPartIdx, uint32_t width, bool bIsLuma, bool bIsIntra)
 {
     uint32_t scanIdx;
     uint32_t dirMode;
+
     if (!bIsIntra)
     {
         return SCAN_DIAG;
     }
+
     //check that MDCS can be used for this TU
 
     uint32_t height = width; // For testing Need to change later
@@ -3017,12 +3021,11 @@
         break;
 
     default:
-        //std::cerr << "ERROR: Unrecognised MDCS mode" << std::endl;
-        //assert(false);
-        scanIdx = 0;
-        //exit(1);
+        assert(false);
+        x265_log(NULL, X265_LOG_ERROR, "Unrecognised MDCS mode\n");
         break;
     }
+
     return scanIdx;
 }
 
diff -r c95b1f7269df -r fd3dde2aa296 source/Lib/TLibEncoder/TEncSearch.cpp
--- a/source/Lib/TLibEncoder/TEncSearch.cpp	Fri Jan 10 14:57:18 2014 +0530
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp	Fri Jan 10 20:06:39 2014 +0530
@@ -526,7 +526,9 @@
     uint32_t origTrDepth = trDepth;
     uint32_t fullDepth   = cu->getDepth(0) + trDepth;
     uint32_t trSizeLog2  = g_convertToBit[cu->getSlice()->getSPS()->getMaxCUWidth() >> fullDepth] + 2;
-    if ((trSizeLog2 == 2) && !(cu->getChromaFormat() == CHROMA_444))
+    int      chFmt       = cu->getChromaFormat();
+
+    if ((trSizeLog2 == 2) && !(chFmt == CHROMA_444))
     {
         assert(trDepth > 0);
         trDepth--;
@@ -537,6 +539,7 @@
             return;
         }
     }
+
     TextType ttype          = (chromaId > 0 ? TEXT_CHROMA_V : TEXT_CHROMA_U);
     uint32_t chromaPredMode = cu->getChromaIntraDir(absPartIdx);
     uint32_t width          = cu->getWidth(0)  >> (trDepth + m_hChromaShift);
@@ -546,11 +549,13 @@
     Pel*     pred           = (chromaId > 0 ? predYuv->getCrAddr(absPartIdx) : predYuv->getCbAddr(absPartIdx));
     int16_t* residual       = (chromaId > 0 ? resiYuv->getCrAddr(absPartIdx) : resiYuv->getCbAddr(absPartIdx));
     Pel*     recon          = (chromaId > 0 ? predYuv->getCrAddr(absPartIdx) : predYuv->getCbAddr(absPartIdx));
+
     uint32_t qtlayer        = cu->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - trSizeLog2;
     uint32_t numCoeffPerInc = (cu->getSlice()->getSPS()->getMaxCUWidth() * cu->getSlice()->getSPS()->getMaxCUHeight() >> (cu->getSlice()->getSPS()->getMaxCUDepth() << 1)) >> (m_hChromaShift + m_vChromaShift);
     TCoeff*  coeff          = (chromaId > 0 ? m_qtTempCoeffCr[qtlayer] : m_qtTempCoeffCb[qtlayer]) + numCoeffPerInc * absPartIdx;
     int16_t* reconQt        = (chromaId > 0 ? m_qtTempTComYuv[qtlayer].getCrAddr(absPartIdx) : m_qtTempTComYuv[qtlayer].getCbAddr(absPartIdx));
     uint32_t reconQtStride  = m_qtTempTComYuv[qtlayer].m_cwidth;
+
     uint32_t zorder           = cu->getZorderIdxInCU() + absPartIdx;
     Pel*     reconIPred       = (chromaId > 0 ? cu->getPic()->getPicYuvRec()->getCrAddr(cu->getAddr(), zorder) : cu->getPic()->getPicYuvRec()->getCbAddr(cu->getAddr(), zorder));
     uint32_t reconIPredStride = cu->getPic()->getPicYuvRec()->getCStride();
@@ -562,14 +567,18 @@
     {
         chromaPredMode = cu->getLumaIntraDir(absPartIdx);
     }
+
     //===== init availability pattern =====
     if (default0Save1Load2 != 2)
     {
         cu->getPattern()->initPattern(cu, trDepth, absPartIdx);
+
         cu->getPattern()->initAdiPatternChroma(cu, absPartIdx, trDepth, m_predBuf, m_predBufStride, m_predBufHeight, chromaId);
         Pel* chromaPred = (chromaId > 0 ? cu->getPattern()->getAdiCrBuf(width, height, m_predBuf) : cu->getPattern()->getAdiCbBuf(width, height, m_predBuf));
+
         //===== get prediction signal =====
-        predIntraChromaAng(chromaPred, chromaPredMode, pred, stride, width, height, cu->getChromaFormat());
+        predIntraChromaAng(chromaPred, chromaPredMode, pred, stride, width, height, chFmt);
+
         // save prediction
         if (default0Save1Load2 == 1)
         {
@@ -611,8 +620,10 @@
         {
             curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
         }
-        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+
         m_trQuant->selectLambda(TEXT_CHROMA);
+
         absSum = m_trQuant->transformNxN(cu, residual, stride, coeff, width, height, ttype, absPartIdx, &lastPos, useTransformSkipChroma);
 
         //--- set coded block flag ---
@@ -637,6 +648,7 @@
     assert(((uint32_t)(size_t)residual & (width - 1)) == 0);
     assert(width <= 32);
     primitives.calcrecon[size](pred, residual, recon, reconQt, reconIPred, stride, reconQtStride, reconIPredStride);
+
     //===== update distortion =====
     uint32_t dist = primitives.sse_pp[part](fenc, stride, recon, stride);
     if (ttype == TEXT_CHROMA_U)
@@ -1534,13 +1546,15 @@
 {
     uint32_t fullDepth = cu->getDepth(0) + trDepth;
     uint32_t trMode    = cu->getTransformIdx(absPartIdx);
+    int      chFmt     = cu->getChromaFormat();
 
     if (trMode == trDepth)
     {
         uint32_t trSizeLog2 = g_convertToBit[cu->getSlice()->getSPS()->getMaxCUWidth() >> fullDepth] + 2;
         uint32_t qtlayer    = cu->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() - trSizeLog2;
+
         bool bChromaSame  = false;
-        if ((trSizeLog2 == 2) && !(cu->getChromaFormat() == CHROMA_444))
+        if ((trSizeLog2 == 2) && !(chFmt == CHROMA_444))
         {
             assert(trDepth > 0);
             uint32_t qpdiv = cu->getPic()->getNumPartInCU() >> ((cu->getDepth(0) + trDepth - 1) << 1);
@@ -1566,8 +1580,9 @@
         TCoeff* coeffDstV = cu->getCoeffCr()         + (numCoeffIncC * absPartIdx);
         ::memcpy(coeffDstU, coeffSrcU, sizeof(TCoeff) * numCoeffC);
         ::memcpy(coeffDstV, coeffSrcV, sizeof(TCoeff) * numCoeffC);
+
         //===== copy reconstruction =====
-        uint32_t trSizeCLog2 = (bChromaSame || (cu->getChromaFormat() == CHROMA_444))  ? trSizeLog2 : trSizeLog2 - 1;
+        uint32_t trSizeCLog2 = (bChromaSame || (chFmt == CHROMA_444))  ? trSizeLog2 : trSizeLog2 - 1;
         m_qtTempTComYuv[qtlayer].copyPartToPartChroma(reconYuv, absPartIdx, 1 << trSizeCLog2, 1 << trSizeCLog2);
     }
     else
@@ -1590,6 +1605,8 @@
 {
     uint32_t fullDepth = cu->getDepth(0) + trDepth;
     uint32_t trMode    = cu->getTransformIdx(absPartIdx);
+    int      chFmt     = cu->getChromaFormat();
+
     if (trMode == trDepth)
     {
         uint32_t trSizeLog2 = g_convertToBit[cu->getSlice()->getSPS()->getMaxCUWidth() >> fullDepth] + 2;
@@ -1636,8 +1653,10 @@
             cu->getPattern()->initPattern(cu, trDepth, absPartIdx);
             cu->getPattern()->initAdiPatternChroma(cu, absPartIdx, trDepth, m_predBuf, m_predBufStride, m_predBufHeight, chromaId);
             Pel* chromaPred = (chromaId > 0 ? cu->getPattern()->getAdiCrBuf(width, height, m_predBuf) : cu->getPattern()->getAdiCbBuf(width, height, m_predBuf));
+
             //===== get prediction signal =====
-            predIntraChromaAng(chromaPred, chromaPredMode, pred, stride, width, height, cu->getChromaFormat());
+            predIntraChromaAng(chromaPred, chromaPredMode, pred, stride, width, height, chFmt);
+
             //===== get residual signal =====
             assert(!((uint32_t)(size_t)fenc & (width - 1)));
             assert(!((uint32_t)(size_t)pred & (width - 1)));
@@ -1658,8 +1677,10 @@
             {
                 curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
             }
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+
             m_trQuant->selectLambda(TEXT_CHROMA);
+
             absSum = m_trQuant->transformNxN(cu, residual, stride, coeff, width, height, ttype, absPartIdx, &lastPos, useTransformSkipChroma);
 
             //--- set coded block flag ---
@@ -1713,10 +1734,11 @@
     uint32_t width  = cu->getWidth(0) >> 1;
     uint32_t height = cu->getHeight(0) >> 1;
     uint32_t stride = fencYuv->getCStride();
-    Pel* fencU  = fencYuv->getCbAddr(0);
-    Pel* fencV  = fencYuv->getCrAddr(0);
-    Pel* predU  = predYuv->getCbAddr(0);
-    Pel* predV  = predYuv->getCrAddr(0);
+    int      chFmt  = cu->getChromaFormat();
+    Pel* fencU      = fencYuv->getCbAddr(0);
+    Pel* fencV      = fencYuv->getCrAddr(0);
+    Pel* predU      = predYuv->getCbAddr(0);
+    Pel* predV      = predYuv->getCrAddr(0);
 
     //===== init pattern =====
     assert(width == height);
@@ -1725,6 +1747,7 @@
     cu->getPattern()->initAdiPatternChroma(cu, 0, 0, m_predBuf, m_predBufStride, m_predBufHeight, 1/*chromaId*/);
     Pel* patChromaU = cu->getPattern()->getAdiCbBuf(width, height, m_predBuf);
     Pel* patChromaV = cu->getPattern()->getAdiCrBuf(width, height, m_predBuf);
+
     //===== get best prediction modes (using SAD) =====
     uint32_t minMode  = 0;
     uint32_t maxMode  = 4;
@@ -1734,8 +1757,9 @@
     for (uint32_t mode = minMode; mode < maxMode; mode++)
     {
         //--- get prediction ---
-        predIntraChromaAng(patChromaU, mode, predU, stride, width, height, cu->getChromaFormat());
-        predIntraChromaAng(patChromaV, mode, predV, stride, width, height, cu->getChromaFormat());
+        predIntraChromaAng(patChromaU, mode, predU, stride, width, height, chFmt);
+        predIntraChromaAng(patChromaV, mode, predV, stride, width, height, chFmt);
+
         //--- get SAD ---
         uint32_t sad = sa8d(fencU, stride, predU, stride) + sa8d(fencV, stride, predV, stride);
 
@@ -3304,8 +3328,9 @@
 void TEncSearch::residualTransformQuantInter(TComDataCU* cu, uint32_t absPartIdx, uint32_t absTUPartIdx, TShortYUV* resiYuv, const uint32_t depth, bool curuseRDOQ)
 {
     assert(cu->getDepth(0) == cu->getDepth(absPartIdx));
-    const uint32_t trMode = depth - cu->getDepth(0);
+    const uint32_t trMode     = depth - cu->getDepth(0);
     const uint32_t trSizeLog2 = g_convertToBit[cu->getSlice()->getSPS()->getMaxCUWidth() >> depth] + 2;
+    int chFmt                 = cu->getChromaFormat();
 
     bool bSplitFlag = ((cu->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && cu->getPredictionMode(absPartIdx) == MODE_INTER && (cu->getPartitionSize(absPartIdx) != SIZE_2Nx2N));
     bool bCheckFull;
@@ -3352,8 +3377,10 @@
             cu->setTransformSkipSubParts(0, TEXT_CHROMA_U, absPartIdx, cu->getDepth(0) + trModeC);
             cu->setTransformSkipSubParts(0, TEXT_CHROMA_V, absPartIdx, cu->getDepth(0) + trModeC);
         }
-        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());
+
+        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, chFmt);
         m_trQuant->selectLambda(TEXT_LUMA);
+
         absSumY = m_trQuant->transformNxN(cu, resiYuv->getLumaAddr(absTUPartIdx), resiYuv->m_width, coeffCurY,
                                           trWidth, trHeight, TEXT_LUMA, absPartIdx, &lastPosY, false, curuseRDOQ);
 
@@ -3362,14 +3389,18 @@
         if (bCodeChroma)
         {
             int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+
             m_trQuant->selectLambda(TEXT_CHROMA);
+
             absSumU = m_trQuant->transformNxN(cu, resiYuv->getCbAddr(absTUPartIdxC), resiYuv->m_cwidth, coeffCurU,
                                               trWidthC, trHeightC, TEXT_CHROMA_U, absPartIdx, &lastPosU, false, curuseRDOQ);
+
             curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
             absSumV = m_trQuant->transformNxN(cu, resiYuv->getCrAddr(absTUPartIdxC), resiYuv->m_cwidth, coeffCurV,
                                               trWidthC, trHeightC, TEXT_CHROMA_V, absPartIdx, &lastPosV, false, curuseRDOQ);
+
             cu->setCbfSubParts(absSumU ? setCbf : 0, TEXT_CHROMA_U, absPartIdx, cu->getDepth(0) + trModeC);
             cu->setCbfSubParts(absSumV ? setCbf : 0, TEXT_CHROMA_V, absPartIdx, cu->getDepth(0) + trModeC);
         }
@@ -3377,7 +3408,9 @@
         if (absSumY)
         {
             int16_t *curResiY = resiYuv->getLumaAddr(absTUPartIdx);
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());
+
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, chFmt);
+
             int scalingListType = 3 + g_eTTable[(int)TEXT_LUMA];
             assert(scalingListType < 6);
             m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, curResiY, resiYuv->m_width,  coeffCurY, trWidth, trHeight, scalingListType, false, lastPosY); //this is for inter mode only
@@ -3394,8 +3427,10 @@
             if (absSumU)
             {
                 int16_t *pcResiCurrU = resiYuv->getCbAddr(absTUPartIdxC);
+
                 int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+
                 int scalingListType = 3 + g_eTTable[(int)TEXT_CHROMA_U];
                 assert(scalingListType < 6);
                 m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, pcResiCurrU, resiYuv->m_cwidth, coeffCurU, trWidthC, trHeightC, scalingListType, false, lastPosU);
@@ -3410,7 +3445,8 @@
             {
                 int16_t *curResiV = resiYuv->getCrAddr(absTUPartIdxC);
                 int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+
                 int scalingListType = 3 + g_eTTable[(int)TEXT_CHROMA_V];
                 assert(scalingListType < 6);
                 m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, curResiV, resiYuv->m_cwidth, coeffCurV, trWidthC, trHeightC, scalingListType, false, lastPosV);
@@ -3482,9 +3518,11 @@
                                      bool           curuseRDOQ)
 {
     assert(cu->getDepth(0) == cu->getDepth(absPartIdx));
-    const uint32_t trMode = depth - cu->getDepth(0);
+    const uint32_t trMode     = depth - cu->getDepth(0);
     const uint32_t trSizeLog2 = g_convertToBit[cu->getSlice()->getSPS()->getMaxCUWidth() >> depth] + 2;
-    uint32_t  trSizeCLog2 = g_convertToBit[(cu->getSlice()->getSPS()->getMaxCUWidth() >> m_hChromaShift) >> depth] + 2;;
+    uint32_t  trSizeCLog2     = g_convertToBit[(cu->getSlice()->getSPS()->getMaxCUWidth() >> m_hChromaShift) >> depth] + 2;;
+    int chFmt                 = cu->getChromaFormat();
+
     bool bSplitFlag = ((cu->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && cu->getPredictionMode(absPartIdx) == MODE_INTER && (cu->getPartitionSize(absPartIdx) != SIZE_2Nx2N));
     bool bCheckFull;
     if (bSplitFlag && depth == cu->getDepth(absPartIdx) && (trSizeLog2 > cu->getQuadtreeTULog2MinSizeInCU(absPartIdx)))
@@ -3493,15 +3531,17 @@
         bCheckFull = (trSizeLog2 <= cu->getSlice()->getSPS()->getQuadtreeTULog2MaxSize());
     const bool bCheckSplit = (trSizeLog2 > cu->getQuadtreeTULog2MinSizeInCU(absPartIdx));
     assert(bCheckFull || bCheckSplit);
+
     bool  bCodeChroma = true;
     uint32_t  trModeC     = trMode;
-    if ((trSizeLog2 == 2) && !(cu->getChromaFormat() == CHROMA_444))
+    if ((trSizeLog2 == 2) && !(chFmt == CHROMA_444))
     {
         trSizeCLog2++;
         trModeC--;
         uint32_t qpdiv = cu->getPic()->getNumPartInCU() >> ((depth - 1) << 1);
         bCodeChroma = ((absPartIdx % qpdiv) == 0);
     }
+
     const uint32_t setCbf = 1 << trMode;
     // code full block
     uint64_t singleCost = MAX_INT64;
@@ -3520,6 +3560,7 @@
         TCoeff *coeffCurY = m_qtTempCoeffY[qtlayer] + (numCoeffPerAbsPartIdxIncrement * absPartIdx);
         TCoeff *coeffCurU = m_qtTempCoeffCb[qtlayer] + (numCoeffPerAbsPartIdxIncrement * absPartIdx >> (m_hChromaShift + m_vChromaShift));
         TCoeff *coeffCurV = m_qtTempCoeffCr[qtlayer] + (numCoeffPerAbsPartIdxIncrement * absPartIdx >> (m_hChromaShift + m_vChromaShift));
+
         int trWidth = 0, trHeight = 0, trWidthC = 0, trHeightC = 0;
         uint32_t absTUPartIdxC = absPartIdx;
 
@@ -3546,8 +3587,10 @@
         {
             m_entropyCoder->estimateBit(m_trQuant->m_estBitsSbac, trWidth, trHeight, TEXT_LUMA);
         }
-        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());
+
+        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, chFmt);
         m_trQuant->selectLambda(TEXT_LUMA);
+
         absSumY = m_trQuant->transformNxN(cu, resiYuv->getLumaAddr(absTUPartIdx), resiYuv->m_width, coeffCurY,
                                           trWidth, trHeight, TEXT_LUMA, absPartIdx, &lastPosY, false, curuseRDOQ);
 
@@ -3561,15 +3604,18 @@
             }
             //Cb transform
             int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+
             m_trQuant->selectLambda(TEXT_CHROMA);
+
             absSumU = m_trQuant->transformNxN(cu, resiYuv->getCbAddr(absTUPartIdxC), resiYuv->m_cwidth, coeffCurU,
                                               trWidthC, trHeightC, TEXT_CHROMA_U, absPartIdx, &lastPosU, false, curuseRDOQ);
             //Cr transform
             curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
             absSumV = m_trQuant->transformNxN(cu, resiYuv->getCrAddr(absTUPartIdxC), resiYuv->m_cwidth, coeffCurV,
                                               trWidthC, trHeightC, TEXT_CHROMA_V, absPartIdx, &lastPosV, false, curuseRDOQ);
+
             cu->setCbfSubParts(absSumU ? setCbf : 0, TEXT_CHROMA_U, absPartIdx, cu->getDepth(0) + trModeC);
             cu->setCbfSubParts(absSumV ? setCbf : 0, TEXT_CHROMA_V, absPartIdx, cu->getDepth(0) + trModeC);
         }
@@ -3607,7 +3653,9 @@
         if (absSumY)
         {
             int16_t *curResiY = m_qtTempTComYuv[qtlayer].getLumaAddr(absTUPartIdx);
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());
+
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, chFmt);
+
             int scalingListType = 3 + g_eTTable[(int)TEXT_LUMA];
             assert(scalingListType < 6);
             assert(m_qtTempTComYuv[qtlayer].m_width == MAX_CU_SIZE);
@@ -3676,15 +3724,19 @@
             if (absSumU)
             {
                 int16_t *pcResiCurrU = m_qtTempTComYuv[qtlayer].getCbAddr(absTUPartIdxC);
+
                 int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+
                 int scalingListType = 3 + g_eTTable[(int)TEXT_CHROMA_U];
                 assert(scalingListType < 6);
                 m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, pcResiCurrU, m_qtTempTComYuv[qtlayer].m_cwidth, coeffCurU, trWidthC, trHeightC, scalingListType, false, lastPosU);
+
                 uint32_t dist = primitives.sse_ss[partSizeC](resiYuv->getCbAddr(absTUPartIdxC), resiYuv->m_cwidth,
                                                              m_qtTempTComYuv[qtlayer].getCbAddr(absTUPartIdxC),
                                                              m_qtTempTComYuv[qtlayer].m_cwidth);
                 const uint32_t nonZeroDistU = m_rdCost->scaleChromaDistCb(dist);
+
                 if (cu->isLosslessCoded(0))
                 {
                     distU = nonZeroDistU;
@@ -3726,9 +3778,11 @@
             {
                 int16_t *ptr = m_qtTempTComYuv[qtlayer].getCbAddr(absTUPartIdxC);
                 const uint32_t stride = m_qtTempTComYuv[qtlayer].m_cwidth;
+
                 assert(trWidthC == trHeightC);
                 primitives.blockfill_s[(int)g_convertToBit[trWidthC]](ptr, stride, 0);
             }
+
             distV = m_rdCost->scaleChromaDistCr(primitives.sse_sp[partSizeC](resiYuv->getCrAddr(absTUPartIdxC), resiYuv->m_cwidth, m_tempPel, trWidthC));
             if (outZeroDist)
             {
@@ -3738,14 +3792,17 @@
             {
                 int16_t *curResiV = m_qtTempTComYuv[qtlayer].getCrAddr(absTUPartIdxC);
                 int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+
                 int scalingListType = 3 + g_eTTable[(int)TEXT_CHROMA_V];
                 assert(scalingListType < 6);
                 m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, curResiV, m_qtTempTComYuv[qtlayer].m_cwidth, coeffCurV, trWidthC, trHeightC, scalingListType, false, lastPosV);
+
                 uint32_t dist = primitives.sse_ss[partSizeC](resiYuv->getCrAddr(absTUPartIdxC), resiYuv->m_cwidth,
                                                              m_qtTempTComYuv[qtlayer].getCrAddr(absTUPartIdxC),
                                                              m_qtTempTComYuv[qtlayer].m_cwidth);
                 const uint32_t nonZeroDistV = m_rdCost->scaleChromaDistCr(dist);
+
                 if (cu->isLosslessCoded(0))
                 {
                     distV = nonZeroDistV;
@@ -3787,6 +3844,7 @@
             {
                 int16_t *ptr =  m_qtTempTComYuv[qtlayer].getCrAddr(absTUPartIdxC);
                 const uint32_t stride = m_qtTempTComYuv[qtlayer].m_cwidth;
+
                 assert(trWidthC == trHeightC);
                 primitives.blockfill_s[(int)g_convertToBit[trWidthC]](ptr, stride, 0);
             }
@@ -3824,7 +3882,9 @@
             {
                 m_entropyCoder->estimateBit(m_trQuant->m_estBitsSbac, trWidth, trHeight, TEXT_LUMA);
             }
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());
+
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, chFmt);
+
             m_trQuant->selectLambda(TEXT_LUMA);
             absSumTransformSkipY = m_trQuant->transformNxN(cu, resiYuv->getLumaAddr(absTUPartIdx), resiYuv->m_width, coeffCurY,
                                                            trWidth, trHeight, TEXT_LUMA, absPartIdx, &lastPosTransformSkipY, true, curuseRDOQ);
@@ -3836,7 +3896,9 @@
                 m_entropyCoder->encodeQtCbf(cu, absPartIdx, TEXT_LUMA, trMode);
                 m_entropyCoder->encodeCoeffNxN(cu, coeffCurY, absPartIdx, trWidth, trHeight, depth, TEXT_LUMA);
                 const uint32_t skipSingleBitsY = m_entropyCoder->getNumberOfWrittenBits();
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, cu->getChromaFormat());
+
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, cu->getSlice()->getSPS()->getQpBDOffsetY(), 0, chFmt);
+
                 int scalingListType = 3 + g_eTTable[(int)TEXT_LUMA];
                 assert(scalingListType < 6);
                 assert(m_qtTempTComYuv[qtlayer].m_width == MAX_CU_SIZE);
@@ -3875,9 +3937,11 @@
             int lastPosTransformSkipU = -1, lastPosTransformSkipV = -1;
             uint64_t singleCostU = MAX_INT64;
             uint64_t singleCostV = MAX_INT64;
+
             int16_t *curResiU = m_qtTempTComYuv[qtlayer].getCbAddr(absTUPartIdxC);
             int16_t *curResiV = m_qtTempTComYuv[qtlayer].getCrAddr(absTUPartIdxC);
             uint32_t stride = m_qtTempTComYuv[qtlayer].m_cwidth;
+
             TCoeff bestCoeffU[32 * 32], bestCoeffV[32 * 32];
             memcpy(bestCoeffU, coeffCurU, sizeof(TCoeff) * numSamplesChroma);
             memcpy(bestCoeffV, coeffCurV, sizeof(TCoeff) * numSamplesChroma);
@@ -3888,6 +3952,7 @@
                 memcpy(&bestResiU[i * trWidthC], curResiU + i * stride, sizeof(int16_t) * trWidthC);
                 memcpy(&bestResiV[i * trWidthC], curResiV + i * stride, sizeof(int16_t) * trWidthC);
             }
+
             m_rdGoOnSbacCoder->load(m_rdSbacCoders[depth][CI_QT_TRAFO_ROOT]);
 
             cu->setTransformSkipSubParts(1, TEXT_CHROMA_U, absPartIdx, cu->getDepth(0) + trModeC);
@@ -3897,15 +3962,18 @@
             {
                 m_entropyCoder->estimateBit(m_trQuant->m_estBitsSbac, trWidthC, trHeightC, TEXT_CHROMA);
             }
+
             int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
             m_trQuant->selectLambda(TEXT_CHROMA);
+
             absSumTransformSkipU = m_trQuant->transformNxN(cu, resiYuv->getCbAddr(absTUPartIdxC), resiYuv->m_cwidth, coeffCurU,
                                                            trWidthC, trHeightC, TEXT_CHROMA_U, absPartIdx, &lastPosTransformSkipU, true, curuseRDOQ);
             curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
             absSumTransformSkipV = m_trQuant->transformNxN(cu, resiYuv->getCrAddr(absTUPartIdxC), resiYuv->m_cwidth, coeffCurV,
                                                            trWidthC, trHeightC, TEXT_CHROMA_V, absPartIdx, &lastPosTransformSkipV, true, curuseRDOQ);
+
             cu->setCbfSubParts(absSumTransformSkipU ? setCbf : 0, TEXT_CHROMA_U, absPartIdx, cu->getDepth(0) + trModeC);
             cu->setCbfSubParts(absSumTransformSkipV ? setCbf : 0, TEXT_CHROMA_V, absPartIdx, cu->getDepth(0) + trModeC);
 
@@ -3918,11 +3986,14 @@
                 m_entropyCoder->encodeQtCbf(cu, absPartIdx, TEXT_CHROMA_U, trMode);
                 m_entropyCoder->encodeCoeffNxN(cu, coeffCurU, absPartIdx, trWidthC, trHeightC, depth, TEXT_CHROMA_U);
                 singleBitsU = m_entropyCoder->getNumberOfWrittenBits();
+
                 curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+
                 int scalingListType = 3 + g_eTTable[(int)TEXT_CHROMA_U];
                 assert(scalingListType < 6);
                 m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, curResiU, m_qtTempTComYuv[qtlayer].m_cwidth, coeffCurU, trWidthC, trHeightC, scalingListType, true, lastPosTransformSkipU);
+
                 uint32_t dist = primitives.sse_ss[partSizeC](resiYuv->getCbAddr(absTUPartIdxC), resiYuv->m_cwidth,
                                                              m_qtTempTComYuv[qtlayer].getCbAddr(absTUPartIdxC),
                                                              m_qtTempTComYuv[qtlayer].m_cwidth);
@@ -3952,11 +4023,14 @@
                 m_entropyCoder->encodeQtCbf(cu, absPartIdx, TEXT_CHROMA_V, trMode);
                 m_entropyCoder->encodeCoeffNxN(cu, coeffCurV, absPartIdx, trWidthC, trHeightC, depth, TEXT_CHROMA_V);
                 singleBitsV = m_entropyCoder->getNumberOfWrittenBits() - singleBitsU;
+
                 curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, cu->getChromaFormat());
+                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+
                 int scalingListType = 3 + g_eTTable[(int)TEXT_CHROMA_V];
                 assert(scalingListType < 6);
                 m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), REG_DCT, curResiV, m_qtTempTComYuv[qtlayer].m_cwidth, coeffCurV, trWidthC, trHeightC, scalingListType, true, lastPosTransformSkipV);
+
                 uint32_t dist = primitives.sse_ss[partSizeC](resiYuv->getCrAddr(absTUPartIdxC), resiYuv->m_cwidth,
                                                              m_qtTempTComYuv[qtlayer].getCrAddr(absTUPartIdxC),
                                                              m_qtTempTComYuv[qtlayer].m_cwidth);
diff -r c95b1f7269df -r fd3dde2aa296 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Fri Jan 10 14:57:18 2014 +0530
+++ b/source/encoder/frameencoder.cpp	Fri Jan 10 20:06:39 2014 +0530
@@ -311,8 +311,9 @@
 
 void FrameEncoder::setLambda(int qp, int row)
 {
-    TComSlice* slice = m_pic->getSlice();
-    TComPicYuv *fenc = slice->getPic()->getPicYuvOrg();
+    TComSlice*  slice = m_pic->getSlice();
+    TComPicYuv* fenc  = slice->getPic()->getPicYuvOrg();
+    int         chFmt = slice->getSPS()->getChromaFormatIdc();
 
     double lambda = 0;
 
@@ -330,11 +331,13 @@
     // instead we weight the distortion of chroma.
     int chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb();
     int qpc = Clip3(0, 70, qp + chromaQPOffset);
-    double cbWeight = pow(2.0, (qp - g_chromaScale[slice->getSPS()->getChromaFormatIdc()][qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
+    double cbWeight = pow(2.0, (qp - g_chromaScale[chFmt][qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
+
     chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr();
     qpc = Clip3(0, 70, qp + chromaQPOffset);
-    double crWeight = pow(2.0, (qp - g_chromaScale[slice->getSPS()->getChromaFormatIdc()][qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
+    double crWeight = pow(2.0, (qp - g_chromaScale[chFmt][qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
     double chromaLambda = lambda / crWeight;
+
     m_rows[row].m_search.setQPLambda(qp, lambda, chromaLambda);
     m_rows[row].m_search.m_me.setSourcePlane(fenc->getLumaAddr(), fenc->getStride());
     m_rows[row].m_rdCost.setLambda(lambda);
@@ -345,9 +348,11 @@
 void FrameEncoder::compressFrame()
 {
     PPAScopeEvent(FrameEncoder_compressFrame);
-    int64_t startCompressTime = x265_mdate();
-    TEncEntropy* entropyCoder = getEntropyCoder(0);
-    TComSlice*   slice        = m_pic->getSlice();
+    int64_t      startCompressTime = x265_mdate();
+    TEncEntropy* entropyCoder      = getEntropyCoder(0);
+    TComSlice*   slice             = m_pic->getSlice();
+    int          chFmt             = slice->getSPS()->getChromaFormatIdc();
+
     m_nalCount = 0;
 
     int qp = slice->getSliceQp();
@@ -367,11 +372,12 @@
     int qpc;
     int chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb();
     qpc = Clip3(0, 70, qp + chromaQPOffset);
-    double cbWeight = pow(2.0, (qp - g_chromaScale[slice->getSPS()->getChromaFormatIdc()][qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
-    chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr();
+    double cbWeight = pow(2.0, (qp - g_chromaScale[chFmt][qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
+    chromaQPOffset  = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr();
     qpc = Clip3(0, 70, qp + chromaQPOffset);
-    double crWeight = pow(2.0, (qp - g_chromaScale[slice->getSPS()->getChromaFormatIdc()][qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
+    double crWeight = pow(2.0, (qp - g_chromaScale[chFmt][qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
     double chromaLambda = lambda / crWeight;
+
     // NOTE: set SAO lambda every Frame
     m_frameFilter.m_sao.lumaLambda = lambda;
     m_frameFilter.m_sao.chromaLambda = chromaLambda;


More information about the x265-devel mailing list