source: 3DVCSoftware/branches/HTM-10.2-dev0/source/Lib/TLibCommon/TComPrediction.cpp @ 935

Last change on this file since 935 was 935, checked in by tech, 10 years ago

Merged 10.2-dev1-MediaTek@934.

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