source: 3DVCSoftware/branches/HTM-8.2-dev1-Sharp2/source/Lib/TLibCommon/TComPrediction.cpp @ 1404

Last change on this file since 1404 was 706, checked in by sharpjp-htm, 11 years ago

Integration of F0102

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