Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncCu.cpp


Ignore:
Timestamp:
13 Aug 2015, 17:38:13 (9 years ago)
Author:
tech
Message:

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibEncoder/TEncCu.cpp

    r1196 r1313  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
     4 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4040#include "TEncCu.h"
    4141#include "TEncAnalyze.h"
     42#include "TLibCommon/Debug.h"
    4243
    4344#include <cmath>
     
    4546using namespace std;
    4647
     48
    4749//! \ingroup TLibEncoder
    4850//! \{
     
    5355
    5456/**
    55  \param    uiTotalDepth  total number of allowable depth
     57 \param    uhTotalDepth  total number of allowable depth
    5658 \param    uiMaxWidth    largest CU width
    5759 \param    uiMaxHeight   largest CU height
     60 \param    chromaFormat  chroma format
    5861 */
    59 Void TEncCu::create(UChar uhTotalDepth, UInt uiMaxWidth, UInt uiMaxHeight)
     62Void TEncCu::create(UChar uhTotalDepth, UInt uiMaxWidth, UInt uiMaxHeight, ChromaFormat chromaFormat)
    6063{
    6164  Int i;
    62  
     65
    6366  m_uhTotalDepth   = uhTotalDepth + 1;
    6467  m_ppcBestCU      = new TComDataCU*[m_uhTotalDepth-1];
    6568  m_ppcTempCU      = new TComDataCU*[m_uhTotalDepth-1];
    66    
    67 #if H_3D_ARP
     69
     70#if NH_3D_ARP
    6871  m_ppcWeightedTempCU = new TComDataCU*[m_uhTotalDepth-1];
    6972#endif
     
    7679  m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1];
    7780  m_ppcOrigYuv     = new TComYuv*[m_uhTotalDepth-1];
    78 #if H_3D_DBBP
     81#if NH_3D_DBBP
    7982  m_ppcOrigYuvDBBP = new TComYuv*[m_uhTotalDepth-1];
    8083#endif
    81  
     84
    8285  UInt uiNumPartitions;
    8386  for( i=0 ; i<m_uhTotalDepth-1 ; i++)
     
    8689    UInt uiWidth  = uiMaxWidth  >> i;
    8790    UInt uiHeight = uiMaxHeight >> i;
    88    
    89     m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
    90     m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
    91    
    92 #if H_3D_ARP
    93     m_ppcWeightedTempCU[i] = new TComDataCU; m_ppcWeightedTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
     91
     92    m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( chromaFormat, uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
     93    m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( chromaFormat, uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
     94#if NH_3D_ARP
     95    m_ppcWeightedTempCU[i] = new TComDataCU; m_ppcWeightedTempCU[i]->create( chromaFormat, uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
    9496#endif 
    9597
    96     m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight);
    97     m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight);
    98     m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight);
    99    
    100     m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight);
    101     m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight);
    102     m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight);
    103    
    104     m_ppcOrigYuv    [i] = new TComYuv; m_ppcOrigYuv    [i]->create(uiWidth, uiHeight);
    105 #if H_3D_DBBP
    106     m_ppcOrigYuvDBBP[i] = new TComYuv; m_ppcOrigYuvDBBP[i]->create(uiWidth, uiHeight);
    107 #endif
    108   }
    109  
    110   m_bEncodeDQP = false;
     98    m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight, chromaFormat);
     99    m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight, chromaFormat);
     100    m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight, chromaFormat);
     101
     102    m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat);
     103    m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat);
     104    m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat);
     105
     106    m_ppcOrigYuv    [i] = new TComYuv; m_ppcOrigYuv    [i]->create(uiWidth, uiHeight, chromaFormat);
     107#if NH_3D_DBBP
     108    m_ppcOrigYuvDBBP[i] = new TComYuv; m_ppcOrigYuvDBBP[i]->create(uiWidth, uiHeight, chromaFormat);
     109#endif
     110
     111  }
     112
     113  m_bEncodeDQP          = false;
     114
    111115#if KWU_RC_MADPRED_E0227
    112116  m_LCUPredictionSAD = 0;
     
    116120#endif
    117121
     122  m_stillToCodeChromaQpOffsetFlag  = false;
     123  m_cuChromaQpOffsetIdxPlus1       = 0;
     124  m_bFastDeltaQP                   = false;
     125
    118126  // initialize partition order.
    119127  UInt* piTmp = &g_auiZscanToRaster[0];
    120128  initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp);
    121129  initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth );
    122  
     130
    123131  // initialize conversion matrix from partition index to pel
    124132  initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth );
     
    128136{
    129137  Int i;
    130  
     138
    131139  for( i=0 ; i<m_uhTotalDepth-1 ; i++)
    132140  {
     
    139147      m_ppcTempCU[i]->destroy();      delete m_ppcTempCU[i];      m_ppcTempCU[i] = NULL;
    140148    }
    141 #if H_3D_ARP
     149#if NH_3D_ARP
    142150    if(m_ppcWeightedTempCU[i])
    143151    {
     
    173181      m_ppcOrigYuv[i]->destroy();     delete m_ppcOrigYuv[i];     m_ppcOrigYuv[i] = NULL;
    174182    }
    175 #if H_3D_DBBP
     183#if NH_3D_DBBP
    176184    if(m_ppcOrigYuvDBBP[i])
    177185    {
     
    191199  }
    192200
    193 #if H_3D_ARP
     201#if NH_3D_ARP
    194202  if(m_ppcWeightedTempCU)
    195203  {
     
    233241    m_ppcOrigYuv = NULL;
    234242  }
    235 #if H_3D_DBBP
     243#if NH_3D_DBBP
    236244  if(m_ppcOrigYuvDBBP)
    237245  {
     
    249257  m_pcPredSearch       = pcEncTop->getPredSearch();
    250258  m_pcTrQuant          = pcEncTop->getTrQuant();
    251   m_pcBitCounter       = pcEncTop->getBitCounter();
    252259  m_pcRdCost           = pcEncTop->getRdCost();
    253  
     260
    254261  m_pcEntropyCoder     = pcEncTop->getEntropyCoder();
    255   m_pcCavlcCoder       = pcEncTop->getCavlcCoder();
    256   m_pcSbacCoder       = pcEncTop->getSbacCoder();
    257262  m_pcBinCABAC         = pcEncTop->getBinCABAC();
    258  
    259   m_pppcRDSbacCoder   = pcEncTop->getRDSbacCoder();
    260   m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder();
    261  
    262   m_pcRateCtrl        = pcEncTop->getRateCtrl();
     263
     264  m_pppcRDSbacCoder    = pcEncTop->getRDSbacCoder();
     265  m_pcRDGoOnSbacCoder  = pcEncTop->getRDGoOnSbacCoder();
     266
     267  m_pcRateCtrl         = pcEncTop->getRateCtrl();
    263268}
    264269
     
    267272// ====================================================================================================================
    268273
    269 /** \param  rpcCU pointer of CU data class
     274/**
     275 \param  pCtu pointer of CU data class
    270276 */
    271 Void TEncCu::compressCU( TComDataCU*& rpcCU )
     277Void TEncCu::compressCtu( TComDataCU* pCtu )
    272278{
    273279  // initialize CU data
    274   m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
    275   m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
    276 
    277 #if H_3D_DISABLE_CHROMA
    278   m_ppcWeightedTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
     280  m_ppcBestCU[0]->initCtu( pCtu->getPic(), pCtu->getCtuRsAddr() );
     281  m_ppcTempCU[0]->initCtu( pCtu->getPic(), pCtu->getCtuRsAddr() );
     282
     283#if NH_3D_ARP
     284  m_ppcWeightedTempCU[0]->initCtu( pCtu->getPic(), pCtu->getCtuRsAddr() );
    279285#endif
    280286
     
    287293
    288294  // analysis of CU
    289   xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 );
     295  DEBUG_STRING_NEW(sDebug)
     296
     297  xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 DEBUG_STRING_PASS_INTO(sDebug) );
     298  DEBUG_STRING_OUTPUT(std::cout, sDebug)
    290299
    291300#if ADAPTIVE_QP_SELECTION
    292301  if( m_pcEncCfg->getUseAdaptQpSelect() )
    293302  {
    294     if(rpcCU->getSlice()->getSliceType()!=I_SLICE) //IIII
    295     {
    296       xLcuCollectARLStats( rpcCU);
     303    if(pCtu->getSlice()->getSliceType()!=I_SLICE) //IIII
     304    {
     305      xCtuCollectARLStats( pCtu );
    297306    }
    298307  }
    299308#endif
    300309}
    301 /** \param  pcCU  pointer of CU data class
     310/** \param  pCtu  pointer of CU data class
    302311 */
    303 Void TEncCu::encodeCU ( TComDataCU* pcCU )
     312Void TEncCu::encodeCtu ( TComDataCU* pCtu )
    304313{
    305   if ( pcCU->getSlice()->getPPS()->getUseDQP() )
     314  if ( pCtu->getSlice()->getPPS()->getUseDQP() )
    306315  {
    307316    setdQPFlag(true);
    308317  }
    309318
     319  if ( pCtu->getSlice()->getUseChromaQpAdj() )
     320  {
     321    setCodeChromaQpAdjFlag(true);
     322  }
     323
    310324  // Encode CU data
    311   xEncodeCU( pcCU, 0, 0 );
     325  xEncodeCU( pCtu, 0, 0 );
    312326}
    313327
     
    315329// Protected member functions
    316330// ====================================================================================================================
    317 /** Derive small set of test modes for AMP encoder speed-up
    318  *\param   rpcBestCU
    319  *\param   eParentPartSize
    320  *\param   bTestAMP_Hor
    321  *\param   bTestAMP_Ver
    322  *\param   bTestMergeAMP_Hor
    323  *\param   bTestMergeAMP_Ver
    324  *\returns Void
    325 */
     331//! Derive small set of test modes for AMP encoder speed-up
    326332#if AMP_ENC_SPEEDUP
    327333#if AMP_MRG
    328 Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver)
    329 #else
    330 Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver)
     334Void TEncCu::deriveTestModeAMP (TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver)
     335#else
     336Void TEncCu::deriveTestModeAMP (TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver)
    331337#endif
    332338{
    333   if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN )
     339  if ( pcBestCU->getPartitionSize(0) == SIZE_2NxN )
    334340  {
    335341    bTestAMP_Hor = true;
    336342  }
    337   else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N )
     343  else if ( pcBestCU->getPartitionSize(0) == SIZE_Nx2N )
    338344  {
    339345    bTestAMP_Ver = true;
    340346  }
    341   else if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->getMergeFlag(0) == false && rpcBestCU->isSkipped(0) == false )
    342   {
    343     bTestAMP_Hor = true;         
    344     bTestAMP_Ver = true;         
     347  else if ( pcBestCU->getPartitionSize(0) == SIZE_2Nx2N && pcBestCU->getMergeFlag(0) == false && pcBestCU->isSkipped(0) == false )
     348  {
     349    bTestAMP_Hor = true;
     350    bTestAMP_Ver = true;
    345351  }
    346352
    347353#if AMP_MRG
    348   //! Utilizing the partition size of parent PU   
     354  //! Utilizing the partition size of parent PU
    349355  if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N )
    350   { 
     356  {
    351357    bTestMergeAMP_Hor = true;
    352358    bTestMergeAMP_Ver = true;
    353359  }
    354360
    355   if ( eParentPartSize == SIZE_NONE ) //! if parent is intra
    356   {
    357     if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN )
     361  if ( eParentPartSize == NUMBER_OF_PART_SIZES ) //! if parent is intra
     362  {
     363    if ( pcBestCU->getPartitionSize(0) == SIZE_2NxN )
    358364    {
    359365      bTestMergeAMP_Hor = true;
    360366    }
    361     else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N )
     367    else if ( pcBestCU->getPartitionSize(0) == SIZE_Nx2N )
    362368    {
    363369      bTestMergeAMP_Ver = true;
     
    365371  }
    366372
    367   if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->isSkipped(0) == false )
    368   {
    369     bTestMergeAMP_Hor = true;         
    370     bTestMergeAMP_Ver = true;         
    371   }
    372 
    373   if ( rpcBestCU->getWidth(0) == 64 )
    374   { 
     373  if ( pcBestCU->getPartitionSize(0) == SIZE_2Nx2N && pcBestCU->isSkipped(0) == false )
     374  {
     375    bTestMergeAMP_Hor = true;
     376    bTestMergeAMP_Ver = true;
     377  }
     378
     379  if ( pcBestCU->getWidth(0) == 64 )
     380  {
    375381    bTestAMP_Hor = false;
    376382    bTestAMP_Ver = false;
    377   }   
    378 #else
    379   //! Utilizing the partition size of parent PU       
     383  }
     384#else
     385  //! Utilizing the partition size of parent PU
    380386  if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N )
    381   { 
     387  {
    382388    bTestAMP_Hor = true;
    383389    bTestAMP_Ver = true;
     
    385391
    386392  if ( eParentPartSize == SIZE_2Nx2N )
    387   { 
     393  {
    388394    bTestAMP_Hor = false;
    389395    bTestAMP_Ver = false;
    390   }     
     396  }
    391397#endif
    392398}
    393399#endif
     400
    394401
    395402// ====================================================================================================================
    396403// Protected member functions
    397404// ====================================================================================================================
    398 /** Compress a CU block recursively with enabling sub-LCU-level delta QP
    399  *\param   rpcBestCU
    400  *\param   rpcTempCU
    401  *\param   uiDepth
    402  *\returns Void
    403  *
    404  *- for loop of QP value to compress the current CU with all possible QP
     405/** Compress a CU block recursively with enabling sub-CTU-level delta QP
     406 *  - for loop of QP value to compress the current CU with all possible QP
    405407*/
    406408#if AMP_ENC_SPEEDUP
    407 Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth, PartSize eParentPartSize )
    408 #else
    409 Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth )
     409Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, const UInt uiDepth DEBUG_STRING_FN_DECLARE(sDebug_), PartSize eParentPartSize )
     410#else
     411Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, const UInt uiDepth )
    410412#endif
    411413{
    412414  TComPic* pcPic = rpcBestCU->getPic();
    413 
    414 #if H_3D_QTLPC
     415  DEBUG_STRING_NEW(sDebug)
     416  const TComPPS &pps=*(rpcTempCU->getSlice()->getPPS());
     417  const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS());
     418 
     419  // These are only used if getFastDeltaQp() is true
     420  const UInt fastDeltaQPCuMaxSize    = Clip3(sps.getMaxCUHeight()>>sps.getLog2DiffMaxMinCodingBlockSize(), sps.getMaxCUHeight(), 32u);
     421
     422
     423#if NH_3D_QTLPC
    415424  Bool  bLimQtPredFalg    = pcPic->getSlice(0)->getQtPredFlag();
    416425  TComPic *pcTexture      = rpcBestCU->getSlice()->getTexturePic();
     
    424433  Bool bTryNx2N           = true;
    425434#endif
     435
    426436  // get Original YUV data from picture
    427   m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() );
    428 
    429 #if H_3D_QTLPC 
     437  m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getCtuRsAddr(), rpcBestCU->getZorderIdxInCtu() );
     438
     439#if NH_3D_QTLPC 
    430440  Bool    bTrySplit     = true;
    431441  Bool    bTrySplitDQP  = true;
    432442#endif
    433 
    434   // variable for Early CU determination
    435   Bool    bSubBranch = true;
    436 
    437443  // variable for Cbf fast mode PU decision
    438444  Bool    doNotBlockPu = true;
    439   Bool earlyDetectionSkipMode = false;
    440 
    441 #if H_3D_VSP
     445  Bool    earlyDetectionSkipMode = false;
     446
     447#if NH_3D_NBDV
    442448  DisInfo DvInfo;
    443449  DvInfo.m_acNBDV.setZero();
    444450  DvInfo.m_aVIdxCan = 0;
    445 #if H_3D_NBDV_REF
     451#if NH_3D_NBDV_REF
    446452  DvInfo.m_acDoNBDV.setZero();
    447453#endif
    448454#endif
    449   Bool bBoundary = false;
    450   UInt uiLPelX   = rpcBestCU->getCUPelX();
    451   UInt uiRPelX   = uiLPelX + rpcBestCU->getWidth(0)  - 1;
    452   UInt uiTPelY   = rpcBestCU->getCUPelY();
    453   UInt uiBPelY   = uiTPelY + rpcBestCU->getHeight(0) - 1;
     455  const UInt uiLPelX   = rpcBestCU->getCUPelX();
     456  const UInt uiRPelX   = uiLPelX + rpcBestCU->getWidth(0)  - 1;
     457  const UInt uiTPelY   = rpcBestCU->getCUPelY();
     458  const UInt uiBPelY   = uiTPelY + rpcBestCU->getHeight(0) - 1;
     459  const UInt uiWidth   = rpcBestCU->getWidth(0);
    454460
    455461#if H_MV_ENC_DEC_TRAC
     
    469475  Bool isAddLowestQP = false;
    470476
    471   if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
     477  const UInt numberValidComponents = rpcBestCU->getPic()->getNumberValidComponents();
     478
     479  if( uiDepth <= pps.getMaxCuDQPDepth() )
    472480  {
    473481    Int idQP = m_pcEncCfg->getMaxDeltaQP();
    474     iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
    475     iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
     482    iMinQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP );
     483    iMaxQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP );
    476484  }
    477485  else
     
    486494    iMaxQP = m_pcRateCtrl->getRCQP();
    487495  }
     496
    488497  // transquant-bypass (TQB) processing loop variable initialisation ---
    489498
    490499  const Int lowestQP = iMinQP; // For TQB, use this QP which is the lowest non TQB QP tested (rather than QP'=0) - that way delta QPs are smaller, and TQB can be tested at all CU levels.
    491500
    492   if ( (rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) )
     501  if ( (pps.getTransquantBypassEnableFlag()) )
    493502  {
    494503    isAddLowestQP = true; // mark that the first iteration is to cost TQB mode.
     
    500509  }
    501510
    502 #if H_3D_IC
     511#if NH_3D_IC
    503512  Bool bICEnabled = rpcTempCU->getSlice()->getViewIndex() && ( rpcTempCU->getSlice()->getSliceType() == P_SLICE || rpcTempCU->getSlice()->getSliceType() == B_SLICE ) && !rpcTempCU->getSlice()->getIsDepth();
    504513  bICEnabled = bICEnabled && rpcTempCU->getSlice()->getApplyIC();
    505514#endif
    506   // If slice start or slice end is within this cu...
     515
    507516  TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx());
    508   Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart();
    509   Bool bSliceEnd = (pcSlice->getSliceSegmentCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart());
    510   Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
    511   // We need to split, so don't try these modes.
    512   if(!bSliceEnd && !bSliceStart && bInsidePicture )
    513   {
    514 #if  H_3D_FAST_TEXTURE_ENCODING
     517
     518  const Bool bBoundary = !( uiRPelX < sps.getPicWidthInLumaSamples() && uiBPelY < sps.getPicHeightInLumaSamples() );
     519#if  NH_3D_FAST_TEXTURE_ENCODING
    515520    Bool bIVFMerge = false;
    516521    Int  iIVFMaxD = 0;
    517522    Bool bFMD = false;
    518 #endif
     523    Bool bSubBranch = true;
     524#endif
     525  if ( !bBoundary )
     526  {
    519527    for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
    520528    {
     
    526534      }
    527535
    528 #if H_3D_QTLPC
     536#if NH_3D_QTLPC
    529537      bTrySplit    = true;
    530538#endif
    531539
     540      m_cuChromaQpOffsetIdxPlus1 = 0;
     541      if (pcSlice->getUseChromaQpAdj())
     542      {
     543        /* Pre-estimation of chroma QP based on input block activity may be performed
     544         * here, using for example m_ppcOrigYuv[uiDepth] */
     545        /* To exercise the current code, the index used for adjustment is based on
     546         * block position
     547         */
     548        Int lgMinCuSize = sps.getLog2MinCodingBlockSize() +
     549                          std::max<Int>(0, sps.getLog2DiffMaxMinCodingBlockSize()-Int(pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth()));
     550        m_cuChromaQpOffsetIdxPlus1 = ((uiLPelX >> lgMinCuSize) + (uiTPelY >> lgMinCuSize)) % (pps.getPpsRangeExtension().getChromaQpOffsetListLen() + 1);
     551      }
     552
    532553      rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    533 #if H_3D_QTLPC
     554#if NH_3D_QTLPC
    534555      //logic for setting bTrySplit using the partition information that is stored of the texture colocated CU
    535556#if H_3D_FCO
     
    539560#endif
    540561      {
    541         TComDataCU* pcTextureCU = pcTexture->getCU( rpcBestCU->getAddr() ); //Corresponding texture LCU
    542         UInt uiCUIdx            = rpcBestCU->getZorderIdxInCU();
     562        TComDataCU* pcTextureCU = pcTexture->getCtu( rpcBestCU->getCtuRsAddr() ); //Corresponding texture LCU
     563        UInt uiCUIdx            = rpcBestCU->getZorderIdxInCtu();
    543564        assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); //Depth cannot be more partitioned than the texture.
    544565        if (pcTextureCU->getDepth(uiCUIdx) > uiDepth || pcTextureCU->getPartitionSize(uiCUIdx) == SIZE_NxN) //Texture was split.
     
    568589#endif
    569590
    570 #if H_3D_NBDV
     591#if NH_3D_NBDV
    571592      if( rpcTempCU->getSlice()->getSliceType() != I_SLICE )
    572593      {
    573 #if H_3D_ARP && H_3D_IV_MERGE
    574         if( rpcTempCU->getSlice()->getIvResPredFlag() || rpcTempCU->getSlice()->getIvMvPredFlag() )
     594#if NH_3D_ARP && NH_3D_IV_MERGE && NH_3D_VSP
     595        if( rpcTempCU->getSlice()->getIvResPredFlag() || rpcTempCU->getSlice()->getIvMvPredFlag() || rpcTempCU->getSlice()->getViewSynthesisPredFlag() )
    575596#else
    576 #if H_3D_ARP
    577         if( rpcTempCU->getSlice()->getVPS()->getUseAdvRP(rpcTempCU->getSlice()->getLayerId()) )
     597#if NH_3D_IV_MERGE && NH_3D_VSP
     598        if( rpcTempCU->getSlice()->getIvMvPredFlag() || rpcTempCU->getSlice()->getViewSynthesisPredFlag() )
     599#else
     600#if NH_3D_ARP && NH_3D_VSP
     601        if( rpcTempCU->getSlice()->getIvResPredFlag() || rpcTempCU->getSlice()->getViewSynthesisPredFlag() )
     602#else
     603#if NH_3D_VSP
     604        if( rpcTempCU->getSlice()->getViewSynthesisPredFlag() )
     605#else
     606#if NH_3D_ARP
     607        if( rpcTempCU->getSlice()->getIvResPredFlag() )
    578608#else
    579609#if H_3D_IV_MERGE
    580610        if( rpcTempCU->getSlice()->getVPS()->getIvMvPredFlag(rpcTempCU->getSlice()->getLayerId()) )
    581611#else
     612#if NH_3D_DBBP
     613        if( rpcTempCU->getSlice()->getDepthBasedBlkPartFlag() )
     614#else
    582615        if (0)
     616#endif
     617#endif
     618#endif
     619#endif
    583620#endif
    584621#endif
     
    586623        {
    587624          PartSize ePartTemp = rpcTempCU->getPartitionSize(0);
    588           rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
    589 #if H_3D_IV_MERGE
     625          rpcTempCU->setPartSizeSubParts(SIZE_2Nx2N, 0, uiDepth);
     626#if NH_3D_IV_MERGE
    590627          if (rpcTempCU->getSlice()->getIsDepth() )
    591628          {
     
    595632          {
    596633#endif
    597 #if H_3D_NBDV_REF
     634#if NH_3D_NBDV_REF
    598635            if( rpcTempCU->getSlice()->getDepthRefinementFlag() )
    599636            {
     
    605642              rpcTempCU->getDisMvpCandNBDV(&DvInfo);
    606643            }
    607 #if H_3D_IV_MERGE
     644#if NH_3D_IV_MERGE
    608645          }
    609646#endif
     
    613650        }
    614651      }
    615 #if  H_3D_FAST_TEXTURE_ENCODING
     652#if  NH_3D_FAST_TEXTURE_ENCODING
    616653      if(rpcTempCU->getSlice()->getViewIndex() && !rpcTempCU->getSlice()->getIsDepth() && rpcTempCU->getSlice()->getDefaultRefViewIdxAvailableFlag() )
    617654      {
     
    626663      if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
    627664      {
    628 #if H_3D_IC
     665#if NH_3D_IC
    629666        for( UInt uiICId = 0; uiICId < ( bICEnabled ? 2 : 1 ); uiICId++ )
    630667        {
    631668          Bool bICFlag = uiICId ? true : false;
    632669#endif
    633           // 2Nx2N
    634           if(m_pcEncCfg->getUseEarlySkipDetection())
    635           {
    636 #if H_3D_IC
     670        // 2Nx2N
     671        if(m_pcEncCfg->getUseEarlySkipDetection())
     672        {
     673#if NH_3D_IC
    637674            rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    638675#endif
    639 #if  H_3D_FAST_TEXTURE_ENCODING
    640             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD );  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode  );//by Competition for inter_2Nx2N
    641 #else
    642             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
    643             rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N
    644 #endif
    645 #if H_3D_VSP
    646             rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    647 #endif
    648           }
    649           // SKIP
    650 #if H_3D_IC
     676#if  NH_3D_FAST_TEXTURE_ENCODING
     677          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD );  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode  );//by Competition for inter_2Nx2N
     678#else
     679          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
     680          rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N
     681#endif
     682#if NH_3D_VSP  || NH_3D_DBBP
     683          rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     684#endif
     685        }
     686        // SKIP
     687#if NH_3D_IC
    651688          rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    652689#endif
    653           xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
    654 #if  H_3D_FAST_TEXTURE_ENCODING
     690        xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU DEBUG_STRING_PASS_INTO(sDebug), &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
     691#if  NH_3D_FAST_TEXTURE_ENCODING
    655692          bFMD = bIVFMerge && rpcBestCU->isSkipped(0);
    656693#endif
     694
     695        rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
     696#if NH_3D_VSP  || NH_3D_DBBP
     697        rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     698#endif
     699
     700        if(!m_pcEncCfg->getUseEarlySkipDetection())
     701        {
     702          // 2Nx2N, NxN
     703#if NH_3D_IC
     704            rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
     705#endif
     706#if  NH_3D_FAST_TEXTURE_ENCODING
     707            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD );  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
     708#else
     709
     710          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
    657711          rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    658 #if H_3D_VSP
     712#endif
     713#if NH_3D_VSP  || NH_3D_DBBP
    659714          rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    660715#endif
    661 
    662           if(!m_pcEncCfg->getUseEarlySkipDetection())
    663           {
    664             // 2Nx2N, NxN
    665 #if H_3D_IC
    666             rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    667 #endif
    668 #if  H_3D_FAST_TEXTURE_ENCODING
    669             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD );  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    670 #else
    671             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
    672             rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    673 #endif
    674 #if H_3D_VSP
    675             rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    676 #endif
    677 
    678 #if H_3D_DBBP
     716#if NH_3D_DBBP
    679717            if( rpcTempCU->getSlice()->getDepthBasedBlkPartFlag() && rpcTempCU->getSlice()->getDefaultRefViewIdxAvailableFlag() )
    680718            {
    681               xCheckRDCostInterDBBP( rpcBestCU, rpcTempCU, false );
     719              xCheckRDCostInterDBBP( rpcBestCU, rpcTempCU DEBUG_STRING_PASS_INTO(sDebug), false );
    682720              rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode  );
    683 #if H_3D_VSP
     721#if NH_3D_VSP  || NH_3D_DBBP
    684722              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    685723#endif
    686724            }
    687725#endif
    688             if(m_pcEncCfg->getUseCbfFastMode())
    689             {
    690               doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
    691             }
     726
     727          if(m_pcEncCfg->getUseCbfFastMode())
     728          {
     729            doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
    692730          }
    693 #if H_3D_IC
    694731        }
     732#if NH_3D_IC
     733        }
    695734#endif
    696735      }
    697 
    698 #if H_3D_QTLPC     
     736#if NH_3D_QTLPC     
    699737      if(depthMapDetect && !bIntraSliceDetect && !rapPic && ( m_pcEncCfg->getUseQTL() || bLimQtPredFalg ))
    700738      {
     
    702740      }
    703741#endif
    704       if ( bIsLosslessMode )
     742
     743      if (bIsLosslessMode) // Restore loop variable if lossless mode was searched.
    705744      {
    706745        iQP = iMinQP;
     
    715754    }
    716755#endif
    717 #if H_3D_DIM_ENC
     756#if NH_3D_ENC_DEPTH
    718757    if( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() )
    719758    {
     
    721760    }
    722761#endif
    723 #if H_3D
     762#if NH_3D_DIS
    724763    rpcTempCU->initEstData( uiDepth, iMinQP, isAddLowestQP  );
    725764    if( rpcBestCU->getSlice()->getDepthIntraSkipFlag() )
     
    733772      for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
    734773      {
    735         const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP);
     774        const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); // If lossless, then iQP is irrelevant for subsequent modules.
    736775
    737776        if (bIsLosslessMode)
     
    739778          iQP = lowestQP;
    740779        }
     780
    741781        rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    742782
     
    745785        {
    746786          // 2Nx2N, NxN
    747             if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
     787
     788          if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
     789          {
     790            if( uiDepth == sps.getLog2DiffMaxMinCodingBlockSize() && doNotBlockPu
     791#if NH_3D_QTLPC
     792                && bTrySplit
     793#endif
     794)
    748795            {
    749               if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu
    750 #if H_3D_QTLPC
    751                 && bTrySplit
    752 #endif
    753                 )
    754               {
    755 #if  H_3D_FAST_TEXTURE_ENCODING
    756                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN, bFMD  );
    757 #else
    758                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
    759 #endif
    760                 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    761 #if H_3D_VSP
    762                 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    763 #endif
    764               }
     796#if  NH_3D_FAST_TEXTURE_ENCODING
     797              xCheckRDCostInter( rpcBestCU, rpcTempCU DEBUG_STRING_PASS_INTO(sDebug), SIZE_NxN, bFMD  );
     798#else
     799
     800              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug)   );
     801#endif
     802              rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
     803#if NH_3D_VSP || NH_3D_DBBP
     804              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     805#endif
     806
    765807            }
    766 
    767           // 2NxN, Nx2N
     808          }
     809
    768810          if(doNotBlockPu
    769 #if H_3D_QTLPC
     811#if NH_3D_QTLPC
    770812            && bTryNx2N
    771813#endif
    772             )
     814)
    773815          {
    774 #if  H_3D_FAST_TEXTURE_ENCODING
    775             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N, bFMD  );
    776 #else
    777             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N );
     816#if  NH_3D_FAST_TEXTURE_ENCODING
     817            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD  );
     818#else
     819            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
    778820#endif
    779821            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    780 #if H_3D_VSP
     822#if NH_3D_VSP || NH_3D_DBBP
    781823            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    782824#endif
     825
    783826            if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N )
    784827            {
     
    787830          }
    788831          if(doNotBlockPu
    789 #if H_3D_QTLPC
     832#if NH_3D_QTLPC
    790833            && bTry2NxN
    791834#endif
    792             )
     835)
    793836          {
    794 #if  H_3D_FAST_TEXTURE_ENCODING
    795             xCheckRDCostInter      ( rpcBestCU, rpcTempCU, SIZE_2NxN, bFMD  );
    796 #else
    797             xCheckRDCostInter      ( rpcBestCU, rpcTempCU, SIZE_2NxN  );
    798 #endif
     837#if  NH_3D_FAST_TEXTURE_ENCODING
     838            xCheckRDCostInter      ( rpcBestCU, rpcTempCU, SIZE_2NxN DEBUG_STRING_PASS_INTO(sDebug), bFMD  );
     839#else
     840
     841            xCheckRDCostInter      ( rpcBestCU, rpcTempCU, SIZE_2NxN DEBUG_STRING_PASS_INTO(sDebug)  );
     842#endif
     843
    799844            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    800 #if H_3D_VSP
     845#if NH_3D_VSP || NH_3D_DBBP
    801846            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    802847#endif
     848
    803849            if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN)
    804850            {
     
    807853          }
    808854
    809 #if 1
    810855          //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N)
    811           if( pcPic->getSlice(0)->getSPS()->getAMPAcc(uiDepth) )
     856          if(sps.getUseAMP() && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() )
    812857          {
    813 #if AMP_ENC_SPEEDUP       
     858#if AMP_ENC_SPEEDUP
    814859            Bool bTestAMP_Hor = false, bTestAMP_Ver = false;
    815860
     
    826871            {
    827872              if(doNotBlockPu
    828 #if H_3D_QTLPC
     873#if NH_3D_QTLPC
    829874                && bTry2NxN
    830875#endif
    831                 )
     876)
    832877              {
    833 #if  H_3D_FAST_TEXTURE_ENCODING
    834                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFMD );
    835 #else
    836                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
     878#if  NH_3D_FAST_TEXTURE_ENCODING
     879                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug), bFMD );
     880#else
     881                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug) );
    837882#endif
    838883                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    839 #if H_3D_VSP
     884#if NH_3D_VSP || NH_3D_DBBP
    840885                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    841886#endif
     
    846891              }
    847892              if(doNotBlockPu
    848 #if H_3D_QTLPC
     893#if NH_3D_QTLPC
    849894                && bTry2NxN
    850895#endif
    851                 )
     896)
    852897              {
    853 #if  H_3D_FAST_TEXTURE_ENCODING
    854                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFMD );
    855 #else
    856                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
    857 #endif
     898#if  NH_3D_FAST_TEXTURE_ENCODING
     899                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug), bFMD );
     900#else
     901                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug) );
     902#endif
     903
    858904                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    859 #if H_3D_VSP
     905#if NH_3D_VSP || NH_3D_DBBP
    860906                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    861907#endif
     908
    862909                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
    863910                {
     
    867914            }
    868915#if AMP_MRG
    869             else if ( bTestMergeAMP_Hor ) 
     916            else if ( bTestMergeAMP_Hor )
    870917            {
    871918              if(doNotBlockPu
    872 #if H_3D_QTLPC
     919#if NH_3D_QTLPC
    873920                && bTry2NxN
    874921#endif
    875                 )
     922)
    876923              {
    877 #if  H_3D_FAST_TEXTURE_ENCODING
    878                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFMD, true );
    879 #else
    880                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true );
    881 #endif
     924#if  NH_3D_FAST_TEXTURE_ENCODING
     925                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug), bFMD, true );
     926#else
     927
     928                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug), true );
     929#endif
     930
    882931                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    883 #if H_3D_VSP
     932#if NH_3D_VSP || NH_3D_DBBP
    884933                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    885934#endif
     
    890939              }
    891940              if(doNotBlockPu
    892 #if H_3D_QTLPC
     941#if NH_3D_QTLPC
    893942                && bTry2NxN
    894943#endif
    895                 )
     944)
    896945              {
    897 #if  H_3D_FAST_TEXTURE_ENCODING
    898                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFMD, true );
    899 #else
    900                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true );
     946#if  NH_3D_FAST_TEXTURE_ENCODING
     947                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug), bFMD, true );
     948#else
     949                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug), true );
    901950#endif
    902951                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    903 #if H_3D_VSP
     952#if NH_3D_VSP || NH_3D_DBBP
    904953                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    905954#endif
     955
    906956                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
    907957                {
     
    916966            {
    917967              if(doNotBlockPu
    918 #if H_3D_QTLPC
     968#if NH_3D_QTLPC
    919969                && bTryNx2N
    920970#endif
    921                 )
     971)
    922972              {
    923 #if  H_3D_FAST_TEXTURE_ENCODING
    924                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFMD );
    925 #else
    926                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
    927 #endif
     973#if  NH_3D_FAST_TEXTURE_ENCODING
     974                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD );
     975#else
     976                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug) );
     977#endif
     978
    928979                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    929 #if H_3D_VSP
     980#if NH_3D_VSP || NH_3D_DBBP
    930981                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    931982#endif
     
    936987              }
    937988              if(doNotBlockPu
    938 #if H_3D_QTLPC
     989#if NH_3D_QTLPC
    939990                && bTryNx2N
    940991#endif
    941                 )
     992)
    942993              {
    943 #if  H_3D_FAST_TEXTURE_ENCODING
    944                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFMD );
    945 #else
    946                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
     994#if  NH_3D_FAST_TEXTURE_ENCODING
     995                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD );
     996#else
     997                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug) );
    947998#endif
    948999                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    949 #if H_3D_VSP
     1000#if NH_3D_VSP || NH_3D_DBBP
    9501001                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    9511002#endif
     
    9561007            {
    9571008              if(doNotBlockPu
    958 #if H_3D_QTLPC
     1009#if NH_3D_QTLPC
    9591010                && bTryNx2N
    9601011#endif
    961                 )
     1012)
    9621013              {
    963 #if  H_3D_FAST_TEXTURE_ENCODING
    964                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFMD, true );
    965 #else
    966                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true );
     1014#if  NH_3D_FAST_TEXTURE_ENCODING
     1015                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD, true );
     1016#else
     1017                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug), true );
    9671018#endif
    9681019                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    969 #if H_3D_VSP
     1020#if NH_3D_VSP || NH_3D_DBBP
    9701021                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    9711022#endif
     
    9761027              }
    9771028              if(doNotBlockPu
    978 #if H_3D_QTLPC
     1029#if NH_3D_QTLPC
    9791030                && bTryNx2N
    9801031#endif
    981                 )
     1032)
    9821033              {
    983 #if  H_3D_FAST_TEXTURE_ENCODING
    984                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFMD, true );
    985 #else
    986                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true );
     1034#if  NH_3D_FAST_TEXTURE_ENCODING
     1035                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug), bFMD, true );
     1036#else
     1037
     1038                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug), true );
    9871039#endif
    9881040                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    989 #if H_3D_VSP
     1041#if NH_3D_VSP || NH_3D_DBBP
    9901042                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    9911043#endif
     1044
    9921045              }
    9931046            }
     
    9951048
    9961049#else
    997 #if H_3D_QTLPC
     1050#if NH_3D_QTLPC
    9981051            if (bTry2NxN)
    9991052            {
    10001053#endif
    1001               xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
    1002               rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    1003 #if H_3D_VSP
    1004               rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    1005 #endif
    1006               xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
    1007               rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    1008 #if H_3D_VSP
    1009               rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    1010 #endif
    1011 #if H_3D_QTLPC
     1054
     1055            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
     1056            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
     1057#if NH_3D_VSP || NH_3D_DBBP
     1058            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     1059#endif
     1060            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
     1061            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
     1062#if NH_3D_VSP || NH_3D_DBBP
     1063            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     1064#endif
     1065#if NH_3D_QTLPC
    10121066            }
    10131067            if (bTryNx2N)
    10141068            {
    10151069#endif
    1016               xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
    1017               rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    1018 #if H_3D_VSP
    1019               rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    1020 #endif
    1021               xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
    1022               rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    1023 #if H_3D_VSP
    1024               rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    1025 #endif
    1026 #if H_3D_QTLPC
     1070            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
     1071            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
     1072#if NH_3D_VSP || NH_3D_DBBP
     1073            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     1074#endif
     1075            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
     1076            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
     1077#if NH_3D_VSP || NH_3D_DBBP
     1078            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     1079#endif
     1080#if NH_3D_QTLPC
    10271081            }
    10281082#endif
    10291083
    1030 #endif
    1031           }   
    1032 #endif
     1084
     1085#endif
     1086          }
    10331087        }
    1034 #if  H_3D_FAST_TEXTURE_ENCODING
     1088#if  NH_3D_FAST_TEXTURE_ENCODING
    10351089        if(!bFMD)
    10361090        {
    10371091#endif
     1092
    10381093        // do normal intra modes
    1039        
    1040           // speedup for inter frames
    1041           if( rpcBestCU->getSlice()->getSliceType() == I_SLICE ||
    1042             rpcBestCU->getCbf( 0, TEXT_LUMA     ) != 0   ||
    1043             rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0   ||
    1044             rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0     
    1045 #if H_3D_DIM_ENC
     1094        // speedup for inter frames
     1095        Double intraCost = 0.0;
     1096
     1097        if((rpcBestCU->getSlice()->getSliceType() == I_SLICE)                                     ||
     1098           ((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && ( // avoid very complex intra if it is unlikely
     1099           (rpcBestCU->getCbf( 0, COMPONENT_Y  ) != 0)                                            ||
     1100          ((rpcBestCU->getCbf( 0, COMPONENT_Cb ) != 0) && (numberValidComponents > COMPONENT_Cb)) ||
     1101          ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr))
     1102 #if NH_3D_ENC_DEPTH
    10461103            || rpcBestCU->getSlice()->getIsDepth()
    10471104#endif
    1048             ) // avoid very complex intra if it is unlikely
    1049           {
    1050 #if H_3D_DIM
     1105            )))
     1106        {
     1107#if NH_3D_ENC_DEPTH
    10511108            Bool bOnlyIVP = false;
    10521109            Bool bUseIVP = true;
    1053             if( rpcBestCU->getSlice()->getIsDepth() && !(rpcBestCU->getSlice()->isIRAP()) &&
    1054               rpcBestCU->getSlice()->getSliceType() != I_SLICE &&
    1055               rpcBestCU->getCbf( 0, TEXT_LUMA     ) == 0 &&
    1056               rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) == 0 &&
    1057               rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) == 0
    1058               )
     1110            if( (rpcBestCU->getSlice()->getSliceType() != I_SLICE) &&
     1111                !( (rpcBestCU->getCbf( 0, COMPONENT_Y  ) != 0)                                            ||
     1112                  ((rpcBestCU->getCbf( 0, COMPONENT_Cb ) != 0) && (numberValidComponents > COMPONENT_Cb)) ||
     1113                  ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr))   ) &&
     1114                  (rpcBestCU->getSlice()->getIsDepth() && !(rpcBestCU->getSlice()->isIRAP())) )
    10591115            {
    10601116              bOnlyIVP = true;
     
    10631119            if( bUseIVP )
    10641120            {
    1065               xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bOnlyIVP );
    1066 #else
    1067             xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
    1068 #endif
    1069 
     1121              xCheckRDCostIntra( rpcBestCU, rpcTempCU, intraCost, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug), bOnlyIVP );
     1122#else
     1123          xCheckRDCostIntra( rpcBestCU, rpcTempCU, intraCost, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
     1124#endif
    10701125#if KWU_RC_MADPRED_E0227
    10711126            if ( uiDepth <= m_addSADDepth )
     
    10761131#endif
    10771132
    1078             rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    1079             if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
    1080             {
    1081 #if H_3D_QTLPC //Try IntraNxN
     1133          rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
     1134          if( uiDepth == sps.getLog2DiffMaxMinCodingBlockSize() )
     1135          {
     1136#if NH_3D_QTLPC //Try IntraNxN
    10821137              if(bTrySplit)
    10831138              {
    10841139#endif
    1085                 if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) )
    1086                 {
    1087 #if H_3D_DIM
    1088                   xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN, bOnlyIVP );
    1089 #else
    1090                   xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN   );
    1091 #endif
    1092                   rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    1093                 }
    1094 #if H_3D_QTLPC
     1140            if( rpcTempCU->getWidth(0) > ( 1 << sps.getQuadtreeTULog2MinSize() ) )
     1141            {
     1142              Double tmpIntraCost;
     1143#if NH_3D_ENC_DEPTH
     1144              xCheckRDCostIntra( rpcBestCU, rpcTempCU, tmpIntraCost, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug), bOnlyIVP );
     1145#else
     1146              xCheckRDCostIntra( rpcBestCU, rpcTempCU, tmpIntraCost, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug)   );
     1147#endif
     1148
     1149              intraCost = std::min(intraCost, tmpIntraCost);
     1150              rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
     1151            }
     1152#if NH_3D_QTLPC
    10951153              }
    10961154#endif
    1097             }
    1098 #if H_3D
    10991155          }
     1156#if NH_3D_ENC_DEPTH
     1157          }
    11001158#endif
    11011159        }
     1160
    11021161        // test PCM
    1103         if(pcPic->getSlice(0)->getSPS()->getUsePCM()
    1104           && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize())
    1105           && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) )
     1162        if(sps.getUsePCM()
     1163          && rpcTempCU->getWidth(0) <= (1<<sps.getPCMLog2MaxSize())
     1164          && rpcTempCU->getWidth(0) >= (1<<sps.getPCMLog2MinSize()) )
    11061165        {
    1107           UInt uiRawBits = (2 * g_bitDepthY + g_bitDepthC) * rpcBestCU->getWidth(0) * rpcBestCU->getHeight(0) / 2;
     1166          UInt uiRawBits = getTotalBits(rpcBestCU->getWidth(0), rpcBestCU->getHeight(0), rpcBestCU->getPic()->getChromaFormat(), sps.getBitDepths().recon);
    11081167          UInt uiBestBits = rpcBestCU->getTotalBits();
    1109 #if H_3D_VSO // M7
    1110           Double dRDCostTemp = m_pcRdCost->getUseVSO() ? m_pcRdCost->calcRdCostVSO(uiRawBits, 0) : m_pcRdCost->calcRdCost(uiRawBits, 0);
     1168#if NH_3D_VSO // M7
     1169          Double dRDCostTemp = m_pcRdCost->getUseLambdaScaleVSO() ? m_pcRdCost->calcRdCostVSO(uiRawBits, 0) : m_pcRdCost->calcRdCost(uiRawBits, 0);
    11111170          if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > dRDCostTemp ))
    11121171#else
    11131172          if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0)))
    11141173#endif
     1174
    11151175          {
    11161176            xCheckIntraPCM (rpcBestCU, rpcTempCU);
     
    11181178          }
    11191179        }
    1120 #if  H_3D_FAST_TEXTURE_ENCODING
     1180#if  NH_3D_FAST_TEXTURE_ENCODING
    11211181        }
    11221182#endif
    1123         if (bIsLosslessMode)
     1183        if (bIsLosslessMode) // Restore loop variable if lossless mode was searched.
    11241184        {
    11251185          iQP = iMinQP;
     
    11281188    }
    11291189
    1130     m_pcEntropyCoder->resetBits();
    1131     m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true );
    1132     rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
     1190    if( rpcBestCU->getTotalCost()!=MAX_DOUBLE )
     1191    {
     1192      m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
     1193      m_pcEntropyCoder->resetBits();
     1194      m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true );
     1195      rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
    11331196      rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    1134     #if H_3D_VSO // M8
     1197#if NH_3D_VSO // M8
    11351198    if ( m_pcRdCost->getUseVSO() )   
     1199    {
    11361200      rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );   
     1201    }
    11371202    else
    11381203#endif
    1139     rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
    1140 
    1141     // Early CU determination
    1142     if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) )
     1204      rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
     1205      m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
     1206    }
     1207#if  NH_3D_FAST_TEXTURE_ENCODING
     1208    if(rpcBestCU->getSlice()->getViewIndex() && !rpcBestCU->getSlice()->getIsDepth() && (uiDepth >=iIVFMaxD) && rpcBestCU->isSkipped(0))
    11431209    {
    11441210      bSubBranch = false;
    11451211    }
    1146     else
    1147     {
    1148       bSubBranch = true;
    1149     }
    1150 #if  H_3D_FAST_TEXTURE_ENCODING
    1151     if(rpcBestCU->getSlice()->getViewIndex() && !rpcBestCU->getSlice()->getIsDepth() && (uiDepth >=iIVFMaxD) && rpcBestCU->isSkipped(0))
    1152     {
    1153       bSubBranch = false;
    1154     }
    1155 #endif
    1156   }
    1157   else if(!(bSliceEnd && bInsidePicture))
    1158   {
    1159     bBoundary = true;
    1160   }
    1161 
    1162   // copy orginal YUV samples to PCM buffer
    1163   if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false))
     1212#endif
     1213  }
     1214
     1215  // copy original YUV samples to PCM buffer
     1216  if( rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false))
    11641217  {
    11651218    xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]);
    11661219  }
    1167   if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
     1220
     1221  if( uiDepth == pps.getMaxCuDQPDepth() )
    11681222  {
    11691223    Int idQP = m_pcEncCfg->getMaxDeltaQP();
    1170     iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
    1171     iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
    1172   }
    1173   else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
     1224    iMinQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP );
     1225    iMaxQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP );
     1226  }
     1227  else if( uiDepth < pps.getMaxCuDQPDepth() )
    11741228  {
    11751229    iMinQP = iBaseQP;
     
    11781232  else
    11791233  {
    1180     Int iStartQP;
    1181     if( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr())
    1182     {
    1183       iStartQP = rpcTempCU->getQP(0);
    1184     }
    1185     else
    1186     {
    1187       UInt uiCurSliceStartPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU();
    1188       iStartQP = rpcTempCU->getQP(uiCurSliceStartPartIdx);
    1189     }
     1234    const Int iStartQP = rpcTempCU->getQP(0);
    11901235    iMinQP = iStartQP;
    11911236    iMaxQP = iStartQP;
    11921237  }
     1238
    11931239  if ( m_pcEncCfg->getUseRateCtrl() )
    11941240  {
     
    11991245  if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
    12001246  {
    1201     iMaxQP = iMinQP; // If all blocks are forced into using transquant bypass, do not loop here.
    1202   }
    1203   for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
    1204   {
    1205     const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true.
    1206     rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    1207 
     1247    iMaxQP = iMinQP; // If all TUs are forced into using transquant bypass, do not loop here.
     1248  }
     1249#if  NH_3D_FAST_TEXTURE_ENCODING
     1250  bSubBranch = bSubBranch && (bBoundary || !( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isSkipped(0) ));
     1251#else
     1252  const Bool bSubBranch = bBoundary || !( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isSkipped(0) );
     1253#endif
     1254#if NH_3D_QTLPC
     1255  if( bSubBranch && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() && (!getFastDeltaQp() || uiWidth > fastDeltaQPCuMaxSize || bBoundary) && bTrySplitDQP )
     1256#else
     1257  if( bSubBranch && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() && (!getFastDeltaQp() || uiWidth > fastDeltaQPCuMaxSize || bBoundary))
     1258#endif
     1259  {
    12081260    // further split
    1209 #if H_3D_QTLPC
    1210     if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
    1211 #else
    1212     if( bSubBranch && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
    1213 #endif
    1214     {
    1215 #if H_3D_VSO // M9
     1261    for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
     1262    {
     1263      const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true.
     1264
     1265      rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
     1266
     1267#if NH_3D_VSO // M9
    12161268      // reset Model
    12171269      if( m_pcRdCost->getUseRenModel() )
    12181270      {
    1219         UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth ( );
    1220         UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight( );
    1221         Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 );
    1222         UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride();
    1223         m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight );
     1271        UInt  uiWidthOy     = m_ppcOrigYuv[uiDepth]->getWidth ( COMPONENT_Y );
     1272        UInt  uiHeightOy    = m_ppcOrigYuv[uiDepth]->getHeight( COMPONENT_Y );
     1273        Pel*  piSrc         = m_ppcOrigYuv[uiDepth]->getAddr  ( COMPONENT_Y, 0 );
     1274        UInt  uiSrcStride   = m_ppcOrigYuv[uiDepth]->getStride( COMPONENT_Y  );
     1275        m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidthOy, uiHeightOy );
    12241276      }
    12251277#endif
    1226 
    12271278      UChar       uhNextDepth         = uiDepth+1;
    12281279      TComDataCU* pcSubBestPartCU     = m_ppcBestCU[uhNextDepth];
    12291280      TComDataCU* pcSubTempPartCU     = m_ppcTempCU[uhNextDepth];
    1230 
    1231 #if H_3D_DISABLE_CHROMA
     1281      DEBUG_STRING_NEW(sTempDebug)
     1282
     1283#if NH_3D_ARP
    12321284      m_ppcWeightedTempCU[uhNextDepth]->setSlice( m_ppcWeightedTempCU[ uiDepth]->getSlice());
     1285      m_ppcWeightedTempCU[uhNextDepth]->setPic  ( m_ppcWeightedTempCU[ uiDepth] );
    12331286#endif
    12341287      for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
     
    12371290        pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP );           // clear sub partition datas or init.
    12381291
    1239         Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getSliceSegmentCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getSliceSegmentCurEndCUAddr();
    1240         if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     1292        if( ( pcSubBestPartCU->getCUPelX() < sps.getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < sps.getPicHeightInLumaSamples() ) )
    12411293        {
    1242             if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer
    1243             {
    1244               m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    1245             }
    1246             else
    1247             {
    1248               m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    1249             }
    1250 
    1251 #if AMP_ENC_SPEEDUP
    1252           if ( rpcBestCU->isIntra(0) )
     1294          if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer
    12531295          {
    1254             xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, SIZE_NONE );
     1296            m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    12551297          }
    12561298          else
    12571299          {
    1258             xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, rpcBestCU->getPartitionSize(0) );
     1300            m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    12591301          }
     1302
     1303#if AMP_ENC_SPEEDUP
     1304          DEBUG_STRING_NEW(sChild)
     1305          if ( !(rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isInter(0)) )
     1306          {
     1307            xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), NUMBER_OF_PART_SIZES );
     1308          }
     1309          else
     1310          {
     1311
     1312            xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), rpcBestCU->getPartitionSize(0) );
     1313          }
     1314          DEBUG_STRING_APPEND(sTempDebug, sChild)
    12601315#else
    12611316          xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth );
     
    12651320          xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth );
    12661321        }
    1267         else if (bInSlice)
     1322        else
    12681323        {
    12691324          pcSubBestPartCU->copyToPic( uhNextDepth );
     
    12721327      }
    12731328
     1329      m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    12741330      if( !bBoundary )
    12751331      {
     
    12781334
    12791335        rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
    1280           rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    1281         }
    1282 #if H_3D_VSO // M10
     1336        rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     1337      }
     1338#if NH_3D_VSO // M10
    12831339      if ( m_pcRdCost->getUseVSO() )
     1340      {
    12841341        rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     1342      }
    12851343      else
    12861344#endif
    1287       rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    1288 
    1289       if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP())
     1345        rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     1346
     1347      if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP())
    12901348      {
    12911349        Bool hasResidual = false;
    12921350        for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++)
    12931351        {
    1294           if( ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getSliceSegmentCurStartCUAddr() ) &&
    1295               ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) )
     1352          if( (     rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Y)
     1353                || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cb) && (numberValidComponents > COMPONENT_Cb))
     1354                || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cr) && (numberValidComponents > COMPONENT_Cr)) ) )
    12961355          {
    12971356            hasResidual = true;
     
    13001359        }
    13011360
    1302         UInt uiTargetPartIdx;
    1303         if ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getSliceSegmentCurStartCUAddr() )
    1304         {
    1305           uiTargetPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU();
    1306         }
    1307         else
    1308         {
    1309           uiTargetPartIdx = 0;
    1310         }
    13111361        if ( hasResidual )
    13121362        {
    1313 #if !RDO_WITHOUT_DQP_BITS
    13141363          m_pcEntropyCoder->resetBits();
    1315           m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false );
     1364          m_pcEntropyCoder->encodeQP( rpcTempCU, 0, false );
    13161365          rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
    1317             rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    1318 #if H_3D_VSO // M11
     1366          rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     1367#if NH_3D_VSO // M11
    13191368          if ( m_pcRdCost->getUseLambdaScaleVSO())         
     1369          {
    13201370            rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );         
     1371          }
    13211372          else
    13221373#endif
    1323           rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    1324 #endif
     1374            rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    13251375
    13261376          Bool foundNonZeroCbf = false;
    1327           rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( uiTargetPartIdx ), rpcTempCU, 0, uiDepth, foundNonZeroCbf );
     1377          rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( 0 ), 0, uiDepth, foundNonZeroCbf );
    13281378          assert( foundNonZeroCbf );
    13291379        }
    13301380        else
    13311381        {
    1332           rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP
     1382          rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP
    13331383        }
    13341384      }
    13351385
    1336         m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    1337       Bool isEndOfSlice        = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES
    1338                                  && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3);
    1339       Bool isEndOfSliceSegment = rpcBestCU->getSlice()->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES
    1340                                  && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceSegmentArgument()<<3);
    1341       if(isEndOfSlice||isEndOfSliceSegment)
     1386      m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
     1387
     1388      // If the configuration being tested exceeds the maximum number of bytes for a slice / slice-segment, then
     1389      // a proper RD evaluation cannot be performed. Therefore, termination of the
     1390      // slice/slice-segment must be made prior to this CTU.
     1391      // This can be achieved by forcing the decision to be that of the rpcTempCU.
     1392      // The exception is each slice / slice-segment must have at least one CTU.
     1393      if (rpcBestCU->getTotalCost()!=MAX_DOUBLE)
    13421394      {
    1343         rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1;
     1395        const Bool isEndOfSlice        =    pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES
     1396                                         && ((pcSlice->getSliceBits()+rpcBestCU->getTotalBits())>pcSlice->getSliceArgument()<<3)
     1397                                         && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceCurStartCtuTsAddr())
     1398                                         && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr());
     1399        const Bool isEndOfSliceSegment =    pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES
     1400                                         && ((pcSlice->getSliceSegmentBits()+rpcBestCU->getTotalBits()) > pcSlice->getSliceSegmentArgument()<<3)
     1401                                         && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr());
     1402                                             // Do not need to check slice condition for slice-segment since a slice-segment is a subset of a slice.
     1403        if(isEndOfSlice||isEndOfSliceSegment)
     1404        {
     1405          rpcBestCU->getTotalCost()=MAX_DOUBLE;
     1406        }
    13441407      }
    1345       xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth);                                  // RD compare current larger prediction
    1346     }                                                                                  // with sub partitioned prediction.
    1347     }
    1348 
    1349 #if H_3D_VSO // M12
     1408
     1409      xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTempDebug) DEBUG_STRING_PASS_INTO(false) ); // RD compare current larger prediction
     1410                                                                                                                                                       // with sub partitioned prediction.
     1411    }
     1412  }
     1413#if NH_3D_VSO // M12
    13501414  if( m_pcRdCost->getUseRenModel() )
    13511415  {
    1352     UInt  uiWidth     = m_ppcRecoYuvBest[uiDepth]->getWidth   ( );
    1353     UInt  uiHeight    = m_ppcRecoYuvBest[uiDepth]->getHeight  ( );
    1354     Pel*  piSrc       = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 );
    1355     UInt  uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride  ( );
    1356     m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    1357   }
    1358 #endif
     1416    UInt  uiWidthRy     = m_ppcRecoYuvBest[uiDepth]->getWidth   ( COMPONENT_Y );
     1417    UInt  uiHeightRy    = m_ppcRecoYuvBest[uiDepth]->getHeight  ( COMPONENT_Y );
     1418    Pel*  piSrc       = m_ppcRecoYuvBest[uiDepth]->getAddr    ( COMPONENT_Y,  0 );
     1419    UInt  uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride  ( COMPONENT_Y );
     1420    m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidthRy, uiHeightRy );
     1421  }
     1422#endif
     1423
     1424  DEBUG_STRING_APPEND(sDebug_, sDebug);
     1425
    13591426  rpcBestCU->copyToPic(uiDepth);                                                     // Copy Best data to Picture for next partition prediction.
    13601427
    1361   xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, uiDepth, rpcBestCU, uiLPelX, uiTPelY );   // Copy Yuv data to picture Yuv
    1362   if( bBoundary ||(bSliceEnd && bInsidePicture))
     1428  xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getCtuRsAddr(), rpcBestCU->getZorderIdxInCtu(), uiDepth, uiDepth );   // Copy Yuv data to picture Yuv
     1429  if (bBoundary)
    13631430  {
    13641431    return;
     
    13671434  // Assert if Best prediction mode is NONE
    13681435  // Selected mode's RD-cost must be not MAX_DOUBLE.
    1369   assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE  );
    1370   assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE );
    1371   assert( rpcBestCU->getTotalCost     (   ) != MAX_DOUBLE );
     1436  assert( rpcBestCU->getPartitionSize ( 0 ) != NUMBER_OF_PART_SIZES       );
     1437  assert( rpcBestCU->getPredictionMode( 0 ) != NUMBER_OF_PREDICTION_MODES );
     1438  assert( rpcBestCU->getTotalCost     (   ) != MAX_DOUBLE                 );
    13721439}
    13731440
     
    13751442 * \param pcCU
    13761443 * \param uiAbsPartIdx
    1377  * \param uiDepth 
     1444 * \param uiDepth
    13781445 * \returns Void
    13791446 */
    1380 Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     1447Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx )
    13811448{
    13821449  TComPic* pcPic = pcCU->getPic();
     
    13841451
    13851452  //Calculate end address
    1386   UInt uiCUAddr = pcCU->getSCUAddr()+uiAbsPartIdx;
    1387 
    1388   UInt uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) % pcPic->getNumPartInCU();
    1389   UInt uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) / pcPic->getNumPartInCU();
    1390   UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
    1391   UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
    1392   UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
    1393   UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
    1394   while(uiPosX>=uiWidth||uiPosY>=uiHeight)
    1395   {
    1396     uiInternalAddress--;
    1397     uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
    1398     uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
    1399   }
    1400   uiInternalAddress++;
    1401   if(uiInternalAddress==pcCU->getPic()->getNumPartInCU())
    1402   {
    1403     uiInternalAddress = 0;
    1404     uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1);
    1405   }
    1406   UInt uiRealEndAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress);
    1407 
    1408   // Encode slice finish
    1409   Bool bTerminateSlice = false;
    1410   if (uiCUAddr+(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)) == uiRealEndAddress)
    1411   {
    1412     bTerminateSlice = true;
    1413   }
    1414   UInt uiGranularityWidth = g_uiMaxCUWidth;
    1415   uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
    1416   uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    1417   Bool granularityBoundary=((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth))
    1418     &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight));
    1419  
    1420   if(granularityBoundary)
     1453  const Int  currentCTUTsAddr = pcPic->getPicSym()->getCtuRsToTsAddrMap(pcCU->getCtuRsAddr());
     1454  const Bool isLastSubCUOfCtu = pcCU->isLastSubCUOfCtu(uiAbsPartIdx);
     1455  if ( isLastSubCUOfCtu )
    14211456  {
    14221457    // The 1-terminating bit is added to all streams, so don't add it here when it's 1.
    1423     if (!bTerminateSlice)
    1424       m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 );
    1425   }
    1426  
    1427   Int numberOfWrittenBits = 0;
    1428   if (m_pcBitCounter)
    1429   {
    1430     numberOfWrittenBits = m_pcEntropyCoder->getNumberOfWrittenBits();
    1431   }
    1432  
    1433   // Calculate slice end IF this CU puts us over slice bit size.
    1434   UInt iGranularitySize = pcCU->getPic()->getNumPartInCU();
    1435   Int iGranularityEnd = ((pcCU->getSCUAddr()+uiAbsPartIdx)/iGranularitySize)*iGranularitySize;
    1436   if(iGranularityEnd<=pcSlice->getSliceSegmentCurStartCUAddr())
    1437   {
    1438     iGranularityEnd+=max(iGranularitySize,(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)));
    1439   }
    1440   // Set slice end parameter
    1441   if(pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceBits()+numberOfWrittenBits>pcSlice->getSliceArgument()<<3)
    1442   {
    1443     pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd);
    1444     pcSlice->setSliceCurEndCUAddr(iGranularityEnd);
    1445     return;
    1446   }
    1447   // Set dependent slice end parameter
    1448   if(pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceSegmentBits()+numberOfWrittenBits > pcSlice->getSliceSegmentArgument()<<3)
    1449   {
    1450     pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd);
    1451     return;
    1452   }
    1453   if(granularityBoundary)
    1454   {
    1455     pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) );
    1456     pcSlice->setSliceSegmentBits(pcSlice->getSliceSegmentBits()+numberOfWrittenBits);
    1457     if (m_pcBitCounter)
    1458     {
    1459       m_pcEntropyCoder->resetBits();     
     1458    // i.e. when the slice segment CurEnd CTU address is the current CTU address+1.
     1459    if (pcSlice->getSliceSegmentCurEndCtuTsAddr() != currentCTUTsAddr+1)
     1460    {
     1461      m_pcEntropyCoder->encodeTerminatingBit( 0 );
    14601462    }
    14611463  }
     
    14881490    iQpOffset = Int(floor( dQpOffset + 0.49999 ));
    14891491  }
    1490   return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset );
     1492
     1493  return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQp+iQpOffset );
    14911494}
    14921495
     
    14941497 * \param pcCU
    14951498 * \param uiAbsPartIdx
    1496  * \param uiDepth 
     1499 * \param uiDepth
    14971500 * \returns Void
    14981501 */
    14991502Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    15001503{
    1501   TComPic* pcPic = pcCU->getPic();
    1502  
    1503   Bool bBoundary = false;
    1504   UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
    1505   UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
    1506   UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    1507   UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
    1508  
     1504        TComPic   *const pcPic   = pcCU->getPic();
     1505        TComSlice *const pcSlice = pcCU->getSlice();
     1506  const TComSPS   &sps =*(pcSlice->getSPS());
     1507  const TComPPS   &pps =*(pcSlice->getPPS());
     1508
     1509  const UInt maxCUWidth  = sps.getMaxCUWidth();
     1510  const UInt maxCUHeight = sps.getMaxCUHeight();
     1511
     1512        Bool bBoundary = false;
     1513        UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
     1514  const UInt uiRPelX   = uiLPelX + (maxCUWidth>>uiDepth)  - 1;
     1515        UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
     1516  const UInt uiBPelY   = uiTPelY + (maxCUHeight>>uiDepth) - 1;
     1517
    15091518#if H_MV_ENC_DEC_TRAC
    15101519  DTRACE_CU_S("=========== coding_quadtree ===========\n")
    15111520  DTRACE_CU("x0", uiLPelX)
    15121521  DTRACE_CU("x1", uiTPelY)
    1513   DTRACE_CU("log2CbSize", g_uiMaxCUWidth>>uiDepth)
     1522  DTRACE_CU("log2CbSize", maxCUWidth>>uiDepth )
    15141523  DTRACE_CU("cqtDepth"  , uiDepth)
    15151524#endif
    15161525
    1517   TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
    1518   // If slice start is within this cu...
    1519   Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx &&
    1520     pcSlice->getSliceSegmentCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) );
    1521   // We need to split, so don't try these modes.
    1522   if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     1526  if( ( uiRPelX < sps.getPicWidthInLumaSamples() ) && ( uiBPelY < sps.getPicHeightInLumaSamples() ) )
    15231527  {
    15241528    m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
     
    15281532    bBoundary = true;
    15291533  }
    1530  
    1531   if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary )
    1532   {
    1533     UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2;
    1534     if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
     1534
     1535  if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) ) || bBoundary )
     1536  {
     1537    UInt uiQNumParts = ( pcPic->getNumPartitionsInCtu() >> (uiDepth<<1) )>>2;
     1538    if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP())
    15351539    {
    15361540      setdQPFlag(true);
    15371541    }
     1542
     1543    if( uiDepth == pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcSlice->getUseChromaQpAdj())
     1544    {
     1545      setCodeChromaQpAdjFlag(true);
     1546    }
     1547
    15381548    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts )
    15391549    {
    15401550      uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
    15411551      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    1542       Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurEndCUAddr();
    1543       if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     1552      if( ( uiLPelX < sps.getPicWidthInLumaSamples() ) && ( uiTPelY < sps.getPicHeightInLumaSamples() ) )
    15441553      {
    15451554        xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 );
     
    15481557    return;
    15491558  }
    1550  
     1559
    15511560#if H_MV_ENC_DEC_TRAC
    15521561  DTRACE_CU_S("=========== coding_unit ===========\n")
    15531562#endif
    15541563
    1555   if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP())
     1564
     1565  if( uiDepth <= pps.getMaxCuDQPDepth() && pps.getUseDQP())
    15561566  {
    15571567    setdQPFlag(true);
    15581568  }
    1559   if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
     1569
     1570  if( uiDepth <= pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcSlice->getUseChromaQpAdj())
     1571  {
     1572    setCodeChromaQpAdjFlag(true);
     1573  }
     1574
     1575  if (pps.getTransquantBypassEnableFlag())
    15601576  {
    15611577    m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
    15621578  }
    1563   if( !pcCU->getSlice()->isIntra() )
     1579
     1580  if( !pcSlice->isIntra() )
    15641581  {
    15651582    m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx );
    15661583  }
    1567  
     1584
    15681585  if( pcCU->isSkipped( uiAbsPartIdx ) )
    15691586  {
     
    15731590    DTRACE_PU("x1", uiTPelY)
    15741591#endif
     1592
    15751593    m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx );
    1576 #if H_3D_ARP
     1594#if NH_3D_ARP
    15771595    m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx );
    15781596#endif
    1579 #if H_3D_IC
     1597#if NH_3D_IC
    15801598    m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx );
    15811599#endif
    1582     finishCU(pcCU,uiAbsPartIdx,uiDepth);
     1600
     1601    finishCU(pcCU,uiAbsPartIdx);
    15831602    return;
    15841603  }
    1585 #if H_3D
     1604
     1605#if NH_3D_DIS
    15861606  m_pcEntropyCoder->encodeDIS( pcCU, uiAbsPartIdx );
    15871607  if(!pcCU->getDISFlag(uiAbsPartIdx))
    15881608  {
    15891609#endif
    1590 
    15911610  m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx );
    1592  
    15931611  m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth );
    1594  
     1612
    15951613  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
    15961614  {
    15971615    m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx );
     1616
    15981617    if(pcCU->getIPCMFlag(uiAbsPartIdx))
    15991618    {
    1600 #if H_3D_DIM_SDC
    1601       m_pcEntropyCoder->encodeSDCFlag( pcCU, uiAbsPartIdx, false );
     1619#if NH_3D_SDC_INTRA
     1620      m_pcEntropyCoder->encodeSDCFlag( pcCU, uiAbsPartIdx );
    16021621#endif 
     1622
    16031623      // Encode slice finish
    1604       finishCU(pcCU,uiAbsPartIdx,uiDepth);
     1624      finishCU(pcCU,uiAbsPartIdx);
    16051625      return;
    16061626    }
     
    16091629  // prediction Info ( Intra : direction mode, Inter : Mv, reference idx )
    16101630  m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx );
    1611 #if H_3D
     1631#if NH_3D_DBBP
    16121632  m_pcEntropyCoder->encodeDBBPFlag( pcCU, uiAbsPartIdx );
    16131633#endif
    1614 #if H_3D_DIM_SDC
    1615   m_pcEntropyCoder->encodeSDCFlag( pcCU, uiAbsPartIdx, false );
     1634#if NH_3D_SDC_INTRA
     1635  m_pcEntropyCoder->encodeSDCFlag( pcCU, uiAbsPartIdx );
    16161636#endif 
    1617 #if H_3D_ARP
     1637#if NH_3D_ARP
    16181638  m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx );
    16191639#endif
    1620 #if H_3D_IC
     1640#if NH_3D_IC
    16211641  m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx );
    16221642#endif
     1643
    16231644  // Encode Coefficients
    16241645  Bool bCodeDQP = getdQPFlag();
    1625 #if H_3D_DISABLE_CHROMA
    1626   m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx), bCodeDQP, false );
    1627 #else
    1628   m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx), bCodeDQP );
    1629 #endif
     1646  Bool codeChromaQpAdj = getCodeChromaQpAdjFlag();
     1647  m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, bCodeDQP, codeChromaQpAdj );
     1648  setCodeChromaQpAdjFlag( codeChromaQpAdj );
    16301649  setdQPFlag( bCodeDQP );
    1631 #if H_3D
    1632   }
    1633 #endif
     1650#if NH_3D_DIS
     1651  }
     1652#endif
     1653
     1654
    16341655  // --- write terminating bit ---
    1635   finishCU(pcCU,uiAbsPartIdx,uiDepth);
     1656  finishCU(pcCU,uiAbsPartIdx);
    16361657}
    16371658
    1638 Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) 
     1659Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg)
    16391660{
    16401661  Int k, i, j, jj;
     
    16511672    diff[k+6] = piOrg[6] ;
    16521673    diff[k+7] = piOrg[7] ;
    1653  
     1674
    16541675    piOrg += iStrideOrg;
    16551676  }
    1656  
     1677
    16571678  //horizontal
    16581679  for (j=0; j < 8; j++)
     
    16671688    m2[j][6] = diff[jj+2] - diff[jj+6];
    16681689    m2[j][7] = diff[jj+3] - diff[jj+7];
    1669    
     1690
    16701691    m1[j][0] = m2[j][0] + m2[j][2];
    16711692    m1[j][1] = m2[j][1] + m2[j][3];
     
    16761697    m1[j][6] = m2[j][4] - m2[j][6];
    16771698    m1[j][7] = m2[j][5] - m2[j][7];
    1678    
     1699
    16791700    m2[j][0] = m1[j][0] + m1[j][1];
    16801701    m2[j][1] = m1[j][0] - m1[j][1];
     
    16861707    m2[j][7] = m1[j][6] - m1[j][7];
    16871708  }
    1688  
     1709
    16891710  //vertical
    16901711  for (i=0; i < 8; i++)
     
    16981719    m3[6][i] = m2[2][i] - m2[6][i];
    16991720    m3[7][i] = m2[3][i] - m2[7][i];
    1700    
     1721
    17011722    m1[0][i] = m3[0][i] + m3[2][i];
    17021723    m1[1][i] = m3[1][i] + m3[3][i];
     
    17071728    m1[6][i] = m3[4][i] - m3[6][i];
    17081729    m1[7][i] = m3[5][i] - m3[7][i];
    1709    
     1730
    17101731    m2[0][i] = m1[0][i] + m1[1][i];
    17111732    m2[1][i] = m1[0][i] - m1[1][i];
     
    17171738    m2[7][i] = m1[6][i] - m1[7][i];
    17181739  }
    1719  
     1740
    17201741  for (i = 0; i < 8; i++)
    17211742  {
     
    17301751}
    17311752
    1732 Int  TEncCu::updateLCUDataISlice(TComDataCU* pcCU, Int LCUIdx, Int width, Int height)
     1753Int  TEncCu::updateCtuDataISlice(TComDataCU* pCtu, Int width, Int height)
    17331754{
    1734   Int  xBl, yBl; 
     1755  Int  xBl, yBl;
    17351756  const Int iBlkSize = 8;
    17361757
    1737   Pel* pOrgInit   = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
    1738   Int  iStrideOrig = pcCU->getPic()->getPicYuvOrg()->getStride();
     1758  Pel* pOrgInit   = pCtu->getPic()->getPicYuvOrg()->getAddr(COMPONENT_Y, pCtu->getCtuRsAddr(), 0);
     1759  Int  iStrideOrig = pCtu->getPic()->getPicYuvOrg()->getStride(COMPONENT_Y);
    17391760  Pel  *pOrg;
    17401761
     
    17441765    for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize)
    17451766    {
    1746       pOrg = pOrgInit + iStrideOrig*yBl + xBl; 
     1767      pOrg = pOrgInit + iStrideOrig*yBl + xBl;
    17471768      iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig);
    17481769    }
     
    17541775 * \param rpcBestCU
    17551776 * \param rpcTempCU
    1756  * \returns Void
     1777 * \param earlyDetectionSkipMode
    17571778 */
    1758 Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode )
     1779Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU DEBUG_STRING_FN_DECLARE(sDebug), Bool *earlyDetectionSkipMode )
    17591780{
    17601781  assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE );
    1761 #if H_3D_IV_MERGE
     1782  if(getFastDeltaQp())
     1783  {
     1784    return;   // never check merge in fast deltaqp mode
     1785  }
     1786
     1787  D_PRINT_INC_INDENT( g_traceModeCheck, "xCheckRDCostMerge2Nx2N" );
     1788
     1789#if NH_3D_MLC
    17621790  TComMvField  cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
    17631791  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
     
    17741802  }
    17751803  UChar uhDepth = rpcTempCU->getDepth( 0 );
    1776 #if H_3D_IC
     1804#if NH_3D_IC
    17771805  Bool bICFlag = rpcTempCU->getICFlag( 0 );
    17781806#endif
    1779 #if H_3D_VSO // M1  //necessary here?
     1807#if NH_3D_VSO // M1  //necessary here?
    17801808  if( m_pcRdCost->getUseRenModel() )
    17811809  {
    1782     UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
    1783     UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
    1784     Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
    1785     UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
     1810    UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y );
     1811    UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( COMPONENT_Y );
     1812    Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getAddr  ( COMPONENT_Y );
     1813    UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride( COMPONENT_Y );
    17861814    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    17871815  }
    17881816#endif
    17891817
    1790 #if H_3D_ARP
     1818#if NH_3D_ARP
    17911819  DisInfo cOrigDisInfo = rpcTempCU->getDvInfo(0);
    17921820#else
    1793   rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
    1794 #endif
    1795 
    1796 #if H_3D_VSP
    1797 #if !H_3D_ARP
     1821#endif
     1822
     1823  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level
     1824
     1825#if NH_3D_SPIVMP
     1826  Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM];
     1827  memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
     1828  TComMvField*  pcMvFieldSP;
     1829  UChar* puhInterDirSP;
     1830  pcMvFieldSP = new TComMvField[rpcTempCU->getPic()->getPicSym()->getNumPartitionsInCtu()*2];
     1831  puhInterDirSP = new UChar[rpcTempCU->getPic()->getPicSym()->getNumPartitionsInCtu()];
     1832#endif
     1833
     1834#if NH_3D_VSP
     1835#if !NH_3D_ARP
    17981836  Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
    17991837  memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
    1800   InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM];
    1801   rpcTempCU->m_bAvailableFlagA1 = 0;
    1802   rpcTempCU->m_bAvailableFlagB1 = 0;
    1803   rpcTempCU->m_bAvailableFlagB0 = 0;
    1804   rpcTempCU->m_bAvailableFlagA0 = 0;
    1805   rpcTempCU->m_bAvailableFlagB2 = 0;
     1838#if NH_3D_MLC
     1839  rpcTempCU->initAvailableFlags();
     1840#endif
    18061841  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
    1807   rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag,inheritedVSPDisInfo, numValidMergeCand );
    1808 #endif
    1809 #else
    1810 #if H_3D
    1811   rpcTempCU->m_bAvailableFlagA1 = 0;
    1812   rpcTempCU->m_bAvailableFlagB1 = 0;
    1813   rpcTempCU->m_bAvailableFlagB0 = 0;
    1814   rpcTempCU->m_bAvailableFlagA0 = 0;
    1815   rpcTempCU->m_bAvailableFlagB2 = 0;
    1816   rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
    1817   rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
    1818 #else
     1842#if NH_3D_MLC
     1843  rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours
     1844#if NH_3D_SPIVMP
     1845    , pcMvFieldSP, puhInterDirSP
     1846#endif
     1847    , numValidMergeCand
     1848    );
     1849
     1850  rpcTempCU->buildMCL( cMvFieldNeighbours,uhInterDirNeighbours, vspFlag
     1851#if NH_3D_SPIVMP
     1852    , bSPIVMPFlag
     1853#endif
     1854    , numValidMergeCand
     1855    );
     1856#endif
     1857#endif
     1858#else
     1859#if NH_3D_MLC
     1860  rpcTempCU->initAvailableFlags();
     1861#endif
    18191862  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
    1820 #endif
    1821 #endif
    1822 
    1823 #if H_3D_IV_MERGE
     1863#if NH_3D_MLC
     1864  rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours
     1865#if H_3D_SPIVMP
     1866    , pcMvFieldSP, puhInterDirSP
     1867#endif
     1868    , numValidMergeCand
     1869    );
     1870#if NH_3D_MLC
     1871  rpcTempCU->buildMCL( cMvFieldNeighbours,uhInterDirNeighbours
     1872#if H_3D_SPIVMP
     1873    , bSPIVMPFlag
     1874#endif
     1875    , numValidMergeCand
     1876    );
     1877#endif
     1878#endif
     1879#endif
     1880
     1881#if NH_3D_MLC
    18241882  Int mergeCandBuffer[MRG_MAX_NUM_CANDS_MEM];
    18251883#else
    18261884  Int mergeCandBuffer[MRG_MAX_NUM_CANDS];
    18271885#endif
    1828 #if H_3D_ARP
    1829 for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
    1830 #else
    1831 for( UInt ui = 0; ui < numValidMergeCand; ++ui )
     1886#if NH_3D_MLC
     1887  for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
     1888#else
     1889  for( UInt ui = 0; ui < numValidMergeCand; ++ui )
    18321890#endif
    18331891  {
     
    18421900    iteration = 1;
    18431901  }
    1844   else 
     1902  else
    18451903  {
    18461904    iteration = 2;
    18471905  }
    1848 
    1849 #if H_3D_ARP
     1906  DEBUG_STRING_NEW(bestStr)
     1907
     1908#if NH_3D_ARP
    18501909  Int nARPWMax = rpcTempCU->getSlice()->getARPStepNum() - 1;
     1910#if NH_3D_IC
    18511911  if( nARPWMax < 0 || bICFlag )
     1912#else
     1913  if( nARPWMax < 0 )
     1914#endif
    18521915  {
    18531916    nARPWMax = 0;
     
    18551918  for( Int nARPW=nARPWMax; nARPW >= 0 ; nARPW-- )
    18561919  {
     1920#if NH_3D
     1921#if DEBUG_STRING
     1922    bestStr.clear();
     1923#endif
     1924#endif
     1925#if NH_3D_IV_MERGE
    18571926    memset( mergeCandBuffer, 0, MRG_MAX_NUM_CANDS_MEM*sizeof(Int) );
     1927#else
     1928    memset( mergeCandBuffer, 0, MRG_MAX_NUM_CANDS * sizeof(Int) );
     1929#endif
    18581930    rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
    18591931    rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth );
    1860 #if H_3D_IC
     1932#if NH_3D_IC
    18611933    rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth );
    18621934#endif
    18631935    rpcTempCU->getDvInfo(0) = cOrigDisInfo;
    1864     rpcTempCU->setDvInfoSubParts(cOrigDisInfo, 0, 0, uhDepth );
     1936    rpcTempCU->setDvInfoSubParts(cOrigDisInfo, 0, uhDepth );
     1937#if NH_3D_VSP
    18651938    Int vspFlag[MRG_MAX_NUM_CANDS_MEM];
    18661939    memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM);
    1867 #if H_3D_SPIVMP
    1868     Bool bSPIVMPFlag[MRG_MAX_NUM_CANDS_MEM];
    1869     memset(bSPIVMPFlag, false, sizeof(Bool)*MRG_MAX_NUM_CANDS_MEM);
    1870     TComMvField*  pcMvFieldSP;
    1871     UChar* puhInterDirSP;
    1872     pcMvFieldSP = new TComMvField[rpcTempCU->getPic()->getPicSym()->getNumPartition()*2];
    1873     puhInterDirSP = new UChar[rpcTempCU->getPic()->getPicSym()->getNumPartition()];
    1874 #endif
    1875 #if H_3D
     1940#endif
     1941#if NH_3D
     1942#if NH_3D_MLC
    18761943    rpcTempCU->initAvailableFlags();
     1944#endif
    18771945    rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
    18781946    rpcTempCU->xGetInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours
    1879 #if H_3D_SPIVMP
     1947#if NH_3D_SPIVMP
    18801948      , pcMvFieldSP, puhInterDirSP
    18811949#endif
     
    18831951      );
    18841952
    1885     rpcTempCU->buildMCL( cMvFieldNeighbours,uhInterDirNeighbours, vspFlag
    1886 #if H_3D_SPIVMP
     1953    rpcTempCU->buildMCL( cMvFieldNeighbours,uhInterDirNeighbours
     1954#if NH_3D_VSP
     1955      , vspFlag
     1956#endif
     1957#if NH_3D_SPIVMP
    18871958      , bSPIVMPFlag
    18881959#endif
     
    18911962
    18921963#else
    1893     rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag, numValidMergeCand );
     1964    rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
    18941965#endif
    18951966
     
    18991970  for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual )
    19001971  {
     1972    D_PRINT_INC_INDENT ( g_traceModeCheck, "uiNoResidual: " + n2s( uiNoResidual) );
     1973
    19011974    for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
    1902     {     
    1903 #if H_3D_IC
     1975    {
     1976#if NH_3D_IC
    19041977      if( rpcTempCU->getSlice()->getApplyIC() && rpcTempCU->getSlice()->getIcSkipParseFlag() )
    19051978      {
     
    19101983      }
    19111984#endif
     1985      D_PRINT_INC_INDENT ( g_traceModeCheck, "uiMergeCand: "+  n2s(uiMergeCand) );
     1986
    19121987      if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1))
    19131988      {
    19141989        if( !(bestIsSkip && uiNoResidual == 0) )
    19151990        {
     1991          DEBUG_STRING_NEW(tmpStr)
    19161992          // set MC parameters
    1917           rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level
    1918           rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag,     0, uhDepth );
    1919           rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
    1920 #if H_3D_IC
     1993          rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to CTU level
     1994#if NH_3D_IC
    19211995          rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth );
    19221996#endif
    1923 #if H_3D_ARP
     1997          rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag, 0, uhDepth );
     1998          rpcTempCU->setChromaQpAdjSubParts( bTransquantBypassFlag ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uhDepth );
     1999          rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level
     2000          rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to CTU level
     2001          rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to CTU level
     2002#if NH_3D_ARP
    19242003          rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth );
    19252004#endif
    1926           rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level
    1927           rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level
    1928 #if H_3D_VSP
     2005
     2006#if NH_3D_VSP
    19292007          rpcTempCU->setVSPFlagSubParts( vspFlag[uiMergeCand], 0, 0, uhDepth );
    19302008#endif
    1931 #if H_3D_SPIVMP
     2009#if NH_3D_SPIVMP
    19322010          rpcTempCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeCand], 0, 0, uhDepth);
    19332011          if (bSPIVMPFlag[uiMergeCand])
     
    19482026          else
    19492027#endif
    1950 #if H_3D_VSP
    19512028          {
     2029#if NH_3D_VSP
    19522030            if ( vspFlag[uiMergeCand] )
    19532031            {
     
    19792057            {
    19802058#endif
    1981               rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
    1982               rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
    1983               rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
    1984 #if H_3D_VSP
     2059            rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to CTU level
     2060            rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
     2061            rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
     2062#if NH_3D_VSP
    19852063            }
     2064#endif
    19862065          }
    1987 #endif
    19882066          // do MC
    19892067          m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
    19902068          // estimate residual and encode everything
    1991 #if H_3D_VSO //M2
     2069#if NH_3D_VSO //M2
    19922070          if( m_pcRdCost->getUseRenModel() )
    19932071          { //Reset
    1994             UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth    ();
    1995             UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight   ();
    1996             Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr ();
    1997             UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride   ();
     2072            UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth    ( COMPONENT_Y );
     2073            UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight   ( COMPONENT_Y );
     2074            Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getAddr     ( COMPONENT_Y );
     2075            UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride   ( COMPONENT_Y );
    19982076            m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    19992077          }
    20002078#endif
    20012079          m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU,
    2002             m_ppcOrigYuv    [uhDepth],
    2003             m_ppcPredYuvTemp[uhDepth],
    2004             m_ppcResiYuvTemp[uhDepth],
    2005             m_ppcResiYuvBest[uhDepth],
    2006             m_ppcRecoYuvTemp[uhDepth],
    2007             (uiNoResidual? true:false));
    2008 
    2009 
    2010           if ( uiNoResidual == 0 && rpcTempCU->getQtRootCbf(0) == 0 )
     2080                                                     m_ppcOrigYuv    [uhDepth],
     2081                                                     m_ppcPredYuvTemp[uhDepth],
     2082                                                     m_ppcResiYuvTemp[uhDepth],
     2083                                                     m_ppcResiYuvBest[uhDepth],
     2084                                                     m_ppcRecoYuvTemp[uhDepth],
     2085                                                     (uiNoResidual != 0) DEBUG_STRING_PASS_INTO(tmpStr) );
     2086
     2087#if DEBUG_STRING
     2088          DebugInterPredResiReco(tmpStr, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0)));
     2089#endif
     2090
     2091          if ((uiNoResidual == 0) && (rpcTempCU->getQtRootCbf(0) == 0))
    20112092          {
    20122093            // If no residual when allowing for one, then set mark to not try case where residual is forced to 0
    20132094            mergeCandBuffer[uiMergeCand] = 1;
    20142095          }
    2015 
    2016           rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth );
    2017 #if H_3D
     2096#if NH_3D_DIS
    20182097          rpcTempCU->setDISFlagSubParts( false, 0, uhDepth );
    20192098#endif
    2020 #if H_3D_VSP // possible bug fix
     2099#if NH_3D_VSP
    20212100          if( rpcTempCU->getSkipFlag(0) )
    20222101          {
     
    20242103          }
    20252104#endif
    2026 #if H_3D_INTER_SDC
     2105#if NH_3D_SDC_INTER
    20272106          TComDataCU *rpcTempCUPre = rpcTempCU;
    20282107#endif
    20292108          Int orgQP = rpcTempCU->getQP( 0 );
    20302109          xCheckDQP( rpcTempCU );
    2031           xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
    2032 #if H_3D_INTER_SDC
     2110          xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(bestStr) DEBUG_STRING_PASS_INTO(tmpStr));
     2111#if NH_3D_SDC_INTER
    20332112          if( rpcTempCU->getSlice()->getInterSdcFlag() && !uiNoResidual )
    20342113          {
     
    20572136              }
    20582137              rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth );
    2059 #if H_3D
     2138#if NH_3D_DIS
    20602139              rpcTempCU->setDISFlagSubParts( false, 0, uhDepth );
    20612140#endif
    20622141              rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth );
    2063               rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth );
    2064 #if H_3D_VSO //M2
     2142              rpcTempCU->setCbfSubParts( 1, COMPONENT_Y, 0, uhDepth );
     2143#if NH_3D_VSO //M2
    20652144              if( m_pcRdCost->getUseRenModel() )
    20662145              { //Reset
    2067                 UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth    ();
    2068                 UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight   ();
    2069                 Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr ();
    2070                 UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride   ();
     2146                UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth    ( COMPONENT_Y );
     2147                UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight   ( COMPONENT_Y );
     2148                Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getAddr     ( COMPONENT_Y );
     2149                UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride   ( COMPONENT_Y );
    20712150                m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    20722151              }
     
    20982177          }
    20992178#endif
     2179
    21002180          rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag );
    21012181
    21022182          if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
    21032183          {
    2104 #if H_3D_INTER_SDC
     2184#if NH_3D_SDC_INTER
    21052185            if( rpcTempCU->getSlice()->getInterSdcFlag() )
    21062186            {
     
    21102190            {
    21112191#endif
    2112               bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
    2113 #if H_3D_INTER_SDC
     2192            bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
     2193#if NH_3D_SDC_INTER
    21142194            }
    21152195#endif
     
    21172197        }
    21182198      }
     2199      D_DEC_INDENT( g_traceModeCheck );
    21192200    }
    21202201
     
    21272208          *earlyDetectionSkipMode = true;
    21282209        }
    2129         else
     2210        else if(m_pcEncCfg->getFastSearch() != SELECTIVE)
    21302211        {
    21312212          Int absoulte_MV=0;
     
    21482229      }
    21492230    }
    2150   }
    2151 #if H_3D_SPIVMP
     2231    D_DEC_INDENT( g_traceModeCheck );
     2232  }
     2233  DEBUG_STRING_APPEND(sDebug, bestStr)
     2234#if NH_3D_ARP
     2235 }
     2236#endif
     2237#if NH_3D_SPIVMP
    21522238 delete[] pcMvFieldSP;
    21532239 delete[] puhInterDirSP;
    21542240#endif
    2155 #if H_3D_ARP
    2156  }
    2157 #endif
     2241 D_DEC_INDENT( g_traceModeCheck );
    21582242}
    21592243
    21602244
    21612245#if AMP_MRG
    2162 #if  H_3D_FAST_TEXTURE_ENCODING
    2163 Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bFMD, Bool bUseMRG)
    2164 #else
    2165 Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bUseMRG)
     2246#if  NH_3D_FAST_TEXTURE_ENCODING
     2247Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize DEBUG_STRING_FN_DECLARE(sDebug), Bool bFMD, Bool bUseMRG)
     2248#else
     2249Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize DEBUG_STRING_FN_DECLARE(sDebug), Bool bUseMRG)
    21662250#endif
    21672251#else
     
    21692253#endif
    21702254{
    2171 #if H_3D
     2255  DEBUG_STRING_NEW(sTest)
     2256
     2257  if(getFastDeltaQp())
     2258  {
     2259    const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS());
     2260    const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>(sps.getLog2DiffMaxMinCodingBlockSize()), sps.getMaxCUHeight(), 32u);
     2261    if(ePartSize != SIZE_2Nx2N || rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxSize)
     2262    {
     2263      return; // only check necessary 2Nx2N Inter in fast deltaqp mode
     2264    }
     2265  }
     2266
     2267  D_PRINT_INC_INDENT(g_traceModeCheck,   "xCheckRDCostInter; ePartSize:" + n2s( ePartSize) );
     2268
     2269
     2270  // prior to this, rpcTempCU will have just been reset using rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
     2271#if NH_3D_ARP
    21722272  const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0);
    21732273#endif
    2174 #if  H_3D_FAST_TEXTURE_ENCODING
     2274#if  NH_3D_FAST_TEXTURE_ENCODING
    21752275  if(!(bFMD && (ePartSize == SIZE_2Nx2N)))  //have  motion estimation or merge check
    21762276  {
    21772277#endif
    2178     UChar uhDepth = rpcTempCU->getDepth( 0 );
    2179 #if H_3D_ARP
     2278  UChar uhDepth = rpcTempCU->getDepth( 0 );
     2279#if NH_3D_ARP
    21802280    Bool bFirstTime = true;
    21812281    Int nARPWMax    = rpcTempCU->getSlice()->getARPStepNum() - 1;
     2282#if NH_3D_IC
    21822283    if( nARPWMax < 0 || ePartSize != SIZE_2Nx2N || rpcTempCU->getICFlag(0) )
     2284#else
     2285    if( nARPWMax < 0 || ePartSize != SIZE_2Nx2N )
     2286#endif
    21832287    {
    21842288      nARPWMax = 0;
     
    21872291    for( Int nARPW = 0; nARPW <= nARPWMax; nARPW++ )
    21882292    {
     2293#if DEBUG_STRING && H_MV_ENC_DEC_TRAC
     2294      sTest.clear();
     2295#endif
     2296
    21892297      if( !bFirstTime && rpcTempCU->getSlice()->getIvResPredFlag() )
    21902298      {
     
    21922300      }
    21932301#endif
    2194 #if H_3D_VSO // M3
     2302#if NH_3D_VSO // M3
    21952303      if( m_pcRdCost->getUseRenModel() )
    21962304      {
    2197         UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
    2198         UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
    2199         Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
    2200         UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
     2305        UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y );
     2306        UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( COMPONENT_Y );
     2307        Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getAddr  ( COMPONENT_Y );
     2308        UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride( COMPONENT_Y );
    22012309        m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    22022310      }
    22032311#endif
    2204 
    2205       rpcTempCU->setDepthSubParts( uhDepth, 0 );
    2206 
    2207       rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth );
    2208 #if H_3D
     2312#if NH_3D_DIS
    22092313      rpcTempCU->setDISFlagSubParts( false, 0, uhDepth );
    22102314#endif
    2211       rpcTempCU->setPartSizeSubParts  ( ePartSize,  0, uhDepth );
    2212       rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
    2213 #if H_3D_ARP
     2315  rpcTempCU->setPartSizeSubParts  ( ePartSize,  0, uhDepth );
     2316  rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
     2317  rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uhDepth );
     2318#if NH_3D_ARP
    22142319      rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth );
    22152320#endif
    2216 #if H_3D_ARP
     2321#if NH_3D_ARP
    22172322      if( bFirstTime == false && nARPWMax )
    22182323      {
     
    22272332#endif
    22282333#if AMP_MRG
    2229         rpcTempCU->setMergeAMP (true);
    2230 #if  H_3D_FAST_TEXTURE_ENCODING
    2231         m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bFMD, false, bUseMRG );
    2232 #else
    2233         m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], false, bUseMRG );
    2234 #endif
    2235 #else 
    2236         m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] );
    2237 #endif
    2238 #if H_3D_ARP
     2334  rpcTempCU->setMergeAMP (true);
     2335#if  NH_3D_FAST_TEXTURE_ENCODING
     2336        m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] DEBUG_STRING_PASS_INTO(sTest), bFMD, false, bUseMRG );
     2337#else
     2338  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] DEBUG_STRING_PASS_INTO(sTest), false, bUseMRG );
     2339#endif
     2340
     2341#else
     2342  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] );
     2343#endif
     2344#if NH_3D_ARP
    22392345        if( nARPWMax )
    22402346        {
     
    22452351
    22462352#if AMP_MRG
    2247       if ( !rpcTempCU->getMergeAMP() )
    2248       {
    2249 #if H_3D_ARP
    2250         if( nARPWMax )
    2251         {
    2252           continue;
    2253         }
    2254         else
    2255 #endif
    2256           return;
    2257       }
    2258 #endif
    2259 
     2353  if ( !rpcTempCU->getMergeAMP() )
     2354  {
     2355#if NH_3D_ARP
     2356    if( nARPWMax )
     2357    {
     2358      continue;
     2359    }
     2360    else
     2361#endif
     2362    {
     2363      D_DEC_INDENT( g_traceModeCheck );
     2364      return;
     2365    }
     2366  }
     2367#endif
    22602368#if KWU_RC_MADPRED_E0227
    22612369      if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
     
    22672375      }
    22682376#endif
    2269       m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false );
    2270 #if H_3D_VSP // possible bug fix
    2271       if( rpcTempCU->getQtRootCbf(0)==0 )
    2272       {
    2273         rpcTempCU->setTrIdxSubParts(0, 0, uhDepth);
    2274       }
    2275 #endif
    2276 #if H_3D_VSO // M4
    2277       if( m_pcRdCost->getUseLambdaScaleVSO() )
    2278         rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    2279       else
    2280 #endif
    2281         rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    2282 #if H_3D_INTER_SDC
     2377
     2378  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false DEBUG_STRING_PASS_INTO(sTest) );
     2379#if NH_3D_VSP
     2380  if( rpcTempCU->getQtRootCbf(0)==0 )
     2381  {
     2382    rpcTempCU->setTrIdxSubParts(0, 0, uhDepth);
     2383  }
     2384#endif
     2385#if NH_3D_VSO // M4
     2386  if( m_pcRdCost->getUseLambdaScaleVSO() )
     2387  {
     2388    rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     2389  }
     2390  else           
     2391#endif
     2392    rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     2393
     2394#if DEBUG_STRING
     2395  DebugInterPredResiReco(sTest, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0)));
     2396#endif
     2397#if NH_3D_SDC_INTER
    22832398      TComDataCU *rpcTempCUPre = rpcTempCU;
    22842399#endif
    2285       xCheckDQP( rpcTempCU );
    2286       xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
    2287 #if H_3D_INTER_SDC
     2400
     2401  xCheckDQP( rpcTempCU );
     2402  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest));
     2403#if NH_3D_SDC_INTER
    22882404      if( rpcTempCU->getSlice()->getInterSdcFlag() && ePartSize == SIZE_2Nx2N)
    22892405      {
     
    23142430          }
    23152431          rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth );
    2316 #if H_3D
     2432#if NH_3D_DIS
    23172433          rpcTempCU->setDISFlagSubParts( false, 0, uhDepth );
    23182434#endif
    23192435          rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth );
    2320           rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth );
    2321 #if H_3D_VSO // M3
     2436          rpcTempCU->setCbfSubParts( 1, COMPONENT_Y, 0, uhDepth );
     2437#if NH_3D_VSO // M3
    23222438          if( m_pcRdCost->getUseRenModel() )
    23232439          {
    2324             UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
    2325             UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
    2326             Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
    2327             UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
     2440            UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y );
     2441            UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( COMPONENT_Y  );
     2442            Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getAddr  ( COMPONENT_Y );
     2443            UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride( COMPONENT_Y  );
    23282444            m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    23292445          }
     
    23572473      }
    23582474#endif
    2359 #if H_3D_ARP
    2360     }
    2361 #endif
    2362 #if  H_3D_FAST_TEXTURE_ENCODING
    2363   }
    2364 #endif
     2475#if NH_3D_ARP
     2476    }
     2477#endif
     2478#if  NH_3D_FAST_TEXTURE_ENCODING
     2479  }
     2480#endif
     2481  D_DEC_INDENT( g_traceModeCheck );
    23652482}
    23662483
    2367 #if H_3D_DBBP
     2484#if NH_3D_DBBP
    23682485Void TEncCu::xInvalidateOriginalSegments( TComYuv* pOrigYuv, TComYuv* pOrigYuvTemp, Bool* pMask, UInt uiValidSegment )
    23692486{
    2370   UInt  uiWidth     = pOrigYuv->getWidth ( );
    2371   UInt  uiHeight    = pOrigYuv->getHeight( );
    2372   Pel*  piSrc       = pOrigYuv->getLumaAddr( );
    2373   UInt  uiSrcStride = pOrigYuv->getStride();
    2374   Pel*  piDst       = pOrigYuvTemp->getLumaAddr( );
    2375   UInt  uiDstStride = pOrigYuvTemp->getStride();
     2487  UInt  uiWidth     = pOrigYuv->getWidth (COMPONENT_Y);
     2488  UInt  uiHeight    = pOrigYuv->getHeight(COMPONENT_Y);
     2489  Pel*  piSrc       = pOrigYuv->getAddr(COMPONENT_Y);
     2490  UInt  uiSrcStride = pOrigYuv->getStride(COMPONENT_Y);
     2491  Pel*  piDst       = pOrigYuvTemp->getAddr(COMPONENT_Y);
     2492  UInt  uiDstStride = pOrigYuvTemp->getStride(COMPONENT_Y);
    23762493 
    23772494  UInt  uiMaskStride= MAX_CU_SIZE;
     
    23982515 
    23992516  // now invalidate chroma
    2400   Pel*  piSrcU       = pOrigYuv->getCbAddr();
    2401   Pel*  piSrcV       = pOrigYuv->getCrAddr();
    2402   UInt  uiSrcStrideC = pOrigYuv->getCStride();
    2403   Pel*  piDstU       = pOrigYuvTemp->getCbAddr( );
    2404   Pel*  piDstV       = pOrigYuvTemp->getCrAddr( );
    2405   UInt  uiDstStrideC = pOrigYuvTemp->getCStride();
     2517  Pel*  piSrcU       = pOrigYuv->getAddr(COMPONENT_Cb);
     2518  Pel*  piSrcV       = pOrigYuv->getAddr(COMPONENT_Cr);
     2519  UInt  uiSrcStrideC = pOrigYuv->getStride(COMPONENT_Cb);
     2520  Pel*  piDstU       = pOrigYuvTemp->getAddr(COMPONENT_Cb);
     2521  Pel*  piDstV       = pOrigYuvTemp->getAddr(COMPONENT_Cr);
     2522  UInt  uiDstStrideC = pOrigYuvTemp->getStride(COMPONENT_Cb);
    24062523  pMask = pMaskStart;
    24072524 
     
    24242541  }
    24252542}
    2426 
    2427 Void TEncCu::xCheckRDCostDIS( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize )
     2543#endif
     2544
     2545#if NH_3D_DBBP
     2546Void TEncCu::xCheckRDCostInterDBBP( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU  DEBUG_STRING_FN_DECLARE(sDebug), Bool bUseMRG )
    24282547{
    2429   UInt uiDepth = rpcTempCU->getDepth( 0 );
    2430   if( !rpcBestCU->getSlice()->getIsDepth() || (eSize != SIZE_2Nx2N))
    2431   {
    2432     return;
    2433   }
    2434 
    2435 #if H_3D_VSO // M5
    2436   if( m_pcRdCost->getUseRenModel() )
    2437   {
    2438     UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth   ();
    2439     UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight  ();
    2440     Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getLumaAddr();
    2441     UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride  ();
    2442     m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    2443   }
    2444 #endif
    2445 
    2446   rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth );
    2447   rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
    2448   rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
    2449   rpcTempCU->setCUTransquantBypassSubParts( rpcTempCU->getCUTransquantBypass(0), 0, uiDepth );
    2450 
    2451   rpcTempCU->setTrIdxSubParts(0, 0, uiDepth);
    2452   rpcTempCU->setCbfSubParts(0, 1, 1, 0, uiDepth);
    2453   rpcTempCU->setDISFlagSubParts(true, 0, uiDepth);
    2454   rpcTempCU->setLumaIntraDirSubParts (DC_IDX, 0, uiDepth);
    2455 #if H_3D_DIM_SDC
    2456   rpcTempCU->setSDCFlagSubParts( false, 0, uiDepth);
    2457 #endif
    2458 
    2459   UInt uiPreCalcDistC;
    2460   m_pcPredSearch  ->estIntraPredDIS      ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, false );
    2461 
    2462 #if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
    2463   Int oldTraceCopyBack = g_traceCopyBack;
    2464   g_traceCopyBack = false; 
    2465 #endif
    2466   m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() );
    2467   #if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC 
    2468     g_traceCopyBack = oldTraceCopyBack;
    2469   #endif
    2470 
    2471 
    2472   m_pcEntropyCoder->resetBits();
    2473   if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
    2474   {
    2475     m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0,          true );
    2476   }
    2477   m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0,          true );
    2478   m_pcEntropyCoder->encodeDIS( rpcTempCU, 0,          true );
    2479 
    2480 
    2481   m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    2482 
    2483   rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
    2484   rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    2485 
    2486 
    2487 #if H_3D_VSO // M6
    2488   if( m_pcRdCost->getUseLambdaScaleVSO()) 
    2489     rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 
    2490   else
    2491 #endif
    2492     rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    2493 
    2494 
    2495   xCheckDQP( rpcTempCU );
    2496   xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth);
    2497 }
    2498 
    2499 Void TEncCu::xCheckRDCostInterDBBP( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool bUseMRG )
    2500 {
     2548  DEBUG_STRING_NEW(sTest)
    25012549  AOF( !rpcTempCU->getSlice()->getIsDepth() );
    25022550 
    25032551  UChar uhDepth = rpcTempCU->getDepth( 0 );
    25042552 
    2505 #if H_3D_VSO
     2553#if NH_3D_VSO
    25062554  if( m_pcRdCost->getUseRenModel() )
    25072555  {
    2508     UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
    2509     UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
    2510     Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
    2511     UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
     2556    UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( COMPONENT_Y );
     2557    UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( COMPONENT_Y );
     2558    Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getAddr  ( COMPONENT_Y );
     2559    UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride( COMPONENT_Y );
    25122560    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    25132561  }
     
    25182566  AOF( uiWidth == uiHeight );
    25192567 
    2520 #if H_3D_DBBP
    2521   // Is this correct here, was under the macro SEC_DBBP_DISALLOW_8x8_I0078, however the function is related to Single Depth Mode
     2568#if NH_3D_DBBP
    25222569  if(uiWidth <= 8)
    25232570  {
     
    25702617    rpcTempCU->getDBBPTmpData()->eVirtualPartSize = eVirtualPartSize;
    25712618    rpcTempCU->getDBBPTmpData()->uiVirtualPartIndex = uiSegment;
    2572     m_pcPredSearch->predInterSearch( rpcTempCU, m_ppcOrigYuvDBBP[uhDepth], apPredYuv[uiSegment], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], false, false, bUseMRG );
     2619    m_pcPredSearch->predInterSearch( rpcTempCU, m_ppcOrigYuvDBBP[uhDepth], apPredYuv[uiSegment], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth] DEBUG_STRING_PASS_INTO(sTest), false, bUseMRG );
    25732620    m_pcRdCost->setUseMask(false);
    25742621   
     
    25792626    pDBBPTmpData->auhMergeIndex[uiSegment] = rpcTempCU->getMergeIndex(0);
    25802627   
     2628#if NH_3D_VSP
    25812629    AOF( rpcTempCU->getSPIVMPFlag(0) == false );
    25822630    AOF( rpcTempCU->getVSPFlag(0) == 0 );
     2631#endif
    25832632   
    25842633    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
     
    25992648  rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
    26002649 
    2601   UInt uiPUOffset = ( g_auiPUOffset[UInt( eVirtualPartSize )] << ( ( rpcTempCU->getSlice()->getSPS()->getMaxCUDepth() - uhDepth ) << 1 ) ) >> 4;
     2650  UInt uiPUOffset = ( g_auiPUOffset[UInt( eVirtualPartSize )] << ( ( rpcTempCU->getSlice()->getSPS()->getMaxTotalCUDepth() - uhDepth ) << 1 ) ) >> 4;
    26022651  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
    26032652  {
     
    26252674 
    26262675  // reconstruct final prediction signal by combining both segments
    2627   m_pcPredSearch->combineSegmentsWithMask(apPredYuv, m_ppcPredYuvTemp[uhDepth], pMask, uiWidth, uiHeight, 0, eVirtualPartSize);
    2628   m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false );
     2676  Int bitDepthY = rpcTempCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA);
     2677  m_pcPredSearch->combineSegmentsWithMask(apPredYuv, m_ppcPredYuvTemp[uhDepth], pMask, uiWidth, uiHeight, 0, eVirtualPartSize, bitDepthY);
     2678  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false DEBUG_STRING_PASS_INTO(sTest) );
    26292679 
    26302680  xCheckDQP( rpcTempCU );
    2631   xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
     2681  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth  DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest) );
    26322682}
    26332683#endif
    2634 
    2635 #if H_3D_DIM
    2636 Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize, Bool bOnlyIVP )
    2637 #else
    2638 Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize )
    2639 #endif
     2684#if NH_3D_DIS
     2685Void TEncCu::xCheckRDCostDIS( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize )
    26402686{
    2641   UInt uiDepth = rpcTempCU->getDepth( 0 ); 
    2642 #if H_3D_VSO // M5
     2687  UInt uiDepth = rpcTempCU->getDepth( 0 );
     2688  if( !rpcBestCU->getSlice()->getIsDepth() || (eSize != SIZE_2Nx2N))
     2689  {
     2690    return;
     2691  }
     2692
     2693  D_PRINT_INC_INDENT(g_traceModeCheck, "xCheckRDCostDIS" );
     2694
     2695#if NH_3D_VSO // M5
    26432696  if( m_pcRdCost->getUseRenModel() )
    26442697  {
    2645     UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth   ();
    2646     UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight  ();
    2647     Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getLumaAddr();
    2648     UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride  ();
     2698    UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth   ( COMPONENT_Y );
     2699    UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight  ( COMPONENT_Y );
     2700    Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getAddr    ( COMPONENT_Y );
     2701    UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride  ( COMPONENT_Y );
    26492702    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
    26502703  }
     
    26522705
    26532706  rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth );
    2654 #if H_3D
     2707  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );
     2708  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
     2709  rpcTempCU->setCUTransquantBypassSubParts( rpcTempCU->getCUTransquantBypass(0), 0, uiDepth );
     2710
     2711  rpcTempCU->setTrIdxSubParts(0, 0, uiDepth);
     2712  rpcTempCU->setCbfSubParts(0, COMPONENT_Y, 0, uiDepth);
     2713  rpcTempCU->setDISFlagSubParts(true, 0, uiDepth);
     2714  rpcTempCU->setIntraDirSubParts(CHANNEL_TYPE_LUMA, DC_IDX, 0, uiDepth);
     2715#if NH_3D_SDC_INTRA
     2716  rpcTempCU->setSDCFlagSubParts( false, 0, uiDepth);
     2717#endif
     2718
     2719  UInt uiPreCalcDistC;
     2720  m_pcPredSearch  ->estIntraPredDIS      ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, false );
     2721
     2722#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
     2723  Int oldTraceCopyBack = g_traceCopyBack;
     2724  g_traceCopyBack = false; 
     2725#endif
     2726  m_ppcRecoYuvTemp[uiDepth]->copyToPicComponent(COMPONENT_Y, rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getCtuRsAddr(), rpcTempCU->getZorderIdxInCtu() );
     2727#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC 
     2728  g_traceCopyBack = oldTraceCopyBack;
     2729#endif
     2730
     2731  m_pcEntropyCoder->resetBits();
     2732  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
     2733  {
     2734    m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0,          true );
     2735  }
     2736  m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0,          true );
     2737  m_pcEntropyCoder->encodeDIS( rpcTempCU, 0,          true );
     2738
     2739  m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
     2740
     2741  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
     2742  rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     2743
     2744#if NH_3D_VSO // M6
     2745  if( m_pcRdCost->getUseLambdaScaleVSO())
     2746  {
     2747    rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 
     2748  }
     2749  else
     2750#endif
     2751  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     2752
     2753  xCheckDQP( rpcTempCU );
     2754  xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth  DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest) );
     2755  D_DEC_INDENT( g_traceModeCheck ); 
     2756}
     2757#endif
     2758Void TEncCu::xCheckRDCostIntra( TComDataCU *&rpcBestCU,
     2759                                TComDataCU *&rpcTempCU,
     2760                                Double      &cost,
     2761                                PartSize     eSize
     2762                                DEBUG_STRING_FN_DECLARE(sDebug)
     2763#if NH_3D_ENC_DEPTH
     2764                              , Bool bOnlyIVP
     2765#endif
     2766                              )
     2767{
     2768  DEBUG_STRING_NEW(sTest)
     2769
     2770  if(getFastDeltaQp())
     2771  {
     2772    const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS());
     2773    const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>(sps.getLog2DiffMaxMinCodingBlockSize()), sps.getMaxCUHeight(), 32u);
     2774    if(rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxSize)
     2775    {
     2776      return; // only check necessary 2Nx2N Intra in fast deltaqp mode
     2777    }
     2778  }
     2779  D_PRINT_INC_INDENT (g_traceModeCheck, "xCheckRDCostIntra; eSize: " + n2s(eSize) );
     2780 
     2781  UInt uiDepth = rpcTempCU->getDepth( 0 );
     2782#if NH_3D_VSO // M5
     2783  if( m_pcRdCost->getUseRenModel() )
     2784  {
     2785    UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth   ( COMPONENT_Y );
     2786    UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight  ( COMPONENT_Y );
     2787    Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getAddr    ( COMPONENT_Y );
     2788    UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride  ( COMPONENT_Y );
     2789    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
     2790  }
     2791#endif
     2792
     2793  rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth );
     2794#if NH_3D_DIS
    26552795  rpcTempCU->setDISFlagSubParts( false, 0, uiDepth );
    26562796#endif
     2797
     2798
    26572799  rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth );
    26582800  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
     2801  rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uiDepth );
     2802
     2803  Pel resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE];
     2804
     2805  m_pcPredSearch->estIntraPredLumaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest)
     2806#if NH_3D_ENC_DEPTH
     2807                                    , bOnlyIVP
     2808#endif
     2809                                    );
     2810
     2811  m_ppcRecoYuvTemp[uiDepth]->copyToPicComponent(COMPONENT_Y, rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getCtuRsAddr(), rpcTempCU->getZorderIdxInCtu() );
     2812
     2813  if (rpcBestCU->getPic()->getChromaFormat()!=CHROMA_400)
     2814  {
     2815    m_pcPredSearch->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) );
     2816  }
    26592817 
    2660   Bool bSeparateLumaChroma = true; // choose estimation mode
    2661   UInt uiPreCalcDistC      = 0;
    2662   if( !bSeparateLumaChroma )
    2663   {
    2664     m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] );
    2665   }
    2666 #if H_3D_DIM
    2667   m_pcPredSearch  ->estIntraPredQT      ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma, bOnlyIVP );
    2668 #else
    2669   m_pcPredSearch  ->estIntraPredQT      ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma );
    2670 #endif
    2671   m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() );
    2672  
    2673 #if H_3D_DIM_SDC
    2674   if( !rpcTempCU->getSDCFlag( 0 ) )
    2675 #endif
    2676     m_pcPredSearch  ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC );
    2677  
     2818#if NH_3D_SDC_INTRA
     2819  if( rpcTempCU->getSDCFlag( 0 ) )
     2820  {
     2821    assert( rpcTempCU->getTransformIdx(0) == 0 );
     2822    assert( rpcTempCU->getCbf(0, COMPONENT_Y) == 1 );
     2823  }
     2824#endif
     2825
    26782826  m_pcEntropyCoder->resetBits();
     2827
    26792828  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
    26802829  {
    26812830    m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0,          true );
    26822831  }
    2683   m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0,          true );
    2684 #if H_3D
     2832#if NH_3D_DIS && !NH_3D_DIS_FIX
    26852833  m_pcEntropyCoder->encodeDIS( rpcTempCU, 0,          true );
    26862834  if(!rpcTempCU->getDISFlag(0))
    26872835  {
    26882836#endif
    2689     m_pcEntropyCoder->encodePredMode( rpcTempCU, 0,          true );
    2690     m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true );
    2691     m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0,          true );
    2692     m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true );
    2693 #if H_3D_DIM_SDC
     2837  m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0,          true );
     2838#if NH_3D_DIS_FIX
     2839  m_pcEntropyCoder->encodeDIS( rpcTempCU, 0,          true );
     2840  if(!rpcTempCU->getDISFlag(0))
     2841  {
     2842#endif
     2843  m_pcEntropyCoder->encodePredMode( rpcTempCU, 0,          true );
     2844  m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true );
     2845  m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0 );
     2846  m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true );
     2847#if NH_3D_SDC_INTRA
    26942848    m_pcEntropyCoder->encodeSDCFlag( rpcTempCU, 0, true );
    26952849#endif
    26962850
    2697     // Encode Coefficients
    2698     Bool bCodeDQP = getdQPFlag();
    2699 #if H_3D_DISABLE_CHROMA
    2700     m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0), bCodeDQP, true );
    2701 #else
    2702     m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0), bCodeDQP );
    2703 #endif
    2704     setdQPFlag( bCodeDQP );
    2705 #if H_3D
     2851  // Encode Coefficients
     2852  Bool bCodeDQP = getdQPFlag();
     2853  Bool codeChromaQpAdjFlag = getCodeChromaQpAdjFlag();
     2854  m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, bCodeDQP, codeChromaQpAdjFlag );
     2855  setCodeChromaQpAdjFlag( codeChromaQpAdjFlag );
     2856  setdQPFlag( bCodeDQP );
     2857#if NH_3D_DIS
    27062858  }
    27072859#endif
    27082860  m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    2709  
     2861
    27102862  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
    27112863  rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    2712 #if H_3D_VSO // M6
     2864#if NH_3D_VSO // M6
    27132865  if( m_pcRdCost->getUseLambdaScaleVSO()) 
     2866  {
    27142867    rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 
     2868  }
    27152869  else
    27162870#endif
    2717   rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    2718  
     2871    rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     2872
    27192873  xCheckDQP( rpcTempCU );
    2720   xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth);
    2721 }
    2722 
    2723 /** Check R-D costs for a CU with PCM mode.
     2874
     2875  cost = rpcTempCU->getTotalCost();
     2876
     2877  xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest));
     2878
     2879  D_DEC_INDENT( g_traceModeCheck );
     2880  }
     2881
     2882
     2883/** Check R-D costs for a CU with PCM mode.
    27242884 * \param rpcBestCU pointer to best mode CU data structure
    27252885 * \param rpcTempCU pointer to testing mode CU data structure
    27262886 * \returns Void
    2727  * 
     2887 *
    27282888 * \note Current PCM implementation encodes sample values in a lossless way. The distortion of PCM mode CUs are zero. PCM mode is selected if the best mode yields bits greater than that of PCM mode.
    27292889 */
    27302890Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU )
    27312891{
     2892  if(getFastDeltaQp())
     2893  {
     2894    const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS());
     2895    const UInt fastDeltaQPCuMaxPCMSize = Clip3((UInt)1<<sps.getPCMLog2MinSize(), (UInt)1<<sps.getPCMLog2MaxSize(), 32u);
     2896    if (rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxPCMSize)
     2897    {
     2898      return;   // only check necessary PCM in fast deltaqp mode
     2899    }
     2900  }
     2901 
    27322902  UInt uiDepth = rpcTempCU->getDepth( 0 );
    27332903
     2904#if NH_3D_VSO // VERY NEW
     2905  if( m_pcRdCost->getUseRenModel() )
     2906  {
     2907    UInt  uiWidth     = m_ppcOrigYuv[uiDepth]->getWidth   ( COMPONENT_Y );
     2908    UInt  uiHeight    = m_ppcOrigYuv[uiDepth]->getHeight  ( COMPONENT_Y );
     2909    Pel*  piSrc       = m_ppcOrigYuv[uiDepth]->getAddr    ( COMPONENT_Y );
     2910    UInt  uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride  ( COMPONENT_Y );
     2911    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
     2912  }
     2913#endif
     2914
    27342915  rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth );
    2735 #if H_3D
     2916#if NH_3D_DIS
    27362917  rpcTempCU->setDISFlagSubParts( false, 0, uiDepth );
    27372918#endif
     
    27412922  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
    27422923  rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth );
     2924  rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uiDepth );
    27432925
    27442926  m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]);
     
    27472929
    27482930  m_pcEntropyCoder->resetBits();
     2931
    27492932  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
    27502933  {
    27512934    m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0,          true );
    27522935  }
     2936
    27532937  m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0,          true );
    2754 #if H_3D
     2938#if NH_3D_DIS
    27552939  m_pcEntropyCoder->encodeDIS( rpcTempCU, 0,          true );
    27562940#endif
     
    27582942  m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true );
    27592943  m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true );
    2760 #if H_3D_DIM_SDC
     2944#if NH_3D_SDC_INTRA
    27612945  m_pcEntropyCoder->encodeSDCFlag( rpcTempCU, 0, true );
    27622946#endif
     
    27642948
    27652949  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
    2766     rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    2767 #if H_3D_VSO // M44
     2950  rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     2951#if NH_3D_VSO // M44
    27682952  if ( m_pcRdCost->getUseVSO() )
     2953  {
    27692954    rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     2955  }
    27702956  else
    27712957#endif
    2772   rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     2958    rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    27732959
    27742960  xCheckDQP( rpcTempCU );
    2775   xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth );
     2961  DEBUG_STRING_NEW(a)
     2962  DEBUG_STRING_NEW(b)
     2963  xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(a) DEBUG_STRING_PASS_INTO(b));
    27762964}
    27772965
     
    27792967 * \param rpcBestCU
    27802968 * \param rpcTempCU
    2781  * \returns Void
     2969 * \param uiDepth
    27822970 */
    2783 Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth )
     2971Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth DEBUG_STRING_FN_DECLARE(sParent) DEBUG_STRING_FN_DECLARE(sTest) DEBUG_STRING_PASS_INTO(Bool bAddSizeInfo) )
    27842972{
    27852973  if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() )
     
    28052993
    28062994    // store temp best CI for next CU coding
    2807       m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
     2995    m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
     2996
     2997
     2998#if DEBUG_STRING
     2999    DEBUG_STRING_SWAP(sParent, sTest)
     3000    const PredMode predMode=rpcBestCU->getPredictionMode(0);
     3001    if ((DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode)) && bAddSizeInfo)
     3002    {
     3003      std::stringstream ss(stringstream::out);
     3004      ss <<"###: " << (predMode==MODE_INTRA?"Intra   ":"Inter   ") << partSizeToString[rpcBestCU->getPartitionSize(0)] << " CU at " << rpcBestCU->getCUPelX() << ", " << rpcBestCU->getCUPelY() << " width=" << UInt(rpcBestCU->getWidth(0)) << std::endl;
     3005      sParent+=ss.str();
     3006    }
     3007#endif
    28083008  }
    28093009}
     
    28133013  UInt uiDepth = pcCU->getDepth( 0 );
    28143014
    2815   if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() )
    2816   {
    2817     if ( pcCU->getCbf( 0, TEXT_LUMA, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_U, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_V, 0 ) )
    2818     {
    2819 #if !RDO_WITHOUT_DQP_BITS
     3015  const TComPPS &pps = *(pcCU->getSlice()->getPPS());
     3016  if ( pps.getUseDQP() && uiDepth <= pps.getMaxCuDQPDepth() )
     3017  {
     3018    if ( pcCU->getQtRootCbf( 0) )
     3019    {
    28203020      m_pcEntropyCoder->resetBits();
    28213021      m_pcEntropyCoder->encodeQP( pcCU, 0, false );
    28223022      pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
    2823         pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    2824 #if H_3D_VSO // M45
     3023      pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     3024#if NH_3D_VSO // M45
    28253025      if ( m_pcRdCost->getUseVSO() )     
     3026      {
    28263027        pcCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( pcCU->getTotalBits(), pcCU->getTotalDistortion() );     
     3028      }
    28273029      else
    28283030#endif
    2829       pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() );
    2830 #endif
     3031        pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() );
    28313032    }
    28323033    else
     
    28453046  }
    28463047}
    2847 Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY )
     3048Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth )
    28483049{
    2849   UInt uiRPelX   = uiLPelX + (g_uiMaxCUWidth>>uiDepth)  - 1;
    2850   UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
    2851   TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
    2852   Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx &&
    2853     pcSlice->getSliceSegmentCurStartCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) );
    2854   Bool bSliceEnd   = pcSlice->getSliceSegmentCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx &&
    2855     pcSlice->getSliceSegmentCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) );
    2856   if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
    2857   {
    2858     UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx];
    2859     UInt uiSrcBlkWidth = rpcPic->getNumPartInWidth() >> (uiSrcDepth);
    2860     UInt uiBlkWidth    = rpcPic->getNumPartInWidth() >> (uiDepth);
    2861     UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth;
    2862     UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth;
    2863     UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX;
    2864     m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx);
    2865   }
    2866   else
    2867   {
    2868     UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) )>>2;
    2869 
    2870     for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts )
    2871     {
    2872       UInt uiSubCULPelX   = uiLPelX + ( g_uiMaxCUWidth >>(uiDepth+1) )*( uiPartUnitIdx &  1 );
    2873       UInt uiSubCUTPelY   = uiTPelY + ( g_uiMaxCUHeight>>(uiDepth+1) )*( uiPartUnitIdx >> 1 );
    2874 
    2875       Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getSliceSegmentCurStartCUAddr() &&
    2876         rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getSliceSegmentCurEndCUAddr();
    2877       if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
    2878       {
    2879         xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY );   // Copy Yuv data to picture Yuv
    2880       }
    2881     }
    2882   }
     3050  UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx];
     3051  UInt uiSrcBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiSrcDepth);
     3052  UInt uiBlkWidth    = rpcPic->getNumPartInCtuWidth() >> (uiDepth);
     3053  UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth;
     3054  UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth;
     3055  UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX;
     3056  m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx);
     3057
     3058#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
     3059  Bool oldtraceCopyBack = g_traceCopyBack;
     3060  g_traceCopyBack = false;
     3061#endif
     3062  m_ppcPredYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvPred (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx);
     3063
     3064#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
     3065  g_traceCopyBack = oldtraceCopyBack;
     3066#endif
    28833067}
    28843068
     
    28873071  UInt uiCurrDepth = uiNextDepth - 1;
    28883072  m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx );
     3073  m_ppcPredYuvBest[uiNextDepth]->copyToPartYuv( m_ppcPredYuvBest[uiCurrDepth], uiPartUnitIdx);
    28893074}
    28903075
    2891 /** Function for filling the PCM buffer of a CU using its original sample array
    2892  * \param pcCU pointer to current CU
    2893  * \param pcOrgYuv pointer to original sample array
    2894  * \returns Void
     3076/** Function for filling the PCM buffer of a CU using its original sample array
     3077 * \param pCU pointer to current CU
     3078 * \param pOrgYuv pointer to original sample array
    28953079 */
    2896 Void TEncCu::xFillPCMBuffer     ( TComDataCU*& pCU, TComYuv* pOrgYuv )
     3080Void TEncCu::xFillPCMBuffer     ( TComDataCU* pCU, TComYuv* pOrgYuv )
    28973081{
    2898 
    2899   UInt   width        = pCU->getWidth(0);
    2900   UInt   height       = pCU->getHeight(0);
    2901 
    2902   Pel*   pSrcY = pOrgYuv->getLumaAddr(0, width);
    2903   Pel*   pDstY = pCU->getPCMSampleY();
    2904   UInt   srcStride = pOrgYuv->getStride();
    2905 
    2906   for(Int y = 0; y < height; y++ )
    2907   {
    2908     for(Int x = 0; x < width; x++ )
    2909     {
    2910       pDstY[x] = pSrcY[x];
    2911     }
    2912     pDstY += width;
    2913     pSrcY += srcStride;
    2914   }
    2915 
    2916   Pel* pSrcCb       = pOrgYuv->getCbAddr();
    2917   Pel* pSrcCr       = pOrgYuv->getCrAddr();;
    2918 
    2919   Pel* pDstCb       = pCU->getPCMSampleCb();
    2920   Pel* pDstCr       = pCU->getPCMSampleCr();;
    2921 
    2922   UInt srcStrideC = pOrgYuv->getCStride();
    2923   UInt heightC   = height >> 1;
    2924   UInt widthC    = width  >> 1;
    2925 
    2926   for(Int y = 0; y < heightC; y++ )
    2927   {
    2928     for(Int x = 0; x < widthC; x++ )
    2929     {
    2930       pDstCb[x] = pSrcCb[x];
    2931       pDstCr[x] = pSrcCr[x];
    2932     }
    2933     pDstCb += widthC;
    2934     pDstCr += widthC;
    2935     pSrcCb += srcStrideC;
    2936     pSrcCr += srcStrideC;
     3082  const ChromaFormat format = pCU->getPic()->getChromaFormat();
     3083  const UInt numberValidComponents = getNumberValidComponents(format);
     3084  for (UInt componentIndex = 0; componentIndex < numberValidComponents; componentIndex++)
     3085  {
     3086    const ComponentID component = ComponentID(componentIndex);
     3087
     3088    const UInt width  = pCU->getWidth(0)  >> getComponentScaleX(component, format);
     3089    const UInt height = pCU->getHeight(0) >> getComponentScaleY(component, format);
     3090
     3091    Pel *source      = pOrgYuv->getAddr(component, 0, width);
     3092    Pel *destination = pCU->getPCMSample(component);
     3093
     3094    const UInt sourceStride = pOrgYuv->getStride(component);
     3095
     3096    for (Int line = 0; line < height; line++)
     3097    {
     3098      for (Int column = 0; column < width; column++)
     3099      {
     3100        destination[column] = source[column];
     3101      }
     3102
     3103      source      += sourceStride;
     3104      destination += width;
     3105    }
    29373106  }
    29383107}
     
    29413110/** Collect ARL statistics from one block
    29423111  */
    2943 Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, Int* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples )
     3112Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, TCoeff* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples )
    29443113{
    29453114  for( Int n = 0; n < NumCoeffInCU; n++ )
    29463115  {
    2947     Int u = abs( rpcCoeff[ n ] );
    2948     Int absc = rpcArlCoeff[ n ];
     3116    TCoeff u = abs( rpcCoeff[ n ] );
     3117    TCoeff absc = rpcArlCoeff[ n ];
    29493118
    29503119    if( u != 0 )
     
    29553124        numSamples[ u ]++;
    29563125      }
    2957       else 
     3126      else
    29583127      {
    29593128        cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION );
     
    29663135}
    29673136
    2968 /** Collect ARL statistics from one LCU
    2969  * \param pcCU
    2970  */
    2971 Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU )
     3137//! Collect ARL statistics from one CTU
     3138Void TEncCu::xCtuCollectARLStats(TComDataCU* pCtu )
    29723139{
    2973   Double cSum[ LEVEL_RANGE + 1 ];     //: the sum of DCT coefficients corresponding to datatype and quantization output
    2974   UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output
    2975 
    2976   TCoeff* pCoeffY = rpcCU->getCoeffY();
    2977   Int* pArlCoeffY = rpcCU->getArlCoeffY();
    2978 
    2979   UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth;
    2980   UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth;
     3140  Double cSum[ LEVEL_RANGE + 1 ];     //: the sum of DCT coefficients corresponding to data type and quantization output
     3141  UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to data type and quantization output
     3142
     3143  TCoeff* pCoeffY = pCtu->getCoeff(COMPONENT_Y);
     3144  TCoeff* pArlCoeffY = pCtu->getArlCoeff(COMPONENT_Y);
     3145  const TComSPS &sps = *(pCtu->getSlice()->getSPS());
     3146
     3147  const UInt uiMinCUWidth = sps.getMaxCUWidth() >> sps.getMaxTotalCUDepth(); // NOTE: ed - this is not the minimum CU width. It is the square-root of the number of coefficients per part.
     3148  const UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth;                          // NOTE: ed - what is this?
    29813149
    29823150  memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) );
     
    29843152
    29853153  // Collect stats to cSum[][] and numSamples[][]
    2986   for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ )
    2987   {
    2988     UInt uiTrIdx = rpcCU->getTransformIdx(i);
    2989 
    2990     if(rpcCU->getPredictionMode(i) == MODE_INTER)
    2991     if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) )
     3154  for(Int i = 0; i < pCtu->getTotalNumPart(); i ++ )
     3155  {
     3156    UInt uiTrIdx = pCtu->getTransformIdx(i);
     3157
     3158    if(pCtu->isInter(i) && pCtu->getCbf( i, COMPONENT_Y, uiTrIdx ) )
    29923159    {
    29933160      xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples);
    29943161    }//Note that only InterY is processed. QP rounding is based on InterY data only.
    2995    
     3162
    29963163    pCoeffY  += uiMinNumCoeffInCU;
    29973164    pArlCoeffY  += uiMinNumCoeffInCU;
     
    30073174}
    30083175#endif
     3176
    30093177//! \}
Note: See TracChangeset for help on using the changeset viewer.