source: 3DVCSoftware/branches/HTM-14.1-update-dev4-RWTH/source/Lib/TLibCommon/TComPrediction.cpp @ 1231

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