source: 3DVCSoftware/branches/HTM-13.1-dev0/source/Lib/TLibCommon/TComPrediction.cpp @ 1175

Last change on this file since 1175 was 1175, checked in by tech, 9 years ago

Added direct dependency type for qtl.
Updated cfg files.
updated copy right headers.

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