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

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

Merged HTM-8.2-dev0@723.

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