source: 3DVCSoftware/branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComPrediction.cpp @ 798

Last change on this file since 798 was 781, checked in by qualcomm, 11 years ago

integration of JCT3V-G0122 (generalize SDC to all depth intra modes) by Qualcomm.

  • Property svn:eol-style set to native
File size: 71.3 KB
RevLine 
[5]1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
[56]4 * granted under this license. 
[5]5 *
[608]6 * Copyright (c) 2010-2013, ITU/ISO/IEC
[5]7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
[2]33
34/** \file     TComPrediction.cpp
35    \brief    prediction class
36*/
37
38#include <memory.h>
39#include "TComPrediction.h"
40
[56]41//! \ingroup TLibCommon
42//! \{
43
[2]44// ====================================================================================================================
45// Constructor / destructor / initialize
46// ====================================================================================================================
47
48TComPrediction::TComPrediction()
49: m_pLumaRecBuffer(0)
[608]50, m_iLumaRecStride(0)
[2]51{
52  m_piYuvExt = NULL;
[608]53#if H_3D_VSP
54  m_pDepthBlock = (Int*) malloc(MAX_NUM_SPU_W*MAX_NUM_SPU_W*sizeof(Int));
55  if (m_pDepthBlock == NULL)
[296]56      printf("ERROR: UKTGHU, No memory allocated.\n");
57#endif
[2]58}
59
60TComPrediction::~TComPrediction()
61{
[608]62#if H_3D_VSP
63  if (m_pDepthBlock != NULL)
64      free(m_pDepthBlock);
65  m_cYuvDepthOnVsp.destroy();
[296]66#endif
[608]67
[2]68  delete[] m_piYuvExt;
69
70  m_acYuvPred[0].destroy();
71  m_acYuvPred[1].destroy();
72
73  m_cYuvPredTemp.destroy();
[608]74
75#if H_3D_ARP
[443]76  m_acYuvPredBase[0].destroy();
77  m_acYuvPredBase[1].destroy();
78#endif
[2]79  if( m_pLumaRecBuffer )
[56]80  {
81    delete [] m_pLumaRecBuffer;
82  }
83 
84  Int i, j;
85  for (i = 0; i < 4; i++)
86  {
87    for (j = 0; j < 4; j++)
88    {
89      m_filteredBlock[i][j].destroy();
90    }
91    m_filteredBlockTmp[i].destroy();
92  }
[2]93}
94
95Void TComPrediction::initTempBuff()
96{
97  if( m_piYuvExt == NULL )
98  {
[608]99    Int extWidth  = MAX_CU_SIZE + 16; 
100    Int extHeight = MAX_CU_SIZE + 1;
[56]101    Int i, j;
102    for (i = 0; i < 4; i++)
103    {
104      m_filteredBlockTmp[i].create(extWidth, extHeight + 7);
105      for (j = 0; j < 4; j++)
106      {
107        m_filteredBlock[i][j].create(extWidth, extHeight);
108      }
109    }
[608]110    m_iYuvExtHeight  = ((MAX_CU_SIZE + 2) << 4);
111    m_iYuvExtStride = ((MAX_CU_SIZE  + 8) << 4);
[2]112    m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
113
114    // new structure
[608]115    m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE );
116    m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE );
[2]117
[608]118    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE );
119#if H_3D_ARP
[443]120    m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
121    m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
122#endif
[655]123#if H_3D_VSP
[608]124    m_cYuvDepthOnVsp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
125#endif
[2]126  }
127
[608]128  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
129  {
130    m_iLumaRecStride =  (MAX_CU_SIZE>>1) + 1;
131    if (!m_pLumaRecBuffer)
132    {
133      m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ];
134    }
135  }
136#if H_3D_IC
137  m_uiaShift[0] = 0;
[56]138  for( Int i = 1; i < 64; i++ )
139  {
[608]140    m_uiaShift[i] = ( (1 << 15) + i/2 ) / i;
141  }
142#endif
[2]143}
144
145// ====================================================================================================================
146// Public member functions
147// ====================================================================================================================
148
149// Function for calculating DC value of the reference samples used in Intra prediction
150Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft )
151{
[608]152  assert(iWidth > 0 && iHeight > 0);
[2]153  Int iInd, iSum = 0;
154  Pel pDcVal;
155
156  if (bAbove)
157  {
158    for (iInd = 0;iInd < iWidth;iInd++)
[56]159    {
[2]160      iSum += pSrc[iInd-iSrcStride];
[56]161    }
[2]162  }
163  if (bLeft)
164  {
165    for (iInd = 0;iInd < iHeight;iInd++)
[56]166    {
[2]167      iSum += pSrc[iInd*iSrcStride-1];
[56]168    }
[2]169  }
170
171  if (bAbove && bLeft)
[56]172  {
[2]173    pDcVal = (iSum + iWidth) / (iWidth + iHeight);
[56]174  }
[2]175  else if (bAbove)
[56]176  {
[2]177    pDcVal = (iSum + iWidth/2) / iWidth;
[56]178  }
[2]179  else if (bLeft)
[56]180  {
[2]181    pDcVal = (iSum + iHeight/2) / iHeight;
[56]182  }
[2]183  else
[56]184  {
[2]185    pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available
[56]186  }
187 
[2]188  return pDcVal;
189}
190
191// Function for deriving the angular Intra predictions
192
193/** Function for deriving the simplified angular intra predictions.
194 * \param pSrc pointer to reconstructed sample array
195 * \param srcStride the stride of the reconstructed sample array
196 * \param rpDst reference to pointer for the prediction sample array
197 * \param dstStride the stride of the prediction sample array
198 * \param width the width of the block
199 * \param height the height of the block
200 * \param dirMode the intra prediction mode index
201 * \param blkAboveAvailable boolean indication if the block above is available
202 * \param blkLeftAvailable boolean indication if the block to the left is available
203 *
204 * This function derives the prediction samples for the angular mode based on the prediction direction indicated by
205 * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and
206 * the reference row above the block in the case of vertical prediction or displacement of the rightmost column
207 * of the block and reference column left from the block in the case of the horizontal prediction. The displacement
208 * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples,
209 * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken
210 * from the extended main reference.
211 */
[608]212Void TComPrediction::xPredIntraAng(Int bitDepth, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter )
[2]213{
214  Int k,l;
215  Int blkSize        = width;
216  Pel* pDst          = rpDst;
217
218  // Map the mode index to main prediction direction and angle
[56]219  assert( dirMode > 0 ); //no planar
220  Bool modeDC        = dirMode < 2;
221  Bool modeHor       = !modeDC && (dirMode < 18);
222  Bool modeVer       = !modeDC && !modeHor;
223  Int intraPredAngle = modeVer ? (Int)dirMode - VER_IDX : modeHor ? -((Int)dirMode - HOR_IDX) : 0;
[2]224  Int absAng         = abs(intraPredAngle);
225  Int signAng        = intraPredAngle < 0 ? -1 : 1;
226
227  // Set bitshifts and scale the angle parameter to block size
228  Int angTable[9]    = {0,    2,    5,   9,  13,  17,  21,  26,  32};
229  Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
230  Int invAngle       = invAngTable[absAng];
231  absAng             = angTable[absAng];
232  intraPredAngle     = signAng * absAng;
233
234  // Do the DC prediction
235  if (modeDC)
236  {
237    Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable);
238
239    for (k=0;k<blkSize;k++)
240    {
241      for (l=0;l<blkSize;l++)
242      {
243        pDst[k*dstStride+l] = dcval;
244      }
245    }
246  }
247
248  // Do angular predictions
249  else
250  {
251    Pel* refMain;
252    Pel* refSide;
253    Pel  refAbove[2*MAX_CU_SIZE+1];
254    Pel  refLeft[2*MAX_CU_SIZE+1];
255
256    // Initialise the Main and Left reference array.
257    if (intraPredAngle < 0)
258    {
259      for (k=0;k<blkSize+1;k++)
260      {
261        refAbove[k+blkSize-1] = pSrc[k-srcStride-1];
262      }
263      for (k=0;k<blkSize+1;k++)
264      {
265        refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1];
266      }
267      refMain = (modeVer ? refAbove : refLeft) + (blkSize-1);
268      refSide = (modeVer ? refLeft : refAbove) + (blkSize-1);
269
270      // Extend the Main reference to the left.
271      Int invAngleSum    = 128;       // rounding for (shift by 8)
272      for (k=-1; k>blkSize*intraPredAngle>>5; k--)
273      {
274        invAngleSum += invAngle;
275        refMain[k] = refSide[invAngleSum>>8];
276      }
277    }
278    else
279    {
280      for (k=0;k<2*blkSize+1;k++)
281      {
282        refAbove[k] = pSrc[k-srcStride-1];
283      }
284      for (k=0;k<2*blkSize+1;k++)
285      {
286        refLeft[k] = pSrc[(k-1)*srcStride-1];
287      }
288      refMain = modeVer ? refAbove : refLeft;
[56]289      refSide = modeVer ? refLeft  : refAbove;
[2]290    }
291
292    if (intraPredAngle == 0)
293    {
294      for (k=0;k<blkSize;k++)
295      {
296        for (l=0;l<blkSize;l++)
297        {
298          pDst[k*dstStride+l] = refMain[l+1];
299        }
300      }
[56]301
302      if ( bFilter )
303      {
304        for (k=0;k<blkSize;k++)
305        {
[608]306          pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) );
[56]307        }
308      }
[2]309    }
310    else
311    {
312      Int deltaPos=0;
313      Int deltaInt;
314      Int deltaFract;
315      Int refMainIndex;
316
317      for (k=0;k<blkSize;k++)
318      {
319        deltaPos += intraPredAngle;
320        deltaInt   = deltaPos >> 5;
321        deltaFract = deltaPos & (32 - 1);
322
323        if (deltaFract)
324        {
325          // Do linear filtering
326          for (l=0;l<blkSize;l++)
327          {
328            refMainIndex        = l+deltaInt+1;
329            pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 );
330          }
331        }
332        else
333        {
334          // Just copy the integer samples
335          for (l=0;l<blkSize;l++)
336          {
337            pDst[k*dstStride+l] = refMain[l+deltaInt+1];
338          }
339        }
340      }
341    }
342
343    // Flip the block if this is the horizontal mode
344    if (modeHor)
345    {
346      Pel  tmp;
347      for (k=0;k<blkSize-1;k++)
348      {
349        for (l=k+1;l<blkSize;l++)
350        {
351          tmp                 = pDst[k*dstStride+l];
352          pDst[k*dstStride+l] = pDst[l*dstStride+k];
353          pDst[l*dstStride+k] = tmp;
354        }
355      }
356    }
357  }
358}
359
[608]360Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
[2]361{
362  Pel *pDst = piPred;
363  Int *ptrSrc;
364
[56]365  assert( g_aucConvertToBit[ iWidth ] >= 0 ); //   4x  4
366  assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128
[2]367  assert( iWidth == iHeight  );
368
[56]369  ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
370
371  // get starting pixel in block
372  Int sw = 2 * iWidth + 1;
373
374  // Create the prediction
375  if ( uiDirMode == PLANAR_IDX )
376  {
377    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
378  }
379  else
380  {
[608]381    if ( (iWidth > 16) || (iHeight > 16) )
[56]382    {
[608]383      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
[56]384    }
[608]385    else
386    {
387      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );
388
389      if( (uiDirMode == DC_IDX ) && bAbove && bLeft )
390      {
391        xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);
392      }
393    }
[56]394  }
395}
396
397// Angular chroma
[608]398Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
[56]399{
400  Pel *pDst = piPred;
401  Int *ptrSrc = piSrc;
402
[2]403  // get starting pixel in block
[56]404  Int sw = 2 * iWidth + 1;
[2]405
406  if ( uiDirMode == PLANAR_IDX )
407  {
408    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
[56]409  }
410  else
411  {
412    // Create the prediction
[608]413    xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
[56]414  }
415}
416
[608]417#if H_3D_DIM
[781]418Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc
419#if QC_GENERIC_SDC_G0122
420  , TComWedgelet* dmm4Segmentation
421#endif
422  )
[56]423{
[608]424  assert( iWidth == iHeight  );
425  assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE );
426  assert( isDimMode( uiIntraMode ) );
[56]427
[608]428  UInt dimType    = getDimType  ( uiIntraMode );
429  Bool dimDeltaDC = isDimDeltaDC( uiIntraMode );   
430  Bool isDmmMode  = (dimType <  DMM_NUM_TYPE);
[100]431
[608]432  Bool* biSegPattern  = NULL;
433  UInt  patternStride = 0;
[100]434
[608]435  // get partiton
436#if H_3D_DIM_DMM
437  TComWedgelet* dmmSegmentation = NULL;
438  if( isDmmMode )
[100]439  {
[608]440    switch( dimType )
[100]441    {
[608]442    case( DMM1_IDX ): 
[100]443      {
[608]444        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]);
445      } break;
446    case( DMM4_IDX ): 
[100]447      {
[781]448#if QC_GENERIC_SDC_G0122
449        if( dmm4Segmentation == NULL )
450        { 
451          dmmSegmentation = new TComWedgelet( iWidth, iHeight );
452          xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
453        }
454        else
455        {
456          xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmm4Segmentation );
457          dmmSegmentation = dmm4Segmentation;
458        }
459#else
[608]460        dmmSegmentation = new TComWedgelet( iWidth, iHeight );
461        xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
[781]462#endif
[608]463      } break;
464    default: assert(0);
[100]465    }
[608]466    assert( dmmSegmentation );
467    biSegPattern  = dmmSegmentation->getPattern();
468    patternStride = dmmSegmentation->getStride ();
[100]469  }
[608]470#endif
[100]471
[608]472  // get predicted partition values
473  assert( biSegPattern );
474  Int* piMask = NULL;
[724]475  piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering
[608]476  assert( piMask );
477  Int maskStride = 2*iWidth + 1; 
478  Int* ptrSrc = piMask+maskStride+1;
479  Pel predDC1 = 0; Pel predDC2 = 0;
480  xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 );
481
482  // set segment values with deltaDC offsets
483  Pel segDC1 = 0;
484  Pel segDC2 = 0;
485  if( dimDeltaDC )
[100]486  {
[608]487    Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx );
488    Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx );
489#if H_3D_DIM_DMM
490    if( isDmmMode )
491    {
492#if H_3D_DIM_DLT
[758]493      segDC1 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 );
494      segDC2 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 );
495#else
[608]496      segDC1 = ClipY( predDC1 + deltaDC1 );
497      segDC2 = ClipY( predDC2 + deltaDC2 );
498#endif
499    }
500#endif
[100]501  }
[608]502  else
[100]503  {
[608]504    segDC1 = predDC1;
505    segDC2 = predDC2;
[100]506  }
507
[608]508  // set prediction signal
509  Pel* pDst = piPred;
510  xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 );
[100]511
[608]512#if H_3D_DIM_DMM
[781]513#if QC_GENERIC_SDC_G0122
514  if( dimType == DMM4_IDX && dmm4Segmentation == NULL ) { dmmSegmentation->destroy(); delete dmmSegmentation; }
515#else
[608]516  if( dimType == DMM4_IDX ) { dmmSegmentation->destroy(); delete dmmSegmentation; }
517#endif
[781]518#endif
[100]519}
[608]520#endif
[100]521
[608]522/** Function for checking identical motion.
523 * \param TComDataCU* pcCU
524 * \param UInt PartAddr
525 */
526Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr )
[100]527{
[608]528  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() )
[100]529  {
[608]530    if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0)
[100]531    {
[608]532      Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
533      Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
534      if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
[100]535      {
[608]536        return true;
[100]537      }
538    }
539  }
[608]540  return false;
[100]541}
542
[773]543#if H_3D_SPIVMP
[724]544Void TComPrediction::xGetSubPUAddrAndMerge(TComDataCU* pcCU, UInt uiPartAddr, Int iSPWidth, Int iSPHeight, Int iNumSPInOneLine, Int iNumSP, UInt* uiMergedSPW, UInt* uiMergedSPH, UInt* uiSPAddr )
545{
546  for (Int i = 0; i < iNumSP; i++)
547  {
548    uiMergedSPW[i] = iSPWidth;
549    uiMergedSPH[i] = iSPHeight;
550    pcCU->getSPAbsPartIdx(uiPartAddr, iSPWidth, iSPHeight, i, iNumSPInOneLine, uiSPAddr[i]);
551  }
552  // horizontal sub-PU merge
553  for (Int i=0; i<iNumSP; i++)
554  {
555    if (i % iNumSPInOneLine == iNumSPInOneLine - 1 || uiMergedSPW[i]==0 || uiMergedSPH[i]==0)
556    {
557      continue;
558    }
559    for (Int j=i+1; j<i+iNumSPInOneLine-i%iNumSPInOneLine; j++)
560    {
561      if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j]))
562      {
563        uiMergedSPW[i] += iSPWidth;
564        uiMergedSPW[j] = uiMergedSPH[j] = 0;
565      }
566      else
567      {
568        break;
569      }
570    }
571  }
572  //vertical sub-PU merge
573  for (Int i=0; i<iNumSP-iNumSPInOneLine; i++)
574  {
575    if (uiMergedSPW[i]==0 || uiMergedSPH[i]==0)
576    {
577      continue;
578    }
579    for (Int j=i+iNumSPInOneLine; j<iNumSP; j+=iNumSPInOneLine)
580    {
581      if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j]) && uiMergedSPW[i]==uiMergedSPW[j])
582      {
583        uiMergedSPH[i] += iSPHeight;
584        uiMergedSPH[j] = uiMergedSPW[j] = 0;
585      }
586      else
587      {
588        break;
589      }
590    }
591  }
592}
[608]593
[724]594Bool TComPrediction::xCheckTwoSPMotion ( TComDataCU* pcCU, UInt PartAddr0, UInt PartAddr1 )
595{
596  if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr1))
597  {
598    return false;
599  }
600  if( pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr1))
601  {
602    return false;
603  }
604
605  if (pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) >= 0)
606  {
607    if (pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr1))
608    {
609      return false;
610    }
611  }
612
613  if (pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) >= 0)
614  {
615    if (pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr1))
616    {
617      return false;
618    }
619  }
620  return true;
621}
622#endif
623
[56]624Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
625{
626  Int         iWidth;
627  Int         iHeight;
628  UInt        uiPartAddr;
629
630  if ( iPartIdx >= 0 )
631  {
632    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
[608]633#if H_3D_VSP
[622]634    if ( pcCU->getVSPFlag(uiPartAddr) == 0)
[56]635    {
636#endif
[608]637      if ( eRefPicList != REF_PIC_LIST_X )
[56]638      {
[608]639        if( pcCU->getSlice()->getPPS()->getUseWP())
640        {
641          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
642        }
643        else
644        {
645          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
646        }
647        if ( pcCU->getSlice()->getPPS()->getUseWP() )
648        {
649          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
650        }
[56]651      }
652      else
653      {
[773]654#if H_3D_SPIVMP
[724]655        if ( pcCU->getSPIVMPFlag(uiPartAddr)!=0) 
[608]656        {
[724]657          Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
658
659          pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
660
661          UInt uiW[256], uiH[256];
662          UInt uiSPAddr[256];
663
664          xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr);
665
666          //MC
667          for (Int i = 0; i < iNumSP; i++)
668          {
669            if (uiW[i]==0 || uiH[i]==0)
670            {
671              continue;
672            }
673            if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] ))
674            {
675              xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred );
676            }
677            else
678            {
679              xPredInterBi  (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred);
680            }
681          }
[608]682        }
683        else
684        {
[724]685#endif
686          if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
687          {
688            xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
689          }
690          else
691          {
692            xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
693          }
[773]694#if H_3D_SPIVMP
[608]695        }
[724]696#endif
[56]697      }
[608]698#if H_3D_VSP
[56]699    }
700    else
701    {
[608]702      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
[622]703      {
[608]704        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
[622]705      }
[56]706      else
[622]707      {
[608]708        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
[622]709      }
[608]710    }
[296]711#endif
[2]712    return;
713  }
[56]714
715  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
716  {
717    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
718
[608]719#if H_3D_VSP
[622]720    if ( pcCU->getVSPFlag(uiPartAddr) == 0 )
[56]721    {
[189]722#endif
[608]723      if ( eRefPicList != REF_PIC_LIST_X )
[56]724      {
[608]725        if( pcCU->getSlice()->getPPS()->getUseWP())
726        {
727          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
728        }
729        else
730        {
731          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
732        }
733        if ( pcCU->getSlice()->getPPS()->getUseWP() )
734        {
735          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
736        }
[56]737      }
[608]738      else
[56]739      {
[773]740#if H_3D_SPIVMP
[724]741       if (pcCU->getSPIVMPFlag(uiPartAddr)!=0) 
742      {
743        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
744
745        pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
746
747        UInt uiW[256], uiH[256];
748        UInt uiSPAddr[256];
749
750        xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr);
751        //MC
752        for (Int i = 0; i < iNumSP; i++)
753        {
754          if (uiW[i]==0 || uiH[i]==0)
755          {
756            continue;
757          }
758          if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] ))
759          {
760            xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred );
761          }
762          else
763          {
764            xPredInterBi  (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred);
765          }
766        }
767      }
768      else
769      {
770#endif
[608]771        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
772        {
773          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
774        }
775        else
776        {
777          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
778        }
[773]779#if H_3D_SPIVMP
[724]780       }
781#endif
[56]782      }
[608]783#if H_3D_VSP
[56]784    }
785    else
786    {
787      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
[622]788      {
[608]789        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
[622]790      }
[56]791      else
[622]792      {
[608]793        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
[622]794      }
[56]795    }
[608]796#endif
[56]797  }
798  return;
799}
[2]800
[608]801Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
[296]802{
[608]803  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
804  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
805  pcCU->clipMv(cMv);
806#if H_3D_ARP
[724]807  if(pcCU->getARPW( uiPartAddr ) > 0  && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC())
808  {
[773]809    xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , rpcYuvPred , bi );
[724]810  }
811  else
[443]812  {
[773]813    if(  pcCU->getARPW( uiPartAddr ) > 0 
814      && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N
815      && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() 
816      )
817    {
818      xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi );
819    }
820    else
821    {
[443]822#endif
[608]823#if H_3D_IC
[773]824      Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() );
825      xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
[608]826#if H_3D_ARP
[773]827        , false
[443]828#endif
[773]829        , bICFlag );
830      bICFlag = bICFlag && (iWidth > 8);
831      xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
[608]832#if H_3D_ARP
[773]833        , false
[443]834#endif
[773]835        , bICFlag );
[443]836#else
[773]837      xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
838      xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
[443]839#endif
[608]840#if H_3D_ARP
[773]841    }
[443]842  }
843#endif
844}
845
[608]846#if H_3D_VSP
847Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
[56]848{
[608]849  // Get depth reference
[622]850  Int       depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
[655]851#if H_3D_FCO_VSP_DONBDV_E0163
852  TComPic* pRefPicBaseDepth = 0;
853  Bool     bIsCurrDepthCoded = false;
854  pRefPicBaseDepth  = pcCU->getSlice()->getIvPic( true, pcCU->getSlice()->getViewIndex() );
855  if ( pRefPicBaseDepth->getPicYuvRec() != NULL  ) 
856  {
857    bIsCurrDepthCoded = true;
858  }
859  else 
860  {
861    pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
862  }
863#else
[608]864  TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
[655]865#endif
[608]866  assert(pRefPicBaseDepth != NULL);
867  TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
868  assert(pcBaseViewDepthPicYuv != NULL);
[296]869
[608]870  // Get texture reference
871  Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
872  assert(iRefIdx >= 0);
873  TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx );
874  TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
875  assert(pcBaseViewTxtPicYuv != NULL);
[56]876
[608]877  // Initialize LUT according to the reference viewIdx
878  Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex();
879  Int* pShiftLUT    = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx );
880  assert( txtRefViewIdx < pcCU->getSlice()->getViewIndex() );
[100]881
[608]882  // Do compensation
883  TComMv cDv  = pcCU->getDvInfo(uiPartAddr).m_acNBDV;
884  pcCU->clipMv(cDv);
[296]885
[655]886#if H_3D_FCO_VSP_DONBDV_E0163
887  if ( bIsCurrDepthCoded )
888  {
889      cDv.setZero();
890  }
891#endif
[608]892  // fetch virtual depth map
893  pcBaseViewDepthPicYuv->extendPicBorder();
[724]894
895  Int vspSize=0;
896  xGetVirtualDepth( pcCU, pcBaseViewDepthPicYuv, &cDv, uiPartAddr, iWidth, iHeight, &m_cYuvDepthOnVsp,vspSize );
897  // sub-PU based compensation
898  xPredInterLumaBlkFromDM   ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi, vspSize);
899  xPredInterChromaBlkFromDM ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi, vspSize);
[608]900}
[296]901#endif
[189]902
[608]903#if H_3D_ARP
904Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
905{
906  Int         iRefIdx      = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
907  TComMv      cMv          = pNewMvFiled ? pNewMvFiled->getMv()     : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
908  Bool        bTobeScaled  = false;
909  TComPic* pcPicYuvBaseCol = NULL;
910  TComPic* pcPicYuvBaseRef = NULL;
[2]911
[608]912#if H_3D_NBDV
[443]913  DisInfo cDistparity;
914  cDistparity.bDV           = pcCU->getDvInfo(uiPartAddr).bDV;
915  if( cDistparity.bDV )
916  {
[608]917    cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV;
[443]918    assert(pcCU->getDvInfo(uiPartAddr).bDV ==  pcCU->getDvInfo(0).bDV);
[608]919    cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
[443]920  }
921#else
[608]922  assert(0); // ARP can be applied only when a DV is available
[443]923#endif
924
[608]925  UChar dW = cDistparity.bDV ? pcCU->getARPW ( uiPartAddr ) : 0;
926
927  if( cDistparity.bDV ) 
[443]928  {
[724]929    Int arpRefIdx = pcCU->getSlice()->getFirstTRefIdx(eRefPicList);
930    if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() )
[608]931    {
[443]932      bTobeScaled = true;
[608]933    }
934
935    pcPicYuvBaseCol =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(),                              cDistparity.m_aVIdxCan );
[724]936
937    pcPicYuvBaseRef =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC(), cDistparity.m_aVIdxCan );
938
939    if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, cDistparity.m_aVIdxCan))
[443]940    {
941      dW = 0;
942      bTobeScaled = false;
943    }
944    else
[608]945    {
[724]946      assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC() );
[608]947    }
948
[443]949    if(bTobeScaled)
950    {     
[608]951      Int iCurrPOC    = pcCU->getSlice()->getPOC();
[443]952      Int iColRefPOC  = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx );
953      Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList,  0);
954      Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC);
955      if ( iScale != 4096 )
[608]956      {
[443]957        cMv = cMv.scaleMv( iScale );
[608]958      }
[443]959      iRefIdx = 0;
960    }
961  }
[608]962
[443]963  pcCU->clipMv(cMv);
964  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec();
[608]965  xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
966  xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
967
[443]968  if( dW > 0 )
969  {
[608]970    TComYuv * pYuvB0 = &m_acYuvPredBase[0];
[443]971    TComYuv * pYuvB1  = &m_acYuvPredBase[1];
[608]972
973    TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV;
974    pcCU->clipMv(cMVwithDisparity);
975
976    assert ( cDistparity.bDV );
977
[443]978    pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec();
[608]979    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
980    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
981   
[443]982    pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec();
[608]983    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
984    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
985
986    pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight );
987
988    if( 2 == dW )
989    {
990      pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
991    }
992    rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi );
[443]993  }
994}
[724]995Void TComPrediction::xPredInterUniARPviewRef( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
996{
997  Int         iRefIdx       = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
998  TComMv      cDMv          = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
999  TComMv      cTempDMv      = cDMv;
1000  UChar       dW            = pcCU->getARPW ( uiPartAddr );
1001
1002  TComPic* pcPicYuvBaseTRef = NULL;
1003  TComPic* pcPicYuvCurrTRef = NULL;
1004  TComPic* pcPicYuvBaseCol  = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx ); 
1005  TComPicYuv* pcYuvBaseCol  = pcPicYuvBaseCol->getPicYuvRec();   
1006  Bool bTMVAvai = false;     
1007  TComMv cBaseTMV;
1008  if( pNewMvFiled )
1009  {
1010    iRefIdx = pNewMvFiled->getRefIdx(); 
1011    cDMv = pNewMvFiled->getMv();
1012  }
1013  pcCU->clipMv(cTempDMv);
1014
1015  assert(dW > 0);
1016  if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, pcPicYuvBaseCol->getViewIndex()))
1017  {
1018    dW = 0;
1019  }
1020  Int uiLCUAddr,uiAbsPartAddr;
1021  Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2  + ((cDMv.getHor() + 2)>>2);
1022  Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2);
[443]1023
[724]1024  irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX);
1025  irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); 
1026  pcYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr);
1027  TComDataCU *pColCU = pcPicYuvBaseCol->getCU( uiLCUAddr );
1028
1029  if(!pColCU->isIntra(uiAbsPartAddr))
1030  {
1031    TComMvField puMVField;
1032    for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1) && !bTMVAvai; iList ++)
1033    {
1034      RefPicList eRefPicListCurr = RefPicList(iList);
1035      Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr);
1036      if( iRef != -1)
1037      {
1038        pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); 
1039        Int  iCurrPOC    = pColCU->getSlice()->getPOC();
1040        Int  iCurrRefPOC = pcPicYuvBaseTRef->getPOC();
1041        Int  iCurrRef    = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr);
1042        if( iCurrRef >= 0)
1043        {
1044          pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); 
1045          Int iTargetPOC = pcPicYuvCurrTRef->getPOC();
1046          {
1047            pcPicYuvBaseTRef =  pcCU->getSlice()->getBaseViewRefPic(iTargetPOC,  pcPicYuvBaseCol->getViewIndex() ); 
1048            if(pcPicYuvBaseTRef)
1049            {
1050              cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr);
1051              Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC);
1052              if ( iScale != 4096 )
1053                cBaseTMV = cBaseTMV.scaleMv( iScale );                 
1054              bTMVAvai = true;
1055              break;
1056            }
1057          }
1058        }
1059      }
1060    }
1061  }
1062  if (bTMVAvai == false)
1063  { 
1064    bTMVAvai = true;
1065    cBaseTMV.set(0, 0);
1066    pcPicYuvBaseTRef =  pColCU->getSlice()->getRefPic(eRefPicList,  pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); 
1067    pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic  (eRefPicList,  pcCU->getSlice()->getFirstTRefIdx(eRefPicList));     
1068  }
1069
1070  xPredInterLumaBlk  ( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi,        bTMVAvai);
1071  xPredInterChromaBlk( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi,        bTMVAvai);
1072
1073  if( dW > 0 && bTMVAvai ) 
1074  {
1075    TComYuv*    pYuvCurrTRef    = &m_acYuvPredBase[0];
1076    TComYuv*    pYuvBaseTRef    = &m_acYuvPredBase[1];
1077    TComPicYuv* pcYuvCurrTref   = pcPicYuvCurrTRef->getPicYuvRec();       
1078    TComPicYuv* pcYuvBaseTref   = pcPicYuvBaseTRef->getPicYuvRec(); 
1079    TComMv      cTempMv         = cDMv + cBaseTMV;
1080
1081    pcCU->clipMv(cBaseTMV);
1082    pcCU->clipMv(cTempMv);
1083
1084    xPredInterLumaBlk  ( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, bi,   true);
1085    xPredInterChromaBlk( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, bi,   true);
1086    xPredInterLumaBlk  ( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, bi,   true); 
1087    xPredInterChromaBlk( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, bi,   true); 
1088
1089    pYuvCurrTRef->subtractARP( pYuvCurrTRef , pYuvBaseTRef , uiPartAddr , iWidth , iHeight ); 
1090    if(dW == 2)
1091    {
1092      pYuvCurrTRef->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
1093    }
1094    rpcYuvPred->addARP( rpcYuvPred , pYuvCurrTRef , uiPartAddr , iWidth , iHeight , !bi ); 
1095  }
1096}
1097
1098#endif
1099
[608]1100Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
[2]1101{
[56]1102  TComYuv* pcMbYuv;
1103  Int      iRefIdx[2] = {-1, -1};
1104
1105  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
1106  {
1107    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
1108    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
1109
1110    if ( iRefIdx[iRefList] < 0 )
1111    {
1112      continue;
1113    }
1114
1115    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
1116
1117    pcMbYuv = &m_acYuvPred[iRefList];
1118    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
1119    {
[608]1120      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
[56]1121    }
1122    else
1123    {
[608]1124      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) || 
1125           ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
[56]1126      {
[608]1127        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
[56]1128      }
1129      else
1130      {
[608]1131        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
[56]1132      }
1133    }
1134  }
[608]1135
1136  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE  )
[56]1137  {
1138    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
[608]1139  } 
[313]1140  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
1141  {
[608]1142    xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); 
[313]1143  }
[56]1144  else
1145  {
[608]1146    xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
[56]1147  }
[2]1148}
1149
[608]1150#if H_3D_VSP
[296]1151
[608]1152Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
1153{
1154  TComYuv* pcMbYuv;
1155  Int      iRefIdx[2] = {-1, -1};
1156  Bool     bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0);
[296]1157
[608]1158  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
[2]1159  {
[608]1160    RefPicList eRefPicList = RefPicList(iRefList);
1161    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
[56]1162
[608]1163    if ( iRefIdx[iRefList] < 0 )
[622]1164    {
[608]1165      continue;
[622]1166    }
[608]1167    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
[56]1168
[608]1169    pcMbYuv = &m_acYuvPred[iRefList];
1170    xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi );
[2]1171  }
[296]1172
[608]1173  xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1174}
[296]1175
1176#endif
[56]1177
1178/**
1179 * \brief Generate motion-compensated luma block
1180 *
1181 * \param cu       Pointer to current CU
1182 * \param refPic   Pointer to reference picture
1183 * \param partAddr Address of block within CU
1184 * \param mv       Motion vector
1185 * \param width    Width of block
1186 * \param height   Height of block
1187 * \param dstPic   Pointer to destination picture
1188 * \param bi       Flag indicating whether bipred is used
1189 */
[608]1190Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
1191#if H_3D_ARP
1192    , Bool filterType
[189]1193#endif
[608]1194#if H_3D_IC
1195    , Bool bICFlag
1196#endif
1197  )
[56]1198{
1199  Int refStride = refPic->getStride(); 
1200  Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride;
1201  Pel *ref      = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1202 
1203  Int dstStride = dstPic->getStride();
1204  Pel *dst      = dstPic->getLumaAddr( partAddr );
1205 
1206  Int xFrac = mv->getHor() & 0x3;
1207  Int yFrac = mv->getVer() & 0x3;
1208
[608]1209#if H_3D_IC
1210  if( cu->getSlice()->getIsDepth() )
1211  {
1212    refOffset = mv->getHor() + mv->getVer() * refStride;
1213    ref       = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1214    xFrac     = 0;
1215    yFrac     = 0;
1216  }
[56]1217#endif
1218  if ( yFrac == 0 )
[2]1219  {
[655]1220#if H_3D_IC
[608]1221    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi || bICFlag
1222#else
1223    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi
[443]1224#endif
[608]1225#if H_3D_ARP
1226    , filterType
1227#endif
1228      );
[2]1229  }
[56]1230  else if ( xFrac == 0 )
1231  {
[655]1232#if H_3D_IC
[608]1233    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag
1234#else
1235    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi
[443]1236#endif
[608]1237#if H_3D_ARP
1238    , filterType
1239#endif
1240      );
[56]1241  }
1242  else
1243  {
1244    Int tmpStride = m_filteredBlockTmp[0].getStride();
1245    Short *tmp    = m_filteredBlockTmp[0].getLumaAddr();
1246
1247    Int filterSize = NTAPS_LUMA;
1248    Int halfFilterSize = ( filterSize >> 1 );
1249
[443]1250    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     
[608]1251#if H_3D_ARP
1252    , filterType
[443]1253#endif
[608]1254      );
[655]1255#if H_3D_IC
[608]1256    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi || bICFlag
1257#else
[443]1258    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi
[608]1259#endif
1260#if H_3D_ARP
1261    , filterType
[443]1262#endif
[608]1263      );   
[56]1264  }
[189]1265
[608]1266#if H_3D_IC
1267  if( bICFlag )
[189]1268  {
[608]1269    Int a, b, i, j;
1270    const Int iShift = IC_CONST_SHIFT;
1271
1272    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA );
[189]1273
1274
[608]1275    for ( i = 0; i < height; i++ )
[189]1276    {
[608]1277      for ( j = 0; j < width; j++ )
[189]1278      {
[608]1279          dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
[189]1280      }
1281      dst += dstStride;
1282    }
[655]1283
[608]1284    if(bi)
1285    {
1286      Pel *dst2      = dstPic->getLumaAddr( partAddr );
1287      Int shift = IF_INTERNAL_PREC - g_bitDepthY;
1288      for (i = 0; i < height; i++)
1289      {
1290        for (j = 0; j < width; j++)
1291        {
1292          Short val = dst2[j] << shift;
1293          dst2[j] = val - (Short)IF_INTERNAL_OFFS;
1294        }
1295        dst2 += dstStride;
1296      }
1297    }
[189]1298  }
1299#endif
[2]1300}
1301
[56]1302/**
1303 * \brief Generate motion-compensated chroma block
1304 *
1305 * \param cu       Pointer to current CU
1306 * \param refPic   Pointer to reference picture
1307 * \param partAddr Address of block within CU
1308 * \param mv       Motion vector
1309 * \param width    Width of block
1310 * \param height   Height of block
1311 * \param dstPic   Pointer to destination picture
1312 * \param bi       Flag indicating whether bipred is used
1313 */
[608]1314Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
1315#if H_3D_ARP
1316    , Bool filterType
[189]1317#endif
[608]1318#if H_3D_IC
1319    , Bool bICFlag
1320#endif
[443]1321  )
[2]1322{
[56]1323  Int     refStride  = refPic->getCStride();
1324  Int     dstStride  = dstPic->getCStride();
1325 
1326  Int     refOffset  = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride;
1327 
1328  Pel*    refCb     = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1329  Pel*    refCr     = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1330 
1331  Pel* dstCb = dstPic->getCbAddr( partAddr );
1332  Pel* dstCr = dstPic->getCrAddr( partAddr );
1333 
1334  Int     xFrac  = mv->getHor() & 0x7;
1335  Int     yFrac  = mv->getVer() & 0x7;
1336  UInt    cxWidth  = width  >> 1;
1337  UInt    cxHeight = height >> 1;
1338 
1339  Int     extStride = m_filteredBlockTmp[0].getStride();
1340  Short*  extY      = m_filteredBlockTmp[0].getLumaAddr();
1341 
1342  Int filterSize = NTAPS_CHROMA;
1343 
1344  Int halfFilterSize = (filterSize>>1);
1345 
1346  if ( yFrac == 0 )
1347  {
[655]1348#if H_3D_IC
[608]1349    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
1350#else
[443]1351    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi
[608]1352#endif
1353#if H_3D_ARP
1354    , filterType
1355#endif
[443]1356    );   
[655]1357#if H_3D_IC
[608]1358    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
1359#else
[443]1360    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi
[608]1361#endif
1362#if H_3D_ARP
1363    , filterType
1364#endif
1365    );
[56]1366  }
1367  else if ( xFrac == 0 )
1368  {
[655]1369#if H_3D_IC
[608]1370    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
1371#else
[443]1372    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi
[608]1373#endif
1374#if H_3D_ARP
1375    , filterType
1376#endif
1377    );
[655]1378#if H_3D_IC
[608]1379    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
1380#else
[443]1381    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi
[608]1382#endif
1383#if H_3D_ARP
1384    , filterType
1385#endif
1386    );
[56]1387  }
1388  else
1389  {
[443]1390    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
[608]1391#if H_3D_ARP
1392    , filterType
1393#endif 
1394      );
[655]1395#if H_3D_IC
[608]1396    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
1397#else
[443]1398    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
[608]1399#endif
1400#if H_3D_ARP
1401    , filterType
1402#endif
1403      );
[56]1404   
[443]1405    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
[608]1406#if H_3D_ARP
1407    , filterType
1408#endif
1409      );
[655]1410#if H_3D_IC
[608]1411    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
1412#else
[443]1413    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
[608]1414#endif
1415#if H_3D_ARP
1416    , filterType
1417#endif
1418      );   
[56]1419  }
[608]1420
1421#if H_3D_IC
1422  if( bICFlag )
[189]1423  {
[608]1424    Int a, b, i, j;
1425    const Int iShift = IC_CONST_SHIFT;
1426    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb
1427    for ( i = 0; i < cxHeight; i++ )
[189]1428    {
[608]1429      for ( j = 0; j < cxWidth; j++ )
[189]1430      {
[608]1431          dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
[189]1432      }
1433      dstCb += dstStride;
1434    }
[608]1435    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr
1436    for ( i = 0; i < cxHeight; i++ )
[189]1437    {
[608]1438      for ( j = 0; j < cxWidth; j++ )
[189]1439      {
[608]1440          dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
[189]1441      }
1442      dstCr += dstStride;
1443    }
[655]1444
[608]1445    if(bi)
[296]1446    {
[608]1447      Pel* dstCb2 = dstPic->getCbAddr( partAddr );
1448      Pel* dstCr2 = dstPic->getCrAddr( partAddr );
1449      Int shift = IF_INTERNAL_PREC - g_bitDepthC;
1450      for (i = 0; i < cxHeight; i++)
[296]1451      {
[608]1452        for (j = 0; j < cxWidth; j++)
[296]1453        {
[608]1454          Short val = dstCb2[j] << shift;
1455          dstCb2[j] = val - (Short)IF_INTERNAL_OFFS;
[461]1456
[608]1457          val = dstCr2[j] << shift;
1458          dstCr2[j] = val - (Short)IF_INTERNAL_OFFS;
[296]1459        }
[608]1460        dstCb2 += dstStride;
1461        dstCr2 += dstStride;
[443]1462      }
1463    }
[296]1464  }
[443]1465#endif
[296]1466}
1467
[608]1468Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
[2]1469{
[56]1470  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
[2]1471  {
[56]1472    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
[2]1473  }
[56]1474  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
[2]1475  {
[56]1476    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
[2]1477  }
[56]1478  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
[2]1479  {
[56]1480    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
1481  }
1482}
1483
1484// AMVP
[608]1485Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
[56]1486{
1487  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
[608]1488  if( pcAMVPInfo->iN <= 1 )
[56]1489  {
1490    rcMvPred = pcAMVPInfo->m_acMvCand[0];
1491
1492    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1493    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1494    return;
1495  }
1496
1497  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
1498  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
1499  return;
1500}
1501
1502/** Function for deriving planar intra prediction.
1503 * \param pSrc pointer to reconstructed sample array
1504 * \param srcStride the stride of the reconstructed sample array
1505 * \param rpDst reference to pointer for the prediction sample array
1506 * \param dstStride the stride of the prediction sample array
1507 * \param width the width of the block
1508 * \param height the height of the block
1509 *
1510 * This function derives the prediction samples for planar mode (intra coding).
1511 */
1512Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
1513{
1514  assert(width == height);
1515
1516  Int k, l, bottomLeft, topRight;
1517  Int horPred;
[655]1518  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
[56]1519  UInt blkSize = width;
1520  UInt offset2D = width;
1521  UInt shift1D = g_aucConvertToBit[ width ] + 2;
1522  UInt shift2D = shift1D + 1;
1523
1524  // Get left and above reference column and row
1525  for(k=0;k<blkSize+1;k++)
1526  {
1527    topRow[k] = pSrc[k-srcStride];
1528    leftColumn[k] = pSrc[k*srcStride-1];
1529  }
1530
1531  // Prepare intermediate variables used in interpolation
1532  bottomLeft = leftColumn[blkSize];
1533  topRight   = topRow[blkSize];
1534  for (k=0;k<blkSize;k++)
1535  {
1536    bottomRow[k]   = bottomLeft - topRow[k];
1537    rightColumn[k] = topRight   - leftColumn[k];
1538    topRow[k]      <<= shift1D;
1539    leftColumn[k]  <<= shift1D;
1540  }
1541
1542  // Generate prediction signal
1543  for (k=0;k<blkSize;k++)
1544  {
1545    horPred = leftColumn[k] + offset2D;
1546    for (l=0;l<blkSize;l++)
[2]1547    {
[56]1548      horPred += rightColumn[k];
1549      topRow[l] += bottomRow[l];
1550      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
[2]1551    }
1552  }
1553}
1554
[608]1555/** Function for filtering intra DC predictor.
1556 * \param pSrc pointer to reconstructed sample array
1557 * \param iSrcStride the stride of the reconstructed sample array
1558 * \param rpDst reference to pointer for the prediction sample array
1559 * \param iDstStride the stride of the prediction sample array
1560 * \param iWidth the width of the block
1561 * \param iHeight the height of the block
[56]1562 *
[608]1563 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
[56]1564 */
[608]1565Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
[56]1566{
[608]1567  Pel* pDst = rpDst;
1568  Int x, y, iDstStride2, iSrcStride2;
[2]1569
[608]1570  // boundary pixels processing
1571  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
[56]1572
[608]1573  for ( x = 1; x < iWidth; x++ )
[2]1574  {
[608]1575    pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
[2]1576  }
1577
[608]1578  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
[56]1579  {
[608]1580    pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
[56]1581  }
[2]1582
[608]1583  return;
[2]1584}
[608]1585#if H_3D_IC
1586/** Function for deriving the position of first non-zero binary bit of a value
[56]1587 * \param x input value
1588 *
[608]1589 * This function derives the position of first non-zero binary bit of a value
[56]1590 */
1591Int GetMSB( UInt x )
1592{
1593  Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1;
1594
1595  while( x > 1 )
1596  {
1597    bits >>= 1;
1598    y = x >> bits;
1599
1600    if( y )
1601    {
1602      x = y;
1603      iMSB += bits;
1604    }
1605  }
1606
1607  iMSB+=y;
1608
1609  return iMSB;
1610}
1611
1612
[608]1613/** Function for deriving LM illumination compensation.
[56]1614 */
[608]1615Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType )
[56]1616{
[608]1617  TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
1618  Pel *pRec = NULL, *pRef = NULL;
1619  UInt uiWidth, uiHeight, uiTmpPartIdx;
1620  Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride();
1621  Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride();
1622  Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer;
[56]1623
[608]1624  iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
1625  iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
1626  iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 );
1627  iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 );
1628  iRefX   = iCUPelX + iHor;
1629  iRefY   = iCUPelY + iVer;
1630  if( eType != TEXT_LUMA )
1631  {
1632    iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 );
1633    iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 );
1634  }
1635  uiWidth  = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 )  : ( pcCU->getWidth( 0 )  >> 1 );
1636  uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 );
[56]1637
1638  Int i, j, iCountShift = 0;
1639
1640  // LLS parameters estimation -->
1641
1642  Int x = 0, y = 0, xx = 0, xy = 0;
[608]1643  Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12);
[56]1644
[608]1645  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 )
[56]1646  {
[608]1647    iRefOffset = iHor + iVer * iRefStride - iRefStride;
1648    if( eType == TEXT_LUMA )
[56]1649    {
[608]1650      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1651      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
[56]1652    }
[608]1653    else if( eType == TEXT_CHROMA_U )
[56]1654    {
[608]1655      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1656      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
[56]1657    }
[608]1658    else
1659    {
1660      assert( eType == TEXT_CHROMA_V );
1661      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1662      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
1663    }
[56]1664
[608]1665    for( j = 0; j < uiWidth; j+=2 )
[189]1666    {
1667      x += pRef[j];
1668      y += pRec[j];
[608]1669      xx += (pRef[j] * pRef[j])>>precShift;
1670      xy += (pRef[j] * pRec[j])>>precShift;
[189]1671    }
[608]1672    iCountShift += g_aucConvertToBit[ uiWidth ] + 1;
[189]1673  }
1674
1675
[608]1676  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 )
[189]1677  {
[608]1678    iRefOffset = iHor + iVer * iRefStride - 1;
1679    if( eType == TEXT_LUMA )
1680    {
1681      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1682      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1683    }
1684    else if( eType == TEXT_CHROMA_U )
1685    {
1686      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1687      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1688    }
1689    else
1690    {
1691      assert( eType == TEXT_CHROMA_V );
1692      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1693      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1694    }
1695
1696    for( i = 0; i < uiHeight; i+=2 )
[189]1697    {
1698      x += pRef[0];
1699      y += pRec[0];
[655]1700
[608]1701      xx += (pRef[0] * pRef[0])>>precShift;
1702      xy += (pRef[0] * pRec[0])>>precShift;
1703
1704      pRef += iRefStride*2;
1705      pRec += iRecStride*2;
[189]1706    }
[608]1707    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 );
[189]1708  }
1709
[608]1710  xy += xx >> IC_REG_COST_SHIFT;
1711  xx += xx >> IC_REG_COST_SHIFT;
1712  Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift);
1713  Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift);
1714  const Int iShift = IC_CONST_SHIFT;
1715  {
[189]1716    {
1717      const Int iShiftA2 = 6;
1718      const Int iAccuracyShift = 15;
1719
1720      Int iScaleShiftA2 = 0;
1721      Int iScaleShiftA1 = 0;
1722      Int a1s = a1;
1723      Int a2s = a2;
1724
[608]1725      a1 = Clip3(0, 2*a2, a1);
1726      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2;
1727      iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF;
[189]1728
1729      if( iScaleShiftA1 < 0 )
1730      {
1731        iScaleShiftA1 = 0;
1732      }
1733
1734      if( iScaleShiftA2 < 0 )
1735      {
1736        iScaleShiftA2 = 0;
1737      }
1738
1739      Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
1740
[608]1741
[189]1742      a2s = a2 >> iScaleShiftA2;
1743
1744      a1s = a1 >> iScaleShiftA1;
1745
[608]1746      a = a1s * m_uiaShift[ a2s ];
1747      a = a >> iScaleShiftA;
[189]1748      b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
1749    }
1750  }   
1751}
[608]1752#endif
[189]1753
[608]1754#if H_3D_VSP
1755// not fully support iRatioTxtPerDepth* != 1
[724]1756Void TComPrediction::xGetVirtualDepth( TComDataCU *cu, TComPicYuv *picRefDepth, TComMv *mv, UInt partAddr, Int width, Int height, TComYuv *yuvDepth, Int &vspSize, Int ratioTxtPerDepthX, Int ratioTxtPerDepthY )
[189]1757{
[608]1758  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
1759  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
[189]1760
[608]1761  Int refDepStride = picRefDepth->getStride();
[189]1762
[608]1763  Int refDepOffset  = ( (mv->getHor()+2) >> 2 ) + ( (mv->getVer()+2) >> 2 ) * refDepStride;
1764  Pel *refDepth     = picRefDepth->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
[189]1765
[608]1766  if( ratioTxtPerDepthX!=1 || ratioTxtPerDepthY!=1 )
[189]1767  {
[608]1768    Int posX, posY;
1769    refDepth    = picRefDepth->getLumaAddr( );
1770    cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
1771    posX /= ratioTxtPerDepthX; // texture position -> depth postion
1772    posY /= ratioTxtPerDepthY;
1773    refDepOffset += posX + posY * refDepStride;
[189]1774
[608]1775    width  /= ratioTxtPerDepthX; // texture size -> depth size
1776    height /= ratioTxtPerDepthY;
[189]1777  }
1778
[608]1779  refDepth += refDepOffset;
[189]1780
[608]1781  Int depStride = yuvDepth->getStride();
1782  Pel *depth = yuvDepth->getLumaAddr();
[189]1783
[724]1784  if ((height % 8))
1785  {
1786    vspSize = 1; // 8x4
[608]1787  }
[724]1788  else if ((width % 8))
1789  {
1790    vspSize = 0; // 4x8
1791  }
1792  else
1793  {
1794    Bool ULvsBR, URvsBL;
1795    ULvsBR = refDepth[0]       < refDepth[refDepStride * (height-1) + width-1];
1796    URvsBL = refDepth[width-1] < refDepth[refDepStride * (height-1)];
1797    vspSize = ( ULvsBR ^ URvsBL ) ? 0 : 1;
1798  }
1799  Int subBlockW, subBlockH;
1800  Int depStrideTmp = depStride * nTxtPerDepthY;
1801  if (vspSize)
1802  {
1803    subBlockW = 8;
1804    subBlockH = 4;
1805  }
1806  else
1807  {
1808    subBlockW = 4;
1809    subBlockH = 8;
1810  }
1811  for( Int y=0; y<height; y+=subBlockH )
1812  {
1813    Pel *refDepthTmp[4];
1814    refDepthTmp[0] = refDepth + refDepStride * y;
1815    refDepthTmp[1] = refDepthTmp[0] + subBlockW - 1;
1816    refDepthTmp[2] = refDepthTmp[0] + refDepStride * (subBlockH - 1);
1817    refDepthTmp[3] = refDepthTmp[2] + subBlockW - 1;
1818    for( Int x=0; x<width; x+=subBlockW )
1819    {
1820      Pel  maxDepthVal;
1821      maxDepthVal = refDepthTmp[0][x];
1822      maxDepthVal = std::max( maxDepthVal, refDepthTmp[1][x]);
1823      maxDepthVal = std::max( maxDepthVal, refDepthTmp[2][x]);
1824      maxDepthVal = std::max( maxDepthVal, refDepthTmp[3][x]);
1825      Pel *depthTmp = &depth[x+y*depStride];
1826      for( Int sY=0; sY<subBlockH; sY+=nTxtPerDepthY )
1827      {
1828        for( Int sX=0; sX<subBlockW; sX+=nTxtPerDepthX )
1829        {
1830          depthTmp[sX] = maxDepthVal;
1831        }
1832        depthTmp += depStrideTmp;
1833      }
1834    }
[773]1835  }   
[608]1836}
1837
[724]1838Void TComPrediction::xPredInterLumaBlkFromDM( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi, Int vspSize)
[608]1839{
1840  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
1841  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
1842 
[724]1843  nTxtPerDepthX = nTxtPerDepthX << vspSize;
1844  nTxtPerDepthY = nTxtPerDepthY << (1-vspSize);
[773]1845
[608]1846  Int refStride = picRef->getStride();
1847  Int dstStride = yuvDst->getStride();
1848  Int depStride = yuvDepth->getStride();
1849  Int refStrideBlock = refStride  * nTxtPerDepthY;
1850  Int dstStrideBlock = dstStride * nTxtPerDepthY;
1851  Int depStrideBlock = depStride * nTxtPerDepthY;
1852
1853  Pel *ref    = picRef->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
1854  Pel *dst    = yuvDst->getLumaAddr(partAddr);
1855  Pel *depth  = yuvDepth->getLumaAddr();
1856
1857#if H_3D_VSP_BLOCKSIZE == 1
1858#if H_3D_VSP_CONSTRAINED
1859  //get LUT based horizontal reference range
1860  Int range = xGetConstrainedSize(width, height);
1861
1862  // The minimum depth value
1863  Int minRelativePos = MAX_INT;
1864  Int maxRelativePos = MIN_INT;
1865
1866  Pel* depthTemp, *depthInitial=depth;
1867  for (Int yTxt = 0; yTxt < height; yTxt++)
1868  {
1869    for (Int xTxt = 0; xTxt < width; xTxt++)
1870    {
1871      if (depthPosX+xTxt < widthDepth)
[189]1872      {
[608]1873        depthTemp = depthInitial + xTxt;
[189]1874      }
1875      else
1876      {
[608]1877        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
[189]1878      }
1879
[608]1880      Int disparity = shiftLUT[ *depthTemp ]; // << iShiftPrec;
1881      Int disparityInt = disparity >> 2;
[189]1882
[608]1883      if( disparity <= 0)
[189]1884      {
[608]1885        if (minRelativePos > disparityInt+xTxt)
1886        {
1887          minRelativePos = disparityInt+xTxt;
1888        }
[189]1889      }
1890      else
1891      {
[608]1892        if (maxRelativePos < disparityInt+xTxt)
1893        {
1894          maxRelativePos = disparityInt+xTxt;
1895        }
[189]1896      }
1897    }
[608]1898    if (depthPosY+yTxt < heightDepth)
1899    {
1900      depthInitial = depthInitial + depStride;
1901    }
1902  }
[56]1903
[608]1904  Int disparity_tmp = shiftLUT[ *depth ]; // << iShiftPrec;
1905  if (disparity_tmp <= 0)
[56]1906  {
[608]1907    maxRelativePos = minRelativePos + range -1 ;
[56]1908  }
[608]1909  else
[56]1910  {
[608]1911    minRelativePos = maxRelativePos - range +1 ;
[56]1912  }
[608]1913#endif
1914#endif // H_3D_VSP_BLOCKSIZE == 1
[56]1915
[608]1916  TComMv dv(0, 0);
[56]1917
[608]1918  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
1919  {
1920    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
1921    {
1922      Pel repDepth = depth[ xTxt ];
1923      assert( repDepth >= 0 && repDepth <= 255 );
1924
1925      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec ??
1926      Int xFrac = disparity & 0x3;
1927
1928      dv.setHor( disparity );
1929      cu->clipMv( dv );
1930
1931      Int refOffset = xTxt + (dv.getHor() >> 2);
1932     
1933#if H_3D_VSP_CONSTRAINED
1934      if(refOffset<minRelativePos || refOffset>maxRelativePos)
1935      {
1936        xFrac = 0;
1937      }
1938      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
[5]1939#endif
[608]1940
1941      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
1942      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
1943    }
1944    ref   += refStrideBlock;
1945    dst   += dstStrideBlock;
1946    depth += depStrideBlock;
[443]1947  }
1948
1949}
[608]1950
[724]1951Void TComPrediction::xPredInterChromaBlkFromDM  ( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi, Int vspSize)
[608]1952{
1953#if (H_3D_VSP_BLOCKSIZE==1)
1954  Int nTxtPerDepthX = 1;
1955  Int nTxtPerDepthY = 1;
[443]1956#else
[608]1957  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE >> 1;
1958  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE >> 1;
1959#endif
[2]1960
[724]1961  nTxtPerDepthX = nTxtPerDepthX << vspSize;
1962  nTxtPerDepthY = nTxtPerDepthY << (1-vspSize);
[773]1963
[608]1964  Int refStride = picRef->getCStride();
1965  Int dstStride = yuvDst->getCStride();
1966  Int depStride = yuvDepth->getStride();
1967  Int refStrideBlock = refStride * nTxtPerDepthY;
1968  Int dstStrideBlock = dstStride * nTxtPerDepthY;
1969  Int depStrideBlock = depStride * (nTxtPerDepthY<<1);
[2]1970
[608]1971  Pel *refCb  = picRef->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
1972  Pel *refCr  = picRef->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
1973  Pel *dstCb  = yuvDst->getCbAddr(partAddr);
1974  Pel *dstCr  = yuvDst->getCrAddr(partAddr);
1975  Pel *depth  = yuvDepth->getLumaAddr();
[56]1976
[608]1977#if H_3D_VSP_BLOCKSIZE == 1
1978#if H_3D_VSP_CONSTRAINED
1979  //get LUT based horizontal reference range
1980  Int range = xGetConstrainedSize(width, height, false);
[296]1981
[608]1982  // The minimum depth value
1983  Int minRelativePos = MAX_INT;
1984  Int maxRelativePos = MIN_INT;
1985
1986  Int depthTmp;
1987  for (Int yTxt=0; yTxt<height; yTxt++)
[56]1988  {
[608]1989    for (Int xTxt=0; xTxt<width; xTxt++)
[56]1990    {
[608]1991      depthTmp = m_pDepthBlock[xTxt+yTxt*width];
1992      Int disparity = shiftLUT[ depthTmp ]; // << iShiftPrec;
1993      Int disparityInt = disparity >> 3;//in chroma resolution
1994
1995      if (disparityInt < 0)
[56]1996      {
[608]1997        if (minRelativePos > disparityInt+xTxt)
1998        {
1999          minRelativePos = disparityInt+xTxt;
2000        }
[56]2001      }
2002      else
2003      {
[608]2004        if (maxRelativePos < disparityInt+xTxt)
2005        {
2006          maxRelativePos = disparityInt+xTxt;
2007        }
[56]2008      }
2009    }
2010  }
2011
[608]2012  depthTmp = m_pDepthBlock[0];
2013  Int disparity_tmp = shiftLUT[ depthTmp ]; // << iShiftPrec;
2014  if ( disparity_tmp < 0 )
[56]2015  {
[608]2016    maxRelativePos = minRelativePos + range - 1;
[56]2017  }
[608]2018  else
[56]2019  {
[608]2020    minRelativePos = maxRelativePos - range + 1;
[56]2021  }
[2]2022
[608]2023#endif // H_3D_VSP_CONSTRAINED
2024#endif // H_3D_VSP_BLOCKSIZE == 1
2025
2026  TComMv dv(0, 0);
2027  // luma size -> chroma size
2028  height >>= 1;
2029  width  >>= 1;
2030
2031  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
[5]2032  {
[608]2033    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
[5]2034    {
[608]2035      Pel repDepth = depth[ xTxt<<1 ];
2036      assert( repDepth >= 0 && repDepth <= 255 );
2037
2038      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec;
2039      Int xFrac = disparity & 0x7;
2040     
2041      dv.setHor( disparity );
2042      cu->clipMv( dv );
2043
2044      Int refOffset = xTxt + (dv.getHor() >> 3);
2045
2046#if H_3D_VSP_CONSTRAINED
2047      if(refOffset<minRelativePos || refOffset>maxRelativePos)
[5]2048      {
[608]2049        xFrac = 0;
[5]2050      }
[608]2051      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
2052#endif
2053
2054      assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
2055      assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
2056
2057      m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
2058      m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
[5]2059    }
[608]2060    refCb += refStrideBlock;
2061    refCr += refStrideBlock;
2062    dstCb += dstStrideBlock;
2063    dstCr += dstStrideBlock;
2064    depth += depStrideBlock;
[5]2065  }
2066}
[2]2067
[5]2068
[608]2069#if H_3D_VSP_CONSTRAINED
2070Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma)
[56]2071{
[608]2072  Int iSize = 0;
2073  if (bLuma)
[2]2074  {
[608]2075    Int iArea = (nPbW+7) * (nPbH+7);
2076    Int iAlpha = iArea / nPbH - nPbW - 7;
2077    iSize = iAlpha + nPbW;
[2]2078  }
[608]2079  else // chroma
2080  {
2081    Int iArea = (nPbW+2) * (nPbH+2);
2082    Int iAlpha = iArea / nPbH - nPbW - 4;
2083    iSize = iAlpha + nPbW;
2084  }
2085  return iSize;
[2]2086}
[608]2087#endif // H_3D_VSP_CONSTRAINED
[2]2088
[608]2089#endif // H_3D_VSP
2090
2091#if H_3D_DIM
2092Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
[2]2093{
[608]2094  Int  refDC1, refDC2;
2095  const Int  iTR = (   patternStride - 1        ) - srcStride;
2096  const Int  iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride;
2097  const Int  iLB = (   patternStride - 1        ) * srcStride - 1;
2098  const Int  iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1;
[2]2099
[608]2100  Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] );
2101  Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)]               );
2102
2103  if( bL == bT )
[56]2104  {
[608]2105    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : 1<<( g_bitDepthY - 1 );
2106    refDC2 =      ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1;
[56]2107  }
2108  else
2109  {
[608]2110    refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR];
2111    refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM];
[56]2112  }
2113
[608]2114  predDC1 = biSegPattern[0] ? refDC1 : refDC2;
2115  predDC2 = biSegPattern[0] ? refDC2 : refDC1;
[2]2116}
2117
[608]2118Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
[56]2119{
[608]2120  if( dstStride == patternStride )
2121  {
2122    for( UInt k = 0; k < (patternStride * patternStride); k++ )
2123    {
2124      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
2125      else                          { ptrDst[k] = valDC1; }
2126    }
[443]2127  }
[608]2128  else
2129  {
2130    Pel* piTemp = ptrDst;
2131    for( UInt uiY = 0; uiY < patternStride; uiY++ )
2132    {
2133      for( UInt uiX = 0; uiX < patternStride; uiX++ )
2134      {
2135        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
2136        else                            { piTemp[uiX] = valDC1; }
2137      }
2138      piTemp       += dstStride;
2139      biSegPattern += patternStride;
2140    }
[443]2141  }
[56]2142}
2143
[608]2144#if H_3D_DIM_DMM
[56]2145
[608]2146Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
[56]2147{
[608]2148  pcContourWedge->clear();
[56]2149
[608]2150  // get copy of co-located texture luma block
2151  TComYuv cTempYuv;
2152  cTempYuv.create( uiWidth, uiHeight ); 
2153  cTempYuv.clear();
2154  Pel* piRefBlkY = cTempYuv.getLumaAddr();
2155  xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
2156  piRefBlkY = cTempYuv.getLumaAddr();
[56]2157
[608]2158  // find contour for texture luma block
2159  UInt iDC = 0;
2160  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2161  { 
2162    iDC += piRefBlkY[k]; 
2163  }
2164
[655]2165  Int cuMaxLog2Size = g_aucConvertToBit[g_uiMaxCUWidth]+2;   //
2166  iDC = iDC >> (cuMaxLog2Size - pcCU->getDepth(0))*2;        //  iDC /= (uiWidth*uiHeight);
2167
[608]2168  piRefBlkY = cTempYuv.getLumaAddr();
[56]2169
[608]2170  Bool* pabContourPattern = pcContourWedge->getPattern();
2171  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
[443]2172  { 
[608]2173    pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
[443]2174  }
[608]2175
2176  cTempYuv.destroy();
[56]2177}
2178
[608]2179
2180Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
[56]2181{
[608]2182  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
2183  assert( pcPicYuvRef != NULL );
2184  Int         iRefStride = pcPicYuvRef->getStride();
2185  Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
[56]2186
[608]2187  for ( Int y = 0; y < uiHeight; y++ )
[56]2188  {
[608]2189    ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
2190    piDestBlockY += uiWidth;
2191    piRefY += iRefStride;
[56]2192  }
2193}
[655]2194#endif
[56]2195
[2]2196
[608]2197#if H_3D_DIM_SDC
2198Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
2199                                         ,UInt uiIntraMode
2200                                         ,Bool orgDC
2201                                        )
2202{
2203  Int iSumDepth[2];
2204  memset(iSumDepth, 0, sizeof(Int)*2);
2205  Int iSumPix[2];
2206  memset(iSumPix, 0, sizeof(Int)*2);
[781]2207#if QC_GENERIC_SDC_G0122
2208  for( Int i = 0; i < uiNumSegments; i++ )
2209  {
2210    rpSegMeans[i] = 0;
2211  }
2212#endif
[608]2213  if (orgDC == false)
[2]2214  {
[608]2215    if ( getDimType(uiIntraMode) == DMM1_IDX )
2216    {
2217      UChar ucSegmentLT = pMask[0];
2218      UChar ucSegmentRT = pMask[uiSize-1];
2219      UChar ucSegmentLB = pMask[uiMaskStride * (uiSize-1)]; 
2220      UChar ucSegmentRB = pMask[uiMaskStride * (uiSize-1) + (uiSize-1)]; 
2221
2222      rpSegMeans[ucSegmentLT] = pOrig[0];
2223      rpSegMeans[ucSegmentRT] = pOrig[uiSize-1];
2224      rpSegMeans[ucSegmentLB] = pOrig[uiStride * (uiSize-1) ];
2225      rpSegMeans[ucSegmentRB] = pOrig[uiStride * (uiSize-1) + (uiSize-1) ];
2226    }
[781]2227#if QC_GENERIC_SDC_G0122
2228    else if( getDimType( uiIntraMode ) == DMM4_IDX )
2229    {
2230      Pel *ptmpOrig = pOrig;
2231      Bool *ptmpMask = pMask, bBreak = false;
2232      UChar ucSegment = ptmpMask? (UChar) ptmpMask[0] : 0;
2233      UChar bFirstSeg = ucSegment;
2234
2235      rpSegMeans[ucSegment] = ptmpOrig[0];
2236      for ( Int y = 0; y < uiSize; y++ )
2237      {
2238        for ( Int x = 0; x < uiSize; x++ )
2239        {
2240          ucSegment = ptmpMask[x];
2241          assert( ucSegment < uiNumSegments );
2242
2243          if( bFirstSeg != ucSegment )
2244          {
2245            rpSegMeans[ucSegment] = ptmpOrig[x];
2246            bBreak = true;
2247            break;
2248          }
2249        }
2250
2251        if( bBreak )
2252        {
2253          break;
2254        }
2255
2256        ptmpOrig  += uiStride;
2257        ptmpMask  += uiMaskStride;
2258      }
2259    }
2260    else
2261#else
[608]2262    else if (uiIntraMode == PLANAR_IDX)
[781]2263#endif
[608]2264    {
2265      Pel* pLeftTop = pOrig;
2266      Pel* pRightTop = pOrig + (uiSize-1);
2267      Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1)));
2268      Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1));
2269
2270      rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
2271    }
2272    return;
[2]2273  }
[608]2274
2275  Int subSamplePix;
2276  if ( uiSize == 64 || uiSize == 32 )
[2]2277  {
[608]2278    subSamplePix = 2;
[2]2279  }
[608]2280  else
[2]2281  {
[608]2282    subSamplePix = 1;
[2]2283  }
[608]2284  for (Int y=0; y<uiSize; y+=subSamplePix)
[2]2285  {
[608]2286    for (Int x=0; x<uiSize; x+=subSamplePix)
2287    {
2288      UChar ucSegment = pMask?(UChar)pMask[x]:0;
2289      assert( ucSegment < uiNumSegments );
2290     
2291      iSumDepth[ucSegment] += pOrig[x];
2292      iSumPix[ucSegment]   += 1;
2293    }
2294   
2295    pOrig  += uiStride*subSamplePix;
2296    pMask  += uiMaskStride*subSamplePix;
[2]2297  }
[608]2298 
2299  // compute mean for each segment
2300  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
[2]2301  {
[608]2302    if( iSumPix[ucSeg] > 0 )
2303      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
2304    else
2305      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
[2]2306  }
2307}
[608]2308#endif // H_3D_DIM_SDC
2309#endif
[56]2310//! \}
Note: See TracBrowser for help on using the repository browser.