Changeset 608 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComPrediction.cpp


Ignore:
Timestamp:
1 Sep 2013, 22:47:26 (12 years ago)
Author:
tech
Message:

Merged DEV-2.0-dev0@604.

File:
1 edited

Legend:

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

    r461 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3939#include "TComPrediction.h"
    4040
     41#if SHARP_ILLUCOMP_REFINE_E0046
     42#define IC_REG_COST_SHIFT 7
     43#define IC_CONST_SHIFT 5
     44#define IC_SHIFT_DIFF 12
     45#endif
     46
    4147//! \ingroup TLibCommon
    4248//! \{
     
    4652// ====================================================================================================================
    4753
    48 #if LGE_EDGE_INTRA_A0070
    49 #define MAX_DISTANCE_EDGEINTRA 255
    50 #endif
    51 
    52 #if HHI_DELTADC_DLT_D0035
    53 #define GetDepthValue2Idx(val)     (pcCU->getSlice()->getSPS()->depthValue2idx(val))
    54 #define GetIdx2DepthValue(val)     (pcCU->getSlice()->getSPS()->idx2DepthValue(val))
    55 #endif
    56 
    57 #if MERL_General_Fix
    58 #if MERL_VSP_C0152
    59 #if MERL_CVSP_D0165
    60 Int TComPrediction::m_iRangeLuma[12]   = {14, 34, 21, 15, 36, 26, 21, 49, 41, 36, 80, 72};
    61 Int TComPrediction::m_iRangeChroma[12] = { 2,  8,  5,  4, 11,  9,  8, 19, 17, 15, 34, 32};
    62 #endif
    63 #endif
    64 #endif
    65 
    6654TComPrediction::TComPrediction()
    6755: m_pLumaRecBuffer(0)
     56, m_iLumaRecStride(0)
    6857{
    6958  m_piYuvExt = NULL;
    70 #if MERL_VSP_C0152
    71   m_pDepth = (Int*) malloc(64*64*sizeof(Int)); // TODO: Use a smart way to determine the size of the array
    72   if (m_pDepth == NULL)
    73   {
     59#if H_3D_VSP
     60  m_pDepthBlock = (Int*) malloc(MAX_NUM_SPU_W*MAX_NUM_SPU_W*sizeof(Int));
     61  if (m_pDepthBlock == NULL)
    7462      printf("ERROR: UKTGHU, No memory allocated.\n");
    75   }
    7663#endif
    7764}
     
    7966TComPrediction::~TComPrediction()
    8067{
    81  
    82 #if MERL_VSP_C0152
    83   if (m_pDepth != NULL)
    84   {
    85       free(m_pDepth);
    86   }
    87 #endif
     68#if H_3D_VSP
     69  if (m_pDepthBlock != NULL)
     70      free(m_pDepthBlock);
     71#if NTT_VSP_COMMON_E0207_E0208
     72  m_cYuvDepthOnVsp.destroy();
     73#endif
     74#endif
     75
    8876  delete[] m_piYuvExt;
    8977
     
    9280
    9381  m_cYuvPredTemp.destroy();
    94 #if QC_ARP_D0177
     82
     83#if H_3D_ARP
    9584  m_acYuvPredBase[0].destroy();
    9685  m_acYuvPredBase[1].destroy();
    97   m_acYuvDiff[0].destroy();
    98   m_acYuvDiff[1].destroy();
    9986#endif
    10087  if( m_pLumaRecBuffer )
     
    118105  if( m_piYuvExt == NULL )
    119106  {
    120     Int extWidth  = g_uiMaxCUWidth + 16;
    121     Int extHeight = g_uiMaxCUHeight + 1;
     107    Int extWidth  = MAX_CU_SIZE + 16;
     108    Int extHeight = MAX_CU_SIZE + 1;
    122109    Int i, j;
    123110    for (i = 0; i < 4; i++)
     
    129116      }
    130117    }
    131     m_iYuvExtHeight  = ((g_uiMaxCUHeight + 2) << 4);
    132     m_iYuvExtStride = ((g_uiMaxCUWidth  + 8) << 4);
     118    m_iYuvExtHeight  = ((MAX_CU_SIZE + 2) << 4);
     119    m_iYuvExtStride = ((MAX_CU_SIZE  + 8) << 4);
    133120    m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
    134121
    135122    // new structure
    136     m_acYuvPred[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
    137     m_acYuvPred[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
    138 
    139     m_cYuvPredTemp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
    140 #if QC_ARP_D0177
     123    m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE );
     124    m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE );
     125
     126    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE );
     127#if H_3D_ARP
    141128    m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
    142129    m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
    143     m_acYuvDiff    [0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
    144     m_acYuvDiff    [1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
    145 #endif
    146   }
    147 
    148   m_iLumaRecStride =  (g_uiMaxCUWidth>>1) + 1;
    149   m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ];
    150 
     130#endif
     131#if NTT_VSP_COMMON_E0207_E0208
     132    m_cYuvDepthOnVsp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
     133#endif
     134  }
     135
     136  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
     137  {
     138    m_iLumaRecStride =  (MAX_CU_SIZE>>1) + 1;
     139    if (!m_pLumaRecBuffer)
     140    {
     141      m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ];
     142    }
     143  }
     144#if H_3D_IC
     145#if SHARP_ILLUCOMP_REFINE_E0046
     146  m_uiaShift[0] = 0;
    151147  for( Int i = 1; i < 64; i++ )
    152148  {
     149    m_uiaShift[i] = ( (1 << 15) + i/2 ) / i;
     150  }
     151#else
     152  for( Int i = 1; i < 64; i++ )
     153  {
    153154    m_uiaShift[i-1] = ( (1 << 15) + i/2 ) / i;
    154155  }
     156#endif
     157#endif
    155158}
    156159
     
    162165Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft )
    163166{
     167  assert(iWidth > 0 && iHeight > 0);
    164168  Int iInd, iSum = 0;
    165169  Pel pDcVal;
     
    221225 * from the extended main reference.
    222226 */
    223 Void TComPrediction::xPredIntraAng( Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter )
     227Void TComPrediction::xPredIntraAng(Int bitDepth, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter )
    224228{
    225229  Int k,l;
     
    315319        for (k=0;k<blkSize;k++)
    316320        {
    317           pDst[k*dstStride] = Clip ( pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) );
     321          pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) );
    318322        }
    319323      }
     
    369373}
    370374
    371 Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight,  TComDataCU* pcCU, Bool bAbove, Bool bLeft )
     375Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
    372376{
    373377  Pel *pDst = piPred;
     
    390394  else
    391395  {
    392     xPredIntraAng( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );
    393 
    394     if( (uiDirMode == DC_IDX ) && bAbove && bLeft )
    395     {
    396       xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);
     396    if ( (iWidth > 16) || (iHeight > 16) )
     397    {
     398      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
     399    }
     400    else
     401    {
     402      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );
     403
     404      if( (uiDirMode == DC_IDX ) && bAbove && bLeft )
     405      {
     406        xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);
     407      }
    397408    }
    398409  }
     
    400411
    401412// Angular chroma
    402 Void TComPrediction::predIntraChromaAng( TComPattern* pcTComPattern, Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, TComDataCU* pcCU, Bool bAbove, Bool bLeft )
     413Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
    403414{
    404415  Pel *pDst = piPred;
     
    415426  {
    416427    // Create the prediction
    417     xPredIntraAng( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
    418   }
    419 }
     428    xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
     429  }
     430}
     431
     432#if H_3D_DIM
     433Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc )
     434{
     435  assert( iWidth == iHeight  );
     436  assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE );
     437  assert( isDimMode( uiIntraMode ) );
     438
     439  UInt dimType    = getDimType  ( uiIntraMode );
     440  Bool dimDeltaDC = isDimDeltaDC( uiIntraMode );   
     441  Bool isDmmMode  = (dimType <  DMM_NUM_TYPE);
     442  Bool isRbcMode  = (dimType == RBC_IDX);
     443
     444  Bool* biSegPattern  = NULL;
     445  UInt  patternStride = 0;
     446
     447  // get partiton
     448#if H_3D_DIM_DMM
     449  TComWedgelet* dmmSegmentation = NULL;
     450  if( isDmmMode )
     451  {
     452    switch( dimType )
     453    {
     454    case( DMM1_IDX ):
     455      {
     456        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]);
     457      } break;
     458#if !SEC_DMM2_E0146
     459    case( DMM2_IDX ):
     460      {
     461        UInt uiTabIdx = 0;
     462        if( bFastEnc ) { uiTabIdx = pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ); }
     463        else
     464        {
     465          uiTabIdx = xPredWedgeFromIntra( pcCU, uiAbsPartIdx, iWidth, iHeight, pcCU->getDmm2DeltaEnd( uiAbsPartIdx ) );
     466          pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, uiAbsPartIdx, (pcCU->getDepth(0) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1)) );
     467        }
     468        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ uiTabIdx ]);
     469      } break;
     470#endif
     471    case( DMM3_IDX ):
     472      {
     473        UInt uiTabIdx = 0;
     474        if( bFastEnc ) { uiTabIdx = pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ); }
     475        else
     476        {
     477          uiTabIdx = xPredWedgeFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, pcCU->getDmm3IntraTabIdx( uiAbsPartIdx ) );
     478          pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, uiAbsPartIdx, (pcCU->getDepth(0) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1)) );
     479        }
     480        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ uiTabIdx ]);
     481      } break;
     482    case( DMM4_IDX ):
     483      {
     484        dmmSegmentation = new TComWedgelet( iWidth, iHeight );
     485        xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
     486      } break;
     487    default: assert(0);
     488    }
     489    assert( dmmSegmentation );
     490    biSegPattern  = dmmSegmentation->getPattern();
     491    patternStride = dmmSegmentation->getStride ();
     492  }
     493#endif
     494#if H_3D_DIM_RBC
     495  if( isRbcMode )
     496  {
     497    biSegPattern  = pcCU->getEdgePartition( uiAbsPartIdx );
     498    patternStride = iWidth;
     499  }
     500#endif
     501
     502  // get predicted partition values
     503  assert( biSegPattern );
     504  Int* piMask = NULL;
     505  if( isDmmMode ) piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering for DMM
     506  else            piMask = pcCU->getPattern()->getPredictorPtr( 0, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
     507  assert( piMask );
     508  Int maskStride = 2*iWidth + 1; 
     509  Int* ptrSrc = piMask+maskStride+1;
     510  Pel predDC1 = 0; Pel predDC2 = 0;
     511  xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 );
     512
     513  // set segment values with deltaDC offsets
     514  Pel segDC1 = 0;
     515  Pel segDC2 = 0;
     516  if( dimDeltaDC )
     517  {
     518    Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx );
     519    Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx );
     520#if H_3D_DIM_DMM
     521    if( isDmmMode )
     522    {
     523#if H_3D_DIM_DLT
     524      segDC1 = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 );
     525      segDC2 = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 );
     526#else
     527      segDC1 = ClipY( predDC1 + deltaDC1 );
     528      segDC2 = ClipY( predDC2 + deltaDC2 );
     529#endif
     530    }
     531#endif
     532#if H_3D_DIM_RBC
     533    if( isRbcMode )
     534    {
     535      xDeltaDCQuantScaleUp( pcCU, deltaDC1 );
     536      xDeltaDCQuantScaleUp( pcCU, deltaDC2 );
     537      segDC1 = ClipY( predDC1 + deltaDC1 );
     538      segDC2 = ClipY( predDC2 + deltaDC2 );
     539    }
     540#endif
     541  }
     542  else
     543  {
     544    segDC1 = predDC1;
     545    segDC2 = predDC2;
     546  }
     547
     548  // set prediction signal
     549  Pel* pDst = piPred;
     550  xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 );
     551
     552#if H_3D_DIM_DMM
     553  if( dimType == DMM4_IDX ) { dmmSegmentation->destroy(); delete dmmSegmentation; }
     554#endif
     555}
     556#endif
    420557
    421558/** Function for checking identical motion.
     
    425562Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr )
    426563{
    427   if( pcCU->getSlice()->isInterB() && pcCU->getSlice()->getPPS()->getWPBiPredIdc() == 0 )
     564  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() )
    428565  {
    429566    if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0)
    430567    {
    431       Int RefPOCL0    = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
    432       Int RefViewIdL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getViewId();
    433       Int RefPOCL1    = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
    434       Int RefViewIdL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getViewId();
    435       if(RefPOCL0 == RefPOCL1 && RefViewIdL0 == RefViewIdL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
     568      Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
     569      Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
     570      if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
    436571      {
    437572        return true;
     
    442577}
    443578
    444 #if LGE_EDGE_INTRA_A0070
    445 Void TComPrediction::predIntraLumaEdge ( TComDataCU* pcCU, TComPattern* pcTComPattern, UInt uiAbsPartIdx, Int iWidth, Int iHeight, Pel* piPred, UInt uiStride, Bool bDelta )
    446 {
    447   Pel *piDst = piPred;
    448   Int *piSrc;
    449   Int iSrcStride = ( iWidth<<1 ) + 1;
    450   Int iDstStride = uiStride;
    451 
    452   piSrc = pcTComPattern->getPredictorPtr( 0, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
    453 
    454   xPredIntraEdge ( pcCU, uiAbsPartIdx, iWidth, iHeight, piSrc, iSrcStride, piDst, iDstStride
    455 #if LGE_EDGE_INTRA_DELTA_DC
    456     , bDelta
    457 #endif
    458     );
    459 }
    460 
    461 Pel  TComPrediction::xGetNearestNeighbor( Int x, Int y, Int* pSrc, Int srcStride, Int iWidth, Int iHeight, Bool* bpRegion )
    462 {
    463   Bool bLeft = (x < y) ? true : false;
    464   Bool bFound = false;
    465   Int  iFoundX = -1, iFoundY = -1;
    466   Int  cResult = 0;
    467 
    468   UChar* piTopDistance = new UChar[iWidth];
    469   UChar* piLeftDistance = new UChar[iHeight];
    470 
    471   for( Int i = 0; i < iWidth; i++ )
    472   {
    473     int Abs = x > i ? x - i : i - x;
    474     piTopDistance[ i ] = y + Abs;
    475 
    476     Abs = y > i ? y - i : i - y;
    477     piLeftDistance[ i ] = x + Abs;
    478   }
    479 
    480   for( Int dist = 0; dist < MAX_DISTANCE_EDGEINTRA && !bFound; dist++ )
    481   {
    482     if( !bLeft )
    483     {
    484       for( Int i = 0; i < iWidth; i++ )
    485       {
    486         if( piTopDistance[ i ] == dist )
    487         {
    488           if( bpRegion[ i ] == bpRegion[ x + y * iWidth ] )
    489           {
    490             iFoundX = i;
    491             iFoundY = 0;
    492             bFound = true;
    493           }
    494         }
    495       }
    496       for( Int i = 0; i < iHeight; i++ )
    497       {
    498         if( piLeftDistance[ i ] == dist )
    499         {
    500           if( bpRegion[ i * iWidth ] == bpRegion[ x + y * iWidth ] )
    501           {
    502             iFoundX = 0;
    503             iFoundY = i;
    504             bFound = true;
    505           }
    506         }
    507       }
    508     }
    509     else
    510     {
    511       for( Int i = 0; i < iHeight; i++ )
    512       {
    513         if( piLeftDistance[ i ] == dist )
    514         {
    515           if( bpRegion[ i * iWidth ] == bpRegion[ x + y * iWidth ] )
    516           {
    517             iFoundX = 0;
    518             iFoundY = i;
    519             bFound = true;
    520           }
    521         }
    522       }
    523       for( Int i = 0; i < iWidth; i++ )
    524       {
    525         if( piTopDistance[ i ] == dist )
    526         {
    527           if( bpRegion[ i ] == bpRegion[ x + y * iWidth ] )
    528           {
    529             iFoundX = i;
    530             iFoundY = 0;
    531             bFound = true;
    532           }
    533         }
    534       }
    535     }
    536   }
    537 
    538   if( iFoundY == 0 )
    539   {
    540     cResult = pSrc[ iFoundX + 1 ];
    541   }
    542   else // iFoundX == 0
    543   {
    544     cResult = pSrc[ (iFoundY + 1) * srcStride ];
    545   }
    546 
    547   delete[] piTopDistance;  piTopDistance = NULL;
    548   delete[] piLeftDistance; piLeftDistance = NULL;
    549 
    550   assert( bFound );
    551 
    552   return cResult;
    553 }
    554 
    555 Void TComPrediction::xPredIntraEdge( TComDataCU* pcCU, UInt uiAbsPartIdx, Int iWidth, Int iHeight, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, Bool bDelta )
    556 {
    557   Pel* pDst = rpDst;
    558   Bool* pbRegion = pcCU->getEdgePartition( uiAbsPartIdx );
    559 
    560   // Do prediction
    561   {
    562 #if QC_DC_PREDICTOR_D0183
    563     Int iMean0, iMean1;
    564     getPredDCs( pbRegion, iWidth, pSrc+srcStride+1, srcStride, iMean0, iMean1 );
    565 #else
    566     //UInt uiSum0 = 0, uiSum1 = 0;
    567     Int iSum0 = 0, iSum1 = 0;
    568     //UInt uiMean0, uiMean1;
    569     Int iMean0, iMean1;
    570     //UInt uiCount0 = 0, uiCount1 = 0;
    571     Int iCount0 = 0, iCount1 = 0;
    572     for( UInt ui = 0; ui < iWidth; ui++ )
    573     {
    574       if( pbRegion[ ui ] == false )
    575       {
    576         iSum0 += (pSrc[ ui + 1 ]);
    577         iCount0++;
    578       }
    579       else
    580       {
    581         iSum1 += (pSrc[ ui + 1 ]);
    582         iCount1++;
    583       }
    584     }
    585     for( UInt ui = 0; ui < iHeight; ui++ ) // (0,0) recount (to avoid division)
    586     {
    587       if( pbRegion[ ui * iWidth ] == false )
    588       {
    589         iSum0 += (pSrc[ (ui + 1) * srcStride ]);
    590         iCount0++;
    591       }
    592       else
    593       {
    594         iSum1 += (pSrc[ (ui + 1) * srcStride ]);
    595         iCount1++;
    596       }
    597     }
    598     if( iCount0 == 0 )
    599       assert(false);
    600     if( iCount1 == 0 )
    601       assert(false);
    602     iMean0 = iSum0 / iCount0; // TODO : integer op.
    603     iMean1 = iSum1 / iCount1;
    604 #endif
    605 #if LGE_EDGE_INTRA_DELTA_DC
    606     if( bDelta )
    607     {
    608       Int iDeltaDC0 = pcCU->getEdgeDeltaDC0( uiAbsPartIdx );
    609       Int iDeltaDC1 = pcCU->getEdgeDeltaDC1( uiAbsPartIdx );
    610       xDeltaDCQuantScaleUp( pcCU, iDeltaDC0 );
    611       xDeltaDCQuantScaleUp( pcCU, iDeltaDC1 );
    612       iMean0 = Clip( iMean0 + iDeltaDC0 );
    613       iMean1 = Clip( iMean1 + iDeltaDC1 );
    614     }
    615 #endif
    616     for( UInt ui = 0; ui < iHeight; ui++ )
    617     {
    618       for( UInt uii = 0; uii < iWidth; uii++ )
    619       {
    620         if( pbRegion[ uii + ui * iWidth ] == false )
    621           pDst[ uii + ui * dstStride ] = iMean0;
    622         else
    623           pDst[ uii + ui * dstStride ] = iMean1;
    624       }
    625     }
    626   }
    627 }
    628 #endif
    629 
    630 #if DEPTH_MAP_GENERATION
    631 #if MERL_VSP_C0152
    632 Void TComPrediction::motionCompensation( TComDataCU* pcCU, TComYuv* pcYuvPred, UInt uiAbsPartIdx, RefPicList eRefPicList, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY )
    633 #else
    634 Void TComPrediction::motionCompensation( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY )
    635 #endif
    636 #else
    637 #if MERL_VSP_C0152
    638 Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, UInt uiAbsPartIdx, RefPicList eRefPicList, Int iPartIdx )
    639 #else
     579
    640580Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
    641 #endif
    642 #endif
    643581{
    644582  Int         iWidth;
     
    649587  {
    650588    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
    651 
    652 #if DEPTH_MAP_GENERATION
    653     if( bPrdDepthMap )
    654     {
    655       iWidth  >>= uiSubSampExpX;
    656       iHeight >>= uiSubSampExpY;
    657     }
    658 #endif
    659 
    660     if ( eRefPicList != REF_PIC_LIST_X )
    661     {
    662 #if LGE_ILLUCOMP_B0045
    663       if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr))
     589#if H_3D_VSP
     590    if ( 0 == pcCU->getVSPFlag(uiPartAddr) )
     591    {
     592#endif
     593      if ( eRefPicList != REF_PIC_LIST_X )
     594      {
     595        if( pcCU->getSlice()->getPPS()->getUseWP())
     596        {
     597          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
     598        }
     599        else
     600        {
     601          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
     602        }
     603        if ( pcCU->getSlice()->getPPS()->getUseWP() )
     604        {
     605          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
     606        }
     607      }
     608      else
     609      {
     610        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
     611        {
     612          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
     613        }
     614        else
     615        {
     616          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
     617        }
     618      }
     619#if H_3D_VSP
     620    }
     621    else
     622    {
     623      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
     624        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
     625      else
     626        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
     627    }
     628#endif
     629    return;
     630  }
     631
     632  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
     633  {
     634    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
     635
     636#if H_3D_VSP
     637    if ( 0 == pcCU->getVSPFlag(uiPartAddr) )
     638    {
     639#endif
     640      if ( eRefPicList != REF_PIC_LIST_X )
     641      {
     642        if( pcCU->getSlice()->getPPS()->getUseWP())
     643        {
     644          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
     645        }
     646        else
     647        {
     648          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
     649        }
     650        if ( pcCU->getSlice()->getPPS()->getUseWP() )
     651        {
     652          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
     653        }
     654      }
     655      else
     656      {
     657        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
     658        {
     659          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
     660        }
     661        else
     662        {
     663          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
     664        }
     665      }
     666#if H_3D_VSP
     667    }
     668    else
     669    {
     670      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
     671        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
     672      else
     673        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
     674    }
     675#endif
     676  }
     677  return;
     678}
     679
     680Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
     681{
     682  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
     683  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
     684  pcCU->clipMv(cMv);
     685#if H_3D_ARP
     686  if(  pcCU->getARPW( uiPartAddr ) > 0
     687    && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N
     688    && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC()
     689    )
     690  {
     691    xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi );
     692  }
     693  else
     694  {
     695#endif
     696#if H_3D_IC
     697    Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() );
     698    xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
     699#if H_3D_ARP
     700      , false
     701#endif
     702      , bICFlag );
     703#if SHARP_ILLUCOMP_REFINE_E0046
     704    bICFlag = bICFlag && (iWidth > 8);
     705#endif
     706    xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
     707#if H_3D_ARP
     708      , false
     709#endif
     710      , bICFlag );
    664711#else
    665       if( pcCU->getSlice()->getPPS()->getUseWP())
    666 #endif
    667       {
    668 #if MERL_VSP_C0152
    669         xPredInterUni (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
     712  xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
     713  xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
     714#endif
     715#if H_3D_ARP
     716  }
     717#endif
     718}
     719
     720#if H_3D_VSP
     721Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
     722{
     723  // Get depth reference
     724#if MTK_VSP_FIX_E0172
     725  Int vspDir = pcCU->getVSPDir( uiPartAddr );
     726  RefPicList privateRefPicList = (vspDir == 0) ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
     727  Int privateRefIdx = pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
     728  Int depthRefViewIdx = pcCU->getSlice()->getRefPic(privateRefPicList, privateRefIdx)->getViewIndex();
    670729#else
    671         xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
    672 #endif
    673       }
    674       else
    675       {
    676 #if MERL_VSP_C0152
    677         xPredInterUni (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
    678 #else       
    679         xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
    680 #endif
    681       }
    682 #if LGE_ILLUCOMP_B0045
    683       if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr) )
     730  Int depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
     731#endif
     732  TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
     733  assert(pRefPicBaseDepth != NULL);
     734  TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
     735  assert(pcBaseViewDepthPicYuv != NULL);
     736
     737  // Get texture reference
     738  Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
     739  assert(iRefIdx >= 0);
     740  TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx );
     741  TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
     742  assert(pcBaseViewTxtPicYuv != NULL);
     743
     744  // Initialize LUT according to the reference viewIdx
     745  Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex();
     746  Int* pShiftLUT    = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx );
     747  assert( txtRefViewIdx < pcCU->getSlice()->getViewIndex() );
     748
     749  // Do compensation
     750#if MTK_VSP_FIX_ALIGN_WD_E0172
     751  TComMv cDv  = pcCU->getDvInfo(uiPartAddr).m_acNBDV;
    684752#else
    685       if ( pcCU->getSlice()->getPPS()->getUseWP() )
    686 #endif
    687       {
    688         xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx );
    689       }
    690     }
    691     else
    692     {
    693       if( xCheckIdenticalMotion( pcCU, uiPartAddr ) && !bPrdDepthMap )
    694       {
    695 #if MERL_VSP_C0152
    696         xPredInterUni (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
     753#if MTK_VSP_FIX_E0172
     754  TComMv cDv  = pcCU->getCUMvField( privateRefPicList )->getMv( uiPartAddr );
    697755#else
    698         xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
    699 #endif
    700       }
    701       else
    702       {
    703 #if MERL_VSP_C0152
    704         xPredInterBi  (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, pcYuvPred, iPartIdx, bPrdDepthMap );
     756  TComMv cDv  = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); // cDv is the disparity vector derived from the neighbors
     757#endif
     758#endif // end of MTK_VSP_FIX_ALIGN_WD_E0172
     759  pcCU->clipMv(cDv);
     760
     761#if NTT_VSP_COMMON_E0207_E0208
     762  // fetch virtual depth map
     763#if NTT_VSP_VECTOR_CLIP_E0208
     764  pcBaseViewDepthPicYuv->extendPicBorder();
     765#endif
     766  xGetVirtualDepth( pcCU, pcBaseViewDepthPicYuv, &cDv, uiPartAddr, iWidth, iHeight, &m_cYuvDepthOnVsp );
     767  // sub-PU based compensation
     768  xPredInterLumaBlkFromDM   ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
     769  xPredInterChromaBlkFromDM ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
    705770#else
    706         xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, pcYuvPred, iPartIdx, bPrdDepthMap );
    707 #endif
    708       }
    709     }
    710     return;
    711   }
    712 
    713   for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
    714   {
    715     pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
    716 
    717     if( bPrdDepthMap )
    718     {
    719       iWidth  >>= uiSubSampExpX;
    720       iHeight >>= uiSubSampExpY;
    721     }
    722 
    723     if ( eRefPicList != REF_PIC_LIST_X )
    724     {
    725 #if LGE_ILLUCOMP_B0045
    726       if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr))
    727 #else
    728       if( pcCU->getSlice()->getPPS()->getUseWP())
    729 #endif
    730       {
    731 #if MERL_VSP_C0152
    732         xPredInterUni (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
    733 #else
    734         xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
    735 #endif
    736   }
    737   else
    738   {
    739 #if MERL_VSP_C0152
    740         xPredInterUni (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
    741 #else
    742         xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
    743 #endif
    744       }
    745 #if MERL_VSP_C0152
    746       xPredInterUni (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
    747 #else
    748       xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
    749 #endif
    750 
    751 #if LGE_ILLUCOMP_B0045
    752       if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr))
    753 #else
    754       if( pcCU->getSlice()->getPPS()->getUseWP())
    755 #endif
    756       {
    757         xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx );
    758       }
    759     }
    760     else
    761     {
    762       if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
    763       {
    764 #if MERL_VSP_C0152
    765         xPredInterUni (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
    766 #else
    767         xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
    768 #endif
    769       }
    770       else
    771       {
    772 #if MERL_VSP_C0152
    773         xPredInterBi  (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, pcYuvPred, iPartIdx, bPrdDepthMap );
    774 #else
    775         xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, pcYuvPred, iPartIdx, bPrdDepthMap );
    776 #endif   
    777       }
    778     }
    779   }
    780   return;
    781 }
    782 
    783 #if H3D_IVRP & !QC_ARP_D0177
    784 Void TComPrediction::residualPrediction(TComDataCU* pcCU, TComYuv* pcYuvPred, TComYuv* pcYuvResPred)
    785 {
    786   Int         iWidth;
    787   Int         iHeight;
    788   UInt        uiPartAddr;
    789 
    790   pcCU->getPartIndexAndSize( 0, uiPartAddr, iWidth, iHeight );
    791 
    792   Bool bResAvail = false;
    793 
    794   bResAvail = pcCU->getResidualSamples( 0, true, pcYuvResPred );
    795 
    796   assert (bResAvail);
    797 
    798   pcYuvPred->add(pcYuvResPred, iWidth, iHeight);
    799 }
    800 #endif
    801 
    802 #if MERL_General_Fix
    803 #if MERL_VSP_C0152
    804 // Function to perform VSP block compensation
    805 Void  TComPrediction::xPredInterVSPBlk(TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, TComMv cMv, RefPicList eRefPicList, TComYuv*& rpcYuvPred
    806                                      , Bool bi
    807 #if !MERL_Bi_VSP_D0166
    808                                      , Int vspIdx
    809 #endif
    810                                        )
    811 {
    812   TComPic*    pRefPicBaseTxt        = NULL;
    813   TComPicYuv* pcBaseViewTxtPicYuv   = NULL;
    814   TComPicYuv* pcBaseViewDepthPicYuv = NULL;
    815   Int iBlkX = 0;
    816   Int iBlkY = 0;
    817   Int* pShiftLUT;
    818   Int  iShiftPrec;
    819 
    820 #if !MERL_VSP_NBDV_RefVId_Fix_D0166
    821   pRefPicBaseTxt        = pcCU->getSlice()->getRefPicBaseTxt();
    822   pcBaseViewTxtPicYuv   = pRefPicBaseTxt->getPicYuvRec();
    823   TComPic* pRefPicBaseDepth = pcCU->getSlice()->getRefPicBaseDepth();
    824   pcBaseViewDepthPicYuv     = pRefPicBaseDepth->getPicYuvRec();
    825 
     771  UInt uiAbsPartIdx = pcCU->getZorderIdxInCU();
    826772  Int iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
    827773  Int iBlkY = ( pcCU->getAddr() / pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
    828   pcCU->getSlice()->getBWVSPLUTParam(pShiftLUT, iShiftPrec);
    829   xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getSPS()->isDepth(), rpcYuvPred );
    830   xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getSPS()->isDepth(), rpcYuvPred );
    831 
    832 #else // MERL_VSP_NBDV_RefVId_Fix_D0166
    833    // Step 1: get depth reference
    834 #if QC_BVSP_CleanUP_D0191
    835   RefPicList privateRefPicList = REF_PIC_LIST_0;
    836   Int refIdxList0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr );
    837   Int refIdxList1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr );
    838   privateRefPicList = refIdxList0 != NOT_VALID ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
    839   if(privateRefPicList == REF_PIC_LIST_1 && refIdxList1== NOT_VALID )
    840   {
    841     assert(0);
    842   }
    843   Int privateRefIdx = privateRefPicList == REF_PIC_LIST_0 ? refIdxList0 : refIdxList1;
    844   Int viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, privateRefIdx);
    845   Int refPoc = pcCU->getSlice()->getRefPOC(privateRefPicList, privateRefIdx);
    846 #else
    847   //recover VSP reference frame according to negative refIdx number
    848   RefPicList privateRefPicList = (RefPicList) pcCU->getVSPDir( uiPartAddr );
    849   assert(privateRefPicList == REF_PIC_LIST_0 || privateRefPicList == REF_PIC_LIST_1);
    850   Int  refIdx = -1-pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr ); // texture ref index, a trick when storing refIdx
    851   Int  viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, refIdx);  // texture view id
    852   Int  refPoc = pcCU->getSlice()->getRefPOC(privateRefPicList, refIdx);     // texture POC
    853 #endif
    854   TComPic* pRefPicBaseDepth = pcCU->getSlice()->getDepthRefPic(viewId, refPoc);
    855 
    856   pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
    857   assert(refPoc == pcCU->getSlice()->getPOC());
    858   assert(pRefPicBaseDepth != NULL);
    859   assert(pcBaseViewDepthPicYuv != NULL);
    860 
    861   iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
    862   iBlkY = ( pcCU->getAddr() / pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
    863 #if MERL_Bi_VSP_D0166
    864   // Step 2: get texture reference
    865   pRefPicBaseTxt = xGetVspRefTxt( pcCU, uiPartAddr, eRefPicList);
    866   pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
    867   assert(pcBaseViewTxtPicYuv != NULL);
    868 
    869   // initialize the LUT according to the reference view idx
    870   pcCU->getSlice()->getBWVSPLUTParam(pShiftLUT, iShiftPrec, pRefPicBaseTxt->getViewId());
    871 
    872   // Step 3: Do compensation
    873   xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getSPS()->isDepth(), rpcYuvPred, bi );
    874   xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getSPS()->isDepth(), rpcYuvPred, bi );
    875 #else
    876   // Step 2: get texture reference
    877   pRefPicBaseTxt = pcCU->getSlice()->getRefPic(privateRefPicList, refIdx);
    878   pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
    879   assert(pcBaseViewTxtPicYuv != NULL);
    880 
    881   //initialize the LUT according to the reference view idx
    882   pcCU->getSlice()->getBWVSPLUTParam(pShiftLUT, iShiftPrec, pRefPicBaseTxt->getViewId());
    883 
    884   // Step 3: Do compensation
    885   xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
    886   xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
    887 #endif
    888 
    889 #endif
    890 }
    891 
    892 #endif
    893 
    894 #if MERL_Bi_VSP_D0166
    895 TComPic*  TComPrediction::xGetVspRefTxt(TComDataCU* pcCU, UInt uiPartAddr, RefPicList eRefPicList)
    896 {
    897 #if QC_BVSP_CleanUP_D0191
    898   RefPicList privateRefPicList = REF_PIC_LIST_0;
    899   Int refIdxList0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr );
    900   Int refIdxList1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr );
    901   privateRefPicList = refIdxList0 != NOT_VALID ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
    902   if(privateRefPicList == REF_PIC_LIST_1 && refIdxList1==NOT_VALID )
    903   {
    904     assert(0);
    905   }
    906   Int privateRefIdx = privateRefPicList == REF_PIC_LIST_0 ? refIdxList0 : refIdxList1;
    907   Int viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, privateRefIdx);
    908 #else
    909   RefPicList  privateRefPicList = (RefPicList) pcCU->getVSPDir( uiPartAddr );
    910   Int         refIdx = -1-pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr ); // texture ref index, a trick when storing refIdx
    911   Int         viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, refIdx);  // texture view id
    912 #endif
    913   TComPic*    refPic = NULL;
    914 
    915   assert(privateRefPicList == REF_PIC_LIST_0 || privateRefPicList == REF_PIC_LIST_1);
    916 
    917   if (privateRefPicList == eRefPicList)
    918   {
    919 #if QC_BVSP_CleanUP_D0191
    920     Int  refIdxt = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
    921 #else
    922     Int  refIdxt = -1-pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
    923 #endif
    924     assert(refIdxt>= 0);
    925     refPic = pcCU->getSlice()->getRefPic(eRefPicList, refIdxt);
    926   }
    927   else
    928   {
    929     // Find the other interview reference in order to do VSP
    930     RefPicList otherRefPicList = privateRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
    931     Bool isFound = false;
    932     for (Int iRefIdx = 0; iRefIdx <pcCU->getSlice()->getNumRefIdx(otherRefPicList); iRefIdx ++ )
    933     {
    934       Int refViewIdx  = pcCU->getSlice()->getRefViewId( otherRefPicList, iRefIdx);
    935       if ( (refViewIdx != pcCU->getSlice()->getViewId()) && (refViewIdx != viewId ) )
    936       {
    937         refPic = pcCU->getSlice()->getRefPic(otherRefPicList, iRefIdx);
    938         isFound = true;
    939         break;
    940       }
    941     }
    942 
    943     if (isFound == false)
    944     {
    945 #if QC_BVSP_CleanUP_D0191
    946       Int  refIdxTxt = pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
    947 #else
    948       Int  refIdxTxt = -1-pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
    949 #endif
    950       assert(refIdxTxt >= 0);
    951       refPic = pcCU->getSlice()->getRefPic(privateRefPicList, refIdxTxt);
    952     }
    953     assert(isFound);
    954   }
    955   assert(refPic != NULL);
    956   return refPic;
    957 }
    958 #endif
    959 #endif
    960 
    961 #if MERL_VSP_C0152
    962 Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY, Bool bi )
    963 #else
    964 Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY, Bool bi )
    965 #endif
    966 {
    967 #if MERL_VSP_C0152
    968   Int  iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );   
    969   Int  vspIdx  = pcCU->getVSPIndex(uiPartAddr);
    970   if (vspIdx != 0)
    971   {
    972 #if !QC_BVSP_CleanUP_D0191
    973     if (iRefIdx >= 0)
    974     {
    975       printf("vspIdx = %d, iRefIdx = %d\n", vspIdx, iRefIdx);
    976     }
    977     assert (iRefIdx < 0); // assert (iRefIdx == NOT_VALID);
    978 #endif
    979   }
    980   else
    981   {
    982     assert (iRefIdx >= 0);
    983   }
    984 #else
    985   Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
    986 #endif
    987 
    988   TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
    989   pcCU->clipMv(cMv);
    990 
    991 #if DEPTH_MAP_GENERATION
    992   if( bPrdDepthMap )
    993   {
    994     UInt uiRShift = 0;
    995     if( pcCU->getPic()->getStoredPDMforV2() == 1 )
    996       xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPredDepthMapTemp(), uiPartAddr, &cMv, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, rpcYuvPred, uiRShift, 0 );
    997     else
    998       xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPredDepthMap(), uiPartAddr, &cMv, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, rpcYuvPred, uiRShift, 0 );
    999 
    1000     return;
    1001   }
    1002 #endif
    1003 #if QC_ARP_D0177
    1004   if(
    1005 #if MERL_General_Fix // TODO: Maybe logically redundant, but easier to read. Need verification before being removed
    1006 #if MERL_VSP_C0152
    1007        vspIdx == 0 &&
    1008 #endif
    1009 #endif
    1010        pcCU->getSlice()->getSPS()->isDepth() == false
    1011     && pcCU->getSlice()->getSPS()->getViewId() > 0
    1012     && pcCU->getSlice()->getSPS()->getUseAdvRP() > 0
    1013     && pcCU->getARPW( uiPartAddr ) > 0
    1014     && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC()
    1015     && (pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N || pcCU->isSkipped(uiPartAddr))
    1016     )
    1017   {
    1018     xPredInterUniARP( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , rpcYuvPred , iPartIdx , bi );
    1019   }
    1020   else
    1021   {
    1022 #endif
    1023 #if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
    1024   if( pcCU->getSlice()->getSPS()->isDepth() )
    1025   {
    1026 #if MERL_VSP_C0152
    1027     if (vspIdx != 0)
    1028     { // depth, vsp compensation
    1029 #if !MERL_General_Fix
    1030       // get depth estimator here
    1031       TComPic* pRefPicBaseDepth = pcCU->getSlice()->getRefPicBaseDepth();
    1032       TComPicYuv* pcBaseViewDepthPicYuv = NULL;
    1033       if (vspIdx < 4) // spatial
    1034       {
    1035         pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
    1036       }
    1037       Int iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
    1038       Int iBlkY = ( pcCU->getAddr() / pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
    1039       Int* pShiftLUT;
    1040       Int iShiftPrec;
    1041       pcCU->getSlice()->getBWVSPLUTParam(pShiftLUT, iShiftPrec);
    1042       //using disparity to find the depth block of the base view as the depth block estimator of the current block
    1043       //using depth block estimator and base view texture to get Backward warping
    1044       xPredInterLumaBlkFromDM  ( pcBaseViewDepthPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,     pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
    1045       xPredInterChromaBlkFromDM( pcBaseViewDepthPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1,  pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
    1046 #else
    1047 #if MERL_Bi_VSP_D0166
    1048       xPredInterVSPBlk(pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, cMv, eRefPicList, rpcYuvPred, bi );
    1049 #else
    1050       xPredInterVSPBlk(pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, cMv, eRefPicList, rpcYuvPred, bi, vspIdx );
    1051 #endif
    1052 #endif
    1053     }
    1054     else
    1055     {
    1056 #endif
    1057       UInt uiRShift = ( bi ? 14-g_uiBitDepth-g_uiBitIncrement : 0 );
    1058       UInt uiOffset = bi ? IF_INTERNAL_OFFS : 0;
    1059 #if LGE_ILLUCOMP_DEPTH_C0046
    1060     Bool bICFlag = pcCU->getICFlag(uiPartAddr) && (pcCU->getSlice()->getRefViewId( eRefPicList, iRefIdx ) != pcCU->getSlice()->getViewId());
    1061 #endif
    1062 #if DEPTH_MAP_GENERATION
    1063     xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, 0, 0, rpcYuvPred, uiRShift, uiOffset
    1064 #if LGE_ILLUCOMP_DEPTH_C0046
    1065         , bICFlag
    1066 #endif
    1067         );
    1068 #else
    1069       xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, uiRShift, uiOffset );
    1070 #endif
    1071 #if MERL_VSP_C0152
    1072     }
    1073 #endif// MERL_VSP_C0152 //else
    1074   }
    1075   else  // texture
    1076   {
    1077 #endif
    1078 #if MERL_VSP_C0152
    1079     if ( vspIdx != 0 )
    1080     { // texture, vsp compensation
    1081 #if !MERL_General_Fix
    1082       TComPic*    pRefPicBaseTxt        = pcCU->getSlice()->getRefPicBaseTxt();
    1083       TComPicYuv* pcBaseViewTxtPicYuv   = pRefPicBaseTxt->getPicYuvRec();
    1084       TComPicYuv* pcBaseViewDepthPicYuv = NULL;
    1085       if (vspIdx < 4) // spatial
    1086       {
    1087         TComPic* pRefPicBaseDepth = pcCU->getSlice()->getRefPicBaseDepth();
    1088         pcBaseViewDepthPicYuv     = pRefPicBaseDepth->getPicYuvRec();
    1089       }
    1090       Int iBlkX = ( pcCU->getAddr() % pRefPicBaseTxt->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
    1091       Int iBlkY = ( pcCU->getAddr() / pRefPicBaseTxt->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
    1092       Int* pShiftLUT;
    1093       Int iShiftPrec;
    1094       pcCU->getSlice()->getBWVSPLUTParam(pShiftLUT, iShiftPrec);
    1095 
    1096       //using disparity to find the depth block of the base view as the depth block estimator of the current block
    1097       //using depth block estimator and base view texture to get Backward warping
    1098       xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
    1099       xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
    1100 #else
    1101 #if MERL_Bi_VSP_D0166
    1102       xPredInterVSPBlk(pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, cMv, eRefPicList, rpcYuvPred, bi );
    1103 #else
    1104       xPredInterVSPBlk(pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, cMv, eRefPicList, rpcYuvPred, bi, vspIdx );
    1105 #endif
    1106 #endif
    1107     }
    1108     else//texture not VSP
    1109     {
    1110 #endif //MERL_VSP_C0152
    1111 #if LGE_ILLUCOMP_B0045
    1112       Bool bICFlag = pcCU->getICFlag(uiPartAddr) && (pcCU->getSlice()->getRefViewId( eRefPicList, iRefIdx ) != pcCU->getSlice()->getViewId());
    1113 
    1114       xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, bICFlag);
    1115 #else
    1116       xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
    1117 #endif
    1118 #if MERL_VSP_C0152
    1119      } //texture not VSP
    1120 #endif
    1121 #if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
    1122   }
    1123 #endif
    1124 
    1125 #if MERL_VSP_C0152
    1126   if ( vspIdx == 0 )//Not VSP
    1127   {
    1128 #endif
    1129 #if LGE_ILLUCOMP_B0045
    1130   Bool bICFlag = pcCU->getICFlag(uiPartAddr) && (pcCU->getSlice()->getRefViewId( eRefPicList, iRefIdx ) != pcCU->getSlice()->getViewId());
    1131 
    1132   xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, bICFlag );
    1133 #else
    1134   xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
    1135 #endif
    1136 #if MERL_VSP_C0152
    1137    }
    1138 #endif
    1139 #if QC_ARP_D0177
    1140   }
    1141 #endif
    1142 }
    1143 
    1144 #if QC_ARP_D0177
    1145 Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bi, TComMvField * pNewMvFiled )
    1146 {
    1147   Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
    1148   TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
    1149   Bool        bTobeScaled = false;
    1150   UChar dW = pcCU->getARPW ( uiPartAddr );
    1151   TComPic* pcPicYuvBaseCol =  NULL;
    1152   TComPic* pcPicYuvBaseRef =  NULL;
     774  xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
     775  xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
     776#endif
     777
     778}
     779#endif
     780
     781#if H_3D_ARP
     782Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
     783{
     784  Int         iRefIdx      = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
     785  TComMv      cMv          = pNewMvFiled ? pNewMvFiled->getMv()     : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
     786  Bool        bTobeScaled  = false;
     787  TComPic* pcPicYuvBaseCol = NULL;
     788  TComPic* pcPicYuvBaseRef = NULL;
     789
     790#if H_3D_NBDV
    1153791  DisInfo cDistparity;
    1154 
    1155   if( pNewMvFiled )
    1156   {
    1157     iRefIdx = pNewMvFiled->getRefIdx();
    1158     cMv = pNewMvFiled->getMv();
    1159   }
    1160 
    1161 #if QC_CU_NBDV_D0181
    1162792  cDistparity.bDV           = pcCU->getDvInfo(uiPartAddr).bDV;
    1163793  if( cDistparity.bDV )
    1164794  {
    1165 #if MERL_VSP_C0152
    1166     cDistparity.m_acMvCand[0] = pcCU->getDvInfo(0).m_acMvCandNoRef[0];
     795    cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV;
     796    assert(pcCU->getDvInfo(uiPartAddr).bDV ==  pcCU->getDvInfo(0).bDV);
     797    cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
     798  }
    1167799#else
    1168     cDistparity.m_acMvCand[0] = pcCU->getDvInfo(0).m_acMvCand[0];
    1169 #endif
    1170     assert(pcCU->getDvInfo(uiPartAddr).bDV ==  pcCU->getDvInfo(0).bDV);
    1171     cDistparity.m_aVIdxCan[0] = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan[0];
    1172     cDistparity.iN            = pcCU->getDvInfo(uiPartAddr).iN;
    1173   }
    1174   else
    1175     cDistparity.iN    =  0;
    1176 #else
    1177   pcCU->getDisMvpCandNBDV( iPartIdx, uiPartAddr,  &cDistparity, false );
    1178 #endif
    1179 
    1180   dW = !cDistparity.iN ? 0: dW;
    1181   if( cDistparity.iN )
    1182   {
    1183     if(dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC()!= pcCU->getSlice()->getPOC())
     800  assert(0); // ARP can be applied only when a DV is available
     801#endif
     802
     803  UChar dW = cDistparity.bDV ? pcCU->getARPW ( uiPartAddr ) : 0;
     804
     805  if( cDistparity.bDV )
     806  {
     807    if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC()!= pcCU->getSlice()->getPOC() )
     808    {
    1184809      bTobeScaled = true;
    1185     pcPicYuvBaseCol =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(),                              cDistparity.m_aVIdxCan[0] );
    1186     pcPicYuvBaseRef =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC(), cDistparity.m_aVIdxCan[0] );
    1187     if( (!pcPicYuvBaseCol || pcPicYuvBaseCol->getPOC() != pcCU->getSlice()->getPOC()) || (!pcPicYuvBaseRef || pcPicYuvBaseRef->getPOC() != pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() ))
     810    }
     811
     812    pcPicYuvBaseCol =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(),                              cDistparity.m_aVIdxCan );
     813    pcPicYuvBaseRef =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC(), cDistparity.m_aVIdxCan );
     814   
     815    if( ( !pcPicYuvBaseCol || pcPicYuvBaseCol->getPOC() != pcCU->getSlice()->getPOC() ) || ( !pcPicYuvBaseRef || pcPicYuvBaseRef->getPOC() != pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() ) )
    1188816    {
    1189817      dW = 0;
     
    1191819    }
    1192820    else
     821    {
    1193822      assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() );
     823    }
     824
    1194825    if(bTobeScaled)
    1195826    {     
    1196       Int iCurrPOC = pcCU->getSlice()->getPOC();
     827      Int iCurrPOC    = pcCU->getSlice()->getPOC();
    1197828      Int iColRefPOC  = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx );
    1198829      Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList,  0);
    1199830      Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC);
    1200831      if ( iScale != 4096 )
     832      {
    1201833        cMv = cMv.scaleMv( iScale );
     834      }
    1202835      iRefIdx = 0;
    1203836    }
    1204837  }
     838
    1205839  pcCU->clipMv(cMv);
    1206840  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec();
    1207   xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
    1208 #if LGE_ILLUCOMP_B0045
    1209     , false
    1210 #endif
    1211     , true
    1212     );
    1213   xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
    1214 #if LGE_ILLUCOMP_B0045
    1215     , false
    1216 #endif
    1217     , true
    1218     );
     841  xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
     842  xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
     843
    1219844  if( dW > 0 )
    1220845  {
    1221     TComYuv * pYuvmB0 = &m_acYuvPredBase[0];
     846    TComYuv * pYuvB0 = &m_acYuvPredBase[0];
    1222847    TComYuv * pYuvB1  = &m_acYuvPredBase[1];
    1223     assert ( cDistparity.iN == 1 );
     848
     849    TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV;
     850    pcCU->clipMv(cMVwithDisparity);
     851
     852    assert ( cDistparity.bDV );
     853
    1224854    pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec();
    1225     xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acMvCand[0], iWidth, iHeight, pYuvB1, bi
    1226 #if LGE_ILLUCOMP_B0045
    1227       , false
    1228 #endif
    1229       ,  true
    1230       );
    1231     xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acMvCand[0], iWidth, iHeight, pYuvB1, bi
    1232 #if LGE_ILLUCOMP_B0045
    1233       , false
    1234 #endif
    1235       , true
    1236       );
     855    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
     856    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
     857   
    1237858    pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec();
    1238     TComMv cMVwithDisparity = cMv + cDistparity.m_acMvCand[0];
    1239     pcCU->clipMv(cMVwithDisparity);
    1240     xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvmB0, bi
    1241 #if LGE_ILLUCOMP_B0045
    1242       , false
    1243 #endif
    1244       , true
    1245       );
    1246     xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvmB0, bi
    1247 #if LGE_ILLUCOMP_B0045
    1248       , false
    1249 #endif
    1250       , true
    1251       );
    1252     pYuvB1->subtractARP( pYuvB1 , pYuvmB0 , uiPartAddr , iWidth , iHeight );
    1253     if(dW == 2)
    1254       pYuvB1->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
    1255     rpcYuvPred->addARP( rpcYuvPred , pYuvB1 , uiPartAddr , iWidth , iHeight , !bi );
    1256   }
    1257 }
    1258 #endif
    1259 
    1260 #if MERL_VSP_C0152
    1261 Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap )
    1262 #else
    1263 Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap )
    1264 #endif
     859    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
     860    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
     861
     862    pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight );
     863
     864    if( 2 == dW )
     865    {
     866      pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
     867    }
     868    rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi );
     869  }
     870}
     871#endif
     872
     873Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
    1265874{
    1266875  TComYuv* pcMbYuv;
    1267876  Int      iRefIdx[2] = {-1, -1};
    1268877
    1269 #if MERL_Bi_VSP_D0166
    1270   Bool biDecision = 0;
    1271   Int  predDirVSP = 0;
    1272 #if QC_BVSP_CleanUP_D0191
    1273   RefPicList privateRefPicList = REF_PIC_LIST_0;
    1274 #endif
    1275   if (pcCU->getVSPIndex(uiPartAddr) != 0) // is VSP
    1276   {
    1277     Int biVSPAvail = 0;
    1278     //test whether VSP is Bi or Uni
    1279     //Step1. Get derived DV view id
    1280 #if QC_BVSP_CleanUP_D0191
    1281     RefPicList otherRefPicList = REF_PIC_LIST_1;
    1282     Int refIdxList0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr );
    1283     Int refIdxList1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr );
    1284     privateRefPicList = refIdxList0 != NOT_VALID ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
    1285     if(privateRefPicList == REF_PIC_LIST_1 && refIdxList1==NOT_VALID )
    1286     {
    1287       assert(0);
    1288     }
    1289     Int privateRefIdx = privateRefPicList == REF_PIC_LIST_0 ? refIdxList0 : refIdxList1;
    1290     Int viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, privateRefIdx);
    1291     Int refPoc = pcCU->getSlice()->getRefPOC(privateRefPicList, privateRefIdx);
    1292 #else
    1293     Int  refIdx = pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
    1294     RefPicList privateRefPicList = (RefPicList) pcCU->getVSPDir( uiPartAddr );
    1295     RefPicList otherRefPicList = privateRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
    1296     assert(privateRefPicList == REF_PIC_LIST_0 || privateRefPicList == REF_PIC_LIST_1);
    1297     Int  refIdx = -1-pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
    1298     assert(refIdx >= 0);
    1299     Int  viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, refIdx);
    1300     Int  refPoc = pcCU->getSlice()->getRefPOC(privateRefPicList, refIdx);
    1301 #endif
    1302     assert(refPoc == pcCU->getSlice()->getPOC());
    1303 //    if(refPoc != pcCU->getSlice()->getPOC() )
    1304 //    {
    1305 //      printf("refPOC= %d, and current POC=%d\n", refPoc, pcCU->getSlice()->getPOC() );
    1306 //    }
    1307     //Step 2. Get initial prediction direction value according to reference picture list availability
    1308     Int iInterDir = ((pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0) > 0 && pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_1) > 0) ? 3 :
    1309       (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_0) > 0 ? 1 : 2));
    1310     //Step 3.  Check the availability of Bi VSP by checking the interview reference availability in the other reference list
    1311     if(iInterDir == 3)
    1312     {
    1313       for (Int jRefIdx = 0; jRefIdx <pcCU->getSlice()->getNumRefIdx(otherRefPicList); jRefIdx++ )
    1314       {
    1315         Int refViewIdx  = pcCU->getSlice()->getRefViewId( otherRefPicList, jRefIdx);
    1316         if ( (refViewIdx != pcCU->getSlice()->getViewId()) && (refViewIdx != viewId ) )
    1317         {
    1318           biVSPAvail = 1;
    1319           break;
    1320         }
    1321       }
    1322     }
    1323     //Step 4. Update the Bi VSP prediction direction
    1324     if ( iInterDir == 3 && biVSPAvail == 1)
    1325     {
    1326       biDecision   = 1;
    1327       predDirVSP = 3;
    1328     }
    1329     else
    1330     {
    1331       biDecision = 0;
    1332       if ( privateRefPicList == REF_PIC_LIST_0 )
    1333         predDirVSP = 1;
    1334       else
    1335         predDirVSP = 2;
    1336     }
    1337   }
    1338   else
    1339   {//not VSP
    1340     if( ( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 ) )
    1341       biDecision = 1;
    1342     else
    1343       biDecision = 0;
    1344   }
    1345 #endif
    1346 
    1347878  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
    1348879  {
     
    1350881    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
    1351882
    1352 #if MERL_VSP_C0152
    1353     if(!pcCU->getVSPIndex(uiPartAddr))
    1354     {
    1355       if ( iRefIdx[iRefList] < 0 )
    1356       {
    1357         continue;
    1358       }
     883    if ( iRefIdx[iRefList] < 0 )
     884    {
     885      continue;
     886    }
     887
     888    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
     889
     890    pcMbYuv = &m_acYuvPred[iRefList];
     891    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
     892    {
     893      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
    1359894    }
    1360895    else
    1361896    {
    1362 
    1363 #if !MERL_Bi_VSP_D0166 //both lists should go
    1364       if ( iRefList == REF_PIC_LIST_1 && iRefIdx[iRefList] < 0 ) // iRefIdx[iRefList] ==NOT_VALID
    1365       {
    1366         continue;
    1367       }
    1368 #else
    1369       //Reference list loop termination
    1370 #if QC_BVSP_CleanUP_D0191
    1371       RefPicList privateVSPRefPicList = privateRefPicList;
    1372 #else
    1373       RefPicList privateVSPRefPicList = (RefPicList) pcCU->getVSPDir( uiPartAddr );
    1374 #endif
    1375       if( (pcCU->getVSPIndex(uiPartAddr)!=0) &&  iRefList != privateVSPRefPicList && !biDecision  )
    1376       {//when VSP mode, if it is uni prediction, the other reference list should skip
    1377         continue;
    1378       }
    1379 #endif
    1380 
    1381     }
    1382 #else
     897      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) ||
     898           ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
     899      {
     900        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
     901      }
     902      else
     903      {
     904        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
     905      }
     906    }
     907  }
     908
     909  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE  )
     910  {
     911    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
     912  } 
     913  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
     914  {
     915    xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred );
     916  }
     917  else
     918  {
     919    xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
     920  }
     921}
     922
     923#if H_3D_VSP
     924
     925Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
     926{
     927  TComYuv* pcMbYuv;
     928  Int      iRefIdx[2] = {-1, -1};
     929  Bool     bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0);
     930
     931  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
     932  {
     933    RefPicList eRefPicList = RefPicList(iRefList);
     934    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
     935
    1383936    if ( iRefIdx[iRefList] < 0 )
    1384     {
    1385937      continue;
    1386     }
    1387 #endif
    1388 
    1389938    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
    1390939
    1391940    pcMbYuv = &m_acYuvPred[iRefList];
    1392 
    1393 #if MERL_Bi_VSP_D0166
    1394     if(biDecision == 1)
    1395 #else
    1396     if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
    1397 #endif
    1398     {
    1399 #if MERL_VSP_C0152
    1400       xPredInterUni ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
    1401 #else
    1402       xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
    1403 #endif
    1404     }
    1405     else
    1406     {
    1407 #if FIX_LGE_WP_FOR_3D_C0223
    1408       if ( ( pcCU->getSlice()->getPPS()->getUseWP()      && pcCU->getSlice()->getSliceType() == P_SLICE ) ||
    1409          ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
    1410 #else
    1411       if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() )
    1412 #endif
    1413       {
    1414 #if MERL_VSP_C0152
    1415         xPredInterUni ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
    1416 #else
    1417         xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
    1418 #endif
    1419       }
    1420       else
    1421       {
    1422 #if MERL_VSP_C0152
    1423         xPredInterUni ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
    1424 #else
    1425         xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
    1426 #endif
    1427       }
    1428     }
    1429   }
    1430 #if FIX_LGE_WP_FOR_3D_C0223
    1431   if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() && pcCU->getSlice()->getSliceType() == B_SLICE  )
    1432 #else
    1433   if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() )
    1434 #endif
    1435   {
    1436 #if MERL_VSP_C0152
    1437 #if !MERL_Bi_VSP_D0166
    1438     if(pcCU->getVSPIndex(uiPartAddr))
    1439       m_acYuvPred[0].copyPartToPartYuv( rpcYuvPred, uiPartAddr, iWidth, iHeight );
    1440     else
    1441 #endif
    1442 #endif
    1443     xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
    1444   }
    1445 #if FIX_LGE_WP_FOR_3D_C0223
    1446   else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
    1447 
    1448   {
    1449 #if MERL_VSP_C0152
    1450 #if !MERL_Bi_VSP_D0166
    1451     if(pcCU->getVSPIndex(uiPartAddr))
    1452       m_acYuvPred[0].copyPartToPartYuv( rpcYuvPred, uiPartAddr, iWidth, iHeight );
    1453     else
    1454 #endif
    1455 #endif
    1456       xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred, iPartIdx );
    1457   }
    1458 #endif
    1459   else
    1460   {
    1461     if ( bPrdDepthMap )
    1462     {
    1463       xWeightedAveragePdm( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred, uiSubSampExpX, uiSubSampExpY );
    1464     }
    1465     else
    1466     {
    1467 #if MERL_VSP_C0152
    1468 #if !MERL_Bi_VSP_D0166
    1469       if(pcCU->getVSPIndex(uiPartAddr))
    1470         m_acYuvPred[0].copyPartToPartYuv( rpcYuvPred, uiPartAddr, iWidth, iHeight );
    1471       else
    1472         xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
    1473 #else
    1474       xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred, predDirVSP );
    1475 #endif
    1476 #else
    1477       xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
    1478 #endif
    1479     }
    1480   }
    1481 }
    1482 
    1483 
    1484 
    1485 Void
    1486 TComPrediction::xPredInterPrdDepthMap( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY, TComYuv*& rpcYuv, UInt uiRShift, UInt uiOffset
    1487 #if LGE_ILLUCOMP_DEPTH_C0046
    1488 , Bool bICFlag
    1489 #endif
    1490 )
    1491 {
    1492   Int     iShiftX     = 2 + uiSubSampExpX;
    1493   Int     iShiftY     = 2 + uiSubSampExpY;
    1494   Int     iAddX       = ( 1 << iShiftX ) >> 1;
    1495   Int     iAddY       = ( 1 << iShiftY ) >> 1;
    1496   Int     iHor        = ( pcMv->getHor() + iAddX ) >> iShiftX;
    1497   Int     iVer        = ( pcMv->getVer() + iAddY ) >> iShiftY;
    1498 #if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
    1499   if( pcCU->getSlice()->getSPS()->isDepth() )
    1500   {
    1501     iHor = pcMv->getHor();
    1502     iVer = pcMv->getVer();
    1503   }
    1504 #endif
    1505   Int     iRefStride  = pcPicYuvRef->getStride();
    1506   Int     iDstStride  = rpcYuv->getStride();
    1507   Int     iRefOffset  = iHor + iVer * iRefStride;
    1508 
    1509   Pel*    piRefY      = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
    1510   Pel*    piDstY      = rpcYuv->getLumaAddr( uiPartAddr );
    1511 
    1512   for( Int y = 0; y < iHeight; y++, piDstY += iDstStride, piRefY += iRefStride )
    1513   {
    1514     for( Int x = 0; x < iWidth; x++ )
    1515     {
    1516       piDstY[ x ] = ( piRefY[ x ] << uiRShift ) - uiOffset;
    1517     }
    1518   }
    1519 
    1520 #if LGE_ILLUCOMP_DEPTH_C0046
    1521   if(bICFlag)
    1522   {
    1523     Int a, b, iShift;
    1524     TComMv tTmpMV(pcMv->getHor()<<2, pcMv->getVer()<<2);
    1525 
    1526     piRefY      = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
    1527     piDstY      = rpcYuv->getLumaAddr( uiPartAddr );
    1528 
    1529     xGetLLSICPrediction(pcCU, &tTmpMV, pcPicYuvRef, a, b, iShift);
    1530 
    1531     for( Int y = 0; y < iHeight; y++, piDstY += iDstStride, piRefY += iRefStride )
    1532     {
    1533       for( Int x = 0; x < iWidth; x++ )
    1534       {
    1535         if(uiOffset)
    1536         {
    1537           Int iIFshift = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement );
    1538           piDstY[ x ] = ( (a*piDstY[ x ]+a*IF_INTERNAL_OFFS) >> iShift ) + b*(1<<iIFshift) - IF_INTERNAL_OFFS;
    1539         }
    1540         else
    1541           piDstY[ x ] = Clip( ( (a*piDstY[ x ]) >> iShift ) + b );
    1542       }
    1543     }
    1544   }
    1545 #endif
    1546 }
    1547 
     941    xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi );
     942  }
     943
     944  xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
     945}
     946
     947#endif
    1548948
    1549949/**
     
    1559959 * \param bi       Flag indicating whether bipred is used
    1560960 */
    1561 #if LGE_ILLUCOMP_B0045
    1562 Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi, Bool bICFlag
    1563 #if QC_ARP_D0177
    1564     ,
    1565     Int filterType
    1566 #endif
    1567     )
    1568 #else
    1569 Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
    1570 #if QC_ARP_D0177
    1571     ,
    1572     Int filterType
    1573 #endif
    1574     )
    1575 #endif
     961Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
     962#if H_3D_ARP
     963    , Bool filterType
     964#endif
     965#if H_3D_IC
     966    , Bool bICFlag
     967#endif
     968  )
    1576969{
    1577970  Int refStride = refPic->getStride(); 
     
    1585978  Int yFrac = mv->getVer() & 0x3;
    1586979
    1587 #if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
    1588   assert( ! cu->getSlice()->getIsDepth() || ( xFrac == 0 && yFrac == 0 ) );
    1589 #endif
    1590 
     980#if H_3D_IC
     981  if( cu->getSlice()->getIsDepth() )
     982  {
     983    refOffset = mv->getHor() + mv->getVer() * refStride;
     984    ref       = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
     985    xFrac     = 0;
     986    yFrac     = 0;
     987  }
     988#endif
    1591989  if ( yFrac == 0 )
    1592990  {
    1593     m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi
    1594 #if QC_ARP_D0177
    1595     ,
    1596     filterType
    1597 #endif
    1598     );
     991#if MTK_CLIPPING_ALIGN_IC_E0168
     992    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi || bICFlag
     993#else
     994    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi
     995#endif
     996#if H_3D_ARP
     997    , filterType
     998#endif
     999      );
    15991000  }
    16001001  else if ( xFrac == 0 )
    16011002  {
    1602     m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi
    1603 #if QC_ARP_D0177
    1604     ,
    1605     filterType
    1606 #endif
    1607     );
     1003#if MTK_CLIPPING_ALIGN_IC_E0168
     1004    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag
     1005#else
     1006    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi
     1007#endif
     1008#if H_3D_ARP
     1009    , filterType
     1010#endif
     1011      );
    16081012  }
    16091013  else
     
    16161020
    16171021    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     
    1618  #if QC_ARP_D0177
    1619     ,
    1620     filterType
     1022#if H_3D_ARP
     1023    , filterType
    16211024#endif
    1622     );
     1025      );
     1026#if MTK_CLIPPING_ALIGN_IC_E0168
     1027    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi || bICFlag
     1028#else
    16231029    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi
    1624  #if QC_ARP_D0177
    1625     ,
    1626     filterType
     1030#endif
     1031#if H_3D_ARP
     1032    , filterType
    16271033#endif
    1628     );   
    1629   }
    1630 
    1631 #if LGE_ILLUCOMP_B0045
    1632   if(bICFlag)
    1633   {
     1034      );   
     1035  }
     1036
     1037#if H_3D_IC
     1038  if( bICFlag )
     1039  {
     1040#if SHARP_ILLUCOMP_REFINE_E0046
     1041    Int a, b, i, j;
     1042    const Int iShift = IC_CONST_SHIFT;
     1043
     1044    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA );
     1045#else
    16341046    Int a, b, iShift, i, j;
    16351047
    1636     xGetLLSICPrediction(cu, mv, refPic, a, b, iShift);
    1637 
    1638     for (i = 0; i < height; i++)
    1639     {
    1640       for (j = 0; j < width; j++)
    1641       {
    1642         if(bi)
     1048    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_LUMA );
     1049#endif
     1050
     1051
     1052    for ( i = 0; i < height; i++ )
     1053    {
     1054      for ( j = 0; j < width; j++ )
     1055      {
     1056#if !MTK_CLIPPING_ALIGN_IC_E0168
     1057        if( bi )
    16431058        {
    1644           Int iIFshift = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement );
    1645           dst[j] = ( (a*dst[j]+a*IF_INTERNAL_OFFS) >> iShift ) + b*(1<<iIFshift) - IF_INTERNAL_OFFS;
     1059          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthY;
     1060          dst[j] = ( ( a*dst[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1 << iIFshift ) - IF_INTERNAL_OFFS;
    16461061        }
    16471062        else
    1648           dst[j] = Clip( ( (a*dst[j]) >> iShift ) + b );
     1063#endif
     1064          dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
    16491065      }
    16501066      dst += dstStride;
    16511067    }
     1068#if MTK_CLIPPING_ALIGN_IC_E0168
     1069    if(bi)
     1070    {
     1071      Pel *dst2      = dstPic->getLumaAddr( partAddr );
     1072      Int shift = IF_INTERNAL_PREC - g_bitDepthY;
     1073      for (i = 0; i < height; i++)
     1074      {
     1075        for (j = 0; j < width; j++)
     1076        {
     1077          Short val = dst2[j] << shift;
     1078          dst2[j] = val - (Short)IF_INTERNAL_OFFS;
     1079        }
     1080        dst2 += dstStride;
     1081      }
     1082    }
     1083#endif
    16521084  }
    16531085#endif
     
    16661098 * \param bi       Flag indicating whether bipred is used
    16671099 */
    1668 #if LGE_ILLUCOMP_B0045
    1669 Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi, Bool bICFlag
    1670 #if QC_ARP_D0177
    1671     ,
    1672     Int filterType
    1673 #endif   
    1674     )
    1675 #else
    1676 Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
    1677 #if QC_ARP_D0177
    1678   , Int filterType
     1100Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
     1101#if H_3D_ARP
     1102    , Bool filterType
     1103#endif
     1104#if H_3D_IC
     1105    , Bool bICFlag
    16791106#endif
    16801107  )
    1681 #endif
    16821108{
    16831109  Int     refStride  = refPic->getCStride();
     
    17061132  if ( yFrac == 0 )
    17071133  {
     1134#if MTK_CLIPPING_ALIGN_IC_E0168
     1135    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
     1136#else
    17081137    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi
    1709 #if QC_ARP_D0177
    1710     ,
    1711     filterType
    1712 #endif   
     1138#endif
     1139#if H_3D_ARP
     1140    , filterType
     1141#endif
    17131142    );   
     1143#if MTK_CLIPPING_ALIGN_IC_E0168
     1144    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
     1145#else
    17141146    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi
    1715 #if QC_ARP_D0177
    1716     ,
    1717     filterType
    1718 #endif   
    1719     );   
     1147#endif
     1148#if H_3D_ARP
     1149    , filterType
     1150#endif
     1151    );
    17201152  }
    17211153  else if ( xFrac == 0 )
    17221154  {
     1155#if MTK_CLIPPING_ALIGN_IC_E0168
     1156    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
     1157#else
    17231158    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi
    1724  #if QC_ARP_D0177
    1725     ,
    1726     filterType
    1727 #endif   
    1728     );   
     1159#endif
     1160#if H_3D_ARP
     1161    , filterType
     1162#endif
     1163    );
     1164#if MTK_CLIPPING_ALIGN_IC_E0168
     1165    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
     1166#else
    17291167    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi
    1730  #if QC_ARP_D0177
    1731     ,
    1732     filterType
    1733 #endif   
    1734     );   
     1168#endif
     1169#if H_3D_ARP
     1170    , filterType
     1171#endif
     1172    );
    17351173  }
    17361174  else
    17371175  {
    17381176    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
    1739 #if QC_ARP_D0177
    1740     ,
    1741     filterType
    1742 #endif   
    1743     );
     1177#if H_3D_ARP
     1178    , filterType
     1179#endif 
     1180      );
     1181#if MTK_CLIPPING_ALIGN_IC_E0168
     1182    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
     1183#else
    17441184    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
    1745 #if QC_ARP_D0177
    1746     ,
    1747     filterType
    1748 #endif  
    1749     );
     1185#endif
     1186#if H_3D_ARP
     1187    , filterType
     1188#endif
     1189      );
    17501190   
    17511191    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
    1752 #if QC_ARP_D0177
    1753     ,
    1754     filterType
    1755 #endif   
    1756     );
     1192#if H_3D_ARP
     1193    , filterType
     1194#endif
     1195      );
     1196#if MTK_CLIPPING_ALIGN_IC_E0168
     1197    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
     1198#else
    17571199    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
    1758 #if QC_ARP_D0177
    1759     ,
    1760     filterType
    1761 #endif   
    1762     );   
    1763   }
    1764 #if LGE_ILLUCOMP_B0045
    1765   if(bICFlag)
    1766   {
     1200#endif
     1201#if H_3D_ARP
     1202    , filterType
     1203#endif
     1204      );   
     1205  }
     1206
     1207#if H_3D_IC
     1208  if( bICFlag )
     1209  {
     1210#if SHARP_ILLUCOMP_REFINE_E0046
     1211    Int a, b, i, j;
     1212    const Int iShift = IC_CONST_SHIFT;
     1213    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb
     1214#else
    17671215    Int a, b, iShift, i, j;
    1768     xGetLLSICPredictionChroma(cu, mv, refPic, a, b, iShift, 0); // Cb
    1769     for (i = 0; i < cxHeight; i++)
    1770     {
    1771       for (j = 0; j < cxWidth; j++)
    1772       {
    1773         if(bi)
     1216    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_U ); // Cb
     1217#endif
     1218    for ( i = 0; i < cxHeight; i++ )
     1219    {
     1220      for ( j = 0; j < cxWidth; j++ )
     1221      {
     1222#if !MTK_CLIPPING_ALIGN_IC_E0168
     1223        if( bi )
    17741224        {
    1775           Int iIFshift = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement );
    1776           dstCb[j] = ( (a*dstCb[j]+a*IF_INTERNAL_OFFS) >> iShift ) + b*(1<<iIFshift) - IF_INTERNAL_OFFS;
     1225          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC;
     1226          dstCb[j] = ( ( a*dstCb[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS;
    17771227        }
    17781228        else
    1779           dstCb[j] = Clip3(0, 255, ((a*dstCb[j])>>iShift)+b);
     1229#endif
     1230          dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
    17801231      }
    17811232      dstCb += dstStride;
    17821233    }
    1783 
    1784     xGetLLSICPredictionChroma(cu, mv, refPic, a, b, iShift, 1); // Cr
    1785     for (i = 0; i < cxHeight; i++)
    1786     {
    1787       for (j = 0; j < cxWidth; j++)
    1788       {
    1789         if(bi)
     1234#if SHARP_ILLUCOMP_REFINE_E0046
     1235    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr
     1236#else
     1237    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_V ); // Cr
     1238#endif
     1239    for ( i = 0; i < cxHeight; i++ )
     1240    {
     1241      for ( j = 0; j < cxWidth; j++ )
     1242      {
     1243#if !MTK_CLIPPING_ALIGN_IC_E0168
     1244        if( bi )
    17901245        {
    1791           Int iIFshift = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement );
    1792           dstCr[j] = ( (a*dstCr[j]+a*IF_INTERNAL_OFFS) >> iShift ) + b*(1<<iIFshift) - IF_INTERNAL_OFFS;
     1246          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC;
     1247          dstCr[j] = ( ( a*dstCr[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS;
    17931248        }
    17941249        else
    1795           dstCr[j] = Clip3(0, 255, ((a*dstCr[j])>>iShift)+b);
     1250#endif
     1251          dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
    17961252      }
    17971253      dstCr += dstStride;
    17981254    }
    1799   }
    1800 #endif
    1801 }
    1802 
    1803 #if MERL_VSP_C0152
    1804 // Input:
    1805 // refPic: Ref picture. Full picture, with padding
    1806 // posX, posY:     PU position, texture
    1807 // sizeX, sizeY: PU size
    1808 // partAddr: z-order index
    1809 // mv: disparity vector. derived from neighboring blocks
    1810 //
    1811 // Output: dstPic, PU predictor 64x64
    1812 Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv* mv, UInt partAddr,Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth
    1813 #if !MERL_Bi_VSP_D0166
    1814                                             , Int vspIdx
    1815 #endif
    1816                                             , TComYuv *&dstPic
    1817 #if MERL_Bi_VSP_D0166
    1818                                             , Bool bi
    1819 #endif         
    1820                                             )
    1821 {
    1822   Int widthLuma;
    1823   Int heightLuma;
    1824 
    1825   if (isDepth)
    1826   {
    1827     widthLuma   =  pPicBaseDepth->getWidth();
    1828     heightLuma  =  pPicBaseDepth->getHeight();
    1829   }
    1830   else
    1831   {
    1832     widthLuma   =  refPic->getWidth();
    1833     heightLuma  =  refPic->getHeight();
    1834   }
    1835 
    1836 #if MERL_VSP_BLOCKSIZE_C0152 != 1
    1837   Int widthDepth  = pPicBaseDepth->getWidth();
    1838   Int heightDepth = pPicBaseDepth->getHeight();
    1839 #endif
    1840 
    1841 #if MERL_CVSP_D0165
    1842   Int widthDepth  = pPicBaseDepth->getWidth();
    1843   Int heightDepth = pPicBaseDepth->getHeight();
    1844 #endif
    1845 
    1846   Int nTxtPerDepthX = widthLuma  / ( pPicBaseDepth->getWidth() );  // texture pixel # per depth pixel
    1847   Int nTxtPerDepthY = heightLuma / ( pPicBaseDepth->getHeight() );
    1848 
    1849   Int refStride = refPic->getStride();
    1850   Int dstStride = dstPic->getStride();
    1851   Int depStride =  pPicBaseDepth->getStride();
    1852 #if LGE_ROUND_OFFSET_D0135
    1853   Int depthPosX = Clip3(0,   widthLuma - sizeX,  (posX/nTxtPerDepthX) + ((mv->getHor()+2)>>2));
    1854   Int depthPosY = Clip3(0,   heightLuma- sizeY,  (posY/nTxtPerDepthY) + ((mv->getVer()+2)>>2));
    1855 #else
    1856   Int depthPosX = Clip3(0,   widthLuma - sizeX,  (posX/nTxtPerDepthX) + (mv->getHor()>>2));
    1857   Int depthPosY = Clip3(0,   heightLuma- sizeY,  (posY/nTxtPerDepthY) + (mv->getVer()>>2));
    1858 #endif
    1859   Pel *ref    = refPic->getLumaAddr() + posX + posY * refStride;
    1860   Pel *dst    = dstPic->getLumaAddr(partAddr);
    1861   Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;
    1862 
    1863 #if MERL_VSP_BLOCKSIZE_C0152 != 1
    1864 #if MERL_VSP_BLOCKSIZE_C0152 == 2
    1865   Int  dW = sizeX>>1;
    1866   Int  dH = sizeY>>1;
    1867 #endif
    1868 #if MERL_VSP_BLOCKSIZE_C0152 == 4
    1869   Int  dW = sizeX>>2;
    1870   Int  dH = sizeY>>2;
    1871 #endif
    1872   {
    1873     Pel* depthi = depth;
    1874     for (Int j = 0; j < dH; j++)
    1875     {
    1876       for (Int i = 0; i < dW; i++)
    1877       {
    1878         Pel* depthTmp;
    1879 #if MERL_VSP_BLOCKSIZE_C0152 == 2
    1880         if (depthPosX + (i<<1) < widthDepth)
    1881           depthTmp = depthi + (i << 1);
    1882         else
    1883           depthTmp = depthi + (widthDepth - depthPosX - 1);
    1884 #endif
    1885 #if MERL_VSP_BLOCKSIZE_C0152 == 4
    1886         if (depthPosX + (i<<2) < widthDepth)
    1887           depthTmp = depthi + (i << 2);
    1888         else
    1889           depthTmp = depthi + (widthDepth - depthPosX - 1);
    1890 #endif
    1891         Int maxV = 0;
    1892 #if MTK_DEPTH_TO_DISP_D0138
    1893         for (Int blockj = 0; blockj < MERL_VSP_BLOCKSIZE_C0152; blockj+=(MERL_VSP_BLOCKSIZE_C0152-1))
    1894 #else
    1895         for (Int blockj = 0; blockj < MERL_VSP_BLOCKSIZE_C0152; blockj++)
    1896 #endif
     1255#if MTK_CLIPPING_ALIGN_IC_E0168
     1256    if(bi)
     1257    {
     1258      Pel* dstCb2 = dstPic->getCbAddr( partAddr );
     1259      Pel* dstCr2 = dstPic->getCrAddr( partAddr );
     1260      Int shift = IF_INTERNAL_PREC - g_bitDepthC;
     1261      for (i = 0; i < cxHeight; i++)
     1262      {
     1263        for (j = 0; j < cxWidth; j++)
    18971264        {
    1898           Int iX = 0;
    1899 #if MTK_DEPTH_TO_DISP_D0138
    1900           for (Int blocki = 0; blocki < MERL_VSP_BLOCKSIZE_C0152; blocki+=(MERL_VSP_BLOCKSIZE_C0152-1))
    1901 #else
    1902           for (Int blocki = 0; blocki < MERL_VSP_BLOCKSIZE_C0152; blocki++)
    1903 #endif
    1904           {
    1905             if (maxV < depthTmp[iX])
    1906               maxV = depthTmp[iX];
    1907 #if MERL_VSP_BLOCKSIZE_C0152 == 2
    1908             if (depthPosX + (i<<1) + blocki < widthDepth - 1)
    1909 #else // MERL_VSP_BLOCKSIZE_C0152 == 4
    1910             if (depthPosX + (i<<2) + blocki < widthDepth - 1)
    1911 #endif
    1912 
    1913 #if NCKU_BUG_FIX
    1914     iX = (MERL_VSP_BLOCKSIZE_C0152-1);
    1915 #else
    1916     iX++;
    1917 #endif
    1918           }
    1919 #if MERL_VSP_BLOCKSIZE_C0152 == 2
    1920           if (depthPosY + (j<<1) + blockj < heightDepth - 1)
    1921 #else // MERL_VSP_BLOCKSIZE_C0152 == 4
    1922           if (depthPosY + (j<<2) + blockj < heightDepth - 1)
    1923 #endif
    1924 #if NCKU_BUG_FIX
    1925     depthTmp += depStride * (MERL_VSP_BLOCKSIZE_C0152-1);
    1926 #else
    1927     depthTmp += depStride;
    1928 #endif
    1929         }
    1930         m_pDepth[i+j*dW] = maxV;
    1931       } // end of i < dW
    1932 #if MERL_VSP_BLOCKSIZE_C0152 == 2
    1933       if (depthPosY + ((j+1)<<1) < heightDepth)
    1934         depthi += (depStride << 1);
    1935       else
    1936         depthi  = depth + (heightDepth-depthPosY-1)*depStride;
    1937 #endif
    1938 #if MERL_VSP_BLOCKSIZE_C0152 == 4
    1939       if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
    1940         depthi += (depStride << 2);
    1941       else
    1942         depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
    1943 #endif
    1944     }
    1945   }
    1946 #endif
    1947  
    1948 #if MERL_General_Fix
    1949 #if MERL_VSP_BLOCKSIZE_C0152 == 1
    1950 #if MERL_CVSP_D0165
    1951   //get LUT based horizontal reference range
    1952   Int range = 0;
    1953   if( sizeX == 4 && sizeY == 8 )
    1954     range = m_iRangeLuma[0];
    1955   else if( sizeX == 8 && sizeY == 4 )
    1956     range = m_iRangeLuma[1];
    1957   else if( sizeX == 8 && sizeY == 8 )
    1958     range = m_iRangeLuma[2];
    1959   else if( sizeX == 8 && sizeY == 16 )
    1960     range = m_iRangeLuma[3];
    1961   else if( sizeX == 16 && sizeY == 8 )
    1962     range = m_iRangeLuma[4];
    1963   else if( sizeX == 16 && sizeY == 16 )
    1964     range = m_iRangeLuma[5];
    1965   else if( sizeX == 16 && sizeY == 32 )
    1966     range = m_iRangeLuma[6];
    1967   else if( sizeX == 32 && sizeY == 16 )
    1968     range = m_iRangeLuma[7];
    1969   else if( sizeX == 32 && sizeY == 32 )
    1970     range = m_iRangeLuma[8];
    1971   else if( sizeX == 32 && sizeY == 64 )
    1972     range = m_iRangeLuma[9];
    1973   else if( sizeX == 64 && sizeY == 32 )
    1974     range = m_iRangeLuma[10];
    1975   else if( sizeX == 64 && sizeY == 64 )
    1976     range = m_iRangeLuma[11];
    1977   else
    1978     assert(0);
    1979 
    1980   // The minimum depth value
    1981   Int minRelativePos = 5000;
    1982   Int maxRelativePos = -5000;
    1983 
    1984   Pel* depthTemp, *depthInitial=depth;
    1985   for (Int yTxt =0; yTxt<sizeY; yTxt++)
    1986   {
    1987     for (Int xTxt =0; xTxt<sizeX; xTxt++)
    1988     {
    1989       if (depthPosX+xTxt < widthDepth)
    1990         depthTemp = depthInitial + xTxt;
    1991       else
    1992         depthTemp = depthInitial + (widthDepth - depthPosX - 1);
    1993 
    1994       Int disparity = pShiftLUT[ *depthTemp ] << iShiftPrec;
    1995       Int disparityInt = disparity >> 2;
    1996 
    1997       if( disparity <= 0)
    1998       {
    1999         if (minRelativePos > disparityInt+xTxt)
    2000             minRelativePos = disparityInt+xTxt;
    2001       }
    2002       else
    2003       {
    2004         if (maxRelativePos < disparityInt+xTxt)
    2005             maxRelativePos = disparityInt+xTxt;
    2006       }
    2007     }
    2008     if (depthPosY+yTxt < heightDepth)
    2009       depthInitial = depthInitial + depStride;
    2010   }
    2011 
    2012   Int disparity_tmp = pShiftLUT[ *depth ] << iShiftPrec;
    2013   if (disparity_tmp <= 0)
    2014     maxRelativePos = minRelativePos + range -1 ;
    2015   else
    2016     minRelativePos = maxRelativePos - range +1 ;
    2017 #endif
    2018 #endif
    2019 #endif
    2020 
    2021 #if MERL_VSP_BLOCKSIZE_C0152 != 1
    2022   Int yDepth = 0;
    2023 #endif
    2024   for ( Int yTxt = 0; yTxt < sizeY; yTxt += nTxtPerDepthY )
    2025   {
    2026     for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth++ )
    2027     {
    2028       Pel repDepth = 0; // to store the depth value used for warping
    2029 #if MERL_VSP_BLOCKSIZE_C0152 == 1
    2030       repDepth = depth[xDepth];
    2031 #endif
    2032 #if MERL_VSP_BLOCKSIZE_C0152 == 2
    2033       repDepth = m_pDepth[(xTxt>>1) + (yTxt>>1)*dW];
    2034 #endif
    2035 #if MERL_VSP_BLOCKSIZE_C0152 == 4
    2036       repDepth = m_pDepth[(xTxt>>2) + (yTxt>>2)*dW];
    2037 #endif
    2038 
    2039       assert( repDepth >= 0 && repDepth <= 255 );
    2040       Int disparity = pShiftLUT[ repDepth ] << iShiftPrec;
    2041       Int refOffset = xTxt + (disparity >> 2);
    2042       Int xFrac = disparity & 0x3;
    2043 #if MERL_CVSP_D0165
    2044       if(refOffset<minRelativePos || refOffset>maxRelativePos)
    2045         xFrac = 0;
    2046       refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
    2047 #endif
    2048       Int absX  = posX + refOffset;
    2049 
    2050       if (xFrac == 0)
    2051         absX = Clip3(0, widthLuma-1, absX);
    2052       else
    2053         absX = Clip3(4, widthLuma-5, absX);
    2054 
    2055       refOffset = absX - posX;
    2056 
    2057       assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
    2058 #if MERL_Bi_VSP_D0166
    2059       m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi );
    2060 #else
    2061       m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, true );
    2062 #endif
    2063 
    2064     }
    2065     ref   += refStride*nTxtPerDepthY;
    2066     dst   += dstStride*nTxtPerDepthY;
    2067     depth += depStride;
    2068 #if MERL_VSP_BLOCKSIZE_C0152 != 1
    2069     yDepth++;
    2070 #endif
    2071 
    2072   }
    2073 }
    2074 
    2075 Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv*mv, UInt partAddr, Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth
    2076 #if !MERL_Bi_VSP_D0166
    2077                                                , Int vspIdx
    2078 #endif
    2079                                                , TComYuv *&dstPic
    2080 #if MERL_Bi_VSP_D0166
    2081                                                , Bool bi
    2082 #endif
    2083                                                )
    2084 {
    2085   Int refStride = refPic->getCStride();
    2086   Int dstStride = dstPic->getCStride();
    2087   Int depStride = pPicBaseDepth->getStride();
    2088 
    2089   Int widthChroma, heightChroma;
    2090   if( isDepth)
    2091   {
    2092      widthChroma   = pPicBaseDepth->getWidth()>>1;
    2093      heightChroma  = pPicBaseDepth->getHeight()>>1;
    2094   }
    2095   else
    2096   {
    2097      widthChroma   = refPic->getWidth()>>1;
    2098      heightChroma  = refPic->getHeight()>>1;
    2099   }
    2100 
    2101   // Below is only for Texture chroma component
    2102 
    2103   Int widthDepth  = pPicBaseDepth->getWidth();
    2104   Int heightDepth = pPicBaseDepth->getHeight();
    2105 
    2106   Int nTxtPerDepthX, nTxtPerDepthY;  // Number of texture samples per one depth sample
    2107   Int nDepthPerTxtX, nDepthPerTxtY;  // Number of depth samples per one texture sample
    2108 
    2109   Int depthPosX;  // Starting position in depth image
    2110   Int depthPosY;
    2111 
    2112   if ( widthChroma > widthDepth )
    2113   {
    2114     nTxtPerDepthX = widthChroma / widthDepth;
    2115     nDepthPerTxtX = 1;
    2116 #if LGE_ROUND_OFFSET_D0135
    2117     depthPosX = posX / nTxtPerDepthX + ((mv->getHor()+2)>>2);        //mv denotes the disparity for VSP
    2118 #else
    2119     depthPosX = posX / nTxtPerDepthX + (mv->getHor()>>2);        //mv denotes the disparity for VSP
    2120 #endif
    2121   }
    2122   else
    2123   {
    2124     nTxtPerDepthX = 1;
    2125     nDepthPerTxtX = widthDepth / widthChroma;
    2126 #if LGE_ROUND_OFFSET_D0135
    2127     depthPosX = posX * nDepthPerTxtX + ((mv->getHor()+2)>>2);        //mv denotes the disparity for VSP
    2128 #else
    2129     depthPosX = posX * nDepthPerTxtX + (mv->getHor()>>2);        //mv denotes the disparity for VSP
    2130 #endif
    2131   }
    2132   depthPosX = Clip3(0, widthDepth - (sizeX<<1), depthPosX);
    2133   if ( heightChroma > heightDepth )
    2134   {
    2135     nTxtPerDepthY = heightChroma / heightDepth;
    2136     nDepthPerTxtY = 1;
    2137 #if LGE_ROUND_OFFSET_D0135
    2138     depthPosY = posY / nTxtPerDepthY + ((mv->getVer()+2)>>2);     //mv denotes the disparity for VSP
    2139 #else
    2140     depthPosY = posY / nTxtPerDepthY + (mv->getVer()>>2);     //mv denotes the disparity for VSP
    2141 #endif
    2142   }
    2143   else
    2144   {
    2145     nTxtPerDepthY = 1;
    2146     nDepthPerTxtY = heightDepth / heightChroma;
    2147 #if LGE_ROUND_OFFSET_D0135
    2148     depthPosY = posY * nDepthPerTxtY + ((mv->getVer()+2)>>2);     //mv denotes the disparity for VSP
    2149 #else
    2150     depthPosY = posY * nDepthPerTxtY + (mv->getVer()>>2);     //mv denotes the disparity for VSP
    2151 #endif
    2152   }
    2153   depthPosY = Clip3(0, heightDepth - (sizeY<<1), depthPosY);
    2154 
    2155   Pel *refCb  = refPic->getCbAddr() + posX + posY * refStride;
    2156   Pel *refCr  = refPic->getCrAddr() + posX + posY * refStride;
    2157   Pel *dstCb  = dstPic->getCbAddr(partAddr);
    2158   Pel *dstCr  = dstPic->getCrAddr(partAddr);
    2159   Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;  // move the pointer to the current depth pixel position
    2160  
    2161   Int refStrideBlock = refStride * nTxtPerDepthY;
    2162   Int dstStrideBlock = dstStride * nTxtPerDepthY;
    2163   Int depStrideBlock = depStride * nDepthPerTxtY;
    2164 
    2165 #if !MERL_Bi_VSP_D0166
    2166   if (isDepth)
    2167   {
    2168      // DT: Since the call for this function is redundant, ..
    2169      for (Int y = 0; y < sizeY; y++)
    2170      {
    2171        for (Int x = 0; x < sizeX; x++)
    2172        {
    2173          dstCb[x] = 128;
    2174          dstCr[x] = 128;
    2175        }
    2176        dstCb += dstStride;
    2177        dstCr += dstStride;
    2178      }
    2179      return;
    2180   }
    2181 #endif
    2182 
    2183   if ( widthChroma > widthDepth ) // We assume
    2184   {
    2185     assert( heightChroma > heightDepth );
    2186     printf("This branch should never been reached.\n");
    2187     exit(0);
    2188   }
    2189   else
    2190   {
    2191 #if MERL_VSP_BLOCKSIZE_C0152 == 1
    2192   Int  dW = sizeX;
    2193   Int  dH = sizeY;
    2194   Int  sW = 2; // search window size
    2195   Int  sH = 2;
    2196 #endif
    2197 #if MERL_VSP_BLOCKSIZE_C0152 == 2
    2198   Int  dW = sizeX;
    2199   Int  dH = sizeY;
    2200   Int  sW = 2; // search window size
    2201   Int  sH = 2;
    2202 #endif
    2203 #if MERL_VSP_BLOCKSIZE_C0152 == 4
    2204   Int  dW = sizeX>>1;
    2205   Int  dH = sizeY>>1;
    2206   Int  sW = 4; // search window size
    2207   Int  sH = 4;
    2208 #endif
    2209 
    2210   {
    2211     Pel* depthi = depth;
    2212     for (Int j = 0; j < dH; j++)
    2213     {
    2214       for (Int i = 0; i < dW; i++)
    2215       {
    2216         Pel* depthTmp;
    2217 #if MERL_VSP_BLOCKSIZE_C0152 == 1
    2218         depthTmp = depthi + (i << 1);
    2219 #endif
    2220 #if MERL_VSP_BLOCKSIZE_C0152 == 2
    2221         if (depthPosX + (i<<1) < widthDepth)
    2222           depthTmp = depthi + (i << 1);
    2223         else
    2224           depthTmp = depthi + (widthDepth - depthPosX - 1);
    2225 #endif
    2226 #if MERL_VSP_BLOCKSIZE_C0152 == 4
    2227         if (depthPosX + (i<<2) < widthDepth)
    2228           depthTmp = depthi + (i << 2);
    2229         else
    2230           depthTmp = depthi + (widthDepth - depthPosX - 1);
    2231 #endif
    2232         Int maxV = 0;
    2233 #if NCKU_BUG_FIX
    2234         for (Int blockj = 0; blockj < sH; blockj+=(sH-1))
    2235 #else
    2236         for (Int blockj = 0; blockj < sH; blockj++)
    2237 #endif
    2238         {
    2239           Int iX = 0;
    2240 #if NCKU_BUG_FIX
    2241           for (Int blocki = 0; blocki < sW; blocki+=(sW-1))
    2242 #else
    2243           for (Int blocki = 0; blocki < sW; blocki++)
    2244 #endif
    2245           {
    2246             if (maxV < depthTmp[iX])
    2247               maxV = depthTmp[iX];
    2248             if (depthPosX + i*sW + blocki < widthDepth - 1)
    2249 #if NCKU_BUG_FIX
    2250                 iX = (sW-1);
    2251 #else
    2252                 iX++;
    2253 #endif
    2254           }
    2255           if (depthPosY + j*sH + blockj < heightDepth - 1)
    2256 #if NCKU_BUG_FIX
    2257                 depthTmp += depStride * (sH-1);
    2258 #else
    2259                 depthTmp += depStride;
    2260 #endif
    2261         }
    2262         m_pDepth[i+j*dW] = maxV;
    2263       } // end of i < dW
    2264 #if MERL_VSP_BLOCKSIZE_C0152 == 1
    2265       if (depthPosY + ((j+1)<<1) < heightDepth)
    2266         depthi += (depStride << 1);
    2267       else
    2268         depthi  = depth + (heightDepth-1)*depStride;
    2269 #endif
    2270 #if MERL_VSP_BLOCKSIZE_C0152 == 2
    2271       if (depthPosY + ((j+1)<<1) < heightDepth)
    2272         depthi += (depStride << 1);
    2273       else
    2274         depthi  = depth + (heightDepth-depthPosY-1)*depStride;
    2275 #endif
    2276 #if MERL_VSP_BLOCKSIZE_C0152 == 4
    2277       if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
    2278         depthi += (depStride << 2);
    2279       else
    2280         depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
    2281 #endif
    2282     }
    2283   }
    2284 
    2285 
    2286 #if MERL_General_Fix
    2287 #if MERL_VSP_BLOCKSIZE_C0152 == 1
    2288 #if MERL_CVSP_D0165
    2289   //get LUT based horizontal reference range
    2290   Int range=0;
    2291   if( sizeX == 2 && sizeY == 4 )
    2292     range = m_iRangeChroma[0];
    2293   else if( sizeX == 4 && sizeY == 2 )
    2294     range = m_iRangeChroma[1];
    2295   else if( sizeX == 4 && sizeY == 4 )
    2296     range = m_iRangeChroma[2];
    2297   else if( sizeX == 4 && sizeY == 8 )
    2298     range = m_iRangeChroma[3];
    2299   else if( sizeX == 8 && sizeY == 4 )
    2300     range = m_iRangeChroma[4];
    2301   else if( sizeX == 8 && sizeY == 8 )
    2302     range = m_iRangeChroma[5];
    2303   else if( sizeX == 8 && sizeY == 16 )
    2304     range = m_iRangeChroma[6];
    2305   else if( sizeX == 16 && sizeY == 8 )
    2306     range = m_iRangeChroma[7];
    2307   else if( sizeX == 16 && sizeY == 16 )
    2308     range = m_iRangeChroma[8];
    2309   else if( sizeX == 16 && sizeY == 32 )
    2310     range = m_iRangeChroma[9];
    2311   else if( sizeX == 32 && sizeY == 16 )
    2312     range = m_iRangeChroma[10];
    2313   else if( sizeX == 32 && sizeY == 32 )
    2314     range = m_iRangeChroma[11];
    2315   else
    2316     assert(0);
    2317  
    2318   // The minimum depth value
    2319   Int minRelativePos = 5000;
    2320   Int maxRelativePos = -5000;
    2321 
    2322   Int depthTmp;
    2323   for (Int yTxt=0; yTxt<sizeY; yTxt++)
    2324   {
    2325     for (Int xTxt=0; xTxt<sizeX; xTxt++)
    2326     {
    2327       depthTmp = m_pDepth[xTxt+yTxt*dW];
    2328       Int disparity = pShiftLUT[ depthTmp ] << iShiftPrec;
    2329       Int disparityInt = disparity >> 3;//in chroma resolution
    2330 
    2331       if (disparityInt < 0)
    2332       {
    2333         if (minRelativePos > disparityInt+xTxt)
    2334             minRelativePos = disparityInt+xTxt;
    2335       }
    2336       else
    2337       {
    2338         if (maxRelativePos < disparityInt+xTxt)
    2339             maxRelativePos = disparityInt+xTxt;
    2340       }
    2341     }
    2342   }
    2343 
    2344   depthTmp = m_pDepth[0];
    2345   Int disparity_tmp = pShiftLUT[ depthTmp ] << iShiftPrec;
    2346   if ( disparity_tmp < 0 )
    2347     maxRelativePos = minRelativePos + range - 1;
    2348   else
    2349     minRelativePos = maxRelativePos - range + 1;
    2350 
    2351 #endif
    2352 #endif
    2353 #endif
    2354 
    2355     // (sizeX, sizeY) is Chroma block size
    2356     for ( Int yTxt = 0, yDepth = 0; yTxt < sizeY; yTxt += nTxtPerDepthY, yDepth += nDepthPerTxtY )
    2357     {
    2358       for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth += nDepthPerTxtX )
    2359       {
    2360         Pel repDepth = 0; // to store the depth value used for warping
    2361 #if MERL_VSP_BLOCKSIZE_C0152 == 1
    2362         repDepth = m_pDepth[(xTxt) + (yTxt)*dW];
    2363 #endif
    2364 #if MERL_VSP_BLOCKSIZE_C0152 == 2
    2365         repDepth = m_pDepth[(xTxt) + (yTxt)*dW];
    2366 #endif
    2367 #if MERL_VSP_BLOCKSIZE_C0152 == 4
    2368         repDepth = m_pDepth[(xTxt>>1) + (yTxt>>1)*dW];
    2369 #endif
    2370 
    2371       // calculate the offset in the reference picture
    2372         Int disparity = pShiftLUT[ repDepth ] << iShiftPrec;
    2373         Int refOffset = xTxt + (disparity >> 3); // in integer pixel in chroma image
    2374         Int xFrac = disparity & 0x7;
    2375 #if MERL_CVSP_D0165
    2376         if(refOffset < minRelativePos || refOffset > maxRelativePos)
    2377           xFrac = 0;
    2378         refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
    2379 #endif
    2380         Int absX  = posX + refOffset;
    2381 
    2382         if (xFrac == 0)
    2383           absX = Clip3(0, widthChroma-1, absX);
    2384         else
    2385           absX = Clip3(4, widthChroma-5, absX);
    2386 
    2387         refOffset = absX - posX;
    2388 
    2389         assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
    2390         assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
    2391 #if MERL_Bi_VSP_D0166
    2392         m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
    2393         m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
    2394 #else
    2395         m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, true);
    2396         m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, true);
    2397 #endif
    2398 
    2399       }
    2400       refCb += refStrideBlock;
    2401       refCr += refStrideBlock;
    2402       dstCb += dstStrideBlock;
    2403       dstCr += dstStrideBlock;
    2404       depth += depStrideBlock;
    2405     }
    2406   }
    2407 
    2408 }
    2409 
    2410 #endif // MERL_VSP_C0152
    2411 
    2412 #if DEPTH_MAP_GENERATION
    2413 Void TComPrediction::xWeightedAveragePdm( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst, UInt uiSubSampExpX, UInt uiSubSampExpY )
    2414 {
    2415 
     1265          Short val = dstCb2[j] << shift;
     1266          dstCb2[j] = val - (Short)IF_INTERNAL_OFFS;
     1267
     1268          val = dstCr2[j] << shift;
     1269          dstCr2[j] = val - (Short)IF_INTERNAL_OFFS;
     1270        }
     1271        dstCb2 += dstStride;
     1272        dstCr2 += dstStride;
     1273      }
     1274    }
     1275#endif
     1276  }
     1277#endif
     1278}
     1279
     1280Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
     1281{
    24161282  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
    24171283  {
    2418     rpcYuvDst->addAvgPdm( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY );
     1284    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
    24191285  }
    24201286  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
    24211287  {
    2422     pcYuvSrc0->copyPartToPartYuvPdm( rpcYuvDst, uiPartIdx, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY );
     1288    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
    24231289  }
    24241290  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
    24251291  {
    2426     pcYuvSrc1->copyPartToPartYuvPdm( rpcYuvDst, uiPartIdx, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY );
    2427   }
    2428   else
    2429   {
    2430     assert (0);
    2431   }
    2432 }
    2433 #endif
    2434 
    2435 Void TComPrediction::xWeightedAverage( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst
    2436 #if MERL_Bi_VSP_D0166
    2437                                  , Int predDirVSP
    2438 #endif
    2439   )
    2440 {
    2441 #if MERL_Bi_VSP_D0166
    2442   Bool isVSP = 0;
    2443   if (pcCU->getVSPIndex(uiPartIdx)!=0)//is VSP
    2444   {
    2445     isVSP = 1;
    2446   }
    2447 
    2448   if(( !isVSP && iRefIdx0 >= 0 && iRefIdx1 >= 0 ) || ( isVSP && predDirVSP == 3 ))
    2449 #else
    2450   if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
    2451 #endif
    2452   {
    2453     rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
    2454   }
    2455 #if MERL_Bi_VSP_D0166
    2456   else if ( ( !isVSP && iRefIdx0 >= 0 && iRefIdx1 <  0 ) || ( isVSP && predDirVSP == 1))
    2457 #else
    2458   else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
    2459 #endif
    2460   {
    2461     pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
    2462   }
    2463 #if MERL_Bi_VSP_D0166
    2464   else if (( !isVSP && iRefIdx0 <  0 && iRefIdx1 >= 0 ) || ( isVSP && predDirVSP == 2))
    2465 #else
    2466   else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
    2467 #endif
    2468   {
    24691292    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
    24701293  }
    2471 #if MERL_Bi_VSP_D0166
    2472   else
    2473   {//for debug test only
    2474     assert(0);
    2475   }
    2476 #endif
    24771294}
    24781295
    24791296// AMVP
    2480 Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMvPred )
     1297Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
    24811298{
    24821299  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
    2483 
    2484   if( pcCU->getAMVPMode(uiPartAddr) == AM_NONE || (pcAMVPInfo->iN <= 1 && pcCU->getAMVPMode(uiPartAddr) == AM_EXPL) )
     1300  if( pcAMVPInfo->iN <= 1 )
    24851301  {
    24861302    rcMvPred = pcAMVPInfo->m_acMvCand[0];
     
    25491365}
    25501366
    2551 /** Function for deriving chroma LM intra prediction.
    2552  * \param pcPattern pointer to neighbouring pixel access pattern
    2553  * \param piSrc pointer to reconstructed chroma sample array
    2554  * \param pPred pointer for the prediction sample array
    2555  * \param uiPredStride the stride of the prediction sample array
    2556  * \param uiCWidth the width of the chroma block
    2557  * \param uiCHeight the height of the chroma block
    2558  * \param uiChromaId boolean indication of chroma component
    2559  *
    2560  * This function derives the prediction samples for chroma LM mode (chroma intra coding)
    2561  */
    2562 Void TComPrediction::predLMIntraChroma( TComPattern* pcPattern, Int* piSrc, Pel* pPred, UInt uiPredStride, UInt uiCWidth, UInt uiCHeight, UInt uiChromaId )
    2563 {
    2564   UInt uiWidth  = 2 * uiCWidth;
    2565 
    2566   xGetLLSPrediction( pcPattern, piSrc+uiWidth+2, uiWidth+1, pPred, uiPredStride, uiCWidth, uiCHeight, 1 ); 
    2567 }
    2568 
    2569 /** Function for deriving downsampled luma sample of current chroma block and its above, left causal pixel
    2570  * \param pcPattern pointer to neighbouring pixel access pattern
    2571  * \param uiCWidth the width of the chroma block
    2572  * \param uiCHeight the height of the chroma block
    2573  *
    2574  * This function derives downsampled luma sample of current chroma block and its above, left causal pixel
    2575  */
    2576 Void TComPrediction::getLumaRecPixels( TComPattern* pcPattern, UInt uiCWidth, UInt uiCHeight )
    2577 {
    2578   UInt uiWidth  = 2 * uiCWidth;
    2579   UInt uiHeight = 2 * uiCHeight; 
    2580 
    2581   Pel* pRecSrc = pcPattern->getROIY();
    2582   Pel* pDst0 = m_pLumaRecBuffer + m_iLumaRecStride + 1;
    2583 
    2584   Int iRecSrcStride = pcPattern->getPatternLStride();
    2585   Int iRecSrcStride2 = iRecSrcStride << 1;
    2586   Int iDstStride = m_iLumaRecStride;
    2587   Int iSrcStride = ( max( uiWidth, uiHeight ) << 1 ) + 1;
    2588 
    2589   Int* ptrSrc = pcPattern->getAdiOrgBuf( uiWidth, uiHeight, m_piYuvExt );
    2590 
    2591   // initial pointers
    2592   Pel* pDst = pDst0 - 1 - iDstStride; 
    2593   Int* piSrc = ptrSrc;
    2594 
    2595   // top left corner downsampled from ADI buffer
    2596   // don't need this point
    2597 
    2598   // top row downsampled from ADI buffer
    2599   pDst++;     
    2600   piSrc ++;
    2601   for (Int i = 0; i < uiCWidth; i++)
    2602   {
    2603     pDst[i] = ((piSrc[2*i] * 2 ) + piSrc[2*i - 1] + piSrc[2*i + 1] + 2) >> 2;
    2604   }
    2605 
    2606   // left column downsampled from ADI buffer
    2607   pDst = pDst0 - 1;
    2608   piSrc = ptrSrc + iSrcStride;
    2609   for (Int j = 0; j < uiCHeight; j++)
    2610   {
    2611     pDst[0] = ( piSrc[0] + piSrc[iSrcStride] ) >> 1;
    2612     piSrc += iSrcStride << 1;
    2613     pDst += iDstStride;   
    2614   }
    2615 
    2616   // inner part from reconstructed picture buffer
    2617   for( Int j = 0; j < uiCHeight; j++ )
    2618   {
    2619     for (Int i = 0; i < uiCWidth; i++)
    2620     {
    2621       pDst0[i] = (pRecSrc[2*i] + pRecSrc[2*i + iRecSrcStride]) >> 1;
    2622     }
    2623 
    2624     pDst0 += iDstStride;
    2625     pRecSrc += iRecSrcStride2;
    2626   }
    2627 }
    2628 
    2629 /** Function for deriving the positon of first non-zero binary bit of a value
    2630  * \param x input value
    2631  *
    2632  * This function derives the positon of first non-zero binary bit of a value
    2633  */
    2634 Int GetMSB( UInt x )
    2635 {
    2636   Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1;
    2637 
    2638   while( x > 1 )
    2639   {
    2640     bits >>= 1;
    2641     y = x >> bits;
    2642 
    2643     if( y )
    2644     {
    2645       x = y;
    2646       iMSB += bits;
    2647     }
    2648   }
    2649 
    2650   iMSB+=y;
    2651 
    2652   return iMSB;
    2653 }
    2654 
    2655 /** Function for counting leading number of zeros/ones
    2656  * \param x input value
    2657  \ This function counts leading number of zeros for positive numbers and
    2658  \ leading number of ones for negative numbers. This can be implemented in
    2659  \ single instructure cycle on many processors.
    2660  */
    2661 
    2662 Short CountLeadingZerosOnes (Short x)
    2663 {
    2664   Short clz;
    2665   Short i;
    2666 
    2667   if(x == 0)
    2668   {
    2669     clz = 0;
    2670   }
    2671   else
    2672   {
    2673     if (x == -1)
    2674     {
    2675       clz = 15;
    2676     }
    2677     else
    2678     {
    2679       if(x < 0)
    2680       {
    2681         x = ~x;
    2682       }
    2683       clz = 15;
    2684       for(i = 0;i < 15;++i)
    2685       {
    2686         if(x)
    2687         {
    2688           clz --;
    2689         }
    2690         x = x >> 1;
    2691       }
    2692     }
    2693   }
    2694   return clz;
    2695 }
    2696 
    2697 /** Function for deriving LM intra prediction.
    2698  * \param pcPattern pointer to neighbouring pixel access pattern
    2699  * \param pSrc0 pointer to reconstructed chroma sample array
    2700  * \param iSrcStride the stride of reconstructed chroma sample array
    2701  * \param pDst0 reference to pointer for the prediction sample array
    2702  * \param iDstStride the stride of the prediction sample array
    2703  * \param uiWidth the width of the chroma block
    2704  * \param uiHeight the height of the chroma block
    2705  * \param uiExt0 line number of neiggboirng pixels for calculating LM model parameter, default value is 1
    2706  *
    2707  * This function derives the prediction samples for chroma LM mode (chroma intra coding)
    2708  */
    2709 Void TComPrediction::xGetLLSPrediction( TComPattern* pcPattern, Int* pSrc0, Int iSrcStride, Pel* pDst0, Int iDstStride, UInt uiWidth, UInt uiHeight, UInt uiExt0 )
    2710 {
    2711 
    2712   Pel  *pDst, *pLuma;
    2713   Int  *pSrc;
    2714 
    2715   Int  iLumaStride = m_iLumaRecStride;
    2716   Pel* pLuma0 = m_pLumaRecBuffer + uiExt0 * iLumaStride + uiExt0;
    2717 
    2718   Int i, j, iCountShift = 0;
    2719 
    2720   UInt uiExt = uiExt0;
    2721 
    2722   // LLS parameters estimation -->
    2723 
    2724   Int x = 0, y = 0, xx = 0, xy = 0;
    2725 
    2726   pSrc  = pSrc0  - iSrcStride;
    2727   pLuma = pLuma0 - iLumaStride;
    2728 
    2729   for( j = 0; j < uiWidth; j++ )
    2730   {
    2731     x += pLuma[j];
    2732     y += pSrc[j];
    2733     xx += pLuma[j] * pLuma[j];
    2734     xy += pLuma[j] * pSrc[j];
    2735   }
    2736   iCountShift += g_aucConvertToBit[ uiWidth ] + 2;
    2737 
    2738   pSrc  = pSrc0 - uiExt;
    2739   pLuma = pLuma0 - uiExt;
    2740 
    2741   for( i = 0; i < uiHeight; i++ )
    2742   {
    2743     x += pLuma[0];
    2744     y += pSrc[0];
    2745     xx += pLuma[0] * pLuma[0];
    2746     xy += pLuma[0] * pSrc[0];
    2747 
    2748     pSrc  += iSrcStride;
    2749     pLuma += iLumaStride;
    2750   }
    2751   iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 );
    2752 
    2753   Int iTempShift = ( g_uiBitDepth + g_uiBitIncrement ) + g_aucConvertToBit[ uiWidth ] + 3 - 15;
    2754 
    2755   if(iTempShift > 0)
    2756   {
    2757     x  = ( x +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
    2758     y  = ( y +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
    2759     xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
    2760     xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
    2761     iCountShift -= iTempShift;
    2762   }
    2763 
    2764   Int a, b, iShift = 13;
    2765 
    2766   if( iCountShift == 0 )
    2767   {
    2768     a = 0;
    2769     b = 1 << (g_uiBitDepth + g_uiBitIncrement - 1);
    2770     iShift = 0;
    2771   }
    2772   else
    2773   {
    2774     Int a1 = ( xy << iCountShift ) - y * x;
    2775     Int a2 = ( xx << iCountShift ) - x * x;             
    2776 
    2777     {
    2778       const Int iShiftA2 = 6;
    2779       const Int iShiftA1 = 15;
    2780       const Int iAccuracyShift = 15;
    2781 
    2782       Int iScaleShiftA2 = 0;
    2783       Int iScaleShiftA1 = 0;
    2784       Int a1s = a1;
    2785       Int a2s = a2;
    2786 
    2787       iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1;
    2788       iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; 
    2789 
    2790       if( iScaleShiftA1 < 0 )
    2791       {
    2792         iScaleShiftA1 = 0;
    2793       }
    2794      
    2795       if( iScaleShiftA2 < 0 )
    2796       {
    2797         iScaleShiftA2 = 0;
    2798       }
    2799      
    2800       Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
    2801 
    2802       a2s = a2 >> iScaleShiftA2;
    2803 
    2804       a1s = a1 >> iScaleShiftA1;
    2805 
    2806       if (a2s >= 1)
    2807       {
    2808         a = a1s * m_uiaShift[ a2s - 1];
    2809       }
    2810       else
    2811       {
    2812         a = 0;
    2813       }
    2814      
    2815       if( iScaleShiftA < 0 )
    2816       {
    2817         a = a << -iScaleShiftA;
    2818       }
    2819       else
    2820       {
    2821         a = a >> iScaleShiftA;
    2822       }
    2823      
    2824        a = Clip3(-( 1 << 15 ), ( 1 << 15 ) - 1, a);
    2825      
    2826       Int minA = -(1 << (6));
    2827       Int maxA = (1 << 6) - 1;
    2828       if( a <= maxA && a >= minA )
    2829       {
    2830         // do nothing
    2831       }
    2832       else
    2833       {
    2834         Short n = CountLeadingZerosOnes(a);
    2835         a = a >> (9-n);
    2836         iShift -= (9-n);
    2837       }
    2838 
    2839       b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
    2840     }
    2841   }   
    2842 
    2843   // <-- end of LLS parameters estimation
    2844 
    2845   // get prediction -->
    2846   uiExt = uiExt0;
    2847   pLuma = pLuma0;
    2848   pDst = pDst0;
    2849 
    2850   for( i = 0; i < uiHeight; i++ )
    2851   {
    2852     for( j = 0; j < uiWidth; j++ )
    2853     {
    2854       pDst[j] = Clip( ( ( a * pLuma[j] ) >> iShift ) + b );
    2855     }
    2856    
    2857     pDst  += iDstStride;
    2858     pLuma += iLumaStride;
    2859   }
    2860   // <-- end of get prediction
    2861 
    2862 }
    2863 
    2864 
    2865 #if LGE_ILLUCOMP_B0045
    2866 /** Function for deriving LM illumination compensation.
    2867  */
    2868 Void TComPrediction::xGetLLSICPrediction(TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, Int &iShift)
    2869 {
    2870   TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
    2871   Pel *pRec, *pRef;
    2872   UInt uiWidth, uiHeight, uiTmpPartIdx;
    2873   Int iRecStride = pRecPic->getStride(), iRefStride = pRefPic->getStride();
    2874   Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset;
    2875 
    2876   iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
    2877   iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
    2878 #if LGE_ROUND_OFFSET_D0135
    2879   iRefX   = iCUPelX + ((pMv->getHor()+2) >> 2);
    2880   iRefY   = iCUPelY + ((pMv->getVer()+2) >> 2);
    2881 #else
    2882   iRefX   = iCUPelX + (pMv->getHor() >> 2);
    2883   iRefY   = iCUPelY + (pMv->getVer() >> 2);
    2884 #endif
    2885   uiWidth = pcCU->getWidth(0);
    2886   uiHeight = pcCU->getHeight(0);
    2887 
    2888   Int i, j, iCountShift = 0;
    2889 
    2890   // LLS parameters estimation -->
    2891 
    2892   Int x = 0, y = 0, xx = 0, xy = 0;
    2893 
    2894   if(pcCU->getPUAbove(uiTmpPartIdx, pcCU->getZorderIdxInCU()) && iCUPelY > 0 && iRefY > 0)
    2895   {
    2896 #if LGE_ROUND_OFFSET_D0135
    2897     iRefOffset = ( (pMv->getHor()+2) >> 2 ) + ( (pMv->getVer()+2) >> 2 ) * iRefStride - iRefStride;
    2898 #else
    2899     iRefOffset = ( pMv->getHor() >> 2 ) + ( pMv->getVer() >> 2 ) * iRefStride - iRefStride;
    2900 #endif
    2901     pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2902     pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
    2903 
    2904     for( j = 0; j < uiWidth; j++ )
    2905     {
    2906       x += pRef[j];
    2907       y += pRec[j];
    2908       xx += pRef[j] * pRef[j];
    2909       xy += pRef[j] * pRec[j];
    2910     }
    2911     iCountShift += g_aucConvertToBit[ uiWidth ] + 2;
    2912   }
    2913 
    2914 
    2915   if(pcCU->getPULeft(uiTmpPartIdx, pcCU->getZorderIdxInCU()) && iCUPelX > 0 && iRefX > 0)
    2916   {
    2917 #if LGE_ROUND_OFFSET_D0135
    2918     iRefOffset = ( (pMv->getHor()+2) >> 2 ) + ( (pMv->getVer()+2) >> 2 ) * iRefStride - 1;
    2919 #else
    2920     iRefOffset = ( pMv->getHor() >> 2 ) + ( pMv->getVer() >> 2 ) * iRefStride - 1;
    2921 #endif
    2922     pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2923     pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
    2924 
    2925     for( i = 0; i < uiHeight; i++ )
    2926     {
    2927       x += pRef[0];
    2928       y += pRec[0];
    2929       xx += pRef[0] * pRef[0];
    2930       xy += pRef[0] * pRec[0];
    2931 
    2932       pRef += iRefStride;
    2933       pRec += iRecStride;
    2934     }
    2935     iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 );
    2936   }
    2937 
    2938   Int iTempShift = ( g_uiBitDepth + g_uiBitIncrement ) + g_aucConvertToBit[ uiWidth ] + 3 - 15;
    2939 
    2940   if(iTempShift > 0)
    2941   {
    2942     x  = ( x +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
    2943     y  = ( y +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
    2944     xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
    2945     xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
    2946     iCountShift -= iTempShift;
    2947   }
    2948 
    2949   iShift = 13;
    2950 
    2951   if( iCountShift == 0 )
    2952   {
    2953     a = 1;
    2954     b = 0;
    2955     iShift = 0;
    2956   }
    2957   else
    2958   {
    2959     Int a1 = ( xy << iCountShift ) - y * x;
    2960     Int a2 = ( xx << iCountShift ) - x * x;             
    2961 
    2962     {
    2963       const Int iShiftA2 = 6;
    2964       const Int iShiftA1 = 15;
    2965       const Int iAccuracyShift = 15;
    2966 
    2967       Int iScaleShiftA2 = 0;
    2968       Int iScaleShiftA1 = 0;
    2969       Int a1s = a1;
    2970       Int a2s = a2;
    2971 
    2972       iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1;
    2973       iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; 
    2974 
    2975       if( iScaleShiftA1 < 0 )
    2976       {
    2977         iScaleShiftA1 = 0;
    2978       }
    2979 
    2980       if( iScaleShiftA2 < 0 )
    2981       {
    2982         iScaleShiftA2 = 0;
    2983       }
    2984 
    2985       Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
    2986 
    2987       a2s = a2 >> iScaleShiftA2;
    2988 
    2989       a1s = a1 >> iScaleShiftA1;
    2990 
    2991       if (a2s >= 1)
    2992       {
    2993         a = a1s * m_uiaShift[ a2s - 1];
    2994       }
    2995       else
    2996       {
    2997         a = 0;
    2998       }
    2999 
    3000       if( iScaleShiftA < 0 )
    3001       {
    3002         a = a << -iScaleShiftA;
    3003       }
    3004       else
    3005       {
    3006         a = a >> iScaleShiftA;
    3007       }
    3008 
    3009       a = Clip3(-( 1 << 15 ), ( 1 << 15 ) - 1, a);
    3010 
    3011       Int minA = -(1 << (6));
    3012       Int maxA = (1 << 6) - 1;
    3013       if( a <= maxA && a >= minA )
    3014       {
    3015         // do nothing
    3016       }
    3017       else
    3018       {
    3019         Short n = CountLeadingZerosOnes(a);
    3020         a = a >> (9-n);
    3021         iShift -= (9-n);
    3022       }
    3023 
    3024       b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
    3025     }
    3026   }   
    3027 }
    3028 
    3029 Void TComPrediction::xGetLLSICPredictionChroma(TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, Int &iShift, Int iChromaId)
    3030 {
    3031   TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
    3032   Pel *pRec = NULL, *pRef = NULL;
    3033   UInt uiWidth, uiHeight, uiTmpPartIdx;
    3034   Int iRecStride = pRecPic->getCStride(), iRefStride = pRefPic->getCStride();
    3035   Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset;
    3036 
    3037   iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
    3038   iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
    3039 #if LGE_ROUND_OFFSET_D0135
    3040   iRefX   = iCUPelX + ((pMv->getHor()+2) >> 2);
    3041   iRefY   = iCUPelY + ((pMv->getVer()+2) >> 2);
    3042 #else
    3043   iRefX   = iCUPelX + (pMv->getHor() >> 2);
    3044   iRefY   = iCUPelY + (pMv->getVer() >> 2);
    3045 #endif
    3046   uiWidth = pcCU->getWidth(0) >> 1;
    3047   uiHeight = pcCU->getHeight(0) >> 1;
    3048 
    3049   Int i, j, iCountShift = 0;
    3050 
    3051   // LLS parameters estimation -->
    3052 
    3053   Int x = 0, y = 0, xx = 0, xy = 0;
    3054 
    3055   if(pcCU->getPUAbove(uiTmpPartIdx, pcCU->getZorderIdxInCU()) && iCUPelY > 0 && iRefY > 0)
    3056   {
    3057 #if LGE_ROUND_OFFSET_D0135
    3058     iRefOffset = ( (pMv->getHor()+4) >> 3 ) + ( (pMv->getVer()+4) >> 3 ) * iRefStride - iRefStride;
    3059 #else
    3060     iRefOffset = ( pMv->getHor() >> 3 ) + ( pMv->getVer() >> 3 ) * iRefStride - iRefStride;
    3061 #endif
    3062     if (iChromaId == 0) // Cb
    3063     {
    3064       pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    3065       pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
    3066     }
    3067     else if (iChromaId == 1) // Cr
    3068     {
    3069       pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    3070       pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
    3071     }
    3072 
    3073     for( j = 0; j < uiWidth; j++ )
    3074     {
    3075       x += pRef[j];
    3076       y += pRec[j];
    3077       xx += pRef[j] * pRef[j];
    3078       xy += pRef[j] * pRec[j];
    3079     }
    3080     iCountShift += g_aucConvertToBit[ uiWidth ] + 2;
    3081   }
    3082 
    3083 
    3084   if(pcCU->getPULeft(uiTmpPartIdx, pcCU->getZorderIdxInCU()) && iCUPelX > 0 && iRefX > 0)
    3085   {
    3086 #if LGE_ROUND_OFFSET_D0135
    3087     iRefOffset = ( (pMv->getHor()+4) >> 3 ) + ( (pMv->getVer()+4) >> 3 ) * iRefStride - 1;
    3088 #else
    3089     iRefOffset = ( pMv->getHor() >> 3 ) + ( pMv->getVer() >> 3 ) * iRefStride - 1;
    3090 #endif
    3091     if (iChromaId == 0) // Cb
    3092     {
    3093       pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    3094       pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
    3095     }
    3096     else if (iChromaId == 1) // Cr
    3097     {
    3098       pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    3099       pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
    3100     }
    3101 
    3102     for( i = 0; i < uiHeight; i++ )
    3103     {
    3104       x += pRef[0];
    3105       y += pRec[0];
    3106       xx += pRef[0] * pRef[0];
    3107       xy += pRef[0] * pRec[0];
    3108 
    3109       pRef += iRefStride;
    3110       pRec += iRecStride;
    3111     }
    3112     iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 );
    3113   }
    3114 
    3115   Int iTempShift = ( g_uiBitDepth + g_uiBitIncrement ) + g_aucConvertToBit[ uiWidth ] + 3 - 15;
    3116 
    3117   if(iTempShift > 0)
    3118   {
    3119     x  = ( x +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
    3120     y  = ( y +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
    3121     xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
    3122     xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
    3123     iCountShift -= iTempShift;
    3124   }
    3125 
    3126   iShift = 13;
    3127 
    3128   if( iCountShift == 0 )
    3129   {
    3130     a = 1;
    3131     b = 0;
    3132     iShift = 0;
    3133   }
    3134   else
    3135   {
    3136     Int a1 = ( xy << iCountShift ) - y * x;
    3137     Int a2 = ( xx << iCountShift ) - x * x;             
    3138 
    3139     {
    3140       const Int iShiftA2 = 6;
    3141       const Int iShiftA1 = 15;
    3142       const Int iAccuracyShift = 15;
    3143 
    3144       Int iScaleShiftA2 = 0;
    3145       Int iScaleShiftA1 = 0;
    3146       Int a1s = a1;
    3147       Int a2s = a2;
    3148 
    3149       iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1;
    3150       iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; 
    3151 
    3152       if( iScaleShiftA1 < 0 )
    3153       {
    3154         iScaleShiftA1 = 0;
    3155       }
    3156 
    3157       if( iScaleShiftA2 < 0 )
    3158       {
    3159         iScaleShiftA2 = 0;
    3160       }
    3161 
    3162       Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
    3163 
    3164       a2s = a2 >> iScaleShiftA2;
    3165 
    3166       a1s = a1 >> iScaleShiftA1;
    3167 
    3168       if (a2s >= 1)
    3169       {
    3170         a = a1s * m_uiaShift[ a2s - 1];
    3171       }
    3172       else
    3173       {
    3174         a = 0;
    3175       }
    3176 
    3177       if( iScaleShiftA < 0 )
    3178       {
    3179         a = a << -iScaleShiftA;
    3180       }
    3181       else
    3182       {
    3183         a = a >> iScaleShiftA;
    3184       }
    3185 
    3186       a = Clip3(-( 1 << 15 ), ( 1 << 15 ) - 1, a);
    3187 
    3188       Int minA = -(1 << (6));
    3189       Int maxA = (1 << 6) - 1;
    3190       if( a <= maxA && a >= minA )
    3191       {
    3192         // do nothing
    3193       }
    3194       else
    3195       {
    3196         Short n = CountLeadingZerosOnes(a);
    3197         a = a >> (9-n);
    3198         iShift -= (9-n);
    3199       }
    3200 
    3201       b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
    3202     }
    3203   }   
    3204 }
    3205 #endif
    32061367/** Function for filtering intra DC predictor.
    32071368 * \param pSrc pointer to reconstructed sample array
     
    32341395  return;
    32351396}
    3236 
    3237 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    3238 Void TComPrediction::predIntraLumaDMM( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder )
    3239 {
    3240 #if HHI_DMM_WEDGE_INTRA
    3241   if( uiMode == DMM_WEDGE_FULL_IDX        ) { xPredIntraWedgeFull ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, false, pcCU->getWedgeFullTabIdx ( uiAbsPartIdx ) ); }
    3242   if( uiMode == DMM_WEDGE_FULL_D_IDX      ) { xPredIntraWedgeFull ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, true,  pcCU->getWedgeFullTabIdx( uiAbsPartIdx ), pcCU->getWedgeFullDeltaDC1( uiAbsPartIdx ), pcCU->getWedgeFullDeltaDC2( uiAbsPartIdx ) ); }
    3243   if( uiMode == DMM_WEDGE_PREDDIR_IDX     ) { xPredIntraWedgeDir  ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, false, pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ) ); }
    3244   if( uiMode == DMM_WEDGE_PREDDIR_D_IDX   ) { xPredIntraWedgeDir  ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, true,  pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ), pcCU->getWedgePredDirDeltaDC1( uiAbsPartIdx ), pcCU->getWedgePredDirDeltaDC2( uiAbsPartIdx ) ); }
    3245 #endif
    3246 #if HHI_DMM_PRED_TEX
    3247   if( uiMode == DMM_WEDGE_PREDTEX_IDX     ) { xPredIntraWedgeTex  ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, false ); }
    3248   if( uiMode == DMM_WEDGE_PREDTEX_D_IDX   ) { xPredIntraWedgeTex  ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, true, pcCU->getWedgePredTexDeltaDC1( uiAbsPartIdx ), pcCU->getWedgePredTexDeltaDC2( uiAbsPartIdx ) ); }
    3249   if( uiMode == DMM_CONTOUR_PREDTEX_IDX   ) { xPredIntraContourTex( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, false ); }
    3250   if( uiMode == DMM_CONTOUR_PREDTEX_D_IDX ) { xPredIntraContourTex( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, true, pcCU->getContourPredTexDeltaDC1( uiAbsPartIdx ), pcCU->getContourPredTexDeltaDC2( uiAbsPartIdx ) ); }
    3251 #endif
    3252 }
    3253 
    3254 #if QC_DC_PREDICTOR_D0183
    3255 Void TComPrediction::getPredDCs( Bool* pbPattern, Int iStride, Int* piMask, Int iMaskStride, Int& riPredDC1, Int& riPredDC2 )
    3256 {
    3257   Int  iDC1, iDC2;
    3258   const Int  iTR = (   iStride - 1        ) - iMaskStride;
    3259   const Int  iTM = ( ( iStride - 1 ) >> 1 ) - iMaskStride;
    3260   const Int  iLB = (   iStride - 1        ) * iMaskStride - 1;
    3261   const Int  iLM = ( ( iStride - 1 ) >> 1 ) * iMaskStride - 1;
    3262   const UInt uiBitDepth = g_uiBitDepth + g_uiBitIncrement;
    3263 
    3264   Bool bL = ( pbPattern[0] != pbPattern[(iStride-1)*iStride] );
    3265   Bool bT = ( pbPattern[0] != pbPattern[(iStride-1)]         );
    3266 
    3267   if( bL == bT )
    3268   {
    3269     iDC1 = bL ? ( piMask[iTR] + piMask[iLB] )>>1 : 1<<( uiBitDepth - 1 );
    3270     iDC2 =      ( piMask[ -1] + piMask[-iMaskStride] )>>1;
     1397#if H_3D_IC
     1398/** Function for deriving the position of first non-zero binary bit of a value
     1399 * \param x input value
     1400 *
     1401 * This function derives the position of first non-zero binary bit of a value
     1402 */
     1403Int GetMSB( UInt x )
     1404{
     1405  Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1;
     1406
     1407  while( x > 1 )
     1408  {
     1409    bits >>= 1;
     1410    y = x >> bits;
     1411
     1412    if( y )
     1413    {
     1414      x = y;
     1415      iMSB += bits;
     1416    }
     1417  }
     1418
     1419  iMSB+=y;
     1420
     1421  return iMSB;
     1422}
     1423
     1424#if !SHARP_ILLUCOMP_REFINE_E0046
     1425/** Function for counting leading number of zeros/ones
     1426 * \param x input value
     1427 \ This function counts leading number of zeros for positive numbers and
     1428 \ leading number of ones for negative numbers. This can be implemented in
     1429 \ single instructure cycle on many processors.
     1430 */
     1431
     1432Short CountLeadingZerosOnes (Short x)
     1433{
     1434  Short clz;
     1435  Short i;
     1436
     1437  if(x == 0)
     1438  {
     1439    clz = 0;
    32711440  }
    32721441  else
    32731442  {
    3274     iDC1 = bL ? piMask[iLB] : piMask[iTR];
    3275     iDC2 = bL ? piMask[iTM] : piMask[iLM];
    3276   }
    3277 
    3278   riPredDC1 = pbPattern[0] ? iDC1 : iDC2;
    3279   riPredDC2 = pbPattern[0] ? iDC2 : iDC1;
    3280 }
     1443    if (x == -1)
     1444    {
     1445      clz = 15;
     1446    }
     1447    else
     1448    {
     1449      if(x < 0)
     1450      {
     1451        x = ~x;
     1452      }
     1453      clz = 15;
     1454      for(i = 0;i < 15;++i)
     1455      {
     1456        if(x)
     1457        {
     1458          clz --;
     1459        }
     1460        x = x >> 1;
     1461      }
     1462    }
     1463  }
     1464  return clz;
     1465}
     1466#endif
     1467
     1468/** Function for deriving LM illumination compensation.
     1469 */
     1470#if SHARP_ILLUCOMP_REFINE_E0046
     1471Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType )
    32811472#else
    3282 Void TComPrediction::getWedgePredDCs( TComWedgelet* pcWedgelet, Int* piMask, Int iMaskStride, Int& riPredDC1, Int& riPredDC2, Bool bAbove, Bool bLeft )
    3283 {
    3284   riPredDC1 = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) ); //pred val, if no neighbors are available
    3285   riPredDC2 = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) );
    3286 
    3287   if( !bAbove && !bLeft ) { return; }
    3288 
    3289   UInt uiNumSmpDC1 = 0, uiNumSmpDC2 = 0;
    3290   Int iPredDC1 = 0, iPredDC2 = 0;
    3291 
    3292   Bool* pabWedgePattern = pcWedgelet->getPattern();
    3293   UInt  uiWedgeStride   = pcWedgelet->getStride();
    3294 
    3295 #if HS_REFERENCE_SUBSAMPLE_C0154
    3296   Int subSamplePix;
    3297   if ( pcWedgelet->getWidth() == 32 )
    3298   {
    3299     subSamplePix = 2;
     1473Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, Int &iShift, TextType eType )
     1474#endif
     1475{
     1476  TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
     1477  Pel *pRec = NULL, *pRef = NULL;
     1478  UInt uiWidth, uiHeight, uiTmpPartIdx;
     1479  Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride();
     1480  Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride();
     1481  Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer;
     1482
     1483  iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
     1484  iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
     1485  iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 );
     1486  iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 );
     1487  iRefX   = iCUPelX + iHor;
     1488  iRefY   = iCUPelY + iVer;
     1489  if( eType != TEXT_LUMA )
     1490  {
     1491    iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 );
     1492    iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 );
     1493  }
     1494  uiWidth  = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 )  : ( pcCU->getWidth( 0 )  >> 1 );
     1495  uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 );
     1496
     1497  Int i, j, iCountShift = 0;
     1498
     1499  // LLS parameters estimation -->
     1500
     1501  Int x = 0, y = 0, xx = 0, xy = 0;
     1502#if SHARP_ILLUCOMP_REFINE_E0046
     1503  Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12);
     1504#endif
     1505
     1506  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 )
     1507  {
     1508    iRefOffset = iHor + iVer * iRefStride - iRefStride;
     1509    if( eType == TEXT_LUMA )
     1510    {
     1511      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
     1512      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
     1513    }
     1514    else if( eType == TEXT_CHROMA_U )
     1515    {
     1516      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
     1517      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
     1518    }
     1519    else
     1520    {
     1521      assert( eType == TEXT_CHROMA_V );
     1522      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
     1523      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
     1524    }
     1525
     1526#if SHARP_ILLUCOMP_REFINE_E0046
     1527    for( j = 0; j < uiWidth; j+=2 )
     1528#else
     1529    for( j = 0; j < uiWidth; j++ )
     1530#endif
     1531    {
     1532      x += pRef[j];
     1533      y += pRec[j];
     1534#if SHARP_ILLUCOMP_REFINE_E0046
     1535      xx += (pRef[j] * pRef[j])>>precShift;
     1536      xy += (pRef[j] * pRec[j])>>precShift;
     1537#else
     1538      xx += pRef[j] * pRef[j];
     1539      xy += pRef[j] * pRec[j];
     1540#endif
     1541    }
     1542#if SHARP_ILLUCOMP_REFINE_E0046
     1543    iCountShift += g_aucConvertToBit[ uiWidth ] + 1;
     1544#else
     1545    iCountShift += g_aucConvertToBit[ uiWidth ] + 2;
     1546#endif
     1547  }
     1548
     1549
     1550  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 )
     1551  {
     1552    iRefOffset = iHor + iVer * iRefStride - 1;
     1553    if( eType == TEXT_LUMA )
     1554    {
     1555      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
     1556      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
     1557    }
     1558    else if( eType == TEXT_CHROMA_U )
     1559    {
     1560      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
     1561      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
     1562    }
     1563    else
     1564    {
     1565      assert( eType == TEXT_CHROMA_V );
     1566      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
     1567      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
     1568    }
     1569
     1570#if SHARP_ILLUCOMP_REFINE_E0046
     1571    for( i = 0; i < uiHeight; i+=2 )
     1572#else
     1573    for( i = 0; i < uiHeight; i++ )
     1574#endif
     1575    {
     1576      x += pRef[0];
     1577      y += pRec[0];
     1578#if SHARP_ILLUCOMP_REFINE_E0046
     1579      xx += (pRef[0] * pRef[0])>>precShift;
     1580      xy += (pRef[0] * pRec[0])>>precShift;
     1581
     1582      pRef += iRefStride*2;
     1583      pRec += iRecStride*2;
     1584#else
     1585      xx += pRef[0] * pRef[0];
     1586      xy += pRef[0] * pRec[0];
     1587
     1588      pRef += iRefStride;
     1589      pRec += iRecStride;
     1590#endif
     1591    }
     1592#if SHARP_ILLUCOMP_REFINE_E0046
     1593    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 );
     1594#else
     1595    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 );
     1596#endif
     1597  }
     1598
     1599#if SHARP_ILLUCOMP_REFINE_E0046
     1600  xy += xx >> IC_REG_COST_SHIFT;
     1601  xx += xx >> IC_REG_COST_SHIFT;
     1602  Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift);
     1603  Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift);
     1604  const Int iShift = IC_CONST_SHIFT;
     1605  {
     1606#else
     1607  Int iTempShift = ( ( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC ) + g_aucConvertToBit[ uiWidth ] + 3 - 15;
     1608
     1609  if( iTempShift > 0 )
     1610  {
     1611    x  = ( x +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
     1612    y  = ( y +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
     1613    xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
     1614    xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
     1615    iCountShift -= iTempShift;
     1616  }
     1617
     1618  iShift = 13;
     1619
     1620  if( iCountShift == 0 )
     1621  {
     1622    a = 1;
     1623    b = 0;
     1624    iShift = 0;
    33001625  }
    33011626  else
    33021627  {
    3303     subSamplePix = 1;
    3304   }
    3305 #endif
    3306 
    3307   if( bAbove )
    3308   {
    3309 #if HS_REFERENCE_SUBSAMPLE_C0154
    3310     for( Int k = 0; k < pcWedgelet->getWidth(); k+=subSamplePix )
     1628    Int a1 = ( xy << iCountShift ) - y * x;
     1629    Int a2 = ( xx << iCountShift ) - x * x;             
     1630#endif
     1631    {
     1632      const Int iShiftA2 = 6;
     1633#if !SHARP_ILLUCOMP_REFINE_E0046
     1634      const Int iShiftA1 = 15;
     1635#endif
     1636      const Int iAccuracyShift = 15;
     1637
     1638      Int iScaleShiftA2 = 0;
     1639      Int iScaleShiftA1 = 0;
     1640      Int a1s = a1;
     1641      Int a2s = a2;
     1642
     1643#if SHARP_ILLUCOMP_REFINE_E0046
     1644      a1 = Clip3(0, 2*a2, a1);
     1645      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2;
     1646      iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF;
    33111647#else
    3312     for( Int k = 0; k < pcWedgelet->getWidth(); k++ )
    3313 #endif
    3314     {
    3315       if( true == pabWedgePattern[k] )
    3316       {
    3317         iPredDC2 += piMask[k-iMaskStride];
    3318         uiNumSmpDC2++;
     1648      iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1;
     1649      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; 
     1650#endif
     1651
     1652      if( iScaleShiftA1 < 0 )
     1653      {
     1654        iScaleShiftA1 = 0;
     1655      }
     1656
     1657      if( iScaleShiftA2 < 0 )
     1658      {
     1659        iScaleShiftA2 = 0;
     1660      }
     1661
     1662      Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
     1663
     1664
     1665      a2s = a2 >> iScaleShiftA2;
     1666
     1667      a1s = a1 >> iScaleShiftA1;
     1668
     1669#if SHARP_ILLUCOMP_REFINE_E0046
     1670      a = a1s * m_uiaShift[ a2s ];
     1671      a = a >> iScaleShiftA;
     1672#else
     1673      if (a2s >= 1)
     1674      {
     1675        a = a1s * m_uiaShift[ a2s - 1];
    33191676      }
    33201677      else
    33211678      {
    3322         iPredDC1 += piMask[k-iMaskStride];
    3323         uiNumSmpDC1++;
    3324       }
    3325     }
    3326   }
    3327   if( bLeft )
    3328   {
    3329 #if HS_REFERENCE_SUBSAMPLE_C0154
    3330     for( Int k = 0; k < pcWedgelet->getHeight(); k+=subSamplePix )
    3331 #else
    3332     for( Int k = 0; k < pcWedgelet->getHeight(); k++ )
    3333 #endif
    3334     {
    3335       if( true == pabWedgePattern[k*uiWedgeStride] )
    3336       {
    3337         iPredDC2 += piMask[k*iMaskStride-1];
    3338         uiNumSmpDC2++;
    3339       }
     1679        a = 0;
     1680      }
     1681
     1682      if( iScaleShiftA < 0 )
     1683      {
     1684        a = a << -iScaleShiftA;
     1685      }
    33401686      else
    33411687      {
    3342         iPredDC1 += piMask[k*iMaskStride-1];
    3343         uiNumSmpDC1++;
    3344       }
    3345     }
    3346   }
    3347 
    3348   if( uiNumSmpDC1 > 0 )
    3349   {
    3350     iPredDC1 /= uiNumSmpDC1;
    3351     riPredDC1 = iPredDC1;
    3352   }
    3353   if( uiNumSmpDC2 > 0 )
    3354   {
    3355     iPredDC2 /= uiNumSmpDC2;
    3356     riPredDC2 = iPredDC2;
    3357   }
    3358 }
    3359 #endif
    3360 
    3361 Void TComPrediction::calcWedgeDCs( TComWedgelet* pcWedgelet, Pel* piOrig, UInt uiStride, Int& riDC1, Int& riDC2 )
    3362 {
    3363   UInt uiDC1 = 0;
    3364   UInt uiDC2 = 0;
    3365   UInt uiNumPixDC1 = 0, uiNumPixDC2 = 0;
    3366   Bool* pabWedgePattern = pcWedgelet->getPattern();
    3367   if( uiStride == pcWedgelet->getStride() )
    3368   {
    3369     for( UInt k = 0; k < (pcWedgelet->getWidth() * pcWedgelet->getHeight()); k++ )
    3370     {
    3371       if( true == pabWedgePattern[k] )
    3372       {
    3373         uiDC2 += piOrig[k];
    3374         uiNumPixDC2++;
     1688        a = a >> iScaleShiftA;
     1689      }
     1690
     1691      a = Clip3( -( 1 << 15 ), ( 1 << 15 ) - 1, a );
     1692
     1693      Int minA = -(1 << (6));
     1694      Int maxA = (1 << 6) - 1;
     1695      if( a <= maxA && a >= minA )
     1696      {
     1697        // do nothing
    33751698      }
    33761699      else
    33771700      {
    3378         uiDC1 += piOrig[k];
    3379         uiNumPixDC1++;
    3380       }
     1701        Short n = CountLeadingZerosOnes( a );
     1702        a = a >> (9-n);
     1703        iShift -= (9-n);
     1704      }
     1705#endif
     1706      b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
     1707    }
     1708  }   
     1709}
     1710#endif
     1711
     1712#if H_3D_VSP
     1713
     1714#if NTT_VSP_COMMON_E0207_E0208
     1715// not fully support iRatioTxtPerDepth* != 1
     1716Void TComPrediction::xGetVirtualDepth( TComDataCU *cu, TComPicYuv *picRefDepth, TComMv *mv, UInt partAddr, Int width, Int height, TComYuv *yuvDepth, Int ratioTxtPerDepthX, Int ratioTxtPerDepthY )
     1717{
     1718  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
     1719  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
     1720
     1721  Int refDepStride = picRefDepth->getStride();
     1722
     1723#if NTT_VSP_VECTOR_CLIP_E0208
     1724
     1725  Int refDepOffset  = ( (mv->getHor()+2) >> 2 ) + ( (mv->getVer()+2) >> 2 ) * refDepStride;
     1726  Pel *refDepth     = picRefDepth->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
     1727
     1728  if( ratioTxtPerDepthX!=1 || ratioTxtPerDepthY!=1 )
     1729  {
     1730    Int posX, posY;
     1731    refDepth    = picRefDepth->getLumaAddr( );
     1732    cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
     1733    posX /= ratioTxtPerDepthX; // texture position -> depth postion
     1734    posY /= ratioTxtPerDepthY;
     1735    refDepOffset += posX + posY * refDepStride;
     1736
     1737    width  /= ratioTxtPerDepthX; // texture size -> depth size
     1738    height /= ratioTxtPerDepthY;
     1739  }
     1740
     1741  refDepth += refDepOffset;
     1742
     1743#else // NTT_VSP_VECTOR_CLIP_E0208
     1744
     1745  Int widthDepth = picRefDepth->getWidth();
     1746  Int heightDepth = picRefDepth->getHeight();
     1747  Int posX, posY;
     1748  cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
     1749  posX /= ratioTxtPerDepthX; // texture position -> depth postion
     1750  posY /= ratioTxtPerDepthY;
     1751 
     1752  posX = Clip3(0, widthDepth-width,   posX + ((mv->getHor()+2)>>2));
     1753  posY = Clip3(0, heightDepth-height, posY + ((mv->getVer()+2)>>2));
     1754 
     1755  Pel *refDepth  = picRefDepth->getLumaAddr() + posX + posY * refDepStride;
     1756
     1757#endif // NTT_VSP_VECTOR_CLIP_E0208
     1758
     1759  Int depStride = yuvDepth->getStride();
     1760  Pel *depth = yuvDepth->getLumaAddr();
     1761
     1762#if NTT_VSP_ADAPTIVE_SPLIT_E0207
     1763
     1764  if( width<8 || height<8 )
     1765  { // no split
     1766    Int rightOffset = width - 1;
     1767    Int depStrideBlock = depStride * nTxtPerDepthY;
     1768    Pel *refDepthTop = refDepth;
     1769    Pel *refDepthBot = refDepthTop + (height-1)*refDepStride;
     1770
     1771    Pel maxDepth = refDepthTop[0] > refDepthBot[0] ? refDepthTop[0] : refDepthBot[0];
     1772    if( maxDepth < refDepthTop[rightOffset] ) { maxDepth = refDepthTop[rightOffset]; }
     1773    if( maxDepth < refDepthBot[rightOffset] ) { maxDepth = refDepthBot[rightOffset]; }
     1774
     1775    for( Int sY=0; sY<height; sY+=nTxtPerDepthY )
     1776    {
     1777      for( Int sX=0; sX<width; sX+=nTxtPerDepthX )
     1778      {
     1779        depth[sX] = maxDepth;
     1780      }
     1781      depth += depStrideBlock;
    33811782    }
    33821783  }
    33831784  else
    3384   {
    3385     Pel* piTemp = piOrig;
    3386     UInt uiWedgeStride = pcWedgelet->getStride();
    3387     for( UInt uiY = 0; uiY < pcWedgelet->getHeight(); uiY++ )
    3388     {
    3389       for( UInt uiX = 0; uiX < pcWedgelet->getWidth(); uiX++ )
    3390       {
    3391         if( true == pabWedgePattern[uiX] )
     1785  { // split to 4x8, or 8x4
     1786    Int blocksize    = 8;
     1787    Int subblocksize = 4;
     1788    Int depStrideBlock = depStride * blocksize;
     1789    Pel *depthTmp = NULL;
     1790    Int depStrideTmp = depStride * nTxtPerDepthY;
     1791    Int offset[4] = { 0, subblocksize-1, subblocksize, blocksize-1 };
     1792    Pel *refDepthTmp[4] = { NULL, NULL, NULL, NULL };
     1793    Pel repDepth4x8[2] = {0, 0};
     1794    Pel repDepth8x4[2] = {0, 0};
     1795
     1796    Int refDepStrideBlock    = refDepStride * blocksize;
     1797    Int refDepStrideSubBlock = refDepStride * subblocksize;
     1798
     1799    refDepthTmp[0] = refDepth;
     1800    refDepthTmp[2] = refDepthTmp[0] + refDepStrideSubBlock;
     1801    refDepthTmp[1] = refDepthTmp[2] - refDepStride;
     1802    refDepthTmp[3] = refDepthTmp[1] + refDepStrideSubBlock;
     1803
     1804    for( Int y=0; y<height; y+=blocksize )
     1805    {
     1806      for( Int x=0; x<width; x+=blocksize )
     1807      {
     1808        Bool ULvsBR = false, URvsBL = false;
     1809
     1810        ULvsBR = refDepthTmp[0][x+offset[0]] < refDepthTmp[3][x+offset[3]];
     1811        URvsBL = refDepthTmp[0][x+offset[3]] < refDepthTmp[3][x+offset[0]];
     1812
     1813        if( ULvsBR ^ URvsBL )
     1814        { // 4x8
     1815          repDepth4x8[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[1]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[1]];
     1816          if( repDepth4x8[0] < refDepthTmp[3][x+offset[0]] )
     1817          {
     1818            repDepth4x8[0] = refDepthTmp[3][x+offset[0]];
     1819          }
     1820          if( repDepth4x8[0] < refDepthTmp[3][x+offset[1]] )
     1821          {
     1822            repDepth4x8[0] = refDepthTmp[3][x+offset[1]];
     1823          }
     1824          repDepth4x8[1] = refDepthTmp[0][x+offset[2]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[2]] : refDepthTmp[0][x+offset[3]];
     1825          if( repDepth4x8[1] < refDepthTmp[3][x+offset[2]] )
     1826          {
     1827            repDepth4x8[1] = refDepthTmp[3][x+offset[2]];
     1828          }
     1829          if( repDepth4x8[1] < refDepthTmp[3][x+offset[3]] )
     1830          {
     1831            repDepth4x8[1] = refDepthTmp[3][x+offset[3]];
     1832          }
     1833
     1834          depthTmp = &depth[x];
     1835          for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY )
     1836          {
     1837            for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX )
     1838            {
     1839              depthTmp[sX] = repDepth4x8[0];
     1840            }
     1841            depthTmp += depStrideTmp;
     1842          }
     1843          depthTmp = &depth[x+subblocksize];
     1844          for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY )
     1845          {
     1846            for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX )
     1847            {
     1848              depthTmp[sX] = repDepth4x8[1];
     1849            }
     1850            depthTmp += depStrideTmp;
     1851          }
     1852        }
     1853        else
     1854        { // 8x4
     1855          repDepth8x4[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[3]];
     1856          if( repDepth8x4[0] < refDepthTmp[1][x+offset[0]] )
     1857          {
     1858            repDepth8x4[0] = refDepthTmp[1][x+offset[0]];
     1859          }
     1860          if( repDepth8x4[0] < refDepthTmp[1][x+offset[3]] )
     1861          {
     1862            repDepth8x4[0] = refDepthTmp[1][x+offset[3]];
     1863          }
     1864          repDepth8x4[1] = refDepthTmp[2][x+offset[0]] > refDepthTmp[2][x+offset[3]] ? refDepthTmp[2][x+offset[0]] : refDepthTmp[2][x+offset[3]];
     1865          if( repDepth8x4[1] < refDepthTmp[3][x+offset[0]] )
     1866          {
     1867            repDepth8x4[1] = refDepthTmp[3][x+offset[0]];
     1868          }
     1869          if( repDepth8x4[1] < refDepthTmp[3][x+offset[3]] )
     1870          {
     1871            repDepth8x4[1] = refDepthTmp[3][x+offset[3]];
     1872          }
     1873         
     1874          depthTmp = &depth[x];
     1875          for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY )
     1876          {
     1877            for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX )
     1878            {
     1879              depthTmp[sX] = repDepth8x4[0];
     1880            }
     1881            depthTmp += depStrideTmp;
     1882          }
     1883          for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY )
     1884          {
     1885            for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX )
     1886            {
     1887              depthTmp[sX] = repDepth8x4[1];
     1888            }
     1889            depthTmp += depStrideTmp;
     1890          }
     1891        }
     1892      }
     1893      refDepthTmp[0] += refDepStrideBlock;
     1894      refDepthTmp[1] += refDepStrideBlock;
     1895      refDepthTmp[2] += refDepStrideBlock;
     1896      refDepthTmp[3] += refDepStrideBlock;
     1897      depth       += depStrideBlock;
     1898    }
     1899  }
     1900
     1901#else // NTT_VSP_ADAPTIVE_SPLIT_E0207
     1902
     1903  Int rightOffset = nTxtPerDepthX - 1;
     1904  Int depStrideBlock = depStride * nTxtPerDepthY;
     1905  Int refDepStrideBlock = refDepStride * nTxtPerDepthY;
     1906  Pel *refDepthTop = refDepth;
     1907  Pel *refDepthBot = refDepthTop + (nTxtPerDepthY-1)*refDepStride;
     1908
     1909  for( Int y=0; y<height; y+= nTxtPerDepthY )
     1910  {
     1911    for( Int x=0; x<width; x+=nTxtPerDepthX )
     1912    {
     1913      Pel maxDepth = refDepthTop[x] > refDepthBot[x] ? refDepthTop[x] : refDepthBot[x];
     1914
     1915      if( maxDepth < refDepthTop[x+rightOffset] )
     1916      {
     1917        maxDepth = refDepthTop[x+rightOffset];
     1918      }
     1919      if( maxDepth < refDepthBot[x+rightOffset] )
     1920      {
     1921        maxDepth = refDepthBot[x+rightOffset];
     1922      }
     1923
     1924      depth[x] = maxDepth;
     1925
     1926    }
     1927    refDepthTop += refDepStrideBlock;
     1928    refDepthBot += refDepStrideBlock;
     1929    depth       += depStrideBlock;
     1930  }
     1931
     1932#endif // NTT_VSP_ADAPTIVE_SPLIT_E0207
     1933}
     1934
     1935Void TComPrediction::xPredInterLumaBlkFromDM( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi )
     1936{
     1937  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
     1938  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
     1939 
     1940  Int refStride = picRef->getStride();
     1941  Int dstStride = yuvDst->getStride();
     1942  Int depStride = yuvDepth->getStride();
     1943  Int refStrideBlock = refStride  * nTxtPerDepthY;
     1944  Int dstStrideBlock = dstStride * nTxtPerDepthY;
     1945  Int depStrideBlock = depStride * nTxtPerDepthY;
     1946
     1947  Pel *ref    = picRef->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
     1948  Pel *dst    = yuvDst->getLumaAddr(partAddr);
     1949  Pel *depth  = yuvDepth->getLumaAddr();
     1950 
     1951#if !(NTT_VSP_DC_BUGFIX_E0208)
     1952  Int widthLuma = picRef->getWidth();
     1953  Int posX, posY;
     1954  cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
     1955#endif
     1956
     1957#if H_3D_VSP_BLOCKSIZE == 1
     1958#if H_3D_VSP_CONSTRAINED
     1959  //get LUT based horizontal reference range
     1960  Int range = xGetConstrainedSize(width, height);
     1961
     1962  // The minimum depth value
     1963  Int minRelativePos = MAX_INT;
     1964  Int maxRelativePos = MIN_INT;
     1965
     1966  Pel* depthTemp, *depthInitial=depth;
     1967  for (Int yTxt = 0; yTxt < height; yTxt++)
     1968  {
     1969    for (Int xTxt = 0; xTxt < width; xTxt++)
     1970    {
     1971      if (depthPosX+xTxt < widthDepth)
     1972      {
     1973        depthTemp = depthInitial + xTxt;
     1974      }
     1975      else
     1976      {
     1977        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
     1978      }
     1979
     1980      Int disparity = shiftLUT[ *depthTemp ]; // << iShiftPrec;
     1981      Int disparityInt = disparity >> 2;
     1982
     1983      if( disparity <= 0)
     1984      {
     1985        if (minRelativePos > disparityInt+xTxt)
    33921986        {
    3393           uiDC2 += piTemp[uiX];
    3394           uiNumPixDC2++;
     1987          minRelativePos = disparityInt+xTxt;
     1988        }
     1989      }
     1990      else
     1991      {
     1992        if (maxRelativePos < disparityInt+xTxt)
     1993        {
     1994          maxRelativePos = disparityInt+xTxt;
     1995        }
     1996      }
     1997    }
     1998    if (depthPosY+yTxt < heightDepth)
     1999    {
     2000      depthInitial = depthInitial + depStride;
     2001    }
     2002  }
     2003
     2004  Int disparity_tmp = shiftLUT[ *depth ]; // << iShiftPrec;
     2005  if (disparity_tmp <= 0)
     2006  {
     2007    maxRelativePos = minRelativePos + range -1 ;
     2008  }
     2009  else
     2010  {
     2011    minRelativePos = maxRelativePos - range +1 ;
     2012  }
     2013#endif
     2014#endif // H_3D_VSP_BLOCKSIZE == 1
     2015
     2016  TComMv dv(0, 0);
     2017
     2018  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
     2019  {
     2020    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
     2021    {
     2022      Pel repDepth = depth[ xTxt ];
     2023      assert( repDepth >= 0 && repDepth <= 255 );
     2024
     2025      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec ??
     2026      Int xFrac = disparity & 0x3;
     2027
     2028#if NTT_VSP_DC_BUGFIX_E0208
     2029
     2030      dv.setHor( disparity );
     2031      cu->clipMv( dv );
     2032
     2033      Int refOffset = xTxt + (dv.getHor() >> 2);
     2034     
     2035#if H_3D_VSP_CONSTRAINED
     2036      if(refOffset<minRelativePos || refOffset>maxRelativePos)
     2037      {
     2038        xFrac = 0;
     2039      }
     2040      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
     2041#endif
     2042
     2043      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
     2044      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
     2045
     2046#else // NTT_VSP_DC_BUGFIX_E0208
     2047
     2048      for( Int j=0; j < nTxtPerDepthX; j++ )
     2049      {
     2050        Int refOffset = xTxt+j + (disparity >> 2);
     2051#if H_3D_VSP_CONSTRAINED
     2052        if(refOffset<minRelativePos || refOffset>maxRelativePos)
     2053        {
     2054          xFrac = 0;
     2055        }
     2056        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
     2057#endif
     2058        Int absX  = posX + refOffset;
     2059
     2060        if (xFrac == 0)
     2061        {
     2062          absX = Clip3(0, widthLuma-1, absX);
    33952063        }
    33962064        else
    33972065        {
    3398           uiDC1 += piTemp[uiX];
    3399           uiNumPixDC1++;
    3400         }
    3401       }
    3402       piTemp          += uiStride;
    3403       pabWedgePattern += uiWedgeStride;
    3404     }
    3405   }
    3406 
    3407   if( uiNumPixDC1 > 0 ) { riDC1 = uiDC1 / uiNumPixDC1; }
    3408   else                  { riDC1 = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) ); }
    3409 
    3410   if( uiNumPixDC2 > 0 ) { riDC2 = uiDC2 / uiNumPixDC2; }
    3411   else                  { riDC2 = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) ); }
    3412 }
    3413 
    3414 Void TComPrediction::assignWedgeDCs2Pred( TComWedgelet* pcWedgelet, Pel* piPred, UInt uiStride, Int iDC1, Int iDC2 )
    3415 {
    3416   Bool* pabWedgePattern = pcWedgelet->getPattern();
    3417 
    3418   if( uiStride == pcWedgelet->getStride() )
    3419   {
    3420     for( UInt k = 0; k < (pcWedgelet->getWidth() * pcWedgelet->getHeight()); k++ )
    3421     {
    3422       if( true == pabWedgePattern[k] )
    3423       {
    3424         piPred[k] = iDC2;
     2066          absX = Clip3(4, widthLuma-5, absX);
     2067        }
     2068
     2069        refOffset = absX - posX;
     2070        assert( ref[refOffset] >= 0 && ref[refOffset] <= 255 );
     2071       
     2072        m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt+j], dstStride, 1, nTxtPerDepthY, xFrac, !isBi );
     2073      }
     2074
     2075#endif // NTT_VSP_DC_BUGFIX_E0208
     2076
     2077    }
     2078    ref   += refStrideBlock;
     2079    dst   += dstStrideBlock;
     2080    depth += depStrideBlock;
     2081  }
     2082
     2083}
     2084
     2085Void TComPrediction::xPredInterChromaBlkFromDM  ( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi )
     2086{
     2087#if (H_3D_VSP_BLOCKSIZE==1)
     2088  Int nTxtPerDepthX = 1;
     2089  Int nTxtPerDepthY = 1;
     2090#else
     2091  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE >> 1;
     2092  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE >> 1;
     2093#endif
     2094
     2095  Int refStride = picRef->getCStride();
     2096  Int dstStride = yuvDst->getCStride();
     2097  Int depStride = yuvDepth->getStride();
     2098  Int refStrideBlock = refStride * nTxtPerDepthY;
     2099  Int dstStrideBlock = dstStride * nTxtPerDepthY;
     2100  Int depStrideBlock = depStride * (nTxtPerDepthY<<1);
     2101
     2102  Pel *refCb  = picRef->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
     2103  Pel *refCr  = picRef->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
     2104  Pel *dstCb  = yuvDst->getCbAddr(partAddr);
     2105  Pel *dstCr  = yuvDst->getCrAddr(partAddr);
     2106  Pel *depth  = yuvDepth->getLumaAddr();
     2107
     2108#if !(NTT_VSP_DC_BUGFIX_E0208)
     2109  Int widthChroma = picRef->getWidth() >> 1;
     2110  Int posX, posY;
     2111  cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
     2112  posX >>= 1;
     2113  posY >>= 1;
     2114#endif
     2115 
     2116#if H_3D_VSP_BLOCKSIZE == 1
     2117#if H_3D_VSP_CONSTRAINED
     2118  //get LUT based horizontal reference range
     2119  Int range = xGetConstrainedSize(width, height, false);
     2120
     2121  // The minimum depth value
     2122  Int minRelativePos = MAX_INT;
     2123  Int maxRelativePos = MIN_INT;
     2124
     2125  Int depthTmp;
     2126  for (Int yTxt=0; yTxt<height; yTxt++)
     2127  {
     2128    for (Int xTxt=0; xTxt<width; xTxt++)
     2129    {
     2130      depthTmp = m_pDepthBlock[xTxt+yTxt*width];
     2131      Int disparity = shiftLUT[ depthTmp ]; // << iShiftPrec;
     2132      Int disparityInt = disparity >> 3;//in chroma resolution
     2133
     2134      if (disparityInt < 0)
     2135      {
     2136        if (minRelativePos > disparityInt+xTxt)
     2137        {
     2138          minRelativePos = disparityInt+xTxt;
     2139        }
    34252140      }
    34262141      else
    34272142      {
    3428         piPred[k] = iDC1;
    3429       }
    3430     }
     2143        if (maxRelativePos < disparityInt+xTxt)
     2144        {
     2145          maxRelativePos = disparityInt+xTxt;
     2146        }
     2147      }
     2148    }
     2149  }
     2150
     2151  depthTmp = m_pDepthBlock[0];
     2152  Int disparity_tmp = shiftLUT[ depthTmp ]; // << iShiftPrec;
     2153  if ( disparity_tmp < 0 )
     2154  {
     2155    maxRelativePos = minRelativePos + range - 1;
    34312156  }
    34322157  else
    34332158  {
    3434     Pel* piTemp = piPred;
    3435     UInt uiWedgeStride = pcWedgelet->getStride();
    3436     for( UInt uiY = 0; uiY < pcWedgelet->getHeight(); uiY++ )
    3437     {
    3438       for( UInt uiX = 0; uiX < pcWedgelet->getWidth(); uiX++ )
    3439       {
    3440         if( true == pabWedgePattern[uiX] )
     2159    minRelativePos = maxRelativePos - range + 1;
     2160  }
     2161
     2162#endif // H_3D_VSP_CONSTRAINED
     2163#endif // H_3D_VSP_BLOCKSIZE == 1
     2164
     2165  TComMv dv(0, 0);
     2166  // luma size -> chroma size
     2167  height >>= 1;
     2168  width  >>= 1;
     2169
     2170  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
     2171  {
     2172    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
     2173    {
     2174      Pel repDepth = depth[ xTxt<<1 ];
     2175      assert( repDepth >= 0 && repDepth <= 255 );
     2176
     2177      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec;
     2178      Int xFrac = disparity & 0x7;
     2179     
     2180#if NTT_VSP_DC_BUGFIX_E0208
     2181
     2182      dv.setHor( disparity );
     2183      cu->clipMv( dv );
     2184
     2185      Int refOffset = xTxt + (dv.getHor() >> 3);
     2186
     2187#if H_3D_VSP_CONSTRAINED
     2188      if(refOffset<minRelativePos || refOffset>maxRelativePos)
     2189      {
     2190        xFrac = 0;
     2191      }
     2192      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
     2193#endif
     2194
     2195      assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
     2196      assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
     2197
     2198      m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
     2199      m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
     2200
     2201#else // NTT_VSP_DC_BUGFIX_E0208
     2202     
     2203      for( Int j=0; j < nTxtPerDepthX; j++ )
     2204      {
     2205        Int refOffset = xTxt+j + (disparity >> 3);
     2206#if H_3D_VSP_CONSTRAINED
     2207        if(refOffset<minRelativePos || refOffset>maxRelativePos)
    34412208        {
    3442           piTemp[uiX] = iDC2;
     2209          xFrac = 0;
     2210        }
     2211        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
     2212#endif
     2213        Int absX  = posX + refOffset;
     2214
     2215        if (xFrac == 0)
     2216        {
     2217          absX = Clip3(0, widthChroma-1, absX);
    34432218        }
    34442219        else
    34452220        {
    3446           piTemp[uiX] = iDC1;
    3447         }
    3448       }
    3449       piTemp          += uiStride;
    3450       pabWedgePattern += uiWedgeStride;
    3451     }
    3452   }
    3453 }
    3454 
    3455 Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Int& riDeltaDC )
    3456 {
    3457   Int  iSign  = riDeltaDC < 0 ? -1 : 1;
    3458   UInt uiAbs  = abs( riDeltaDC );
    3459 
    3460   Int iQp = pcCU->getQP(0);
    3461   Double dMax = (Double)( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) );
    3462   Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 + g_iDeltaDCsQuantOffset ) );
    3463 
    3464   riDeltaDC = iSign * roftoi( uiAbs * dStepSize );
    3465   return;
    3466 }
    3467 
    3468 Void TComPrediction::xDeltaDCQuantScaleDown( TComDataCU*  pcCU, Int& riDeltaDC )
    3469 {
    3470   Int  iSign  = riDeltaDC < 0 ? -1 : 1;
    3471   UInt uiAbs  = abs( riDeltaDC );
    3472 
    3473   Int iQp = pcCU->getQP(0);
    3474   Double dMax = (Double)( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) );
    3475   Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 + g_iDeltaDCsQuantOffset ) );
    3476 
    3477   riDeltaDC = iSign * roftoi( uiAbs / dStepSize );
    3478   return;
    3479 }
    3480 #endif
    3481 
    3482 #if HHI_DMM_PRED_TEX
    3483 Void TComPrediction::getBestContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
     2221          absX = Clip3(4, widthChroma-5, absX);
     2222        }
     2223
     2224        refOffset = absX - posX;
     2225        assert( refCb[refOffset] >= 0 && refCb[refOffset] <= 255 );
     2226        assert( refCr[refOffset] >= 0 && refCr[refOffset] <= 255 );
     2227
     2228        m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt+j], dstStride, 1, nTxtPerDepthY, xFrac, !isBi );
     2229        m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt+j], dstStride, 1, nTxtPerDepthY, xFrac, !isBi );
     2230      }
     2231
     2232#endif // NTT_VSP_DC_BUGFIX_E0208
     2233    }
     2234    refCb += refStrideBlock;
     2235    refCr += refStrideBlock;
     2236    dstCb += dstStrideBlock;
     2237    dstCr += dstStrideBlock;
     2238    depth += depStrideBlock;
     2239  }
     2240
     2241}
     2242#else // NTT_VSP_COMMON_E0207_E0208
     2243
     2244// Input:
     2245// refPic: Ref picture. Full picture, with padding
     2246// posX, posY:     PU position, texture
     2247// sizeX, sizeY: PU size
     2248// partAddr: z-order index
     2249// dv: disparity vector. derived from neighboring blocks
     2250//
     2251// Output: dstPic, PU predictor 64x64
     2252Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr,Int posX, Int posY
     2253                                            , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi )
     2254{
     2255  Int widthLuma;
     2256  Int heightLuma;
     2257
     2258  if (isDepth)
     2259  {
     2260    widthLuma   =  pPicBaseDepth->getWidth();
     2261    heightLuma  =  pPicBaseDepth->getHeight();
     2262  }
     2263  else
     2264  {
     2265    widthLuma   =  refPic->getWidth();
     2266    heightLuma  =  refPic->getHeight();
     2267  }
     2268
     2269#if H_3D_VSP_BLOCKSIZE != 1
     2270  Int widthDepth  = pPicBaseDepth->getWidth();
     2271  Int heightDepth = pPicBaseDepth->getHeight();
     2272#endif
     2273
     2274#if H_3D_VSP_CONSTRAINED
     2275  Int widthDepth  = pPicBaseDepth->getWidth();
     2276  Int heightDepth = pPicBaseDepth->getHeight();
     2277#endif
     2278
     2279  Int nTxtPerDepthX = widthLuma  / ( pPicBaseDepth->getWidth() );  // texture pixel # per depth pixel
     2280  Int nTxtPerDepthY = heightLuma / ( pPicBaseDepth->getHeight() );
     2281
     2282  Int refStride = refPic->getStride();
     2283  Int dstStride = dstPic->getStride();
     2284  Int depStride =  pPicBaseDepth->getStride();
     2285  Int depthPosX = Clip3(0,   widthLuma - sizeX,  (posX/nTxtPerDepthX) + ((dv->getHor()+2)>>2));
     2286  Int depthPosY = Clip3(0,   heightLuma- sizeY,  (posY/nTxtPerDepthY) + ((dv->getVer()+2)>>2));
     2287  Pel *ref    = refPic->getLumaAddr() + posX + posY * refStride;
     2288  Pel *dst    = dstPic->getLumaAddr(partAddr);
     2289  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;
     2290
     2291#if H_3D_VSP_BLOCKSIZE != 1
     2292#if H_3D_VSP_BLOCKSIZE == 2
     2293  Int  dW = sizeX>>1;
     2294  Int  dH = sizeY>>1;
     2295#endif
     2296#if H_3D_VSP_BLOCKSIZE == 4
     2297  Int  dW = sizeX>>2;
     2298  Int  dH = sizeY>>2;
     2299#endif
     2300  {
     2301    Pel* depthi = depth;
     2302    for (Int j = 0; j < dH; j++)
     2303    {
     2304      for (Int i = 0; i < dW; i++)
     2305      {
     2306        Pel* depthTmp;
     2307#if H_3D_VSP_BLOCKSIZE == 2
     2308        if (depthPosX + (i<<1) < widthDepth)
     2309          depthTmp = depthi + (i << 1);
     2310        else
     2311          depthTmp = depthi + (widthDepth - depthPosX - 1);
     2312#endif
     2313#if H_3D_VSP_BLOCKSIZE == 4
     2314        if (depthPosX + (i<<2) < widthDepth)
     2315          depthTmp = depthi + (i << 2);
     2316        else
     2317          depthTmp = depthi + (widthDepth - depthPosX - 1);
     2318#endif
     2319        Int maxV = 0;
     2320        for (Int blockj = 0; blockj < H_3D_VSP_BLOCKSIZE; blockj+=(H_3D_VSP_BLOCKSIZE-1))
     2321        {
     2322          Int iX = 0;
     2323          for (Int blocki = 0; blocki < H_3D_VSP_BLOCKSIZE; blocki+=(H_3D_VSP_BLOCKSIZE-1))
     2324          {
     2325            if (maxV < depthTmp[iX])
     2326              maxV = depthTmp[iX];
     2327#if H_3D_VSP_BLOCKSIZE == 2
     2328            if (depthPosX + (i<<1) + blocki < widthDepth - 1)
     2329#else // H_3D_VSP_BLOCKSIZE == 4
     2330            if (depthPosX + (i<<2) + blocki < widthDepth - 1)
     2331#endif
     2332              iX = (H_3D_VSP_BLOCKSIZE-1);
     2333          }
     2334#if H_3D_VSP_BLOCKSIZE == 2
     2335          if (depthPosY + (j<<1) + blockj < heightDepth - 1)
     2336#else // H_3D_VSP_BLOCKSIZE == 4
     2337          if (depthPosY + (j<<2) + blockj < heightDepth - 1)
     2338#endif
     2339            depthTmp += depStride * (H_3D_VSP_BLOCKSIZE-1);
     2340        }
     2341        m_pDepthBlock[i+j*dW] = maxV;
     2342      } // end of i < dW
     2343#if H_3D_VSP_BLOCKSIZE == 2
     2344      if (depthPosY + ((j+1)<<1) < heightDepth)
     2345        depthi += (depStride << 1);
     2346      else
     2347        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
     2348#endif
     2349#if H_3D_VSP_BLOCKSIZE == 4
     2350      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
     2351        depthi += (depStride << 2);
     2352      else
     2353        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
     2354#endif
     2355    }
     2356  }
     2357#endif // H_3D_VSP_BLOCKSIZE != 1
     2358
     2359#if H_3D_VSP_BLOCKSIZE == 1
     2360#if H_3D_VSP_CONSTRAINED
     2361  //get LUT based horizontal reference range
     2362  Int range = xGetConstrainedSize(sizeX, sizeY);
     2363
     2364  // The minimum depth value
     2365  Int minRelativePos = MAX_INT;
     2366  Int maxRelativePos = MIN_INT;
     2367
     2368  Pel* depthTemp, *depthInitial=depth;
     2369  for (Int yTxt = 0; yTxt < sizeY; yTxt++)
     2370  {
     2371    for (Int xTxt = 0; xTxt < sizeX; xTxt++)
     2372    {
     2373      if (depthPosX+xTxt < widthDepth)
     2374        depthTemp = depthInitial + xTxt;
     2375      else
     2376        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
     2377
     2378      Int disparity = pShiftLUT[ *depthTemp ]; // << iShiftPrec;
     2379      Int disparityInt = disparity >> 2;
     2380
     2381      if( disparity <= 0)
     2382      {
     2383        if (minRelativePos > disparityInt+xTxt)
     2384            minRelativePos = disparityInt+xTxt;
     2385      }
     2386      else
     2387      {
     2388        if (maxRelativePos < disparityInt+xTxt)
     2389            maxRelativePos = disparityInt+xTxt;
     2390      }
     2391    }
     2392    if (depthPosY+yTxt < heightDepth)
     2393      depthInitial = depthInitial + depStride;
     2394  }
     2395
     2396  Int disparity_tmp = pShiftLUT[ *depth ]; // << iShiftPrec;
     2397  if (disparity_tmp <= 0)
     2398    maxRelativePos = minRelativePos + range -1 ;
     2399  else
     2400    minRelativePos = maxRelativePos - range +1 ;
     2401#endif
     2402#endif // H_3D_VSP_BLOCKSIZE == 1
     2403
     2404#if H_3D_VSP_BLOCKSIZE != 1
     2405  Int yDepth = 0;
     2406#endif
     2407  for ( Int yTxt = 0; yTxt < sizeY; yTxt += nTxtPerDepthY )
     2408  {
     2409    for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth++ )
     2410    {
     2411      Pel repDepth = 0; // to store the depth value used for warping
     2412#if H_3D_VSP_BLOCKSIZE == 1
     2413      repDepth = depth[xDepth];
     2414#endif
     2415#if H_3D_VSP_BLOCKSIZE == 2
     2416      repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW];
     2417#endif
     2418#if H_3D_VSP_BLOCKSIZE == 4
     2419      repDepth = m_pDepthBlock[(xTxt>>2) + (yTxt>>2)*dW];
     2420#endif
     2421
     2422      assert( repDepth >= 0 && repDepth <= 255 );
     2423      Int disparity = pShiftLUT[ repDepth ]; // remove << iShiftPrec ??
     2424      Int refOffset = xTxt + (disparity >> 2);
     2425      Int xFrac = disparity & 0x3;
     2426#if H_3D_VSP_CONSTRAINED
     2427      if(refOffset<minRelativePos || refOffset>maxRelativePos)
     2428        xFrac = 0;
     2429      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
     2430#endif
     2431      Int absX  = posX + refOffset;
     2432
     2433      if (xFrac == 0)
     2434        absX = Clip3(0, widthLuma-1, absX);
     2435      else
     2436        absX = Clip3(4, widthLuma-5, absX);
     2437
     2438      refOffset = absX - posX;
     2439
     2440      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
     2441      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi );
     2442    }
     2443    ref   += refStride*nTxtPerDepthY;
     2444    dst   += dstStride*nTxtPerDepthY;
     2445    depth += depStride;
     2446#if H_3D_VSP_BLOCKSIZE != 1
     2447    yDepth++;
     2448#endif
     2449
     2450  }
     2451}
     2452
     2453Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv*dv, UInt partAddr, Int posX, Int posY
     2454                                               , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi)
     2455{
     2456  Int refStride = refPic->getCStride();
     2457  Int dstStride = dstPic->getCStride();
     2458  Int depStride = pPicBaseDepth->getStride();
     2459
     2460  Int widthChroma, heightChroma;
     2461  if( isDepth)
     2462  {
     2463     widthChroma   = pPicBaseDepth->getWidth()>>1;
     2464     heightChroma  = pPicBaseDepth->getHeight()>>1;
     2465  }
     2466  else
     2467  {
     2468     widthChroma   = refPic->getWidth()>>1;
     2469     heightChroma  = refPic->getHeight()>>1;
     2470  }
     2471
     2472  // Below is only for Texture chroma component
     2473
     2474  Int widthDepth  = pPicBaseDepth->getWidth();
     2475  Int heightDepth = pPicBaseDepth->getHeight();
     2476
     2477  Int nTxtPerDepthX, nTxtPerDepthY;  // Number of texture samples per one depth sample
     2478  Int nDepthPerTxtX, nDepthPerTxtY;  // Number of depth samples per one texture sample
     2479
     2480  Int depthPosX;  // Starting position in depth image
     2481  Int depthPosY;
     2482
     2483  if ( widthChroma > widthDepth )
     2484  {
     2485    nTxtPerDepthX = widthChroma / widthDepth;
     2486    nDepthPerTxtX = 1;
     2487    depthPosX = posX / nTxtPerDepthX + ((dv->getHor()+2)>>2);
     2488  }
     2489  else
     2490  {
     2491    nTxtPerDepthX = 1;
     2492    nDepthPerTxtX = widthDepth / widthChroma;
     2493    depthPosX = posX * nDepthPerTxtX + ((dv->getHor()+2)>>2);
     2494  }
     2495  depthPosX = Clip3(0, widthDepth - (sizeX<<1), depthPosX);
     2496  if ( heightChroma > heightDepth )
     2497  {
     2498    nTxtPerDepthY = heightChroma / heightDepth;
     2499    nDepthPerTxtY = 1;
     2500    depthPosY = posY / nTxtPerDepthY + ((dv->getVer()+2)>>2);
     2501  }
     2502  else
     2503  {
     2504    nTxtPerDepthY = 1;
     2505    nDepthPerTxtY = heightDepth / heightChroma;
     2506    depthPosY = posY * nDepthPerTxtY + ((dv->getVer()+2)>>2);
     2507  }
     2508  depthPosY = Clip3(0, heightDepth - (sizeY<<1), depthPosY);
     2509
     2510  Pel *refCb  = refPic->getCbAddr() + posX + posY * refStride;
     2511  Pel *refCr  = refPic->getCrAddr() + posX + posY * refStride;
     2512  Pel *dstCb  = dstPic->getCbAddr(partAddr);
     2513  Pel *dstCr  = dstPic->getCrAddr(partAddr);
     2514  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;  // move the pointer to the current depth pixel position
     2515
     2516  Int refStrideBlock = refStride * nTxtPerDepthY;
     2517  Int dstStrideBlock = dstStride * nTxtPerDepthY;
     2518  Int depStrideBlock = depStride * nDepthPerTxtY;
     2519
     2520  if ( widthChroma > widthDepth ) // We assume
     2521  {
     2522    assert( heightChroma > heightDepth );
     2523    printf("This branch should never been reached.\n");
     2524    exit(0);
     2525  }
     2526  else
     2527  {
     2528#if H_3D_VSP_BLOCKSIZE == 1
     2529  Int  dW = sizeX;
     2530  Int  dH = sizeY;
     2531  Int  sW = 2; // search window size
     2532  Int  sH = 2;
     2533#endif
     2534#if H_3D_VSP_BLOCKSIZE == 2
     2535  Int  dW = sizeX;
     2536  Int  dH = sizeY;
     2537  Int  sW = 2; // search window size
     2538  Int  sH = 2;
     2539#endif
     2540#if H_3D_VSP_BLOCKSIZE == 4
     2541  Int  dW = sizeX>>1;
     2542  Int  dH = sizeY>>1;
     2543  Int  sW = 4; // search window size
     2544  Int  sH = 4;
     2545#endif
     2546
     2547  {
     2548    Pel* depthi = depth;
     2549    for (Int j = 0; j < dH; j++)
     2550    {
     2551      for (Int i = 0; i < dW; i++)
     2552      {
     2553        Pel* depthTmp;
     2554#if H_3D_VSP_BLOCKSIZE == 1
     2555        depthTmp = depthi + (i << 1);
     2556#endif
     2557#if H_3D_VSP_BLOCKSIZE == 2
     2558        if (depthPosX + (i<<1) < widthDepth)
     2559          depthTmp = depthi + (i << 1);
     2560        else
     2561          depthTmp = depthi + (widthDepth - depthPosX - 1);
     2562#endif
     2563#if H_3D_VSP_BLOCKSIZE == 4
     2564        if (depthPosX + (i<<2) < widthDepth)
     2565          depthTmp = depthi + (i << 2);
     2566        else
     2567          depthTmp = depthi + (widthDepth - depthPosX - 1);
     2568#endif
     2569        Int maxV = 0;
     2570        for (Int blockj = 0; blockj < sH; blockj+=(sH-1))
     2571        {
     2572          Int iX = 0;
     2573          for (Int blocki = 0; blocki < sW; blocki+=(sW-1))
     2574          {
     2575            if (maxV < depthTmp[iX])
     2576              maxV = depthTmp[iX];
     2577            if (depthPosX + i*sW + blocki < widthDepth - 1)
     2578                iX = (sW-1);
     2579          }
     2580          if (depthPosY + j*sH + blockj < heightDepth - 1)
     2581                depthTmp += depStride * (sH-1);
     2582        }
     2583        m_pDepthBlock[i+j*dW] = maxV;
     2584      } // end of i < dW
     2585#if H_3D_VSP_BLOCKSIZE == 1
     2586      if (depthPosY + ((j+1)<<1) < heightDepth)
     2587        depthi += (depStride << 1);
     2588      else
     2589        depthi  = depth + (heightDepth-1)*depStride;
     2590#endif
     2591#if H_3D_VSP_BLOCKSIZE == 2
     2592      if (depthPosY + ((j+1)<<1) < heightDepth)
     2593        depthi += (depStride << 1);
     2594      else
     2595        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
     2596#endif
     2597#if H_3D_VSP_BLOCKSIZE == 4
     2598      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
     2599        depthi += (depStride << 2);
     2600      else
     2601        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
     2602#endif
     2603    }
     2604  }
     2605
     2606
     2607#if H_3D_VSP_BLOCKSIZE == 1
     2608#if H_3D_VSP_CONSTRAINED
     2609  //get LUT based horizontal reference range
     2610  Int range = xGetConstrainedSize(sizeX, sizeY, false);
     2611
     2612  // The minimum depth value
     2613  Int minRelativePos = MAX_INT;
     2614  Int maxRelativePos = MIN_INT;
     2615
     2616  Int depthTmp;
     2617  for (Int yTxt=0; yTxt<sizeY; yTxt++)
     2618  {
     2619    for (Int xTxt=0; xTxt<sizeX; xTxt++)
     2620    {
     2621      depthTmp = m_pDepthBlock[xTxt+yTxt*dW];
     2622      Int disparity = pShiftLUT[ depthTmp ]; // << iShiftPrec;
     2623      Int disparityInt = disparity >> 3;//in chroma resolution
     2624
     2625      if (disparityInt < 0)
     2626      {
     2627        if (minRelativePos > disparityInt+xTxt)
     2628            minRelativePos = disparityInt+xTxt;
     2629      }
     2630      else
     2631      {
     2632        if (maxRelativePos < disparityInt+xTxt)
     2633            maxRelativePos = disparityInt+xTxt;
     2634      }
     2635    }
     2636  }
     2637
     2638  depthTmp = m_pDepthBlock[0];
     2639  Int disparity_tmp = pShiftLUT[ depthTmp ]; // << iShiftPrec;
     2640  if ( disparity_tmp < 0 )
     2641    maxRelativePos = minRelativePos + range - 1;
     2642  else
     2643    minRelativePos = maxRelativePos - range + 1;
     2644
     2645#endif // H_3D_VSP_CONSTRAINED
     2646#endif // H_3D_VSP_BLOCKSIZE == 1
     2647
     2648    // (sizeX, sizeY) is Chroma block size
     2649    for ( Int yTxt = 0, yDepth = 0; yTxt < sizeY; yTxt += nTxtPerDepthY, yDepth += nDepthPerTxtY )
     2650    {
     2651      for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth += nDepthPerTxtX )
     2652      {
     2653        Pel repDepth = 0; // to store the depth value used for warping
     2654#if H_3D_VSP_BLOCKSIZE == 1
     2655        repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW];
     2656#endif
     2657#if H_3D_VSP_BLOCKSIZE == 2
     2658        repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW];
     2659#endif
     2660#if H_3D_VSP_BLOCKSIZE == 4
     2661        repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW];
     2662#endif
     2663
     2664      // calculate the offset in the reference picture
     2665        Int disparity = pShiftLUT[ repDepth ]; // Remove << iShiftPrec;
     2666        Int refOffset = xTxt + (disparity >> 3); // in integer pixel in chroma image
     2667        Int xFrac = disparity & 0x7;
     2668#if H_3D_VSP_CONSTRAINED
     2669        if(refOffset < minRelativePos || refOffset > maxRelativePos)
     2670          xFrac = 0;
     2671        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
     2672#endif
     2673        Int absX  = posX + refOffset;
     2674
     2675        if (xFrac == 0)
     2676          absX = Clip3(0, widthChroma-1, absX);
     2677        else
     2678          absX = Clip3(4, widthChroma-5, absX);
     2679
     2680        refOffset = absX - posX;
     2681
     2682        assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
     2683        assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
     2684        m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
     2685        m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
     2686      }
     2687      refCb += refStrideBlock;
     2688      refCr += refStrideBlock;
     2689      dstCb += dstStrideBlock;
     2690      dstCr += dstStrideBlock;
     2691      depth += depStrideBlock;
     2692    }
     2693  }
     2694
     2695}
     2696
     2697#endif // NTT_VSP_COMMON_E0207_E0208
     2698
     2699#if H_3D_VSP_CONSTRAINED
     2700Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma)
     2701{
     2702  Int iSize = 0;
     2703  if (bLuma)
     2704  {
     2705    Int iArea = (nPbW+7) * (nPbH+7);
     2706    Int iAlpha = iArea / nPbH - nPbW - 7;
     2707    iSize = iAlpha + nPbW;
     2708  }
     2709  else // chroma
     2710  {
     2711    Int iArea = (nPbW+2) * (nPbH+2);
     2712    Int iAlpha = iArea / nPbH - nPbW - 4;
     2713    iSize = iAlpha + nPbW;
     2714  }
     2715  return iSize;
     2716}
     2717#endif // H_3D_VSP_CONSTRAINED
     2718
     2719#endif // H_3D_VSP
     2720
     2721#if H_3D_DIM
     2722Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
     2723{
     2724  Int  refDC1, refDC2;
     2725  const Int  iTR = (   patternStride - 1        ) - srcStride;
     2726  const Int  iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride;
     2727  const Int  iLB = (   patternStride - 1        ) * srcStride - 1;
     2728  const Int  iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1;
     2729
     2730  Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] );
     2731  Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)]               );
     2732
     2733  if( bL == bT )
     2734  {
     2735    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : 1<<( g_bitDepthY - 1 );
     2736    refDC2 =      ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1;
     2737  }
     2738  else
     2739  {
     2740    refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR];
     2741    refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM];
     2742  }
     2743
     2744  predDC1 = biSegPattern[0] ? refDC1 : refDC2;
     2745  predDC2 = biSegPattern[0] ? refDC2 : refDC1;
     2746}
     2747
     2748Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
     2749{
     2750  if( dstStride == patternStride )
     2751  {
     2752    for( UInt k = 0; k < (patternStride * patternStride); k++ )
     2753    {
     2754      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
     2755      else                          { ptrDst[k] = valDC1; }
     2756    }
     2757  }
     2758  else
     2759  {
     2760    Pel* piTemp = ptrDst;
     2761    for( UInt uiY = 0; uiY < patternStride; uiY++ )
     2762    {
     2763      for( UInt uiX = 0; uiX < patternStride; uiX++ )
     2764      {
     2765        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
     2766        else                            { piTemp[uiX] = valDC1; }
     2767      }
     2768      piTemp       += dstStride;
     2769      biSegPattern += patternStride;
     2770    }
     2771  }
     2772}
     2773
     2774#if H_3D_DIM_DMM
     2775UInt TComPrediction::xPredWedgeFromIntra( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd )
     2776{
     2777  UInt uiThisBlockSize = uiWidth;
     2778
     2779  TComDataCU* pcTempCU;
     2780  UInt        uiTempPartIdx;
     2781  // 1st: try continue above wedgelet
     2782  pcTempCU = pcCU->getPUAbove( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
     2783  if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) )
     2784  {
     2785    UInt dimType =  getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
     2786#if SEC_DMM2_E0146
     2787    if( DMM1_IDX == dimType || DMM3_IDX == dimType )
     2788#else
     2789    if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
     2790#endif
     2791    {
     2792      // get offset between current and reference block
     2793      UInt uiOffsetX = 0, uiOffsetY = 0;
     2794      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
     2795
     2796      // get reference wedgelet
     2797      WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])];
     2798      TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) );
     2799
     2800      // find wedgelet, if direction is suitable for continue wedge
     2801      if( pcRefWedgelet->checkPredDirAbovePossible( uiThisBlockSize, uiOffsetX ) )
     2802      {
     2803        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
     2804        pcRefWedgelet->getPredDirStartEndAbove( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetX, iDeltaEnd );
     2805        return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
     2806      }
     2807    }
     2808  }
     2809
     2810  // 2nd: try continue left wedglelet
     2811  pcTempCU = pcCU->getPULeft( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
     2812  if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) )
     2813  {
     2814    UInt dimType = getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
     2815#if SEC_DMM2_E0146
     2816    if( DMM1_IDX == dimType || DMM3_IDX == dimType )
     2817#else
     2818    if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
     2819#endif
     2820    {
     2821      // get offset between current and reference block
     2822      UInt uiOffsetX = 0, uiOffsetY = 0;
     2823      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
     2824
     2825      // get reference wedgelet
     2826      WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])];
     2827      TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) );
     2828
     2829      // find wedgelet, if direction is suitable for continue wedge
     2830      if( pcRefWedgelet->checkPredDirLeftPossible( uiThisBlockSize, uiOffsetY ) )
     2831      {
     2832        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
     2833        pcRefWedgelet->getPredDirStartEndLeft( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetY, iDeltaEnd );
     2834        return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
     2835      }
     2836    }
     2837  }
     2838
     2839  // 3rd: (default) make wedglet from intra dir and max slope point
     2840  Int iSlopeX = 0, iSlopeY = 0;
     2841  UInt uiStartPosX = 0, uiStartPosY = 0;
     2842  if( xGetWedgeIntraDirPredData( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY ) )
     2843  {
     2844    UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
     2845    xGetWedgeIntraDirStartEnd( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, iDeltaEnd );
     2846    return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
     2847  }
     2848
     2849  return 0;
     2850}
     2851
     2852UInt TComPrediction::xPredWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx )
     2853{
     2854  TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
     2855  assert( pcPicTex != NULL );
     2856  TComDataCU*   pcColTexCU = pcPicTex->getCU(pcCU->getAddr());
     2857  UInt          uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
     2858  Int           uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
     2859
     2860  if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 ) { return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx); }
     2861  else                                                     { return g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])].at(intraTabIdx).getPatternIdx(); }
     2862}
     2863
     2864Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
    34842865{
    34852866  pcContourWedge->clear();
     
    34902871  cTempYuv.clear();
    34912872  Pel* piRefBlkY = cTempYuv.getLumaAddr();
    3492   copyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
     2873  xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
    34932874  piRefBlkY = cTempYuv.getLumaAddr();
    34942875
     
    34992880    iDC += piRefBlkY[k];
    35002881  }
     2882
     2883#if SCU_HS_DMM4_REMOVE_DIV_E0242
     2884  Int cuMaxLog2Size = g_aucConvertToBit[g_uiMaxCUWidth]+2;
     2885  iDC = iDC >> (cuMaxLog2Size - pcCU->getDepth(0))*2;
     2886#else
    35012887  iDC /= (uiWidth*uiHeight);
     2888#endif
    35022889  piRefBlkY = cTempYuv.getLumaAddr();
    35032890
     
    35112898}
    35122899
    3513 #if LGE_DMM3_SIMP_C0044
    3514 /**
    3515  - fetch best Wedgelet pattern at decoder
    3516  */
    3517 UInt TComPrediction::getBestWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt IntraTabIdx)
    3518 {
    3519   assert( uiWidth >= DMM_WEDGEMODEL_MIN_SIZE && uiWidth <= DMM_WEDGEMODEL_MAX_SIZE );
    3520 
    3521   UInt          uiBestTabIdx = 0;
    3522   TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
    3523   TComDataCU*   pcColTexCU = pcPicTex->getCU(pcCU->getAddr());
    3524   UInt          uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
    3525   Int           uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
    3526 
    3527   std::vector< std::vector<UInt> > pauiWdgLstSz = g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]];
    3528 
    3529   if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 )
    3530   {
    3531     std::vector<UInt>* pauiWdgLst = &pauiWdgLstSz[uiColTexIntraDir-2];
    3532     uiBestTabIdx    =   pauiWdgLst->at(IntraTabIdx);
    3533   }
    3534   else
    3535   {
    3536     WedgeNodeList* pacWedgeNodeList = &g_aacWedgeNodeLists[(g_aucConvertToBit[uiWidth])];
    3537     uiBestTabIdx = pacWedgeNodeList->at(IntraTabIdx).getPatternIdx();
    3538   }
    3539 
    3540   return uiBestTabIdx;
    3541 }
    3542 #endif
    3543 
    3544 #if LGE_DMM3_SIMP_C0044
    3545 /**
    3546  - calculate best Wedgelet pattern at encoder
    3547  */
    3548 UInt TComPrediction::getBestWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Pel* piOrigi, UInt uiStride, UInt & ruiIntraTabIdx)
    3549 #else
    3550 UInt TComPrediction::getBestWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight )
    3551 #endif
    3552 {
    3553   assert( uiWidth >= DMM_WEDGEMODEL_MIN_SIZE && uiWidth <= DMM_WEDGEMODEL_MAX_SIZE );
    3554 
    3555   // get copy of co-located texture luma block
    3556   TComYuv cTempYuv;
    3557   cTempYuv.create( uiWidth, uiHeight );
    3558   cTempYuv.clear();
    3559   Pel* piRefBlkY = cTempYuv.getLumaAddr();
    3560 
    3561   copyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
    3562   piRefBlkY = cTempYuv.getLumaAddr();
    3563 
    3564   // local pred buffer
    3565   TComYuv cPredYuv;
    3566   cPredYuv.create( uiWidth, uiHeight );
    3567   cPredYuv.clear();
    3568   Pel* piPred = cPredYuv.getLumaAddr();
    3569 
    3570   UInt uiPredStride = cPredYuv.getStride();
    3571 
    3572   // wedge search
    3573   TComWedgeDist cWedgeDist;
    3574   UInt uiBestDist = MAX_UINT;
    3575   UInt uiBestTabIdx = 0;
    3576   Int  iDC1 = 0;
    3577   Int  iDC2 = 0;
    3578   WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[uiWidth])];
    3579 #if LGE_DMM3_SIMP_C0044
    3580   ruiIntraTabIdx  = 0;
    3581 #endif
    3582   TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
    3583   TComDataCU* pcColTexCU = pcPicTex->getCU(pcCU->getAddr());
    3584   UInt      uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
    3585   Int   uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
    3586 
    3587   std::vector< std::vector<UInt> > pauiWdgLstSz = g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]];
    3588   if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 )
    3589   {
    3590     std::vector<UInt>* pauiWdgLst = &pauiWdgLstSz[uiColTexIntraDir-2];
    3591     for( UInt uiIdxW = 0; uiIdxW < pauiWdgLst->size(); uiIdxW++ )
    3592     {
    3593       UInt uiIdx     =   pauiWdgLst->at(uiIdxW);
    3594 #if LGE_DMM3_SIMP_C0044
    3595       calcWedgeDCs       ( &(pacWedgeList->at(uiIdx)), piOrigi,   uiWidth,      iDC1, iDC2 );
    3596 #else
    3597       calcWedgeDCs       ( &(pacWedgeList->at(uiIdx)), piRefBlkY, uiWidth,      iDC1, iDC2 );
    3598 #endif
    3599       assignWedgeDCs2Pred( &(pacWedgeList->at(uiIdx)), piPred,    uiPredStride, iDC1, iDC2 );
    3600 
    3601 #if LGE_DMM3_SIMP_C0044
    3602       UInt uiActDist = cWedgeDist.getDistPart( piPred, uiPredStride, piOrigi, uiStride, uiWidth, uiHeight, WedgeDist_SAD );
    3603 #else
    3604       UInt uiActDist = cWedgeDist.getDistPart( piPred, uiPredStride, piRefBlkY, uiWidth, uiWidth, uiHeight, WedgeDist_SAD );
    3605 #endif
    3606 
    3607       if( uiActDist < uiBestDist || uiBestDist == MAX_UINT )
    3608       {
    3609         uiBestDist   = uiActDist;
    3610         uiBestTabIdx = uiIdx;
    3611 #if LGE_DMM3_SIMP_C0044
    3612         ruiIntraTabIdx = uiIdxW;
    3613 #endif
    3614       }
    3615     }
    3616   }
    3617   else
    3618   {
    3619     WedgeNodeList* pacWedgeNodeList = &g_aacWedgeNodeLists[(g_aucConvertToBit[uiWidth])];
    3620     UInt uiBestNodeDist = MAX_UINT;
    3621     UInt uiBestNodeId   = 0;
    3622     for( UInt uiNodeId = 0; uiNodeId < pacWedgeNodeList->size(); uiNodeId++ )
    3623     {
    3624 #if LGE_DMM3_SIMP_C0044
    3625       calcWedgeDCs       ( &(pacWedgeList->at(pacWedgeNodeList->at(uiNodeId).getPatternIdx())), piOrigi, uiWidth,      iDC1, iDC2 );
    3626 #else
    3627       calcWedgeDCs       ( &(pacWedgeList->at(pacWedgeNodeList->at(uiNodeId).getPatternIdx())), piRefBlkY, uiWidth,      iDC1, iDC2 );
    3628 #endif
    3629       assignWedgeDCs2Pred( &(pacWedgeList->at(pacWedgeNodeList->at(uiNodeId).getPatternIdx())), piPred,    uiPredStride, iDC1, iDC2 );
    3630 
    3631 #if LGE_DMM3_SIMP_C0044
    3632       UInt uiActDist = cWedgeDist.getDistPart( piPred, uiPredStride, piOrigi, uiStride, uiWidth, uiHeight, WedgeDist_SAD );
    3633 #else
    3634       UInt uiActDist = cWedgeDist.getDistPart( piPred, uiPredStride, piRefBlkY, uiWidth, uiWidth, uiHeight, WedgeDist_SAD );
    3635 #endif
    3636 
    3637       if( uiActDist < uiBestNodeDist || uiBestNodeDist == MAX_UINT )
    3638       {
    3639         uiBestNodeDist = uiActDist;
    3640         uiBestNodeId   = uiNodeId;
    3641 #if LGE_DMM3_SIMP_C0044
    3642         ruiIntraTabIdx = uiNodeId;
    3643 #endif
    3644       }
    3645     }
    3646 #if LGE_DMM3_SIMP_C0044
    3647     uiBestTabIdx = pacWedgeNodeList->at(uiBestNodeId).getPatternIdx();
    3648 #else
    3649     // refinement
    3650     uiBestDist   = uiBestNodeDist;
    3651     uiBestTabIdx = pacWedgeNodeList->at(uiBestNodeId).getPatternIdx();
    3652     for( UInt uiRefId = 0; uiRefId < NUM_WEDGE_REFINES; uiRefId++ )
    3653     {
    3654       if( pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId ) != NO_IDX )
    3655       {
    3656         calcWedgeDCs       ( &(pacWedgeList->at(pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId ))), piRefBlkY, uiWidth,      iDC1, iDC2 );
    3657         assignWedgeDCs2Pred( &(pacWedgeList->at(pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId ))), piPred,    uiPredStride, iDC1, iDC2 );
    3658 
    3659         UInt uiActDist = cWedgeDist.getDistPart( piPred, uiPredStride, piRefBlkY, uiWidth, uiWidth, uiHeight, WedgeDist_SAD );
    3660 
    3661         if( uiActDist < uiBestDist || uiBestDist == MAX_UINT )
    3662         {
    3663           uiBestDist   = uiActDist;
    3664           uiBestTabIdx = pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId );
    3665         }
    3666       }
    3667     }
    3668 #endif
    3669   }
    3670 
    3671   cPredYuv.destroy();
    3672   cTempYuv.destroy();
    3673   return uiBestTabIdx;
    3674 }
    3675 
    3676 Void TComPrediction::copyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
     2900
     2901Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
    36772902{
    36782903  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
     2904  assert( pcPicYuvRef != NULL );
    36792905  Int         iRefStride = pcPicYuvRef->getStride();
    3680   Pel*        piRefY;
    3681 
    3682   piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
     2906  Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
    36832907
    36842908  for ( Int y = 0; y < uiHeight; y++ )
    36852909  {
    36862910    ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
    3687 //    ::memset(piDestBlockY, 128, sizeof(Pel)*uiWidth);
    36882911    piDestBlockY += uiWidth;
    36892912    piRefY += iRefStride;
    3690   }
    3691 }
    3692 
    3693 Void TComPrediction::xPredIntraWedgeTex( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder, Bool bDelta, Int iDeltaDC1, Int iDeltaDC2 )
    3694 {
    3695   assert( iWidth >= DMM_WEDGEMODEL_MIN_SIZE && iWidth <= DMM_WEDGEMODEL_MAX_SIZE );
    3696   WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[iWidth])];
    3697 
    3698   // get wedge pattern
    3699   UInt uiTextureWedgeTabIdx = 0;
    3700   if( bEncoder )
    3701   {
    3702     // encoder: load stored wedge pattern from CU
    3703     uiTextureWedgeTabIdx = pcCU->getWedgePredTexTabIdx( uiAbsPartIdx );
    3704   }
    3705   else
    3706   {
    3707     // decoder: get and store wedge pattern in CU
    3708       // decoder: get and store wedge pattern in CU
    3709 #if LGE_DMM3_SIMP_C0044
    3710     UInt uiIntraTabIdx   = pcCU->getWedgePredTexIntraTabIdx ( uiAbsPartIdx );
    3711     uiTextureWedgeTabIdx = getBestWedgeFromTex( pcCU, uiAbsPartIdx, (UInt)iWidth, (UInt)iHeight, uiIntraTabIdx );
    3712 #else
    3713     uiTextureWedgeTabIdx = getBestWedgeFromTex( pcCU, uiAbsPartIdx, (UInt)iWidth, (UInt)iHeight );
    3714 #endif
    3715 
    3716     UInt uiDepth = (pcCU->getDepth(0)) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1);
    3717     pcCU->setWedgePredTexTabIdxSubParts( uiTextureWedgeTabIdx, uiAbsPartIdx, uiDepth );
    3718   }
    3719   TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiTextureWedgeTabIdx));
    3720 
    3721   // get wedge pred DCs
    3722   Int iPredDC1 = 0;
    3723   Int iPredDC2 = 0;
    3724   Int* piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt );
    3725   Int iMaskStride = ( iWidth<<1 ) + 1;
    3726   piMask += iMaskStride+1;
    3727 #if QC_DC_PREDICTOR_D0183
    3728   getPredDCs( pcWedgelet->getPattern(), pcWedgelet->getStride(), piMask, iMaskStride, iPredDC1, iPredDC2 );
    3729 #else
    3730   getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft );
    3731 #endif
    3732 
    3733   // assign wedge pred DCs to prediction
    3734   if( bDelta )
    3735   {
    3736 #if HHI_DELTADC_DLT_D0035
    3737     assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, GetIdx2DepthValue( GetDepthValue2Idx(iPredDC1) + iDeltaDC1 ), GetIdx2DepthValue( GetDepthValue2Idx(iPredDC2) + iDeltaDC2 ) );
    3738 #else
    3739     assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) );
    3740 #endif
    3741   }
    3742   else
    3743   {
    3744     assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, iPredDC1, iPredDC2 );
    3745   }
    3746 }
    3747 
    3748 Void TComPrediction::xPredIntraContourTex( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder, Bool bDelta, Int iDeltaDC1, Int iDeltaDC2 )
    3749 {
    3750   // get contour pattern
    3751   TComWedgelet* pcContourWedge = new TComWedgelet( iWidth, iHeight );
    3752   getBestContourFromTex( pcCU, uiAbsPartIdx, (UInt)iWidth, (UInt)iHeight, pcContourWedge );
    3753 
    3754   // get wedge pred DCs
    3755   Int iPredDC1 = 0;
    3756   Int iPredDC2 = 0;
    3757   Int* piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt );
    3758   Int iMaskStride = ( iWidth<<1 ) + 1;
    3759   piMask += iMaskStride+1;
    3760 #if QC_DC_PREDICTOR_D0183
    3761   getPredDCs( pcContourWedge->getPattern(), pcContourWedge->getStride(), piMask, iMaskStride, iPredDC1, iPredDC2 );
    3762 #else
    3763   getWedgePredDCs( pcContourWedge, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft );
    3764 #endif
    3765 
    3766   // assign wedge pred DCs to prediction
    3767   if( bDelta )
    3768   {
    3769 #if HHI_DELTADC_DLT_D0035
    3770     assignWedgeDCs2Pred( pcContourWedge, piPred, uiStride, GetIdx2DepthValue( GetDepthValue2Idx(iPredDC1) + iDeltaDC1 ), GetIdx2DepthValue( GetDepthValue2Idx(iPredDC2) + iDeltaDC2 ) );
    3771 #else
    3772     assignWedgeDCs2Pred( pcContourWedge, piPred, uiStride, Clip( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) );
    3773 #endif
    3774   }
    3775   else
    3776   {
    3777     assignWedgeDCs2Pred( pcContourWedge, piPred, uiStride, iPredDC1, iPredDC2 );
    3778   }
    3779 
    3780   pcContourWedge->destroy();
    3781   delete pcContourWedge;
    3782 }
    3783 #endif // HHI_DMM_PRED_TEX
    3784 
    3785 #if HHI_DMM_WEDGE_INTRA
    3786 UInt TComPrediction::getBestContinueWedge( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd )
    3787 {
    3788   UInt uiThisBlockSize = uiWidth;
    3789   assert( uiThisBlockSize >= DMM_WEDGEMODEL_MIN_SIZE && uiThisBlockSize <= DMM_WEDGEMODEL_MAX_SIZE );
    3790   WedgeRefList* pacContDWedgeRefList = &g_aacWedgeRefLists[(g_aucConvertToBit[uiThisBlockSize])];
    3791 
    3792   UInt uiPredDirWedgeTabIdx = 0;
    3793   TComDataCU* pcTempCU;
    3794   UInt        uiTempPartIdx;
    3795   // 1st: try continue above wedgelet
    3796   pcTempCU = pcCU->getPUAbove( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
    3797   if( pcTempCU )
    3798   {
    3799     UChar uhLumaIntraDir = pcTempCU->getLumaIntraDir( uiTempPartIdx );
    3800     if( DMM_WEDGE_FULL_IDX      == uhLumaIntraDir ||
    3801         DMM_WEDGE_FULL_D_IDX    == uhLumaIntraDir ||
    3802         DMM_WEDGE_PREDDIR_IDX   == uhLumaIntraDir ||
    3803         DMM_WEDGE_PREDDIR_D_IDX == uhLumaIntraDir
    3804 #if HHI_DMM_PRED_TEX
    3805         ||
    3806         DMM_WEDGE_PREDTEX_IDX   == uhLumaIntraDir ||
    3807         DMM_WEDGE_PREDTEX_D_IDX == uhLumaIntraDir   
    3808 #endif
    3809       )
    3810     {
    3811       UInt uiRefWedgeSize = (UInt)g_aucIntraSizeIdxToWedgeSize[pcTempCU->getIntraSizeIdx( uiTempPartIdx )];
    3812       WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[uiRefWedgeSize])];
    3813 
    3814       // get offset between current and reference block
    3815       UInt uiOffsetX = 0;
    3816       UInt uiOffsetY = 0;
    3817       xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
    3818 
    3819       // get reference wedgelet
    3820       UInt uiRefWedgeTabIdx = 0;
    3821       switch( uhLumaIntraDir )
    3822       {
    3823       case( DMM_WEDGE_FULL_IDX      ): { uiRefWedgeTabIdx = pcTempCU->getWedgeFullTabIdx   ( uiTempPartIdx ); } break;
    3824       case( DMM_WEDGE_FULL_D_IDX    ): { uiRefWedgeTabIdx = pcTempCU->getWedgeFullTabIdx   ( uiTempPartIdx ); } break;
    3825       case( DMM_WEDGE_PREDDIR_IDX   ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredDirTabIdx( uiTempPartIdx ); } break;
    3826       case( DMM_WEDGE_PREDDIR_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredDirTabIdx( uiTempPartIdx ); } break;
    3827 #if HHI_DMM_PRED_TEX
    3828       case( DMM_WEDGE_PREDTEX_IDX   ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredTexTabIdx( uiTempPartIdx ); } break;
    3829       case( DMM_WEDGE_PREDTEX_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredTexTabIdx( uiTempPartIdx ); } break;
    3830 #endif
    3831       default: { assert( 0 ); return uiPredDirWedgeTabIdx; }
    3832       }
    3833       TComWedgelet* pcRefWedgelet;
    3834       pcRefWedgelet = &(pacWedgeList->at( uiRefWedgeTabIdx ));
    3835 
    3836       // find reference wedgelet, if direction is suitable for continue wedge
    3837       if( pcRefWedgelet->checkPredDirAbovePossible( uiThisBlockSize, uiOffsetX ) )
    3838       {
    3839         UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
    3840         pcRefWedgelet->getPredDirStartEndAbove( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetX, iDeltaEnd );
    3841         getWedgePatternIdx( pacContDWedgeRefList, uiPredDirWedgeTabIdx, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
    3842         return uiPredDirWedgeTabIdx;
    3843       }
    3844     }
    3845   }
    3846 
    3847   // 2nd: try continue left wedglelet
    3848   pcTempCU = pcCU->getPULeft( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
    3849   if( pcTempCU )
    3850   {
    3851     UChar uhLumaIntraDir = pcTempCU->getLumaIntraDir( uiTempPartIdx );
    3852     if( DMM_WEDGE_FULL_IDX      == uhLumaIntraDir ||
    3853         DMM_WEDGE_FULL_D_IDX    == uhLumaIntraDir ||
    3854         DMM_WEDGE_PREDDIR_IDX   == uhLumaIntraDir ||
    3855         DMM_WEDGE_PREDDIR_D_IDX == uhLumaIntraDir
    3856 #if HHI_DMM_PRED_TEX
    3857         ||
    3858         DMM_WEDGE_PREDTEX_IDX   == uhLumaIntraDir ||
    3859         DMM_WEDGE_PREDTEX_D_IDX == uhLumaIntraDir   
    3860 #endif
    3861       )
    3862     {
    3863       UInt uiRefWedgeSize = (UInt)g_aucIntraSizeIdxToWedgeSize[pcTempCU->getIntraSizeIdx( uiTempPartIdx )];
    3864       WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[uiRefWedgeSize])];
    3865 
    3866       // get offset between current and reference block
    3867       UInt uiOffsetX = 0;
    3868       UInt uiOffsetY = 0;
    3869       xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
    3870 
    3871       // get reference wedgelet
    3872       UInt uiRefWedgeTabIdx = 0;
    3873       switch( uhLumaIntraDir )
    3874       {
    3875       case( DMM_WEDGE_FULL_IDX      ): { uiRefWedgeTabIdx = pcTempCU->getWedgeFullTabIdx   ( uiTempPartIdx ); } break;
    3876       case( DMM_WEDGE_FULL_D_IDX    ): { uiRefWedgeTabIdx = pcTempCU->getWedgeFullTabIdx   ( uiTempPartIdx ); } break;
    3877       case( DMM_WEDGE_PREDDIR_IDX   ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredDirTabIdx( uiTempPartIdx ); } break;
    3878       case( DMM_WEDGE_PREDDIR_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredDirTabIdx( uiTempPartIdx ); } break;
    3879 #if HHI_DMM_PRED_TEX
    3880       case( DMM_WEDGE_PREDTEX_IDX   ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredTexTabIdx( uiTempPartIdx ); } break;
    3881       case( DMM_WEDGE_PREDTEX_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredTexTabIdx( uiTempPartIdx ); } break;
    3882 #endif
    3883       default: { assert( 0 ); return uiPredDirWedgeTabIdx; }
    3884       }
    3885       TComWedgelet* pcRefWedgelet;
    3886       pcRefWedgelet = &(pacWedgeList->at( uiRefWedgeTabIdx ));
    3887 
    3888       // find reference wedgelet, if direction is suitable for continue wedge
    3889       if( pcRefWedgelet->checkPredDirLeftPossible( uiThisBlockSize, uiOffsetY ) )
    3890       {
    3891         UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
    3892         pcRefWedgelet->getPredDirStartEndLeft( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetY, iDeltaEnd );
    3893         getWedgePatternIdx( pacContDWedgeRefList, uiPredDirWedgeTabIdx, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
    3894         return uiPredDirWedgeTabIdx;
    3895       }
    3896     }
    3897   }
    3898 
    3899   // 3rd: (default) make wedglet from intra dir and max slope point
    3900   Int iSlopeX = 0;
    3901   Int iSlopeY = 0;
    3902   UInt uiStartPosX = 0;
    3903   UInt uiStartPosY = 0;
    3904   if( xGetWedgeIntraDirPredData( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY ) )
    3905   {
    3906     UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
    3907     xGetWedgeIntraDirStartEnd( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, iDeltaEnd );
    3908     getWedgePatternIdx( pacContDWedgeRefList, uiPredDirWedgeTabIdx, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
    3909     return uiPredDirWedgeTabIdx;
    3910   }
    3911 
    3912   return uiPredDirWedgeTabIdx;
    3913 }
    3914 
    3915 Bool TComPrediction::getWedgePatternIdx( WedgeRefList* pcWedgeRefList, UInt& ruiTabIdx, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe )
    3916 {
    3917   ruiTabIdx = 0;
    3918 
    3919   for( UInt uiIdx = 0; uiIdx < pcWedgeRefList->size(); uiIdx++ )
    3920   {
    3921     TComWedgeRef* pcTestWedgeRef = &(pcWedgeRefList->at(uiIdx));
    3922 
    3923     if( pcTestWedgeRef->getStartX() == uhXs &&
    3924       pcTestWedgeRef->getStartY() == uhYs &&
    3925       pcTestWedgeRef->getEndX()   == uhXe &&
    3926       pcTestWedgeRef->getEndY()   == uhYe    )
    3927     {
    3928       ruiTabIdx = pcTestWedgeRef->getRefIdx();
    3929       return true;
    3930     }
    3931   }
    3932 
    3933   return false;
    3934 }
    3935 
    3936 Void TComPrediction::xPredIntraWedgeFull( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder, Bool bDelta, UInt uiTabIdx, Int iDeltaDC1, Int iDeltaDC2 )
    3937 {
    3938   assert( iWidth >= DMM_WEDGEMODEL_MIN_SIZE && iWidth <= DMM_WEDGEMODEL_MAX_SIZE );
    3939   WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[iWidth])];
    3940   TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiTabIdx));
    3941 
    3942   // get wedge pred DCs
    3943   Int iPredDC1 = 0;
    3944   Int iPredDC2 = 0;
    3945 
    3946   Int* piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt );
    3947   Int iMaskStride = ( iWidth<<1 ) + 1;
    3948   piMask += iMaskStride+1;
    3949 #if QC_DC_PREDICTOR_D0183
    3950   getPredDCs( pcWedgelet->getPattern(), pcWedgelet->getStride(), piMask, iMaskStride, iPredDC1, iPredDC2 );
    3951 #else
    3952   getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft );
    3953 #endif
    3954 
    3955   // assign wedge pred DCs to prediction
    3956   if( bDelta )
    3957   {
    3958 #if HHI_DELTADC_DLT_D0035
    3959     assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, GetIdx2DepthValue( GetDepthValue2Idx(iPredDC1) + iDeltaDC1 ), GetIdx2DepthValue( GetDepthValue2Idx(iPredDC2) + iDeltaDC2 ) );
    3960 #else
    3961     assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) );
    3962 #endif
    3963   }
    3964   else
    3965   {
    3966     assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, iPredDC1, iPredDC2 );
    3967   }
    3968 }
    3969 
    3970 Void TComPrediction::xPredIntraWedgeDir( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder, Bool bDelta, Int iWedgeDeltaEnd, Int iDeltaDC1, Int iDeltaDC2 )
    3971 {
    3972   assert( iWidth >= DMM_WEDGEMODEL_MIN_SIZE && iWidth <= DMM_WEDGEMODEL_MAX_SIZE );
    3973   WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[iWidth])];
    3974 
    3975   // get wedge pattern
    3976   UInt uiDirWedgeTabIdx = 0;
    3977   if( bEncoder )
    3978   {
    3979     // encoder: load stored wedge pattern from CU
    3980     uiDirWedgeTabIdx = pcCU->getWedgePredDirTabIdx( uiAbsPartIdx );
    3981   }
    3982   else
    3983   {
    3984     uiDirWedgeTabIdx = getBestContinueWedge( pcCU, uiAbsPartIdx, iWidth, iHeight, iWedgeDeltaEnd );
    3985 
    3986     UInt uiDepth = (pcCU->getDepth(0)) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1);
    3987     pcCU->setWedgePredDirTabIdxSubParts( uiDirWedgeTabIdx, uiAbsPartIdx, uiDepth );
    3988   }
    3989   TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiDirWedgeTabIdx));
    3990 
    3991   // get wedge pred DCs
    3992   Int iPredDC1 = 0;
    3993   Int iPredDC2 = 0;
    3994 
    3995   Int* piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt );
    3996   Int iMaskStride = ( iWidth<<1 ) + 1;
    3997   piMask += iMaskStride+1;
    3998 #if QC_DC_PREDICTOR_D0183
    3999   getPredDCs( pcWedgelet->getPattern(), pcWedgelet->getStride(), piMask, iMaskStride, iPredDC1, iPredDC2 );
    4000 #else
    4001   getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft );
    4002 #endif
    4003 
    4004   // assign wedge pred DCs to prediction
    4005   if( bDelta )
    4006   {
    4007 #if HHI_DELTADC_DLT_D0035
    4008     assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, GetIdx2DepthValue( GetDepthValue2Idx(iPredDC1) + iDeltaDC1 ), GetIdx2DepthValue( GetDepthValue2Idx(iPredDC2) + iDeltaDC2 ) );
    4009 #else
    4010     assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) );
    4011 #endif
    4012   }
    4013   else
    4014   {
    4015     assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, iPredDC1, iPredDC2 );
    40162913  }
    40172914}
     
    40472944Bool TComPrediction::xGetWedgeIntraDirPredData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int& riSlopeX, Int& riSlopeY, UInt& ruiStartPosX, UInt& ruiStartPosY )
    40482945{
    4049   riSlopeX     = 0;
    4050   riSlopeY     = 0;
    4051   ruiStartPosX = 0;
    4052   ruiStartPosY = 0;
     2946  riSlopeX = 0, riSlopeY = 0, ruiStartPosX = 0, ruiStartPosY = 0;
    40532947
    40542948  // 1st step: get wedge start point (max. slope)
     
    40562950  Int iSourceStride = ( uiBlockSize<<1 ) + 1;
    40572951
    4058   UInt uiSlopeMaxAbove = 0;
    4059   UInt uiPosSlopeMaxAbove = 0;
     2952  UInt uiSlopeMaxAbove = 0, uiPosSlopeMaxAbove = 0;
    40602953  for( UInt uiPosHor = 0; uiPosHor < (uiBlockSize-1); uiPosHor++ )
    40612954  {
     
    40672960  }
    40682961
    4069   UInt uiSlopeMaxLeft = 0;
    4070   UInt uiPosSlopeMaxLeft = 0;
     2962  UInt uiSlopeMaxLeft = 0, uiPosSlopeMaxLeft = 0;
    40712963  for( UInt uiPosVer = 0; uiPosVer < (uiBlockSize-1); uiPosVer++ )
    40722964  {
     
    40832975  }
    40842976
    4085   if( uiSlopeMaxAbove > uiSlopeMaxLeft )
    4086   {
    4087     ruiStartPosX = uiPosSlopeMaxAbove;
    4088     ruiStartPosY = 0;
    4089   }
    4090   else
    4091   {
    4092     ruiStartPosX = 0;
    4093     ruiStartPosY = uiPosSlopeMaxLeft;
    4094   }
     2977  ruiStartPosX = ( uiSlopeMaxAbove >  uiSlopeMaxLeft  ) ? uiPosSlopeMaxAbove : 0;
     2978  ruiStartPosY = ( uiSlopeMaxLeft  >= uiSlopeMaxAbove ) ? uiPosSlopeMaxLeft  : 0;
    40952979
    40962980  // 2nd step: derive wedge direction
     
    41183002  if( modeHor )
    41193003  {
    4120     if( intraPredAngle > 0 )
    4121     {
    4122       riSlopeX = -32;
    4123       riSlopeY = intraPredAngle;
    4124     }
    4125     else
    4126     {
    4127       riSlopeX = 32;
    4128       riSlopeY = -intraPredAngle;
    4129     }
     3004    riSlopeX = ( intraPredAngle > 0 ) ?            -32 :              32;
     3005    riSlopeY = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle;
    41303006  }
    41313007  else if( modeVer )
    41323008  {
    4133     if( intraPredAngle > 0 )
    4134     {
    4135       riSlopeX = intraPredAngle;
    4136       riSlopeY = -32;
    4137     }
    4138     else
    4139     {
    4140       riSlopeX = -intraPredAngle;
    4141       riSlopeY = 32;
    4142     }
     3009    riSlopeX = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle;
     3010    riSlopeY = ( intraPredAngle > 0 ) ?            -32 :              32;
    41433011  }
    41443012
     
    41573025  UInt uiScaledStartPosY = 0;
    41583026  UInt uiScaledBlockSize = 0;
    4159   WedgeResolution eWedgeRes = g_aeWedgeResolutionList[(UInt)g_aucConvertToBit[uiBlockSize]];
     3027  WedgeResolution eWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiBlockSize]];
    41603028  switch( eWedgeRes )
    41613029  {
     
    44193287  }
    44203288}
    4421 #endif
    4422 
    4423 Void
    4424 TComPrediction::predIntraDepthAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight )
    4425 {
    4426   Pel*  pDst    = piPred;
    4427   Int*  ptrSrc  = pcTComPattern->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt );
    4428   Int   sw      = ( iWidth<<1 ) + 1;
    4429   xPredIntraAngDepth( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode );
    4430 }
    4431 
    4432 Int
    4433 TComPrediction::xGetDCDepth( Int* pSrc, Int iDelta, Int iBlkSize )
    4434 {
    4435   Int iDC    = PDM_UNDEFINED_DEPTH;
    4436   Int iSum   = 0;
    4437   Int iNum   = 0;
    4438   for( Int k = 0; k < iBlkSize; k++, pSrc += iDelta )
    4439   {
    4440     if( *pSrc != PDM_UNDEFINED_DEPTH )
    4441     {
    4442       iSum += *pSrc;
    4443       iNum ++;
    4444     }
    4445   }
    4446   if( iNum )
    4447   {
    4448     iDC = ( iSum + ( iNum >> 1 ) ) / iNum;
    4449   }
    4450   return iDC;
    4451 }
    4452 
    4453 Int
    4454 TComPrediction::xGetDCValDepth( Int iVal1, Int iVal2, Int iVal3, Int iVal4 )
    4455 {
    4456   if     ( iVal1 != PDM_UNDEFINED_DEPTH )   return iVal1;
    4457   else if( iVal2 != PDM_UNDEFINED_DEPTH )   return iVal2;
    4458   else if( iVal3 != PDM_UNDEFINED_DEPTH )   return iVal3;
    4459   return   iVal4;
    4460 }
    4461 
    4462 Void
    4463 TComPrediction::xPredIntraAngDepth( Int* pSrc, Int srcStride, Pel* pDst, Int dstStride, UInt width, UInt height, UInt dirMode )
    4464 {
    4465   AOF( width == height );
    4466   Int blkSize       = width;
    4467   Int iDCAbove      = xGetDCDepth( pSrc - srcStride,                               1, blkSize );
    4468   Int iDCAboveRight = xGetDCDepth( pSrc - srcStride + blkSize,                     1, blkSize );
    4469   Int iDCLeft       = xGetDCDepth( pSrc -         1,                       srcStride, blkSize );
    4470   Int iDCBelowLeft  = xGetDCDepth( pSrc -         1 + blkSize * srcStride, srcStride, blkSize );
    4471   Int iWgt, iDC1, iDC2;
    4472   if( dirMode < 2 ) // 1..2
    4473   {
    4474     iDC1  = xGetDCValDepth( iDCAbove, iDCAboveRight, iDCLeft,  iDCBelowLeft  );
    4475     iDC2  = xGetDCValDepth( iDCLeft,  iDCBelowLeft,  iDCAbove, iDCAboveRight );
    4476     iWgt  = 8;
    4477   }
    4478   else if( dirMode < 11 ) // 3..10
    4479   {
    4480     iDC1  = xGetDCValDepth( iDCLeft,  iDCBelowLeft,  iDCAbove, iDCAboveRight );
    4481     iDC2  = xGetDCValDepth( iDCBelowLeft,  iDCLeft,  iDCAbove, iDCAboveRight );
    4482     iWgt  = 6 + dirMode;
    4483   }
    4484   else if( dirMode < 27 ) // 11..26
    4485   {
    4486     iDC1  = xGetDCValDepth( iDCAbove, iDCAboveRight, iDCLeft,  iDCBelowLeft  );
    4487     iDC2  = xGetDCValDepth( iDCLeft,  iDCBelowLeft,  iDCAbove, iDCAboveRight );
    4488     iWgt  = dirMode - 10;
    4489   }
    4490   else if( dirMode < 35 ) // 27..34
    4491   {
    4492     iDC1  = xGetDCValDepth( iDCAbove, iDCAboveRight, iDCLeft,  iDCBelowLeft  );
    4493     iDC2  = xGetDCValDepth( iDCAboveRight, iDCAbove, iDCLeft,  iDCBelowLeft  );
    4494     iWgt  = 42 - dirMode;
    4495   }
    4496   else // (wedgelet -> use simple DC prediction
    4497   {
    4498     iDC1  = xGetDCValDepth( iDCAbove, iDCAboveRight, iDCLeft,  iDCBelowLeft  );
    4499     iDC2  = xGetDCValDepth( iDCLeft,  iDCBelowLeft,  iDCAbove, iDCAboveRight );
    4500     iWgt  = 8;
    4501   }
    4502   Int iWgt2   = 16 - iWgt;
    4503   Int iDCVal  = ( iWgt * iDC1 + iWgt2 * iDC2 + 8 ) >> 4;
    4504 
    4505   // set depth
    4506   for( Int iY = 0; iY < blkSize; iY++, pDst += dstStride )
    4507   {
    4508     for( Int iX = 0; iX < blkSize; iX++ )
    4509     {
    4510       pDst[ iX ] = iDCVal;
    4511     }
    4512   }
    4513 }
    4514 
     3289
     3290UInt TComPrediction::xGetWedgePatternIdx( UInt uiBlockSize, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe )
     3291{
     3292  WedgeRefList* pcWedgeRefList = &g_dmmWedgeRefLists[(g_aucConvertToBit[uiBlockSize])];
     3293  for( UInt uiIdx = 0; uiIdx < pcWedgeRefList->size(); uiIdx++ )
     3294  {
     3295    TComWedgeRef* pcTestWedgeRef = &(pcWedgeRefList->at(uiIdx));
     3296    if( pcTestWedgeRef->getStartX() == uhXs && pcTestWedgeRef->getStartY() == uhYs && pcTestWedgeRef->getEndX() == uhXe && pcTestWedgeRef->getEndY() == uhYe )
     3297    {
     3298      return pcTestWedgeRef->getRefIdx();
     3299    }
     3300  }
     3301  return 0;
     3302}
     3303#endif
     3304#if H_3D_DIM_RBC
     3305Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Pel& rDeltaDC )
     3306{
     3307  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
     3308  UInt uiAbs  = abs( rDeltaDC );
     3309
     3310  Int iQp = pcCU->getQP(0);
     3311  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
     3312  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
     3313
     3314  rDeltaDC = iSign * roftoi( uiAbs * dStepSize );
     3315  return;
     3316}
     3317
     3318Void TComPrediction::xDeltaDCQuantScaleDown( TComDataCU*  pcCU, Pel& rDeltaDC )
     3319{
     3320  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
     3321  UInt uiAbs  = abs( rDeltaDC );
     3322
     3323  Int iQp = pcCU->getQP(0);
     3324  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
     3325  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
     3326
     3327  rDeltaDC = iSign * roftoi( uiAbs / dStepSize );
     3328  return;
     3329}
     3330#endif
     3331#if H_3D_DIM_SDC
     3332Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
     3333#if KWU_SDC_SIMPLE_DC_E0117
     3334                                         ,UInt uiIntraMode
     3335                                         ,Bool orgDC
     3336#endif
     3337                                        )
     3338{
     3339  Int iSumDepth[2];
     3340  memset(iSumDepth, 0, sizeof(Int)*2);
     3341  Int iSumPix[2];
     3342  memset(iSumPix, 0, sizeof(Int)*2);
     3343 
     3344#if KWU_SDC_SIMPLE_DC_E0117
     3345  if (orgDC == false)
     3346  {
     3347    if ( getDimType(uiIntraMode) == DMM1_IDX )
     3348    {
     3349      UChar ucSegmentLT = pMask[0];
     3350      UChar ucSegmentRT = pMask[uiSize-1];
     3351      UChar ucSegmentLB = pMask[uiMaskStride * (uiSize-1)];
     3352      UChar ucSegmentRB = pMask[uiMaskStride * (uiSize-1) + (uiSize-1)];
     3353
     3354      rpSegMeans[ucSegmentLT] = pOrig[0];
     3355      rpSegMeans[ucSegmentRT] = pOrig[uiSize-1];
     3356      rpSegMeans[ucSegmentLB] = pOrig[uiStride * (uiSize-1) ];
     3357      rpSegMeans[ucSegmentRB] = pOrig[uiStride * (uiSize-1) + (uiSize-1) ];
     3358    }
     3359    else if (uiIntraMode == PLANAR_IDX)
     3360    {
     3361      Pel* pLeftTop = pOrig;
     3362      Pel* pRightTop = pOrig + (uiSize-1);
     3363      Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1)));
     3364      Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1));
     3365
     3366      rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
     3367    }
     3368    return;
     3369  }
     3370#endif
     3371
     3372  Int subSamplePix;
     3373  if ( uiSize == 64 || uiSize == 32 )
     3374  {
     3375    subSamplePix = 2;
     3376  }
     3377  else
     3378  {
     3379    subSamplePix = 1;
     3380  }
     3381  for (Int y=0; y<uiSize; y+=subSamplePix)
     3382  {
     3383    for (Int x=0; x<uiSize; x+=subSamplePix)
     3384    {
     3385      UChar ucSegment = pMask?(UChar)pMask[x]:0;
     3386      assert( ucSegment < uiNumSegments );
     3387     
     3388      iSumDepth[ucSegment] += pOrig[x];
     3389      iSumPix[ucSegment]   += 1;
     3390    }
     3391   
     3392    pOrig  += uiStride*subSamplePix;
     3393    pMask  += uiMaskStride*subSamplePix;
     3394  }
     3395 
     3396  // compute mean for each segment
     3397  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
     3398  {
     3399    if( iSumPix[ucSeg] > 0 )
     3400      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
     3401    else
     3402      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
     3403  }
     3404}
     3405#endif // H_3D_DIM_SDC
     3406#endif
    45153407//! \}
Note: See TracChangeset for help on using the changeset viewer.