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

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

Merged 9.3-dev0@831.

  • Property svn:eol-style set to native
File size: 82.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-2013, 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
419#if QC_GENERIC_SDC_G0122
420  , TComWedgelet* dmm4Segmentation
421#endif
422  )
423{
424  assert( iWidth == iHeight  );
425  assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE );
426  assert( isDimMode( uiIntraMode ) );
427
428  UInt dimType    = getDimType  ( uiIntraMode );
429  Bool dimDeltaDC = isDimDeltaDC( uiIntraMode );   
430  Bool isDmmMode  = (dimType <  DMM_NUM_TYPE);
431
432  Bool* biSegPattern  = NULL;
433  UInt  patternStride = 0;
434
435  // get partiton
436#if H_3D_DIM_DMM
437  TComWedgelet* dmmSegmentation = NULL;
438  if( isDmmMode )
439  {
440    switch( dimType )
441    {
442    case( DMM1_IDX ): 
443      {
444        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]);
445      } break;
446    case( DMM4_IDX ): 
447      {
448#if QC_GENERIC_SDC_G0122
449        if( dmm4Segmentation == NULL )
450        { 
451          dmmSegmentation = new TComWedgelet( iWidth, iHeight );
452          xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
453        }
454        else
455        {
456          xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmm4Segmentation );
457          dmmSegmentation = dmm4Segmentation;
458        }
459#else
460        dmmSegmentation = new TComWedgelet( iWidth, iHeight );
461        xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
462#endif
463      } break;
464    default: assert(0);
465    }
466    assert( dmmSegmentation );
467    biSegPattern  = dmmSegmentation->getPattern();
468    patternStride = dmmSegmentation->getStride ();
469  }
470#endif
471
472  // get predicted partition values
473  assert( biSegPattern );
474  Int* piMask = NULL;
475  piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering
476  assert( piMask );
477  Int maskStride = 2*iWidth + 1; 
478  Int* ptrSrc = piMask+maskStride+1;
479  Pel predDC1 = 0; Pel predDC2 = 0;
480  xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 );
481
482  // set segment values with deltaDC offsets
483  Pel segDC1 = 0;
484  Pel segDC2 = 0;
485  if( dimDeltaDC )
486  {
487    Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx );
488    Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx );
489#if H_3D_DIM_DMM
490    if( isDmmMode )
491    {
492#if H_3D_DIM_DLT
493      segDC1 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 );
494      segDC2 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 );
495#else
496      segDC1 = ClipY( predDC1 + deltaDC1 );
497      segDC2 = ClipY( predDC2 + deltaDC2 );
498#endif
499    }
500#endif
501  }
502  else
503  {
504    segDC1 = predDC1;
505    segDC2 = predDC2;
506  }
507
508  // set prediction signal
509  Pel* pDst = piPred;
510  xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 );
511
512#if H_3D_DIM_DMM
513#if QC_GENERIC_SDC_G0122
514  if( dimType == DMM4_IDX && dmm4Segmentation == NULL ) { dmmSegmentation->destroy(); delete dmmSegmentation; }
515#else
516  if( dimType == DMM4_IDX ) { dmmSegmentation->destroy(); delete dmmSegmentation; }
517#endif
518#endif
519}
520#endif
521
522/** Function for checking identical motion.
523 * \param TComDataCU* pcCU
524 * \param UInt PartAddr
525 */
526Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr )
527{
528  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() )
529  {
530    if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0)
531    {
532      Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
533      Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
534      if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
535      {
536        return true;
537      }
538    }
539  }
540  return false;
541}
542
543#if H_3D_SPIVMP
544Void TComPrediction::xGetSubPUAddrAndMerge(TComDataCU* pcCU, UInt uiPartAddr, Int iSPWidth, Int iSPHeight, Int iNumSPInOneLine, Int iNumSP, UInt* uiMergedSPW, UInt* uiMergedSPH, UInt* uiSPAddr )
545{
546  for (Int i = 0; i < iNumSP; i++)
547  {
548    uiMergedSPW[i] = iSPWidth;
549    uiMergedSPH[i] = iSPHeight;
550    pcCU->getSPAbsPartIdx(uiPartAddr, iSPWidth, iSPHeight, i, iNumSPInOneLine, uiSPAddr[i]);
551  }
552  // horizontal sub-PU merge
553  for (Int i=0; i<iNumSP; i++)
554  {
555    if (i % iNumSPInOneLine == iNumSPInOneLine - 1 || uiMergedSPW[i]==0 || uiMergedSPH[i]==0)
556    {
557      continue;
558    }
559    for (Int j=i+1; j<i+iNumSPInOneLine-i%iNumSPInOneLine; j++)
560    {
561      if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j]))
562      {
563        uiMergedSPW[i] += iSPWidth;
564        uiMergedSPW[j] = uiMergedSPH[j] = 0;
565      }
566      else
567      {
568        break;
569      }
570    }
571  }
572  //vertical sub-PU merge
573  for (Int i=0; i<iNumSP-iNumSPInOneLine; i++)
574  {
575    if (uiMergedSPW[i]==0 || uiMergedSPH[i]==0)
576    {
577      continue;
578    }
579    for (Int j=i+iNumSPInOneLine; j<iNumSP; j+=iNumSPInOneLine)
580    {
581      if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j]) && uiMergedSPW[i]==uiMergedSPW[j])
582      {
583        uiMergedSPH[i] += iSPHeight;
584        uiMergedSPH[j] = uiMergedSPW[j] = 0;
585      }
586      else
587      {
588        break;
589      }
590    }
591  }
592}
593
594Bool TComPrediction::xCheckTwoSPMotion ( TComDataCU* pcCU, UInt PartAddr0, UInt PartAddr1 )
595{
596  if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr1))
597  {
598    return false;
599  }
600  if( pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr1))
601  {
602    return false;
603  }
604
605  if (pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) >= 0)
606  {
607    if (pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr1))
608    {
609      return false;
610    }
611  }
612
613  if (pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) >= 0)
614  {
615    if (pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr1))
616    {
617      return false;
618    }
619  }
620  return true;
621}
622#endif
623
624#if H_3D_DBBP
625PartSize TComPrediction::getPartitionSizeFromDepth(Pel* pDepthPels, UInt uiDepthStride, UInt uiSize)
626{
627  // find virtual partitioning for this CU based on depth block
628  // segmentation of texture block --> mask IDs
629  Pel*  pDepthBlockStart      = pDepthPels;
630 
631  // first compute average of depth block for thresholding
632  Int iSumDepth = 0;
633  Int iSubSample = 4;
634  for (Int y=0; y<uiSize; y+=iSubSample)
635  {
636    for (Int x=0; x<uiSize; x+=iSubSample)
637    {
638      Int depthPel = pDepthPels[x];
639     
640      iSumDepth += depthPel;
641    }
642   
643    // next row
644    pDepthPels += uiDepthStride*iSubSample;
645  }
646 
647  Int iSizeInBits = g_aucConvertToBit[uiSize] - g_aucConvertToBit[iSubSample];  // respect sub-sampling factor
648  Int iMean = iSumDepth >> iSizeInBits*2;       // iMean /= (uiSize*uiSize);
649 
650  // start again for segmentation
651  pDepthPels = pDepthBlockStart;
652 
653  // start mapping process
654  Bool bAMPAvail = uiSize > 8;
655  Int matchedPartSum[6][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}; // counter for each part size and boolean option
656  PartSize virtualPartSizes[6] = { SIZE_Nx2N, SIZE_2NxN, SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N };
657 
658  UInt uiHalfSize = uiSize>>1;
659  UInt uiQuarterSize = uiSize>>2;
660 
661  for (Int y=0; y<uiSize; y+=iSubSample)
662  {
663    for (Int x=0; x<uiSize; x+=iSubSample)
664    {
665      Int depthPel = pDepthPels[x];
666     
667      // decide which segment this pixel belongs to
668      Int ucSegment = (Int)(depthPel>iMean);
669     
670      // Matched Filter to find optimal (conventional) partitioning
671     
672      // SIZE_Nx2N
673      if(x<uiHalfSize)  // left
674      {
675        matchedPartSum[0][ucSegment]++;
676      }
677      else  // right
678      {
679        matchedPartSum[0][1-ucSegment]++;
680      }
681     
682      // SIZE_2NxN
683      if(y<uiHalfSize)  // top
684      {
685        matchedPartSum[1][ucSegment]++;
686      }
687      else  // bottom
688      {
689        matchedPartSum[1][1-ucSegment]++;
690      }
691     
692      if( bAMPAvail )
693      {
694        // SIZE_2NxnU
695        if(y<uiQuarterSize)  // top (1/4)
696        {
697          matchedPartSum[2][ucSegment]++;
698        }
699        else  // bottom (3/4)
700        {
701          matchedPartSum[2][1-ucSegment]++;
702        }
703       
704        // SIZE_2NxnD
705        if(y<(uiQuarterSize*3))  // top (3/4)
706        {
707          matchedPartSum[3][ucSegment]++;
708        }
709        else  // bottom (1/4)
710        {
711          matchedPartSum[3][1-ucSegment]++;
712        }
713       
714        // SIZE_nLx2N
715        if(x<uiQuarterSize)  // left (1/4)
716        {
717          matchedPartSum[4][ucSegment]++;
718        }
719        else  // right (3/4)
720        {
721          matchedPartSum[4][1-ucSegment]++;
722        }
723       
724        // SIZE_nRx2N
725        if(x<(uiQuarterSize*3))  // left (3/4)
726        {
727          matchedPartSum[5][ucSegment]++;
728        }
729        else  // right (1/4)
730        {
731          matchedPartSum[5][1-ucSegment]++;
732        }
733      }
734    }
735   
736    // next row
737    pDepthPels += uiDepthStride*iSubSample;
738  }
739 
740  PartSize matchedPartSize = SIZE_NONE;
741 
742  Int iMaxMatchSum = 0;
743  for(Int p=0; p<6; p++)  // loop over partition sizes
744  {
745    for( Int b=0; b<=1; b++ ) // loop over boolean options
746    {
747      if(matchedPartSum[p][b] > iMaxMatchSum)
748      {
749        iMaxMatchSum = matchedPartSum[p][b];
750        matchedPartSize = virtualPartSizes[p];
751      }
752    }
753  }
754 
755  AOF( matchedPartSize != SIZE_NONE );
756 
757  return matchedPartSize;
758}
759
760Bool TComPrediction::getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask )
761{
762  // segmentation of texture block --> mask IDs
763  Pel*  pDepthBlockStart      = pDepthPels;
764 
765  // first compute average of depth block for thresholding
766  Int iSumDepth = 0;
767  Int uiMinDepth = MAX_INT;
768  Int uiMaxDepth = 0;
769  for (Int y=0; y<uiHeight; y++)
770  {
771    for (Int x=0; x<uiWidth; x++)
772    {
773      Int depthPel = pDepthPels[x];
774      iSumDepth += depthPel;
775     
776      if( depthPel > uiMaxDepth )
777      {
778        uiMaxDepth = depthPel;
779      }
780      if( depthPel < uiMinDepth )
781      {
782        uiMinDepth = depthPel;
783      }
784    }
785   
786    // next row
787    pDepthPels += uiDepthStride;
788  }
789 
790  // don't generate mask for blocks with small depth range (encoder decision)
791  if( uiMaxDepth - uiMinDepth < 10 )
792  {
793    return false;
794  }
795 
796  AOF(uiWidth==uiHeight);
797  Int iSizeInBits = g_aucConvertToBit[uiWidth]+2;
798  Int iMean = iSumDepth >> iSizeInBits*2;       // iMean /= (uiWidth*uiHeight);
799 
800  // start again for segmentation
801  pDepthPels = pDepthBlockStart;
802 
803  Bool bInvertMask = pDepthPels[0]>iMean; // top-left segment needs to be mapped to partIdx 0
804 
805  // generate mask
806  UInt uiSumPix[2] = {0,0};
807  for (Int y=0; y<uiHeight; y++)
808  {
809    for (Int x=0; x<uiHeight; x++)
810    {
811      Int depthPel = pDepthPels[x];
812     
813      // decide which segment this pixel belongs to
814      Int ucSegment = (Int)(depthPel>iMean);
815     
816      if( bInvertMask )
817      {
818        ucSegment = 1-ucSegment;
819      }
820     
821      // count pixels for each segment
822      uiSumPix[ucSegment]++;
823     
824      // set mask value
825      pMask[x] = (Bool)ucSegment;
826    }
827   
828    // next row
829    pDepthPels += uiDepthStride;
830    pMask += MAX_CU_SIZE;
831  }
832 
833  // don't generate valid mask for tiny segments (encoder decision)
834  // each segment needs to cover at least 1/8th of block
835  UInt uiMinPixPerSegment = (uiWidth*uiHeight) >> 3;
836  if( !( uiSumPix[0] > uiMinPixPerSegment && uiSumPix[1] > uiMinPixPerSegment ) )
837  {
838    return false;
839  }
840 
841  // all good
842  return true;
843}
844
845Void TComPrediction::combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr )
846{
847  Pel*  piSrc[2]    = {pInYuv[0]->getLumaAddr(uiPartAddr), pInYuv[1]->getLumaAddr(uiPartAddr)};
848  UInt  uiSrcStride = pInYuv[0]->getStride();
849  Pel*  piDst       = pOutYuv->getLumaAddr(uiPartAddr);
850  UInt  uiDstStride = pOutYuv->getStride();
851 
852  UInt  uiMaskStride= MAX_CU_SIZE;
853 
854  // backup pointer
855  Bool* pMaskStart = pMask;
856 
857  // combine luma first
858  for (Int y=0; y<uiHeight; y++)
859  {
860    for (Int x=0; x<uiWidth; x++)
861    {
862      UChar ucSegment = (UChar)pMask[x];
863      AOF( ucSegment < 2 );
864     
865      // filtering
866      Bool t = (y==0)?pMaskStart[(y+1)*uiMaskStride+x]:pMaskStart[(y-1)*uiMaskStride+x];
867      Bool l = (x==0)?pMaskStart[y*uiMaskStride+x+1]:pMaskStart[y*uiMaskStride+x-1];
868      Bool b = (y==uiHeight-1)?pMaskStart[(y-1)*uiMaskStride+x]:pMaskStart[(y+1)*uiMaskStride+x];
869      Bool r = (x==uiWidth-1)?pMaskStart[y*uiMaskStride+x-1]:pMaskStart[y*uiMaskStride+x+1];
870     
871      Bool bBlend = !((t&&l&&b&&r) || (!t&&!l&&!b&&!r));
872      piDst[x] = bBlend?((piSrc[0][x]+piSrc[1][x]+1)>>1):piSrc[ucSegment][x];
873    }
874   
875    piSrc[0]  += uiSrcStride;
876    piSrc[1]  += uiSrcStride;
877    piDst     += uiDstStride;
878    pMask     += uiMaskStride;
879  }
880 
881  // now combine chroma
882  Pel*  piSrcU[2]       = { pInYuv[0]->getCbAddr(uiPartAddr), pInYuv[1]->getCbAddr(uiPartAddr) };
883  Pel*  piSrcV[2]       = { pInYuv[0]->getCrAddr(uiPartAddr), pInYuv[1]->getCrAddr(uiPartAddr) };
884  UInt  uiSrcStrideC    = pInYuv[0]->getCStride();
885  Pel*  piDstU          = pOutYuv->getCbAddr(uiPartAddr);
886  Pel*  piDstV          = pOutYuv->getCrAddr(uiPartAddr);
887  UInt  uiDstStrideC    = pOutYuv->getCStride();
888  UInt  uiWidthC        = uiWidth >> 1;
889  UInt  uiHeightC       = uiHeight >> 1;
890  pMask = pMaskStart;
891 
892  for (Int y=0; y<uiHeightC; y++)
893  {
894    for (Int x=0; x<uiWidthC; x++)
895    {
896      UChar ucSegment = (UChar)pMask[x*2];
897      AOF( ucSegment < 2 );
898     
899      // filtering
900      Bool t = (y==0)?pMaskStart[(y+1)*2*uiMaskStride+x*2]:pMaskStart[(y-1)*2*uiMaskStride+x*2];
901      Bool l = (x==0)?pMaskStart[y*2*uiMaskStride+(x+1)*2]:pMaskStart[y*2*uiMaskStride+(x-1)*2];
902      Bool b = (y==uiHeightC-1)?pMaskStart[(y-1)*2*uiMaskStride+x*2]:pMaskStart[(y+1)*2*uiMaskStride+x*2];
903      Bool r = (x==uiWidthC-1)?pMaskStart[y*2*uiMaskStride+(x-1)*2]:pMaskStart[y*2*uiMaskStride+(x+1)*2];
904     
905      Bool bBlend = !((t&&l&&b&&r) || (!t&&!l&&!b&&!r));
906     
907      piDstU[x] = bBlend?((piSrcU[0][x]+piSrcU[1][x]+1)>>1):piSrcU[ucSegment][x];
908      piDstV[x] = bBlend?((piSrcV[0][x]+piSrcV[1][x]+1)>>1):piSrcV[ucSegment][x];
909    }
910   
911    piSrcU[0]   += uiSrcStrideC;
912    piSrcU[1]   += uiSrcStrideC;
913    piSrcV[0]   += uiSrcStrideC;
914    piSrcV[1]   += uiSrcStrideC;
915    piDstU      += uiDstStrideC;
916    piDstV      += uiDstStrideC;
917    pMask       += 2*uiMaskStride;
918  }
919}
920#endif
921
922Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
923{
924  Int         iWidth;
925  Int         iHeight;
926  UInt        uiPartAddr;
927
928  if ( iPartIdx >= 0 )
929  {
930    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
931#if H_3D_VSP
932    if ( pcCU->getVSPFlag(uiPartAddr) == 0)
933    {
934#endif
935      if ( eRefPicList != REF_PIC_LIST_X )
936      {
937        if( pcCU->getSlice()->getPPS()->getUseWP())
938        {
939          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
940        }
941        else
942        {
943          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
944        }
945        if ( pcCU->getSlice()->getPPS()->getUseWP() )
946        {
947          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
948        }
949      }
950      else
951      {
952#if H_3D_SPIVMP
953        if ( pcCU->getSPIVMPFlag(uiPartAddr)!=0) 
954        {
955          Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
956
957          pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
958
959          UInt uiW[256], uiH[256];
960          UInt uiSPAddr[256];
961
962          xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr);
963
964          //MC
965          for (Int i = 0; i < iNumSP; i++)
966          {
967            if (uiW[i]==0 || uiH[i]==0)
968            {
969              continue;
970            }
971            if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] ))
972            {
973              xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred );
974            }
975            else
976            {
977              xPredInterBi  (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred);
978            }
979          }
980        }
981        else
982        {
983#endif
984          if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
985          {
986            xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
987          }
988          else
989          {
990            xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
991          }
992#if H_3D_SPIVMP
993        }
994#endif
995      }
996#if H_3D_VSP
997    }
998    else
999    {
1000      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
1001      {
1002        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
1003      }
1004      else
1005      {
1006        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
1007      }
1008    }
1009#endif
1010    return;
1011  }
1012
1013  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
1014  {
1015    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
1016
1017#if H_3D_VSP
1018    if ( pcCU->getVSPFlag(uiPartAddr) == 0 )
1019    {
1020#endif
1021      if ( eRefPicList != REF_PIC_LIST_X )
1022      {
1023        if( pcCU->getSlice()->getPPS()->getUseWP())
1024        {
1025          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
1026        }
1027        else
1028        {
1029          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
1030        }
1031        if ( pcCU->getSlice()->getPPS()->getUseWP() )
1032        {
1033          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
1034        }
1035      }
1036      else
1037      {
1038#if H_3D_SPIVMP
1039       if (pcCU->getSPIVMPFlag(uiPartAddr)!=0) 
1040      {
1041        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
1042
1043        pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
1044
1045        UInt uiW[256], uiH[256];
1046        UInt uiSPAddr[256];
1047
1048        xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr);
1049        //MC
1050        for (Int i = 0; i < iNumSP; i++)
1051        {
1052          if (uiW[i]==0 || uiH[i]==0)
1053          {
1054            continue;
1055          }
1056          if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] ))
1057          {
1058            xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred );
1059          }
1060          else
1061          {
1062            xPredInterBi  (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred);
1063          }
1064        }
1065      }
1066      else
1067      {
1068#endif
1069        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
1070        {
1071          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
1072        }
1073        else
1074        {
1075          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
1076        }
1077#if H_3D_SPIVMP
1078       }
1079#endif
1080      }
1081#if H_3D_VSP
1082    }
1083    else
1084    {
1085      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
1086      {
1087        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
1088      }
1089      else
1090      {
1091        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
1092      }
1093    }
1094#endif
1095  }
1096  return;
1097}
1098
1099Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
1100{
1101  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
1102  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
1103  pcCU->clipMv(cMv);
1104
1105#if MTK_DDD_G0063
1106  if( pcCU->getUseDDD( uiPartAddr ) )
1107  {
1108      assert( pcCU->getSPIVMPFlag( uiPartAddr ) == 0 );
1109      assert( pcCU->getSlice()->getViewIndex() != 0 );
1110
1111      Int dstStride = rpcYuvPred->getStride();
1112      Int dstStrideC = rpcYuvPred->getCStride();
1113      Pel *dst      = rpcYuvPred->getLumaAddr( uiPartAddr );
1114      Pel *dstU     = rpcYuvPred->getCbAddr( uiPartAddr );
1115      Pel *dstV     = rpcYuvPred->getCrAddr( uiPartAddr );
1116
1117      Int iWidthC  = iWidth >> 1;
1118      Int iHeightC = iHeight >> 1;
1119      Int DefaultC = 1 << ( g_bitDepthY - 1);
1120      for ( Int i = 0; i < iHeight; i++)
1121      {
1122          for ( Int j = 0; j < iWidth ; j++)
1123          {
1124              dst[j] = pcCU->getDDDepth( uiPartAddr );
1125          }
1126          dst += dstStride;
1127      }
1128      for ( Int i = 0; i < iHeightC; i++)
1129      {
1130          for ( Int j = 0; j < iWidthC; j++)
1131          {
1132              dstU[j] = dstV[j] = DefaultC;
1133          }
1134          dstU += dstStrideC;
1135          dstV += dstStrideC;
1136      }
1137
1138      //return;
1139  } else
1140#endif
1141#if H_3D_ARP
1142  if(pcCU->getARPW( uiPartAddr ) > 0  && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC())
1143  {
1144    xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , rpcYuvPred , bi );
1145  }
1146  else
1147  {
1148    if(  pcCU->getARPW( uiPartAddr ) > 0 
1149      && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N
1150      && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() 
1151      )
1152    {
1153      xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi );
1154    }
1155    else
1156    {
1157#endif
1158#if H_3D_IC
1159      Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() );
1160      xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
1161#if H_3D_ARP
1162        , false
1163#endif
1164        , bICFlag );
1165      bICFlag = bICFlag && (iWidth > 8);
1166      xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
1167#if H_3D_ARP
1168        , false
1169#endif
1170        , bICFlag );
1171#else
1172      xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
1173      xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
1174#endif
1175#if H_3D_ARP
1176    }
1177  }
1178#endif
1179}
1180
1181#if H_3D_VSP
1182Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
1183{
1184#if NTT_STORE_SPDV_VSP_G0148
1185  Int vspSize = pcCU->getVSPFlag( uiPartAddr ) >> 1;
1186
1187  Int widthSubPU, heightSubPU;
1188  if (vspSize)
1189  {
1190    widthSubPU  = 8;
1191    heightSubPU = 4;
1192  }
1193  else
1194  {
1195    widthSubPU  = 4;
1196    heightSubPU = 8;
1197  }
1198  xPredInterUniSubPU( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi, widthSubPU, heightSubPU );
1199
1200#else // NTT_STORE_SPDV_VSP_G0148
1201  // Get depth reference
1202  Int       depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
1203#if H_3D_FCO_VSP_DONBDV_E0163
1204  TComPic* pRefPicBaseDepth = 0;
1205  Bool     bIsCurrDepthCoded = false;
1206  pRefPicBaseDepth  = pcCU->getSlice()->getIvPic( true, pcCU->getSlice()->getViewIndex() );
1207  if ( pRefPicBaseDepth->getPicYuvRec() != NULL  ) 
1208  {
1209    bIsCurrDepthCoded = true;
1210  }
1211  else 
1212  {
1213    pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
1214  }
1215#else
1216  TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
1217#endif
1218  assert(pRefPicBaseDepth != NULL);
1219  TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
1220  assert(pcBaseViewDepthPicYuv != NULL);
1221
1222  // Get texture reference
1223  Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
1224  assert(iRefIdx >= 0);
1225  TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx );
1226  TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
1227  assert(pcBaseViewTxtPicYuv != NULL);
1228
1229  // Initialize LUT according to the reference viewIdx
1230  Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex();
1231  Int* pShiftLUT    = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx );
1232  assert( txtRefViewIdx < pcCU->getSlice()->getViewIndex() );
1233
1234  // Do compensation
1235  TComMv cDv  = pcCU->getDvInfo(uiPartAddr).m_acNBDV;
1236  pcCU->clipMv(cDv);
1237
1238#if H_3D_FCO_VSP_DONBDV_E0163
1239  if ( bIsCurrDepthCoded )
1240  {
1241      cDv.setZero();
1242  }
1243#endif
1244  // fetch virtual depth map
1245  pcBaseViewDepthPicYuv->extendPicBorder();
1246
1247  Int vspSize=0;
1248  xGetVirtualDepth( pcCU, pcBaseViewDepthPicYuv, &cDv, uiPartAddr, iWidth, iHeight, &m_cYuvDepthOnVsp,vspSize );
1249  // sub-PU based compensation
1250  xPredInterLumaBlkFromDM   ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi, vspSize);
1251  xPredInterChromaBlkFromDM ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi, vspSize);
1252#endif // NTT_STORE_SPDV_VSP_G0148
1253}
1254
1255#if NTT_STORE_SPDV_VSP_G0148
1256Void TComPrediction::xPredInterUniSubPU( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, Int widthSubPU, Int heightSubPU )
1257{
1258  UInt numPartsInLine       = pcCU->getPic()->getNumPartInWidth();
1259  UInt horiNumPartsInSubPU  = widthSubPU >> 2;
1260  UInt vertNumPartsInSubPU  = (heightSubPU >> 2) * numPartsInLine;
1261
1262  UInt partAddrRasterLine = g_auiZscanToRaster[ uiPartAddr ];
1263
1264  for( Int posY=0; posY<iHeight; posY+=heightSubPU, partAddrRasterLine+=vertNumPartsInSubPU )
1265  {
1266    UInt partAddrRasterSubPU = partAddrRasterLine;
1267    for( Int posX=0; posX<iWidth; posX+=widthSubPU, partAddrRasterSubPU+=horiNumPartsInSubPU )
1268    {
1269      UInt    partAddrSubPU = g_auiRasterToZscan[ partAddrRasterSubPU ];
1270      Int     refIdx        = pcCU->getCUMvField( eRefPicList )->getRefIdx( partAddrSubPU );           assert (refIdx >= 0);
1271      TComMv  cMv           = pcCU->getCUMvField( eRefPicList )->getMv( partAddrSubPU );
1272      pcCU->clipMv(cMv);
1273
1274      xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi );
1275      xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi );
1276
1277    }
1278  }
1279}
1280#endif // NTT_STORE_SPDV_VSP_G0148
1281
1282#endif
1283
1284#if H_3D_ARP
1285Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
1286{
1287  Int         iRefIdx      = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
1288  TComMv      cMv          = pNewMvFiled ? pNewMvFiled->getMv()     : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
1289  Bool        bTobeScaled  = false;
1290  TComPic* pcPicYuvBaseCol = NULL;
1291  TComPic* pcPicYuvBaseRef = NULL;
1292
1293#if H_3D_NBDV
1294  DisInfo cDistparity;
1295  cDistparity.bDV           = pcCU->getDvInfo(uiPartAddr).bDV;
1296  if( cDistparity.bDV )
1297  {
1298    cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV;
1299    assert(pcCU->getDvInfo(uiPartAddr).bDV ==  pcCU->getDvInfo(0).bDV);
1300    cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
1301  }
1302#else
1303  assert(0); // ARP can be applied only when a DV is available
1304#endif
1305
1306  UChar dW = cDistparity.bDV ? pcCU->getARPW ( uiPartAddr ) : 0;
1307
1308  if( cDistparity.bDV ) 
1309  {
1310    Int arpRefIdx = pcCU->getSlice()->getFirstTRefIdx(eRefPicList);
1311    if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() )
1312    {
1313      bTobeScaled = true;
1314    }
1315
1316    pcPicYuvBaseCol =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(),                              cDistparity.m_aVIdxCan );
1317
1318    pcPicYuvBaseRef =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC(), cDistparity.m_aVIdxCan );
1319
1320    if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, cDistparity.m_aVIdxCan))
1321    {
1322      dW = 0;
1323      bTobeScaled = false;
1324    }
1325    else
1326    {
1327      assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC() );
1328    }
1329
1330    if(bTobeScaled)
1331    {     
1332      Int iCurrPOC    = pcCU->getSlice()->getPOC();
1333      Int iColRefPOC  = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx );
1334      Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList,  0);
1335      Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC);
1336      if ( iScale != 4096 )
1337      {
1338        cMv = cMv.scaleMv( iScale );
1339      }
1340      iRefIdx = 0;
1341    }
1342  }
1343
1344  pcCU->clipMv(cMv);
1345  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec();
1346  xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
1347  xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
1348
1349  if( dW > 0 )
1350  {
1351    TComYuv * pYuvB0 = &m_acYuvPredBase[0];
1352    TComYuv * pYuvB1  = &m_acYuvPredBase[1];
1353
1354    TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV;
1355    pcCU->clipMv(cMVwithDisparity);
1356
1357    assert ( cDistparity.bDV );
1358
1359    pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec();
1360    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
1361    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
1362   
1363    pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec();
1364    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
1365    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
1366
1367    pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight );
1368
1369    if( 2 == dW )
1370    {
1371      pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
1372    }
1373    rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi );
1374  }
1375}
1376Void TComPrediction::xPredInterUniARPviewRef( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
1377{
1378  Int         iRefIdx       = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
1379  TComMv      cDMv          = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
1380  TComMv      cTempDMv      = cDMv;
1381  UChar       dW            = pcCU->getARPW ( uiPartAddr );
1382
1383  TComPic* pcPicYuvBaseTRef = NULL;
1384  TComPic* pcPicYuvCurrTRef = NULL;
1385  TComPic* pcPicYuvBaseCol  = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx ); 
1386  TComPicYuv* pcYuvBaseCol  = pcPicYuvBaseCol->getPicYuvRec();   
1387  Bool bTMVAvai = false;     
1388  TComMv cBaseTMV;
1389  if( pNewMvFiled )
1390  {
1391    iRefIdx = pNewMvFiled->getRefIdx(); 
1392    cDMv = pNewMvFiled->getMv();
1393  }
1394  pcCU->clipMv(cTempDMv);
1395
1396  assert(dW > 0);
1397  if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, pcPicYuvBaseCol->getViewIndex()))
1398  {
1399    dW = 0;
1400  }
1401  Int uiLCUAddr,uiAbsPartAddr;
1402  Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2  + ((cDMv.getHor() + 2)>>2);
1403  Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2);
1404
1405  irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX);
1406  irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); 
1407  pcYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr);
1408  TComDataCU *pColCU = pcPicYuvBaseCol->getCU( uiLCUAddr );
1409
1410  if(!pColCU->isIntra(uiAbsPartAddr))
1411  {
1412    TComMvField puMVField;
1413    for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1) && !bTMVAvai; iList ++)
1414    {
1415      RefPicList eRefPicListCurr = RefPicList(iList);
1416      Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr);
1417      if( iRef != -1)
1418      {
1419        pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); 
1420        Int  iCurrPOC    = pColCU->getSlice()->getPOC();
1421        Int  iCurrRefPOC = pcPicYuvBaseTRef->getPOC();
1422        Int  iCurrRef    = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr);
1423        if( iCurrRef >= 0)
1424        {
1425          pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); 
1426          Int iTargetPOC = pcPicYuvCurrTRef->getPOC();
1427          {
1428            pcPicYuvBaseTRef =  pcCU->getSlice()->getBaseViewRefPic(iTargetPOC,  pcPicYuvBaseCol->getViewIndex() ); 
1429            if(pcPicYuvBaseTRef)
1430            {
1431              cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr);
1432              Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC);
1433              if ( iScale != 4096 )
1434                cBaseTMV = cBaseTMV.scaleMv( iScale );                 
1435              bTMVAvai = true;
1436              break;
1437            }
1438          }
1439        }
1440      }
1441    }
1442  }
1443  if (bTMVAvai == false)
1444  { 
1445    bTMVAvai = true;
1446    cBaseTMV.set(0, 0);
1447    pcPicYuvBaseTRef =  pColCU->getSlice()->getRefPic(eRefPicList,  pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); 
1448    pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic  (eRefPicList,  pcCU->getSlice()->getFirstTRefIdx(eRefPicList));     
1449  }
1450
1451  xPredInterLumaBlk  ( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi,        bTMVAvai);
1452  xPredInterChromaBlk( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi,        bTMVAvai);
1453
1454  if( dW > 0 && bTMVAvai ) 
1455  {
1456    TComYuv*    pYuvCurrTRef    = &m_acYuvPredBase[0];
1457    TComYuv*    pYuvBaseTRef    = &m_acYuvPredBase[1];
1458    TComPicYuv* pcYuvCurrTref   = pcPicYuvCurrTRef->getPicYuvRec();       
1459    TComPicYuv* pcYuvBaseTref   = pcPicYuvBaseTRef->getPicYuvRec(); 
1460    TComMv      cTempMv         = cDMv + cBaseTMV;
1461
1462    pcCU->clipMv(cBaseTMV);
1463    pcCU->clipMv(cTempMv);
1464
1465    xPredInterLumaBlk  ( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, bi,   true);
1466    xPredInterChromaBlk( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, bi,   true);
1467    xPredInterLumaBlk  ( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, bi,   true); 
1468    xPredInterChromaBlk( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, bi,   true); 
1469
1470    pYuvCurrTRef->subtractARP( pYuvCurrTRef , pYuvBaseTRef , uiPartAddr , iWidth , iHeight ); 
1471    if(dW == 2)
1472    {
1473      pYuvCurrTRef->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
1474    }
1475    rpcYuvPred->addARP( rpcYuvPred , pYuvCurrTRef , uiPartAddr , iWidth , iHeight , !bi ); 
1476  }
1477}
1478
1479#endif
1480
1481Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
1482{
1483  TComYuv* pcMbYuv;
1484  Int      iRefIdx[2] = {-1, -1};
1485
1486  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
1487  {
1488    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
1489    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
1490
1491    if ( iRefIdx[iRefList] < 0 )
1492    {
1493      continue;
1494    }
1495
1496    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
1497
1498    pcMbYuv = &m_acYuvPred[iRefList];
1499    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
1500    {
1501      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
1502    }
1503    else
1504    {
1505      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) || 
1506           ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
1507      {
1508        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
1509      }
1510      else
1511      {
1512        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
1513      }
1514    }
1515  }
1516
1517  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE  )
1518  {
1519    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1520  } 
1521  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
1522  {
1523    xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); 
1524  }
1525  else
1526  {
1527    xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1528  }
1529}
1530
1531#if H_3D_VSP
1532
1533Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
1534{
1535  TComYuv* pcMbYuv;
1536  Int      iRefIdx[2] = {-1, -1};
1537  Bool     bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0);
1538
1539  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
1540  {
1541    RefPicList eRefPicList = RefPicList(iRefList);
1542    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
1543
1544    if ( iRefIdx[iRefList] < 0 )
1545    {
1546      continue;
1547    }
1548    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
1549
1550    pcMbYuv = &m_acYuvPred[iRefList];
1551    xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi );
1552  }
1553
1554  xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1555}
1556
1557#endif
1558
1559/**
1560 * \brief Generate motion-compensated luma block
1561 *
1562 * \param cu       Pointer to current CU
1563 * \param refPic   Pointer to reference picture
1564 * \param partAddr Address of block within CU
1565 * \param mv       Motion vector
1566 * \param width    Width of block
1567 * \param height   Height of block
1568 * \param dstPic   Pointer to destination picture
1569 * \param bi       Flag indicating whether bipred is used
1570 */
1571Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
1572#if H_3D_ARP
1573    , Bool filterType
1574#endif
1575#if H_3D_IC
1576    , Bool bICFlag
1577#endif
1578  )
1579{
1580  Int refStride = refPic->getStride(); 
1581  Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride;
1582  Pel *ref      = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1583 
1584  Int dstStride = dstPic->getStride();
1585  Pel *dst      = dstPic->getLumaAddr( partAddr );
1586 
1587  Int xFrac = mv->getHor() & 0x3;
1588  Int yFrac = mv->getVer() & 0x3;
1589
1590#if H_3D_IC
1591  if( cu->getSlice()->getIsDepth() )
1592  {
1593    refOffset = mv->getHor() + mv->getVer() * refStride;
1594    ref       = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1595    xFrac     = 0;
1596    yFrac     = 0;
1597  }
1598#endif
1599  if ( yFrac == 0 )
1600  {
1601#if H_3D_IC
1602    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi || bICFlag
1603#else
1604    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi
1605#endif
1606#if H_3D_ARP
1607    , filterType
1608#endif
1609      );
1610  }
1611  else if ( xFrac == 0 )
1612  {
1613#if H_3D_IC
1614    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag
1615#else
1616    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi
1617#endif
1618#if H_3D_ARP
1619    , filterType
1620#endif
1621      );
1622  }
1623  else
1624  {
1625    Int tmpStride = m_filteredBlockTmp[0].getStride();
1626    Short *tmp    = m_filteredBlockTmp[0].getLumaAddr();
1627
1628    Int filterSize = NTAPS_LUMA;
1629    Int halfFilterSize = ( filterSize >> 1 );
1630
1631    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     
1632#if H_3D_ARP
1633    , filterType
1634#endif
1635      );
1636#if H_3D_IC
1637    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi || bICFlag
1638#else
1639    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi
1640#endif
1641#if H_3D_ARP
1642    , filterType
1643#endif
1644      );   
1645  }
1646
1647#if H_3D_IC
1648  if( bICFlag )
1649  {
1650    Int a, b, i, j;
1651    const Int iShift = IC_CONST_SHIFT;
1652
1653    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA );
1654
1655
1656    for ( i = 0; i < height; i++ )
1657    {
1658      for ( j = 0; j < width; j++ )
1659      {
1660          dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
1661      }
1662      dst += dstStride;
1663    }
1664
1665    if(bi)
1666    {
1667      Pel *dst2      = dstPic->getLumaAddr( partAddr );
1668      Int shift = IF_INTERNAL_PREC - g_bitDepthY;
1669      for (i = 0; i < height; i++)
1670      {
1671        for (j = 0; j < width; j++)
1672        {
1673          Short val = dst2[j] << shift;
1674          dst2[j] = val - (Short)IF_INTERNAL_OFFS;
1675        }
1676        dst2 += dstStride;
1677      }
1678    }
1679  }
1680#endif
1681}
1682
1683/**
1684 * \brief Generate motion-compensated chroma block
1685 *
1686 * \param cu       Pointer to current CU
1687 * \param refPic   Pointer to reference picture
1688 * \param partAddr Address of block within CU
1689 * \param mv       Motion vector
1690 * \param width    Width of block
1691 * \param height   Height of block
1692 * \param dstPic   Pointer to destination picture
1693 * \param bi       Flag indicating whether bipred is used
1694 */
1695Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
1696#if H_3D_ARP
1697    , Bool filterType
1698#endif
1699#if H_3D_IC
1700    , Bool bICFlag
1701#endif
1702  )
1703{
1704  Int     refStride  = refPic->getCStride();
1705  Int     dstStride  = dstPic->getCStride();
1706 
1707  Int     refOffset  = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride;
1708 
1709  Pel*    refCb     = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1710  Pel*    refCr     = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1711 
1712  Pel* dstCb = dstPic->getCbAddr( partAddr );
1713  Pel* dstCr = dstPic->getCrAddr( partAddr );
1714 
1715  Int     xFrac  = mv->getHor() & 0x7;
1716  Int     yFrac  = mv->getVer() & 0x7;
1717  UInt    cxWidth  = width  >> 1;
1718  UInt    cxHeight = height >> 1;
1719 
1720  Int     extStride = m_filteredBlockTmp[0].getStride();
1721  Short*  extY      = m_filteredBlockTmp[0].getLumaAddr();
1722 
1723  Int filterSize = NTAPS_CHROMA;
1724 
1725  Int halfFilterSize = (filterSize>>1);
1726 
1727  if ( yFrac == 0 )
1728  {
1729#if H_3D_IC
1730    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
1731#else
1732    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi
1733#endif
1734#if H_3D_ARP
1735    , filterType
1736#endif
1737    );   
1738#if H_3D_IC
1739    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
1740#else
1741    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi
1742#endif
1743#if H_3D_ARP
1744    , filterType
1745#endif
1746    );
1747  }
1748  else if ( xFrac == 0 )
1749  {
1750#if H_3D_IC
1751    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
1752#else
1753    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1754#endif
1755#if H_3D_ARP
1756    , filterType
1757#endif
1758    );
1759#if H_3D_IC
1760    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
1761#else
1762    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1763#endif
1764#if H_3D_ARP
1765    , filterType
1766#endif
1767    );
1768  }
1769  else
1770  {
1771    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1772#if H_3D_ARP
1773    , filterType
1774#endif 
1775      );
1776#if H_3D_IC
1777    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
1778#else
1779    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1780#endif
1781#if H_3D_ARP
1782    , filterType
1783#endif
1784      );
1785   
1786    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1787#if H_3D_ARP
1788    , filterType
1789#endif
1790      );
1791#if H_3D_IC
1792    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
1793#else
1794    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1795#endif
1796#if H_3D_ARP
1797    , filterType
1798#endif
1799      );   
1800  }
1801
1802#if H_3D_IC
1803  if( bICFlag )
1804  {
1805    Int a, b, i, j;
1806    const Int iShift = IC_CONST_SHIFT;
1807    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb
1808    for ( i = 0; i < cxHeight; i++ )
1809    {
1810      for ( j = 0; j < cxWidth; j++ )
1811      {
1812          dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
1813      }
1814      dstCb += dstStride;
1815    }
1816    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr
1817    for ( i = 0; i < cxHeight; i++ )
1818    {
1819      for ( j = 0; j < cxWidth; j++ )
1820      {
1821          dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
1822      }
1823      dstCr += dstStride;
1824    }
1825
1826    if(bi)
1827    {
1828      Pel* dstCb2 = dstPic->getCbAddr( partAddr );
1829      Pel* dstCr2 = dstPic->getCrAddr( partAddr );
1830      Int shift = IF_INTERNAL_PREC - g_bitDepthC;
1831      for (i = 0; i < cxHeight; i++)
1832      {
1833        for (j = 0; j < cxWidth; j++)
1834        {
1835          Short val = dstCb2[j] << shift;
1836          dstCb2[j] = val - (Short)IF_INTERNAL_OFFS;
1837
1838          val = dstCr2[j] << shift;
1839          dstCr2[j] = val - (Short)IF_INTERNAL_OFFS;
1840        }
1841        dstCb2 += dstStride;
1842        dstCr2 += dstStride;
1843      }
1844    }
1845  }
1846#endif
1847}
1848
1849Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
1850{
1851  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
1852  {
1853    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
1854  }
1855  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
1856  {
1857    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
1858  }
1859  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
1860  {
1861    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
1862  }
1863}
1864
1865// AMVP
1866Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
1867{
1868  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
1869  if( pcAMVPInfo->iN <= 1 )
1870  {
1871    rcMvPred = pcAMVPInfo->m_acMvCand[0];
1872
1873    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1874    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1875    return;
1876  }
1877
1878  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
1879  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
1880  return;
1881}
1882
1883/** Function for deriving planar intra prediction.
1884 * \param pSrc pointer to reconstructed sample array
1885 * \param srcStride the stride of the reconstructed sample array
1886 * \param rpDst reference to pointer for the prediction sample array
1887 * \param dstStride the stride of the prediction sample array
1888 * \param width the width of the block
1889 * \param height the height of the block
1890 *
1891 * This function derives the prediction samples for planar mode (intra coding).
1892 */
1893Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
1894{
1895  assert(width == height);
1896
1897  Int k, l, bottomLeft, topRight;
1898  Int horPred;
1899  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
1900  UInt blkSize = width;
1901  UInt offset2D = width;
1902  UInt shift1D = g_aucConvertToBit[ width ] + 2;
1903  UInt shift2D = shift1D + 1;
1904
1905  // Get left and above reference column and row
1906  for(k=0;k<blkSize+1;k++)
1907  {
1908    topRow[k] = pSrc[k-srcStride];
1909    leftColumn[k] = pSrc[k*srcStride-1];
1910  }
1911
1912  // Prepare intermediate variables used in interpolation
1913  bottomLeft = leftColumn[blkSize];
1914  topRight   = topRow[blkSize];
1915  for (k=0;k<blkSize;k++)
1916  {
1917    bottomRow[k]   = bottomLeft - topRow[k];
1918    rightColumn[k] = topRight   - leftColumn[k];
1919    topRow[k]      <<= shift1D;
1920    leftColumn[k]  <<= shift1D;
1921  }
1922
1923  // Generate prediction signal
1924  for (k=0;k<blkSize;k++)
1925  {
1926    horPred = leftColumn[k] + offset2D;
1927    for (l=0;l<blkSize;l++)
1928    {
1929      horPred += rightColumn[k];
1930      topRow[l] += bottomRow[l];
1931      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
1932    }
1933  }
1934}
1935
1936/** Function for filtering intra DC predictor.
1937 * \param pSrc pointer to reconstructed sample array
1938 * \param iSrcStride the stride of the reconstructed sample array
1939 * \param rpDst reference to pointer for the prediction sample array
1940 * \param iDstStride the stride of the prediction sample array
1941 * \param iWidth the width of the block
1942 * \param iHeight the height of the block
1943 *
1944 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
1945 */
1946Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
1947{
1948  Pel* pDst = rpDst;
1949  Int x, y, iDstStride2, iSrcStride2;
1950
1951  // boundary pixels processing
1952  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
1953
1954  for ( x = 1; x < iWidth; x++ )
1955  {
1956    pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
1957  }
1958
1959  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
1960  {
1961    pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
1962  }
1963
1964  return;
1965}
1966#if H_3D_IC
1967/** Function for deriving the position of first non-zero binary bit of a value
1968 * \param x input value
1969 *
1970 * This function derives the position of first non-zero binary bit of a value
1971 */
1972Int GetMSB( UInt x )
1973{
1974  Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1;
1975
1976  while( x > 1 )
1977  {
1978    bits >>= 1;
1979    y = x >> bits;
1980
1981    if( y )
1982    {
1983      x = y;
1984      iMSB += bits;
1985    }
1986  }
1987
1988  iMSB+=y;
1989
1990  return iMSB;
1991}
1992
1993
1994/** Function for deriving LM illumination compensation.
1995 */
1996Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType )
1997{
1998  TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
1999  Pel *pRec = NULL, *pRef = NULL;
2000  UInt uiWidth, uiHeight, uiTmpPartIdx;
2001  Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride();
2002  Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride();
2003  Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer;
2004
2005  iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
2006  iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
2007  iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 );
2008  iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 );
2009  iRefX   = iCUPelX + iHor;
2010  iRefY   = iCUPelY + iVer;
2011  if( eType != TEXT_LUMA )
2012  {
2013    iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 );
2014    iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 );
2015  }
2016  uiWidth  = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 )  : ( pcCU->getWidth( 0 )  >> 1 );
2017  uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 );
2018
2019  Int i, j, iCountShift = 0;
2020
2021  // LLS parameters estimation -->
2022
2023  Int x = 0, y = 0, xx = 0, xy = 0;
2024  Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12);
2025
2026  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 )
2027  {
2028    iRefOffset = iHor + iVer * iRefStride - iRefStride;
2029    if( eType == TEXT_LUMA )
2030    {
2031      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2032      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
2033    }
2034    else if( eType == TEXT_CHROMA_U )
2035    {
2036      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2037      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
2038    }
2039    else
2040    {
2041      assert( eType == TEXT_CHROMA_V );
2042      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2043      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
2044    }
2045
2046    for( j = 0; j < uiWidth; j+=2 )
2047    {
2048      x += pRef[j];
2049      y += pRec[j];
2050      xx += (pRef[j] * pRef[j])>>precShift;
2051      xy += (pRef[j] * pRec[j])>>precShift;
2052    }
2053    iCountShift += g_aucConvertToBit[ uiWidth ] + 1;
2054  }
2055
2056
2057  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 )
2058  {
2059    iRefOffset = iHor + iVer * iRefStride - 1;
2060    if( eType == TEXT_LUMA )
2061    {
2062      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2063      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
2064    }
2065    else if( eType == TEXT_CHROMA_U )
2066    {
2067      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2068      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
2069    }
2070    else
2071    {
2072      assert( eType == TEXT_CHROMA_V );
2073      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2074      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
2075    }
2076
2077    for( i = 0; i < uiHeight; i+=2 )
2078    {
2079      x += pRef[0];
2080      y += pRec[0];
2081
2082      xx += (pRef[0] * pRef[0])>>precShift;
2083      xy += (pRef[0] * pRec[0])>>precShift;
2084
2085      pRef += iRefStride*2;
2086      pRec += iRecStride*2;
2087    }
2088    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 );
2089  }
2090
2091  xy += xx >> IC_REG_COST_SHIFT;
2092  xx += xx >> IC_REG_COST_SHIFT;
2093  Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift);
2094  Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift);
2095  const Int iShift = IC_CONST_SHIFT;
2096  {
2097    {
2098      const Int iShiftA2 = 6;
2099      const Int iAccuracyShift = 15;
2100
2101      Int iScaleShiftA2 = 0;
2102      Int iScaleShiftA1 = 0;
2103      Int a1s = a1;
2104      Int a2s = a2;
2105
2106      a1 = Clip3(0, 2*a2, a1);
2107      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2;
2108      iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF;
2109
2110      if( iScaleShiftA1 < 0 )
2111      {
2112        iScaleShiftA1 = 0;
2113      }
2114
2115      if( iScaleShiftA2 < 0 )
2116      {
2117        iScaleShiftA2 = 0;
2118      }
2119
2120      Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
2121
2122
2123      a2s = a2 >> iScaleShiftA2;
2124
2125      a1s = a1 >> iScaleShiftA1;
2126
2127      a = a1s * m_uiaShift[ a2s ];
2128      a = a >> iScaleShiftA;
2129      b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
2130    }
2131  }   
2132}
2133#endif
2134
2135#if H_3D_VSP
2136#if !(NTT_STORE_SPDV_VSP_G0148)
2137// not fully support iRatioTxtPerDepth* != 1
2138Void TComPrediction::xGetVirtualDepth( TComDataCU *cu, TComPicYuv *picRefDepth, TComMv *mv, UInt partAddr, Int width, Int height, TComYuv *yuvDepth, Int &vspSize, Int ratioTxtPerDepthX, Int ratioTxtPerDepthY )
2139{
2140  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
2141  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
2142
2143  Int refDepStride = picRefDepth->getStride();
2144
2145  Int refDepOffset  = ( (mv->getHor()+2) >> 2 ) + ( (mv->getVer()+2) >> 2 ) * refDepStride;
2146  Pel *refDepth     = picRefDepth->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
2147
2148  if( ratioTxtPerDepthX!=1 || ratioTxtPerDepthY!=1 )
2149  {
2150    Int posX, posY;
2151    refDepth    = picRefDepth->getLumaAddr( );
2152    cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
2153    posX /= ratioTxtPerDepthX; // texture position -> depth postion
2154    posY /= ratioTxtPerDepthY;
2155    refDepOffset += posX + posY * refDepStride;
2156
2157    width  /= ratioTxtPerDepthX; // texture size -> depth size
2158    height /= ratioTxtPerDepthY;
2159  }
2160
2161  refDepth += refDepOffset;
2162
2163  Int depStride = yuvDepth->getStride();
2164  Pel *depth = yuvDepth->getLumaAddr();
2165
2166  if ((height % 8))
2167  {
2168    vspSize = 1; // 8x4
2169  }
2170  else if ((width % 8))
2171  {
2172    vspSize = 0; // 4x8
2173  }
2174  else
2175  {
2176    Bool ULvsBR, URvsBL;
2177    ULvsBR = refDepth[0]       < refDepth[refDepStride * (height-1) + width-1];
2178    URvsBL = refDepth[width-1] < refDepth[refDepStride * (height-1)];
2179    vspSize = ( ULvsBR ^ URvsBL ) ? 0 : 1;
2180  }
2181  Int subBlockW, subBlockH;
2182  Int depStrideTmp = depStride * nTxtPerDepthY;
2183  if (vspSize)
2184  {
2185    subBlockW = 8;
2186    subBlockH = 4;
2187  }
2188  else
2189  {
2190    subBlockW = 4;
2191    subBlockH = 8;
2192  }
2193  for( Int y=0; y<height; y+=subBlockH )
2194  {
2195    Pel *refDepthTmp[4];
2196    refDepthTmp[0] = refDepth + refDepStride * y;
2197    refDepthTmp[1] = refDepthTmp[0] + subBlockW - 1;
2198    refDepthTmp[2] = refDepthTmp[0] + refDepStride * (subBlockH - 1);
2199    refDepthTmp[3] = refDepthTmp[2] + subBlockW - 1;
2200    for( Int x=0; x<width; x+=subBlockW )
2201    {
2202      Pel  maxDepthVal;
2203      maxDepthVal = refDepthTmp[0][x];
2204      maxDepthVal = std::max( maxDepthVal, refDepthTmp[1][x]);
2205      maxDepthVal = std::max( maxDepthVal, refDepthTmp[2][x]);
2206      maxDepthVal = std::max( maxDepthVal, refDepthTmp[3][x]);
2207      Pel *depthTmp = &depth[x+y*depStride];
2208      for( Int sY=0; sY<subBlockH; sY+=nTxtPerDepthY )
2209      {
2210        for( Int sX=0; sX<subBlockW; sX+=nTxtPerDepthX )
2211        {
2212          depthTmp[sX] = maxDepthVal;
2213        }
2214        depthTmp += depStrideTmp;
2215      }
2216    }
2217  }   
2218}
2219
2220Void TComPrediction::xPredInterLumaBlkFromDM( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi, Int vspSize)
2221{
2222  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
2223  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
2224 
2225  nTxtPerDepthX = nTxtPerDepthX << vspSize;
2226  nTxtPerDepthY = nTxtPerDepthY << (1-vspSize);
2227
2228  Int refStride = picRef->getStride();
2229  Int dstStride = yuvDst->getStride();
2230  Int depStride = yuvDepth->getStride();
2231  Int refStrideBlock = refStride  * nTxtPerDepthY;
2232  Int dstStrideBlock = dstStride * nTxtPerDepthY;
2233  Int depStrideBlock = depStride * nTxtPerDepthY;
2234
2235  Pel *ref    = picRef->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
2236  Pel *dst    = yuvDst->getLumaAddr(partAddr);
2237  Pel *depth  = yuvDepth->getLumaAddr();
2238
2239#if H_3D_VSP_BLOCKSIZE == 1
2240#if H_3D_VSP_CONSTRAINED
2241  //get LUT based horizontal reference range
2242  Int range = xGetConstrainedSize(width, height);
2243
2244  // The minimum depth value
2245  Int minRelativePos = MAX_INT;
2246  Int maxRelativePos = MIN_INT;
2247
2248  Pel* depthTemp, *depthInitial=depth;
2249  for (Int yTxt = 0; yTxt < height; yTxt++)
2250  {
2251    for (Int xTxt = 0; xTxt < width; xTxt++)
2252    {
2253      if (depthPosX+xTxt < widthDepth)
2254      {
2255        depthTemp = depthInitial + xTxt;
2256      }
2257      else
2258      {
2259        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
2260      }
2261
2262      Int disparity = shiftLUT[ *depthTemp ]; // << iShiftPrec;
2263      Int disparityInt = disparity >> 2;
2264
2265      if( disparity <= 0)
2266      {
2267        if (minRelativePos > disparityInt+xTxt)
2268        {
2269          minRelativePos = disparityInt+xTxt;
2270        }
2271      }
2272      else
2273      {
2274        if (maxRelativePos < disparityInt+xTxt)
2275        {
2276          maxRelativePos = disparityInt+xTxt;
2277        }
2278      }
2279    }
2280    if (depthPosY+yTxt < heightDepth)
2281    {
2282      depthInitial = depthInitial + depStride;
2283    }
2284  }
2285
2286  Int disparity_tmp = shiftLUT[ *depth ]; // << iShiftPrec;
2287  if (disparity_tmp <= 0)
2288  {
2289    maxRelativePos = minRelativePos + range -1 ;
2290  }
2291  else
2292  {
2293    minRelativePos = maxRelativePos - range +1 ;
2294  }
2295#endif
2296#endif // H_3D_VSP_BLOCKSIZE == 1
2297
2298  TComMv dv(0, 0);
2299
2300  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
2301  {
2302    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
2303    {
2304      Pel repDepth = depth[ xTxt ];
2305      assert( repDepth >= 0 && repDepth <= 255 );
2306
2307      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec ??
2308      Int xFrac = disparity & 0x3;
2309
2310      dv.setHor( disparity );
2311      cu->clipMv( dv );
2312
2313      Int refOffset = xTxt + (dv.getHor() >> 2);
2314     
2315#if H_3D_VSP_CONSTRAINED
2316      if(refOffset<minRelativePos || refOffset>maxRelativePos)
2317      {
2318        xFrac = 0;
2319      }
2320      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
2321#endif
2322
2323      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
2324      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
2325    }
2326    ref   += refStrideBlock;
2327    dst   += dstStrideBlock;
2328    depth += depStrideBlock;
2329  }
2330
2331}
2332
2333Void TComPrediction::xPredInterChromaBlkFromDM  ( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi, Int vspSize)
2334{
2335#if (H_3D_VSP_BLOCKSIZE==1)
2336  Int nTxtPerDepthX = 1;
2337  Int nTxtPerDepthY = 1;
2338#else
2339  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE >> 1;
2340  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE >> 1;
2341#endif
2342
2343  nTxtPerDepthX = nTxtPerDepthX << vspSize;
2344  nTxtPerDepthY = nTxtPerDepthY << (1-vspSize);
2345
2346  Int refStride = picRef->getCStride();
2347  Int dstStride = yuvDst->getCStride();
2348  Int depStride = yuvDepth->getStride();
2349  Int refStrideBlock = refStride * nTxtPerDepthY;
2350  Int dstStrideBlock = dstStride * nTxtPerDepthY;
2351  Int depStrideBlock = depStride * (nTxtPerDepthY<<1);
2352
2353  Pel *refCb  = picRef->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
2354  Pel *refCr  = picRef->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
2355  Pel *dstCb  = yuvDst->getCbAddr(partAddr);
2356  Pel *dstCr  = yuvDst->getCrAddr(partAddr);
2357  Pel *depth  = yuvDepth->getLumaAddr();
2358
2359#if H_3D_VSP_BLOCKSIZE == 1
2360#if H_3D_VSP_CONSTRAINED
2361  //get LUT based horizontal reference range
2362  Int range = xGetConstrainedSize(width, height, false);
2363
2364  // The minimum depth value
2365  Int minRelativePos = MAX_INT;
2366  Int maxRelativePos = MIN_INT;
2367
2368  Int depthTmp;
2369  for (Int yTxt=0; yTxt<height; yTxt++)
2370  {
2371    for (Int xTxt=0; xTxt<width; xTxt++)
2372    {
2373      depthTmp = m_pDepthBlock[xTxt+yTxt*width];
2374      Int disparity = shiftLUT[ depthTmp ]; // << iShiftPrec;
2375      Int disparityInt = disparity >> 3;//in chroma resolution
2376
2377      if (disparityInt < 0)
2378      {
2379        if (minRelativePos > disparityInt+xTxt)
2380        {
2381          minRelativePos = disparityInt+xTxt;
2382        }
2383      }
2384      else
2385      {
2386        if (maxRelativePos < disparityInt+xTxt)
2387        {
2388          maxRelativePos = disparityInt+xTxt;
2389        }
2390      }
2391    }
2392  }
2393
2394  depthTmp = m_pDepthBlock[0];
2395  Int disparity_tmp = shiftLUT[ depthTmp ]; // << iShiftPrec;
2396  if ( disparity_tmp < 0 )
2397  {
2398    maxRelativePos = minRelativePos + range - 1;
2399  }
2400  else
2401  {
2402    minRelativePos = maxRelativePos - range + 1;
2403  }
2404
2405#endif // H_3D_VSP_CONSTRAINED
2406#endif // H_3D_VSP_BLOCKSIZE == 1
2407
2408  TComMv dv(0, 0);
2409  // luma size -> chroma size
2410  height >>= 1;
2411  width  >>= 1;
2412
2413  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
2414  {
2415    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
2416    {
2417      Pel repDepth = depth[ xTxt<<1 ];
2418      assert( repDepth >= 0 && repDepth <= 255 );
2419
2420      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec;
2421      Int xFrac = disparity & 0x7;
2422     
2423      dv.setHor( disparity );
2424      cu->clipMv( dv );
2425
2426      Int refOffset = xTxt + (dv.getHor() >> 3);
2427
2428#if H_3D_VSP_CONSTRAINED
2429      if(refOffset<minRelativePos || refOffset>maxRelativePos)
2430      {
2431        xFrac = 0;
2432      }
2433      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
2434#endif
2435
2436      assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
2437      assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
2438
2439      m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
2440      m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
2441    }
2442    refCb += refStrideBlock;
2443    refCr += refStrideBlock;
2444    dstCb += dstStrideBlock;
2445    dstCr += dstStrideBlock;
2446    depth += depStrideBlock;
2447  }
2448}
2449#endif
2450
2451#if H_3D_VSP_CONSTRAINED
2452Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma)
2453{
2454  Int iSize = 0;
2455  if (bLuma)
2456  {
2457    Int iArea = (nPbW+7) * (nPbH+7);
2458    Int iAlpha = iArea / nPbH - nPbW - 7;
2459    iSize = iAlpha + nPbW;
2460  }
2461  else // chroma
2462  {
2463    Int iArea = (nPbW+2) * (nPbH+2);
2464    Int iAlpha = iArea / nPbH - nPbW - 4;
2465    iSize = iAlpha + nPbW;
2466  }
2467  return iSize;
2468}
2469#endif // H_3D_VSP_CONSTRAINED
2470
2471#endif // H_3D_VSP
2472
2473#if H_3D_DIM
2474Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
2475{
2476  Int  refDC1, refDC2;
2477  const Int  iTR = (   patternStride - 1        ) - srcStride;
2478  const Int  iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride;
2479  const Int  iLB = (   patternStride - 1        ) * srcStride - 1;
2480  const Int  iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1;
2481
2482  Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] );
2483  Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)]               );
2484
2485  if( bL == bT )
2486  {
2487#if SCU_HS_DEPTH_DC_PRED_G0143
2488    const Int  iTRR = ( patternStride * 2 - 1  ) - srcStride; 
2489    const Int  iLBB = ( patternStride * 2 - 1  ) * srcStride - 1;
2490    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : (abs(ptrSrc[iTRR] - ptrSrc[-(Int)srcStride]) > abs(ptrSrc[iLBB] - ptrSrc[ -1]) ? ptrSrc[iTRR] : ptrSrc[iLBB]);
2491#else
2492    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : 1<<( g_bitDepthY - 1 );
2493#endif
2494    refDC2 =      ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1;
2495  }
2496  else
2497  {
2498    refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR];
2499    refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM];
2500  }
2501
2502  predDC1 = biSegPattern[0] ? refDC1 : refDC2;
2503  predDC2 = biSegPattern[0] ? refDC2 : refDC1;
2504}
2505
2506Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
2507{
2508  if( dstStride == patternStride )
2509  {
2510    for( UInt k = 0; k < (patternStride * patternStride); k++ )
2511    {
2512      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
2513      else                          { ptrDst[k] = valDC1; }
2514    }
2515  }
2516  else
2517  {
2518    Pel* piTemp = ptrDst;
2519    for( UInt uiY = 0; uiY < patternStride; uiY++ )
2520    {
2521      for( UInt uiX = 0; uiX < patternStride; uiX++ )
2522      {
2523        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
2524        else                            { piTemp[uiX] = valDC1; }
2525      }
2526      piTemp       += dstStride;
2527      biSegPattern += patternStride;
2528    }
2529  }
2530}
2531
2532#if H_3D_DIM_DMM
2533
2534Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
2535{
2536  pcContourWedge->clear();
2537
2538  // get copy of co-located texture luma block
2539  TComYuv cTempYuv;
2540  cTempYuv.create( uiWidth, uiHeight ); 
2541  cTempYuv.clear();
2542  Pel* piRefBlkY = cTempYuv.getLumaAddr();
2543  xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
2544  piRefBlkY = cTempYuv.getLumaAddr();
2545
2546  // find contour for texture luma block
2547  UInt iDC = 0;
2548  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2549  { 
2550    iDC += piRefBlkY[k]; 
2551  }
2552
2553  Int cuMaxLog2Size = g_aucConvertToBit[g_uiMaxCUWidth]+2;   //
2554  iDC = iDC >> (cuMaxLog2Size - pcCU->getDepth(0))*2;        //  iDC /= (uiWidth*uiHeight);
2555
2556  piRefBlkY = cTempYuv.getLumaAddr();
2557
2558  Bool* pabContourPattern = pcContourWedge->getPattern();
2559  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2560  { 
2561    pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
2562  }
2563
2564  cTempYuv.destroy();
2565}
2566
2567
2568Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
2569{
2570  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
2571  assert( pcPicYuvRef != NULL );
2572  Int         iRefStride = pcPicYuvRef->getStride();
2573  Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2574
2575  for ( Int y = 0; y < uiHeight; y++ )
2576  {
2577    ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
2578    piDestBlockY += uiWidth;
2579    piRefY += iRefStride;
2580  }
2581}
2582#endif
2583
2584
2585#if H_3D_DIM_SDC
2586Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
2587                                         ,UInt uiIntraMode
2588                                         ,Bool orgDC
2589                                        )
2590{
2591  Int iSumDepth[2];
2592  memset(iSumDepth, 0, sizeof(Int)*2);
2593  Int iSumPix[2];
2594  memset(iSumPix, 0, sizeof(Int)*2);
2595#if QC_GENERIC_SDC_G0122
2596  for( Int i = 0; i < uiNumSegments; i++ )
2597  {
2598    rpSegMeans[i] = 0;
2599  }
2600#endif
2601  if (orgDC == false)
2602  {
2603    if ( getDimType(uiIntraMode) == DMM1_IDX )
2604    {
2605      UChar ucSegmentLT = pMask[0];
2606      UChar ucSegmentRT = pMask[uiSize-1];
2607      UChar ucSegmentLB = pMask[uiMaskStride * (uiSize-1)]; 
2608      UChar ucSegmentRB = pMask[uiMaskStride * (uiSize-1) + (uiSize-1)]; 
2609
2610      rpSegMeans[ucSegmentLT] = pOrig[0];
2611      rpSegMeans[ucSegmentRT] = pOrig[uiSize-1];
2612      rpSegMeans[ucSegmentLB] = pOrig[uiStride * (uiSize-1) ];
2613      rpSegMeans[ucSegmentRB] = pOrig[uiStride * (uiSize-1) + (uiSize-1) ];
2614    }
2615#if QC_GENERIC_SDC_G0122
2616    else if( getDimType( uiIntraMode ) == DMM4_IDX )
2617    {
2618      Pel *ptmpOrig = pOrig;
2619      Bool *ptmpMask = pMask, bBreak = false;
2620      UChar ucSegment = ptmpMask? (UChar) ptmpMask[0] : 0;
2621      UChar bFirstSeg = ucSegment;
2622
2623      rpSegMeans[ucSegment] = ptmpOrig[0];
2624      for ( Int y = 0; y < uiSize; y++ )
2625      {
2626        for ( Int x = 0; x < uiSize; x++ )
2627        {
2628          ucSegment = ptmpMask[x];
2629          assert( ucSegment < uiNumSegments );
2630
2631          if( bFirstSeg != ucSegment )
2632          {
2633            rpSegMeans[ucSegment] = ptmpOrig[x];
2634            bBreak = true;
2635            break;
2636          }
2637        }
2638
2639        if( bBreak )
2640        {
2641          break;
2642        }
2643
2644        ptmpOrig  += uiStride;
2645        ptmpMask  += uiMaskStride;
2646      }
2647    }
2648    else
2649#else
2650    else if (uiIntraMode == PLANAR_IDX)
2651#endif
2652    {
2653      Pel* pLeftTop = pOrig;
2654      Pel* pRightTop = pOrig + (uiSize-1);
2655      Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1)));
2656      Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1));
2657
2658      rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
2659    }
2660    return;
2661  }
2662
2663  Int subSamplePix;
2664  if ( uiSize == 64 || uiSize == 32 )
2665  {
2666    subSamplePix = 2;
2667  }
2668  else
2669  {
2670    subSamplePix = 1;
2671  }
2672  for (Int y=0; y<uiSize; y+=subSamplePix)
2673  {
2674    for (Int x=0; x<uiSize; x+=subSamplePix)
2675    {
2676      UChar ucSegment = pMask?(UChar)pMask[x]:0;
2677      assert( ucSegment < uiNumSegments );
2678     
2679      iSumDepth[ucSegment] += pOrig[x];
2680      iSumPix[ucSegment]   += 1;
2681    }
2682   
2683    pOrig  += uiStride*subSamplePix;
2684    pMask  += uiMaskStride*subSamplePix;
2685  }
2686 
2687  // compute mean for each segment
2688  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
2689  {
2690    if( iSumPix[ucSeg] > 0 )
2691      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
2692    else
2693      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
2694  }
2695}
2696#endif // H_3D_DIM_SDC
2697#endif
2698//! \}
Note: See TracBrowser for help on using the repository browser.