source: 3DVCSoftware/branches/HTM-11.2-dev3-Samsung/source/Lib/TLibCommon/TComPrediction.cpp @ 1133

Last change on this file since 1133 was 1013, checked in by samsung-htm, 11 years ago

Integration of JCT3V-I0076: Simplification of threshold derivation for DBBP and DMM4

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