Ignore:
Timestamp:
12 Nov 2014, 08:09:17 (10 years ago)
Author:
seregin
Message:

initial porting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/SHM-upgrade/source/Lib/TLibCommon/TComDataCU.cpp

    r901 r916  
    3838
    3939#include "TComDataCU.h"
     40#include "TComTU.h"
    4041#include "TComPic.h"
    4142
     
    4445
    4546#if ADAPTIVE_QP_SELECTION
    46 Int * TComDataCU::m_pcGlbArlCoeffY  = NULL;
    47 Int * TComDataCU::m_pcGlbArlCoeffCb = NULL;
    48 Int * TComDataCU::m_pcGlbArlCoeffCr = NULL;
     47  TCoeff * TComDataCU::m_pcGlbArlCoeff[MAX_NUM_COMPONENT] = { NULL, NULL, NULL };
    4948#endif
    5049
     
    5857  m_pcSlice            = NULL;
    5958  m_puhDepth           = NULL;
    60  
     59
    6160  m_skipFlag           = NULL;
    6261
     
    6766  m_puhHeight          = NULL;
    6867  m_phQP               = NULL;
     68  m_ChromaQpAdj        = NULL;
    6969  m_pbMergeFlag        = NULL;
    7070  m_puhMergeIndex      = NULL;
    71   m_puhLumaIntraDir    = NULL;
    72   m_puhChromaIntraDir  = NULL;
     71  for(UInt i=0; i<MAX_NUM_CHANNEL_TYPE; i++)
     72  {
     73    m_puhIntraDir[i]     = NULL;
     74  }
    7375  m_puhInterDir        = NULL;
    7476  m_puhTrIdx           = NULL;
    75   m_puhTransformSkip[0] = NULL;
    76   m_puhTransformSkip[1] = NULL;
    77   m_puhTransformSkip[2] = NULL;
    78   m_puhCbf[0]          = NULL;
    79   m_puhCbf[1]          = NULL;
    80   m_puhCbf[2]          = NULL;
    81   m_pcTrCoeffY         = NULL;
    82   m_pcTrCoeffCb        = NULL;
    83   m_pcTrCoeffCr        = NULL;
    84 #if ADAPTIVE_QP_SELECTION 
     77
     78  for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     79  {
     80    m_puhCbf[comp]                        = NULL;
     81    m_crossComponentPredictionAlpha[comp] = NULL;
     82    m_puhTransformSkip[comp]              = NULL;
     83    m_pcTrCoeff[comp]                     = NULL;
     84#if ADAPTIVE_QP_SELECTION
     85    m_pcArlCoeff[comp]                    = NULL;
     86#endif
     87    m_pcIPCMSample[comp]                  = NULL;
     88    m_explicitRdpcmMode[comp]             = NULL;
     89  }
     90#if ADAPTIVE_QP_SELECTION
    8591  m_ArlCoeffIsAliasedAllocation = false;
    86   m_pcArlCoeffY        = NULL;
    87   m_pcArlCoeffCb       = NULL;
    88   m_pcArlCoeffCr       = NULL;
    8992#endif
    90  
    9193  m_pbIPCMFlag         = NULL;
    92   m_pcIPCMSampleY      = NULL;
    93   m_pcIPCMSampleCb     = NULL;
    94   m_pcIPCMSampleCr     = NULL;
    95 
    96   m_pcPattern          = NULL;
    97  
    98   m_pcCUAboveLeft      = NULL;
    99   m_pcCUAboveRight     = NULL;
    100   m_pcCUAbove          = NULL;
    101   m_pcCULeft           = NULL;
    102  
    103   m_apcCUColocated[0]  = NULL;
    104   m_apcCUColocated[1]  = NULL;
    105  
    106   m_apiMVPIdx[0]       = NULL;
    107   m_apiMVPIdx[1]       = NULL;
    108   m_apiMVPNum[0]       = NULL;
    109   m_apiMVPNum[1]       = NULL;
     94
     95  m_pCtuAboveLeft      = NULL;
     96  m_pCtuAboveRight     = NULL;
     97  m_pCtuAbove          = NULL;
     98  m_pCtuLeft           = NULL;
     99
     100  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     101  {
     102    m_apcCUColocated[i]  = NULL;
     103    m_apiMVPIdx[i]       = NULL;
     104    m_apiMVPNum[i]       = NULL;
     105  }
    110106
    111107  m_bDecSubCu          = false;
    112   m_sliceStartCU        = 0;
    113   m_sliceSegmentStartCU = 0;
    114108}
    115109
     
    118112}
    119113
    120 Void TComDataCU::create(UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize
     114Void TComDataCU::create( ChromaFormat chromaFormatIDC, UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize
    121115#if ADAPTIVE_QP_SELECTION
    122116                        , Bool bGlobalRMARLBuffer
    123 #endif                                             
     117#endif
    124118                        )
    125119{
    126120  m_bDecSubCu = bDecSubCu;
    127  
     121
    128122  m_pcPic              = NULL;
    129123  m_pcSlice            = NULL;
    130124  m_uiNumPartition     = uiNumPartition;
    131125  m_unitSize = unitSize;
    132  
     126
    133127  if ( !bDecSubCu )
    134128  {
     
    138132    m_puhHeight          = (UChar*    )xMalloc(UChar,    uiNumPartition);
    139133
     134    m_ChromaQpAdj        = new UChar[ uiNumPartition ];
    140135    m_skipFlag           = new Bool[ uiNumPartition ];
    141 
    142136    m_pePartSize         = new Char[ uiNumPartition ];
    143     memset( m_pePartSize, SIZE_NONE,uiNumPartition * sizeof( *m_pePartSize ) );
     137    memset( m_pePartSize, NUMBER_OF_PART_SIZES,uiNumPartition * sizeof( *m_pePartSize ) );
    144138    m_pePredMode         = new Char[ uiNumPartition ];
    145139    m_CUTransquantBypass = new Bool[ uiNumPartition ];
     140
    146141    m_pbMergeFlag        = (Bool*  )xMalloc(Bool,   uiNumPartition);
    147142    m_puhMergeIndex      = (UChar* )xMalloc(UChar,  uiNumPartition);
    148     m_puhLumaIntraDir    = (UChar* )xMalloc(UChar,  uiNumPartition);
    149     m_puhChromaIntraDir  = (UChar* )xMalloc(UChar,  uiNumPartition);
     143
     144    for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     145    {
     146      m_puhIntraDir[ch] = (UChar* )xMalloc(UChar,  uiNumPartition);
     147    }
    150148    m_puhInterDir        = (UChar* )xMalloc(UChar,  uiNumPartition);
    151    
     149
    152150    m_puhTrIdx           = (UChar* )xMalloc(UChar,  uiNumPartition);
    153     m_puhTransformSkip[0] = (UChar* )xMalloc(UChar,  uiNumPartition);
    154     m_puhTransformSkip[1] = (UChar* )xMalloc(UChar,  uiNumPartition);
    155     m_puhTransformSkip[2] = (UChar* )xMalloc(UChar,  uiNumPartition);
    156 
    157     m_puhCbf[0]          = (UChar* )xMalloc(UChar,  uiNumPartition);
    158     m_puhCbf[1]          = (UChar* )xMalloc(UChar,  uiNumPartition);
    159     m_puhCbf[2]          = (UChar* )xMalloc(UChar,  uiNumPartition);
    160    
    161     m_apiMVPIdx[0]       = new Char[ uiNumPartition ];
    162     m_apiMVPIdx[1]       = new Char[ uiNumPartition ];
    163     m_apiMVPNum[0]       = new Char[ uiNumPartition ];
    164     m_apiMVPNum[1]       = new Char[ uiNumPartition ];
    165     memset( m_apiMVPIdx[0], -1,uiNumPartition * sizeof( Char ) );
    166     memset( m_apiMVPIdx[1], -1,uiNumPartition * sizeof( Char ) );
    167    
    168     m_pcTrCoeffY         = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight);
    169     m_pcTrCoeffCb        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
    170     m_pcTrCoeffCr        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
    171     memset( m_pcTrCoeffY, 0,uiWidth*uiHeight * sizeof( TCoeff ) );
    172     memset( m_pcTrCoeffCb, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
    173     memset( m_pcTrCoeffCr, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
     151
     152    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     153    {
     154      const RefPicList rpl=RefPicList(i);
     155      m_apiMVPIdx[rpl]       = new Char[ uiNumPartition ];
     156      m_apiMVPNum[rpl]       = new Char[ uiNumPartition ];
     157      memset( m_apiMVPIdx[rpl], -1,uiNumPartition * sizeof( Char ) );
     158    }
     159
     160    for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     161    {
     162      const ComponentID compID = ComponentID(comp);
     163      const UInt chromaShift = getComponentScaleX(compID, chromaFormatIDC) + getComponentScaleY(compID, chromaFormatIDC);
     164      const UInt totalSize   = (uiWidth * uiHeight) >> chromaShift;
     165
     166      m_crossComponentPredictionAlpha[compID] = (Char*  )xMalloc(Char,   uiNumPartition);
     167      m_puhTransformSkip[compID]              = (UChar* )xMalloc(UChar,  uiNumPartition);
     168      m_explicitRdpcmMode[compID]             = (UChar* )xMalloc(UChar,  uiNumPartition);
     169      m_puhCbf[compID]                        = (UChar* )xMalloc(UChar,  uiNumPartition);
     170      m_pcTrCoeff[compID]                     = (TCoeff*)xMalloc(TCoeff, totalSize);
     171      memset( m_pcTrCoeff[compID], 0, (totalSize * sizeof( TCoeff )) );
     172
    174173#if ADAPTIVE_QP_SELECTION
    175     if( bGlobalRMARLBuffer )
    176     {
    177       if( m_pcGlbArlCoeffY == NULL )
     174      if( bGlobalRMARLBuffer )
    178175      {
    179176#if LAYER_CTB
    180         m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, MAX_CU_SIZE * MAX_CU_SIZE);
    181         m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, MAX_CU_SIZE * MAX_CU_SIZE/4);
    182         m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, MAX_CU_SIZE * MAX_CU_SIZE/4);
     177        if (m_pcGlbArlCoeff[compID] == NULL) m_pcGlbArlCoeff[compID] = (TCoeff*)xMalloc(TCoeff, MAX_CU_SIZE * MAX_CU_SIZE);
    183178#else
    184         m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, uiWidth*uiHeight);
    185         m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
    186         m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
     179        if (m_pcGlbArlCoeff[compID] == NULL) m_pcGlbArlCoeff[compID] = (TCoeff*)xMalloc(TCoeff, totalSize);
    187180#endif
    188       }
    189       m_pcArlCoeffY        = m_pcGlbArlCoeffY;
    190       m_pcArlCoeffCb       = m_pcGlbArlCoeffCb;
    191       m_pcArlCoeffCr       = m_pcGlbArlCoeffCr;
    192       m_ArlCoeffIsAliasedAllocation = true;
    193     }
    194     else
    195     {
    196       m_pcArlCoeffY        = (Int*)xMalloc(Int, uiWidth*uiHeight);
    197       m_pcArlCoeffCb       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
    198       m_pcArlCoeffCr       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
    199     }
     181
     182        m_pcArlCoeff[compID] = m_pcGlbArlCoeff[compID];
     183        m_ArlCoeffIsAliasedAllocation = true;
     184      }
     185      else
     186      {
     187         m_pcArlCoeff[compID] = (TCoeff*)xMalloc(TCoeff, totalSize);
     188      }
    200189#endif
    201    
     190      m_pcIPCMSample[compID] = (Pel*   )xMalloc(Pel , totalSize);
     191    }
     192
    202193    m_pbIPCMFlag         = (Bool*  )xMalloc(Bool, uiNumPartition);
    203     m_pcIPCMSampleY      = (Pel*   )xMalloc(Pel , uiWidth*uiHeight);
    204     m_pcIPCMSampleCb     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
    205     m_pcIPCMSampleCr     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
    206 
    207     m_acCUMvField[0].create( uiNumPartition );
    208     m_acCUMvField[1].create( uiNumPartition );
    209    
     194
     195    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     196    {
     197      m_acCUMvField[i].create( uiNumPartition );
     198    }
     199
    210200  }
    211201  else
    212202  {
    213     m_acCUMvField[0].setNumPartition(uiNumPartition );
    214     m_acCUMvField[1].setNumPartition(uiNumPartition );
    215   }
    216  
    217   m_sliceStartCU        = (UInt*  )xMalloc(UInt, uiNumPartition);
    218   m_sliceSegmentStartCU = (UInt*  )xMalloc(UInt, uiNumPartition);
    219  
    220   // create pattern memory
    221   m_pcPattern            = (TComPattern*)xMalloc(TComPattern, 1);
    222  
     203    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     204    {
     205      m_acCUMvField[i].setNumPartition(uiNumPartition );
     206    }
     207  }
     208
    223209  // create motion vector fields
    224  
    225   m_pcCUAboveLeft      = NULL;
    226   m_pcCUAboveRight     = NULL;
    227   m_pcCUAbove          = NULL;
    228   m_pcCULeft           = NULL;
    229  
    230   m_apcCUColocated[0]  = NULL;
    231   m_apcCUColocated[1]  = NULL;
     210
     211  m_pCtuAboveLeft      = NULL;
     212  m_pCtuAboveRight     = NULL;
     213  m_pCtuAbove          = NULL;
     214  m_pCtuLeft           = NULL;
     215
     216  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     217  {
     218    m_apcCUColocated[i]  = NULL;
     219  }
    232220}
    233221
    234222Void TComDataCU::destroy()
    235223{
     224  // encoder-side buffer free
     225  if ( !m_bDecSubCu )
     226  {
     227    if ( m_phQP               ) { xFree(m_phQP);                m_phQP               = NULL; }
     228    if ( m_puhDepth           ) { xFree(m_puhDepth);            m_puhDepth           = NULL; }
     229    if ( m_puhWidth           ) { xFree(m_puhWidth);            m_puhWidth           = NULL; }
     230    if ( m_puhHeight          ) { xFree(m_puhHeight);           m_puhHeight          = NULL; }
     231
     232    if ( m_skipFlag           ) { delete[] m_skipFlag;          m_skipFlag          = NULL; }
     233
     234    if ( m_pePartSize         ) { delete[] m_pePartSize;        m_pePartSize         = NULL; }
     235    if ( m_pePredMode         ) { delete[] m_pePredMode;        m_pePredMode         = NULL; }
     236    if ( m_ChromaQpAdj        ) { delete[] m_ChromaQpAdj;       m_ChromaQpAdj        = NULL; }
     237    if ( m_CUTransquantBypass ) { delete[] m_CUTransquantBypass;m_CUTransquantBypass = NULL; }
     238    if ( m_puhInterDir        ) { xFree(m_puhInterDir);         m_puhInterDir        = NULL; }
     239    if ( m_pbMergeFlag        ) { xFree(m_pbMergeFlag);         m_pbMergeFlag        = NULL; }
     240    if ( m_puhMergeIndex      ) { xFree(m_puhMergeIndex);       m_puhMergeIndex      = NULL; }
     241
     242    for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     243    {
     244      xFree(m_puhIntraDir[ch]);
     245      m_puhIntraDir[ch] = NULL;
     246    }
     247
     248    if ( m_puhTrIdx           ) { xFree(m_puhTrIdx);            m_puhTrIdx          = NULL; }
     249
     250    for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     251    {
     252      if ( m_crossComponentPredictionAlpha[comp] ) { xFree(m_crossComponentPredictionAlpha[comp]); m_crossComponentPredictionAlpha[comp] = NULL; }
     253      if ( m_puhTransformSkip[comp]              ) { xFree(m_puhTransformSkip[comp]);              m_puhTransformSkip[comp]              = NULL; }
     254      if ( m_puhCbf[comp]                        ) { xFree(m_puhCbf[comp]);                        m_puhCbf[comp]                        = NULL; }
     255      if ( m_pcTrCoeff[comp]                     ) { xFree(m_pcTrCoeff[comp]);                     m_pcTrCoeff[comp]                     = NULL; }
     256      if ( m_explicitRdpcmMode[comp]             ) { xFree(m_explicitRdpcmMode[comp]);             m_explicitRdpcmMode[comp]             = NULL; }
     257
     258#if ADAPTIVE_QP_SELECTION
     259      if (!m_ArlCoeffIsAliasedAllocation)
     260      {
     261        if ( m_pcArlCoeff[comp]     ) { xFree(m_pcArlCoeff[comp]);      m_pcArlCoeff[comp]    = NULL; }
     262      }
     263
     264      if ( m_pcGlbArlCoeff[comp]  ) { xFree(m_pcGlbArlCoeff[comp]);   m_pcGlbArlCoeff[comp] = NULL; }
     265#endif
     266
     267      if ( m_pcIPCMSample[comp]   ) { xFree(m_pcIPCMSample[comp]);    m_pcIPCMSample[comp]  = NULL; }
     268    }
     269    if ( m_pbIPCMFlag         ) { xFree(m_pbIPCMFlag   );       m_pbIPCMFlag        = NULL; }
     270
     271    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     272    {
     273      const RefPicList rpl=RefPicList(i);
     274      if ( m_apiMVPIdx[rpl]       ) { delete[] m_apiMVPIdx[rpl];      m_apiMVPIdx[rpl]      = NULL; }
     275      if ( m_apiMVPNum[rpl]       ) { delete[] m_apiMVPNum[rpl];      m_apiMVPNum[rpl]      = NULL; }
     276    }
     277
     278    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     279    {
     280      const RefPicList rpl=RefPicList(i);
     281      m_acCUMvField[rpl].destroy();
     282    }
     283  }
     284
    236285  m_pcPic              = NULL;
    237286  m_pcSlice            = NULL;
    238  
    239   if ( m_pcPattern )
    240   {
    241     xFree(m_pcPattern);
    242     m_pcPattern = NULL;
    243   }
    244  
    245   // encoder-side buffer free
    246   if ( !m_bDecSubCu )
    247   {
    248     if ( m_phQP               ) { xFree(m_phQP);                m_phQP              = NULL; }
    249     if ( m_puhDepth           ) { xFree(m_puhDepth);            m_puhDepth          = NULL; }
    250     if ( m_puhWidth           ) { xFree(m_puhWidth);            m_puhWidth          = NULL; }
    251     if ( m_puhHeight          ) { xFree(m_puhHeight);           m_puhHeight         = NULL; }
    252 
    253     if ( m_skipFlag           ) { delete[] m_skipFlag;          m_skipFlag          = NULL; }
    254 
    255     if ( m_pePartSize         ) { delete[] m_pePartSize;        m_pePartSize        = NULL; }
    256     if ( m_pePredMode         ) { delete[] m_pePredMode;        m_pePredMode        = NULL; }
    257     if ( m_CUTransquantBypass ) { delete[] m_CUTransquantBypass;m_CUTransquantBypass = NULL; }
    258     if ( m_puhCbf[0]          ) { xFree(m_puhCbf[0]);           m_puhCbf[0]         = NULL; }
    259     if ( m_puhCbf[1]          ) { xFree(m_puhCbf[1]);           m_puhCbf[1]         = NULL; }
    260     if ( m_puhCbf[2]          ) { xFree(m_puhCbf[2]);           m_puhCbf[2]         = NULL; }
    261     if ( m_puhInterDir        ) { xFree(m_puhInterDir);         m_puhInterDir       = NULL; }
    262     if ( m_pbMergeFlag        ) { xFree(m_pbMergeFlag);         m_pbMergeFlag       = NULL; }
    263     if ( m_puhMergeIndex      ) { xFree(m_puhMergeIndex);       m_puhMergeIndex     = NULL; }
    264     if ( m_puhLumaIntraDir    ) { xFree(m_puhLumaIntraDir);     m_puhLumaIntraDir   = NULL; }
    265     if ( m_puhChromaIntraDir  ) { xFree(m_puhChromaIntraDir);   m_puhChromaIntraDir = NULL; }
    266     if ( m_puhTrIdx           ) { xFree(m_puhTrIdx);            m_puhTrIdx          = NULL; }
    267     if ( m_puhTransformSkip[0]) { xFree(m_puhTransformSkip[0]); m_puhTransformSkip[0] = NULL; }
    268     if ( m_puhTransformSkip[1]) { xFree(m_puhTransformSkip[1]); m_puhTransformSkip[1] = NULL; }
    269     if ( m_puhTransformSkip[2]) { xFree(m_puhTransformSkip[2]); m_puhTransformSkip[2] = NULL; }
    270     if ( m_pcTrCoeffY         ) { xFree(m_pcTrCoeffY);          m_pcTrCoeffY        = NULL; }
    271     if ( m_pcTrCoeffCb        ) { xFree(m_pcTrCoeffCb);         m_pcTrCoeffCb       = NULL; }
    272     if ( m_pcTrCoeffCr        ) { xFree(m_pcTrCoeffCr);         m_pcTrCoeffCr       = NULL; }
    273 #if ADAPTIVE_QP_SELECTION
    274     if (!m_ArlCoeffIsAliasedAllocation)
    275     {
    276       xFree(m_pcArlCoeffY); m_pcArlCoeffY = 0;
    277       xFree(m_pcArlCoeffCb); m_pcArlCoeffCb = 0;
    278       xFree(m_pcArlCoeffCr); m_pcArlCoeffCr = 0;
    279     }
    280     if ( m_pcGlbArlCoeffY     ) { xFree(m_pcGlbArlCoeffY);      m_pcGlbArlCoeffY    = NULL; }
    281     if ( m_pcGlbArlCoeffCb    ) { xFree(m_pcGlbArlCoeffCb);     m_pcGlbArlCoeffCb   = NULL; }
    282     if ( m_pcGlbArlCoeffCr    ) { xFree(m_pcGlbArlCoeffCr);     m_pcGlbArlCoeffCr   = NULL; }
    283 #endif
    284     if ( m_pbIPCMFlag         ) { xFree(m_pbIPCMFlag   );       m_pbIPCMFlag        = NULL; }
    285     if ( m_pcIPCMSampleY      ) { xFree(m_pcIPCMSampleY);       m_pcIPCMSampleY     = NULL; }
    286     if ( m_pcIPCMSampleCb     ) { xFree(m_pcIPCMSampleCb);      m_pcIPCMSampleCb    = NULL; }
    287     if ( m_pcIPCMSampleCr     ) { xFree(m_pcIPCMSampleCr);      m_pcIPCMSampleCr    = NULL; }
    288     if ( m_apiMVPIdx[0]       ) { delete[] m_apiMVPIdx[0];      m_apiMVPIdx[0]      = NULL; }
    289     if ( m_apiMVPIdx[1]       ) { delete[] m_apiMVPIdx[1];      m_apiMVPIdx[1]      = NULL; }
    290     if ( m_apiMVPNum[0]       ) { delete[] m_apiMVPNum[0];      m_apiMVPNum[0]      = NULL; }
    291     if ( m_apiMVPNum[1]       ) { delete[] m_apiMVPNum[1];      m_apiMVPNum[1]      = NULL; }
    292    
    293     m_acCUMvField[0].destroy();
    294     m_acCUMvField[1].destroy();
    295    
    296   }
    297  
    298   m_pcCUAboveLeft       = NULL;
    299   m_pcCUAboveRight      = NULL;
    300   m_pcCUAbove           = NULL;
    301   m_pcCULeft            = NULL;
    302  
    303   m_apcCUColocated[0]   = NULL;
    304   m_apcCUColocated[1]   = NULL;
    305 
    306   if( m_sliceStartCU )
    307   {
    308     xFree(m_sliceStartCU);
    309     m_sliceStartCU=NULL;
    310   }
    311   if(m_sliceSegmentStartCU )
    312   {
    313     xFree(m_sliceSegmentStartCU);
    314     m_sliceSegmentStartCU=NULL;
    315   }
     287
     288  m_pCtuAboveLeft      = NULL;
     289  m_pCtuAboveRight     = NULL;
     290  m_pCtuAbove          = NULL;
     291  m_pCtuLeft           = NULL;
     292
     293
     294  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     295  {
     296    m_apcCUColocated[i]  = NULL;
     297  }
     298
     299}
     300
     301Bool TComDataCU::CUIsFromSameTile            ( const TComDataCU *pCU /* Can be NULL */) const
     302{
     303  return pCU!=NULL &&
     304         pCU->getSlice() != NULL &&
     305         m_pcPic->getPicSym()->getTileIdxMap( pCU->getCtuRsAddr() ) == m_pcPic->getPicSym()->getTileIdxMap(getCtuRsAddr());
     306}
     307
     308Bool TComDataCU::CUIsFromSameSliceAndTile    ( const TComDataCU *pCU /* Can be NULL */) const
     309{
     310  return pCU!=NULL &&
     311         pCU->getSlice() != NULL &&
     312         pCU->getSlice()->getSliceCurStartCtuTsAddr() == getSlice()->getSliceCurStartCtuTsAddr() &&
     313         m_pcPic->getPicSym()->getTileIdxMap( pCU->getCtuRsAddr() ) == m_pcPic->getPicSym()->getTileIdxMap(getCtuRsAddr())
     314         ;
     315}
     316
     317Bool TComDataCU::CUIsFromSameSliceTileAndWavefrontRow( const TComDataCU *pCU /* Can be NULL */) const
     318{
     319  return CUIsFromSameSliceAndTile(pCU)
     320         && (!getSlice()->getPPS()->getEntropyCodingSyncEnabledFlag() || getPic()->getCtu(getCtuRsAddr())->getCUPelY() == getPic()->getCtu(pCU->getCtuRsAddr())->getCUPelY());
     321}
     322
     323Bool TComDataCU::isLastSubCUOfCtu(const UInt absPartIdx)
     324{
     325  TComPic* pcPic = getPic();
     326  TComSlice * pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
     327
     328  const UInt picWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
     329  const UInt picHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
     330  const UInt granularityWidth = g_uiMaxCUWidth;
     331
     332  const UInt cuPosX = getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ];
     333  const UInt cuPosY = getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ];
     334
     335  return (((cuPosX+getWidth( absPartIdx))%granularityWidth==0||(cuPosX+getWidth( absPartIdx)==picWidth ))
     336       && ((cuPosY+getHeight(absPartIdx))%granularityWidth==0||(cuPosY+getHeight(absPartIdx)==picHeight)));
    316337}
    317338
     
    332353 \param  iCUAddr   CU address
    333354 */
    334 Void TComDataCU::initCU( TComPic* pcPic, UInt iCUAddr )
     355Void TComDataCU::initCtu( TComPic* pcPic, UInt ctuRsAddr )
    335356{
    336357
    337358  m_pcPic              = pcPic;
    338359  m_pcSlice            = pcPic->getSlice(pcPic->getCurrSliceIdx());
    339   m_uiCUAddr           = iCUAddr;
    340   m_uiCUPelX           = ( iCUAddr % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth;
    341   m_uiCUPelY           = ( iCUAddr / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight;
    342   m_uiAbsIdxInLCU      = 0;
     360  m_ctuRsAddr          = ctuRsAddr;
     361  m_uiCUPelX           = ( ctuRsAddr % pcPic->getFrameWidthInCtus() ) * g_uiMaxCUWidth;
     362  m_uiCUPelY           = ( ctuRsAddr / pcPic->getFrameWidthInCtus() ) * g_uiMaxCUHeight;
     363  m_absZIdxInCtu       = 0;
    343364  m_dTotalCost         = MAX_DOUBLE;
    344365  m_uiTotalDistortion  = 0;
    345366  m_uiTotalBits        = 0;
    346367  m_uiTotalBins        = 0;
    347   m_uiNumPartition     = pcPic->getNumPartInCU();
     368  m_uiNumPartition     = pcPic->getNumPartitionsInCtu();
     369
     370  memset( m_skipFlag          , false,                      m_uiNumPartition * sizeof( *m_skipFlag ) );
    348371
    349372#if SVC_EXTENSION
    350373  m_layerId           = pcPic->getLayerId();
    351 #endif
    352  
    353   for(Int i=0; i<pcPic->getNumPartInCU(); i++)
    354   {
    355     if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceCurStartCUAddr())
    356     {
    357       m_sliceStartCU[i]=getSlice()->getSliceCurStartCUAddr();
    358     }
    359     else
    360     {
    361       m_sliceStartCU[i]=pcPic->getCU(getAddr())->m_sliceStartCU[i];
    362     }
    363   }
    364   for(Int i=0; i<pcPic->getNumPartInCU(); i++)
    365   {
    366     if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceSegmentCurStartCUAddr())
    367     {
    368       m_sliceSegmentStartCU[i]=getSlice()->getSliceSegmentCurStartCUAddr();
    369     }
    370     else
    371     {
    372       m_sliceSegmentStartCU[i]=pcPic->getCU(getAddr())->m_sliceSegmentStartCU[i];
    373     }
    374   }
    375 
    376   Int partStartIdx = getSlice()->getSliceSegmentCurStartCUAddr() - pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr) * pcPic->getNumPartInCU();
    377 
    378   Int numElements = min<Int>( partStartIdx, m_uiNumPartition );
    379   for ( Int ui = 0; ui < numElements; ui++ )
    380   {
    381     TComDataCU * pcFrom = pcPic->getCU(getAddr());
    382     m_skipFlag[ui]   = pcFrom->getSkipFlag(ui);
    383     m_pePartSize[ui] = pcFrom->getPartitionSize(ui);
    384     m_pePredMode[ui] = pcFrom->getPredictionMode(ui);
    385     m_CUTransquantBypass[ui] = pcFrom->getCUTransquantBypass(ui);
    386     m_puhDepth[ui] = pcFrom->getDepth(ui);
    387     m_puhWidth  [ui] = pcFrom->getWidth(ui);
    388     m_puhHeight [ui] = pcFrom->getHeight(ui);
    389     m_puhTrIdx  [ui] = pcFrom->getTransformIdx(ui);
    390     m_puhTransformSkip[0][ui] = pcFrom->getTransformSkip(ui,TEXT_LUMA);
    391     m_puhTransformSkip[1][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_U);
    392     m_puhTransformSkip[2][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_V);
    393     m_apiMVPIdx[0][ui] = pcFrom->m_apiMVPIdx[0][ui];;
    394     m_apiMVPIdx[1][ui] = pcFrom->m_apiMVPIdx[1][ui];
    395     m_apiMVPNum[0][ui] = pcFrom->m_apiMVPNum[0][ui];
    396     m_apiMVPNum[1][ui] = pcFrom->m_apiMVPNum[1][ui];
    397     m_phQP[ui]=pcFrom->m_phQP[ui];
    398     m_pbMergeFlag[ui]=pcFrom->m_pbMergeFlag[ui];
    399     m_puhMergeIndex[ui]=pcFrom->m_puhMergeIndex[ui];
    400     m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
    401     m_puhChromaIntraDir[ui]=pcFrom->m_puhChromaIntraDir[ui];
    402     m_puhInterDir[ui]=pcFrom->m_puhInterDir[ui];
    403     m_puhCbf[0][ui]=pcFrom->m_puhCbf[0][ui];
    404     m_puhCbf[1][ui]=pcFrom->m_puhCbf[1][ui];
    405     m_puhCbf[2][ui]=pcFrom->m_puhCbf[2][ui];
    406     m_pbIPCMFlag[ui] = pcFrom->m_pbIPCMFlag[ui];
    407   }
    408  
    409   Int firstElement = max<Int>( partStartIdx, 0 );
    410   numElements = m_uiNumPartition - firstElement;
    411  
    412   if ( numElements > 0 )
    413   {
    414     memset( m_skipFlag          + firstElement, false,                    numElements * sizeof( *m_skipFlag ) );
    415 
    416     memset( m_pePartSize        + firstElement, SIZE_NONE,                numElements * sizeof( *m_pePartSize ) );
    417     memset( m_pePredMode        + firstElement, MODE_NONE,                numElements * sizeof( *m_pePredMode ) );
    418     memset( m_CUTransquantBypass+ firstElement, false,                    numElements * sizeof( *m_CUTransquantBypass) );
    419     memset( m_puhDepth          + firstElement, 0,                        numElements * sizeof( *m_puhDepth ) );
    420     memset( m_puhTrIdx          + firstElement, 0,                        numElements * sizeof( *m_puhTrIdx ) );
    421     memset( m_puhTransformSkip[0] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[0]) );
    422     memset( m_puhTransformSkip[1] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[1]) );
    423     memset( m_puhTransformSkip[2] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[2]) );
    424     memset( m_puhWidth          + firstElement, g_uiMaxCUWidth,           numElements * sizeof( *m_puhWidth ) );
    425     memset( m_puhHeight         + firstElement, g_uiMaxCUHeight,          numElements * sizeof( *m_puhHeight ) );
    426     memset( m_apiMVPIdx[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[0] ) );
    427     memset( m_apiMVPIdx[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[1] ) );
    428     memset( m_apiMVPNum[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[0] ) );
    429     memset( m_apiMVPNum[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[1] ) );
    430     memset( m_phQP              + firstElement, getSlice()->getSliceQp(), numElements * sizeof( *m_phQP ) );
    431     memset( m_pbMergeFlag       + firstElement, false,                    numElements * sizeof( *m_pbMergeFlag ) );
    432     memset( m_puhMergeIndex     + firstElement, 0,                        numElements * sizeof( *m_puhMergeIndex ) );
    433     memset( m_puhLumaIntraDir   + firstElement, DC_IDX,                   numElements * sizeof( *m_puhLumaIntraDir ) );
    434     memset( m_puhChromaIntraDir + firstElement, 0,                        numElements * sizeof( *m_puhChromaIntraDir ) );
    435     memset( m_puhInterDir       + firstElement, 0,                        numElements * sizeof( *m_puhInterDir ) );
    436     memset( m_puhCbf[0]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[0] ) );
    437     memset( m_puhCbf[1]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[1] ) );
    438     memset( m_puhCbf[2]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[2] ) );
    439     memset( m_pbIPCMFlag        + firstElement, false,                    numElements * sizeof( *m_pbIPCMFlag ) );
    440   }
    441  
    442   UInt uiTmp = g_uiMaxCUWidth*g_uiMaxCUHeight;
    443   if ( 0 >= partStartIdx )
    444   {
    445     m_acCUMvField[0].clearMvField();
    446     m_acCUMvField[1].clearMvField();
    447     memset( m_pcTrCoeffY , 0, sizeof( TCoeff ) * uiTmp );
     374#endif
     375
     376  memset( m_pePartSize        , NUMBER_OF_PART_SIZES,       m_uiNumPartition * sizeof( *m_pePartSize ) );
     377  memset( m_pePredMode        , NUMBER_OF_PREDICTION_MODES, m_uiNumPartition * sizeof( *m_pePredMode ) );
     378  memset( m_CUTransquantBypass, false,                      m_uiNumPartition * sizeof( *m_CUTransquantBypass) );
     379  memset( m_puhDepth          , 0,                          m_uiNumPartition * sizeof( *m_puhDepth ) );
     380  memset( m_puhTrIdx          , 0,                          m_uiNumPartition * sizeof( *m_puhTrIdx ) );
     381  memset( m_puhWidth          , g_uiMaxCUWidth,             m_uiNumPartition * sizeof( *m_puhWidth ) );
     382  memset( m_puhHeight         , g_uiMaxCUHeight,            m_uiNumPartition * sizeof( *m_puhHeight ) );
     383  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     384  {
     385    const RefPicList rpl=RefPicList(i);
     386    memset( m_apiMVPIdx[rpl]  , -1,                         m_uiNumPartition * sizeof( *m_apiMVPIdx[rpl] ) );
     387    memset( m_apiMVPNum[rpl]  , -1,                         m_uiNumPartition * sizeof( *m_apiMVPNum[rpl] ) );
     388  }
     389  memset( m_phQP              , getSlice()->getSliceQp(),   m_uiNumPartition * sizeof( *m_phQP ) );
     390  memset( m_ChromaQpAdj       , 0,                          m_uiNumPartition * sizeof( *m_ChromaQpAdj ) );
     391  for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     392  {
     393    memset( m_crossComponentPredictionAlpha[comp] , 0,                     m_uiNumPartition * sizeof( *m_crossComponentPredictionAlpha[comp] ) );
     394    memset( m_puhTransformSkip[comp]              , 0,                     m_uiNumPartition * sizeof( *m_puhTransformSkip[comp]) );
     395    memset( m_puhCbf[comp]                        , 0,                     m_uiNumPartition * sizeof( *m_puhCbf[comp] ) );
     396    memset( m_explicitRdpcmMode[comp]             , NUMBER_OF_RDPCM_MODES, m_uiNumPartition * sizeof( *m_explicitRdpcmMode[comp] ) );
     397  }
     398  memset( m_pbMergeFlag       , false,                    m_uiNumPartition * sizeof( *m_pbMergeFlag ) );
     399  memset( m_puhMergeIndex     , 0,                        m_uiNumPartition * sizeof( *m_puhMergeIndex ) );
     400  for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     401  {
     402    memset( m_puhIntraDir[ch] , ((ch==0) ? DC_IDX : 0),   m_uiNumPartition * sizeof( *(m_puhIntraDir[ch]) ) );
     403  }
     404  memset( m_puhInterDir       , 0,                        m_uiNumPartition * sizeof( *m_puhInterDir ) );
     405  memset( m_pbIPCMFlag        , false,                    m_uiNumPartition * sizeof( *m_pbIPCMFlag ) );
     406
     407  const UInt numCoeffY    = g_uiMaxCUWidth*g_uiMaxCUHeight;
     408  for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     409  {
     410    const UInt componentShift = m_pcPic->getComponentScaleX(ComponentID(comp)) + m_pcPic->getComponentScaleY(ComponentID(comp));
     411    memset( m_pcTrCoeff[comp], 0, sizeof(TCoeff)* numCoeffY>>componentShift );
    448412#if ADAPTIVE_QP_SELECTION
    449     memset( m_pcArlCoeffY , 0, sizeof( Int ) * uiTmp ); 
     413    memset( m_pcArlCoeff[comp], 0, sizeof(TCoeff)* numCoeffY>>componentShift );
    450414#endif
    451     memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
    452     uiTmp  >>= 2;
    453     memset( m_pcTrCoeffCb, 0, sizeof( TCoeff ) * uiTmp );
    454     memset( m_pcTrCoeffCr, 0, sizeof( TCoeff ) * uiTmp );
    455 #if ADAPTIVE_QP_SELECTION 
    456     memset( m_pcArlCoeffCb, 0, sizeof( Int ) * uiTmp );
    457     memset( m_pcArlCoeffCr, 0, sizeof( Int ) * uiTmp );
    458 #endif
    459     memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
    460     memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
    461   }
    462   else
    463   {
    464     TComDataCU * pcFrom = pcPic->getCU(getAddr());
    465     m_acCUMvField[0].copyFrom(&pcFrom->m_acCUMvField[0],m_uiNumPartition,0);
    466     m_acCUMvField[1].copyFrom(&pcFrom->m_acCUMvField[1],m_uiNumPartition,0);
    467     for(Int i=0; i<uiTmp; i++)
    468     {
    469       m_pcTrCoeffY[i]=pcFrom->m_pcTrCoeffY[i];
    470 #if ADAPTIVE_QP_SELECTION
    471       m_pcArlCoeffY[i]=pcFrom->m_pcArlCoeffY[i];
    472 #endif
    473       m_pcIPCMSampleY[i]=pcFrom->m_pcIPCMSampleY[i];
    474     }
    475     for(Int i=0; i<(uiTmp>>2); i++)
    476     {
    477       m_pcTrCoeffCb[i]=pcFrom->m_pcTrCoeffCb[i];
    478       m_pcTrCoeffCr[i]=pcFrom->m_pcTrCoeffCr[i];
    479 #if ADAPTIVE_QP_SELECTION
    480       m_pcArlCoeffCb[i]=pcFrom->m_pcArlCoeffCb[i];
    481       m_pcArlCoeffCr[i]=pcFrom->m_pcArlCoeffCr[i];
    482 #endif
    483       m_pcIPCMSampleCb[i]=pcFrom->m_pcIPCMSampleCb[i];
    484       m_pcIPCMSampleCr[i]=pcFrom->m_pcIPCMSampleCr[i];
    485     }
     415  }
     416
     417  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     418  {
     419    m_acCUMvField[i].clearMvField();
    486420  }
    487421
    488422  // Setting neighbor CU
    489   m_pcCULeft        = NULL;
    490   m_pcCUAbove       = NULL;
    491   m_pcCUAboveLeft   = NULL;
    492   m_pcCUAboveRight  = NULL;
    493 
    494   m_apcCUColocated[0] = NULL;
    495   m_apcCUColocated[1] = NULL;
    496 
    497   UInt uiWidthInCU = pcPic->getFrameWidthInCU();
    498   if ( m_uiCUAddr % uiWidthInCU )
    499   {
    500     m_pcCULeft = pcPic->getCU( m_uiCUAddr - 1 );
    501   }
    502 
    503   if ( m_uiCUAddr / uiWidthInCU )
    504   {
    505     m_pcCUAbove = pcPic->getCU( m_uiCUAddr - uiWidthInCU );
    506   }
    507 
    508   if ( m_pcCULeft && m_pcCUAbove )
    509   {
    510     m_pcCUAboveLeft = pcPic->getCU( m_uiCUAddr - uiWidthInCU - 1 );
    511   }
    512 
    513   if ( m_pcCUAbove && ( (m_uiCUAddr%uiWidthInCU) < (uiWidthInCU-1) )  )
    514   {
    515     m_pcCUAboveRight = pcPic->getCU( m_uiCUAddr - uiWidthInCU + 1 );
    516   }
    517 
    518   if ( getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 )
    519   {
    520     m_apcCUColocated[0] = getSlice()->getRefPic( REF_PIC_LIST_0, 0)->getCU( m_uiCUAddr );
    521   }
    522 
    523   if ( getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 )
    524   {
    525     m_apcCUColocated[1] = getSlice()->getRefPic( REF_PIC_LIST_1, 0)->getCU( m_uiCUAddr );
    526   }
    527 }
    528 
    529 /** initialize prediction data with enabling sub-LCU-level delta QP
     423  m_pCtuLeft        = NULL;
     424  m_pCtuAbove       = NULL;
     425  m_pCtuAboveLeft   = NULL;
     426  m_pCtuAboveRight  = NULL;
     427
     428
     429  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     430  {
     431    m_apcCUColocated[i]  = NULL;
     432  }
     433
     434  UInt frameWidthInCtus = pcPic->getFrameWidthInCtus();
     435  if ( m_ctuRsAddr % frameWidthInCtus )
     436  {
     437    m_pCtuLeft = pcPic->getCtu( m_ctuRsAddr - 1 );
     438  }
     439
     440  if ( m_ctuRsAddr / frameWidthInCtus )
     441  {
     442    m_pCtuAbove = pcPic->getCtu( m_ctuRsAddr - frameWidthInCtus );
     443  }
     444
     445  if ( m_pCtuLeft && m_pCtuAbove )
     446  {
     447    m_pCtuAboveLeft = pcPic->getCtu( m_ctuRsAddr - frameWidthInCtus - 1 );
     448  }
     449
     450  if ( m_pCtuAbove && ( (m_ctuRsAddr%frameWidthInCtus) < (frameWidthInCtus-1) )  )
     451  {
     452    m_pCtuAboveRight = pcPic->getCtu( m_ctuRsAddr - frameWidthInCtus + 1 );
     453  }
     454
     455  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     456  {
     457    const RefPicList rpl=RefPicList(i);
     458    if ( getSlice()->getNumRefIdx( rpl ) > 0 )
     459    {
     460      m_apcCUColocated[rpl] = getSlice()->getRefPic( rpl, 0)->getCtu( m_ctuRsAddr );
     461    }
     462  }
     463}
     464
     465
     466/** initialize prediction data with enabling sub-CTU-level delta QP
    530467*\param  uiDepth  depth of the current CU
    531468*\param  qp     qp for the current CU
    532469*- set CU width and CU height according to depth
    533 *- set qp value according to input qp 
    534 *- set last-coded qp value according to input last-coded qp 
     470*- set qp value according to input qp
     471*- set last-coded qp value according to input last-coded qp
    535472*/
    536 Void TComDataCU::initEstData( UInt uiDepth, Int qp, Bool bTransquantBypass )
     473Void TComDataCU::initEstData( const UInt uiDepth, const Int qp, const Bool bTransquantBypass )
    537474{
    538475  m_dTotalCost         = MAX_DOUBLE;
     
    546483  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
    547484  {
    548     if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui >= getSlice()->getSliceSegmentCurStartCUAddr())
    549     {
    550       m_apiMVPIdx[0][ui] = -1;
    551       m_apiMVPIdx[1][ui] = -1;
    552       m_apiMVPNum[0][ui] = -1;
    553       m_apiMVPNum[1][ui] = -1;
    554       m_puhDepth  [ui] = uiDepth;
    555       m_puhWidth  [ui] = uhWidth;
    556       m_puhHeight [ui] = uhHeight;
    557       m_puhTrIdx  [ui] = 0;
    558       m_puhTransformSkip[0][ui] = 0;
    559       m_puhTransformSkip[1][ui] = 0;
    560       m_puhTransformSkip[2][ui] = 0;
    561       m_skipFlag[ui]   = false;
    562       m_pePartSize[ui] = SIZE_NONE;
    563       m_pePredMode[ui] = MODE_NONE;
    564       m_CUTransquantBypass[ui] = bTransquantBypass;
    565       m_pbIPCMFlag[ui] = 0;
    566       m_phQP[ui] = qp;
    567       m_pbMergeFlag[ui] = 0;
    568       m_puhMergeIndex[ui] = 0;
    569       m_puhLumaIntraDir[ui] = DC_IDX;
    570       m_puhChromaIntraDir[ui] = 0;
    571       m_puhInterDir[ui] = 0;
    572       m_puhCbf[0][ui] = 0;
    573       m_puhCbf[1][ui] = 0;
    574       m_puhCbf[2][ui] = 0;
    575     }
    576   }
    577 
    578   if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU >= getSlice()->getSliceSegmentCurStartCUAddr())
    579   {
    580     m_acCUMvField[0].clearMvField();
    581     m_acCUMvField[1].clearMvField();
    582     UInt uiTmp = uhWidth*uhHeight;
    583    
    584     memset( m_pcTrCoeffY,    0, uiTmp * sizeof( *m_pcTrCoeffY    ) );
     485    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     486    {
     487      const RefPicList rpl=RefPicList(i);
     488      m_apiMVPIdx[rpl][ui]  = -1;
     489      m_apiMVPNum[rpl][ui]  = -1;
     490    }
     491    m_puhDepth  [ui]    = uiDepth;
     492    m_puhWidth  [ui]    = uhWidth;
     493    m_puhHeight [ui]    = uhHeight;
     494    m_puhTrIdx  [ui]    = 0;
     495    for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     496    {
     497      m_crossComponentPredictionAlpha[comp][ui] = 0;
     498      m_puhTransformSkip             [comp][ui] = 0;
     499      m_explicitRdpcmMode            [comp][ui] = NUMBER_OF_RDPCM_MODES;
     500    }
     501    m_skipFlag[ui]      = false;
     502    m_pePartSize[ui]    = NUMBER_OF_PART_SIZES;
     503    m_pePredMode[ui]    = NUMBER_OF_PREDICTION_MODES;
     504    m_CUTransquantBypass[ui] = bTransquantBypass;
     505    m_pbIPCMFlag[ui]    = 0;
     506    m_phQP[ui]          = qp;
     507    m_ChromaQpAdj[ui]   = 0;
     508    m_pbMergeFlag[ui]   = 0;
     509    m_puhMergeIndex[ui] = 0;
     510
     511    for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     512    {
     513      m_puhIntraDir[ch][ui] = ((ch==0) ? DC_IDX : 0);
     514    }
     515
     516    m_puhInterDir[ui] = 0;
     517    for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     518    {
     519      m_puhCbf[comp][ui] = 0;
     520    }
     521  }
     522
     523  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     524  {
     525    m_acCUMvField[i].clearMvField();
     526  }
     527
     528  const UInt numCoeffY = uhWidth*uhHeight;
     529
     530  for (UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     531  {
     532    const ComponentID component = ComponentID(comp);
     533    const UInt numCoeff = numCoeffY >> (getPic()->getComponentScaleX(component) + getPic()->getComponentScaleY(component));
     534    memset( m_pcTrCoeff[comp],    0, numCoeff * sizeof( TCoeff ) );
    585535#if ADAPTIVE_QP_SELECTION
    586     memset( m_pcArlCoeffY ,  0, uiTmp * sizeof( *m_pcArlCoeffY  ) );
     536    memset( m_pcArlCoeff[comp],   0, numCoeff * sizeof( TCoeff ) );
    587537#endif
    588     memset( m_pcIPCMSampleY, 0, uiTmp * sizeof( *m_pcIPCMSampleY ) );
    589 
    590     uiTmp>>=2;
    591     memset( m_pcTrCoeffCb,    0, uiTmp * sizeof( *m_pcTrCoeffCb    ) );
    592     memset( m_pcTrCoeffCr,    0, uiTmp * sizeof( *m_pcTrCoeffCr    ) );
    593 #if ADAPTIVE_QP_SELECTION 
    594     memset( m_pcArlCoeffCb,   0, uiTmp * sizeof( *m_pcArlCoeffCb   ) );
    595     memset( m_pcArlCoeffCr,   0, uiTmp * sizeof( *m_pcArlCoeffCr   ) );
    596 #endif
    597     memset( m_pcIPCMSampleCb, 0, uiTmp * sizeof( *m_pcIPCMSampleCb ) );
    598     memset( m_pcIPCMSampleCr, 0, uiTmp * sizeof( *m_pcIPCMSampleCr ) );
     538    memset( m_pcIPCMSample[comp], 0, numCoeff * sizeof( Pel) );
    599539  }
    600540}
     
    610550  m_pcPic              = pcCU->getPic();
    611551  m_pcSlice            = m_pcPic->getSlice(m_pcPic->getCurrSliceIdx());
    612   m_uiCUAddr           = pcCU->getAddr();
    613   m_uiAbsIdxInLCU      = pcCU->getZorderIdxInCU() + uiPartOffset;
     552  m_ctuRsAddr          = pcCU->getCtuRsAddr();
     553  m_absZIdxInCtu       = pcCU->getZorderIdxInCtu() + uiPartOffset;
    614554
    615555  m_uiCUPelX           = pcCU->getCUPelX() + ( g_uiMaxCUWidth>>uiDepth  )*( uiPartUnitIdx &  1 );
     
    624564  Int iSizeInUchar = sizeof( UChar  ) * m_uiNumPartition;
    625565  Int iSizeInBool  = sizeof( Bool   ) * m_uiNumPartition;
    626 
    627566  Int sizeInChar = sizeof( Char  ) * m_uiNumPartition;
     567
    628568  memset( m_phQP,              qp,  sizeInChar );
    629 
    630569  memset( m_pbMergeFlag,        0, iSizeInBool  );
    631570  memset( m_puhMergeIndex,      0, iSizeInUchar );
    632   memset( m_puhLumaIntraDir,    DC_IDX, iSizeInUchar );
    633   memset( m_puhChromaIntraDir,  0, iSizeInUchar );
     571  for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     572  {
     573    memset( m_puhIntraDir[ch],  ((ch==0) ? DC_IDX : 0), iSizeInUchar );
     574  }
     575
    634576  memset( m_puhInterDir,        0, iSizeInUchar );
    635577  memset( m_puhTrIdx,           0, iSizeInUchar );
    636   memset( m_puhTransformSkip[0], 0, iSizeInUchar );
    637   memset( m_puhTransformSkip[1], 0, iSizeInUchar );
    638   memset( m_puhTransformSkip[2], 0, iSizeInUchar );
    639   memset( m_puhCbf[0],          0, iSizeInUchar );
    640   memset( m_puhCbf[1],          0, iSizeInUchar );
    641   memset( m_puhCbf[2],          0, iSizeInUchar );
     578
     579  for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     580  {
     581    memset( m_crossComponentPredictionAlpha[comp], 0, iSizeInUchar );
     582    memset( m_puhTransformSkip[comp],              0, iSizeInUchar );
     583    memset( m_puhCbf[comp],                        0, iSizeInUchar );
     584    memset( m_explicitRdpcmMode[comp],             NUMBER_OF_RDPCM_MODES, iSizeInUchar );
     585  }
     586
    642587  memset( m_puhDepth,     uiDepth, iSizeInUchar );
    643588
     
    650595  {
    651596    m_skipFlag[ui]   = false;
    652     m_pePartSize[ui] = SIZE_NONE;
    653     m_pePredMode[ui] = MODE_NONE;
     597    m_pePartSize[ui] = NUMBER_OF_PART_SIZES;
     598    m_pePredMode[ui] = NUMBER_OF_PREDICTION_MODES;
    654599    m_CUTransquantBypass[ui] = false;
    655     m_apiMVPIdx[0][ui] = -1;
    656     m_apiMVPIdx[1][ui] = -1;
    657     m_apiMVPNum[0][ui] = -1;
    658     m_apiMVPNum[1][ui] = -1;
    659     if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui<getSlice()->getSliceSegmentCurStartCUAddr())
    660     {
    661       m_apiMVPIdx[0][ui] = pcCU->m_apiMVPIdx[0][uiPartOffset+ui];
    662       m_apiMVPIdx[1][ui] = pcCU->m_apiMVPIdx[1][uiPartOffset+ui];;
    663       m_apiMVPNum[0][ui] = pcCU->m_apiMVPNum[0][uiPartOffset+ui];;
    664       m_apiMVPNum[1][ui] = pcCU->m_apiMVPNum[1][uiPartOffset+ui];;
    665       m_puhDepth  [ui] = pcCU->getDepth(uiPartOffset+ui);
    666       m_puhWidth  [ui] = pcCU->getWidth(uiPartOffset+ui);
    667       m_puhHeight  [ui] = pcCU->getHeight(uiPartOffset+ui);
    668       m_puhTrIdx  [ui] = pcCU->getTransformIdx(uiPartOffset+ui);
    669       m_puhTransformSkip[0][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_LUMA);
    670       m_puhTransformSkip[1][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_U);
    671       m_puhTransformSkip[2][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_V);
    672       m_skipFlag[ui]   = pcCU->getSkipFlag(uiPartOffset+ui);
    673       m_pePartSize[ui] = pcCU->getPartitionSize(uiPartOffset+ui);
    674       m_pePredMode[ui] = pcCU->getPredictionMode(uiPartOffset+ui);
    675       m_CUTransquantBypass[ui] = pcCU->getCUTransquantBypass(uiPartOffset+ui);
    676       m_pbIPCMFlag[ui]=pcCU->m_pbIPCMFlag[uiPartOffset+ui];
    677       m_phQP[ui] = pcCU->m_phQP[uiPartOffset+ui];
    678       m_pbMergeFlag[ui]=pcCU->m_pbMergeFlag[uiPartOffset+ui];
    679       m_puhMergeIndex[ui]=pcCU->m_puhMergeIndex[uiPartOffset+ui];
    680       m_puhLumaIntraDir[ui]=pcCU->m_puhLumaIntraDir[uiPartOffset+ui];
    681       m_puhChromaIntraDir[ui]=pcCU->m_puhChromaIntraDir[uiPartOffset+ui];
    682       m_puhInterDir[ui]=pcCU->m_puhInterDir[uiPartOffset+ui];
    683       m_puhCbf[0][ui]=pcCU->m_puhCbf[0][uiPartOffset+ui];
    684       m_puhCbf[1][ui]=pcCU->m_puhCbf[1][uiPartOffset+ui];
    685       m_puhCbf[2][ui]=pcCU->m_puhCbf[2][uiPartOffset+ui];
    686 
    687     }
    688   }
    689   UInt uiTmp = uhWidth*uhHeight;
    690   memset( m_pcTrCoeffY , 0, sizeof(TCoeff)*uiTmp );
    691 #if ADAPTIVE_QP_SELECTION 
    692   memset( m_pcArlCoeffY , 0, sizeof(Int)*uiTmp );
     600    m_ChromaQpAdj[ui] = 0;
     601
     602    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     603    {
     604      const RefPicList rpl=RefPicList(i);
     605      m_apiMVPIdx[rpl][ui] = -1;
     606      m_apiMVPNum[rpl][ui] = -1;
     607    }
     608  }
     609
     610  const UInt numCoeffY    = uhWidth*uhHeight;
     611  for (UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
     612  {
     613    const UInt componentShift = m_pcPic->getComponentScaleX(ComponentID(ch)) + m_pcPic->getComponentScaleY(ComponentID(ch));
     614    memset( m_pcTrCoeff[ch],  0, sizeof(TCoeff)*(numCoeffY>>componentShift) );
     615#if ADAPTIVE_QP_SELECTION
     616    memset( m_pcArlCoeff[ch], 0, sizeof(TCoeff)*(numCoeffY>>componentShift) );
    693617#endif
    694   memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
    695   uiTmp >>= 2;
    696   memset( m_pcTrCoeffCb, 0, sizeof(TCoeff)*uiTmp );
    697   memset( m_pcTrCoeffCr, 0, sizeof(TCoeff)*uiTmp );
    698 #if ADAPTIVE_QP_SELECTION
    699   memset( m_pcArlCoeffCb, 0, sizeof(Int)*uiTmp );
    700   memset( m_pcArlCoeffCr, 0, sizeof(Int)*uiTmp );
    701 #endif
    702   memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
    703   memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
    704   m_acCUMvField[0].clearMvField();
    705   m_acCUMvField[1].clearMvField();
    706 
    707   if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU<getSlice()->getSliceSegmentCurStartCUAddr())
    708   {
    709     // Part of this CU contains data from an older slice. Now copy in that data.
    710     UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
    711     UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
    712     TComDataCU * bigCU = getPic()->getCU(getAddr());
    713     Int minui = uiPartOffset;
    714     minui = -minui;
    715     pcCU->m_acCUMvField[0].copyTo(&m_acCUMvField[0],minui,uiPartOffset,m_uiNumPartition);
    716     pcCU->m_acCUMvField[1].copyTo(&m_acCUMvField[1],minui,uiPartOffset,m_uiNumPartition);
    717     UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*m_uiAbsIdxInLCU/pcCU->getPic()->getNumPartInCU();
    718     uiTmp = uhWidth*uhHeight;
    719     for(Int i=0; i<uiTmp; i++)
    720     {
    721       m_pcTrCoeffY[i]=bigCU->m_pcTrCoeffY[uiCoffOffset+i];
    722 #if ADAPTIVE_QP_SELECTION
    723       m_pcArlCoeffY[i]=bigCU->m_pcArlCoeffY[uiCoffOffset+i];
    724 #endif
    725       m_pcIPCMSampleY[i]=bigCU->m_pcIPCMSampleY[uiCoffOffset+i];
    726     }
    727     uiTmp>>=2;
    728     uiCoffOffset>>=2;
    729     for(Int i=0; i<uiTmp; i++)
    730     {
    731       m_pcTrCoeffCr[i]=bigCU->m_pcTrCoeffCr[uiCoffOffset+i];
    732       m_pcTrCoeffCb[i]=bigCU->m_pcTrCoeffCb[uiCoffOffset+i];
    733 #if ADAPTIVE_QP_SELECTION
    734       m_pcArlCoeffCr[i]=bigCU->m_pcArlCoeffCr[uiCoffOffset+i];
    735       m_pcArlCoeffCb[i]=bigCU->m_pcArlCoeffCb[uiCoffOffset+i];
    736 #endif
    737       m_pcIPCMSampleCb[i]=bigCU->m_pcIPCMSampleCb[uiCoffOffset+i];
    738       m_pcIPCMSampleCr[i]=bigCU->m_pcIPCMSampleCr[uiCoffOffset+i];
    739     }
    740   }
    741 
    742   m_pcCULeft        = pcCU->getCULeft();
    743   m_pcCUAbove       = pcCU->getCUAbove();
    744   m_pcCUAboveLeft   = pcCU->getCUAboveLeft();
    745   m_pcCUAboveRight  = pcCU->getCUAboveRight();
    746 
    747   m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
    748   m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
    749   memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
    750   memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
     618    memset( m_pcIPCMSample[ch], 0, sizeof(Pel)* (numCoeffY>>componentShift) );
     619  }
     620
     621  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     622  {
     623    m_acCUMvField[i].clearMvField();
     624  }
     625
     626  m_pCtuLeft        = pcCU->getCtuLeft();
     627  m_pCtuAbove       = pcCU->getCtuAbove();
     628  m_pCtuAboveLeft   = pcCU->getCtuAboveLeft();
     629  m_pCtuAboveRight  = pcCU->getCtuAboveRight();
     630
     631  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     632  {
     633    m_apcCUColocated[i] = pcCU->getCUColocated(RefPicList(i));
     634  }
    751635}
    752636
     
    770654{
    771655  UInt uiPart = uiAbsPartIdx;
    772  
     656
    773657  m_pcPic              = pcCU->getPic();
    774658  m_pcSlice            = pcCU->getSlice();
    775   m_uiCUAddr           = pcCU->getAddr();
    776   m_uiAbsIdxInLCU      = uiAbsPartIdx;
    777  
     659  m_ctuRsAddr          = pcCU->getCtuRsAddr();
     660  m_absZIdxInCtu       = uiAbsPartIdx;
     661
    778662  m_uiCUPelX           = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
    779663  m_uiCUPelY           = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    780  
     664
    781665  m_skipFlag=pcCU->getSkipFlag()          + uiPart;
    782666
    783667  m_phQP=pcCU->getQP()                    + uiPart;
     668  m_ChromaQpAdj = pcCU->getChromaQpAdj()  + uiPart;
    784669  m_pePartSize = pcCU->getPartitionSize() + uiPart;
    785670  m_pePredMode=pcCU->getPredictionMode()  + uiPart;
    786671  m_CUTransquantBypass  = pcCU->getCUTransquantBypass()+uiPart;
    787  
     672
    788673  m_pbMergeFlag         = pcCU->getMergeFlag()        + uiPart;
    789674  m_puhMergeIndex       = pcCU->getMergeIndex()       + uiPart;
    790675
    791   m_puhLumaIntraDir     = pcCU->getLumaIntraDir()     + uiPart;
    792   m_puhChromaIntraDir   = pcCU->getChromaIntraDir()   + uiPart;
     676  for (UInt ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     677  {
     678    m_puhIntraDir[ch]   = pcCU->getIntraDir(ChannelType(ch)) + uiPart;
     679  }
     680
    793681  m_puhInterDir         = pcCU->getInterDir()         + uiPart;
    794682  m_puhTrIdx            = pcCU->getTransformIdx()     + uiPart;
    795   m_puhTransformSkip[0] = pcCU->getTransformSkip(TEXT_LUMA)     + uiPart;
    796   m_puhTransformSkip[1] = pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPart;
    797   m_puhTransformSkip[2] = pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPart;
    798 
    799   m_puhCbf[0]= pcCU->getCbf(TEXT_LUMA)            + uiPart;
    800   m_puhCbf[1]= pcCU->getCbf(TEXT_CHROMA_U)        + uiPart;
    801   m_puhCbf[2]= pcCU->getCbf(TEXT_CHROMA_V)        + uiPart;
    802  
     683
     684  for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     685  {
     686    m_crossComponentPredictionAlpha[comp] = pcCU->getCrossComponentPredictionAlpha(ComponentID(comp)) + uiPart;
     687    m_puhTransformSkip[comp]              = pcCU->getTransformSkip(ComponentID(comp))                 + uiPart;
     688    m_puhCbf[comp]                        = pcCU->getCbf(ComponentID(comp))                           + uiPart;
     689    m_explicitRdpcmMode[comp]             = pcCU->getExplicitRdpcmMode(ComponentID(comp))             + uiPart;
     690  }
     691
    803692  m_puhDepth=pcCU->getDepth()                     + uiPart;
    804693  m_puhWidth=pcCU->getWidth()                     + uiPart;
    805694  m_puhHeight=pcCU->getHeight()                   + uiPart;
    806  
    807   m_apiMVPIdx[0]=pcCU->getMVPIdx(REF_PIC_LIST_0)  + uiPart;
    808   m_apiMVPIdx[1]=pcCU->getMVPIdx(REF_PIC_LIST_1)  + uiPart;
    809   m_apiMVPNum[0]=pcCU->getMVPNum(REF_PIC_LIST_0)  + uiPart;
    810   m_apiMVPNum[1]=pcCU->getMVPNum(REF_PIC_LIST_1)  + uiPart;
    811  
     695
    812696  m_pbIPCMFlag         = pcCU->getIPCMFlag()        + uiPart;
    813697
    814   m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
    815   m_pcCUAboveRight     = pcCU->getCUAboveRight();
    816   m_pcCUAbove          = pcCU->getCUAbove();
    817   m_pcCULeft           = pcCU->getCULeft();
    818  
    819   m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
    820   m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
    821  
     698  m_pCtuAboveLeft      = pcCU->getCtuAboveLeft();
     699  m_pCtuAboveRight     = pcCU->getCtuAboveRight();
     700  m_pCtuAbove          = pcCU->getCtuAbove();
     701  m_pCtuLeft           = pcCU->getCtuLeft();
     702
     703  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     704  {
     705    const RefPicList rpl=RefPicList(i);
     706    m_apcCUColocated[rpl] = pcCU->getCUColocated(rpl);
     707    m_apiMVPIdx[rpl]=pcCU->getMVPIdx(rpl)  + uiPart;
     708    m_apiMVPNum[rpl]=pcCU->getMVPNum(rpl)  + uiPart;
     709  }
     710
     711  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     712  {
     713    const RefPicList rpl=RefPicList(i);
     714    m_acCUMvField[rpl].linkToWithOffset( pcCU->getCUMvField(rpl), uiPart );
     715  }
     716
    822717  UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
    823718  UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
    824  
    825   UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*uiAbsPartIdx/pcCU->getPic()->getNumPartInCU();
    826  
    827   m_pcTrCoeffY = pcCU->getCoeffY() + uiCoffOffset;
     719
     720  UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*uiAbsPartIdx/pcCU->getPic()->getNumPartitionsInCtu();
     721
     722  for (UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
     723  {
     724    const ComponentID component = ComponentID(ch);
     725    const UInt componentShift   = m_pcPic->getComponentScaleX(component) + m_pcPic->getComponentScaleY(component);
     726    const UInt offset           = uiCoffOffset >> componentShift;
     727    m_pcTrCoeff[ch] = pcCU->getCoeff(component) + offset;
    828728#if ADAPTIVE_QP_SELECTION
    829   m_pcArlCoeffY= pcCU->getArlCoeffY() + uiCoffOffset; 
     729    m_pcArlCoeff[ch] = pcCU->getArlCoeff(component) + offset;
    830730#endif
    831   m_pcIPCMSampleY = pcCU->getPCMSampleY() + uiCoffOffset;
    832 
    833   uiCoffOffset >>=2;
    834   m_pcTrCoeffCb=pcCU->getCoeffCb() + uiCoffOffset;
    835   m_pcTrCoeffCr=pcCU->getCoeffCr() + uiCoffOffset;
    836 #if ADAPTIVE_QP_SELECTION 
    837   m_pcArlCoeffCb=pcCU->getArlCoeffCb() + uiCoffOffset;
    838   m_pcArlCoeffCr=pcCU->getArlCoeffCr() + uiCoffOffset;
    839 #endif
    840   m_pcIPCMSampleCb = pcCU->getPCMSampleCb() + uiCoffOffset;
    841   m_pcIPCMSampleCr = pcCU->getPCMSampleCr() + uiCoffOffset;
    842 
    843   m_acCUMvField[0].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_0), uiPart );
    844   m_acCUMvField[1].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_1), uiPart );
    845   memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
    846   memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
     731    m_pcIPCMSample[ch] = pcCU->getPCMSample(component) + offset;
     732  }
    847733}
    848734
     
    852738  m_pcPic              = pcCU->getPic();
    853739  m_pcSlice            = pcCU->getSlice();
    854   m_uiCUAddr           = pcCU->getAddr();
    855   m_uiAbsIdxInLCU      = uiAbsPartIdx;
    856  
     740  m_ctuRsAddr          = pcCU->getCtuRsAddr();
     741  m_absZIdxInCtu       = uiAbsPartIdx;
     742
    857743  Int iRastPartIdx     = g_auiZscanToRaster[uiAbsPartIdx];
    858   m_uiCUPelX           = pcCU->getCUPelX() + m_pcPic->getMinCUWidth ()*( iRastPartIdx % m_pcPic->getNumPartInWidth() );
    859   m_uiCUPelY           = pcCU->getCUPelY() + m_pcPic->getMinCUHeight()*( iRastPartIdx / m_pcPic->getNumPartInWidth() );
    860  
    861   m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
    862   m_pcCUAboveRight     = pcCU->getCUAboveRight();
    863   m_pcCUAbove          = pcCU->getCUAbove();
    864   m_pcCULeft           = pcCU->getCULeft();
    865  
    866   m_apcCUColocated[0]  = pcCU->getCUColocated(REF_PIC_LIST_0);
    867   m_apcCUColocated[1]  = pcCU->getCUColocated(REF_PIC_LIST_1);
    868  
     744  m_uiCUPelX           = pcCU->getCUPelX() + m_pcPic->getMinCUWidth ()*( iRastPartIdx % m_pcPic->getNumPartInCtuWidth() );
     745  m_uiCUPelY           = pcCU->getCUPelY() + m_pcPic->getMinCUHeight()*( iRastPartIdx / m_pcPic->getNumPartInCtuWidth() );
     746
     747  m_pCtuAboveLeft      = pcCU->getCtuAboveLeft();
     748  m_pCtuAboveRight     = pcCU->getCtuAboveRight();
     749  m_pCtuAbove          = pcCU->getCtuAbove();
     750  m_pCtuLeft           = pcCU->getCtuLeft();
     751
     752  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     753  {
     754    m_apcCUColocated[i]  = pcCU->getCUColocated(RefPicList(i));
     755  }
     756
    869757  m_skipFlag           = pcCU->getSkipFlag ()             + uiAbsPartIdx;
    870758
    871759  m_pePartSize         = pcCU->getPartitionSize ()        + uiAbsPartIdx;
    872760  m_pePredMode         = pcCU->getPredictionMode()        + uiAbsPartIdx;
     761  m_ChromaQpAdj        = pcCU->getChromaQpAdj()           + uiAbsPartIdx;
    873762  m_CUTransquantBypass = pcCU->getCUTransquantBypass()    + uiAbsPartIdx;
    874763  m_puhInterDir        = pcCU->getInterDir      ()        + uiAbsPartIdx;
    875  
     764
    876765  m_puhDepth           = pcCU->getDepth ()                + uiAbsPartIdx;
    877766  m_puhWidth           = pcCU->getWidth ()                + uiAbsPartIdx;
    878767  m_puhHeight          = pcCU->getHeight()                + uiAbsPartIdx;
    879  
     768
    880769  m_pbMergeFlag        = pcCU->getMergeFlag()             + uiAbsPartIdx;
    881770  m_puhMergeIndex      = pcCU->getMergeIndex()            + uiAbsPartIdx;
     
    883772  m_apiMVPIdx[eRefPicList] = pcCU->getMVPIdx(eRefPicList) + uiAbsPartIdx;
    884773  m_apiMVPNum[eRefPicList] = pcCU->getMVPNum(eRefPicList) + uiAbsPartIdx;
    885  
     774
    886775  m_acCUMvField[ eRefPicList ].linkToWithOffset( pcCU->getCUMvField(eRefPicList), uiAbsPartIdx );
    887 
    888   memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
    889   memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
    890776}
    891777
     
    895781{
    896782  assert( uiPartUnitIdx<4 );
    897  
     783
    898784  m_dTotalCost         += pcCU->getTotalCost();
    899785  m_uiTotalDistortion  += pcCU->getTotalDistortion();
    900786  m_uiTotalBits        += pcCU->getTotalBits();
    901  
     787
    902788  UInt uiOffset         = pcCU->getTotalNumPart()*uiPartUnitIdx;
    903  
     789  const UInt numValidComp=pcCU->getPic()->getNumberValidComponents();
     790  const UInt numValidChan=pcCU->getPic()->getChromaFormat()==CHROMA_400 ? 1:2;
     791
    904792  UInt uiNumPartition = pcCU->getTotalNumPart();
    905793  Int iSizeInUchar  = sizeof( UChar ) * uiNumPartition;
    906794  Int iSizeInBool   = sizeof( Bool  ) * uiNumPartition;
    907  
     795
    908796  Int sizeInChar  = sizeof( Char ) * uiNumPartition;
    909797  memcpy( m_skipFlag   + uiOffset, pcCU->getSkipFlag(),       sizeof( *m_skipFlag )   * uiNumPartition );
     
    911799  memcpy( m_pePartSize + uiOffset, pcCU->getPartitionSize(),  sizeof( *m_pePartSize ) * uiNumPartition );
    912800  memcpy( m_pePredMode + uiOffset, pcCU->getPredictionMode(), sizeof( *m_pePredMode ) * uiNumPartition );
     801  memcpy( m_ChromaQpAdj + uiOffset, pcCU->getChromaQpAdj(),   sizeof( *m_ChromaQpAdj ) * uiNumPartition );
    913802  memcpy( m_CUTransquantBypass + uiOffset, pcCU->getCUTransquantBypass(), sizeof( *m_CUTransquantBypass ) * uiNumPartition );
    914803  memcpy( m_pbMergeFlag         + uiOffset, pcCU->getMergeFlag(),         iSizeInBool  );
    915804  memcpy( m_puhMergeIndex       + uiOffset, pcCU->getMergeIndex(),        iSizeInUchar );
    916   memcpy( m_puhLumaIntraDir     + uiOffset, pcCU->getLumaIntraDir(),      iSizeInUchar );
    917   memcpy( m_puhChromaIntraDir   + uiOffset, pcCU->getChromaIntraDir(),    iSizeInUchar );
     805
     806  for (UInt ch=0; ch<numValidChan; ch++)
     807  {
     808    memcpy( m_puhIntraDir[ch]   + uiOffset, pcCU->getIntraDir(ChannelType(ch)), iSizeInUchar );
     809  }
     810
    918811  memcpy( m_puhInterDir         + uiOffset, pcCU->getInterDir(),          iSizeInUchar );
    919812  memcpy( m_puhTrIdx            + uiOffset, pcCU->getTransformIdx(),      iSizeInUchar );
    920   memcpy( m_puhTransformSkip[0] + uiOffset, pcCU->getTransformSkip(TEXT_LUMA),     iSizeInUchar );
    921   memcpy( m_puhTransformSkip[1] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_U), iSizeInUchar );
    922   memcpy( m_puhTransformSkip[2] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_V), iSizeInUchar );
    923 
    924   memcpy( m_puhCbf[0] + uiOffset, pcCU->getCbf(TEXT_LUMA)    , iSizeInUchar );
    925   memcpy( m_puhCbf[1] + uiOffset, pcCU->getCbf(TEXT_CHROMA_U), iSizeInUchar );
    926   memcpy( m_puhCbf[2] + uiOffset, pcCU->getCbf(TEXT_CHROMA_V), iSizeInUchar );
    927  
     813
     814  for(UInt comp=0; comp<numValidComp; comp++)
     815  {
     816    memcpy( m_crossComponentPredictionAlpha[comp] + uiOffset, pcCU->getCrossComponentPredictionAlpha(ComponentID(comp)), iSizeInUchar );
     817    memcpy( m_puhTransformSkip[comp]              + uiOffset, pcCU->getTransformSkip(ComponentID(comp))                , iSizeInUchar );
     818    memcpy( m_puhCbf[comp]                        + uiOffset, pcCU->getCbf(ComponentID(comp))                          , iSizeInUchar );
     819    memcpy( m_explicitRdpcmMode[comp]             + uiOffset, pcCU->getExplicitRdpcmMode(ComponentID(comp))            , iSizeInUchar );
     820  }
     821
    928822  memcpy( m_puhDepth  + uiOffset, pcCU->getDepth(),  iSizeInUchar );
    929823  memcpy( m_puhWidth  + uiOffset, pcCU->getWidth(),  iSizeInUchar );
    930824  memcpy( m_puhHeight + uiOffset, pcCU->getHeight(), iSizeInUchar );
    931  
    932   memcpy( m_apiMVPIdx[0] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_0), iSizeInUchar );
    933   memcpy( m_apiMVPIdx[1] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_1), iSizeInUchar );
    934   memcpy( m_apiMVPNum[0] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_0), iSizeInUchar );
    935   memcpy( m_apiMVPNum[1] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_1), iSizeInUchar );
    936  
     825
    937826  memcpy( m_pbIPCMFlag + uiOffset, pcCU->getIPCMFlag(), iSizeInBool );
    938827
    939   m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
    940   m_pcCUAboveRight     = pcCU->getCUAboveRight();
    941   m_pcCUAbove          = pcCU->getCUAbove();
    942   m_pcCULeft           = pcCU->getCULeft();
    943  
    944   m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
    945   m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
    946  
    947   m_acCUMvField[0].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_0 ), pcCU->getTotalNumPart(), uiOffset );
    948   m_acCUMvField[1].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_1 ), pcCU->getTotalNumPart(), uiOffset );
    949  
    950   UInt uiTmp  = g_uiMaxCUWidth*g_uiMaxCUHeight >> (uiDepth<<1);
    951   UInt uiTmp2 = uiPartUnitIdx*uiTmp;
    952   memcpy( m_pcTrCoeffY  + uiTmp2, pcCU->getCoeffY(),  sizeof(TCoeff)*uiTmp );
     828  m_pCtuAboveLeft      = pcCU->getCtuAboveLeft();
     829  m_pCtuAboveRight     = pcCU->getCtuAboveRight();
     830  m_pCtuAbove          = pcCU->getCtuAbove();
     831  m_pCtuLeft           = pcCU->getCtuLeft();
     832
     833  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     834  {
     835    const RefPicList rpl=RefPicList(i);
     836    memcpy( m_apiMVPIdx[rpl] + uiOffset, pcCU->getMVPIdx(rpl), iSizeInUchar );
     837    memcpy( m_apiMVPNum[rpl] + uiOffset, pcCU->getMVPNum(rpl), iSizeInUchar );
     838    m_apcCUColocated[rpl] = pcCU->getCUColocated(rpl);
     839  }
     840
     841  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     842  {
     843    const RefPicList rpl=RefPicList(i);
     844    m_acCUMvField[rpl].copyFrom( pcCU->getCUMvField( rpl ), pcCU->getTotalNumPart(), uiOffset );
     845  }
     846
     847  const UInt numCoeffY = g_uiMaxCUWidth*g_uiMaxCUHeight >> (uiDepth<<1);
     848  const UInt offsetY   = uiPartUnitIdx*numCoeffY;
     849  for (UInt ch=0; ch<numValidComp; ch++)
     850  {
     851    const ComponentID component = ComponentID(ch);
     852    const UInt componentShift   = m_pcPic->getComponentScaleX(component) + m_pcPic->getComponentScaleY(component);
     853    const UInt offset           = offsetY>>componentShift;
     854    memcpy( m_pcTrCoeff [ch] + offset, pcCU->getCoeff(component),    sizeof(TCoeff)*(numCoeffY>>componentShift) );
    953855#if ADAPTIVE_QP_SELECTION
    954   memcpy( m_pcArlCoeffY  + uiTmp2, pcCU->getArlCoeffY(),  sizeof(Int)*uiTmp );
     856    memcpy( m_pcArlCoeff[ch] + offset, pcCU->getArlCoeff(component), sizeof(TCoeff)*(numCoeffY>>componentShift) );
    955857#endif
    956   memcpy( m_pcIPCMSampleY + uiTmp2 , pcCU->getPCMSampleY(), sizeof(Pel) * uiTmp );
    957 
    958   uiTmp >>= 2; uiTmp2>>= 2;
    959   memcpy( m_pcTrCoeffCb + uiTmp2, pcCU->getCoeffCb(), sizeof(TCoeff)*uiTmp );
    960   memcpy( m_pcTrCoeffCr + uiTmp2, pcCU->getCoeffCr(), sizeof(TCoeff)*uiTmp );
    961 #if ADAPTIVE_QP_SELECTION
    962   memcpy( m_pcArlCoeffCb + uiTmp2, pcCU->getArlCoeffCb(), sizeof(Int)*uiTmp );
    963   memcpy( m_pcArlCoeffCr + uiTmp2, pcCU->getArlCoeffCr(), sizeof(Int)*uiTmp );
    964 #endif
    965   memcpy( m_pcIPCMSampleCb + uiTmp2 , pcCU->getPCMSampleCb(), sizeof(Pel) * uiTmp );
    966   memcpy( m_pcIPCMSampleCr + uiTmp2 , pcCU->getPCMSampleCr(), sizeof(Pel) * uiTmp );
     858    memcpy( m_pcIPCMSample[ch] + offset, pcCU->getPCMSample(component), sizeof(Pel)*(numCoeffY>>componentShift) );
     859  }
     860
    967861  m_uiTotalBins += pcCU->getTotalBins();
    968   memcpy( m_sliceStartCU        + uiOffset, pcCU->m_sliceStartCU,        sizeof( UInt ) * uiNumPartition  );
    969   memcpy( m_sliceSegmentStartCU + uiOffset, pcCU->m_sliceSegmentStartCU, sizeof( UInt ) * uiNumPartition  );
    970862}
    971863
     
    974866Void TComDataCU::copyToPic( UChar uhDepth )
    975867{
    976   TComDataCU*& rpcCU = m_pcPic->getCU( m_uiCUAddr );
    977  
    978   rpcCU->getTotalCost()       = m_dTotalCost;
    979   rpcCU->getTotalDistortion() = m_uiTotalDistortion;
    980   rpcCU->getTotalBits()       = m_uiTotalBits;
    981  
     868  TComDataCU* pCtu = m_pcPic->getCtu( m_ctuRsAddr );
     869  const UInt numValidComp=pCtu->getPic()->getNumberValidComponents();
     870  const UInt numValidChan=pCtu->getPic()->getChromaFormat()==CHROMA_400 ? 1:2;
     871
     872  pCtu->getTotalCost()       = m_dTotalCost;
     873  pCtu->getTotalDistortion() = m_uiTotalDistortion;
     874  pCtu->getTotalBits()       = m_uiTotalBits;
     875
    982876  Int iSizeInUchar  = sizeof( UChar ) * m_uiNumPartition;
    983877  Int iSizeInBool   = sizeof( Bool  ) * m_uiNumPartition;
    984  
    985878  Int sizeInChar  = sizeof( Char ) * m_uiNumPartition;
    986879
    987   memcpy( rpcCU->getSkipFlag() + m_uiAbsIdxInLCU, m_skipFlag, sizeof( *m_skipFlag ) * m_uiNumPartition );
    988 
    989   memcpy( rpcCU->getQP() + m_uiAbsIdxInLCU, m_phQP, sizeInChar  );
    990 
    991   memcpy( rpcCU->getPartitionSize()  + m_uiAbsIdxInLCU, m_pePartSize, sizeof( *m_pePartSize ) * m_uiNumPartition );
    992   memcpy( rpcCU->getPredictionMode() + m_uiAbsIdxInLCU, m_pePredMode, sizeof( *m_pePredMode ) * m_uiNumPartition );
    993   memcpy( rpcCU->getCUTransquantBypass()+ m_uiAbsIdxInLCU, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * m_uiNumPartition );
    994   memcpy( rpcCU->getMergeFlag()         + m_uiAbsIdxInLCU, m_pbMergeFlag,         iSizeInBool  );
    995   memcpy( rpcCU->getMergeIndex()        + m_uiAbsIdxInLCU, m_puhMergeIndex,       iSizeInUchar );
    996   memcpy( rpcCU->getLumaIntraDir()      + m_uiAbsIdxInLCU, m_puhLumaIntraDir,     iSizeInUchar );
    997   memcpy( rpcCU->getChromaIntraDir()    + m_uiAbsIdxInLCU, m_puhChromaIntraDir,   iSizeInUchar );
    998   memcpy( rpcCU->getInterDir()          + m_uiAbsIdxInLCU, m_puhInterDir,         iSizeInUchar );
    999   memcpy( rpcCU->getTransformIdx()      + m_uiAbsIdxInLCU, m_puhTrIdx,            iSizeInUchar );
    1000   memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhTransformSkip[0], iSizeInUchar );
    1001   memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhTransformSkip[1], iSizeInUchar );
    1002   memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhTransformSkip[2], iSizeInUchar );
    1003 
    1004   memcpy( rpcCU->getCbf(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhCbf[0], iSizeInUchar );
    1005   memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhCbf[1], iSizeInUchar );
    1006   memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhCbf[2], iSizeInUchar );
    1007  
    1008   memcpy( rpcCU->getDepth()  + m_uiAbsIdxInLCU, m_puhDepth,  iSizeInUchar );
    1009   memcpy( rpcCU->getWidth()  + m_uiAbsIdxInLCU, m_puhWidth,  iSizeInUchar );
    1010   memcpy( rpcCU->getHeight() + m_uiAbsIdxInLCU, m_puhHeight, iSizeInUchar );
    1011  
    1012   memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPIdx[0], iSizeInUchar );
    1013   memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPIdx[1], iSizeInUchar );
    1014   memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPNum[0], iSizeInUchar );
    1015   memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPNum[1], iSizeInUchar );
    1016  
    1017   m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU );
    1018   m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU );
    1019  
    1020   memcpy( rpcCU->getIPCMFlag() + m_uiAbsIdxInLCU, m_pbIPCMFlag,         iSizeInBool  );
    1021 
    1022   UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>(uhDepth<<1);
    1023   UInt uiTmp2 = m_uiAbsIdxInLCU*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
    1024   memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
    1025 #if ADAPTIVE_QP_SELECTION 
    1026   memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
     880  memcpy( pCtu->getSkipFlag() + m_absZIdxInCtu, m_skipFlag, sizeof( *m_skipFlag ) * m_uiNumPartition );
     881
     882  memcpy( pCtu->getQP() + m_absZIdxInCtu, m_phQP, sizeInChar  );
     883
     884  memcpy( pCtu->getPartitionSize()  + m_absZIdxInCtu, m_pePartSize, sizeof( *m_pePartSize ) * m_uiNumPartition );
     885  memcpy( pCtu->getPredictionMode() + m_absZIdxInCtu, m_pePredMode, sizeof( *m_pePredMode ) * m_uiNumPartition );
     886  memcpy( pCtu->getChromaQpAdj() + m_absZIdxInCtu, m_ChromaQpAdj, sizeof( *m_ChromaQpAdj ) * m_uiNumPartition );
     887  memcpy( pCtu->getCUTransquantBypass()+ m_absZIdxInCtu, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * m_uiNumPartition );
     888  memcpy( pCtu->getMergeFlag()         + m_absZIdxInCtu, m_pbMergeFlag,         iSizeInBool  );
     889  memcpy( pCtu->getMergeIndex()        + m_absZIdxInCtu, m_puhMergeIndex,       iSizeInUchar );
     890  for (UInt ch=0; ch<numValidChan; ch++)
     891  {
     892    memcpy( pCtu->getIntraDir(ChannelType(ch)) + m_absZIdxInCtu, m_puhIntraDir[ch], iSizeInUchar);
     893  }
     894
     895  memcpy( pCtu->getInterDir()          + m_absZIdxInCtu, m_puhInterDir,         iSizeInUchar );
     896  memcpy( pCtu->getTransformIdx()      + m_absZIdxInCtu, m_puhTrIdx,            iSizeInUchar );
     897
     898  for(UInt comp=0; comp<numValidComp; comp++)
     899  {
     900    memcpy( pCtu->getCrossComponentPredictionAlpha(ComponentID(comp)) + m_absZIdxInCtu, m_crossComponentPredictionAlpha[comp], iSizeInUchar );
     901    memcpy( pCtu->getTransformSkip(ComponentID(comp))                 + m_absZIdxInCtu, m_puhTransformSkip[comp],              iSizeInUchar );
     902    memcpy( pCtu->getCbf(ComponentID(comp))                           + m_absZIdxInCtu, m_puhCbf[comp],                        iSizeInUchar );
     903    memcpy( pCtu->getExplicitRdpcmMode(ComponentID(comp))             + m_absZIdxInCtu, m_explicitRdpcmMode[comp],             iSizeInUchar );
     904  }
     905
     906  memcpy( pCtu->getDepth()  + m_absZIdxInCtu, m_puhDepth,  iSizeInUchar );
     907  memcpy( pCtu->getWidth()  + m_absZIdxInCtu, m_puhWidth,  iSizeInUchar );
     908  memcpy( pCtu->getHeight() + m_absZIdxInCtu, m_puhHeight, iSizeInUchar );
     909
     910  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     911  {
     912    const RefPicList rpl=RefPicList(i);
     913    memcpy( pCtu->getMVPIdx(rpl) + m_absZIdxInCtu, m_apiMVPIdx[rpl], iSizeInUchar );
     914    memcpy( pCtu->getMVPNum(rpl) + m_absZIdxInCtu, m_apiMVPNum[rpl], iSizeInUchar );
     915  }
     916
     917  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     918  {
     919    const RefPicList rpl=RefPicList(i);
     920    m_acCUMvField[rpl].copyTo( pCtu->getCUMvField( rpl ), m_absZIdxInCtu );
     921  }
     922
     923  memcpy( pCtu->getIPCMFlag() + m_absZIdxInCtu, m_pbIPCMFlag,         iSizeInBool  );
     924
     925  const UInt numCoeffY    = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>(uhDepth<<1);
     926  const UInt offsetY      = m_absZIdxInCtu*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
     927  for (UInt comp=0; comp<numValidComp; comp++)
     928  {
     929    const ComponentID component = ComponentID(comp);
     930    const UInt componentShift   = m_pcPic->getComponentScaleX(component) + m_pcPic->getComponentScaleY(component);
     931    memcpy( pCtu->getCoeff(component)   + (offsetY>>componentShift), m_pcTrCoeff[component], sizeof(TCoeff)*(numCoeffY>>componentShift) );
     932#if ADAPTIVE_QP_SELECTION
     933    memcpy( pCtu->getArlCoeff(component) + (offsetY>>componentShift), m_pcArlCoeff[component], sizeof(TCoeff)*(numCoeffY>>componentShift) );
    1027934#endif
    1028   memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof(Pel)*uiTmp );
    1029 
    1030   uiTmp >>= 2; uiTmp2 >>= 2;
    1031   memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
    1032   memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
    1033 #if ADAPTIVE_QP_SELECTION
    1034   memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
    1035   memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
    1036 #endif
    1037   memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
    1038   memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
    1039   rpcCU->getTotalBins() = m_uiTotalBins;
    1040   memcpy( rpcCU->m_sliceStartCU        + m_uiAbsIdxInLCU, m_sliceStartCU,        sizeof( UInt ) * m_uiNumPartition  );
    1041   memcpy( rpcCU->m_sliceSegmentStartCU + m_uiAbsIdxInLCU, m_sliceSegmentStartCU, sizeof( UInt ) * m_uiNumPartition  );
     935    memcpy( pCtu->getPCMSample(component) + (offsetY>>componentShift), m_pcIPCMSample[component], sizeof(Pel)*(numCoeffY>>componentShift) );
     936  }
     937
     938  pCtu->getTotalBins() = m_uiTotalBins;
    1042939}
    1043940
    1044941Void TComDataCU::copyToPic( UChar uhDepth, UInt uiPartIdx, UInt uiPartDepth )
    1045942{
    1046   TComDataCU*&  rpcCU       = m_pcPic->getCU( m_uiCUAddr );
     943  TComDataCU*   pCtu       = m_pcPic->getCtu( m_ctuRsAddr );
    1047944  UInt          uiQNumPart  = m_uiNumPartition>>(uiPartDepth<<1);
    1048  
     945
    1049946  UInt uiPartStart          = uiPartIdx*uiQNumPart;
    1050   UInt uiPartOffset         = m_uiAbsIdxInLCU + uiPartStart;
    1051  
    1052   rpcCU->getTotalCost()       = m_dTotalCost;
    1053   rpcCU->getTotalDistortion() = m_uiTotalDistortion;
    1054   rpcCU->getTotalBits()       = m_uiTotalBits;
    1055  
     947  UInt uiPartOffset         = m_absZIdxInCtu + uiPartStart;
     948
     949  const UInt numValidComp=pCtu->getPic()->getNumberValidComponents();
     950  const UInt numValidChan=pCtu->getPic()->getChromaFormat()==CHROMA_400 ? 1:2;
     951
     952  pCtu->getTotalCost()       = m_dTotalCost;
     953  pCtu->getTotalDistortion() = m_uiTotalDistortion;
     954  pCtu->getTotalBits()       = m_uiTotalBits;
     955
    1056956  Int iSizeInUchar  = sizeof( UChar  ) * uiQNumPart;
    1057957  Int iSizeInBool   = sizeof( Bool   ) * uiQNumPart;
    1058  
    1059958  Int sizeInChar  = sizeof( Char ) * uiQNumPart;
    1060   memcpy( rpcCU->getSkipFlag()       + uiPartOffset, m_skipFlag,   sizeof( *m_skipFlag )   * uiQNumPart );
    1061 
    1062   memcpy( rpcCU->getQP() + uiPartOffset, m_phQP, sizeInChar );
    1063   memcpy( rpcCU->getPartitionSize()  + uiPartOffset, m_pePartSize, sizeof( *m_pePartSize ) * uiQNumPart );
    1064   memcpy( rpcCU->getPredictionMode() + uiPartOffset, m_pePredMode, sizeof( *m_pePredMode ) * uiQNumPart );
    1065   memcpy( rpcCU->getCUTransquantBypass()+ uiPartOffset, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * uiQNumPart );
    1066   memcpy( rpcCU->getMergeFlag()         + uiPartOffset, m_pbMergeFlag,         iSizeInBool  );
    1067   memcpy( rpcCU->getMergeIndex()        + uiPartOffset, m_puhMergeIndex,       iSizeInUchar );
    1068   memcpy( rpcCU->getLumaIntraDir()      + uiPartOffset, m_puhLumaIntraDir,     iSizeInUchar );
    1069   memcpy( rpcCU->getChromaIntraDir()    + uiPartOffset, m_puhChromaIntraDir,   iSizeInUchar );
    1070   memcpy( rpcCU->getInterDir()          + uiPartOffset, m_puhInterDir,         iSizeInUchar );
    1071   memcpy( rpcCU->getTransformIdx()      + uiPartOffset, m_puhTrIdx,            iSizeInUchar );
    1072   memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + uiPartOffset, m_puhTransformSkip[0], iSizeInUchar );
    1073   memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, m_puhTransformSkip[1], iSizeInUchar );
    1074   memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, m_puhTransformSkip[2], iSizeInUchar );
    1075   memcpy( rpcCU->getCbf(TEXT_LUMA)     + uiPartOffset, m_puhCbf[0], iSizeInUchar );
    1076   memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + uiPartOffset, m_puhCbf[1], iSizeInUchar );
    1077   memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + uiPartOffset, m_puhCbf[2], iSizeInUchar );
    1078  
    1079   memcpy( rpcCU->getDepth()  + uiPartOffset, m_puhDepth,  iSizeInUchar );
    1080   memcpy( rpcCU->getWidth()  + uiPartOffset, m_puhWidth,  iSizeInUchar );
    1081   memcpy( rpcCU->getHeight() + uiPartOffset, m_puhHeight, iSizeInUchar );
    1082  
    1083   memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPIdx[0], iSizeInUchar );
    1084   memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPIdx[1], iSizeInUchar );
    1085   memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPNum[0], iSizeInUchar );
    1086   memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPNum[1], iSizeInUchar );
    1087   m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
    1088   m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
    1089  
    1090   memcpy( rpcCU->getIPCMFlag() + uiPartOffset, m_pbIPCMFlag,         iSizeInBool  );
    1091 
    1092   UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>((uhDepth+uiPartDepth)<<1);
    1093   UInt uiTmp2 = uiPartOffset*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
    1094   memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
     959
     960  memcpy( pCtu->getSkipFlag()       + uiPartOffset, m_skipFlag,   sizeof( *m_skipFlag )   * uiQNumPart );
     961
     962  memcpy( pCtu->getQP() + uiPartOffset, m_phQP, sizeInChar );
     963  memcpy( pCtu->getPartitionSize()  + uiPartOffset, m_pePartSize, sizeof( *m_pePartSize ) * uiQNumPart );
     964  memcpy( pCtu->getPredictionMode() + uiPartOffset, m_pePredMode, sizeof( *m_pePredMode ) * uiQNumPart );
     965
     966  memcpy( pCtu->getCUTransquantBypass()+ uiPartOffset, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * uiQNumPart );
     967  memcpy( pCtu->getMergeFlag()         + uiPartOffset, m_pbMergeFlag,         iSizeInBool  );
     968  memcpy( pCtu->getMergeIndex()        + uiPartOffset, m_puhMergeIndex,       iSizeInUchar );
     969  for (UInt ch=0; ch<numValidChan; ch++)
     970  {
     971    memcpy( pCtu->getIntraDir(ChannelType(ch)) + uiPartOffset, m_puhIntraDir[ch], iSizeInUchar );
     972  }
     973
     974  memcpy( pCtu->getInterDir()          + uiPartOffset, m_puhInterDir,         iSizeInUchar );
     975  memcpy( pCtu->getTransformIdx()      + uiPartOffset, m_puhTrIdx,            iSizeInUchar );
     976
     977  for(UInt comp=0; comp<numValidComp; comp++)
     978  {
     979    memcpy( pCtu->getCrossComponentPredictionAlpha(ComponentID(comp)) + uiPartOffset, m_crossComponentPredictionAlpha[comp], iSizeInUchar );
     980    memcpy( pCtu->getTransformSkip(ComponentID(comp) )                + uiPartOffset, m_puhTransformSkip[comp],   iSizeInUchar );
     981    memcpy( pCtu->getCbf(ComponentID(comp))                           + uiPartOffset, m_puhCbf[comp],             iSizeInUchar );
     982    memcpy( pCtu->getExplicitRdpcmMode(ComponentID(comp) )            + uiPartOffset, m_explicitRdpcmMode[comp],  iSizeInUchar );
     983  }
     984
     985  memcpy( pCtu->getDepth()  + uiPartOffset, m_puhDepth,  iSizeInUchar );
     986  memcpy( pCtu->getWidth()  + uiPartOffset, m_puhWidth,  iSizeInUchar );
     987  memcpy( pCtu->getHeight() + uiPartOffset, m_puhHeight, iSizeInUchar );
     988
     989  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     990  {
     991    const RefPicList rpl=RefPicList(i);
     992    memcpy( pCtu->getMVPIdx(rpl) + uiPartOffset, m_apiMVPIdx[rpl], iSizeInUchar );
     993    memcpy( pCtu->getMVPNum(rpl) + uiPartOffset, m_apiMVPNum[rpl], iSizeInUchar );
     994  }
     995
     996  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     997  {
     998    const RefPicList rpl=RefPicList(i);
     999    m_acCUMvField[rpl].copyTo( pCtu->getCUMvField( rpl ), m_absZIdxInCtu, uiPartStart, uiQNumPart );
     1000  }
     1001
     1002  memcpy( pCtu->getIPCMFlag() + uiPartOffset, m_pbIPCMFlag,         iSizeInBool  );
     1003
     1004  const UInt numCoeffY    = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>((uhDepth+uiPartDepth)<<1);
     1005  const UInt offsetY      = uiPartOffset*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
     1006  for (UInt comp=0; comp<numValidComp; comp++)
     1007  {
     1008    UInt componentShift = m_pcPic->getComponentScaleX(ComponentID(comp)) + m_pcPic->getComponentScaleY(ComponentID(comp));
     1009    memcpy( pCtu->getCoeff(ComponentID(comp)) + (offsetY>>componentShift), m_pcTrCoeff[comp], sizeof(TCoeff)*(numCoeffY>>componentShift) );
    10951010#if ADAPTIVE_QP_SELECTION
    1096   memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp );
     1011    memcpy( pCtu->getArlCoeff(ComponentID(comp)) + (offsetY>>componentShift), m_pcArlCoeff[comp], sizeof(TCoeff)*(numCoeffY>>componentShift) );
    10971012#endif
    1098  
    1099   memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof( Pel ) * uiTmp );
    1100 
    1101   uiTmp >>= 2; uiTmp2 >>= 2;
    1102   memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
    1103   memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
    1104 #if ADAPTIVE_QP_SELECTION
    1105   memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
    1106   memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
    1107 #endif
    1108 
    1109   memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
    1110   memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
    1111   rpcCU->getTotalBins() = m_uiTotalBins;
    1112   memcpy( rpcCU->m_sliceStartCU        + uiPartOffset, m_sliceStartCU,        sizeof( UInt ) * uiQNumPart  );
    1113   memcpy( rpcCU->m_sliceSegmentStartCU + uiPartOffset, m_sliceSegmentStartCU, sizeof( UInt ) * uiQNumPart  );
     1013    memcpy( pCtu->getPCMSample(ComponentID(comp)) + (offsetY>>componentShift), m_pcIPCMSample[comp], sizeof(Pel)*(numCoeffY>>componentShift) );
     1014  }
     1015
     1016  pCtu->getTotalBins() = m_uiTotalBins;
    11141017}
    11151018
     
    11181021// --------------------------------------------------------------------------------------------------------------------
    11191022
    1120 TComDataCU* TComDataCU::getPULeft( UInt& uiLPartUnitIdx, 
    1121                                    UInt uiCurrPartUnitIdx, 
    1122                                    Bool bEnforceSliceRestriction, 
     1023TComDataCU* TComDataCU::getPULeft( UInt& uiLPartUnitIdx,
     1024                                   UInt uiCurrPartUnitIdx,
     1025                                   Bool bEnforceSliceRestriction,
    11231026                                   Bool bEnforceTileRestriction )
    11241027{
    11251028  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1126   UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
    1127   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
    1128  
    1129   if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
     1029  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_absZIdxInCtu];
     1030  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1031
     1032  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, numPartInCtuWidth ) )
    11301033  {
    11311034    uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
    1132     if ( RasterAddress::isEqualCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
    1133     {
    1134       return m_pcPic->getCU( getAddr() );
     1035    if ( RasterAddress::isEqualCol( uiAbsPartIdx, uiAbsZorderCUIdx, numPartInCtuWidth ) )
     1036    {
     1037      return m_pcPic->getCtu( getCtuRsAddr() );
    11351038    }
    11361039    else
    11371040    {
    1138       uiLPartUnitIdx -= m_uiAbsIdxInLCU;
     1041      uiLPartUnitIdx -= m_absZIdxInCtu;
    11391042      return this;
    11401043    }
    11411044  }
    1142  
    1143   uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth - 1 ];
    1144 
    1145 
    1146   if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || m_pcCULeft->getSCUAddr()+uiLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
    1147       ||
    1148        (bEnforceTileRestriction && ( m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))  )  )
    1149       )
     1045
     1046  uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + numPartInCtuWidth - 1 ];
     1047  if ( (bEnforceSliceRestriction && !CUIsFromSameSlice(m_pCtuLeft)) || (bEnforceTileRestriction && !CUIsFromSameTile(m_pCtuLeft)) )
    11501048  {
    11511049    return NULL;
    11521050  }
    1153   return m_pcCULeft;
    1154 }
     1051  return m_pCtuLeft;
     1052}
     1053
    11551054
    11561055TComDataCU* TComDataCU::getPUAbove( UInt& uiAPartUnitIdx,
    1157                                     UInt uiCurrPartUnitIdx, 
    1158                                     Bool bEnforceSliceRestriction, 
    1159                                     Bool planarAtLCUBoundary ,
     1056                                    UInt uiCurrPartUnitIdx,
     1057                                    Bool bEnforceSliceRestriction,
     1058                                    Bool planarAtCtuBoundary,
    11601059                                    Bool bEnforceTileRestriction )
    11611060{
    11621061  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1163   UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
    1164   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
    1165  
    1166   if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
    1167   {
    1168     uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth ];
    1169     if ( RasterAddress::isEqualRow( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
    1170     {
    1171       return m_pcPic->getCU( getAddr() );
     1062  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_absZIdxInCtu];
     1063  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1064
     1065  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, numPartInCtuWidth ) )
     1066  {
     1067    uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - numPartInCtuWidth ];
     1068    if ( RasterAddress::isEqualRow( uiAbsPartIdx, uiAbsZorderCUIdx, numPartInCtuWidth ) )
     1069    {
     1070      return m_pcPic->getCtu( getCtuRsAddr() );
    11721071    }
    11731072    else
    11741073    {
    1175       uiAPartUnitIdx -= m_uiAbsIdxInLCU;
     1074      uiAPartUnitIdx -= m_absZIdxInCtu;
    11761075      return this;
    11771076    }
    11781077  }
    11791078
    1180   if(planarAtLCUBoundary)
     1079  if(planarAtCtuBoundary)
    11811080  {
    11821081    return NULL;
    11831082  }
    1184  
    1185   uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
    1186 
    1187   if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || m_pcCUAbove->getSCUAddr()+uiAPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
    1188       ||
    1189        (bEnforceTileRestriction &&(m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))))
    1190       )
     1083
     1084  uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + m_pcPic->getNumPartitionsInCtu() - numPartInCtuWidth ];
     1085
     1086  if ( (bEnforceSliceRestriction && !CUIsFromSameSlice(m_pCtuAbove)) || (bEnforceTileRestriction && !CUIsFromSameTile(m_pCtuAbove)) )
    11911087  {
    11921088    return NULL;
    11931089  }
    1194   return m_pcCUAbove;
     1090  return m_pCtuAbove;
    11951091}
    11961092
     
    11981094{
    11991095  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1200   UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
    1201   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
    1202  
    1203   if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
    1204   {
    1205     if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
    1206     {
    1207       uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth - 1 ];
    1208       if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
    1209       {
    1210         return m_pcPic->getCU( getAddr() );
     1096  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_absZIdxInCtu];
     1097  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1098
     1099  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, numPartInCtuWidth ) )
     1100  {
     1101    if ( !RasterAddress::isZeroRow( uiAbsPartIdx, numPartInCtuWidth ) )
     1102    {
     1103      uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - numPartInCtuWidth - 1 ];
     1104      if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdx, uiAbsZorderCUIdx, numPartInCtuWidth ) )
     1105      {
     1106        return m_pcPic->getCtu( getCtuRsAddr() );
    12111107      }
    12121108      else
    12131109      {
    1214         uiALPartUnitIdx -= m_uiAbsIdxInLCU;
     1110        uiALPartUnitIdx -= m_absZIdxInCtu;
    12151111        return this;
    12161112      }
    12171113    }
    1218     uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + getPic()->getNumPartInCU() - uiNumPartInCUWidth - 1 ];
    1219     if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
    1220        m_pcCUAbove->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1221        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1222        ))
    1223      )
     1114    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + getPic()->getNumPartitionsInCtu() - numPartInCtuWidth - 1 ];
     1115    if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAbove) )
    12241116    {
    12251117      return NULL;
    12261118    }
    1227     return m_pcCUAbove;
    1228   }
    1229  
    1230   if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
     1119    return m_pCtuAbove;
     1120  }
     1121
     1122  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, numPartInCtuWidth ) )
    12311123  {
    12321124    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
    1233     if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL ||
    1234        m_pcCULeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1235        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1236        ))
    1237      )
     1125    if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuLeft) )
    12381126    {
    12391127      return NULL;
    12401128    }
    1241     return m_pcCULeft;
    1242   }
    1243  
    1244   uiALPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - 1 ];
    1245   if ( (bEnforceSliceRestriction && (m_pcCUAboveLeft==NULL || m_pcCUAboveLeft->getSlice()==NULL ||
    1246        m_pcCUAboveLeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1247        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveLeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1248        ))
    1249      )
     1129    return m_pCtuLeft;
     1130  }
     1131
     1132  uiALPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartitionsInCtu() - 1 ];
     1133  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAboveLeft) )
    12501134  {
    12511135    return NULL;
    12521136  }
    1253   return m_pcCUAboveLeft;
     1137  return m_pCtuAboveLeft;
    12541138}
    12551139
     
    12571141{
    12581142  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1259   UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1;
    1260   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
     1143  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_absZIdxInCtu ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1;
     1144  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
    12611145 
    12621146#if REPN_FORMAT_IN_VPS
    1263   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getPicWidthInLumaSamples() )
     1147  if( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getPicWidthInLumaSamples() )
    12641148#else
    1265   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
     1149  if( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
    12661150#endif
    12671151  {
     
    12691153    return NULL;
    12701154  }
    1271  
    1272   if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - 1, uiNumPartInCUWidth ) )
    1273   {
    1274     if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
    1275     {
    1276       if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ] )
    1277       {
    1278         uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ];
    1279         if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
     1155
     1156  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, numPartInCtuWidth - 1, numPartInCtuWidth ) )
     1157  {
     1158    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, numPartInCtuWidth ) )
     1159    {
     1160      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - numPartInCtuWidth + 1 ] )
     1161      {
     1162        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - numPartInCtuWidth + 1 ];
     1163        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, numPartInCtuWidth ) )
    12801164        {
    1281           return m_pcPic->getCU( getAddr() );
     1165          return m_pcPic->getCtu( getCtuRsAddr() );
    12821166        }
    12831167        else
    12841168        {
    1285           uiARPartUnitIdx -= m_uiAbsIdxInLCU;
     1169          uiARPartUnitIdx -= m_absZIdxInCtu;
    12861170          return this;
    12871171        }
     
    12901174      return NULL;
    12911175    }
    1292     uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + 1 ];
    1293     if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
    1294        m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1295        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1296        ))
    1297      )
     1176    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartitionsInCtu() - numPartInCtuWidth + 1 ];
     1177
     1178    if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAbove) )
    12981179    {
    12991180      return NULL;
    13001181    }
    1301     return m_pcCUAbove;
    1302   }
    1303  
    1304   if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
     1182    return m_pCtuAbove;
     1183  }
     1184
     1185  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, numPartInCtuWidth ) )
    13051186  {
    13061187    uiARPartUnitIdx = MAX_UINT;
    13071188    return NULL;
    13081189  }
    1309  
    1310   uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
    1311   if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
    1312        m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
    1313        m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1314        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1315        ))
    1316      )
     1190
     1191  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartitionsInCtu() - numPartInCtuWidth ];
     1192
     1193  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAboveRight) )
    13171194  {
    13181195    return NULL;
    13191196  }
    1320   return m_pcCUAboveRight;
     1197  return m_pCtuAboveRight;
    13211198}
    13221199
     
    13241201{
    13251202  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1326   UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhHeight[0] / m_pcPic->getMinCUHeight() - 1)*m_pcPic->getNumPartInWidth();
    1327   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
     1203  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1204  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_absZIdxInCtu ] + (m_puhHeight[0] / m_pcPic->getMinCUHeight() - 1)*numPartInCtuWidth;
    13281205
    13291206#if REPN_FORMAT_IN_VPS
    1330   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getPicHeightInLumaSamples() )
     1207  if( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getPicHeightInLumaSamples() )
    13311208#else
    1332   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
     1209  if( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
    13331210#endif
    13341211  {
     
    13361213    return NULL;
    13371214  }
    1338  
    1339   if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - 1, uiNumPartInCUWidth ) )
    1340   {
    1341     if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
    1342     {
    1343       if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ] )
    1344       {
    1345         uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ];
    1346         if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
     1215
     1216  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInCtuHeight() - 1, numPartInCtuWidth ) )
     1217  {
     1218    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, numPartInCtuWidth ) )
     1219    {
     1220      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + numPartInCtuWidth - 1 ] )
     1221      {
     1222        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + numPartInCtuWidth - 1 ];
     1223        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, numPartInCtuWidth ) )
    13471224        {
    1348           return m_pcPic->getCU( getAddr() );
     1225          return m_pcPic->getCtu( getCtuRsAddr() );
    13491226        }
    13501227        else
    13511228        {
    1352           uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
     1229          uiBLPartUnitIdx -= m_absZIdxInCtu;
    13531230          return this;
    13541231        }
     
    13571234      return NULL;
    13581235    }
    1359     uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth*2 - 1 ];
    1360     if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL ||
    1361        m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1362        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1363        ))
    1364      )
     1236    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + numPartInCtuWidth*2 - 1 ];
     1237    if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuLeft) )
    13651238    {
    13661239      return NULL;
    13671240    }
    1368     return m_pcCULeft;
    1369   }
    1370  
     1241    return m_pCtuLeft;
     1242  }
     1243
    13711244  uiBLPartUnitIdx = MAX_UINT;
    13721245  return NULL;
    13731246}
    13741247
    1375 TComDataCU* TComDataCU::getPUBelowLeftAdi(UInt& uiBLPartUnitIdx,  UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
     1248TComDataCU* TComDataCU::getPUBelowLeftAdi(UInt& uiBLPartUnitIdx,  UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction)
    13761249{
    13771250  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1378   UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ((m_puhHeight[0] / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth();
    1379   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
     1251  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1252  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_absZIdxInCtu ] + ((m_puhHeight[0] / m_pcPic->getMinCUHeight()) - 1)*numPartInCtuWidth;
    13801253 
    13811254#if REPN_FORMAT_IN_VPS
    1382   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getPicHeightInLumaSamples())
     1255  if( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getPicHeightInLumaSamples())
    13831256#else
    1384   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples())
     1257  if( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples())
    13851258#endif
    13861259  {
     
    13881261    return NULL;
    13891262  }
    1390  
    1391   if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - uiPartUnitOffset, uiNumPartInCUWidth ) )
    1392   {
    1393     if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
    1394     {
    1395       if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ] )
    1396       {
    1397         uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ];
    1398         if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
     1263
     1264  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInCtuHeight() - uiPartUnitOffset, numPartInCtuWidth ) )
     1265  {
     1266    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, numPartInCtuWidth ) )
     1267    {
     1268      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * numPartInCtuWidth - 1 ] )
     1269      {
     1270        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * numPartInCtuWidth - 1 ];
     1271        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, numPartInCtuWidth ) )
    13991272        {
    1400           return m_pcPic->getCU( getAddr() );
     1273          return m_pcPic->getCtu( getCtuRsAddr() );
    14011274        }
    14021275        else
    14031276        {
    1404           uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
     1277          uiBLPartUnitIdx -= m_absZIdxInCtu;
    14051278          return this;
    14061279        }
     
    14091282      return NULL;
    14101283    }
    1411     uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + (1+uiPartUnitOffset) * uiNumPartInCUWidth - 1 ];
    1412     if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL ||
    1413        m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1414        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1415        ))
    1416      )
     1284    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + (1+uiPartUnitOffset) * numPartInCtuWidth - 1 ];
     1285    if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuLeft) )
    14171286    {
    14181287      return NULL;
    14191288    }
    1420     return m_pcCULeft;
    1421   }
    1422  
     1289    return m_pCtuLeft;
     1290  }
     1291
    14231292  uiBLPartUnitIdx = MAX_UINT;
    14241293  return NULL;
    14251294}
    14261295
    1427 TComDataCU* TComDataCU::getPUAboveRightAdi(UInt&  uiARPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
     1296TComDataCU* TComDataCU::getPUAboveRightAdi(UInt&  uiARPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction)
    14281297{
    14291298  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
    1430   UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhWidth[0] / m_pcPic->getMinCUWidth()) - 1;
    1431   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
     1299  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_absZIdxInCtu ] + (m_puhWidth[0] / m_pcPic->getMinCUWidth()) - 1;
     1300  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
    14321301 
    14331302#if REPN_FORMAT_IN_VPS
    1434   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getPicWidthInLumaSamples() )
     1303  if( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getPicWidthInLumaSamples() )
    14351304#else
    1436   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
     1305  if( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
    14371306#endif
    14381307  {
     
    14401309    return NULL;
    14411310  }
    1442  
    1443   if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - uiPartUnitOffset, uiNumPartInCUWidth ) )
    1444   {
    1445     if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
    1446     {
    1447       if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ] )
    1448       {
    1449         uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ];
    1450         if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
     1311
     1312  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, numPartInCtuWidth - uiPartUnitOffset, numPartInCtuWidth ) )
     1313  {
     1314    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, numPartInCtuWidth ) )
     1315    {
     1316      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - numPartInCtuWidth + uiPartUnitOffset ] )
     1317      {
     1318        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - numPartInCtuWidth + uiPartUnitOffset ];
     1319        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, numPartInCtuWidth ) )
    14511320        {
    1452           return m_pcPic->getCU( getAddr() );
     1321          return m_pcPic->getCtu( getCtuRsAddr() );
    14531322        }
    14541323        else
    14551324        {
    1456           uiARPartUnitIdx -= m_uiAbsIdxInLCU;
     1325          uiARPartUnitIdx -= m_absZIdxInCtu;
    14571326          return this;
    14581327        }
     
    14611330      return NULL;
    14621331    }
    1463     uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset ];
    1464     if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
    1465        m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1466        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1467        ))
    1468      )
     1332
     1333    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartitionsInCtu() - numPartInCtuWidth + uiPartUnitOffset ];
     1334    if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAbove) )
    14691335    {
    14701336      return NULL;
    14711337    }
    1472     return m_pcCUAbove;
    1473   }
    1474  
    1475   if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
     1338    return m_pCtuAbove;
     1339  }
     1340
     1341  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, numPartInCtuWidth ) )
    14761342  {
    14771343    uiARPartUnitIdx = MAX_UINT;
    14781344    return NULL;
    14791345  }
    1480  
    1481   uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset-1 ];
    1482   if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
    1483        m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
    1484        m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
    1485        (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
    1486        ))
    1487      )
     1346
     1347  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartitionsInCtu() - numPartInCtuWidth + uiPartUnitOffset-1 ];
     1348  if ( bEnforceSliceRestriction && !CUIsFromSameSliceAndTile(m_pCtuAboveRight) )
    14881349  {
    14891350    return NULL;
    14901351  }
    1491   return m_pcCUAboveRight;
     1352  return m_pCtuAboveRight;
    14921353}
    14931354
    14941355/** Get left QpMinCu
    14951356*\param   uiLPartUnitIdx
    1496 *\param   uiCurrAbsIdxInLCU
     1357*\param   uiCurrAbsIdxInCtu
    14971358*\returns TComDataCU*   point of TComDataCU of left QpMinCu
    14981359*/
    1499 TComDataCU* TComDataCU::getQpMinCuLeft( UInt& uiLPartUnitIdx, UInt uiCurrAbsIdxInLCU)
    1500 {
    1501   UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
    1502   UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth -getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
     1360TComDataCU* TComDataCU::getQpMinCuLeft( UInt& uiLPartUnitIdx, UInt uiCurrAbsIdxInCtu )
     1361{
     1362  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1363  UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInCtu>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth -getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
    15031364  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
    15041365
    1505   // check for left LCU boundary
    1506   if ( RasterAddress::isZeroCol(absRorderQpMinCUIdx, numPartInCUWidth) )
     1366  // check for left CTU boundary
     1367  if ( RasterAddress::isZeroCol(absRorderQpMinCUIdx, numPartInCtuWidth) )
    15071368  {
    15081369    return NULL;
     
    15121373  uiLPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - 1];
    15131374
    1514   // return pointer to current LCU
    1515   return m_pcPic->getCU( getAddr() );
     1375  // return pointer to current CTU
     1376  return m_pcPic->getCtu( getCtuRsAddr() );
    15161377}
    15171378
    15181379/** Get Above QpMinCu
    1519 *\param   aPartUnitIdx
    1520 *\param   currAbsIdxInLCU
     1380*\param   uiAPartUnitIdx
     1381*\param   uiCurrAbsIdxInCtu
    15211382*\returns TComDataCU*   point of TComDataCU of above QpMinCu
    15221383*/
    1523 TComDataCU* TComDataCU::getQpMinCuAbove( UInt& aPartUnitIdx, UInt currAbsIdxInLCU )
    1524 {
    1525   UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
    1526   UInt absZorderQpMinCUIdx = (currAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
     1384TComDataCU* TComDataCU::getQpMinCuAbove( UInt& uiAPartUnitIdx, UInt uiCurrAbsIdxInCtu )
     1385{
     1386  const UInt numPartInCtuWidth = m_pcPic->getNumPartInCtuWidth();
     1387  UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInCtu>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
    15271388  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
    15281389
    1529   // check for top LCU boundary
    1530   if ( RasterAddress::isZeroRow( absRorderQpMinCUIdx, numPartInCUWidth) )
     1390  // check for top CTU boundary
     1391  if ( RasterAddress::isZeroRow( absRorderQpMinCUIdx, numPartInCtuWidth) )
    15311392  {
    15321393    return NULL;
     
    15341395
    15351396  // get index of top-CU relative to top-left corner of current quantization group
    1536   aPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - numPartInCUWidth];
    1537 
    1538   // return pointer to current LCU
    1539   return m_pcPic->getCU( getAddr() );
    1540 }
     1397  uiAPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - numPartInCtuWidth];
     1398
     1399  // return pointer to current CTU
     1400  return m_pcPic->getCtu( getCtuRsAddr() );
     1401}
     1402
     1403
    15411404
    15421405/** Get reference QP from left QpMinCu or latest coded QP
    1543 *\param   uiCurrAbsIdxInLCU
     1406*\param   uiCurrAbsIdxInCtu
    15441407*\returns Char   reference QP value
    15451408*/
    1546 Char TComDataCU::getRefQP( UInt uiCurrAbsIdxInLCU )
    1547 {
    1548   UInt        lPartIdx = 0, aPartIdx = 0;
    1549   TComDataCU* cULeft  = getQpMinCuLeft ( lPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
    1550   TComDataCU* cUAbove = getQpMinCuAbove( aPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
    1551   return (((cULeft? cULeft->getQP( lPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + (cUAbove? cUAbove->getQP( aPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + 1) >> 1);
     1409Char TComDataCU::getRefQP( UInt uiCurrAbsIdxInCtu )
     1410{
     1411  UInt lPartIdx = MAX_UINT;
     1412  UInt aPartIdx = MAX_UINT;
     1413  TComDataCU* cULeft  = getQpMinCuLeft ( lPartIdx, m_absZIdxInCtu + uiCurrAbsIdxInCtu );
     1414  TComDataCU* cUAbove = getQpMinCuAbove( aPartIdx, m_absZIdxInCtu + uiCurrAbsIdxInCtu );
     1415  return (((cULeft? cULeft->getQP( lPartIdx ): getLastCodedQP( uiCurrAbsIdxInCtu )) + (cUAbove? cUAbove->getQP( aPartIdx ): getLastCodedQP( uiCurrAbsIdxInCtu )) + 1) >> 1);
    15521416}
    15531417
     
    15561420  Int iLastValidPartIdx = iAbsPartIdx-1;
    15571421  while ( iLastValidPartIdx >= 0
    1558        && getPredictionMode( iLastValidPartIdx ) == MODE_NONE )
     1422       && getPredictionMode( iLastValidPartIdx ) == NUMBER_OF_PREDICTION_MODES )
    15591423  {
    15601424    UInt uiDepth = getDepth( iLastValidPartIdx );
     
    15671431{
    15681432  UInt uiQUPartIdxMask = ~((1<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))-1);
    1569   Int iLastValidPartIdx = getLastValidPartIdx( uiAbsPartIdx&uiQUPartIdxMask );
    1570   if ( uiAbsPartIdx < m_uiNumPartition
    1571     && (getSCUAddr()+iLastValidPartIdx < getSliceStartCU(m_uiAbsIdxInLCU+uiAbsPartIdx)))
     1433  Int iLastValidPartIdx = getLastValidPartIdx( uiAbsPartIdx&uiQUPartIdxMask ); // A idx will be invalid if it is off the right or bottom edge of the picture.
     1434  // If this CU is in the first CTU of the slice and there is no valid part before this one, use slice QP
     1435  if ( getPic()->getPicSym()->getCtuTsToRsAddrMap(getSlice()->getSliceCurStartCtuTsAddr()) == getCtuRsAddr() && Int(getZorderIdxInCtu())+iLastValidPartIdx<0)
    15721436  {
    15731437    return getSlice()->getSliceQp();
     
    15751439  else if ( iLastValidPartIdx >= 0 )
    15761440  {
     1441    // If there is a valid part within the current Sub-CU, use it
    15771442    return getQP( iLastValidPartIdx );
    15781443  }
    15791444  else
    15801445  {
    1581     if ( getZorderIdxInCU() > 0 )
    1582     {
    1583       return getPic()->getCU( getAddr() )->getLastCodedQP( getZorderIdxInCU() );
    1584     }
    1585     else if ( getPic()->getPicSym()->getInverseCUOrderMap(getAddr()) > 0
    1586       && getPic()->getPicSym()->getTileIdxMap(getAddr()) == getPic()->getPicSym()->getTileIdxMap(getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1))
    1587       && !( getSlice()->getPPS()->getEntropyCodingSyncEnabledFlag() && getAddr() % getPic()->getFrameWidthInCU() == 0 ) )
    1588     {
    1589       return getPic()->getCU( getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1) )->getLastCodedQP( getPic()->getNumPartInCU() );
     1446    if ( getZorderIdxInCtu() > 0 )
     1447    {
     1448      // If this wasn't the first sub-cu within the Ctu, explore the CTU itself.
     1449      return getPic()->getCtu( getCtuRsAddr() )->getLastCodedQP( getZorderIdxInCtu() ); // TODO - remove this recursion
     1450    }
     1451    else if ( getPic()->getPicSym()->getCtuRsToTsAddrMap(getCtuRsAddr()) > 0
     1452      && CUIsFromSameSliceTileAndWavefrontRow(getPic()->getCtu(getPic()->getPicSym()->getCtuTsToRsAddrMap(getPic()->getPicSym()->getCtuRsToTsAddrMap(getCtuRsAddr())-1))) )
     1453    {
     1454      // 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.
     1455      return getPic()->getCtu( getPic()->getPicSym()->getCtuTsToRsAddrMap(getPic()->getPicSym()->getCtuRsToTsAddrMap(getCtuRsAddr())-1) )->getLastCodedQP( getPic()->getNumPartitionsInCtu() );  // TODO - remove this recursion
    15901456    }
    15911457    else
    15921458    {
     1459      // No other options available - use the slice-level QP.
    15931460      return getSlice()->getSliceQp();
    15941461    }
    15951462  }
    15961463}
     1464
     1465
    15971466/** Check whether the CU is coded in lossless coding mode
    15981467 * \param   uiAbsPartIdx
    1599  * \returns true if the CU is coded in lossless coding mode; false if otherwise 
     1468 * \returns true if the CU is coded in lossless coding mode; false if otherwise
    16001469 */
    16011470Bool TComDataCU::isLosslessCoded(UInt absPartIdx)
     
    16031472  return (getSlice()->getPPS()->getTransquantBypassEnableFlag() && getCUTransquantBypass (absPartIdx));
    16041473}
     1474
    16051475
    16061476/** Get allowed chroma intra modes
    16071477*\param   uiAbsPartIdx
    16081478*\param   uiModeList  pointer to chroma intra modes array
    1609 *\returns 
     1479*\returns
    16101480*- fill uiModeList with chroma intra modes
    16111481*/
    1612 Void TComDataCU::getAllowedChromaDir( UInt uiAbsPartIdx, UInt* uiModeList )
     1482Void TComDataCU::getAllowedChromaDir( UInt uiAbsPartIdx, UInt uiModeList[NUM_CHROMA_MODE] )
    16131483{
    16141484  uiModeList[0] = PLANAR_IDX;
     
    16171487  uiModeList[3] = DC_IDX;
    16181488  uiModeList[4] = DM_CHROMA_IDX;
    1619 
    1620   UInt uiLumaMode = getLumaIntraDir( uiAbsPartIdx );
     1489  assert(4<NUM_CHROMA_MODE);
     1490
     1491  UInt uiLumaMode = getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartIdx );
    16211492
    16221493  for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ )
     
    16361507*\returns Number of MPM
    16371508*/
    1638 Int TComDataCU::getIntraDirLumaPredictor( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int* piMode  )
    1639 {
    1640   TComDataCU* pcTempCU;
    1641   UInt        uiTempPartIdx;
     1509Int TComDataCU::getIntraDirPredictor( UInt uiAbsPartIdx, Int uiIntraDirPred[NUM_MOST_PROBABLE_MODES], const ComponentID compID, Int* piMode  )
     1510{
     1511  TComDataCU* pcCULeft, *pcCUAbove;
     1512  UInt        LeftPartIdx  = MAX_UINT;
     1513  UInt        AbovePartIdx = MAX_UINT;
    16421514  Int         iLeftIntraDir, iAboveIntraDir;
    16431515  Int         uiPredNum = 0;
    16441516
     1517  const ChannelType chType = toChannelType(compID);
     1518  const ChromaFormat chForm = getPic()->getChromaFormat();
    16451519  // Get intra direction of left PU
    1646   pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
    1647  
    1648   iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
    1649  
     1520  pcCULeft = getPULeft( LeftPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
     1521
     1522  if (isChroma(compID)) LeftPartIdx = getChromasCorrespondingPULumaIdx(LeftPartIdx, chForm);
     1523  iLeftIntraDir  = pcCULeft ? ( pcCULeft->isIntra( LeftPartIdx ) ? pcCULeft->getIntraDir( chType, LeftPartIdx ) : DC_IDX ) : DC_IDX;
     1524
    16501525  // Get intra direction of above PU
    1651   pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, true );
    1652  
    1653   iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
    1654  
    1655   uiPredNum = 3;
     1526  pcCUAbove = getPUAbove( AbovePartIdx, m_absZIdxInCtu + uiAbsPartIdx, true, true );
     1527
     1528  if (isChroma(compID)) AbovePartIdx = getChromasCorrespondingPULumaIdx(AbovePartIdx, chForm);
     1529  iAboveIntraDir = pcCUAbove ? ( pcCUAbove->isIntra( AbovePartIdx ) ? pcCUAbove->getIntraDir( chType, AbovePartIdx ) : DC_IDX ) : DC_IDX;
     1530
     1531  if (isChroma(chType))
     1532  {
     1533    if (iLeftIntraDir  == DM_CHROMA_IDX) iLeftIntraDir  = pcCULeft-> getIntraDir( CHANNEL_TYPE_LUMA, LeftPartIdx  );
     1534    if (iAboveIntraDir == DM_CHROMA_IDX) iAboveIntraDir = pcCUAbove->getIntraDir( CHANNEL_TYPE_LUMA, AbovePartIdx );
     1535  }
     1536
     1537  assert (2<NUM_MOST_PROBABLE_MODES);
     1538  uiPredNum = NUM_MOST_PROBABLE_MODES;
    16561539  if(iLeftIntraDir == iAboveIntraDir)
    16571540  {
     
    16601543      *piMode = 1;
    16611544    }
    1662    
     1545
    16631546    if (iLeftIntraDir > 1) // angular modes
    16641547    {
     
    16711554      uiIntraDirPred[0] = PLANAR_IDX;
    16721555      uiIntraDirPred[1] = DC_IDX;
    1673       uiIntraDirPred[2] = VER_IDX; 
     1556      uiIntraDirPred[2] = VER_IDX;
    16741557    }
    16751558  }
     
    16821565    uiIntraDirPred[0] = iLeftIntraDir;
    16831566    uiIntraDirPred[1] = iAboveIntraDir;
    1684    
     1567
    16851568    if (iLeftIntraDir && iAboveIntraDir ) //both modes are non-planar
    16861569    {
     
    16921575    }
    16931576  }
    1694  
     1577  for (Int i=0; i<uiPredNum; i++)
     1578    assert(uiIntraDirPred[i] < 35);
     1579
    16951580  return uiPredNum;
    16961581}
     
    17021587  UInt        uiCtx;
    17031588  // Get left split flag
    1704   pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
     1589  pcTempCU = getPULeft( uiTempPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
    17051590  uiCtx  = ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
    1706  
     1591
    17071592  // Get above split flag
    1708   pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
     1593  pcTempCU = getPUAbove( uiTempPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
    17091594  uiCtx += ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
    1710  
     1595
    17111596  return uiCtx;
    17121597}
    17131598
    1714 UInt TComDataCU::getCtxQtCbf( TextType eType, UInt uiTrDepth )
    1715 {
    1716   if( eType )
    1717   {
    1718     return uiTrDepth;
     1599UInt TComDataCU::getCtxQtCbf( TComTU &rTu, const ChannelType chType )
     1600{
     1601  const UInt transformDepth = rTu.GetTransformDepthRel();
     1602
     1603  if (isChroma(chType))
     1604  {
     1605    return transformDepth;
    17191606  }
    17201607  else
    17211608  {
    1722     const UInt uiCtx = ( uiTrDepth == 0 ? 1 : 0 );
     1609    const UInt uiCtx = ( transformDepth == 0 ? 1 : 0 );
    17231610    return uiCtx;
    17241611  }
     
    17291616  UInt log2CbSize = g_aucConvertToBit[getWidth( absPartIdx )] + 2;
    17301617  PartSize  partSize  = getPartitionSize( absPartIdx );
    1731   UInt quadtreeTUMaxDepth = getPredictionMode( absPartIdx ) == MODE_INTRA ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter();
    1732   Int intraSplitFlag = ( getPredictionMode( absPartIdx ) == MODE_INTRA && partSize == SIZE_NxN ) ? 1 : 0;
    1733   Int interSplitFlag = ((quadtreeTUMaxDepth == 1) && (getPredictionMode( absPartIdx ) == MODE_INTER) && (partSize != SIZE_2Nx2N) );
    1734  
     1618  UInt quadtreeTUMaxDepth = isIntra( absPartIdx ) ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter();
     1619  Int intraSplitFlag = ( isIntra( absPartIdx ) && partSize == SIZE_NxN ) ? 1 : 0;
     1620  Int interSplitFlag = ((quadtreeTUMaxDepth == 1) && isInter( absPartIdx ) && (partSize != SIZE_2Nx2N) );
     1621
    17351622  UInt log2MinTUSizeInCU = 0;
    1736   if (log2CbSize < (m_pcSlice->getSPS()->getQuadtreeTULog2MinSize() + quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag) ) 
     1623  if (log2CbSize < (m_pcSlice->getSPS()->getQuadtreeTULog2MinSize() + quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag) )
    17371624  {
    17381625    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is < QuadtreeTULog2MinSize
     
    17471634      // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still > QuadtreeTULog2MaxSize
    17481635      log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize();
    1749     } 
     1636    }
    17501637  }
    17511638  return log2MinTUSizeInCU;
     
    17571644  UInt        uiTempPartIdx;
    17581645  UInt        uiCtx = 0;
    1759  
     1646
    17601647  // Get BCBP of left PU
    1761   pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
     1648  pcTempCU = getPULeft( uiTempPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
    17621649  uiCtx    = ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
    1763  
     1650
    17641651  // Get BCBP of above PU
    1765   pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
     1652  pcTempCU = getPUAbove( uiTempPartIdx, m_absZIdxInCtu + uiAbsPartIdx );
    17661653  uiCtx   += ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
    1767  
     1654
    17681655  return uiCtx;
    17691656}
     
    17741661}
    17751662
    1776 Void TComDataCU::setCbfSubParts( UInt uiCbfY, UInt uiCbfU, UInt uiCbfV, UInt uiAbsPartIdx, UInt uiDepth )
    1777 {
    1778   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    1779   memset( m_puhCbf[0] + uiAbsPartIdx, uiCbfY, sizeof( UChar ) * uiCurrPartNumb );
    1780   memset( m_puhCbf[1] + uiAbsPartIdx, uiCbfU, sizeof( UChar ) * uiCurrPartNumb );
    1781   memset( m_puhCbf[2] + uiAbsPartIdx, uiCbfV, sizeof( UChar ) * uiCurrPartNumb );
    1782 }
    1783 
    1784 Void TComDataCU::setCbfSubParts( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiDepth )
    1785 {
    1786   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    1787   memset( m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]] + uiAbsPartIdx, uiCbf, sizeof( UChar ) * uiCurrPartNumb );
     1663
     1664UChar TComDataCU::getQtRootCbf( UInt uiIdx )
     1665{
     1666  const UInt numberValidComponents = getPic()->getNumberValidComponents();
     1667  return getCbf( uiIdx, COMPONENT_Y, 0 )
     1668          || ((numberValidComponents > COMPONENT_Cb) && getCbf( uiIdx, COMPONENT_Cb, 0 ))
     1669          || ((numberValidComponents > COMPONENT_Cr) && getCbf( uiIdx, COMPONENT_Cr, 0 ));
     1670}
     1671
     1672Void TComDataCU::setCbfSubParts( const UInt uiCbf[MAX_NUM_COMPONENT], UInt uiAbsPartIdx, UInt uiDepth )
     1673{
     1674  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     1675  for(UInt comp=0; comp<MAX_NUM_COMPONENT; comp++)
     1676  {
     1677    memset( m_puhCbf[comp] + uiAbsPartIdx, uiCbf[comp], sizeof( UChar ) * uiCurrPartNumb );
     1678  }
     1679}
     1680
     1681Void TComDataCU::setCbfSubParts( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiDepth )
     1682{
     1683  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     1684  memset( m_puhCbf[compID] + uiAbsPartIdx, uiCbf, sizeof( UChar ) * uiCurrPartNumb );
    17881685}
    17891686
     
    17961693 * \returns Void
    17971694 */
    1798 Void TComDataCU::setCbfSubParts ( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
    1799 {
    1800   setSubPart<UChar>( uiCbf, m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]], uiAbsPartIdx, uiDepth, uiPartIdx );
     1695Void TComDataCU::setCbfSubParts ( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
     1696{
     1697  setSubPart<UChar>( uiCbf, m_puhCbf[compID], uiAbsPartIdx, uiDepth, uiPartIdx );
     1698}
     1699
     1700Void TComDataCU::setCbfPartRange ( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
     1701{
     1702  memset((m_puhCbf[compID] + uiAbsPartIdx), uiCbf, (sizeof(UChar) * uiCoveredPartIdxes));
     1703}
     1704
     1705Void TComDataCU::bitwiseOrCbfPartRange( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
     1706{
     1707  const UInt stopAbsPartIdx = uiAbsPartIdx + uiCoveredPartIdxes;
     1708
     1709  for (UInt subPartIdx = uiAbsPartIdx; subPartIdx < stopAbsPartIdx; subPartIdx++)
     1710  {
     1711    m_puhCbf[compID][subPartIdx] |= uiCbf;
     1712  }
    18011713}
    18021714
    18031715Void TComDataCU::setDepthSubParts( UInt uiDepth, UInt uiAbsPartIdx )
    18041716{
    1805   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
     1717  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
    18061718  memset( m_puhDepth + uiAbsPartIdx, uiDepth, sizeof(UChar)*uiCurrPartNumb );
    18071719}
     
    18091721Bool TComDataCU::isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth)
    18101722{
    1811   UInt uiPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    1812   return (((m_uiAbsIdxInLCU + uiAbsPartIdx)% uiPartNumb) == 0);
     1723  UInt uiPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     1724  return (((m_absZIdxInCtu + uiAbsPartIdx)% uiPartNumb) == 0);
    18131725}
    18141726
     
    18161728{
    18171729  assert( sizeof( *m_pePartSize) == 1 );
    1818   memset( m_pePartSize + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
     1730  memset( m_pePartSize + uiAbsPartIdx, eMode, m_pcPic->getNumPartitionsInCtu() >> ( 2 * uiDepth ) );
    18191731}
    18201732
    18211733Void TComDataCU::setCUTransquantBypassSubParts( Bool flag, UInt uiAbsPartIdx, UInt uiDepth )
    18221734{
    1823   memset( m_CUTransquantBypass + uiAbsPartIdx, flag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
     1735  memset( m_CUTransquantBypass + uiAbsPartIdx, flag, m_pcPic->getNumPartitionsInCtu() >> ( 2 * uiDepth ) );
    18241736}
    18251737
     
    18271739{
    18281740  assert( sizeof( *m_skipFlag) == 1 );
    1829   memset( m_skipFlag + absPartIdx, skip, m_pcPic->getNumPartInCU() >> ( 2 * depth ) );
     1741  memset( m_skipFlag + absPartIdx, skip, m_pcPic->getNumPartitionsInCtu() >> ( 2 * depth ) );
    18301742}
    18311743
     
    18331745{
    18341746  assert( sizeof( *m_pePredMode) == 1 );
    1835   memset( m_pePredMode + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
    1836 }
    1837 
    1838 Void TComDataCU::setQPSubCUs( Int qp, TComDataCU* pcCU, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf )
    1839 {
    1840   UInt currPartNumb = m_pcPic->getNumPartInCU() >> (depth << 1);
     1747  memset( m_pePredMode + uiAbsPartIdx, eMode, m_pcPic->getNumPartitionsInCtu() >> ( 2 * uiDepth ) );
     1748}
     1749
     1750Void TComDataCU::setChromaQpAdjSubParts( UChar val, Int absPartIdx, Int depth )
     1751{
     1752  assert( sizeof(*m_ChromaQpAdj) == 1 );
     1753  memset( m_ChromaQpAdj + absPartIdx, val, m_pcPic->getNumPartitionsInCtu() >> ( 2 * depth ) );
     1754}
     1755
     1756Void TComDataCU::setQPSubCUs( Int qp, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf )
     1757{
     1758  UInt currPartNumb = m_pcPic->getNumPartitionsInCtu() >> (depth << 1);
    18411759  UInt currPartNumQ = currPartNumb >> 2;
     1760  const UInt numValidComp = m_pcPic->getNumberValidComponents();
    18421761
    18431762  if(!foundNonZeroCbf)
    18441763  {
    1845     if(pcCU->getDepth(absPartIdx) > depth)
     1764    if(getDepth(absPartIdx) > depth)
    18461765    {
    18471766      for ( UInt partUnitIdx = 0; partUnitIdx < 4; partUnitIdx++ )
    18481767      {
    1849         pcCU->setQPSubCUs( qp, pcCU, absPartIdx+partUnitIdx*currPartNumQ, depth+1, foundNonZeroCbf );
     1768        setQPSubCUs( qp, absPartIdx+partUnitIdx*currPartNumQ, depth+1, foundNonZeroCbf );
    18501769      }
    18511770    }
    18521771    else
    18531772    {
    1854       if(pcCU->getCbf( absPartIdx, TEXT_LUMA ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_U ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_V ) )
     1773      if(getCbf( absPartIdx, COMPONENT_Y ) || (numValidComp>COMPONENT_Cb && getCbf( absPartIdx, COMPONENT_Cb )) || (numValidComp>COMPONENT_Cr && getCbf( absPartIdx, COMPONENT_Cr) ) )
    18551774      {
    18561775        foundNonZeroCbf = true;
     
    18661785Void TComDataCU::setQPSubParts( Int qp, UInt uiAbsPartIdx, UInt uiDepth )
    18671786{
    1868   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    1869   TComSlice * pcSlice = getPic()->getSlice(getPic()->getCurrSliceIdx());
    1870 
    1871   for(UInt uiSCUIdx = uiAbsPartIdx; uiSCUIdx < uiAbsPartIdx+uiCurrPartNumb; uiSCUIdx++)
    1872   {
    1873     if( m_pcPic->getCU( getAddr() )->getSliceSegmentStartCU(uiSCUIdx+getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr() )
    1874     {
    1875       m_phQP[uiSCUIdx] = qp;
    1876     }
    1877   }
    1878 }
    1879 
    1880 Void TComDataCU::setLumaIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
    1881 {
    1882   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    1883  
    1884   memset( m_puhLumaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
     1787  const UInt numPart = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     1788  memset(m_phQP+uiAbsPartIdx, qp, numPart);
     1789}
     1790
     1791Void TComDataCU::setIntraDirSubParts( const ChannelType channelType, const UInt dir, const UInt absPartIdx, const UInt depth )
     1792{
     1793  UInt numPart = m_pcPic->getNumPartitionsInCtu() >> (depth << 1);
     1794  memset( m_puhIntraDir[channelType] + absPartIdx, dir,sizeof(UChar)*numPart );
    18851795}
    18861796
    18871797template<typename T>
    1888 Void TComDataCU::setSubPart( T uiParameter, T* puhBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
     1798Void TComDataCU::setSubPart( T uiParameter, T* puhBaseCtu, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
    18891799{
    18901800  assert( sizeof(T) == 1 ); // Using memset() works only for types of size 1
    1891  
    1892   UInt uiCurrPartNumQ = (m_pcPic->getNumPartInCU() >> (2 * uiCUDepth)) >> 2;
     1801
     1802  UInt uiCurrPartNumQ = (m_pcPic->getNumPartitionsInCtu() >> (2 * uiCUDepth)) >> 2;
    18931803  switch ( m_pePartSize[ uiCUAddr ] )
    18941804  {
    18951805    case SIZE_2Nx2N:
    1896       memset( puhBaseLCU + uiCUAddr, uiParameter, 4 * uiCurrPartNumQ );
     1806      memset( puhBaseCtu + uiCUAddr, uiParameter, 4 * uiCurrPartNumQ );
    18971807      break;
    18981808    case SIZE_2NxN:
    1899       memset( puhBaseLCU + uiCUAddr, uiParameter, 2 * uiCurrPartNumQ );
     1809      memset( puhBaseCtu + uiCUAddr, uiParameter, 2 * uiCurrPartNumQ );
    19001810      break;
    19011811    case SIZE_Nx2N:
    1902       memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ );
    1903       memset( puhBaseLCU + uiCUAddr + 2 * uiCurrPartNumQ, uiParameter, uiCurrPartNumQ );
     1812      memset( puhBaseCtu + uiCUAddr, uiParameter, uiCurrPartNumQ );
     1813      memset( puhBaseCtu + uiCUAddr + 2 * uiCurrPartNumQ, uiParameter, uiCurrPartNumQ );
    19041814      break;
    19051815    case SIZE_NxN:
    1906       memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ );
     1816      memset( puhBaseCtu + uiCUAddr, uiParameter, uiCurrPartNumQ );
    19071817      break;
    19081818    case SIZE_2NxnU:
    19091819      if ( uiPUIdx == 0 )
    19101820      {
    1911         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
    1912         memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
     1821        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );
     1822        memset( puhBaseCtu + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );
    19131823      }
    19141824      else if ( uiPUIdx == 1 )
    19151825      {
    1916         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
    1917         memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, ((uiCurrPartNumQ >> 1) + (uiCurrPartNumQ << 1)) );                     
     1826        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );
     1827        memset( puhBaseCtu + uiCUAddr + uiCurrPartNumQ, uiParameter, ((uiCurrPartNumQ >> 1) + (uiCurrPartNumQ << 1)) );
    19181828      }
    19191829      else
     
    19251835      if ( uiPUIdx == 0 )
    19261836      {
    1927         memset( puhBaseLCU + uiCUAddr, uiParameter, ((uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1)) );                     
    1928         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
     1837        memset( puhBaseCtu + uiCUAddr, uiParameter, ((uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1)) );
     1838        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );
    19291839      }
    19301840      else if ( uiPUIdx == 1 )
    19311841      {
    1932         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
    1933         memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
     1842        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );
     1843        memset( puhBaseCtu + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );
    19341844      }
    19351845      else
     
    19411851      if ( uiPUIdx == 0 )
    19421852      {
    1943         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
    1944         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
    1945         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );
    1946         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
     1853        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
     1854        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
     1855        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );
     1856        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
    19471857      }
    19481858      else if ( uiPUIdx == 1 )
    19491859      {
    1950         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
    1951         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
    1952         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );
    1953         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
     1860        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
     1861        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
     1862        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );
     1863        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
    19541864      }
    19551865      else
     
    19601870    case SIZE_nRx2N:
    19611871      if ( uiPUIdx == 0 )
    1962       {     
    1963         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
    1964         memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
    1965         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
    1966         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
     1872      {
     1873        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
     1874        memset( puhBaseCtu + uiCUAddr + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
     1875        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );
     1876        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
    19671877      }
    19681878      else if ( uiPUIdx == 1 )
    19691879      {
    1970         memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );                           
    1971         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
    1972         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
    1973         memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                         
     1880        memset( puhBaseCtu + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
     1881        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
     1882        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );
     1883        memset( puhBaseCtu + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );
    19741884      }
    19751885      else
     
    19801890    default:
    19811891      assert( 0 );
     1892      break;
    19821893  }
    19831894}
     
    19931904}
    19941905
    1995 Void TComDataCU::setChromIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
    1996 {
    1997   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    1998  
    1999   memset( m_puhChromaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
    2000 }
    2001 
    20021906Void TComDataCU::setInterDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
    20031907{
     
    20181922Void TComDataCU::setTrIdxSubParts( UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth )
    20191923{
    2020   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2021  
     1924  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     1925
    20221926  memset( m_puhTrIdx + uiAbsPartIdx, uiTrIdx, sizeof(UChar)*uiCurrPartNumb );
    20231927}
    20241928
    2025 Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkipY, UInt useTransformSkipU, UInt useTransformSkipV, UInt uiAbsPartIdx, UInt uiDepth )
    2026 {
    2027   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2028 
    2029   memset( m_puhTransformSkip[0] + uiAbsPartIdx, useTransformSkipY, sizeof( UChar ) * uiCurrPartNumb );
    2030   memset( m_puhTransformSkip[1] + uiAbsPartIdx, useTransformSkipU, sizeof( UChar ) * uiCurrPartNumb );
    2031   memset( m_puhTransformSkip[2] + uiAbsPartIdx, useTransformSkipV, sizeof( UChar ) * uiCurrPartNumb );
    2032 }
    2033 
    2034 Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkip, TextType eType, UInt uiAbsPartIdx, UInt uiDepth)
    2035 {
    2036   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2037 
    2038   memset( m_puhTransformSkip[g_aucConvertTxtTypeToIdx[eType]] + uiAbsPartIdx, useTransformSkip, sizeof( UChar ) * uiCurrPartNumb );
     1929Void TComDataCU::setTransformSkipSubParts( const UInt useTransformSkip[MAX_NUM_COMPONENT], UInt uiAbsPartIdx, UInt uiDepth )
     1930{
     1931  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     1932
     1933  for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
     1934  {
     1935    memset( m_puhTransformSkip[i] + uiAbsPartIdx, useTransformSkip[i], sizeof( UChar ) * uiCurrPartNumb );
     1936  }
     1937}
     1938
     1939Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkip, ComponentID compID, UInt uiAbsPartIdx, UInt uiDepth)
     1940{
     1941  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     1942
     1943  memset( m_puhTransformSkip[compID] + uiAbsPartIdx, useTransformSkip, sizeof( UChar ) * uiCurrPartNumb );
     1944}
     1945
     1946Void TComDataCU::setTransformSkipPartRange ( UInt useTransformSkip, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
     1947{
     1948  memset((m_puhTransformSkip[compID] + uiAbsPartIdx), useTransformSkip, (sizeof(UChar) * uiCoveredPartIdxes));
     1949}
     1950
     1951Void TComDataCU::setCrossComponentPredictionAlphaPartRange( Char alphaValue, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
     1952{
     1953  memset((m_crossComponentPredictionAlpha[compID] + uiAbsPartIdx), alphaValue, (sizeof(Char) * uiCoveredPartIdxes));
     1954}
     1955
     1956Void TComDataCU::setExplicitRdpcmModePartRange ( UInt rdpcmMode, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes )
     1957{
     1958  memset((m_explicitRdpcmMode[compID] + uiAbsPartIdx), rdpcmMode, (sizeof(UChar) * uiCoveredPartIdxes));
    20391959}
    20401960
    20411961Void TComDataCU::setSizeSubParts( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, UInt uiDepth )
    20421962{
    2043   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
    2044  
     1963  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
     1964
    20451965  memset( m_puhWidth  + uiAbsPartIdx, uiWidth,  sizeof(UChar)*uiCurrPartNumb );
    20461966  memset( m_puhHeight + uiAbsPartIdx, uiHeight, sizeof(UChar)*uiCurrPartNumb );
    20471967}
    20481968
    2049 UChar TComDataCU::getNumPartitions()
     1969UChar TComDataCU::getNumPartitions(const UInt uiAbsPartIdx)
    20501970{
    20511971  UChar iNumPart = 0;
    2052  
    2053   switch ( m_pePartSize[0] )
     1972
     1973  switch ( m_pePartSize[uiAbsPartIdx] )
    20541974  {
    20551975    case SIZE_2Nx2N:    iNumPart = 1; break;
     
    20631983    default:            assert (0);   break;
    20641984  }
    2065  
     1985
    20661986  return  iNumPart;
    20671987}
     
    21162036    return;
    21172037  }
    2118  
     2038
    21192039  TComCUMvField*  pcCUMvField = pcCU->getCUMvField( eRefPicList );
    21202040  rcMvField.setMvField( pcCUMvField->getMv( uiAbsPartIdx ), pcCUMvField->getRefIdx( uiAbsPartIdx ) );
     
    21232043Void TComDataCU::deriveLeftRightTopIdxGeneral ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
    21242044{
    2125   ruiPartIdxLT = m_uiAbsIdxInLCU + uiAbsPartIdx;
     2045  ruiPartIdxLT = m_absZIdxInCtu + uiAbsPartIdx;
    21262046  UInt uiPUWidth = 0;
    2127  
     2047
    21282048  switch ( m_pePartSize[uiAbsPartIdx] )
    21292049  {
     
    21342054    case SIZE_2NxnU:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
    21352055    case SIZE_2NxnD:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
    2136     case SIZE_nLx2N:   
     2056    case SIZE_nLx2N:
    21372057      if ( uiPartIdx == 0 )
    21382058      {
    2139         uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
     2059        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2;
    21402060      }
    21412061      else if ( uiPartIdx == 1 )
    21422062      {
    2143         uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
     2063        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2);
    21442064      }
    21452065      else
     
    21482068      }
    21492069      break;
    2150     case SIZE_nRx2N:   
     2070    case SIZE_nRx2N:
    21512071      if ( uiPartIdx == 0 )
    21522072      {
    2153         uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
     2073        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2);
    21542074      }
    21552075      else if ( uiPartIdx == 1 )
    21562076      {
    2157         uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
     2077        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2;
    21582078      }
    21592079      else
     
    21662086      break;
    21672087  }
    2168  
     2088
    21692089  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + uiPUWidth / m_pcPic->getMinCUWidth() - 1 ];
    21702090}
     
    21792099    case SIZE_Nx2N:  uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
    21802100    case SIZE_NxN:   uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
    2181     case SIZE_2NxnU: 
     2101    case SIZE_2NxnU:
    21822102      if ( uiPartIdx == 0 )
    21832103      {
    2184         uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
     2104        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;
    21852105      }
    21862106      else if ( uiPartIdx == 1 )
    21872107      {
    2188         uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
     2108        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);
    21892109      }
    21902110      else
     
    21932113      }
    21942114      break;
    2195     case SIZE_2NxnD: 
     2115    case SIZE_2NxnD:
    21962116      if ( uiPartIdx == 0 )
    21972117      {
    2198         uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
     2118        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);
    21992119      }
    22002120      else if ( uiPartIdx == 1 )
    22012121      {
    2202         uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
     2122        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;
    22032123      }
    22042124      else
     
    22132133      break;
    22142134  }
    2215  
    2216   ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU + uiAbsPartIdx ] + ((uiPUHeight / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth()];
     2135
     2136  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_absZIdxInCtu + uiAbsPartIdx ] + ((uiPUHeight / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInCtuWidth()];
    22172137}
    22182138
    22192139Void TComDataCU::deriveLeftRightTopIdx ( UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
    22202140{
    2221   ruiPartIdxLT = m_uiAbsIdxInLCU;
     2141  ruiPartIdxLT = m_absZIdxInCtu;
    22222142  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1 ];
    2223  
     2143
    22242144  switch ( m_pePartSize[0] )
    22252145  {
     
    22542174      break;
    22552175  }
    2256  
     2176
    22572177}
    22582178
    22592179Void TComDataCU::deriveLeftBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxLB )
    22602180{
    2261   ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ( ((m_puhHeight[0] / m_pcPic->getMinCUHeight())>>1) - 1)*m_pcPic->getNumPartInWidth()];
    2262  
     2181  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_absZIdxInCtu ] + ( ((m_puhHeight[0] / m_pcPic->getMinCUHeight())>>1) - 1)*m_pcPic->getNumPartInCtuWidth()];
     2182
    22632183  switch ( m_pePartSize[0] )
    22642184  {
     
    22952215/** Derives the partition index of neighbouring bottom right block
    22962216 * \param [in]  eCUMode
    2297  * \param [in]  uiPartIdx 
    2298  * \param [out] ruiPartIdxRB 
     2217 * \param [in]  uiPartIdx
     2218 * \param [out] ruiPartIdxRB
    22992219 */
    23002220Void TComDataCU::deriveRightBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxRB )
    23012221{
    2302   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];
     2222  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];
    23032223
    23042224  switch ( m_pePartSize[0] )
    23052225  {
    2306     case SIZE_2Nx2N: 
    2307       ruiPartIdxRB += m_uiNumPartition >> 1;   
    2308       break;
    2309     case SIZE_2NxN: 
    2310       ruiPartIdxRB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;   
    2311       break;
    2312     case SIZE_Nx2N: 
    2313       ruiPartIdxRB += ( uiPartIdx == 0 )? m_uiNumPartition >> 2 : (m_uiNumPartition >> 1);   
    2314       break;
    2315     case SIZE_NxN:   
    2316       ruiPartIdxRB += ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );   
     2226    case SIZE_2Nx2N:
     2227      ruiPartIdxRB += m_uiNumPartition >> 1;
     2228      break;
     2229    case SIZE_2NxN:
     2230      ruiPartIdxRB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
     2231      break;
     2232    case SIZE_Nx2N:
     2233      ruiPartIdxRB += ( uiPartIdx == 0 )? m_uiNumPartition >> 2 : (m_uiNumPartition >> 1);
     2234      break;
     2235    case SIZE_NxN:
     2236      ruiPartIdxRB += ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );
    23172237      break;
    23182238    case SIZE_2NxnU:
     
    23372257{
    23382258  UInt uiNumPartInWidth = (m_puhWidth[0]/m_pcPic->getMinCUWidth())>>uiPartDepth;
    2339   ruiPartIdxLT = m_uiAbsIdxInLCU + uiPartOffset;
     2259  ruiPartIdxLT = m_absZIdxInCtu + uiPartOffset;
    23402260  ruiPartIdxRT = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxLT ] + uiNumPartInWidth - 1 ];
    23412261}
     
    23452265  UInt uiAbsIdx;
    23462266  UInt uiMinCuWidth, uiWidthInMinCus;
    2347  
     2267
    23482268  uiMinCuWidth    = getPic()->getMinCUWidth();
    23492269  uiWidthInMinCus = (getWidth(0)/uiMinCuWidth)>>uiPartDepth;
    2350   uiAbsIdx        = getZorderIdxInCU()+uiPartOffset+(m_uiNumPartition>>(uiPartDepth<<1))-1;
     2270  uiAbsIdx        = getZorderIdxInCtu()+uiPartOffset+(m_uiNumPartition>>(uiPartDepth<<1))-1;
    23512271  uiAbsIdx        = g_auiZscanToRaster[uiAbsIdx]-(uiWidthInMinCus-1);
    23522272  ruiPartIdxLB    = g_auiRasterToZscan[uiAbsIdx];
     
    23552275Bool TComDataCU::hasEqualMotion( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx )
    23562276{
    2357 
    23582277  if ( getInterDir( uiAbsPartIdx ) != pcCandCU->getInterDir( uiCandAbsPartIdx ) )
    23592278  {
     
    23652284    if ( getInterDir( uiAbsPartIdx ) & ( 1 << uiRefListIdx ) )
    23662285    {
    2367       if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx )     != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiCandAbsPartIdx ) || 
     2286      if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx )     != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiCandAbsPartIdx ) ||
    23682287        getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiAbsPartIdx ) != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiCandAbsPartIdx ) )
    23692288      {
     
    23782297/** Constructs a list of merging candidates
    23792298 * \param uiAbsPartIdx
    2380  * \param uiPUIdx 
     2299 * \param uiPUIdx
    23812300 * \param uiDepth
    23822301 * \param pcMvFieldNeighbours
     
    23862305Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx )
    23872306{
    2388   UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
     2307  UInt uiAbsPartAddr = m_absZIdxInCtu + uiAbsPartIdx;
    23892308  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
    23902309  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
     
    24042323  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
    24052324  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
    2406   deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
     2325  deriveLeftBottomIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
    24072326
    24082327  //left
     
    24102329  TComDataCU* pcCULeft = 0;
    24112330  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
     2331
    24122332  Bool isAvailableA1 = pcCULeft &&
    2413   pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
    2414   !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
    2415   !pcCULeft->isIntra( uiLeftPartIdx ) ;
     2333                       pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
     2334                       !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
     2335                       pcCULeft->isInter( uiLeftPartIdx ) ;
     2336
    24162337  if ( isAvailableA1 )
    24172338  {
     
    24312352    iCount ++;
    24322353  }
    2433  
     2354
    24342355  // early termination
    2435   if (iCount == getSlice()->getMaxNumMergeCand()) 
     2356  if (iCount == getSlice()->getMaxNumMergeCand())
    24362357  {
    24372358    return;
     
    24412362  TComDataCU* pcCUAbove = 0;
    24422363  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
     2364
    24432365  Bool isAvailableB1 = pcCUAbove &&
    2444   pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
    2445   !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
    2446   !pcCUAbove->isIntra( uiAbovePartIdx );
     2366                       pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
     2367                       !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
     2368                       pcCUAbove->isInter( uiAbovePartIdx );
     2369
    24472370  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
    24482371  {
     
    24632386  }
    24642387  // early termination
    2465   if (iCount == getSlice()->getMaxNumMergeCand()) 
     2388  if (iCount == getSlice()->getMaxNumMergeCand())
    24662389  {
    24672390    return;
     
    24722395  TComDataCU* pcCUAboveRight = 0;
    24732396  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
     2397
    24742398  Bool isAvailableB0 = pcCUAboveRight &&
    2475   pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
    2476   !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
     2399                       pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
     2400                       pcCUAboveRight->isInter( uiAboveRightPartIdx );
     2401
    24772402  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
    24782403  {
     
    24932418  }
    24942419  // early termination
    2495   if (iCount == getSlice()->getMaxNumMergeCand()) 
     2420  if (iCount == getSlice()->getMaxNumMergeCand())
    24962421  {
    24972422    return;
     
    25022427  TComDataCU* pcCULeftBottom = 0;
    25032428  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
     2429
    25042430  Bool isAvailableA0 = pcCULeftBottom &&
    2505   pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
    2506   !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
     2431                       pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
     2432                       pcCULeftBottom->isInter( uiLeftBottomPartIdx ) ;
     2433
    25072434  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
    25082435  {
     
    25232450  }
    25242451  // early termination
    2525   if (iCount == getSlice()->getMaxNumMergeCand()) 
     2452  if (iCount == getSlice()->getMaxNumMergeCand())
    25262453  {
    25272454    return;
    25282455  }
    2529   // above left
     2456
     2457  // above left
    25302458  if( iCount < 4 )
    25312459  {
     
    25332461    TComDataCU* pcCUAboveLeft = 0;
    25342462    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
     2463
    25352464    Bool isAvailableB2 = pcCUAboveLeft &&
    2536     pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
    2537     !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
     2465                         pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
     2466                         pcCUAboveLeft->isInter( uiAboveLeftPartIdx );
     2467
    25382468    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
    25392469        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
     
    25562486  }
    25572487  // early termination
    2558   if (iCount == getSlice()->getMaxNumMergeCand()) 
     2488  if (iCount == getSlice()->getMaxNumMergeCand())
    25592489  {
    25602490    return;
    25612491  }
    2562   if ( getSlice()->getEnableTMVPFlag())
     2492
     2493  if ( getSlice()->getEnableTMVPFlag() )
    25632494  {
    25642495    //>> MTK colocated-RightBottom
    25652496    UInt uiPartIdxRB;
    25662497
    2567     deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
     2498    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB );
    25682499
    25692500    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
    2570     UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
     2501    const UInt numPartInCtuWidth  = m_pcPic->getNumPartInCtuWidth();
     2502    const UInt numPartInCtuHeight = m_pcPic->getNumPartInCtuHeight();
    25712503
    25722504    TComMv cColMv;
    25732505    Int iRefIdx;
    2574     Int uiLCUIdx = -1;
     2506    Int ctuRsAddr = -1;
    25752507
    25762508#if REPN_FORMAT_IN_VPS
    2577     if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getPicWidthInLumaSamples() )  // image boundary check
    2578     {
    2579     }
    2580     else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getPicHeightInLumaSamples() )
    2581     {
    2582     }
     2509    if (   ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth () ) < m_pcSlice->getPicWidthInLumaSamples() )  // image boundary check
     2510        && ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) < m_pcSlice->getPicHeightInLumaSamples() ) )
    25832511#else
    2584     if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
    2585     {
    2586     }
    2587     else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
    2588     {
    2589     }
    2590 #endif
    2591     else
    2592     {
    2593       if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
    2594         ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
    2595       {
    2596         uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
    2597         uiLCUIdx = getAddr();
    2598       }
    2599       else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
    2600       {
    2601         uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
    2602       }
    2603       else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
     2512    if (   ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth () ) < m_pcSlice->getSPS()->getPicWidthInLumaSamples () )  // image boundary check
     2513        && ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) < m_pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     2514#endif   
     2515    {
     2516      if ( ( uiAbsPartIdxTmp % numPartInCtuWidth < numPartInCtuWidth - 1 ) &&           // is not at the last column of CTU
     2517        ( uiAbsPartIdxTmp / numPartInCtuWidth < numPartInCtuHeight - 1 ) )              // is not at the last row    of CTU
     2518      {
     2519        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + numPartInCtuWidth + 1 ];
     2520        ctuRsAddr = getCtuRsAddr();
     2521      }
     2522      else if ( uiAbsPartIdxTmp % numPartInCtuWidth < numPartInCtuWidth - 1 )           // is not at the last column of CTU But is last row of CTU
     2523      {
     2524        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + numPartInCtuWidth + 1) % m_pcPic->getNumPartitionsInCtu() ];
     2525      }
     2526      else if ( uiAbsPartIdxTmp / numPartInCtuWidth < numPartInCtuHeight - 1 )          // is not at the last row of CTU But is last column of CTU
    26042527      {
    26052528        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
    2606         uiLCUIdx = getAddr() + 1;
    2607       }
    2608       else //is the right bottom corner of LCU                       
     2529        ctuRsAddr = getCtuRsAddr() + 1;
     2530      }
     2531      else //is the right bottom corner of CTU
    26092532      {
    26102533        uiAbsPartAddr = 0;
    26112534      }
    26122535    }
    2613    
    2614    
     2536
    26152537    iRefIdx = 0;
     2538
    26162539    Bool bExistMV = false;
    26172540    UInt uiPartIdxCenter;
    2618     UInt uiCurLCUIdx = getAddr();
    26192541    Int dir = 0;
    26202542    UInt uiArrayAddr = iCount;
    26212543    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
    2622     bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
     2544    bExistMV = ctuRsAddr >= 0 && xGetColMVP( REF_PIC_LIST_0, ctuRsAddr, uiAbsPartAddr, cColMv, iRefIdx );
    26232545    if( bExistMV == false )
    26242546    {
    2625       bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
     2547      bExistMV = xGetColMVP( REF_PIC_LIST_0, getCtuRsAddr(), uiPartIdxCenter, cColMv, iRefIdx );
    26262548    }
    26272549    if( bExistMV )
     
    26302552      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
    26312553    }
    2632    
     2554
    26332555    if ( getSlice()->isInterB() )
    26342556    {
    2635       bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
     2557      bExistMV = ctuRsAddr >= 0 && xGetColMVP( REF_PIC_LIST_1, ctuRsAddr, uiAbsPartAddr, cColMv, iRefIdx);
    26362558      if( bExistMV == false )
    26372559      {
    2638         bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
     2560        bExistMV = xGetColMVP( REF_PIC_LIST_1, getCtuRsAddr(), uiPartIdxCenter, cColMv, iRefIdx );
    26392561      }
    26402562      if( bExistMV )
     
    26442566      }
    26452567    }
    2646    
     2568
    26472569    if (dir != 0)
    26482570    {
     
    26582580  }
    26592581  // early termination
    2660   if (iCount == getSlice()->getMaxNumMergeCand()) 
     2582  if (iCount == getSlice()->getMaxNumMergeCand())
    26612583  {
    26622584    return;
    26632585  }
     2586
    26642587  UInt uiArrayAddr = iCount;
    26652588  UInt uiCutoff = uiArrayAddr;
    2666    
    2667   if ( getSlice()->isInterB())
    2668   {
    2669     UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
    2670     UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
     2589
     2590  if ( getSlice()->isInterB() )
     2591  {
     2592    static const UInt NUM_PRIORITY_LIST=12;
     2593    static const UInt uiPriorityList0[NUM_PRIORITY_LIST] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
     2594    static const UInt uiPriorityList1[NUM_PRIORITY_LIST] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
    26712595
    26722596    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
    26732597    {
    2674       Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
     2598      assert(idx<NUM_PRIORITY_LIST);
     2599      Int i = uiPriorityList0[idx];
     2600      Int j = uiPriorityList1[idx];
    26752601      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
    26762602      {
     
    26962622  }
    26972623  // early termination
    2698   if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
     2624  if (uiArrayAddr == getSlice()->getMaxNumMergeCand())
    26992625  {
    27002626    return;
    27012627  }
     2628
    27022629  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);
     2630
    27032631  Int r = 0;
    27042632  Int refcnt = 0;
     
    27152643    }
    27162644    uiArrayAddr++;
     2645
    27172646    if ( refcnt == iNumRefIdx - 1 )
    27182647    {
     
    27252654    }
    27262655  }
    2727 
    27282656  numValidMergeCand = uiArrayAddr;
    27292657}
     
    27482676  return false;
    27492677}
     2678
    27502679/** calculate the location of upper-left corner pixel and size of the current PU.
    27512680 * \param partIdx  PU index within a CU
     
    27622691  {
    27632692  case SIZE_2NxN:
    2764     nPSW = getWidth(0);     
    2765     nPSH = getHeight(0) >> 1; 
     2693    nPSW = getWidth(0);
     2694    nPSH = getHeight(0) >> 1;
    27662695    xP   = col;
    27672696    yP   = (partIdx ==0)? row: row + nPSH;
    27682697    break;
    27692698  case SIZE_Nx2N:
    2770     nPSW = getWidth(0) >> 1; 
    2771     nPSH = getHeight(0);     
     2699    nPSW = getWidth(0) >> 1;
     2700    nPSH = getHeight(0);
    27722701    xP   = (partIdx ==0)? col: col + nPSW;
    27732702    yP   = row;
    27742703    break;
    27752704  case SIZE_NxN:
    2776     nPSW = getWidth(0) >> 1; 
    2777     nPSH = getHeight(0) >> 1; 
     2705    nPSW = getWidth(0) >> 1;
     2706    nPSH = getHeight(0) >> 1;
    27782707    xP   = col + (partIdx&0x1)*nPSW;
    27792708    yP   = row + (partIdx>>1)*nPSH;
     
    28062735  default:
    28072736    assert ( m_pePartSize[0] == SIZE_2Nx2N );
    2808     nPSW = getWidth(0);     
    2809     nPSH = getHeight(0);     
     2737    nPSW = getWidth(0);
     2738    nPSH = getHeight(0);
    28102739    xP   = col ;
    28112740    yP   = row ;
     
    28172746/** Constructs a list of candidates for AMVP
    28182747 * \param uiPartIdx
    2819  * \param uiPartAddr 
     2748 * \param uiPartAddr
    28202749 * \param eRefPicList
    28212750 * \param iRefIdx
     
    28272756  Bool bAddedSmvp = false;
    28282757
    2829   pInfo->iN = 0; 
     2758  pInfo->iN = 0;
    28302759  if (iRefIdx < 0)
    28312760  {
    28322761    return;
    28332762  }
    2834  
     2763
    28352764  //-- Get Spatial MV
    28362765  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
    2837   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
     2766  const UInt numPartInCtuWidth  = m_pcPic->getNumPartInCtuWidth();
     2767  const UInt numPartInCtuHeight = m_pcPic->getNumPartInCtuHeight();
    28382768  Bool bAdded = false;
    2839  
     2769
    28402770  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
    28412771  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
    2842  
     2772
    28432773  TComDataCU* tmpCU = NULL;
    28442774  UInt idx;
    28452775  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
    2846   bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
     2776  bAddedSmvp = (tmpCU != NULL) && (tmpCU->isInter(idx));
    28472777
    28482778  if (!bAddedSmvp)
    28492779  {
    28502780    tmpCU = getPULeft(idx, uiPartIdxLB);
    2851     bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
     2781    bAddedSmvp = (tmpCU != NULL) && (tmpCU->isInter(idx));
    28522782  }
    28532783
    28542784  // Left predictor search
    28552785  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
    2856   if (!bAdded) 
     2786  if (!bAdded)
    28572787  {
    28582788    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
    28592789  }
    2860  
     2790
    28612791  if(!bAdded)
    28622792  {
    28632793    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
    2864     if (!bAdded) 
     2794    if (!bAdded)
    28652795    {
    28662796      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
    28672797    }
    28682798  }
    2869  
     2799
    28702800  // Above predictor search
    28712801  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
    28722802
    2873   if (!bAdded) 
     2803  if (!bAdded)
    28742804  {
    28752805    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
     
    28812811  }
    28822812
    2883   if (!bAddedSmvp)
     2813  if(!bAddedSmvp)
    28842814  {
    28852815    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
    2886     if (!bAdded) 
     2816    if (!bAdded)
    28872817    {
    28882818      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
     
    28942824    }
    28952825  }
    2896  
     2826
    28972827  if ( pInfo->iN == 2 )
    28982828  {
     
    29092839    TComMv cColMv;
    29102840    UInt uiPartIdxRB;
    2911     UInt uiAbsPartIdx; 
     2841    UInt uiAbsPartIdx;
    29122842    UInt uiAbsPartAddr;
    29132843
    29142844    deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
    2915     uiAbsPartAddr = m_uiAbsIdxInLCU + uiPartAddr;
     2845    uiAbsPartAddr = m_absZIdxInCtu + uiPartAddr;
    29162846
    29172847    //----  co-located RightBottom Temporal Predictor (H) ---//
    29182848    uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
    2919     Int uiLCUIdx = -1;
     2849    Int ctuRsAddr = -1;
    29202850#if REPN_FORMAT_IN_VPS
    2921     if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getPicWidthInLumaSamples() )  // image boundary check
    2922     {
    2923     }
    2924     else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getPicHeightInLumaSamples() )
    2925     {
    2926     }
     2851    if (  ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth () ) < m_pcSlice->getPicWidthInLumaSamples())   // image boundary check
     2852       && ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) < m_pcSlice->getPicHeightInLumaSamples() ) )   
    29272853#else
    2928     if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
    2929     {
    2930     }
    2931     else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
    2932     {
    2933     }
    2934 #endif
     2854    if (  ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth () ) < m_pcSlice->getSPS()->getPicWidthInLumaSamples () )  // image boundary check
     2855       && ( ( m_pcPic->getCtu(m_ctuRsAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) < m_pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     2856#endif   
     2857    {
     2858      if ( ( uiAbsPartIdx % numPartInCtuWidth < numPartInCtuWidth - 1 ) &&  // is not at the last column of CTU
     2859           ( uiAbsPartIdx / numPartInCtuWidth < numPartInCtuHeight - 1 ) )  // is not at the last row    of CTU
     2860      {
     2861        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + numPartInCtuWidth + 1 ];
     2862        ctuRsAddr = getCtuRsAddr();
     2863      }
     2864      else if ( uiAbsPartIdx % numPartInCtuWidth < numPartInCtuWidth - 1 )  // is not at the last column of CTU But is last row of CTU
     2865      {
     2866        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + numPartInCtuWidth + 1) % m_pcPic->getNumPartitionsInCtu() ];
     2867      }
     2868      else if ( uiAbsPartIdx / numPartInCtuWidth < numPartInCtuHeight - 1 ) // is not at the last row of CTU But is last column of CTU
     2869      {
     2870        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
     2871        ctuRsAddr = getCtuRsAddr() + 1;
     2872      }
     2873      else //is the right bottom corner of CTU
     2874      {
     2875        uiAbsPartAddr = 0;
     2876      }
     2877    }
     2878    if ( ctuRsAddr >= 0 && xGetColMVP( eRefPicList, ctuRsAddr, uiAbsPartAddr, cColMv, iRefIdx_Col ) )
     2879    {
     2880      pInfo->m_acMvCand[pInfo->iN++] = cColMv;
     2881    }
    29352882    else
    29362883    {
    2937       if ( ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
    2938         ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
    2939       {
    2940         uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth + 1 ];
    2941         uiLCUIdx = getAddr();
    2942       }
    2943       else if ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
    2944       {
    2945         uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
    2946       }
    2947       else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
    2948       {
    2949         uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
    2950         uiLCUIdx = getAddr() + 1;
    2951       }
    2952       else //is the right bottom corner of LCU                       
    2953       {
    2954         uiAbsPartAddr = 0;
    2955       }
    2956     }
    2957     if ( uiLCUIdx >= 0 && xGetColMVP( eRefPicList, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx_Col ) )
    2958     {
    2959       pInfo->m_acMvCand[pInfo->iN++] = cColMv;
    2960     }
    2961     else
    2962     {
    29632884      UInt uiPartIdxCenter;
    2964       UInt uiCurLCUIdx = getAddr();
    29652885      xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
    2966       if (xGetColMVP( eRefPicList, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx_Col ))
     2886      if (xGetColMVP( eRefPicList, getCtuRsAddr(), uiPartIdxCenter,  cColMv, iRefIdx_Col ))
    29672887      {
    29682888        pInfo->m_acMvCand[pInfo->iN++] = cColMv;
     
    29762896    pInfo->iN = AMVP_MAX_NUM_CANDS;
    29772897  }
     2898
    29782899  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
    29792900  {
    2980       pInfo->m_acMvCand[pInfo->iN].set(0,0);
    2981       pInfo->iN++;
     2901    pInfo->m_acMvCand[pInfo->iN].set(0,0);
     2902    pInfo->iN++;
    29822903  }
    29832904  return ;
    29842905}
     2906
    29852907
    29862908Bool TComDataCU::isBipredRestriction(UInt puIdx)
     
    29972919  return false;
    29982920}
     2921
    29992922
    30002923Void TComDataCU::clipMv    (TComMv&  rcMv)
     
    30152938#endif
    30162939  Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
    3017  
     2940
    30182941  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
    30192942  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
    30202943}
    30212944
     2945
    30222946UInt TComDataCU::getIntraSizeIdx(UInt uiAbsPartIdx)
    30232947{
    30242948  UInt uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
    3025  
     2949
    30262950  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
    30272951  UInt  uiCnt = 0;
     
    30352959}
    30362960
    3037 Void TComDataCU::clearCbf( UInt uiIdx, TextType eType, UInt uiNumParts )
    3038 {
    3039   ::memset( &m_puhCbf[g_aucConvertTxtTypeToIdx[eType]][uiIdx], 0, sizeof(UChar)*uiNumParts);
     2961Void TComDataCU::clearCbf( UInt uiIdx, ComponentID compID, UInt uiNumParts )
     2962{
     2963  memset( &m_puhCbf[compID][uiIdx], 0, sizeof(UChar)*uiNumParts);
    30402964}
    30412965
     
    30482972Void TComDataCU::setIPCMFlagSubParts  (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
    30492973{
    3050   UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
     2974  UInt uiCurrPartNumb = m_pcPic->getNumPartitionsInCtu() >> (uiDepth << 1);
    30512975
    30522976  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
     
    30793003    case MD_ABOVE:
    30803004    {
    3081       pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx );
     3005      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
    30823006      break;
    30833007    }
     
    31073031    return false;
    31083032  }
    3109  
     3033
    31103034  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
    31113035  {
    31123036    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
    3113    
     3037
    31143038    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
    31153039    return true;
     
    31443068}
    31453069
    3146 /** 
     3070/**
    31473071 * \param pInfo
    3148  * \param eRefPicList 
     3072 * \param eRefPicList
    31493073 * \param iRefIdx
    31503074 * \param uiPartUnitIdx
     
    31893113  }
    31903114
    3191   if ( pcTmpCU == NULL ) 
     3115  if ( pcTmpCU == NULL )
    31923116  {
    31933117    return false;
    31943118  }
    3195  
     3119
    31963120  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
    31973121  if(       eRefPicList == REF_PIC_LIST_0 )
     
    32083132  Int iNeibPOC = iCurrPOC;
    32093133  Int iNeibRefPOC;
    3210 
    32113134  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
    32123135  Bool bIsNeibRefLongTerm = false;
     3136
    32133137  //---------------  V1 (END) ------------------//
    32143138  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
     
    32193143
    32203144    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
    3221     if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm )
    3222     {
    3223     if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
    3224     {
    3225       rcMv = cMvPred;
    3226     }
    3227     else
    3228     {
    3229       Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
    3230       if ( iScale == 4096 )
     3145    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm )
     3146    {
     3147      if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
    32313148      {
    32323149        rcMv = cMvPred;
     
    32343151      else
    32353152      {
    3236         rcMv = cMvPred.scaleMv( iScale );
    3237       }
    3238     }
    3239     pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
    3240     return true;
     3153        Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
     3154        if ( iScale == 4096 )
     3155        {
     3156          rcMv = cMvPred;
     3157        }
     3158        else
     3159        {
     3160          rcMv = cMvPred.scaleMv( iScale );
     3161        }
     3162      }
     3163
     3164      pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
     3165      return true;
    32413166    }
    32423167  }
     
    32493174
    32503175    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
    3251     if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm )
    3252     {
    3253     if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
    3254     {
    3255       rcMv = cMvPred;
    3256     }
    3257     else
    3258     {
    3259       Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
    3260       if ( iScale == 4096 )
     3176    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm )
     3177    {
     3178      if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
    32613179      {
    32623180        rcMv = cMvPred;
     
    32643182      else
    32653183      {
    3266         rcMv = cMvPred.scaleMv( iScale );
    3267       }
    3268     }
    3269     pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
    3270     return true;
     3184        Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
     3185        if ( iScale == 4096 )
     3186        {
     3187          rcMv = cMvPred;
     3188        }
     3189        else
     3190        {
     3191          rcMv = cMvPred.scaleMv( iScale );
     3192        }
     3193      }
     3194
     3195      pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
     3196      return true;
    32713197    }
    32723198  }
     
    32753201}
    32763202
    3277 /** 
     3203/**
    32783204 * \param eRefPicList
    3279  * \param uiCUAddr 
     3205 * \param uiCUAddr
    32803206 * \param uiPartUnitIdx
    32813207 * \param riRefIdx
    32823208 * \returns Bool
    32833209 */
    3284 Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx )
     3210Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int ctuRsAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx )
    32853211{
    32863212  UInt uiAbsPartAddr = uiPartUnitIdx;
     
    32923218  // use coldir.
    32933219  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
    3294   TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
    3295   if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
     3220  TComDataCU *pColCtu = pColPic->getCtu( ctuRsAddr );
     3221  if(pColCtu->getPic()==0||pColCtu->getPartitionSize(uiPartUnitIdx)==NUMBER_OF_PART_SIZES)
    32963222  {
    32973223    return false;
    32983224  }
    3299   iCurrPOC = m_pcSlice->getPOC();   
    3300   iColPOC = pColCU->getSlice()->getPOC(); 
    3301 
    3302   if (pColCU->isIntra(uiAbsPartAddr))
     3225  iCurrPOC = m_pcSlice->getPOC();
     3226  iColPOC = pColCtu->getSlice()->getPOC();
     3227
     3228  if (!pColCtu->isInter(uiAbsPartAddr))
    33033229  {
    33043230    return false;
    33053231  }
     3232
    33063233  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
    33073234
    3308   Int iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
     3235  Int iColRefIdx = pColCtu->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
    33093236
    33103237  if (iColRefIdx < 0 )
    33113238  {
    33123239    eColRefPicList = RefPicList(1 - eColRefPicList);
    3313     iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
     3240    iColRefIdx = pColCtu->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
    33143241
    33153242    if (iColRefIdx < 0 )
     
    33203247
    33213248  // Scale the vector.
    3322   iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
    3323   cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
     3249  iColRefPOC = pColCtu->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
     3250  cColMv = pColCtu->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
    33243251
    33253252  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
     3253
    33263254  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
    3327   Bool bIsColRefLongTerm = pColCU->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
    3328 
    3329   if ( bIsCurrRefLongTerm != bIsColRefLongTerm ) 
     3255  Bool bIsColRefLongTerm = pColCtu->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
     3256
     3257  if ( bIsCurrRefLongTerm != bIsColRefLongTerm )
    33303258  {
    33313259    return false;
     
    33483276    }
    33493277  }
     3278
    33503279  return true;
    33513280}
     
    33603289  UInt uiLength = 1;
    33613290  UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
    3362  
     3291
    33633292  assert ( uiTemp );
    3364  
     3293
    33653294  while ( 1 != uiTemp )
    33663295  {
     
    33683297    uiLength += 2;
    33693298  }
    3370  
     3299
    33713300  return uiLength;
    33723301}
     
    33773306  Int iDiffPocD = iColPOC - iColRefPOC;
    33783307  Int iDiffPocB = iCurrPOC - iCurrRefPOC;
    3379  
     3308
    33803309  if( iDiffPocD == iDiffPocB )
    33813310  {
     
    33923321}
    33933322
    3394 /** 
     3323/**
    33953324 * \param eCUMode
    3396  * \param uiPartIdx 
     3325 * \param uiPartIdx
    33973326 * \param ruiPartIdxCenter
    33983327 * \returns Void
     
    34043333  Int  iPartHeight;
    34053334  getPartIndexAndSize( uiPartIdx, uiPartAddr, iPartWidth, iPartHeight);
    3406  
    3407   ruiPartIdxCenter = m_uiAbsIdxInLCU+uiPartAddr; // partition origin.
     3335
     3336  ruiPartIdxCenter = m_absZIdxInCtu+uiPartAddr; // partition origin.
    34083337  ruiPartIdxCenter = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxCenter ]
    3409                                         + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInWidth()
     3338                                        + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInCtuWidth()
    34103339                                        + ( iPartWidth/m_pcPic->getMinCUWidth()  )/2];
    34113340}
     
    34163345  if (scaleFactor > 0)
    34173346  {
    3418     m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
    3419     m_acCUMvField[1].compress(m_pePredMode, scaleFactor);   
    3420   }
    3421 }
    3422 
    3423 UInt TComDataCU::getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra)
    3424 {
    3425   UInt uiCTXIdx;
    3426   UInt uiScanIdx;
    3427   UInt uiDirMode;
    3428 
    3429   if ( !bIsIntra )
    3430   {
    3431     uiScanIdx = SCAN_DIAG;
    3432     return uiScanIdx;
    3433   }
    3434 
    3435   switch(uiWidth)
    3436   {
    3437     case  2: uiCTXIdx = 6; break;
    3438     case  4: uiCTXIdx = 5; break;
    3439     case  8: uiCTXIdx = 4; break;
    3440     case 16: uiCTXIdx = 3; break;
    3441     case 32: uiCTXIdx = 2; break;
    3442     case 64: uiCTXIdx = 1; break;
    3443     default: uiCTXIdx = 0; break;
    3444   }
    3445 
    3446   if ( bIsLuma )
    3447   {
    3448     uiDirMode = getLumaIntraDir(uiAbsPartIdx);
    3449     uiScanIdx = SCAN_DIAG;
    3450     if (uiCTXIdx >3 && uiCTXIdx < 6) //if multiple scans supported for transform size
    3451     {
    3452       uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
    3453     }
    3454   }
    3455   else
    3456   {
    3457     uiDirMode = getChromaIntraDir(uiAbsPartIdx);
    3458     if( uiDirMode == DM_CHROMA_IDX )
    3459     {
    3460       // get number of partitions in current CU
    3461       UInt depth = getDepth(uiAbsPartIdx);
    3462       UInt numParts = getPic()->getNumPartInCU() >> (2 * depth);
    3463      
    3464       // get luma mode from upper-left corner of current CU
    3465       uiDirMode = getLumaIntraDir((uiAbsPartIdx/numParts)*numParts);
    3466     }
    3467     uiScanIdx = SCAN_DIAG;
    3468     if (uiCTXIdx >4 && uiCTXIdx < 7) //if multiple scans supported for transform size
    3469     {
    3470       uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
    3471     }
    3472   }
    3473 
    3474   return uiScanIdx;
    3475 }
    3476 
    3477 UInt TComDataCU::getSCUAddr()
    3478 {
    3479   return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU;
     3347    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     3348    {
     3349      m_acCUMvField[i].compress(m_pePredMode, scaleFactor);
     3350    }
     3351  }
     3352}
     3353
     3354UInt TComDataCU::getCoefScanIdx(const UInt uiAbsPartIdx, const UInt uiWidth, const UInt uiHeight, const ComponentID compID) const
     3355{
     3356  //------------------------------------------------
     3357
     3358  //this mechanism is available for intra only
     3359
     3360  if (!isIntra(uiAbsPartIdx)) return SCAN_DIAG;
     3361
     3362  //------------------------------------------------
     3363
     3364  //check that MDCS can be used for this TU
     3365
     3366  const ChromaFormat format = getPic()->getChromaFormat();
     3367
     3368  const UInt maximumWidth  = MDCS_MAXIMUM_WIDTH  >> getComponentScaleX(compID, format);
     3369  const UInt maximumHeight = MDCS_MAXIMUM_HEIGHT >> getComponentScaleY(compID, format);
     3370
     3371  if ((uiWidth > maximumWidth) || (uiHeight > maximumHeight)) return SCAN_DIAG;
     3372
     3373  //------------------------------------------------
     3374
     3375  //otherwise, select the appropriate mode
     3376
     3377  UInt uiDirMode  = getIntraDir(toChannelType(compID), uiAbsPartIdx);
     3378
     3379  if (uiDirMode==DM_CHROMA_IDX)
     3380  {
     3381    uiDirMode = getIntraDir(CHANNEL_TYPE_LUMA, getChromasCorrespondingPULumaIdx(uiAbsPartIdx, getPic()->getChromaFormat()));
     3382  }
     3383
     3384  if (isChroma(compID) && (format == CHROMA_422))
     3385  {
     3386    uiDirMode = g_chroma422IntraAngleMappingTable[uiDirMode];
     3387  }
     3388
     3389  //------------------
     3390
     3391  if      (abs((Int)uiDirMode - VER_IDX) <= MDCS_ANGLE_LIMIT) return SCAN_HOR;
     3392  else if (abs((Int)uiDirMode - HOR_IDX) <= MDCS_ANGLE_LIMIT) return SCAN_VER;
     3393  else return SCAN_DIAG;
    34803394}
    34813395
     
    34933407  TComPic* baseColPic = m_pcSlice->getBaseColPic(refLayerIdc);
    34943408
    3495   UInt uiPelX = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getWidth()  - 1, pelX);
    3496   UInt uiPelY = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getHeight() - 1, pelY);
     3409  UInt uiPelX = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getWidth(COMPONENT_Y)  - 1, pelX);
     3410  UInt uiPelY = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getHeight(COMPONENT_Y) - 1, pelY);
    34973411
    34983412#if REF_IDX_MFM
     
    35613475#endif
    35623476
    3563   if ( iBX < 0 || iBX >= baseColPic->getPicYuvRec()->getWidth() || iBY < 0 || iBY >= baseColPic->getPicYuvRec()->getHeight() )
     3477  if ( iBX < 0 || iBX >= baseColPic->getPicYuvRec()->getWidth(COMPONENT_Y) || iBY < 0 || iBY >= baseColPic->getPicYuvRec()->getHeight(COMPONENT_Y) )
    35643478  {
    35653479    return NULL;
     
    35713485  UInt baseMinUnitSize = baseColPic->getMinCUWidth();
    35723486 
    3573   uiCUAddrBase = ( iBY / baseMaxCUHeight ) * baseColPic->getFrameWidthInCU() + ( iBX / baseMaxCUWidth );
     3487  uiCUAddrBase = ( iBY / baseMaxCUHeight ) * baseColPic->getFrameWidthInCtus() + ( iBX / baseMaxCUWidth );
    35743488#else
    3575   uiCUAddrBase = (iBY/g_uiMaxCUHeight)*baseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
     3489  uiCUAddrBase = (iBY/g_uiMaxCUHeight)*baseColPic->getFrameWidthInCtus() + (iBX/g_uiMaxCUWidth);
    35763490#endif
    35773491
    3578   assert(uiCUAddrBase < baseColPic->getNumCUsInFrame());
     3492  assert(uiCUAddrBase < baseColPic->getNumberOfCtusInFrame());
    35793493
    35803494#if LAYER_CTB
    3581   UInt uiRasterAddrBase = ( iBY - (iBY/baseMaxCUHeight)*baseMaxCUHeight ) / baseMinUnitSize * baseColPic->getNumPartInWidth() + ( iBX - (iBX/baseMaxCUWidth)*baseMaxCUWidth ) / baseMinUnitSize;
     3495  UInt uiRasterAddrBase = ( iBY - (iBY/baseMaxCUHeight)*baseMaxCUHeight ) / baseMinUnitSize * baseColPic->getNumPartInCtuWidth() + ( iBX - (iBX/baseMaxCUWidth)*baseMaxCUWidth ) / baseMinUnitSize;
    35823496 
    35833497  uiAbsPartIdxBase = g_auiLayerRasterToZscan[baseColPic->getLayerId()][uiRasterAddrBase];
    35843498#else
    3585   UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*baseColPic->getNumPartInWidth()
     3499  UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*baseColPic->getNumPartInCtuWidth()
    35863500    + (iBX - (iBX/g_uiMaxCUWidth)*g_uiMaxCUWidth)/uiMinUnitSize;
    35873501
     
    35893503#endif
    35903504
    3591   return baseColPic->getCU(uiCUAddrBase);
     3505  return baseColPic->getCtu(uiCUAddrBase);
    35923506}
    35933507
     
    36293543  }
    36303544
    3631   Int iColBaseDir = pcTempCU->getLumaIntraDir( uiAbsPartAddrBase );
     3545  Int iColBaseDir = pcTempCU->getIntraDir( CHANNEL_TYPE_LUMA, uiAbsPartAddrBase );
    36323546  if ( authorizedMode[iColBaseDir] )  //possibly add BL mode
    36333547  {
Note: See TracChangeset for help on using the changeset viewer.