source: 3DVCSoftware/trunk/source/Lib/TLibCommon/TComPrediction.cpp @ 1064

Last change on this file since 1064 was 1039, checked in by tech, 11 years ago

Merged 11.2-dev0@1038.

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