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

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

JCT3V-I0072 integrated. This is a problem fix for IBP cfg, and no impact for CTC, so no simulation results attached.

  • Property svn:eol-style set to native
File size: 78.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-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 MTK_I0072_IVARP_SCALING_FIX
1414        if( iCurrRef >= 0 && iCurrPOC != iCurrRefPOC)
1415#else
1416        if( iCurrRef >= 0)
1417#endif
1418        {
1419          pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); 
1420          Int iTargetPOC = pcPicYuvCurrTRef->getPOC();
1421          pcPicYuvBaseTRef =  pcCU->getSlice()->getBaseViewRefPic(iTargetPOC,  pcPicYuvBaseCol->getViewIndex() ); 
1422          if(pcPicYuvBaseTRef)
1423          {
1424            cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr);
1425            Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC);
1426            if ( iScale != 4096 )
1427            {
1428              cBaseTMV = cBaseTMV.scaleMv( iScale );
1429            }
1430            iCurrTRefPoc = iTargetPOC;
1431            return true;
1432          }
1433        }
1434      }
1435    }
1436  }
1437
1438  //If there is no available motion in base reference list, use ( 0, 0 )
1439  if( pcCU->getSlice()->getFirstTRefIdx( eBaseRefPicList ) >= 0 )
1440  {
1441    cBaseTMV.set( 0, 0 );
1442    pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic( eBaseRefPicList,  pcCU->getSlice()->getFirstTRefIdx( eBaseRefPicList ) );
1443    iCurrTRefPoc = pcPicYuvCurrTRef->getPOC();
1444    return true;
1445  }
1446
1447  return false;
1448}
1449#endif
1450
1451Void TComPrediction::xPredInterUniARPviewRef( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
1452{
1453  Int         iRefIdx       = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
1454  TComMv      cDMv          = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
1455  TComMv      cTempDMv      = cDMv;
1456  UChar       dW            = pcCU->getARPW ( uiPartAddr );
1457
1458  TComPic* pcPicYuvBaseTRef = NULL;
1459  TComPic* pcPicYuvCurrTRef = NULL;
1460  TComPic* pcPicYuvBaseCol  = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx ); 
1461  TComPicYuv* pcYuvBaseCol  = pcPicYuvBaseCol->getPicYuvRec();   
1462  Bool bTMVAvai = false;     
1463  TComMv cBaseTMV;
1464  if( pNewMvFiled )
1465  {
1466    iRefIdx = pNewMvFiled->getRefIdx(); 
1467    cDMv = pNewMvFiled->getMv();
1468  }
1469  pcCU->clipMv(cTempDMv);
1470
1471  assert(dW > 0);
1472  if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, pcPicYuvBaseCol->getViewIndex()))
1473  {
1474    dW = 0;
1475  }
1476  Int uiLCUAddr,uiAbsPartAddr;
1477  Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2  + ((cDMv.getHor() + 2)>>2);
1478  Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2);
1479
1480  irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX);
1481  irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); 
1482  pcYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr);
1483  TComDataCU *pColCU = pcPicYuvBaseCol->getCU( uiLCUAddr );
1484#if QC_I0051_ARP_SIMP
1485  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getIsDepth() )
1486  {
1487    RefPicList eOtherRefList = ( eRefPicList == REF_PIC_LIST_0 ) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
1488    Int iOtherRefIdx = pcCU->getCUMvField( eOtherRefList )->getRefIdx( uiPartAddr );
1489    //The other prediction direction is temporal ARP
1490    if( iOtherRefIdx >= 0 && pcCU->getSlice()->getViewIndex() == pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx )->getViewIndex() )
1491    {
1492      bTMVAvai = true;
1493      pcPicYuvBaseTRef = pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx );
1494      Int  iCurrPOC    = pcCU->getSlice()->getPOC();
1495      Int  iCurrRefPOC = pcPicYuvBaseTRef->getPOC();
1496      Int  iCurrRef    = pcCU->getSlice()->getFirstTRefIdx( eOtherRefList );
1497     
1498      if( iCurrRef >= 0 )
1499      {
1500        pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic( eOtherRefList,iCurrRef ); 
1501        Int iTargetPOC = pcPicYuvCurrTRef->getPOC();
1502        pcPicYuvBaseTRef =  pcCU->getSlice()->getBaseViewRefPic( iTargetPOC,  pcPicYuvBaseCol->getViewIndex() );
1503        if( pcPicYuvBaseTRef )
1504        {
1505          cBaseTMV = pcCU->getCUMvField( eOtherRefList )->getMv( uiPartAddr );
1506          Int iScale = pcCU-> xGetDistScaleFactor( iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC );
1507          if ( iScale != 4096 )
1508          {
1509            cBaseTMV = cBaseTMV.scaleMv( iScale );
1510          }
1511        }
1512        else
1513        {
1514          dW = 0;
1515        }
1516      }
1517      else
1518      {
1519        dW = 0;
1520      }
1521    }
1522
1523    //Both prediction directions are inter-view ARP
1524    if ( iOtherRefIdx >= 0 && !bTMVAvai )
1525    {
1526      RefPicList eBaseList = REF_PIC_LIST_0;
1527      Int iCurrTRefPoc;
1528      bTMVAvai = ( eBaseList != eRefPicList ) && ( pcCU->getSlice()->getViewIndex() != pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx )->getViewIndex() );
1529     
1530      if ( bTMVAvai )
1531      {
1532        if( xCheckBiInterviewARP( pcCU, uiPartAddr, iWidth, iHeight, eBaseList, pcPicYuvCurrTRef, cBaseTMV, iCurrTRefPoc ) )
1533        {
1534          pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic( iCurrTRefPoc,  pcPicYuvBaseCol->getViewIndex() );
1535          if ( pcPicYuvBaseTRef == NULL )
1536          {
1537            dW = 0;
1538          }
1539        }
1540        else
1541        {
1542          dW = 0;
1543        }
1544      }
1545    }
1546  }
1547
1548  if( !pColCU->isIntra( uiAbsPartAddr ) && !bTMVAvai )
1549#else
1550  if(!pColCU->isIntra(uiAbsPartAddr))
1551#endif
1552  {
1553    TComMvField puMVField;
1554    for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1) && !bTMVAvai; iList ++)
1555    {
1556      RefPicList eRefPicListCurr = RefPicList(iList);
1557      Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr);
1558      if( iRef != -1)
1559      {
1560        pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); 
1561        Int  iCurrPOC    = pColCU->getSlice()->getPOC();
1562        Int  iCurrRefPOC = pcPicYuvBaseTRef->getPOC();
1563        Int  iCurrRef    = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr);
1564#if MTK_I0072_IVARP_SCALING_FIX
1565        if (iCurrRef >= 0 && iCurrRefPOC != iCurrPOC)
1566#else
1567        if( iCurrRef >= 0)
1568#endif
1569        {
1570          pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); 
1571          Int iTargetPOC = pcPicYuvCurrTRef->getPOC();
1572          {
1573            pcPicYuvBaseTRef =  pcCU->getSlice()->getBaseViewRefPic(iTargetPOC,  pcPicYuvBaseCol->getViewIndex() ); 
1574            if(pcPicYuvBaseTRef)
1575            {
1576              cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr);
1577              Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC);
1578              if ( iScale != 4096 )
1579                cBaseTMV = cBaseTMV.scaleMv( iScale );                 
1580              bTMVAvai = true;
1581              break;
1582            }
1583          }
1584        }
1585      }
1586    }
1587  }
1588  if (bTMVAvai == false)
1589  { 
1590    bTMVAvai = true;
1591    cBaseTMV.set(0, 0);
1592    pcPicYuvBaseTRef =  pColCU->getSlice()->getRefPic(eRefPicList,  pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); 
1593    pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic  (eRefPicList,  pcCU->getSlice()->getFirstTRefIdx(eRefPicList));     
1594  }
1595#if QC_I0129_ARP_FIX
1596  xPredInterLumaBlk  ( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 && bTMVAvai ),        bTMVAvai);
1597  xPredInterChromaBlk( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 && bTMVAvai ),        bTMVAvai);
1598#else
1599  xPredInterLumaBlk  ( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi,        bTMVAvai);
1600  xPredInterChromaBlk( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi,        bTMVAvai);
1601#endif
1602  if( dW > 0 && bTMVAvai ) 
1603  {
1604    TComYuv*    pYuvCurrTRef    = &m_acYuvPredBase[0];
1605    TComYuv*    pYuvBaseTRef    = &m_acYuvPredBase[1];
1606    TComPicYuv* pcYuvCurrTref   = pcPicYuvCurrTRef->getPicYuvRec();       
1607    TComPicYuv* pcYuvBaseTref   = pcPicYuvBaseTRef->getPicYuvRec(); 
1608    TComMv      cTempMv         = cDMv + cBaseTMV;
1609
1610    pcCU->clipMv(cBaseTMV);
1611    pcCU->clipMv(cTempMv);
1612#if SHARP_ARP_CHROMA_I0104
1613    if (iWidth <= 8)
1614    {
1615      pYuvCurrTRef->clear(); pYuvBaseTRef->clear();
1616    }
1617#endif
1618#if QC_I0129_ARP_FIX
1619    xPredInterLumaBlk  ( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, true,   true);
1620#if SHARP_ARP_CHROMA_I0104
1621    if (iWidth > 8)
1622#endif
1623    xPredInterChromaBlk( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, true,   true);
1624    xPredInterLumaBlk  ( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, true,   true); 
1625#if SHARP_ARP_CHROMA_I0104
1626    if (iWidth > 8)
1627#endif
1628    xPredInterChromaBlk( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, true,   true); 
1629#else
1630    xPredInterLumaBlk  ( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, bi,   true);
1631    xPredInterChromaBlk( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, bi,   true);
1632    xPredInterLumaBlk  ( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, bi,   true); 
1633    xPredInterChromaBlk( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, bi,   true); 
1634#endif
1635    pYuvCurrTRef->subtractARP( pYuvCurrTRef , pYuvBaseTRef , uiPartAddr , iWidth , iHeight ); 
1636    if(dW == 2)
1637    {
1638      pYuvCurrTRef->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
1639    }
1640    rpcYuvPred->addARP( rpcYuvPred , pYuvCurrTRef , uiPartAddr , iWidth , iHeight , !bi ); 
1641  }
1642}
1643
1644#endif
1645
1646Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
1647{
1648  TComYuv* pcMbYuv;
1649  Int      iRefIdx[2] = {-1, -1};
1650
1651  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
1652  {
1653    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
1654    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
1655
1656    if ( iRefIdx[iRefList] < 0 )
1657    {
1658      continue;
1659    }
1660
1661    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
1662
1663    pcMbYuv = &m_acYuvPred[iRefList];
1664    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
1665    {
1666      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
1667    }
1668    else
1669    {
1670      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) || 
1671           ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
1672      {
1673        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
1674      }
1675      else
1676      {
1677        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
1678      }
1679    }
1680  }
1681
1682  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE  )
1683  {
1684    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1685  } 
1686  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
1687  {
1688    xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); 
1689  }
1690  else
1691  {
1692    xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1693  }
1694}
1695
1696#if H_3D_VSP
1697
1698Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
1699{
1700  TComYuv* pcMbYuv;
1701  Int      iRefIdx[2] = {-1, -1};
1702  Bool     bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0);
1703
1704  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
1705  {
1706    RefPicList eRefPicList = RefPicList(iRefList);
1707    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
1708
1709    if ( iRefIdx[iRefList] < 0 )
1710    {
1711      continue;
1712    }
1713    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
1714
1715    pcMbYuv = &m_acYuvPred[iRefList];
1716    xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi );
1717  }
1718
1719  xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1720}
1721
1722#endif
1723
1724/**
1725 * \brief Generate motion-compensated luma block
1726 *
1727 * \param cu       Pointer to current CU
1728 * \param refPic   Pointer to reference picture
1729 * \param partAddr Address of block within CU
1730 * \param mv       Motion vector
1731 * \param width    Width of block
1732 * \param height   Height of block
1733 * \param dstPic   Pointer to destination picture
1734 * \param bi       Flag indicating whether bipred is used
1735 */
1736Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
1737#if H_3D_ARP
1738    , Bool filterType
1739#endif
1740#if H_3D_IC
1741    , Bool bICFlag
1742#endif
1743  )
1744{
1745  Int refStride = refPic->getStride(); 
1746  Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride;
1747  Pel *ref      = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1748 
1749  Int dstStride = dstPic->getStride();
1750  Pel *dst      = dstPic->getLumaAddr( partAddr );
1751 
1752  Int xFrac = mv->getHor() & 0x3;
1753  Int yFrac = mv->getVer() & 0x3;
1754
1755#if H_3D_IC
1756  if( cu->getSlice()->getIsDepth() )
1757  {
1758    refOffset = mv->getHor() + mv->getVer() * refStride;
1759    ref       = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1760    xFrac     = 0;
1761    yFrac     = 0;
1762  }
1763#endif
1764  if ( yFrac == 0 )
1765  {
1766#if H_3D_IC
1767    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi || bICFlag
1768#else
1769    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi
1770#endif
1771#if H_3D_ARP
1772    , filterType
1773#endif
1774      );
1775  }
1776  else if ( xFrac == 0 )
1777  {
1778#if H_3D_IC
1779    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag
1780#else
1781    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi
1782#endif
1783#if H_3D_ARP
1784    , filterType
1785#endif
1786      );
1787  }
1788  else
1789  {
1790    Int tmpStride = m_filteredBlockTmp[0].getStride();
1791    Short *tmp    = m_filteredBlockTmp[0].getLumaAddr();
1792
1793    Int filterSize = NTAPS_LUMA;
1794    Int halfFilterSize = ( filterSize >> 1 );
1795
1796    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     
1797#if H_3D_ARP
1798    , filterType
1799#endif
1800      );
1801#if H_3D_IC
1802    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi || bICFlag
1803#else
1804    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi
1805#endif
1806#if H_3D_ARP
1807    , filterType
1808#endif
1809      );   
1810  }
1811
1812#if H_3D_IC
1813  if( bICFlag )
1814  {
1815    Int a, b, i, j;
1816    const Int iShift = IC_CONST_SHIFT;
1817
1818    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA );
1819
1820
1821    for ( i = 0; i < height; i++ )
1822    {
1823      for ( j = 0; j < width; j++ )
1824      {
1825          dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
1826      }
1827      dst += dstStride;
1828    }
1829
1830    if(bi)
1831    {
1832      Pel *dst2      = dstPic->getLumaAddr( partAddr );
1833      Int shift = IF_INTERNAL_PREC - g_bitDepthY;
1834      for (i = 0; i < height; i++)
1835      {
1836        for (j = 0; j < width; j++)
1837        {
1838          Short val = dst2[j] << shift;
1839          dst2[j] = val - (Short)IF_INTERNAL_OFFS;
1840        }
1841        dst2 += dstStride;
1842      }
1843    }
1844  }
1845#endif
1846}
1847
1848/**
1849 * \brief Generate motion-compensated chroma block
1850 *
1851 * \param cu       Pointer to current CU
1852 * \param refPic   Pointer to reference picture
1853 * \param partAddr Address of block within CU
1854 * \param mv       Motion vector
1855 * \param width    Width of block
1856 * \param height   Height of block
1857 * \param dstPic   Pointer to destination picture
1858 * \param bi       Flag indicating whether bipred is used
1859 */
1860Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
1861#if H_3D_ARP
1862    , Bool filterType
1863#endif
1864#if H_3D_IC
1865    , Bool bICFlag
1866#endif
1867  )
1868{
1869  Int     refStride  = refPic->getCStride();
1870  Int     dstStride  = dstPic->getCStride();
1871 
1872  Int     refOffset  = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride;
1873 
1874  Pel*    refCb     = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1875  Pel*    refCr     = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1876 
1877  Pel* dstCb = dstPic->getCbAddr( partAddr );
1878  Pel* dstCr = dstPic->getCrAddr( partAddr );
1879 
1880  Int     xFrac  = mv->getHor() & 0x7;
1881  Int     yFrac  = mv->getVer() & 0x7;
1882  UInt    cxWidth  = width  >> 1;
1883  UInt    cxHeight = height >> 1;
1884 
1885  Int     extStride = m_filteredBlockTmp[0].getStride();
1886  Short*  extY      = m_filteredBlockTmp[0].getLumaAddr();
1887 
1888  Int filterSize = NTAPS_CHROMA;
1889 
1890  Int halfFilterSize = (filterSize>>1);
1891 
1892  if ( yFrac == 0 )
1893  {
1894#if H_3D_IC
1895    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
1896#else
1897    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi
1898#endif
1899#if H_3D_ARP
1900    , filterType
1901#endif
1902    );   
1903#if H_3D_IC
1904    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
1905#else
1906    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi
1907#endif
1908#if H_3D_ARP
1909    , filterType
1910#endif
1911    );
1912  }
1913  else if ( xFrac == 0 )
1914  {
1915#if H_3D_IC
1916    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
1917#else
1918    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1919#endif
1920#if H_3D_ARP
1921    , filterType
1922#endif
1923    );
1924#if H_3D_IC
1925    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
1926#else
1927    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1928#endif
1929#if H_3D_ARP
1930    , filterType
1931#endif
1932    );
1933  }
1934  else
1935  {
1936    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1937#if H_3D_ARP
1938    , filterType
1939#endif 
1940      );
1941#if H_3D_IC
1942    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
1943#else
1944    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1945#endif
1946#if H_3D_ARP
1947    , filterType
1948#endif
1949      );
1950   
1951    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1952#if H_3D_ARP
1953    , filterType
1954#endif
1955      );
1956#if H_3D_IC
1957    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
1958#else
1959    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1960#endif
1961#if H_3D_ARP
1962    , filterType
1963#endif
1964      );   
1965  }
1966
1967#if H_3D_IC
1968  if( bICFlag )
1969  {
1970    Int a, b, i, j;
1971    const Int iShift = IC_CONST_SHIFT;
1972    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb
1973    for ( i = 0; i < cxHeight; i++ )
1974    {
1975      for ( j = 0; j < cxWidth; j++ )
1976      {
1977          dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
1978      }
1979      dstCb += dstStride;
1980    }
1981    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr
1982    for ( i = 0; i < cxHeight; i++ )
1983    {
1984      for ( j = 0; j < cxWidth; j++ )
1985      {
1986          dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
1987      }
1988      dstCr += dstStride;
1989    }
1990
1991    if(bi)
1992    {
1993      Pel* dstCb2 = dstPic->getCbAddr( partAddr );
1994      Pel* dstCr2 = dstPic->getCrAddr( partAddr );
1995      Int shift = IF_INTERNAL_PREC - g_bitDepthC;
1996      for (i = 0; i < cxHeight; i++)
1997      {
1998        for (j = 0; j < cxWidth; j++)
1999        {
2000          Short val = dstCb2[j] << shift;
2001          dstCb2[j] = val - (Short)IF_INTERNAL_OFFS;
2002
2003          val = dstCr2[j] << shift;
2004          dstCr2[j] = val - (Short)IF_INTERNAL_OFFS;
2005        }
2006        dstCb2 += dstStride;
2007        dstCr2 += dstStride;
2008      }
2009    }
2010  }
2011#endif
2012}
2013
2014Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
2015{
2016  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
2017  {
2018    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
2019  }
2020  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
2021  {
2022    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
2023  }
2024  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
2025  {
2026    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
2027  }
2028}
2029
2030// AMVP
2031Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
2032{
2033  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
2034  if( pcAMVPInfo->iN <= 1 )
2035  {
2036    rcMvPred = pcAMVPInfo->m_acMvCand[0];
2037
2038    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
2039    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
2040    return;
2041  }
2042
2043  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
2044  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
2045  return;
2046}
2047
2048/** Function for deriving planar intra prediction.
2049 * \param pSrc pointer to reconstructed sample array
2050 * \param srcStride the stride of the reconstructed sample array
2051 * \param rpDst reference to pointer for the prediction sample array
2052 * \param dstStride the stride of the prediction sample array
2053 * \param width the width of the block
2054 * \param height the height of the block
2055 *
2056 * This function derives the prediction samples for planar mode (intra coding).
2057 */
2058Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
2059{
2060  assert(width == height);
2061
2062  Int k, l, bottomLeft, topRight;
2063  Int horPred;
2064  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
2065  UInt blkSize = width;
2066  UInt offset2D = width;
2067  UInt shift1D = g_aucConvertToBit[ width ] + 2;
2068  UInt shift2D = shift1D + 1;
2069
2070  // Get left and above reference column and row
2071  for(k=0;k<blkSize+1;k++)
2072  {
2073    topRow[k] = pSrc[k-srcStride];
2074    leftColumn[k] = pSrc[k*srcStride-1];
2075  }
2076
2077  // Prepare intermediate variables used in interpolation
2078  bottomLeft = leftColumn[blkSize];
2079  topRight   = topRow[blkSize];
2080  for (k=0;k<blkSize;k++)
2081  {
2082    bottomRow[k]   = bottomLeft - topRow[k];
2083    rightColumn[k] = topRight   - leftColumn[k];
2084    topRow[k]      <<= shift1D;
2085    leftColumn[k]  <<= shift1D;
2086  }
2087
2088  // Generate prediction signal
2089  for (k=0;k<blkSize;k++)
2090  {
2091    horPred = leftColumn[k] + offset2D;
2092    for (l=0;l<blkSize;l++)
2093    {
2094      horPred += rightColumn[k];
2095      topRow[l] += bottomRow[l];
2096      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
2097    }
2098  }
2099}
2100
2101/** Function for filtering intra DC predictor.
2102 * \param pSrc pointer to reconstructed sample array
2103 * \param iSrcStride the stride of the reconstructed sample array
2104 * \param rpDst reference to pointer for the prediction sample array
2105 * \param iDstStride the stride of the prediction sample array
2106 * \param iWidth the width of the block
2107 * \param iHeight the height of the block
2108 *
2109 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
2110 */
2111Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
2112{
2113  Pel* pDst = rpDst;
2114  Int x, y, iDstStride2, iSrcStride2;
2115
2116  // boundary pixels processing
2117  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
2118
2119  for ( x = 1; x < iWidth; x++ )
2120  {
2121    pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
2122  }
2123
2124  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
2125  {
2126    pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
2127  }
2128
2129  return;
2130}
2131#if H_3D_IC
2132/** Function for deriving the position of first non-zero binary bit of a value
2133 * \param x input value
2134 *
2135 * This function derives the position of first non-zero binary bit of a value
2136 */
2137Int GetMSB( UInt x )
2138{
2139  Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1;
2140
2141  while( x > 1 )
2142  {
2143    bits >>= 1;
2144    y = x >> bits;
2145
2146    if( y )
2147    {
2148      x = y;
2149      iMSB += bits;
2150    }
2151  }
2152
2153  iMSB+=y;
2154
2155  return iMSB;
2156}
2157
2158
2159/** Function for deriving LM illumination compensation.
2160 */
2161Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType )
2162{
2163  TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
2164  Pel *pRec = NULL, *pRef = NULL;
2165  UInt uiWidth, uiHeight, uiTmpPartIdx;
2166  Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride();
2167  Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride();
2168  Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer;
2169
2170  iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
2171  iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
2172  iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 );
2173  iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 );
2174  iRefX   = iCUPelX + iHor;
2175  iRefY   = iCUPelY + iVer;
2176  if( eType != TEXT_LUMA )
2177  {
2178    iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 );
2179    iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 );
2180  }
2181  uiWidth  = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 )  : ( pcCU->getWidth( 0 )  >> 1 );
2182  uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 );
2183
2184  Int i, j, iCountShift = 0;
2185
2186  // LLS parameters estimation -->
2187
2188  Int x = 0, y = 0, xx = 0, xy = 0;
2189  Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12);
2190
2191  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 )
2192  {
2193    iRefOffset = iHor + iVer * iRefStride - iRefStride;
2194    if( eType == TEXT_LUMA )
2195    {
2196      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2197      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
2198    }
2199    else if( eType == TEXT_CHROMA_U )
2200    {
2201      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2202      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
2203    }
2204    else
2205    {
2206      assert( eType == TEXT_CHROMA_V );
2207      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2208      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
2209    }
2210
2211    for( j = 0; j < uiWidth; j+=2 )
2212    {
2213      x += pRef[j];
2214      y += pRec[j];
2215      xx += (pRef[j] * pRef[j])>>precShift;
2216      xy += (pRef[j] * pRec[j])>>precShift;
2217    }
2218    iCountShift += g_aucConvertToBit[ uiWidth ] + 1;
2219  }
2220
2221
2222  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 )
2223  {
2224    iRefOffset = iHor + iVer * iRefStride - 1;
2225    if( eType == TEXT_LUMA )
2226    {
2227      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2228      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
2229    }
2230    else if( eType == TEXT_CHROMA_U )
2231    {
2232      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2233      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
2234    }
2235    else
2236    {
2237      assert( eType == TEXT_CHROMA_V );
2238      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2239      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
2240    }
2241
2242    for( i = 0; i < uiHeight; i+=2 )
2243    {
2244      x += pRef[0];
2245      y += pRec[0];
2246
2247      xx += (pRef[0] * pRef[0])>>precShift;
2248      xy += (pRef[0] * pRec[0])>>precShift;
2249
2250      pRef += iRefStride*2;
2251      pRec += iRecStride*2;
2252    }
2253    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 );
2254  }
2255
2256  xy += xx >> IC_REG_COST_SHIFT;
2257  xx += xx >> IC_REG_COST_SHIFT;
2258  Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift);
2259  Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift);
2260  const Int iShift = IC_CONST_SHIFT;
2261  {
2262    {
2263      const Int iShiftA2 = 6;
2264      const Int iAccuracyShift = 15;
2265
2266      Int iScaleShiftA2 = 0;
2267      Int iScaleShiftA1 = 0;
2268      Int a1s = a1;
2269      Int a2s = a2;
2270
2271      a1 = Clip3(0, 2*a2, a1);
2272      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2;
2273      iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF;
2274
2275      if( iScaleShiftA1 < 0 )
2276      {
2277        iScaleShiftA1 = 0;
2278      }
2279
2280      if( iScaleShiftA2 < 0 )
2281      {
2282        iScaleShiftA2 = 0;
2283      }
2284
2285      Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
2286
2287
2288      a2s = a2 >> iScaleShiftA2;
2289
2290      a1s = a1 >> iScaleShiftA1;
2291
2292      a = a1s * m_uiaShift[ a2s ];
2293      a = a >> iScaleShiftA;
2294      b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
2295    }
2296  }   
2297}
2298#endif
2299
2300#if H_3D_DIM
2301Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
2302{
2303  Int  refDC1, refDC2;
2304  const Int  iTR = (   patternStride - 1        ) - srcStride;
2305  const Int  iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride;
2306  const Int  iLB = (   patternStride - 1        ) * srcStride - 1;
2307  const Int  iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1;
2308
2309  Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] );
2310  Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)]               );
2311
2312  if( bL == bT )
2313  {
2314    const Int  iTRR = ( patternStride * 2 - 1  ) - srcStride; 
2315    const Int  iLBB = ( patternStride * 2 - 1  ) * srcStride - 1;
2316    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : (abs(ptrSrc[iTRR] - ptrSrc[-(Int)srcStride]) > abs(ptrSrc[iLBB] - ptrSrc[ -1]) ? ptrSrc[iTRR] : ptrSrc[iLBB]);
2317    refDC2 =      ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1;
2318  }
2319  else
2320  {
2321    refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR];
2322    refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM];
2323  }
2324
2325  predDC1 = biSegPattern[0] ? refDC1 : refDC2;
2326  predDC2 = biSegPattern[0] ? refDC2 : refDC1;
2327}
2328
2329Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
2330{
2331  if( dstStride == patternStride )
2332  {
2333    for( UInt k = 0; k < (patternStride * patternStride); k++ )
2334    {
2335      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
2336      else                          { ptrDst[k] = valDC1; }
2337    }
2338  }
2339  else
2340  {
2341    Pel* piTemp = ptrDst;
2342    for( UInt uiY = 0; uiY < patternStride; uiY++ )
2343    {
2344      for( UInt uiX = 0; uiX < patternStride; uiX++ )
2345      {
2346        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
2347        else                            { piTemp[uiX] = valDC1; }
2348      }
2349      piTemp       += dstStride;
2350      biSegPattern += patternStride;
2351    }
2352  }
2353}
2354
2355#if H_3D_DIM_DMM
2356
2357Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
2358{
2359  pcContourWedge->clear();
2360
2361  // get copy of co-located texture luma block
2362  TComYuv cTempYuv;
2363  cTempYuv.create( uiWidth, uiHeight ); 
2364  cTempYuv.clear();
2365  Pel* piRefBlkY = cTempYuv.getLumaAddr();
2366  xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
2367  piRefBlkY = cTempYuv.getLumaAddr();
2368
2369  // find contour for texture luma block
2370  UInt iDC = 0;
2371  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2372  { 
2373    iDC += piRefBlkY[k]; 
2374  }
2375
2376  Int cuMaxLog2Size = g_aucConvertToBit[g_uiMaxCUWidth]+2;   //
2377  iDC = iDC >> (cuMaxLog2Size - pcCU->getDepth(0))*2;        //  iDC /= (uiWidth*uiHeight);
2378
2379  piRefBlkY = cTempYuv.getLumaAddr();
2380
2381  Bool* pabContourPattern = pcContourWedge->getPattern();
2382  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2383  { 
2384    pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
2385  }
2386
2387  cTempYuv.destroy();
2388}
2389
2390
2391Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
2392{
2393  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
2394  assert( pcPicYuvRef != NULL );
2395  Int         iRefStride = pcPicYuvRef->getStride();
2396  Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2397
2398  for ( Int y = 0; y < uiHeight; y++ )
2399  {
2400    ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
2401    piDestBlockY += uiWidth;
2402    piRefY += iRefStride;
2403  }
2404}
2405#endif
2406
2407
2408#if H_3D_DIM_SDC
2409Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
2410                                         ,UInt uiIntraMode
2411                                         ,Bool orgDC
2412                                        )
2413{
2414  Int iSumDepth[2];
2415  memset(iSumDepth, 0, sizeof(Int)*2);
2416  Int iSumPix[2];
2417  memset(iSumPix, 0, sizeof(Int)*2);
2418  for( Int i = 0; i < uiNumSegments; i++ )
2419  {
2420    rpSegMeans[i] = 0;
2421  }
2422  if (orgDC == false)
2423  {
2424    Pel* pLeftTop = pOrig;
2425    Pel* pRightTop = pOrig + (uiSize-1);
2426    Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1)));
2427    Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1));
2428
2429    rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
2430    return;
2431  }
2432
2433  Int subSamplePix;
2434  if ( uiSize == 64 || uiSize == 32 )
2435  {
2436    subSamplePix = 2;
2437  }
2438  else
2439  {
2440    subSamplePix = 1;
2441  }
2442  for (Int y=0; y<uiSize; y+=subSamplePix)
2443  {
2444    for (Int x=0; x<uiSize; x+=subSamplePix)
2445    {
2446      UChar ucSegment = pMask?(UChar)pMask[x]:0;
2447      assert( ucSegment < uiNumSegments );
2448     
2449      iSumDepth[ucSegment] += pOrig[x];
2450      iSumPix[ucSegment]   += 1;
2451    }
2452   
2453    pOrig  += uiStride*subSamplePix;
2454    pMask  += uiMaskStride*subSamplePix;
2455  }
2456 
2457  // compute mean for each segment
2458  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
2459  {
2460    if( iSumPix[ucSeg] > 0 )
2461      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
2462    else
2463      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
2464  }
2465}
2466#endif // H_3D_DIM_SDC
2467#endif
2468//! \}
Note: See TracBrowser for help on using the repository browser.