source: 3DVCSoftware/branches/HTM-10.2-dev2-RWTH/source/Lib/TLibCommon/TComPrediction.cpp @ 908

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