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

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

Merged HTM-9.1-dev0-MediaTek@757. (3D-HEVC HLS)

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