[x265] [PATCH 2 of 2] search: make RDCost and TComTrQuant member instances of TEncSearch

Steve Borho steve at borho.org
Fri Jul 11 06:15:40 CEST 2014


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1405052124 18000
#      Thu Jul 10 23:15:24 2014 -0500
# Node ID f5fe4e345362d4eb389a25f8eb3b212408bb0fe4
# Parent  3685d607012f345079e7ae2cf1949338a23683d0
search: make RDCost and TComTrQuant member instances of TEncSearch

Both of these structs are required by TEncSearch, it cannot operate without them
There is always a 1::1 correlation with each. There is no reason at all to
allocated them separately in TLD and then link them all together.  Much simpler
for them to be members of the TEncSearch class.

diff -r 3685d607012f -r f5fe4e345362 source/Lib/TLibEncoder/TEncCu.cpp
--- a/source/Lib/TLibEncoder/TEncCu.cpp	Thu Jul 10 22:32:24 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncCu.cpp	Thu Jul 10 23:15:24 2014 -0500
@@ -72,13 +72,23 @@
     m_rdSbacCoders    = NULL;
 }
 
-bool TEncCu::init(Encoder* top, RDCost* rdCost, TComTrQuant* trQuant)
+bool TEncCu::init(Encoder* top)
 {
-    m_trQuant = trQuant;
-    m_rdCost  = rdCost;
+    m_param = top->m_param;
+    m_trQuant.init(top->m_bEnableRDOQ);
+    if (top->m_useScalingListId == SCALING_LIST_OFF)
+    {
+        m_trQuant.setFlatScalingList();
+        m_trQuant.setUseScalingList(false);
+    }
+    else if (top->m_useScalingListId == SCALING_LIST_DEFAULT)
+    {
+        m_trQuant.setScalingList(top->getScalingList());
+        m_trQuant.setUseScalingList(true);
+    }
 
+    m_rdCost.setPsyRdScale(m_param->psyRd);
     m_CUTransquantBypass = top->m_CUTransquantBypassFlagValue;
-    m_param = top->m_param;
     m_bEnableRDOQ = top->m_bEnableRDOQ;
     m_bFrameParallel = top->m_totalFrameThreads > 1;
     m_numLayers = top->m_quadtreeTULog2MaxSize - top->m_quadtreeTULog2MinSize + 1;
@@ -544,30 +554,21 @@
         if (depth == g_maxCUDepth - g_addCUDepth)
         {
             if (cuSize > (1 << slice->getSPS()->getQuadtreeTULog2MinSize()))
-            {
                 xCheckRDCostIntra(outBestCU, outTempCU, SIZE_NxN);
-            }
         }
 
         m_sbacCoder->resetBits();
         m_sbacCoder->codeSplitFlag(outBestCU, 0, depth);
         outBestCU->m_totalBits += m_sbacCoder->getNumberOfWrittenBits(); // split bits
-        if (m_rdCost->psyRdEnabled())
-        {
-            outBestCU->m_totalPsyCost = m_rdCost->calcPsyRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits, 
-                outBestCU->m_psyEnergy);
-        }
+        if (m_rdCost.psyRdEnabled())
+            outBestCU->m_totalPsyCost = m_rdCost.calcPsyRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits, outBestCU->m_psyEnergy);
         else
-        {
-            outBestCU->m_totalRDCost  = m_rdCost->calcRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits);
-        }
+            outBestCU->m_totalRDCost  = m_rdCost.calcRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits);
     }
 
     // copy original YUV samples in lossless mode
     if (outBestCU->isLosslessCoded(0))
-    {
         xFillOrigYUVBuffer(outBestCU, m_origYuv[depth]);
-    }
 
     // further split
     if (depth < g_maxCUDepth - g_addCUDepth)
@@ -613,15 +614,10 @@
             outTempCU->m_totalBits += m_sbacCoder->getNumberOfWrittenBits(); // split bits
         }
         
-        if (m_rdCost->psyRdEnabled())
-        {
-            outTempCU->m_totalPsyCost = m_rdCost->calcPsyRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits, 
-                outTempCU->m_psyEnergy);
-        }
+        if (m_rdCost.psyRdEnabled())
+            outTempCU->m_totalPsyCost = m_rdCost.calcPsyRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits, outTempCU->m_psyEnergy);
         else
-        {
-            outTempCU->m_totalRDCost = m_rdCost->calcRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
-        }
+            outTempCU->m_totalRDCost = m_rdCost.calcRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
 
         if ((g_maxCUSize >> depth) == slice->getPPS()->getMinCuDQPSize() && slice->getPPS()->getUseDQP())
         {
@@ -644,9 +640,7 @@
                 X265_CHECK(foundNonZeroCbf, "expected to find non-zero CBF\n");
             }
             else
-            {
                 outTempCU->setQPSubParts(outTempCU->getRefQP(targetPartIdx), 0, depth); // set QP to default QP
-            }
         }
 
         m_rdSbacCoders[nextDepth][CI_NEXT_BEST].store(m_rdSbacCoders[depth][CI_TEMP_BEST]);
@@ -661,7 +655,7 @@
 
     X265_CHECK(outBestCU->getPartitionSize(0) != SIZE_NONE, "no best partition size\n");
     X265_CHECK(outBestCU->getPredictionMode(0) != MODE_NONE, "no best partition mode\n");
-    if (m_rdCost->psyRdEnabled())
+    if (m_rdCost.psyRdEnabled())
     {
         X265_CHECK(outBestCU->m_totalPsyCost != MAX_INT64, "no best partition cost\n");
     }
@@ -889,15 +883,10 @@
         m_sbacCoder->resetBits();
         m_sbacCoder->codeSplitFlag(outBestCU, 0, depth);
         outBestCU->m_totalBits += m_sbacCoder->getNumberOfWrittenBits(); // split bits
-        if (m_rdCost->psyRdEnabled())
-        {
-            outBestCU->m_totalPsyCost = m_rdCost->calcPsyRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits,
-                outBestCU->m_psyEnergy);
-        }
+        if (m_rdCost.psyRdEnabled())
+            outBestCU->m_totalPsyCost = m_rdCost.calcPsyRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits, outBestCU->m_psyEnergy);
         else
-        {
-            outBestCU->m_totalRDCost = m_rdCost->calcRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits);
-        }
+            outBestCU->m_totalRDCost = m_rdCost.calcRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits);
 
         // Early CU determination
         if (outBestCU->isSkipped(0))
@@ -956,15 +945,10 @@
             outTempCU->m_totalBits += m_sbacCoder->getNumberOfWrittenBits(); // split bits
         }
 
-        if (m_rdCost->psyRdEnabled())
-        {
-            outTempCU->m_totalPsyCost = m_rdCost->calcPsyRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits, 
-                outTempCU->m_psyEnergy);
-        }
+        if (m_rdCost.psyRdEnabled())
+            outTempCU->m_totalPsyCost = m_rdCost.calcPsyRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits, outTempCU->m_psyEnergy);
         else
-        {
-            outTempCU->m_totalRDCost = m_rdCost->calcRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
-        }
+            outTempCU->m_totalRDCost = m_rdCost.calcRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
 
         if ((g_maxCUSize >> depth) == slice->getPPS()->getMinCuDQPSize() && slice->getPPS()->getUseDQP())
         {
@@ -987,9 +971,7 @@
                 X265_CHECK(foundNonZeroCbf, "expected to find non-zero CBF\n");
             }
             else
-            {
                 outTempCU->setQPSubParts(outTempCU->getRefQP(targetPartIdx), 0, depth); // set QP to default QP
-            }
         }
 
         m_rdSbacCoders[nextDepth][CI_NEXT_BEST].store(m_rdSbacCoders[depth][CI_TEMP_BEST]);
@@ -1004,7 +986,7 @@
 
     X265_CHECK(outBestCU->getPartitionSize(0) != SIZE_NONE, "no best partition size\n");
     X265_CHECK(outBestCU->getPredictionMode(0) != MODE_NONE, "no best partition mode\n");
-    if (m_rdCost->psyRdEnabled())
+    if (m_rdCost.psyRdEnabled())
     {
         X265_CHECK(outBestCU->m_totalPsyCost != MAX_INT64, "no best partition cost\n");
     }
@@ -1242,8 +1224,8 @@
                     outTempCU->setSkipFlagSubParts(!outTempCU->getQtRootCbf(0), 0, depth);
                     int origQP = outTempCU->getQP(0);
                     xCheckDQP(outTempCU);
-                    uint64_t tempCost = m_rdCost->psyRdEnabled() ? outTempCU->m_totalPsyCost : outTempCU->m_totalRDCost;
-                    uint64_t bestCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
+                    uint64_t tempCost = m_rdCost.psyRdEnabled() ? outTempCU->m_totalPsyCost : outTempCU->m_totalRDCost;
+                    uint64_t bestCost = m_rdCost.psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
                     if (tempCost < bestCost)
                     {
                         std::swap(outBestCU, outTempCU);
@@ -1255,9 +1237,7 @@
                     outTempCU->setQPSubParts(origQP, 0, depth);
                     outTempCU->setSkipFlagSubParts(false, 0, depth);
                     if (!bestIsSkip)
-                    {
                         bestIsSkip = !outBestCU->getQtRootCbf(0);
-                    }
                 }
             }
         }
@@ -1267,9 +1247,7 @@
             if (outBestCU->getQtRootCbf(0) == 0)
             {
                 if (outBestCU->getMergeFlag(0))
-                {
                     *earlyDetectionSkipMode = true;
-                }
                 else
                 {
                     int mvsum = 0;
@@ -1285,9 +1263,7 @@
                     }
 
                     if (mvsum == 0)
-                    {
                         *earlyDetectionSkipMode = true;
-                    }
                 }
             }
         }
@@ -1327,9 +1303,8 @@
 
     m_sbacCoder->resetBits();
     if (outTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
-    {
         m_sbacCoder->codeCUTransquantBypassFlag(outTempCU, 0);
-    }
+
     if (!outTempCU->getSlice()->isIntra())
     {
         m_sbacCoder->codeSkipFlag(outTempCU, 0);
@@ -1346,17 +1321,16 @@
     outTempCU->m_totalBits = m_sbacCoder->getNumberOfWrittenBits();
     outTempCU->m_coeffBits = outTempCU->m_totalBits - outTempCU->m_mvBits;
 
-    if (m_rdCost->psyRdEnabled())
+    if (m_rdCost.psyRdEnabled())
     {
         int part = g_convertToBit[outTempCU->getCUSize(0)];
-        outTempCU->m_psyEnergy = m_rdCost->psyCost(part, m_origYuv[depth]->getLumaAddr(), m_origYuv[depth]->getStride(),
-                                                     m_tmpRecoYuv[depth]->getLumaAddr(), m_tmpRecoYuv[depth]->getStride());
-        outTempCU->m_totalPsyCost = m_rdCost->calcPsyRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits, outTempCU->m_psyEnergy);
+        outTempCU->m_psyEnergy = m_rdCost.psyCost(part, m_origYuv[depth]->getLumaAddr(), m_origYuv[depth]->getStride(),
+                                                  m_tmpRecoYuv[depth]->getLumaAddr(), m_tmpRecoYuv[depth]->getStride());
+        outTempCU->m_totalPsyCost = m_rdCost.calcPsyRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits, outTempCU->m_psyEnergy);
     }
     else
-    {
-        outTempCU->m_totalRDCost = m_rdCost->calcRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
-    }
+        outTempCU->m_totalRDCost = m_rdCost.calcRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
+
     xCheckDQP(outTempCU);
     xCheckBestMode(outBestCU, outTempCU, depth);
 }
@@ -1379,6 +1353,7 @@
     m_sbacCoder->resetBits();
     if (outTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
         m_sbacCoder->codeCUTransquantBypassFlag(outTempCU, 0);
+
     if (!outTempCU->getSlice()->isIntra())
     {
         m_sbacCoder->codeSkipFlag(outTempCU, 0);
@@ -1395,17 +1370,16 @@
     outTempCU->m_totalBits = m_sbacCoder->getNumberOfWrittenBits();
     outTempCU->m_coeffBits = outTempCU->m_totalBits - outTempCU->m_mvBits;
 
-    if (m_rdCost->psyRdEnabled())
+    if (m_rdCost.psyRdEnabled())
     {
         int part = g_convertToBit[outTempCU->getCUSize(0)];
-        outTempCU->m_psyEnergy = m_rdCost->psyCost(part, m_origYuv[depth]->getLumaAddr(), m_origYuv[depth]->getStride(),
-                                                     m_tmpRecoYuv[depth]->getLumaAddr(), m_tmpRecoYuv[depth]->getStride());
-        outTempCU->m_totalPsyCost = m_rdCost->calcPsyRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits, outTempCU->m_psyEnergy);
+        outTempCU->m_psyEnergy = m_rdCost.psyCost(part, m_origYuv[depth]->getLumaAddr(), m_origYuv[depth]->getStride(),
+                                                  m_tmpRecoYuv[depth]->getLumaAddr(), m_tmpRecoYuv[depth]->getStride());
+        outTempCU->m_totalPsyCost = m_rdCost.calcPsyRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits, outTempCU->m_psyEnergy);
     }
     else
-    {
-        outTempCU->m_totalRDCost = m_rdCost->calcRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
-    }
+        outTempCU->m_totalRDCost = m_rdCost.calcRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
+
     xCheckDQP(outTempCU);
     xCheckBestMode(outBestCU, outTempCU, depth);
 }
@@ -1417,8 +1391,8 @@
  */
 void TEncCu::xCheckBestMode(TComDataCU*& outBestCU, TComDataCU*& outTempCU, uint32_t depth)
 {
-    uint64_t tempCost = m_rdCost->psyRdEnabled() ? outTempCU->m_totalPsyCost : outTempCU->m_totalRDCost;
-    uint64_t bestCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
+    uint64_t tempCost = m_rdCost.psyRdEnabled() ? outTempCU->m_totalPsyCost : outTempCU->m_totalRDCost;
+    uint64_t bestCost = m_rdCost.psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
 
     if (tempCost < bestCost)
     {
diff -r 3685d607012f -r f5fe4e345362 source/Lib/TLibEncoder/TEncCu.h
--- a/source/Lib/TLibEncoder/TEncCu.h	Thu Jul 10 22:32:24 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncCu.h	Thu Jul 10 23:15:24 2014 -0500
@@ -125,7 +125,7 @@
 
     TEncCu();
 
-    bool init(Encoder* top, RDCost* rdCost, TComTrQuant* trQuant);
+    bool init(Encoder* top);
     bool create(uint8_t totalDepth, uint32_t maxWidth);
     void destroy();
     void compressCU(TComDataCU* cu);
diff -r 3685d607012f -r f5fe4e345362 source/Lib/TLibEncoder/TEncSearch.cpp
--- a/source/Lib/TLibEncoder/TEncSearch.cpp	Thu Jul 10 22:32:24 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp	Thu Jul 10 23:15:24 2014 -0500
@@ -62,12 +62,10 @@
         m_qtTempCbf[i] = NULL;
     }
 
+    m_numLayers = 0;
     m_param = NULL;
-    m_rdCost = NULL;
-    m_trQuant = NULL;
     m_sbacCoder = NULL;
     m_rdSbacCoders = NULL;
-    m_numLayers = 0;
 }
 
 TEncSearch::~TEncSearch()
@@ -132,14 +130,14 @@
     double lambdaCr = x265_lambda2_tab[qpCr];
 
     m_me.setQP(qp);
-    m_trQuant->setLambdas(lambda2, lambdaCb, lambdaCr);
-    m_rdCost->setLambda(lambda2, x265_lambda_tab[qp]);
+    m_trQuant.setLambdas(lambda2, lambdaCb, lambdaCr);
+    m_rdCost.setLambda(lambda2, x265_lambda_tab[qp]);
     int chroma_offset_idx = X265_MIN(qp - qpCb + 12, MAX_CHROMA_LAMBDA_OFFSET);
-    double lambdaOffset = m_rdCost->psyRdEnabled() ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256.0;
-    m_rdCost->setCbDistortionWeight(lambdaOffset);
+    double lambdaOffset = m_rdCost.psyRdEnabled() ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256.0;
+    m_rdCost.setCbDistortionWeight(lambdaOffset);
     chroma_offset_idx = X265_MIN(qp - qpCr + 12, MAX_CHROMA_LAMBDA_OFFSET);
-    lambdaOffset = m_rdCost->psyRdEnabled() ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256.0;
-    m_rdCost->setCrDistortionWeight(lambdaOffset);
+    lambdaOffset = m_rdCost.psyRdEnabled() ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256.0;
+    m_rdCost.setCrDistortionWeight(lambdaOffset);
 }
 
 void TEncSearch::xEncSubdivCbfQTLuma(TComDataCU* cu, uint32_t trDepth, uint32_t absPartIdx)
@@ -434,12 +432,12 @@
     //===== transform and quantization =====
     //--- init rate estimation arrays for RDOQ ---
     if (m_bEnableRDOQ)
-        m_sbacCoder->estBit(m_trQuant->m_estBitsSbac, tuSize, TEXT_LUMA);
+        m_sbacCoder->estBit(m_trQuant.m_estBitsSbac, tuSize, TEXT_LUMA);
 
     //--- transform and quantization ---
     int chFmt = cu->getChromaFormat();
-    m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
-    uint32_t numSig = m_trQuant->transformNxN(cu, residual, stride, coeff, log2TrSize, TEXT_LUMA, absPartIdx, useTransformSkip);
+    m_trQuant.setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
+    uint32_t numSig = m_trQuant.transformNxN(cu, residual, stride, coeff, log2TrSize, TEXT_LUMA, absPartIdx, useTransformSkip);
 
     //--- set coded block flag ---
     cbf = numSig ? 1 : 0;
@@ -447,7 +445,7 @@
     if (numSig)
     {
         //--- inverse transform ---
-        m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), residual, stride, coeff, log2TrSize, TEXT_LUMA, true, useTransformSkip, numSig);
+        m_trQuant.invtransformNxN(cu->getCUTransquantBypass(absPartIdx), residual, stride, coeff, log2TrSize, TEXT_LUMA, true, useTransformSkip, numSig);
         X265_CHECK(log2TrSize <= 5, "log2TrSize is too large %d\n", log2TrSize);
         //===== reconstruction =====
         primitives.calcrecon[sizeIdx](pred, residual, reconQt, reconIPred, stride, reconQtStride, reconIPredStride);
@@ -503,7 +501,7 @@
     //===== transform and quantization =====
     //--- init rate estimation arrays for RDOQ ---
     if (m_bEnableRDOQ)
-        m_sbacCoder->estBit(m_trQuant->m_estBitsSbac, tuSize, TEXT_CHROMA);
+        m_sbacCoder->estBit(m_trQuant.m_estBitsSbac, tuSize, TEXT_CHROMA);
 
     //--- transform and quantization ---
     int chFmt = cu->getChromaFormat();
@@ -513,8 +511,8 @@
     else
         curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
 
-    m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
-    uint32_t numSig = m_trQuant->transformNxN(cu, residual, stride, coeff, log2TrSizeC, ttype, absPartIdx, useTransformSkipC);
+    m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+    uint32_t numSig = m_trQuant.transformNxN(cu, residual, stride, coeff, log2TrSizeC, ttype, absPartIdx, useTransformSkipC);
 
     //--- set coded block flag ---
     cbf = numSig ? 1 : 0;
@@ -523,7 +521,7 @@
     if (numSig)
     {
         //--- inverse transform ---
-        m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), residual, stride, coeff, log2TrSizeC, ttype, true, useTransformSkipC, numSig);
+        m_trQuant.invtransformNxN(cu->getCUTransquantBypass(absPartIdx), residual, stride, coeff, log2TrSizeC, ttype, true, useTransformSkipC, numSig);
         X265_CHECK(log2TrSizeC <= 5, "log2TrSizeC is too large %d\n", log2TrSizeC);
         //===== reconstruction =====
         primitives.calcrecon[sizeIdxC](pred, residual, reconQt, reconIPred, stride, reconQtStride, reconIPredStride);
@@ -544,9 +542,9 @@
 
     X265_CHECK(ttype == TEXT_CHROMA_U || ttype == TEXT_CHROMA_V, "invalid ttype\n");
     if (ttype == TEXT_CHROMA_U)
-        outDist += m_rdCost->scaleChromaDistCb(dist);
+        outDist += m_rdCost.scaleChromaDistCb(dist);
     else
-        outDist += m_rdCost->scaleChromaDistCr(dist);
+        outDist += m_rdCost.scaleChromaDistCr(dist);
 }
 
 void TEncSearch::xRecurIntraCodingQT(TComDataCU* cu,
@@ -655,10 +653,10 @@
 
                 //----- code luma block with given intra prediction mode and store Cbf-----
                 xIntraCodingLumaBlk(cu, absPartIdx, log2TrSize, fencYuv, predYuv, resiYuv, recon, reconStride, coeff, singleCbfYTmp, singleDistYTmp);
-                if (m_rdCost->psyRdEnabled())
+                if (m_rdCost.psyRdEnabled())
                 {
                     uint32_t zorder = cu->getZorderIdxInCU() + absPartIdx;
-                    singlePsyEnergyYTmp = m_rdCost->psyCost(log2TrSize - 2, fencYuv->getLumaAddr(absPartIdx), fencYuv->getStride(),
+                    singlePsyEnergyYTmp = m_rdCost.psyCost(log2TrSize - 2, fencYuv->getLumaAddr(absPartIdx), fencYuv->getStride(),
                         cu->getPic()->getPicYuvRec()->getLumaAddr(cu->getAddr(), zorder), cu->getPic()->getPicYuvRec()->getStride());
                 }
                 cu->setCbfSubParts(singleCbfYTmp << trDepth, TEXT_LUMA, absPartIdx, fullDepth);
@@ -670,10 +668,10 @@
                 else
                 {
                     uint32_t singleBits = xGetIntraBitsLuma(cu, trDepth, absPartIdx, log2TrSize, coeff);
-                    if (m_rdCost->psyRdEnabled())
-                        singleCostTmp = m_rdCost->calcPsyRdCost(singleDistYTmp, singleBits, singlePsyEnergyYTmp);
+                    if (m_rdCost.psyRdEnabled())
+                        singleCostTmp = m_rdCost.calcPsyRdCost(singleDistYTmp, singleBits, singlePsyEnergyYTmp);
                     else
-                        singleCostTmp = m_rdCost->calcRdCost(singleDistYTmp, singleBits);
+                        singleCostTmp = m_rdCost.calcRdCost(singleDistYTmp, singleBits);
                 }
 
                 if (singleCostTmp < singleCost)
@@ -715,10 +713,10 @@
             //----- code luma block with given intra prediction mode and store Cbf-----
             cu->setTransformSkipSubParts(0, TEXT_LUMA, absPartIdx, fullDepth);
             xIntraCodingLumaBlk(cu, absPartIdx, log2TrSize, fencYuv, predYuv, resiYuv, reconQt, reconQtStride, coeffY, singleCbfY, singleDistY);
-            if (m_rdCost->psyRdEnabled())
+            if (m_rdCost.psyRdEnabled())
             {
                 uint32_t zorder = cu->getZorderIdxInCU() + absPartIdx;
-                singlePsyEnergyY = m_rdCost->psyCost(log2TrSize - 2, fencYuv->getLumaAddr(absPartIdx), fencYuv->getStride(),
+                singlePsyEnergyY = m_rdCost.psyCost(log2TrSize - 2, fencYuv->getLumaAddr(absPartIdx), fencYuv->getStride(),
                     cu->getPic()->getPicYuvRec()->getLumaAddr(cu->getAddr(), zorder), cu->getPic()->getPicYuvRec()->getStride());
             }
             cu->setCbfSubParts(singleCbfY << trDepth, TEXT_LUMA, absPartIdx, fullDepth);
@@ -727,10 +725,10 @@
             if (m_param->rdPenalty && (log2TrSize == 5) && !isIntraSlice)
                 singleBits *= 4;
 
-            if (m_rdCost->psyRdEnabled())
-                singleCost = m_rdCost->calcPsyRdCost(singleDistY, singleBits, singlePsyEnergyY);
+            if (m_rdCost.psyRdEnabled())
+                singleCost = m_rdCost.calcPsyRdCost(singleDistY, singleBits, singlePsyEnergyY);
             else
-                singleCost = m_rdCost->calcRdCost(singleDistY, singleBits);
+                singleCost = m_rdCost.calcRdCost(singleDistY, singleBits);
         }
     }
 
@@ -771,10 +769,10 @@
 
         //----- determine rate and r-d cost -----
         uint32_t splitBits = xGetIntraBitsQTLuma(cu, trDepth, absPartIdx);
-        if (m_rdCost->psyRdEnabled())
-            splitCost = m_rdCost->calcPsyRdCost(splitDistY, splitBits, splitPsyEnergyY);
+        if (m_rdCost.psyRdEnabled())
+            splitCost = m_rdCost.calcPsyRdCost(splitDistY, splitBits, splitPsyEnergyY);
         else
-            splitCost = m_rdCost->calcRdCost(splitDistY, splitBits);
+            splitCost = m_rdCost.calcRdCost(splitDistY, splitBits);
 
         //===== compare and set best =====
         if (splitCost < singleCost)
@@ -871,8 +869,8 @@
         primitives.calcresidual[sizeIdx](fenc, pred, residual, stride);
 
         //===== transform and quantization =====
-        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
-        uint32_t numSig = m_trQuant->transformNxN(cu, residual, stride, coeff, log2TrSize, TEXT_LUMA, absPartIdx, useTransformSkip);
+        m_trQuant.setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
+        uint32_t numSig = m_trQuant.transformNxN(cu, residual, stride, coeff, log2TrSize, TEXT_LUMA, absPartIdx, useTransformSkip);
 
         //--- set coded block flag ---
         cu->setCbfSubParts((numSig ? 1 : 0) << trDepth, TEXT_LUMA, absPartIdx, fullDepth);
@@ -882,7 +880,7 @@
         if (numSig)
         {
             //--- inverse transform ---
-            m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), residual, stride, coeff, log2TrSize, TEXT_LUMA, true, useTransformSkip, numSig);
+            m_trQuant.invtransformNxN(cu->getCUTransquantBypass(absPartIdx), residual, stride, coeff, log2TrSize, TEXT_LUMA, true, useTransformSkip, numSig);
 
             // Generate Recon
             primitives.luma_add_ps[part](recon, stride, pred, residual, stride, stride);
@@ -1126,15 +1124,15 @@
                         else
                         {
                             uint32_t bitsTmp = singleCbfCTmp ? xGetIntraBitsChroma(cu, absPartIdxC, log2TrSizeC, chromaId, coeff) : 0;
-                            if (m_rdCost->psyRdEnabled())
+                            if (m_rdCost.psyRdEnabled())
                             {
                                 uint32_t zorder = cu->getZorderIdxInCU() + absPartIdxC;
-                                singlePsyEnergyTmp = m_rdCost->psyCost(log2TrSizeC - 2, fencYuv->getChromaAddr(chromaId, absPartIdxC), fencYuv->getCStride(),
+                                singlePsyEnergyTmp = m_rdCost.psyCost(log2TrSizeC - 2, fencYuv->getChromaAddr(chromaId, absPartIdxC), fencYuv->getCStride(),
                                     cu->getPic()->getPicYuvRec()->getChromaAddr(chromaId, cu->getAddr(), zorder), cu->getPic()->getPicYuvRec()->getCStride());
-                                singleCostTmp = m_rdCost->calcPsyRdCost(singleDistCTmp, bitsTmp, singlePsyEnergyTmp);
+                                singleCostTmp = m_rdCost.calcPsyRdCost(singleDistCTmp, bitsTmp, singlePsyEnergyTmp);
                             }
                             else
-                                singleCostTmp = m_rdCost->calcRdCost(singleDistCTmp, bitsTmp);
+                                singleCostTmp = m_rdCost.calcRdCost(singleDistCTmp, bitsTmp);
                         }
 
                         if (singleCostTmp < singleCost)
@@ -1175,10 +1173,10 @@
                 {
                     cu->setTransformSkipPartRange(0, (TextType)chromaId, absPartIdxC, tuIterator.absPartIdxStep);
                     xIntraCodingChromaBlk(cu, absPartIdxC, fencYuv, predYuv, resiYuv, reconQt, reconQtStride, coeffC, singleCbfC, outDist, chromaId, log2TrSizeC);
-                    if (m_rdCost->psyRdEnabled())
+                    if (m_rdCost.psyRdEnabled())
                     {
                         uint32_t zorder = cu->getZorderIdxInCU() + absPartIdxC;
-                        singlePsyEnergyTmp = m_rdCost->psyCost(log2TrSizeC - 2, fencYuv->getChromaAddr(chromaId, absPartIdxC), fencYuv->getCStride(),
+                        singlePsyEnergyTmp = m_rdCost.psyCost(log2TrSizeC - 2, fencYuv->getChromaAddr(chromaId, absPartIdxC), fencYuv->getCStride(),
                             cu->getPic()->getPicYuvRec()->getChromaAddr(chromaId, cu->getAddr(), zorder), cu->getPic()->getPicYuvRec()->getCStride());
                     }
                     cu->setCbfPartRange(singleCbfC << trDepth, (TextType)chromaId, absPartIdxC, tuIterator.absPartIdxStep);
@@ -1349,8 +1347,8 @@
                     curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();
                 else
                     curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
-                uint32_t numSig = m_trQuant->transformNxN(cu, residual, stride, coeff, log2TrSizeC, ttype, absPartIdxC, useTransformSkipC);
+                m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+                uint32_t numSig = m_trQuant.transformNxN(cu, residual, stride, coeff, log2TrSizeC, ttype, absPartIdxC, useTransformSkipC);
 
                 //--- set coded block flag ---
                 cu->setCbfPartRange((((numSig > 0) ? 1 : 0) << origTrDepth), ttype, absPartIdxC, tuIterator.absPartIdxStep);
@@ -1358,7 +1356,7 @@
                 if (numSig)
                 {
                     //--- inverse transform ---
-                    m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), residual, stride, coeff, log2TrSizeC, ttype, true, useTransformSkipC, numSig);
+                    m_trQuant.invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), residual, stride, coeff, log2TrSizeC, ttype, true, useTransformSkipC, numSig);
 
                     //===== reconstruction =====
                     // use square primitives
@@ -1528,7 +1526,7 @@
             {
                 uint32_t sad = modeCosts[mode];
                 uint32_t bits = !(mpms & ((uint64_t)1 << mode)) ? rbits : xModeBitsIntra(cu, mode, partOffset, depth);
-                uint64_t cost = m_rdCost->calcRdSADCost(sad, bits);
+                uint64_t cost = m_rdCost.calcRdSADCost(sad, bits);
                 candNum += xUpdateCandList(mode, cost, numModesForFullRD, rdModeList, candCostList);
             }
 
@@ -1769,10 +1767,10 @@
 
             uint32_t bits = xGetIntraBitsQTChroma(cu, initTrDepth, absPartIdxC, tuIterator.absPartIdxStep);
             uint64_t cost = 0; 
-            if (m_rdCost->psyRdEnabled())
-                cost = m_rdCost->calcPsyRdCost(dist, bits, cu->m_psyEnergy);
+            if (m_rdCost.psyRdEnabled())
+                cost = m_rdCost.calcPsyRdCost(dist, bits, cu->m_psyEnergy);
             else
-                cost = m_rdCost->calcRdCost(dist, bits);
+                cost = m_rdCost.calcRdCost(dist, bits);
             //----- compare -----
             if (cost < bestCost)
             {
@@ -1891,7 +1889,7 @@
         motionCompensation(cu, &m_predTempYuv, REF_PIC_LIST_X, puIdx, true, false);
         uint32_t costCand = m_me.bufSATD(m_predTempYuv.getLumaAddr(m.absPartIdx), m_predTempYuv.getStride());
         uint32_t bitsCand = getTUBits(mergeCand, m.maxNumMergeCand);
-        costCand = costCand + m_rdCost->getCost(bitsCand);
+        costCand = costCand + m_rdCost.getCost(bitsCand);
         if (costCand < outCost)
         {
             outCost = costCand;
@@ -2006,7 +2004,7 @@
 
                     xPredInterLumaBlk(cu, cu->getSlice()->getRefPic(l, ref)->getPicYuvRec(), partAddr, &mvCand, roiWidth, roiHeight, &m_predTempYuv);
                     uint32_t cost = m_me.bufSAD(m_predTempYuv.getLumaAddr(partAddr), m_predTempYuv.getStride());
-                    cost = m_rdCost->calcRdSADCost(cost, MVP_IDX_BITS);
+                    cost = m_rdCost.calcRdSADCost(cost, MVP_IDX_BITS);
 
                     if (bestCost > cost)
                     {
@@ -2023,7 +2021,7 @@
 
                 /* Get total cost of partition, but only include MV bit cost once */
                 bits += m_me.bitcost(outmv);
-                uint32_t cost = (satdCost - m_me.mvcost(outmv)) + m_rdCost->getCost(bits);
+                uint32_t cost = (satdCost - m_me.mvcost(outmv)) + m_rdCost.getCost(bits);
 
                 /* Refine MVP selection, updates: mvp, mvpIdx, bits, cost */
                 xCheckBestMVP(&amvpInfo[l][ref], outmv, mvp, mvpIdx, bits, cost);
@@ -2062,7 +2060,7 @@
             int satdCost = m_me.bufSATD(avg, roiWidth);
 
             bidirBits = list[0].bits + list[1].bits + listSelBits[2] - (listSelBits[0] + listSelBits[1]);
-            bidirCost = satdCost + m_rdCost->getCost(bidirBits);
+            bidirCost = satdCost + m_rdCost.getCost(bidirBits);
 
             MV mvzero(0, 0);
             bool bTryZero = list[0].mv.notZero() || list[1].mv.notZero();
@@ -2100,7 +2098,7 @@
                 m_me.setMVP(mvp1);
                 uint32_t bits1 = list[1].bits - m_me.bitcost(list[1].mv) + m_me.bitcost(mvzero);
 
-                uint32_t cost = satdCost + m_rdCost->getCost(bits0) + m_rdCost->getCost(bits1);
+                uint32_t cost = satdCost + m_rdCost.getCost(bits0) + m_rdCost.getCost(bits1);
 
                 /* refine MVP selection for zero mv, updates: mvp, mvpidx, bits, cost */
                 xCheckBestMVP(&amvpInfo[0][list[0].ref], mvzero, mvp0, mvpIdx0, bits0, cost);
@@ -2271,7 +2269,7 @@
         outMvpIdx = bestMvpIdx;
         uint32_t origOutBits = outBits;
         outBits = origOutBits - mvBitsOrig + bestMvBits;
-        outCost = (outCost - m_rdCost->getCost(origOutBits)) + m_rdCost->getCost(outBits);
+        outCost = (outCost - m_rdCost.getCost(origOutBits)) + m_rdCost.getCost(outBits);
     }
 }
 
@@ -2327,8 +2325,8 @@
         distortion = primitives.sse_pp[part](fencYuv->getLumaAddr(), fencYuv->getStride(), outReconYuv->getLumaAddr(), outReconYuv->getStride());
         // Chroma
         part = partitionFromSizes(cuSize >> m_hChromaShift, cuSize >> m_vChromaShift);
-        distortion += m_rdCost->scaleChromaDistCb(primitives.sse_pp[part](fencYuv->getCbAddr(), fencYuv->getCStride(), outReconYuv->getCbAddr(), outReconYuv->getCStride()));
-        distortion += m_rdCost->scaleChromaDistCr(primitives.sse_pp[part](fencYuv->getCrAddr(), fencYuv->getCStride(), outReconYuv->getCrAddr(), outReconYuv->getCStride()));
+        distortion += m_rdCost.scaleChromaDistCb(primitives.sse_pp[part](fencYuv->getCbAddr(), fencYuv->getCStride(), outReconYuv->getCbAddr(), outReconYuv->getCStride()));
+        distortion += m_rdCost.scaleChromaDistCr(primitives.sse_pp[part](fencYuv->getCrAddr(), fencYuv->getCStride(), outReconYuv->getCrAddr(), outReconYuv->getCStride()));
 
         m_sbacCoder->load(m_rdSbacCoders[depth][CI_CURR_BEST]);
         m_sbacCoder->resetBits();
@@ -2341,15 +2339,15 @@
         
         cu->m_totalBits       = bits;
         cu->m_totalDistortion = distortion;
-        if (m_rdCost->psyRdEnabled())
+        if (m_rdCost.psyRdEnabled())
         {
             int size = g_convertToBit[cuSize];
-            cu->m_psyEnergy = m_rdCost->psyCost(size, fencYuv->getLumaAddr(), fencYuv->getStride(),
+            cu->m_psyEnergy = m_rdCost.psyCost(size, fencYuv->getLumaAddr(), fencYuv->getStride(),
                                                    outReconYuv->getLumaAddr(), outReconYuv->getStride());
-            cu->m_totalPsyCost = m_rdCost->calcPsyRdCost(cu->m_totalDistortion, cu->m_totalBits, cu->m_psyEnergy);
+            cu->m_totalPsyCost = m_rdCost.calcPsyRdCost(cu->m_totalDistortion, cu->m_totalBits, cu->m_psyEnergy);
         }
         else
-            cu->m_totalRDCost = m_rdCost->calcRdCost(cu->m_totalDistortion, cu->m_totalBits);
+            cu->m_totalRDCost = m_rdCost.calcRdCost(cu->m_totalDistortion, cu->m_totalBits);
 
         m_sbacCoder->store(m_rdSbacCoders[depth][CI_TEMP_BEST]);
 
@@ -2393,15 +2391,15 @@
         uint32_t zeroResiBits = m_sbacCoder->getNumberOfWrittenBits();
         uint64_t zeroCost = 0;
         uint32_t zeroPsyEnergyY = 0;
-        if (m_rdCost->psyRdEnabled())
+        if (m_rdCost.psyRdEnabled())
         {
+            // need to check whether zero distortion is similar to psyenergy of fenc
             int size = g_convertToBit[cuSize];
-            zeroPsyEnergyY = m_rdCost->psyCost(size, fencYuv->getLumaAddr(), fencYuv->getStride(),
-                (pixel*)RDCost::zeroPel, MAX_CU_SIZE); // need to check whether zero distortion is similar to psyenergy of fenc
-            zeroCost = m_rdCost->calcPsyRdCost(zeroDistortion, zeroResiBits, zeroPsyEnergyY);
+            zeroPsyEnergyY = m_rdCost.psyCost(size, fencYuv->getLumaAddr(), fencYuv->getStride(), (pixel*)RDCost::zeroPel, MAX_CU_SIZE);
+            zeroCost = m_rdCost.calcPsyRdCost(zeroDistortion, zeroResiBits, zeroPsyEnergyY);
         }
         else
-            zeroCost = m_rdCost->calcRdCost(zeroDistortion, zeroResiBits);
+            zeroCost = m_rdCost.calcRdCost(zeroDistortion, zeroResiBits);
 
         if (cu->isLosslessCoded(0))
             zeroCost = cost + 1;
@@ -2430,10 +2428,10 @@
 
         bits = xSymbolBitsInter(cu);
 
-        if (m_rdCost->psyRdEnabled())
-            cost = m_rdCost->calcPsyRdCost(distortion, bits, cu->m_psyEnergy);
+        if (m_rdCost.psyRdEnabled())
+            cost = m_rdCost.calcPsyRdCost(distortion, bits, cu->m_psyEnergy);
         else
-            cost = m_rdCost->calcRdCost(distortion, bits);
+            cost = m_rdCost.calcRdCost(distortion, bits);
 
         if (cost < bestCost)
         {
@@ -2456,17 +2454,17 @@
         int part = partitionFromSize(cuSize);
         bestDist = primitives.sse_pp[part](fencYuv->getLumaAddr(), fencYuv->getStride(), outReconYuv->getLumaAddr(), outReconYuv->getStride());
         part = partitionFromSizes(cuSize >> m_hChromaShift, cuSize >> m_vChromaShift);
-        bestDist += m_rdCost->scaleChromaDistCb(primitives.sse_pp[part](fencYuv->getCbAddr(), fencYuv->getCStride(), outReconYuv->getCbAddr(), outReconYuv->getCStride()));
-        bestDist += m_rdCost->scaleChromaDistCr(primitives.sse_pp[part](fencYuv->getCrAddr(), fencYuv->getCStride(), outReconYuv->getCrAddr(), outReconYuv->getCStride()));
-        if (m_rdCost->psyRdEnabled())
+        bestDist += m_rdCost.scaleChromaDistCb(primitives.sse_pp[part](fencYuv->getCbAddr(), fencYuv->getCStride(), outReconYuv->getCbAddr(), outReconYuv->getCStride()));
+        bestDist += m_rdCost.scaleChromaDistCr(primitives.sse_pp[part](fencYuv->getCrAddr(), fencYuv->getCStride(), outReconYuv->getCrAddr(), outReconYuv->getCStride()));
+        if (m_rdCost.psyRdEnabled())
         {
             int size = g_convertToBit[cuSize];
-            cu->m_psyEnergy = m_rdCost->psyCost(size, fencYuv->getLumaAddr(), fencYuv->getStride(),
-                                                   outReconYuv->getLumaAddr(), outReconYuv->getStride());
-            cu->m_totalPsyCost = m_rdCost->calcPsyRdCost(bestDist, bestBits, cu->m_psyEnergy);
+            cu->m_psyEnergy = m_rdCost.psyCost(size, fencYuv->getLumaAddr(), fencYuv->getStride(),
+                                               outReconYuv->getLumaAddr(), outReconYuv->getStride());
+            cu->m_totalPsyCost = m_rdCost.calcPsyRdCost(bestDist, bestBits, cu->m_psyEnergy);
         }
         else
-            cu->m_totalRDCost = m_rdCost->calcRdCost(bestDist, bestBits);
+            cu->m_totalRDCost = m_rdCost.calcRdCost(bestDist, bestBits);
         cu->m_totalBits       = bestBits;
         cu->m_totalDistortion = bestDist;
 
@@ -2555,16 +2553,16 @@
         const uint32_t strideResiY = resiYuv->m_width;
         const uint32_t strideResiC = resiYuv->m_cwidth;
 
-        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
-        uint32_t numSigY = m_trQuant->transformNxN(cu, curResiY, strideResiY, coeffCurY,
-                                                   log2TrSize, TEXT_LUMA, absPartIdx, false, curuseRDOQ);
+        m_trQuant.setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
+        uint32_t numSigY = m_trQuant.transformNxN(cu, curResiY, strideResiY, coeffCurY,
+                                                  log2TrSize, TEXT_LUMA, absPartIdx, false, curuseRDOQ);
 
         cu->setCbfSubParts(numSigY ? setCbf : 0, TEXT_LUMA, absPartIdx, depth);
 
         if (numSigY)
         {
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
-            m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), curResiY, strideResiY, coeffCurY, log2TrSize, TEXT_LUMA, false, false, numSigY);
+            m_trQuant.setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
+            m_trQuant.invtransformNxN(cu->getCUTransquantBypass(absPartIdx), curResiY, strideResiY, coeffCurY, log2TrSize, TEXT_LUMA, false, false, numSigY);
         }
         else
             primitives.blockfill_s[sizeIdx](curResiY, strideResiY, 0);
@@ -2585,14 +2583,14 @@
                 cu->setTransformSkipPartRange(0, TEXT_CHROMA_V, absPartIdxC, tuIterator.absPartIdxStep);
 
                 int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
-                uint32_t numSigU = m_trQuant->transformNxN(cu, curResiU, strideResiC, coeffCurU + subTUOffset,
-                                                           log2TrSizeC, TEXT_CHROMA_U, absPartIdxC, false, curuseRDOQ);
+                m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+                uint32_t numSigU = m_trQuant.transformNxN(cu, curResiU, strideResiC, coeffCurU + subTUOffset,
+                                                          log2TrSizeC, TEXT_CHROMA_U, absPartIdxC, false, curuseRDOQ);
 
                 curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
-                uint32_t numSigV = m_trQuant->transformNxN(cu, curResiV, strideResiC, coeffCurV + subTUOffset,
-                                                           log2TrSizeC, TEXT_CHROMA_V, absPartIdxC, false, curuseRDOQ);
+                m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+                uint32_t numSigV = m_trQuant.transformNxN(cu, curResiV, strideResiC, coeffCurV + subTUOffset,
+                                                          log2TrSizeC, TEXT_CHROMA_V, absPartIdxC, false, curuseRDOQ);
 
                 cu->setCbfPartRange(numSigU ? setCbf : 0, TEXT_CHROMA_U, absPartIdxC, tuIterator.absPartIdxStep);
                 cu->setCbfPartRange(numSigV ? setCbf : 0, TEXT_CHROMA_V, absPartIdxC, tuIterator.absPartIdxStep);
@@ -2600,8 +2598,8 @@
                 if (numSigU)
                 {
                     curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();
-                    m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
-                    m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), curResiU, strideResiC, coeffCurU + subTUOffset, log2TrSizeC, TEXT_CHROMA_U, false, false, numSigU);
+                    m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+                    m_trQuant.invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), curResiU, strideResiC, coeffCurU + subTUOffset, log2TrSizeC, TEXT_CHROMA_U, false, false, numSigU);
                 }
                 else
                     primitives.blockfill_s[sizeIdxC](curResiU, strideResiC, 0);
@@ -2609,8 +2607,8 @@
                 if (numSigV)
                 {
                     curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
-                    m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
-                    m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), curResiV, strideResiC, coeffCurV + subTUOffset, log2TrSizeC, TEXT_CHROMA_V, false, false, numSigV);
+                    m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+                    m_trQuant.invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), curResiV, strideResiC, coeffCurV + subTUOffset, log2TrSizeC, TEXT_CHROMA_V, false, false, numSigV);
                 }
                 else
                     primitives.blockfill_s[sizeIdxC](curResiV, strideResiC, 0);
@@ -2734,11 +2732,11 @@
         cu->setTransformSkipSubParts(0, TEXT_LUMA, absPartIdx, depth);
 
         if (m_bEnableRDOQ && curuseRDOQ)
-            m_sbacCoder->estBit(m_trQuant->m_estBitsSbac, trSize, TEXT_LUMA);
-
-        m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
-        numSigY = m_trQuant->transformNxN(cu, resiYuv->getLumaAddr(absPartIdx), resiYuv->m_width, coeffCurY,
-                                          log2TrSize, TEXT_LUMA, absPartIdx, false, curuseRDOQ);
+            m_sbacCoder->estBit(m_trQuant.m_estBitsSbac, trSize, TEXT_LUMA);
+
+        m_trQuant.setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
+        numSigY = m_trQuant.transformNxN(cu, resiYuv->getLumaAddr(absPartIdx), resiYuv->m_width, coeffCurY,
+                                         log2TrSize, TEXT_LUMA, absPartIdx, false, curuseRDOQ);
 
         cu->setCbfSubParts(numSigY ? setCbf : 0, TEXT_LUMA, absPartIdx, depth);
 
@@ -2763,18 +2761,18 @@
                 cu->setTransformSkipPartRange(0, TEXT_CHROMA_V, absPartIdxC, tuIterator.absPartIdxStep);
 
                 if (m_bEnableRDOQ && curuseRDOQ)
-                    m_sbacCoder->estBit(m_trQuant->m_estBitsSbac, trSizeC, TEXT_CHROMA);
+                    m_sbacCoder->estBit(m_trQuant.m_estBitsSbac, trSizeC, TEXT_CHROMA);
 
                 //Cb transform
                 int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
-                numSigU[tuIterator.section] = m_trQuant->transformNxN(cu, resiYuv->getCbAddr(absPartIdxC), resiYuv->m_cwidth, coeffCurU + subTUOffset,
-                                                                        log2TrSizeC, TEXT_CHROMA_U, absPartIdxC, false, curuseRDOQ);
+                m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+                numSigU[tuIterator.section] = m_trQuant.transformNxN(cu, resiYuv->getCbAddr(absPartIdxC), resiYuv->m_cwidth, coeffCurU + subTUOffset,
+                                                                     log2TrSizeC, TEXT_CHROMA_U, absPartIdxC, 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, chFmt);
-                numSigV[tuIterator.section] = m_trQuant->transformNxN(cu, resiYuv->getCrAddr(absPartIdxC), resiYuv->m_cwidth, coeffCurV + subTUOffset,
-                                                                        log2TrSizeC, TEXT_CHROMA_V, absPartIdxC, false, curuseRDOQ);
+                m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+                numSigV[tuIterator.section] = m_trQuant.transformNxN(cu, resiYuv->getCrAddr(absPartIdxC), resiYuv->m_cwidth, coeffCurV + subTUOffset,
+                                                                     log2TrSizeC, TEXT_CHROMA_V, absPartIdxC, false, curuseRDOQ);
 
                 cu->setCbfPartRange(numSigU[tuIterator.section] ? setCbf : 0, TEXT_CHROMA_U, absPartIdxC, tuIterator.absPartIdxStep);
                 cu->setCbfPartRange(numSigV[tuIterator.section] ? setCbf : 0, TEXT_CHROMA_V, absPartIdxC, tuIterator.absPartIdxStep);
@@ -2787,6 +2785,7 @@
                 m_sbacCoder->codeQtCbf(cu, absPartIdxC, TEXT_CHROMA_V, trMode);
                 if (numSigV[tuIterator.section])
                     m_sbacCoder->codeCoeffNxN(cu, coeffCurV + subTUOffset, absPartIdxC, log2TrSizeC, TEXT_CHROMA_V);
+
                 uint32_t newBits = m_sbacCoder->getNumberOfWrittenBits();
                 singleBitsComp[TEXT_CHROMA_V][tuIterator.section] = newBits - (singleBitsPrev + singleBitsComp[TEXT_CHROMA_U][tuIterator.section]);
 
@@ -2808,11 +2807,11 @@
         int partSize = partitionFromSize(trSize);
         uint32_t distY = primitives.sse_sp[partSize](resiYuv->getLumaAddr(absPartIdx), resiYuv->m_width, (pixel*)RDCost::zeroPel, trSize);
         uint32_t psyEnergyY = 0;
-        if (m_rdCost->psyRdEnabled())
+        if (m_rdCost.psyRdEnabled())
         {
+            // need to check whether zero distortion is similar to psyenergy of fenc
             int size = g_convertToBit[trSize];
-            psyEnergyY = m_rdCost->psyCost(size, fencYuv->getLumaAddr(absPartIdx), fencYuv->getStride(),
-                (pixel*)RDCost::zeroPel, trSize); // need to check whether zero distortion is similar to psyenergy of fenc
+            psyEnergyY = m_rdCost.psyCost(size, fencYuv->getLumaAddr(absPartIdx), fencYuv->getStride(), (pixel*)RDCost::zeroPel, trSize);
         }
         int16_t *curResiY = m_qtTempShortYuv[qtLayer].getLumaAddr(absPartIdx);
         X265_CHECK(m_qtTempShortYuv[qtLayer].m_width == MAX_CU_SIZE, "width not full CU\n");
@@ -2824,12 +2823,12 @@
 
         if (numSigY)
         {
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
-            m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), curResiY, strideResiY, coeffCurY, log2TrSize, TEXT_LUMA, false, false, numSigY); //this is for inter mode only
+            m_trQuant.setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
+            m_trQuant.invtransformNxN(cu->getCUTransquantBypass(absPartIdx), curResiY, strideResiY, coeffCurY, log2TrSize, TEXT_LUMA, false, false, numSigY); //this is for inter mode only
 
             const uint32_t nonZeroDistY = primitives.sse_ss[partSize](resiYuv->getLumaAddr(absPartIdx), resiYuv->m_width, curResiY, strideResiY);
             uint32_t nonZeroPsyEnergyY = 0;
-            if (m_rdCost->psyRdEnabled())
+            if (m_rdCost.psyRdEnabled())
             {
                 pixel*   pred = predYuv->getLumaAddr(absPartIdx);
                 uint32_t zorder = cu->getZorderIdxInCU() + absPartIdx;
@@ -2839,7 +2838,7 @@
                 //===== reconstruction =====
                 primitives.luma_add_ps[partSize](reconIPred, reconIPredStride, pred, curResiY, stride, strideResiY);
                 int size = g_convertToBit[trSize];
-                nonZeroPsyEnergyY = m_rdCost->psyCost(size, fencYuv->getLumaAddr(absPartIdx), fencYuv->getStride(),
+                nonZeroPsyEnergyY = m_rdCost.psyCost(size, fencYuv->getLumaAddr(absPartIdx), fencYuv->getStride(),
                     cu->getPic()->getPicYuvRec()->getLumaAddr(cu->getAddr(), zorder), cu->getPic()->getPicYuvRec()->getStride());
             }
             if (cu->isLosslessCoded(0))
@@ -2850,18 +2849,18 @@
             else
             {
                 uint64_t singleCostY = 0;
-                if (m_rdCost->psyRdEnabled())
-                    singleCostY = m_rdCost->calcPsyRdCost(nonZeroDistY, singleBitsComp[TEXT_LUMA][0], nonZeroPsyEnergyY);
+                if (m_rdCost.psyRdEnabled())
+                    singleCostY = m_rdCost.calcPsyRdCost(nonZeroDistY, singleBitsComp[TEXT_LUMA][0], nonZeroPsyEnergyY);
                 else
-                    singleCostY = m_rdCost->calcRdCost(nonZeroDistY, singleBitsComp[TEXT_LUMA][0]);
+                    singleCostY = m_rdCost.calcRdCost(nonZeroDistY, singleBitsComp[TEXT_LUMA][0]);
                 m_sbacCoder->resetBits();
                 m_sbacCoder->codeQtCbfZero(cu, TEXT_LUMA, trMode);
                 const uint32_t nullBitsY = m_sbacCoder->getNumberOfWrittenBits();
                 uint64_t nullCostY = 0;
-                if (m_rdCost->psyRdEnabled())
-                    nullCostY = m_rdCost->calcPsyRdCost(distY, nullBitsY, psyEnergyY);
+                if (m_rdCost.psyRdEnabled())
+                    nullCostY = m_rdCost.calcPsyRdCost(distY, nullBitsY, psyEnergyY);
                 else
-                    nullCostY = m_rdCost->calcRdCost(distY, nullBitsY);
+                    nullCostY = m_rdCost.calcRdCost(distY, nullBitsY);
                 if (nullCostY < singleCostY)
                 {
                     numSigY = 0;
@@ -2885,10 +2884,10 @@
             m_sbacCoder->resetBits();
             m_sbacCoder->codeQtCbfZero(cu, TEXT_LUMA, trMode);
             const uint32_t nullBitsY = m_sbacCoder->getNumberOfWrittenBits();
-            if (m_rdCost->psyRdEnabled())
-                minCost[TEXT_LUMA][0] = m_rdCost->calcPsyRdCost(distY, nullBitsY, psyEnergyY);
+            if (m_rdCost.psyRdEnabled())
+                minCost[TEXT_LUMA][0] = m_rdCost.calcPsyRdCost(distY, nullBitsY, psyEnergyY);
             else
-                minCost[TEXT_LUMA][0] = m_rdCost->calcRdCost(distY, nullBitsY);
+                minCost[TEXT_LUMA][0] = m_rdCost.calcRdCost(distY, nullBitsY);
         }
 
         singleDistComp[TEXT_LUMA][0] = distY;
@@ -2915,7 +2914,7 @@
                 int16_t *curResiU = m_qtTempShortYuv[qtLayer].getCbAddr(absPartIdxC);
                 int16_t *curResiV = m_qtTempShortYuv[qtLayer].getCrAddr(absPartIdxC);
 
-                distU = m_rdCost->scaleChromaDistCb(primitives.sse_sp[partSizeC](resiYuv->getCbAddr(absPartIdxC), resiYuv->m_cwidth, (pixel*)RDCost::zeroPel, trSizeC));
+                distU = m_rdCost.scaleChromaDistCb(primitives.sse_sp[partSizeC](resiYuv->getCbAddr(absPartIdxC), resiYuv->m_cwidth, (pixel*)RDCost::zeroPel, trSizeC));
 
                 if (outZeroDist)
                 {
@@ -2924,15 +2923,15 @@
                 if (numSigU[tuIterator.section])
                 {
                     int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();
-                    m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
-                    m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), curResiU, strideResiC, coeffCurU + subTUOffset,
-                                               log2TrSizeC, TEXT_CHROMA_U, false, false, numSigU[tuIterator.section]);
+                    m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+                    m_trQuant.invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), curResiU, strideResiC, coeffCurU + subTUOffset,
+                                              log2TrSizeC, TEXT_CHROMA_U, false, false, numSigU[tuIterator.section]);
                     uint32_t dist = primitives.sse_ss[partSizeC](resiYuv->getCbAddr(absPartIdxC), resiYuv->m_cwidth,
                                                                  curResiU, strideResiC);
-                    const uint32_t nonZeroDistU = m_rdCost->scaleChromaDistCb(dist);
+                    const uint32_t nonZeroDistU = m_rdCost.scaleChromaDistCb(dist);
                     uint32_t nonZeroPsyEnergyU = 0;
 
-                    if (m_rdCost->psyRdEnabled())
+                    if (m_rdCost.psyRdEnabled())
                     {
                         pixel*   pred = predYuv->getCbAddr(absPartIdxC);
                         uint32_t zorder = cu->getZorderIdxInCU() + absPartIdxC;
@@ -2942,8 +2941,9 @@
                         //===== reconstruction =====
                         primitives.luma_add_ps[partSizeC](reconIPred, reconIPredStride, pred, curResiU, stride, strideResiC);
                         int size = g_convertToBit[trSizeC];
-                        nonZeroPsyEnergyU = m_rdCost->psyCost(size, fencYuv->getCbAddr(absPartIdxC), fencYuv->getCStride(),
-                            cu->getPic()->getPicYuvRec()->getCbAddr(cu->getAddr(), zorder), cu->getPic()->getPicYuvRec()->getCStride());
+                        nonZeroPsyEnergyU = m_rdCost.psyCost(size, fencYuv->getCbAddr(absPartIdxC), fencYuv->getCStride(),
+                                                             cu->getPic()->getPicYuvRec()->getCbAddr(cu->getAddr(), zorder),
+                                                             cu->getPic()->getPicYuvRec()->getCStride());
                     }
                     if (cu->isLosslessCoded(0))
                     {
@@ -2953,18 +2953,18 @@
                     else
                     {
                         uint64_t singleCostU = 0;
-                        if (m_rdCost->psyRdEnabled())
-                            singleCostU = m_rdCost->calcPsyRdCost(nonZeroDistU, singleBitsComp[TEXT_CHROMA_U][tuIterator.section], nonZeroPsyEnergyU);
+                        if (m_rdCost.psyRdEnabled())
+                            singleCostU = m_rdCost.calcPsyRdCost(nonZeroDistU, singleBitsComp[TEXT_CHROMA_U][tuIterator.section], nonZeroPsyEnergyU);
                         else
-                            singleCostU = m_rdCost->calcRdCost(nonZeroDistU, singleBitsComp[TEXT_CHROMA_U][tuIterator.section]);
+                            singleCostU = m_rdCost.calcRdCost(nonZeroDistU, singleBitsComp[TEXT_CHROMA_U][tuIterator.section]);
                         m_sbacCoder->resetBits();
                         m_sbacCoder->codeQtCbfZero(cu, TEXT_CHROMA_U, trMode);
                         const uint32_t nullBitsU = m_sbacCoder->getNumberOfWrittenBits();
                         uint64_t nullCostU = 0;
-                        if (m_rdCost->psyRdEnabled())
-                            nullCostU = m_rdCost->calcPsyRdCost(distU, nullBitsU, psyEnergyU);
+                        if (m_rdCost.psyRdEnabled())
+                            nullCostU = m_rdCost.calcPsyRdCost(distU, nullBitsU, psyEnergyU);
                         else
-                            nullCostU = m_rdCost->calcRdCost(distU, nullBitsU);
+                            nullCostU = m_rdCost.calcRdCost(distU, nullBitsU);
                         if (nullCostU < singleCostU)
                         {
                             numSigU[tuIterator.section] = 0;
@@ -2988,10 +2988,10 @@
                     m_sbacCoder->resetBits();
                     m_sbacCoder->codeQtCbfZero(cu, TEXT_CHROMA_U, trModeC);
                     const uint32_t nullBitsU = m_sbacCoder->getNumberOfWrittenBits();
-                    if (m_rdCost->psyRdEnabled())
-                        minCost[TEXT_CHROMA_U][tuIterator.section] = m_rdCost->calcPsyRdCost(distU, nullBitsU, psyEnergyU);
+                    if (m_rdCost.psyRdEnabled())
+                        minCost[TEXT_CHROMA_U][tuIterator.section] = m_rdCost.calcPsyRdCost(distU, nullBitsU, psyEnergyU);
                     else
-                        minCost[TEXT_CHROMA_U][tuIterator.section] = m_rdCost->calcRdCost(distU, nullBitsU);
+                        minCost[TEXT_CHROMA_U][tuIterator.section] = m_rdCost.calcRdCost(distU, nullBitsU);
                 }
 
                 singleDistComp[TEXT_CHROMA_U][tuIterator.section] = distU;
@@ -3000,22 +3000,22 @@
                 if (!numSigU[tuIterator.section])
                     primitives.blockfill_s[sizeIdxC](curResiU, strideResiC, 0);
 
-                distV = m_rdCost->scaleChromaDistCr(primitives.sse_sp[partSizeC](resiYuv->getCrAddr(absPartIdxC), resiYuv->m_cwidth, (pixel*)RDCost::zeroPel, trSizeC));
+                distV = m_rdCost.scaleChromaDistCr(primitives.sse_sp[partSizeC](resiYuv->getCrAddr(absPartIdxC), resiYuv->m_cwidth, (pixel*)RDCost::zeroPel, trSizeC));
                 if (outZeroDist)
                     *outZeroDist += distV;
 
                 if (numSigV[tuIterator.section])
                 {
                     int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
-                    m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
-                    m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), curResiV, strideResiC, coeffCurV + subTUOffset,
-                                               log2TrSizeC, TEXT_CHROMA_V, false, false, numSigV[tuIterator.section]);
+                    m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+                    m_trQuant.invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), curResiV, strideResiC, coeffCurV + subTUOffset,
+                                              log2TrSizeC, TEXT_CHROMA_V, false, false, numSigV[tuIterator.section]);
                     uint32_t dist = primitives.sse_ss[partSizeC](resiYuv->getCrAddr(absPartIdxC), resiYuv->m_cwidth,
                                                                  curResiV, strideResiC);
-                    const uint32_t nonZeroDistV = m_rdCost->scaleChromaDistCr(dist);
+                    const uint32_t nonZeroDistV = m_rdCost.scaleChromaDistCr(dist);
                     uint32_t nonZeroPsyEnergyV = 0;
 
-                    if (m_rdCost->psyRdEnabled())
+                    if (m_rdCost.psyRdEnabled())
                     {
                         pixel*   pred = predYuv->getCrAddr(absPartIdxC);
                         uint32_t zorder = cu->getZorderIdxInCU() + absPartIdxC;
@@ -3025,8 +3025,9 @@
                         //===== reconstruction =====
                         primitives.luma_add_ps[partSizeC](reconIPred, reconIPredStride, pred, curResiV, stride, strideResiC);
                         int size = g_convertToBit[trSizeC];
-                        nonZeroPsyEnergyV = m_rdCost->psyCost(size, fencYuv->getCrAddr(absPartIdxC), fencYuv->getCStride(),
-                            cu->getPic()->getPicYuvRec()->getCrAddr(cu->getAddr(), zorder), cu->getPic()->getPicYuvRec()->getCStride());
+                        nonZeroPsyEnergyV = m_rdCost.psyCost(size, fencYuv->getCrAddr(absPartIdxC), fencYuv->getCStride(),
+                                                             cu->getPic()->getPicYuvRec()->getCrAddr(cu->getAddr(), zorder),
+                                                             cu->getPic()->getPicYuvRec()->getCStride());
                     }
                     if (cu->isLosslessCoded(0))
                     {
@@ -3036,18 +3037,18 @@
                     else
                     {
                         uint64_t singleCostV = 0;
-                        if (m_rdCost->psyRdEnabled())
-                            singleCostV = m_rdCost->calcPsyRdCost(nonZeroDistV, singleBitsComp[TEXT_CHROMA_V][tuIterator.section], nonZeroPsyEnergyV);
+                        if (m_rdCost.psyRdEnabled())
+                            singleCostV = m_rdCost.calcPsyRdCost(nonZeroDistV, singleBitsComp[TEXT_CHROMA_V][tuIterator.section], nonZeroPsyEnergyV);
                         else
-                            singleCostV = m_rdCost->calcRdCost(nonZeroDistV, singleBitsComp[TEXT_CHROMA_V][tuIterator.section]);
+                            singleCostV = m_rdCost.calcRdCost(nonZeroDistV, singleBitsComp[TEXT_CHROMA_V][tuIterator.section]);
                         m_sbacCoder->resetBits();
                         m_sbacCoder->codeQtCbfZero(cu, TEXT_CHROMA_V, trMode);
                         const uint32_t nullBitsV = m_sbacCoder->getNumberOfWrittenBits();
                         uint64_t nullCostV = 0;
-                        if (m_rdCost->psyRdEnabled())
-                            nullCostV = m_rdCost->calcPsyRdCost(distV, nullBitsV, psyEnergyV);
+                        if (m_rdCost.psyRdEnabled())
+                            nullCostV = m_rdCost.calcPsyRdCost(distV, nullBitsV, psyEnergyV);
                         else
-                            nullCostV = m_rdCost->calcRdCost(distV, nullBitsV);
+                            nullCostV = m_rdCost.calcRdCost(distV, nullBitsV);
                         if (nullCostV < singleCostV)
                         {
                             numSigV[tuIterator.section] = 0;
@@ -3071,10 +3072,10 @@
                     m_sbacCoder->resetBits();
                     m_sbacCoder->codeQtCbfZero(cu, TEXT_CHROMA_V, trModeC);
                     const uint32_t nullBitsV = m_sbacCoder->getNumberOfWrittenBits();
-                    if (m_rdCost->psyRdEnabled())
-                        minCost[TEXT_CHROMA_V][tuIterator.section] = m_rdCost->calcPsyRdCost(distV, nullBitsV, psyEnergyV);
+                    if (m_rdCost.psyRdEnabled())
+                        minCost[TEXT_CHROMA_V][tuIterator.section] = m_rdCost.calcPsyRdCost(distV, nullBitsV, psyEnergyV);
                     else
-                        minCost[TEXT_CHROMA_V][tuIterator.section] = m_rdCost->calcRdCost(distV, nullBitsV);
+                        minCost[TEXT_CHROMA_V][tuIterator.section] = m_rdCost.calcRdCost(distV, nullBitsV);
                 }
 
                 singleDistComp[TEXT_CHROMA_V][tuIterator.section] = distV;
@@ -3103,11 +3104,11 @@
             cu->setTransformSkipSubParts(1, TEXT_LUMA, absPartIdx, depth);
 
             if (m_bEnableRDOQ)
-                m_sbacCoder->estBit(m_trQuant->m_estBitsSbac, trSize, TEXT_LUMA);
-
-            m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
-            uint32_t numSigTSkipY = m_trQuant->transformNxN(cu, resiYuv->getLumaAddr(absPartIdx), resiYuv->m_width, tsCoeffY,
-                                                            log2TrSize, TEXT_LUMA, absPartIdx, true, curuseRDOQ);
+                m_sbacCoder->estBit(m_trQuant.m_estBitsSbac, trSize, TEXT_LUMA);
+
+            m_trQuant.setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
+            uint32_t numSigTSkipY = m_trQuant.transformNxN(cu, resiYuv->getLumaAddr(absPartIdx), resiYuv->m_width, tsCoeffY,
+                                                           log2TrSize, TEXT_LUMA, absPartIdx, true, curuseRDOQ);
             cu->setCbfSubParts(numSigTSkipY ? setCbf : 0, TEXT_LUMA, absPartIdx, depth);
 
             if (numSigTSkipY)
@@ -3117,13 +3118,12 @@
                 m_sbacCoder->codeCoeffNxN(cu, tsCoeffY, absPartIdx, log2TrSize, TEXT_LUMA);
                 const uint32_t skipSingleBitsY = m_sbacCoder->getNumberOfWrittenBits();
 
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
-                m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdx), tsResiY, trSize, tsCoeffY, log2TrSize, TEXT_LUMA, false, true, numSigTSkipY);
-
-                nonZeroDistY = primitives.sse_ss[partSize](resiYuv->getLumaAddr(absPartIdx), resiYuv->m_width,
-                                                           tsResiY, trSize);
-
-                if (m_rdCost->psyRdEnabled())
+                m_trQuant.setQPforQuant(cu->getQP(0), TEXT_LUMA, QP_BD_OFFSET, 0, chFmt);
+                m_trQuant.invtransformNxN(cu->getCUTransquantBypass(absPartIdx), tsResiY, trSize, tsCoeffY, log2TrSize, TEXT_LUMA, false, true, numSigTSkipY);
+
+                nonZeroDistY = primitives.sse_ss[partSize](resiYuv->getLumaAddr(absPartIdx), resiYuv->m_width, tsResiY, trSize);
+
+                if (m_rdCost.psyRdEnabled())
                 {
                     pixel*   pred = predYuv->getLumaAddr(absPartIdx);
                     uint32_t zorder = cu->getZorderIdxInCU() + absPartIdx;
@@ -3133,12 +3133,13 @@
                     //===== reconstruction =====
                     primitives.luma_add_ps[partSize](reconIPred, reconIPredStride, pred, tsResiY, stride, trSize);
                     int size = g_convertToBit[trSize];
-                    nonZeroPsyEnergyY = m_rdCost->psyCost(size, fencYuv->getLumaAddr(absPartIdx), fencYuv->getStride(),
-                        cu->getPic()->getPicYuvRec()->getLumaAddr(cu->getAddr(), zorder), cu->getPic()->getPicYuvRec()->getStride());
-                    singleCostY = m_rdCost->calcPsyRdCost(nonZeroDistY, skipSingleBitsY, nonZeroPsyEnergyY);
+                    nonZeroPsyEnergyY = m_rdCost.psyCost(size, fencYuv->getLumaAddr(absPartIdx), fencYuv->getStride(),
+                                                         cu->getPic()->getPicYuvRec()->getLumaAddr(cu->getAddr(), zorder),
+                                                         cu->getPic()->getPicYuvRec()->getStride());
+                    singleCostY = m_rdCost.calcPsyRdCost(nonZeroDistY, skipSingleBitsY, nonZeroPsyEnergyY);
                 }
                 else
-                    singleCostY = m_rdCost->calcRdCost(nonZeroDistY, skipSingleBitsY);
+                    singleCostY = m_rdCost.calcRdCost(nonZeroDistY, skipSingleBitsY);
             }
 
             if (!numSigTSkipY || minCost[TEXT_LUMA][0] < singleCostY)
@@ -3186,16 +3187,16 @@
                 cu->setTransformSkipPartRange(1, TEXT_CHROMA_V, absPartIdxC, tuIterator.absPartIdxStep);
 
                 if (m_bEnableRDOQ)
-                    m_sbacCoder->estBit(m_trQuant->m_estBitsSbac, trSizeC, TEXT_CHROMA);
+                    m_sbacCoder->estBit(m_trQuant.m_estBitsSbac, trSizeC, TEXT_CHROMA);
 
                 int curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
-                uint32_t numSigTSkipU = m_trQuant->transformNxN(cu, resiYuv->getCbAddr(absPartIdxC), resiYuv->m_cwidth, tsCoeffU,
-                                                                log2TrSizeC, TEXT_CHROMA_U, absPartIdxC, true, curuseRDOQ);
+                m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+                uint32_t numSigTSkipU = m_trQuant.transformNxN(cu, resiYuv->getCbAddr(absPartIdxC), resiYuv->m_cwidth, tsCoeffU,
+                                                               log2TrSizeC, TEXT_CHROMA_U, absPartIdxC, true, curuseRDOQ);
                 curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
-                m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
-                uint32_t numSigTSkipV = m_trQuant->transformNxN(cu, resiYuv->getCrAddr(absPartIdxC), resiYuv->m_cwidth, tsCoeffV,
-                                                                log2TrSizeC, TEXT_CHROMA_V, absPartIdxC, true, curuseRDOQ);
+                m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+                uint32_t numSigTSkipV = m_trQuant.transformNxN(cu, resiYuv->getCrAddr(absPartIdxC), resiYuv->m_cwidth, tsCoeffV,
+                                                               log2TrSizeC, TEXT_CHROMA_V, absPartIdxC, true, curuseRDOQ);
 
                 cu->setCbfPartRange(numSigTSkipU ? setCbf : 0, TEXT_CHROMA_U, absPartIdxC, tuIterator.absPartIdxStep);
                 cu->setCbfPartRange(numSigTSkipV ? setCbf : 0, TEXT_CHROMA_V, absPartIdxC, tuIterator.absPartIdxStep);
@@ -3210,13 +3211,13 @@
                     singleBitsComp[TEXT_CHROMA_U][tuIterator.section] = m_sbacCoder->getNumberOfWrittenBits();
 
                     curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCbQpOffset() + cu->getSlice()->getSliceQpDeltaCb();
-                    m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
-                    m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), tsResiU, trSizeC, tsCoeffU,
-                                               log2TrSizeC, TEXT_CHROMA_U, false, true, numSigTSkipU);
+                    m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+                    m_trQuant.invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), tsResiU, trSizeC, tsCoeffU,
+                                              log2TrSizeC, TEXT_CHROMA_U, false, true, numSigTSkipU);
                     uint32_t dist = primitives.sse_ss[partSizeC](resiYuv->getCbAddr(absPartIdxC), resiYuv->m_cwidth,
                                                                  tsResiU, trSizeC);
-                    nonZeroDistU = m_rdCost->scaleChromaDistCb(dist);
-                    if (m_rdCost->psyRdEnabled())
+                    nonZeroDistU = m_rdCost.scaleChromaDistCb(dist);
+                    if (m_rdCost.psyRdEnabled())
                     {
                         pixel*   pred = predYuv->getCbAddr(absPartIdxC);
                         uint32_t zorder = cu->getZorderIdxInCU() + absPartIdxC;
@@ -3226,12 +3227,12 @@
                         //===== reconstruction =====
                         primitives.luma_add_ps[partSizeC](reconIPred, reconIPredStride, pred, tsResiU, stride, trSizeC);
                         int size = g_convertToBit[trSizeC];
-                        nonZeroPsyEnergyU = m_rdCost->psyCost(size, fencYuv->getCbAddr(absPartIdxC), fencYuv->getCStride(),
+                        nonZeroPsyEnergyU = m_rdCost.psyCost(size, fencYuv->getCbAddr(absPartIdxC), fencYuv->getCStride(),
                             cu->getPic()->getPicYuvRec()->getCbAddr(cu->getAddr(), zorder), cu->getPic()->getPicYuvRec()->getCStride());
-                        singleCostU = m_rdCost->calcPsyRdCost(nonZeroDistU, singleBitsComp[TEXT_CHROMA_U][tuIterator.section], nonZeroPsyEnergyU);
+                        singleCostU = m_rdCost.calcPsyRdCost(nonZeroDistU, singleBitsComp[TEXT_CHROMA_U][tuIterator.section], nonZeroPsyEnergyU);
                     }
                     else
-                        singleCostU = m_rdCost->calcRdCost(nonZeroDistU, singleBitsComp[TEXT_CHROMA_U][tuIterator.section]);
+                        singleCostU = m_rdCost.calcRdCost(nonZeroDistU, singleBitsComp[TEXT_CHROMA_U][tuIterator.section]);
                 }
 
                 if (!numSigTSkipU || minCost[TEXT_CHROMA_U][tuIterator.section] < singleCostU)
@@ -3253,13 +3254,13 @@
                     singleBitsComp[TEXT_CHROMA_V][tuIterator.section] = m_sbacCoder->getNumberOfWrittenBits() - singleBitsComp[TEXT_CHROMA_U][tuIterator.section];
 
                     curChromaQpOffset = cu->getSlice()->getPPS()->getChromaCrQpOffset() + cu->getSlice()->getSliceQpDeltaCr();
-                    m_trQuant->setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
-                    m_trQuant->invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), tsResiV, trSizeC, tsCoeffV,
-                                               log2TrSizeC, TEXT_CHROMA_V, false, true, numSigTSkipV);
+                    m_trQuant.setQPforQuant(cu->getQP(0), TEXT_CHROMA, cu->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset, chFmt);
+                    m_trQuant.invtransformNxN(cu->getCUTransquantBypass(absPartIdxC), tsResiV, trSizeC, tsCoeffV,
+                                              log2TrSizeC, TEXT_CHROMA_V, false, true, numSigTSkipV);
                     uint32_t dist = primitives.sse_ss[partSizeC](resiYuv->getCrAddr(absPartIdxC), resiYuv->m_cwidth,
                                                                  tsResiV, trSizeC);
-                    nonZeroDistV = m_rdCost->scaleChromaDistCr(dist);
-                    if (m_rdCost->psyRdEnabled())
+                    nonZeroDistV = m_rdCost.scaleChromaDistCr(dist);
+                    if (m_rdCost.psyRdEnabled())
                     {
                         pixel*   pred = predYuv->getCrAddr(absPartIdxC);
                         uint32_t zorder = cu->getZorderIdxInCU() + absPartIdxC;
@@ -3269,12 +3270,12 @@
                         //===== reconstruction =====
                         primitives.luma_add_ps[partSizeC](reconIPred, reconIPredStride, pred, tsResiV, stride, trSizeC);
                         int size = g_convertToBit[trSizeC];
-                        nonZeroPsyEnergyV = m_rdCost->psyCost(size, fencYuv->getCrAddr(absPartIdxC), fencYuv->getCStride(),
+                        nonZeroPsyEnergyV = m_rdCost.psyCost(size, fencYuv->getCrAddr(absPartIdxC), fencYuv->getCStride(),
                             cu->getPic()->getPicYuvRec()->getCrAddr(cu->getAddr(), zorder), cu->getPic()->getPicYuvRec()->getCStride());
-                        singleCostV = m_rdCost->calcPsyRdCost(nonZeroDistV, singleBitsComp[TEXT_CHROMA_V][tuIterator.section], nonZeroPsyEnergyV);
+                        singleCostV = m_rdCost.calcPsyRdCost(nonZeroDistV, singleBitsComp[TEXT_CHROMA_V][tuIterator.section], nonZeroPsyEnergyV);
                     }
                     else
-                        singleCostV = m_rdCost->calcRdCost(nonZeroDistV, singleBitsComp[TEXT_CHROMA_V][tuIterator.section]);
+                        singleCostV = m_rdCost.calcRdCost(nonZeroDistV, singleBitsComp[TEXT_CHROMA_V][tuIterator.section]);
                 }
 
                 if (!numSigTSkipV || minCost[TEXT_CHROMA_V][tuIterator.section] < singleCostV)
@@ -3353,10 +3354,10 @@
         }
 
         singleBits = m_sbacCoder->getNumberOfWrittenBits();
-        if (m_rdCost->psyRdEnabled())
-            singleCost = m_rdCost->calcPsyRdCost(singleDist, singleBits, singlePsyEnergy);
+        if (m_rdCost.psyRdEnabled())
+            singleCost = m_rdCost.calcPsyRdCost(singleDist, singleBits, singlePsyEnergy);
         else
-            singleCost = m_rdCost->calcRdCost(singleDist, singleBits);
+            singleCost = m_rdCost.calcRdCost(singleDist, singleBits);
 
         bestCBF[TEXT_LUMA] = cu->getCbf(absPartIdx, TEXT_LUMA, trMode);
         if (bCodeChroma)
@@ -3436,10 +3437,10 @@
 
         subdivBits = m_sbacCoder->getNumberOfWrittenBits();
 
-        if (m_rdCost->psyRdEnabled())
-            subDivCost = m_rdCost->calcPsyRdCost(subdivDist, subdivBits, subDivPsyEnergy);
+        if (m_rdCost.psyRdEnabled())
+            subDivCost = m_rdCost.calcPsyRdCost(subdivDist, subdivBits, subDivPsyEnergy);
         else
-            subDivCost = m_rdCost->calcRdCost(subdivDist, subdivBits);
+            subDivCost = m_rdCost.calcRdCost(subdivDist, subdivBits);
 
         if (ycbf || ucbf || vcbf || !bCheckFull)
         {
diff -r 3685d607012f -r f5fe4e345362 source/Lib/TLibEncoder/TEncSearch.h
--- a/source/Lib/TLibEncoder/TEncSearch.h	Thu Jul 10 22:32:24 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncSearch.h	Thu Jul 10 23:15:24 2014 -0500
@@ -48,6 +48,7 @@
 #include "motion.h"
 
 #include "entropy.h"
+#include "rdcost.h"
 
 #define MVP_IDX_BITS 1
 
@@ -115,11 +116,11 @@
     uint8_t*        m_qtTempTransformSkipFlag[3];
 
     // interface to classes
-    TComTrQuant*    m_trQuant;
-    RDCost*         m_rdCost;
+    TComTrQuant     m_trQuant;
+    RDCost          m_rdCost;
+
     SBac*           m_sbacCoder;
     x265_param*     m_param;
-
     SBac          (*m_rdSbacCoders)[CI_NUM];
 
     bool            m_bEnableRDOQ;
diff -r 3685d607012f -r f5fe4e345362 source/common/common.h
--- a/source/common/common.h	Thu Jul 10 22:32:24 2014 -0500
+++ b/source/common/common.h	Thu Jul 10 23:15:24 2014 -0500
@@ -192,6 +192,12 @@
     uint32_t countBuf[4][8];
 };
 
+enum SCALING_LIST_PARAMETER
+{
+    SCALING_LIST_OFF,
+    SCALING_LIST_DEFAULT,
+};
+
 /* defined in common.cpp */
 int64_t x265_mdate(void);
 void x265_log(const x265_param *param, int level, const char *fmt, ...);
diff -r 3685d607012f -r f5fe4e345362 source/encoder/compress.cpp
--- a/source/encoder/compress.cpp	Thu Jul 10 22:32:24 2014 -0500
+++ b/source/encoder/compress.cpp	Thu Jul 10 23:15:24 2014 -0500
@@ -56,9 +56,8 @@
     estIntraPredChromaQT(cu, fencYuv, predYuv, outResiYuv, outReconYuv);
     m_sbacCoder->resetBits();
     if (cu->getSlice()->getPPS()->getTransquantBypassEnableFlag())
-    {
         m_sbacCoder->codeCUTransquantBypassFlag(cu, 0);
-    }
+
     if (!cu->getSlice()->isIntra())
     {
         m_sbacCoder->codeSkipFlag(cu, 0);
@@ -75,17 +74,15 @@
 
     cu->m_totalBits = m_sbacCoder->getNumberOfWrittenBits();
     cu->m_coeffBits = cu->m_totalBits - cu->m_mvBits;
-    if (m_rdCost->psyRdEnabled())
+    if (m_rdCost.psyRdEnabled())
     {
         int part = g_convertToBit[cu->getCUSize(0)];
-        cu->m_psyEnergy = m_rdCost->psyCost(part, m_origYuv[depth]->getLumaAddr(), m_origYuv[depth]->getStride(),
+        cu->m_psyEnergy = m_rdCost.psyCost(part, m_origYuv[depth]->getLumaAddr(), m_origYuv[depth]->getStride(),
             m_tmpRecoYuv[depth]->getLumaAddr(), m_tmpRecoYuv[depth]->getStride());
-        cu->m_totalPsyCost = m_rdCost->calcPsyRdCost(cu->m_totalDistortion, cu->m_totalBits, cu->m_psyEnergy);
+        cu->m_totalPsyCost = m_rdCost.calcPsyRdCost(cu->m_totalDistortion, cu->m_totalBits, cu->m_psyEnergy);
     }
     else
-    {
-        cu->m_totalRDCost = m_rdCost->calcRdCost(cu->m_totalDistortion, cu->m_totalBits);
-    }
+        cu->m_totalRDCost = m_rdCost.calcRdCost(cu->m_totalDistortion, cu->m_totalBits);
 }
 
 void TEncCu::xComputeCostIntraInInter(TComDataCU* cu, PartSize partSize)
@@ -163,10 +160,10 @@
     bsad = costMultiplier * sa8d(fenc, scaleStride, tmp, scaleStride);
     bmode = mode = DC_IDX;
     bbits = !(mpms & ((uint64_t)1 << mode)) ? rbits : xModeBitsIntra(cu, mode, partOffset, depth);
-    bcost = m_rdCost->calcRdSADCost(bsad, bbits);
+    bcost = m_rdCost.calcRdSADCost(bsad, bbits);
 
-    pixel *abovePlanar   = above;
-    pixel *leftPlanar    = left;
+    pixel *abovePlanar = above;
+    pixel *leftPlanar  = left;
 
     if (tuSize >= 8 && tuSize <= 32)
     {
@@ -179,7 +176,7 @@
     sad = costMultiplier * sa8d(fenc, scaleStride, tmp, scaleStride);
     mode = PLANAR_IDX;
     bits = !(mpms & ((uint64_t)1 << mode)) ? rbits : xModeBitsIntra(cu, mode, partOffset, depth);
-    cost = m_rdCost->calcRdSADCost(sad, bits);
+    cost = m_rdCost.calcRdSADCost(sad, bits);
     COPY4_IF_LT(bcost, cost, bmode, mode, bsad, sad, bbits, bits);
 
     // Transpose NxN
@@ -194,7 +191,7 @@
         intptr_t srcStride = (modeHor ? scaleTuSize : scaleStride);
         sad  = costMultiplier * sa8d(cmp, srcStride, &tmp[(mode - 2) * (scaleTuSize * scaleTuSize)], scaleTuSize);
         bits = !(mpms & ((uint64_t)1 << mode)) ? rbits : xModeBitsIntra(cu, mode, partOffset, depth);
-        cost = m_rdCost->calcRdSADCost(sad, bits);
+        cost = m_rdCost.calcRdSADCost(sad, bits);
         COPY4_IF_LT(bcost, cost, bmode, mode, bsad, sad, bbits, bits);
     }
 
@@ -223,7 +220,7 @@
         uint32_t distortion = primitives.sa8d[sizeIdx](m_origYuv[depth]->getLumaAddr(), m_origYuv[depth]->getStride(),
                                                        outPredYuv->getLumaAddr(), outPredYuv->getStride());
         outTempCU->m_totalDistortion = distortion;
-        outTempCU->m_totalRDCost = m_rdCost->calcRdSADCost(distortion, outTempCU->m_totalBits);
+        outTempCU->m_totalRDCost = m_rdCost.calcRdSADCost(distortion, outTempCU->m_totalBits);
     }
     else
     {
@@ -272,7 +269,7 @@
             outTempCU->m_totalBits = bitsCand;
             outTempCU->m_totalDistortion = primitives.sa8d[sizeIdx](m_origYuv[depth]->getLumaAddr(), m_origYuv[depth]->getStride(),
                                                                     m_tmpPredYuv[depth]->getLumaAddr(), m_tmpPredYuv[depth]->getStride());
-            outTempCU->m_totalRDCost = m_rdCost->calcRdSADCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
+            outTempCU->m_totalRDCost = m_rdCost.calcRdSADCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
 
             if (outTempCU->m_totalRDCost < outBestCU->m_totalRDCost)
             {
@@ -298,12 +295,12 @@
         outTempCU->m_totalBits = outBestCU->m_totalBits;
         outTempCU->m_totalDistortion = outBestCU->m_totalDistortion;
         outTempCU->m_totalBits = 0;
-        outTempCU->m_totalRDCost = m_rdCost->calcRdSADCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
+        outTempCU->m_totalRDCost = m_rdCost.calcRdSADCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
         outTempCU->m_sa8dCost = outTempCU->m_totalRDCost;
         outBestCU->m_sa8dCost = outTempCU->m_sa8dCost;
         if (m_param->rdLevel >= 1)
         {
-            //calculate the motion compensation for chroma for the best mode selected
+            // calculate the motion compensation for chroma for the best mode selected
             int numPart = outBestCU->getNumPartInter();
             for (int partIdx = 0; partIdx < numPart; partIdx++)
                 motionCompensation(outBestCU, bestPredYuv, REF_PIC_LIST_X, partIdx, false, true);
@@ -312,18 +309,18 @@
                 outBestCU->m_totalRDCost = MAX_INT64;
             else
             {
-                //No-residue mode
+                // No-residue mode
                 encodeResAndCalcRdInterCU(outBestCU, m_origYuv[depth], bestPredYuv, m_tmpResiYuv[depth], m_bestResiYuv[depth], m_tmpRecoYuv[depth], true, true);
 
                 std::swap(yuvReconBest, m_tmpRecoYuv[depth]);
             }
 
-            //Encode with residue
+            // Encode with residue
             encodeResAndCalcRdInterCU(outTempCU, m_origYuv[depth], bestPredYuv, m_tmpResiYuv[depth], m_bestResiYuv[depth], m_tmpRecoYuv[depth], false, true);
 
-            uint64_t tempCost = m_rdCost->psyRdEnabled() ? outTempCU->m_totalPsyCost : outTempCU->m_totalRDCost;
-            uint64_t bestCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
-            if (tempCost < bestCost) //Choose best from no-residue mode and residue mode
+            uint64_t tempCost = m_rdCost.psyRdEnabled() ? outTempCU->m_totalPsyCost : outTempCU->m_totalRDCost;
+            uint64_t bestCost = m_rdCost.psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
+            if (tempCost < bestCost) // Choose best from no-residue mode and residue mode
             {
                 std::swap(outBestCU, outTempCU);
                 std::swap(yuvReconBest, m_tmpRecoYuv[depth]);
@@ -338,15 +335,11 @@
     uint32_t absPartIdx = outTempCU->getZorderIdxInCU();
 
     if (depth == 0)
-    {
         // get original YUV data from picture
         m_origYuv[depth]->copyFromPicYuv(pic->getPicYuvOrg(), outTempCU->getAddr(), absPartIdx);
-    }
     else
-    {
         // copy partition YUV from depth 0 CTU cache
         m_origYuv[0]->copyPartToYuv(m_origYuv[depth], absPartIdx);
-    }
 
     // variables for fast encoder decision
     bool bSubBranch = true;
@@ -471,8 +464,8 @@
 
                     encodeResAndCalcRdInterCU(outBestCU, m_origYuv[depth], m_bestPredYuv[depth], m_tmpResiYuv[depth],
                                               m_bestResiYuv[depth], m_bestRecoYuv[depth], false, true);
-                    uint64_t bestMergeCost = m_rdCost->psyRdEnabled() ? m_bestMergeCU[depth]->m_totalPsyCost : m_bestMergeCU[depth]->m_totalRDCost;
-                    uint64_t bestCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
+                    uint64_t bestMergeCost = m_rdCost.psyRdEnabled() ? m_bestMergeCU[depth]->m_totalPsyCost : m_bestMergeCU[depth]->m_totalRDCost;
+                    uint64_t bestCost = m_rdCost.psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
                     if (bestMergeCost < bestCost)
                     {
                         outBestCU = m_bestMergeCU[depth];
@@ -500,8 +493,8 @@
                         {
                             xEncodeIntraInInter(m_intraInInterCU[depth], m_origYuv[depth], m_modePredYuv[5][depth],
                                                 m_tmpResiYuv[depth],  m_tmpRecoYuv[depth]);
-                            intraInInterCost = m_rdCost->psyRdEnabled() ? m_intraInInterCU[depth]->m_totalPsyCost : m_intraInInterCU[depth]->m_totalRDCost;
-                            bestCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
+                            intraInInterCost = m_rdCost.psyRdEnabled() ? m_intraInInterCU[depth]->m_totalPsyCost : m_intraInInterCU[depth]->m_totalRDCost;
+                            bestCost = m_rdCost.psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
                         }
                         else
                         {
@@ -587,22 +580,15 @@
                 m_sbacCoder->resetBits();
                 m_sbacCoder->codeSplitFlag(outBestCU, 0, depth);
                 outBestCU->m_totalBits += m_sbacCoder->getNumberOfWrittenBits(); // split bits
-                if (m_rdCost->psyRdEnabled())
-                {
-                    outBestCU->m_totalPsyCost = m_rdCost->calcPsyRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits,
-                        outBestCU->m_psyEnergy);
-                }
+                if (m_rdCost.psyRdEnabled())
+                    outBestCU->m_totalPsyCost = m_rdCost.calcPsyRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits, outBestCU->m_psyEnergy);
                 else
-                {
-                    outBestCU->m_totalRDCost = m_rdCost->calcRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits);
-                }
+                    outBestCU->m_totalRDCost = m_rdCost.calcRdCost(outBestCU->m_totalDistortion, outBestCU->m_totalBits);
             }
 
             // copy original YUV samples in lossless mode
             if (outBestCU->isLosslessCoded(0))
-            {
                 xFillOrigYUVBuffer(outBestCU, m_origYuv[depth]);
-            }
         }
     }
 
@@ -654,7 +640,7 @@
                 avgCost = ((3 * totalCostCU) + (2 * totalCostNeigh)) / ((3 * totalCountCU) + (2 * totalCountNeigh));
             uint64_t bestavgCost = 0;
             if (m_param->rdLevel > 1)
-                bestavgCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
+                bestavgCost = m_rdCost.psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
             else
                 bestavgCost = outBestCU->m_totalRDCost;
 
@@ -684,20 +670,17 @@
                  (subTempPartCU->getCUPelY() < slice->getSPS()->getPicHeightInLumaSamples())))
             {
                 if (0 == nextDepth_partIndex) // initialize RD with previous depth buffer
-                {
                     m_rdSbacCoders[nextDepth][CI_CURR_BEST].load(m_rdSbacCoders[depth][CI_CURR_BEST]);
-                }
                 else
-                {
                     m_rdSbacCoders[nextDepth][CI_CURR_BEST].load(m_rdSbacCoders[nextDepth][CI_NEXT_BEST]);
-                }
+
                 xCompressInterCU(subBestPartCU, subTempPartCU, outTempCU, nextDepth, bInsidePicture, nextDepth_partIndex, minDepth);
 #if EARLY_EXIT
                 if (subBestPartCU->getPredictionMode(0) != MODE_INTRA)
                 {
                     uint64_t tempavgCost = 0;
                     if (m_param->rdLevel > 1)
-                        tempavgCost = m_rdCost->psyRdEnabled() ? subBestPartCU->m_totalPsyCost : subBestPartCU->m_totalRDCost;
+                        tempavgCost = m_rdCost.psyRdEnabled() ? subBestPartCU->m_totalPsyCost : subBestPartCU->m_totalRDCost;
                     else
                         tempavgCost = subBestPartCU->m_totalRDCost;
                     TComDataCU* rootCU = pic->getPicSym()->getCU(outTempCU->getAddr());
@@ -731,18 +714,13 @@
         }
         if (m_param->rdLevel > 1)
         {
-            if (m_rdCost->psyRdEnabled())
-            {
-                outTempCU->m_totalPsyCost = m_rdCost->calcPsyRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits,
-                    outTempCU->m_psyEnergy);
-            }
+            if (m_rdCost.psyRdEnabled())
+                outTempCU->m_totalPsyCost = m_rdCost.calcPsyRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits, outTempCU->m_psyEnergy);
             else
-            {
-                outTempCU->m_totalRDCost = m_rdCost->calcRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
-            }
+                outTempCU->m_totalRDCost = m_rdCost.calcRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
         }
         else
-            outTempCU->m_totalRDCost = m_rdCost->calcRdSADCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
+            outTempCU->m_totalRDCost = m_rdCost.calcRdSADCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
 
         if ((g_maxCUSize >> depth) == slice->getPPS()->getMinCuDQPSize() && slice->getPPS()->getUseDQP())
         {
@@ -779,15 +757,15 @@
 #if EARLY_EXIT
             if (depth == 0)
             {
-                uint64_t tempavgCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
+                uint64_t tempavgCost = m_rdCost.psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
                 TComDataCU* rootCU = pic->getPicSym()->getCU(outTempCU->getAddr());
                 uint64_t temp = rootCU->m_avgCost[depth] * rootCU->m_count[depth];
                 rootCU->m_count[depth] += 1;
                 rootCU->m_avgCost[depth] = (temp + tempavgCost) / rootCU->m_count[depth];
             }
 #endif
-            uint64_t tempCost = m_rdCost->psyRdEnabled() ? outTempCU->m_totalPsyCost : outTempCU->m_totalRDCost;
-            uint64_t bestCost = m_rdCost->psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost; 
+            uint64_t tempCost = m_rdCost.psyRdEnabled() ? outTempCU->m_totalPsyCost : outTempCU->m_totalRDCost;
+            uint64_t bestCost = m_rdCost.psyRdEnabled() ? outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost; 
             if (tempCost < bestCost)
             {
                 outBestCU = outTempCU;
@@ -807,9 +785,7 @@
     outBestCU->copyToPic((uint8_t)depth);
 
     if (m_param->rdLevel == 0 && depth == 0)
-    {
         encodeResidue(outBestCU, outBestCU, 0, 0);
-    }
     else if (m_param->rdLevel != 0)
     {
         /* Copy Yuv data to picture Yuv */
diff -r 3685d607012f -r f5fe4e345362 source/encoder/cturow.cpp
--- a/source/encoder/cturow.cpp	Thu Jul 10 22:32:24 2014 -0500
+++ b/source/encoder/cturow.cpp	Thu Jul 10 23:15:24 2014 -0500
@@ -32,21 +32,7 @@
 
 void ThreadLocalData::init(Encoder& enc)
 {
-    m_trQuant.init(enc.m_bEnableRDOQ);
-    if (enc.m_useScalingListId == SCALING_LIST_OFF)
-    {
-        m_trQuant.setFlatScalingList();
-        m_trQuant.setUseScalingList(false);
-    }
-    else if (enc.m_useScalingListId == SCALING_LIST_DEFAULT)
-    {
-        m_trQuant.setScalingList(enc.getScalingList());
-        m_trQuant.setUseScalingList(true);
-    }
-
-    m_rdCost.setPsyRdScale(enc.m_param->psyRd);
-
-    m_cuCoder.init(&enc, &m_rdCost, &m_trQuant);
+    m_cuCoder.init(&enc);
     m_cuCoder.create((uint8_t)g_maxCUDepth, g_maxCUSize);
 }
 
diff -r 3685d607012f -r f5fe4e345362 source/encoder/cturow.h
--- a/source/encoder/cturow.h	Thu Jul 10 22:32:24 2014 -0500
+++ b/source/encoder/cturow.h	Thu Jul 10 23:15:24 2014 -0500
@@ -41,8 +41,6 @@
 struct ThreadLocalData
 {
     TEncCu      m_cuCoder;
-    RDCost      m_rdCost;
-    TComTrQuant m_trQuant;
 
     // NOTE: the maximum LCU 64x64 have 256 partitions
     bool        m_edgeFilter[256];
diff -r 3685d607012f -r f5fe4e345362 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Thu Jul 10 22:32:24 2014 -0500
+++ b/source/encoder/frameencoder.cpp	Thu Jul 10 23:15:24 2014 -0500
@@ -851,7 +851,7 @@
 
     // setup thread-local data
     TComPicYuv* fenc = m_frame->getPicYuvOrg();
-    tld.m_trQuant.m_nr = &m_nr;
+    tld.m_cuCoder.m_trQuant.m_nr = &m_nr;
     tld.m_cuCoder.m_mref = m_mref;
     tld.m_cuCoder.m_me.setSourcePlane(fenc->getLumaAddr(), fenc->getStride());
     tld.m_cuCoder.m_log = &tld.m_cuCoder.m_sliceTypeLog[m_frame->getSlice()->getSliceType()];
diff -r 3685d607012f -r f5fe4e345362 source/encoder/frameencoder.h
--- a/source/encoder/frameencoder.h	Thu Jul 10 22:32:24 2014 -0500
+++ b/source/encoder/frameencoder.h	Thu Jul 10 23:15:24 2014 -0500
@@ -43,12 +43,6 @@
 namespace x265 {
 // private x265 namespace
 
-enum SCALING_LIST_PARAMETER
-{
-    SCALING_LIST_OFF,
-    SCALING_LIST_DEFAULT,
-};
-
 class ThreadPool;
 class Encoder;
 



More information about the x265-devel mailing list