source: 3DVCSoftware/branches/HTM-9.3-dev3-Qualcomm/source/Lib/TLibCommon/TComPrediction.cpp @ 781

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

integration of JCT3V-G0122 (generalize SDC to all depth intra modes) by Qualcomm.

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