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

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibCommon/TComPrediction.cpp

    r1196 r1313  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
     4 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3838#include <memory.h>
    3939#include "TComPrediction.h"
     40#include "TComPic.h"
     41#include "TComTU.h"
    4042
    4143//! \ingroup TLibCommon
    4244//! \{
     45
     46// ====================================================================================================================
     47// Tables
     48// ====================================================================================================================
     49
     50const UChar TComPrediction::m_aucIntraFilter[MAX_NUM_CHANNEL_TYPE][MAX_INTRA_FILTER_DEPTHS] =
     51{
     52  { // Luma
     53    10, //4x4
     54    7, //8x8
     55    1, //16x16
     56    0, //32x32
     57    10, //64x64
     58  },
     59  { // Chroma
     60    10, //4xn
     61    7, //8xn
     62    1, //16xn
     63    0, //32xn
     64    10, //64xn
     65  }
     66
     67};
    4368
    4469// ====================================================================================================================
     
    5075, m_iLumaRecStride(0)
    5176{
    52   m_piYuvExt = NULL;
    53 #if H_3D_VSP
    54   m_pDepthBlock = (Int*) malloc(MAX_NUM_SPU_W*MAX_NUM_SPU_W*sizeof(Int));
     77  for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
     78  {
     79    for(UInt buf=0; buf<2; buf++)
     80    {
     81      m_piYuvExt[ch][buf] = NULL;
     82    }
     83  }
     84#if NH_3D_VSP
     85  m_pDepthBlock = (Int*) malloc(MAX_NUM_PART_IDXS_IN_CTU_WIDTH*MAX_NUM_PART_IDXS_IN_CTU_WIDTH*sizeof(Int));
    5586  if (m_pDepthBlock == NULL)
    5687  {
     
    5889  }
    5990#endif
     91
    6092}
    6193
    6294TComPrediction::~TComPrediction()
    6395{
    64 #if H_3D_VSP
     96#if NH_3D_VSP
    6597  if (m_pDepthBlock != NULL)
    6698  {
     
    70102#endif
    71103
    72   delete[] m_piYuvExt;
    73 
    74   m_acYuvPred[0].destroy();
    75   m_acYuvPred[1].destroy();
     104  destroy();
     105}
     106
     107Void TComPrediction::destroy()
     108{
     109  for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
     110  {
     111    for(UInt buf=0; buf<NUM_PRED_BUF; buf++)
     112    {
     113      delete [] m_piYuvExt[ch][buf];
     114      m_piYuvExt[ch][buf] = NULL;
     115    }
     116  }
     117
     118  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     119  {
     120    m_acYuvPred[i].destroy();
     121  }
    76122
    77123  m_cYuvPredTemp.destroy();
    78124
    79 #if H_3D_ARP
     125#if NH_3D_ARP
    80126  m_acYuvPredBase[0].destroy();
    81127  m_acYuvPredBase[1].destroy();
     
    84130  {
    85131    delete [] m_pLumaRecBuffer;
    86   }
    87  
    88   Int i, j;
    89   for (i = 0; i < 4; i++)
    90   {
    91     for (j = 0; j < 4; j++)
     132    m_pLumaRecBuffer = 0;
     133  }
     134  m_iLumaRecStride = 0;
     135
     136  for (UInt i = 0; i < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; i++)
     137  {
     138    for (UInt j = 0; j < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; j++)
    92139    {
    93140      m_filteredBlock[i][j].destroy();
     
    97144}
    98145
    99 Void TComPrediction::initTempBuff()
    100 {
    101   if( m_piYuvExt == NULL )
    102   {
    103     Int extWidth  = MAX_CU_SIZE + 16;
     146Void TComPrediction::initTempBuff(ChromaFormat chromaFormatIDC)
     147{
     148  // if it has been initialised before, but the chroma format has changed, release the memory and start again.
     149  if( m_piYuvExt[COMPONENT_Y][PRED_BUF_UNFILTERED] != NULL && m_cYuvPredTemp.getChromaFormat()!=chromaFormatIDC)
     150  {
     151    destroy();
     152  }
     153
     154  if( m_piYuvExt[COMPONENT_Y][PRED_BUF_UNFILTERED] == NULL ) // check if first is null (in which case, nothing initialised yet)
     155  {
     156    Int extWidth  = MAX_CU_SIZE + 16;
    104157    Int extHeight = MAX_CU_SIZE + 1;
    105     Int i, j;
    106     for (i = 0; i < 4; i++)
    107     {
    108       m_filteredBlockTmp[i].create(extWidth, extHeight + 7);
    109       for (j = 0; j < 4; j++)
    110       {
    111         m_filteredBlock[i][j].create(extWidth, extHeight);
    112       }
    113     }
    114     m_iYuvExtHeight  = ((MAX_CU_SIZE + 2) << 4);
    115     m_iYuvExtStride = ((MAX_CU_SIZE  + 8) << 4);
    116     m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
     158
     159    for (UInt i = 0; i < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; i++)
     160    {
     161      m_filteredBlockTmp[i].create(extWidth, extHeight + 7, chromaFormatIDC);
     162      for (UInt j = 0; j < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; j++)
     163      {
     164        m_filteredBlock[i][j].create(extWidth, extHeight, chromaFormatIDC);
     165      }
     166    }
     167
     168    m_iYuvExtSize = (MAX_CU_SIZE*2+1) * (MAX_CU_SIZE*2+1);
     169    for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
     170    {
     171      for(UInt buf=0; buf<NUM_PRED_BUF; buf++)
     172      {
     173        m_piYuvExt[ch][buf] = new Pel[ m_iYuvExtSize ];
     174      }
     175    }
    117176
    118177    // new structure
    119     m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE );
    120     m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE );
    121 
    122     m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE );
    123 #if H_3D_ARP
    124     m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
    125     m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
    126 #endif
    127 #if H_3D_VSP
    128     m_cYuvDepthOnVsp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
    129 #endif
    130   }
     178    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     179    {
     180      m_acYuvPred[i] .create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );
     181    }
     182
     183    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );
     184#if NH_3D_ARP
     185    m_acYuvPredBase[0] .create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );
     186    m_acYuvPredBase[1] .create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );
     187#endif
     188#if NH_3D_VSP
     189    m_cYuvDepthOnVsp.create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );
     190#endif
     191
     192  }
     193
    131194
    132195  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
     
    138201    }
    139202  }
    140 #if H_3D_IC
     203#if NH_3D_IC
    141204  m_uiaShift[0] = 0;
    142205  for( Int i = 1; i < 64; i++ )
     
    152215
    153216// Function for calculating DC value of the reference samples used in Intra prediction
    154 Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft )
     217//NOTE: Bit-Limit - 25-bit source
     218Pel TComPrediction::predIntraGetPredValDC( const Pel* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight)
    155219{
    156220  assert(iWidth > 0 && iHeight > 0);
     
    158222  Pel pDcVal;
    159223
    160   if (bAbove)
    161   {
    162     for (iInd = 0;iInd < iWidth;iInd++)
    163     {
    164       iSum += pSrc[iInd-iSrcStride];
    165     }
    166   }
    167   if (bLeft)
    168   {
    169     for (iInd = 0;iInd < iHeight;iInd++)
    170     {
    171       iSum += pSrc[iInd*iSrcStride-1];
    172     }
    173   }
    174 
    175   if (bAbove && bLeft)
    176   {
    177     pDcVal = (iSum + iWidth) / (iWidth + iHeight);
    178   }
    179   else if (bAbove)
    180   {
    181     pDcVal = (iSum + iWidth/2) / iWidth;
    182   }
    183   else if (bLeft)
    184   {
    185     pDcVal = (iSum + iHeight/2) / iHeight;
    186   }
    187   else
    188   {
    189     pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available
    190   }
    191  
     224  for (iInd = 0;iInd < iWidth;iInd++)
     225  {
     226    iSum += pSrc[iInd-iSrcStride];
     227  }
     228  for (iInd = 0;iInd < iHeight;iInd++)
     229  {
     230    iSum += pSrc[iInd*iSrcStride-1];
     231  }
     232
     233  pDcVal = (iSum + iWidth) / (iWidth + iHeight);
     234
    192235  return pDcVal;
    193236}
     
    196239
    197240/** Function for deriving the simplified angular intra predictions.
    198  * \param pSrc pointer to reconstructed sample array
    199  * \param srcStride the stride of the reconstructed sample array
    200  * \param rpDst reference to pointer for the prediction sample array
    201  * \param dstStride the stride of the prediction sample array
    202  * \param width the width of the block
    203  * \param height the height of the block
    204  * \param dirMode the intra prediction mode index
    205  * \param blkAboveAvailable boolean indication if the block above is available
    206  * \param blkLeftAvailable boolean indication if the block to the left is available
     241 * \param bitDepth           bit depth
     242 * \param pSrc               pointer to reconstructed sample array
     243 * \param srcStride          the stride of the reconstructed sample array
     244 * \param pTrueDst           reference to pointer for the prediction sample array
     245 * \param dstStrideTrue      the stride of the prediction sample array
     246 * \param uiWidth            the width of the block
     247 * \param uiHeight           the height of the block
     248 * \param channelType        type of pel array (luma/chroma)
     249 * \param format             chroma format
     250 * \param dirMode            the intra prediction mode index
     251 * \param blkAboveAvailable  boolean indication if the block above is available
     252 * \param blkLeftAvailable   boolean indication if the block to the left is available
     253 * \param bEnableEdgeFilters indication whether to enable edge filters
    207254 *
    208255 * This function derives the prediction samples for the angular mode based on the prediction direction indicated by
     
    214261 * from the extended main reference.
    215262 */
    216 Void TComPrediction::xPredIntraAng(Int bitDepth, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter )
    217 {
    218   Int k,l;
    219   Int blkSize        = width;
    220   Pel* pDst          = rpDst;
     263//NOTE: Bit-Limit - 25-bit source
     264Void TComPrediction::xPredIntraAng(       Int bitDepth,
     265                                    const Pel* pSrc,     Int srcStride,
     266                                          Pel* pTrueDst, Int dstStrideTrue,
     267                                          UInt uiWidth, UInt uiHeight, ChannelType channelType,
     268                                          UInt dirMode, const Bool bEnableEdgeFilters
     269                                  )
     270{
     271  Int width=Int(uiWidth);
     272  Int height=Int(uiHeight);
    221273
    222274  // Map the mode index to main prediction direction and angle
    223   assert( dirMode > 0 ); //no planar
    224   Bool modeDC        = dirMode < 2;
    225   Bool modeHor       = !modeDC && (dirMode < 18);
    226   Bool modeVer       = !modeDC && !modeHor;
    227   Int intraPredAngle = modeVer ? (Int)dirMode - VER_IDX : modeHor ? -((Int)dirMode - HOR_IDX) : 0;
    228   Int absAng         = abs(intraPredAngle);
    229   Int signAng        = intraPredAngle < 0 ? -1 : 1;
    230 
    231   // Set bitshifts and scale the angle parameter to block size
    232   Int angTable[9]    = {0,    2,    5,   9,  13,  17,  21,  26,  32};
    233   Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
    234   Int invAngle       = invAngTable[absAng];
    235   absAng             = angTable[absAng];
    236   intraPredAngle     = signAng * absAng;
     275  assert( dirMode != PLANAR_IDX ); //no planar
     276  const Bool modeDC        = dirMode==DC_IDX;
    237277
    238278  // Do the DC prediction
    239279  if (modeDC)
    240280  {
    241     Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable);
    242 
    243     for (k=0;k<blkSize;k++)
    244     {
    245       for (l=0;l<blkSize;l++)
    246       {
    247         pDst[k*dstStride+l] = dcval;
    248       }
    249     }
    250   }
    251 
    252   // Do angular predictions
    253   else
    254   {
     281    const Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height);
     282
     283    for (Int y=height;y>0;y--, pTrueDst+=dstStrideTrue)
     284    {
     285      for (Int x=0; x<width;) // width is always a multiple of 4.
     286      {
     287        pTrueDst[x++] = dcval;
     288      }
     289    }
     290  }
     291  else // Do angular predictions
     292  {
     293    const Bool       bIsModeVer         = (dirMode >= 18);
     294    const Int        intraPredAngleMode = (bIsModeVer) ? (Int)dirMode - VER_IDX :  -((Int)dirMode - HOR_IDX);
     295    const Int        absAngMode         = abs(intraPredAngleMode);
     296    const Int        signAng            = intraPredAngleMode < 0 ? -1 : 1;
     297    const Bool       edgeFilter         = bEnableEdgeFilters && isLuma(channelType) && (width <= MAXIMUM_INTRA_FILTERED_WIDTH) && (height <= MAXIMUM_INTRA_FILTERED_HEIGHT);
     298
     299    // Set bitshifts and scale the angle parameter to block size
     300    static const Int angTable[9]    = {0,    2,    5,   9,  13,  17,  21,  26,  32};
     301    static const Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
     302    Int invAngle                    = invAngTable[absAngMode];
     303    Int absAng                      = angTable[absAngMode];
     304    Int intraPredAngle              = signAng * absAng;
     305
    255306    Pel* refMain;
    256307    Pel* refSide;
     308
    257309    Pel  refAbove[2*MAX_CU_SIZE+1];
    258310    Pel  refLeft[2*MAX_CU_SIZE+1];
    259311
    260     // Initialise the Main and Left reference array.
     312    // Initialize the Main and Left reference array.
    261313    if (intraPredAngle < 0)
    262314    {
    263       for (k=0;k<blkSize+1;k++)
    264       {
    265         refAbove[k+blkSize-1] = pSrc[k-srcStride-1];
    266       }
    267       for (k=0;k<blkSize+1;k++)
    268       {
    269         refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1];
    270       }
    271       refMain = (modeVer ? refAbove : refLeft) + (blkSize-1);
    272       refSide = (modeVer ? refLeft : refAbove) + (blkSize-1);
     315      const Int refMainOffsetPreScale = (bIsModeVer ? height : width ) - 1;
     316      const Int refMainOffset         = height - 1;
     317      for (Int x=0;x<width+1;x++)
     318      {
     319        refAbove[x+refMainOffset] = pSrc[x-srcStride-1];
     320      }
     321      for (Int y=0;y<height+1;y++)
     322      {
     323        refLeft[y+refMainOffset] = pSrc[(y-1)*srcStride-1];
     324      }
     325      refMain = (bIsModeVer ? refAbove : refLeft)  + refMainOffset;
     326      refSide = (bIsModeVer ? refLeft  : refAbove) + refMainOffset;
    273327
    274328      // Extend the Main reference to the left.
    275329      Int invAngleSum    = 128;       // rounding for (shift by 8)
    276       for (k=-1; k>blkSize*intraPredAngle>>5; k--)
     330      for (Int k=-1; k>(refMainOffsetPreScale+1)*intraPredAngle>>5; k--)
    277331      {
    278332        invAngleSum += invAngle;
     
    282336    else
    283337    {
    284       for (k=0;k<2*blkSize+1;k++)
    285       {
    286         refAbove[k] = pSrc[k-srcStride-1];
    287       }
    288       for (k=0;k<2*blkSize+1;k++)
    289       {
    290         refLeft[k] = pSrc[(k-1)*srcStride-1];
    291       }
    292       refMain = modeVer ? refAbove : refLeft;
    293       refSide = modeVer ? refLeft  : refAbove;
    294     }
    295 
    296     if (intraPredAngle == 0)
    297     {
    298       for (k=0;k<blkSize;k++)
    299       {
    300         for (l=0;l<blkSize;l++)
    301         {
    302           pDst[k*dstStride+l] = refMain[l+1];
    303         }
    304       }
    305 
    306       if ( bFilter )
    307       {
    308         for (k=0;k<blkSize;k++)
    309         {
    310           pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) );
     338      for (Int x=0;x<2*width+1;x++)
     339      {
     340        refAbove[x] = pSrc[x-srcStride-1];
     341      }
     342      for (Int y=0;y<2*height+1;y++)
     343      {
     344        refLeft[y] = pSrc[(y-1)*srcStride-1];
     345      }
     346      refMain = bIsModeVer ? refAbove : refLeft ;
     347      refSide = bIsModeVer ? refLeft  : refAbove;
     348    }
     349
     350    // swap width/height if we are doing a horizontal mode:
     351    Pel tempArray[MAX_CU_SIZE*MAX_CU_SIZE];
     352    const Int dstStride = bIsModeVer ? dstStrideTrue : MAX_CU_SIZE;
     353    Pel *pDst = bIsModeVer ? pTrueDst : tempArray;
     354    if (!bIsModeVer)
     355    {
     356      std::swap(width, height);
     357    }
     358
     359    if (intraPredAngle == 0)  // pure vertical or pure horizontal
     360    {
     361      for (Int y=0;y<height;y++)
     362      {
     363        for (Int x=0;x<width;x++)
     364        {
     365          pDst[y*dstStride+x] = refMain[x+1];
     366        }
     367      }
     368
     369      if (edgeFilter)
     370      {
     371        for (Int y=0;y<height;y++)
     372        {
     373          pDst[y*dstStride] = Clip3 (0, ((1 << bitDepth) - 1), pDst[y*dstStride] + (( refSide[y+1] - refSide[0] ) >> 1) );
    311374        }
    312375      }
     
    314377    else
    315378    {
    316       Int deltaPos=0;
    317       Int deltaInt;
    318       Int deltaFract;
    319       Int refMainIndex;
    320 
    321       for (k=0;k<blkSize;k++)
    322       {
    323         deltaPos += intraPredAngle;
    324         deltaInt   = deltaPos >> 5;
    325         deltaFract = deltaPos & (32 - 1);
     379      Pel *pDsty=pDst;
     380
     381      for (Int y=0, deltaPos=intraPredAngle; y<height; y++, deltaPos+=intraPredAngle, pDsty+=dstStride)
     382      {
     383        const Int deltaInt   = deltaPos >> 5;
     384        const Int deltaFract = deltaPos & (32 - 1);
    326385
    327386        if (deltaFract)
    328387        {
    329388          // Do linear filtering
    330           for (l=0;l<blkSize;l++)
     389          const Pel *pRM=refMain+deltaInt+1;
     390          Int lastRefMainPel=*pRM++;
     391          for (Int x=0;x<width;pRM++,x++)
    331392          {
    332             refMainIndex        = l+deltaInt+1;
    333             pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 );
     393            Int thisRefMainPel=*pRM;
     394            pDsty[x+0] = (Pel) ( ((32-deltaFract)*lastRefMainPel + deltaFract*thisRefMainPel +16) >> 5 );
     395            lastRefMainPel=thisRefMainPel;
    334396          }
    335397        }
     
    337399        {
    338400          // Just copy the integer samples
    339           for (l=0;l<blkSize;l++)
     401          for (Int x=0;x<width; x++)
    340402          {
    341             pDst[k*dstStride+l] = refMain[l+deltaInt+1];
     403            pDsty[x] = refMain[x+deltaInt+1];
    342404          }
    343405        }
     
    346408
    347409    // Flip the block if this is the horizontal mode
    348     if (modeHor)
    349     {
    350       Pel  tmp;
    351       for (k=0;k<blkSize-1;k++)
    352       {
    353         for (l=k+1;l<blkSize;l++)
    354         {
    355           tmp                 = pDst[k*dstStride+l];
    356           pDst[k*dstStride+l] = pDst[l*dstStride+k];
    357           pDst[l*dstStride+k] = tmp;
    358         }
    359       }
    360     }
    361   }
    362 }
    363 
    364 Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
    365 {
    366   Pel *pDst = piPred;
    367   Int *ptrSrc;
     410    if (!bIsModeVer)
     411    {
     412      for (Int y=0; y<height; y++)
     413      {
     414        for (Int x=0; x<width; x++)
     415        {
     416          pTrueDst[x*dstStrideTrue] = pDst[x];
     417        }
     418        pTrueDst++;
     419        pDst+=dstStride;
     420      }
     421    }
     422  }
     423}
     424
     425Void TComPrediction::predIntraAng( const ComponentID compID, UInt uiDirMode, Pel* piOrg /* Will be null for decoding */, UInt uiOrgStride, Pel* piPred, UInt uiStride, TComTU &rTu, const Bool bUseFilteredPredSamples, const Bool bUseLosslessDPCM )
     426{
     427  const ChannelType    channelType = toChannelType(compID);
     428  const TComRectangle &rect        = rTu.getRect(isLuma(compID) ? COMPONENT_Y : COMPONENT_Cb);
     429  const Int            iWidth      = rect.width;
     430  const Int            iHeight     = rect.height;
    368431
    369432  assert( g_aucConvertToBit[ iWidth ] >= 0 ); //   4x  4
    370433  assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128
     434  //assert( iWidth == iHeight  );
     435
     436        Pel *pDst = piPred;
     437
     438  // get starting pixel in block
     439  const Int sw = (2 * iWidth + 1);
     440
     441  if ( bUseLosslessDPCM )
     442  {
     443    const Pel *ptrSrc = getPredictorPtr( compID, false );
     444    // Sample Adaptive intra-Prediction (SAP)
     445    if (uiDirMode==HOR_IDX)
     446    {
     447      // left column filled with reference samples
     448      // remaining columns filled with piOrg data (if available).
     449      for(Int y=0; y<iHeight; y++)
     450      {
     451        piPred[y*uiStride+0] = ptrSrc[(y+1)*sw];
     452      }
     453      if (piOrg!=0)
     454      {
     455        piPred+=1; // miss off first column
     456        for(Int y=0; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride)
     457        {
     458          memcpy(piPred, piOrg, (iWidth-1)*sizeof(Pel));
     459        }
     460      }
     461    }
     462    else // VER_IDX
     463    {
     464      // top row filled with reference samples
     465      // remaining rows filled with piOrd data (if available)
     466      for(Int x=0; x<iWidth; x++)
     467      {
     468        piPred[x] = ptrSrc[x+1];
     469      }
     470      if (piOrg!=0)
     471      {
     472        piPred+=uiStride; // miss off the first row
     473        for(Int y=1; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride)
     474        {
     475          memcpy(piPred, piOrg, iWidth*sizeof(Pel));
     476        }
     477      }
     478    }
     479  }
     480  else
     481  {
     482    const Pel *ptrSrc = getPredictorPtr( compID, bUseFilteredPredSamples );
     483
     484    if ( uiDirMode == PLANAR_IDX )
     485    {
     486      xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
     487    }
     488    else
     489    {
     490      // Create the prediction
     491            TComDataCU *const pcCU              = rTu.getCU();
     492      const UInt              uiAbsPartIdx      = rTu.GetAbsPartIdxTU();
     493      const Bool              enableEdgeFilters = !(pcCU->isRDPCMEnabled(uiAbsPartIdx) && pcCU->getCUTransquantBypass(uiAbsPartIdx));
     494#if O0043_BEST_EFFORT_DECODING
     495      const Int channelsBitDepthForPrediction = rTu.getCU()->getSlice()->getSPS()->getStreamBitDepth(channelType);
     496#else
     497      const Int channelsBitDepthForPrediction = rTu.getCU()->getSlice()->getSPS()->getBitDepth(channelType);
     498#endif
     499      xPredIntraAng( channelsBitDepthForPrediction, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, uiDirMode, enableEdgeFilters );
     500
     501      if( uiDirMode == DC_IDX )
     502      {
     503        xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType );
     504      }
     505    }
     506  }
     507
     508}
     509
     510#if NH_3D_DMM
     511Void TComPrediction::predIntraLumaDmm( TComDataCU* pcCU, UInt uiAbsPartIdx, DmmID dmmType, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight )
     512{
    371513  assert( iWidth == iHeight  );
    372 
    373   ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
    374 
    375   // get starting pixel in block
    376   Int sw = 2 * iWidth + 1;
    377 
    378   // Create the prediction
    379   if ( uiDirMode == PLANAR_IDX )
    380   {
    381     xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
    382   }
    383   else
    384   {
    385     if ( (iWidth > 16) || (iHeight > 16) )
    386     {
    387       xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
    388     }
    389     else
    390     {
    391       xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );
    392 
    393       if( (uiDirMode == DC_IDX ) && bAbove && bLeft )
    394       {
    395         xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);
    396       }
    397     }
    398   }
    399 }
    400 
    401 // Angular chroma
    402 Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
    403 {
    404   Pel *pDst = piPred;
    405   Int *ptrSrc = piSrc;
    406 
    407   // get starting pixel in block
    408   Int sw = 2 * iWidth + 1;
    409 
    410   if ( uiDirMode == PLANAR_IDX )
    411   {
    412     xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
    413   }
    414   else
    415   {
    416     // Create the prediction
    417     xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
    418   }
    419 }
    420 
    421 #if H_3D_DIM
    422 Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc, TComWedgelet* dmm4Segmentation  )
    423 {
    424   assert( iWidth == iHeight  );
    425   assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE );
    426   assert( isDimMode( uiIntraMode ) );
    427 
    428   UInt dimType    = getDimType  ( uiIntraMode );
    429   Bool isDmmMode  = (dimType <  DMM_NUM_TYPE);
    430 
    431   Bool* biSegPattern  = NULL;
    432   UInt  patternStride = 0;
    433 
    434   // get partiton
    435 #if H_3D_DIM_DMM
    436   TComWedgelet* dmmSegmentation = NULL;
    437   if( isDmmMode )
    438   {
    439     switch( dimType )
    440     {
    441     case( DMM1_IDX ):
    442       {
    443         dmmSegmentation = pcCU->isDMM1UpscaleMode((UInt)iWidth) ?
    444             &(g_dmmWedgeLists[ g_aucConvertToBit[pcCU->getDMM1BasePatternWidth((UInt)iWidth)] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]) :
    445             &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]);
    446       } break;
    447     case( DMM4_IDX ):
    448       {
    449         if( dmm4Segmentation == NULL )
    450         {
    451           dmmSegmentation = new TComWedgelet( iWidth, iHeight );
    452           xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
    453         }
    454         else
    455         {
    456           xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmm4Segmentation );
    457           dmmSegmentation = dmm4Segmentation;
    458         }
    459       } break;
    460     default: assert(0);
    461     }
    462     assert( dmmSegmentation );
    463     if( dimType == DMM1_IDX && pcCU->isDMM1UpscaleMode((UInt)iWidth) )
    464     {
    465         biSegPattern = dmmSegmentation->getScaledPattern((UInt)iWidth);
    466         patternStride = iWidth;
    467     }
    468     else
    469     {
    470         biSegPattern  = dmmSegmentation->getPattern();
    471         patternStride = dmmSegmentation->getStride ();
    472     }
    473   }
    474 #endif
     514  assert( iWidth >= DMM_MIN_SIZE && iWidth <= DMM_MAX_SIZE );
     515#if NH_3D_SDC_INTRA
     516  assert( !pcCU->getSDCFlag( uiAbsPartIdx ) );
     517#endif
     518
     519  // get partition
     520  Bool* biSegPattern  = new Bool[ (UInt)(iWidth*iHeight) ];
     521  UInt  patternStride = (UInt)iWidth;
     522  switch( dmmType )
     523  {
     524  case( DMM1_IDX ): { (getWedgeListScaled( (UInt)iWidth )->at( pcCU->getDmm1WedgeTabIdx( uiAbsPartIdx ) )).getPatternScaledCopy( (UInt)iWidth, biSegPattern ); } break;
     525  case( DMM4_IDX ): { predContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, biSegPattern );                                                                 } break;
     526  default: assert(0);
     527  }
    475528
    476529  // get predicted partition values
    477   assert( biSegPattern );
    478   Int* piMask = NULL;
    479   piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering
    480   assert( piMask );
    481   Int maskStride = 2*iWidth + 1; 
    482   Int* ptrSrc = piMask+maskStride+1;
    483   Pel predDC1 = 0; Pel predDC2 = 0;
    484   xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 );
     530  Pel predDC1 = 0, predDC2 = 0;
     531  predBiSegDCs( pcCU, uiAbsPartIdx, iWidth, iHeight, biSegPattern, patternStride, predDC1, predDC2 );
    485532
    486533  // set segment values with deltaDC offsets
    487   Pel segDC1 = 0;
    488   Pel segDC2 = 0;
    489   if( !pcCU->getSDCFlag( uiAbsPartIdx ) )
    490   {
    491     Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx );
    492     Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx );
    493 #if H_3D_DIM_DMM
    494     if( isDmmMode )
    495     {
    496 #if H_3D_DIM_DLT
    497       segDC1 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 );
    498       segDC2 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 );
     534  Pel segDC1 = 0, segDC2 = 0;
     535  Pel deltaDC1 = pcCU->getDmmDeltaDC( dmmType, 0, uiAbsPartIdx );
     536  Pel deltaDC2 = pcCU->getDmmDeltaDC( dmmType, 1, uiAbsPartIdx );
     537#if NH_3D_DLT
     538  segDC1 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 );
     539  segDC2 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 );
    499540#else
    500       segDC1 = ClipY( predDC1 + deltaDC1 );
    501       segDC2 = ClipY( predDC2 + deltaDC2 );
    502 #endif
    503     }
    504 #endif
    505   }
    506   else
    507   {
    508     segDC1 = predDC1;
    509     segDC2 = predDC2;
    510   }
     541  segDC1 = ClipBD( predDC1 + deltaDC1, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) );
     542  segDC2 = ClipBD( predDC2 + deltaDC2, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) );
     543#endif
    511544
    512545  // set prediction signal
    513546  Pel* pDst = piPred;
    514   xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 );
    515   pcCU->setDmmPredictor(segDC1, 0);
    516   pcCU->setDmmPredictor(segDC2, 1);
    517 
    518 #if H_3D_DIM_DMM
    519   if( dimType == DMM4_IDX && dmm4Segmentation == NULL )
    520   {
    521     dmmSegmentation->destroy();
    522     delete dmmSegmentation;
    523   }
    524 #endif
    525 }
    526 #endif
    527 
    528 /** Function for checking identical motion.
    529  * \param TComDataCU* pcCU
    530  * \param UInt PartAddr
     547  assignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 );
     548 
     549  delete[] biSegPattern;
     550}
     551#endif
     552
     553/** Check for identical motion in both motion vector direction of a bi-directional predicted CU
     554  * \returns true, if motion vectors and reference pictures match
    531555 */
    532556Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr )
     
    538562      Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
    539563      Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
    540 #if H_3D_ARP
     564#if NH_3D_ARP
    541565      if(!pcCU->getARPW(PartAddr) && RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
    542566#else
     
    551575}
    552576
    553 #if H_3D_SPIVMP
     577#if NH_3D_SPIVMP
    554578Void TComPrediction::xGetSubPUAddrAndMerge(TComDataCU* pcCU, UInt uiPartAddr, Int iSPWidth, Int iSPHeight, Int iNumSPInOneLine, Int iNumSP, UInt* uiMergedSPW, UInt* uiMergedSPH, UInt* uiSPAddr )
    555579{
     
    560584    pcCU->getSPAbsPartIdx(uiPartAddr, iSPWidth, iSPHeight, i, iNumSPInOneLine, uiSPAddr[i]);
    561585  }
     586#if H_3D_ARP || NH_3D_ALIGN_SPIVMP_RP // check this!
    562587  if( pcCU->getARPW( uiPartAddr ) != 0 )
    563588  {
    564589    return;
    565590  }
     591#endif
    566592
    567593  // horizontal sub-PU merge
     
    637663#endif
    638664
    639 #if H_3D_DBBP
     665#if NH_3D_DBBP
    640666PartSize TComPrediction::getPartitionSizeFromDepth(Pel* pDepthPels, UInt uiDepthStride, UInt uiSize, TComDataCU*& pcCU)
    641667{
     668  const TComSPS* sps = pcCU->getSlice()->getSPS();
     669  UInt uiMaxCUWidth = sps->getMaxCUWidth();
     670  UInt uiMaxCUHeight = sps->getMaxCUHeight();
     671 
    642672  // find virtual partitioning for this CU based on depth block
    643673  // segmentation of texture block --> mask IDs
     
    647677  Int iSumDepth = 0;
    648678  Int iSubSample = 4;
    649   Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth();
    650   Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight();
     679  Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth(COMPONENT_Y);
     680  Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight(COMPONENT_Y);
    651681  TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag(  ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV;
    652682  if( pcCU->getSlice()->getDepthRefinementFlag(  ) )
     
    654684    cDv.setVer(0);
    655685  }
    656   Int iBlkX = ( pcCU->getAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getHor()+2)>>2);
    657   Int iBlkY = ( pcCU->getAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getVer()+2)>>2);
     686  Int iBlkX = ( pcCU->getCtuRsAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCtus() ) * uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCtu() ] ]+ ((cDv.getHor()+2)>>2);
     687  Int iBlkY = ( pcCU->getCtuRsAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCtus() ) * uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCtu() ] ]+ ((cDv.getVer()+2)>>2);
    658688 
    659689  UInt t=0;
     
    742772  }
    743773
    744   PartSize matchedPartSize = SIZE_NONE;
     774  PartSize matchedPartSize = NUMBER_OF_PART_SIZES;
    745775
    746776  Int iMaxMatchSum = 0;
     
    757787  }
    758788
    759   AOF( matchedPartSize != SIZE_NONE );
     789  AOF( matchedPartSize != NUMBER_OF_PART_SIZES );
    760790
    761791  return matchedPartSize;
     
    764794Bool TComPrediction::getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask, TComDataCU*& pcCU)
    765795{
     796  const TComSPS* sps = pcCU->getSlice()->getSPS();
     797  UInt uiMaxCUWidth = sps->getMaxCUWidth();
     798  UInt uiMaxCUHeight = sps->getMaxCUHeight();
     799 
    766800  // segmentation of texture block --> mask IDs
    767801  Pel*  pDepthBlockStart      = pDepthPels;
     
    775809  iSumDepth  = pDepthPels[ 0 ];
    776810 
    777   Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth();
    778   Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight(); 
     811  Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth(COMPONENT_Y);
     812  Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight(COMPONENT_Y); 
    779813  TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag(  ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV;
    780814  if( pcCU->getSlice()->getDepthRefinementFlag(  ) )
     
    782816    cDv.setVer(0);
    783817  }
    784   Int iBlkX = ( pcCU->getAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getHor()+2)>>2);
    785   Int iBlkY = ( pcCU->getAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getVer()+2)>>2);
     818  Int iBlkX = ( pcCU->getCtuRsAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCtus() ) * uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCtu() ] ]+ ((cDv.getHor()+2)>>2);
     819  Int iBlkY = ( pcCU->getCtuRsAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCtus() ) * uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCtu() ] ]+ ((cDv.getVer()+2)>>2);
    786820  if (iBlkX>(Int)(iPictureWidth - uiWidth))
    787821  {
     
    898932}
    899933
    900 Void TComPrediction::combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr, UInt partSize )
    901 {
    902   Pel*  piSrc[2]    = {pInYuv[0]->getLumaAddr(uiPartAddr), pInYuv[1]->getLumaAddr(uiPartAddr)};
    903   UInt  uiSrcStride = pInYuv[0]->getStride();
    904   Pel*  piDst       = pOutYuv->getLumaAddr(uiPartAddr);
    905   UInt  uiDstStride = pOutYuv->getStride();
     934Void TComPrediction::combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr, UInt partSize, Int bitDepthY )
     935{
     936  Pel*  piSrc[2]    = {pInYuv[0]->getAddr(COMPONENT_Y, uiPartAddr), pInYuv[1]->getAddr(COMPONENT_Y, uiPartAddr)};
     937  UInt  uiSrcStride = pInYuv[0]->getStride(COMPONENT_Y);
     938  Pel*  piDst       = pOutYuv->getAddr(COMPONENT_Y, uiPartAddr);
     939  UInt  uiDstStride = pOutYuv->getStride(COMPONENT_Y);
    906940 
    907941  UInt  uiMaskStride= MAX_CU_SIZE;
     
    942976        right  = (x==uiWidth-1)  ? tmpTar[y*uiWidth+x] : tmpTar[y*uiWidth+x+1];
    943977       
    944         piDst[x] = (l!=r) ? ClipY( Pel(( left + (tmpTar[y*uiWidth+x] << 1) + right ) >> 2 )) : tmpTar[y*uiWidth+x];
     978        piDst[x] = (l!=r) ? ClipBD( Pel(( left + (tmpTar[y*uiWidth+x] << 1) + right ) >> 2 ), bitDepthY) : tmpTar[y*uiWidth+x];
    945979      }
    946980      piDst     += uiDstStride;
     
    960994        bottom = (y==uiHeight-1) ? tmpTar[y*uiWidth+x] : tmpTar[(y+1)*uiWidth+x];
    961995       
    962         piDst[x] = (t!=b) ? ClipY( Pel(( top + (tmpTar[y*uiWidth+x] << 1) + bottom ) >> 2 )) : tmpTar[y*uiWidth+x];
     996        piDst[x] = (t!=b) ? ClipBD( Pel(( top + (tmpTar[y*uiWidth+x] << 1) + bottom ) >> 2 ), bitDepthY) : tmpTar[y*uiWidth+x];
    963997      }
    964998      piDst     += uiDstStride;
     
    9731007 
    9741008  // now combine chroma
    975   Pel*  piSrcU[2]       = { pInYuv[0]->getCbAddr(uiPartAddr), pInYuv[1]->getCbAddr(uiPartAddr) };
    976   Pel*  piSrcV[2]       = { pInYuv[0]->getCrAddr(uiPartAddr), pInYuv[1]->getCrAddr(uiPartAddr) };
    977   UInt  uiSrcStrideC    = pInYuv[0]->getCStride();
    978   Pel*  piDstU          = pOutYuv->getCbAddr(uiPartAddr);
    979   Pel*  piDstV          = pOutYuv->getCrAddr(uiPartAddr);
    980   UInt  uiDstStrideC    = pOutYuv->getCStride();
     1009  Pel*  piSrcU[2]       = { pInYuv[0]->getAddr(COMPONENT_Cb, uiPartAddr), pInYuv[1]->getAddr(COMPONENT_Cb, uiPartAddr) };
     1010  Pel*  piSrcV[2]       = { pInYuv[0]->getAddr(COMPONENT_Cr, uiPartAddr), pInYuv[1]->getAddr(COMPONENT_Cr, uiPartAddr) };
     1011  UInt  uiSrcStrideC    = pInYuv[0]->getStride(COMPONENT_Cb);
     1012  Pel*  piDstU          = pOutYuv->getAddr(COMPONENT_Cb, uiPartAddr);
     1013  Pel*  piDstV          = pOutYuv->getAddr(COMPONENT_Cr, uiPartAddr);
     1014  UInt  uiDstStrideC    = pOutYuv->getStride(COMPONENT_Cb);
    9811015  UInt  uiWidthC        = uiWidth >> 1;
    9821016  UInt  uiHeightC       = uiHeight >> 1;
     
    10241058        if (l!=r)
    10251059        {
    1026           filSrcU = ClipC( Pel(( leftU + (tmpTarU[y*uiWidthC+x] << 1) + rightU ) >> 2 ));
    1027           filSrcV = ClipC( Pel(( leftV + (tmpTarV[y*uiWidthC+x] << 1) + rightV ) >> 2 ));
     1060          filSrcU = ClipBD( Pel(( leftU + (tmpTarU[y*uiWidthC+x] << 1) + rightU ) >> 2 ), bitDepthY);
     1061          filSrcV = ClipBD( Pel(( leftV + (tmpTarV[y*uiWidthC+x] << 1) + rightV ) >> 2 ), bitDepthY);
    10281062        }
    10291063        else
     
    10571091        if (t!=b)
    10581092        {
    1059           filSrcU = ClipC( Pel(( topU + (tmpTarU[y*uiWidthC+x] << 1) + bottomU ) >> 2 ));
    1060           filSrcV = ClipC( Pel(( topV + (tmpTarV[y*uiWidthC+x] << 1) + bottomV ) >> 2 ));
     1093          filSrcU = ClipBD( Pel(( topU + (tmpTarU[y*uiWidthC+x] << 1) + bottomU ) >> 2 ), bitDepthY);
     1094          filSrcV = ClipBD( Pel(( topV + (tmpTarV[y*uiWidthC+x] << 1) + bottomV ) >> 2 ), bitDepthY);
    10611095        }
    10621096        else
     
    10951129  {
    10961130    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
    1097 #if H_3D_VSP
     1131#if NH_3D_VSP
    10981132    if ( pcCU->getVSPFlag(uiPartAddr) == 0)
    10991133    {
     
    11161150      else
    11171151      {
    1118 #if H_3D_SPIVMP
     1152#if NH_3D_SPIVMP
    11191153        if ( pcCU->getSPIVMPFlag(uiPartAddr)!=0) 
    11201154        {
     
    11561190            xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
    11571191          }
    1158 #if H_3D_SPIVMP
    1159         }
    1160 #endif
    1161       }
    1162 #if H_3D_VSP
     1192#if NH_3D_SPIVMP
     1193        }
     1194#endif
     1195      }
     1196#if NH_3D_VSP
    11631197    }
    11641198    else
     
    11811215    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
    11821216
    1183 #if H_3D_VSP
     1217#if NH_3D_VSP
    11841218    if ( pcCU->getVSPFlag(uiPartAddr) == 0 )
    11851219    {
    11861220#endif
    1187       if ( eRefPicList != REF_PIC_LIST_X )
    1188       {
    1189         if( pcCU->getSlice()->getPPS()->getUseWP())
    1190         {
    1191           xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
    1192         }
    1193         else
    1194         {
    1195           xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
    1196         }
    1197         if ( pcCU->getSlice()->getPPS()->getUseWP() )
    1198         {
    1199           xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
    1200         }
     1221    if ( eRefPicList != REF_PIC_LIST_X )
     1222    {
     1223      if( pcCU->getSlice()->getPPS()->getUseWP())
     1224      {
     1225        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
    12011226      }
    12021227      else
    12031228      {
    1204 #if H_3D_SPIVMP
    1205        if (pcCU->getSPIVMPFlag(uiPartAddr)!=0) 
     1229        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
     1230      }
     1231      if ( pcCU->getSlice()->getPPS()->getUseWP() )
     1232      {
     1233        xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
     1234      }
     1235    }
     1236    else
     1237    {
     1238#if NH_3D_SPIVMP
     1239      if (pcCU->getSPIVMPFlag(uiPartAddr)!=0) 
    12061240      {
    12071241        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
     
    12411275          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
    12421276        }
    1243 #if H_3D_SPIVMP
    1244        }
    1245 #endif
    1246       }
    1247 #if H_3D_VSP
     1277#if NH_3D_SPIVMP
     1278      }
     1279#endif
     1280    }
     1281#if NH_3D_VSP
    12481282    }
    12491283    else
     
    12631297}
    12641298
    1265 Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
     1299Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv* pcYuvPred, Bool bi )
    12661300{
    12671301  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
    12681302  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
    12691303  pcCU->clipMv(cMv);
    1270 #if H_MV
     1304#if NH_MV
    12711305  pcCU->checkMvVertRest(cMv, eRefPicList, iRefIdx );
    12721306#endif
    1273 #if H_3D_ARP
    1274   if(pcCU->getARPW( uiPartAddr ) > 0  && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC())
    1275   {
    1276     xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , rpcYuvPred , bi );
     1307#if NH_3D_ARP
     1308  if(  pcCU->getARPW( uiPartAddr ) > 0 )
     1309  {
     1310    if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC() )
     1311  {
     1312      xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , pcYuvPred , bi );
    12771313  }
    12781314  else
    12791315  {
    1280     if(  pcCU->getARPW( uiPartAddr ) > 0
    1281       && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N
    1282       && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC()
    1283       )
    1284     {
    1285       xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi );
     1316      xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, bi );
     1317    }     
    12861318    }
    12871319    else
    12881320    {
    12891321#endif
    1290 #if H_3D_IC
    1291       Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() );
    1292       xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
    1293 #if H_3D_ARP
    1294         , false
    1295 #endif
    1296         , bICFlag );
    1297       bICFlag = bICFlag && (iWidth > 8);
    1298       xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
    1299 #if H_3D_ARP
     1322  for (UInt comp=COMPONENT_Y; comp<pcYuvPred->getNumberValidComponents(); comp++)
     1323  {
     1324    const ComponentID compID=ComponentID(comp);
     1325#if NH_3D_IC
     1326    Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() ) && ( isLuma(compID) || (iWidth > 8) );
     1327      xPredInterBlk(compID,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID))
     1328#if NH_3D_ARP
    13001329        , false
    13011330#endif
    13021331        , bICFlag );
    13031332#else
    1304       xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
    1305       xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
    1306 #endif
    1307 #if H_3D_ARP
    1308     }
    1309   }
    1310 #endif
    1311 }
    1312 
    1313 #if H_3D_VSP
     1333    xPredInterBlk  (compID,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)) );
     1334#endif
     1335  }
     1336#if NH_3D_ARP
     1337  }
     1338#endif
     1339}
     1340
     1341#if NH_3D_VSP
    13141342Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
    13151343{
     
    13321360Void TComPrediction::xPredInterUniSubPU( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, Int widthSubPU, Int heightSubPU )
    13331361{
    1334   UInt numPartsInLine       = pcCU->getPic()->getNumPartInWidth();
     1362  UInt numPartsInLine       = pcCU->getPic()->getNumPartInCtuWidth();
    13351363  UInt horiNumPartsInSubPU  = widthSubPU >> 2;
    13361364  UInt vertNumPartsInSubPU  = (heightSubPU >> 2) * numPartsInLine;
     
    13481376      pcCU->clipMv(cMv);
    13491377
    1350       xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi );
    1351       xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi );
    1352 
    1353     }
    1354   }
    1355 }
    1356 
    1357 #endif
    1358 
    1359 #if H_3D_ARP
    1360 Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
    1361 {
    1362   Int         iRefIdx      = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
    1363   TComMv      cMv          = pNewMvFiled ? pNewMvFiled->getMv()     : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
     1378      xPredInterBlk( COMPONENT_Y,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) );
     1379      xPredInterBlk( COMPONENT_Cb, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA) );
     1380      xPredInterBlk( COMPONENT_Cr, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA) );
     1381    }
     1382  }
     1383}
     1384#endif
     1385
     1386#if NH_3D_ARP
     1387//temporal ARP
     1388Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
     1389{
     1390  Int         iRefIdx      = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
     1391  TComMv      cMv          = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
    13641392  Bool        bTobeScaled  = false;
    13651393  TComPic* pcPicYuvBaseCol = NULL;
    13661394  TComPic* pcPicYuvBaseRef = NULL;
    13671395
    1368 #if H_3D_NBDV
     1396#if NH_3D_NBDV
    13691397  DisInfo cDistparity;
    13701398  cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV;
     
    13751403  UChar dW = pcCU->getARPW ( uiPartAddr );
    13761404
    1377   {
    13781405    Int arpRefIdx = pcCU->getSlice()->getFirstTRefIdx(eRefPicList);
    1379     if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() )
    1380     {
    1381       bTobeScaled = true;
    1382     }
    1383 
    1384     pcPicYuvBaseCol =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(),                              cDistparity.m_aVIdxCan );
    1385 
    1386     pcPicYuvBaseRef =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC(), cDistparity.m_aVIdxCan );
    1387 
    1388     if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, cDistparity.m_aVIdxCan))
     1406  if (arpRefIdx < 0 || !pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, cDistparity.m_aVIdxCan))
    13891407    {
    13901408      dW = 0;
     
    13931411    else
    13941412    {
    1395       assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC() );
     1413    if( arpRefIdx != iRefIdx )
     1414    {
     1415      bTobeScaled = true;
     1416    }
     1417    pcPicYuvBaseCol =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(),                              cDistparity.m_aVIdxCan );
     1418    pcPicYuvBaseRef =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC(), cDistparity.m_aVIdxCan );
    13961419    }
    13971420
     
    14001423      Int iCurrPOC    = pcCU->getSlice()->getPOC();
    14011424      Int iColRefPOC  = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx );
    1402       Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList,  0);
     1425    Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, arpRefIdx );
    14031426      Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC);
    14041427      if ( iScale != 4096 )
     
    14061429        cMv = cMv.scaleMv( iScale );
    14071430      }
    1408       iRefIdx = 0;
    1409     }
     1431    iRefIdx = arpRefIdx;
    14101432  }
    14111433
    14121434  pcCU->clipMv(cMv);
    14131435  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec();
    1414   xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 ), true );
    1415   xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 ), true );
     1436
     1437  for (UInt comp=COMPONENT_Y; comp< rpcYuvPred->getNumberValidComponents(); comp++)
     1438  {
     1439    const ComponentID compID=ComponentID(comp);
     1440    xPredInterBlk  ( compID,  pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 ), pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true );
     1441  }
    14161442
    14171443  if( dW > 0 )
     
    14291455    pcCU->clipMv( cNBDV );
    14301456   
    1431     pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec();
    1432     xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, true, true );
    1433     if (iWidth > 8)
    1434       xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, true, true );
     1457    TComPicYuv* pcPicYuvBaseColRec = pcPicYuvBaseCol->getPicYuvRec();
     1458    TComPicYuv* pcPicYuvBaseRefRec = pcPicYuvBaseRef->getPicYuvRec();
    14351459   
    1436     pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec();
    1437     xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, true, true );
    1438  
    1439     if (iWidth > 8)
    1440       xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, true, true );
     1460    UInt uiCompNum = ( iWidth > 8 ) ? 3: 1;
     1461    for (UInt comp=COMPONENT_Y; comp< uiCompNum; comp++)
     1462    {
     1463      const ComponentID compID=ComponentID(comp);
     1464      xPredInterBlk  ( compID,  pcCU, pcPicYuvBaseColRec, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, true, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true );
     1465      xPredInterBlk  ( compID,  pcCU, pcPicYuvBaseRefRec, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, true, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true );
     1466    }   
    14411467   
    14421468    pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight );
     
    14461472      pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
    14471473    }
    1448     rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi );
     1474    rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi, pcCU->getSlice()->getSPS()->getBitDepths() );
    14491475  }
    14501476}
     
    14551481  TComMv      cDMv          = pcCU->getCUMvField( eBaseRefPicList )->getMv( uiPartAddr );
    14561482  TComPic* pcPicYuvBaseCol  = pcCU->getSlice()->getRefPic( eBaseRefPicList, iRefIdx ); 
    1457   TComPicYuv* pcYuvBaseCol  = pcPicYuvBaseCol->getPicYuvRec();
    1458   Int uiLCUAddr,uiAbsPartAddr;
    14591483  Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2  + ((cDMv.getHor() + 2)>>2);
    14601484  Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2);
     
    14621486  irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX);
    14631487  irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); 
    1464   pcYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr);
    1465   TComDataCU *pColCU = pcPicYuvBaseCol->getCU( uiLCUAddr );
     1488
     1489  Int uiLCUAddr,uiAbsPartAddr;
     1490  pcPicYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr);
     1491  TComDataCU *pColCU = pcPicYuvBaseCol->getCtu( uiLCUAddr );
    14661492
    14671493  TComPic* pcPicYuvBaseTRef = NULL;
     
    15151541}
    15161542
    1517 Void TComPrediction::xPredInterUniARPviewRef( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
     1543//inter-view ARP
     1544Void TComPrediction::xPredInterUniARPviewRef( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
    15181545{
    15191546  Int         iRefIdx       = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
     
    15281555  Bool bTMVAvai = false;     
    15291556  TComMv cBaseTMV;
    1530   if( pNewMvFiled )
    1531   {
    1532     iRefIdx = pNewMvFiled->getRefIdx();
    1533     cDMv = pNewMvFiled->getMv();
    1534   }
     1557
    15351558  pcCU->clipMv(cTempDMv);
    15361559
    1537   assert(dW > 0);
    1538   if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, pcPicYuvBaseCol->getViewIndex()))
    1539   {
    1540     dW = 0;
    1541   }
    1542   Int uiLCUAddr,uiAbsPartAddr;
    15431560  Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2  + ((cDMv.getHor() + 2)>>2);
    15441561  Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2);
     
    15461563  irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX);
    15471564  irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); 
    1548   pcYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr);
    1549   TComDataCU *pColCU = pcPicYuvBaseCol->getCU( uiLCUAddr );
     1565 
     1566  Int uiLCUAddr,uiAbsPartAddr;
     1567  pcPicYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr);
     1568  TComDataCU *pColCU = pcPicYuvBaseCol->getCtu( uiLCUAddr );
    15501569  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getIsDepth() )
    15511570  {
     
    16181637      RefPicList eRefPicListCurr = RefPicList(iList);
    16191638      Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr);
    1620       if( iRef != -1)
     1639      if( iRef != -1 && pcCU->getSlice()->getArpRefPicAvailable( eRefPicListCurr, pcPicYuvBaseCol->getViewIndex()))
    16211640      {
    16221641        pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); 
     
    16521671  }
    16531672
    1654   xPredInterLumaBlk  ( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 && bTMVAvai ),        bTMVAvai);
    1655   xPredInterChromaBlk( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 && bTMVAvai ),        bTMVAvai);
    1656 
    1657   if( dW > 0 && bTMVAvai )
    1658   {
     1673  for (UInt comp=COMPONENT_Y; comp< rpcYuvPred->getNumberValidComponents(); comp++)
     1674  {
     1675    const ComponentID compID=ComponentID(comp);
     1676    xPredInterBlk  ( compID,  pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 && bTMVAvai ), pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), bTMVAvai );
     1677  }
     1678
     1679  if( dW > 0 )
     1680  {
     1681    assert ( bTMVAvai );
    16591682    TComYuv*    pYuvCurrTRef    = &m_acYuvPredBase[0];
    16601683    TComYuv*    pYuvBaseTRef    = &m_acYuvPredBase[1];
     
    16701693      pYuvCurrTRef->clear(); pYuvBaseTRef->clear();
    16711694    }
    1672     xPredInterLumaBlk  ( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, true,   true);
    1673 
    1674     if (iWidth > 8)
    1675       xPredInterChromaBlk( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, true,   true);
    1676 
    1677     xPredInterLumaBlk  ( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, true,   true);
    1678 
    1679     if (iWidth > 8)
    1680       xPredInterChromaBlk( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, true,   true);
     1695
     1696    UInt uiCompNum = ( iWidth > 8 ) ? 3: 1;
     1697    for (UInt comp=COMPONENT_Y; comp< uiCompNum; comp++)
     1698    {
     1699      const ComponentID compID=ComponentID(comp);
     1700      xPredInterBlk  ( compID,  pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, true, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true );
     1701      xPredInterBlk  ( compID,  pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv, iWidth, iHeight, pYuvBaseTRef, true, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true );
     1702    }
    16811703
    16821704    pYuvCurrTRef->subtractARP( pYuvCurrTRef , pYuvBaseTRef , uiPartAddr , iWidth , iHeight ); 
     
    16851707      pYuvCurrTRef->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
    16861708    }
    1687     rpcYuvPred->addARP( rpcYuvPred , pYuvCurrTRef , uiPartAddr , iWidth , iHeight , !bi );
    1688   }
    1689 }
    1690 #endif
    1691 
    1692 Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
     1709    rpcYuvPred->addARP( rpcYuvPred , pYuvCurrTRef , uiPartAddr , iWidth , iHeight , !bi, pcCU->getSlice()->getSPS()->getBitDepths() );
     1710  }
     1711}
     1712#endif
     1713
     1714Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv* pcYuvPred )
    16931715{
    16941716  TComYuv* pcMbYuv;
    1695   Int      iRefIdx[2] = {-1, -1};
    1696 
    1697   for ( Int iRefList = 0; iRefList < 2; iRefList++ )
    1698   {
    1699     RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
    1700     iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
    1701 
    1702     if ( iRefIdx[iRefList] < 0 )
     1717  Int      iRefIdx[NUM_REF_PIC_LIST_01] = {-1, -1};
     1718
     1719  for ( UInt refList = 0; refList < NUM_REF_PIC_LIST_01; refList++ )
     1720  {
     1721    RefPicList eRefPicList = (refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
     1722    iRefIdx[refList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
     1723
     1724    if ( iRefIdx[refList] < 0 )
    17031725    {
    17041726      continue;
    17051727    }
    17061728
    1707     assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
    1708 
    1709     pcMbYuv = &m_acYuvPred[iRefList];
     1729    assert( iRefIdx[refList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
     1730
     1731    pcMbYuv = &m_acYuvPred[refList];
    17101732    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
    17111733    {
     
    17141736    else
    17151737    {
    1716       if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) || 
    1717            ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
     1738      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) ||
     1739           ( pcCU->getSlice()->getPPS()->getWPBiPred()    && pcCU->getSlice()->getSliceType() == B_SLICE ) )
    17181740      {
    17191741        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
     
    17261748  }
    17271749
    1728   if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE  )
    1729   {
    1730     xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
    1731   } 
     1750  if ( pcCU->getSlice()->getPPS()->getWPBiPred()    && pcCU->getSlice()->getSliceType() == B_SLICE  )
     1751  {
     1752    xWeightedPredictionBi( pcCU, &m_acYuvPred[REF_PIC_LIST_0], &m_acYuvPred[REF_PIC_LIST_1], iRefIdx[REF_PIC_LIST_0], iRefIdx[REF_PIC_LIST_1], uiPartAddr, iWidth, iHeight, pcYuvPred );
     1753  }
    17321754  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
    17331755  {
    1734     xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred );
     1756    xWeightedPredictionUni( pcCU, &m_acYuvPred[REF_PIC_LIST_0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
    17351757  }
    17361758  else
    17371759  {
    1738     xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
    1739   }
    1740 }
    1741 
    1742 #if H_3D_VSP
    1743 
     1760    xWeightedAverage( &m_acYuvPred[REF_PIC_LIST_0], &m_acYuvPred[REF_PIC_LIST_1], iRefIdx[REF_PIC_LIST_0], iRefIdx[REF_PIC_LIST_1], uiPartAddr, iWidth, iHeight, pcYuvPred, pcCU->getSlice()->getSPS()->getBitDepths() );
     1761  }
     1762}
     1763
     1764#if NH_3D_VSP
    17441765Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
    17451766{
     
    17631784  }
    17641785
    1765   xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
    1766 }
    1767 
     1786  xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred, pcCU->getSlice()->getSPS()->getBitDepths() );
     1787}
    17681788#endif
    17691789
    17701790/**
    1771  * \brief Generate motion-compensated luma block
     1791 * \brief Generate motion-compensated block
    17721792 *
    1773  * \param cu       Pointer to current CU
    1774  * \param refPic   Pointer to reference picture
    1775  * \param partAddr Address of block within CU
    1776  * \param mv       Motion vector
    1777  * \param width    Width of block
    1778  * \param height   Height of block
    1779  * \param dstPic   Pointer to destination picture
    1780  * \param bi       Flag indicating whether bipred is used
     1793 * \param compID     Colour component ID
     1794 * \param cu         Pointer to current CU
     1795 * \param refPic     Pointer to reference picture
     1796 * \param partAddr   Address of block within CU
     1797 * \param mv         Motion vector
     1798 * \param width      Width of block
     1799 * \param height     Height of block
     1800 * \param dstPic     Pointer to destination picture
     1801 * \param bi         Flag indicating whether bipred is used
     1802 * \param  bitDepth  Bit depth
    17811803 */
    1782 Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
    1783 #if H_3D_ARP
     1804
     1805
     1806Void TComPrediction::xPredInterBlk(const ComponentID compID, TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *dstPic, Bool bi, const Int bitDepth
     1807#if NH_3D_ARP
    17841808    , Bool filterType
    17851809#endif
    1786 #if H_3D_IC
     1810#if NH_3D_IC
    17871811    , Bool bICFlag
    17881812#endif
    1789   )
    1790 {
    1791   Int refStride = refPic->getStride(); 
    1792   Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride;
    1793   Pel *ref      = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
    1794  
    1795   Int dstStride = dstPic->getStride();
    1796   Pel *dst      = dstPic->getLumaAddr( partAddr );
    1797  
    1798   Int xFrac = mv->getHor() & 0x3;
    1799   Int yFrac = mv->getVer() & 0x3;
    1800 
    1801 #if H_3D_IC
     1813)
     1814{
     1815  Int     refStride  = refPic->getStride(compID);
     1816  Int     dstStride  = dstPic->getStride(compID);
     1817  Int shiftHor=(2+refPic->getComponentScaleX(compID));
     1818  Int shiftVer=(2+refPic->getComponentScaleY(compID));
     1819
     1820  Int     refOffset  = (mv->getHor() >> shiftHor) + (mv->getVer() >> shiftVer) * refStride;
     1821
     1822  Pel*    ref     = refPic->getAddr(compID, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refOffset;
     1823
     1824  Pel*    dst = dstPic->getAddr( compID, partAddr );
     1825
     1826  Int     xFrac  = mv->getHor() & ((1<<shiftHor)-1);
     1827  Int     yFrac  = mv->getVer() & ((1<<shiftVer)-1);
     1828
     1829#if NH_3D_INTEGER_MV_DEPTH
    18021830  if( cu->getSlice()->getIsDepth() )
    18031831  {
    18041832    refOffset = mv->getHor() + mv->getVer() * refStride;
    1805     ref       = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
     1833    ref       = refPic->getAddr(compID, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refOffset;
    18061834    xFrac     = 0;
    18071835    yFrac     = 0;
    18081836  }
    18091837#endif
     1838
     1839  UInt    cxWidth  = width  >> refPic->getComponentScaleX(compID);
     1840  UInt    cxHeight = height >> refPic->getComponentScaleY(compID);
     1841
     1842  const ChromaFormat chFmt = cu->getPic()->getChromaFormat();
     1843
    18101844  if ( yFrac == 0 )
    18111845  {
    1812 #if H_3D_IC
    1813     m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi || bICFlag
     1846#if NH_3D_IC
     1847    m_if.filterHor(compID, ref, refStride, dst,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag, chFmt, bitDepth
    18141848#else
    1815     m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi
    1816 #endif
    1817 #if H_3D_ARP
    1818     , filterType
    1819 #endif
    1820       );
    1821   }
    1822   else if ( xFrac == 0 )
    1823   {
    1824 #if H_3D_IC
    1825     m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag
    1826 #else
    1827     m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi
    1828 #endif
    1829 #if H_3D_ARP
    1830     , filterType
    1831 #endif
    1832       );
    1833   }
    1834   else
    1835   {
    1836     Int tmpStride = m_filteredBlockTmp[0].getStride();
    1837     Short *tmp    = m_filteredBlockTmp[0].getLumaAddr();
    1838 
    1839     Int filterSize = NTAPS_LUMA;
    1840     Int halfFilterSize = ( filterSize >> 1 );
    1841 
    1842     m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     
    1843 #if H_3D_ARP
     1849    m_if.filterHor(compID, ref, refStride, dst,  dstStride, cxWidth, cxHeight, xFrac, !bi, chFmt, bitDepth
     1850#endif
     1851#if NH_3D_ARP
    18441852    , filterType
    18451853#endif
    1846       );
    1847 #if H_3D_IC
    1848     m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi || bICFlag
     1854);
     1855  }
     1856  else if ( xFrac == 0 )
     1857  {
     1858#if NH_3D_IC
     1859    m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag, chFmt, bitDepth
    18491860#else
    1850     m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi
    1851 #endif
    1852 #if H_3D_ARP
     1861    m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi, chFmt, bitDepth
     1862#endif
     1863#if NH_3D_ARP
     1864    , filterType
     1865#endif
     1866);
     1867  }
     1868  else
     1869  {
     1870    Int   tmpStride = m_filteredBlockTmp[0].getStride(compID);
     1871    Pel*  tmp       = m_filteredBlockTmp[0].getAddr(compID);
     1872
     1873    const Int vFilterSize = isLuma(compID) ? NTAPS_LUMA : NTAPS_CHROMA;
     1874
     1875    m_if.filterHor(compID, ref - ((vFilterSize>>1) -1)*refStride, refStride, tmp, tmpStride, cxWidth, cxHeight+vFilterSize-1, xFrac, false,      chFmt, bitDepth
     1876#if NH_3D_ARP
    18531877    , filterType
    18541878#endif
    1855       );   
    1856   }
    1857 
    1858 #if H_3D_IC
     1879);
     1880#if NH_3D_IC
     1881    m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight,               yFrac, false, !bi || bICFlag, chFmt, bitDepth
     1882#else
     1883    m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight,               yFrac, false, !bi, chFmt, bitDepth
     1884#endif
     1885#if NH_3D_ARP
     1886    , filterType
     1887#endif
     1888);
     1889  }
     1890
     1891#if NH_3D_IC
    18591892  if( bICFlag )
    18601893  {
    18611894    Int a, b, i, j;
    18621895    const Int iShift = IC_CONST_SHIFT;
    1863 
    1864     xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA );
    1865 
    1866 
    1867     for ( i = 0; i < height; i++ )
    1868     {
    1869       for ( j = 0; j < width; j++ )
    1870       {
    1871           dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
     1896    Pel *dst2 = dst;
     1897
     1898    xGetLLSICPrediction( compID, cu, mv, refPic, a, b, bitDepth );
     1899
     1900    for ( i = 0; i < cxHeight; i++ )
     1901    {
     1902      for ( j = 0; j < cxWidth; j++ )
     1903      {
     1904        dst[j] = Clip3( 0, ( 1 << bitDepth ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
    18721905      }
    18731906      dst += dstStride;
     
    18761909    if(bi)
    18771910    {
    1878       Pel *dst2      = dstPic->getLumaAddr( partAddr );
    1879       Int shift = IF_INTERNAL_PREC - g_bitDepthY;
    1880       for (i = 0; i < height; i++)
    1881       {
    1882         for (j = 0; j < width; j++)
    1883         {
    1884           Short val = dst2[j] << shift;
    1885           dst2[j] = val - (Short)IF_INTERNAL_OFFS;
     1911      Int shift = IF_INTERNAL_PREC - bitDepth;
     1912      for (i = 0; i < cxHeight; i++)
     1913      {
     1914        for (j = 0; j < cxWidth; j++)
     1915        {
     1916          Pel val = dst2[j] << shift;
     1917          dst2[j] = val - (Pel)IF_INTERNAL_OFFS;
    18861918        }
    18871919        dst2 += dstStride;
     
    18901922  }
    18911923#endif
    1892 }
    1893 
    1894 /**
    1895  * \brief Generate motion-compensated chroma block
    1896  *
    1897  * \param cu       Pointer to current CU
    1898  * \param refPic   Pointer to reference picture
    1899  * \param partAddr Address of block within CU
    1900  * \param mv       Motion vector
    1901  * \param width    Width of block
    1902  * \param height   Height of block
    1903  * \param dstPic   Pointer to destination picture
    1904  * \param bi       Flag indicating whether bipred is used
    1905  */
    1906 Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
    1907 #if H_3D_ARP
    1908     , Bool filterType
    1909 #endif
    1910 #if H_3D_IC
    1911     , Bool bICFlag
    1912 #endif
    1913   )
    1914 {
    1915   Int     refStride  = refPic->getCStride();
    1916   Int     dstStride  = dstPic->getCStride();
    1917  
    1918   Int     refOffset  = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride;
    1919  
    1920   Pel*    refCb     = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
    1921   Pel*    refCr     = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
    1922  
    1923   Pel* dstCb = dstPic->getCbAddr( partAddr );
    1924   Pel* dstCr = dstPic->getCrAddr( partAddr );
    1925  
    1926   Int     xFrac  = mv->getHor() & 0x7;
    1927   Int     yFrac  = mv->getVer() & 0x7;
    1928   UInt    cxWidth  = width  >> 1;
    1929   UInt    cxHeight = height >> 1;
    1930  
    1931   Int     extStride = m_filteredBlockTmp[0].getStride();
    1932   Short*  extY      = m_filteredBlockTmp[0].getLumaAddr();
    1933  
    1934   Int filterSize = NTAPS_CHROMA;
    1935  
    1936   Int halfFilterSize = (filterSize>>1);
    1937  
    1938   if ( yFrac == 0 )
    1939   {
    1940 #if H_3D_IC
    1941     m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
    1942 #else
    1943     m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi
    1944 #endif
    1945 #if H_3D_ARP
    1946     , filterType
    1947 #endif
    1948     );   
    1949 #if H_3D_IC
    1950     m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
    1951 #else
    1952     m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi
    1953 #endif
    1954 #if H_3D_ARP
    1955     , filterType
    1956 #endif
    1957     );
    1958   }
    1959   else if ( xFrac == 0 )
    1960   {
    1961 #if H_3D_IC
    1962     m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
    1963 #else
    1964     m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi
    1965 #endif
    1966 #if H_3D_ARP
    1967     , filterType
    1968 #endif
    1969     );
    1970 #if H_3D_IC
    1971     m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
    1972 #else
    1973     m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi
    1974 #endif
    1975 #if H_3D_ARP
    1976     , filterType
    1977 #endif
    1978     );
    1979   }
    1980   else
    1981   {
    1982     m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
    1983 #if H_3D_ARP
    1984     , filterType
    1985 #endif 
    1986       );
    1987 #if H_3D_IC
    1988     m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
    1989 #else
    1990     m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
    1991 #endif
    1992 #if H_3D_ARP
    1993     , filterType
    1994 #endif
    1995       );
    1996    
    1997     m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
    1998 #if H_3D_ARP
    1999     , filterType
    2000 #endif
    2001       );
    2002 #if H_3D_IC
    2003     m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
    2004 #else
    2005     m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
    2006 #endif
    2007 #if H_3D_ARP
    2008     , filterType
    2009 #endif
    2010       );   
    2011   }
    2012 
    2013 #if H_3D_IC
    2014   if( bICFlag )
    2015   {
    2016     Int a, b, i, j;
    2017     const Int iShift = IC_CONST_SHIFT;
    2018 
    2019     xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb
    2020     for ( i = 0; i < cxHeight; i++ )
    2021     {
    2022       for ( j = 0; j < cxWidth; j++ )
    2023       {
    2024           dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
    2025       }
    2026       dstCb += dstStride;
    2027     }
    2028     xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr
    2029     for ( i = 0; i < cxHeight; i++ )
    2030     {
    2031       for ( j = 0; j < cxWidth; j++ )
    2032       {
    2033           dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
    2034       }
    2035       dstCr += dstStride;
    2036     }
    2037 
    2038     if(bi)
    2039     {
    2040       Pel* dstCb2 = dstPic->getCbAddr( partAddr );
    2041       Pel* dstCr2 = dstPic->getCrAddr( partAddr );
    2042       Int shift = IF_INTERNAL_PREC - g_bitDepthC;
    2043       for (i = 0; i < cxHeight; i++)
    2044       {
    2045         for (j = 0; j < cxWidth; j++)
    2046         {
    2047           Short val = dstCb2[j] << shift;
    2048           dstCb2[j] = val - (Short)IF_INTERNAL_OFFS;
    2049 
    2050           val = dstCr2[j] << shift;
    2051           dstCr2[j] = val - (Short)IF_INTERNAL_OFFS;
    2052         }
    2053         dstCb2 += dstStride;
    2054         dstCr2 += dstStride;
    2055       }
    2056     }
    2057   }
    2058 #endif
    2059 }
    2060 
    2061 Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
     1924
     1925}
     1926
     1927Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv* pcYuvDst, const BitDepths &clipBitDepths
     1928 )
    20621929{
    20631930  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
    20641931  {
    2065     rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
     1932    pcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight, clipBitDepths );
    20661933  }
    20671934  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
    20681935  {
    2069     pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
     1936    pcYuvSrc0->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight );
    20701937  }
    20711938  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
    20721939  {
    2073     pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
     1940    pcYuvSrc1->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight );
    20741941  }
    20751942}
     
    20791946{
    20801947  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
     1948
    20811949  if( pcAMVPInfo->iN <= 1 )
    20821950  {
     
    20941962
    20951963/** Function for deriving planar intra prediction.
    2096  * \param pSrc pointer to reconstructed sample array
    2097  * \param srcStride the stride of the reconstructed sample array
    2098  * \param rpDst reference to pointer for the prediction sample array
    2099  * \param dstStride the stride of the prediction sample array
    2100  * \param width the width of the block
    2101  * \param height the height of the block
     1964 * \param pSrc        pointer to reconstructed sample array
     1965 * \param srcStride   the stride of the reconstructed sample array
     1966 * \param rpDst       reference to pointer for the prediction sample array
     1967 * \param dstStride   the stride of the prediction sample array
     1968 * \param width       the width of the block
     1969 * \param height      the height of the block
     1970 * \param channelType type of pel array (luma, chroma)
     1971 * \param format      chroma format
    21021972 *
    21031973 * This function derives the prediction samples for planar mode (intra coding).
    21041974 */
    2105 Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
    2106 {
    2107   assert(width == height);
    2108 
    2109   Int k, l, bottomLeft, topRight;
    2110   Int horPred;
     1975//NOTE: Bit-Limit - 24-bit source
     1976Void TComPrediction::xPredIntraPlanar( const Pel* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
     1977{
     1978  assert(width <= height);
     1979
    21111980  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
    2112   UInt blkSize = width;
    2113   UInt offset2D = width;
    2114   UInt shift1D = g_aucConvertToBit[ width ] + 2;
    2115   UInt shift2D = shift1D + 1;
     1981  UInt shift1Dhor = g_aucConvertToBit[ width ] + 2;
     1982  UInt shift1Dver = g_aucConvertToBit[ height ] + 2;
    21161983
    21171984  // Get left and above reference column and row
    2118   for(k=0;k<blkSize+1;k++)
     1985  for(Int k=0;k<width+1;k++)
    21191986  {
    21201987    topRow[k] = pSrc[k-srcStride];
     1988  }
     1989
     1990  for (Int k=0; k < height+1; k++)
     1991  {
    21211992    leftColumn[k] = pSrc[k*srcStride-1];
    21221993  }
    21231994
    21241995  // Prepare intermediate variables used in interpolation
    2125   bottomLeft = leftColumn[blkSize];
    2126   topRight   = topRow[blkSize];
    2127   for (k=0;k<blkSize;k++)
    2128   {
    2129     bottomRow[k]   = bottomLeft - topRow[k];
    2130     rightColumn[k] = topRight   - leftColumn[k];
    2131     topRow[k]      <<= shift1D;
    2132     leftColumn[k]  <<= shift1D;
    2133   }
     1996  Int bottomLeft = leftColumn[height];
     1997  Int topRight   = topRow[width];
     1998
     1999  for(Int k=0;k<width;k++)
     2000  {
     2001    bottomRow[k]  = bottomLeft - topRow[k];
     2002    topRow[k]     <<= shift1Dver;
     2003  }
     2004
     2005  for(Int k=0;k<height;k++)
     2006  {
     2007    rightColumn[k]  = topRight - leftColumn[k];
     2008    leftColumn[k]   <<= shift1Dhor;
     2009  }
     2010
     2011  const UInt topRowShift = 0;
    21342012
    21352013  // Generate prediction signal
    2136   for (k=0;k<blkSize;k++)
    2137   {
    2138     horPred = leftColumn[k] + offset2D;
    2139     for (l=0;l<blkSize;l++)
    2140     {
    2141       horPred += rightColumn[k];
    2142       topRow[l] += bottomRow[l];
    2143       rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
     2014  for (Int y=0;y<height;y++)
     2015  {
     2016    Int horPred = leftColumn[y] + width;
     2017    for (Int x=0;x<width;x++)
     2018    {
     2019      horPred += rightColumn[y];
     2020      topRow[x] += bottomRow[x];
     2021
     2022      Int vertPred = ((topRow[x] + topRowShift)>>topRowShift);
     2023      rpDst[y*dstStride+x] = ( horPred + vertPred ) >> (shift1Dhor+1);
    21442024    }
    21452025  }
     
    21492029 * \param pSrc pointer to reconstructed sample array
    21502030 * \param iSrcStride the stride of the reconstructed sample array
    2151  * \param rpDst reference to pointer for the prediction sample array
     2031 * \param pDst reference to pointer for the prediction sample array
    21522032 * \param iDstStride the stride of the prediction sample array
    21532033 * \param iWidth the width of the block
    21542034 * \param iHeight the height of the block
     2035 * \param channelType type of pel array (luma, chroma)
    21552036 *
    21562037 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
    21572038 */
    2158 Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
    2159 {
    2160   Pel* pDst = rpDst;
     2039Void TComPrediction::xDCPredFiltering( const Pel* pSrc, Int iSrcStride, Pel* pDst, Int iDstStride, Int iWidth, Int iHeight, ChannelType channelType )
     2040{
    21612041  Int x, y, iDstStride2, iSrcStride2;
    21622042
    2163   // boundary pixels processing
    2164   pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
    2165 
    2166   for ( x = 1; x < iWidth; x++ )
    2167   {
    2168     pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
    2169   }
    2170 
    2171   for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
    2172   {
    2173     pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
     2043  if (isLuma(channelType) && (iWidth <= MAXIMUM_INTRA_FILTERED_WIDTH) && (iHeight <= MAXIMUM_INTRA_FILTERED_HEIGHT))
     2044  {
     2045    //top-left
     2046    pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
     2047
     2048    //top row (vertical filter)
     2049    for ( x = 1; x < iWidth; x++ )
     2050    {
     2051      pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
     2052    }
     2053
     2054    //left column (horizontal filter)
     2055    for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
     2056    {
     2057      pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
     2058    }
    21742059  }
    21752060
    21762061  return;
    21772062}
    2178 #if H_3D_IC
     2063
     2064/* Static member function */
     2065Bool TComPrediction::UseDPCMForFirstPassIntraEstimation(TComTU &rTu, const UInt uiDirMode)
     2066{
     2067  return (rTu.getCU()->isRDPCMEnabled(rTu.GetAbsPartIdxTU()) ) &&
     2068          rTu.getCU()->getCUTransquantBypass(rTu.GetAbsPartIdxTU()) &&
     2069          (uiDirMode==HOR_IDX || uiDirMode==VER_IDX);
     2070}
     2071#if NH_3D_IC
    21792072/** Function for deriving the position of first non-zero binary bit of a value
    21802073 * \param x input value
     
    22062099/** Function for deriving LM illumination compensation.
    22072100 */
    2208 Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType )
     2101Void TComPrediction::xGetLLSICPrediction( const ComponentID compID, TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, const Int bitDepth )
    22092102{
    22102103  TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
    22112104  Pel *pRec = NULL, *pRef = NULL;
    22122105  UInt uiWidth, uiHeight, uiTmpPartIdx;
    2213   Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride();
    2214   Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride();
     2106  Int iRecStride = pRecPic->getStride(compID);
     2107  Int iRefStride = pRefPic->getStride(compID);
    22152108  Int iRefOffset, iHor, iVer;
    22162109  iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 );
    22172110  iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 );
    2218   if( eType != TEXT_LUMA )
     2111  if( !isLuma(compID) )
    22192112  {
    22202113    iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 );
    22212114    iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 );
    22222115  }
    2223   uiWidth  = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 )  : ( pcCU->getWidth( 0 )  >> 1 );
    2224   uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 );
     2116  uiWidth  = pcCU->getWidth( 0 ) >> pRefPic->getComponentScaleX(compID);
     2117  uiHeight = pcCU->getHeight( 0 ) >> pRefPic->getComponentScaleY(compID);
    22252118
    22262119  Int i, j, iCountShift = 0;
    22272120
    2228   // LLS parameters estimation -->
     2121  // LLS parameters estimation
    22292122
    22302123  Int x = 0, y = 0, xx = 0, xy = 0;
    2231   Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12);
    2232 
    2233   if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) )
     2124  Int precShift = std::max(0, bitDepth - 12);
     2125
     2126  UInt partAddr = 0;
     2127  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCtu() ) )
    22342128  {
    22352129    iRefOffset = iHor + iVer * iRefStride - iRefStride;
    2236     if( eType == TEXT_LUMA )
    2237     {
    2238       pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2239       pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
    2240     }
    2241     else if( eType == TEXT_CHROMA_U )
    2242     {
    2243       pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2244       pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
    2245     }
    2246     else
    2247     {
    2248       assert( eType == TEXT_CHROMA_V );
    2249       pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2250       pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
    2251     }
    2252 
     2130    pRef = pRefPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) + iRefOffset;
     2131    pRec = pRecPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) - iRecStride;
    22532132    for( j = 0; j < uiWidth; j+=2 )
    22542133    {
    22552134      x += pRef[j];
    22562135      y += pRec[j];
    2257       if ( eType == TEXT_LUMA )
     2136      if( isLuma(compID) )
    22582137      {
    22592138        xx += (pRef[j] * pRef[j])>>precShift;
     
    22642143  }
    22652144
    2266   if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) )
     2145  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCtu() ) )
    22672146  {
    22682147    iRefOffset = iHor + iVer * iRefStride - 1;
    2269     if( eType == TEXT_LUMA )
    2270     {
    2271       pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2272       pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
    2273     }
    2274     else if( eType == TEXT_CHROMA_U )
    2275     {
    2276       pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2277       pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
    2278     }
    2279     else
    2280     {
    2281       assert( eType == TEXT_CHROMA_V );
    2282       pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2283       pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
    2284     }
    2285 
     2148    pRef = pRefPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) + iRefOffset;
     2149    pRec = pRecPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) - 1;
    22862150    for( i = 0; i < uiHeight; i+=2 )
    22872151    {
    22882152      x += pRef[0];
    22892153      y += pRec[0];
    2290       if ( eType == TEXT_LUMA )
     2154      if( isLuma(compID) )
    22912155      {
    22922156        xx += (pRef[0] * pRef[0])>>precShift;
     
    23062170  }
    23072171
    2308   if (  eType != TEXT_LUMA )
    2309   {
    2310     a = 32;
     2172  if( !isLuma(compID) )
     2173  {
     2174    a = ( 1 << IC_CONST_SHIFT );
    23112175    b = (  y - x + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
    23122176  }
     
    23182182  Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift);
    23192183  const Int iShift = IC_CONST_SHIFT;
    2320   {
    2321     {
    23222184      const Int iShiftA2 = 6;
    23232185      const Int iAccuracyShift = 15;
     
    23252187      Int iScaleShiftA2 = 0;
    23262188      Int iScaleShiftA1 = 0;
    2327       Int a1s = a1;
    2328       Int a2s = a2;
     2189    Int a1s;
     2190    Int a2s;
    23292191
    23302192      a1 = Clip3(0, 2*a2, a1);
     
    23542216    }
    23552217  }   
    2356   }
    2357 }
    2358 #endif
    2359 
    2360 #if H_3D_DIM
    2361 Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
    2362 {
     2218#endif
     2219
     2220#if NH_3D_SDC_INTRA
     2221Void TComPrediction::predConstantSDC( Pel* ptrSrc, UInt srcStride, UInt uiSize, Pel& predDC )
     2222{
     2223  Pel* pLeftTop     =  ptrSrc;
     2224  Pel* pRightTop    =  ptrSrc                          + (uiSize-1);
     2225  Pel* pLeftBottom  = (ptrSrc+ (srcStride*(uiSize-1))              );
     2226  Pel* pRightBottom = (ptrSrc+ (srcStride*(uiSize-1))  + (uiSize-1));
     2227  predDC = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
     2228}
     2229#endif // NH_3D_SDC_INTRA
     2230
     2231#if NH_3D_DMM
     2232Void TComPrediction::predContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool* segPattern )
     2233{
     2234  // get copy of co-located texture luma block
     2235  TComYuv cTempYuv;
     2236  cTempYuv.create( uiWidth, uiHeight, CHROMA_400 );
     2237  cTempYuv.clear();
     2238  Pel* piRefBlkY = cTempYuv.getAddr( COMPONENT_Y );
     2239  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
     2240  assert( pcPicYuvRef != NULL );
     2241  Int  iRefStride = pcPicYuvRef->getStride( COMPONENT_Y );
     2242  Pel* piRefY     = pcPicYuvRef->getAddr  ( COMPONENT_Y, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx );
     2243
     2244  for( Int y = 0; y < uiHeight; y++ )
     2245  {
     2246    ::memcpy(piRefBlkY, piRefY, sizeof(Pel)*uiWidth);
     2247    piRefBlkY += uiWidth;
     2248    piRefY += iRefStride;
     2249  }
     2250
     2251
     2252  // find contour for texture luma block
     2253  piRefBlkY = cTempYuv.getAddr( COMPONENT_Y );
     2254  UInt iDC = 0;
     2255  iDC  = piRefBlkY[ 0 ];
     2256  iDC += piRefBlkY[ uiWidth - 1 ];
     2257  iDC += piRefBlkY[ uiWidth * (uiHeight - 1) ];
     2258  iDC += piRefBlkY[ uiWidth * (uiHeight - 1) + uiWidth - 1 ];
     2259  iDC = iDC >> 2;
     2260
     2261  piRefBlkY = cTempYuv.getAddr( COMPONENT_Y );
     2262  for( UInt k = 0; k < (uiWidth*uiHeight); k++ )
     2263  {
     2264    segPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
     2265  }
     2266
     2267  cTempYuv.destroy();
     2268}
     2269
     2270Void TComPrediction::predBiSegDCs( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
     2271{
     2272  assert( biSegPattern );
     2273  const Pel *piMask = getPredictorPtr( COMPONENT_Y, false );
     2274  assert( piMask );
     2275  Int srcStride = 2*uiWidth + 1;
     2276  const Pel *ptrSrc = piMask+srcStride+1;
     2277
    23632278  Int  refDC1, refDC2;
    23642279  const Int  iTR = (   patternStride - 1        ) - srcStride;
     
    23872302}
    23882303
    2389 Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
    2390 {
     2304Void TComPrediction::assignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
     2305{
     2306  assert( biSegPattern );
    23912307  if( dstStride == patternStride )
    23922308  {
    23932309    for( UInt k = 0; k < (patternStride * patternStride); k++ )
    23942310    {
    2395       if( true == biSegPattern[k] )
    2396       {
    2397         ptrDst[k] = valDC2;
    2398       }
    2399       else                         
    2400       {
    2401         ptrDst[k] = valDC1;
    2402       }
     2311      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
     2312      else                          { ptrDst[k] = valDC1; }
    24032313    }
    24042314  }
     
    24102320      for( UInt uiX = 0; uiX < patternStride; uiX++ )
    24112321      {
    2412         if( true == biSegPattern[uiX] )
    2413         {
    2414           piTemp[uiX] = valDC2;
    2415         }
    2416         else                           
    2417         {
    2418           piTemp[uiX] = valDC1;
    2419         }
     2322        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
     2323        else                            { piTemp[uiX] = valDC1; }
    24202324      }
    24212325      piTemp       += dstStride;
     
    24242328  }
    24252329}
    2426 
    2427 #if H_3D_DIM_DMM
    2428 
    2429 Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
    2430 {
    2431   pcContourWedge->clear();
    2432 
    2433   // get copy of co-located texture luma block
    2434   TComYuv cTempYuv;
    2435   cTempYuv.create( uiWidth, uiHeight );
    2436   cTempYuv.clear();
    2437   Pel* piRefBlkY = cTempYuv.getLumaAddr();
    2438   xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
    2439   piRefBlkY = cTempYuv.getLumaAddr();
    2440 
    2441   // find contour for texture luma block
    2442   UInt iDC = 0;
    2443 
    2444   iDC  = piRefBlkY[ 0 ];
    2445   iDC += piRefBlkY[ uiWidth - 1 ];
    2446   iDC += piRefBlkY[ uiWidth * (uiHeight - 1) ];
    2447   iDC += piRefBlkY[ uiWidth * (uiHeight - 1) + uiWidth - 1 ];
    2448   iDC = iDC >> 2;
    2449 
    2450   piRefBlkY = cTempYuv.getLumaAddr();
    2451 
    2452   Bool* pabContourPattern = pcContourWedge->getPattern();
    2453   for( UInt k = 0; k < (uiWidth*uiHeight); k++ )
    2454   {
    2455     pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
    2456   }
    2457 
    2458   cTempYuv.destroy();
    2459 }
    2460 
    2461 
    2462 Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
    2463 {
    2464   TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
    2465   assert( pcPicYuvRef != NULL );
    2466   Int         iRefStride = pcPicYuvRef->getStride();
    2467   Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
    2468 
    2469   for ( Int y = 0; y < uiHeight; y++ )
    2470   {
    2471     ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
    2472     piDestBlockY += uiWidth;
    2473     piRefY += iRefStride;
    2474   }
    2475 }
    2476 #endif
    2477 
    2478 
    2479 #if H_3D_DIM_SDC
    2480 Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
    2481                                          ,UInt uiIntraMode
    2482                                          ,Bool orgDC
    2483                                         )
    2484 {
    2485   Int iSumDepth[2];
    2486   memset(iSumDepth, 0, sizeof(Int)*2);
    2487   Int iSumPix[2];
    2488   memset(iSumPix, 0, sizeof(Int)*2);
    2489 
    2490   for( Int i = 0; i < uiNumSegments; i++ )
    2491   {
    2492     rpSegMeans[i] = 0; 
    2493   }
    2494 
    2495   if ( !orgDC )
    2496   {
    2497     Pel* pLeftTop = pOrig;
    2498     Pel* pRightTop = pOrig + (uiSize-1);
    2499     Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1)));
    2500     Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1));
    2501 
    2502     rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
    2503     return;
    2504   }
    2505 
    2506   Int subSamplePix;
    2507   if ( uiSize == 64 || uiSize == 32 )
    2508   {
    2509     subSamplePix = 2;
    2510   }
    2511   else
    2512   {
    2513     subSamplePix = 1;
    2514   }
    2515 
    2516   for (Int y=0; y<uiSize; y+=subSamplePix)
    2517   {
    2518     for (Int x=0; x<uiSize; x+=subSamplePix)
    2519     {
    2520       UChar ucSegment = pMask?(UChar)pMask[x]:0;
    2521       assert( ucSegment < uiNumSegments );
    2522      
    2523       iSumDepth[ucSegment] += pOrig[x];
    2524       iSumPix[ucSegment]   += 1;
    2525     }
    2526    
    2527     pOrig  += uiStride*subSamplePix;
    2528     pMask  += uiMaskStride*subSamplePix;
    2529   }
    2530  
    2531   // compute mean for each segment
    2532   for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
    2533   {
    2534     if( iSumPix[ucSeg] > 0 )
    2535     {
    2536       rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
    2537     }
    2538     else
    2539     {
    2540       rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
    2541     }
    2542   }
    2543 }
    2544 #endif // H_3D_DIM_SDC
    25452330#endif
    25462331//! \}
Note: See TracChangeset for help on using the changeset viewer.