source: 3DVCSoftware/branches/HTM-11.2-dev2-Sharp/source/Lib/TLibCommon/TComPrediction.cpp @ 995

Last change on this file since 995 was 995, checked in by sharpjp-htm, 10 years ago

Integration of JCT3V-I0104

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