source: 3DVCSoftware/trunk/source/Lib/TLibCommon/TComPrediction.cpp @ 884

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

Merged HTM-10.1-dev0@883. (MV-HEVC 7 HLS)

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