source: 3DVCSoftware/branches/HTM-11.2-dev2-Qualcomm/source/Lib/TLibCommon/TComPrediction.cpp @ 986

Last change on this file since 986 was 986, checked in by qualcomm, 10 years ago

Integration of JCT3V-I0051

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