source: 3DVCSoftware/branches/HTM-10.2-dev0/source/Lib/TLibCommon/TComPrediction.cpp @ 939

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

Merged 10.2-dev3-HiSilicon@928.

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