source: 3DVCSoftware/branches/HTM-8.2-dev1-MTK-LG/source/Lib/TLibCommon/TComPrediction.cpp @ 912

Last change on this file since 912 was 704, checked in by mediatek-htm, 11 years ago

Xianguo Zhang from MediaTek integrated the changes in F0109 and F0120 in the software, also including the crosscheck result of F0105 and new software performance.

  • Property svn:eol-style set to native
File size: 78.2 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( width<8 || height<8 )
1673  { // no split
1674    Int rightOffset = width - 1;
1675    Int depStrideBlock = depStride * nTxtPerDepthY;
1676    Pel *refDepthTop = refDepth;
1677    Pel *refDepthBot = refDepthTop + (height-1)*refDepStride;
1678
1679    Pel maxDepth = refDepthTop[0] > refDepthBot[0] ? refDepthTop[0] : refDepthBot[0];
1680    if( maxDepth < refDepthTop[rightOffset] ) { maxDepth = refDepthTop[rightOffset]; }
1681    if( maxDepth < refDepthBot[rightOffset] ) { maxDepth = refDepthBot[rightOffset]; }
1682
1683    for( Int sY=0; sY<height; sY+=nTxtPerDepthY )
1684    {
1685      for( Int sX=0; sX<width; sX+=nTxtPerDepthX )
1686      {
1687        depth[sX] = maxDepth;
1688      }
1689      depth += depStrideBlock;
1690    }
1691#if MTK_F0109_LG_F0120_VSP_BLOCK
1692  if(width==4)
1693    vspSize=0;
1694  else
1695    vspSize=1;
1696#endif
1697  }
1698  else
1699  { // split to 4x8, or 8x4
1700    Int blocksize    = 8;
1701    Int subblocksize = 4;
1702    Int depStrideBlock = depStride * blocksize;
1703    Pel *depthTmp = NULL;
1704    Int depStrideTmp = depStride * nTxtPerDepthY;
1705    Int offset[4] = { 0, subblocksize-1, subblocksize, blocksize-1 };
1706    Pel *refDepthTmp[4] = { NULL, NULL, NULL, NULL };
1707    Pel repDepth4x8[2] = {0, 0};
1708    Pel repDepth8x4[2] = {0, 0};
1709
1710#if !MTK_F0109_LG_F0120_VSP_BLOCK
1711    Int refDepStrideBlock    = refDepStride * blocksize;
1712    Int refDepStrideSubBlock = refDepStride * subblocksize;
1713
1714    refDepthTmp[0] = refDepth;
1715    refDepthTmp[2] = refDepthTmp[0] + refDepStrideSubBlock;
1716    refDepthTmp[1] = refDepthTmp[2] - refDepStride;
1717    refDepthTmp[3] = refDepthTmp[1] + refDepStrideSubBlock;
1718
1719    for( Int y=0; y<height; y+=blocksize )
1720    {
1721      for( Int x=0; x<width; x+=blocksize )
1722      {
1723        Bool ULvsBR = false, URvsBL = false;
1724
1725        ULvsBR = refDepthTmp[0][x+offset[0]] < refDepthTmp[3][x+offset[3]];
1726        URvsBL = refDepthTmp[0][x+offset[3]] < refDepthTmp[3][x+offset[0]];
1727
1728        if( ULvsBR ^ URvsBL )
1729        { // 4x8
1730          repDepth4x8[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[1]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[1]];
1731          if( repDepth4x8[0] < refDepthTmp[3][x+offset[0]] )
1732          {
1733            repDepth4x8[0] = refDepthTmp[3][x+offset[0]];
1734          }
1735          if( repDepth4x8[0] < refDepthTmp[3][x+offset[1]] )
1736          {
1737            repDepth4x8[0] = refDepthTmp[3][x+offset[1]];
1738          }
1739          repDepth4x8[1] = refDepthTmp[0][x+offset[2]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[2]] : refDepthTmp[0][x+offset[3]];
1740          if( repDepth4x8[1] < refDepthTmp[3][x+offset[2]] )
1741          {
1742            repDepth4x8[1] = refDepthTmp[3][x+offset[2]];
1743          }
1744          if( repDepth4x8[1] < refDepthTmp[3][x+offset[3]] )
1745          {
1746            repDepth4x8[1] = refDepthTmp[3][x+offset[3]];
1747          }
1748
1749          depthTmp = &depth[x];
1750          for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY )
1751          {
1752            for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX )
1753            {
1754              depthTmp[sX] = repDepth4x8[0];
1755            }
1756            depthTmp += depStrideTmp;
1757          }
1758          depthTmp = &depth[x+subblocksize];
1759          for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY )
1760          {
1761            for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX )
1762            {
1763              depthTmp[sX] = repDepth4x8[1];
1764            }
1765            depthTmp += depStrideTmp;
1766          }
1767        }
1768        else
1769        { // 8x4
1770          repDepth8x4[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[3]];
1771          if( repDepth8x4[0] < refDepthTmp[1][x+offset[0]] )
1772          {
1773            repDepth8x4[0] = refDepthTmp[1][x+offset[0]];
1774          }
1775          if( repDepth8x4[0] < refDepthTmp[1][x+offset[3]] )
1776          {
1777            repDepth8x4[0] = refDepthTmp[1][x+offset[3]];
1778          }
1779          repDepth8x4[1] = refDepthTmp[2][x+offset[0]] > refDepthTmp[2][x+offset[3]] ? refDepthTmp[2][x+offset[0]] : refDepthTmp[2][x+offset[3]];
1780          if( repDepth8x4[1] < refDepthTmp[3][x+offset[0]] )
1781          {
1782            repDepth8x4[1] = refDepthTmp[3][x+offset[0]];
1783          }
1784          if( repDepth8x4[1] < refDepthTmp[3][x+offset[3]] )
1785          {
1786            repDepth8x4[1] = refDepthTmp[3][x+offset[3]];
1787          }
1788         
1789          depthTmp = &depth[x];
1790          for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY )
1791          {
1792            for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX )
1793            {
1794              depthTmp[sX] = repDepth8x4[0];
1795            }
1796            depthTmp += depStrideTmp;
1797          }
1798          for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY )
1799          {
1800            for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX )
1801            {
1802              depthTmp[sX] = repDepth8x4[1];
1803            }
1804            depthTmp += depStrideTmp;
1805          }
1806        }
1807      }
1808      refDepthTmp[0] += refDepStrideBlock;
1809      refDepthTmp[1] += refDepStrideBlock;
1810      refDepthTmp[2] += refDepStrideBlock;
1811      refDepthTmp[3] += refDepStrideBlock;
1812      depth       += depStrideBlock;
1813    }
1814#else
1815    Int refDepStrideBlock    = refDepStride * height;
1816    Int refDepStrideSubBlock = refDepStride * height/2;
1817    refDepthTmp[0] = refDepth;
1818    refDepthTmp[2] = refDepthTmp[0] + refDepStrideSubBlock;
1819    refDepthTmp[1] = refDepthTmp[2] - refDepStride;
1820    refDepthTmp[3] = refDepthTmp[1] + refDepStrideSubBlock;
1821    offset[3] = width-1;
1822    Bool ULvsBR = false, URvsBL = false;
1823    ULvsBR = refDepthTmp[0][0+offset[0]] < refDepthTmp[3][0+offset[3]];
1824    URvsBL = refDepthTmp[0][0+offset[3]] < refDepthTmp[3][0+offset[0]];
1825    refDepStrideBlock    = refDepStride * blocksize;
1826    refDepStrideSubBlock = refDepStride * subblocksize;
1827    refDepthTmp[0] = refDepth;
1828    refDepthTmp[2] = refDepthTmp[0] + refDepStrideSubBlock;
1829    refDepthTmp[1] = refDepthTmp[2] - refDepStride;
1830    refDepthTmp[3] = refDepthTmp[1] + refDepStrideSubBlock;
1831    offset[3] = blocksize-1;
1832    if( ULvsBR ^ URvsBL )
1833    {
1834    vspSize = 0;//4x8
1835    for( Int y=0; y<height; y+=blocksize )
1836    {
1837      for( Int x=0; x<width; x+=blocksize )
1838      {
1839        { // 4x8
1840          repDepth4x8[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[1]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[1]];
1841          if( repDepth4x8[0] < refDepthTmp[3][x+offset[0]] )
1842          {
1843            repDepth4x8[0] = refDepthTmp[3][x+offset[0]];
1844          }
1845          if( repDepth4x8[0] < refDepthTmp[3][x+offset[1]] )
1846          {
1847            repDepth4x8[0] = refDepthTmp[3][x+offset[1]];
1848          }
1849          repDepth4x8[1] = refDepthTmp[0][x+offset[2]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[2]] : refDepthTmp[0][x+offset[3]];
1850          if( repDepth4x8[1] < refDepthTmp[3][x+offset[2]] )
1851          {
1852            repDepth4x8[1] = refDepthTmp[3][x+offset[2]];
1853          }
1854          if( repDepth4x8[1] < refDepthTmp[3][x+offset[3]] )
1855          {
1856            repDepth4x8[1] = refDepthTmp[3][x+offset[3]];
1857          }
1858
1859          depthTmp = &depth[x];
1860          for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY )
1861          {
1862            for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX )
1863            {
1864              depthTmp[sX] = repDepth4x8[0];
1865            }
1866            depthTmp += depStrideTmp;
1867          }
1868          depthTmp = &depth[x+subblocksize];
1869          for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY )
1870          {
1871            for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX )
1872            {
1873              depthTmp[sX] = repDepth4x8[1];
1874            }
1875            depthTmp += depStrideTmp;
1876          }
1877        }
1878      }
1879      refDepthTmp[0] += refDepStrideBlock;
1880      refDepthTmp[1] += refDepStrideBlock;
1881      refDepthTmp[2] += refDepStrideBlock;
1882      refDepthTmp[3] += refDepStrideBlock;
1883      depth       += depStrideBlock;
1884    }
1885  }
1886  else
1887  { // 8x4
1888    vspSize = 1;
1889    for( Int y=0; y<height; y+=blocksize )
1890    {
1891      for( Int x=0; x<width; x+=blocksize )
1892      {
1893        repDepth8x4[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[3]];
1894        if( repDepth8x4[0] < refDepthTmp[1][x+offset[0]] )
1895        {
1896          repDepth8x4[0] = refDepthTmp[1][x+offset[0]];
1897        }
1898        if( repDepth8x4[0] < refDepthTmp[1][x+offset[3]] )
1899        {
1900          repDepth8x4[0] = refDepthTmp[1][x+offset[3]];
1901        }
1902        repDepth8x4[1] = refDepthTmp[2][x+offset[0]] > refDepthTmp[2][x+offset[3]] ? refDepthTmp[2][x+offset[0]] : refDepthTmp[2][x+offset[3]];
1903        if( repDepth8x4[1] < refDepthTmp[3][x+offset[0]] )
1904        {
1905          repDepth8x4[1] = refDepthTmp[3][x+offset[0]];
1906        }
1907        if( repDepth8x4[1] < refDepthTmp[3][x+offset[3]] )
1908        {
1909          repDepth8x4[1] = refDepthTmp[3][x+offset[3]];
1910        }
1911
1912        depthTmp = &depth[x];
1913        for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY )
1914        {
1915          for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX )
1916          {
1917            depthTmp[sX] = repDepth8x4[0];
1918          }
1919          depthTmp += depStrideTmp;
1920        }
1921        for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY )
1922        {
1923          for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX )
1924          {
1925            depthTmp[sX] = repDepth8x4[1];
1926          }
1927          depthTmp += depStrideTmp;
1928        }
1929      }
1930      refDepthTmp[0] += refDepStrideBlock;
1931      refDepthTmp[1] += refDepStrideBlock;
1932      refDepthTmp[2] += refDepStrideBlock;
1933      refDepthTmp[3] += refDepStrideBlock;
1934      depth       += depStrideBlock;
1935    }
1936  }
1937#endif
1938  }
1939
1940
1941}
1942#if MTK_F0109_LG_F0120_VSP_BLOCK
1943Void 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)
1944#else
1945Void TComPrediction::xPredInterLumaBlkFromDM( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi )
1946#endif
1947{
1948  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
1949  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
1950
1951#if MTK_F0109_LG_F0120_VSP_BLOCK
1952  nTxtPerDepthX = nTxtPerDepthX << vspSize;
1953  nTxtPerDepthY = nTxtPerDepthY << (1-vspSize);
1954#endif
1955  Int refStride = picRef->getStride();
1956  Int dstStride = yuvDst->getStride();
1957  Int depStride = yuvDepth->getStride();
1958  Int refStrideBlock = refStride  * nTxtPerDepthY;
1959  Int dstStrideBlock = dstStride * nTxtPerDepthY;
1960  Int depStrideBlock = depStride * nTxtPerDepthY;
1961
1962  Pel *ref    = picRef->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
1963  Pel *dst    = yuvDst->getLumaAddr(partAddr);
1964  Pel *depth  = yuvDepth->getLumaAddr();
1965
1966#if H_3D_VSP_BLOCKSIZE == 1
1967#if H_3D_VSP_CONSTRAINED
1968  //get LUT based horizontal reference range
1969  Int range = xGetConstrainedSize(width, height);
1970
1971  // The minimum depth value
1972  Int minRelativePos = MAX_INT;
1973  Int maxRelativePos = MIN_INT;
1974
1975  Pel* depthTemp, *depthInitial=depth;
1976  for (Int yTxt = 0; yTxt < height; yTxt++)
1977  {
1978    for (Int xTxt = 0; xTxt < width; xTxt++)
1979    {
1980      if (depthPosX+xTxt < widthDepth)
1981      {
1982        depthTemp = depthInitial + xTxt;
1983      }
1984      else
1985      {
1986        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
1987      }
1988
1989      Int disparity = shiftLUT[ *depthTemp ]; // << iShiftPrec;
1990      Int disparityInt = disparity >> 2;
1991
1992      if( disparity <= 0)
1993      {
1994        if (minRelativePos > disparityInt+xTxt)
1995        {
1996          minRelativePos = disparityInt+xTxt;
1997        }
1998      }
1999      else
2000      {
2001        if (maxRelativePos < disparityInt+xTxt)
2002        {
2003          maxRelativePos = disparityInt+xTxt;
2004        }
2005      }
2006    }
2007    if (depthPosY+yTxt < heightDepth)
2008    {
2009      depthInitial = depthInitial + depStride;
2010    }
2011  }
2012
2013  Int disparity_tmp = shiftLUT[ *depth ]; // << iShiftPrec;
2014  if (disparity_tmp <= 0)
2015  {
2016    maxRelativePos = minRelativePos + range -1 ;
2017  }
2018  else
2019  {
2020    minRelativePos = maxRelativePos - range +1 ;
2021  }
2022#endif
2023#endif // H_3D_VSP_BLOCKSIZE == 1
2024
2025  TComMv dv(0, 0);
2026
2027  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
2028  {
2029    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
2030    {
2031      Pel repDepth = depth[ xTxt ];
2032      assert( repDepth >= 0 && repDepth <= 255 );
2033
2034      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec ??
2035      Int xFrac = disparity & 0x3;
2036
2037      dv.setHor( disparity );
2038      cu->clipMv( dv );
2039
2040      Int refOffset = xTxt + (dv.getHor() >> 2);
2041     
2042#if H_3D_VSP_CONSTRAINED
2043      if(refOffset<minRelativePos || refOffset>maxRelativePos)
2044      {
2045        xFrac = 0;
2046      }
2047      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
2048#endif
2049
2050      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
2051      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
2052    }
2053    ref   += refStrideBlock;
2054    dst   += dstStrideBlock;
2055    depth += depStrideBlock;
2056  }
2057
2058}
2059#if MTK_F0109_LG_F0120_VSP_BLOCK
2060Void 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)
2061#else
2062Void TComPrediction::xPredInterChromaBlkFromDM  ( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi )
2063#endif
2064{
2065#if (H_3D_VSP_BLOCKSIZE==1)
2066  Int nTxtPerDepthX = 1;
2067  Int nTxtPerDepthY = 1;
2068#else
2069  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE >> 1;
2070  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE >> 1;
2071#endif
2072
2073#if MTK_F0109_LG_F0120_VSP_BLOCK
2074  nTxtPerDepthX = nTxtPerDepthX << vspSize;
2075  nTxtPerDepthY = nTxtPerDepthY << (1-vspSize);
2076#endif
2077  Int refStride = picRef->getCStride();
2078  Int dstStride = yuvDst->getCStride();
2079  Int depStride = yuvDepth->getStride();
2080  Int refStrideBlock = refStride * nTxtPerDepthY;
2081  Int dstStrideBlock = dstStride * nTxtPerDepthY;
2082  Int depStrideBlock = depStride * (nTxtPerDepthY<<1);
2083
2084  Pel *refCb  = picRef->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
2085  Pel *refCr  = picRef->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
2086  Pel *dstCb  = yuvDst->getCbAddr(partAddr);
2087  Pel *dstCr  = yuvDst->getCrAddr(partAddr);
2088  Pel *depth  = yuvDepth->getLumaAddr();
2089
2090#if H_3D_VSP_BLOCKSIZE == 1
2091#if H_3D_VSP_CONSTRAINED
2092  //get LUT based horizontal reference range
2093  Int range = xGetConstrainedSize(width, height, false);
2094
2095  // The minimum depth value
2096  Int minRelativePos = MAX_INT;
2097  Int maxRelativePos = MIN_INT;
2098
2099  Int depthTmp;
2100  for (Int yTxt=0; yTxt<height; yTxt++)
2101  {
2102    for (Int xTxt=0; xTxt<width; xTxt++)
2103    {
2104      depthTmp = m_pDepthBlock[xTxt+yTxt*width];
2105      Int disparity = shiftLUT[ depthTmp ]; // << iShiftPrec;
2106      Int disparityInt = disparity >> 3;//in chroma resolution
2107
2108      if (disparityInt < 0)
2109      {
2110        if (minRelativePos > disparityInt+xTxt)
2111        {
2112          minRelativePos = disparityInt+xTxt;
2113        }
2114      }
2115      else
2116      {
2117        if (maxRelativePos < disparityInt+xTxt)
2118        {
2119          maxRelativePos = disparityInt+xTxt;
2120        }
2121      }
2122    }
2123  }
2124
2125  depthTmp = m_pDepthBlock[0];
2126  Int disparity_tmp = shiftLUT[ depthTmp ]; // << iShiftPrec;
2127  if ( disparity_tmp < 0 )
2128  {
2129    maxRelativePos = minRelativePos + range - 1;
2130  }
2131  else
2132  {
2133    minRelativePos = maxRelativePos - range + 1;
2134  }
2135
2136#endif // H_3D_VSP_CONSTRAINED
2137#endif // H_3D_VSP_BLOCKSIZE == 1
2138
2139  TComMv dv(0, 0);
2140  // luma size -> chroma size
2141  height >>= 1;
2142  width  >>= 1;
2143
2144  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
2145  {
2146    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
2147    {
2148      Pel repDepth = depth[ xTxt<<1 ];
2149      assert( repDepth >= 0 && repDepth <= 255 );
2150
2151      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec;
2152      Int xFrac = disparity & 0x7;
2153     
2154      dv.setHor( disparity );
2155      cu->clipMv( dv );
2156
2157      Int refOffset = xTxt + (dv.getHor() >> 3);
2158
2159#if H_3D_VSP_CONSTRAINED
2160      if(refOffset<minRelativePos || refOffset>maxRelativePos)
2161      {
2162        xFrac = 0;
2163      }
2164      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
2165#endif
2166
2167      assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
2168      assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
2169
2170      m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
2171      m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
2172    }
2173    refCb += refStrideBlock;
2174    refCr += refStrideBlock;
2175    dstCb += dstStrideBlock;
2176    dstCr += dstStrideBlock;
2177    depth += depStrideBlock;
2178  }
2179}
2180
2181
2182#if H_3D_VSP_CONSTRAINED
2183Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma)
2184{
2185  Int iSize = 0;
2186  if (bLuma)
2187  {
2188    Int iArea = (nPbW+7) * (nPbH+7);
2189    Int iAlpha = iArea / nPbH - nPbW - 7;
2190    iSize = iAlpha + nPbW;
2191  }
2192  else // chroma
2193  {
2194    Int iArea = (nPbW+2) * (nPbH+2);
2195    Int iAlpha = iArea / nPbH - nPbW - 4;
2196    iSize = iAlpha + nPbW;
2197  }
2198  return iSize;
2199}
2200#endif // H_3D_VSP_CONSTRAINED
2201
2202#endif // H_3D_VSP
2203
2204#if H_3D_DIM
2205Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
2206{
2207  Int  refDC1, refDC2;
2208  const Int  iTR = (   patternStride - 1        ) - srcStride;
2209  const Int  iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride;
2210  const Int  iLB = (   patternStride - 1        ) * srcStride - 1;
2211  const Int  iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1;
2212
2213  Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] );
2214  Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)]               );
2215
2216  if( bL == bT )
2217  {
2218    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : 1<<( g_bitDepthY - 1 );
2219    refDC2 =      ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1;
2220  }
2221  else
2222  {
2223    refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR];
2224    refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM];
2225  }
2226
2227  predDC1 = biSegPattern[0] ? refDC1 : refDC2;
2228  predDC2 = biSegPattern[0] ? refDC2 : refDC1;
2229}
2230
2231Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
2232{
2233  if( dstStride == patternStride )
2234  {
2235    for( UInt k = 0; k < (patternStride * patternStride); k++ )
2236    {
2237      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
2238      else                          { ptrDst[k] = valDC1; }
2239    }
2240  }
2241  else
2242  {
2243    Pel* piTemp = ptrDst;
2244    for( UInt uiY = 0; uiY < patternStride; uiY++ )
2245    {
2246      for( UInt uiX = 0; uiX < patternStride; uiX++ )
2247      {
2248        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
2249        else                            { piTemp[uiX] = valDC1; }
2250      }
2251      piTemp       += dstStride;
2252      biSegPattern += patternStride;
2253    }
2254  }
2255}
2256
2257#if H_3D_DIM_DMM
2258UInt TComPrediction::xPredWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx )
2259{
2260  TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
2261  assert( pcPicTex != NULL );
2262  TComDataCU*   pcColTexCU = pcPicTex->getCU(pcCU->getAddr());
2263  UInt          uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
2264  Int           uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
2265
2266  assert( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 );
2267  return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx);
2268}
2269
2270Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
2271{
2272  pcContourWedge->clear();
2273
2274  // get copy of co-located texture luma block
2275  TComYuv cTempYuv;
2276  cTempYuv.create( uiWidth, uiHeight ); 
2277  cTempYuv.clear();
2278  Pel* piRefBlkY = cTempYuv.getLumaAddr();
2279  xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
2280  piRefBlkY = cTempYuv.getLumaAddr();
2281
2282  // find contour for texture luma block
2283  UInt iDC = 0;
2284  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2285  { 
2286    iDC += piRefBlkY[k]; 
2287  }
2288
2289  Int cuMaxLog2Size = g_aucConvertToBit[g_uiMaxCUWidth]+2;   //
2290  iDC = iDC >> (cuMaxLog2Size - pcCU->getDepth(0))*2;        //  iDC /= (uiWidth*uiHeight);
2291
2292  piRefBlkY = cTempYuv.getLumaAddr();
2293
2294  Bool* pabContourPattern = pcContourWedge->getPattern();
2295  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2296  { 
2297    pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
2298  }
2299
2300  cTempYuv.destroy();
2301}
2302
2303
2304Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
2305{
2306  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
2307  assert( pcPicYuvRef != NULL );
2308  Int         iRefStride = pcPicYuvRef->getStride();
2309  Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2310
2311  for ( Int y = 0; y < uiHeight; y++ )
2312  {
2313    ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
2314    piDestBlockY += uiWidth;
2315    piRefY += iRefStride;
2316  }
2317}
2318#endif
2319
2320#if H_3D_DIM_RBC
2321Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Pel& rDeltaDC )
2322{
2323  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
2324  UInt uiAbs  = abs( rDeltaDC );
2325
2326  Int iQp = pcCU->getQP(0);
2327  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
2328  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
2329
2330  rDeltaDC = iSign * roftoi( uiAbs * dStepSize );
2331  return;
2332}
2333
2334Void TComPrediction::xDeltaDCQuantScaleDown( TComDataCU*  pcCU, Pel& rDeltaDC )
2335{
2336  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
2337  UInt uiAbs  = abs( rDeltaDC );
2338
2339  Int iQp = pcCU->getQP(0);
2340  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
2341  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
2342
2343  rDeltaDC = iSign * roftoi( uiAbs / dStepSize );
2344  return;
2345}
2346#endif
2347#if H_3D_DIM_SDC
2348Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
2349                                         ,UInt uiIntraMode
2350                                         ,Bool orgDC
2351                                        )
2352{
2353  Int iSumDepth[2];
2354  memset(iSumDepth, 0, sizeof(Int)*2);
2355  Int iSumPix[2];
2356  memset(iSumPix, 0, sizeof(Int)*2);
2357 
2358  if (orgDC == false)
2359  {
2360    if ( getDimType(uiIntraMode) == DMM1_IDX )
2361    {
2362      UChar ucSegmentLT = pMask[0];
2363      UChar ucSegmentRT = pMask[uiSize-1];
2364      UChar ucSegmentLB = pMask[uiMaskStride * (uiSize-1)]; 
2365      UChar ucSegmentRB = pMask[uiMaskStride * (uiSize-1) + (uiSize-1)]; 
2366
2367      rpSegMeans[ucSegmentLT] = pOrig[0];
2368      rpSegMeans[ucSegmentRT] = pOrig[uiSize-1];
2369      rpSegMeans[ucSegmentLB] = pOrig[uiStride * (uiSize-1) ];
2370      rpSegMeans[ucSegmentRB] = pOrig[uiStride * (uiSize-1) + (uiSize-1) ];
2371    }
2372    else if (uiIntraMode == PLANAR_IDX)
2373    {
2374      Pel* pLeftTop = pOrig;
2375      Pel* pRightTop = pOrig + (uiSize-1);
2376      Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1)));
2377      Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1));
2378
2379      rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
2380    }
2381    return;
2382  }
2383
2384  Int subSamplePix;
2385  if ( uiSize == 64 || uiSize == 32 )
2386  {
2387    subSamplePix = 2;
2388  }
2389  else
2390  {
2391    subSamplePix = 1;
2392  }
2393  for (Int y=0; y<uiSize; y+=subSamplePix)
2394  {
2395    for (Int x=0; x<uiSize; x+=subSamplePix)
2396    {
2397      UChar ucSegment = pMask?(UChar)pMask[x]:0;
2398      assert( ucSegment < uiNumSegments );
2399     
2400      iSumDepth[ucSegment] += pOrig[x];
2401      iSumPix[ucSegment]   += 1;
2402    }
2403   
2404    pOrig  += uiStride*subSamplePix;
2405    pMask  += uiMaskStride*subSamplePix;
2406  }
2407 
2408  // compute mean for each segment
2409  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
2410  {
2411    if( iSumPix[ucSeg] > 0 )
2412      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
2413    else
2414      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
2415  }
2416}
2417#endif // H_3D_DIM_SDC
2418#endif
2419//! \}
Note: See TracBrowser for help on using the repository browser.