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

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

Integration of JCT3V-I0129

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