Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComDataCU.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/TLibCommon/TComDataCU.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 *
     
    3838
    3939#include "TComDataCU.h"
     40#include "TComTU.h"
    4041#include "TComPic.h"
    4142
    4243//! \ingroup TLibCommon
    4344//! \{
    44 
    45 #if ADAPTIVE_QP_SELECTION
    46 Int * TComDataCU::m_pcGlbArlCoeffY  = NULL;
    47 Int * TComDataCU::m_pcGlbArlCoeffCb = NULL;
    48 Int * TComDataCU::m_pcGlbArlCoeffCr = NULL;
    49 #endif
    5045
    5146// ====================================================================================================================
     
    5853  m_pcSlice            = NULL;
    5954  m_puhDepth           = NULL;
    60  
     55
    6156  m_skipFlag           = NULL;
    62 #if H_3D
     57#if NH_3D_DIS
    6358  m_bDISFlag           = NULL;
    64   m_uiDISType          = NULL;
     59  m_ucDISType          = NULL;
    6560#endif
    6661  m_pePartSize         = NULL;
     
    7065  m_puhHeight          = NULL;
    7166  m_phQP               = NULL;
     67  m_ChromaQpAdj        = NULL;
    7268  m_pbMergeFlag        = NULL;
    7369  m_puhMergeIndex      = NULL;
    74   m_puhLumaIntraDir    = NULL;
    75   m_puhChromaIntraDir  = NULL;
     70  for(UInt i=0; i<MAX_NUM_CHANNEL_TYPE; i++)
     71  {
     72    m_puhIntraDir[i]     = NULL;
     73  }
    7674  m_puhInterDir        = NULL;
    7775  m_puhTrIdx           = NULL;
    78   m_puhTransformSkip[0] = NULL;
    79   m_puhTransformSkip[1] = NULL;
    80   m_puhTransformSkip[2] = NULL;
    81   m_puhCbf[0]          = NULL;
    82   m_puhCbf[1]          = NULL;
    83   m_puhCbf[2]          = NULL;
    84   m_pcTrCoeffY         = NULL;
    85   m_pcTrCoeffCb        = NULL;
    86   m_pcTrCoeffCr        = NULL;
    87 #if ADAPTIVE_QP_SELECTION 
     76
     77  for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     78  {
     79    m_puhCbf[comp]                        = NULL;
     80    m_crossComponentPredictionAlpha[comp] = NULL;
     81    m_puhTransformSkip[comp]              = NULL;
     82    m_pcTrCoeff[comp]                     = NULL;
     83#if ADAPTIVE_QP_SELECTION
     84    m_pcArlCoeff[comp]                    = NULL;
     85#endif
     86    m_pcIPCMSample[comp]                  = NULL;
     87    m_explicitRdpcmMode[comp]             = NULL;
     88  }
     89#if ADAPTIVE_QP_SELECTION
    8890  m_ArlCoeffIsAliasedAllocation = false;
    89   m_pcArlCoeffY        = NULL;
    90   m_pcArlCoeffCb       = NULL;
    91   m_pcArlCoeffCr       = NULL;
    92 #endif
    93  
     91#endif
    9492  m_pbIPCMFlag         = NULL;
    95   m_pcIPCMSampleY      = NULL;
    96   m_pcIPCMSampleCb     = NULL;
    97   m_pcIPCMSampleCr     = NULL;
    98 
    99   m_pcPattern          = NULL;
    100  
    101   m_pcCUAboveLeft      = NULL;
    102   m_pcCUAboveRight     = NULL;
    103   m_pcCUAbove          = NULL;
    104   m_pcCULeft           = NULL;
    105  
    106   m_apcCUColocated[0]  = NULL;
    107   m_apcCUColocated[1]  = NULL;
    108  
    109   m_apiMVPIdx[0]       = NULL;
    110   m_apiMVPIdx[1]       = NULL;
    111   m_apiMVPNum[0]       = NULL;
    112   m_apiMVPNum[1]       = NULL;
    113 
    114 #if H_3D_DIM
    115   for( Int i = 0; i < DIM_NUM_TYPE; i++ )
    116   {
    117     m_dimDeltaDC[i][0] = NULL;
    118     m_dimDeltaDC[i][1] = NULL;
    119   }
    120 #if H_3D_DIM_DMM
    121   for( Int i = 0; i < DMM_NUM_TYPE; i++ )
    122   {
    123     m_dmmWedgeTabIdx[i] = NULL;
    124   }
    125 #endif
    126 #if H_3D_DIM_SDC
     93
     94  m_pCtuAboveLeft      = NULL;
     95  m_pCtuAboveRight     = NULL;
     96  m_pCtuAbove          = NULL;
     97  m_pCtuLeft           = NULL;
     98
     99  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     100  {
     101    m_apcCUColocated[i]  = NULL;
     102    m_apiMVPIdx[i]       = NULL;
     103    m_apiMVPNum[i]       = NULL;
     104  }
     105
     106#if NH_3D_DMM
     107  for( Int i = 0; i < NUM_DMM; i++ )
     108  {
     109    m_dmmDeltaDC[i][0] = NULL;
     110    m_dmmDeltaDC[i][1] = NULL;
     111  }
     112  m_dmm1WedgeTabIdx = NULL;
     113#endif
     114#if NH_3D_SDC_INTRA
    127115  m_pbSDCFlag             = NULL;
    128116  m_apSegmentDCOffset[0]  = NULL;
    129117  m_apSegmentDCOffset[1]  = NULL;
    130118#endif
    131 #endif
     119
    132120  m_bDecSubCu          = false;
    133   m_sliceStartCU        = 0;
    134   m_sliceSegmentStartCU = 0;
    135 #if H_3D_NBDV
     121
     122#if NH_3D_NBDV
    136123  m_pDvInfo              = NULL;
    137124#endif
    138 #if H_3D_VSP
     125#if NH_3D_VSP
    139126  m_piVSPFlag            = NULL;
    140127#endif
    141 #if H_3D_SPIVMP
     128#if NH_3D_SPIVMP
    142129  m_pbSPIVMPFlag         = NULL;
    143130#endif
    144 #if H_3D_ARP
     131#if NH_3D_ARP
    145132  m_puhARPW              = NULL;
    146133#endif
    147 #if H_3D_IC
     134#if NH_3D_IC
    148135  m_pbICFlag             = NULL;
    149136#endif
    150 #if H_3D_INTER_SDC
    151 #endif
    152 #if H_3D_DBBP
     137#if NH_3D_DBBP
    153138  m_pbDBBPFlag         = NULL;
    154139#endif
     140
    155141}
    156142
     
    159145}
    160146
    161 Void TComDataCU::create(UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize
     147Void TComDataCU::create( ChromaFormat chromaFormatIDC, UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize
    162148#if ADAPTIVE_QP_SELECTION
    163                         , Bool bGlobalRMARLBuffer
    164 #endif                                             
     149                        , TCoeff *pParentARLBuffer
     150#endif
    165151                        )
    166152{
    167153  m_bDecSubCu = bDecSubCu;
    168  
     154
    169155  m_pcPic              = NULL;
    170156  m_pcSlice            = NULL;
    171157  m_uiNumPartition     = uiNumPartition;
    172158  m_unitSize = unitSize;
    173  
     159
    174160  if ( !bDecSubCu )
    175161  {
     
    179165    m_puhHeight          = (UChar*    )xMalloc(UChar,    uiNumPartition);
    180166
     167    m_ChromaQpAdj        = new UChar[ uiNumPartition ];
    181168    m_skipFlag           = new Bool[ uiNumPartition ];
    182 #if H_3D
     169#if NH_3D_DIS
    183170    m_bDISFlag           = new Bool[ uiNumPartition ];
    184     m_uiDISType          = (UInt*)xMalloc(UInt, uiNumPartition);
     171    m_ucDISType          = (UChar*)xMalloc(UChar, uiNumPartition);
    185172#endif
    186173    m_pePartSize         = new Char[ uiNumPartition ];
    187     memset( m_pePartSize, SIZE_NONE,uiNumPartition * sizeof( *m_pePartSize ) );
     174    memset( m_pePartSize, NUMBER_OF_PART_SIZES,uiNumPartition * sizeof( *m_pePartSize ) );
    188175    m_pePredMode         = new Char[ uiNumPartition ];
    189176    m_CUTransquantBypass = new Bool[ uiNumPartition ];
     177
    190178    m_pbMergeFlag        = (Bool*  )xMalloc(Bool,   uiNumPartition);
    191179    m_puhMergeIndex      = (UChar* )xMalloc(UChar,  uiNumPartition);
    192 #if H_3D_VSP
     180#if NH_3D_VSP
    193181    m_piVSPFlag          = (Char*  )xMalloc(Char,   uiNumPartition);
    194182#endif
    195 #if H_3D_SPIVMP
     183#if NH_3D_SPIVMP
    196184    m_pbSPIVMPFlag       = (Bool*  )xMalloc(Bool,   uiNumPartition);
    197185#endif
    198     m_puhLumaIntraDir    = (UChar* )xMalloc(UChar,  uiNumPartition);
    199     m_puhChromaIntraDir  = (UChar* )xMalloc(UChar,  uiNumPartition);
     186
     187    for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     188    {
     189      m_puhIntraDir[ch] = (UChar* )xMalloc(UChar,  uiNumPartition);
     190    }
    200191    m_puhInterDir        = (UChar* )xMalloc(UChar,  uiNumPartition);
    201    
     192
    202193    m_puhTrIdx           = (UChar* )xMalloc(UChar,  uiNumPartition);
    203     m_puhTransformSkip[0] = (UChar* )xMalloc(UChar,  uiNumPartition);
    204     m_puhTransformSkip[1] = (UChar* )xMalloc(UChar,  uiNumPartition);
    205     m_puhTransformSkip[2] = (UChar* )xMalloc(UChar,  uiNumPartition);
    206 
    207     m_puhCbf[0]          = (UChar* )xMalloc(UChar,  uiNumPartition);
    208     m_puhCbf[1]          = (UChar* )xMalloc(UChar,  uiNumPartition);
    209     m_puhCbf[2]          = (UChar* )xMalloc(UChar,  uiNumPartition);
    210    
    211     m_apiMVPIdx[0]       = new Char[ uiNumPartition ];
    212     m_apiMVPIdx[1]       = new Char[ uiNumPartition ];
    213     m_apiMVPNum[0]       = new Char[ uiNumPartition ];
    214     m_apiMVPNum[1]       = new Char[ uiNumPartition ];
    215     memset( m_apiMVPIdx[0], -1,uiNumPartition * sizeof( Char ) );
    216     memset( m_apiMVPIdx[1], -1,uiNumPartition * sizeof( Char ) );
    217    
    218     m_pcTrCoeffY         = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight);
    219     m_pcTrCoeffCb        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
    220     m_pcTrCoeffCr        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
    221 #if H_3D_NBDV
     194
     195    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     196    {
     197      const RefPicList rpl=RefPicList(i);
     198      m_apiMVPIdx[rpl]       = new Char[ uiNumPartition ];
     199      m_apiMVPNum[rpl]       = new Char[ uiNumPartition ];
     200      memset( m_apiMVPIdx[rpl], -1,uiNumPartition * sizeof( Char ) );
     201    }
     202
     203#if NH_3D_NBDV
    222204    m_pDvInfo            = (DisInfo* )xMalloc(DisInfo,  uiNumPartition);
    223205#endif
    224     memset( m_pcTrCoeffY, 0,uiWidth*uiHeight * sizeof( TCoeff ) );
    225     memset( m_pcTrCoeffCb, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
    226     memset( m_pcTrCoeffCr, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
    227 #if ADAPTIVE_QP_SELECTION   
    228     if( bGlobalRMARLBuffer )
    229     {
    230       if( m_pcGlbArlCoeffY == NULL )
    231       {
    232         m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, uiWidth*uiHeight);
    233         m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
    234         m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
    235       }
    236       m_pcArlCoeffY        = m_pcGlbArlCoeffY;
    237       m_pcArlCoeffCb       = m_pcGlbArlCoeffCb;
    238       m_pcArlCoeffCr       = m_pcGlbArlCoeffCr;
    239       m_ArlCoeffIsAliasedAllocation = true;
    240     }
    241     else
    242     {
    243       m_pcArlCoeffY        = (Int*)xMalloc(Int, uiWidth*uiHeight);
    244       m_pcArlCoeffCb       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
    245       m_pcArlCoeffCr       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
    246     }
    247 #endif
    248    
     206
     207
     208    for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     209    {
     210      const ComponentID compID = ComponentID(comp);
     211      const UInt chromaShift = getComponentScaleX(compID, chromaFormatIDC) + getComponentScaleY(compID, chromaFormatIDC);
     212      const UInt totalSize   = (uiWidth * uiHeight) >> chromaShift;
     213
     214      m_crossComponentPredictionAlpha[compID] = (Char*  )xMalloc(Char,   uiNumPartition);
     215      m_puhTransformSkip[compID]              = (UChar* )xMalloc(UChar,  uiNumPartition);
     216      m_explicitRdpcmMode[compID]             = (UChar* )xMalloc(UChar,  uiNumPartition);
     217      m_puhCbf[compID]                        = (UChar* )xMalloc(UChar,  uiNumPartition);
     218      m_pcTrCoeff[compID]                     = (TCoeff*)xMalloc(TCoeff, totalSize);
     219      memset( m_pcTrCoeff[compID], 0, (totalSize * sizeof( TCoeff )) );
     220
     221#if ADAPTIVE_QP_SELECTION
     222      if( pParentARLBuffer != 0 )
     223      {
     224        m_pcArlCoeff[compID] = pParentARLBuffer;
     225        m_ArlCoeffIsAliasedAllocation = true;
     226        pParentARLBuffer += totalSize;
     227      }
     228      else
     229      {
     230        m_pcArlCoeff[compID] = (TCoeff*)xMalloc(TCoeff, totalSize);
     231        m_ArlCoeffIsAliasedAllocation = false;
     232      }
     233#endif
     234      m_pcIPCMSample[compID] = (Pel*   )xMalloc(Pel , totalSize);
     235    }
     236
    249237    m_pbIPCMFlag         = (Bool*  )xMalloc(Bool, uiNumPartition);
    250     m_pcIPCMSampleY      = (Pel*   )xMalloc(Pel , uiWidth*uiHeight);
    251     m_pcIPCMSampleCb     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
    252     m_pcIPCMSampleCr     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
    253 
    254     m_acCUMvField[0].create( uiNumPartition );
    255     m_acCUMvField[1].create( uiNumPartition );
    256    
    257 #if H_3D_ARP
    258     m_puhARPW            = new UChar[ uiNumPartition];
    259 #endif
    260 #if H_3D_IC
     238
     239    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     240    {
     241      m_acCUMvField[i].create( uiNumPartition );
     242    }
     243
     244#if NH_3D_ARP
     245    m_puhARPW            = (UChar*  )xMalloc(UChar,   uiNumPartition);
     246#endif
     247#if NH_3D_IC
    261248    m_pbICFlag           = (Bool* )xMalloc(Bool,   uiNumPartition);
    262249#endif
    263 #if H_3D_DIM
    264     for( Int i = 0; i < DIM_NUM_TYPE; i++ )
    265     {
    266       m_dimDeltaDC[i][0] = (Pel* )xMalloc(Pel, uiNumPartition);
    267       m_dimDeltaDC[i][1] = (Pel* )xMalloc(Pel, uiNumPartition);
    268     }
    269 #if H_3D_DIM_DMM
    270     for( Int i = 0; i < DMM_NUM_TYPE; i++ )
    271     {
    272       m_dmmWedgeTabIdx[i]    = (UInt*)xMalloc(UInt, uiNumPartition);
    273     }
    274 #endif
    275 #if H_3D_DIM_SDC
     250#if NH_3D_DMM
     251    for( Int i = 0; i < NUM_DMM; i++ )
     252    {
     253      m_dmmDeltaDC[i][0] = (Pel* )xMalloc(Pel, uiNumPartition);
     254      m_dmmDeltaDC[i][1] = (Pel* )xMalloc(Pel, uiNumPartition);
     255    }
     256    m_dmm1WedgeTabIdx    = (UInt*)xMalloc(UInt, uiNumPartition);
     257#endif
     258#if NH_3D_SDC_INTRA
    276259    m_pbSDCFlag             = (Bool*)xMalloc(Bool, uiNumPartition);
    277260    m_apSegmentDCOffset[0]  = (Pel*)xMalloc(Pel, uiNumPartition);
    278261    m_apSegmentDCOffset[1]  = (Pel*)xMalloc(Pel, uiNumPartition);
    279262#endif
    280 #endif
    281 #if H_3D_DBBP
     263#if NH_3D_DBBP
    282264    m_pbDBBPFlag         = (Bool*  )xMalloc(Bool,   uiNumPartition);
    283265#endif
     266
    284267  }
    285268  else
    286269  {
    287     m_acCUMvField[0].setNumPartition(uiNumPartition );
    288     m_acCUMvField[1].setNumPartition(uiNumPartition );
    289   }
    290   m_sliceStartCU        = (UInt*  )xMalloc(UInt, uiNumPartition);
    291   m_sliceSegmentStartCU = (UInt*  )xMalloc(UInt, uiNumPartition);
    292  
    293   // create pattern memory
    294   m_pcPattern            = (TComPattern*)xMalloc(TComPattern, 1);
    295 
     270    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     271    {
     272      m_acCUMvField[i].setNumPartition(uiNumPartition );
     273    }
     274  }
    296275
    297276  // create motion vector fields
    298  
    299   m_pcCUAboveLeft      = NULL;
    300   m_pcCUAboveRight     = NULL;
    301   m_pcCUAbove          = NULL;
    302   m_pcCULeft           = NULL;
    303  
    304   m_apcCUColocated[0]  = NULL;
    305   m_apcCUColocated[1]  = NULL;
     277
     278  m_pCtuAboveLeft      = NULL;
     279  m_pCtuAboveRight     = NULL;
     280  m_pCtuAbove          = NULL;
     281  m_pCtuLeft           = NULL;
     282
     283  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     284  {
     285    m_apcCUColocated[i]  = NULL;
     286  }
    306287}
    307288
    308289Void TComDataCU::destroy()
    309290{
    310   m_pcPic              = NULL;
    311   m_pcSlice            = NULL;
    312  
    313   if ( m_pcPattern )
    314   {
    315     xFree(m_pcPattern);
    316     m_pcPattern = NULL;
    317   }
    318  
    319291  // encoder-side buffer free
    320292  if ( !m_bDecSubCu )
    321293  {
    322     if ( m_phQP               ) { xFree(m_phQP);                m_phQP              = NULL; }
    323     if ( m_puhDepth           ) { xFree(m_puhDepth);            m_puhDepth          = NULL; }
    324     if ( m_puhWidth           ) { xFree(m_puhWidth);            m_puhWidth          = NULL; }
    325     if ( m_puhHeight          ) { xFree(m_puhHeight);           m_puhHeight         = NULL; }
    326 
    327     if ( m_skipFlag           ) { delete[] m_skipFlag;          m_skipFlag          = NULL; }
    328 #if H_3D
     294    if ( m_phQP )
     295    {
     296      xFree(m_phQP);
     297      m_phQP = NULL;
     298    }
     299    if ( m_puhDepth )
     300    {
     301      xFree(m_puhDepth);
     302      m_puhDepth = NULL;
     303    }
     304    if ( m_puhWidth )
     305    {
     306      xFree(m_puhWidth);
     307      m_puhWidth = NULL;
     308    }
     309    if ( m_puhHeight )
     310    {
     311      xFree(m_puhHeight);
     312      m_puhHeight = NULL;
     313    }
     314
     315    if ( m_skipFlag )
     316    {
     317      delete[] m_skipFlag;
     318      m_skipFlag = NULL;
     319    }
     320
     321#if NH_3D_DIS
    329322    if ( m_bDISFlag           ) { delete[] m_bDISFlag;   m_bDISFlag     = NULL; }
    330     if ( m_uiDISType         ) { xFree(m_uiDISType);  m_uiDISType    = NULL; }
    331 #endif
    332     if ( m_pePartSize         ) { delete[] m_pePartSize;        m_pePartSize        = NULL; }
    333     if ( m_pePredMode         ) { delete[] m_pePredMode;        m_pePredMode        = NULL; }
    334     if ( m_CUTransquantBypass ) { delete[] m_CUTransquantBypass;m_CUTransquantBypass = NULL; }
    335     if ( m_puhCbf[0]          ) { xFree(m_puhCbf[0]);           m_puhCbf[0]         = NULL; }
    336     if ( m_puhCbf[1]          ) { xFree(m_puhCbf[1]);           m_puhCbf[1]         = NULL; }
    337     if ( m_puhCbf[2]          ) { xFree(m_puhCbf[2]);           m_puhCbf[2]         = NULL; }
    338     if ( m_puhInterDir        ) { xFree(m_puhInterDir);         m_puhInterDir       = NULL; }
    339     if ( m_pbMergeFlag        ) { xFree(m_pbMergeFlag);         m_pbMergeFlag       = NULL; }
    340     if ( m_puhMergeIndex      ) { xFree(m_puhMergeIndex);       m_puhMergeIndex     = NULL; }
    341 #if H_3D_VSP
    342     if ( m_piVSPFlag          ) { xFree(m_piVSPFlag);           m_piVSPFlag         = NULL; }
    343 #endif
    344 #if H_3D_SPIVMP
     323    if ( m_ucDISType         ) { xFree(m_ucDISType);  m_ucDISType    = NULL; }
     324#endif
     325
     326    if ( m_pePartSize )
     327    {
     328      delete[] m_pePartSize;
     329      m_pePartSize = NULL;
     330    }
     331    if ( m_pePredMode )
     332    {
     333      delete[] m_pePredMode;
     334      m_pePredMode = NULL;
     335    }
     336    if ( m_ChromaQpAdj )
     337    {
     338      delete[] m_ChromaQpAdj;
     339      m_ChromaQpAdj = NULL;
     340    }
     341    if ( m_CUTransquantBypass )
     342    {
     343      delete[] m_CUTransquantBypass;
     344      m_CUTransquantBypass = NULL;
     345    }
     346    if ( m_puhInterDir )
     347    {
     348      xFree(m_puhInterDir);
     349      m_puhInterDir = NULL;
     350    }
     351    if ( m_pbMergeFlag )
     352    {
     353      xFree(m_pbMergeFlag);
     354      m_pbMergeFlag = NULL;
     355    }
     356    if ( m_puhMergeIndex )
     357    {
     358      xFree(m_puhMergeIndex);
     359      m_puhMergeIndex  = NULL;
     360    }
     361
     362#if NH_3D_VSP
     363    if ( m_piVSPFlag )
     364    {
     365      xFree(m_piVSPFlag);
     366      m_piVSPFlag = NULL;
     367    }
     368#endif
     369#if NH_3D_SPIVMP
    345370    if ( m_pbSPIVMPFlag       ) { xFree(m_pbSPIVMPFlag);           m_pbSPIVMPFlag         = NULL; }
    346371#endif
    347     if ( m_puhLumaIntraDir    ) { xFree(m_puhLumaIntraDir);     m_puhLumaIntraDir   = NULL; }
    348     if ( m_puhChromaIntraDir  ) { xFree(m_puhChromaIntraDir);   m_puhChromaIntraDir = NULL; }
    349     if ( m_puhTrIdx           ) { xFree(m_puhTrIdx);            m_puhTrIdx          = NULL; }
    350     if ( m_puhTransformSkip[0]) { xFree(m_puhTransformSkip[0]); m_puhTransformSkip[0] = NULL; }
    351     if ( m_puhTransformSkip[1]) { xFree(m_puhTransformSkip[1]); m_puhTransformSkip[1] = NULL; }
    352     if ( m_puhTransformSkip[2]) { xFree(m_puhTransformSkip[2]); m_puhTransformSkip[2] = NULL; }
    353     if ( m_pcTrCoeffY         ) { xFree(m_pcTrCoeffY);          m_pcTrCoeffY        = NULL; }
    354     if ( m_pcTrCoeffCb        ) { xFree(m_pcTrCoeffCb);         m_pcTrCoeffCb       = NULL; }
    355     if ( m_pcTrCoeffCr        ) { xFree(m_pcTrCoeffCr);         m_pcTrCoeffCr       = NULL; }
     372
     373
     374    for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     375    {
     376      xFree(m_puhIntraDir[ch]);
     377      m_puhIntraDir[ch] = NULL;
     378    }
     379
     380    if ( m_puhTrIdx )
     381    {
     382      xFree(m_puhTrIdx);
     383      m_puhTrIdx = NULL;
     384    }
     385
     386    for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     387    {
     388      if ( m_crossComponentPredictionAlpha[comp] )
     389      {
     390        xFree(m_crossComponentPredictionAlpha[comp]);
     391        m_crossComponentPredictionAlpha[comp] = NULL;
     392      }
     393      if ( m_puhTransformSkip[comp] )
     394      {
     395        xFree(m_puhTransformSkip[comp]);
     396        m_puhTransformSkip[comp] = NULL;
     397      }
     398      if ( m_puhCbf[comp] )
     399      {
     400        xFree(m_puhCbf[comp]);
     401        m_puhCbf[comp] = NULL;
     402      }
     403      if ( m_pcTrCoeff[comp] )
     404      {
     405        xFree(m_pcTrCoeff[comp]);
     406        m_pcTrCoeff[comp] = NULL;
     407      }
     408      if ( m_explicitRdpcmMode[comp] )
     409      {
     410        xFree(m_explicitRdpcmMode[comp]);
     411        m_explicitRdpcmMode[comp] = NULL;
     412      }
     413
    356414#if ADAPTIVE_QP_SELECTION
    357     if (!m_ArlCoeffIsAliasedAllocation)
    358     {
    359       xFree(m_pcArlCoeffY); m_pcArlCoeffY = 0;
    360       xFree(m_pcArlCoeffCb); m_pcArlCoeffCb = 0;
    361       xFree(m_pcArlCoeffCr); m_pcArlCoeffCr = 0;
    362     }
    363     if ( m_pcGlbArlCoeffY     ) { xFree(m_pcGlbArlCoeffY);      m_pcGlbArlCoeffY    = NULL; }
    364     if ( m_pcGlbArlCoeffCb    ) { xFree(m_pcGlbArlCoeffCb);     m_pcGlbArlCoeffCb   = NULL; }
    365     if ( m_pcGlbArlCoeffCr    ) { xFree(m_pcGlbArlCoeffCr);     m_pcGlbArlCoeffCr   = NULL; }
    366 #endif
    367     if ( m_pbIPCMFlag         ) { xFree(m_pbIPCMFlag   );       m_pbIPCMFlag        = NULL; }
    368     if ( m_pcIPCMSampleY      ) { xFree(m_pcIPCMSampleY);       m_pcIPCMSampleY     = NULL; }
    369     if ( m_pcIPCMSampleCb     ) { xFree(m_pcIPCMSampleCb);      m_pcIPCMSampleCb    = NULL; }
    370     if ( m_pcIPCMSampleCr     ) { xFree(m_pcIPCMSampleCr);      m_pcIPCMSampleCr    = NULL; }
    371     if ( m_apiMVPIdx[0]       ) { delete[] m_apiMVPIdx[0];      m_apiMVPIdx[0]      = NULL; }
    372     if ( m_apiMVPIdx[1]       ) { delete[] m_apiMVPIdx[1];      m_apiMVPIdx[1]      = NULL; }
    373     if ( m_apiMVPNum[0]       ) { delete[] m_apiMVPNum[0];      m_apiMVPNum[0]      = NULL; }
    374     if ( m_apiMVPNum[1]       ) { delete[] m_apiMVPNum[1];      m_apiMVPNum[1]      = NULL; }
    375 #if H_3D_NBDV
     415      if (!m_ArlCoeffIsAliasedAllocation)
     416      {
     417        if ( m_pcArlCoeff[comp] )
     418        {
     419          xFree(m_pcArlCoeff[comp]);
     420          m_pcArlCoeff[comp] = NULL;
     421        }
     422      }
     423#endif
     424
     425      if ( m_pcIPCMSample[comp] )
     426      {
     427        xFree(m_pcIPCMSample[comp]);
     428        m_pcIPCMSample[comp] = NULL;
     429      }
     430    }
     431    if ( m_pbIPCMFlag )
     432    {
     433      xFree(m_pbIPCMFlag );
     434      m_pbIPCMFlag = NULL;
     435    }
     436
     437    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     438    {
     439      const RefPicList rpl=RefPicList(i);
     440      if ( m_apiMVPIdx[rpl] )
     441      {
     442        delete[] m_apiMVPIdx[rpl];
     443        m_apiMVPIdx[rpl] = NULL;
     444      }
     445      if ( m_apiMVPNum[rpl] )
     446      {
     447        delete[] m_apiMVPNum[rpl];
     448        m_apiMVPNum[rpl] = NULL;
     449      }
     450    }
     451
     452    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     453    {
     454      const RefPicList rpl=RefPicList(i);
     455      m_acCUMvField[rpl].destroy();
     456    }
     457#if NH_3D_NBDV
    376458    if ( m_pDvInfo            ) { xFree(m_pDvInfo);             m_pDvInfo           = NULL; }
    377459#endif
    378460
    379461
    380 #if H_3D_ARP
    381     if ( m_puhARPW            ) { delete[] m_puhARPW;           m_puhARPW           = NULL; }
    382 #endif
    383 #if H_3D_IC
     462#if NH_3D_ARP
     463    if ( m_puhARPW            ) { xFree(m_puhARPW);             m_puhARPW           = NULL; }
     464#endif
     465#if NH_3D_IC
    384466    if ( m_pbICFlag           ) { xFree(m_pbICFlag);            m_pbICFlag          = NULL; }
    385467#endif
    386     m_acCUMvField[0].destroy();
    387     m_acCUMvField[1].destroy();
    388 
    389 #if H_3D_DIM
    390     for( Int i = 0; i < DIM_NUM_TYPE; i++ )
    391     {
    392       if ( m_dimDeltaDC[i][0] ) { xFree( m_dimDeltaDC[i][0] ); m_dimDeltaDC[i][0] = NULL; }
    393       if ( m_dimDeltaDC[i][1] ) { xFree( m_dimDeltaDC[i][1] ); m_dimDeltaDC[i][1] = NULL; }
    394     }
    395 #if H_3D_DIM_DMM
    396     for( Int i = 0; i < DMM_NUM_TYPE; i++ )
    397     {
    398       if ( m_dmmWedgeTabIdx[i] ) { xFree( m_dmmWedgeTabIdx[i] ); m_dmmWedgeTabIdx[i] = NULL; }
    399     }
    400 #endif
    401 #if H_3D_DIM_SDC
     468
     469#if NH_3D_DMM
     470    for( Int i = 0; i < NUM_DMM; i++ )
     471    {
     472      if ( m_dmmDeltaDC[i][0] ) { xFree( m_dmmDeltaDC[i][0] ); m_dmmDeltaDC[i][0] = NULL; }
     473      if ( m_dmmDeltaDC[i][1] ) { xFree( m_dmmDeltaDC[i][1] ); m_dmmDeltaDC[i][1] = NULL; }
     474    }
     475    if ( m_dmm1WedgeTabIdx    ) { xFree( m_dmm1WedgeTabIdx );  m_dmm1WedgeTabIdx = NULL;  }
     476#endif
     477#if NH_3D_SDC_INTRA
    402478    if ( m_pbSDCFlag            ) { xFree(m_pbSDCFlag);             m_pbSDCFlag             = NULL; }
    403479    if ( m_apSegmentDCOffset[0] ) { xFree(m_apSegmentDCOffset[0]);  m_apSegmentDCOffset[0]  = NULL; }
    404480    if ( m_apSegmentDCOffset[1] ) { xFree(m_apSegmentDCOffset[1]);  m_apSegmentDCOffset[1]  = NULL; }
    405481#endif   
    406 #endif   
    407 #if H_3D_DBBP
     482#if NH_3D_DBBP
    408483    if ( m_pbDBBPFlag         ) { xFree(m_pbDBBPFlag);          m_pbDBBPFlag        = NULL; }
    409484#endif
    410   }
    411   m_pcCUAboveLeft       = NULL;
    412   m_pcCUAboveRight      = NULL;
    413   m_pcCUAbove           = NULL;
    414   m_pcCULeft            = NULL;
    415  
    416   m_apcCUColocated[0]   = NULL;
    417   m_apcCUColocated[1]   = NULL;
    418 
    419   if( m_sliceStartCU )
    420   {
    421     xFree(m_sliceStartCU);
    422     m_sliceStartCU=NULL;
    423   }
    424   if(m_sliceSegmentStartCU )
    425   {
    426     xFree(m_sliceSegmentStartCU);
    427     m_sliceSegmentStartCU=NULL;
    428   }
     485
     486  }
     487
     488  m_pcPic              = NULL;
     489  m_pcSlice            = NULL;
     490
     491  m_pCtuAboveLeft      = NULL;
     492  m_pCtuAboveRight     = NULL;
     493  m_pCtuAbove          = NULL;
     494  m_pCtuLeft           = NULL;
     495
     496
     497  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     498  {
     499    m_apcCUColocated[i]  = NULL;
     500  }
     501
     502}
     503
     504Bool TComDataCU::CUIsFromSameTile            ( const TComDataCU *pCU /* Can be NULL */) const
     505{
     506  return pCU!=NULL &&
     507         pCU->getSlice() != NULL &&
     508         m_pcPic->getPicSym()->getTileIdxMap( pCU->getCtuRsAddr() ) == m_pcPic->getPicSym()->getTileIdxMap(getCtuRsAddr());
     509}
     510
     511Bool TComDataCU::CUIsFromSameSliceAndTile    ( const TComDataCU *pCU /* Can be NULL */) const
     512{
     513  return pCU!=NULL &&
     514         pCU->getSlice() != NULL &&
     515         pCU->getSlice()->getSliceCurStartCtuTsAddr() == getSlice()->getSliceCurStartCtuTsAddr() &&
     516         m_pcPic->getPicSym()->getTileIdxMap( pCU->getCtuRsAddr() ) == m_pcPic->getPicSym()->getTileIdxMap(getCtuRsAddr())
     517         ;
     518}
     519
     520Bool TComDataCU::CUIsFromSameSliceTileAndWavefrontRow( const TComDataCU *pCU /* Can be NULL */) const
     521{
     522  return CUIsFromSameSliceAndTile(pCU)
     523         && (!getSlice()->getPPS()->getEntropyCodingSyncEnabledFlag() || getPic()->getCtu(getCtuRsAddr())->getCUPelY() == getPic()->getCtu(pCU->getCtuRsAddr())->getCUPelY());
     524}
     525
     526Bool TComDataCU::isLastSubCUOfCtu(const UInt absPartIdx)
     527{
     528  const TComSPS &sps=*(getSlice()->getSPS());
     529
     530  const UInt picWidth = sps.getPicWidthInLumaSamples();
     531  const UInt picHeight = sps.getPicHeightInLumaSamples();
     532  const UInt granularityWidth = sps.getMaxCUWidth();
     533
     534  const UInt cuPosX = getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ];
     535  const UInt cuPosY = getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ];
     536
     537  return (((cuPosX+getWidth( absPartIdx))%granularityWidth==0||(cuPosX+getWidth( absPartIdx)==picWidth ))
     538       && ((cuPosY+getHeight(absPartIdx))%granularityWidth==0||(cuPosY+getHeight(absPartIdx)==picHeight)));
    429539}
    430540
     
    438548
    439549/**
    440  - initialize top-level CU
    441  - internal buffers are already created
    442  - set values before encoding a CU
    443  .
    444  \param  pcPic     picture (TComPic) class pointer
    445  \param  iCUAddr   CU address
     550 Initialize top-level CU: create internal buffers and set initial values before encoding the CTU.
     551 
     552 \param  pcPic       picture (TComPic) class pointer
     553 \param  ctuRsAddr   CTU address in raster scan order
    446554 */
    447 Void TComDataCU::initCU( TComPic* pcPic, UInt iCUAddr )
    448 {
    449 
     555Void TComDataCU::initCtu( TComPic* pcPic, UInt ctuRsAddr )
     556{
     557
     558  const UInt maxCUWidth = pcPic->getPicSym()->getSPS().getMaxCUWidth();
     559  const UInt maxCUHeight= pcPic->getPicSym()->getSPS().getMaxCUHeight();
    450560  m_pcPic              = pcPic;
    451561  m_pcSlice            = pcPic->getSlice(pcPic->getCurrSliceIdx());
    452   m_uiCUAddr           = iCUAddr;
    453   m_uiCUPelX           = ( iCUAddr % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth;
    454   m_uiCUPelY           = ( iCUAddr / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight;
    455   m_uiAbsIdxInLCU      = 0;
     562  m_ctuRsAddr          = ctuRsAddr;
     563  m_uiCUPelX           = ( ctuRsAddr % pcPic->getFrameWidthInCtus() ) * maxCUWidth;
     564  m_uiCUPelY           = ( ctuRsAddr / pcPic->getFrameWidthInCtus() ) * maxCUHeight;
     565  m_absZIdxInCtu       = 0;
    456566  m_dTotalCost         = MAX_DOUBLE;
    457567  m_uiTotalDistortion  = 0;
    458568  m_uiTotalBits        = 0;
    459569  m_uiTotalBins        = 0;
    460   m_uiNumPartition     = pcPic->getNumPartInCU();
    461  
    462   for(Int i=0; i<pcPic->getNumPartInCU(); i++)
    463   {
    464     if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceCurStartCUAddr())
    465     {
    466       m_sliceStartCU[i]=getSlice()->getSliceCurStartCUAddr();
    467     }
    468     else
    469     {
    470       m_sliceStartCU[i]=pcPic->getCU(getAddr())->m_sliceStartCU[i];
    471     }
    472   }
    473   for(Int i=0; i<pcPic->getNumPartInCU(); i++)
    474   {
    475     if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceSegmentCurStartCUAddr())
    476     {
    477       m_sliceSegmentStartCU[i]=getSlice()->getSliceSegmentCurStartCUAddr();
    478     }
    479     else
    480     {
    481       m_sliceSegmentStartCU[i]=pcPic->getCU(getAddr())->m_sliceSegmentStartCU[i];
    482     }
    483   }
    484 
    485   Int partStartIdx = getSlice()->getSliceSegmentCurStartCUAddr() - pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr) * pcPic->getNumPartInCU();
    486 
    487   Int numElements = min<Int>( partStartIdx, m_uiNumPartition );
    488   for ( Int ui = 0; ui < numElements; ui++ )
    489   {
    490     TComDataCU * pcFrom = pcPic->getCU(getAddr());
    491     m_skipFlag[ui]   = pcFrom->getSkipFlag(ui);
    492 #if H_3D
    493     m_bDISFlag[ui]   = pcFrom->getDISFlag(ui);
    494     m_uiDISType[ui]  = pcFrom->getDISType(ui);
    495 #endif
    496     m_pePartSize[ui] = pcFrom->getPartitionSize(ui);
    497     m_pePredMode[ui] = pcFrom->getPredictionMode(ui);
    498     m_CUTransquantBypass[ui] = pcFrom->getCUTransquantBypass(ui);
    499     m_puhDepth[ui] = pcFrom->getDepth(ui);
    500 #if H_3D_ARP
    501     m_puhARPW   [ui] = pcFrom->getARPW( ui );
    502 #endif
    503 #if H_3D_IC
    504     m_pbICFlag[ui]   =  pcFrom->m_pbICFlag[ui];
    505 #endif
    506 
    507     m_puhWidth  [ui] = pcFrom->getWidth(ui);
    508     m_puhHeight [ui] = pcFrom->getHeight(ui);
    509     m_puhTrIdx  [ui] = pcFrom->getTransformIdx(ui);
    510     m_puhTransformSkip[0][ui] = pcFrom->getTransformSkip(ui,TEXT_LUMA);
    511     m_puhTransformSkip[1][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_U);
    512     m_puhTransformSkip[2][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_V);
    513     m_apiMVPIdx[0][ui] = pcFrom->m_apiMVPIdx[0][ui];;
    514     m_apiMVPIdx[1][ui] = pcFrom->m_apiMVPIdx[1][ui];
    515     m_apiMVPNum[0][ui] = pcFrom->m_apiMVPNum[0][ui];
    516     m_apiMVPNum[1][ui] = pcFrom->m_apiMVPNum[1][ui];
    517     m_phQP[ui]=pcFrom->m_phQP[ui];
    518     m_pbMergeFlag[ui]=pcFrom->m_pbMergeFlag[ui];
    519     m_puhMergeIndex[ui]=pcFrom->m_puhMergeIndex[ui];
    520 #if H_3D_VSP
    521     m_piVSPFlag[ui] = pcFrom->m_piVSPFlag[ui];
    522 #endif
    523 #if H_3D_SPIVMP
    524     m_pbSPIVMPFlag[ui] = pcFrom->m_pbSPIVMPFlag[ui];
    525 #endif
    526     m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
    527     m_puhChromaIntraDir[ui]=pcFrom->m_puhChromaIntraDir[ui];
    528     m_puhInterDir[ui]=pcFrom->m_puhInterDir[ui];
    529     m_puhCbf[0][ui]=pcFrom->m_puhCbf[0][ui];
    530     m_puhCbf[1][ui]=pcFrom->m_puhCbf[1][ui];
    531     m_puhCbf[2][ui]=pcFrom->m_puhCbf[2][ui];
    532     m_pbIPCMFlag[ui] = pcFrom->m_pbIPCMFlag[ui];
    533 #if H_3D_DIM_SDC
    534     m_pbSDCFlag[ui] = pcFrom->m_pbSDCFlag[ui];
    535 #endif
    536 #if H_3D_DBBP
    537     m_pbDBBPFlag[ui] = pcFrom->m_pbDBBPFlag[ui];
    538 #endif
    539   }
    540  
    541   Int firstElement = max<Int>( partStartIdx, 0 );
    542   numElements = m_uiNumPartition - firstElement;
    543  
    544   if ( numElements > 0 )
    545   {
    546     memset( m_skipFlag          + firstElement, false,                    numElements * sizeof( *m_skipFlag ) );
    547 #if H_3D
    548     memset( m_bDISFlag          + firstElement, false,                    numElements * sizeof( *m_bDISFlag ) );
    549     memset( m_uiDISType         + firstElement,     0,                    numElements * sizeof( *m_uiDISType) );
    550 #endif
    551     memset( m_pePartSize        + firstElement, SIZE_NONE,                numElements * sizeof( *m_pePartSize ) );
    552     memset( m_pePredMode        + firstElement, MODE_NONE,                numElements * sizeof( *m_pePredMode ) );
    553     memset( m_CUTransquantBypass+ firstElement, false,                    numElements * sizeof( *m_CUTransquantBypass) );
    554     memset( m_puhDepth          + firstElement, 0,                        numElements * sizeof( *m_puhDepth ) );
    555     memset( m_puhTrIdx          + firstElement, 0,                        numElements * sizeof( *m_puhTrIdx ) );
    556     memset( m_puhTransformSkip[0] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[0]) );
    557     memset( m_puhTransformSkip[1] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[1]) );
    558     memset( m_puhTransformSkip[2] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[2]) );
    559     memset( m_puhWidth          + firstElement, g_uiMaxCUWidth,           numElements * sizeof( *m_puhWidth ) );
    560     memset( m_puhHeight         + firstElement, g_uiMaxCUHeight,          numElements * sizeof( *m_puhHeight ) );
    561     memset( m_apiMVPIdx[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[0] ) );
    562     memset( m_apiMVPIdx[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[1] ) );
    563     memset( m_apiMVPNum[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[0] ) );
    564     memset( m_apiMVPNum[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[1] ) );
    565     memset( m_phQP              + firstElement, getSlice()->getSliceQp(), numElements * sizeof( *m_phQP ) );
    566     memset( m_pbMergeFlag       + firstElement, false,                    numElements * sizeof( *m_pbMergeFlag ) );
    567     memset( m_puhMergeIndex     + firstElement, 0,                        numElements * sizeof( *m_puhMergeIndex ) );
    568 #if H_3D_VSP
    569     memset( m_piVSPFlag         + firstElement, 0,                        numElements * sizeof( *m_piVSPFlag ) );
    570 #endif
    571 #if H_3D_SPIVMP
    572     memset( m_pbSPIVMPFlag      + firstElement, 0,                        numElements * sizeof( *m_pbSPIVMPFlag ) );
    573 #endif
    574     memset( m_puhLumaIntraDir   + firstElement, DC_IDX,                   numElements * sizeof( *m_puhLumaIntraDir ) );
    575     memset( m_puhChromaIntraDir + firstElement, 0,                        numElements * sizeof( *m_puhChromaIntraDir ) );
    576     memset( m_puhInterDir       + firstElement, 0,                        numElements * sizeof( *m_puhInterDir ) );
    577     memset( m_puhCbf[0]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[0] ) );
    578     memset( m_puhCbf[1]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[1] ) );
    579     memset( m_puhCbf[2]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[2] ) );
    580     memset( m_pbIPCMFlag        + firstElement, false,                    numElements * sizeof( *m_pbIPCMFlag ) );
    581 #if H_3D_ARP
    582     memset( m_puhARPW           + firstElement, 0,                        numElements * sizeof( UChar )         );
    583 #endif
    584 #if H_3D_IC
    585     memset( m_pbICFlag          + firstElement, false,                    numElements * sizeof( *m_pbICFlag )   );
    586 #endif
    587 
    588 
    589 #if H_3D_DIM
    590     for( Int i = 0; i < DIM_NUM_TYPE; i++ )
    591     {
    592       memset( m_dimDeltaDC[i][0] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][0] ) );
    593       memset( m_dimDeltaDC[i][1] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][1] ) );
    594     }
    595 #if H_3D_DIM_DMM
    596     for( Int i = 0; i < DMM_NUM_TYPE; i++ )
    597     {
    598       memset( m_dmmWedgeTabIdx[i] + firstElement, 0,                      numElements * sizeof( *m_dmmWedgeTabIdx[i] ) );
    599     }
    600 #endif
    601 #if H_3D_DIM_SDC
    602     memset( m_pbSDCFlag             + firstElement,     0,                numElements * sizeof( *m_pbSDCFlag            ) );
    603     memset( m_apSegmentDCOffset[0]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[0] ) );
    604     memset( m_apSegmentDCOffset[1]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[1] ) );
    605 #endif
    606     m_apDmmPredictor[0] = 0;
    607     m_apDmmPredictor[1] = 0;
    608 #endif
    609 #if H_3D_DBBP
    610     memset( m_pbDBBPFlag        + firstElement, false,                    numElements * sizeof( *m_pbDBBPFlag ) );
    611 #endif
    612   }
    613  
    614   UInt uiTmp = g_uiMaxCUWidth*g_uiMaxCUHeight;
    615   if ( 0 >= partStartIdx )
    616   {
    617     m_acCUMvField[0].clearMvField();
    618     m_acCUMvField[1].clearMvField();
    619     memset( m_pcTrCoeffY , 0, sizeof( TCoeff ) * uiTmp );
     570  m_uiNumPartition     = pcPic->getNumPartitionsInCtu();
     571
     572  memset( m_skipFlag          , false,                      m_uiNumPartition * sizeof( *m_skipFlag ) );
     573
     574#if NH_3D_DIS
     575    memset( m_bDISFlag        , false,                      m_uiNumPartition * sizeof( *m_bDISFlag ) );
     576    memset( m_ucDISType       , false,                      m_uiNumPartition * sizeof( *m_ucDISType ) );
     577#endif
     578
     579  memset( m_pePartSize        , NUMBER_OF_PART_SIZES,       m_uiNumPartition * sizeof( *m_pePartSize ) );
     580  memset( m_pePredMode        , NUMBER_OF_PREDICTION_MODES, m_uiNumPartition * sizeof( *m_pePredMode ) );
     581  memset( m_CUTransquantBypass, false,                      m_uiNumPartition * sizeof( *m_CUTransquantBypass) );
     582  memset( m_puhDepth          , 0,                          m_uiNumPartition * sizeof( *m_puhDepth ) );
     583  memset( m_puhTrIdx          , 0,                          m_uiNumPartition * sizeof( *m_puhTrIdx ) );
     584  memset( m_puhWidth          , maxCUWidth,                 m_uiNumPartition * sizeof( *m_puhWidth ) );
     585  memset( m_puhHeight         , maxCUHeight,                m_uiNumPartition * sizeof( *m_puhHeight ) );
     586
     587#if NH_3D_IC
     588  memset( m_pbICFlag          , false,                      m_uiNumPartition * sizeof( *m_pbICFlag ) );
     589#endif
     590  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     591  {
     592    const RefPicList rpl=RefPicList(i);
     593    memset( m_apiMVPIdx[rpl]  , -1,                         m_uiNumPartition * sizeof( *m_apiMVPIdx[rpl] ) );
     594    memset( m_apiMVPNum[rpl]  , -1,                         m_uiNumPartition * sizeof( *m_apiMVPNum[rpl] ) );
     595  }
     596  memset( m_phQP              , getSlice()->getSliceQp(),   m_uiNumPartition * sizeof( *m_phQP ) );
     597  memset( m_ChromaQpAdj       , 0,                          m_uiNumPartition * sizeof( *m_ChromaQpAdj ) );
     598  for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     599  {
     600    memset( m_crossComponentPredictionAlpha[comp] , 0,                     m_uiNumPartition * sizeof( *m_crossComponentPredictionAlpha[comp] ) );
     601    memset( m_puhTransformSkip[comp]              , 0,                     m_uiNumPartition * sizeof( *m_puhTransformSkip[comp]) );
     602    memset( m_puhCbf[comp]                        , 0,                     m_uiNumPartition * sizeof( *m_puhCbf[comp] ) );
     603    memset( m_explicitRdpcmMode[comp]             , NUMBER_OF_RDPCM_MODES, m_uiNumPartition * sizeof( *m_explicitRdpcmMode[comp] ) );
     604  }
     605  memset( m_pbMergeFlag       , false,                    m_uiNumPartition * sizeof( *m_pbMergeFlag ) );
     606  memset( m_puhMergeIndex     , 0,                        m_uiNumPartition * sizeof( *m_puhMergeIndex ) );
     607
     608#if NH_3D_VSP
     609  memset( m_piVSPFlag         , 0,                        m_uiNumPartition * sizeof( *m_piVSPFlag ) );
     610#endif
     611#if NH_3D_SPIVMP
     612  memset( m_pbSPIVMPFlag      , 0,                     m_uiNumPartition * sizeof( *m_pbSPIVMPFlag ) );   
     613#endif
     614#if NH_3D_SDC_INTRA
     615  memset( m_pbSDCFlag, false, m_uiNumPartition * sizeof( *m_pbSDCFlag ) );
     616#endif
     617#if NH_3D_DBBP
     618  memset( m_pbDBBPFlag , false, m_uiNumPartition * sizeof( *m_pbDBBPFlag ));
     619#endif
     620
     621  for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     622  {
     623    memset( m_puhIntraDir[ch] , ((ch==0) ? DC_IDX : 0),   m_uiNumPartition * sizeof( *(m_puhIntraDir[ch]) ) );
     624  }
     625
     626#if NH_3D_ARP
     627  memset( m_puhARPW      ,      0,        m_uiNumPartition * sizeof( *m_puhARPW )         );
     628#endif
     629
     630
     631#if NH_3D_DMM
     632  for( Int i = 0; i < NUM_DMM; i++ )
     633  {
     634    memset( m_dmmDeltaDC[i][0], 0,                        m_uiNumPartition * sizeof( *m_dmmDeltaDC[i][0] ) );
     635    memset( m_dmmDeltaDC[i][1], 0,                        m_uiNumPartition * sizeof( *m_dmmDeltaDC[i][1] ) );
     636  }
     637  memset( m_dmm1WedgeTabIdx,    0,                        m_uiNumPartition * sizeof( *m_dmm1WedgeTabIdx   ) );
     638#endif
     639#if NH_3D_SDC_INTRA
     640    memset( m_pbSDCFlag,     false,                m_uiNumPartition * sizeof( *m_pbSDCFlag ) );
     641    memset( m_apSegmentDCOffset[0],     0,                m_uiNumPartition * sizeof( *m_apSegmentDCOffset[0] ) );
     642    memset( m_apSegmentDCOffset[1],     0,                m_uiNumPartition * sizeof( *m_apSegmentDCOffset[1] ) );
     643#endif
     644
     645  memset( m_puhInterDir       , 0,                        m_uiNumPartition * sizeof( *m_puhInterDir ) );
     646  memset( m_pbIPCMFlag        , false,                    m_uiNumPartition * sizeof( *m_pbIPCMFlag ) );
     647
     648  const UInt numCoeffY    = maxCUWidth*maxCUHeight;
     649  for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     650  {
     651    const UInt componentShift = m_pcPic->getComponentScaleX(ComponentID(comp)) + m_pcPic->getComponentScaleY(ComponentID(comp));
     652    memset( m_pcTrCoeff[comp], 0, sizeof(TCoeff)* numCoeffY>>componentShift );
    620653#if ADAPTIVE_QP_SELECTION
    621     memset( m_pcArlCoeffY , 0, sizeof( Int ) * uiTmp ); 
    622 #endif
    623     memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
    624     uiTmp  >>= 2;
    625     memset( m_pcTrCoeffCb, 0, sizeof( TCoeff ) * uiTmp );
    626     memset( m_pcTrCoeffCr, 0, sizeof( TCoeff ) * uiTmp );
    627 #if ADAPTIVE_QP_SELECTION 
    628     memset( m_pcArlCoeffCb, 0, sizeof( Int ) * uiTmp );
    629     memset( m_pcArlCoeffCr, 0, sizeof( Int ) * uiTmp );
    630 #endif
    631     memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
    632     memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
    633   }
    634   else
    635   {
    636     TComDataCU * pcFrom = pcPic->getCU(getAddr());
    637     m_acCUMvField[0].copyFrom(&pcFrom->m_acCUMvField[0],m_uiNumPartition,0);
    638     m_acCUMvField[1].copyFrom(&pcFrom->m_acCUMvField[1],m_uiNumPartition,0);
    639     for(Int i=0; i<uiTmp; i++)
    640     {
    641       m_pcTrCoeffY[i]=pcFrom->m_pcTrCoeffY[i];
    642 #if ADAPTIVE_QP_SELECTION
    643       m_pcArlCoeffY[i]=pcFrom->m_pcArlCoeffY[i];
    644 #endif
    645       m_pcIPCMSampleY[i]=pcFrom->m_pcIPCMSampleY[i];
    646     }
    647     for(Int i=0; i<(uiTmp>>2); i++)
    648     {
    649       m_pcTrCoeffCb[i]=pcFrom->m_pcTrCoeffCb[i];
    650       m_pcTrCoeffCr[i]=pcFrom->m_pcTrCoeffCr[i];
    651 #if ADAPTIVE_QP_SELECTION
    652       m_pcArlCoeffCb[i]=pcFrom->m_pcArlCoeffCb[i];
    653       m_pcArlCoeffCr[i]=pcFrom->m_pcArlCoeffCr[i];
    654 #endif
    655       m_pcIPCMSampleCb[i]=pcFrom->m_pcIPCMSampleCb[i];
    656       m_pcIPCMSampleCr[i]=pcFrom->m_pcIPCMSampleCr[i];
    657     }
     654    memset( m_pcArlCoeff[comp], 0, sizeof(TCoeff)* numCoeffY>>componentShift );
     655#endif
     656  }
     657
     658  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     659  {
     660    m_acCUMvField[i].clearMvField();
    658661  }
    659662
    660663  // Setting neighbor CU
    661   m_pcCULeft        = NULL;
    662   m_pcCUAbove       = NULL;
    663   m_pcCUAboveLeft   = NULL;
    664   m_pcCUAboveRight  = NULL;
    665 
    666   m_apcCUColocated[0] = NULL;
    667   m_apcCUColocated[1] = NULL;
    668 
    669   UInt uiWidthInCU = pcPic->getFrameWidthInCU();
    670   if ( m_uiCUAddr % uiWidthInCU )
    671   {
    672     m_pcCULeft = pcPic->getCU( m_uiCUAddr - 1 );
    673   }
    674 
    675   if ( m_uiCUAddr / uiWidthInCU )
    676   {
    677     m_pcCUAbove = pcPic->getCU( m_uiCUAddr - uiWidthInCU );
    678   }
    679 
    680   if ( m_pcCULeft && m_pcCUAbove )
    681   {
    682     m_pcCUAboveLeft = pcPic->getCU( m_uiCUAddr - uiWidthInCU - 1 );
    683   }
    684 
    685   if ( m_pcCUAbove && ( (m_uiCUAddr%uiWidthInCU) < (uiWidthInCU-1) )  )
    686   {
    687     m_pcCUAboveRight = pcPic->getCU( m_uiCUAddr - uiWidthInCU + 1 );
    688   }
    689 
    690   if ( getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 )
    691   {
    692     m_apcCUColocated[0] = getSlice()->getRefPic( REF_PIC_LIST_0, 0)->getCU( m_uiCUAddr );
    693   }
    694 
    695   if ( getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 )
    696   {
    697     m_apcCUColocated[1] = getSlice()->getRefPic( REF_PIC_LIST_1, 0)->getCU( m_uiCUAddr );
    698   }
    699 }
    700 
    701 /** initialize prediction data with enabling sub-LCU-level delta QP
    702 *\param  uiDepth  depth of the current CU
    703 *\param  qp     qp for the current CU
    704 *- set CU width and CU height according to depth
    705 *- set qp value according to input qp
    706 *- set last-coded qp value according to input last-coded qp
     664  m_pCtuLeft        = NULL;
     665  m_pCtuAbove       = NULL;
     666  m_pCtuAboveLeft   = NULL;
     667  m_pCtuAboveRight  = NULL;
     668
     669
     670  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     671  {
     672    m_apcCUColocated[i]  = NULL;
     673  }
     674
     675  UInt frameWidthInCtus = pcPic->getFrameWidthInCtus();
     676  if ( m_ctuRsAddr % frameWidthInCtus )
     677  {
     678    m_pCtuLeft = pcPic->getCtu( m_ctuRsAddr - 1 );
     679  }
     680
     681  if ( m_ctuRsAddr / frameWidthInCtus )
     682  {
     683    m_pCtuAbove = pcPic->getCtu( m_ctuRsAddr - frameWidthInCtus );
     684  }
     685
     686  if ( m_pCtuLeft && m_pCtuAbove )
     687  {
     688    m_pCtuAboveLeft = pcPic->getCtu( m_ctuRsAddr - frameWidthInCtus - 1 );
     689  }
     690
     691  if ( m_pCtuAbove && ( (m_ctuRsAddr%frameWidthInCtus) < (frameWidthInCtus-1) )  )
     692  {
     693    m_pCtuAboveRight = pcPic->getCtu( m_ctuRsAddr - frameWidthInCtus + 1 );
     694  }
     695
     696  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     697  {
     698    const RefPicList rpl=RefPicList(i);
     699    if ( getSlice()->getNumRefIdx( rpl ) > 0 )
     700    {
     701      m_apcCUColocated[rpl] = getSlice()->getRefPic( rpl, 0)->getCtu( m_ctuRsAddr );
     702    }
     703  }
     704}
     705
     706
     707/** Initialize prediction data with enabling sub-CTU-level delta QP.
     708*   - set CU width and CU height according to depth
     709*   - set qp value according to input qp
     710*   - set last-coded qp value according to input last-coded qp
     711*
     712* \param  uiDepth            depth of the current CU
     713* \param  qp                 qp for the current CU
     714* \param  bTransquantBypass  true for transquant bypass
    707715*/
    708 Void TComDataCU::initEstData( UInt uiDepth, Int qp, Bool bTransquantBypass )
     716Void TComDataCU::initEstData( const UInt uiDepth, const Int qp, const Bool bTransquantBypass )
    709717{
    710718  m_dTotalCost         = MAX_DOUBLE;
     
    713721  m_uiTotalBins        = 0;
    714722
    715   UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
    716   UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
     723  const UChar uhWidth  = getSlice()->getSPS()->getMaxCUWidth()  >> uiDepth;
     724  const UChar uhHeight = getSlice()->getSPS()->getMaxCUHeight() >> uiDepth;
    717725
    718726  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
    719727  {
    720     if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui >= getSlice()->getSliceSegmentCurStartCUAddr())
    721     {
    722       m_apiMVPIdx[0][ui] = -1;
    723       m_apiMVPIdx[1][ui] = -1;
    724       m_apiMVPNum[0][ui] = -1;
    725       m_apiMVPNum[1][ui] = -1;
    726       m_puhDepth  [ui] = uiDepth;
    727       m_puhWidth  [ui] = uhWidth;
    728       m_puhHeight [ui] = uhHeight;
    729       m_puhTrIdx  [ui] = 0;
    730       m_puhTransformSkip[0][ui] = 0;
    731       m_puhTransformSkip[1][ui] = 0;
    732       m_puhTransformSkip[2][ui] = 0;
    733       m_skipFlag[ui]   = false;
    734 #if H_3D
    735       m_bDISFlag[ui]   = false;
    736       m_uiDISType[ui]  = 0;
    737 #endif
    738       m_pePartSize[ui] = SIZE_NONE;
    739       m_pePredMode[ui] = MODE_NONE;
    740       m_CUTransquantBypass[ui] = bTransquantBypass;
    741       m_pbIPCMFlag[ui] = 0;
    742       m_phQP[ui] = qp;
    743       m_pbMergeFlag[ui] = 0;
    744       m_puhMergeIndex[ui] = 0;
    745 #if H_3D_VSP
    746       m_piVSPFlag[ui] = 0;
    747 #endif
    748 #if H_3D_SPIVMP
    749       m_pbSPIVMPFlag[ui] = 0;
    750 #endif
    751       m_puhLumaIntraDir[ui] = DC_IDX;
    752       m_puhChromaIntraDir[ui] = 0;
    753       m_puhInterDir[ui] = 0;
    754       m_puhCbf[0][ui] = 0;
    755       m_puhCbf[1][ui] = 0;
    756       m_puhCbf[2][ui] = 0;
    757 #if H_3D_ARP
     728    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     729    {
     730      const RefPicList rpl=RefPicList(i);
     731      m_apiMVPIdx[rpl][ui]  = -1;
     732      m_apiMVPNum[rpl][ui]  = -1;
     733    }
     734    m_puhDepth  [ui]    = uiDepth;
     735    m_puhWidth  [ui]    = uhWidth;
     736    m_puhHeight [ui]    = uhHeight;
     737    m_puhTrIdx  [ui]    = 0;
     738    for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     739    {
     740      m_crossComponentPredictionAlpha[comp][ui] = 0;
     741      m_puhTransformSkip             [comp][ui] = 0;
     742      m_explicitRdpcmMode            [comp][ui] = NUMBER_OF_RDPCM_MODES;
     743    }
     744    m_skipFlag[ui]      = false;
     745#if NH_3D_DIS
     746    m_bDISFlag[ui]      = false;
     747    m_ucDISType[ui]     = 0;
     748#endif
     749    m_pePartSize[ui]    = NUMBER_OF_PART_SIZES;
     750    m_pePredMode[ui]    = NUMBER_OF_PREDICTION_MODES;
     751    m_CUTransquantBypass[ui] = bTransquantBypass;
     752    m_pbIPCMFlag[ui]    = 0;
     753    m_phQP[ui]          = qp;
     754    m_ChromaQpAdj[ui]   = 0;
     755    m_pbMergeFlag[ui]   = 0;
     756    m_puhMergeIndex[ui] = 0;
     757#if NH_3D_VSP
     758    m_piVSPFlag[ui]     = 0;
     759#endif
     760#if NH_3D_SPIVMP
     761    m_pbSPIVMPFlag[ui] = 0;
     762#endif
     763
     764    for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     765    {
     766      m_puhIntraDir[ch][ui] = ((ch==0) ? DC_IDX : 0);
     767    }
     768
     769    m_puhInterDir[ui] = 0;
     770    for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     771    {
     772      m_puhCbf[comp][ui] = 0;
     773    }
     774#if NH_3D_ARP
    758775      m_puhARPW[ui] = 0;
    759776#endif
    760 #if H_3D_IC
     777#if NH_3D_IC
    761778      m_pbICFlag[ui]  = false;
    762779#endif
    763780
    764781
    765 #if H_3D_DIM
    766       for( Int i = 0; i < DIM_NUM_TYPE; i++ )
    767       {
    768         m_dimDeltaDC[i][0] [ui] = 0;
    769         m_dimDeltaDC[i][1] [ui] = 0;
    770       }
    771 #if H_3D_DIM_DMM
    772       for( Int i = 0; i < DMM_NUM_TYPE; i++ )
    773       {
    774         m_dmmWedgeTabIdx[i] [ui] = 0;
    775       }
    776 #endif
    777 #if H_3D_DIM_SDC
     782#if NH_3D_DMM
     783    for( Int i = 0; i < NUM_DMM; i++ )
     784    {
     785      m_dmmDeltaDC[i][0] [ui] = 0;
     786      m_dmmDeltaDC[i][1] [ui] = 0;
     787    }
     788    m_dmm1WedgeTabIdx    [ui] = 0;
     789#endif
     790#if NH_3D_SDC_INTRA
    778791      m_pbSDCFlag           [ui] = false;
    779792      m_apSegmentDCOffset[0][ui] = 0;
    780793      m_apSegmentDCOffset[1][ui] = 0;
    781794#endif
    782       m_apDmmPredictor[0] = 0;
    783       m_apDmmPredictor[1] = 0;
    784 #endif
    785 #if H_3D_DBBP
     795#if NH_3D_DBBP
    786796      m_pbDBBPFlag[ui] = false;
    787797#endif
    788     }
    789   }
    790 
    791   if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU >= getSlice()->getSliceSegmentCurStartCUAddr())
    792   {
    793     m_acCUMvField[0].clearMvField();
    794     m_acCUMvField[1].clearMvField();
    795     UInt uiTmp = uhWidth*uhHeight;
    796    
    797     memset( m_pcTrCoeffY,    0, uiTmp * sizeof( *m_pcTrCoeffY    ) );
     798  }
     799
     800  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     801  {
     802    m_acCUMvField[i].clearMvField();
     803  }
     804
     805  const UInt numCoeffY = uhWidth*uhHeight;
     806
     807  for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     808  {
     809    const ComponentID component = ComponentID(comp);
     810    const UInt numCoeff = numCoeffY >> (getPic()->getComponentScaleX(component) + getPic()->getComponentScaleY(component));
     811    memset( m_pcTrCoeff[comp],    0, numCoeff * sizeof( TCoeff ) );
    798812#if ADAPTIVE_QP_SELECTION
    799     memset( m_pcArlCoeffY ,  0, uiTmp * sizeof( *m_pcArlCoeffY   ) );
    800 #endif
    801     memset( m_pcIPCMSampleY, 0, uiTmp * sizeof( *m_pcIPCMSampleY ) );
    802 
    803     uiTmp>>=2;
    804     memset( m_pcTrCoeffCb,    0, uiTmp * sizeof( *m_pcTrCoeffCb    ) );
    805     memset( m_pcTrCoeffCr,    0, uiTmp * sizeof( *m_pcTrCoeffCr    ) );
    806 #if ADAPTIVE_QP_SELECTION 
    807     memset( m_pcArlCoeffCb,   0, uiTmp * sizeof( *m_pcArlCoeffCb   ) );
    808     memset( m_pcArlCoeffCr,   0, uiTmp * sizeof( *m_pcArlCoeffCr   ) );
    809 #endif
    810     memset( m_pcIPCMSampleCb, 0, uiTmp * sizeof( *m_pcIPCMSampleCb ) );
    811     memset( m_pcIPCMSampleCr, 0, uiTmp * sizeof( *m_pcIPCMSampleCr ) );
     813    memset( m_pcArlCoeff[comp],   0, numCoeff * sizeof( TCoeff ) );
     814#endif
     815    memset( m_pcIPCMSample[comp], 0, numCoeff * sizeof( Pel) );
    812816  }
    813817}
     
    822826
    823827  m_pcPic              = pcCU->getPic();
    824   m_pcSlice            = m_pcPic->getSlice(m_pcPic->getCurrSliceIdx());
    825   m_uiCUAddr           = pcCU->getAddr();
    826   m_uiAbsIdxInLCU      = pcCU->getZorderIdxInCU() + uiPartOffset;
    827 
    828   m_uiCUPelX           = pcCU->getCUPelX() + ( g_uiMaxCUWidth>>uiDepth  )*( uiPartUnitIdx &  1 );
    829   m_uiCUPelY           = pcCU->getCUPelY() + ( g_uiMaxCUHeight>>uiDepth  )*( uiPartUnitIdx >> 1 );
     828  m_pcSlice            = pcCU->getSlice();
     829  m_ctuRsAddr          = pcCU->getCtuRsAddr();
     830  m_absZIdxInCtu       = pcCU->getZorderIdxInCtu() + uiPartOffset;
     831
     832  const UChar uhWidth  = getSlice()->getSPS()->getMaxCUWidth()  >> uiDepth;
     833  const UChar uhHeight = getSlice()->getSPS()->getMaxCUHeight() >> uiDepth;
     834
     835  m_uiCUPelX           = pcCU->getCUPelX() + ( uhWidth )*( uiPartUnitIdx &  1 );
     836  m_uiCUPelY           = pcCU->getCUPelY() + ( uhHeight)*( uiPartUnitIdx >> 1 );
    830837
    831838  m_dTotalCost         = MAX_DOUBLE;
     
    837844  Int iSizeInUchar = sizeof( UChar  ) * m_uiNumPartition;
    838845  Int iSizeInBool  = sizeof( Bool   ) * m_uiNumPartition;
    839 
    840846  Int sizeInChar = sizeof( Char  ) * m_uiNumPartition;
     847
    841848  memset( m_phQP,              qp,  sizeInChar );
    842 
    843849  memset( m_pbMergeFlag,        0, iSizeInBool  );
    844850  memset( m_puhMergeIndex,      0, iSizeInUchar );
    845 #if H_3D_VSP
     851#if NH_3D_VSP
    846852  memset( m_piVSPFlag,          0, sizeof( Char  ) * m_uiNumPartition );
    847853#endif
    848 #if H_3D_SPIVMP
     854#if NH_3D_SPIVMP
    849855  memset( m_pbSPIVMPFlag,       0, sizeof( Bool  ) * m_uiNumPartition );
    850856#endif
    851   memset( m_puhLumaIntraDir,    DC_IDX, iSizeInUchar );
    852   memset( m_puhChromaIntraDir,  0, iSizeInUchar );
     857
     858  for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     859  {
     860    memset( m_puhIntraDir[ch],  ((ch==0) ? DC_IDX : 0), iSizeInUchar );
     861  }
     862
    853863  memset( m_puhInterDir,        0, iSizeInUchar );
    854864  memset( m_puhTrIdx,           0, iSizeInUchar );
    855   memset( m_puhTransformSkip[0], 0, iSizeInUchar );
    856   memset( m_puhTransformSkip[1], 0, iSizeInUchar );
    857   memset( m_puhTransformSkip[2], 0, iSizeInUchar );
    858   memset( m_puhCbf[0],          0, iSizeInUchar );
    859   memset( m_puhCbf[1],          0, iSizeInUchar );
    860   memset( m_puhCbf[2],          0, iSizeInUchar );
     865
     866  for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     867  {
     868    memset( m_crossComponentPredictionAlpha[comp], 0, iSizeInUchar );
     869    memset( m_puhTransformSkip[comp],              0, iSizeInUchar );
     870    memset( m_puhCbf[comp],                        0, iSizeInUchar );
     871    memset( m_explicitRdpcmMode[comp],             NUMBER_OF_RDPCM_MODES, iSizeInUchar );
     872  }
     873
    861874  memset( m_puhDepth,     uiDepth, iSizeInUchar );
    862 #if H_3D_ARP
    863   memset( m_puhARPW,            0, iSizeInUchar  );
    864 #endif
    865 
    866 
    867   UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
    868   UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
    869875  memset( m_puhWidth,          uhWidth,  iSizeInUchar );
    870876  memset( m_puhHeight,         uhHeight, iSizeInUchar );
    871877  memset( m_pbIPCMFlag,        0, iSizeInBool  );
    872 #if H_3D_IC
     878#if NH_3D_ARP
     879  memset( m_puhARPW,           0, iSizeInUchar  );
     880#endif
     881#if NH_3D_IC
    873882  memset( m_pbICFlag,          0, iSizeInBool  );
    874883#endif
    875 #if H_3D_DIM
    876   for( Int i = 0; i < DIM_NUM_TYPE; i++ )
    877   {
    878     memset( m_dimDeltaDC[i][0], 0, sizeof(Pel ) * m_uiNumPartition );
    879     memset( m_dimDeltaDC[i][1], 0, sizeof(Pel ) * m_uiNumPartition );
    880   }
    881 #if H_3D_DIM_DMM
    882   for( Int i = 0; i < DMM_NUM_TYPE; i++ )
    883   {
    884     memset( m_dmmWedgeTabIdx[i], 0, sizeof(UInt) * m_uiNumPartition );
    885   }
    886 #endif
    887 #if H_3D_DIM_SDC
     884#if NH_3D_DMM
     885  for( Int i = 0; i < NUM_DMM; i++ )
     886  {
     887    memset( m_dmmDeltaDC[i][0], 0, sizeof(Pel ) * m_uiNumPartition );
     888    memset( m_dmmDeltaDC[i][1], 0, sizeof(Pel ) * m_uiNumPartition );
     889  }
     890  memset( m_dmm1WedgeTabIdx,    0, sizeof(UInt) * m_uiNumPartition );
     891#endif
     892#if NH_3D_SDC_INTRA
    888893  memset( m_pbSDCFlag,            0, sizeof(Bool) * m_uiNumPartition  );
    889894  memset( m_apSegmentDCOffset[0], 0, sizeof(Pel) * m_uiNumPartition   );
    890895  memset( m_apSegmentDCOffset[1], 0, sizeof(Pel) * m_uiNumPartition   );
    891896#endif
    892   m_apDmmPredictor[0] = 0;
    893   m_apDmmPredictor[1] = 0;
    894 #endif
    895 #if H_3D_DBBP
    896   memset( m_pbDBBPFlag,         0, iSizeInBool  );
     897#if NH_3D_DBBP
     898  memset( m_pbDBBPFlag,         0, sizeof(Bool) * m_uiNumPartition  );
    897899#endif
    898900
     
    900902  {
    901903    m_skipFlag[ui]   = false;
    902 #if H_3D
     904#if NH_3D_DIS
    903905    m_bDISFlag[ui]   = false;
    904     m_uiDISType[ui]  = 0;
    905 #endif
    906     m_pePartSize[ui] = SIZE_NONE;
    907     m_pePredMode[ui] = MODE_NONE;
     906    m_ucDISType[ui]  = 0;
     907#endif
     908
     909    m_pePartSize[ui] = NUMBER_OF_PART_SIZES;
     910    m_pePredMode[ui] = NUMBER_OF_PREDICTION_MODES;
    908911    m_CUTransquantBypass[ui] = false;
    909     m_apiMVPIdx[0][ui] = -1;
    910     m_apiMVPIdx[1][ui] = -1;
    911     m_apiMVPNum[0][ui] = -1;
    912     m_apiMVPNum[1][ui] = -1;
    913     if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui<getSlice()->getSliceSegmentCurStartCUAddr())
    914     {
    915       m_apiMVPIdx[0][ui] = pcCU->m_apiMVPIdx[0][uiPartOffset+ui];
    916       m_apiMVPIdx[1][ui] = pcCU->m_apiMVPIdx[1][uiPartOffset+ui];;
    917       m_apiMVPNum[0][ui] = pcCU->m_apiMVPNum[0][uiPartOffset+ui];;
    918       m_apiMVPNum[1][ui] = pcCU->m_apiMVPNum[1][uiPartOffset+ui];;
    919       m_puhDepth  [ui] = pcCU->getDepth(uiPartOffset+ui);
    920       m_puhWidth  [ui] = pcCU->getWidth(uiPartOffset+ui);
    921       m_puhHeight  [ui] = pcCU->getHeight(uiPartOffset+ui);
    922       m_puhTrIdx  [ui] = pcCU->getTransformIdx(uiPartOffset+ui);
    923       m_puhTransformSkip[0][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_LUMA);
    924       m_puhTransformSkip[1][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_U);
    925       m_puhTransformSkip[2][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_V);
    926       m_skipFlag[ui]   = pcCU->getSkipFlag(uiPartOffset+ui);
    927 #if H_3D
     912    m_ChromaQpAdj[ui] = 0;
     913
     914    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     915    {
     916      const RefPicList rpl=RefPicList(i);
     917      m_apiMVPIdx[rpl][ui] = -1;
     918      m_apiMVPNum[rpl][ui] = -1;
     919    }
     920#if NH_3D_DIS
    928921      m_bDISFlag[ui]    = pcCU->getDISFlag(uiPartOffset+ui);
    929       m_uiDISType[ui]   = pcCU->getDISType(uiPartOffset+ui);
    930 #endif
    931       m_pePartSize[ui] = pcCU->getPartitionSize(uiPartOffset+ui);
    932       m_pePredMode[ui] = pcCU->getPredictionMode(uiPartOffset+ui);
    933       m_CUTransquantBypass[ui] = pcCU->getCUTransquantBypass(uiPartOffset+ui);
    934       m_pbIPCMFlag[ui]=pcCU->m_pbIPCMFlag[uiPartOffset+ui];
    935       m_phQP[ui] = pcCU->m_phQP[uiPartOffset+ui];
    936       m_pbMergeFlag[ui]=pcCU->m_pbMergeFlag[uiPartOffset+ui];
    937       m_puhMergeIndex[ui]=pcCU->m_puhMergeIndex[uiPartOffset+ui];
    938 #if H_3D_VSP
    939       m_piVSPFlag[ui]=pcCU->m_piVSPFlag[uiPartOffset+ui];
    940       m_pDvInfo[ ui ] = pcCU->m_pDvInfo[uiPartOffset+ui];
    941 #endif
    942 #if H_3D_SPIVMP
    943       m_pbSPIVMPFlag[ui]=pcCU->m_pbSPIVMPFlag[uiPartOffset+ui];
    944 #endif
    945       m_puhLumaIntraDir[ui]=pcCU->m_puhLumaIntraDir[uiPartOffset+ui];
    946       m_puhChromaIntraDir[ui]=pcCU->m_puhChromaIntraDir[uiPartOffset+ui];
    947       m_puhInterDir[ui]=pcCU->m_puhInterDir[uiPartOffset+ui];
    948       m_puhCbf[0][ui]=pcCU->m_puhCbf[0][uiPartOffset+ui];
    949       m_puhCbf[1][ui]=pcCU->m_puhCbf[1][uiPartOffset+ui];
    950       m_puhCbf[2][ui]=pcCU->m_puhCbf[2][uiPartOffset+ui];
    951 
    952 #if H_3D_ARP
     922      m_ucDISType[ui]   = pcCU->getDISType(uiPartOffset+ui);
     923#endif
     924#if NH_3D_VSP
     925    m_piVSPFlag[ui] = pcCU->m_piVSPFlag[uiPartOffset+ui];
     926    m_pDvInfo[ ui ] = pcCU->m_pDvInfo[uiPartOffset+ui];
     927#endif
     928#if NH_3D_SPIVMP
     929    m_pbSPIVMPFlag[ui]=pcCU->m_pbSPIVMPFlag[uiPartOffset+ui];
     930#endif
     931#if NH_3D_ARP
    953932      m_puhARPW           [ui] = pcCU->getARPW( uiPartOffset+ui );
    954933#endif
    955 #if H_3D_IC
     934#if NH_3D_IC
    956935      m_pbICFlag          [ui] = pcCU->m_pbICFlag[uiPartOffset+ui];
    957936#endif
    958 #if H_3D_DIM
    959       for( Int i = 0; i < DIM_NUM_TYPE; i++ )
    960       {
    961         m_dimDeltaDC[i][0] [ui] = pcCU->m_dimDeltaDC[i][0] [uiPartOffset+ui];
    962         m_dimDeltaDC[i][1] [ui] = pcCU->m_dimDeltaDC[i][1] [uiPartOffset+ui];
    963       }
    964 #if H_3D_DIM_DMM
    965       for( Int i = 0; i < DMM_NUM_TYPE; i++ )
    966       {
    967         m_dmmWedgeTabIdx[i] [ui] = pcCU->m_dmmWedgeTabIdx[i] [uiPartOffset+ui];
    968       }
    969 #endif
    970 #if H_3D_DIM_SDC
    971       m_pbSDCFlag           [ui] = pcCU->m_pbSDCFlag            [ uiPartOffset + ui ];
    972       m_apSegmentDCOffset[0][ui] = pcCU->m_apSegmentDCOffset[0] [ uiPartOffset + ui ];
    973       m_apSegmentDCOffset[1][ui] = pcCU->m_apSegmentDCOffset[1] [ uiPartOffset + ui ];
    974 #endif
    975 #endif
    976 #if H_3D_DBBP
     937#if NH_3D_DMM
     938  for( Int i = 0; i < NUM_DMM; i++ )
     939  {
     940    m_dmmDeltaDC[i][0] [ui] = pcCU->m_dmmDeltaDC[i][0] [uiPartOffset+ui];
     941    m_dmmDeltaDC[i][1] [ui] = pcCU->m_dmmDeltaDC[i][1] [uiPartOffset+ui];
     942  }
     943  m_dmm1WedgeTabIdx    [ui] = pcCU->m_dmm1WedgeTabIdx  [uiPartOffset+ui];
     944#endif
     945#if NH_3D_SDC_INTRA
     946    m_pbSDCFlag           [ui] = pcCU->m_pbSDCFlag            [ uiPartOffset + ui ];
     947    m_apSegmentDCOffset[0][ui] = pcCU->m_apSegmentDCOffset[0] [ uiPartOffset + ui ];
     948    m_apSegmentDCOffset[1][ui] = pcCU->m_apSegmentDCOffset[1] [ uiPartOffset + ui ];
     949#endif
     950#if NH_3D_DBBP
    977951      m_pbDBBPFlag[ui]=pcCU->m_pbDBBPFlag[uiPartOffset+ui];
    978952#endif
    979     }
    980   }
    981   UInt uiTmp = uhWidth*uhHeight;
    982   memset( m_pcTrCoeffY , 0, sizeof(TCoeff)*uiTmp );
    983 #if ADAPTIVE_QP_SELECTION 
    984   memset( m_pcArlCoeffY , 0, sizeof(Int)*uiTmp );
    985 #endif
    986   memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
    987   uiTmp >>= 2;
    988   memset( m_pcTrCoeffCb, 0, sizeof(TCoeff)*uiTmp );
    989   memset( m_pcTrCoeffCr, 0, sizeof(TCoeff)*uiTmp );
     953  }
     954
     955  const UInt numCoeffY    = uhWidth*uhHeight;
     956  for (UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
     957  {
     958    const UInt componentShift = m_pcPic->getComponentScaleX(ComponentID(ch)) + m_pcPic->getComponentScaleY(ComponentID(ch));
     959    memset( m_pcTrCoeff[ch],  0, sizeof(TCoeff)*(numCoeffY>>componentShift) );
    990960#if ADAPTIVE_QP_SELECTION
    991   memset( m_pcArlCoeffCb, 0, sizeof(Int)*uiTmp );
    992   memset( m_pcArlCoeffCr, 0, sizeof(Int)*uiTmp );
    993 #endif
    994   memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
    995   memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
    996   m_acCUMvField[0].clearMvField();
    997   m_acCUMvField[1].clearMvField();
    998 
    999   if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU<getSlice()->getSliceSegmentCurStartCUAddr())
    1000   {
    1001     // Part of this CU contains data from an older slice. Now copy in that data.
    1002     UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
    1003     UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
    1004     TComDataCU * bigCU = getPic()->getCU(getAddr());
    1005     Int minui = uiPartOffset;
    1006     minui = -minui;
    1007     pcCU->m_acCUMvField[0].copyTo(&m_acCUMvField[0],minui,uiPartOffset,m_uiNumPartition);
    1008     pcCU->m_acCUMvField[1].copyTo(&m_acCUMvField[1],minui,uiPartOffset,m_uiNumPartition);
    1009     UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*m_uiAbsIdxInLCU/pcCU->getPic()->getNumPartInCU();
    1010     uiTmp = uhWidth*uhHeight;
    1011     for(Int i=0; i<uiTmp; i++)
    1012     {
    1013       m_pcTrCoeffY[i]=bigCU->m_pcTrCoeffY[uiCoffOffset+i];
    1014 #if ADAPTIVE_QP_SELECTION
    1015       m_pcArlCoeffY[i]=bigCU->m_pcArlCoeffY[uiCoffOffset+i];
    1016 #endif
    1017       m_pcIPCMSampleY[i]=bigCU->m_pcIPCMSampleY[uiCoffOffset+i];
    1018     }
    1019     uiTmp>>=2;
    1020     uiCoffOffset>>=2;
    1021     for(Int i=0; i<uiTmp; i++)
    1022     {
    1023       m_pcTrCoeffCr[i]=bigCU->m_pcTrCoeffCr[uiCoffOffset+i];
    1024       m_pcTrCoeffCb[i]=bigCU->m_pcTrCoeffCb[uiCoffOffset+i];
    1025 #if ADAPTIVE_QP_SELECTION
    1026       m_pcArlCoeffCr[i]=bigCU->m_pcArlCoeffCr[uiCoffOffset+i];
    1027       m_pcArlCoeffCb[i]=bigCU->m_pcArlCoeffCb[uiCoffOffset+i];
    1028 #endif
    1029       m_pcIPCMSampleCb[i]=bigCU->m_pcIPCMSampleCb[uiCoffOffset+i];
    1030       m_pcIPCMSampleCr[i]=bigCU->m_pcIPCMSampleCr[uiCoffOffset+i];
    1031     }
    1032   }
    1033 
    1034   m_pcCULeft        = pcCU->getCULeft();
    1035   m_pcCUAbove       = pcCU->getCUAbove();
    1036   m_pcCUAboveLeft   = pcCU->getCUAboveLeft();
    1037   m_pcCUAboveRight  = pcCU->getCUAboveRight();
    1038 
    1039   m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
    1040   m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
    1041   memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
    1042   memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
     961    memset( m_pcArlCoeff[ch], 0, sizeof(TCoeff)*(numCoeffY>>componentShift) );
     962#endif
     963    memset( m_pcIPCMSample[ch], 0, sizeof(Pel)* (numCoeffY>>componentShift) );
     964  }
     965
     966  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     967  {
     968    m_acCUMvField[i].clearMvField();
     969  }
     970
     971  m_pCtuLeft        = pcCU->getCtuLeft();
     972  m_pCtuAbove       = pcCU->getCtuAbove();
     973  m_pCtuAboveLeft   = pcCU->getCtuAboveLeft();
     974  m_pCtuAboveRight  = pcCU->getCtuAboveRight();
     975
     976  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     977  {
     978    m_apcCUColocated[i] = pcCU->getCUColocated(RefPicList(i));
     979  }
    1043980}
    1044981
    1045982Void TComDataCU::setOutsideCUPart( UInt uiAbsPartIdx, UInt uiDepth )
    1046983{
    1047   UInt uiNumPartition = m_uiNumPartition >> (uiDepth << 1);
    1048   UInt uiSizeInUchar = sizeof( UChar  ) * uiNumPartition;
    1049 
    1050   UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
    1051   UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
     984  const UInt    uiNumPartition = m_uiNumPartition >> (uiDepth << 1);
     985  const UInt     uiSizeInUchar = sizeof( UChar  ) * uiNumPartition;
     986  const TComSPS &sps            = *(getSlice()->getSPS());
     987  const UChar    uhWidth        = sps.getMaxCUWidth()  >> uiDepth;
     988  const UChar    uhHeight       = sps.getMaxCUHeight() >> uiDepth;
    1052989  memset( m_puhDepth    + uiAbsPartIdx,     uiDepth,  uiSizeInUchar );
    1053990  memset( m_puhWidth    + uiAbsPartIdx,     uhWidth,  uiSizeInUchar );
     
    1059996// --------------------------------------------------------------------------------------------------------------------
    1060997
    1061 Void TComDataCU::copySubCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     998Void TComDataCU::copySubCU( TComDataCU* pcCU, UInt uiAbsPartIdx )
    1062999{
    10631000  UInt uiPart = uiAbsPartIdx;
    1064  
     1001
    10651002  m_pcPic              = pcCU->getPic();
    10661003  m_pcSlice            = pcCU->getSlice();
    1067   m_uiCUAddr           = pcCU->getAddr();
    1068   m_uiAbsIdxInLCU      = uiAbsPartIdx;
    1069  
     1004  m_ctuRsAddr          = pcCU->getCtuRsAddr();
     1005  m_absZIdxInCtu       = uiAbsPartIdx;
     1006
    10701007  m_uiCUPelX           = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
    10711008  m_uiCUPelY           = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    1072  
     1009
    10731010  m_skipFlag=pcCU->getSkipFlag()          + uiPart;
    1074 #if H_3D
     1011#if NH_3D_DIS
    10751012  m_bDISFlag     = pcCU->getDISFlag()     + uiPart;
    1076   m_uiDISType    = pcCU->getDISType()     + uiPart;
    1077 #endif
     1013  m_ucDISType    = pcCU->getDISType()     + uiPart;
     1014#endif
     1015
    10781016  m_phQP=pcCU->getQP()                    + uiPart;
     1017  m_ChromaQpAdj = pcCU->getChromaQpAdj()  + uiPart;
    10791018  m_pePartSize = pcCU->getPartitionSize() + uiPart;
    10801019  m_pePredMode=pcCU->getPredictionMode()  + uiPart;
    10811020  m_CUTransquantBypass  = pcCU->getCUTransquantBypass()+uiPart;
    1082  
    1083 #if H_3D_NBDV
     1021#if NH_3D_NBDV
    10841022  m_pDvInfo             = pcCU->getDvInfo()           + uiPart;
    10851023#endif
     1024
    10861025  m_pbMergeFlag         = pcCU->getMergeFlag()        + uiPart;
    10871026  m_puhMergeIndex       = pcCU->getMergeIndex()       + uiPart;
    1088 #if H_3D_VSP
     1027#if NH_3D_VSP
    10891028  m_piVSPFlag           = pcCU->getVSPFlag()          + uiPart;
    10901029#endif
    1091 #if H_3D_SPIVMP
     1030#if NH_3D_SPIVMP
    10921031  m_pbSPIVMPFlag        = pcCU->getSPIVMPFlag()          + uiPart;
    10931032#endif
    1094 #if H_3D_ARP
     1033#if NH_3D_ARP
    10951034  m_puhARPW             = pcCU->getARPW()             + uiPart;
    10961035#endif
    1097 #if H_3D_IC
     1036#if NH_3D_IC
    10981037  m_pbICFlag            = pcCU->getICFlag()           + uiPart;
    10991038#endif
    1100   m_puhLumaIntraDir     = pcCU->getLumaIntraDir()     + uiPart;
    1101   m_puhChromaIntraDir   = pcCU->getChromaIntraDir()   + uiPart;
     1039
     1040  for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     1041  {
     1042    m_puhIntraDir[ch]   = pcCU->getIntraDir(ChannelType(ch)) + uiPart;
     1043  }
     1044
    11021045  m_puhInterDir         = pcCU->getInterDir()         + uiPart;
    11031046  m_puhTrIdx            = pcCU->getTransformIdx()     + uiPart;
    1104   m_puhTransformSkip[0] = pcCU->getTransformSkip(TEXT_LUMA)     + uiPart;
    1105   m_puhTransformSkip[1] = pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPart;
    1106   m_puhTransformSkip[2] = pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPart;
    1107 
    1108   m_puhCbf[0]= pcCU->getCbf(TEXT_LUMA)            + uiPart;
    1109   m_puhCbf[1]= pcCU->getCbf(TEXT_CHROMA_U)        + uiPart;
    1110   m_puhCbf[2]= pcCU->getCbf(TEXT_CHROMA_V)        + uiPart;
    1111 #if H_3D_DIM
    1112   for( Int i = 0; i < DIM_NUM_TYPE; i++ )
    1113   {
    1114     m_dimDeltaDC[i][0] = pcCU->getDimDeltaDC( i, 0 ) + uiPart;
    1115     m_dimDeltaDC[i][1] = pcCU->getDimDeltaDC( i, 1 ) + uiPart;
    1116   }
    1117 #if H_3D_DIM_DMM
    1118   for( Int i = 0; i < DMM_NUM_TYPE; i++ )
    1119   {
    1120     m_dmmWedgeTabIdx[i] = pcCU->getDmmWedgeTabIdx( i ) + uiPart;
    1121   }
    1122 #endif
    1123 #if H_3D_DIM_SDC
     1047
     1048  for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     1049  {
     1050    m_crossComponentPredictionAlpha[comp] = pcCU->getCrossComponentPredictionAlpha(ComponentID(comp)) + uiPart;
     1051    m_puhTransformSkip[comp]              = pcCU->getTransformSkip(ComponentID(comp))                 + uiPart;
     1052    m_puhCbf[comp]                        = pcCU->getCbf(ComponentID(comp))                           + uiPart;
     1053    m_explicitRdpcmMode[comp]             = pcCU->getExplicitRdpcmMode(ComponentID(comp))             + uiPart;
     1054  }
     1055#if NH_3D_DMM
     1056  for( Int i = 0; i < NUM_DMM; i++ )
     1057  {
     1058    m_dmmDeltaDC[i][0] = pcCU->getDmmDeltaDC( (DmmID)i, 0 ) + uiPart;
     1059    m_dmmDeltaDC[i][1] = pcCU->getDmmDeltaDC( (DmmID)i, 1 ) + uiPart;
     1060  }
     1061  m_dmm1WedgeTabIdx    = pcCU->getDmm1WedgeTabIdx()  + uiPart;
     1062#endif
     1063#if NH_3D_SDC_INTRA
    11241064  m_pbSDCFlag               = pcCU->getSDCFlag()              + uiPart;
    11251065  m_apSegmentDCOffset[0]    = pcCU->getSDCSegmentDCOffset(0)  + uiPart;
    11261066  m_apSegmentDCOffset[1]    = pcCU->getSDCSegmentDCOffset(1)  + uiPart;
    11271067#endif 
    1128 #endif 
    1129 #if H_3D_DBBP
     1068#if NH_3D_DBBP
    11301069  m_pbDBBPFlag              = pcCU->getDBBPFlag()         + uiPart;
    11311070#endif
     1071
    11321072  m_puhDepth=pcCU->getDepth()                     + uiPart;
    11331073  m_puhWidth=pcCU->getWidth()                     + uiPart;
    11341074  m_puhHeight=pcCU->getHeight()                   + uiPart;
    1135  
    1136   m_apiMVPIdx[0]=pcCU->getMVPIdx(REF_PIC_LIST_0)  + uiPart;
    1137   m_apiMVPIdx[1]=pcCU->getMVPIdx(REF_PIC_LIST_1)  + uiPart;
    1138   m_apiMVPNum[0]=pcCU->getMVPNum(REF_PIC_LIST_0)  + uiPart;
    1139   m_apiMVPNum[1]=pcCU->getMVPNum(REF_PIC_LIST_1)  + uiPart;
    1140  
     1075
    11411076  m_pbIPCMFlag         = pcCU->getIPCMFlag()        + uiPart;
    11421077
    1143   m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
    1144   m_pcCUAboveRight     = pcCU->getCUAboveRight();
    1145   m_pcCUAbove          = pcCU->getCUAbove();
    1146   m_pcCULeft           = pcCU->getCULeft();
    1147  
    1148   m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
    1149   m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
    1150  
     1078  m_pCtuAboveLeft      = pcCU->getCtuAboveLeft();
     1079  m_pCtuAboveRight     = pcCU->getCtuAboveRight();
     1080  m_pCtuAbove          = pcCU->getCtuAbove();
     1081  m_pCtuLeft           = pcCU->getCtuLeft();
     1082
     1083  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     1084  {
     1085    const RefPicList rpl=RefPicList(i);
     1086    m_apcCUColocated[rpl] = pcCU->getCUColocated(rpl);
     1087    m_apiMVPIdx[rpl]=pcCU->getMVPIdx(rpl)  + uiPart;
     1088    m_apiMVPNum[rpl]=pcCU->getMVPNum(rpl)  + uiPart;
     1089  }
     1090
     1091  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     1092  {
     1093    const RefPicList rpl=RefPicList(i);
     1094    m_acCUMvField[rpl].linkToWithOffset( pcCU->getCUMvField(rpl), uiPart );
     1095  }
     1096
    11511097  UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
    11521098  UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
    1153  
    1154   UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*uiAbsPartIdx/pcCU->getPic()->getNumPartInCU();
    1155  
    1156   m_pcTrCoeffY = pcCU->getCoeffY() + uiCoffOffset;
     1099
     1100  UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*uiAbsPartIdx/pcCU->getPic()->getNumPartitionsInCtu();
     1101
     1102  for (UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
     1103  {
     1104    const ComponentID component = ComponentID(ch);
     1105    const UInt componentShift   = m_pcPic->getComponentScaleX(component) + m_pcPic->getComponentScaleY(component);
     1106    const UInt offset           = uiCoffOffset >> componentShift;
     1107    m_pcTrCoeff[ch] = pcCU->getCoeff(component) + offset;
    11571108#if ADAPTIVE_QP_SELECTION
    1158   m_pcArlCoeffY= pcCU->getArlCoeffY() + uiCoffOffset; 
    1159 #endif
    1160   m_pcIPCMSampleY = pcCU->getPCMSampleY() + uiCoffOffset;
    1161 
    1162   uiCoffOffset >>=2;
    1163   m_pcTrCoeffCb=pcCU->getCoeffCb() + uiCoffOffset;
    1164   m_pcTrCoeffCr=pcCU->getCoeffCr() + uiCoffOffset;
    1165 #if ADAPTIVE_QP_SELECTION 
    1166   m_pcArlCoeffCb=pcCU->getArlCoeffCb() + uiCoffOffset;
    1167   m_pcArlCoeffCr=pcCU->getArlCoeffCr() + uiCoffOffset;
    1168 #endif
    1169   m_pcIPCMSampleCb = pcCU->getPCMSampleCb() + uiCoffOffset;
    1170   m_pcIPCMSampleCr = pcCU->getPCMSampleCr() + uiCoffOffset;
    1171 
    1172   m_acCUMvField[0].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_0), uiPart );
    1173   m_acCUMvField[1].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_1), uiPart );
    1174   memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
    1175   memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
    1176 }
    1177 #if H_3D_NBDV
     1109    m_pcArlCoeff[ch] = pcCU->getArlCoeff(component) + offset;
     1110#endif
     1111    m_pcIPCMSample[ch] = pcCU->getPCMSample(component) + offset;
     1112  }
     1113}
     1114
     1115#if NH_3D_NBDV
    11781116Void TComDataCU::copyDVInfoFrom (TComDataCU* pcCU, UInt uiAbsPartIdx)
    11791117{
     
    11811119}
    11821120#endif
     1121
    11831122// Copy inter prediction info from the biggest CU
    11841123Void TComDataCU::copyInterPredInfoFrom    ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList
    1185 #if H_3D_NBDV
     1124#if NH_3D_NBDV
    11861125  , Bool bNBDV
    11871126#endif
    1188   )
     1127)
    11891128{
    11901129  m_pcPic              = pcCU->getPic();
    11911130  m_pcSlice            = pcCU->getSlice();
    1192   m_uiCUAddr           = pcCU->getAddr();
    1193   m_uiAbsIdxInLCU      = uiAbsPartIdx;
    1194  
     1131  m_ctuRsAddr          = pcCU->getCtuRsAddr();
     1132  m_absZIdxInCtu       = uiAbsPartIdx;
     1133
    11951134  Int iRastPartIdx     = g_auiZscanToRaster[uiAbsPartIdx];
    1196   m_uiCUPelX           = pcCU->getCUPelX() + m_pcPic->getMinCUWidth ()*( iRastPartIdx % m_pcPic->getNumPartInWidth() );
    1197   m_uiCUPelY           = pcCU->getCUPelY() + m_pcPic->getMinCUHeight()*( iRastPartIdx / m_pcPic->getNumPartInWidth() );
    1198  
    1199   m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
    1200   m_pcCUAboveRight     = pcCU->getCUAboveRight();
    1201   m_pcCUAbove          = pcCU->getCUAbove();
    1202   m_pcCULeft           = pcCU->getCULeft();
    1203  
    1204   m_apcCUColocated[0]  = pcCU->getCUColocated(REF_PIC_LIST_0);
    1205   m_apcCUColocated[1]  = pcCU->getCUColocated(REF_PIC_LIST_1);
    1206  
     1135  m_uiCUPelX           = pcCU->getCUPelX() + m_pcPic->getMinCUWidth ()*( iRastPartIdx % m_pcPic->getNumPartInCtuWidth() );
     1136  m_uiCUPelY           = pcCU->getCUPelY() + m_pcPic->getMinCUHeight()*( iRastPartIdx / m_pcPic->getNumPartInCtuWidth() );
     1137
     1138  m_pCtuAboveLeft      = pcCU->getCtuAboveLeft();
     1139  m_pCtuAboveRight     = pcCU->getCtuAboveRight();
     1140  m_pCtuAbove          = pcCU->getCtuAbove();
     1141  m_pCtuLeft           = pcCU->getCtuLeft();
     1142
     1143  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     1144  {
     1145    m_apcCUColocated[i]  = pcCU->getCUColocated(RefPicList(i));
     1146  }
     1147
    12071148  m_skipFlag           = pcCU->getSkipFlag ()             + uiAbsPartIdx;
    1208 #if H_3D
     1149#if NH_3D_DIS
    12091150  m_bDISFlag           = pcCU->getDISFlag ()              + uiAbsPartIdx;
    1210   m_uiDISType          = pcCU->getDISType()               + uiAbsPartIdx;
    1211 #endif
     1151  m_ucDISType          = pcCU->getDISType()               + uiAbsPartIdx;
     1152#endif
     1153
    12121154  m_pePartSize         = pcCU->getPartitionSize ()        + uiAbsPartIdx;
    1213 #if H_3D_NBDV
     1155#if NH_3D_NBDV
    12141156  if(bNBDV == true)
    12151157  {
     
    12221164#endif
    12231165  m_pePredMode         = pcCU->getPredictionMode()        + uiAbsPartIdx;
     1166  m_ChromaQpAdj        = pcCU->getChromaQpAdj()           + uiAbsPartIdx;
    12241167  m_CUTransquantBypass = pcCU->getCUTransquantBypass()    + uiAbsPartIdx;
    12251168  m_puhInterDir        = pcCU->getInterDir      ()        + uiAbsPartIdx;
    1226  
     1169
    12271170  m_puhDepth           = pcCU->getDepth ()                + uiAbsPartIdx;
    12281171  m_puhWidth           = pcCU->getWidth ()                + uiAbsPartIdx;
    12291172  m_puhHeight          = pcCU->getHeight()                + uiAbsPartIdx;
    1230  
     1173
    12311174  m_pbMergeFlag        = pcCU->getMergeFlag()             + uiAbsPartIdx;
    12321175  m_puhMergeIndex      = pcCU->getMergeIndex()            + uiAbsPartIdx;
    1233 #if H_3D_VSP
     1176#if NH_3D_VSP
    12341177  m_piVSPFlag          = pcCU->getVSPFlag()               + uiAbsPartIdx;
    12351178  m_pDvInfo            = pcCU->getDvInfo()                + uiAbsPartIdx;
    12361179#endif
    1237 #if H_3D_SPIVMP
     1180#if NH_3D_SPIVMP
    12381181  m_pbSPIVMPFlag       = pcCU->getSPIVMPFlag()            + uiAbsPartIdx;
    12391182#endif
     1183
    12401184  m_apiMVPIdx[eRefPicList] = pcCU->getMVPIdx(eRefPicList) + uiAbsPartIdx;
    1241   m_apiMVPNum[eRefPicList] = pcCU->getMVPNum(eRefPicList) + uiAbsPartIdx; 
    1242 #if H_3D_ARP
     1185  m_apiMVPNum[eRefPicList] = pcCU->getMVPNum(eRefPicList) + uiAbsPartIdx;
     1186#if NH_3D_ARP
    12431187  m_puhARPW            = pcCU->getARPW()                  + uiAbsPartIdx;
    12441188#endif   
    1245 #if H_3D_DBBP
     1189#if NH_3D_DBBP
    12461190  m_pbDBBPFlag       = pcCU->getDBBPFlag()              + uiAbsPartIdx;
    12471191#endif
    12481192
    12491193  m_acCUMvField[ eRefPicList ].linkToWithOffset( pcCU->getCUMvField(eRefPicList), uiAbsPartIdx );
    1250 
    1251   memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
    1252   memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
    1253 #if H_3D_NBDV
    1254   }
    1255 #endif
    1256 #if H_3D_IC
     1194#if NH_3D_NBDV
     1195  }
     1196#endif
     1197#if NH_3D_IC
    12571198  m_pbICFlag           = pcCU->getICFlag()                + uiAbsPartIdx;
    12581199#endif
     1200
    12591201}
    12601202
     
    12641206{
    12651207  assert( uiPartUnitIdx<4 );
    1266  
     1208
    12671209  m_dTotalCost         += pcCU->getTotalCost();
    12681210  m_uiTotalDistortion  += pcCU->getTotalDistortion();
    12691211  m_uiTotalBits        += pcCU->getTotalBits();
    1270  
     1212
    12711213  UInt uiOffset         = pcCU->getTotalNumPart()*uiPartUnitIdx;
    1272  
     1214  const UInt numValidComp=pcCU->getPic()->getNumberValidComponents();
     1215  const UInt numValidChan=pcCU->getPic()->getChromaFormat()==CHROMA_400 ? 1:2;
     1216
    12731217  UInt uiNumPartition = pcCU->getTotalNumPart();
    12741218  Int iSizeInUchar  = sizeof( UChar ) * uiNumPartition;
    12751219  Int iSizeInBool   = sizeof( Bool  ) * uiNumPartition;
    1276  
     1220
    12771221  Int sizeInChar  = sizeof( Char ) * uiNumPartition;
    12781222  memcpy( m_skipFlag   + uiOffset, pcCU->getSkipFlag(),       sizeof( *m_skipFlag )   * uiNumPartition );
    1279 #if H_3D
    1280   memcpy( m_bDISFlag   + uiOffset, pcCU->getDISFlag(),       sizeof( *m_bDISFlag )   * uiNumPartition );
    1281   memcpy( m_uiDISType  + uiOffset, pcCU->getDISType(),       sizeof( *m_uiDISType )  * uiNumPartition);
     1223#if NH_3D_DIS
     1224  memcpy( m_bDISFlag   + uiOffset, pcCU->getDISFlag(),        sizeof( *m_bDISFlag )   * uiNumPartition );
     1225  memcpy( m_ucDISType  + uiOffset, pcCU->getDISType(),        sizeof( *m_ucDISType )  * uiNumPartition);
    12821226#endif
    12831227  memcpy( m_phQP       + uiOffset, pcCU->getQP(),             sizeInChar                        );
    12841228  memcpy( m_pePartSize + uiOffset, pcCU->getPartitionSize(),  sizeof( *m_pePartSize ) * uiNumPartition );
    12851229  memcpy( m_pePredMode + uiOffset, pcCU->getPredictionMode(), sizeof( *m_pePredMode ) * uiNumPartition );
     1230  memcpy( m_ChromaQpAdj + uiOffset, pcCU->getChromaQpAdj(),   sizeof( *m_ChromaQpAdj ) * uiNumPartition );
    12861231  memcpy( m_CUTransquantBypass + uiOffset, pcCU->getCUTransquantBypass(), sizeof( *m_CUTransquantBypass ) * uiNumPartition );
    12871232  memcpy( m_pbMergeFlag         + uiOffset, pcCU->getMergeFlag(),         iSizeInBool  );
    12881233  memcpy( m_puhMergeIndex       + uiOffset, pcCU->getMergeIndex(),        iSizeInUchar );
    1289 #if H_3D_VSP
     1234#if NH_3D_VSP
    12901235  memcpy( m_piVSPFlag           + uiOffset, pcCU->getVSPFlag(),           sizeof( Char ) * uiNumPartition );
    12911236  memcpy( m_pDvInfo             + uiOffset, pcCU->getDvInfo(),            sizeof( *m_pDvInfo ) * uiNumPartition );
    12921237#endif
    1293 #if H_3D_SPIVMP
     1238#if NH_3D_SPIVMP  || NH_3D_DBBP
    12941239  memcpy( m_pbSPIVMPFlag        + uiOffset, pcCU->getSPIVMPFlag(),        sizeof( Bool ) * uiNumPartition );
    12951240#endif
    1296   memcpy( m_puhLumaIntraDir     + uiOffset, pcCU->getLumaIntraDir(),      iSizeInUchar );
    1297   memcpy( m_puhChromaIntraDir   + uiOffset, pcCU->getChromaIntraDir(),    iSizeInUchar );
     1241
     1242  for (UInt ch=0; ch<numValidChan; ch++)
     1243  {
     1244    memcpy( m_puhIntraDir[ch]   + uiOffset, pcCU->getIntraDir(ChannelType(ch)), iSizeInUchar );
     1245  }
     1246
    12981247  memcpy( m_puhInterDir         + uiOffset, pcCU->getInterDir(),          iSizeInUchar );
    12991248  memcpy( m_puhTrIdx            + uiOffset, pcCU->getTransformIdx(),      iSizeInUchar );
    1300   memcpy( m_puhTransformSkip[0] + uiOffset, pcCU->getTransformSkip(TEXT_LUMA),     iSizeInUchar );
    1301   memcpy( m_puhTransformSkip[1] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_U), iSizeInUchar );
    1302   memcpy( m_puhTransformSkip[2] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_V), iSizeInUchar );
    1303 
    1304   memcpy( m_puhCbf[0] + uiOffset, pcCU->getCbf(TEXT_LUMA)    , iSizeInUchar );
    1305   memcpy( m_puhCbf[1] + uiOffset, pcCU->getCbf(TEXT_CHROMA_U), iSizeInUchar );
    1306   memcpy( m_puhCbf[2] + uiOffset, pcCU->getCbf(TEXT_CHROMA_V), iSizeInUchar );
    1307 #if H_3D_DIM
    1308   for( Int i = 0; i < DIM_NUM_TYPE; i++ )
    1309   {
    1310     memcpy( m_dimDeltaDC[i][0] + uiOffset, pcCU->getDimDeltaDC( i, 0 ), sizeof(Pel ) * uiNumPartition );
    1311     memcpy( m_dimDeltaDC[i][1] + uiOffset, pcCU->getDimDeltaDC( i, 1 ), sizeof(Pel ) * uiNumPartition );
    1312   }
    1313 #if H_3D_DIM_DMM
    1314   for( Int i = 0; i < DMM_NUM_TYPE; i++ )
    1315   {
    1316     memcpy( m_dmmWedgeTabIdx[i] + uiOffset, pcCU->getDmmWedgeTabIdx( i ), sizeof(UInt) * uiNumPartition );
    1317   }
    1318 #endif
    1319 #if H_3D_DIM_SDC
    1320   memcpy( m_pbSDCFlag             + uiOffset, pcCU->getSDCFlag(),             iSizeInBool  );
     1249
     1250  for(UInt comp=0; comp<numValidComp; comp++)
     1251  {
     1252    memcpy( m_crossComponentPredictionAlpha[comp] + uiOffset, pcCU->getCrossComponentPredictionAlpha(ComponentID(comp)), iSizeInUchar );
     1253    memcpy( m_puhTransformSkip[comp]              + uiOffset, pcCU->getTransformSkip(ComponentID(comp))                , iSizeInUchar );
     1254    memcpy( m_puhCbf[comp]                        + uiOffset, pcCU->getCbf(ComponentID(comp))                          , iSizeInUchar );
     1255    memcpy( m_explicitRdpcmMode[comp]             + uiOffset, pcCU->getExplicitRdpcmMode(ComponentID(comp))            , iSizeInUchar );
     1256  }
     1257#if NH_3D_DMM
     1258  for( Int i = 0; i < NUM_DMM; i++ )
     1259  {
     1260    memcpy( m_dmmDeltaDC[i][0] + uiOffset, pcCU->getDmmDeltaDC( (DmmID)i, 0 ), sizeof(Pel ) * uiNumPartition );
     1261    memcpy( m_dmmDeltaDC[i][1] + uiOffset, pcCU->getDmmDeltaDC( (DmmID)i, 1 ), sizeof(Pel ) * uiNumPartition );
     1262  }
     1263  memcpy( m_dmm1WedgeTabIdx    + uiOffset, pcCU->getDmm1WedgeTabIdx(),         sizeof(UInt) * uiNumPartition );
     1264#endif
     1265#if NH_3D_SDC_INTRA
     1266  memcpy( m_pbSDCFlag             + uiOffset, pcCU->getSDCFlag(), sizeof( *m_pbSDCFlag ) * uiNumPartition  );
    13211267  memcpy( m_apSegmentDCOffset[0]  + uiOffset, pcCU->getSDCSegmentDCOffset(0), sizeof( Pel ) * uiNumPartition);
    13221268  memcpy( m_apSegmentDCOffset[1]  + uiOffset, pcCU->getSDCSegmentDCOffset(1), sizeof( Pel ) * uiNumPartition);
    13231269#endif
    1324 #endif
    1325 #if H_3D_DBBP
     1270#if NH_3D_DBBP
    13261271  memcpy( m_pbDBBPFlag          + uiOffset, pcCU->getDBBPFlag(),          iSizeInBool  );
     1272#endif
     1273#if NH_3D_ARP
     1274  memcpy( m_puhARPW             + uiOffset, pcCU->getARPW(),              iSizeInUchar );
    13271275#endif
    13281276
     
    13301278  memcpy( m_puhWidth  + uiOffset, pcCU->getWidth(),  iSizeInUchar );
    13311279  memcpy( m_puhHeight + uiOffset, pcCU->getHeight(), iSizeInUchar );
    1332  
    1333   memcpy( m_apiMVPIdx[0] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_0), iSizeInUchar );
    1334   memcpy( m_apiMVPIdx[1] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_1), iSizeInUchar );
    1335   memcpy( m_apiMVPNum[0] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_0), iSizeInUchar );
    1336   memcpy( m_apiMVPNum[1] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_1), iSizeInUchar );
    1337  
     1280
    13381281  memcpy( m_pbIPCMFlag + uiOffset, pcCU->getIPCMFlag(), iSizeInBool );
    13391282
    1340   m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
    1341   m_pcCUAboveRight     = pcCU->getCUAboveRight();
    1342   m_pcCUAbove          = pcCU->getCUAbove();
    1343   m_pcCULeft           = pcCU->getCULeft();
    1344  
    1345   m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
    1346   m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
    1347  
    1348   m_acCUMvField[0].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_0 ), pcCU->getTotalNumPart(), uiOffset );
    1349   m_acCUMvField[1].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_1 ), pcCU->getTotalNumPart(), uiOffset );
    1350  
    1351   UInt uiTmp  = g_uiMaxCUWidth*g_uiMaxCUHeight >> (uiDepth<<1);
    1352   UInt uiTmp2 = uiPartUnitIdx*uiTmp;
    1353   memcpy( m_pcTrCoeffY  + uiTmp2, pcCU->getCoeffY(),  sizeof(TCoeff)*uiTmp );
     1283  m_pCtuAboveLeft      = pcCU->getCtuAboveLeft();
     1284  m_pCtuAboveRight     = pcCU->getCtuAboveRight();
     1285  m_pCtuAbove          = pcCU->getCtuAbove();
     1286  m_pCtuLeft           = pcCU->getCtuLeft();
     1287
     1288  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     1289  {
     1290    const RefPicList rpl=RefPicList(i);
     1291    memcpy( m_apiMVPIdx[rpl] + uiOffset, pcCU->getMVPIdx(rpl), iSizeInUchar );
     1292    memcpy( m_apiMVPNum[rpl] + uiOffset, pcCU->getMVPNum(rpl), iSizeInUchar );
     1293    m_apcCUColocated[rpl] = pcCU->getCUColocated(rpl);
     1294  }
     1295
     1296  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     1297  {
     1298    const RefPicList rpl=RefPicList(i);
     1299    m_acCUMvField[rpl].copyFrom( pcCU->getCUMvField( rpl ), pcCU->getTotalNumPart(), uiOffset );
     1300  }
     1301
     1302  const UInt numCoeffY = (pcCU->getSlice()->getSPS()->getMaxCUWidth()*pcCU->getSlice()->getSPS()->getMaxCUHeight()) >> (uiDepth<<1);
     1303  const UInt offsetY   = uiPartUnitIdx*numCoeffY;
     1304  for (UInt ch=0; ch<numValidComp; ch++)
     1305  {
     1306    const ComponentID component = ComponentID(ch);
     1307    const UInt componentShift   = m_pcPic->getComponentScaleX(component) + m_pcPic->getComponentScaleY(component);
     1308    const UInt offset           = offsetY>>componentShift;
     1309    memcpy( m_pcTrCoeff [ch] + offset, pcCU->getCoeff(component),    sizeof(TCoeff)*(numCoeffY>>componentShift) );
    13541310#if ADAPTIVE_QP_SELECTION
    1355   memcpy( m_pcArlCoeffY  + uiTmp2, pcCU->getArlCoeffY(),  sizeof(Int)*uiTmp );
    1356 #endif
    1357   memcpy( m_pcIPCMSampleY + uiTmp2 , pcCU->getPCMSampleY(), sizeof(Pel) * uiTmp );
    1358 
    1359   uiTmp >>= 2; uiTmp2>>= 2;
    1360   memcpy( m_pcTrCoeffCb + uiTmp2, pcCU->getCoeffCb(), sizeof(TCoeff)*uiTmp );
    1361   memcpy( m_pcTrCoeffCr + uiTmp2, pcCU->getCoeffCr(), sizeof(TCoeff)*uiTmp );
    1362 #if ADAPTIVE_QP_SELECTION
    1363   memcpy( m_pcArlCoeffCb + uiTmp2, pcCU->getArlCoeffCb(), sizeof(Int)*uiTmp );
    1364   memcpy( m_pcArlCoeffCr + uiTmp2, pcCU->getArlCoeffCr(), sizeof(Int)*uiTmp );
    1365 #endif
    1366   memcpy( m_pcIPCMSampleCb + uiTmp2 , pcCU->getPCMSampleCb(), sizeof(Pel) * uiTmp );
    1367   memcpy( m_pcIPCMSampleCr + uiTmp2 , pcCU->getPCMSampleCr(), sizeof(Pel) * uiTmp );
     1311    memcpy( m_pcArlCoeff[ch] + offset, pcCU->getArlCoeff(component), sizeof(TCoeff)*(numCoeffY>>componentShift) );
     1312#endif
     1313    memcpy( m_pcIPCMSample[ch] + offset, pcCU->getPCMSample(component), sizeof(Pel)*(numCoeffY>>componentShift) );
     1314  }
     1315
     1316#if NH_3D_IC
     1317  memcpy( m_pbICFlag            + uiOffset, pcCU->getICFlag(),            iSizeInBool );
     1318#endif
     1319
    13681320  m_uiTotalBins += pcCU->getTotalBins();
    1369   memcpy( m_sliceStartCU        + uiOffset, pcCU->m_sliceStartCU,        sizeof( UInt ) * uiNumPartition  );
    1370   memcpy( m_sliceSegmentStartCU + uiOffset, pcCU->m_sliceSegmentStartCU, sizeof( UInt ) * uiNumPartition  );
    1371 #if H_3D_ARP
    1372   memcpy( m_puhARPW             + uiOffset, pcCU->getARPW(),              iSizeInUchar );
    1373 #endif
    1374 #if H_3D_IC
    1375   memcpy( m_pbICFlag            + uiOffset, pcCU->getICFlag(),            iSizeInBool );
    1376 #endif
    13771321}
    13781322
     
    13811325Void TComDataCU::copyToPic( UChar uhDepth )
    13821326{
    1383   TComDataCU*& rpcCU = m_pcPic->getCU( m_uiCUAddr );
    1384  
    1385   rpcCU->getTotalCost()       = m_dTotalCost;
    1386   rpcCU->getTotalDistortion() = m_uiTotalDistortion;
    1387   rpcCU->getTotalBits()       = m_uiTotalBits;
    1388  
     1327  TComDataCU* pCtu = m_pcPic->getCtu( m_ctuRsAddr );
     1328  const UInt numValidComp=pCtu->getPic()->getNumberValidComponents();
     1329  const UInt numValidChan=pCtu->getPic()->getChromaFormat()==CHROMA_400 ? 1:2;
     1330
     1331  pCtu->getTotalCost()       = m_dTotalCost;
     1332  pCtu->getTotalDistortion() = m_uiTotalDistortion;
     1333  pCtu->getTotalBits()       = m_uiTotalBits;
     1334
    13891335  Int iSizeInUchar  = sizeof( UChar ) * m_uiNumPartition;
    13901336  Int iSizeInBool   = sizeof( Bool  ) * m_uiNumPartition;
    1391  
    13921337  Int sizeInChar  = sizeof( Char ) * m_uiNumPartition;
    13931338
    1394   memcpy( rpcCU->getSkipFlag() + m_uiAbsIdxInLCU, m_skipFlag, sizeof( *m_skipFlag ) * m_uiNumPartition );
    1395 #if H_3D
    1396   memcpy( rpcCU->getDISFlag()  + m_uiAbsIdxInLCU, m_bDISFlag,    sizeof( *m_bDISFlag )  * m_uiNumPartition );
    1397   memcpy( rpcCU->getDISType()  + m_uiAbsIdxInLCU, m_uiDISType,   sizeof( *m_uiDISType ) * m_uiNumPartition );
    1398 #endif
    1399   memcpy( rpcCU->getQP() + m_uiAbsIdxInLCU, m_phQP, sizeInChar  );
    1400 #if H_3D_NBDV
    1401   memcpy( rpcCU->getDvInfo()         + m_uiAbsIdxInLCU, m_pDvInfo,    sizeof(* m_pDvInfo)     * m_uiNumPartition );
    1402 #endif
    1403   memcpy( rpcCU->getPartitionSize()  + m_uiAbsIdxInLCU, m_pePartSize, sizeof( *m_pePartSize ) * m_uiNumPartition );
    1404   memcpy( rpcCU->getPredictionMode() + m_uiAbsIdxInLCU, m_pePredMode, sizeof( *m_pePredMode ) * m_uiNumPartition );
    1405   memcpy( rpcCU->getCUTransquantBypass()+ m_uiAbsIdxInLCU, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * m_uiNumPartition );
    1406   memcpy( rpcCU->getMergeFlag()         + m_uiAbsIdxInLCU, m_pbMergeFlag,         iSizeInBool  );
    1407   memcpy( rpcCU->getMergeIndex()        + m_uiAbsIdxInLCU, m_puhMergeIndex,       iSizeInUchar );
    1408 #if H_3D_VSP
    1409   memcpy( rpcCU->getVSPFlag()           + m_uiAbsIdxInLCU, m_piVSPFlag,           sizeof( Char ) * m_uiNumPartition );
    1410   memcpy( rpcCU->getDvInfo()            + m_uiAbsIdxInLCU, m_pDvInfo,             sizeof( *m_pDvInfo ) * m_uiNumPartition );
    1411 #endif
    1412 #if H_3D_SPIVMP
    1413   memcpy( rpcCU->getSPIVMPFlag()        + m_uiAbsIdxInLCU, m_pbSPIVMPFlag,        sizeof( Bool ) * m_uiNumPartition );
    1414 #endif
    1415   memcpy( rpcCU->getLumaIntraDir()      + m_uiAbsIdxInLCU, m_puhLumaIntraDir,     iSizeInUchar );
    1416   memcpy( rpcCU->getChromaIntraDir()    + m_uiAbsIdxInLCU, m_puhChromaIntraDir,   iSizeInUchar );
    1417   memcpy( rpcCU->getInterDir()          + m_uiAbsIdxInLCU, m_puhInterDir,         iSizeInUchar );
    1418   memcpy( rpcCU->getTransformIdx()      + m_uiAbsIdxInLCU, m_puhTrIdx,            iSizeInUchar );
    1419   memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhTransformSkip[0], iSizeInUchar );
    1420   memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhTransformSkip[1], iSizeInUchar );
    1421   memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhTransformSkip[2], iSizeInUchar );
    1422 
    1423   memcpy( rpcCU->getCbf(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhCbf[0], iSizeInUchar );
    1424   memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhCbf[1], iSizeInUchar );
    1425   memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhCbf[2], iSizeInUchar );
    1426  
    1427 #if H_3D_DIM
    1428   for( Int i = 0; i < DIM_NUM_TYPE; i++ )
    1429   {
    1430     memcpy( rpcCU->getDimDeltaDC( i, 0 ) + m_uiAbsIdxInLCU, m_dimDeltaDC[i][0], sizeof(Pel ) * m_uiNumPartition );
    1431     memcpy( rpcCU->getDimDeltaDC( i, 1 ) + m_uiAbsIdxInLCU, m_dimDeltaDC[i][1], sizeof(Pel ) * m_uiNumPartition );
    1432   }
    1433 #if H_3D_DIM_DMM
    1434   for( Int i = 0; i < DMM_NUM_TYPE; i++ )
    1435   {
    1436     memcpy( rpcCU->getDmmWedgeTabIdx( i ) + m_uiAbsIdxInLCU, m_dmmWedgeTabIdx[i], sizeof(UInt) * m_uiNumPartition );
    1437   }
    1438 #endif
    1439 #if H_3D_DIM_SDC
    1440   memcpy( rpcCU->getSDCFlag()             + m_uiAbsIdxInLCU, m_pbSDCFlag,      iSizeInBool  );
    1441   memcpy( rpcCU->getSDCSegmentDCOffset(0) + m_uiAbsIdxInLCU, m_apSegmentDCOffset[0], sizeof( Pel ) * m_uiNumPartition);
    1442   memcpy( rpcCU->getSDCSegmentDCOffset(1) + m_uiAbsIdxInLCU, m_apSegmentDCOffset[1], sizeof( Pel ) * m_uiNumPartition);
    1443 #endif
    1444 #endif
    1445 #if H_3D_DBBP
    1446   memcpy( rpcCU->getDBBPFlag()          + m_uiAbsIdxInLCU, m_pbDBBPFlag,          iSizeInBool  );
    1447 #endif
    1448  
    1449   memcpy( rpcCU->getDepth()  + m_uiAbsIdxInLCU, m_puhDepth,  iSizeInUchar );
    1450   memcpy( rpcCU->getWidth()  + m_uiAbsIdxInLCU, m_puhWidth,  iSizeInUchar );
    1451   memcpy( rpcCU->getHeight() + m_uiAbsIdxInLCU, m_puhHeight, iSizeInUchar );
    1452  
    1453   memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPIdx[0], iSizeInUchar );
    1454   memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPIdx[1], iSizeInUchar );
    1455   memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPNum[0], iSizeInUchar );
    1456   memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPNum[1], iSizeInUchar );
    1457  
    1458   m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU );
    1459   m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU );
    1460  
    1461   memcpy( rpcCU->getIPCMFlag() + m_uiAbsIdxInLCU, m_pbIPCMFlag,         iSizeInBool  );
    1462 
    1463   UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>(uhDepth<<1);
    1464   UInt uiTmp2 = m_uiAbsIdxInLCU*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
    1465   memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
    1466 #if ADAPTIVE_QP_SELECTION 
    1467   memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
    1468 #endif
    1469   memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof(Pel)*uiTmp );
    1470 
    1471   uiTmp >>= 2; uiTmp2 >>= 2;
    1472   memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
    1473   memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
     1339  memcpy( pCtu->getSkipFlag() + m_absZIdxInCtu, m_skipFlag, sizeof( *m_skipFlag ) * m_uiNumPartition );
     1340#if NH_3D_DIS
     1341  memcpy( pCtu->getDISFlag()  + m_absZIdxInCtu, m_bDISFlag, sizeof( *m_bDISFlag )  * m_uiNumPartition );
     1342  memcpy( pCtu->getDISType()  + m_absZIdxInCtu, m_ucDISType, sizeof( *m_ucDISType ) * m_uiNumPartition );
     1343#endif
     1344
     1345  memcpy( pCtu->getQP() + m_absZIdxInCtu, m_phQP, sizeInChar  );
     1346#if NH_3D_NBDV
     1347  memcpy( pCtu->getDvInfo() + m_absZIdxInCtu, m_pDvInfo, sizeof(* m_pDvInfo) * m_uiNumPartition );
     1348#endif
     1349
     1350  memcpy( pCtu->getPartitionSize()  + m_absZIdxInCtu, m_pePartSize, sizeof( *m_pePartSize ) * m_uiNumPartition );
     1351  memcpy( pCtu->getPredictionMode() + m_absZIdxInCtu, m_pePredMode, sizeof( *m_pePredMode ) * m_uiNumPartition );
     1352  memcpy( pCtu->getChromaQpAdj() + m_absZIdxInCtu, m_ChromaQpAdj, sizeof( *m_ChromaQpAdj ) * m_uiNumPartition );
     1353  memcpy( pCtu->getCUTransquantBypass()+ m_absZIdxInCtu, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * m_uiNumPartition );
     1354  memcpy( pCtu->getMergeFlag()         + m_absZIdxInCtu, m_pbMergeFlag,         iSizeInBool  );
     1355  memcpy( pCtu->getMergeIndex()        + m_absZIdxInCtu, m_puhMergeIndex,       iSizeInUchar );
     1356#if NH_3D_VSP
     1357  memcpy( pCtu->getVSPFlag()           + m_absZIdxInCtu, m_piVSPFlag,           sizeof( Char ) * m_uiNumPartition );
     1358#endif
     1359#if NH_3D_DBBP
     1360  memcpy( pCtu->getDvInfo()            + m_absZIdxInCtu, m_pDvInfo,             sizeof( *m_pDvInfo ) * m_uiNumPartition );
     1361#endif
     1362#if NH_3D_SPIVMP
     1363  memcpy( pCtu->getSPIVMPFlag()        + m_absZIdxInCtu, m_pbSPIVMPFlag,        sizeof( Bool ) * m_uiNumPartition );
     1364#endif
     1365
     1366for (UInt ch=0; ch<numValidChan; ch++)
     1367  {
     1368    memcpy( pCtu->getIntraDir(ChannelType(ch)) + m_absZIdxInCtu, m_puhIntraDir[ch], iSizeInUchar);
     1369  }
     1370
     1371  memcpy( pCtu->getInterDir()          + m_absZIdxInCtu, m_puhInterDir,         iSizeInUchar );
     1372  memcpy( pCtu->getTransformIdx()      + m_absZIdxInCtu, m_puhTrIdx,            iSizeInUchar );
     1373
     1374  for(UInt comp=0; comp<numValidComp; comp++)
     1375  {
     1376    memcpy( pCtu->getCrossComponentPredictionAlpha(ComponentID(comp)) + m_absZIdxInCtu, m_crossComponentPredictionAlpha[comp], iSizeInUchar );
     1377    memcpy( pCtu->getTransformSkip(ComponentID(comp))                 + m_absZIdxInCtu, m_puhTransformSkip[comp],              iSizeInUchar );
     1378    memcpy( pCtu->getCbf(ComponentID(comp))                           + m_absZIdxInCtu, m_puhCbf[comp],                        iSizeInUchar );
     1379    memcpy( pCtu->getExplicitRdpcmMode(ComponentID(comp))             + m_absZIdxInCtu, m_explicitRdpcmMode[comp],             iSizeInUchar );
     1380  }
     1381
     1382#if NH_3D_DMM
     1383  for( Int i = 0; i < NUM_DMM; i++ )
     1384  {
     1385    memcpy( pCtu->getDmmDeltaDC( (DmmID)i, 0 ) + m_absZIdxInCtu, m_dmmDeltaDC[i][0], sizeof(Pel ) * m_uiNumPartition );
     1386    memcpy( pCtu->getDmmDeltaDC( (DmmID)i, 1 ) + m_absZIdxInCtu, m_dmmDeltaDC[i][1], sizeof(Pel ) * m_uiNumPartition );
     1387  }
     1388  memcpy( pCtu->getDmm1WedgeTabIdx()           + m_absZIdxInCtu, m_dmm1WedgeTabIdx,  sizeof(UInt) * m_uiNumPartition );
     1389#endif
     1390#if NH_3D_SDC_INTRA
     1391  memcpy( pCtu->getSDCFlag()             + m_absZIdxInCtu, m_pbSDCFlag, sizeof(Bool) * m_uiNumPartition );
     1392  memcpy( pCtu->getSDCSegmentDCOffset(0) + m_absZIdxInCtu, m_apSegmentDCOffset[0], sizeof( Pel ) * m_uiNumPartition);
     1393  memcpy( pCtu->getSDCSegmentDCOffset(1) + m_absZIdxInCtu, m_apSegmentDCOffset[1], sizeof( Pel ) * m_uiNumPartition);
     1394#endif
     1395#if NH_3D_DBBP
     1396  memcpy( pCtu->getDBBPFlag()          + m_absZIdxInCtu, m_pbDBBPFlag,          iSizeInBool  );
     1397#endif
     1398#if NH_3D_ARP
     1399  memcpy( pCtu->getARPW()              + m_absZIdxInCtu, m_puhARPW,             iSizeInUchar );
     1400#endif
     1401
     1402  memcpy( pCtu->getDepth()  + m_absZIdxInCtu, m_puhDepth,  iSizeInUchar );
     1403  memcpy( pCtu->getWidth()  + m_absZIdxInCtu, m_puhWidth,  iSizeInUchar );
     1404  memcpy( pCtu->getHeight() + m_absZIdxInCtu, m_puhHeight, iSizeInUchar );
     1405
     1406  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     1407  {
     1408    const RefPicList rpl=RefPicList(i);
     1409    memcpy( pCtu->getMVPIdx(rpl) + m_absZIdxInCtu, m_apiMVPIdx[rpl], iSizeInUchar );
     1410    memcpy( pCtu->getMVPNum(rpl) + m_absZIdxInCtu, m_apiMVPNum[rpl], iSizeInUchar );
     1411  }
     1412
     1413  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     1414  {
     1415    const RefPicList rpl=RefPicList(i);
     1416    m_acCUMvField[rpl].copyTo( pCtu->getCUMvField( rpl ), m_absZIdxInCtu );
     1417  }
     1418
     1419  memcpy( pCtu->getIPCMFlag() + m_absZIdxInCtu, m_pbIPCMFlag,         iSizeInBool  );
     1420
     1421  const UInt numCoeffY    = (pCtu->getSlice()->getSPS()->getMaxCUWidth()*pCtu->getSlice()->getSPS()->getMaxCUHeight())>>(uhDepth<<1);
     1422  const UInt offsetY      = m_absZIdxInCtu*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
     1423  for (UInt comp=0; comp<numValidComp; comp++)
     1424  {
     1425    const ComponentID component = ComponentID(comp);
     1426    const UInt componentShift   = m_pcPic->getComponentScaleX(component) + m_pcPic->getComponentScaleY(component);
     1427    memcpy( pCtu->getCoeff(component)   + (offsetY>>componentShift), m_pcTrCoeff[component], sizeof(TCoeff)*(numCoeffY>>componentShift) );
    14741428#if ADAPTIVE_QP_SELECTION
    1475   memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
    1476   memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
    1477 #endif
    1478   memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
    1479   memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
    1480   rpcCU->getTotalBins() = m_uiTotalBins;
    1481   memcpy( rpcCU->m_sliceStartCU        + m_uiAbsIdxInLCU, m_sliceStartCU,        sizeof( UInt ) * m_uiNumPartition  );
    1482   memcpy( rpcCU->m_sliceSegmentStartCU + m_uiAbsIdxInLCU, m_sliceSegmentStartCU, sizeof( UInt ) * m_uiNumPartition  );
    1483 #if H_3D_ARP
    1484   memcpy( rpcCU->getARPW()             + m_uiAbsIdxInLCU, m_puhARPW,             iSizeInUchar );
    1485 #endif
    1486 #if H_3D_IC
    1487   memcpy( rpcCU->getICFlag()           + m_uiAbsIdxInLCU, m_pbICFlag,            iSizeInBool );
    1488 #endif
    1489 }
    1490 
    1491 Void TComDataCU::copyToPic( UChar uhDepth, UInt uiPartIdx, UInt uiPartDepth )
    1492 {
    1493   TComDataCU*&  rpcCU       = m_pcPic->getCU( m_uiCUAddr );
    1494   UInt          uiQNumPart  = m_uiNumPartition>>(uiPartDepth<<1);
    1495  
    1496   UInt uiPartStart          = uiPartIdx*uiQNumPart;
    1497   UInt uiPartOffset         = m_uiAbsIdxInLCU + uiPartStart;
    1498  
    1499   rpcCU->getTotalCost()       = m_dTotalCost;
    1500   rpcCU->getTotalDistortion() = m_uiTotalDistortion;
    1501   rpcCU->getTotalBits()       = m_uiTotalBits;
    1502  
    1503   Int iSizeInUchar  = sizeof( UChar  ) * uiQNumPart;
    1504   Int iSizeInBool   = sizeof( Bool   ) * uiQNumPart;
    1505  
    1506   Int sizeInChar  = sizeof( Char ) * uiQNumPart;
    1507   memcpy( rpcCU->getSkipFlag()       + uiPartOffset, m_skipFlag,   sizeof( *m_skipFlag )   * uiQNumPart );
    1508 #if H_3D
    1509   memcpy( rpcCU->getDISFlag()  + uiPartOffset, m_bDISFlag,    sizeof( *m_bDISFlag )   * uiQNumPart );
    1510   memcpy( rpcCU->getDISType()  + uiPartOffset, m_uiDISType,   sizeof( *m_uiDISType )  * uiQNumPart );
    1511 #endif
    1512   memcpy( rpcCU->getQP() + uiPartOffset, m_phQP, sizeInChar );
    1513   memcpy( rpcCU->getPartitionSize()  + uiPartOffset, m_pePartSize, sizeof( *m_pePartSize ) * uiQNumPart );
    1514   memcpy( rpcCU->getPredictionMode() + uiPartOffset, m_pePredMode, sizeof( *m_pePredMode ) * uiQNumPart );
    1515   memcpy( rpcCU->getCUTransquantBypass()+ uiPartOffset, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * uiQNumPart );
    1516   memcpy( rpcCU->getMergeFlag()         + uiPartOffset, m_pbMergeFlag,         iSizeInBool  );
    1517   memcpy( rpcCU->getMergeIndex()        + uiPartOffset, m_puhMergeIndex,       iSizeInUchar );
    1518 #if H_3D_VSP
    1519   memcpy( rpcCU->getVSPFlag()           + uiPartOffset, m_piVSPFlag,           sizeof(Char) * uiQNumPart );
    1520 #endif
     1429    memcpy( pCtu->getArlCoeff(component) + (offsetY>>componentShift), m_pcArlCoeff[component], sizeof(TCoeff)*(numCoeffY>>componentShift) );
     1430#endif
     1431    memcpy( pCtu->getPCMSample(component) + (offsetY>>componentShift), m_pcIPCMSample[component], sizeof(Pel)*(numCoeffY>>componentShift) );
     1432  }
     1433
     1434#if NH_3D_IC
     1435  memcpy( pCtu->getICFlag() + m_absZIdxInCtu, m_pbICFlag, sizeof( *m_pbICFlag ) * m_uiNumPartition );
     1436#endif
     1437  pCtu->getTotalBins() = m_uiTotalBins;
     1438}
    15211439#if H_3D_SPIVMP
    15221440  memcpy( rpcCU->getSPIVMPFlag()        + uiPartOffset, m_pbSPIVMPFlag,        sizeof(Bool) * uiQNumPart );
    15231441#endif
    1524   memcpy( rpcCU->getLumaIntraDir()      + uiPartOffset, m_puhLumaIntraDir,     iSizeInUchar );
    1525   memcpy( rpcCU->getChromaIntraDir()    + uiPartOffset, m_puhChromaIntraDir,   iSizeInUchar );
    1526   memcpy( rpcCU->getInterDir()          + uiPartOffset, m_puhInterDir,         iSizeInUchar );
    1527   memcpy( rpcCU->getTransformIdx()      + uiPartOffset, m_puhTrIdx,            iSizeInUchar );
    1528   memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + uiPartOffset, m_puhTransformSkip[0], iSizeInUchar );
    1529   memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, m_puhTransformSkip[1], iSizeInUchar );
    1530   memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, m_puhTransformSkip[2], iSizeInUchar );
    1531   memcpy( rpcCU->getCbf(TEXT_LUMA)     + uiPartOffset, m_puhCbf[0], iSizeInUchar );
    1532   memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + uiPartOffset, m_puhCbf[1], iSizeInUchar );
    1533   memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + uiPartOffset, m_puhCbf[2], iSizeInUchar );
    1534 #if H_3D_DIM
    1535   for( Int i = 0; i < DMM_NUM_TYPE; i++ )
    1536   {
    1537     memcpy( rpcCU->getDimDeltaDC( i, 0 ) + uiPartOffset, m_dimDeltaDC[i][0], sizeof(Pel ) * uiQNumPart );
    1538     memcpy( rpcCU->getDimDeltaDC( i, 1 ) + uiPartOffset, m_dimDeltaDC[i][1], sizeof(Pel ) * uiQNumPart );
    1539   }
    1540 #if H_3D_DIM_DMM
    1541   for( Int i = 0; i < DMM_NUM_TYPE; i++ )
    1542   {
    1543     memcpy( rpcCU->getDmmWedgeTabIdx( i ) + uiPartOffset, m_dmmWedgeTabIdx[i], sizeof(UInt) * uiQNumPart );
    1544   }
    1545 #endif
    1546 #if H_3D_DIM_SDC
    1547   memcpy( rpcCU->getSDCFlag()             + uiPartOffset, m_pbSDCFlag,      iSizeInBool  );
    1548   memcpy( rpcCU->getSDCSegmentDCOffset(0) + uiPartOffset, m_apSegmentDCOffset[0], sizeof( Pel ) * uiQNumPart);
    1549   memcpy( rpcCU->getSDCSegmentDCOffset(1) + uiPartOffset, m_apSegmentDCOffset[1], sizeof( Pel ) * uiQNumPart);
    1550 #endif
    1551 #endif
    1552 #if H_3D_DBBP
    1553   memcpy( rpcCU->getDBBPFlag()          + uiPartOffset, m_pbDBBPFlag,          iSizeInBool  );
    1554 #endif
    1555  
    1556   memcpy( rpcCU->getDepth()  + uiPartOffset, m_puhDepth,  iSizeInUchar );
    1557   memcpy( rpcCU->getWidth()  + uiPartOffset, m_puhWidth,  iSizeInUchar );
    1558   memcpy( rpcCU->getHeight() + uiPartOffset, m_puhHeight, iSizeInUchar );
    1559  
    1560   memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPIdx[0], iSizeInUchar );
    1561   memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPIdx[1], iSizeInUchar );
    1562   memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPNum[0], iSizeInUchar );
    1563   memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPNum[1], iSizeInUchar );
    1564   m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
    1565   m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
    1566  
    1567   memcpy( rpcCU->getIPCMFlag() + uiPartOffset, m_pbIPCMFlag,         iSizeInBool  );
    1568 
    1569   UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>((uhDepth+uiPartDepth)<<1);
    1570   UInt uiTmp2 = uiPartOffset*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
    1571   memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
    1572 #if ADAPTIVE_QP_SELECTION
    1573   memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
    1574 #endif
    1575  
    1576   memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof( Pel ) * uiTmp );
    1577 
    1578   uiTmp >>= 2; uiTmp2 >>= 2;
    1579   memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
    1580   memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
    1581 #if ADAPTIVE_QP_SELECTION
    1582   memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
    1583   memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
    1584 #endif
    1585 
    1586   memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
    1587   memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
    1588   rpcCU->getTotalBins() = m_uiTotalBins;
    1589   memcpy( rpcCU->m_sliceStartCU        + uiPartOffset, m_sliceStartCU,        sizeof( UInt ) * uiQNumPart  );
    1590   memcpy( rpcCU->m_sliceSegmentStartCU + uiPartOffset, m_sliceSegmentStartCU, sizeof( UInt ) * uiQNumPart  );
    1591 #if H_3D_ARP
    1592   memcpy( rpcCU->getARPW()             + uiPartOffset, m_puhARPW,             iSizeInUchar );
    1593 #endif
    1594 #if H_3D_IC
    1595   memcpy( rpcCU->getICFlag()           + uiPartOffset, m_pbICFlag,            iSizeInBool );
    1596 #endif
    1597 }
     1442
    15981443
    15991444
     
    16021447// --------------------------------------------------------------------------------------------------------------------
    16031448
    1604 TComDataCU* TComDataCU::getPULeft( UInt& uiLPartUnitIdx, 
    1605                                    UInt uiCurrPartUnitIdx, 
    1606                                    Bool bEnforceSliceRestriction, 
     1449TComDataCU* TComDataCU::getPULeft( UInt& uiLPartUnitIdx,
     1450                                   UInt uiCurrPartUnitIdx,
     1451                                   Bool bEnforceSliceRestriction,
    16071452                                   Bool bEnforceTileRestriction )
    16081453{
    16091454  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1610   UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
    1611   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
    1612  
    1613   if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
     1455  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_absZIdxInCtu];
     1456  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1457
     1458  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, numPartInCtuWidth ) )
    16141459  {
    16151460    uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
    1616     if ( RasterAddress::isEqualCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
    1617     {
    1618       return m_pcPic->getCU( getAddr() );
     1461    if ( RasterAddress::isEqualCol( uiAbsPartIdx, uiAbsZorderCUIdx, numPartInCtuWidth ) )
     1462    {
     1463      return m_pcPic->getCtu( getCtuRsAddr() );
    16191464    }
    16201465    else
    16211466    {
    1622       uiLPartUnitIdx -= m_uiAbsIdxInLCU;
     1467      uiLPartUnitIdx -= m_absZIdxInCtu;
    16231468      return this;
    16241469    }
    16251470  }
    1626  
    1627   uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth - 1 ];
    1628 
    1629 
    1630   if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || m_pcCULeft->getSCUAddr()+uiLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
    1631       ||
    1632        (bEnforceTileRestriction && ( m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))  )  )
    1633       )
     1471
     1472  uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + numPartInCtuWidth - 1 ];
     1473  if ( (bEnforceSliceRestriction && !CUIsFromSameSlice(m_pCtuLeft)) || (bEnforceTileRestriction && !CUIsFromSameTile(m_pCtuLeft)) )
    16341474  {
    16351475    return NULL;
    16361476  }
    1637   return m_pcCULeft;
    1638 }
     1477  return m_pCtuLeft;
     1478}
     1479
    16391480
    16401481TComDataCU* TComDataCU::getPUAbove( UInt& uiAPartUnitIdx,
    1641                                     UInt uiCurrPartUnitIdx, 
    1642                                     Bool bEnforceSliceRestriction, 
    1643                                     Bool planarAtLCUBoundary ,
     1482                                    UInt uiCurrPartUnitIdx,
     1483                                    Bool bEnforceSliceRestriction,
     1484                                    Bool planarAtCtuBoundary,
    16441485                                    Bool bEnforceTileRestriction )
    16451486{
    16461487  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1647   UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
    1648   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
    1649  
    1650   if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
    1651   {
    1652     uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth ];
    1653     if ( RasterAddress::isEqualRow( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
    1654     {
    1655       return m_pcPic->getCU( getAddr() );
     1488  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_absZIdxInCtu];
     1489  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1490
     1491  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, numPartInCtuWidth ) )
     1492  {
     1493    uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - numPartInCtuWidth ];
     1494    if ( RasterAddress::isEqualRow( uiAbsPartIdx, uiAbsZorderCUIdx, numPartInCtuWidth ) )
     1495    {
     1496      return m_pcPic->getCtu( getCtuRsAddr() );
    16561497    }
    16571498    else
    16581499    {
    1659       uiAPartUnitIdx -= m_uiAbsIdxInLCU;
     1500      uiAPartUnitIdx -= m_absZIdxInCtu;
    16601501      return this;
    16611502    }
    16621503  }
    16631504
    1664   if(planarAtLCUBoundary)
     1505  if(planarAtCtuBoundary)
    16651506  {
    16661507    return NULL;
    16671508  }
    1668  
    1669   uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
    1670 
    1671   if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || m_pcCUAbove->getSCUAddr()+uiAPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
    1672       ||
    1673        (bEnforceTileRestriction &&(m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))))
    1674       )
     1509
     1510  uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + m_pcPic->getNumPartitionsInCtu() - numPartInCtuWidth ];
     1511
     1512  if ( (bEnforceSliceRestriction && !CUIsFromSameSlice(m_pCtuAbove)) || (bEnforceTileRestriction && !CUIsFromSameTile(m_pCtuAbove)) )
    16751513  {
    16761514    return NULL;
    16771515  }
    1678   return m_pcCUAbove;
     1516  return m_pCtuAbove;
    16791517}
    16801518
     
    16821520{
    16831521  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1684   UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
    1685   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
    1686  
    1687   if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
    1688   {
    1689     if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
    1690     {
    1691       uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth - 1 ];
    1692       if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
    1693       {
    1694         return m_pcPic->getCU( getAddr() );
     1522  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_absZIdxInCtu];
     1523  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1524
     1525  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, numPartInCtuWidth ) )
     1526  {
     1527    if ( !RasterAddress::isZeroRow( uiAbsPartIdx, numPartInCtuWidth ) )
     1528    {
     1529      uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - numPartInCtuWidth - 1 ];
     1530      if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdx, uiAbsZorderCUIdx, numPartInCtuWidth ) )
     1531      {
     1532        return m_pcPic->getCtu( getCtuRsAddr() );
    16951533      }
    16961534      else
    16971535      {
    1698         uiALPartUnitIdx -= m_uiAbsIdxInLCU;
     1536        uiALPartUnitIdx -= m_absZIdxInCtu;
    16991537        return this;
    17001538      }
    17011539    }
    1702     uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + getPic()->getNumPartInCU() - uiNumPartInCUWidth - 1 ];
    1703     if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
    1704        m_pcCUAbove->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1705        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1706        ))
    1707      )
     1540    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + getPic()->getNumPartitionsInCtu() - numPartInCtuWidth - 1 ];
     1541    if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAbove) )
    17081542    {
    17091543      return NULL;
    17101544    }
    1711     return m_pcCUAbove;
    1712   }
    1713  
    1714   if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
     1545    return m_pCtuAbove;
     1546  }
     1547
     1548  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, numPartInCtuWidth ) )
    17151549  {
    17161550    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
    1717     if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL ||
    1718        m_pcCULeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1719        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1720        ))
    1721      )
     1551    if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuLeft) )
    17221552    {
    17231553      return NULL;
    17241554    }
    1725     return m_pcCULeft;
    1726   }
    1727  
    1728   uiALPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - 1 ];
    1729   if ( (bEnforceSliceRestriction && (m_pcCUAboveLeft==NULL || m_pcCUAboveLeft->getSlice()==NULL ||
    1730        m_pcCUAboveLeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1731        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveLeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1732        ))
    1733      )
     1555    return m_pCtuLeft;
     1556  }
     1557
     1558  uiALPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartitionsInCtu() - 1 ];
     1559  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAboveLeft) )
    17341560  {
    17351561    return NULL;
    17361562  }
    1737   return m_pcCUAboveLeft;
    1738 }
    1739 
    1740 TComDataCU* TComDataCU::getPUAboveRight( UInt& uiARPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
    1741 {
    1742   UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1743   UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1;
    1744   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
    1745  
    1746   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
    1747   {
    1748     uiARPartUnitIdx = MAX_UINT;
     1563  return m_pCtuAboveLeft;
     1564}
     1565
     1566TComDataCU* TComDataCU::getPUBelowLeft(UInt& uiBLPartUnitIdx,  UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction)
     1567{
     1568  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
     1569  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1570  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_absZIdxInCtu ] + ((m_puhHeight[0] / m_pcPic->getMinCUHeight()) - 1)*numPartInCtuWidth;
     1571
     1572  if( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples())
     1573  {
     1574    uiBLPartUnitIdx = MAX_UINT;
    17491575    return NULL;
    17501576  }
    1751  
    1752   if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - 1, uiNumPartInCUWidth ) )
    1753   {
    1754     if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
    1755     {
    1756       if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ] )
    1757       {
    1758         uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ];
    1759         if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
     1577
     1578  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInCtuHeight() - uiPartUnitOffset, numPartInCtuWidth ) )
     1579  {
     1580    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, numPartInCtuWidth ) )
     1581    {
     1582      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * numPartInCtuWidth - 1 ] )
     1583      {
     1584        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * numPartInCtuWidth - 1 ];
     1585        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, numPartInCtuWidth ) )
    17601586        {
    1761           return m_pcPic->getCU( getAddr() );
     1587          return m_pcPic->getCtu( getCtuRsAddr() );
    17621588        }
    17631589        else
    17641590        {
    1765           uiARPartUnitIdx -= m_uiAbsIdxInLCU;
     1591          uiBLPartUnitIdx -= m_absZIdxInCtu;
    17661592          return this;
    17671593        }
    17681594      }
    1769       uiARPartUnitIdx = MAX_UINT;
     1595      uiBLPartUnitIdx = MAX_UINT;
    17701596      return NULL;
    17711597    }
    1772     uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + 1 ];
    1773     if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
    1774        m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1775        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1776        ))
    1777      )
     1598    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + (1+uiPartUnitOffset) * numPartInCtuWidth - 1 ];
     1599    if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuLeft) )
    17781600    {
    17791601      return NULL;
    17801602    }
    1781     return m_pcCUAbove;
    1782   }
    1783  
    1784   if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
     1603    return m_pCtuLeft;
     1604  }
     1605
     1606  uiBLPartUnitIdx = MAX_UINT;
     1607  return NULL;
     1608}
     1609
     1610TComDataCU* TComDataCU::getPUAboveRight(UInt&  uiARPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction)
     1611{
     1612  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
     1613  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_absZIdxInCtu ] + (m_puhWidth[0] / m_pcPic->getMinCUWidth()) - 1;
     1614  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1615
     1616  if( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
    17851617  {
    17861618    uiARPartUnitIdx = MAX_UINT;
    17871619    return NULL;
    17881620  }
    1789  
    1790   uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
    1791   if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
    1792        m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
    1793        m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1794        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1795        ))
    1796      )
    1797   {
    1798     return NULL;
    1799   }
    1800   return m_pcCUAboveRight;
    1801 }
    1802 
    1803 TComDataCU* TComDataCU::getPUBelowLeft( UInt& uiBLPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
    1804 {
    1805   UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1806   UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhHeight[0] / m_pcPic->getMinCUHeight() - 1)*m_pcPic->getNumPartInWidth();
    1807   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
    1808  
    1809   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
    1810   {
    1811     uiBLPartUnitIdx = MAX_UINT;
    1812     return NULL;
    1813   }
    1814  
    1815   if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - 1, uiNumPartInCUWidth ) )
    1816   {
    1817     if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
    1818     {
    1819       if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ] )
    1820       {
    1821         uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ];
    1822         if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
     1621
     1622  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, numPartInCtuWidth - uiPartUnitOffset, numPartInCtuWidth ) )
     1623  {
     1624    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, numPartInCtuWidth ) )
     1625    {
     1626      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - numPartInCtuWidth + uiPartUnitOffset ] )
     1627      {
     1628        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - numPartInCtuWidth + uiPartUnitOffset ];
     1629        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, numPartInCtuWidth ) )
    18231630        {
    1824           return m_pcPic->getCU( getAddr() );
     1631          return m_pcPic->getCtu( getCtuRsAddr() );
    18251632        }
    18261633        else
    18271634        {
    1828           uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
     1635          uiARPartUnitIdx -= m_absZIdxInCtu;
    18291636          return this;
    18301637        }
    18311638      }
    1832       uiBLPartUnitIdx = MAX_UINT;
     1639      uiARPartUnitIdx = MAX_UINT;
    18331640      return NULL;
    18341641    }
    1835     uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth*2 - 1 ];
    1836     if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL ||
    1837        m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1838        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1839        ))
    1840      )
     1642
     1643    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartitionsInCtu() - numPartInCtuWidth + uiPartUnitOffset ];
     1644    if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAbove) )
    18411645    {
    18421646      return NULL;
    18431647    }
    1844     return m_pcCULeft;
    1845   }
    1846  
    1847   uiBLPartUnitIdx = MAX_UINT;
    1848   return NULL;
    1849 }
    1850 
    1851 TComDataCU* TComDataCU::getPUBelowLeftAdi(UInt& uiBLPartUnitIdx,  UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
    1852 {
    1853   UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1854   UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ((m_puhHeight[0] / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth();
    1855   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
    1856  
    1857   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples())
    1858   {
    1859     uiBLPartUnitIdx = MAX_UINT;
    1860     return NULL;
    1861   }
    1862  
    1863   if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - uiPartUnitOffset, uiNumPartInCUWidth ) )
    1864   {
    1865     if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
    1866     {
    1867       if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ] )
    1868       {
    1869         uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ];
    1870         if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
    1871         {
    1872           return m_pcPic->getCU( getAddr() );
    1873         }
    1874         else
    1875         {
    1876           uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
    1877           return this;
    1878         }
    1879       }
    1880       uiBLPartUnitIdx = MAX_UINT;
    1881       return NULL;
    1882     }
    1883     uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + (1+uiPartUnitOffset) * uiNumPartInCUWidth - 1 ];
    1884     if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL ||
    1885        m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1886        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1887        ))
    1888      )
    1889     {
    1890       return NULL;
    1891     }
    1892     return m_pcCULeft;
    1893   }
    1894  
    1895   uiBLPartUnitIdx = MAX_UINT;
    1896   return NULL;
    1897 }
    1898 
    1899 TComDataCU* TComDataCU::getPUAboveRightAdi(UInt&  uiARPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
    1900 {
    1901   UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1902   UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhWidth[0] / m_pcPic->getMinCUWidth()) - 1;
    1903   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
    1904  
    1905   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
     1648    return m_pCtuAbove;
     1649  }
     1650
     1651  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, numPartInCtuWidth ) )
    19061652  {
    19071653    uiARPartUnitIdx = MAX_UINT;
    19081654    return NULL;
    19091655  }
    1910  
    1911   if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - uiPartUnitOffset, uiNumPartInCUWidth ) )
    1912   {
    1913     if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
    1914     {
    1915       if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ] )
    1916       {
    1917         uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ];
    1918         if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
    1919         {
    1920           return m_pcPic->getCU( getAddr() );
    1921         }
    1922         else
    1923         {
    1924           uiARPartUnitIdx -= m_uiAbsIdxInLCU;
    1925           return this;
    1926         }
    1927       }
    1928       uiARPartUnitIdx = MAX_UINT;
    1929       return NULL;
    1930     }
    1931     uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset ];
    1932     if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
    1933        m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1934        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1935        ))
    1936      )
    1937     {
    1938       return NULL;
    1939     }
    1940     return m_pcCUAbove;
    1941   }
    1942  
    1943   if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
    1944   {
    1945     uiARPartUnitIdx = MAX_UINT;
     1656
     1657  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartitionsInCtu() - numPartInCtuWidth + uiPartUnitOffset-1 ];
     1658  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAboveRight) )
     1659  {
    19461660    return NULL;
    19471661  }
    1948  
    1949   uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset-1 ];
    1950   if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
    1951        m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
    1952        m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1953        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1954        ))
    1955      )
    1956   {
    1957     return NULL;
    1958   }
    1959   return m_pcCUAboveRight;
     1662  return m_pCtuAboveRight;
    19601663}
    19611664
    19621665/** Get left QpMinCu
    19631666*\param   uiLPartUnitIdx
    1964 *\param   uiCurrAbsIdxInLCU
     1667*\param   uiCurrAbsIdxInCtu
    19651668*\returns TComDataCU*   point of TComDataCU of left QpMinCu
    19661669*/
    1967 TComDataCU* TComDataCU::getQpMinCuLeft( UInt& uiLPartUnitIdx, UInt uiCurrAbsIdxInLCU)
    1968 {
    1969   UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
    1970   UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth -getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
     1670TComDataCU* TComDataCU::getQpMinCuLeft( UInt& uiLPartUnitIdx, UInt uiCurrAbsIdxInCtu )
     1671{
     1672  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1673  const UInt maxCUDepth        = getSlice()->getSPS()->getMaxTotalCUDepth();
     1674  const UInt maxCuDQPDepth     = getSlice()->getPPS()->getMaxCuDQPDepth();
     1675  const UInt doubleDepthDifference = ((maxCUDepth - maxCuDQPDepth)<<1);
     1676  UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInCtu>>doubleDepthDifference)<<doubleDepthDifference;
    19711677  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
    19721678
    1973   // check for left LCU boundary
    1974   if ( RasterAddress::isZeroCol(absRorderQpMinCUIdx, numPartInCUWidth) )
     1679  // check for left CTU boundary
     1680  if ( RasterAddress::isZeroCol(absRorderQpMinCUIdx, numPartInCtuWidth) )
    19751681  {
    19761682    return NULL;
     
    19801686  uiLPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - 1];
    19811687
    1982   // return pointer to current LCU
    1983   return m_pcPic->getCU( getAddr() );
     1688  // return pointer to current CTU
     1689  return m_pcPic->getCtu( getCtuRsAddr() );
    19841690}
    19851691
    19861692/** Get Above QpMinCu
    1987 *\param   aPartUnitIdx
    1988 *\param   currAbsIdxInLCU
     1693*\param   uiAPartUnitIdx
     1694*\param   uiCurrAbsIdxInCtu
    19891695*\returns TComDataCU*   point of TComDataCU of above QpMinCu
    19901696*/
    1991 TComDataCU* TComDataCU::getQpMinCuAbove( UInt& aPartUnitIdx, UInt currAbsIdxInLCU )
    1992 {
    1993   UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
    1994   UInt absZorderQpMinCUIdx = (currAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
     1697TComDataCU* TComDataCU::getQpMinCuAbove( UInt& uiAPartUnitIdx, UInt uiCurrAbsIdxInCtu )
     1698{
     1699  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1700  const UInt maxCUDepth        = getSlice()->getSPS()->getMaxTotalCUDepth();
     1701  const UInt maxCuDQPDepth     = getSlice()->getPPS()->getMaxCuDQPDepth();
     1702  const UInt doubleDepthDifference = ((maxCUDepth - maxCuDQPDepth)<<1);
     1703  UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInCtu>>doubleDepthDifference)<<doubleDepthDifference;
    19951704  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
    19961705
    1997   // check for top LCU boundary
    1998   if ( RasterAddress::isZeroRow( absRorderQpMinCUIdx, numPartInCUWidth) )
     1706  // check for top CTU boundary
     1707  if ( RasterAddress::isZeroRow( absRorderQpMinCUIdx, numPartInCtuWidth) )
    19991708  {
    20001709    return NULL;
     
    20021711
    20031712  // get index of top-CU relative to top-left corner of current quantization group
    2004   aPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - numPartInCUWidth];
    2005 
    2006   // return pointer to current LCU
    2007   return m_pcPic->getCU( getAddr() );
    2008 }
     1713  uiAPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - numPartInCtuWidth];
     1714
     1715  // return pointer to current CTU
     1716  return m_pcPic->getCtu( getCtuRsAddr() );
     1717}
     1718
     1719
    20091720
    20101721/** Get reference QP from left QpMinCu or latest coded QP
    2011 *\param   uiCurrAbsIdxInLCU
     1722*\param   uiCurrAbsIdxInCtu
    20121723*\returns Char   reference QP value
    20131724*/
    2014 Char TComDataCU::getRefQP( UInt uiCurrAbsIdxInLCU )
    2015 {
    2016   UInt        lPartIdx = 0, aPartIdx = 0;
    2017   TComDataCU* cULeft  = getQpMinCuLeft ( lPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
    2018   TComDataCU* cUAbove = getQpMinCuAbove( aPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
    2019   return (((cULeft? cULeft->getQP( lPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + (cUAbove? cUAbove->getQP( aPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + 1) >> 1);
     1725Char TComDataCU::getRefQP( UInt uiCurrAbsIdxInCtu )
     1726{
     1727  UInt lPartIdx = MAX_UINT;
     1728  UInt aPartIdx = MAX_UINT;
     1729  TComDataCU* cULeft  = getQpMinCuLeft ( lPartIdx, m_absZIdxInCtu + uiCurrAbsIdxInCtu );
     1730  TComDataCU* cUAbove = getQpMinCuAbove( aPartIdx, m_absZIdxInCtu + uiCurrAbsIdxInCtu );
     1731  return (((cULeft? cULeft->getQP( lPartIdx ): getLastCodedQP( uiCurrAbsIdxInCtu )) + (cUAbove? cUAbove->getQP( aPartIdx ): getLastCodedQP( uiCurrAbsIdxInCtu )) + 1) >> 1);
    20201732}
    20211733
     
    20241736  Int iLastValidPartIdx = iAbsPartIdx-1;
    20251737  while ( iLastValidPartIdx >= 0
    2026        && getPredictionMode( iLastValidPartIdx ) == MODE_NONE )
     1738       && getPredictionMode( iLastValidPartIdx ) == NUMBER_OF_PREDICTION_MODES )
    20271739  {
    20281740    UInt uiDepth = getDepth( iLastValidPartIdx );
     
    20341746Char TComDataCU::getLastCodedQP( UInt uiAbsPartIdx )
    20351747{
    2036   UInt uiQUPartIdxMask = ~((1<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))-1);
    2037   Int iLastValidPartIdx = getLastValidPartIdx( uiAbsPartIdx&uiQUPartIdxMask );
    2038   if ( uiAbsPartIdx < m_uiNumPartition
    2039     && (getSCUAddr()+iLastValidPartIdx < getSliceStartCU(m_uiAbsIdxInLCU+uiAbsPartIdx)))
     1748  UInt uiQUPartIdxMask = ~((1<<((getSlice()->getSPS()->getMaxTotalCUDepth() - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))-1);
     1749  Int iLastValidPartIdx = getLastValidPartIdx( uiAbsPartIdx&uiQUPartIdxMask ); // A idx will be invalid if it is off the right or bottom edge of the picture.
     1750  // If this CU is in the first CTU of the slice and there is no valid part before this one, use slice QP
     1751  if ( getPic()->getPicSym()->getCtuTsToRsAddrMap(getSlice()->getSliceCurStartCtuTsAddr()) == getCtuRsAddr() && Int(getZorderIdxInCtu())+iLastValidPartIdx<0)
    20401752  {
    20411753    return getSlice()->getSliceQp();
     
    20431755  else if ( iLastValidPartIdx >= 0 )
    20441756  {
     1757    // If there is a valid part within the current Sub-CU, use it
    20451758    return getQP( iLastValidPartIdx );
    20461759  }
    20471760  else
    20481761  {
    2049     if ( getZorderIdxInCU() > 0 )
    2050     {
    2051       return getPic()->getCU( getAddr() )->getLastCodedQP( getZorderIdxInCU() );
    2052     }
    2053     else if ( getPic()->getPicSym()->getInverseCUOrderMap(getAddr()) > 0
    2054       && getPic()->getPicSym()->getTileIdxMap(getAddr()) == getPic()->getPicSym()->getTileIdxMap(getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1))
    2055       && !( getSlice()->getPPS()->getEntropyCodingSyncEnabledFlag() && getAddr() % getPic()->getFrameWidthInCU() == 0 ) )
    2056     {
    2057       return getPic()->getCU( getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1) )->getLastCodedQP( getPic()->getNumPartInCU() );
     1762    if ( getZorderIdxInCtu() > 0 )
     1763    {
     1764      // If this wasn't the first sub-cu within the Ctu, explore the CTU itself.
     1765      return getPic()->getCtu( getCtuRsAddr() )->getLastCodedQP( getZorderIdxInCtu() ); // TODO - remove this recursion
     1766    }
     1767    else if ( getPic()->getPicSym()->getCtuRsToTsAddrMap(getCtuRsAddr()) > 0
     1768      && CUIsFromSameSliceTileAndWavefrontRow(getPic()->getCtu(getPic()->getPicSym()->getCtuTsToRsAddrMap(getPic()->getPicSym()->getCtuRsToTsAddrMap(getCtuRsAddr())-1))) )
     1769    {
     1770      // If this isn't the first Ctu (how can it be due to the first 'if'?), and the previous Ctu is from the same tile, examine the previous Ctu.
     1771      return getPic()->getCtu( getPic()->getPicSym()->getCtuTsToRsAddrMap(getPic()->getPicSym()->getCtuRsToTsAddrMap(getCtuRsAddr())-1) )->getLastCodedQP( getPic()->getNumPartitionsInCtu() );  // TODO - remove this recursion
    20581772    }
    20591773    else
    20601774    {
     1775      // No other options available - use the slice-level QP.
    20611776      return getSlice()->getSliceQp();
    20621777    }
    20631778  }
    20641779}
    2065 /** Check whether the CU is coded in lossless coding mode
    2066  * \param   uiAbsPartIdx
    2067  * \returns true if the CU is coded in lossless coding mode; false if otherwise
     1780
     1781
     1782/** Check whether the CU is coded in lossless coding mode.
     1783 * \param   absPartIdx
     1784 * \returns true if the CU is coded in lossless coding mode; false if otherwise
    20681785 */
    20691786Bool TComDataCU::isLosslessCoded(UInt absPartIdx)
     
    20721789}
    20731790
     1791
    20741792/** Get allowed chroma intra modes
    2075 *\param   uiAbsPartIdx
    2076 *\param   uiModeList  pointer to chroma intra modes array
    2077 *\returns
    2078 *- fill uiModeList with chroma intra modes
     1793*   - fills uiModeList with chroma intra modes
     1794*
     1795*\param   [in]  uiAbsPartIdx
     1796*\param   [out] uiModeList pointer to chroma intra modes array
    20791797*/
    2080 Void TComDataCU::getAllowedChromaDir( UInt uiAbsPartIdx, UInt* uiModeList )
     1798Void TComDataCU::getAllowedChromaDir( UInt uiAbsPartIdx, UInt uiModeList[NUM_CHROMA_MODE] )
    20811799{
    20821800  uiModeList[0] = PLANAR_IDX;
     
    20851803  uiModeList[3] = DC_IDX;
    20861804  uiModeList[4] = DM_CHROMA_IDX;
    2087 
    2088   UInt uiLumaMode = getLumaIntraDir( uiAbsPartIdx );
     1805  assert(4<NUM_CHROMA_MODE);
     1806
     1807  UInt uiLumaMode = getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx );
    20891808
    20901809  for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ )
     
    20991818
    21001819/** Get most probable intra modes
    2101 *\param   uiAbsPartIdx
     1820*\param   uiAbsPartIdx    partition index
    21021821*\param   uiIntraDirPred  pointer to the array for MPM storage
     1822*\param   compID          colour component ID
    21031823*\param   piMode          it is set with MPM mode in case both MPM are equal. It is used to restrict RD search at encode side.
    21041824*\returns Number of MPM
    21051825*/
    2106 Int TComDataCU::getIntraDirLumaPredictor( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int* piMode  )
    2107 {
    2108   TComDataCU* pcTempCU;
    2109   UInt        uiTempPartIdx;
     1826Void TComDataCU::getIntraDirPredictor( UInt uiAbsPartIdx, Int uiIntraDirPred[NUM_MOST_PROBABLE_MODES], const ComponentID compID, Int* piMode  )
     1827{
     1828  TComDataCU* pcCULeft, *pcCUAbove;
     1829  UInt        LeftPartIdx  = MAX_UINT;
     1830  UInt        AbovePartIdx = MAX_UINT;
    21101831  Int         iLeftIntraDir, iAboveIntraDir;
    2111   Int         uiPredNum = 0;
    2112  
     1832  const TComSPS *sps=getSlice()->getSPS();
     1833  const UInt partsPerMinCU = 1<<(2*(sps->getMaxTotalCUDepth() - sps->getLog2DiffMaxMinCodingBlockSize()));
     1834
     1835  const ChannelType chType = toChannelType(compID);
     1836  const ChromaFormat chForm = getPic()->getChromaFormat();
    21131837  // Get intra direction of left PU
    2114   pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
    2115  
    2116   iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
    2117 #if H_3D_DIM
    2118   mapDepthModeToIntraDir( iLeftIntraDir );
    2119 #endif
    2120  
     1838  pcCULeft = getPULeft( LeftPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
     1839
     1840  if (isChroma(compID))
     1841  {
     1842    LeftPartIdx = getChromasCorrespondingPULumaIdx(LeftPartIdx, chForm, partsPerMinCU);
     1843  }
     1844  iLeftIntraDir  = pcCULeft ? ( pcCULeft->isIntra( LeftPartIdx ) ? pcCULeft->getIntraDir( chType, LeftPartIdx ) : DC_IDX ) : DC_IDX;
     1845#if NH_3D_DMM
     1846  mapDmmToIntraDir( iLeftIntraDir );
     1847#endif
     1848
    21211849  // Get intra direction of above PU
    2122   pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, true );
    2123  
    2124   iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
    2125 #if H_3D_DIM
    2126   mapDepthModeToIntraDir( iAboveIntraDir );
    2127 #endif
    2128  
    2129   uiPredNum = 3;
     1850  pcCUAbove = getPUAbove( AbovePartIdx, m_absZIdxInCtu + uiAbsPartIdx, true, true );
     1851
     1852  if (isChroma(compID))
     1853  {
     1854    AbovePartIdx = getChromasCorrespondingPULumaIdx(AbovePartIdx, chForm, partsPerMinCU);
     1855  }
     1856  iAboveIntraDir = pcCUAbove ? ( pcCUAbove->isIntra( AbovePartIdx ) ? pcCUAbove->getIntraDir( chType, AbovePartIdx ) : DC_IDX ) : DC_IDX;
     1857#if NH_3D_DMM
     1858  mapDmmToIntraDir( iAboveIntraDir );
     1859#endif
     1860
     1861
     1862  if (isChroma(chType))
     1863  {
     1864    if (iLeftIntraDir  == DM_CHROMA_IDX)
     1865    {
     1866      iLeftIntraDir  = pcCULeft-> getIntraDir( CHANNEL_TYPE_LUMA, LeftPartIdx  );
     1867    }
     1868    if (iAboveIntraDir == DM_CHROMA_IDX)
     1869    {
     1870      iAboveIntraDir = pcCUAbove->getIntraDir( CHANNEL_TYPE_LUMA, AbovePartIdx );
     1871    }
     1872  }
     1873
     1874  assert (2<NUM_MOST_PROBABLE_MODES);
    21301875  if(iLeftIntraDir == iAboveIntraDir)
    21311876  {
     
    21341879      *piMode = 1;
    21351880    }
    2136    
     1881
    21371882    if (iLeftIntraDir > 1) // angular modes
    21381883    {
     
    21451890      uiIntraDirPred[0] = PLANAR_IDX;
    21461891      uiIntraDirPred[1] = DC_IDX;
    2147       uiIntraDirPred[2] = VER_IDX; 
     1892      uiIntraDirPred[2] = VER_IDX;
    21481893    }
    21491894  }
     
    21561901    uiIntraDirPred[0] = iLeftIntraDir;
    21571902    uiIntraDirPred[1] = iAboveIntraDir;
    2158    
     1903
    21591904    if (iLeftIntraDir && iAboveIntraDir ) //both modes are non-planar
    21601905    {
     
    21661911    }
    21671912  }
    2168  
    2169   return uiPredNum;
     1913  for (UInt i=0; i<NUM_MOST_PROBABLE_MODES; i++)
     1914  {
     1915    assert(uiIntraDirPred[i] < 35);
     1916  }
    21701917}
    21711918
     
    21761923  UInt        uiCtx;
    21771924  // Get left split flag
    2178   pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
     1925  pcTempCU = getPULeft( uiTempPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
    21791926  uiCtx  = ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
    2180  
     1927
    21811928  // Get above split flag
    2182   pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
     1929  pcTempCU = getPUAbove( uiTempPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
    21831930  uiCtx += ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
    2184  
     1931
    21851932  return uiCtx;
    21861933}
    21871934
    2188 UInt TComDataCU::getCtxQtCbf( TextType eType, UInt uiTrDepth )
    2189 {
    2190   if( eType )
    2191   {
    2192     return uiTrDepth;
     1935UInt TComDataCU::getCtxQtCbf( TComTU &rTu, const ChannelType chType )
     1936{
     1937  const UInt transformDepth = rTu.GetTransformDepthRel();
     1938
     1939  if (isChroma(chType))
     1940  {
     1941    return transformDepth;
    21931942  }
    21941943  else
    21951944  {
    2196     const UInt uiCtx = ( uiTrDepth == 0 ? 1 : 0 );
     1945    const UInt uiCtx = ( transformDepth == 0 ? 1 : 0 );
    21971946    return uiCtx;
    21981947  }
     
    22031952  UInt log2CbSize = g_aucConvertToBit[getWidth( absPartIdx )] + 2;
    22041953  PartSize  partSize  = getPartitionSize( absPartIdx );
    2205   UInt quadtreeTUMaxDepth = getPredictionMode( absPartIdx ) == MODE_INTRA ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter();
    2206   Int intraSplitFlag = ( getPredictionMode( absPartIdx ) == MODE_INTRA && partSize == SIZE_NxN ) ? 1 : 0;
    2207   Int interSplitFlag = ((quadtreeTUMaxDepth == 1) && (getPredictionMode( absPartIdx ) == MODE_INTER) && (partSize != SIZE_2Nx2N) );
    2208  
     1954  UInt quadtreeTUMaxDepth = isIntra( absPartIdx ) ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter();
     1955  Int intraSplitFlag = ( isIntra( absPartIdx ) && partSize == SIZE_NxN ) ? 1 : 0;
     1956  Int interSplitFlag = ((quadtreeTUMaxDepth == 1) && isInter( absPartIdx ) && (partSize != SIZE_2Nx2N) );
     1957
    22091958  UInt log2MinTUSizeInCU = 0;
    2210   if (log2CbSize < (m_pcSlice->getSPS()->getQuadtreeTULog2MinSize() + quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag) ) 
     1959  if (log2CbSize < (m_pcSlice->getSPS()->getQuadtreeTULog2MinSize() + quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag) )
    22111960  {
    22121961    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is < QuadtreeTULog2MinSize
     
    22211970      // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still > QuadtreeTULog2MaxSize
    22221971      log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize();
    2223     } 
     1972    }
    22241973  }
    22251974  return log2MinTUSizeInCU;
     
    22271976
    22281977UInt TComDataCU::getCtxSkipFlag( UInt uiAbsPartIdx )
     1978{
     1979  TComDataCU* pcTempCU;
     1980  UInt        uiTempPartIdx;
     1981  UInt        uiCtx = 0;
     1982
     1983  // Get BCBP of left PU
     1984  pcTempCU = getPULeft( uiTempPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
     1985  uiCtx    = ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
     1986
     1987  // Get BCBP of above PU
     1988  pcTempCU = getPUAbove( uiTempPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
     1989  uiCtx   += ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
     1990
     1991  return uiCtx;
     1992}
     1993#if NH_3D_ARP
     1994UInt TComDataCU::getCTXARPWFlag( UInt uiAbsPartIdx )
    22291995{
    22301996  TComDataCU* pcTempCU;
     
    22321998  UInt        uiCtx = 0;
    22331999 
    2234   // Get BCBP of left PU
    2235   pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
    2236   uiCtx    = ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
    2237  
    2238   // Get BCBP of above PU
    2239   pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
    2240   uiCtx   += ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
    2241  
    2242   return uiCtx;
    2243 }
    2244 
    2245 #if H_3D_ARP
    2246 UInt TComDataCU::getCTXARPWFlag( UInt uiAbsPartIdx )
    2247 {
    2248   TComDataCU* pcTempCU;
    2249   UInt        uiTempPartIdx;
    2250   UInt        uiCtx = 0;
    2251  
    2252   pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
     2000  pcTempCU = getPULeft( uiTempPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
    22532001  uiCtx    = ( pcTempCU ) ? ((pcTempCU->getARPW( uiTempPartIdx )==0)?0:1) : 0;
    22542002    return uiCtx;
    22552003}
    22562004#endif
    2257 #if H_3D_DBBP
     2005#if NH_3D_DBBP
    22582006Pel* TComDataCU::getVirtualDepthBlock(UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt& uiDepthStride)
    22592007{
     2008  const TComSPS* sps = getSlice()->getSPS();
     2009  UInt uiMaxCUWidth = sps->getMaxCUWidth();
     2010  UInt uiMaxCUHeight = sps->getMaxCUHeight();
     2011 
    22602012  // get coded and reconstructed depth view
    22612013  TComPicYuv* depthPicYuv = NULL;
     
    22632015 
    22642016  // DBBP is a texture coding tool
    2265   if( getSlice()->getIsDepth() )
    2266   {
    2267     return NULL;
    2268   } 
     2017  assert( !getSlice()->getIsDepth() );
     2018 
    22692019#if H_3D_FCO
    22702020  TComPic* depthPic = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
     
    22932043    depthPicYuv   = baseDepthPic->getPicYuvRec();
    22942044    depthPicYuv->extendPicBorder();
    2295     uiDepthStride = depthPicYuv->getStride();
     2045    uiDepthStride = depthPicYuv->getStride(COMPONENT_Y);
    22962046   
    2297     Int iBlkX = ( getAddr() % baseDepthPic->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ getZorderIdxInCU()+uiAbsPartIdx ] ];
    2298     Int iBlkY = ( getAddr() / baseDepthPic->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ getZorderIdxInCU()+uiAbsPartIdx ] ];
     2047    Int iBlkX = ( getCtuRsAddr() % baseDepthPic->getFrameWidthInCtus() ) * uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ getZorderIdxInCtu()+uiAbsPartIdx ] ];
     2048    Int iBlkY = ( getCtuRsAddr() / baseDepthPic->getFrameWidthInCtus() ) * uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ getZorderIdxInCtu()+uiAbsPartIdx ] ];
    22992049   
    2300     Int iPictureWidth  = depthPicYuv->getWidth();
    2301     Int iPictureHeight = depthPicYuv->getHeight();
     2050    Int iPictureWidth  = depthPicYuv->getWidth(COMPONENT_Y);
     2051    Int iPictureHeight = depthPicYuv->getHeight(COMPONENT_Y);
    23022052   
    23032053   
    23042054    Bool depthRefineFlag = false;
    2305 #if H_3D_NBDV_REF
    2306     depthRefineFlag = m_pcSlice->getDepthRefinementFlag(  );
    2307 #endif // H_3D_NBDV_REF
     2055#if NH_3D_NBDV_REF
     2056    depthRefineFlag = m_pcSlice->getDepthRefinementFlag();
     2057#endif // NH_3D_NBDV_REF
    23082058   
    23092059    TComMv cDv = depthRefineFlag ? DvInfo.m_acDoNBDV : DvInfo.m_acNBDV;
     
    23162066    Int depthPosY = Clip3(0,   iPictureHeight - 1, iBlkY + ((cDv.getVer()+2)>>2));
    23172067   
    2318     pDepthPels = depthPicYuv->getLumaAddr() + depthPosX + depthPosY * uiDepthStride;
     2068    pDepthPels = depthPicYuv->getAddr(COMPONENT_Y) + depthPosX + depthPosY * uiDepthStride;
    23192069  }
    23202070#endif
     
    23282078#endif
    23292079
    2330 #if H_3D_DBBP
     2080#if NH_3D_DBBP
    23312081Void TComDataCU::setDBBPFlagSubParts ( Bool bDBBPFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
    23322082{
     
    23352085#endif
    23362086
    2337 #if H_3D_DIM_SDC
    2338 UInt TComDataCU::getCtxSDCFlag( UInt uiAbsPartIdx )
    2339 {
    2340   return 0;
    2341 }
    2342 
    2343 #endif
    23442087
    23452088UInt TComDataCU::getCtxInterDir( UInt uiAbsPartIdx )
     
    23482091}
    23492092
    2350 Void TComDataCU::setCbfSubParts( UInt uiCbfY, UInt uiCbfU, UInt uiCbfV, UInt uiAbsPartIdx, UInt uiDepth )
    2351 {
    2352   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2353   memset( m_puhCbf[0] + uiAbsPartIdx, uiCbfY, sizeof( UChar ) * uiCurrPartNumb );
    2354   memset( m_puhCbf[1] + uiAbsPartIdx, uiCbfU, sizeof( UChar ) * uiCurrPartNumb );
    2355   memset( m_puhCbf[2] + uiAbsPartIdx, uiCbfV, sizeof( UChar ) * uiCurrPartNumb );
    2356 }
    2357 
    2358 Void TComDataCU::setCbfSubParts( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiDepth )
    2359 {
    2360 
    2361   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2362   memset( m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]] + uiAbsPartIdx, uiCbf, sizeof( UChar ) * uiCurrPartNumb );
     2093
     2094UChar TComDataCU::getQtRootCbf( UInt uiIdx )
     2095{
     2096  const UInt numberValidComponents = getPic()->getNumberValidComponents();
     2097  return getCbf( uiIdx, COMPONENT_Y, 0 )
     2098          || ((numberValidComponents > COMPONENT_Cb) && getCbf( uiIdx, COMPONENT_Cb, 0 ))
     2099          || ((numberValidComponents > COMPONENT_Cr) && getCbf( uiIdx, COMPONENT_Cr, 0 ));
     2100}
     2101
     2102Void TComDataCU::setCbfSubParts( const UInt uiCbf[MAX_NUM_COMPONENT], UInt uiAbsPartIdx, UInt uiDepth )
     2103{
     2104  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     2105  for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     2106  {
     2107    memset( m_puhCbf[comp] + uiAbsPartIdx, uiCbf[comp], sizeof( UChar ) * uiCurrPartNumb );
     2108  }
     2109}
     2110
     2111Void TComDataCU::setCbfSubParts( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiDepth )
     2112{
     2113  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     2114  memset( m_puhCbf[compID] + uiAbsPartIdx, uiCbf, sizeof( UChar ) * uiCurrPartNumb );
    23632115}
    23642116
    23652117/** Sets a coded block flag for all sub-partitions of a partition
    2366  * \param uiCbf The value of the coded block flag to be set
    2367  * \param eTType
     2118 * \param uiCbf          The value of the coded block flag to be set
     2119 * \param compID
    23682120 * \param uiAbsPartIdx
    23692121 * \param uiPartIdx
    23702122 * \param uiDepth
    2371  * \returns Void
    23722123 */
    2373 Void TComDataCU::setCbfSubParts ( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
    2374 {
    2375   setSubPart<UChar>( uiCbf, m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]], uiAbsPartIdx, uiDepth, uiPartIdx );
     2124Void TComDataCU::setCbfSubParts ( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
     2125{
     2126  setSubPart<UChar>( uiCbf, m_puhCbf[compID], uiAbsPartIdx, uiDepth, uiPartIdx );
     2127}
     2128
     2129Void TComDataCU::setCbfPartRange ( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
     2130{
     2131  memset((m_puhCbf[compID] + uiAbsPartIdx), uiCbf, (sizeof(UChar) * uiCoveredPartIdxes));
     2132}
     2133
     2134Void TComDataCU::bitwiseOrCbfPartRange( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
     2135{
     2136  const UInt stopAbsPartIdx = uiAbsPartIdx + uiCoveredPartIdxes;
     2137
     2138  for (UInt subPartIdx = uiAbsPartIdx; subPartIdx < stopAbsPartIdx; subPartIdx++)
     2139  {
     2140    m_puhCbf[compID][subPartIdx] |= uiCbf;
     2141  }
    23762142}
    23772143
    23782144Void TComDataCU::setDepthSubParts( UInt uiDepth, UInt uiAbsPartIdx )
    23792145{
    2380   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
     2146  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
    23812147  memset( m_puhDepth + uiAbsPartIdx, uiDepth, sizeof(UChar)*uiCurrPartNumb );
    23822148}
     
    23842150Bool TComDataCU::isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth)
    23852151{
    2386   UInt uiPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2387   return (((m_uiAbsIdxInLCU + uiAbsPartIdx)% uiPartNumb) == 0);
     2152  UInt uiPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     2153  return (((m_absZIdxInCtu + uiAbsPartIdx)% uiPartNumb) == 0);
    23882154}
    23892155
     
    23912157{
    23922158  assert( sizeof( *m_pePartSize) == 1 );
    2393   memset( m_pePartSize + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
     2159  memset( m_pePartSize + uiAbsPartIdx, eMode, m_pcPic->getNumPartitionsInCtu() >> ( 2 * uiDepth ) );
    23942160}
    23952161
    23962162Void TComDataCU::setCUTransquantBypassSubParts( Bool flag, UInt uiAbsPartIdx, UInt uiDepth )
    23972163{
    2398   memset( m_CUTransquantBypass + uiAbsPartIdx, flag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
     2164  memset( m_CUTransquantBypass + uiAbsPartIdx, flag, m_pcPic->getNumPartitionsInCtu() >> ( 2 * uiDepth ) );
    23992165}
    24002166
     
    24022168{
    24032169  assert( sizeof( *m_skipFlag) == 1 );
    2404   memset( m_skipFlag + absPartIdx, skip, m_pcPic->getNumPartInCU() >> ( 2 * depth ) );
    2405 }
    2406 #if H_3D
    2407 Void TComDataCU::setDISFlagSubParts( Bool bDIS, UInt absPartIdx, UInt depth )
     2170  memset( m_skipFlag + absPartIdx, skip, m_pcPic->getNumPartitionsInCtu() >> ( 2 * depth ) );
     2171}
     2172
     2173#if NH_3D_DIS
     2174Void TComDataCU::setDISFlagSubParts( Bool bDIS, UInt uiAbsPartIdx, UInt uiDepth )
    24082175{
    24092176    assert( sizeof( *m_bDISFlag) == 1 );
    2410     memset( m_bDISFlag + absPartIdx, bDIS, m_pcPic->getNumPartInCU() >> ( 2 * depth ) );
    2411 }
    2412 
    2413 Void TComDataCU::setDISTypeSubParts(UInt uiDISType, UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth )
    2414 {
    2415     setSubPartT( uiDISType, m_uiDISType, uiAbsPartIdx, uiDepth, uiPUIdx );
     2177    memset( m_bDISFlag + uiAbsPartIdx, bDIS, m_pcPic->getNumPartitionsInCtu() >> ( 2 * uiDepth ) );
     2178}
     2179
     2180Void TComDataCU::setDISTypeSubParts(UChar ucDISType, UInt uiAbsPartIdx, UInt uiDepth )
     2181{
     2182  assert( sizeof( *m_ucDISType) == 1 );
     2183  memset( m_ucDISType + uiAbsPartIdx, ucDISType, m_pcPic->getNumPartitionsInCtu() >> ( 2 * uiDepth ) );
    24162184}
    24172185#endif
     
    24202188{
    24212189  assert( sizeof( *m_pePredMode) == 1 );
    2422   memset( m_pePredMode + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
    2423 }
    2424 
    2425 Void TComDataCU::setQPSubCUs( Int qp, TComDataCU* pcCU, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf )
    2426 {
    2427   UInt currPartNumb = m_pcPic->getNumPartInCU() >> (depth << 1);
     2190  memset( m_pePredMode + uiAbsPartIdx, eMode, m_pcPic->getNumPartitionsInCtu() >> ( 2 * uiDepth ) );
     2191}
     2192
     2193Void TComDataCU::setChromaQpAdjSubParts( UChar val, Int absPartIdx, Int depth )
     2194{
     2195  assert( sizeof(*m_ChromaQpAdj) == 1 );
     2196  memset( m_ChromaQpAdj + absPartIdx, val, m_pcPic->getNumPartitionsInCtu() >> ( 2 * depth ) );
     2197}
     2198
     2199Void TComDataCU::setQPSubCUs( Int qp, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf )
     2200{
     2201  UInt currPartNumb = m_pcPic->getNumPartitionsInCtu() >> (depth << 1);
    24282202  UInt currPartNumQ = currPartNumb >> 2;
     2203  const UInt numValidComp = m_pcPic->getNumberValidComponents();
    24292204
    24302205  if(!foundNonZeroCbf)
    24312206  {
    2432     if(pcCU->getDepth(absPartIdx) > depth)
     2207    if(getDepth(absPartIdx) > depth)
    24332208    {
    24342209      for ( UInt partUnitIdx = 0; partUnitIdx < 4; partUnitIdx++ )
    24352210      {
    2436         pcCU->setQPSubCUs( qp, pcCU, absPartIdx+partUnitIdx*currPartNumQ, depth+1, foundNonZeroCbf );
     2211        setQPSubCUs( qp, absPartIdx+partUnitIdx*currPartNumQ, depth+1, foundNonZeroCbf );
    24372212      }
    24382213    }
    24392214    else
    24402215    {
    2441       if(pcCU->getCbf( absPartIdx, TEXT_LUMA ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_U ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_V ) )
     2216      if(getCbf( absPartIdx, COMPONENT_Y ) || (numValidComp>COMPONENT_Cb && getCbf( absPartIdx, COMPONENT_Cb )) || (numValidComp>COMPONENT_Cr && getCbf( absPartIdx, COMPONENT_Cr) ) )
    24422217      {
    24432218        foundNonZeroCbf = true;
     
    24532228Void TComDataCU::setQPSubParts( Int qp, UInt uiAbsPartIdx, UInt uiDepth )
    24542229{
    2455   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2456   TComSlice * pcSlice = getPic()->getSlice(getPic()->getCurrSliceIdx());
    2457 
    2458   for(UInt uiSCUIdx = uiAbsPartIdx; uiSCUIdx < uiAbsPartIdx+uiCurrPartNumb; uiSCUIdx++)
    2459   {
    2460     if( m_pcPic->getCU( getAddr() )->getSliceSegmentStartCU(uiSCUIdx+getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr() )
    2461     {
    2462       m_phQP[uiSCUIdx] = qp;
    2463     }
    2464   }
    2465 }
    2466 
    2467 Void TComDataCU::setLumaIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
    2468 {
    2469   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2470  
    2471   memset( m_puhLumaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
     2230  const UInt numPart = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     2231  memset(m_phQP+uiAbsPartIdx, qp, numPart);
     2232}
     2233
     2234Void TComDataCU::setIntraDirSubParts( const ChannelType channelType, const UInt dir, const UInt absPartIdx, const UInt depth )
     2235{
     2236  UInt numPart = m_pcPic->getNumPartitionsInCtu() >> (depth << 1);
     2237  memset( m_puhIntraDir[channelType] + absPartIdx, dir,sizeof(UChar)*numPart );
    24722238}
    24732239
    24742240template<typename T>
    2475 Void TComDataCU::setSubPart( T uiParameter, T* puhBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
     2241Void TComDataCU::setSubPart( T uiParameter, T* puhBaseCtu, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
    24762242{
    24772243  assert( sizeof(T) == 1 ); // Using memset() works only for types of size 1
    2478  
    2479   UInt uiCurrPartNumQ = (m_pcPic->getNumPartInCU() >> (2 * uiCUDepth)) >> 2;
     2244
     2245  UInt uiCurrPartNumQ = (m_pcPic->getNumPartitionsInCtu() >> (2 * uiCUDepth)) >> 2;
    24802246  switch ( m_pePartSize[ uiCUAddr ] )
    24812247  {
    24822248    case SIZE_2Nx2N:
    2483       memset( puhBaseLCU + uiCUAddr, uiParameter, 4 * uiCurrPartNumQ );
     2249      memset( puhBaseCtu + uiCUAddr, uiParameter, 4 * uiCurrPartNumQ );
    24842250      break;
    24852251    case SIZE_2NxN:
    2486       memset( puhBaseLCU + uiCUAddr, uiParameter, 2 * uiCurrPartNumQ );
     2252      memset( puhBaseCtu + uiCUAddr, uiParameter, 2 * uiCurrPartNumQ );
    24872253      break;
    24882254    case SIZE_Nx2N:
    2489       memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ );
    2490       memset( puhBaseLCU + uiCUAddr + 2 * uiCurrPartNumQ, uiParameter, uiCurrPartNumQ );
     2255      memset( puhBaseCtu + uiCUAddr, uiParameter, uiCurrPartNumQ );
     2256      memset( puhBaseCtu + uiCUAddr + 2 * uiCurrPartNumQ, uiParameter, uiCurrPartNumQ );
    24912257      break;
    24922258    case SIZE_NxN:
    2493       memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ );
     2259      memset( puhBaseCtu + uiCUAddr, uiParameter, uiCurrPartNumQ );
    24942260      break;
    24952261    case SIZE_2NxnU:
    24962262      if ( uiPUIdx == 0 )
    24972263      {
    2498         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
    2499         memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
     2264        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );
     2265        memset( puhBaseCtu + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );
    25002266      }
    25012267      else if ( uiPUIdx == 1 )
    25022268      {
    2503         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
    2504         memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, ((uiCurrPartNumQ >> 1) + (uiCurrPartNumQ << 1)) );                     
     2269        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );
     2270        memset( puhBaseCtu + uiCUAddr + uiCurrPartNumQ, uiParameter, ((uiCurrPartNumQ >> 1) + (uiCurrPartNumQ << 1)) );
    25052271      }
    25062272      else
     
    25122278      if ( uiPUIdx == 0 )
    25132279      {
    2514         memset( puhBaseLCU + uiCUAddr, uiParameter, ((uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1)) );                     
    2515         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
     2280        memset( puhBaseCtu + uiCUAddr, uiParameter, ((uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1)) );
     2281        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );
    25162282      }
    25172283      else if ( uiPUIdx == 1 )
    25182284      {
    2519         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
    2520         memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
     2285        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );
     2286        memset( puhBaseCtu + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );
    25212287      }
    25222288      else
     
    25282294      if ( uiPUIdx == 0 )
    25292295      {
    2530         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
    2531         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
    2532         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );
    2533         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
     2296        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
     2297        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
     2298        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );
     2299        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
    25342300      }
    25352301      else if ( uiPUIdx == 1 )
    25362302      {
    2537         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
    2538         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
    2539         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );
    2540         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
     2303        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
     2304        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
     2305        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );
     2306        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
    25412307      }
    25422308      else
     
    25472313    case SIZE_nRx2N:
    25482314      if ( uiPUIdx == 0 )
    2549       {     
    2550         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
    2551         memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
    2552         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
    2553         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
     2315      {
     2316        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
     2317        memset( puhBaseCtu + uiCUAddr + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
     2318        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
     2319        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
    25542320      }
    25552321      else if ( uiPUIdx == 1 )
    25562322      {
    2557         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );                           
    2558         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
    2559         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
    2560         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                         
     2323        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
     2324        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
     2325        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );
     2326        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
    25612327      }
    25622328      else
     
    25672333    default:
    25682334      assert( 0 );
    2569   }
    2570 }
    2571 
    2572 #if H_3D_DIM_SDC
    2573 Void TComDataCU::setSDCFlagSubParts ( Bool bSDCFlag, UInt uiAbsPartIdx, UInt uiDepth )
     2335      break;
     2336  }
     2337}
     2338
     2339#if NH_3D_SDC_INTRA
     2340Void TComDataCU::setSDCFlagSubParts ( Bool bSDCFlag, UInt absPartIdx, UInt depth )
    25742341{
    25752342  assert( sizeof( *m_pbSDCFlag) == 1 );
    2576   memset( m_pbSDCFlag + uiAbsPartIdx, bSDCFlag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
     2343  memset( m_pbSDCFlag + absPartIdx, bSDCFlag, m_pcPic->getNumPartitionsInCtu() >> ( 2 * depth ) );
    25772344}
    25782345
    25792346Bool TComDataCU::getSDCAvailable( UInt uiAbsPartIdx )
    25802347{
    2581   // check general CU information
    2582   if( !getSlice()->getIsDepth() || !isIntra(uiAbsPartIdx) || getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
    2583   {
    2584     return false;
    2585   }
    2586 
    2587   if( isDimMode( getLumaIntraDir( uiAbsPartIdx ) ) )
    2588   {
    2589     return true;
    2590   }
    2591  
    2592   if( getLumaIntraDir( uiAbsPartIdx ) < NUM_INTRA_MODE )
    2593   {
    2594     return true;
    2595   }
    2596 
     2348  if( getSlice()->getIsDepth() && isIntra(uiAbsPartIdx) && getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N )
     2349  {
     2350    UInt lumaPredMode = getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx );
     2351    if( lumaPredMode < NUM_INTRA_MODE ) { return true; }
     2352#if NH_3D_DMM
     2353    if( isDmmMode( lumaPredMode )     ) { return true; }
     2354#endif
     2355  }
    25972356  return false;
    2598   // check prediction mode
    2599   UInt uiLumaPredMode = getLumaIntraDir( uiAbsPartIdx ); 
    2600   if( uiLumaPredMode == PLANAR_IDX || ( getDimType( uiLumaPredMode ) == DMM1_IDX  ) )
    2601     return true;
    2602  
    2603   // else
    2604   return false;
    2605 }
    2606 #endif
     2357}
     2358#endif
     2359
    26072360Void TComDataCU::setMergeFlagSubParts ( Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
    26082361{
     
    26152368}
    26162369
    2617 #if H_3D_SPIVMP
     2370#if NH_3D_SPIVMP
    26182371Void TComDataCU::setSPIVMPFlagSubParts( Bool bSPIVMPFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
    26192372{
     
    26222375#endif
    26232376
    2624 #if H_3D_VSP
     2377#if NH_3D_VSP
    26252378Void TComDataCU::setVSPFlagSubParts( Char iVSPFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
    26262379{
    26272380  setSubPart<Char>( iVSPFlag, m_piVSPFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
    26282381}
    2629 #if H_3D_VSP
    26302382template<typename T>
    26312383Void TComDataCU::setSubPartT( T uiParameter, T* puhBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
    26322384{
    2633   UInt uiCurrPartNumQ = (m_pcPic->getNumPartInCU() >> (2 * uiCUDepth)) >> 2;
     2385  UInt uiCurrPartNumQ = (m_pcPic->getNumPartitionsInCtu() >> (2 * uiCUDepth)) >> 2;
    26342386  switch ( m_pePartSize[ uiCUAddr ] )
    26352387  {
     
    27632515}
    27642516#endif
    2765 #endif
    2766 Void TComDataCU::setChromIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
    2767 {
    2768   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2769  
    2770   memset( m_puhChromaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
    2771 }
    27722517
    27732518Void TComDataCU::setInterDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
     
    27892534Void TComDataCU::setTrIdxSubParts( UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth )
    27902535{
    2791   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2792  
     2536  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     2537
    27932538  memset( m_puhTrIdx + uiAbsPartIdx, uiTrIdx, sizeof(UChar)*uiCurrPartNumb );
    27942539}
    27952540
    2796 Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkipY, UInt useTransformSkipU, UInt useTransformSkipV, UInt uiAbsPartIdx, UInt uiDepth )
    2797 {
    2798   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2799 
    2800   memset( m_puhTransformSkip[0] + uiAbsPartIdx, useTransformSkipY, sizeof( UChar ) * uiCurrPartNumb );
    2801   memset( m_puhTransformSkip[1] + uiAbsPartIdx, useTransformSkipU, sizeof( UChar ) * uiCurrPartNumb );
    2802   memset( m_puhTransformSkip[2] + uiAbsPartIdx, useTransformSkipV, sizeof( UChar ) * uiCurrPartNumb );
    2803 }
    2804 
    2805 Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkip, TextType eType, UInt uiAbsPartIdx, UInt uiDepth)
    2806 {
    2807   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2808 
    2809   memset( m_puhTransformSkip[g_aucConvertTxtTypeToIdx[eType]] + uiAbsPartIdx, useTransformSkip, sizeof( UChar ) * uiCurrPartNumb );
     2541Void TComDataCU::setTransformSkipSubParts( const UInt useTransformSkip[MAX_NUM_COMPONENT], UInt uiAbsPartIdx, UInt uiDepth )
     2542{
     2543  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     2544
     2545  for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
     2546  {
     2547    memset( m_puhTransformSkip[i] + uiAbsPartIdx, useTransformSkip[i], sizeof( UChar ) * uiCurrPartNumb );
     2548  }
     2549}
     2550
     2551Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkip, ComponentID compID, UInt uiAbsPartIdx, UInt uiDepth)
     2552{
     2553  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     2554
     2555  memset( m_puhTransformSkip[compID] + uiAbsPartIdx, useTransformSkip, sizeof( UChar ) * uiCurrPartNumb );
     2556}
     2557
     2558Void TComDataCU::setTransformSkipPartRange ( UInt useTransformSkip, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
     2559{
     2560  memset((m_puhTransformSkip[compID] + uiAbsPartIdx), useTransformSkip, (sizeof(UChar) * uiCoveredPartIdxes));
     2561}
     2562
     2563Void TComDataCU::setCrossComponentPredictionAlphaPartRange( Char alphaValue, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
     2564{
     2565  memset((m_crossComponentPredictionAlpha[compID] + uiAbsPartIdx), alphaValue, (sizeof(Char) * uiCoveredPartIdxes));
     2566}
     2567
     2568Void TComDataCU::setExplicitRdpcmModePartRange ( UInt rdpcmMode, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
     2569{
     2570  memset((m_explicitRdpcmMode[compID] + uiAbsPartIdx), rdpcmMode, (sizeof(UChar) * uiCoveredPartIdxes));
    28102571}
    28112572
    28122573Void TComDataCU::setSizeSubParts( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, UInt uiDepth )
    28132574{
    2814   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2815  
     2575  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     2576
    28162577  memset( m_puhWidth  + uiAbsPartIdx, uiWidth,  sizeof(UChar)*uiCurrPartNumb );
    28172578  memset( m_puhHeight + uiAbsPartIdx, uiHeight, sizeof(UChar)*uiCurrPartNumb );
    28182579}
    28192580
    2820 UChar TComDataCU::getNumPartitions()
     2581UChar TComDataCU::getNumPartitions(const UInt uiAbsPartIdx)
    28212582{
    28222583  UChar iNumPart = 0;
    2823  
    2824   switch ( m_pePartSize[0] )
     2584
     2585  switch ( m_pePartSize[uiAbsPartIdx] )
    28252586  {
    28262587    case SIZE_2Nx2N:    iNumPart = 1; break;
     
    28342595    default:            assert (0);   break;
    28352596  }
    2836  
     2597
    28372598  return  iNumPart;
    28382599}
    28392600
    2840 #if H_3D_IC
     2601// This is for use by a leaf/sub CU object only, with no additional AbsPartIdx
     2602#if NH_3D_IC || NH_3D_VSP
    28412603Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight, UInt uiAbsPartIdx, Bool bLCU)
    28422604{
     
    28822644}
    28832645#else
     2646
    28842647Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight )
    28852648{
     
    29322695    return;
    29332696  }
    2934  
     2697
    29352698  TComCUMvField*  pcCUMvField = pcCU->getCUMvField( eRefPicList );
    29362699  rcMvField.setMvField( pcCUMvField->getMv( uiAbsPartIdx ), pcCUMvField->getRefIdx( uiAbsPartIdx ) );
     
    29392702Void TComDataCU::deriveLeftRightTopIdxGeneral ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
    29402703{
    2941   ruiPartIdxLT = m_uiAbsIdxInLCU + uiAbsPartIdx;
     2704  ruiPartIdxLT = m_absZIdxInCtu + uiAbsPartIdx;
    29422705  UInt uiPUWidth = 0;
    2943  
     2706
    29442707  switch ( m_pePartSize[uiAbsPartIdx] )
    29452708  {
     
    29502713    case SIZE_2NxnU:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
    29512714    case SIZE_2NxnD:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
    2952     case SIZE_nLx2N:   
     2715    case SIZE_nLx2N:
    29532716      if ( uiPartIdx == 0 )
    29542717      {
    2955         uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
     2718        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2;
    29562719      }
    29572720      else if ( uiPartIdx == 1 )
    29582721      {
    2959         uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
     2722        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2);
    29602723      }
    29612724      else
     
    29642727      }
    29652728      break;
    2966     case SIZE_nRx2N:   
     2729    case SIZE_nRx2N:
    29672730      if ( uiPartIdx == 0 )
    29682731      {
    2969         uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
     2732        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2);
    29702733      }
    29712734      else if ( uiPartIdx == 1 )
    29722735      {
    2973         uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
     2736        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2;
    29742737      }
    29752738      else
     
    29822745      break;
    29832746  }
    2984  
     2747
    29852748  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + uiPUWidth / m_pcPic->getMinCUWidth() - 1 ];
    29862749}
     
    29952758    case SIZE_Nx2N:  uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
    29962759    case SIZE_NxN:   uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
    2997     case SIZE_2NxnU: 
     2760    case SIZE_2NxnU:
    29982761      if ( uiPartIdx == 0 )
    29992762      {
    3000         uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
     2763        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;
    30012764      }
    30022765      else if ( uiPartIdx == 1 )
    30032766      {
    3004         uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
     2767        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);
    30052768      }
    30062769      else
     
    30092772      }
    30102773      break;
    3011     case SIZE_2NxnD: 
     2774    case SIZE_2NxnD:
    30122775      if ( uiPartIdx == 0 )
    30132776      {
    3014         uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
     2777        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);
    30152778      }
    30162779      else if ( uiPartIdx == 1 )
    30172780      {
    3018         uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
     2781        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;
    30192782      }
    30202783      else
     
    30292792      break;
    30302793  }
    3031  
    3032   ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU + uiAbsPartIdx ] + ((uiPUHeight / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth()];
     2794
     2795  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_absZIdxInCtu + uiAbsPartIdx ] + ((uiPUHeight / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInCtuWidth()];
    30332796}
    30342797
    30352798Void TComDataCU::deriveLeftRightTopIdx ( UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
    30362799{
    3037   ruiPartIdxLT = m_uiAbsIdxInLCU;
     2800  ruiPartIdxLT = m_absZIdxInCtu;
    30382801  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1 ];
    3039  
     2802
    30402803  switch ( m_pePartSize[0] )
    30412804  {
     
    30702833      break;
    30712834  }
    3072  
     2835
    30732836}
    30742837
    30752838Void TComDataCU::deriveLeftBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxLB )
    30762839{
    3077   ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ( ((m_puhHeight[0] / m_pcPic->getMinCUHeight())>>1) - 1)*m_pcPic->getNumPartInWidth()];
    3078  
     2840  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_absZIdxInCtu ] + ( ((m_puhHeight[0] / m_pcPic->getMinCUHeight())>>1) - 1)*m_pcPic->getNumPartInCtuWidth()];
     2841
    30792842  switch ( m_pePartSize[0] )
    30802843  {
     
    31092872}
    31102873
    3111 /** Derives the partition index of neighbouring bottom right block
    3112  * \param [in]  eCUMode
    3113  * \param [in]  uiPartIdx
    3114  * \param [out] ruiPartIdxRB
     2874/** Derive the partition index of neighbouring bottom right block
     2875 * \param [in]  uiPartIdx     current partition index
     2876 * \param [out] ruiPartIdxRB  partition index of neighbouring bottom right block
    31152877 */
    3116 Void TComDataCU::deriveRightBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxRB )
    3117 {
    3118   ruiPartIdxRB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ( ((m_puhHeight[0] / m_pcPic->getMinCUHeight())>>1) - 1)*m_pcPic->getNumPartInWidth() +  m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1];
     2878Void TComDataCU::deriveRightBottomIdx( UInt uiPartIdx, UInt &ruiPartIdxRB )
     2879{
     2880  ruiPartIdxRB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_absZIdxInCtu ] + ( ((m_puhHeight[0] / m_pcPic->getMinCUHeight())>>1) - 1)*m_pcPic->getNumPartInCtuWidth() +  m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1];
    31192881
    31202882  switch ( m_pePartSize[0] )
    31212883  {
    3122     case SIZE_2Nx2N: 
    3123       ruiPartIdxRB += m_uiNumPartition >> 1;   
    3124       break;
    3125     case SIZE_2NxN: 
    3126       ruiPartIdxRB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;   
    3127       break;
    3128     case SIZE_Nx2N: 
    3129       ruiPartIdxRB += ( uiPartIdx == 0 )? m_uiNumPartition >> 2 : (m_uiNumPartition >> 1);   
    3130       break;
    3131     case SIZE_NxN:   
    3132       ruiPartIdxRB += ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );   
     2884    case SIZE_2Nx2N:
     2885      ruiPartIdxRB += m_uiNumPartition >> 1;
     2886      break;
     2887    case SIZE_2NxN:
     2888      ruiPartIdxRB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
     2889      break;
     2890    case SIZE_Nx2N:
     2891      ruiPartIdxRB += ( uiPartIdx == 0 )? m_uiNumPartition >> 2 : (m_uiNumPartition >> 1);
     2892      break;
     2893    case SIZE_NxN:
     2894      ruiPartIdxRB += ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );
    31332895      break;
    31342896    case SIZE_2NxnU:
     
    31502912}
    31512913
    3152 Void TComDataCU::deriveLeftRightTopIdxAdi ( UInt& ruiPartIdxLT, UInt& ruiPartIdxRT, UInt uiPartOffset, UInt uiPartDepth )
    3153 {
    3154   UInt uiNumPartInWidth = (m_puhWidth[0]/m_pcPic->getMinCUWidth())>>uiPartDepth;
    3155   ruiPartIdxLT = m_uiAbsIdxInLCU + uiPartOffset;
    3156   ruiPartIdxRT = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxLT ] + uiNumPartInWidth - 1 ];
    3157 }
    3158 
    3159 Void TComDataCU::deriveLeftBottomIdxAdi( UInt& ruiPartIdxLB, UInt uiPartOffset, UInt uiPartDepth )
    3160 {
    3161   UInt uiAbsIdx;
    3162   UInt uiMinCuWidth, uiWidthInMinCus;
    3163  
    3164   uiMinCuWidth    = getPic()->getMinCUWidth();
    3165   uiWidthInMinCus = (getWidth(0)/uiMinCuWidth)>>uiPartDepth;
    3166   uiAbsIdx        = getZorderIdxInCU()+uiPartOffset+(m_uiNumPartition>>(uiPartDepth<<1))-1;
    3167   uiAbsIdx        = g_auiZscanToRaster[uiAbsIdx]-(uiWidthInMinCus-1);
    3168   ruiPartIdxLB    = g_auiRasterToZscan[uiAbsIdx];
    3169 }
    3170 
    31712914Bool TComDataCU::hasEqualMotion( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx )
    31722915{
    3173 
    31742916  if ( getInterDir( uiAbsPartIdx ) != pcCandCU->getInterDir( uiCandAbsPartIdx ) )
    31752917  {
     
    31812923    if ( getInterDir( uiAbsPartIdx ) & ( 1 << uiRefListIdx ) )
    31822924    {
    3183       if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx )     != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiCandAbsPartIdx ) || 
     2925      if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx )     != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiCandAbsPartIdx ) ||
    31842926        getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiAbsPartIdx ) != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiCandAbsPartIdx ) )
    31852927      {
     
    31922934}
    31932935
    3194 #if H_3D_VSP
    3195 
     2936#if NH_3D_FIX_PRUNING
     2937Bool TComDataCU::hasEqualMotion( Int dirA, const TComMvField* mvFieldA, Int dirB, const TComMvField* mvFieldB )
     2938{
     2939  return  ( dirA == dirB  &&
     2940    ( ( dirA & 1 ) == 0 || mvFieldA[0] == mvFieldB[0]  ) &&
     2941    ( ( dirA & 2 ) == 0 || mvFieldA[1] == mvFieldB[1]  )
     2942    );
     2943}
     2944#endif
     2945
     2946#if NH_3D_VSP
    31962947/** Add a VSP merging candidate
    31972948 * \Inputs
     
    32472998        predFlag[iRefListIdX] = 1;
    32482999        mvVSP[0+iRefListIdX].setMvField( pDInfo->m_acNBDV, i );
    3249 #if H_3D_NBDV
     3000#if NH_3D_NBDV
    32503001        mvVSP[0+iRefListIdX].getMv().setIDVFlag (false);
    32513002#endif
     
    32553006
    32563007  dirVSP = (predFlag[0] | (predFlag[1] << 1));
    3257   m_mergCands[MRG_VSP].setCand( mvVSP, dirVSP, true, false);
     3008  m_mergCands[MRG_VSP].setCand( mvVSP, dirVSP, true
     3009#if NH_3D_SPIVMP
     3010    , false
     3011#endif
     3012    );
    32583013  if ( mrgCandIdx == iCount )
    32593014  {
     
    32653020  return false;
    32663021}
    3267 
    3268 #endif
    3269 
    3270 #if H_3D_IV_MERGE
     3022#endif
     3023
     3024#if NH_3D_IV_MERGE
    32713025inline Bool TComDataCU::xAddIvMRGCand( Int mrgCandIdx, Int& iCount, Int* ivCandDir, TComMv* ivCandMv, Int* ivCandRefIdx )
    32723026{
     
    32923046      if( !iLoop && ivCandDir[0] > 0)
    32933047      {
     3048#if NH_3D_FIX_PRUNING
     3049        if( hasEqualMotion(tmpDir, tmpMV, m_mergCands[MRG_IVMC].m_uDir, m_mergCands[MRG_IVMC].m_cMvField ))
     3050#else
    32943051        if(tmpDir == m_mergCands[MRG_IVMC].m_uDir && m_mergCands[MRG_IVMC].m_cMvField[0]==tmpMV[0] && m_mergCands[MRG_IVMC].m_cMvField[1]==tmpMV[1])
     3052#endif
    32953053        {
    32963054            bRemove                         = true;
     
    32993057      if(!bRemove)
    33003058      {
    3301 #if H_3D_NBDV
     3059#if NH_3D_NBDV
    33023060        if(iLoop) // For IvMcShift candidate
    33033061        {
     
    33203078
    33213079#endif
    3322 
    3323 #if H_3D
     3080#if NH_3D_MLC
     3081/** Construct a extended list of merging candidates
     3082 * \param pcMvFieldNeighbours
     3083 * \param puhInterDirNeighbours
     3084 * \param vspFlag
     3085 * \param pbSPIVMPFlag
     3086 * \param numValidMergeCand
     3087 */
    33243088Void TComDataCU::buildMCL(TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
    3325 #if H_3D_VSP
     3089#if NH_3D_VSP
    33263090  , Int* vspFlag
    33273091#endif
    3328 #if H_3D_SPIVMP
     3092#if NH_3D_SPIVMP
    33293093  , Bool* pbSPIVMPFlag
    33303094#endif
     
    33323096  )
    33333097{
    3334   if (!( getSlice()->getIsDepth() || getSlice()->getViewIndex()>0))  // for only dependent texture
     3098  if (!( getSlice()->getIsDepth() || getSlice()->getViewIndex()>0))
    33353099  {
    33363100    return;
     
    33483112    extMergeCandList[ui<<1].setMvField(cZeroMv, NOT_VALID);
    33493113    extMergeCandList[(ui<<1)+1].setMvField(cZeroMv, NOT_VALID);
     3114#if NH_3D_VSP
    33503115    vspFlag[ui] = 0;
    3351   }
    3352 
    3353   // add candidates to temporal list
    3354   // insert MPI ... IvShift candidate
     3116#endif
     3117  }
     3118
     3119  // insert MPI ... IvShift candidate to extMergeCandList
    33553120  for (Int i=0; i<=MRG_IVSHIFT; i++)
    33563121  {
    33573122    if (m_mergCands[i].m_bAvailable)
    33583123    {
    3359       m_mergCands[i].getCand(iCount, extMergeCandList, uhInterDirNeighboursExt, vspFlag, pbSPIVMPFlag);
     3124      m_mergCands[i].getCand(iCount, extMergeCandList, uhInterDirNeighboursExt
     3125#if NH_3D_VSP
     3126        , vspFlag
     3127#endif
     3128#if NH_3D_SPIVMP
     3129        , pbSPIVMPFlag
     3130#endif
     3131        );
    33603132      iCount++;
    33613133      if (iCount >= getSlice()->getMaxNumMergeCand())
     
    33643136  }
    33653137
    3366   // insert remaining base candidates
    3367   while (iCount < getSlice()->getMaxNumMergeCand() && m_baseListidc < getSlice()->getMaxNumMergeCand())
    3368   {
    3369     uhInterDirNeighboursExt[iCount] = puhInterDirNeighbours[m_baseListidc];
    3370     extMergeCandList[iCount<<1].setMvField(pcMvFieldNeighbours[m_baseListidc<<1].getMv(), pcMvFieldNeighbours[m_baseListidc<<1].getRefIdx());
     3138  Int iCountBase = m_numSpatialCands;
     3139  // insert remaining base candidates to extMergeCandList
     3140  while (iCount < getSlice()->getMaxNumMergeCand() && iCountBase < getSlice()->getMaxNumMergeCand())
     3141  {
     3142    uhInterDirNeighboursExt[iCount] = puhInterDirNeighbours[iCountBase];
     3143    extMergeCandList[iCount<<1].setMvField(pcMvFieldNeighbours[iCountBase<<1].getMv(), pcMvFieldNeighbours[iCountBase<<1].getRefIdx());
    33713144    if ( getSlice()->isInterB() )
    33723145    {
    3373       extMergeCandList[(iCount<<1)+1].setMvField(pcMvFieldNeighbours[(m_baseListidc<<1)+1].getMv(), pcMvFieldNeighbours[(m_baseListidc<<1)+1].getRefIdx());
    3374     }
    3375     m_baseListidc++;
     3146      extMergeCandList[(iCount<<1)+1].setMvField(pcMvFieldNeighbours[(iCountBase<<1)+1].getMv(), pcMvFieldNeighbours[(iCountBase<<1)+1].getRefIdx());
     3147    }
     3148    iCountBase++;
    33763149    iCount++;
    33773150  }
     
    33953168}
    33963169
    3397 /** Constructs a list of merging candidates
     3170
     3171
     3172/** Derive 3D merge candidates
    33983173 * \param uiAbsPartIdx
    33993174 * \param uiPUIdx
    3400  * \param uiDepth
    34013175 * \param pcMvFieldNeighbours
     3176 * \param puhInterDirNeighbours
     3177 * \param pcMvFieldSP
    34023178 * \param puhInterDirNeighbours
    34033179 * \param numValidMergeCand
    34043180 */
    3405 // HM 12.0 based merge candidate list construction
    3406 
    3407 Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx )
    3408 {
    3409 
    3410   UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
    3411   Bool abCandIsInter[ MRG_MAX_NUM_CANDS_MEM ];
     3181Void TComDataCU::xGetInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMFieldNeighbours, UChar* puhInterDirNeighbours
     3182#if NH_3D_SPIVMP
     3183      , TComMvField* pcMvFieldSP, UChar* puhInterDirSP
     3184#endif
     3185      , Int& numValidMergeCand, Int mrgCandIdx
     3186)
     3187{
     3188#if NH_3D_IV_MERGE
    34123189  TComMv cZeroMv;
    3413   for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
    3414   {
    3415     abCandIsInter[ui] = false;
    3416     pcMvFieldNeighbours[ ( ui << 1 )     ].setMvField(cZeroMv, NOT_VALID);
    3417     pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setMvField(cZeroMv, NOT_VALID);
     3190  TComMvField tmpMV[2]; 
     3191#endif
     3192
     3193  //////////////////////////////////
     3194  //////// GET DISPARITIES  ////////
     3195  //////////////////////////////////
     3196#if NH_3D_IV_MERGE
     3197  DisInfo cDisInfo = getDvInfo(uiAbsPartIdx);
     3198  m_cDefaultDisInfo = cDisInfo;
     3199#elif NH_3D_VSP
     3200  // for xAddVspCand()
     3201  DisInfo cDisInfo = getDvInfo(uiAbsPartIdx);
     3202#endif
     3203
     3204  if (!( getSlice()->getIsDepth() || getSlice()->getViewIndex()>0))
     3205  {
     3206    return;
    34183207  }
    34193208  numValidMergeCand = getSlice()->getMaxNumMergeCand();
     3209  //////////////////////////////////
     3210  //////// DERIVE LOCATIONS ////////
     3211  //////////////////////////////////
    34203212  // compute the location of the current PU
    34213213  Int xP, yP, nPSW, nPSH;
     
    34233215
    34243216  Int iCount = 0;
    3425 
    34263217  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
    3427   PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
    34283218  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
    34293219  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
    3430 
    3431   //left
    3432   UInt uiLeftPartIdx = 0;
    3433   TComDataCU* pcCULeft = 0;
    3434   pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
    3435   Bool isAvailableA1 = pcCULeft &&
    3436     pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
    3437     !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
    3438     !pcCULeft->isIntra( uiLeftPartIdx ) ;
    3439   if ( isAvailableA1 )
    3440   {
    3441     m_bAvailableFlagA1 = 1;
    3442     abCandIsInter[iCount] = true;
    3443     // get Inter Dir
    3444     puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
    3445     // get Mv from Left
    3446     pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
    3447     if ( getSlice()->isInterB() )
    3448     {
    3449       pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    3450     }
    3451 
    3452     iCount ++;
    3453   }
    3454  
    3455   // early termination
    3456   if (iCount == getSlice()->getMaxNumMergeCand())
    3457   {
    3458     return;
    3459   }
    3460   // above
    3461   UInt uiAbovePartIdx = 0;
    3462   TComDataCU* pcCUAbove = 0;
    3463   pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
    3464   Bool isAvailableB1 = pcCUAbove &&
    3465   pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
    3466   !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
    3467   !pcCUAbove->isIntra( uiAbovePartIdx );
    3468   if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
    3469   {
    3470     m_bAvailableFlagB1 = 1;
    3471     abCandIsInter[iCount] = true;
    3472     // get Inter Dir
    3473     puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
    3474     // get Mv from Left
    3475     pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
    3476     if ( getSlice()->isInterB() )
    3477     {
    3478       pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    3479     }
    3480     if ( mrgCandIdx == iCount )
    3481     {
    3482       return;
    3483     }
    3484     iCount ++;
    3485   }
    3486   // early termination
    3487   if (iCount == getSlice()->getMaxNumMergeCand())
    3488   {
    3489     return;
    3490   }
    3491 
    3492   // above right
    3493   UInt uiAboveRightPartIdx = 0;
    3494   TComDataCU* pcCUAboveRight = 0;
    3495   pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
    3496   Bool isAvailableB0 = pcCUAboveRight &&
    3497   pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
    3498   !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
    3499   if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
    3500   {
    3501     m_bAvailableFlagB0 = 1;
    3502     abCandIsInter[iCount] = true;
    3503     // get Inter Dir
    3504     puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
    3505     // get Mv from Left
    3506     pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
    3507     if ( getSlice()->isInterB() )
    3508     {
    3509       pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    3510     }
    3511     if ( mrgCandIdx == iCount )
    3512     {
    3513       return;
    3514     }
    3515     iCount ++;
    3516   }
    3517   // early termination
    3518   if (iCount == getSlice()->getMaxNumMergeCand())
    3519   {
    3520     return;
    3521   }
    3522 
    3523   //left bottom
    3524   UInt uiLeftBottomPartIdx = 0;
    3525   TComDataCU* pcCULeftBottom = 0;
    3526   pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
    3527   Bool isAvailableA0 = pcCULeftBottom &&
    3528   pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
    3529   !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
    3530   if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
    3531   {
    3532     m_bAvailableFlagA0 = 1;
    3533     abCandIsInter[iCount] = true;
    3534     // get Inter Dir
    3535     puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
    3536     // get Mv from Left
    3537     pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
    3538     if ( getSlice()->isInterB() )
    3539     {
    3540       pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    3541     }
    3542     if ( mrgCandIdx == iCount )
    3543     {
    3544       return;
    3545     }
    3546     iCount ++;
    3547   }
    3548   // early termination
    3549   if (iCount == getSlice()->getMaxNumMergeCand())
    3550   {
    3551     return;
    3552   }
    3553   // above left
    3554   if( iCount < 4 )
    3555   {
    3556     UInt uiAboveLeftPartIdx = 0;
    3557     TComDataCU* pcCUAboveLeft = 0;
    3558     pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
    3559     Bool isAvailableB2 = pcCUAboveLeft &&
    3560     pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
    3561     !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
    3562     if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
    3563         && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
    3564     {
    3565       m_bAvailableFlagB2 = 1;
    3566       abCandIsInter[iCount] = true;
    3567       // get Inter Dir
    3568       puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
    3569       // get Mv from Left
    3570       pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
    3571       if ( getSlice()->isInterB() )
    3572       {
    3573         pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    3574       }
    3575       if ( mrgCandIdx == iCount )
    3576       {
    3577         return;
    3578       }
    3579       iCount ++;
    3580     }
    3581   }
    3582   // early termination
    3583   if (iCount == getSlice()->getMaxNumMergeCand())
    3584   {
    3585     return;
    3586   }
    3587   if ( getSlice()->getEnableTMVPFlag())
    3588   {
    3589     //>> MTK colocated-RightBottom
    3590     UInt uiPartIdxRB;
    3591 
    3592     deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
    3593 
    3594     UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
    3595     UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
    3596 
    3597     TComMv cColMv;
    3598     Int iRefIdx;
    3599     Int uiLCUIdx = -1;
    3600 
    3601     if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
    3602     {
    3603     }
    3604     else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
    3605     {
    3606     }
    3607     else
    3608     {
    3609       if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
    3610         ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
    3611       {
    3612         uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
    3613         uiLCUIdx = getAddr();
    3614       }
    3615       else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
    3616       {
    3617         uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
    3618       }
    3619       else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
    3620       {
    3621         uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
    3622         uiLCUIdx = getAddr() + 1;
    3623       }
    3624       else //is the right bottom corner of LCU                       
    3625       {
    3626         uiAbsPartAddr = 0;
    3627       }
    3628     }
    3629 
    3630     iRefIdx = 0;
    3631     Bool bExistMV = false;
    3632     UInt uiPartIdxCenter;
    3633     UInt uiCurLCUIdx = getAddr();
    3634     Int dir = 0;
    3635     UInt uiArrayAddr = iCount;
    3636     xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
    3637     bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
    3638     if( bExistMV == false )
    3639     {
    3640       bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
    3641     }
    3642     if( bExistMV )
    3643     {
    3644       dir |= 1;
    3645       pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
    3646     }
    3647 
    3648     if ( getSlice()->isInterB() )
    3649     {
    3650 #if H_3D_TMVP
    3651       iRefIdx = 0;
    3652 #endif
    3653       bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
    3654       if( bExistMV == false )
    3655       {
    3656         bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
    3657       }
    3658       if( bExistMV )
    3659       {
    3660         dir |= 2;
    3661         pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
    3662       }
    3663     }
    3664 
    3665     if (dir != 0)
    3666     {
    3667       puhInterDirNeighbours[uiArrayAddr] = dir;
    3668       abCandIsInter[uiArrayAddr] = true;
    3669 #if H_3D_NBDV
    3670       pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
    3671       pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
    3672 #endif
    3673       if ( mrgCandIdx == iCount )
    3674       {
    3675         return;
    3676       }
    3677       iCount++;
    3678     }
    3679   }
    3680   // early termination
    3681   if (iCount == getSlice()->getMaxNumMergeCand())
    3682   {
    3683     return;
    3684   }
    3685   UInt uiArrayAddr = iCount;
    3686   UInt uiCutoff = uiArrayAddr;
    3687  
    3688   if ( getSlice()->isInterB() && iCount<5)  // JCT3V-F0129 by Qualcomm
    3689   {
    3690     UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
    3691     UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
    3692 
    3693     for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
    3694     {
    3695       Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
    3696       if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
    3697       {
    3698         abCandIsInter[uiArrayAddr] = true;
    3699         puhInterDirNeighbours[uiArrayAddr] = 3;
    3700 
    3701         // get Mv from cand[i] and cand[j]
    3702         pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
    3703         pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
    3704 
    3705         Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
    3706         Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
    3707         if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
    3708         {
    3709           abCandIsInter[uiArrayAddr] = false;
    3710         }
    3711         else
    3712         {
    3713           uiArrayAddr++;
    3714         }
    3715       }
    3716     }
    3717   }
    3718   // early termination
    3719   if (uiArrayAddr == getSlice()->getMaxNumMergeCand())
    3720   {
    3721     return;
    3722   }
    3723  
    3724   Int iNumRefIdx = (getSlice()->isInterB()) ? min(m_pcSlice->getNumRefIdx(REF_PIC_LIST_0), m_pcSlice->getNumRefIdx(REF_PIC_LIST_1)) : m_pcSlice->getNumRefIdx(REF_PIC_LIST_0);
    3725   Int r = 0;
    3726   Int refcnt = 0;
    3727   while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
    3728   {
    3729     abCandIsInter[uiArrayAddr] = true;
    3730     puhInterDirNeighbours[uiArrayAddr] = 1;
    3731     pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
    3732 
    3733     if ( getSlice()->isInterB() )
    3734     {
    3735       puhInterDirNeighbours[uiArrayAddr] = 3;
    3736       pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
    3737     }
    3738     uiArrayAddr++;
    3739     if ( refcnt == iNumRefIdx - 1 )
    3740     {
    3741       r = 0;
    3742     }
    3743     else
    3744     {
    3745       ++r;
    3746       ++refcnt;
    3747     }
    3748   }
    3749  
    3750   numValidMergeCand = uiArrayAddr;
    3751 }
    3752 
    3753 
    3754 
    3755 /** Constructs a list of merging candidates
    3756  * \param uiAbsPartIdx
    3757  * \param uiPUIdx
    3758  * \param uiDepth
    3759  * \param pcMvFieldNeighbours
    3760  * \param puhInterDirNeighbours
    3761  * \param numValidMergeCand
    3762  */
    3763 #if H_3D
    3764 Void TComDataCU::xGetInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
    3765 #else
    3766 Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
    3767 #endif
    3768 #if H_3D_SPIVMP
    3769       , TComMvField* pcMvFieldSP, UChar* puhInterDirSP
    3770 #endif
    3771       , Int& numValidMergeCand, Int mrgCandIdx
    3772 )
    3773 {
    3774 #if H_3D_IV_MERGE
    3775   ////////////////////////////
    3776   //////// INIT LISTS ////////
    3777   ////////////////////////////
    3778   TComMv cZeroMv;
    3779 #else
    3780   Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
    3781 #endif
    3782 #if H_3D
    3783   TComMvField tmpMV[2];
    3784   UChar tmpDir;
    3785 
    3786 
    3787   //////////////////////////////////
    3788   //////// GET DISPARITIES  ////////
    3789   //////////////////////////////////
    3790   DisInfo cDisInfo = getDvInfo(uiAbsPartIdx);
    3791   m_cDefaultDisInfo = cDisInfo;
    3792 
    3793   if (!( getSlice()->getIsDepth() || getSlice()->getViewIndex()>0))  // current slice is not both dependent view or depth
    3794   {
    3795     return;
    3796   }
    3797 #else
    3798   for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
    3799   {
    3800     abCandIsInter[ui] = false;
    3801     pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
    3802     pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
    3803   }
    3804 #endif
    3805 
    3806   numValidMergeCand = getSlice()->getMaxNumMergeCand();
    3807 #if H_3D
    3808   //////////////////////////////////
    3809   //////// DERIVE LOCATIONS ////////
    3810   //////////////////////////////////
    3811 #endif
    3812   // compute the location of the current PU
    3813   Int xP, yP, nPSW, nPSH;
    3814   this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
    3815 
    3816   Int iCount = 0;
    3817 
    3818   UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
    3819 #if !H_3D
    3820   PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
    3821 #endif
    3822   deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
    3823   deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
    3824 #if H_3D
     3220#if NH_3D_TEXT_MERGE
    38253221  Bool bMPIFlag   = getSlice()->getMpiFlag();
     3222  Int  tmpDir;
     3223#endif
     3224#if NH_3D_IV_MERGE || NH_3D_TEXT_MERGE
    38263225  Bool bIsDepth = getSlice()->getIsDepth();
    3827 #endif 
    3828 
    3829 #if H_3D_IC
     3226#endif
     3227
     3228#if NH_3D_IC
    38303229  Bool bICFlag = getICFlag(uiAbsPartIdx);
    38313230#endif
    3832 #if H_3D_ARP
     3231#if NH_3D_ARP
    38333232  Bool bARPFlag = getARPW(uiAbsPartIdx) > 0;
    38343233#endif
    3835 #if H_3D_DBBP
     3234#if NH_3D_DBBP
    38363235  Bool bDBBPFlag = getDBBPFlag(uiAbsPartIdx);
    38373236  assert(bDBBPFlag == getDBBPFlag(0)); 
    38383237#endif
    38393238
    3840 #if H_3D
    3841 #if H_3D_NBDV
     3239#if NH_3D_NBDV
    38423240  for(Int i = 0; i < MRG_MAX_NUM_CANDS_MEM; i++) 
    38433241  {
    3844     pcMvFieldNeighbours[i<<1    ].getMv().setIDVFlag (false);
    3845     pcMvFieldNeighbours[(i<<1)+1].getMv().setIDVFlag (false);
    3846   }
    3847 #endif
    3848   // Clean version for MCL construction align with WD
    3849   // init mergCands list
     3242    pcMFieldNeighbours[i<<1    ].getMv().setIDVFlag (false);
     3243    pcMFieldNeighbours[(i<<1)+1].getMv().setIDVFlag (false);
     3244  }
     3245#endif
     3246  // init containers
    38503247  for (Int i = 0; i<MRG_IVSHIFT+1; i++)
    3851   {
    38523248    m_mergCands[i].init();
    3853   }
    3854 
    3855   m_baseListidc = 0;
    3856 
     3249
     3250  m_numSpatialCands = 0;
     3251
     3252  //////////////////////////////////
     3253  ///////// GET VSP FLAGS //////////
     3254  //////////////////////////////////
    38573255  //left
    38583256  UInt uiLeftPartIdx = 0;
     
    38623260  if (getAvailableFlagA1())
    38633261  {
    3864     m_mergCands[MRG_A1].setCand( &pcMvFieldNeighbours[m_baseListidc<<1], puhInterDirNeighbours[m_baseListidc]
    3865 #if H_3D_VSP
     3262    m_mergCands[MRG_A1].setCand( &pcMFieldNeighbours[m_numSpatialCands<<1], puhInterDirNeighbours[m_numSpatialCands]
     3263#if NH_3D_VSP
    38663264    , (pcCULeft->getVSPFlag(uiLeftPartIdx) != 0
    3867 #if H_3D_IC
     3265#if NH_3D_IC
    38683266      && !bICFlag
    38693267#endif
    3870 #if H_3D_ARP
     3268#if NH_3D_ARP
    38713269      && !bARPFlag
    38723270#endif
    3873 #if H_3D_DBBP
     3271#if NH_3D_DBBP
    38743272      && !bDBBPFlag
    38753273#endif
    38763274      )
    38773275#endif
     3276#if NH_3D_SPIVMP
    38783277      , false
     3278#endif
    38793279      );
    3880     m_baseListidc++;
     3280    m_numSpatialCands++;
    38813281  }
    38823282
    38833283  // above
    3884 
    38853284  if (getAvailableFlagB1())
    38863285  {
    3887     m_mergCands[MRG_B1].setCand( &pcMvFieldNeighbours[m_baseListidc<<1], puhInterDirNeighbours[m_baseListidc]
    3888 #if H_3D_VSP
     3286    m_mergCands[MRG_B1].setCand( &pcMFieldNeighbours[m_numSpatialCands<<1], puhInterDirNeighbours[m_numSpatialCands]
     3287#if NH_3D_VSP
    38893288    , false
    38903289#endif
     3290#if NH_3D_SPIVMP
    38913291      , false
     3292#endif
    38923293      );
    3893     m_baseListidc++;
     3294    m_numSpatialCands++;
    38943295  }
    38953296
    38963297  // above right
    3897 
    38983298  if (getAvailableFlagB0())
    38993299  {
    3900     m_mergCands[MRG_B0].setCand( &pcMvFieldNeighbours[m_baseListidc<<1], puhInterDirNeighbours[m_baseListidc]
    3901 #if H_3D_VSP
    3902     ,
    3903       false
    3904 #endif
     3300    m_mergCands[MRG_B0].setCand( &pcMFieldNeighbours[m_numSpatialCands<<1], puhInterDirNeighbours[m_numSpatialCands]
     3301#if NH_3D_VSP
     3302    , false
     3303#endif
     3304#if NH_3D_SPIVMP
    39053305      , false
     3306#endif
    39063307      );
    3907     m_baseListidc++;
     3308    m_numSpatialCands++;
    39083309  }
    39093310
    39103311  // left bottom
    3911 
    39123312  if (getAvailableFlagA0())
    39133313  {
    3914     m_mergCands[MRG_A0].setCand( &pcMvFieldNeighbours[m_baseListidc<<1], puhInterDirNeighbours[m_baseListidc]
    3915 #if H_3D_VSP
     3314    m_mergCands[MRG_A0].setCand( &pcMFieldNeighbours[m_numSpatialCands<<1], puhInterDirNeighbours[m_numSpatialCands]
     3315#if NH_3D_VSP
    39163316    , false
    39173317#endif
     3318#if NH_3D_SPIVMP
    39183319      , false
     3320#endif
    39193321      );
    3920     m_baseListidc++;
     3322    m_numSpatialCands++;
    39213323  }
    39223324
    39233325  // above left
    3924 
    39253326  if (getAvailableFlagB2())
    39263327  {
    3927     m_mergCands[MRG_B2].setCand( &pcMvFieldNeighbours[m_baseListidc<<1], puhInterDirNeighbours[m_baseListidc]
    3928 #if H_3D_VSP
     3328    m_mergCands[MRG_B2].setCand( &pcMFieldNeighbours[m_numSpatialCands<<1], puhInterDirNeighbours[m_numSpatialCands]
     3329#if NH_3D_VSP
    39293330    , false
    39303331#endif
     3332#if NH_3D_SPIVMP
    39313333      , false
     3334#endif
    39323335      );
    3933     m_baseListidc++;
    3934   }
    3935 
    3936 #endif
    3937 
    3938 
    3939 #if H_3D_IV_MERGE
     3336    m_numSpatialCands++;
     3337  }
     3338
     3339
     3340#if NH_3D_TEXT_MERGE
    39403341
    39413342  /////////////////////////////////////////////
     
    39633364
    39643365      this->getPartIndexAndSize( uiPUIdx, uiPartAddr, iWidth, iHeight );
    3965       pcTexRec->getTopLeftSamplePos( this->getAddr(), this->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
     3366      pcTexRec->getTopLeftSamplePos( this->getCtuRsAddr(), this->getZorderIdxInCtu() + uiPartAddr, iCurrPosX, iCurrPosY );
    39663367
    39673368      Int iPUWidth, iPUHeight, iNumPart, iNumPartLine;
     
    39883389
    39893390      Int         iTexPosX, iTexPosY;
     3391#if NH_3D_INTEGER_MV_DEPTH
    39903392      const TComMv cMvRounding( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
    3991 
     3393#endif
    39923394      Int         iCenterPosX = iCurrPosX + ( ( iWidth /  iPUWidth ) >> 1 )  * iPUWidth + ( iPUWidth >> 1 );
    39933395      Int         iCenterPosY = iCurrPosY + ( ( iHeight /  iPUHeight ) >> 1 )  * iPUHeight + (iPUHeight >> 1);
     
    40033405
    40043406      pcTexRec->getCUAddrAndPartIdx( iCenterPosX , iCenterPosY , iTexCenterCUAddr, iTexCenterAbsPartIdx );
    4005       TComDataCU* pcDefaultCU    = pcTexPic->getCU( iTexCenterCUAddr );
     3407      TComDataCU* pcDefaultCU    = pcTexPic->getCtu( iTexCenterCUAddr );
    40063408
    40073409      if( pcDefaultCU->getPredictionMode( iTexCenterAbsPartIdx ) != MODE_INTRA )
     
    40223424              {
    40233425                bSPIVMPFlag = true;
     3426#if NH_3D_INTEGER_MV_DEPTH
    40243427                TComMv cMv = cDefaultMvField.getMv() + cMvRounding;
    40253428                cMv >>= 2;
     3429#else
     3430                TComMv cMv = cDefaultMvField.getMv();
     3431#endif
    40263432                cMvFieldSaved[eCurrRefPicList].setMvField(cMv, iRefPicList) ;
    40273433                break;
     
    40483454            iTexPosY     = i + iOffsetY;
    40493455            pcTexRec->getCUAddrAndPartIdx( iTexPosX, iTexPosY, iTexCUAddr, iTexAbsPartIdx );
    4050             pcTexCU  = pcTexPic->getCU( iTexCUAddr );
     3456            pcTexCU  = pcTexPic->getCtu( iTexCUAddr );
    40513457
    40523458            if( pcTexCU && !pcTexCU->isIntra(iTexAbsPartIdx) )
     
    40603466                if( (cTexMvField.getRefIdx()>=0) && ( iValidDepRef >= 0 ) )
    40613467                {
     3468#if NH_3D_INTEGER_MV_DEPTH
    40623469                  TComMv cMv = cTexMvField.getMv() + cMvRounding;
    40633470                  cMv >>=2;         
     3471#else
     3472                  TComMv cMv = cTexMvField.getMv();
     3473#endif         
    40643474                  pcMvFieldSP[2*iPartition + uiCurrRefListId].setMvField(cMv, iValidDepRef);
    40653475                }
     
    40803490          }
    40813491        }
    4082 #if H_3D
    4083       }
    4084 #endif
     3492      }
    40853493#if H_3D_FCO
    40863494    }
     
    40913499      for(iCnloop = 0; iCnloop < 2; iCnloop ++)
    40923500      {
    4093         if ( !m_mergCands[MRG_A1+iCnloop].m_bAvailable )  // prunning to A1, B1
     3501        if ( !m_mergCands[MRG_A1+iCnloop].m_bAvailable )  // pruning to A1, B1
    40943502        {
    40953503          continue;
    40963504        }
     3505#if NH_3D_FIX_PRUNING
     3506        if (hasEqualMotion( tmpDir, tmpMV, m_mergCands[MRG_A1+iCnloop].m_uDir, m_mergCands[MRG_A1+iCnloop].m_cMvField ) )
     3507#else
    40973508        if (tmpDir == m_mergCands[MRG_A1+iCnloop].m_uDir && tmpMV[0]==m_mergCands[MRG_A1+iCnloop].m_cMvField[0] && tmpMV[1]==m_mergCands[MRG_A1+iCnloop].m_cMvField[1])
     3509#endif
    40983510        {
    40993511          m_mergCands[MRG_A1+iCnloop].m_bAvailable = false;
     
    41103522    }
    41113523  }
     3524#endif
     3525
     3526#if NH_3D_IV_MERGE
    41123527  /////////////////////////////////////////////////////////////////
    41133528  //////// DERIVE IvMC, IvMCShift,IvDCShift, IvDC  Candidates /////
     
    41273542  if ( ivMvPredFlag && cDisInfo.m_aVIdxCan!=-1)
    41283543  {
     3544#if NH_3D_IC
    41293545    getInterViewMergeCands(uiPUIdx, ivCandRefIdx, ivCandMv, &cDisInfo, ivCandDir , bIsDepth, pcMvFieldSP, puhInterDirSP, bICFlag );
     3546#else
     3547    getInterViewMergeCands(uiPUIdx, ivCandRefIdx, ivCandMv, &cDisInfo, ivCandDir , bIsDepth, pcMvFieldSP, puhInterDirSP, false );
     3548#endif
    41303549  } 
    41313550
     
    41583577      for(Int i = 0; i < 2; i ++)
    41593578      {
    4160         if ( !m_mergCands[MRG_A1 + i].m_bAvailable ) // prunning to A1, B1
     3579        if ( !m_mergCands[MRG_A1 + i].m_bAvailable ) // pruning to A1, B1
    41613580        {
    41623581          continue;
    41633582        }
     3583#if NH_3D_FIX_PRUNING
     3584        if (hasEqualMotion(ivCandDir[0], tmpMV, m_mergCands[MRG_A1+i].m_uDir,  m_mergCands[MRG_A1+i].m_cMvField) )
     3585#else
    41643586        if (ivCandDir[0] == m_mergCands[MRG_A1+i].m_uDir && tmpMV[0]==m_mergCands[MRG_A1+i].m_cMvField[0] && tmpMV[1]==m_mergCands[MRG_A1+i].m_cMvField[1])
     3587#endif
    41653588        {
    41663589          m_mergCands[MRG_A1+i].m_bAvailable = false;
     
    41693592      }
    41703593    }
    4171     if (bIsDepth)
    4172     {
     3594    else
     3595    {
     3596#if NH_3D_FIX_PRUNING
     3597      if( hasEqualMotion( ivCandDir[0], tmpMV, m_mergCands[MRG_T].m_uDir, m_mergCands[MRG_T].m_cMvField ) )
     3598#else
    41733599      if (m_mergCands[MRG_T].m_bAvailable && ivCandDir[0] == m_mergCands[MRG_T].m_uDir && tmpMV[0]==m_mergCands[MRG_T].m_cMvField[0] && tmpMV[1]==m_mergCands[MRG_T].m_cMvField[1])
     3600#endif
    41743601      {
    41753602        bRemoveSpa                      = true;
     
    41833610        spiMvpFlag = true;
    41843611      }
    4185 #if H_3D_DBBP
     3612#if NH_3D_DBBP
    41863613      spiMvpFlag &= !bDBBPFlag;
    41873614#endif
     
    42043631#endif
    42053632
    4206 #if H_3D
    42073633  iCount += m_mergCands[MRG_A1].m_bAvailable + m_mergCands[MRG_B1].m_bAvailable;
     3634
     3635#if NH_3D_VSP
     3636  /////////////////////////////////////////////////
     3637  //////// VIEW SYNTHESIS PREDICTION (VSP) ////////
     3638  /////////////////////////////////////////////////
     3639  if (iCount<getSlice()->getMaxNumMergeCand())
     3640  {
     3641    if (
     3642      (!getAvailableFlagA1() || !(pcCULeft->getVSPFlag(uiLeftPartIdx) != 0)) &&
     3643#if NH_3D_IC
     3644      !bICFlag &&
     3645#endif
     3646#if NH_3D_ARP
     3647      !bARPFlag &&
     3648#endif
     3649#if H_3D || NH_3D_FIX_VSP
     3650      (nPSW + nPSH > 12) &&
     3651#endif
     3652#if NH_3D_DBBP
     3653      !bDBBPFlag &&
     3654#endif
     3655      xAddVspCand( mrgCandIdx, &cDisInfo, iCount ) )
     3656    {
     3657      return;
     3658    }
     3659
     3660    // early termination
     3661    if (iCount == getSlice()->getMaxNumMergeCand())
     3662    {
     3663      return;
     3664    }
     3665  }
     3666#endif
     3667
     3668  iCount += m_mergCands[MRG_B0].m_bAvailable;
     3669
     3670#if NH_3D_IV_MERGE
     3671  /////////////////////////////////////////////
     3672  //////// INTER VIEW DISP COMP (IvDC) ////////
     3673  /////////////////////////////////////////////
     3674  if( ivCandDir[1] && iCount < getSlice()->getMaxNumMergeCand() && !getSlice()->getIsDepth() )
     3675  {
     3676    assert(iCount < getSlice()->getMaxNumMergeCand());
     3677
     3678    tmpMV[0].setMvField( cZeroMv, NOT_VALID );
     3679    tmpMV[1].setMvField( cZeroMv, NOT_VALID );
     3680    if( ( ivCandDir[1] & 1 ) == 1 )
     3681    {
     3682      tmpMV[0].setMvField( ivCandMv[ 2 ], ivCandRefIdx[ 2 ] );
     3683    }
     3684    if( ( ivCandDir[1] & 2 ) == 2 )
     3685    {
     3686      tmpMV[1].setMvField( ivCandMv[ 3 ], ivCandRefIdx[ 3 ] );
     3687    }
     3688
     3689    Bool bRemoveSpa = false; //pruning to A1, B1
     3690    for(Int i = 0; i < 2; i ++)
     3691    {
     3692      if ( !m_mergCands[MRG_A1+i].m_bAvailable )
     3693      {
     3694        continue;
     3695      }
     3696#if NH_3D_FIX_PRUNING
     3697      if ( hasEqualMotion(ivCandDir[1], tmpMV, m_mergCands[MRG_A1+i].m_uDir, m_mergCands[MRG_A1+i].m_cMvField) )
    42083698#else
     3699      if (ivCandDir[1] == m_mergCands[MRG_A1+i].m_uDir && tmpMV[0]==m_mergCands[MRG_A1+i].m_cMvField[0] && tmpMV[1]==m_mergCands[MRG_A1+i].m_cMvField[1])
     3700#endif
     3701      {
     3702        bRemoveSpa                      = true;
     3703        break;
     3704      }     
     3705    }
     3706    if(!bRemoveSpa)
     3707    {
     3708#if NH_3D_NBDV
     3709      tmpMV[0].getMv().setIDVFlag (false);
     3710      tmpMV[1].getMv().setIDVFlag (false);
     3711#endif
     3712      m_mergCands[MRG_IVDC].setCand( tmpMV, ivCandDir[1], false, false);
     3713
     3714      if ( mrgCandIdx == iCount )
     3715        return;
     3716      iCount ++;
     3717
     3718      // early termination
     3719      if (iCount == getSlice()->getMaxNumMergeCand())
     3720      {
     3721        return;
     3722      }
     3723    }
     3724  }
     3725#endif // H_3D_IV_MERGE
     3726
     3727  iCount += m_mergCands[MRG_A0].m_bAvailable + m_mergCands[MRG_B2].m_bAvailable;
     3728
     3729#if NH_3D_IV_MERGE
     3730  ////////////////////////////////////////////////////
     3731  //////// SHIFTED IV (IvMCShift + IvDCShift) ////////
     3732  ////////////////////////////////////////////////////
     3733  if(  ivMvPredFlag && iCount < getSlice()->getMaxNumMergeCand() && !getSlice()->getIsDepth() )
     3734  {
     3735    if(xAddIvMRGCand( mrgCandIdx,  iCount, ivCandDir, ivCandMv, ivCandRefIdx ) )
     3736    {
     3737      return;
     3738    }
     3739    //early termination
     3740    if (iCount == getSlice()->getMaxNumMergeCand())
     3741    {
     3742      return;
     3743    }
     3744  }
     3745#endif
     3746}
     3747#endif
     3748
     3749//! Construct a list of merging candidates
     3750Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx )
     3751{
     3752  UInt uiAbsPartAddr = m_absZIdxInCtu + uiAbsPartIdx;
     3753#if NH_3D_MLC
     3754  Bool abCandIsInter[ MRG_MAX_NUM_CANDS_MEM ];
     3755#else
     3756  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
     3757#endif
     3758  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
     3759  {
     3760    abCandIsInter[ui] = false;
     3761    pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
     3762    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
     3763  }
     3764  numValidMergeCand = getSlice()->getMaxNumMergeCand();
     3765  // compute the location of the current PU
     3766  Int xP, yP, nPSW, nPSH;
     3767  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
     3768
     3769  Int iCount = 0;
     3770
     3771  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
     3772  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
     3773  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
     3774  deriveLeftBottomIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
     3775
    42093776  //left
    42103777  UInt uiLeftPartIdx = 0;
    42113778  TComDataCU* pcCULeft = 0;
    42123779  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
     3780
    42133781  Bool isAvailableA1 = pcCULeft &&
    4214     pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
    4215     !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
    4216     !pcCULeft->isIntra( uiLeftPartIdx ) ;
     3782                       pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
     3783                       !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
     3784                       pcCULeft->isInter( uiLeftPartIdx ) ;
     3785
    42173786  if ( isAvailableA1 )
    42183787  {
     3788#if NH_3D_MLC
     3789    m_bAvailableFlagA1 = 1;
     3790#endif
    42193791    abCandIsInter[iCount] = true;
    42203792    // get Inter Dir
     
    42263798      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    42273799    }
    4228 
    42293800    if ( mrgCandIdx == iCount )
    42303801    {
     
    42353806
    42363807  // early termination
    4237   if (iCount == getSlice()->getMaxNumMergeCand()) 
     3808  if (iCount == getSlice()->getMaxNumMergeCand())
    42383809  {
    42393810    return;
    42403811  }
    4241 
    42423812  // above
    42433813  UInt uiAbovePartIdx = 0;
    42443814  TComDataCU* pcCUAbove = 0;
    42453815  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
     3816
    42463817  Bool isAvailableB1 = pcCUAbove &&
    4247     pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
    4248     !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
    4249     !pcCUAbove->isIntra( uiAbovePartIdx );
     3818                       pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
     3819                       !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
     3820                       pcCUAbove->isInter( uiAbovePartIdx );
     3821
    42503822  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
    42513823  {
     3824#if NH_3D_MLC
     3825    m_bAvailableFlagB1 = 1;
     3826#endif
    42523827    abCandIsInter[iCount] = true;
    42533828    // get Inter Dir
     
    42593834      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    42603835    }
    4261 
    42623836    if ( mrgCandIdx == iCount )
    42633837    {
     
    42673841  }
    42683842  // early termination
    4269   if (iCount == getSlice()->getMaxNumMergeCand()) 
     3843  if (iCount == getSlice()->getMaxNumMergeCand())
    42703844  {
    42713845    return;
     
    42763850  TComDataCU* pcCUAboveRight = 0;
    42773851  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
     3852
    42783853  Bool isAvailableB0 = pcCUAboveRight &&
    4279     pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
    4280     !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
     3854                       pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
     3855                       pcCUAboveRight->isInter( uiAboveRightPartIdx );
     3856
    42813857  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
    42823858  {
     3859#if NH_3D_MLC
     3860    m_bAvailableFlagB0 = 1;
     3861#endif
    42833862    abCandIsInter[iCount] = true;
    42843863    // get Inter Dir
     
    42903869      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    42913870    }
    4292 
    42933871    if ( mrgCandIdx == iCount )
    42943872    {
     
    42983876  }
    42993877  // early termination
    4300   if (iCount == getSlice()->getMaxNumMergeCand()) 
     3878  if (iCount == getSlice()->getMaxNumMergeCand())
    43013879  {
    43023880    return;
    43033881  }
    4304 #endif
    4305 
    4306 
    4307 #if H_3D_VSP
    4308   /////////////////////////////////////////////////
    4309   //////// VIEW SYNTHESIS PREDICTION (VSP) ////////
    4310   /////////////////////////////////////////////////
    4311   if (iCount<getSlice()->getMaxNumMergeCand())
    4312   {
    4313     if (
    4314       (!getAvailableFlagA1() || !(pcCULeft->getVSPFlag(uiLeftPartIdx) != 0)) &&
    4315 #if H_3D_IC
    4316       !bICFlag &&
    4317 #endif
    4318 #if H_3D_ARP
    4319       !bARPFlag &&
    4320 #endif
    4321 #if H_3D
    4322       (nPSW + nPSH > 12) &&
    4323 #endif
    4324 #if H_3D_DBBP
    4325       !bDBBPFlag &&
    4326 #endif
    4327       xAddVspCand( mrgCandIdx, &cDisInfo, iCount ) )
    4328     {
    4329       return;
    4330     }
    4331 
    4332     // early termination
    4333     if (iCount == getSlice()->getMaxNumMergeCand())
    4334     {
    4335       return;
    4336     }
    4337 #endif
    4338 #if H_3D_VSP
    4339   }
    4340 #endif
    4341 
    4342 #if H_3D
    4343   iCount += m_mergCands[MRG_B0].m_bAvailable;
    4344 #endif
    4345 
    4346 
    4347 #if H_3D_IV_MERGE
    4348   /////////////////////////////////////////////
    4349   //////// INTER VIEW DISP COMP (IvDC) ////////
    4350   /////////////////////////////////////////////
    4351   if( ivCandDir[1] && iCount < getSlice()->getMaxNumMergeCand() && !getSlice()->getIsDepth() )
    4352   {
    4353     assert(iCount < getSlice()->getMaxNumMergeCand());
    4354 
    4355     tmpMV[0].setMvField( cZeroMv, NOT_VALID );
    4356     tmpMV[1].setMvField( cZeroMv, NOT_VALID );
    4357     if( ( ivCandDir[1] & 1 ) == 1 )
    4358     {
    4359       tmpMV[0].setMvField( ivCandMv[ 2 ], ivCandRefIdx[ 2 ] );
    4360     }
    4361     if( ( ivCandDir[1] & 2 ) == 2 )
    4362     {
    4363       tmpMV[1].setMvField( ivCandMv[ 3 ], ivCandRefIdx[ 3 ] );
    4364     }
    4365 
    4366     Bool bRemoveSpa = false; //pruning to A1, B1
    4367     for(Int i = 0; i < 2; i ++)
    4368     {
    4369       if ( !m_mergCands[MRG_A1+i].m_bAvailable )
    4370       {
    4371         continue;
    4372       }
    4373       if (ivCandDir[1] == m_mergCands[MRG_A1+i].m_uDir && tmpMV[0]==m_mergCands[MRG_A1+i].m_cMvField[0] && tmpMV[1]==m_mergCands[MRG_A1+i].m_cMvField[1])
    4374       {
    4375         bRemoveSpa                      = true;
    4376         break;
    4377       }     
    4378     }
    4379     if(!bRemoveSpa)
    4380     {
    4381 #if H_3D_NBDV
    4382       tmpMV[0].getMv().setIDVFlag (false);
    4383       tmpMV[1].getMv().setIDVFlag (false);
    4384 #endif
    4385       m_mergCands[MRG_IVDC].setCand( tmpMV, ivCandDir[1], false, false);
    4386 
    4387       if ( mrgCandIdx == iCount )
    4388         return;
    4389       iCount ++;
    4390 
    4391       // early termination
    4392       if (iCount == getSlice()->getMaxNumMergeCand())
    4393       {
    4394         return;
    4395       }
    4396     }
    4397   }
    4398 #endif // H_3D_IV_MERGE
    4399 
    4400 
    4401 #if H_3D
    4402   iCount += m_mergCands[MRG_A0].m_bAvailable + m_mergCands[MRG_B2].m_bAvailable;
    4403 #else
     3882
    44043883  //left bottom
    44053884  UInt uiLeftBottomPartIdx = 0;
    44063885  TComDataCU* pcCULeftBottom = 0;
    44073886  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
     3887
    44083888  Bool isAvailableA0 = pcCULeftBottom &&
    4409   pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
    4410   !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
     3889                       pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
     3890                       pcCULeftBottom->isInter( uiLeftBottomPartIdx ) ;
     3891
    44113892  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
    44123893  {
     3894#if NH_3D_MLC
     3895    m_bAvailableFlagA0 = 1;
     3896#endif
    44133897    abCandIsInter[iCount] = true;
    44143898    // get Inter Dir
     
    44273911  }
    44283912  // early termination
    4429   if (iCount == getSlice()->getMaxNumMergeCand()) 
     3913  if (iCount == getSlice()->getMaxNumMergeCand())
    44303914  {
    44313915    return;
    44323916  }
    44333917
    4434   // above left 
     3918  // above left
    44353919  if( iCount < 4 )
    44363920  {
     
    44383922    TComDataCU* pcCUAboveLeft = 0;
    44393923    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
     3924
    44403925    Bool isAvailableB2 = pcCUAboveLeft &&
    4441     pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
    4442     !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
     3926                         pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
     3927                         pcCUAboveLeft->isInter( uiAboveLeftPartIdx );
     3928
    44433929    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
    44443930        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
    44453931    {
     3932#if NH_3D_MLC
     3933      m_bAvailableFlagB2 = 1;
     3934#endif
    44463935      abCandIsInter[iCount] = true;
    44473936      // get Inter Dir
     
    44613950  }
    44623951  // early termination
    4463   if (iCount == getSlice()->getMaxNumMergeCand()) 
     3952  if (iCount == getSlice()->getMaxNumMergeCand())
    44643953  {
    44653954    return;
    44663955  }
    4467 #endif
    4468 
    4469 
    4470 #if H_3D_IV_MERGE
    4471   ////////////////////////////////////////////////////
    4472   //////// SHIFTED IV (IvMCShift + IvDCShift) ////////
    4473   ////////////////////////////////////////////////////
    4474   if(  ivMvPredFlag && iCount < getSlice()->getMaxNumMergeCand() && !getSlice()->getIsDepth() )
    4475   {
    4476     if(xAddIvMRGCand( mrgCandIdx,  iCount, ivCandDir, ivCandMv, ivCandRefIdx ) )
    4477     {
    4478       return;
    4479     }
    4480     //early termination
    4481     if (iCount == getSlice()->getMaxNumMergeCand())
    4482     {
    4483       return;
    4484     }
    4485   }
    4486 #endif
    4487 #if !H_3D
    4488   if ( getSlice()->getEnableTMVPFlag())
     3956
     3957  if ( getSlice()->getEnableTMVPFlag() )
    44893958  {
    44903959    //>> MTK colocated-RightBottom
    44913960    UInt uiPartIdxRB;
    44923961
    4493     deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
     3962    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB );
    44943963
    44953964    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
    4496     UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
     3965    const UInt numPartInCtuWidth  = m_pcPic->getNumPartInCtuWidth();
     3966    const UInt numPartInCtuHeight = m_pcPic->getNumPartInCtuHeight();
    44973967
    44983968    TComMv cColMv;
    44993969    Int iRefIdx;
    4500     Int uiLCUIdx = -1;
    4501 
    4502     if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
    4503     {
    4504     }
    4505     else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
    4506     {
    4507     }
    4508     else
    4509     {
    4510       if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
    4511         ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
    4512       {
    4513         uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
    4514         uiLCUIdx = getAddr();
    4515       }
    4516       else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
    4517       {
    4518         uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
    4519       }
    4520       else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
     3970    Int ctuRsAddr = -1;
     3971
     3972    if (   ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth () ) < m_pcSlice->getSPS()->getPicWidthInLumaSamples () )  // image boundary check
     3973        && ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) < m_pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     3974    {
     3975      if ( ( uiAbsPartIdxTmp % numPartInCtuWidth < numPartInCtuWidth - 1 ) &&           // is not at the last column of CTU
     3976        ( uiAbsPartIdxTmp / numPartInCtuWidth < numPartInCtuHeight - 1 ) )              // is not at the last row    of CTU
     3977      {
     3978        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + numPartInCtuWidth + 1 ];
     3979        ctuRsAddr = getCtuRsAddr();
     3980      }
     3981      else if ( uiAbsPartIdxTmp % numPartInCtuWidth < numPartInCtuWidth - 1 )           // is not at the last column of CTU But is last row of CTU
     3982      {
     3983        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + numPartInCtuWidth + 1) % m_pcPic->getNumPartitionsInCtu() ];
     3984      }
     3985      else if ( uiAbsPartIdxTmp / numPartInCtuWidth < numPartInCtuHeight - 1 )          // is not at the last row of CTU But is last column of CTU
    45213986      {
    45223987        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
    4523         uiLCUIdx = getAddr() + 1;
    4524       }
    4525       else //is the right bottom corner of LCU                       
     3988        ctuRsAddr = getCtuRsAddr() + 1;
     3989      }
     3990      else //is the right bottom corner of CTU
    45263991      {
    45273992        uiAbsPartAddr = 0;
    45283993      }
    45293994    }
    4530    
    4531    
     3995
    45323996    iRefIdx = 0;
     3997
    45333998    Bool bExistMV = false;
    45343999    UInt uiPartIdxCenter;
    4535     UInt uiCurLCUIdx = getAddr();
    45364000    Int dir = 0;
    45374001    UInt uiArrayAddr = iCount;
    45384002    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
    4539     bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
     4003    bExistMV = ctuRsAddr >= 0 && xGetColMVP( REF_PIC_LIST_0, ctuRsAddr, uiAbsPartAddr, cColMv, iRefIdx );
    45404004    if( bExistMV == false )
    45414005    {
    4542       bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
     4006      bExistMV = xGetColMVP( REF_PIC_LIST_0, getCtuRsAddr(), uiPartIdxCenter, cColMv, iRefIdx );
    45434007    }
    45444008    if( bExistMV )
     
    45504014    if ( getSlice()->isInterB() )
    45514015    {
    4552       bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
     4016#if NH_3D_TMVP
     4017      iRefIdx = 0;
     4018#endif
     4019      bExistMV = ctuRsAddr >= 0 && xGetColMVP( REF_PIC_LIST_1, ctuRsAddr, uiAbsPartAddr, cColMv, iRefIdx);
    45534020      if( bExistMV == false )
    45544021      {
    4555         bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
     4022        bExistMV = xGetColMVP( REF_PIC_LIST_1, getCtuRsAddr(), uiPartIdxCenter, cColMv, iRefIdx );
    45564023      }
    45574024      if( bExistMV )
     
    45614028      }
    45624029    }
    4563    
     4030
    45644031    if (dir != 0)
    45654032    {
    45664033      puhInterDirNeighbours[uiArrayAddr] = dir;
    45674034      abCandIsInter[uiArrayAddr] = true;
     4035#if NH_3D_NBDV
     4036      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
     4037      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
     4038#endif
     4039
    45684040      if ( mrgCandIdx == iCount )
    45694041      {
     
    45734045    }
    45744046  }
    4575   // early termination 
    4576   if (iCount == getSlice()->getMaxNumMergeCand()) 
     4047  // early termination
     4048  if (iCount == getSlice()->getMaxNumMergeCand())
    45774049  {
    45784050    return;
    45794051  }
     4052
    45804053  UInt uiArrayAddr = iCount;
    45814054  UInt uiCutoff = uiArrayAddr;
    4582    
    4583   if ( getSlice()->isInterB())
    4584   {
    4585     UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
    4586     UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
     4055
     4056#if NH_3D_MLC
     4057  if ( getSlice()->isInterB() && iCount<5)
     4058#else
     4059  if ( getSlice()->isInterB() )
     4060#endif
     4061  {
     4062    static const UInt NUM_PRIORITY_LIST=12;
     4063    static const UInt uiPriorityList0[NUM_PRIORITY_LIST] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
     4064    static const UInt uiPriorityList1[NUM_PRIORITY_LIST] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
    45874065
    45884066    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
    45894067    {
    4590       Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
     4068      assert(idx<NUM_PRIORITY_LIST);
     4069      Int i = uiPriorityList0[idx];
     4070      Int j = uiPriorityList1[idx];
    45914071      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
    45924072      {
     
    46124092  }
    46134093  // early termination
    4614   if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
     4094  if (uiArrayAddr == getSlice()->getMaxNumMergeCand())
    46154095  {
    46164096    return;
    46174097  }
     4098
    46184099  Int iNumRefIdx = (getSlice()->isInterB()) ? min(m_pcSlice->getNumRefIdx(REF_PIC_LIST_0), m_pcSlice->getNumRefIdx(REF_PIC_LIST_1)) : m_pcSlice->getNumRefIdx(REF_PIC_LIST_0);
     4100
    46194101  Int r = 0;
    46204102  Int refcnt = 0;
     
    46314113    }
    46324114    uiArrayAddr++;
     4115
    46334116    if ( refcnt == iNumRefIdx - 1 )
    46344117    {
     
    46414124    }
    46424125  }
    4643 
    46444126  numValidMergeCand = uiArrayAddr;
    4645 #endif
    4646 }
    4647 #else
    4648 
    4649 /** Constructs a list of merging candidates
    4650  * \param uiAbsPartIdx
    4651  * \param uiPUIdx
    4652  * \param uiDepth
    4653  * \param pcMvFieldNeighbours
    4654  * \param puhInterDirNeighbours
    4655  * \param numValidMergeCand
    4656  */
    4657 Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
    4658       , Int& numValidMergeCand, Int mrgCandIdx
    4659 )
    4660 {
    4661   UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
    4662   Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
    4663   for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
    4664   {
    4665     abCandIsInter[ui] = false;
    4666     pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
    4667     pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
    4668   }
    4669   numValidMergeCand = getSlice()->getMaxNumMergeCand();
    4670   // compute the location of the current PU
    4671   Int xP, yP, nPSW, nPSH;
    4672   this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
    4673 
    4674   Int iCount = 0;
    4675 
    4676   UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
    4677   PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
    4678   deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
    4679   deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
    4680 
    4681   //left
    4682   UInt uiLeftPartIdx = 0;
    4683   TComDataCU* pcCULeft = 0;
    4684   pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
    4685   Bool isAvailableA1 = pcCULeft &&
    4686   pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
    4687   !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
    4688   !pcCULeft->isIntra( uiLeftPartIdx ) ;
    4689   if ( isAvailableA1 )
    4690   {
    4691     abCandIsInter[iCount] = true;
    4692     // get Inter Dir
    4693     puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
    4694     // get Mv from Left
    4695     pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
    4696     if ( getSlice()->isInterB() )
    4697     {
    4698       pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    4699     }
    4700     if ( mrgCandIdx == iCount )
    4701     {
    4702       return;
    4703     }
    4704     iCount ++;
    4705   }
    4706  
    4707   // early termination
    4708   if (iCount == getSlice()->getMaxNumMergeCand())
    4709   {
    4710     return;
    4711   }
    4712 
    4713   // above
    4714   UInt uiAbovePartIdx = 0;
    4715   TComDataCU* pcCUAbove = 0;
    4716   pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
    4717   Bool isAvailableB1 = pcCUAbove &&
    4718   pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
    4719   !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
    4720   !pcCUAbove->isIntra( uiAbovePartIdx );
    4721   if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
    4722   {
    4723     abCandIsInter[iCount] = true;
    4724     // get Inter Dir
    4725     puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
    4726     // get Mv from Left
    4727     pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
    4728     if ( getSlice()->isInterB() )
    4729     {
    4730       pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    4731     }
    4732 
    4733     if ( mrgCandIdx == iCount )
    4734     {
    4735       return;
    4736     }
    4737     iCount ++;
    4738   }
    4739   // early termination
    4740   if (iCount == getSlice()->getMaxNumMergeCand())
    4741   {
    4742     return;
    4743   }
    4744 
    4745 
    4746   // above right
    4747   UInt uiAboveRightPartIdx = 0;
    4748   TComDataCU* pcCUAboveRight = 0;
    4749   pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
    4750   Bool isAvailableB0 = pcCUAboveRight &&
    4751   pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
    4752   !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
    4753   if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
    4754   {
    4755     abCandIsInter[iCount] = true;
    4756     // get Inter Dir
    4757     puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
    4758     // get Mv from Left
    4759     pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
    4760     if ( getSlice()->isInterB() )
    4761     {
    4762       pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    4763     }
    4764     if ( mrgCandIdx == iCount )
    4765     {
    4766       return;
    4767     }
    4768     iCount ++;
    4769   }
    4770   // early termination
    4771   if (iCount == getSlice()->getMaxNumMergeCand())
    4772   {
    4773     return;
    4774   }
    4775 
    4776   //left bottom
    4777   UInt uiLeftBottomPartIdx = 0;
    4778   TComDataCU* pcCULeftBottom = 0;
    4779   pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
    4780   Bool isAvailableA0 = pcCULeftBottom &&
    4781   pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
    4782   !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
    4783   if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
    4784   {
    4785     abCandIsInter[iCount] = true;
    4786     // get Inter Dir
    4787     puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
    4788     // get Mv from Left
    4789     pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
    4790     if ( getSlice()->isInterB() )
    4791     {
    4792       pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    4793     }
    4794 
    4795     if ( mrgCandIdx == iCount )
    4796     {
    4797       return;
    4798     }
    4799     iCount ++;
    4800   }
    4801   // early termination
    4802   if (iCount == getSlice()->getMaxNumMergeCand())
    4803   {
    4804     return;
    4805   }
    4806 
    4807   // above left
    4808   if( iCount < 4 )
    4809   {
    4810     UInt uiAboveLeftPartIdx = 0;
    4811     TComDataCU* pcCUAboveLeft = 0;
    4812     pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
    4813     Bool isAvailableB2 = pcCUAboveLeft &&
    4814     pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
    4815     !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
    4816     if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
    4817         && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
    4818     {
    4819       abCandIsInter[iCount] = true;
    4820       // get Inter Dir
    4821       puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
    4822       // get Mv from Left
    4823       pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
    4824       if ( getSlice()->isInterB() )
    4825       {
    4826         pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    4827       }
    4828       if ( mrgCandIdx == iCount )
    4829       {
    4830         return;
    4831       }
    4832       iCount ++;
    4833     }
    4834   }
    4835   // early termination
    4836   if (iCount == getSlice()->getMaxNumMergeCand())
    4837   {
    4838     return;
    4839   }
    4840 
    4841   if ( getSlice()->getEnableTMVPFlag())
    4842   {
    4843     //>> MTK colocated-RightBottom
    4844     UInt uiPartIdxRB;
    4845 
    4846     deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
    4847 
    4848     UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
    4849     UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
    4850 
    4851     TComMv cColMv;
    4852     Int iRefIdx;
    4853     Int uiLCUIdx = -1;
    4854 
    4855     if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
    4856     {
    4857     }
    4858     else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
    4859     {
    4860     }
    4861     else
    4862     {
    4863       if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
    4864         ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
    4865       {
    4866         uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
    4867         uiLCUIdx = getAddr();
    4868       }
    4869       else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
    4870       {
    4871         uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
    4872       }
    4873       else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
    4874       {
    4875         uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
    4876         uiLCUIdx = getAddr() + 1;
    4877       }
    4878       else //is the right bottom corner of LCU                       
    4879       {
    4880         uiAbsPartAddr = 0;
    4881       }
    4882     }
    4883    
    4884    
    4885     iRefIdx = 0;
    4886     Bool bExistMV = false;
    4887     UInt uiPartIdxCenter;
    4888     UInt uiCurLCUIdx = getAddr();
    4889     Int dir = 0;
    4890     UInt uiArrayAddr = iCount;
    4891     xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
    4892     bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
    4893     if( bExistMV == false )
    4894     {
    4895       bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
    4896     }
    4897     if( bExistMV )
    4898     {
    4899       dir |= 1;
    4900       pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
    4901     }
    4902 
    4903     if ( getSlice()->isInterB() )
    4904     {
    4905       bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
    4906       if( bExistMV == false )
    4907       {
    4908         bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
    4909       }
    4910       if( bExistMV )
    4911       {
    4912         dir |= 2;
    4913         pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
    4914       }
    4915     }
    4916    
    4917     if (dir != 0)
    4918     {
    4919       puhInterDirNeighbours[uiArrayAddr] = dir;
    4920       abCandIsInter[uiArrayAddr] = true;
    4921       if ( mrgCandIdx == iCount )
    4922       {
    4923         return;
    4924       }
    4925       iCount++;
    4926     }
    4927   }
    4928   // early termination
    4929   if (iCount == getSlice()->getMaxNumMergeCand())
    4930   {
    4931     return;
    4932   }
    4933   UInt uiArrayAddr = iCount;
    4934   UInt uiCutoff = uiArrayAddr;
    4935    
    4936   if ( getSlice()->isInterB())
    4937   {
    4938     UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
    4939     UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
    4940 
    4941     for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
    4942     {
    4943       Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
    4944       if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
    4945       {
    4946         abCandIsInter[uiArrayAddr] = true;
    4947         puhInterDirNeighbours[uiArrayAddr] = 3;
    4948 
    4949         // get Mv from cand[i] and cand[j]
    4950         pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
    4951         pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
    4952 
    4953         Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
    4954         Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
    4955         if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
    4956         {
    4957           abCandIsInter[uiArrayAddr] = false;
    4958         }
    4959         else
    4960         {
    4961           uiArrayAddr++;
    4962         }
    4963       }
    4964     }
    4965   }
    4966   // early termination
    4967   if (uiArrayAddr == getSlice()->getMaxNumMergeCand())
    4968   {
    4969     return;
    4970   }
    4971   Int iNumRefIdx = (getSlice()->isInterB()) ? min(m_pcSlice->getNumRefIdx(REF_PIC_LIST_0), m_pcSlice->getNumRefIdx(REF_PIC_LIST_1)) : m_pcSlice->getNumRefIdx(REF_PIC_LIST_0);
    4972   Int r = 0;
    4973   Int refcnt = 0;
    4974   while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
    4975   {
    4976     abCandIsInter[uiArrayAddr] = true;
    4977     puhInterDirNeighbours[uiArrayAddr] = 1;
    4978     pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
    4979 
    4980     if ( getSlice()->isInterB() )
    4981     {
    4982       puhInterDirNeighbours[uiArrayAddr] = 3;
    4983       pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
    4984     }
    4985     uiArrayAddr++;
    4986     if ( refcnt == iNumRefIdx - 1 )
    4987     {
    4988       r = 0;
    4989     }
    4990     else
    4991     {
    4992       ++r;
    4993       ++refcnt;
    4994     }
    4995   }
    4996 
    4997   numValidMergeCand = uiArrayAddr;
    4998 }
    4999 #endif
     4127}
    50004128
    50014129/** Check whether the current PU and a spatial neighboring PU are in a same ME region.
    5002  * \param xN, xN   location of the upper-left corner pixel of a neighboring PU
     4130 * \param xN, yN   location of the upper-left corner pixel of a neighboring PU
    50034131 * \param xP, yP   location of the upper-left corner pixel of the current PU
    5004  * \returns Bool
    50054132 */
    50064133Bool TComDataCU::isDiffMER(Int xN, Int yN, Int xP, Int yP)
     
    50184145  return false;
    50194146}
    5020 /** calculate the location of upper-left corner pixel and size of the current PU.
    5021  * \param partIdx  PU index within a CU
    5022  * \param xP, yP   location of the upper-left corner pixel of the current PU
    5023  * \param PSW, nPSH    size of the curren PU
    5024  * \returns Void
     4147
     4148/** Calculate the location of upper-left corner pixel and size of the current PU.
     4149 * \param partIdx       PU index within a CU
     4150 * \param xP, yP        location of the upper-left corner pixel of the current PU
     4151 * \param nPSW, nPSH    size of the current PU
    50254152 */
    50264153Void TComDataCU::getPartPosition( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH)
     
    50324159  {
    50334160  case SIZE_2NxN:
    5034     nPSW = getWidth(0);     
    5035     nPSH = getHeight(0) >> 1; 
     4161    nPSW = getWidth(0);
     4162    nPSH = getHeight(0) >> 1;
    50364163    xP   = col;
    50374164    yP   = (partIdx ==0)? row: row + nPSH;
    50384165    break;
    50394166  case SIZE_Nx2N:
    5040     nPSW = getWidth(0) >> 1; 
    5041     nPSH = getHeight(0);     
     4167    nPSW = getWidth(0) >> 1;
     4168    nPSH = getHeight(0);
    50424169    xP   = (partIdx ==0)? col: col + nPSW;
    50434170    yP   = row;
    50444171    break;
    50454172  case SIZE_NxN:
    5046     nPSW = getWidth(0) >> 1; 
    5047     nPSH = getHeight(0) >> 1; 
     4173    nPSW = getWidth(0) >> 1;
     4174    nPSH = getHeight(0) >> 1;
    50484175    xP   = col + (partIdx&0x1)*nPSW;
    50494176    yP   = row + (partIdx>>1)*nPSH;
     
    50764203  default:
    50774204    assert ( m_pePartSize[0] == SIZE_2Nx2N );
    5078     nPSW = getWidth(0);     
    5079     nPSH = getHeight(0);     
     4205    nPSW = getWidth(0);
     4206    nPSH = getHeight(0);
    50804207    xP   = col ;
    50814208    yP   = row ;
     
    50874214/** Constructs a list of candidates for AMVP
    50884215 * \param uiPartIdx
    5089  * \param uiPartAddr 
     4216 * \param uiPartAddr
    50904217 * \param eRefPicList
    50914218 * \param iRefIdx
     
    50974224  Bool bAddedSmvp = false;
    50984225
    5099   pInfo->iN = 0; 
     4226  pInfo->iN = 0;
    51004227  if (iRefIdx < 0)
    51014228  {
    51024229    return;
    51034230  }
    5104  
     4231
    51054232  //-- Get Spatial MV
    51064233  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
    5107   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
     4234  const UInt numPartInCtuWidth  = m_pcPic->getNumPartInCtuWidth();
     4235  const UInt numPartInCtuHeight = m_pcPic->getNumPartInCtuHeight();
    51084236  Bool bAdded = false;
    5109  
     4237
    51104238  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
    51114239  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
    5112  
     4240
    51134241  TComDataCU* tmpCU = NULL;
    51144242  UInt idx;
    51154243  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
    5116   bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
     4244  bAddedSmvp = (tmpCU != NULL) && (tmpCU->isInter(idx));
    51174245
    51184246  if (!bAddedSmvp)
    51194247  {
    51204248    tmpCU = getPULeft(idx, uiPartIdxLB);
    5121     bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
     4249    bAddedSmvp = (tmpCU != NULL) && (tmpCU->isInter(idx));
    51224250  }
    51234251
    51244252  // Left predictor search
    51254253  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
    5126   if (!bAdded) 
     4254  if (!bAdded)
    51274255  {
    51284256    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
    51294257  }
    5130  
     4258
    51314259  if(!bAdded)
    51324260  {
    51334261    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
    5134     if (!bAdded) 
     4262    if (!bAdded)
    51354263    {
    51364264      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
    51374265    }
    51384266  }
     4267
    51394268  // Above predictor search
    51404269  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
    51414270
    5142   if (!bAdded) 
     4271  if (!bAdded)
    51434272  {
    51444273    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
     
    51504279  }
    51514280
    5152   if (!bAddedSmvp)
     4281  if(!bAddedSmvp)
    51534282  {
    51544283    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
    5155     if (!bAdded) 
     4284    if (!bAdded)
    51564285    {
    51574286      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
     
    51634292    }
    51644293  }
    5165  
     4294
    51664295  if ( pInfo->iN == 2 )
    51674296  {
     
    51784307    TComMv cColMv;
    51794308    UInt uiPartIdxRB;
    5180     UInt uiAbsPartIdx; 
     4309    UInt uiAbsPartIdx;
    51814310    UInt uiAbsPartAddr;
    51824311
    51834312    deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
    5184     uiAbsPartAddr = m_uiAbsIdxInLCU + uiPartAddr;
     4313    uiAbsPartAddr = m_absZIdxInCtu + uiPartAddr;
    51854314
    51864315    //----  co-located RightBottom Temporal Predictor (H) ---//
    51874316    uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
    5188     Int uiLCUIdx = -1;
    5189     if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
    5190     {
    5191     }
    5192     else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
    5193     {
     4317    Int ctuRsAddr = -1;
     4318    if (  ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth () ) < m_pcSlice->getSPS()->getPicWidthInLumaSamples () )  // image boundary check
     4319       && ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) < m_pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     4320    {
     4321      if ( ( uiAbsPartIdx % numPartInCtuWidth < numPartInCtuWidth - 1 ) &&  // is not at the last column of CTU
     4322           ( uiAbsPartIdx / numPartInCtuWidth < numPartInCtuHeight - 1 ) )  // is not at the last row    of CTU
     4323      {
     4324        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + numPartInCtuWidth + 1 ];
     4325        ctuRsAddr = getCtuRsAddr();
     4326      }
     4327      else if ( uiAbsPartIdx % numPartInCtuWidth < numPartInCtuWidth - 1 )  // is not at the last column of CTU But is last row of CTU
     4328      {
     4329        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + numPartInCtuWidth + 1) % m_pcPic->getNumPartitionsInCtu() ];
     4330      }
     4331      else if ( uiAbsPartIdx / numPartInCtuWidth < numPartInCtuHeight - 1 ) // is not at the last row of CTU But is last column of CTU
     4332      {
     4333        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
     4334        ctuRsAddr = getCtuRsAddr() + 1;
     4335      }
     4336      else //is the right bottom corner of CTU
     4337      {
     4338        uiAbsPartAddr = 0;
     4339      }
     4340    }
     4341    if ( ctuRsAddr >= 0 && xGetColMVP( eRefPicList, ctuRsAddr, uiAbsPartAddr, cColMv, iRefIdx_Col
     4342#if NH_3D_TMVP
     4343         , 0
     4344#endif
     4345 ) )
     4346    {
     4347      pInfo->m_acMvCand[pInfo->iN++] = cColMv;
    51944348    }
    51954349    else
    51964350    {
    5197       if ( ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
    5198         ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
    5199       {
    5200         uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth + 1 ];
    5201         uiLCUIdx = getAddr();
    5202       }
    5203       else if ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
    5204       {
    5205         uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
    5206       }
    5207       else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
    5208       {
    5209         uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
    5210         uiLCUIdx = getAddr() + 1;
    5211       }
    5212       else //is the right bottom corner of LCU                       
    5213       {
    5214         uiAbsPartAddr = 0;
    5215       }
    5216     }
    5217     if ( uiLCUIdx >= 0 && xGetColMVP( eRefPicList, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx_Col
    5218 #if H_3D_TMVP
     4351      UInt uiPartIdxCenter;
     4352      xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
     4353      if (xGetColMVP( eRefPicList, getCtuRsAddr(), uiPartIdxCenter,  cColMv, iRefIdx_Col
     4354#if NH_3D_TMVP
    52194355         , 0
    52204356#endif
    5221     ) )
    5222     {
    5223       pInfo->m_acMvCand[pInfo->iN++] = cColMv;
    5224     }
    5225     else
    5226     {
    5227       UInt uiPartIdxCenter;
    5228       UInt uiCurLCUIdx = getAddr();
    5229       xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
    5230       if (xGetColMVP( eRefPicList, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx_Col
    5231 #if H_3D_TMVP
    5232          , 0
    5233 #endif
    5234       ))
     4357))
    52354358      {
    52364359        pInfo->m_acMvCand[pInfo->iN++] = cColMv;
     
    52444367    pInfo->iN = AMVP_MAX_NUM_CANDS;
    52454368  }
     4369
    52464370  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
    52474371  {
    5248       pInfo->m_acMvCand[pInfo->iN].set(0,0);
    5249       pInfo->iN++;
     4372    pInfo->m_acMvCand[pInfo->iN].set(0,0);
     4373    pInfo->iN++;
    52504374  }
    52514375  return ;
    52524376}
     4377
    52534378
    52544379Bool TComDataCU::isBipredRestriction(UInt puIdx)
     
    52574382  Int height = 0;
    52584383  UInt partAddr;
    5259  
    5260 #if H_3D_DBBP
     4384
     4385#if NH_3D_DBBP
    52614386  if( getDBBPFlag(0) )
    52624387  {
     
    52734398}
    52744399
     4400
    52754401Void TComDataCU::clipMv    (TComMv&  rcMv)
    52764402{
     4403  const TComSPS &sps=*(m_pcSlice->getSPS());
    52774404  Int  iMvShift = 2;
    5278 #if H_3D_IC
     4405#if NH_3D_INTEGER_MV_DEPTH
    52794406  if( getSlice()->getIsDepth() )
    52804407    iMvShift = 0;
    52814408#endif
     4409
    52824410  Int iOffset = 8;
    5283   Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
    5284   Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
    5285  
    5286   Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
    5287   Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
    5288  
     4411  Int iHorMax = ( sps.getPicWidthInLumaSamples() + iOffset - (Int)m_uiCUPelX - 1 ) << iMvShift;
     4412  Int iHorMin = (      -(Int)sps.getMaxCUWidth() - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
     4413
     4414  Int iVerMax = ( sps.getPicHeightInLumaSamples() + iOffset - (Int)m_uiCUPelY - 1 ) << iMvShift;
     4415  Int iVerMin = (      -(Int)sps.getMaxCUHeight() - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
     4416
    52894417  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
    52904418  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
    52914419}
    52924420
    5293 #if H_MV
     4421#if NH_MV
    52944422Void TComDataCU::checkMvVertRest (TComMv&  rcMv,  RefPicList eRefPicList, int iRefIdx )
    52954423{
     
    53104438{
    53114439  UInt uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
    5312  
     4440
    53134441  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
    53144442  UInt  uiCnt = 0;
     
    53224450}
    53234451
    5324 Void TComDataCU::clearCbf( UInt uiIdx, TextType eType, UInt uiNumParts )
    5325 {
    5326   ::memset( &m_puhCbf[g_aucConvertTxtTypeToIdx[eType]][uiIdx], 0, sizeof(UChar)*uiNumParts);
     4452Void TComDataCU::clearCbf( UInt uiIdx, ComponentID compID, UInt uiNumParts )
     4453{
     4454  memset( &m_puhCbf[compID][uiIdx], 0, sizeof(UChar)*uiNumParts);
    53274455}
    53284456
     
    53354463Void TComDataCU::setIPCMFlagSubParts  (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
    53364464{
    5337   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
     4465  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
    53384466
    53394467  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
    53404468}
    53414469
    5342 /** Test whether the current block is skipped
    5343  * \param uiPartIdx Block index
    5344  * \returns Flag indicating whether the block is skipped
     4470/** Test whether the block at uiPartIdx is skipped.
     4471 * \param uiPartIdx Partition index
     4472 * \returns true if the current the block is skipped
    53454473 */
    53464474Bool TComDataCU::isSkipped( UInt uiPartIdx )
     
    53484476  return ( getSkipFlag( uiPartIdx ) );
    53494477}
    5350 
    5351 #if H_3D_IC
    5352 Bool TComDataCU::isIC( UInt uiPartIdx )
    5353 {
    5354     if ( m_pcSlice->isIntra () )
    5355     {
    5356         return false;
    5357     }
    5358     return ( ( getSkipFlag(uiPartIdx) || getPredictionMode(uiPartIdx) == MODE_INTER) && getICFlag( uiPartIdx ) && isICFlagRequired( uiPartIdx ) );
    5359 }
    5360 #endif
    53614478
    53624479// ====================================================================================================================
     
    53774494    case MD_ABOVE:
    53784495    {
    5379       pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx );
     4496      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
    53804497      break;
    53814498    }
     
    54054522    return false;
    54064523  }
    5407  
     4524
    54084525  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
    54094526  {
    54104527    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
    5411    
     4528
    54124529    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
    54134530    return true;
     
    54424559}
    54434560
    5444 /** 
     4561/**
    54454562 * \param pInfo
    5446  * \param eRefPicList 
     4563 * \param eRefPicList
    54474564 * \param iRefIdx
    54484565 * \param uiPartUnitIdx
     
    54874604  }
    54884605
    5489   if ( pcTmpCU == NULL ) 
     4606  if ( pcTmpCU == NULL )
    54904607  {
    54914608    return false;
    54924609  }
    5493  
     4610
    54944611  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
    54954612  if(       eRefPicList == REF_PIC_LIST_0 )
     
    55064623  Int iNeibPOC = iCurrPOC;
    55074624  Int iNeibRefPOC;
    5508 
    55094625  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
    55104626  Bool bIsNeibRefLongTerm = false;
     4627
    55114628  //---------------  V1 (END) ------------------//
    55124629  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
     
    55174634
    55184635    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
    5519     if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm )
    5520     {
    5521     if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
    5522     {
    5523       rcMv = cMvPred;
    5524     }
    5525     else
    5526     {
    5527       Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
    5528       if ( iScale == 4096 )
     4636    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm )
     4637    {
     4638      if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
    55294639      {
    55304640        rcMv = cMvPred;
     
    55324642      else
    55334643      {
    5534         rcMv = cMvPred.scaleMv( iScale );
    5535       }
    5536     }
    5537     pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
    5538     return true;
     4644        Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
     4645        if ( iScale == 4096 )
     4646        {
     4647          rcMv = cMvPred;
     4648        }
     4649        else
     4650        {
     4651          rcMv = cMvPred.scaleMv( iScale );
     4652        }
     4653      }
     4654
     4655      pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
     4656      return true;
    55394657    }
    55404658  }
     
    55474665
    55484666    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
    5549     if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm )
    5550     {
    5551     if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
    5552     {
    5553       rcMv = cMvPred;
    5554     }
    5555     else
    5556     {
    5557       Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
    5558       if ( iScale == 4096 )
     4667    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm )
     4668    {
     4669      if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
    55594670      {
    55604671        rcMv = cMvPred;
     
    55624673      else
    55634674      {
    5564         rcMv = cMvPred.scaleMv( iScale );
    5565       }
    5566     }
    5567     pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
    5568     return true;
     4675        Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
     4676        if ( iScale == 4096 )
     4677        {
     4678          rcMv = cMvPred;
     4679        }
     4680        else
     4681        {
     4682          rcMv = cMvPred.scaleMv( iScale );
     4683        }
     4684      }
     4685
     4686      pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
     4687      return true;
    55694688    }
    55704689  }
     
    55734692}
    55744693
    5575 /**
    5576  * \param eRefPicList
    5577  * \param uiCUAddr
    5578  * \param uiPartUnitIdx
    5579  * \param riRefIdx
    5580  * \returns Bool
    5581  */
    5582 Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx
    5583 #if H_3D_TMVP
     4694Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int ctuRsAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx
     4695#if NH_3D_TMVP
    55844696  , Bool bMRG
    55854697#endif
    5586   )
     4698)
    55874699{
    55884700  UInt uiAbsPartAddr = uiPartUnitIdx;
     
    55944706  // use coldir.
    55954707  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
    5596   TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
    5597   if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
     4708  TComDataCU *pColCtu = pColPic->getCtu( ctuRsAddr );
     4709  if(pColCtu->getPic()==0||pColCtu->getPartitionSize(uiPartUnitIdx)==NUMBER_OF_PART_SIZES)
    55984710  {
    55994711    return false;
    56004712  }
    5601   iCurrPOC = m_pcSlice->getPOC();   
    5602   iColPOC = pColCU->getSlice()->getPOC(); 
    5603 
    5604   if (pColCU->isIntra(uiAbsPartAddr))
     4713  iCurrPOC = m_pcSlice->getPOC();
     4714  iColPOC = pColCtu->getSlice()->getPOC();
     4715
     4716  if (!pColCtu->isInter(uiAbsPartAddr))
    56054717  {
    56064718    return false;
    56074719  }
     4720
    56084721  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
    56094722
    5610   Int iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
     4723  Int iColRefIdx = pColCtu->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
    56114724
    56124725  if (iColRefIdx < 0 )
    56134726  {
    56144727    eColRefPicList = RefPicList(1 - eColRefPicList);
    5615     iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
     4728    iColRefIdx = pColCtu->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
    56164729
    56174730    if (iColRefIdx < 0 )
     
    56224735
    56234736  // Scale the vector.
    5624   iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
    5625   cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
     4737  iColRefPOC = pColCtu->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
     4738  cColMv = pColCtu->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
    56264739
    56274740  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
     4741
    56284742  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
    5629   Bool bIsColRefLongTerm = pColCU->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
    5630 
    5631   if ( bIsCurrRefLongTerm != bIsColRefLongTerm ) 
    5632   {
    5633 #if H_3D_TMVP
     4743  Bool bIsColRefLongTerm = pColCtu->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
     4744
     4745  if ( bIsCurrRefLongTerm != bIsColRefLongTerm )
     4746  {
     4747#if NH_3D_TMVP
    56344748    Int iAlterRefIdx  = m_pcSlice->getAlterRefIdx(eRefPicList);
    56354749    if(bMRG && iAlterRefIdx > 0)
     
    56434757    {
    56444758#endif
    5645       return false;
    5646 #if H_3D_TMVP
     4759    return false;
     4760#if NH_3D_TMVP
    56474761    }
    56484762#endif
     
    56514765  if ( bIsCurrRefLongTerm || bIsColRefLongTerm )
    56524766  {
    5653 #if H_3D_TMVP
     4767#if NH_3D_TMVP
    56544768    Int iCurrViewId    = m_pcSlice->getViewId ();
    56554769    Int iCurrRefViewId = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewId ();
    5656     Int iColViewId     = pColCU->getSlice()->getViewId();
    5657     Int iColRefViewId  = pColCU->getSlice()->getRefPic( eColRefPicList, pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewId();
     4770    Int iColViewId     = pColCtu->getSlice()->getViewId();
     4771    Int iColRefViewId  = pColCtu->getSlice()->getRefPic( eColRefPicList, pColCtu->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewId();
    56584772    iScale = 4096;
    56594773    if ( iCurrRefViewId != iCurrViewId && iColViewId != iColRefViewId )
     
    56684782    {
    56694783#endif
    5670        rcMv = cColMv;
    5671 #if H_3D_TMVP
     4784    rcMv = cColMv;
     4785#if NH_3D_TMVP
    56724786    }
    56734787#endif
     
    56854799    }
    56864800  }
     4801
    56874802  return true;
    56884803}
    5689 
    5690 UInt TComDataCU::xGetMvdBits(TComMv cMvd)
    5691 {
    5692   return ( xGetComponentBits(cMvd.getHor()) + xGetComponentBits(cMvd.getVer()) );
    5693 }
    5694 
    5695 UInt TComDataCU::xGetComponentBits(Int iVal)
    5696 {
    5697   UInt uiLength = 1;
    5698   UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
    5699  
    5700   assert ( uiTemp );
    5701  
    5702   while ( 1 != uiTemp )
    5703   {
    5704     uiTemp >>= 1;
    5705     uiLength += 2;
    5706   }
    5707  
    5708   return uiLength;
    5709 }
    5710 
    57114804
    57124805Int TComDataCU::xGetDistScaleFactor(Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC)
     
    57144807  Int iDiffPocD = iColPOC - iColRefPOC;
    57154808  Int iDiffPocB = iCurrPOC - iCurrRefPOC;
    5716  
     4809
    57174810  if( iDiffPocD == iDiffPocB )
    57184811  {
     
    57294822}
    57304823
    5731 /**
    5732  * \param eCUMode
    5733  * \param uiPartIdx
    5734  * \param ruiPartIdxCenter
    5735  * \returns Void
    5736  */
    57374824Void TComDataCU::xDeriveCenterIdx( UInt uiPartIdx, UInt& ruiPartIdxCenter )
    57384825{
     
    57414828  Int  iPartHeight;
    57424829  getPartIndexAndSize( uiPartIdx, uiPartAddr, iPartWidth, iPartHeight);
    5743  
    5744   ruiPartIdxCenter = m_uiAbsIdxInLCU+uiPartAddr; // partition origin.
     4830
     4831  ruiPartIdxCenter = m_absZIdxInCtu+uiPartAddr; // partition origin.
    57454832  ruiPartIdxCenter = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxCenter ]
    5746                                         + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInWidth()
     4833                                        + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInCtuWidth()
    57474834                                        + ( iPartWidth/m_pcPic->getMinCUWidth()  )/2];
    57484835}
    5749 #if H_3D
     4836
     4837#if NH_3D
    57504838Void TComDataCU::compressMV(Int scale)
     4839{
     4840   Int scaleFactor = (4 / scale ) * AMVP_DECIMATION_FACTOR / m_unitSize;
    57514841#else
    57524842Void TComDataCU::compressMV()
    5753 #endif
    5754 {
    5755 #if H_3D
    5756   Int scaleFactor = (4 / scale ) * AMVP_DECIMATION_FACTOR / m_unitSize;
    5757 #else
     4843{
    57584844  Int scaleFactor = 4 * AMVP_DECIMATION_FACTOR / m_unitSize;
    57594845#endif
    57604846  if (scaleFactor > 0)
    57614847  {
    5762     m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
    5763     m_acCUMvField[1].compress(m_pePredMode, scaleFactor);   
    5764   }
    5765 }
    5766 
    5767 UInt TComDataCU::getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra)
    5768 {
    5769   UInt uiCTXIdx;
    5770   UInt uiScanIdx;
    5771   UInt uiDirMode;
    5772 
    5773   if ( !bIsIntra )
    5774   {
    5775     uiScanIdx = SCAN_DIAG;
    5776     return uiScanIdx;
    5777   }
    5778 
    5779   switch(uiWidth)
    5780   {
    5781     case  2: uiCTXIdx = 6; break;
    5782     case  4: uiCTXIdx = 5; break;
    5783     case  8: uiCTXIdx = 4; break;
    5784     case 16: uiCTXIdx = 3; break;
    5785     case 32: uiCTXIdx = 2; break;
    5786     case 64: uiCTXIdx = 1; break;
    5787     default: uiCTXIdx = 0; break;
    5788   }
    5789 
    5790   if ( bIsLuma )
    5791   {
    5792     uiDirMode = getLumaIntraDir(uiAbsPartIdx);
    5793 #if H_3D_DIM
    5794     mapDepthModeToIntraDir( uiDirMode );
    5795 #endif
    5796     uiScanIdx = SCAN_DIAG;
    5797     if (uiCTXIdx >3 && uiCTXIdx < 6) //if multiple scans supported for transform size
    5798     {
    5799       uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
    5800     }
     4848    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     4849    {
     4850      m_acCUMvField[i].compress(m_pePredMode, scaleFactor);
     4851    }
     4852  }
     4853}
     4854
     4855UInt TComDataCU::getCoefScanIdx(const UInt uiAbsPartIdx, const UInt uiWidth, const UInt uiHeight, const ComponentID compID) const
     4856{
     4857  //------------------------------------------------
     4858
     4859  //this mechanism is available for intra only
     4860
     4861  if (!isIntra(uiAbsPartIdx))
     4862  {
     4863    return SCAN_DIAG;
     4864  }
     4865
     4866  //------------------------------------------------
     4867
     4868  //check that MDCS can be used for this TU
     4869
     4870  const ChromaFormat format = getPic()->getChromaFormat();
     4871
     4872  const UInt maximumWidth  = MDCS_MAXIMUM_WIDTH  >> getComponentScaleX(compID, format);
     4873  const UInt maximumHeight = MDCS_MAXIMUM_HEIGHT >> getComponentScaleY(compID, format);
     4874
     4875  if ((uiWidth > maximumWidth) || (uiHeight > maximumHeight))
     4876  {
     4877    return SCAN_DIAG;
     4878  }
     4879
     4880  //------------------------------------------------
     4881
     4882  //otherwise, select the appropriate mode
     4883
     4884  UInt uiDirMode  = getIntraDir(toChannelType(compID), uiAbsPartIdx);
     4885#if NH_3D_DMM
     4886  mapDmmToIntraDir( uiDirMode );
     4887#endif
     4888
     4889  if (uiDirMode==DM_CHROMA_IDX)
     4890  {
     4891    const TComSPS *sps=getSlice()->getSPS();
     4892    const UInt partsPerMinCU = 1<<(2*(sps->getMaxTotalCUDepth() - sps->getLog2DiffMaxMinCodingBlockSize()));
     4893    uiDirMode = getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, getPic()->getChromaFormat(), partsPerMinCU));
     4894#if NH_3D_DMM
     4895    mapDmmToIntraDir( uiDirMode );
     4896#endif
     4897  }
     4898
     4899  if (isChroma(compID) && (format == CHROMA_422))
     4900  {
     4901    uiDirMode = g_chroma422IntraAngleMappingTable[uiDirMode];
     4902  }
     4903
     4904  //------------------
     4905
     4906  if      (abs((Int)uiDirMode - VER_IDX) <= MDCS_ANGLE_LIMIT)
     4907  {
     4908    return SCAN_HOR;
     4909  }
     4910  else if (abs((Int)uiDirMode - HOR_IDX) <= MDCS_ANGLE_LIMIT)
     4911  {
     4912    return SCAN_VER;
    58014913  }
    58024914  else
    58034915  {
    5804     uiDirMode = getChromaIntraDir(uiAbsPartIdx);
    5805     if( uiDirMode == DM_CHROMA_IDX )
    5806     {
    5807       // get number of partitions in current CU
    5808       UInt depth = getDepth(uiAbsPartIdx);
    5809       UInt numParts = getPic()->getNumPartInCU() >> (2 * depth);
    5810      
    5811       // get luma mode from upper-left corner of current CU
    5812       uiDirMode = getLumaIntraDir((uiAbsPartIdx/numParts)*numParts);
    5813 #if H_3D_DIM
    5814       mapDepthModeToIntraDir( uiDirMode );
    5815 #endif
    5816     }
    5817     uiScanIdx = SCAN_DIAG;
    5818     if (uiCTXIdx >4 && uiCTXIdx < 7) //if multiple scans supported for transform size
    5819     {
    5820       uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
    5821     }
    5822   }
    5823 
    5824   return uiScanIdx;
    5825 }
    5826 
    5827 UInt TComDataCU::getSCUAddr()
    5828 {
    5829   return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU;
    5830 }
    5831 
    5832 #if H_3D
    5833 Void TComDataCU::getPosInPic( UInt uiAbsPartIndex, Int& riPosX, Int& riPosY )
     4916    return SCAN_DIAG;
     4917  }
     4918}
     4919
     4920#if NH_3D_VSO
     4921Void TComDataCU::getPosInPic( UInt uiAbsPartIndex, Int& riPosX, Int& riPosY ) const
    58344922{
    58354923  riPosX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelX();
     
    58384926#endif
    58394927
    5840 #if H_3D_IV_MERGE
     4928#if NH_3D_IV_MERGE
    58414929Void TComDataCU::getDispforDepth (UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDisp)
    58424930{
     
    58484936    Int iViewIdx = getSlice()->getDefaultRefViewIdx();
    58494937    pDisp->m_aVIdxCan = iViewIdx;
    5850     Int iDisp     = getSlice()->getDepthToDisparityB( iViewIdx )[ (Int64) (1 << ( getSlice()->getSPS()->getBitDepthY() - 1 )) ];
     4938    Int iDisp     = getSlice()->getDepthToDisparityB( iViewIdx )[ (Int64) (1 << ( getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) - 1 )) ];
    58514939
    58524940    cMv.setHor(iDisp);
     
    58584946#endif
    58594947
    5860 #if H_3D
     4948#if NH_3D_DIS
    58614949Bool TComDataCU::getNeighDepth ( UInt uiPartIdx, UInt uiPartAddr, Pel* pNeighDepth, Int index )
    58624950{
    5863   UInt  uiPartIdxLT, uiPartIdxRT;
    5864   this->deriveLeftRightTopIdxAdi( uiPartIdxLT, uiPartIdxRT, 0, 0 );
     4951  assert(uiPartIdx==0);
     4952  const UInt uiPartIdxLT      = getZorderIdxInCtu() + uiPartAddr;
     4953  const Int  iPartIdxStride   = getPic()->getNumPartInCtuWidth();
     4954 
    58654955  UInt uiMidPart, uiPartNeighbor; 
    58664956  TComDataCU* pcCUNeighbor;
    58674957  Bool bDepAvail = false;
    5868   Pel *pDepth  = this->getPic()->getPicYuvRec()->getLumaAddr();
    5869   Int iDepStride =  this->getPic()->getPicYuvRec()->getStride();
     4958  Pel *pDepth  = this->getPic()->getPicYuvRec()->getAddr(COMPONENT_Y);
     4959  Int iDepStride =  this->getPic()->getPicYuvRec()->getStride(COMPONENT_Y);
    58704960
    58714961  Int xP, yP, nPSW, nPSH;
     
    58754965  {
    58764966  case 0: // Mid Left
    5877     uiMidPart = g_auiZscanToRaster[uiPartIdxLT] + (nPSH>>1) / this->getPic()->getMinCUHeight() * this->getPic()->getNumPartInWidth();
     4967    uiMidPart = g_auiZscanToRaster[uiPartIdxLT] + (nPSH>>1) / this->getPic()->getMinCUHeight() * iPartIdxStride;
    58784968    pcCUNeighbor = this->getPULeft( uiPartNeighbor, g_auiRasterToZscan[uiMidPart] );
    58794969    if ( pcCUNeighbor )
     
    59155005}
    59165006#endif
    5917 #if H_3D_NBDV
     5007#if NH_3D_NBDV
    59185008//Notes from QC:
    5919 //TBD#1: DoNBDV related contributions are just partially integrated under the marco of H_3D_NBDV_REF, remove this comment once DoNBDV and BVSP are done
     5009//TBD#1: DoNBDV related contributions are just partially integrated under the marco of NH_3D_NBDV_REF, remove this comment once DoNBDV and BVSP are done
    59205010//TBD#2: set of DvMCP values need to be done as part of inter-view motion prediction process. Remove this comment once merge related integration is done
    59215011//To be checked: Parallel Merge features for NBDV, related to DV_DERIVATION_PARALLEL_B0096 and LGE_IVMP_PARALLEL_MERGE_B0136 are not integrated. The need of these features due to the adoption of CU-based NBDV is not clear. We need confirmation on this, especially by proponents
    59225012Void TComDataCU::getDisMvpCandNBDV( DisInfo* pDInfo
    5923 #if H_3D_NBDV_REF
     5013#if NH_3D_NBDV_REF
    59245014, Bool bDepthRefine
    59255015#endif
     
    59445034    }
    59455035  }
    5946 #if H_3D_NBDV_REF
     5036#if NH_3D_NBDV_REF
    59475037  if( !m_pcSlice->getDepthRefinementFlag( ) )
    59485038  {
     
    59675057    ///*** Derive center position ***
    59685058    UInt uiPartIdxCenter;
    5969     Int  uiLCUIdx   = getAddr();
     5059    Int  uiLCUIdx = getCtuRsAddr();
    59705060    xDeriveCenterIdx(uiPartIdx, uiPartIdxCenter );
    59715061
     
    59945084        pDInfo->m_aVIdxCan  = iTargetViewIdx;
    59955085
    5996 #if H_3D_NBDV_REF
     5086#if NH_3D_NBDV_REF
    59975087        TComPic* picDepth = NULL;   
    59985088#if H_3D_FCO_VSP_DONBDV_E0163
     
    60165106        }
    60175107        pDInfo->m_acDoNBDV  = cColMv;
    6018 #endif //H_3D_NBDV_REF
     5108#endif //NH_3D_NBDV_REF
    60195109        return;
    60205110      }
     
    60305120  bCheckMcpDv = true;
    60315121  if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFT
    6032 #if H_3D_NBDV_REF
     5122#if NH_3D_NBDV_REF
    60335123    , bDepthRefine
    60345124#endif
     
    60405130  if(pcTmpCU != NULL )
    60415131  {
    6042     bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
     5132    bCheckMcpDv = ( ( getCtuRsAddr() - pcTmpCU->getCtuRsAddr() ) == 0);
    60435133    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVE
    6044 #if H_3D_NBDV_REF
     5134#if NH_3D_NBDV_REF
    60455135      , bDepthRefine
    60465136#endif
     
    60615151          pDInfo->m_acNBDV = cDispVec;
    60625152          pDInfo->m_aVIdxCan = cIDVInfo.m_aVIdxCan[iList][ curPos ];
    6063 #if H_3D_NBDV_REF
     5153#if NH_3D_NBDV_REF
    60645154#if H_3D_FCO_VSP_DONBDV_E0163
    60655155          TComPic* picDepth  = NULL;
     
    60995189    pDInfo->m_aVIdxCan = getSlice()->getDefaultRefViewIdx();
    61005190
    6101 #if H_3D_NBDV_REF
     5191#if NH_3D_NBDV_REF
    61025192    TComPic* picDepth = NULL;
    61035193#if H_3D_FCO_VSP_DONBDV_E0163
     
    61255215}
    61265216
    6127 #if H_3D_NBDV_REF
     5217#if NH_3D_NBDV_REF
    61285218Pel TComDataCU::getMcpFromDM(TComPicYuv* pcBaseViewDepthPicYuv, TComMv* mv, Int iBlkX, Int iBlkY, Int iBlkWidth, Int iBlkHeight, Int* aiShiftLUT )
    61295219{
    6130   Int iPictureWidth  = pcBaseViewDepthPicYuv->getWidth();
    6131   Int iPictureHeight = pcBaseViewDepthPicYuv->getHeight();
    6132  
     5220  Int iPictureWidth  = pcBaseViewDepthPicYuv->getWidth(COMPONENT_Y);
     5221  Int iPictureHeight = pcBaseViewDepthPicYuv->getHeight(COMPONENT_Y);
     5222
    61335223  Int depthStartPosX = Clip3(0,   iPictureWidth - 1,  iBlkX + ((mv->getHor()+2)>>2));
    61345224  Int depthStartPosY = Clip3(0,   iPictureHeight - 1, iBlkY + ((mv->getVer()+2)>>2));
     
    61365226  Int depthEndPosY   = Clip3(0,   iPictureHeight - 1, iBlkY + iBlkHeight - 1 + ((mv->getVer()+2)>>2));
    61375227
    6138   Pel* depthTL  = pcBaseViewDepthPicYuv->getLumaAddr();
    6139   Int depStride =  pcBaseViewDepthPicYuv->getStride();
     5228  Pel* depthTL  = pcBaseViewDepthPicYuv->getAddr(COMPONENT_Y);
     5229  Int depStride =  pcBaseViewDepthPicYuv->getStride(COMPONENT_Y);
    61405230
    61415231  Pel  maxDepthVal = 0;
     
    61525242  if (picDepth)
    61535243  {
    6154     UInt uiAbsPartAddrCurrCU = m_uiAbsIdxInLCU + uiPartAddr;
     5244    UInt uiAbsPartAddrCurrCU = m_absZIdxInCtu + uiPartAddr;
    61555245    Int iWidth, iHeight;
    61565246    getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight ); // The modified value of uiPartAddr won't be used any more
    61575247
    61585248    TComPicYuv* pcBaseViewDepthPicYuv = picDepth->getPicYuvRec();
    6159     Int iBlkX = ( getAddr() % picDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
    6160     Int iBlkY = ( getAddr() / picDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
     5249    const TComSPS   &sps =*(getSlice()->getSPS());
     5250    Int iBlkX = ( getCtuRsAddr() % picDepth->getFrameWidthInCtus() ) * sps.getMaxCUWidth()  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
     5251    Int iBlkY = ( getCtuRsAddr() / picDepth->getFrameWidthInCtus() ) * sps.getMaxCUHeight() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
    61615252
    61625253    Int* aiShiftLUT = getSlice()->getDepthToDisparityB(refViewIdx );
     
    61665257  }
    61675258}
    6168 #endif //H_3D_NBDV_REF
     5259#endif //NH_3D_NBDV_REF
    61695260
    61705261
    61715262Bool TComDataCU::xCheckSpatialNBDV( TComDataCU* pcTmpCU, UInt uiIdx, DisInfo* pNbDvInfo, Bool bSearchForMvpDv, IDVInfo* paIDVInfo, UInt uiMvpDvPos
    6172 #if H_3D_NBDV_REF
     5263#if NH_3D_NBDV_REF
    61735264, Bool bDepthRefine
    61745265#endif
     
    61915282          pNbDvInfo->m_acNBDV = cMvPred;
    61925283          pNbDvInfo->m_aVIdxCan = refViewIdx;
    6193 #if H_3D_NBDV_REF
     5284#if NH_3D_NBDV_REF
    61945285          TComPic* picDepth = NULL;
    61955286          assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());         
     
    62375328{
    62385329  UInt uiPartIdx = 0;
    6239   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth(); 
    6240   Int uiLCUIdx = getAddr();
     5330  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInCtuWidth(); 
     5331  Int uiLCUIdx = getCtuRsAddr();
    62415332
    62425333  UInt uiPartIdxRB;
     
    62445335  UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
    62455336
    6246   if (( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() )>= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
     5337  if (( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() )>= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
    62475338  {
    62485339    riLCUIdxRBNb  = -1;
    62495340    riPartIdxRBNb = -1;
    62505341  }
    6251   else if(( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() )>= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
     5342  else if(( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() )>= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
    62525343  {
    62535344    riLCUIdxRBNb  = -1;
     
    62575348  {
    62585349    if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
    6259       ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
     5350      ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInCtuHeight() - 1 ) ) // is not at the last row    of LCU
    62605351    {
    62615352      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
     
    62675358      riLCUIdxRBNb  = -1;
    62685359    }
    6269     else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
     5360    else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInCtuHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
    62705361    {
    62715362      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
     
    62835374Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiDepth )
    62845375{
    6285   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
     5376#if NH_3D_VSP // bug fix
     5377  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     5378  assert(m_pcPic->getNumPartitionsInCtu() ==m_pcPic->getNumPartInCtuWidth()*m_pcPic->getNumPartInCtuHeight());
     5379
     5380#else
     5381  UInt uiCurrPartNumb = m_pcPic->getNumPartInCtuWidth() >> (uiDepth << 1);
     5382#endif
    62865383  for (UInt ui = 0; ui < uiCurrPartNumb; ui++ )
    62875384  {
     
    62895386  }
    62905387}
    6291 #if H_3D_VSP
     5388#if NH_3D_VSP  || NH_3D_DBBP
    62925389Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth )
    62935390{
     
    63025399  Int iColViewIdx, iColRefViewIdx;
    63035400  TComPic *pColPic = getSlice()->getRefPic( eRefPicList, refidx);
    6304   TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
     5401  TComDataCU *pColCU = pColPic->getCtu( uiCUAddr );
    63055402  iColViewIdx = pColCU->getSlice()->getViewIndex();
    6306   if (pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE||pColCU->isIntra(uiPartUnitIdx))
     5403  if (pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==NUMBER_OF_PART_SIZES||pColCU->isIntra(uiPartUnitIdx))
    63075404  {
    63085405    return false;
     
    63445441}
    63455442#endif
    6346 #if  H_3D_FAST_TEXTURE_ENCODING
     5443#if  NH_3D_FAST_TEXTURE_ENCODING
    63475444Void
    63485445TComDataCU::getIVNStatus       ( UInt uiPartIdx,  DisInfo* pDInfo, Bool& bIVFMerge, Int& iIVFMaxD)
     
    63605457
    63615458  Int  iCurrPosX, iCurrPosY;
    6362   pcBaseRec->getTopLeftSamplePos( getAddr(), getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
     5459  pcBaseRec->getTopLeftSamplePos( this->getCtuRsAddr(), this->getZorderIdxInCtu() + uiPartAddr, iCurrPosX, iCurrPosY );
    63635460
    63645461  iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
     
    63665463
    63675464  Bool depthRefineFlag = false;
    6368 #if H_3D_NBDV_REF
     5465#if NH_3D_NBDV_REF
    63695466  depthRefineFlag = m_pcSlice->getDepthRefinementFlag( );
    6370 #endif // H_3D_NBDV_REF
     5467#endif // NH_3D_NBDV_REF
    63715468
    63725469  TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV;
     
    63765473  }
    63775474
    6378   Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
    6379   Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 ));
    6380   Int         iBaseLPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX - (iWidth >> 1) + ( (cDv.getHor() + 2 ) >> 2 ) );
    6381   Int         iBaseLPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 ));
    6382   Int         iBaseRPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + (iWidth >> 1) + 1 + ( (cDv.getHor() + 2 ) >> 2 ) );
    6383   Int         iBaseRPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 ));
    6384   Int         iBaseUPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
    6385   Int         iBaseUPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY - (iHeight >> 1) + ( (cDv.getVer() + 2 ) >> 2 ));
    6386   Int         iBaseDPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
    6387   Int         iBaseDPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + (iHeight >> 1) + 1 + ( (cDv.getVer() + 2 ) >> 2 ));
     5475  Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth (COMPONENT_Y) - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
     5476  Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight(COMPONENT_Y) - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 ));
     5477  Int         iBaseLPosX   = Clip3( 0, pcBaseRec->getWidth (COMPONENT_Y) - 1, iCurrPosX - (iWidth >> 1) + ( (cDv.getHor() + 2 ) >> 2 ) );
     5478  Int         iBaseLPosY   = Clip3( 0, pcBaseRec->getHeight(COMPONENT_Y) - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 ));
     5479  Int         iBaseRPosX   = Clip3( 0, pcBaseRec->getWidth (COMPONENT_Y) - 1, iCurrPosX + (iWidth >> 1) + 1 + ( (cDv.getHor() + 2 ) >> 2 ) );
     5480  Int         iBaseRPosY   = Clip3( 0, pcBaseRec->getHeight(COMPONENT_Y) - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 ));
     5481  Int         iBaseUPosX   = Clip3( 0, pcBaseRec->getWidth (COMPONENT_Y) - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
     5482  Int         iBaseUPosY   = Clip3( 0, pcBaseRec->getHeight(COMPONENT_Y) - 1, iCurrPosY - (iHeight >> 1) + ( (cDv.getVer() + 2 ) >> 2 ));
     5483  Int         iBaseDPosX   = Clip3( 0, pcBaseRec->getWidth (COMPONENT_Y) - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
     5484  Int         iBaseDPosY   = Clip3( 0, pcBaseRec->getHeight(COMPONENT_Y) - 1, iCurrPosY + (iHeight >> 1) + 1 + ( (cDv.getVer() + 2 ) >> 2 ));
    63885485
    63895486  Int         iBaseCUAddr;
     
    64025499  pcBaseRec->getCUAddrAndPartIdx( iBaseUPosX , iBaseUPosY , iBaseUCUAddr, iBaseUAbsPartIdx );
    64035500  pcBaseRec->getCUAddrAndPartIdx( iBaseDPosX , iBaseDPosY , iBaseDCUAddr, iBaseDAbsPartIdx );
    6404   TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
    6405   TComDataCU* pcBaseLCU    = pcBasePic->getCU( iBaseLCUAddr );
    6406   TComDataCU* pcBaseRCU    = pcBasePic->getCU( iBaseRCUAddr );
    6407   TComDataCU* pcBaseUCU    = pcBasePic->getCU( iBaseUCUAddr );
    6408   TComDataCU* pcBaseDCU    = pcBasePic->getCU( iBaseDCUAddr );
     5501  TComDataCU* pcBaseCU     = pcBasePic->getCtu( iBaseCUAddr );
     5502  TComDataCU* pcBaseLCU    = pcBasePic->getCtu( iBaseLCUAddr );
     5503  TComDataCU* pcBaseRCU    = pcBasePic->getCtu( iBaseRCUAddr );
     5504  TComDataCU* pcBaseUCU    = pcBasePic->getCtu( iBaseUCUAddr );
     5505  TComDataCU* pcBaseDCU    = pcBasePic->getCtu( iBaseDCUAddr );
    64095506  bIVFMerge = pcBaseLCU->getMergeFlag( iBaseLAbsPartIdx ) && pcBaseCU->getMergeFlag( iBaseAbsPartIdx ) && pcBaseRCU->getMergeFlag( iBaseRAbsPartIdx ) && pcBaseUCU->getMergeFlag( iBaseUAbsPartIdx ) && pcBaseDCU->getMergeFlag( iBaseDAbsPartIdx );
    64105507  Int aiDepthL[5]; //depth level
     
    64225519#endif
    64235520
    6424 #if H_3D_SPIVMP
     5521#if NH_3D_SPIVMP
    64255522Void TComDataCU::getSPPara(Int iPUWidth, Int iPUHeight, Int& iNumSP, Int& iNumSPInOneLine, Int& iSPWidth, Int& iSPHeight)
    64265523{
     
    64395536Void TComDataCU::getSPAbsPartIdx(UInt uiBaseAbsPartIdx, Int iWidth, Int iHeight, Int iPartIdx, Int iNumPartLine, UInt& ruiPartAddr )
    64405537{
    6441   uiBaseAbsPartIdx += m_uiAbsIdxInLCU;
     5538  uiBaseAbsPartIdx += m_absZIdxInCtu;
    64425539  Int iBasePelX = g_auiRasterToPelX[g_auiZscanToRaster[uiBaseAbsPartIdx]];
    64435540  Int iBasePelY = g_auiRasterToPelY[g_auiZscanToRaster[uiBaseAbsPartIdx]];
    64445541  Int iCurrPelX = iBasePelX + iPartIdx%iNumPartLine * iWidth;
    64455542  Int iCurrPelY = iBasePelY + iPartIdx/iNumPartLine * iHeight;
    6446   Int iCurrRaster = iCurrPelY / getPic()->getMinCUHeight() * getPic()->getNumPartInWidth() + iCurrPelX/getPic()->getMinCUWidth();
     5543  Int iCurrRaster = iCurrPelY / getPic()->getMinCUHeight() * getPic()->getNumPartInCtuWidth() + iCurrPelX/getPic()->getMinCUWidth();
    64475544  ruiPartAddr = g_auiRasterToZscan[iCurrRaster];
    6448   ruiPartAddr -= m_uiAbsIdxInLCU
     5545  ruiPartAddr -= m_absZIdxInCtu
    64495546}
    64505547
    64515548Void TComDataCU::setInterDirSP( UInt uiDir, UInt uiAbsPartIdx, Int iWidth, Int iHeight )
    64525549{
    6453   uiAbsPartIdx += getZorderIdxInCU();
     5550  uiAbsPartIdx += getZorderIdxInCtu();
    64545551  Int iStartPelX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIdx]];
    64555552  Int iStartPelY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIdx]];
     
    64635560    for (Int j=iStartPelX; j < iEndPelX; j += getPic()->getMinCUWidth())
    64645561    {
    6465       iCurrRaster = i / getPic()->getMinCUHeight() * getPic()->getNumPartInWidth() + j/getPic()->getMinCUWidth();
     5562      iCurrRaster = i / getPic()->getMinCUHeight() * getPic()->getNumPartInCtuWidth() + j/getPic()->getMinCUWidth();
    64665563      uiPartAddr = g_auiRasterToZscan[iCurrRaster];
    6467       uiPartAddr -= getZorderIdxInCU(); 
     5564      uiPartAddr -= getZorderIdxInCtu(); 
    64685565
    64695566      m_puhInterDir[uiPartAddr] = uiDir;
     
    64735570#endif
    64745571
    6475 #if H_3D_IV_MERGE
     5572#if NH_3D_IV_MERGE
    64765573Bool
    64775574TComDataCU::getInterViewMergeCands(UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* availableMcDc , Bool bIsDepth           
    6478 #if H_3D_SPIVMP
     5575#if NH_3D_SPIVMP
    64795576, TComMvField* pcMvFieldSP, UChar* puhInterDirSP
    64805577#endif
     
    64955592
    64965593  Int  iCurrPosX, iCurrPosY;
    6497   pcBaseRec->getTopLeftSamplePos( getAddr(), getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
    6498 
    6499 #if !H_3D_SPIVMP
     5594  pcBaseRec->getTopLeftSamplePos( getCtuRsAddr(), getZorderIdxInCtu() + uiPartAddr, iCurrPosX, iCurrPosY );
     5595
     5596#if !NH_3D_SPIVMP
    65005597  iCurrPosX  += ( iWidth  >> 1 );
    65015598  iCurrPosY  += ( iHeight >> 1 );
     
    65035600
    65045601  Bool depthRefineFlag = false;
    6505 #if H_3D_NBDV_REF
     5602#if NH_3D_NBDV_REF
    65065603  depthRefineFlag = m_pcSlice->getDepthRefinementFlag( );
    6507 #endif // H_3D_NBDV_REF
     5604#endif // NH_3D_NBDV_REF
    65085605
    65095606  TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV;
     
    65145611
    65155612  Bool abPdmAvailable[8] =  {false, false, false, false, false, false, false, false};
    6516 #if H_3D_NBDV
     5613#if NH_3D_NBDV
    65175614  for( Int i = 0; i < 8; i++)
    65185615  {
     
    65245621  {
    65255622
    6526 #if H_3D_SPIVMP
     5623#if NH_3D_SPIVMP
    65275624    ////////////////////////////////
    65285625    //////////sub-PU IvMC///////////
     
    65305627    if(!m_pcSlice->getIsDepth())
    65315628    {
     5629#if H_3D_DBBP || NH_3D_ALIGN_SPIVMP_DBBP
    65325630      if (!getDBBPFlag(0))
     5631#else
     5632      if (1)
     5633#endif
    65335634      {
    65345635        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
     
    65625663        }
    65635664
    6564         Int iRefCenterPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCenterPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
    6565         Int iRefCenterPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCenterPosY + ( (cDv.getVer() + 2 ) >> 2 ) );
     5665        Int iRefCenterPosX   = Clip3( 0, pcBaseRec->getWidth (COMPONENT_Y) - 1, iCenterPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
     5666        Int iRefCenterPosY   = Clip3( 0, pcBaseRec->getHeight(COMPONENT_Y) - 1, iCenterPosY + ( (cDv.getVer() + 2 ) >> 2 ) );
    65665667
    65675668        pcBaseRec->getCUAddrAndPartIdx( iRefCenterPosX , iRefCenterPosY , iRefCenterCUAddr, iRefCenterAbsPartIdx );
    6568         TComDataCU* pcDefaultCU    = pcBasePic->getCU( iRefCenterCUAddr );
     5669        TComDataCU* pcDefaultCU    = pcBasePic->getCtu( iRefCenterCUAddr );
    65695670        if(!( pcDefaultCU->getPredictionMode( iRefCenterAbsPartIdx ) == MODE_INTRA ))
    65705671        {
     
    65905691                      abPdmAvailable[ uiCurrRefListId ] = true;
    65915692                      TComMv cMv(cDefaultMvField.getHor(), cDefaultMvField.getVer());
    6592 #if H_3D_NBDV
    6593 #if H_3D_IV_MERGE
     5693#if NH_3D_NBDV
     5694#if NH_3D_IV_MERGE
    65945695                      if( !bIsDepth )
    65955696                      {
     
    65995700                        cMv.setIDVVer    (cDv.getVer()); 
    66005701                        cMv.setIDVVId    (iViewIndex);
    6601 #if H_3D_IV_MERGE
     5702#if NH_3D_IV_MERGE
    66025703                      }
    66035704#endif
     
    66245725            for (Int j = iCurrPosX; j < iCurrPosX + iWidth; j += iSPWidth)
    66255726            {
    6626               iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, j + iDelX + ( (cDv.getHor() + 2 ) >> 2 ));
    6627               iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, i + iDelY + ( (cDv.getVer() + 2 ) >> 2 ));
     5727              iBasePosX   = Clip3( 0, pcBaseRec->getWidth (COMPONENT_Y) - 1, j + iDelX + ( (cDv.getHor() + 2 ) >> 2 ));
     5728              iBasePosY   = Clip3( 0, pcBaseRec->getHeight(COMPONENT_Y) - 1, i + iDelY + ( (cDv.getVer() + 2 ) >> 2 ));
    66285729
    66295730              pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY, iBaseCUAddr, iBaseAbsPartIdx );
    6630               pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
     5731              pcBaseCU    = pcBasePic->getCtu( iBaseCUAddr );
    66315732              if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
    66325733              {
     
    66965797    ////////////////////////////////
    66975798
    6698 #if H_3D_SPIVMP
     5799#if NH_3D_SPIVMP
    66995800    if(m_pcSlice->getIsDepth())
    67005801    {
     
    67025803      iCurrPosY  += ( iHeight >> 1 );
    67035804    }
     5805#if H_3D_DBBP || NH_3D_ALIGN_SPIVMP_DBBP
    67045806    for(Int iLoopCan = ( (m_pcSlice->getIsDepth() || getDBBPFlag(0)) ? 0 : 1 ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++)
    67055807#else
     5808    for(Int iLoopCan = ( m_pcSlice->getIsDepth() ? 0 : 1 ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++)
     5809#endif
     5810#else
    67065811    for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
    67075812#endif
     
    67135818      Int         iBaseAbsPartIdx;
    67145819
    6715       Int offsetW = (iLoopCan == 0) ? 0 : ( iWidth  * 2 );
    6716       Int offsetH = (iLoopCan == 0) ? 0 : ( iHeight * 2 );
    6717 
    6718       Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + offsetW + 2 ) >> 2 ) );
    6719       Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + offsetH + 2 ) >> 2 ) );
     5820      Int offsetW = (iLoopCan == 0) ? 0 : ( iWidth  * 2);
     5821      Int offsetH = (iLoopCan == 0) ? 0 : ( iHeight * 2);
     5822
     5823      Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth (COMPONENT_Y) - 1, iCurrPosX + ( (cDv.getHor() + offsetW + 2 ) >> 2 ) );
     5824      Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight(COMPONENT_Y) - 1, iCurrPosY + ( (cDv.getVer() + offsetH + 2 ) >> 2 ) );
    67205825      pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
    67215826
    6722       TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
     5827      TComDataCU* pcBaseCU    = pcBasePic->getCtu( iBaseCUAddr );
    67235828      if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
    67245829      {
     
    67475852                    abPdmAvailable[ (uiCurrRefListId + (iLoopCan<<2)) ] = true;
    67485853                    TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
    6749 #if H_3D_NBDV
    6750 #if H_3D_IV_MERGE
     5854#if NH_3D_NBDV
     5855#if NH_3D_IV_MERGE
    67515856                    if( !bIsDepth )
    67525857                    {
     
    67565861                      cMv.setIDVVer    (cDv.getVer()); 
    67575862                      cMv.setIDVVId    (iViewIndex);
    6758 #if H_3D_IV_MERGE
     5863#if NH_3D_IV_MERGE
    67595864                    }
    67605865#endif
     
    67725877      }
    67735878    }
    6774 #if H_3D_SPIVMP
     5879#if NH_3D_SPIVMP
     5880#if H_3D_DBBP || NH_3D_ALIGN_SPIVMP_DBBP
    67755881    for(Int iLoopCan = ( (m_pcSlice->getIsDepth() || getDBBPFlag(0)) ? 0 : 1 ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++)
     5882#else
     5883    for(Int iLoopCan = ( m_pcSlice->getIsDepth()  ? 0 : 1 ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++)
     5884#endif
    67765885#else
    67775886    for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
     
    68025911            abPdmAvailable[ iRefListId + 2 + (iLoopCan<<2) ] = true;
    68035912            paiPdmRefIdx  [ iRefListId + 2 + (iLoopCan<<2) ] = iPdmRefIdx;
    6804 #if H_3D_NBDV_REF
     5913#if NH_3D_NBDV_REF
    68055914            TComMv cMv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV;
    68065915#endif
    68075916            cMv.setHor( cMv.getHor() + ioffsetDV );
    6808 #if H_3D_IV_MERGE
     5917#if NH_3D_IV_MERGE
    68095918            if( bIsDepth )
    68105919            {
     
    68275936}
    68285937#endif
    6829 #if H_3D_ARP
     5938#if NH_3D_ARP
    68305939Void TComDataCU::setARPWSubParts ( UChar w, UInt uiAbsPartIdx, UInt uiDepth )
    68315940{
    6832   assert( sizeof( *m_puhARPW) == 1 );
    6833   memset( m_puhARPW + uiAbsPartIdx, w, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
    6834 }
    6835 #endif
    6836 
    6837 #if H_3D_IC
     5941  setSubPart<UChar>( w, m_puhARPW, uiAbsPartIdx, uiDepth, 0 );
     5942}
     5943#endif
     5944
     5945#if NH_3D_IC
    68385946Void TComDataCU::setICFlagSubParts( Bool bICFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
    68395947{
    6840   memset( m_pbICFlag + uiAbsPartIdx, bICFlag, (m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ))*sizeof(Bool) );
     5948  memset( m_pbICFlag + uiAbsPartIdx, bICFlag, (m_pcPic->getNumPartitionsInCtu() >> ( 2 * uiDepth ))*sizeof(Bool) );
    68415949}
    68425950
     
    68895997}
    68905998#endif
    6891 #if H_3D_DIM_DMM
    6892 Void TComDataCU::setDmmWedgeTabIdxSubParts( UInt tabIdx, UInt dmmType, UInt uiAbsPartIdx, UInt uiDepth )
    6893 {
    6894   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    6895   for( UInt ui = 0; ui < uiCurrPartNumb; ui++ )
    6896   {
    6897     m_dmmWedgeTabIdx[dmmType][uiAbsPartIdx+ui] = tabIdx;
    6898   }
    6899 }
    6900 #endif
    6901 
    6902 #if H_3D_VSP
     5999#if NH_3D_DMM
     6000Void TComDataCU::setDmm1WedgeTabIdxSubParts( UInt tabIdx, UInt uiAbsPartIdx, UInt uiDepth )
     6001{
     6002  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     6003  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm1WedgeTabIdx[uiAbsPartIdx+ui] = tabIdx; }
     6004}
     6005#endif
     6006
     6007#if NH_3D_VSP
    69036008Void TComDataCU::setMvFieldPUForVSP( TComDataCU* pcCU, UInt partAddr, Int width, Int height, RefPicList eRefPicList, Int iRefIdx, Int &vspSize )
    69046009{
     
    69566061  TComCUMvField *cuMvField = cu->getCUMvField( refPicList );
    69576062  Int partAddrRasterSubPULine  = g_auiZscanToRaster[ partAddr ];
    6958   Int numPartsLine    = cu->getPic()->getNumPartInWidth();
     6063  Int numPartsLine    = cu->getPic()->getNumPartInCtuWidth();
    69596064
    69606065  Int nTxtPerMvInfoX = 4; // cu->getPic()->getMinCUWidth();
    69616066  Int nTxtPerMvInfoY = 4; // cu->getPic()->getMinCUHeight();
    69626067
    6963   Int refDepStride = picRefDepth->getStride();
     6068  Int refDepStride = picRefDepth->getStride( COMPONENT_Y );
    69646069
    69656070  TComMv tmpMv(0, 0);
     
    69676072
    69686073  Int refDepOffset  = ( (dv->getHor()+2) >> 2 ) + ( (dv->getVer()+2) >> 2 ) * refDepStride;
    6969   Pel *refDepth     = picRefDepth->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refDepOffset;
     6074  Pel *refDepth     = picRefDepth->getAddr( COMPONENT_Y, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refDepOffset;
    69706075
    69716076  if ((height % 8))
Note: See TracChangeset for help on using the changeset viewer.