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

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