Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncEntropy.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/TEncEntropy.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 *
     
    3737
    3838#include "TEncEntropy.h"
    39 #include "TLibCommon/TypeDef.h"
     39#include "TLibCommon/CommonDef.h"
    4040#include "TLibCommon/TComSampleAdaptiveOffset.h"
     41#include "TLibCommon/TComTU.h"
     42
     43#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     44#include "../TLibCommon/Debug.h"
     45static const Bool bDebugPredEnabled = DebugOptionList::DebugPred.getInt()!=0;
     46#endif
    4147
    4248//! \ingroup TLibEncoder
    4349//! \{
    4450
    45 Void TEncEntropy::setEntropyCoder ( TEncEntropyIf* e, TComSlice* pcSlice )
     51Void TEncEntropy::setEntropyCoder ( TEncEntropyIf* e )
    4652{
    4753  m_pcEntropyCoderIf = e;
    48   m_pcEntropyCoderIf->setSlice ( pcSlice );
    4954}
    5055
     
    6368{
    6469  m_pcEntropyCoderIf->codeTerminatingBit( uiIsLast );
    65  
     70
    6671  return;
    6772}
     
    7277}
    7378
    74 Void TEncEntropy::encodePPS( TComPPS* pcPPS )
     79Void TEncEntropy::encodePPS( const TComPPS* pcPPS )
    7580{
    7681  m_pcEntropyCoderIf->codePPS( pcPPS );
     
    7883}
    7984
    80 Void TEncEntropy::encodeSPS( TComSPS* pcSPS )
     85Void TEncEntropy::encodeSPS( const TComSPS* pcSPS )
    8186{
    8287  m_pcEntropyCoderIf->codeSPS( pcSPS );
     
    9398}
    9499
    95 Void TEncEntropy::encodeVPS( TComVPS* pcVPS )
     100Void TEncEntropy::encodeVPS( const TComVPS* pcVPS )
    96101{
    97102  m_pcEntropyCoderIf->codeVPS( pcVPS );
     
    111116  m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx );
    112117}
    113 #if H_3D
     118#if NH_3D_DIS
    114119Void TEncEntropy::encodeDIS( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    115120{
     121#if NH_3D_FIX_TICKET_98 
     122  if( !pcCU->getSlice()->getDepthIntraSkipFlag() )
     123#else
    116124  if ( !pcCU->getSlice()->getIsDepth() )
     125#endif
    117126  {
    118127    return;
     
    125134}
    126135#endif
    127 /** encode merge flag
    128  * \param pcCU
    129  * \param uiAbsPartIdx
    130  * \returns Void
    131  */
     136//! encode merge flag
    132137Void TEncEntropy::encodeMergeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
    133 { 
     138{
    134139  // at least one merge candidate exists
    135140  m_pcEntropyCoderIf->codeMergeFlag( pcCU, uiAbsPartIdx );
    136141}
    137142
    138 /** encode merge index
    139  * \param pcCU
    140  * \param uiAbsPartIdx
    141  * \param uiPUIdx
    142  * \param bRD
    143  * \returns Void
    144  */
     143//! encode merge index
    145144Void TEncEntropy::encodeMergeIndex( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    146145{
     
    153152}
    154153
    155 #if H_3D_IC
     154#if NH_3D_IC
    156155Void TEncEntropy::encodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    157156{
     157#if NH_3D_ARP
    158158  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() || pcCU->getARPW( uiAbsPartIdx ) > 0 )
     159#else
     160  if ( pcCU->isIntra( uiAbsPartIdx ) || ( pcCU->getSlice()->getViewIndex() == 0 ) || pcCU->getSlice()->getIsDepth() )
     161#endif
    159162  {
    160163    return;
     
    189192#endif
    190193
    191 #if H_3D_ARP
     194#if NH_3D_ARP
    192195Void TEncEntropy::encodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx )
    193196{
     
    208211#endif
    209212
    210 /** encode prediction mode
    211  * \param pcCU
    212  * \param uiAbsPartIdx
    213  * \param bRD
    214  * \returns Void
    215  */
     213
     214//! encode prediction mode
    216215Void TEncEntropy::encodePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    217216{
     
    220219    uiAbsPartIdx = 0;
    221220  }
     221
    222222  if ( pcCU->getSlice()->isIntra() )
    223223  {
     
    228228}
    229229
    230 // Split mode
     230//! encode split flag
    231231Void TEncEntropy::encodeSplitFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
    232232{
     
    235235    uiAbsPartIdx = 0;
    236236  }
     237
    237238  m_pcEntropyCoderIf->codeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
    238239}
    239240
    240 /** encode partition size
    241  * \param pcCU
    242  * \param uiAbsPartIdx
    243  * \param uiDepth
    244  * \param bRD
    245  * \returns Void
    246  */
     241//! encode partition size
    247242Void TEncEntropy::encodePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD )
    248243{
     
    251246    uiAbsPartIdx = 0;
    252247  }
    253  
     248
    254249  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
    255  
    256 }
    257 
    258 /** Encode I_PCM information.
    259  * \param pcCU pointer to CU
    260  * \param uiAbsPartIdx CU index
    261  * \param bRD flag indicating estimation or encoding
    262  * \returns Void
     250}
     251
     252
     253/** Encode I_PCM information.
     254 * \param pcCU          pointer to CU
     255 * \param uiAbsPartIdx  CU index
     256 * \param bRD           flag indicating estimation or encoding
    263257 */
    264258Void TEncEntropy::encodeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
     
    270264    return;
    271265  }
    272  
    273   if( bRD )
    274   {
    275     uiAbsPartIdx = 0;
    276   }
    277  
     266
     267  if( bRD )
     268  {
     269    uiAbsPartIdx = 0;
     270  }
     271
    278272  m_pcEntropyCoderIf->codeIPCMInfo ( pcCU, uiAbsPartIdx );
    279 }
    280 
    281 #if H_3D_DISABLE_CHROMA
    282 Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP, Bool rd )
    283 #else
    284 Void TEncEntropy::xEncodeTransform( TComDataCU* pcCU,UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP )
    285 #endif
    286 {
    287 
     273
     274}
     275
     276Void TEncEntropy::xEncodeTransform( Bool& bCodeDQP, Bool& codeChromaQpAdj, TComTU &rTu )
     277{
     278
     279//pcCU, absPartIdxCU, uiAbsPartIdx, uiDepth+1, uiTrIdx+1, quadrant,
     280  TComDataCU *pcCU=rTu.getCU();
     281  const UInt uiAbsPartIdx=rTu.GetAbsPartIdxTU();
     282
     283  const UInt numValidComponent = pcCU->getPic()->getNumberValidComponents();
     284  const Bool bChroma = isChromaEnabled(pcCU->getPic()->getChromaFormat());
     285  const UInt uiTrIdx = rTu.GetTransformDepthRel();
     286  const UInt uiDepth = rTu.GetTransformDepthTotal();
    288287#if H_MV_ENC_DEC_TRAC
    289288#if ENC_DEC_TRACE
     
    292291
    293292  DTRACE_TU_S("=========== transform_tree ===========\n")
    294   DTRACE_TU("x0", uiLPelX)
    295   DTRACE_TU("x1", uiTPelY)
    296   DTRACE_TU("log2TrafoSize", g_uiMaxCUWidth>>uiDepth)
    297   DTRACE_TU("trafoDepth"  , uiDepth)
    298 #endif
    299 #endif
    300 
    301   const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
    302   const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()]+2 - uiDepth;
    303   UInt cbfY = pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA    , uiTrIdx );
    304   UInt cbfU = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
    305   UInt cbfV = pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
    306 #if H_3D_DISABLE_CHROMA
    307   if( !rd && pcCU->getSlice()->getSPS()->getChromaFormatIdc() == 0 )
    308   {
    309     cbfU = 0;
    310     cbfV = 0;
    311   }
    312 #endif
    313   if(uiTrIdx==0)
    314   {
    315     m_bakAbsPartIdxCU = uiAbsPartIdx;
    316   }
    317   if( uiLog2TrafoSize == 2 )
    318   {
    319     UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
    320     if( ( uiAbsPartIdx % partNum ) == 0 )
    321     {
    322       m_uiBakAbsPartIdx   = uiAbsPartIdx;
    323       m_uiBakChromaOffset = offsetChroma;
    324     }
    325     else if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
    326     {
    327       cbfU = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_U, uiTrIdx );
    328       cbfV = pcCU->getCbf( m_uiBakAbsPartIdx, TEXT_CHROMA_V, uiTrIdx );
    329 #if H_3D_DISABLE_CHROMA
    330       if( !rd && pcCU->getSlice()->getSPS()->getChromaFormatIdc() == 0 )
     293    DTRACE_TU("x0", uiLPelX)
     294    DTRACE_TU("x1", uiTPelY)
     295    DTRACE_TU("log2TrafoSize", pcCU->getSlice()->getSPS()->getMaxCUWidth()  >> uiDepth )
     296    DTRACE_TU("trafoDepth"  , uiDepth)
     297#endif
     298#endif
     299
     300#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     301  const Bool bDebugRQT=pcCU->getSlice()->getFinalized() && DebugOptionList::DebugRQT.getInt()!=0;
     302  if (bDebugRQT)
     303  {
     304    printf("x..codeTransform: offsetLuma=%d offsetChroma=%d absPartIdx=%d, uiDepth=%d\n width=%d, height=%d, uiTrIdx=%d, uiInnerQuadIdx=%d\n",
     305           rTu.getCoefficientOffset(COMPONENT_Y), rTu.getCoefficientOffset(COMPONENT_Cb), uiAbsPartIdx, uiDepth, rTu.getRect(COMPONENT_Y).width, rTu.getRect(COMPONENT_Y).height, rTu.GetTransformDepthRel(), rTu.GetSectionNumber());
     306  }
     307#endif
     308  const UInt uiSubdiv = pcCU->getTransformIdx( uiAbsPartIdx ) > uiTrIdx;// + pcCU->getDepth( uiAbsPartIdx ) > uiDepth;
     309  const UInt uiLog2TrafoSize = rTu.GetLog2LumaTrSize();
     310
     311
     312  UInt cbf[MAX_NUM_COMPONENT] = {0,0,0};
     313  Bool bHaveACodedBlock       = false;
     314  Bool bHaveACodedChromaBlock = false;
     315
     316  for(UInt ch=0; ch<numValidComponent; ch++)
     317  {
     318    const ComponentID compID = ComponentID(ch);
     319
     320    cbf[compID] = pcCU->getCbf( uiAbsPartIdx, compID , uiTrIdx );
     321   
     322    if (cbf[ch] != 0)
     323    {
     324      bHaveACodedBlock = true;
     325      if (isChroma(compID))
    331326      {
    332         cbfU = 0;
    333         cbfV = 0;
     327        bHaveACodedChromaBlock = true;
    334328      }
    335 #endif
    336     }
    337   }
    338  
    339   if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTRA && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
     329    }
     330  }
     331
     332  if( pcCU->isIntra(uiAbsPartIdx) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && uiDepth == pcCU->getDepth(uiAbsPartIdx) )
    340333  {
    341334    assert( uiSubdiv );
    342335  }
    343   else if( pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) &&  (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) )
     336  else if( pcCU->isInter(uiAbsPartIdx) && (pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N) && uiDepth == pcCU->getDepth(uiAbsPartIdx) &&  (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) )
    344337  {
    345338    if ( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
     
    372365  const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx );
    373366  const Bool bFirstCbfOfCU = uiTrDepthCurr == 0;
    374   if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
    375   {
    376 #if H_3D_DISABLE_CHROMA
    377     if (pcCU->getSlice()->getSPS()->getChromaFormatIdc() != 0 || rd)
    378     {
    379       if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
     367
     368  for(UInt ch=COMPONENT_Cb; ch<numValidComponent; ch++)
     369  {
     370    const ComponentID compID=ComponentID(ch);
     371    if( bFirstCbfOfCU || rTu.ProcessingAllQuadrants(compID) )
     372    {
     373      if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepthCurr - 1 ) )
    380374      {
    381         m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr );
     375        m_pcEntropyCoderIf->codeQtCbf( rTu, compID, (uiSubdiv == 0) );
    382376      }
    383       if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
    384       {
    385         m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr );
    386       }
    387     }
    388 #else
    389     if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) )
    390     {
    391       m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr );
    392     }
    393     if( bFirstCbfOfCU || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) )
    394     {
    395       m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr );
    396     }
    397 #endif
    398   }
    399   else if( uiLog2TrafoSize == 2 )
    400   {
    401 #if H_3D_DISABLE_CHROMA
    402     if ( rd && pcCU->getSlice()->getSPS()->getChromaFormatIdc() != 0 )
    403     {
    404     assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) );
    405     assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) );
    406   }
    407 #else
    408     assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr - 1 ) );
    409     assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) );
    410 #endif
    411   }
    412  
     377    }
     378    else
     379    {
     380      assert( pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, compID, uiTrDepthCurr - 1 ) );
     381    }
     382  }
     383
    413384  if( uiSubdiv )
    414385  {
    415     UInt size;
    416     width  >>= 1;
    417     height >>= 1;
    418     size = width*height;
    419     uiTrIdx++;
    420     ++uiDepth;
    421     const UInt partNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
    422    
    423 #if H_3D_DISABLE_CHROMA
    424     xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP, rd );
    425 
    426     uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
    427     xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP ,rd );
    428 
    429     uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
    430     xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP, rd );
    431 
    432     uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
    433     xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP, rd );
    434 #else
    435     xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
    436 
    437     uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
    438     xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
    439 
    440     uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
    441     xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
    442 
    443     uiAbsPartIdx += partNum;  offsetLuma += size;  offsetChroma += (size>>2);
    444     xEncodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
    445 #endif
     386    TComTURecurse tuRecurseChild(rTu, true);
     387    do
     388    {
     389      xEncodeTransform( bCodeDQP, codeChromaQpAdj, tuRecurseChild );
     390    } while (tuRecurseChild.nextSection(rTu));
    446391  }
    447392  else
     
    459404    }
    460405#endif
    461    
    462 #if H_3D_DISABLE_CHROMA
    463     Bool notcbfUV = !rd && pcCU->getSlice()->getSPS()->getChromaFormatIdc() == 0 ? 1 : ( !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) ) ;
    464     if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA &&
    465       uiDepth == pcCU->getDepth( uiAbsPartIdx ) && notcbfUV )
    466 #else
    467     if( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, 0 ) && !pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, 0 ) )
    468 #endif
    469     {
    470       assert( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, 0 ) );
     406    if( !pcCU->isIntra(uiAbsPartIdx) && uiDepth == pcCU->getDepth( uiAbsPartIdx ) && (!bChroma || (!pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cb, 0 ) && !pcCU->getCbf( uiAbsPartIdx, COMPONENT_Cr, 0 ) ) ) )
     407    {
     408      assert( pcCU->getCbf( uiAbsPartIdx, COMPONENT_Y, 0 ) );
    471409      //      printf( "saved one bin! " );
    472410    }
    473411    else
    474412    {
    475       m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, pcCU->getTransformIdx( uiAbsPartIdx ) );
    476     }
    477 
    478 
    479     if ( cbfY || cbfU || cbfV )
    480     {
    481       // dQP: only for LCU once
     413      m_pcEntropyCoderIf->codeQtCbf( rTu, COMPONENT_Y, true ); //luma CBF is always at the lowest level
     414    }
     415
     416    if ( bHaveACodedBlock )
     417    {
     418      // dQP: only for CTU once
    482419      if ( pcCU->getSlice()->getPPS()->getUseDQP() )
    483420      {
    484421        if ( bCodeDQP )
    485422        {
    486           encodeQP( pcCU, m_bakAbsPartIdxCU );
     423          encodeQP( pcCU, rTu.GetAbsPartIdxCU() );
    487424          bCodeDQP = false;
    488425        }
    489426      }
    490     }
    491     if( cbfY )
    492     {
    493       Int trWidth = width;
    494       Int trHeight = height;
    495       m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
    496     }
    497     if( uiLog2TrafoSize > 2 )
    498     {
    499       Int trWidth = width >> 1;
    500       Int trHeight = height >> 1;
    501       if( cbfU )
     427
     428      if ( pcCU->getSlice()->getUseChromaQpAdj() )
    502429      {
    503         m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
    504       }
    505       if( cbfV )
    506       {
    507         m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+offsetChroma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
    508       }
    509     }
    510     else
    511     {
    512       UInt partNum = pcCU->getPic()->getNumPartInCU() >> ( ( uiDepth - 1 ) << 1 );
    513       if( ( uiAbsPartIdx % partNum ) == (partNum - 1) )
    514       {
    515         Int trWidth = width;
    516         Int trHeight = height;
    517         if( cbfU )
     430        if ( bHaveACodedChromaBlock && codeChromaQpAdj && !pcCU->getCUTransquantBypass(rTu.GetAbsPartIdxCU()) )
    518431        {
    519           m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCb()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_U );
    520         }
    521         if( cbfV )
    522         {
    523           m_pcEntropyCoderIf->codeCoeffNxN( pcCU, (pcCU->getCoeffCr()+m_uiBakChromaOffset), m_uiBakAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_CHROMA_V );
     432          encodeChromaQpAdjustment( pcCU, rTu.GetAbsPartIdxCU() );
     433          codeChromaQpAdj = false;
    524434        }
    525435      }
    526     }
    527   }
    528 }
    529 
    530 // Intra direction for Luma
     436
     437      const UInt numValidComp=pcCU->getPic()->getNumberValidComponents();
     438
     439      for(UInt ch=COMPONENT_Y; ch<numValidComp; ch++)
     440      {
     441        const ComponentID compID=ComponentID(ch);
     442
     443        if (rTu.ProcessComponentSection(compID))
     444        {
     445#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     446          if (bDebugRQT)
     447          {
     448            printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, rTu.getRect(compID).width, rTu.getRect(compID).height, 1);
     449          }
     450#endif
     451
     452          if (rTu.getRect(compID).width != rTu.getRect(compID).height)
     453          {
     454            //code two sub-TUs
     455            TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
     456
     457            do
     458            {
     459              const UChar subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(compID), compID, (uiTrIdx + 1));
     460
     461              if (subTUCBF != 0)
     462              {
     463#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     464                if (bDebugRQT)
     465                {
     466                  printf("Call NxN for chan %d width=%d height=%d cbf=%d\n", compID, subTUIterator.getRect(compID).width, subTUIterator.getRect(compID).height, 1);
     467                }
     468#endif
     469                m_pcEntropyCoderIf->codeCoeffNxN( subTUIterator, (pcCU->getCoeff(compID) + subTUIterator.getCoefficientOffset(compID)), compID );
     470              }
     471            }
     472            while (subTUIterator.nextSection(rTu));
     473          }
     474          else
     475          {
     476            if (isChroma(compID) && (cbf[COMPONENT_Y] != 0))
     477            {
     478              m_pcEntropyCoderIf->codeCrossComponentPrediction( rTu, compID );
     479            }
     480
     481            if (cbf[compID] != 0)
     482            {
     483              m_pcEntropyCoderIf->codeCoeffNxN( rTu, (pcCU->getCoeff(compID) + rTu.getCoefficientOffset(compID)), compID );
     484            }
     485          }
     486        }
     487      }
     488    }
     489  }
     490}
     491
     492
     493//! encode intra direction for luma
    531494Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU )
    532495{
     
    534497}
    535498
    536 // Intra direction for Chroma
    537 Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    538 {
    539   if( bRD )
    540   {
    541     uiAbsPartIdx = 0;
    542   }
    543  
     499
     500//! encode intra direction for chroma
     501Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx )
     502{
    544503  m_pcEntropyCoderIf->codeIntraDirChroma( pcCU, uiAbsPartIdx );
    545 }
    546 
    547 Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    548 {
    549   if( bRD )
    550   {
    551     uiAbsPartIdx = 0;
    552   }
     504
     505#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     506  if (bDebugPredEnabled && pcCU->getSlice()->getFinalized())
     507  {
     508    UInt cdir=pcCU->getIntraDir(CHANNEL_TYPE_CHROMA, uiAbsPartIdx);
     509    if (cdir==36)
     510    {
     511      cdir=pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx);
     512    }
     513    printf("coding chroma Intra dir: %d, uiAbsPartIdx: %d, luma dir: %d\n", cdir, uiAbsPartIdx, pcCU->getIntraDir(CHANNEL_TYPE_LUMA, uiAbsPartIdx));
     514  }
     515#endif
     516}
     517
     518
     519Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx )
     520{
    553521  if( pcCU->isIntra( uiAbsPartIdx ) )                                 // If it is Intra mode, encode intra prediction mode.
    554522  {
    555523    encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx,true );
    556 #if H_3D_DIM_SDC
    557 #if H_3D_DISABLE_CHROMA
    558     if(!pcCU->getSDCFlag(uiAbsPartIdx) && ( pcCU->getSlice()->getSPS()->getChromaFormatIdc() != 0  || bRD ) )
    559 #else
    560     if(!pcCU->getSDCFlag(uiAbsPartIdx))
    561 #endif
    562 #endif
    563       encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
     524   
     525    if (pcCU->getPic()->getChromaFormat()!=CHROMA_400)
     526    {
     527      encodeIntraDirModeChroma( pcCU, uiAbsPartIdx );
     528
     529      if (enable4ChromaPUsInIntraNxNCU(pcCU->getPic()->getChromaFormat()) && pcCU->getPartitionSize( uiAbsPartIdx )==SIZE_NxN)
     530      {
     531        UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
     532        encodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset   );
     533        encodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*2 );
     534        encodeIntraDirModeChroma( pcCU, uiAbsPartIdx + uiPartOffset*3 );
     535      }
     536    }
    564537  }
    565538  else                                                                // if it is Inter mode, encode motion vector and reference index
    566539  {
    567     encodePUWise( pcCU, uiAbsPartIdx, bRD );
    568   }
    569 }
    570 
    571 /** encode motion information for every PU block
    572  * \param pcCU
    573  * \param uiAbsPartIdx
    574  * \param bRD
    575  * \returns Void
    576  */
    577 Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    578 {
    579   if ( bRD )
    580   {
    581     uiAbsPartIdx = 0;
    582   }
    583  
     540    encodePUWise( pcCU, uiAbsPartIdx );
     541  }
     542}
     543
     544Void TEncEntropy::encodeCrossComponentPrediction( TComTU &rTu, ComponentID compID )
     545{
     546  m_pcEntropyCoderIf->codeCrossComponentPrediction( rTu, compID );
     547}
     548
     549//! encode motion information for every PU block
     550Void TEncEntropy::encodePUWise( TComDataCU* pcCU, UInt uiAbsPartIdx )
     551{
     552#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     553  const Bool bDebugPred = bDebugPredEnabled && pcCU->getSlice()->getFinalized();
     554#endif
     555
    584556  PartSize ePartSize = pcCU->getPartitionSize( uiAbsPartIdx );
    585557  UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
    586558  UInt uiDepth = pcCU->getDepth( uiAbsPartIdx );
    587   UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
     559  UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxTotalCUDepth() - uiDepth ) << 1 ) ) >> 4;
    588560
    589561  for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
     
    599571    {
    600572      encodeMergeIndex( pcCU, uiSubPartIdx );
     573#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     574      if (bDebugPred)
     575      {
     576        std::cout << "Coded merge flag, CU absPartIdx: " << uiAbsPartIdx << " PU(" << uiPartIdx << ") absPartIdx: " << uiSubPartIdx;
     577        std::cout << " merge index: " << (UInt)pcCU->getMergeIndex(uiSubPartIdx) << std::endl;
     578      }
     579#endif
    601580    }
    602581    else
     
    610589          encodeMvdPU       ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
    611590          encodeMVPIdxPU    ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
     591#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     592          if (bDebugPred)
     593          {
     594            std::cout << "refListIdx: " << uiRefListIdx << std::endl;
     595            std::cout << "MVD horizontal: " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getHor() << std::endl;
     596            std::cout << "MVD vertical:   " << pcCU->getCUMvField(RefPicList(uiRefListIdx))->getMvd( uiAbsPartIdx ).getVer() << std::endl;
     597            std::cout << "MVPIdxPU: " << pcCU->getMVPIdx(RefPicList( uiRefListIdx ), uiSubPartIdx) << std::endl;
     598            std::cout << "InterDir: " << (UInt)pcCU->getInterDir(uiSubPartIdx) << std::endl;
     599          }
     600#endif
    612601        }
    613602      }
     
    626615
    627616  m_pcEntropyCoderIf->codeInterDir( pcCU, uiAbsPartIdx );
     617
    628618  return;
    629619}
    630620
    631 /** encode reference frame index for a PU block
    632  * \param pcCU
    633  * \param uiAbsPartIdx
    634  * \param eRefList
    635  * \returns Void
    636  */
     621//! encode reference frame index for a PU block
    637622Void TEncEntropy::encodeRefFrmIdxPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
    638623{
    639   assert( !pcCU->isIntra( uiAbsPartIdx ) );
    640   {
    641     if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
    642     {
    643       return;
    644     }
    645 
    646     if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
    647     {
    648       m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    649     }
     624  assert( pcCU->isInter( uiAbsPartIdx ) );
     625
     626  if ( ( pcCU->getSlice()->getNumRefIdx( eRefList ) == 1 ) )
     627  {
     628    return;
     629  }
     630
     631  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
     632  {
     633    m_pcEntropyCoderIf->codeRefFrmIdx( pcCU, uiAbsPartIdx, eRefList );
    650634  }
    651635
     
    653637}
    654638
    655 /** encode motion vector difference for a PU block
    656  * \param pcCU
    657  * \param uiAbsPartIdx
    658  * \param eRefList
    659  * \returns Void
    660  */
     639//! encode motion vector difference for a PU block
    661640Void TEncEntropy::encodeMvdPU( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
    662641{
    663   assert( !pcCU->isIntra( uiAbsPartIdx ) );
     642  assert( pcCU->isInter( uiAbsPartIdx ) );
    664643
    665644  if ( pcCU->getInterDir( uiAbsPartIdx ) & ( 1 << eRefList ) )
     
    680659}
    681660
    682 Void TEncEntropy::encodeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
    683 {
    684   m_pcEntropyCoderIf->codeQtCbf( pcCU, uiAbsPartIdx, eType, uiTrDepth );
     661Void TEncEntropy::encodeQtCbf( TComTU &rTu, const ComponentID compID, const Bool lowestLevel )
     662{
     663  m_pcEntropyCoderIf->codeQtCbf( rTu, compID, lowestLevel );
    685664}
    686665
     
    695674}
    696675
    697 Void TEncEntropy::encodeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth )
    698 {
    699   m_pcEntropyCoderIf->codeQtCbfZero( pcCU, eType, uiTrDepth );
    700 }
    701 Void TEncEntropy::encodeQtRootCbfZero( TComDataCU* pcCU )
    702 {
    703   m_pcEntropyCoderIf->codeQtRootCbfZero( pcCU );
     676Void TEncEntropy::encodeQtCbfZero( TComTU &rTu, const ChannelType chType )
     677{
     678  m_pcEntropyCoderIf->codeQtCbfZero( rTu, chType );
     679}
     680
     681Void TEncEntropy::encodeQtRootCbfZero( )
     682{
     683  m_pcEntropyCoderIf->codeQtRootCbfZero( );
    704684}
    705685
     
    711691    uiAbsPartIdx = 0;
    712692  }
    713  
     693
    714694  if ( pcCU->getSlice()->getPPS()->getUseDQP() )
    715695  {
     
    718698}
    719699
     700//! encode chroma qp adjustment
     701Void TEncEntropy::encodeChromaQpAdjustment( TComDataCU* cu, UInt absPartIdx, Bool inRd )
     702{
     703  if( inRd )
     704  {
     705    absPartIdx = 0;
     706  }
     707
     708  m_pcEntropyCoderIf->codeChromaQpAdjustment( cu, absPartIdx );
     709}
    720710
    721711// texture
    722 /** encode coefficients
    723  * \param pcCU
    724  * \param uiAbsPartIdx
    725  * \param uiDepth
    726  * \param uiWidth
    727  * \param uiHeight
    728  */
    729 #if H_3D_DISABLE_CHROMA
    730 Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP, Bool rd )
    731 #else
    732 Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP )
    733 #endif
    734 {
    735   UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
    736   UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
    737   UInt uiChromaOffset = uiLumaOffset>>2;
    738 #if H_3D_DIM_SDC
     712
     713//! encode coefficients
     714Void TEncEntropy::encodeCoeff( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool& bCodeDQP, Bool& codeChromaQpAdj )
     715{
     716
     717#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     718  const Bool bDebugRQT=pcCU->getSlice()->getFinalized() && DebugOptionList::DebugRQT.getInt()!=0;
     719#endif
     720
     721#if NH_3D_SDC_INTRA
    739722  if( pcCU->getSDCFlag( uiAbsPartIdx ) && pcCU->isIntra( uiAbsPartIdx ) )
    740723  {
    741724    assert( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N );
    742725    assert( pcCU->getTransformIdx(uiAbsPartIdx) == 0 );
    743     assert( pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA) == 1 );
    744 #if H_3D_DISABLE_CHROMA
    745     if (!pcCU->getSlice()->getIsDepth() )
    746     {
    747       assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
    748       assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
    749     }
    750 #else
    751     assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
    752     assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
    753 #endif
    754   }
    755 
    756 
     726    assert( pcCU->getCbf(uiAbsPartIdx, COMPONENT_Y) == 1 );
     727  }
     728#endif
     729#if NH_3D_SDC_INTER
    757730  if( pcCU->getSDCFlag( uiAbsPartIdx ) && !pcCU->isIntra( uiAbsPartIdx ) )
    758731  {
     
    761734    assert( pcCU->getSlice()->getIsDepth() );
    762735  }
    763 
    764   if( pcCU->getSlice()->getIsDepth() && ( pcCU->getSDCFlag( uiAbsPartIdx ) || pcCU->isIntra( uiAbsPartIdx ) ) )
     736#endif
     737#if NH_3D
     738  if( pcCU->getSlice()->getIsDepth() )
     739  {
     740#if NH_3D_SDC_INTRA || NH_3D_SDC_INTER
     741    if( pcCU->getSDCFlag( uiAbsPartIdx ) )
     742    {
     743      m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx );
     744      return;
     745    }
     746#endif
     747#if NH_3D_DMM
     748    if( pcCU->isIntra(uiAbsPartIdx) )
    765749  {
    766750    Int iPartNum = ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ) ? 4 : 1;
    767     UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2;
    768    
    769     if( !pcCU->getSDCFlag( uiAbsPartIdx ) )
    770     {
     751      UInt uiPartOffset = ( pcCU->getPic()->getNumPartitionsInCtu() >> ( pcCU->getDepth( uiAbsPartIdx ) << 1 ) ) >> 2;
    771752      for( Int iPart = 0; iPart < iPartNum; iPart++ )
    772753      {
    773         if( getDimType( pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset*iPart ) ) < DIM_NUM_TYPE )
     754        if( isDmmMode( pcCU->getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx + uiPartOffset*iPart ) ) )
    774755        {
    775756          m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx + uiPartOffset*iPart );
     
    777758      }
    778759    }
     760#endif
     761  }
     762#endif
     763
     764  if( pcCU->isIntra(uiAbsPartIdx) )
     765  {
     766#if !NH_MV
     767    if (false)
     768    {
     769      DTRACE_CABAC_VL( g_nSymbolCounter++ )
     770      DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
     771      DTRACE_CABAC_V( uiDepth )
     772      DTRACE_CABAC_T( "\n" )
     773    }
     774#endif
     775  }
     776  else
     777  {
     778    if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) )
     779    {
     780      m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
     781    }
     782    if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
     783    {
     784      return;
     785    }
     786  }
     787
     788  TComTURecurse tuRecurse(pcCU, uiAbsPartIdx, uiDepth);
     789#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
     790  if (bDebugRQT)
     791  {
     792    printf("..codeCoeff: uiAbsPartIdx=%d, PU format=%d, 2Nx2N=%d, NxN=%d\n", uiAbsPartIdx, pcCU->getPartitionSize(uiAbsPartIdx), SIZE_2Nx2N, SIZE_NxN);
     793  }
     794#endif
     795
     796  xEncodeTransform( bCodeDQP, codeChromaQpAdj, tuRecurse );
     797}
     798
     799Void TEncEntropy::encodeCoeffNxN( TComTU &rTu, TCoeff* pcCoef, const ComponentID compID)
     800{
     801#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
     802  Bool oldTraceFracBits = g_traceEncFracBits;
     803  g_traceEncFracBits = false;
     804#endif
     805
     806  TComDataCU *pcCU = rTu.getCU();
     807
     808  if (pcCU->getCbf(rTu.GetAbsPartIdxTU(), compID, rTu.GetTransformDepthRel()) != 0)
     809  {
     810    if (rTu.getRect(compID).width != rTu.getRect(compID).height)
     811    {
     812      //code two sub-TUs
     813      TComTURecurse subTUIterator(rTu, false, TComTU::VERTICAL_SPLIT, true, compID);
     814
     815      const UInt subTUSize = subTUIterator.getRect(compID).width * subTUIterator.getRect(compID).height;
     816
     817      do
     818      {
     819        const UChar subTUCBF = pcCU->getCbf(subTUIterator.GetAbsPartIdxTU(compID), compID, (subTUIterator.GetTransformDepthRel() + 1));
     820
     821        if (subTUCBF != 0)
     822        {
     823          m_pcEntropyCoderIf->codeCoeffNxN( subTUIterator, (pcCoef + (subTUIterator.GetSectionNumber() * subTUSize)), compID);
     824        }
     825      }
     826      while (subTUIterator.nextSection(rTu));
     827    }
    779828    else
    780829    {
    781       m_pcEntropyCoderIf->codeDeltaDC( pcCU, uiAbsPartIdx );
    782       return;
    783     }
    784   }
    785 #endif
    786 
    787   if( pcCU->isIntra(uiAbsPartIdx) )
    788   {
    789 #if !H_MV
    790     DTRACE_CABAC_VL( g_nSymbolCounter++ )
    791     DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
    792     DTRACE_CABAC_V( uiDepth )
    793     DTRACE_CABAC_T( "\n" )
    794 #endif
    795   }
    796   else
    797   {
    798     if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N ) )
    799     {
    800       m_pcEntropyCoderIf->codeQtRootCbf( pcCU, uiAbsPartIdx );
    801     }
    802     if ( !pcCU->getQtRootCbf( uiAbsPartIdx ) )
    803     {
    804       return;
    805     }
     830      m_pcEntropyCoderIf->codeCoeffNxN(rTu, pcCoef, compID);
     831    }
     832  }
     833#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
     834  g_traceEncFracBits = oldTraceFracBits;
     835#endif
     836}
     837
     838Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, const ChannelType chType)
     839{
     840  const UInt heightAtEntropyCoding = (width != height) ? (height >> 1) : height;
     841
     842  m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, heightAtEntropyCoding, chType );
     843}
     844
     845Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
     846{
     847  Int count = 0;
     848
     849  for ( Int i = 0; i < uiSize; i++ )
     850  {
     851    count += pcCoef[i] != 0;
     852  }
     853
     854  return count;
     855}
     856
     857#if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER
     858Void TEncEntropy::encodeDeltaDC  ( TComDataCU* pcCU, UInt absPartIdx )
     859{
     860  m_pcEntropyCoderIf->codeDeltaDC( pcCU, absPartIdx );
     861}
     862#endif
     863#if NH_3D_SDC_INTRA || NH_3D_SDC_INTER
     864Void TEncEntropy::encodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
     865{
     866  if( bRD )
     867  {
     868    uiAbsPartIdx = 0;
    806869  }
    807870 
    808 #if H_3D_DISABLE_CHROMA
    809   xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP, rd);
    810 #else
    811   xEncodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP);
    812 #endif
    813 }
    814 
    815 Void TEncEntropy::encodeCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType )
    816 {
    817   // This is for Transform unit processing. This may be used at mode selection stage for Inter.
    818   m_pcEntropyCoderIf->codeCoeffNxN( pcCU, pcCoeff, uiAbsPartIdx, uiTrWidth, uiTrHeight, uiDepth, eType );
    819 }
    820 
    821 Void TEncEntropy::estimateBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType)
    822 
    823   eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
    824  
    825   m_pcEntropyCoderIf->estBit ( pcEstBitsSbac, width, height, eTType );
    826 }
    827 
    828 Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
    829 {
    830   Int count = 0;
    831  
    832   for ( Int i = 0; i < uiSize; i++ )
    833   {
    834     count += pcCoef[i] != 0;
    835   }
    836  
    837   return count;
    838 }
    839 
    840 /** encode quantization matrix
    841  * \param scalingList quantization matrix information
    842  */
    843 Void TEncEntropy::encodeScalingList( TComScalingList* scalingList )
    844 {
    845   m_pcEntropyCoderIf->codeScalingList( scalingList );
    846 }
    847 
    848 #if H_3D_INTER_SDC
    849 Void TEncEntropy::encodeDeltaDC  ( TComDataCU* pcCU, UInt absPartIdx )
    850 {
    851   m_pcEntropyCoderIf->codeDeltaDC( pcCU, absPartIdx );
    852 }
    853 
    854 Void TEncEntropy::encodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    855 {
    856871  if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getInterSdcFlag() ) ||
    857872    ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getIntraSdcWedgeFlag() ) )
     
    865880  }
    866881
    867   assert( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) );
    868 
    869   if( bRD )
    870   {
    871     uiAbsPartIdx = 0;
    872   }
     882  assert( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N );
    873883
    874884  m_pcEntropyCoderIf->codeSDCFlag( pcCU, uiAbsPartIdx );
     
    876886
    877887#endif
    878 #if H_3D_DBBP
     888#if NH_3D_DBBP
    879889Void TEncEntropy::encodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    880890{
     891  if( bRD )
     892  {
     893    uiAbsPartIdx = 0;
     894  }
     895 
    881896  if( pcCU->getSlice()->getDepthBasedBlkPartFlag() &&
    882897    ( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2NxN ||
     
    885900      pcCU->getSlice()->getDefaultRefViewIdxAvailableFlag() )
    886901  {
    887     if( bRD )
    888     {
    889       uiAbsPartIdx = 0;
    890     }
    891902    m_pcEntropyCoderIf->codeDBBPFlag( pcCU, uiAbsPartIdx );
    892903  }
    893904}
    894905#endif
     906
    895907//! \}
Note: See TracChangeset for help on using the changeset viewer.