source: 3DVCSoftware/branches/HTM-9.3-dev1-RWTH/source/Lib/TLibCommon/TComPrediction.cpp @ 1404

Last change on this file since 1404 was 821, checked in by rwth, 11 years ago
  • fixed bracketing
  • removed global variable
  • Property svn:eol-style set to native
File size: 80.9 KB
Line 
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
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2013, ITU/ISO/IEC
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.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
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 */
33
34/** \file     TComPrediction.cpp
35    \brief    prediction class
36*/
37
38#include <memory.h>
39#include "TComPrediction.h"
40
41//! \ingroup TLibCommon
42//! \{
43
44// ====================================================================================================================
45// Constructor / destructor / initialize
46// ====================================================================================================================
47
48TComPrediction::TComPrediction()
49: m_pLumaRecBuffer(0)
50, m_iLumaRecStride(0)
51{
52  m_piYuvExt = NULL;
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)
56      printf("ERROR: UKTGHU, No memory allocated.\n");
57#endif
58}
59
60TComPrediction::~TComPrediction()
61{
62#if H_3D_VSP
63  if (m_pDepthBlock != NULL)
64      free(m_pDepthBlock);
65  m_cYuvDepthOnVsp.destroy();
66#endif
67
68  delete[] m_piYuvExt;
69
70  m_acYuvPred[0].destroy();
71  m_acYuvPred[1].destroy();
72
73  m_cYuvPredTemp.destroy();
74
75#if H_3D_ARP
76  m_acYuvPredBase[0].destroy();
77  m_acYuvPredBase[1].destroy();
78#endif
79  if( m_pLumaRecBuffer )
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  }
93}
94
95Void TComPrediction::initTempBuff()
96{
97  if( m_piYuvExt == NULL )
98  {
99    Int extWidth  = MAX_CU_SIZE + 16; 
100    Int extHeight = MAX_CU_SIZE + 1;
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    }
110    m_iYuvExtHeight  = ((MAX_CU_SIZE + 2) << 4);
111    m_iYuvExtStride = ((MAX_CU_SIZE  + 8) << 4);
112    m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
113
114    // new structure
115    m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE );
116    m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE );
117
118    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE );
119#if H_3D_ARP
120    m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
121    m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
122#endif
123#if H_3D_VSP
124    m_cYuvDepthOnVsp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
125#endif
126  }
127
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;
138  for( Int i = 1; i < 64; i++ )
139  {
140    m_uiaShift[i] = ( (1 << 15) + i/2 ) / i;
141  }
142#endif
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{
152  assert(iWidth > 0 && iHeight > 0);
153  Int iInd, iSum = 0;
154  Pel pDcVal;
155
156  if (bAbove)
157  {
158    for (iInd = 0;iInd < iWidth;iInd++)
159    {
160      iSum += pSrc[iInd-iSrcStride];
161    }
162  }
163  if (bLeft)
164  {
165    for (iInd = 0;iInd < iHeight;iInd++)
166    {
167      iSum += pSrc[iInd*iSrcStride-1];
168    }
169  }
170
171  if (bAbove && bLeft)
172  {
173    pDcVal = (iSum + iWidth) / (iWidth + iHeight);
174  }
175  else if (bAbove)
176  {
177    pDcVal = (iSum + iWidth/2) / iWidth;
178  }
179  else if (bLeft)
180  {
181    pDcVal = (iSum + iHeight/2) / iHeight;
182  }
183  else
184  {
185    pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available
186  }
187 
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 */
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 )
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
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;
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;
289      refSide = modeVer ? refLeft  : refAbove;
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      }
301
302      if ( bFilter )
303      {
304        for (k=0;k<blkSize;k++)
305        {
306          pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) );
307        }
308      }
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
360Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
361{
362  Pel *pDst = piPred;
363  Int *ptrSrc;
364
365  assert( g_aucConvertToBit[ iWidth ] >= 0 ); //   4x  4
366  assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128
367  assert( iWidth == iHeight  );
368
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  {
381    if ( (iWidth > 16) || (iHeight > 16) )
382    {
383      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
384    }
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    }
394  }
395}
396
397// Angular chroma
398Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
399{
400  Pel *pDst = piPred;
401  Int *ptrSrc = piSrc;
402
403  // get starting pixel in block
404  Int sw = 2 * iWidth + 1;
405
406  if ( uiDirMode == PLANAR_IDX )
407  {
408    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
409  }
410  else
411  {
412    // Create the prediction
413    xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
414  }
415}
416
417#if H_3D_DIM
418Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc )
419{
420  assert( iWidth == iHeight  );
421  assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE );
422  assert( isDimMode( uiIntraMode ) );
423
424  UInt dimType    = getDimType  ( uiIntraMode );
425  Bool dimDeltaDC = isDimDeltaDC( uiIntraMode );   
426  Bool isDmmMode  = (dimType <  DMM_NUM_TYPE);
427
428  Bool* biSegPattern  = NULL;
429  UInt  patternStride = 0;
430
431  // get partiton
432#if H_3D_DIM_DMM
433  TComWedgelet* dmmSegmentation = NULL;
434  if( isDmmMode )
435  {
436    switch( dimType )
437    {
438    case( DMM1_IDX ): 
439      {
440        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]);
441      } break;
442    case( DMM4_IDX ): 
443      {
444        dmmSegmentation = new TComWedgelet( iWidth, iHeight );
445        xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
446      } break;
447    default: assert(0);
448    }
449    assert( dmmSegmentation );
450    biSegPattern  = dmmSegmentation->getPattern();
451    patternStride = dmmSegmentation->getStride ();
452  }
453#endif
454
455  // get predicted partition values
456  assert( biSegPattern );
457  Int* piMask = NULL;
458  piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering
459  assert( piMask );
460  Int maskStride = 2*iWidth + 1; 
461  Int* ptrSrc = piMask+maskStride+1;
462  Pel predDC1 = 0; Pel predDC2 = 0;
463  xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 );
464
465  // set segment values with deltaDC offsets
466  Pel segDC1 = 0;
467  Pel segDC2 = 0;
468  if( dimDeltaDC )
469  {
470    Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx );
471    Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx );
472#if H_3D_DIM_DMM
473    if( isDmmMode )
474    {
475#if H_3D_DIM_DLT
476      segDC1 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 );
477      segDC2 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 );
478#else
479      segDC1 = ClipY( predDC1 + deltaDC1 );
480      segDC2 = ClipY( predDC2 + deltaDC2 );
481#endif
482    }
483#endif
484  }
485  else
486  {
487    segDC1 = predDC1;
488    segDC2 = predDC2;
489  }
490
491  // set prediction signal
492  Pel* pDst = piPred;
493  xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 );
494
495#if H_3D_DIM_DMM
496  if( dimType == DMM4_IDX ) { dmmSegmentation->destroy(); delete dmmSegmentation; }
497#endif
498}
499#endif
500
501/** Function for checking identical motion.
502 * \param TComDataCU* pcCU
503 * \param UInt PartAddr
504 */
505Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr )
506{
507  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() )
508  {
509    if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0)
510    {
511      Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
512      Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
513      if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
514      {
515        return true;
516      }
517    }
518  }
519  return false;
520}
521
522#if H_3D_SPIVMP
523Void TComPrediction::xGetSubPUAddrAndMerge(TComDataCU* pcCU, UInt uiPartAddr, Int iSPWidth, Int iSPHeight, Int iNumSPInOneLine, Int iNumSP, UInt* uiMergedSPW, UInt* uiMergedSPH, UInt* uiSPAddr )
524{
525  for (Int i = 0; i < iNumSP; i++)
526  {
527    uiMergedSPW[i] = iSPWidth;
528    uiMergedSPH[i] = iSPHeight;
529    pcCU->getSPAbsPartIdx(uiPartAddr, iSPWidth, iSPHeight, i, iNumSPInOneLine, uiSPAddr[i]);
530  }
531  // horizontal sub-PU merge
532  for (Int i=0; i<iNumSP; i++)
533  {
534    if (i % iNumSPInOneLine == iNumSPInOneLine - 1 || uiMergedSPW[i]==0 || uiMergedSPH[i]==0)
535    {
536      continue;
537    }
538    for (Int j=i+1; j<i+iNumSPInOneLine-i%iNumSPInOneLine; j++)
539    {
540      if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j]))
541      {
542        uiMergedSPW[i] += iSPWidth;
543        uiMergedSPW[j] = uiMergedSPH[j] = 0;
544      }
545      else
546      {
547        break;
548      }
549    }
550  }
551  //vertical sub-PU merge
552  for (Int i=0; i<iNumSP-iNumSPInOneLine; i++)
553  {
554    if (uiMergedSPW[i]==0 || uiMergedSPH[i]==0)
555    {
556      continue;
557    }
558    for (Int j=i+iNumSPInOneLine; j<iNumSP; j+=iNumSPInOneLine)
559    {
560      if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j]) && uiMergedSPW[i]==uiMergedSPW[j])
561      {
562        uiMergedSPH[i] += iSPHeight;
563        uiMergedSPH[j] = uiMergedSPW[j] = 0;
564      }
565      else
566      {
567        break;
568      }
569    }
570  }
571}
572
573Bool TComPrediction::xCheckTwoSPMotion ( TComDataCU* pcCU, UInt PartAddr0, UInt PartAddr1 )
574{
575  if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr1))
576  {
577    return false;
578  }
579  if( pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr1))
580  {
581    return false;
582  }
583
584  if (pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) >= 0)
585  {
586    if (pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr1))
587    {
588      return false;
589    }
590  }
591
592  if (pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) >= 0)
593  {
594    if (pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr1))
595    {
596      return false;
597    }
598  }
599  return true;
600}
601#endif
602
603#if H_3D_DBBP
604PartSize TComPrediction::getPartitionSizeFromDepth(Pel* pDepthPels, UInt uiDepthStride, UInt uiSize)
605{
606  // find virtual partitioning for this CU based on depth block
607  // segmentation of texture block --> mask IDs
608  Pel*  pDepthBlockStart      = pDepthPels;
609 
610  // first compute average of depth block for thresholding
611  Int iSumDepth = 0;
612  Int iSubSample = 4;
613  for (Int y=0; y<uiSize; y+=iSubSample)
614  {
615    for (Int x=0; x<uiSize; x+=iSubSample)
616    {
617      Int depthPel = pDepthPels[x];
618     
619      iSumDepth += depthPel;
620    }
621   
622    // next row
623    pDepthPels += uiDepthStride*iSubSample;
624  }
625 
626  Int iSizeInBits = g_aucConvertToBit[uiSize] - g_aucConvertToBit[iSubSample];  // respect sub-sampling factor
627  Int iMean = iSumDepth >> iSizeInBits*2;       // iMean /= (uiSize*uiSize);
628 
629  // start again for segmentation
630  pDepthPels = pDepthBlockStart;
631 
632  // start mapping process
633  Bool bAMPAvail = uiSize > 8;
634  Int matchedPartSum[6][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}; // counter for each part size and boolean option
635  PartSize virtualPartSizes[6] = { SIZE_Nx2N, SIZE_2NxN, SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N };
636 
637  UInt uiHalfSize = uiSize>>1;
638  UInt uiQuarterSize = uiSize>>2;
639 
640  for (Int y=0; y<uiSize; y+=iSubSample)
641  {
642    for (Int x=0; x<uiSize; x+=iSubSample)
643    {
644      Int depthPel = pDepthPels[x];
645     
646      // decide which segment this pixel belongs to
647      Int ucSegment = (Int)(depthPel>iMean);
648     
649      // Matched Filter to find optimal (conventional) partitioning
650     
651      // SIZE_Nx2N
652      if(x<uiHalfSize)  // left
653      {
654        matchedPartSum[0][ucSegment]++;
655      }
656      else  // right
657      {
658        matchedPartSum[0][1-ucSegment]++;
659      }
660     
661      // SIZE_2NxN
662      if(y<uiHalfSize)  // top
663      {
664        matchedPartSum[1][ucSegment]++;
665      }
666      else  // bottom
667      {
668        matchedPartSum[1][1-ucSegment]++;
669      }
670     
671      if( bAMPAvail )
672      {
673        // SIZE_2NxnU
674        if(y<uiQuarterSize)  // top (1/4)
675        {
676          matchedPartSum[2][ucSegment]++;
677        }
678        else  // bottom (3/4)
679        {
680          matchedPartSum[2][1-ucSegment]++;
681        }
682       
683        // SIZE_2NxnD
684        if(y<(uiQuarterSize*3))  // top (3/4)
685        {
686          matchedPartSum[3][ucSegment]++;
687        }
688        else  // bottom (1/4)
689        {
690          matchedPartSum[3][1-ucSegment]++;
691        }
692       
693        // SIZE_nLx2N
694        if(x<uiQuarterSize)  // left (1/4)
695        {
696          matchedPartSum[4][ucSegment]++;
697        }
698        else  // right (3/4)
699        {
700          matchedPartSum[4][1-ucSegment]++;
701        }
702       
703        // SIZE_nRx2N
704        if(x<(uiQuarterSize*3))  // left (3/4)
705        {
706          matchedPartSum[5][ucSegment]++;
707        }
708        else  // right (1/4)
709        {
710          matchedPartSum[5][1-ucSegment]++;
711        }
712      }
713    }
714   
715    // next row
716    pDepthPels += uiDepthStride*iSubSample;
717  }
718 
719  PartSize matchedPartSize = SIZE_NONE;
720 
721  Int iMaxMatchSum = 0;
722  for(Int p=0; p<6; p++)  // loop over partition sizes
723  {
724    for( Int b=0; b<=1; b++ ) // loop over boolean options
725    {
726      if(matchedPartSum[p][b] > iMaxMatchSum)
727      {
728        iMaxMatchSum = matchedPartSum[p][b];
729        matchedPartSize = virtualPartSizes[p];
730      }
731    }
732  }
733 
734  AOF( matchedPartSize != SIZE_NONE );
735 
736  return matchedPartSize;
737}
738
739Bool TComPrediction::getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask )
740{
741  // segmentation of texture block --> mask IDs
742  Pel*  pDepthBlockStart      = pDepthPels;
743 
744  // first compute average of depth block for thresholding
745  Int iSumDepth = 0;
746  Int uiMinDepth = MAX_INT;
747  Int uiMaxDepth = 0;
748  for (Int y=0; y<uiHeight; y++)
749  {
750    for (Int x=0; x<uiWidth; x++)
751    {
752      Int depthPel = pDepthPels[x];
753      iSumDepth += depthPel;
754     
755      if( depthPel > uiMaxDepth )
756      {
757        uiMaxDepth = depthPel;
758      }
759      if( depthPel < uiMinDepth )
760      {
761        uiMinDepth = depthPel;
762      }
763    }
764   
765    // next row
766    pDepthPels += uiDepthStride;
767  }
768 
769  // don't generate mask for blocks with small depth range (encoder decision)
770  if( uiMaxDepth - uiMinDepth < 10 )
771  {
772    return false;
773  }
774 
775  AOF(uiWidth==uiHeight);
776  Int iSizeInBits = g_aucConvertToBit[uiWidth]+2;
777  Int iMean = iSumDepth >> iSizeInBits*2;       // iMean /= (uiWidth*uiHeight);
778 
779  // start again for segmentation
780  pDepthPels = pDepthBlockStart;
781 
782  Bool bInvertMask = pDepthPels[0]>iMean; // top-left segment needs to be mapped to partIdx 0
783 
784  // generate mask
785  UInt uiSumPix[2] = {0,0};
786  for (Int y=0; y<uiHeight; y++)
787  {
788    for (Int x=0; x<uiHeight; x++)
789    {
790      Int depthPel = pDepthPels[x];
791     
792      // decide which segment this pixel belongs to
793      Int ucSegment = (Int)(depthPel>iMean);
794     
795      if( bInvertMask )
796      {
797        ucSegment = 1-ucSegment;
798      }
799     
800      // count pixels for each segment
801      uiSumPix[ucSegment]++;
802     
803      // set mask value
804      pMask[x] = (Bool)ucSegment;
805    }
806   
807    // next row
808    pDepthPels += uiDepthStride;
809    pMask += MAX_CU_SIZE;
810  }
811 
812  // don't generate valid mask for tiny segments (encoder decision)
813  // each segment needs to cover at least 1/8th of block
814  UInt uiMinPixPerSegment = (uiWidth*uiHeight) >> 3;
815  if( !( uiSumPix[0] > uiMinPixPerSegment && uiSumPix[1] > uiMinPixPerSegment ) )
816  {
817    return false;
818  }
819 
820  // all good
821  return true;
822}
823
824Void TComPrediction::combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr )
825{
826  Pel*  piSrc[2]    = {pInYuv[0]->getLumaAddr(uiPartAddr), pInYuv[1]->getLumaAddr(uiPartAddr)};
827  UInt  uiSrcStride = pInYuv[0]->getStride();
828  Pel*  piDst       = pOutYuv->getLumaAddr(uiPartAddr);
829  UInt  uiDstStride = pOutYuv->getStride();
830 
831  UInt  uiMaskStride= MAX_CU_SIZE;
832 
833  // backup pointer
834  Bool* pMaskStart = pMask;
835 
836  // combine luma first
837  for (Int y=0; y<uiHeight; y++)
838  {
839    for (Int x=0; x<uiWidth; x++)
840    {
841      UChar ucSegment = (UChar)pMask[x];
842      AOF( ucSegment < 2 );
843     
844      // filtering
845      Bool t = (y==0)?pMaskStart[(y+1)*uiMaskStride+x]:pMaskStart[(y-1)*uiMaskStride+x];
846      Bool l = (x==0)?pMaskStart[y*uiMaskStride+x+1]:pMaskStart[y*uiMaskStride+x-1];
847      Bool b = (y==uiHeight-1)?pMaskStart[(y-1)*uiMaskStride+x]:pMaskStart[(y+1)*uiMaskStride+x];
848      Bool r = (x==uiWidth-1)?pMaskStart[y*uiMaskStride+x-1]:pMaskStart[y*uiMaskStride+x+1];
849     
850      Bool bBlend = !((t&&l&&b&&r) || (!t&&!l&&!b&&!r));
851      piDst[x] = bBlend?((piSrc[0][x]+piSrc[1][x]+1)>>1):piSrc[ucSegment][x];
852    }
853   
854    piSrc[0]  += uiSrcStride;
855    piSrc[1]  += uiSrcStride;
856    piDst     += uiDstStride;
857    pMask     += uiMaskStride;
858  }
859 
860  // now combine chroma
861  Pel*  piSrcU[2]       = { pInYuv[0]->getCbAddr(uiPartAddr), pInYuv[1]->getCbAddr(uiPartAddr) };
862  Pel*  piSrcV[2]       = { pInYuv[0]->getCrAddr(uiPartAddr), pInYuv[1]->getCrAddr(uiPartAddr) };
863  UInt  uiSrcStrideC    = pInYuv[0]->getCStride();
864  Pel*  piDstU          = pOutYuv->getCbAddr(uiPartAddr);
865  Pel*  piDstV          = pOutYuv->getCrAddr(uiPartAddr);
866  UInt  uiDstStrideC    = pOutYuv->getCStride();
867  UInt  uiWidthC        = uiWidth >> 1;
868  UInt  uiHeightC       = uiHeight >> 1;
869  pMask = pMaskStart;
870 
871  for (Int y=0; y<uiHeightC; y++)
872  {
873    for (Int x=0; x<uiWidthC; x++)
874    {
875      UChar ucSegment = (UChar)pMask[x*2];
876      AOF( ucSegment < 2 );
877     
878      // filtering
879      Bool t = (y==0)?pMaskStart[(y+1)*2*uiMaskStride+x*2]:pMaskStart[(y-1)*2*uiMaskStride+x*2];
880      Bool l = (x==0)?pMaskStart[y*2*uiMaskStride+(x+1)*2]:pMaskStart[y*2*uiMaskStride+(x-1)*2];
881      Bool b = (y==uiHeightC-1)?pMaskStart[(y-1)*2*uiMaskStride+x*2]:pMaskStart[(y+1)*2*uiMaskStride+x*2];
882      Bool r = (x==uiWidthC-1)?pMaskStart[y*2*uiMaskStride+(x-1)*2]:pMaskStart[y*2*uiMaskStride+(x+1)*2];
883     
884      Bool bBlend = !((t&&l&&b&&r) || (!t&&!l&&!b&&!r));
885     
886      piDstU[x] = bBlend?((piSrcU[0][x]+piSrcU[1][x]+1)>>1):piSrcU[ucSegment][x];
887      piDstV[x] = bBlend?((piSrcV[0][x]+piSrcV[1][x]+1)>>1):piSrcV[ucSegment][x];
888    }
889   
890    piSrcU[0]   += uiSrcStrideC;
891    piSrcU[1]   += uiSrcStrideC;
892    piSrcV[0]   += uiSrcStrideC;
893    piSrcV[1]   += uiSrcStrideC;
894    piDstU      += uiDstStrideC;
895    piDstV      += uiDstStrideC;
896    pMask       += 2*uiMaskStride;
897  }
898}
899#endif
900
901Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
902{
903  Int         iWidth;
904  Int         iHeight;
905  UInt        uiPartAddr;
906
907  if ( iPartIdx >= 0 )
908  {
909    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
910#if H_3D_VSP
911    if ( pcCU->getVSPFlag(uiPartAddr) == 0)
912    {
913#endif
914      if ( eRefPicList != REF_PIC_LIST_X )
915      {
916        if( pcCU->getSlice()->getPPS()->getUseWP())
917        {
918          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
919        }
920        else
921        {
922          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
923        }
924        if ( pcCU->getSlice()->getPPS()->getUseWP() )
925        {
926          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
927        }
928      }
929      else
930      {
931#if H_3D_SPIVMP
932        if ( pcCU->getSPIVMPFlag(uiPartAddr)!=0) 
933        {
934          Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
935
936          pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
937
938          UInt uiW[256], uiH[256];
939          UInt uiSPAddr[256];
940
941          xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr);
942
943          //MC
944          for (Int i = 0; i < iNumSP; i++)
945          {
946            if (uiW[i]==0 || uiH[i]==0)
947            {
948              continue;
949            }
950            if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] ))
951            {
952              xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred );
953            }
954            else
955            {
956              xPredInterBi  (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred);
957            }
958          }
959        }
960        else
961        {
962#endif
963          if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
964          {
965            xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
966          }
967          else
968          {
969            xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
970          }
971#if H_3D_SPIVMP
972        }
973#endif
974      }
975#if H_3D_VSP
976    }
977    else
978    {
979      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
980      {
981        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
982      }
983      else
984      {
985        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
986      }
987    }
988#endif
989    return;
990  }
991
992  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
993  {
994    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
995
996#if H_3D_VSP
997    if ( pcCU->getVSPFlag(uiPartAddr) == 0 )
998    {
999#endif
1000      if ( eRefPicList != REF_PIC_LIST_X )
1001      {
1002        if( pcCU->getSlice()->getPPS()->getUseWP())
1003        {
1004          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
1005        }
1006        else
1007        {
1008          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
1009        }
1010        if ( pcCU->getSlice()->getPPS()->getUseWP() )
1011        {
1012          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
1013        }
1014      }
1015      else
1016      {
1017#if H_3D_SPIVMP
1018       if (pcCU->getSPIVMPFlag(uiPartAddr)!=0) 
1019      {
1020        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
1021
1022        pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
1023
1024        UInt uiW[256], uiH[256];
1025        UInt uiSPAddr[256];
1026
1027        xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr);
1028        //MC
1029        for (Int i = 0; i < iNumSP; i++)
1030        {
1031          if (uiW[i]==0 || uiH[i]==0)
1032          {
1033            continue;
1034          }
1035          if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] ))
1036          {
1037            xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred );
1038          }
1039          else
1040          {
1041            xPredInterBi  (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred);
1042          }
1043        }
1044      }
1045      else
1046      {
1047#endif
1048        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
1049        {
1050          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
1051        }
1052        else
1053        {
1054          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
1055        }
1056#if H_3D_SPIVMP
1057       }
1058#endif
1059      }
1060#if H_3D_VSP
1061    }
1062    else
1063    {
1064      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
1065      {
1066        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
1067      }
1068      else
1069      {
1070        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
1071      }
1072    }
1073#endif
1074  }
1075  return;
1076}
1077
1078Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
1079{
1080  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
1081  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
1082  pcCU->clipMv(cMv);
1083
1084#if MTK_DDD_G0063
1085  if( pcCU->getUseDDD( uiPartAddr ) )
1086  {
1087      assert( pcCU->getSPIVMPFlag( uiPartAddr ) == 0 );
1088      assert( pcCU->getSlice()->getViewIndex() != 0 );
1089
1090      Int dstStride = rpcYuvPred->getStride();
1091      Int dstStrideC = rpcYuvPred->getCStride();
1092      Pel *dst      = rpcYuvPred->getLumaAddr( uiPartAddr );
1093      Pel *dstU     = rpcYuvPred->getCbAddr( uiPartAddr );
1094      Pel *dstV     = rpcYuvPred->getCrAddr( uiPartAddr );
1095
1096      Int iWidthC  = iWidth >> 1;
1097      Int iHeightC = iHeight >> 1;
1098      Int DefaultC = 1 << ( g_bitDepthY - 1);
1099      for ( Int i = 0; i < iHeight; i++)
1100      {
1101          for ( Int j = 0; j < iWidth ; j++)
1102          {
1103              dst[j] = pcCU->getDDDepth( uiPartAddr );
1104          }
1105          dst += dstStride;
1106      }
1107      for ( Int i = 0; i < iHeightC; i++)
1108      {
1109          for ( Int j = 0; j < iWidthC; j++)
1110          {
1111              dstU[j] = dstV[j] = DefaultC;
1112          }
1113          dstU += dstStrideC;
1114          dstV += dstStrideC;
1115      }
1116
1117      //return;
1118  } else
1119#endif
1120#if H_3D_ARP
1121  if(pcCU->getARPW( uiPartAddr ) > 0  && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC())
1122  {
1123    xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , rpcYuvPred , bi );
1124  }
1125  else
1126  {
1127    if(  pcCU->getARPW( uiPartAddr ) > 0 
1128      && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N
1129      && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() 
1130      )
1131    {
1132      xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi );
1133    }
1134    else
1135    {
1136#endif
1137#if H_3D_IC
1138      Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() );
1139      xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
1140#if H_3D_ARP
1141        , false
1142#endif
1143        , bICFlag );
1144      bICFlag = bICFlag && (iWidth > 8);
1145      xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
1146#if H_3D_ARP
1147        , false
1148#endif
1149        , bICFlag );
1150#else
1151      xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
1152      xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
1153#endif
1154#if H_3D_ARP
1155    }
1156  }
1157#endif
1158}
1159
1160#if H_3D_VSP
1161Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
1162{
1163#if NTT_STORE_SPDV_VSP_G0148
1164  Int vspSize = pcCU->getVSPFlag( uiPartAddr ) >> 1;
1165
1166  Int widthSubPU, heightSubPU;
1167  if (vspSize)
1168  {
1169    widthSubPU  = 8;
1170    heightSubPU = 4;
1171  }
1172  else
1173  {
1174    widthSubPU  = 4;
1175    heightSubPU = 8;
1176  }
1177  xPredInterUniSubPU( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi, widthSubPU, heightSubPU );
1178
1179#else // NTT_STORE_SPDV_VSP_G0148
1180  // Get depth reference
1181  Int       depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
1182#if H_3D_FCO_VSP_DONBDV_E0163
1183  TComPic* pRefPicBaseDepth = 0;
1184  Bool     bIsCurrDepthCoded = false;
1185  pRefPicBaseDepth  = pcCU->getSlice()->getIvPic( true, pcCU->getSlice()->getViewIndex() );
1186  if ( pRefPicBaseDepth->getPicYuvRec() != NULL  ) 
1187  {
1188    bIsCurrDepthCoded = true;
1189  }
1190  else 
1191  {
1192    pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
1193  }
1194#else
1195  TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
1196#endif
1197  assert(pRefPicBaseDepth != NULL);
1198  TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
1199  assert(pcBaseViewDepthPicYuv != NULL);
1200
1201  // Get texture reference
1202  Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
1203  assert(iRefIdx >= 0);
1204  TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx );
1205  TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
1206  assert(pcBaseViewTxtPicYuv != NULL);
1207
1208  // Initialize LUT according to the reference viewIdx
1209  Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex();
1210  Int* pShiftLUT    = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx );
1211  assert( txtRefViewIdx < pcCU->getSlice()->getViewIndex() );
1212
1213  // Do compensation
1214  TComMv cDv  = pcCU->getDvInfo(uiPartAddr).m_acNBDV;
1215  pcCU->clipMv(cDv);
1216
1217#if H_3D_FCO_VSP_DONBDV_E0163
1218  if ( bIsCurrDepthCoded )
1219  {
1220      cDv.setZero();
1221  }
1222#endif
1223  // fetch virtual depth map
1224  pcBaseViewDepthPicYuv->extendPicBorder();
1225
1226  Int vspSize=0;
1227  xGetVirtualDepth( pcCU, pcBaseViewDepthPicYuv, &cDv, uiPartAddr, iWidth, iHeight, &m_cYuvDepthOnVsp,vspSize );
1228  // sub-PU based compensation
1229  xPredInterLumaBlkFromDM   ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi, vspSize);
1230  xPredInterChromaBlkFromDM ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi, vspSize);
1231#endif // NTT_STORE_SPDV_VSP_G0148
1232}
1233
1234#if NTT_STORE_SPDV_VSP_G0148
1235Void TComPrediction::xPredInterUniSubPU( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, Int widthSubPU, Int heightSubPU )
1236{
1237  UInt numPartsInLine       = pcCU->getPic()->getNumPartInWidth();
1238  UInt horiNumPartsInSubPU  = widthSubPU >> 2;
1239  UInt vertNumPartsInSubPU  = (heightSubPU >> 2) * numPartsInLine;
1240
1241  UInt partAddrRasterLine = g_auiZscanToRaster[ uiPartAddr ];
1242
1243  for( Int posY=0; posY<iHeight; posY+=heightSubPU, partAddrRasterLine+=vertNumPartsInSubPU )
1244  {
1245    UInt partAddrRasterSubPU = partAddrRasterLine;
1246    for( Int posX=0; posX<iWidth; posX+=widthSubPU, partAddrRasterSubPU+=horiNumPartsInSubPU )
1247    {
1248      UInt    partAddrSubPU = g_auiRasterToZscan[ partAddrRasterSubPU ];
1249      Int     refIdx        = pcCU->getCUMvField( eRefPicList )->getRefIdx( partAddrSubPU );           assert (refIdx >= 0);
1250      TComMv  cMv           = pcCU->getCUMvField( eRefPicList )->getMv( partAddrSubPU );
1251      pcCU->clipMv(cMv);
1252
1253      xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi );
1254      xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi );
1255
1256    }
1257  }
1258}
1259#endif // NTT_STORE_SPDV_VSP_G0148
1260
1261#endif
1262
1263#if H_3D_ARP
1264Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
1265{
1266  Int         iRefIdx      = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
1267  TComMv      cMv          = pNewMvFiled ? pNewMvFiled->getMv()     : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
1268  Bool        bTobeScaled  = false;
1269  TComPic* pcPicYuvBaseCol = NULL;
1270  TComPic* pcPicYuvBaseRef = NULL;
1271
1272#if H_3D_NBDV
1273  DisInfo cDistparity;
1274  cDistparity.bDV           = pcCU->getDvInfo(uiPartAddr).bDV;
1275  if( cDistparity.bDV )
1276  {
1277    cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV;
1278    assert(pcCU->getDvInfo(uiPartAddr).bDV ==  pcCU->getDvInfo(0).bDV);
1279    cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
1280  }
1281#else
1282  assert(0); // ARP can be applied only when a DV is available
1283#endif
1284
1285  UChar dW = cDistparity.bDV ? pcCU->getARPW ( uiPartAddr ) : 0;
1286
1287  if( cDistparity.bDV ) 
1288  {
1289    Int arpRefIdx = pcCU->getSlice()->getFirstTRefIdx(eRefPicList);
1290    if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() )
1291    {
1292      bTobeScaled = true;
1293    }
1294
1295    pcPicYuvBaseCol =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(),                              cDistparity.m_aVIdxCan );
1296
1297    pcPicYuvBaseRef =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC(), cDistparity.m_aVIdxCan );
1298
1299    if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, cDistparity.m_aVIdxCan))
1300    {
1301      dW = 0;
1302      bTobeScaled = false;
1303    }
1304    else
1305    {
1306      assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC() );
1307    }
1308
1309    if(bTobeScaled)
1310    {     
1311      Int iCurrPOC    = pcCU->getSlice()->getPOC();
1312      Int iColRefPOC  = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx );
1313      Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList,  0);
1314      Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC);
1315      if ( iScale != 4096 )
1316      {
1317        cMv = cMv.scaleMv( iScale );
1318      }
1319      iRefIdx = 0;
1320    }
1321  }
1322
1323  pcCU->clipMv(cMv);
1324  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec();
1325  xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
1326  xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
1327
1328  if( dW > 0 )
1329  {
1330    TComYuv * pYuvB0 = &m_acYuvPredBase[0];
1331    TComYuv * pYuvB1  = &m_acYuvPredBase[1];
1332
1333    TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV;
1334    pcCU->clipMv(cMVwithDisparity);
1335
1336    assert ( cDistparity.bDV );
1337
1338    pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec();
1339    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
1340    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
1341   
1342    pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec();
1343    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
1344    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
1345
1346    pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight );
1347
1348    if( 2 == dW )
1349    {
1350      pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
1351    }
1352    rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi );
1353  }
1354}
1355Void TComPrediction::xPredInterUniARPviewRef( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
1356{
1357  Int         iRefIdx       = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
1358  TComMv      cDMv          = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
1359  TComMv      cTempDMv      = cDMv;
1360  UChar       dW            = pcCU->getARPW ( uiPartAddr );
1361
1362  TComPic* pcPicYuvBaseTRef = NULL;
1363  TComPic* pcPicYuvCurrTRef = NULL;
1364  TComPic* pcPicYuvBaseCol  = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx ); 
1365  TComPicYuv* pcYuvBaseCol  = pcPicYuvBaseCol->getPicYuvRec();   
1366  Bool bTMVAvai = false;     
1367  TComMv cBaseTMV;
1368  if( pNewMvFiled )
1369  {
1370    iRefIdx = pNewMvFiled->getRefIdx(); 
1371    cDMv = pNewMvFiled->getMv();
1372  }
1373  pcCU->clipMv(cTempDMv);
1374
1375  assert(dW > 0);
1376  if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, pcPicYuvBaseCol->getViewIndex()))
1377  {
1378    dW = 0;
1379  }
1380  Int uiLCUAddr,uiAbsPartAddr;
1381  Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2  + ((cDMv.getHor() + 2)>>2);
1382  Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2);
1383
1384  irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX);
1385  irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); 
1386  pcYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr);
1387  TComDataCU *pColCU = pcPicYuvBaseCol->getCU( uiLCUAddr );
1388
1389  if(!pColCU->isIntra(uiAbsPartAddr))
1390  {
1391    TComMvField puMVField;
1392    for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1) && !bTMVAvai; iList ++)
1393    {
1394      RefPicList eRefPicListCurr = RefPicList(iList);
1395      Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr);
1396      if( iRef != -1)
1397      {
1398        pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); 
1399        Int  iCurrPOC    = pColCU->getSlice()->getPOC();
1400        Int  iCurrRefPOC = pcPicYuvBaseTRef->getPOC();
1401        Int  iCurrRef    = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr);
1402        if( iCurrRef >= 0)
1403        {
1404          pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); 
1405          Int iTargetPOC = pcPicYuvCurrTRef->getPOC();
1406          {
1407            pcPicYuvBaseTRef =  pcCU->getSlice()->getBaseViewRefPic(iTargetPOC,  pcPicYuvBaseCol->getViewIndex() ); 
1408            if(pcPicYuvBaseTRef)
1409            {
1410              cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr);
1411              Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC);
1412              if ( iScale != 4096 )
1413                cBaseTMV = cBaseTMV.scaleMv( iScale );                 
1414              bTMVAvai = true;
1415              break;
1416            }
1417          }
1418        }
1419      }
1420    }
1421  }
1422  if (bTMVAvai == false)
1423  { 
1424    bTMVAvai = true;
1425    cBaseTMV.set(0, 0);
1426    pcPicYuvBaseTRef =  pColCU->getSlice()->getRefPic(eRefPicList,  pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); 
1427    pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic  (eRefPicList,  pcCU->getSlice()->getFirstTRefIdx(eRefPicList));     
1428  }
1429
1430  xPredInterLumaBlk  ( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi,        bTMVAvai);
1431  xPredInterChromaBlk( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi,        bTMVAvai);
1432
1433  if( dW > 0 && bTMVAvai ) 
1434  {
1435    TComYuv*    pYuvCurrTRef    = &m_acYuvPredBase[0];
1436    TComYuv*    pYuvBaseTRef    = &m_acYuvPredBase[1];
1437    TComPicYuv* pcYuvCurrTref   = pcPicYuvCurrTRef->getPicYuvRec();       
1438    TComPicYuv* pcYuvBaseTref   = pcPicYuvBaseTRef->getPicYuvRec(); 
1439    TComMv      cTempMv         = cDMv + cBaseTMV;
1440
1441    pcCU->clipMv(cBaseTMV);
1442    pcCU->clipMv(cTempMv);
1443
1444    xPredInterLumaBlk  ( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, bi,   true);
1445    xPredInterChromaBlk( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, bi,   true);
1446    xPredInterLumaBlk  ( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, bi,   true); 
1447    xPredInterChromaBlk( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, bi,   true); 
1448
1449    pYuvCurrTRef->subtractARP( pYuvCurrTRef , pYuvBaseTRef , uiPartAddr , iWidth , iHeight ); 
1450    if(dW == 2)
1451    {
1452      pYuvCurrTRef->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
1453    }
1454    rpcYuvPred->addARP( rpcYuvPred , pYuvCurrTRef , uiPartAddr , iWidth , iHeight , !bi ); 
1455  }
1456}
1457
1458#endif
1459
1460Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
1461{
1462  TComYuv* pcMbYuv;
1463  Int      iRefIdx[2] = {-1, -1};
1464
1465  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
1466  {
1467    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
1468    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
1469
1470    if ( iRefIdx[iRefList] < 0 )
1471    {
1472      continue;
1473    }
1474
1475    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
1476
1477    pcMbYuv = &m_acYuvPred[iRefList];
1478    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
1479    {
1480      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
1481    }
1482    else
1483    {
1484      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) || 
1485           ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
1486      {
1487        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
1488      }
1489      else
1490      {
1491        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
1492      }
1493    }
1494  }
1495
1496  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE  )
1497  {
1498    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1499  } 
1500  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
1501  {
1502    xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); 
1503  }
1504  else
1505  {
1506    xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1507  }
1508}
1509
1510#if H_3D_VSP
1511
1512Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
1513{
1514  TComYuv* pcMbYuv;
1515  Int      iRefIdx[2] = {-1, -1};
1516  Bool     bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0);
1517
1518  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
1519  {
1520    RefPicList eRefPicList = RefPicList(iRefList);
1521    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
1522
1523    if ( iRefIdx[iRefList] < 0 )
1524    {
1525      continue;
1526    }
1527    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
1528
1529    pcMbYuv = &m_acYuvPred[iRefList];
1530    xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi );
1531  }
1532
1533  xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1534}
1535
1536#endif
1537
1538/**
1539 * \brief Generate motion-compensated luma block
1540 *
1541 * \param cu       Pointer to current CU
1542 * \param refPic   Pointer to reference picture
1543 * \param partAddr Address of block within CU
1544 * \param mv       Motion vector
1545 * \param width    Width of block
1546 * \param height   Height of block
1547 * \param dstPic   Pointer to destination picture
1548 * \param bi       Flag indicating whether bipred is used
1549 */
1550Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
1551#if H_3D_ARP
1552    , Bool filterType
1553#endif
1554#if H_3D_IC
1555    , Bool bICFlag
1556#endif
1557  )
1558{
1559  Int refStride = refPic->getStride(); 
1560  Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride;
1561  Pel *ref      = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1562 
1563  Int dstStride = dstPic->getStride();
1564  Pel *dst      = dstPic->getLumaAddr( partAddr );
1565 
1566  Int xFrac = mv->getHor() & 0x3;
1567  Int yFrac = mv->getVer() & 0x3;
1568
1569#if H_3D_IC
1570  if( cu->getSlice()->getIsDepth() )
1571  {
1572    refOffset = mv->getHor() + mv->getVer() * refStride;
1573    ref       = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1574    xFrac     = 0;
1575    yFrac     = 0;
1576  }
1577#endif
1578  if ( yFrac == 0 )
1579  {
1580#if H_3D_IC
1581    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi || bICFlag
1582#else
1583    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi
1584#endif
1585#if H_3D_ARP
1586    , filterType
1587#endif
1588      );
1589  }
1590  else if ( xFrac == 0 )
1591  {
1592#if H_3D_IC
1593    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag
1594#else
1595    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi
1596#endif
1597#if H_3D_ARP
1598    , filterType
1599#endif
1600      );
1601  }
1602  else
1603  {
1604    Int tmpStride = m_filteredBlockTmp[0].getStride();
1605    Short *tmp    = m_filteredBlockTmp[0].getLumaAddr();
1606
1607    Int filterSize = NTAPS_LUMA;
1608    Int halfFilterSize = ( filterSize >> 1 );
1609
1610    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     
1611#if H_3D_ARP
1612    , filterType
1613#endif
1614      );
1615#if H_3D_IC
1616    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi || bICFlag
1617#else
1618    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi
1619#endif
1620#if H_3D_ARP
1621    , filterType
1622#endif
1623      );   
1624  }
1625
1626#if H_3D_IC
1627  if( bICFlag )
1628  {
1629    Int a, b, i, j;
1630    const Int iShift = IC_CONST_SHIFT;
1631
1632    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA );
1633
1634
1635    for ( i = 0; i < height; i++ )
1636    {
1637      for ( j = 0; j < width; j++ )
1638      {
1639          dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
1640      }
1641      dst += dstStride;
1642    }
1643
1644    if(bi)
1645    {
1646      Pel *dst2      = dstPic->getLumaAddr( partAddr );
1647      Int shift = IF_INTERNAL_PREC - g_bitDepthY;
1648      for (i = 0; i < height; i++)
1649      {
1650        for (j = 0; j < width; j++)
1651        {
1652          Short val = dst2[j] << shift;
1653          dst2[j] = val - (Short)IF_INTERNAL_OFFS;
1654        }
1655        dst2 += dstStride;
1656      }
1657    }
1658  }
1659#endif
1660}
1661
1662/**
1663 * \brief Generate motion-compensated chroma block
1664 *
1665 * \param cu       Pointer to current CU
1666 * \param refPic   Pointer to reference picture
1667 * \param partAddr Address of block within CU
1668 * \param mv       Motion vector
1669 * \param width    Width of block
1670 * \param height   Height of block
1671 * \param dstPic   Pointer to destination picture
1672 * \param bi       Flag indicating whether bipred is used
1673 */
1674Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
1675#if H_3D_ARP
1676    , Bool filterType
1677#endif
1678#if H_3D_IC
1679    , Bool bICFlag
1680#endif
1681  )
1682{
1683  Int     refStride  = refPic->getCStride();
1684  Int     dstStride  = dstPic->getCStride();
1685 
1686  Int     refOffset  = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride;
1687 
1688  Pel*    refCb     = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1689  Pel*    refCr     = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1690 
1691  Pel* dstCb = dstPic->getCbAddr( partAddr );
1692  Pel* dstCr = dstPic->getCrAddr( partAddr );
1693 
1694  Int     xFrac  = mv->getHor() & 0x7;
1695  Int     yFrac  = mv->getVer() & 0x7;
1696  UInt    cxWidth  = width  >> 1;
1697  UInt    cxHeight = height >> 1;
1698 
1699  Int     extStride = m_filteredBlockTmp[0].getStride();
1700  Short*  extY      = m_filteredBlockTmp[0].getLumaAddr();
1701 
1702  Int filterSize = NTAPS_CHROMA;
1703 
1704  Int halfFilterSize = (filterSize>>1);
1705 
1706  if ( yFrac == 0 )
1707  {
1708#if H_3D_IC
1709    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
1710#else
1711    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi
1712#endif
1713#if H_3D_ARP
1714    , filterType
1715#endif
1716    );   
1717#if H_3D_IC
1718    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
1719#else
1720    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi
1721#endif
1722#if H_3D_ARP
1723    , filterType
1724#endif
1725    );
1726  }
1727  else if ( xFrac == 0 )
1728  {
1729#if H_3D_IC
1730    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
1731#else
1732    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1733#endif
1734#if H_3D_ARP
1735    , filterType
1736#endif
1737    );
1738#if H_3D_IC
1739    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
1740#else
1741    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1742#endif
1743#if H_3D_ARP
1744    , filterType
1745#endif
1746    );
1747  }
1748  else
1749  {
1750    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1751#if H_3D_ARP
1752    , filterType
1753#endif 
1754      );
1755#if H_3D_IC
1756    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
1757#else
1758    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1759#endif
1760#if H_3D_ARP
1761    , filterType
1762#endif
1763      );
1764   
1765    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1766#if H_3D_ARP
1767    , filterType
1768#endif
1769      );
1770#if H_3D_IC
1771    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
1772#else
1773    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1774#endif
1775#if H_3D_ARP
1776    , filterType
1777#endif
1778      );   
1779  }
1780
1781#if H_3D_IC
1782  if( bICFlag )
1783  {
1784    Int a, b, i, j;
1785    const Int iShift = IC_CONST_SHIFT;
1786    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb
1787    for ( i = 0; i < cxHeight; i++ )
1788    {
1789      for ( j = 0; j < cxWidth; j++ )
1790      {
1791          dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
1792      }
1793      dstCb += dstStride;
1794    }
1795    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr
1796    for ( i = 0; i < cxHeight; i++ )
1797    {
1798      for ( j = 0; j < cxWidth; j++ )
1799      {
1800          dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
1801      }
1802      dstCr += dstStride;
1803    }
1804
1805    if(bi)
1806    {
1807      Pel* dstCb2 = dstPic->getCbAddr( partAddr );
1808      Pel* dstCr2 = dstPic->getCrAddr( partAddr );
1809      Int shift = IF_INTERNAL_PREC - g_bitDepthC;
1810      for (i = 0; i < cxHeight; i++)
1811      {
1812        for (j = 0; j < cxWidth; j++)
1813        {
1814          Short val = dstCb2[j] << shift;
1815          dstCb2[j] = val - (Short)IF_INTERNAL_OFFS;
1816
1817          val = dstCr2[j] << shift;
1818          dstCr2[j] = val - (Short)IF_INTERNAL_OFFS;
1819        }
1820        dstCb2 += dstStride;
1821        dstCr2 += dstStride;
1822      }
1823    }
1824  }
1825#endif
1826}
1827
1828Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
1829{
1830  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
1831  {
1832    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
1833  }
1834  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
1835  {
1836    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
1837  }
1838  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
1839  {
1840    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
1841  }
1842}
1843
1844// AMVP
1845Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
1846{
1847  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
1848  if( pcAMVPInfo->iN <= 1 )
1849  {
1850    rcMvPred = pcAMVPInfo->m_acMvCand[0];
1851
1852    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1853    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1854    return;
1855  }
1856
1857  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
1858  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
1859  return;
1860}
1861
1862/** Function for deriving planar intra prediction.
1863 * \param pSrc pointer to reconstructed sample array
1864 * \param srcStride the stride of the reconstructed sample array
1865 * \param rpDst reference to pointer for the prediction sample array
1866 * \param dstStride the stride of the prediction sample array
1867 * \param width the width of the block
1868 * \param height the height of the block
1869 *
1870 * This function derives the prediction samples for planar mode (intra coding).
1871 */
1872Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
1873{
1874  assert(width == height);
1875
1876  Int k, l, bottomLeft, topRight;
1877  Int horPred;
1878  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
1879  UInt blkSize = width;
1880  UInt offset2D = width;
1881  UInt shift1D = g_aucConvertToBit[ width ] + 2;
1882  UInt shift2D = shift1D + 1;
1883
1884  // Get left and above reference column and row
1885  for(k=0;k<blkSize+1;k++)
1886  {
1887    topRow[k] = pSrc[k-srcStride];
1888    leftColumn[k] = pSrc[k*srcStride-1];
1889  }
1890
1891  // Prepare intermediate variables used in interpolation
1892  bottomLeft = leftColumn[blkSize];
1893  topRight   = topRow[blkSize];
1894  for (k=0;k<blkSize;k++)
1895  {
1896    bottomRow[k]   = bottomLeft - topRow[k];
1897    rightColumn[k] = topRight   - leftColumn[k];
1898    topRow[k]      <<= shift1D;
1899    leftColumn[k]  <<= shift1D;
1900  }
1901
1902  // Generate prediction signal
1903  for (k=0;k<blkSize;k++)
1904  {
1905    horPred = leftColumn[k] + offset2D;
1906    for (l=0;l<blkSize;l++)
1907    {
1908      horPred += rightColumn[k];
1909      topRow[l] += bottomRow[l];
1910      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
1911    }
1912  }
1913}
1914
1915/** Function for filtering intra DC predictor.
1916 * \param pSrc pointer to reconstructed sample array
1917 * \param iSrcStride the stride of the reconstructed sample array
1918 * \param rpDst reference to pointer for the prediction sample array
1919 * \param iDstStride the stride of the prediction sample array
1920 * \param iWidth the width of the block
1921 * \param iHeight the height of the block
1922 *
1923 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
1924 */
1925Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
1926{
1927  Pel* pDst = rpDst;
1928  Int x, y, iDstStride2, iSrcStride2;
1929
1930  // boundary pixels processing
1931  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
1932
1933  for ( x = 1; x < iWidth; x++ )
1934  {
1935    pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
1936  }
1937
1938  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
1939  {
1940    pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
1941  }
1942
1943  return;
1944}
1945#if H_3D_IC
1946/** Function for deriving the position of first non-zero binary bit of a value
1947 * \param x input value
1948 *
1949 * This function derives the position of first non-zero binary bit of a value
1950 */
1951Int GetMSB( UInt x )
1952{
1953  Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1;
1954
1955  while( x > 1 )
1956  {
1957    bits >>= 1;
1958    y = x >> bits;
1959
1960    if( y )
1961    {
1962      x = y;
1963      iMSB += bits;
1964    }
1965  }
1966
1967  iMSB+=y;
1968
1969  return iMSB;
1970}
1971
1972
1973/** Function for deriving LM illumination compensation.
1974 */
1975Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType )
1976{
1977  TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
1978  Pel *pRec = NULL, *pRef = NULL;
1979  UInt uiWidth, uiHeight, uiTmpPartIdx;
1980  Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride();
1981  Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride();
1982  Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer;
1983
1984  iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
1985  iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
1986  iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 );
1987  iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 );
1988  iRefX   = iCUPelX + iHor;
1989  iRefY   = iCUPelY + iVer;
1990  if( eType != TEXT_LUMA )
1991  {
1992    iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 );
1993    iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 );
1994  }
1995  uiWidth  = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 )  : ( pcCU->getWidth( 0 )  >> 1 );
1996  uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 );
1997
1998  Int i, j, iCountShift = 0;
1999
2000  // LLS parameters estimation -->
2001
2002  Int x = 0, y = 0, xx = 0, xy = 0;
2003  Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12);
2004
2005  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 )
2006  {
2007    iRefOffset = iHor + iVer * iRefStride - iRefStride;
2008    if( eType == TEXT_LUMA )
2009    {
2010      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2011      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
2012    }
2013    else if( eType == TEXT_CHROMA_U )
2014    {
2015      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2016      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
2017    }
2018    else
2019    {
2020      assert( eType == TEXT_CHROMA_V );
2021      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2022      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
2023    }
2024
2025    for( j = 0; j < uiWidth; j+=2 )
2026    {
2027      x += pRef[j];
2028      y += pRec[j];
2029      xx += (pRef[j] * pRef[j])>>precShift;
2030      xy += (pRef[j] * pRec[j])>>precShift;
2031    }
2032    iCountShift += g_aucConvertToBit[ uiWidth ] + 1;
2033  }
2034
2035
2036  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 )
2037  {
2038    iRefOffset = iHor + iVer * iRefStride - 1;
2039    if( eType == TEXT_LUMA )
2040    {
2041      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2042      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
2043    }
2044    else if( eType == TEXT_CHROMA_U )
2045    {
2046      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2047      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
2048    }
2049    else
2050    {
2051      assert( eType == TEXT_CHROMA_V );
2052      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2053      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
2054    }
2055
2056    for( i = 0; i < uiHeight; i+=2 )
2057    {
2058      x += pRef[0];
2059      y += pRec[0];
2060
2061      xx += (pRef[0] * pRef[0])>>precShift;
2062      xy += (pRef[0] * pRec[0])>>precShift;
2063
2064      pRef += iRefStride*2;
2065      pRec += iRecStride*2;
2066    }
2067    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 );
2068  }
2069
2070  xy += xx >> IC_REG_COST_SHIFT;
2071  xx += xx >> IC_REG_COST_SHIFT;
2072  Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift);
2073  Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift);
2074  const Int iShift = IC_CONST_SHIFT;
2075  {
2076    {
2077      const Int iShiftA2 = 6;
2078      const Int iAccuracyShift = 15;
2079
2080      Int iScaleShiftA2 = 0;
2081      Int iScaleShiftA1 = 0;
2082      Int a1s = a1;
2083      Int a2s = a2;
2084
2085      a1 = Clip3(0, 2*a2, a1);
2086      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2;
2087      iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF;
2088
2089      if( iScaleShiftA1 < 0 )
2090      {
2091        iScaleShiftA1 = 0;
2092      }
2093
2094      if( iScaleShiftA2 < 0 )
2095      {
2096        iScaleShiftA2 = 0;
2097      }
2098
2099      Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
2100
2101
2102      a2s = a2 >> iScaleShiftA2;
2103
2104      a1s = a1 >> iScaleShiftA1;
2105
2106      a = a1s * m_uiaShift[ a2s ];
2107      a = a >> iScaleShiftA;
2108      b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
2109    }
2110  }   
2111}
2112#endif
2113
2114#if H_3D_VSP
2115#if !(NTT_STORE_SPDV_VSP_G0148)
2116// not fully support iRatioTxtPerDepth* != 1
2117Void TComPrediction::xGetVirtualDepth( TComDataCU *cu, TComPicYuv *picRefDepth, TComMv *mv, UInt partAddr, Int width, Int height, TComYuv *yuvDepth, Int &vspSize, Int ratioTxtPerDepthX, Int ratioTxtPerDepthY )
2118{
2119  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
2120  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
2121
2122  Int refDepStride = picRefDepth->getStride();
2123
2124  Int refDepOffset  = ( (mv->getHor()+2) >> 2 ) + ( (mv->getVer()+2) >> 2 ) * refDepStride;
2125  Pel *refDepth     = picRefDepth->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
2126
2127  if( ratioTxtPerDepthX!=1 || ratioTxtPerDepthY!=1 )
2128  {
2129    Int posX, posY;
2130    refDepth    = picRefDepth->getLumaAddr( );
2131    cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
2132    posX /= ratioTxtPerDepthX; // texture position -> depth postion
2133    posY /= ratioTxtPerDepthY;
2134    refDepOffset += posX + posY * refDepStride;
2135
2136    width  /= ratioTxtPerDepthX; // texture size -> depth size
2137    height /= ratioTxtPerDepthY;
2138  }
2139
2140  refDepth += refDepOffset;
2141
2142  Int depStride = yuvDepth->getStride();
2143  Pel *depth = yuvDepth->getLumaAddr();
2144
2145  if ((height % 8))
2146  {
2147    vspSize = 1; // 8x4
2148  }
2149  else if ((width % 8))
2150  {
2151    vspSize = 0; // 4x8
2152  }
2153  else
2154  {
2155    Bool ULvsBR, URvsBL;
2156    ULvsBR = refDepth[0]       < refDepth[refDepStride * (height-1) + width-1];
2157    URvsBL = refDepth[width-1] < refDepth[refDepStride * (height-1)];
2158    vspSize = ( ULvsBR ^ URvsBL ) ? 0 : 1;
2159  }
2160  Int subBlockW, subBlockH;
2161  Int depStrideTmp = depStride * nTxtPerDepthY;
2162  if (vspSize)
2163  {
2164    subBlockW = 8;
2165    subBlockH = 4;
2166  }
2167  else
2168  {
2169    subBlockW = 4;
2170    subBlockH = 8;
2171  }
2172  for( Int y=0; y<height; y+=subBlockH )
2173  {
2174    Pel *refDepthTmp[4];
2175    refDepthTmp[0] = refDepth + refDepStride * y;
2176    refDepthTmp[1] = refDepthTmp[0] + subBlockW - 1;
2177    refDepthTmp[2] = refDepthTmp[0] + refDepStride * (subBlockH - 1);
2178    refDepthTmp[3] = refDepthTmp[2] + subBlockW - 1;
2179    for( Int x=0; x<width; x+=subBlockW )
2180    {
2181      Pel  maxDepthVal;
2182      maxDepthVal = refDepthTmp[0][x];
2183      maxDepthVal = std::max( maxDepthVal, refDepthTmp[1][x]);
2184      maxDepthVal = std::max( maxDepthVal, refDepthTmp[2][x]);
2185      maxDepthVal = std::max( maxDepthVal, refDepthTmp[3][x]);
2186      Pel *depthTmp = &depth[x+y*depStride];
2187      for( Int sY=0; sY<subBlockH; sY+=nTxtPerDepthY )
2188      {
2189        for( Int sX=0; sX<subBlockW; sX+=nTxtPerDepthX )
2190        {
2191          depthTmp[sX] = maxDepthVal;
2192        }
2193        depthTmp += depStrideTmp;
2194      }
2195    }
2196  }   
2197}
2198
2199Void 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)
2200{
2201  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
2202  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
2203 
2204  nTxtPerDepthX = nTxtPerDepthX << vspSize;
2205  nTxtPerDepthY = nTxtPerDepthY << (1-vspSize);
2206
2207  Int refStride = picRef->getStride();
2208  Int dstStride = yuvDst->getStride();
2209  Int depStride = yuvDepth->getStride();
2210  Int refStrideBlock = refStride  * nTxtPerDepthY;
2211  Int dstStrideBlock = dstStride * nTxtPerDepthY;
2212  Int depStrideBlock = depStride * nTxtPerDepthY;
2213
2214  Pel *ref    = picRef->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
2215  Pel *dst    = yuvDst->getLumaAddr(partAddr);
2216  Pel *depth  = yuvDepth->getLumaAddr();
2217
2218#if H_3D_VSP_BLOCKSIZE == 1
2219#if H_3D_VSP_CONSTRAINED
2220  //get LUT based horizontal reference range
2221  Int range = xGetConstrainedSize(width, height);
2222
2223  // The minimum depth value
2224  Int minRelativePos = MAX_INT;
2225  Int maxRelativePos = MIN_INT;
2226
2227  Pel* depthTemp, *depthInitial=depth;
2228  for (Int yTxt = 0; yTxt < height; yTxt++)
2229  {
2230    for (Int xTxt = 0; xTxt < width; xTxt++)
2231    {
2232      if (depthPosX+xTxt < widthDepth)
2233      {
2234        depthTemp = depthInitial + xTxt;
2235      }
2236      else
2237      {
2238        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
2239      }
2240
2241      Int disparity = shiftLUT[ *depthTemp ]; // << iShiftPrec;
2242      Int disparityInt = disparity >> 2;
2243
2244      if( disparity <= 0)
2245      {
2246        if (minRelativePos > disparityInt+xTxt)
2247        {
2248          minRelativePos = disparityInt+xTxt;
2249        }
2250      }
2251      else
2252      {
2253        if (maxRelativePos < disparityInt+xTxt)
2254        {
2255          maxRelativePos = disparityInt+xTxt;
2256        }
2257      }
2258    }
2259    if (depthPosY+yTxt < heightDepth)
2260    {
2261      depthInitial = depthInitial + depStride;
2262    }
2263  }
2264
2265  Int disparity_tmp = shiftLUT[ *depth ]; // << iShiftPrec;
2266  if (disparity_tmp <= 0)
2267  {
2268    maxRelativePos = minRelativePos + range -1 ;
2269  }
2270  else
2271  {
2272    minRelativePos = maxRelativePos - range +1 ;
2273  }
2274#endif
2275#endif // H_3D_VSP_BLOCKSIZE == 1
2276
2277  TComMv dv(0, 0);
2278
2279  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
2280  {
2281    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
2282    {
2283      Pel repDepth = depth[ xTxt ];
2284      assert( repDepth >= 0 && repDepth <= 255 );
2285
2286      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec ??
2287      Int xFrac = disparity & 0x3;
2288
2289      dv.setHor( disparity );
2290      cu->clipMv( dv );
2291
2292      Int refOffset = xTxt + (dv.getHor() >> 2);
2293     
2294#if H_3D_VSP_CONSTRAINED
2295      if(refOffset<minRelativePos || refOffset>maxRelativePos)
2296      {
2297        xFrac = 0;
2298      }
2299      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
2300#endif
2301
2302      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
2303      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
2304    }
2305    ref   += refStrideBlock;
2306    dst   += dstStrideBlock;
2307    depth += depStrideBlock;
2308  }
2309
2310}
2311
2312Void 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)
2313{
2314#if (H_3D_VSP_BLOCKSIZE==1)
2315  Int nTxtPerDepthX = 1;
2316  Int nTxtPerDepthY = 1;
2317#else
2318  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE >> 1;
2319  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE >> 1;
2320#endif
2321
2322  nTxtPerDepthX = nTxtPerDepthX << vspSize;
2323  nTxtPerDepthY = nTxtPerDepthY << (1-vspSize);
2324
2325  Int refStride = picRef->getCStride();
2326  Int dstStride = yuvDst->getCStride();
2327  Int depStride = yuvDepth->getStride();
2328  Int refStrideBlock = refStride * nTxtPerDepthY;
2329  Int dstStrideBlock = dstStride * nTxtPerDepthY;
2330  Int depStrideBlock = depStride * (nTxtPerDepthY<<1);
2331
2332  Pel *refCb  = picRef->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
2333  Pel *refCr  = picRef->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
2334  Pel *dstCb  = yuvDst->getCbAddr(partAddr);
2335  Pel *dstCr  = yuvDst->getCrAddr(partAddr);
2336  Pel *depth  = yuvDepth->getLumaAddr();
2337
2338#if H_3D_VSP_BLOCKSIZE == 1
2339#if H_3D_VSP_CONSTRAINED
2340  //get LUT based horizontal reference range
2341  Int range = xGetConstrainedSize(width, height, false);
2342
2343  // The minimum depth value
2344  Int minRelativePos = MAX_INT;
2345  Int maxRelativePos = MIN_INT;
2346
2347  Int depthTmp;
2348  for (Int yTxt=0; yTxt<height; yTxt++)
2349  {
2350    for (Int xTxt=0; xTxt<width; xTxt++)
2351    {
2352      depthTmp = m_pDepthBlock[xTxt+yTxt*width];
2353      Int disparity = shiftLUT[ depthTmp ]; // << iShiftPrec;
2354      Int disparityInt = disparity >> 3;//in chroma resolution
2355
2356      if (disparityInt < 0)
2357      {
2358        if (minRelativePos > disparityInt+xTxt)
2359        {
2360          minRelativePos = disparityInt+xTxt;
2361        }
2362      }
2363      else
2364      {
2365        if (maxRelativePos < disparityInt+xTxt)
2366        {
2367          maxRelativePos = disparityInt+xTxt;
2368        }
2369      }
2370    }
2371  }
2372
2373  depthTmp = m_pDepthBlock[0];
2374  Int disparity_tmp = shiftLUT[ depthTmp ]; // << iShiftPrec;
2375  if ( disparity_tmp < 0 )
2376  {
2377    maxRelativePos = minRelativePos + range - 1;
2378  }
2379  else
2380  {
2381    minRelativePos = maxRelativePos - range + 1;
2382  }
2383
2384#endif // H_3D_VSP_CONSTRAINED
2385#endif // H_3D_VSP_BLOCKSIZE == 1
2386
2387  TComMv dv(0, 0);
2388  // luma size -> chroma size
2389  height >>= 1;
2390  width  >>= 1;
2391
2392  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
2393  {
2394    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
2395    {
2396      Pel repDepth = depth[ xTxt<<1 ];
2397      assert( repDepth >= 0 && repDepth <= 255 );
2398
2399      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec;
2400      Int xFrac = disparity & 0x7;
2401     
2402      dv.setHor( disparity );
2403      cu->clipMv( dv );
2404
2405      Int refOffset = xTxt + (dv.getHor() >> 3);
2406
2407#if H_3D_VSP_CONSTRAINED
2408      if(refOffset<minRelativePos || refOffset>maxRelativePos)
2409      {
2410        xFrac = 0;
2411      }
2412      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
2413#endif
2414
2415      assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
2416      assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
2417
2418      m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
2419      m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
2420    }
2421    refCb += refStrideBlock;
2422    refCr += refStrideBlock;
2423    dstCb += dstStrideBlock;
2424    dstCr += dstStrideBlock;
2425    depth += depStrideBlock;
2426  }
2427}
2428#endif
2429
2430#if H_3D_VSP_CONSTRAINED
2431Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma)
2432{
2433  Int iSize = 0;
2434  if (bLuma)
2435  {
2436    Int iArea = (nPbW+7) * (nPbH+7);
2437    Int iAlpha = iArea / nPbH - nPbW - 7;
2438    iSize = iAlpha + nPbW;
2439  }
2440  else // chroma
2441  {
2442    Int iArea = (nPbW+2) * (nPbH+2);
2443    Int iAlpha = iArea / nPbH - nPbW - 4;
2444    iSize = iAlpha + nPbW;
2445  }
2446  return iSize;
2447}
2448#endif // H_3D_VSP_CONSTRAINED
2449
2450#endif // H_3D_VSP
2451
2452#if H_3D_DIM
2453Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
2454{
2455  Int  refDC1, refDC2;
2456  const Int  iTR = (   patternStride - 1        ) - srcStride;
2457  const Int  iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride;
2458  const Int  iLB = (   patternStride - 1        ) * srcStride - 1;
2459  const Int  iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1;
2460
2461  Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] );
2462  Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)]               );
2463
2464  if( bL == bT )
2465  {
2466    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : 1<<( g_bitDepthY - 1 );
2467    refDC2 =      ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1;
2468  }
2469  else
2470  {
2471    refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR];
2472    refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM];
2473  }
2474
2475  predDC1 = biSegPattern[0] ? refDC1 : refDC2;
2476  predDC2 = biSegPattern[0] ? refDC2 : refDC1;
2477}
2478
2479Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
2480{
2481  if( dstStride == patternStride )
2482  {
2483    for( UInt k = 0; k < (patternStride * patternStride); k++ )
2484    {
2485      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
2486      else                          { ptrDst[k] = valDC1; }
2487    }
2488  }
2489  else
2490  {
2491    Pel* piTemp = ptrDst;
2492    for( UInt uiY = 0; uiY < patternStride; uiY++ )
2493    {
2494      for( UInt uiX = 0; uiX < patternStride; uiX++ )
2495      {
2496        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
2497        else                            { piTemp[uiX] = valDC1; }
2498      }
2499      piTemp       += dstStride;
2500      biSegPattern += patternStride;
2501    }
2502  }
2503}
2504
2505#if H_3D_DIM_DMM
2506
2507Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
2508{
2509  pcContourWedge->clear();
2510
2511  // get copy of co-located texture luma block
2512  TComYuv cTempYuv;
2513  cTempYuv.create( uiWidth, uiHeight ); 
2514  cTempYuv.clear();
2515  Pel* piRefBlkY = cTempYuv.getLumaAddr();
2516  xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
2517  piRefBlkY = cTempYuv.getLumaAddr();
2518
2519  // find contour for texture luma block
2520  UInt iDC = 0;
2521  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2522  { 
2523    iDC += piRefBlkY[k]; 
2524  }
2525
2526  Int cuMaxLog2Size = g_aucConvertToBit[g_uiMaxCUWidth]+2;   //
2527  iDC = iDC >> (cuMaxLog2Size - pcCU->getDepth(0))*2;        //  iDC /= (uiWidth*uiHeight);
2528
2529  piRefBlkY = cTempYuv.getLumaAddr();
2530
2531  Bool* pabContourPattern = pcContourWedge->getPattern();
2532  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2533  { 
2534    pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
2535  }
2536
2537  cTempYuv.destroy();
2538}
2539
2540
2541Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
2542{
2543  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
2544  assert( pcPicYuvRef != NULL );
2545  Int         iRefStride = pcPicYuvRef->getStride();
2546  Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2547
2548  for ( Int y = 0; y < uiHeight; y++ )
2549  {
2550    ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
2551    piDestBlockY += uiWidth;
2552    piRefY += iRefStride;
2553  }
2554}
2555#endif
2556
2557
2558#if H_3D_DIM_SDC
2559Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
2560                                         ,UInt uiIntraMode
2561                                         ,Bool orgDC
2562                                        )
2563{
2564  Int iSumDepth[2];
2565  memset(iSumDepth, 0, sizeof(Int)*2);
2566  Int iSumPix[2];
2567  memset(iSumPix, 0, sizeof(Int)*2);
2568 
2569  if (orgDC == false)
2570  {
2571    if ( getDimType(uiIntraMode) == DMM1_IDX )
2572    {
2573      UChar ucSegmentLT = pMask[0];
2574      UChar ucSegmentRT = pMask[uiSize-1];
2575      UChar ucSegmentLB = pMask[uiMaskStride * (uiSize-1)]; 
2576      UChar ucSegmentRB = pMask[uiMaskStride * (uiSize-1) + (uiSize-1)]; 
2577
2578      rpSegMeans[ucSegmentLT] = pOrig[0];
2579      rpSegMeans[ucSegmentRT] = pOrig[uiSize-1];
2580      rpSegMeans[ucSegmentLB] = pOrig[uiStride * (uiSize-1) ];
2581      rpSegMeans[ucSegmentRB] = pOrig[uiStride * (uiSize-1) + (uiSize-1) ];
2582    }
2583    else if (uiIntraMode == PLANAR_IDX)
2584    {
2585      Pel* pLeftTop = pOrig;
2586      Pel* pRightTop = pOrig + (uiSize-1);
2587      Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1)));
2588      Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1));
2589
2590      rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
2591    }
2592    return;
2593  }
2594
2595  Int subSamplePix;
2596  if ( uiSize == 64 || uiSize == 32 )
2597  {
2598    subSamplePix = 2;
2599  }
2600  else
2601  {
2602    subSamplePix = 1;
2603  }
2604  for (Int y=0; y<uiSize; y+=subSamplePix)
2605  {
2606    for (Int x=0; x<uiSize; x+=subSamplePix)
2607    {
2608      UChar ucSegment = pMask?(UChar)pMask[x]:0;
2609      assert( ucSegment < uiNumSegments );
2610     
2611      iSumDepth[ucSegment] += pOrig[x];
2612      iSumPix[ucSegment]   += 1;
2613    }
2614   
2615    pOrig  += uiStride*subSamplePix;
2616    pMask  += uiMaskStride*subSamplePix;
2617  }
2618 
2619  // compute mean for each segment
2620  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
2621  {
2622    if( iSumPix[ucSeg] > 0 )
2623      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
2624    else
2625      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
2626  }
2627}
2628#endif // H_3D_DIM_SDC
2629#endif
2630//! \}
Note: See TracBrowser for help on using the repository browser.