source: 3DVCSoftware/branches/HTM-11.2-dev0/source/Lib/TLibCommon/TComPrediction.cpp @ 1030

Last change on this file since 1030 was 1030, checked in by tech, 10 years ago

Merged 11.2-dev2-Samsung@1026.

  • Property svn:eol-style set to native
File size: 85.1 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6* Copyright (c) 2010-2014, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TComPrediction.cpp
35    \brief    prediction class
36*/
37
38#include <memory.h>
39#include "TComPrediction.h"
40
41//! \ingroup TLibCommon
42//! \{
43
44// ====================================================================================================================
45// Constructor / destructor / initialize
46// ====================================================================================================================
47
48TComPrediction::TComPrediction()
49: m_pLumaRecBuffer(0)
50, m_iLumaRecStride(0)
51{
52  m_piYuvExt = NULL;
53#if H_3D_VSP
54  m_pDepthBlock = (Int*) malloc(MAX_NUM_SPU_W*MAX_NUM_SPU_W*sizeof(Int));
55  if (m_pDepthBlock == NULL)
56      printf("ERROR: UKTGHU, No memory allocated.\n");
57#endif
58}
59
60TComPrediction::~TComPrediction()
61{
62#if H_3D_VSP
63  if (m_pDepthBlock != NULL)
64      free(m_pDepthBlock);
65  m_cYuvDepthOnVsp.destroy();
66#endif
67
68  delete[] m_piYuvExt;
69
70  m_acYuvPred[0].destroy();
71  m_acYuvPred[1].destroy();
72
73  m_cYuvPredTemp.destroy();
74
75#if H_3D_ARP
76  m_acYuvPredBase[0].destroy();
77  m_acYuvPredBase[1].destroy();
78#endif
79  if( m_pLumaRecBuffer )
80  {
81    delete [] m_pLumaRecBuffer;
82  }
83 
84  Int i, j;
85  for (i = 0; i < 4; i++)
86  {
87    for (j = 0; j < 4; j++)
88    {
89      m_filteredBlock[i][j].destroy();
90    }
91    m_filteredBlockTmp[i].destroy();
92  }
93}
94
95Void TComPrediction::initTempBuff()
96{
97  if( m_piYuvExt == NULL )
98  {
99    Int extWidth  = MAX_CU_SIZE + 16; 
100    Int extHeight = MAX_CU_SIZE + 1;
101    Int i, j;
102    for (i = 0; i < 4; i++)
103    {
104      m_filteredBlockTmp[i].create(extWidth, extHeight + 7);
105      for (j = 0; j < 4; j++)
106      {
107        m_filteredBlock[i][j].create(extWidth, extHeight);
108      }
109    }
110    m_iYuvExtHeight  = ((MAX_CU_SIZE + 2) << 4);
111    m_iYuvExtStride = ((MAX_CU_SIZE  + 8) << 4);
112    m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
113
114    // new structure
115    m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE );
116    m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE );
117
118    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE );
119#if H_3D_ARP
120    m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
121    m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
122#endif
123#if H_3D_VSP
124    m_cYuvDepthOnVsp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
125#endif
126  }
127
128  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
129  {
130    m_iLumaRecStride =  (MAX_CU_SIZE>>1) + 1;
131    if (!m_pLumaRecBuffer)
132    {
133      m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ];
134    }
135  }
136#if H_3D_IC
137  m_uiaShift[0] = 0;
138  for( Int i = 1; i < 64; i++ )
139  {
140    m_uiaShift[i] = ( (1 << 15) + i/2 ) / i;
141  }
142#endif
143}
144
145// ====================================================================================================================
146// Public member functions
147// ====================================================================================================================
148
149// Function for calculating DC value of the reference samples used in Intra prediction
150Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft )
151{
152  assert(iWidth > 0 && iHeight > 0);
153  Int iInd, iSum = 0;
154  Pel pDcVal;
155
156  if (bAbove)
157  {
158    for (iInd = 0;iInd < iWidth;iInd++)
159    {
160      iSum += pSrc[iInd-iSrcStride];
161    }
162  }
163  if (bLeft)
164  {
165    for (iInd = 0;iInd < iHeight;iInd++)
166    {
167      iSum += pSrc[iInd*iSrcStride-1];
168    }
169  }
170
171  if (bAbove && bLeft)
172  {
173    pDcVal = (iSum + iWidth) / (iWidth + iHeight);
174  }
175  else if (bAbove)
176  {
177    pDcVal = (iSum + iWidth/2) / iWidth;
178  }
179  else if (bLeft)
180  {
181    pDcVal = (iSum + iHeight/2) / iHeight;
182  }
183  else
184  {
185    pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available
186  }
187 
188  return pDcVal;
189}
190
191// Function for deriving the angular Intra predictions
192
193/** Function for deriving the simplified angular intra predictions.
194 * \param pSrc pointer to reconstructed sample array
195 * \param srcStride the stride of the reconstructed sample array
196 * \param rpDst reference to pointer for the prediction sample array
197 * \param dstStride the stride of the prediction sample array
198 * \param width the width of the block
199 * \param height the height of the block
200 * \param dirMode the intra prediction mode index
201 * \param blkAboveAvailable boolean indication if the block above is available
202 * \param blkLeftAvailable boolean indication if the block to the left is available
203 *
204 * This function derives the prediction samples for the angular mode based on the prediction direction indicated by
205 * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and
206 * the reference row above the block in the case of vertical prediction or displacement of the rightmost column
207 * of the block and reference column left from the block in the case of the horizontal prediction. The displacement
208 * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples,
209 * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken
210 * from the extended main reference.
211 */
212Void TComPrediction::xPredIntraAng(Int bitDepth, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter )
213{
214  Int k,l;
215  Int blkSize        = width;
216  Pel* pDst          = rpDst;
217
218  // Map the mode index to main prediction direction and angle
219  assert( dirMode > 0 ); //no planar
220  Bool modeDC        = dirMode < 2;
221  Bool modeHor       = !modeDC && (dirMode < 18);
222  Bool modeVer       = !modeDC && !modeHor;
223  Int intraPredAngle = modeVer ? (Int)dirMode - VER_IDX : modeHor ? -((Int)dirMode - HOR_IDX) : 0;
224  Int absAng         = abs(intraPredAngle);
225  Int signAng        = intraPredAngle < 0 ? -1 : 1;
226
227  // Set bitshifts and scale the angle parameter to block size
228  Int angTable[9]    = {0,    2,    5,   9,  13,  17,  21,  26,  32};
229  Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
230  Int invAngle       = invAngTable[absAng];
231  absAng             = angTable[absAng];
232  intraPredAngle     = signAng * absAng;
233
234  // Do the DC prediction
235  if (modeDC)
236  {
237    Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable);
238
239    for (k=0;k<blkSize;k++)
240    {
241      for (l=0;l<blkSize;l++)
242      {
243        pDst[k*dstStride+l] = dcval;
244      }
245    }
246  }
247
248  // Do angular predictions
249  else
250  {
251    Pel* refMain;
252    Pel* refSide;
253    Pel  refAbove[2*MAX_CU_SIZE+1];
254    Pel  refLeft[2*MAX_CU_SIZE+1];
255
256    // Initialise the Main and Left reference array.
257    if (intraPredAngle < 0)
258    {
259      for (k=0;k<blkSize+1;k++)
260      {
261        refAbove[k+blkSize-1] = pSrc[k-srcStride-1];
262      }
263      for (k=0;k<blkSize+1;k++)
264      {
265        refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1];
266      }
267      refMain = (modeVer ? refAbove : refLeft) + (blkSize-1);
268      refSide = (modeVer ? refLeft : refAbove) + (blkSize-1);
269
270      // Extend the Main reference to the left.
271      Int invAngleSum    = 128;       // rounding for (shift by 8)
272      for (k=-1; k>blkSize*intraPredAngle>>5; k--)
273      {
274        invAngleSum += invAngle;
275        refMain[k] = refSide[invAngleSum>>8];
276      }
277    }
278    else
279    {
280      for (k=0;k<2*blkSize+1;k++)
281      {
282        refAbove[k] = pSrc[k-srcStride-1];
283      }
284      for (k=0;k<2*blkSize+1;k++)
285      {
286        refLeft[k] = pSrc[(k-1)*srcStride-1];
287      }
288      refMain = modeVer ? refAbove : refLeft;
289      refSide = modeVer ? refLeft  : refAbove;
290    }
291
292    if (intraPredAngle == 0)
293    {
294      for (k=0;k<blkSize;k++)
295      {
296        for (l=0;l<blkSize;l++)
297        {
298          pDst[k*dstStride+l] = refMain[l+1];
299        }
300      }
301
302      if ( bFilter )
303      {
304        for (k=0;k<blkSize;k++)
305        {
306          pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) );
307        }
308      }
309    }
310    else
311    {
312      Int deltaPos=0;
313      Int deltaInt;
314      Int deltaFract;
315      Int refMainIndex;
316
317      for (k=0;k<blkSize;k++)
318      {
319        deltaPos += intraPredAngle;
320        deltaInt   = deltaPos >> 5;
321        deltaFract = deltaPos & (32 - 1);
322
323        if (deltaFract)
324        {
325          // Do linear filtering
326          for (l=0;l<blkSize;l++)
327          {
328            refMainIndex        = l+deltaInt+1;
329            pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 );
330          }
331        }
332        else
333        {
334          // Just copy the integer samples
335          for (l=0;l<blkSize;l++)
336          {
337            pDst[k*dstStride+l] = refMain[l+deltaInt+1];
338          }
339        }
340      }
341    }
342
343    // Flip the block if this is the horizontal mode
344    if (modeHor)
345    {
346      Pel  tmp;
347      for (k=0;k<blkSize-1;k++)
348      {
349        for (l=k+1;l<blkSize;l++)
350        {
351          tmp                 = pDst[k*dstStride+l];
352          pDst[k*dstStride+l] = pDst[l*dstStride+k];
353          pDst[l*dstStride+k] = tmp;
354        }
355      }
356    }
357  }
358}
359
360Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
361{
362  Pel *pDst = piPred;
363  Int *ptrSrc;
364
365  assert( g_aucConvertToBit[ iWidth ] >= 0 ); //   4x  4
366  assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128
367  assert( iWidth == iHeight  );
368
369  ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
370
371  // get starting pixel in block
372  Int sw = 2 * iWidth + 1;
373
374  // Create the prediction
375  if ( uiDirMode == PLANAR_IDX )
376  {
377    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
378  }
379  else
380  {
381    if ( (iWidth > 16) || (iHeight > 16) )
382    {
383      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
384    }
385    else
386    {
387      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );
388
389      if( (uiDirMode == DC_IDX ) && bAbove && bLeft )
390      {
391        xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);
392      }
393    }
394  }
395}
396
397// Angular chroma
398Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
399{
400  Pel *pDst = piPred;
401  Int *ptrSrc = piSrc;
402
403  // get starting pixel in block
404  Int sw = 2 * iWidth + 1;
405
406  if ( uiDirMode == PLANAR_IDX )
407  {
408    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
409  }
410  else
411  {
412    // Create the prediction
413    xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
414  }
415}
416
417#if H_3D_DIM
418Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc, TComWedgelet* dmm4Segmentation  )
419{
420  assert( iWidth == iHeight  );
421  assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE );
422  assert( isDimMode( uiIntraMode ) );
423
424  UInt dimType    = getDimType  ( uiIntraMode );
425#if !HS_DMM_SIGNALLING_I0120
426  Bool dimDeltaDC = isDimDeltaDC( uiIntraMode );
427#endif
428  Bool isDmmMode  = (dimType <  DMM_NUM_TYPE);
429
430  Bool* biSegPattern  = NULL;
431  UInt  patternStride = 0;
432
433  // get partiton
434#if H_3D_DIM_DMM
435  TComWedgelet* dmmSegmentation = NULL;
436  if( isDmmMode )
437  {
438    switch( dimType )
439    {
440    case( DMM1_IDX ): 
441      {
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
447        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]);
448#endif
449      } break;
450    case( DMM4_IDX ): 
451      {
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        }
462      } break;
463    default: assert(0);
464    }
465    assert( dmmSegmentation );
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
478    biSegPattern  = dmmSegmentation->getPattern();
479    patternStride = dmmSegmentation->getStride ();
480#endif
481  }
482#endif
483
484  // get predicted partition values
485  assert( biSegPattern );
486  Int* piMask = NULL;
487  piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering
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;
497#if HS_DMM_SIGNALLING_I0120
498  if( !pcCU->getSDCFlag( uiAbsPartIdx ) )
499#else
500  if( dimDeltaDC )
501#endif
502  {
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
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
512      segDC1 = ClipY( predDC1 + deltaDC1 );
513      segDC2 = ClipY( predDC2 + deltaDC2 );
514#endif
515    }
516#endif
517  }
518  else
519  {
520    segDC1 = predDC1;
521    segDC2 = predDC2;
522  }
523
524  // set prediction signal
525  Pel* pDst = piPred;
526  xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 );
527  pcCU->setDmmPredictor(segDC1, 0);
528  pcCU->setDmmPredictor(segDC2, 1);
529
530#if H_3D_DIM_DMM
531  if( dimType == DMM4_IDX && dmm4Segmentation == NULL ) { dmmSegmentation->destroy(); delete dmmSegmentation; }
532#endif
533}
534#endif
535
536/** Function for checking identical motion.
537 * \param TComDataCU* pcCU
538 * \param UInt PartAddr
539 */
540Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr )
541{
542  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() )
543  {
544    if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0)
545    {
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();
548#if H_3D_ARP
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
551      if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
552#endif
553      {
554        return true;
555      }
556    }
557  }
558  return false;
559}
560
561#if H_3D_SPIVMP
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#if SHARP_ARP_CHROMA_I0104
571  if( pcCU->getARPW( uiPartAddr ) != 0 )
572  {
573    return;
574  }
575#endif
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}
617
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
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
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};
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;
721  for(Int p=0; p<2; p++)  // loop over partition
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;
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
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  }
783#endif
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);
792#if SEC_DBBP_DMM4_THRESHOLD_I0076
793  Int iMean = iSumDepth >> 2;
794#else
795  Int iSizeInBits = g_aucConvertToBit[uiWidth]+2;
796  Int iMean = iSumDepth >> iSizeInBits*2;       // iMean /= (uiWidth*uiHeight);
797#endif
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
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
847Void TComPrediction::combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr )
848#endif
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;
856#if !SHARP_DBBP_SIMPLE_FLTER_I0109
857  Pel  filSrc = 0;
858#endif
859  Pel* tmpTar = 0;
860  tmpTar = (Pel *)xMalloc(Pel, uiWidth*uiHeight);
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
874      tmpTar[y*uiWidth+x] = piSrc[ucSegment][x];
875    }
876   
877    piSrc[0]  += uiSrcStride;
878    piSrc[1]  += uiSrcStride;
879    pMask     += uiMaskStride;
880  }
881 
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
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  }
953#endif
954
955  if ( tmpTar    ) { xFree(tmpTar);             tmpTar        = NULL; }
956 
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;
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);
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
980      tmpTarU[y*uiWidthC+x] = piSrcU[ucSegment][x];
981      tmpTarV[y*uiWidthC+x] = piSrcV[ucSegment][x];
982    }
983   
984    piSrcU[0]   += uiSrcStrideC;
985    piSrcU[1]   += uiSrcStrideC;
986    piSrcV[0]   += uiSrcStrideC;
987    piSrcV[1]   += uiSrcStrideC;
988    pMask       += 2*uiMaskStride;
989  }
990
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
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  }
1104#endif
1105  if ( tmpTarU    ) { xFree(tmpTarU);             tmpTarU        = NULL; }
1106  if ( tmpTarV    ) { xFree(tmpTarV);             tmpTarV        = NULL; }
1107}
1108#endif
1109
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 );
1119#if H_3D_VSP
1120    if ( pcCU->getVSPFlag(uiPartAddr) == 0)
1121    {
1122#endif
1123      if ( eRefPicList != REF_PIC_LIST_X )
1124      {
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        }
1137      }
1138      else
1139      {
1140#if H_3D_SPIVMP
1141        if ( pcCU->getSPIVMPFlag(uiPartAddr)!=0) 
1142        {
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          }
1168        }
1169        else
1170        {
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          }
1180#if H_3D_SPIVMP
1181        }
1182#endif
1183      }
1184#if H_3D_VSP
1185    }
1186    else
1187    {
1188      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
1189      {
1190        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
1191      }
1192      else
1193      {
1194        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
1195      }
1196    }
1197#endif
1198    return;
1199  }
1200
1201  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ )
1202  {
1203    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
1204
1205#if H_3D_VSP
1206    if ( pcCU->getVSPFlag(uiPartAddr) == 0 )
1207    {
1208#endif
1209      if ( eRefPicList != REF_PIC_LIST_X )
1210      {
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        }
1223      }
1224      else
1225      {
1226#if H_3D_SPIVMP
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
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        }
1265#if H_3D_SPIVMP
1266       }
1267#endif
1268      }
1269#if H_3D_VSP
1270    }
1271    else
1272    {
1273      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
1274      {
1275        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
1276      }
1277      else
1278      {
1279        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
1280      }
1281    }
1282#endif
1283  }
1284  return;
1285}
1286
1287Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
1288{
1289  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
1290  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
1291  pcCU->clipMv(cMv);
1292
1293#if H_3D_DDD
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
1329#if H_3D_ARP
1330  if(pcCU->getARPW( uiPartAddr ) > 0  && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC())
1331  {
1332    xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , rpcYuvPred , bi );
1333  }
1334  else
1335  {
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    {
1345#endif
1346#if H_3D_IC
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
1349#if H_3D_ARP
1350        , false
1351#endif
1352        , bICFlag );
1353      bICFlag = bICFlag && (iWidth > 8);
1354      xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
1355#if H_3D_ARP
1356        , false
1357#endif
1358        , bICFlag );
1359#else
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 );
1362#endif
1363#if H_3D_ARP
1364    }
1365  }
1366#endif
1367}
1368
1369#if H_3D_VSP
1370Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
1371{
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 );
1386}
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
1413#endif
1414
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;
1423
1424#if H_3D_NBDV
1425  DisInfo cDistparity;
1426  cDistparity.bDV           = pcCU->getDvInfo(uiPartAddr).bDV;
1427  if( cDistparity.bDV )
1428  {
1429    cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV;
1430    assert(pcCU->getDvInfo(uiPartAddr).bDV ==  pcCU->getDvInfo(0).bDV);
1431    cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
1432  }
1433#else
1434  assert(0); // ARP can be applied only when a DV is available
1435#endif
1436
1437  UChar dW = cDistparity.bDV ? pcCU->getARPW ( uiPartAddr ) : 0;
1438
1439  if( cDistparity.bDV ) 
1440  {
1441    Int arpRefIdx = pcCU->getSlice()->getFirstTRefIdx(eRefPicList);
1442    if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() )
1443    {
1444      bTobeScaled = true;
1445    }
1446
1447    pcPicYuvBaseCol =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(),                              cDistparity.m_aVIdxCan );
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))
1452    {
1453      dW = 0;
1454      bTobeScaled = false;
1455    }
1456    else
1457    {
1458      assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC() );
1459    }
1460
1461    if(bTobeScaled)
1462    {     
1463      Int iCurrPOC    = pcCU->getSlice()->getPOC();
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 )
1468      {
1469        cMv = cMv.scaleMv( iScale );
1470      }
1471      iRefIdx = 0;
1472    }
1473  }
1474
1475  pcCU->clipMv(cMv);
1476  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec();
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
1481  xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
1482  xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
1483#endif
1484  if( dW > 0 )
1485  {
1486    TComYuv * pYuvB0 = &m_acYuvPredBase[0];
1487    TComYuv * pYuvB1  = &m_acYuvPredBase[1];
1488
1489    TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV;
1490    pcCU->clipMv(cMVwithDisparity);
1491#if SHARP_ARP_CHROMA_I0104
1492    if (iWidth <= 8)
1493    {
1494      pYuvB0->clear(); pYuvB1->clear();
1495    }
1496#endif
1497
1498    assert ( cDistparity.bDV );
1499   
1500#if NTT_BUG_FIX_TK54
1501    TComMv cNBDV = cDistparity.m_acNBDV;
1502    pcCU->clipMv( cNBDV );
1503   
1504    pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec();
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
1512    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, bi, true );
1513    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, bi, true );
1514#endif
1515#else
1516    pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec();
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 );
1519#endif
1520   
1521    pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec();
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
1529    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
1530    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
1531#endif
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 );
1539  }
1540}
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
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);
1640
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 );
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    }
1683
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
1711  if(!pColCU->isIntra(uiAbsPartAddr))
1712#endif
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);
1725#if MTK_I0072_IVARP_SCALING_FIX
1726        if (iCurrRef >= 0 && iCurrRefPOC != iCurrPOC)
1727#else
1728        if( iCurrRef >= 0)
1729#endif
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  }
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
1760  xPredInterLumaBlk  ( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi,        bTMVAvai);
1761  xPredInterChromaBlk( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi,        bTMVAvai);
1762#endif
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);
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
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
1796#endif
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
1808Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
1809{
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    {
1828      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
1829    }
1830    else
1831    {
1832      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) || 
1833           ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
1834      {
1835        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
1836      }
1837      else
1838      {
1839        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
1840      }
1841    }
1842  }
1843
1844  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE  )
1845  {
1846    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1847  } 
1848  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
1849  {
1850    xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); 
1851  }
1852  else
1853  {
1854    xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1855  }
1856}
1857
1858#if H_3D_VSP
1859
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);
1865
1866  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
1867  {
1868    RefPicList eRefPicList = RefPicList(iRefList);
1869    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
1870
1871    if ( iRefIdx[iRefList] < 0 )
1872    {
1873      continue;
1874    }
1875    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
1876
1877    pcMbYuv = &m_acYuvPred[iRefList];
1878    xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi );
1879  }
1880
1881  xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1882}
1883
1884#endif
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 */
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
1901#endif
1902#if H_3D_IC
1903    , Bool bICFlag
1904#endif
1905  )
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
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  }
1925#endif
1926  if ( yFrac == 0 )
1927  {
1928#if H_3D_IC
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
1932#endif
1933#if H_3D_ARP
1934    , filterType
1935#endif
1936      );
1937  }
1938  else if ( xFrac == 0 )
1939  {
1940#if H_3D_IC
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
1944#endif
1945#if H_3D_ARP
1946    , filterType
1947#endif
1948      );
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
1958    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     
1959#if H_3D_ARP
1960    , filterType
1961#endif
1962      );
1963#if H_3D_IC
1964    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi || bICFlag
1965#else
1966    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi
1967#endif
1968#if H_3D_ARP
1969    , filterType
1970#endif
1971      );   
1972  }
1973
1974#if H_3D_IC
1975  if( bICFlag )
1976  {
1977    Int a, b, i, j;
1978    const Int iShift = IC_CONST_SHIFT;
1979
1980    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA );
1981
1982
1983    for ( i = 0; i < height; i++ )
1984    {
1985      for ( j = 0; j < width; j++ )
1986      {
1987          dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
1988      }
1989      dst += dstStride;
1990    }
1991
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    }
2006  }
2007#endif
2008}
2009
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 */
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
2025#endif
2026#if H_3D_IC
2027    , Bool bICFlag
2028#endif
2029  )
2030{
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  {
2056#if H_3D_IC
2057    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
2058#else
2059    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi
2060#endif
2061#if H_3D_ARP
2062    , filterType
2063#endif
2064    );   
2065#if H_3D_IC
2066    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
2067#else
2068    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi
2069#endif
2070#if H_3D_ARP
2071    , filterType
2072#endif
2073    );
2074  }
2075  else if ( xFrac == 0 )
2076  {
2077#if H_3D_IC
2078    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
2079#else
2080    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi
2081#endif
2082#if H_3D_ARP
2083    , filterType
2084#endif
2085    );
2086#if H_3D_IC
2087    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
2088#else
2089    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi
2090#endif
2091#if H_3D_ARP
2092    , filterType
2093#endif
2094    );
2095  }
2096  else
2097  {
2098    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
2099#if H_3D_ARP
2100    , filterType
2101#endif 
2102      );
2103#if H_3D_IC
2104    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
2105#else
2106    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
2107#endif
2108#if H_3D_ARP
2109    , filterType
2110#endif
2111      );
2112   
2113    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
2114#if H_3D_ARP
2115    , filterType
2116#endif
2117      );
2118#if H_3D_IC
2119    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
2120#else
2121    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
2122#endif
2123#if H_3D_ARP
2124    , filterType
2125#endif
2126      );   
2127  }
2128
2129#if H_3D_IC
2130  if( bICFlag )
2131  {
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++ )
2136    {
2137      for ( j = 0; j < cxWidth; j++ )
2138      {
2139          dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
2140      }
2141      dstCb += dstStride;
2142    }
2143    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr
2144    for ( i = 0; i < cxHeight; i++ )
2145    {
2146      for ( j = 0; j < cxWidth; j++ )
2147      {
2148          dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
2149      }
2150      dstCr += dstStride;
2151    }
2152
2153    if(bi)
2154    {
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++)
2159      {
2160        for (j = 0; j < cxWidth; j++)
2161        {
2162          Short val = dstCb2[j] << shift;
2163          dstCb2[j] = val - (Short)IF_INTERNAL_OFFS;
2164
2165          val = dstCr2[j] << shift;
2166          dstCr2[j] = val - (Short)IF_INTERNAL_OFFS;
2167        }
2168        dstCb2 += dstStride;
2169        dstCr2 += dstStride;
2170      }
2171    }
2172  }
2173#endif
2174}
2175
2176Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
2177{
2178  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
2179  {
2180    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
2181  }
2182  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
2183  {
2184    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
2185  }
2186  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
2187  {
2188    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
2189  }
2190}
2191
2192// AMVP
2193Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
2194{
2195  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
2196  if( pcAMVPInfo->iN <= 1 )
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;
2226  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
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++)
2255    {
2256      horPred += rightColumn[k];
2257      topRow[l] += bottomRow[l];
2258      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
2259    }
2260  }
2261}
2262
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
2270 *
2271 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
2272 */
2273Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
2274{
2275  Pel* pDst = rpDst;
2276  Int x, y, iDstStride2, iSrcStride2;
2277
2278  // boundary pixels processing
2279  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
2280
2281  for ( x = 1; x < iWidth; x++ )
2282  {
2283    pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
2284  }
2285
2286  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
2287  {
2288    pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
2289  }
2290
2291  return;
2292}
2293#if H_3D_IC
2294/** Function for deriving the position of first non-zero binary bit of a value
2295 * \param x input value
2296 *
2297 * This function derives the position of first non-zero binary bit of a value
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
2321/** Function for deriving LM illumination compensation.
2322 */
2323Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType )
2324{
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();
2330#if SEC_IC_NEIGHBOR_CLIP_I0080
2331  Int iRefOffset, iHor, iVer;
2332#else
2333  Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer;
2334
2335  iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
2336  iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
2337#endif
2338  iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 );
2339  iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 );
2340#if !SEC_IC_NEIGHBOR_CLIP_I0080
2341  iRefX   = iCUPelX + iHor;
2342  iRefY   = iCUPelY + iVer;
2343#endif
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 );
2351
2352  Int i, j, iCountShift = 0;
2353
2354  // LLS parameters estimation -->
2355
2356  Int x = 0, y = 0, xx = 0, xy = 0;
2357  Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12);
2358
2359#if SEC_IC_NEIGHBOR_CLIP_I0080
2360  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) )
2361#else
2362  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 )
2363#endif
2364  {
2365    iRefOffset = iHor + iVer * iRefStride - iRefStride;
2366    if( eType == TEXT_LUMA )
2367    {
2368      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2369      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
2370    }
2371    else if( eType == TEXT_CHROMA_U )
2372    {
2373      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2374      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
2375    }
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    }
2382
2383    for( j = 0; j < uiWidth; j+=2 )
2384    {
2385      x += pRef[j];
2386      y += pRec[j];
2387      xx += (pRef[j] * pRef[j])>>precShift;
2388      xy += (pRef[j] * pRec[j])>>precShift;
2389    }
2390    iCountShift += g_aucConvertToBit[ uiWidth ] + 1;
2391  }
2392
2393#if SEC_IC_NEIGHBOR_CLIP_I0080
2394  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) )
2395#else
2396  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 )
2397#endif
2398  {
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 )
2418    {
2419      x += pRef[0];
2420      y += pRec[0];
2421
2422      xx += (pRef[0] * pRef[0])>>precShift;
2423      xy += (pRef[0] * pRec[0])>>precShift;
2424
2425      pRef += iRefStride*2;
2426      pRec += iRecStride*2;
2427    }
2428    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 );
2429  }
2430
2431  xy += xx >> IC_REG_COST_SHIFT;
2432  xx += xx >> IC_REG_COST_SHIFT;
2433  Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift);
2434  Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift);
2435  const Int iShift = IC_CONST_SHIFT;
2436  {
2437    {
2438      const Int iShiftA2 = 6;
2439      const Int iAccuracyShift = 15;
2440
2441      Int iScaleShiftA2 = 0;
2442      Int iScaleShiftA1 = 0;
2443      Int a1s = a1;
2444      Int a2s = a2;
2445
2446      a1 = Clip3(0, 2*a2, a1);
2447      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2;
2448      iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF;
2449
2450      if( iScaleShiftA1 < 0 )
2451      {
2452        iScaleShiftA1 = 0;
2453      }
2454
2455      if( iScaleShiftA2 < 0 )
2456      {
2457        iScaleShiftA2 = 0;
2458      }
2459
2460      Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
2461
2462
2463      a2s = a2 >> iScaleShiftA2;
2464
2465      a1s = a1 >> iScaleShiftA1;
2466
2467      a = a1s * m_uiaShift[ a2s ];
2468      a = a >> iScaleShiftA;
2469      b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
2470    }
2471  }   
2472}
2473#endif
2474
2475#if H_3D_DIM
2476Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
2477{
2478  Int  refDC1, refDC2;
2479  const Int  iTR = (   patternStride - 1        ) - srcStride;
2480  const Int  iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride;
2481  const Int  iLB = (   patternStride - 1        ) * srcStride - 1;
2482  const Int  iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1;
2483
2484  Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] );
2485  Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)]               );
2486
2487  if( bL == bT )
2488  {
2489    const Int  iTRR = ( patternStride * 2 - 1  ) - srcStride; 
2490    const Int  iLBB = ( patternStride * 2 - 1  ) * srcStride - 1;
2491    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : (abs(ptrSrc[iTRR] - ptrSrc[-(Int)srcStride]) > abs(ptrSrc[iLBB] - ptrSrc[ -1]) ? ptrSrc[iTRR] : ptrSrc[iLBB]);
2492    refDC2 =      ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1;
2493  }
2494  else
2495  {
2496    refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR];
2497    refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM];
2498  }
2499
2500  predDC1 = biSegPattern[0] ? refDC1 : refDC2;
2501  predDC2 = biSegPattern[0] ? refDC2 : refDC1;
2502}
2503
2504Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
2505{
2506  if( dstStride == patternStride )
2507  {
2508    for( UInt k = 0; k < (patternStride * patternStride); k++ )
2509    {
2510      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
2511      else                          { ptrDst[k] = valDC1; }
2512    }
2513  }
2514  else
2515  {
2516    Pel* piTemp = ptrDst;
2517    for( UInt uiY = 0; uiY < patternStride; uiY++ )
2518    {
2519      for( UInt uiX = 0; uiX < patternStride; uiX++ )
2520      {
2521        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
2522        else                            { piTemp[uiX] = valDC1; }
2523      }
2524      piTemp       += dstStride;
2525      biSegPattern += patternStride;
2526    }
2527  }
2528}
2529
2530#if H_3D_DIM_DMM
2531
2532Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
2533{
2534  pcContourWedge->clear();
2535
2536  // get copy of co-located texture luma block
2537  TComYuv cTempYuv;
2538  cTempYuv.create( uiWidth, uiHeight ); 
2539  cTempYuv.clear();
2540  Pel* piRefBlkY = cTempYuv.getLumaAddr();
2541  xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
2542  piRefBlkY = cTempYuv.getLumaAddr();
2543
2544  // find contour for texture luma block
2545  UInt iDC = 0;
2546#if SEC_DBBP_DMM4_THRESHOLD_I0076
2547  iDC  = piRefBlkY[ 0 ];
2548  iDC += piRefBlkY[ uiWidth - 1 ];
2549  iDC += piRefBlkY[ uiWidth * (uiHeight - 1) ];
2550  iDC += piRefBlkY[ uiWidth * (uiHeight - 1) + uiWidth - 1 ];
2551  iDC = iDC >> 2;
2552#else
2553  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2554  { 
2555    iDC += piRefBlkY[k]; 
2556  }
2557
2558  Int cuMaxLog2Size = g_aucConvertToBit[g_uiMaxCUWidth]+2;   //
2559  iDC = iDC >> (cuMaxLog2Size - pcCU->getDepth(0))*2;        //  iDC /= (uiWidth*uiHeight);
2560#endif
2561
2562  piRefBlkY = cTempYuv.getLumaAddr();
2563
2564  Bool* pabContourPattern = pcContourWedge->getPattern();
2565  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2566  { 
2567    pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
2568  }
2569
2570  cTempYuv.destroy();
2571}
2572
2573
2574Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
2575{
2576  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
2577  assert( pcPicYuvRef != NULL );
2578  Int         iRefStride = pcPicYuvRef->getStride();
2579  Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2580
2581  for ( Int y = 0; y < uiHeight; y++ )
2582  {
2583    ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
2584    piDestBlockY += uiWidth;
2585    piRefY += iRefStride;
2586  }
2587}
2588#endif
2589
2590
2591#if H_3D_DIM_SDC
2592Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
2593                                         ,UInt uiIntraMode
2594                                         ,Bool orgDC
2595                                        )
2596{
2597  Int iSumDepth[2];
2598  memset(iSumDepth, 0, sizeof(Int)*2);
2599  Int iSumPix[2];
2600  memset(iSumPix, 0, sizeof(Int)*2);
2601  for( Int i = 0; i < uiNumSegments; i++ )
2602  {
2603    rpSegMeans[i] = 0;
2604  }
2605  if (orgDC == false)
2606  {
2607    Pel* pLeftTop = pOrig;
2608    Pel* pRightTop = pOrig + (uiSize-1);
2609    Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1)));
2610    Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1));
2611
2612    rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
2613    return;
2614  }
2615
2616  Int subSamplePix;
2617  if ( uiSize == 64 || uiSize == 32 )
2618  {
2619    subSamplePix = 2;
2620  }
2621  else
2622  {
2623    subSamplePix = 1;
2624  }
2625  for (Int y=0; y<uiSize; y+=subSamplePix)
2626  {
2627    for (Int x=0; x<uiSize; x+=subSamplePix)
2628    {
2629      UChar ucSegment = pMask?(UChar)pMask[x]:0;
2630      assert( ucSegment < uiNumSegments );
2631     
2632      iSumDepth[ucSegment] += pOrig[x];
2633      iSumPix[ucSegment]   += 1;
2634    }
2635   
2636    pOrig  += uiStride*subSamplePix;
2637    pMask  += uiMaskStride*subSamplePix;
2638  }
2639 
2640  // compute mean for each segment
2641  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
2642  {
2643    if( iSumPix[ucSeg] > 0 )
2644      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
2645    else
2646      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
2647  }
2648}
2649#endif // H_3D_DIM_SDC
2650#endif
2651//! \}
Note: See TracBrowser for help on using the repository browser.