source: 3DVCSoftware/branches/HTM-14.1-update-dev3-MediaTek-Qualcomm/source/Lib/TLibCommon/TComPrediction.cpp @ 1259

Last change on this file since 1259 was 1259, checked in by mediatek-htm, 10 years ago

Reactive IVMV by Mediatek

  • Property svn:eol-style set to native
File size: 85.1 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  }
[1255]84#if NH_3D_VSP
85  m_pDepthBlock = (Int*) malloc(MAX_NUM_PART_IDXS_IN_CTU_WIDTH*MAX_NUM_PART_IDXS_IN_CTU_WIDTH*sizeof(Int));
[608]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{
[1255]96#if NH_3D_VSP
[608]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
[1255]188#if NH_3D_VSP
189    m_cYuvDepthOnVsp.create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );
[608]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
[1259]663#if NH_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  }
[1259]672#if H_3D_ARP
[1039]673  if( pcCU->getARPW( uiPartAddr ) != 0 )
674  {
675    return;
676  }
[1259]677#endif
[1084]678
[724]679  // horizontal sub-PU merge
680  for (Int i=0; i<iNumSP; i++)
681  {
682    if (i % iNumSPInOneLine == iNumSPInOneLine - 1 || uiMergedSPW[i]==0 || uiMergedSPH[i]==0)
683    {
684      continue;
685    }
686    for (Int j=i+1; j<i+iNumSPInOneLine-i%iNumSPInOneLine; j++)
687    {
688      if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j]))
689      {
690        uiMergedSPW[i] += iSPWidth;
691        uiMergedSPW[j] = uiMergedSPH[j] = 0;
692      }
693      else
694      {
695        break;
696      }
697    }
698  }
699  //vertical sub-PU merge
700  for (Int i=0; i<iNumSP-iNumSPInOneLine; i++)
701  {
702    if (uiMergedSPW[i]==0 || uiMergedSPH[i]==0)
703    {
704      continue;
705    }
706    for (Int j=i+iNumSPInOneLine; j<iNumSP; j+=iNumSPInOneLine)
707    {
708      if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j]) && uiMergedSPW[i]==uiMergedSPW[j])
709      {
710        uiMergedSPH[i] += iSPHeight;
711        uiMergedSPH[j] = uiMergedSPW[j] = 0;
712      }
713      else
714      {
715        break;
716      }
717    }
718  }
719}
[608]720
[724]721Bool TComPrediction::xCheckTwoSPMotion ( TComDataCU* pcCU, UInt PartAddr0, UInt PartAddr1 )
722{
723  if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr1))
724  {
725    return false;
726  }
727  if( pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr1))
728  {
729    return false;
730  }
731
732  if (pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) >= 0)
733  {
734    if (pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr1))
735    {
736      return false;
737    }
738  }
739
740  if (pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) >= 0)
741  {
742    if (pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr1))
743    {
744      return false;
745    }
746  }
747  return true;
748}
749#endif
750
[833]751#if H_3D_DBBP
[1179]752PartSize TComPrediction::getPartitionSizeFromDepth(Pel* pDepthPels, UInt uiDepthStride, UInt uiSize, TComDataCU*& pcCU)
[833]753{
754  // find virtual partitioning for this CU based on depth block
755  // segmentation of texture block --> mask IDs
756  Pel*  pDepthBlockStart      = pDepthPels;
[1196]757
[833]758  // first compute average of depth block for thresholding
759  Int iSumDepth = 0;
760  Int iSubSample = 4;
[1179]761  Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth();
762  Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight();
763  TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag(  ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV;
764  if( pcCU->getSlice()->getDepthRefinementFlag(  ) )
765  {
766    cDv.setVer(0);
767  }
768  Int iBlkX = ( pcCU->getAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getHor()+2)>>2);
769  Int iBlkY = ( pcCU->getAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getVer()+2)>>2);
[1196]770 
[1179]771  UInt t=0;
772
[833]773  for (Int y=0; y<uiSize; y+=iSubSample)
[1196]774  {
[1179]775    for (Int x=0; x<uiSize; x+=iSubSample)
[1196]776    {
777      if (iBlkX+x>iPictureWidth)
778      {
779        Int depthPel = pDepthPels[t];
780        iSumDepth += depthPel;
781      } 
782      else
783      {
784        Int depthPel = pDepthPels[x];
785        t=x;
786        iSumDepth += depthPel;
787      }
788    }
789
[1179]790    // next row
791    if (!(iBlkY+y+4>iPictureHeight))
[833]792    {
[1196]793      pDepthPels += uiDepthStride*iSubSample;
[833]794    }
795  }
[1196]796
[833]797  Int iSizeInBits = g_aucConvertToBit[uiSize] - g_aucConvertToBit[iSubSample];  // respect sub-sampling factor
798  Int iMean = iSumDepth >> iSizeInBits*2;       // iMean /= (uiSize*uiSize);
[1196]799
[833]800  // start again for segmentation
801  pDepthPels = pDepthBlockStart;
[1196]802
[833]803  // start mapping process
[950]804  Int matchedPartSum[2][2] = {{0,0},{0,0}}; // counter for each part size and boolean option
805  PartSize virtualPartSizes[2] = { SIZE_Nx2N, SIZE_2NxN};
[1196]806
[833]807  UInt uiHalfSize = uiSize>>1;
808  for (Int y=0; y<uiSize; y+=iSubSample)
809  {
810    for (Int x=0; x<uiSize; x+=iSubSample)
811    {
[1179]812      Int depthPel = 0;
[1196]813      if (iBlkX+x>iPictureWidth)
814      {
815        depthPel = pDepthPels[t];
816      }
817      else
818      { 
819        depthPel = pDepthPels[x];
820        t=x;
821      }
822
[833]823      // decide which segment this pixel belongs to
824      Int ucSegment = (Int)(depthPel>iMean);
[1196]825
[833]826      // Matched Filter to find optimal (conventional) partitioning
[1196]827
[833]828      // SIZE_Nx2N
829      if(x<uiHalfSize)  // left
830      {
831        matchedPartSum[0][ucSegment]++;
832      }
833      else  // right
834      {
835        matchedPartSum[0][1-ucSegment]++;
836      }
[1196]837
[833]838      // SIZE_2NxN
839      if(y<uiHalfSize)  // top
840      {
841        matchedPartSum[1][ucSegment]++;
842      }
843      else  // bottom
844      {
845        matchedPartSum[1][1-ucSegment]++;
846      }
847    }
[1196]848
[833]849    // next row
[1179]850    if (!(iBlkY+y+4>iPictureHeight))
[1196]851    {
852      pDepthPels += uiDepthStride*iSubSample;
853    }
[833]854  }
[1196]855
[833]856  PartSize matchedPartSize = SIZE_NONE;
[1196]857
[833]858  Int iMaxMatchSum = 0;
[950]859  for(Int p=0; p<2; p++)  // loop over partition
[833]860  {
861    for( Int b=0; b<=1; b++ ) // loop over boolean options
862    {
863      if(matchedPartSum[p][b] > iMaxMatchSum)
864      {
865        iMaxMatchSum = matchedPartSum[p][b];
866        matchedPartSize = virtualPartSizes[p];
867      }
868    }
869  }
[1196]870
[833]871  AOF( matchedPartSize != SIZE_NONE );
[1196]872
[833]873  return matchedPartSize;
874}
875
[1179]876Bool TComPrediction::getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask, TComDataCU*& pcCU)
[833]877{
878  // segmentation of texture block --> mask IDs
879  Pel*  pDepthBlockStart      = pDepthPels;
[1179]880
[833]881  // first compute average of depth block for thresholding
882  Int iSumDepth = 0;
883  Int uiMinDepth = MAX_INT;
884  Int uiMaxDepth = 0;
[1179]885  uiMinDepth = pDepthPels[ 0 ];
886  uiMaxDepth = pDepthPels[ 0 ];
[1039]887  iSumDepth  = pDepthPels[ 0 ];
[1196]888 
[1179]889  Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth();
890  Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight(); 
891  TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag(  ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV;
892  if( pcCU->getSlice()->getDepthRefinementFlag(  ) )
893  {
894    cDv.setVer(0);
895  }
896  Int iBlkX = ( pcCU->getAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getHor()+2)>>2);
897  Int iBlkY = ( pcCU->getAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getVer()+2)>>2);
898  if (iBlkX>(Int)(iPictureWidth - uiWidth))
899  {
900    iSumDepth += pDepthPels[ iPictureWidth - iBlkX - 1 ];
901    uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ iPictureWidth - iBlkX - 1 ]);
902    uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ iPictureWidth - iBlkX - 1 ]);
903  }
904  else
905  {
906    iSumDepth += pDepthPels[ uiWidth - 1 ];
907    uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiWidth - 1 ]);
908    uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiWidth - 1 ]);
909  }
910  if (iBlkY>(Int)(iPictureHeight - uiHeight))
911  {
912    iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ];
913    uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]);
914    uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]);
915  }
916  else
917  {
918    iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) ];
919    uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) ]);
920    uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) ]);
921  }
922  if (iBlkY>(Int)(iPictureHeight - uiHeight) && iBlkX>(Int)(iPictureWidth - uiWidth))
923  {
924    iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ];
925    uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]);
926    uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]);
927  }
928  else if (iBlkY>(Int)(iPictureHeight - uiHeight))
929  {
930    iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ];
931    uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]);
932    uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]);
933  }
934  else if (iBlkX>(Int)(iPictureWidth - uiWidth))
935  {
936    iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ];
937    uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]);
938    uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]);
939  }
940  else
941  {
942    iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ];
943    uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]);
944    uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]);
945  }
[1039]946
[833]947  // don't generate mask for blocks with small depth range (encoder decision)
948  if( uiMaxDepth - uiMinDepth < 10 )
949  {
950    return false;
951  }
[1179]952
[833]953  AOF(uiWidth==uiHeight);
[1039]954  Int iMean = iSumDepth >> 2;
[1179]955
[833]956  // start again for segmentation
957  pDepthPels = pDepthBlockStart;
[1179]958
[833]959  Bool bInvertMask = pDepthPels[0]>iMean; // top-left segment needs to be mapped to partIdx 0
[1179]960
[833]961  // generate mask
[1196]962  UInt t=0;
[833]963  UInt uiSumPix[2] = {0,0};
964  for (Int y=0; y<uiHeight; y++)
965  {
966    for (Int x=0; x<uiHeight; x++)
967    {
[1179]968      Int depthPel = 0;
969      if (iBlkX+x>iPictureWidth)
970      {
971        depthPel = pDepthPels[t];
972      }
973      else
974      {
975        depthPel = pDepthPels[x];
976        t=x;
977      }
978
[833]979      // decide which segment this pixel belongs to
980      Int ucSegment = (Int)(depthPel>iMean);
[1179]981
[833]982      if( bInvertMask )
983      {
984        ucSegment = 1-ucSegment;
985      }
[1179]986
[833]987      // count pixels for each segment
988      uiSumPix[ucSegment]++;
[1179]989
[833]990      // set mask value
991      pMask[x] = (Bool)ucSegment;
992    }
[1179]993
[833]994    // next row
[1179]995    if (!(iBlkY+y+1>iPictureHeight))
996      pDepthPels += uiDepthStride;
[833]997    pMask += MAX_CU_SIZE;
998  }
[1179]999
[833]1000  // don't generate valid mask for tiny segments (encoder decision)
1001  // each segment needs to cover at least 1/8th of block
1002  UInt uiMinPixPerSegment = (uiWidth*uiHeight) >> 3;
1003  if( !( uiSumPix[0] > uiMinPixPerSegment && uiSumPix[1] > uiMinPixPerSegment ) )
1004  {
1005    return false;
1006  }
[1179]1007
[833]1008  // all good
1009  return true;
1010}
1011
[1039]1012Void TComPrediction::combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr, UInt partSize )
[833]1013{
1014  Pel*  piSrc[2]    = {pInYuv[0]->getLumaAddr(uiPartAddr), pInYuv[1]->getLumaAddr(uiPartAddr)};
1015  UInt  uiSrcStride = pInYuv[0]->getStride();
1016  Pel*  piDst       = pOutYuv->getLumaAddr(uiPartAddr);
1017  UInt  uiDstStride = pOutYuv->getStride();
1018 
1019  UInt  uiMaskStride= MAX_CU_SIZE;
[950]1020  Pel* tmpTar = 0;
1021  tmpTar = (Pel *)xMalloc(Pel, uiWidth*uiHeight);
[833]1022 
1023  // backup pointer
1024  Bool* pMaskStart = pMask;
1025 
1026  // combine luma first
1027  for (Int y=0; y<uiHeight; y++)
1028  {
1029    for (Int x=0; x<uiWidth; x++)
1030    {
1031      UChar ucSegment = (UChar)pMask[x];
1032      AOF( ucSegment < 2 );
1033     
1034      // filtering
[950]1035      tmpTar[y*uiWidth+x] = piSrc[ucSegment][x];
[833]1036    }
1037   
1038    piSrc[0]  += uiSrcStride;
1039    piSrc[1]  += uiSrcStride;
1040    pMask     += uiMaskStride;
1041  }
1042 
[1039]1043  if (partSize == SIZE_Nx2N)
1044  {
1045    for (Int y=0; y<uiHeight; y++)
1046    {
1047      for (Int x=0; x<uiWidth; x++)
1048      {
1049        Bool l = (x==0)?pMaskStart[y*uiMaskStride+x]:pMaskStart[y*uiMaskStride+x-1];
1050        Bool r = (x==uiWidth-1)?pMaskStart[y*uiMaskStride+x]:pMaskStart[y*uiMaskStride+x+1];
1051       
1052        Pel left, right;
1053        left   = (x==0)          ? tmpTar[y*uiWidth+x] : tmpTar[y*uiWidth+x-1];
1054        right  = (x==uiWidth-1)  ? tmpTar[y*uiWidth+x] : tmpTar[y*uiWidth+x+1];
1055       
1056        piDst[x] = (l!=r) ? ClipY( Pel(( left + (tmpTar[y*uiWidth+x] << 1) + right ) >> 2 )) : tmpTar[y*uiWidth+x]; 
1057      }
1058      piDst     += uiDstStride;
1059    }
1060  }
1061  else // SIZE_2NxN
1062  {
1063    for (Int y=0; y<uiHeight; y++)
1064    {
1065      for (Int x=0; x<uiWidth; x++)
1066      {
1067        Bool t = (y==0)?pMaskStart[y*uiMaskStride+x]:pMaskStart[(y-1)*uiMaskStride+x];
1068        Bool b = (y==uiHeight-1)?pMaskStart[y*uiMaskStride+x]:pMaskStart[(y+1)*uiMaskStride+x];
1069       
1070        Pel top, bottom;
1071        top    = (y==0)          ? tmpTar[y*uiWidth+x] : tmpTar[(y-1)*uiWidth+x];
1072        bottom = (y==uiHeight-1) ? tmpTar[y*uiWidth+x] : tmpTar[(y+1)*uiWidth+x];
1073       
1074        piDst[x] = (t!=b) ? ClipY( Pel(( top + (tmpTar[y*uiWidth+x] << 1) + bottom ) >> 2 )) : tmpTar[y*uiWidth+x];
1075      }
1076      piDst     += uiDstStride;
1077    }
1078  }
[950]1079
[1196]1080  if ( tmpTar    ) 
1081  { 
1082    xFree(tmpTar);             
1083    tmpTar        = NULL; 
1084  }
[950]1085 
[833]1086  // now combine chroma
1087  Pel*  piSrcU[2]       = { pInYuv[0]->getCbAddr(uiPartAddr), pInYuv[1]->getCbAddr(uiPartAddr) };
1088  Pel*  piSrcV[2]       = { pInYuv[0]->getCrAddr(uiPartAddr), pInYuv[1]->getCrAddr(uiPartAddr) };
1089  UInt  uiSrcStrideC    = pInYuv[0]->getCStride();
1090  Pel*  piDstU          = pOutYuv->getCbAddr(uiPartAddr);
1091  Pel*  piDstV          = pOutYuv->getCrAddr(uiPartAddr);
1092  UInt  uiDstStrideC    = pOutYuv->getCStride();
1093  UInt  uiWidthC        = uiWidth >> 1;
1094  UInt  uiHeightC       = uiHeight >> 1;
[950]1095  Pel  filSrcU = 0, filSrcV = 0;
1096  Pel* tmpTarU = 0, *tmpTarV = 0;
1097  tmpTarU = (Pel *)xMalloc(Pel, uiWidthC*uiHeightC);
1098  tmpTarV = (Pel *)xMalloc(Pel, uiWidthC*uiHeightC);
[833]1099  pMask = pMaskStart;
1100 
1101  for (Int y=0; y<uiHeightC; y++)
1102  {
1103    for (Int x=0; x<uiWidthC; x++)
1104    {
1105      UChar ucSegment = (UChar)pMask[x*2];
1106      AOF( ucSegment < 2 );
1107     
1108      // filtering
[950]1109      tmpTarU[y*uiWidthC+x] = piSrcU[ucSegment][x];
1110      tmpTarV[y*uiWidthC+x] = piSrcV[ucSegment][x];
[833]1111    }
1112   
1113    piSrcU[0]   += uiSrcStrideC;
1114    piSrcU[1]   += uiSrcStrideC;
1115    piSrcV[0]   += uiSrcStrideC;
1116    piSrcV[1]   += uiSrcStrideC;
1117    pMask       += 2*uiMaskStride;
1118  }
[950]1119
[1039]1120  if (partSize == SIZE_Nx2N)
1121  {
1122    for (Int y=0; y<uiHeightC; y++)
1123    {
1124      for (Int x=0; x<uiWidthC; x++)
1125      {
1126        Bool l = (x==0)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[y*2*uiMaskStride+(x-1)*2];
1127        Bool r = (x==uiWidthC-1)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[y*2*uiMaskStride+(x+1)*2];
1128
1129        Pel leftU, rightU;
1130        leftU   = (x==0)           ? tmpTarU[y*uiWidthC+x] : tmpTarU[y*uiWidthC+x-1];
1131        rightU  = (x==uiWidthC-1)  ? tmpTarU[y*uiWidthC+x] : tmpTarU[y*uiWidthC+x+1];
1132        Pel leftV, rightV;
1133        leftV   = (x==0)           ? tmpTarV[y*uiWidthC+x] : tmpTarV[y*uiWidthC+x-1];
1134        rightV  = (x==uiWidthC-1)  ? tmpTarV[y*uiWidthC+x] : tmpTarV[y*uiWidthC+x+1];
1135
1136        if (l!=r)
1137        {
1138          filSrcU = ClipC( Pel(( leftU + (tmpTarU[y*uiWidthC+x] << 1) + rightU ) >> 2 ));
1139          filSrcV = ClipC( Pel(( leftV + (tmpTarV[y*uiWidthC+x] << 1) + rightV ) >> 2 ));
1140        }
1141        else
1142        {
1143          filSrcU = tmpTarU[y*uiWidthC+x];
1144          filSrcV = tmpTarV[y*uiWidthC+x];
1145        }
1146        piDstU[x] = filSrcU;
1147        piDstV[x] = filSrcV;
1148      }
1149      piDstU      += uiDstStrideC;
1150      piDstV      += uiDstStrideC;
1151    }
1152  }
1153  else
1154  {
1155    for (Int y=0; y<uiHeightC; y++)
1156    {
1157      for (Int x=0; x<uiWidthC; x++)
1158      {
1159        Bool t = (y==0)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[(y-1)*2*uiMaskStride+x*2];
1160        Bool b = (y==uiHeightC-1)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[(y+1)*2*uiMaskStride+x*2];
1161
1162        Pel topU, bottomU;
1163        topU    = (y==0)           ? tmpTarU[y*uiWidthC+x] : tmpTarU[(y-1)*uiWidthC+x];
1164        bottomU = (y==uiHeightC-1) ? tmpTarU[y*uiWidthC+x] : tmpTarU[(y+1)*uiWidthC+x];
1165        Pel topV, bottomV;
1166        topV    = (y==0)           ? tmpTarV[y*uiWidthC+x] : tmpTarV[(y-1)*uiWidthC+x];
1167        bottomV = (y==uiHeightC-1) ? tmpTarV[y*uiWidthC+x] : tmpTarV[(y+1)*uiWidthC+x];
1168
1169        if (t!=b)
1170        {
1171          filSrcU = ClipC( Pel(( topU + (tmpTarU[y*uiWidthC+x] << 1) + bottomU ) >> 2 ));
1172          filSrcV = ClipC( Pel(( topV + (tmpTarV[y*uiWidthC+x] << 1) + bottomV ) >> 2 ));
1173        }
1174        else
1175        {
1176          filSrcU = tmpTarU[y*uiWidthC+x];
1177          filSrcV = tmpTarV[y*uiWidthC+x];
1178        }
1179        piDstU[x] = filSrcU;
1180        piDstV[x] = filSrcV;
1181      }
1182      piDstU      += uiDstStrideC;
1183      piDstV      += uiDstStrideC;
1184    }
1185  }
[950]1186
[1196]1187  if( tmpTarU )
1188  {
1189    xFree(tmpTarU);
1190    tmpTarU        = NULL;
1191  }
1192  if ( tmpTarV    ) 
1193  {
1194    xFree(tmpTarV);
1195    tmpTarV        = NULL; 
1196  }
[833]1197}
1198#endif
1199
[56]1200Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
1201{
1202  Int         iWidth;
1203  Int         iHeight;
1204  UInt        uiPartAddr;
1205
1206  if ( iPartIdx >= 0 )
1207  {
1208    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
[1255]1209#if NH_3D_VSP
[622]1210    if ( pcCU->getVSPFlag(uiPartAddr) == 0)
[56]1211    {
1212#endif
[1259]1213      if ( eRefPicList != REF_PIC_LIST_X )
[56]1214      {
[1259]1215        if( pcCU->getSlice()->getPPS()->getUseWP())
1216        {
1217          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
1218        }
1219        else
1220        {
1221          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
1222        }
1223        if ( pcCU->getSlice()->getPPS()->getUseWP() )
1224        {
1225          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
1226        }
[56]1227      }
1228      else
1229      {
[1259]1230#if NH_3D_SPIVMP
[724]1231        if ( pcCU->getSPIVMPFlag(uiPartAddr)!=0) 
[608]1232        {
[724]1233          Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
1234
1235          pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
1236
1237          UInt uiW[256], uiH[256];
1238          UInt uiSPAddr[256];
1239
1240          xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr);
1241
1242          //MC
1243          for (Int i = 0; i < iNumSP; i++)
1244          {
1245            if (uiW[i]==0 || uiH[i]==0)
1246            {
1247              continue;
1248            }
1249            if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] ))
1250            {
1251              xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred );
1252            }
1253            else
1254            {
1255              xPredInterBi  (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred);
1256            }
1257          }
[608]1258        }
1259        else
1260        {
[724]1261#endif
[1259]1262          if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
1263          {
1264            xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
1265          }
1266          else
1267          {
1268            xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
1269          }
1270#if NH_3D_SPIVMP
[608]1271        }
[724]1272#endif
[1259]1273      }
[1255]1274#if NH_3D_VSP
[56]1275    }
1276    else
1277    {
[608]1278      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
[622]1279      {
[608]1280        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
[622]1281      }
[56]1282      else
[622]1283      {
[608]1284        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
[622]1285      }
[608]1286    }
[296]1287#endif
[2]1288    return;
1289  }
[56]1290
[964]1291  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ )
[56]1292  {
1293    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
1294
[1255]1295#if NH_3D_VSP
[622]1296    if ( pcCU->getVSPFlag(uiPartAddr) == 0 )
[56]1297    {
[189]1298#endif
[1200]1299    if ( eRefPicList != REF_PIC_LIST_X )
1300    {
1301      if( pcCU->getSlice()->getPPS()->getUseWP())
[56]1302      {
[1200]1303        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
[56]1304      }
[608]1305      else
[56]1306      {
[1200]1307        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
1308      }
1309      if ( pcCU->getSlice()->getPPS()->getUseWP() )
1310      {
1311        xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
1312      }
1313    }
1314    else
1315    {
[1259]1316#if NH_3D_SPIVMP
1317      if (pcCU->getSPIVMPFlag(uiPartAddr)!=0) 
[724]1318      {
1319        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
1320
1321        pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
1322
1323        UInt uiW[256], uiH[256];
1324        UInt uiSPAddr[256];
1325
1326        xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr);
1327        //MC
1328        for (Int i = 0; i < iNumSP; i++)
1329        {
1330          if (uiW[i]==0 || uiH[i]==0)
1331          {
1332            continue;
1333          }
1334          if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] ))
1335          {
1336            xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred );
1337          }
1338          else
1339          {
1340            xPredInterBi  (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred);
1341          }
1342        }
1343      }
1344      else
1345      {
1346#endif
[1259]1347        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
1348        {
1349          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
1350        }
1351        else
1352        {
1353          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
1354        }
1355#if NH_3D_SPIVMP
[1200]1356      }
[724]1357#endif
[1200]1358    }
[1255]1359#if NH_3D_VSP
[56]1360    }
1361    else
1362    {
1363      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
[622]1364      {
[608]1365        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
[622]1366      }
[56]1367      else
[622]1368      {
[608]1369        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
[622]1370      }
[56]1371    }
[608]1372#endif
[56]1373  }
1374  return;
1375}
[2]1376
[1200]1377Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv* pcYuvPred, Bool bi )
[296]1378{
[608]1379  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
1380  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
1381  pcCU->clipMv(cMv);
[1200]1382#if NH_MV
[1196]1383  pcCU->checkMvVertRest(cMv, eRefPicList, iRefIdx );
[1179]1384#endif
[608]1385#if H_3D_ARP
[724]1386  if(pcCU->getARPW( uiPartAddr ) > 0  && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC())
1387  {
[773]1388    xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , rpcYuvPred , bi );
[724]1389  }
1390  else
[443]1391  {
[773]1392    if(  pcCU->getARPW( uiPartAddr ) > 0 
1393      && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N
1394      && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() 
1395      )
1396    {
1397      xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi );
1398    }
1399    else
1400    {
[443]1401#endif
[608]1402#if H_3D_IC
[773]1403      Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() );
1404      xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
[608]1405#if H_3D_ARP
[773]1406        , false
[443]1407#endif
[773]1408        , bICFlag );
1409      bICFlag = bICFlag && (iWidth > 8);
1410      xPredInterChromaBlk( 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 );
[443]1415#else
[1200]1416
1417  for (UInt comp=COMPONENT_Y; comp<pcYuvPred->getNumberValidComponents(); comp++)
1418  {
1419    const ComponentID compID=ComponentID(comp);
1420    xPredInterBlk  (compID,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)) );
1421  }
[443]1422#endif
[608]1423#if H_3D_ARP
[773]1424    }
[443]1425  }
1426#endif
1427}
1428
[1255]1429#if NH_3D_VSP
[608]1430Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
[56]1431{
[833]1432  Int vspSize = pcCU->getVSPFlag( uiPartAddr ) >> 1;
1433
1434  Int widthSubPU, heightSubPU;
1435  if (vspSize)
1436  {
1437    widthSubPU  = 8;
1438    heightSubPU = 4;
1439  }
1440  else
1441  {
1442    widthSubPU  = 4;
1443    heightSubPU = 8;
1444  }
1445  xPredInterUniSubPU( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi, widthSubPU, heightSubPU );
[608]1446}
[833]1447
1448Void TComPrediction::xPredInterUniSubPU( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, Int widthSubPU, Int heightSubPU )
1449{
[1255]1450  UInt numPartsInLine       = pcCU->getPic()->getNumPartInCtuWidth();
[833]1451  UInt horiNumPartsInSubPU  = widthSubPU >> 2;
1452  UInt vertNumPartsInSubPU  = (heightSubPU >> 2) * numPartsInLine;
1453
1454  UInt partAddrRasterLine = g_auiZscanToRaster[ uiPartAddr ];
1455
1456  for( Int posY=0; posY<iHeight; posY+=heightSubPU, partAddrRasterLine+=vertNumPartsInSubPU )
1457  {
1458    UInt partAddrRasterSubPU = partAddrRasterLine;
1459    for( Int posX=0; posX<iWidth; posX+=widthSubPU, partAddrRasterSubPU+=horiNumPartsInSubPU )
1460    {
1461      UInt    partAddrSubPU = g_auiRasterToZscan[ partAddrRasterSubPU ];
1462      Int     refIdx        = pcCU->getCUMvField( eRefPicList )->getRefIdx( partAddrSubPU );           assert (refIdx >= 0);
1463      TComMv  cMv           = pcCU->getCUMvField( eRefPicList )->getMv( partAddrSubPU );
1464      pcCU->clipMv(cMv);
1465
[1255]1466      xPredInterBlk( COMPONENT_Y,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) );
1467      xPredInterBlk( COMPONENT_Cb, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA) );
1468      xPredInterBlk( COMPONENT_Cr, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA) );
[833]1469    }
1470  }
1471}
[296]1472#endif
[189]1473
[608]1474#if H_3D_ARP
1475Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
1476{
1477  Int         iRefIdx      = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
1478  TComMv      cMv          = pNewMvFiled ? pNewMvFiled->getMv()     : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
1479  Bool        bTobeScaled  = false;
1480  TComPic* pcPicYuvBaseCol = NULL;
1481  TComPic* pcPicYuvBaseRef = NULL;
[2]1482
[1210]1483#if NH_3D_NBDV
[443]1484  DisInfo cDistparity;
[1179]1485  cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV;
1486  cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
1487#else
[608]1488  assert(0); // ARP can be applied only when a DV is available
[443]1489#endif
[1179]1490  UChar dW = pcCU->getARPW ( uiPartAddr );
[608]1491
[443]1492  {
[724]1493    Int arpRefIdx = pcCU->getSlice()->getFirstTRefIdx(eRefPicList);
1494    if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() )
[608]1495    {
[443]1496      bTobeScaled = true;
[608]1497    }
1498
1499    pcPicYuvBaseCol =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(),                              cDistparity.m_aVIdxCan );
[724]1500
1501    pcPicYuvBaseRef =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC(), cDistparity.m_aVIdxCan );
1502
1503    if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, cDistparity.m_aVIdxCan))
[443]1504    {
1505      dW = 0;
1506      bTobeScaled = false;
1507    }
1508    else
[608]1509    {
[724]1510      assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC() );
[608]1511    }
1512
[443]1513    if(bTobeScaled)
1514    {     
[608]1515      Int iCurrPOC    = pcCU->getSlice()->getPOC();
[443]1516      Int iColRefPOC  = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx );
1517      Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList,  0);
1518      Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC);
1519      if ( iScale != 4096 )
[608]1520      {
[443]1521        cMv = cMv.scaleMv( iScale );
[608]1522      }
[443]1523      iRefIdx = 0;
1524    }
1525  }
[608]1526
[443]1527  pcCU->clipMv(cMv);
1528  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec();
[1039]1529  xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 ), true );
1530  xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 ), true );
[1084]1531
[443]1532  if( dW > 0 )
1533  {
[608]1534    TComYuv * pYuvB0 = &m_acYuvPredBase[0];
[443]1535    TComYuv * pYuvB1  = &m_acYuvPredBase[1];
[608]1536
1537    TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV;
1538    pcCU->clipMv(cMVwithDisparity);
[1039]1539    if (iWidth <= 8)
1540    {
1541      pYuvB0->clear(); pYuvB1->clear();
1542    }
[950]1543    TComMv cNBDV = cDistparity.m_acNBDV;
1544    pcCU->clipMv( cNBDV );
1545   
[443]1546    pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec();
[1039]1547    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, true, true );
1548    if (iWidth > 8)
[1084]1549      xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, true, true );
[608]1550   
[443]1551    pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec();
[1039]1552    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, true, true );
[1084]1553 
[1039]1554    if (iWidth > 8)
[1084]1555      xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, true, true );
1556   
[608]1557    pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight );
1558
1559    if( 2 == dW )
1560    {
1561      pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
1562    }
1563    rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi );
[443]1564  }
1565}
[1039]1566
1567Bool TComPrediction::xCheckBiInterviewARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eBaseRefPicList, TComPic*& pcPicYuvCurrTRef, TComMv& cBaseTMV, Int& iCurrTRefPoc )
1568{
1569  Int         iRefIdx       = pcCU->getCUMvField( eBaseRefPicList )->getRefIdx( uiPartAddr );
1570  TComMv      cDMv          = pcCU->getCUMvField( eBaseRefPicList )->getMv( uiPartAddr );
1571  TComPic* pcPicYuvBaseCol  = pcCU->getSlice()->getRefPic( eBaseRefPicList, iRefIdx ); 
1572  TComPicYuv* pcYuvBaseCol  = pcPicYuvBaseCol->getPicYuvRec();
1573  Int uiLCUAddr,uiAbsPartAddr;
1574  Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2  + ((cDMv.getHor() + 2)>>2);
1575  Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2);
1576
1577  irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX);
1578  irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); 
1579  pcYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr);
1580  TComDataCU *pColCU = pcPicYuvBaseCol->getCU( uiLCUAddr );
1581
1582  TComPic* pcPicYuvBaseTRef = NULL;
1583  pcPicYuvCurrTRef = NULL;
1584
1585  //If there is available motion in base reference list, use it
1586  if(!pColCU->isIntra(uiAbsPartAddr))
1587  {
1588    for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1); iList ++)
1589    {
1590      RefPicList eRefPicListCurr = RefPicList(iList);
1591      Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr);
1592      if( iRef != -1)
1593      {
1594        pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); 
1595        Int  iCurrPOC    = pColCU->getSlice()->getPOC();
1596        Int  iCurrRefPOC = pcPicYuvBaseTRef->getPOC();
1597        Int  iCurrRef    = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr);
[1084]1598
[1039]1599        if( iCurrRef >= 0 && iCurrPOC != iCurrRefPOC)
1600        {
1601          pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); 
1602          Int iTargetPOC = pcPicYuvCurrTRef->getPOC();
1603          pcPicYuvBaseTRef =  pcCU->getSlice()->getBaseViewRefPic(iTargetPOC,  pcPicYuvBaseCol->getViewIndex() ); 
1604          if(pcPicYuvBaseTRef)
1605          {
1606            cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr);
1607            Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC);
1608            if ( iScale != 4096 )
1609            {
1610              cBaseTMV = cBaseTMV.scaleMv( iScale );
1611            }
1612            iCurrTRefPoc = iTargetPOC;
1613            return true;
1614          }
1615        }
1616      }
1617    }
1618  }
1619
1620  //If there is no available motion in base reference list, use ( 0, 0 )
1621  if( pcCU->getSlice()->getFirstTRefIdx( eBaseRefPicList ) >= 0 )
1622  {
1623    cBaseTMV.set( 0, 0 );
1624    pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic( eBaseRefPicList,  pcCU->getSlice()->getFirstTRefIdx( eBaseRefPicList ) );
1625    iCurrTRefPoc = pcPicYuvCurrTRef->getPOC();
1626    return true;
1627  }
1628
1629  return false;
1630}
1631
[724]1632Void TComPrediction::xPredInterUniARPviewRef( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
1633{
1634  Int         iRefIdx       = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
1635  TComMv      cDMv          = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
1636  TComMv      cTempDMv      = cDMv;
1637  UChar       dW            = pcCU->getARPW ( uiPartAddr );
1638
1639  TComPic* pcPicYuvBaseTRef = NULL;
1640  TComPic* pcPicYuvCurrTRef = NULL;
1641  TComPic* pcPicYuvBaseCol  = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx ); 
1642  TComPicYuv* pcYuvBaseCol  = pcPicYuvBaseCol->getPicYuvRec();   
1643  Bool bTMVAvai = false;     
1644  TComMv cBaseTMV;
1645  if( pNewMvFiled )
1646  {
1647    iRefIdx = pNewMvFiled->getRefIdx(); 
1648    cDMv = pNewMvFiled->getMv();
1649  }
1650  pcCU->clipMv(cTempDMv);
1651
1652  assert(dW > 0);
1653  if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, pcPicYuvBaseCol->getViewIndex()))
1654  {
1655    dW = 0;
1656  }
1657  Int uiLCUAddr,uiAbsPartAddr;
1658  Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2  + ((cDMv.getHor() + 2)>>2);
1659  Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2);
[443]1660
[724]1661  irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX);
1662  irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); 
1663  pcYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr);
1664  TComDataCU *pColCU = pcPicYuvBaseCol->getCU( uiLCUAddr );
[1039]1665  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getIsDepth() )
1666  {
1667    RefPicList eOtherRefList = ( eRefPicList == REF_PIC_LIST_0 ) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
1668    Int iOtherRefIdx = pcCU->getCUMvField( eOtherRefList )->getRefIdx( uiPartAddr );
1669    //The other prediction direction is temporal ARP
1670    if( iOtherRefIdx >= 0 && pcCU->getSlice()->getViewIndex() == pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx )->getViewIndex() )
1671    {
1672      bTMVAvai = true;
1673      pcPicYuvBaseTRef = pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx );
1674      Int  iCurrPOC    = pcCU->getSlice()->getPOC();
1675      Int  iCurrRefPOC = pcPicYuvBaseTRef->getPOC();
1676      Int  iCurrRef    = pcCU->getSlice()->getFirstTRefIdx( eOtherRefList );
1677     
1678      if( iCurrRef >= 0 )
1679      {
1680        pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic( eOtherRefList,iCurrRef ); 
1681        Int iTargetPOC = pcPicYuvCurrTRef->getPOC();
1682        pcPicYuvBaseTRef =  pcCU->getSlice()->getBaseViewRefPic( iTargetPOC,  pcPicYuvBaseCol->getViewIndex() );
1683        if( pcPicYuvBaseTRef )
1684        {
1685          cBaseTMV = pcCU->getCUMvField( eOtherRefList )->getMv( uiPartAddr );
1686          Int iScale = pcCU-> xGetDistScaleFactor( iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC );
1687          if ( iScale != 4096 )
1688          {
1689            cBaseTMV = cBaseTMV.scaleMv( iScale );
1690          }
1691        }
1692        else
1693        {
1694          dW = 0;
1695        }
1696      }
1697      else
1698      {
1699        dW = 0;
1700      }
1701    }
[724]1702
[1039]1703    //Both prediction directions are inter-view ARP
1704    if ( iOtherRefIdx >= 0 && !bTMVAvai )
1705    {
1706      RefPicList eBaseList = REF_PIC_LIST_0;
1707      Int iCurrTRefPoc;
1708      bTMVAvai = ( eBaseList != eRefPicList ) && ( pcCU->getSlice()->getViewIndex() != pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx )->getViewIndex() );
1709
1710      if ( bTMVAvai )
1711      {
1712        if( xCheckBiInterviewARP( pcCU, uiPartAddr, iWidth, iHeight, eBaseList, pcPicYuvCurrTRef, cBaseTMV, iCurrTRefPoc ) )
1713        {
1714          pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic( iCurrTRefPoc,  pcPicYuvBaseCol->getViewIndex() );
1715          if ( pcPicYuvBaseTRef == NULL )
1716          {
1717            dW = 0;
1718          }
1719        }
1720        else
1721        {
1722          dW = 0;
1723        }
1724      }
1725    }
1726  }
1727
1728  if( !pColCU->isIntra( uiAbsPartAddr ) && !bTMVAvai )
[724]1729  {
1730    TComMvField puMVField;
1731    for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1) && !bTMVAvai; iList ++)
1732    {
1733      RefPicList eRefPicListCurr = RefPicList(iList);
1734      Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr);
1735      if( iRef != -1)
1736      {
1737        pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); 
1738        Int  iCurrPOC    = pColCU->getSlice()->getPOC();
1739        Int  iCurrRefPOC = pcPicYuvBaseTRef->getPOC();
1740        Int  iCurrRef    = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr);
[1039]1741        if (iCurrRef >= 0 && iCurrRefPOC != iCurrPOC)
[724]1742        {
1743          pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); 
1744          Int iTargetPOC = pcPicYuvCurrTRef->getPOC();
1745          {
1746            pcPicYuvBaseTRef =  pcCU->getSlice()->getBaseViewRefPic(iTargetPOC,  pcPicYuvBaseCol->getViewIndex() ); 
1747            if(pcPicYuvBaseTRef)
1748            {
1749              cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr);
1750              Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC);
1751              if ( iScale != 4096 )
1752                cBaseTMV = cBaseTMV.scaleMv( iScale );                 
1753              bTMVAvai = true;
1754              break;
1755            }
1756          }
1757        }
1758      }
1759    }
1760  }
1761  if (bTMVAvai == false)
1762  { 
1763    bTMVAvai = true;
1764    cBaseTMV.set(0, 0);
1765    pcPicYuvBaseTRef =  pColCU->getSlice()->getRefPic(eRefPicList,  pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); 
1766    pcPicYuvCurrTRef =  pcCU->getSlice()->getRefPic  (eRefPicList,  pcCU->getSlice()->getFirstTRefIdx(eRefPicList));     
1767  }
[1084]1768
[1039]1769  xPredInterLumaBlk  ( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 && bTMVAvai ),        bTMVAvai);
1770  xPredInterChromaBlk( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 && bTMVAvai ),        bTMVAvai);
[1084]1771
[724]1772  if( dW > 0 && bTMVAvai ) 
1773  {
1774    TComYuv*    pYuvCurrTRef    = &m_acYuvPredBase[0];
1775    TComYuv*    pYuvBaseTRef    = &m_acYuvPredBase[1];
1776    TComPicYuv* pcYuvCurrTref   = pcPicYuvCurrTRef->getPicYuvRec();       
1777    TComPicYuv* pcYuvBaseTref   = pcPicYuvBaseTRef->getPicYuvRec(); 
1778    TComMv      cTempMv         = cDMv + cBaseTMV;
1779
1780    pcCU->clipMv(cBaseTMV);
1781    pcCU->clipMv(cTempMv);
[1084]1782
[1039]1783    if (iWidth <= 8)
1784    {
1785      pYuvCurrTRef->clear(); pYuvBaseTRef->clear();
1786    }
1787    xPredInterLumaBlk  ( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, true,   true);
[1084]1788
[1039]1789    if (iWidth > 8)
[1084]1790      xPredInterChromaBlk( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, true,   true);
1791
[1039]1792    xPredInterLumaBlk  ( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, true,   true); 
[1084]1793
[1039]1794    if (iWidth > 8)
[1084]1795      xPredInterChromaBlk( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv,  iWidth, iHeight, pYuvBaseTRef, true,   true); 
[724]1796
1797    pYuvCurrTRef->subtractARP( pYuvCurrTRef , pYuvBaseTRef , uiPartAddr , iWidth , iHeight ); 
1798    if(dW == 2)
1799    {
1800      pYuvCurrTRef->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
1801    }
1802    rpcYuvPred->addARP( rpcYuvPred , pYuvCurrTRef , uiPartAddr , iWidth , iHeight , !bi ); 
1803  }
1804}
1805#endif
1806
[1200]1807Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv* pcYuvPred )
[2]1808{
[56]1809  TComYuv* pcMbYuv;
[1200]1810  Int      iRefIdx[NUM_REF_PIC_LIST_01] = {-1, -1};
[56]1811
[1200]1812  for ( UInt refList = 0; refList < NUM_REF_PIC_LIST_01; refList++ )
[56]1813  {
[1200]1814    RefPicList eRefPicList = (refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
1815    iRefIdx[refList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
[56]1816
[1200]1817    if ( iRefIdx[refList] < 0 )
[56]1818    {
1819      continue;
1820    }
1821
[1200]1822    assert( iRefIdx[refList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
[56]1823
[1200]1824    pcMbYuv = &m_acYuvPred[refList];
[56]1825    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
1826    {
[608]1827      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
[56]1828    }
1829    else
1830    {
[1200]1831      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) ||
1832           ( pcCU->getSlice()->getPPS()->getWPBiPred()    && pcCU->getSlice()->getSliceType() == B_SLICE ) )
[56]1833      {
[608]1834        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
[56]1835      }
1836      else
1837      {
[608]1838        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
[56]1839      }
1840    }
1841  }
[608]1842
[1200]1843  if ( pcCU->getSlice()->getPPS()->getWPBiPred()    && pcCU->getSlice()->getSliceType() == B_SLICE  )
[56]1844  {
[1200]1845    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 );
1846  }
[313]1847  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
1848  {
[1200]1849    xWeightedPredictionUni( pcCU, &m_acYuvPred[REF_PIC_LIST_0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
[313]1850  }
[56]1851  else
1852  {
[1200]1853    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]1854  }
[2]1855}
1856
[1255]1857#if NH_3D_VSP
[608]1858Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
1859{
1860  TComYuv* pcMbYuv;
1861  Int      iRefIdx[2] = {-1, -1};
1862  Bool     bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0);
[296]1863
[608]1864  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
[2]1865  {
[608]1866    RefPicList eRefPicList = RefPicList(iRefList);
1867    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
[56]1868
[608]1869    if ( iRefIdx[iRefList] < 0 )
[622]1870    {
[608]1871      continue;
[622]1872    }
[608]1873    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
[56]1874
[608]1875    pcMbYuv = &m_acYuvPred[iRefList];
1876    xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi );
[2]1877  }
[296]1878
[1255]1879  xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred, pcCU->getSlice()->getSPS()->getBitDepths() );
[608]1880}
[296]1881#endif
[56]1882
1883/**
[1200]1884 * \brief Generate motion-compensated block
[56]1885 *
[1200]1886 * \param compID     Colour component ID
1887 * \param cu         Pointer to current CU
1888 * \param refPic     Pointer to reference picture
1889 * \param partAddr   Address of block within CU
1890 * \param mv         Motion vector
1891 * \param width      Width of block
1892 * \param height     Height of block
1893 * \param dstPic     Pointer to destination picture
1894 * \param bi         Flag indicating whether bipred is used
1895 * \param  bitDepth  Bit depth
[56]1896 */
[1200]1897
1898
1899Void 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]1900#if H_3D_ARP
1901    , Bool filterType
[189]1902#endif
[608]1903#if H_3D_IC
1904    , Bool bICFlag
1905#endif
[1200]1906)
[56]1907{
[1200]1908  Int     refStride  = refPic->getStride(compID);
1909  Int     dstStride  = dstPic->getStride(compID);
1910  Int shiftHor=(2+refPic->getComponentScaleX(compID));
1911  Int shiftVer=(2+refPic->getComponentScaleY(compID));
[56]1912
[1200]1913  Int     refOffset  = (mv->getHor() >> shiftHor) + (mv->getVer() >> shiftVer) * refStride;
1914
1915  Pel*    ref     = refPic->getAddr(compID, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refOffset;
1916
1917  Pel*    dst = dstPic->getAddr( compID, partAddr );
1918
1919  Int     xFrac  = mv->getHor() & ((1<<shiftHor)-1);
1920  Int     yFrac  = mv->getVer() & ((1<<shiftVer)-1);
1921
[608]1922#if H_3D_IC
1923  if( cu->getSlice()->getIsDepth() )
1924  {
1925    refOffset = mv->getHor() + mv->getVer() * refStride;
1926    ref       = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1927    xFrac     = 0;
1928    yFrac     = 0;
1929  }
[56]1930#endif
[1200]1931
1932  UInt    cxWidth  = width  >> refPic->getComponentScaleX(compID);
1933  UInt    cxHeight = height >> refPic->getComponentScaleY(compID);
1934
1935  const ChromaFormat chFmt = cu->getPic()->getChromaFormat();
1936
[56]1937  if ( yFrac == 0 )
[2]1938  {
[655]1939#if H_3D_IC
[608]1940    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi || bICFlag
1941#else
[1200]1942    m_if.filterHor(compID, ref, refStride, dst,  dstStride, cxWidth, cxHeight, xFrac, !bi, chFmt, bitDepth
[443]1943#endif
[1200]1944#if H_3D_ARP
[608]1945    , filterType
[1200]1946#endif
1947);
[2]1948  }
[56]1949  else if ( xFrac == 0 )
1950  {
[655]1951#if H_3D_IC
[608]1952    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag
1953#else
[1200]1954    m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi, chFmt, bitDepth
[443]1955#endif
[608]1956#if H_3D_ARP
1957    , filterType
1958#endif
[1200]1959);
[56]1960  }
1961  else
1962  {
[1200]1963    Int   tmpStride = m_filteredBlockTmp[0].getStride(compID);
1964    Pel*  tmp       = m_filteredBlockTmp[0].getAddr(compID);
[56]1965
[1200]1966    const Int vFilterSize = isLuma(compID) ? NTAPS_LUMA : NTAPS_CHROMA;
[56]1967
[1200]1968    m_if.filterHor(compID, ref - ((vFilterSize>>1) -1)*refStride, refStride, tmp, tmpStride, cxWidth, cxHeight+vFilterSize-1, xFrac, false,      chFmt, bitDepth
[608]1969#if H_3D_ARP
1970    , filterType
[443]1971#endif
[1200]1972);
[655]1973#if H_3D_IC
[608]1974    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi || bICFlag
1975#else
[1200]1976    m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight,               yFrac, false, !bi, chFmt, bitDepth
[608]1977#endif
1978#if H_3D_ARP
1979    , filterType
[443]1980#endif
[1200]1981);
[56]1982  }
[189]1983
[608]1984#if H_3D_IC
1985  if( bICFlag )
[189]1986  {
[608]1987    Int a, b, i, j;
1988    const Int iShift = IC_CONST_SHIFT;
1989
1990    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA );
[189]1991
1992
[608]1993    for ( i = 0; i < height; i++ )
[189]1994    {
[608]1995      for ( j = 0; j < width; j++ )
[189]1996      {
[608]1997          dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
[189]1998      }
1999      dst += dstStride;
2000    }
[655]2001
[608]2002    if(bi)
2003    {
2004      Pel *dst2      = dstPic->getLumaAddr( partAddr );
2005      Int shift = IF_INTERNAL_PREC - g_bitDepthY;
2006      for (i = 0; i < height; i++)
2007      {
2008        for (j = 0; j < width; j++)
2009        {
2010          Short val = dst2[j] << shift;
2011          dst2[j] = val - (Short)IF_INTERNAL_OFFS;
2012        }
2013        dst2 += dstStride;
2014      }
2015    }
[189]2016  }
2017#endif
[1200]2018
[2]2019}
2020
[1200]2021
[608]2022#if H_3D_ARP
2023    , Bool filterType
[189]2024#endif
[608]2025#if H_3D_IC
2026    , Bool bICFlag
2027#endif
[655]2028#if H_3D_IC
[608]2029    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
2030#else
2031#endif
2032#if H_3D_ARP
2033    , filterType
2034#endif
[655]2035#if H_3D_IC
[608]2036    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
2037#else
2038#endif
2039#if H_3D_ARP
2040    , filterType
2041#endif
[655]2042#if H_3D_IC
[608]2043    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
2044#else
2045#endif
2046#if H_3D_ARP
2047    , filterType
2048#endif
[655]2049#if H_3D_IC
[608]2050    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
2051#else
2052#endif
2053#if H_3D_ARP
2054    , filterType
2055#endif
2056#if H_3D_ARP
2057    , filterType
2058#endif 
[655]2059#if H_3D_IC
[608]2060    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
2061#else
2062#endif
2063#if H_3D_ARP
2064    , filterType
2065#endif
2066#if H_3D_ARP
2067    , filterType
2068#endif
[655]2069#if H_3D_IC
[608]2070    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
2071#else
2072#endif
2073#if H_3D_ARP
2074    , filterType
2075#endif
2076#if H_3D_IC
2077  if( bICFlag )
[189]2078  {
[608]2079    Int a, b, i, j;
2080    const Int iShift = IC_CONST_SHIFT;
[1124]2081
[608]2082    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb
2083    for ( i = 0; i < cxHeight; i++ )
[189]2084    {
[608]2085      for ( j = 0; j < cxWidth; j++ )
[189]2086      {
[608]2087          dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
[189]2088      }
2089      dstCb += dstStride;
2090    }
[608]2091    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr
2092    for ( i = 0; i < cxHeight; i++ )
[189]2093    {
[608]2094      for ( j = 0; j < cxWidth; j++ )
[189]2095      {
[608]2096          dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
[189]2097      }
2098      dstCr += dstStride;
2099    }
[655]2100
[608]2101    if(bi)
[296]2102    {
[608]2103      Pel* dstCb2 = dstPic->getCbAddr( partAddr );
2104      Pel* dstCr2 = dstPic->getCrAddr( partAddr );
2105      Int shift = IF_INTERNAL_PREC - g_bitDepthC;
2106      for (i = 0; i < cxHeight; i++)
[296]2107      {
[608]2108        for (j = 0; j < cxWidth; j++)
[296]2109        {
[608]2110          Short val = dstCb2[j] << shift;
2111          dstCb2[j] = val - (Short)IF_INTERNAL_OFFS;
[461]2112
[608]2113          val = dstCr2[j] << shift;
2114          dstCr2[j] = val - (Short)IF_INTERNAL_OFFS;
[296]2115        }
[608]2116        dstCb2 += dstStride;
2117        dstCr2 += dstStride;
[443]2118      }
2119    }
[296]2120  }
[443]2121#endif
[1200]2122Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv* pcYuvDst, const BitDepths &clipBitDepths
2123 )
[2]2124{
[56]2125  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
[2]2126  {
[1200]2127    pcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight, clipBitDepths );
[2]2128  }
[56]2129  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
[2]2130  {
[1200]2131    pcYuvSrc0->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight );
[2]2132  }
[56]2133  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
[2]2134  {
[1200]2135    pcYuvSrc1->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight );
[56]2136  }
2137}
2138
2139// AMVP
[608]2140Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
[56]2141{
2142  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
[1200]2143
[608]2144  if( pcAMVPInfo->iN <= 1 )
[56]2145  {
2146    rcMvPred = pcAMVPInfo->m_acMvCand[0];
2147
2148    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
2149    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
2150    return;
2151  }
2152
2153  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
2154  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
2155  return;
2156}
2157
2158/** Function for deriving planar intra prediction.
[1200]2159 * \param pSrc        pointer to reconstructed sample array
2160 * \param srcStride   the stride of the reconstructed sample array
2161 * \param rpDst       reference to pointer for the prediction sample array
2162 * \param dstStride   the stride of the prediction sample array
2163 * \param width       the width of the block
2164 * \param height      the height of the block
2165 * \param channelType type of pel array (luma, chroma)
2166 * \param format      chroma format
[56]2167 *
2168 * This function derives the prediction samples for planar mode (intra coding).
2169 */
[1200]2170//NOTE: Bit-Limit - 24-bit source
2171Void TComPrediction::xPredIntraPlanar( const Pel* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
[56]2172{
[1200]2173  assert(width <= height);
[56]2174
[655]2175  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
[1200]2176  UInt shift1Dhor = g_aucConvertToBit[ width ] + 2;
2177  UInt shift1Dver = g_aucConvertToBit[ height ] + 2;
[56]2178
2179  // Get left and above reference column and row
[1200]2180  for(Int k=0;k<width+1;k++)
[56]2181  {
2182    topRow[k] = pSrc[k-srcStride];
[1200]2183  }
2184
2185  for (Int k=0; k < height+1; k++)
2186  {
[56]2187    leftColumn[k] = pSrc[k*srcStride-1];
2188  }
2189
2190  // Prepare intermediate variables used in interpolation
[1200]2191  Int bottomLeft = leftColumn[height];
2192  Int topRight   = topRow[width];
2193
2194  for(Int k=0;k<width;k++)
[56]2195  {
[1200]2196    bottomRow[k]  = bottomLeft - topRow[k];
2197    topRow[k]     <<= shift1Dver;
[56]2198  }
2199
[1200]2200  for(Int k=0;k<height;k++)
2201  {
2202    rightColumn[k]  = topRight - leftColumn[k];
2203    leftColumn[k]   <<= shift1Dhor;
2204  }
2205
2206  const UInt topRowShift = 0;
2207
[56]2208  // Generate prediction signal
[1200]2209  for (Int y=0;y<height;y++)
[56]2210  {
[1200]2211    Int horPred = leftColumn[y] + width;
2212    for (Int x=0;x<width;x++)
[2]2213    {
[1200]2214      horPred += rightColumn[y];
2215      topRow[x] += bottomRow[x];
2216
2217      Int vertPred = ((topRow[x] + topRowShift)>>topRowShift);
2218      rpDst[y*dstStride+x] = ( horPred + vertPred ) >> (shift1Dhor+1);
[2]2219    }
2220  }
2221}
2222
[608]2223/** Function for filtering intra DC predictor.
2224 * \param pSrc pointer to reconstructed sample array
2225 * \param iSrcStride the stride of the reconstructed sample array
[1200]2226 * \param pDst reference to pointer for the prediction sample array
[608]2227 * \param iDstStride the stride of the prediction sample array
2228 * \param iWidth the width of the block
2229 * \param iHeight the height of the block
[1200]2230 * \param channelType type of pel array (luma, chroma)
[56]2231 *
[608]2232 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
[56]2233 */
[1200]2234Void TComPrediction::xDCPredFiltering( const Pel* pSrc, Int iSrcStride, Pel* pDst, Int iDstStride, Int iWidth, Int iHeight, ChannelType channelType )
[56]2235{
[608]2236  Int x, y, iDstStride2, iSrcStride2;
[2]2237
[1200]2238  if (isLuma(channelType) && (iWidth <= MAXIMUM_INTRA_FILTERED_WIDTH) && (iHeight <= MAXIMUM_INTRA_FILTERED_HEIGHT))
[2]2239  {
[1200]2240    //top-left
2241    pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
[2]2242
[1200]2243    //top row (vertical filter)
2244    for ( x = 1; x < iWidth; x++ )
2245    {
2246      pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
2247    }
2248
2249    //left column (horizontal filter)
2250    for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
2251    {
2252      pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
2253    }
[56]2254  }
[2]2255
[608]2256  return;
[2]2257}
[1200]2258
2259/* Static member function */
2260Bool TComPrediction::UseDPCMForFirstPassIntraEstimation(TComTU &rTu, const UInt uiDirMode)
2261{
2262  return (rTu.getCU()->isRDPCMEnabled(rTu.GetAbsPartIdxTU()) ) &&
2263          rTu.getCU()->getCUTransquantBypass(rTu.GetAbsPartIdxTU()) &&
2264          (uiDirMode==HOR_IDX || uiDirMode==VER_IDX);
2265}
[608]2266#if H_3D_IC
2267/** Function for deriving the position of first non-zero binary bit of a value
[56]2268 * \param x input value
2269 *
[608]2270 * This function derives the position of first non-zero binary bit of a value
[56]2271 */
2272Int GetMSB( UInt x )
2273{
2274  Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1;
2275
2276  while( x > 1 )
2277  {
2278    bits >>= 1;
2279    y = x >> bits;
2280
2281    if( y )
2282    {
2283      x = y;
2284      iMSB += bits;
2285    }
2286  }
2287
2288  iMSB+=y;
2289
2290  return iMSB;
2291}
2292
2293
[608]2294/** Function for deriving LM illumination compensation.
[56]2295 */
[608]2296Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType )
[56]2297{
[608]2298  TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
2299  Pel *pRec = NULL, *pRef = NULL;
2300  UInt uiWidth, uiHeight, uiTmpPartIdx;
2301  Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride();
2302  Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride();
[1039]2303  Int iRefOffset, iHor, iVer;
[608]2304  iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 );
2305  iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 );
2306  if( eType != TEXT_LUMA )
2307  {
2308    iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 );
2309    iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 );
2310  }
2311  uiWidth  = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 )  : ( pcCU->getWidth( 0 )  >> 1 );
2312  uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 );
[56]2313
2314  Int i, j, iCountShift = 0;
2315
2316  // LLS parameters estimation -->
2317
2318  Int x = 0, y = 0, xx = 0, xy = 0;
[608]2319  Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12);
[56]2320
[1039]2321  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) )
[56]2322  {
[608]2323    iRefOffset = iHor + iVer * iRefStride - iRefStride;
2324    if( eType == TEXT_LUMA )
[56]2325    {
[608]2326      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2327      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
[56]2328    }
[608]2329    else if( eType == TEXT_CHROMA_U )
[56]2330    {
[608]2331      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2332      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
[56]2333    }
[608]2334    else
2335    {
2336      assert( eType == TEXT_CHROMA_V );
2337      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2338      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
2339    }
[56]2340
[608]2341    for( j = 0; j < uiWidth; j+=2 )
[189]2342    {
2343      x += pRef[j];
2344      y += pRec[j];
[1124]2345      if ( eType == TEXT_LUMA )
2346      {
2347        xx += (pRef[j] * pRef[j])>>precShift;
2348        xy += (pRef[j] * pRec[j])>>precShift;
2349      }
[189]2350    }
[608]2351    iCountShift += g_aucConvertToBit[ uiWidth ] + 1;
[189]2352  }
2353
[1039]2354  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) )
[189]2355  {
[608]2356    iRefOffset = iHor + iVer * iRefStride - 1;
2357    if( eType == TEXT_LUMA )
2358    {
2359      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2360      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
2361    }
2362    else if( eType == TEXT_CHROMA_U )
2363    {
2364      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2365      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
2366    }
2367    else
2368    {
2369      assert( eType == TEXT_CHROMA_V );
2370      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
2371      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
2372    }
2373
2374    for( i = 0; i < uiHeight; i+=2 )
[189]2375    {
2376      x += pRef[0];
2377      y += pRec[0];
[1124]2378      if ( eType == TEXT_LUMA )
2379      {
2380        xx += (pRef[0] * pRef[0])>>precShift;
2381        xy += (pRef[0] * pRec[0])>>precShift;
2382      }
[608]2383      pRef += iRefStride*2;
2384      pRec += iRecStride*2;
[189]2385    }
[608]2386    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 );
[189]2387  }
2388
[1039]2389  if( iCountShift == 0 )
2390  {
2391    a = ( 1 << IC_CONST_SHIFT );
2392    b = 0;
2393    return;
2394  }
2395
[1124]2396  if (  eType != TEXT_LUMA )
2397  {
2398    a = 32;
2399    b = (  y - x + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
2400  }
2401  else
2402  {
[608]2403  xy += xx >> IC_REG_COST_SHIFT;
2404  xx += xx >> IC_REG_COST_SHIFT;
2405  Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift);
2406  Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift);
2407  const Int iShift = IC_CONST_SHIFT;
2408  {
[189]2409    {
2410      const Int iShiftA2 = 6;
2411      const Int iAccuracyShift = 15;
2412
2413      Int iScaleShiftA2 = 0;
2414      Int iScaleShiftA1 = 0;
2415      Int a1s = a1;
2416      Int a2s = a2;
2417
[608]2418      a1 = Clip3(0, 2*a2, a1);
2419      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2;
2420      iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF;
[189]2421
2422      if( iScaleShiftA1 < 0 )
2423      {
2424        iScaleShiftA1 = 0;
2425      }
2426
2427      if( iScaleShiftA2 < 0 )
2428      {
2429        iScaleShiftA2 = 0;
2430      }
2431
2432      Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
2433
[608]2434
[189]2435      a2s = a2 >> iScaleShiftA2;
2436
2437      a1s = a1 >> iScaleShiftA1;
2438
[608]2439      a = a1s * m_uiaShift[ a2s ];
2440      a = a >> iScaleShiftA;
[189]2441      b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
2442    }
2443  }   
[1124]2444  }
[189]2445}
[608]2446#endif
[189]2447
[608]2448#if H_3D_DIM
2449Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
[2]2450{
[608]2451  Int  refDC1, refDC2;
2452  const Int  iTR = (   patternStride - 1        ) - srcStride;
2453  const Int  iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride;
2454  const Int  iLB = (   patternStride - 1        ) * srcStride - 1;
2455  const Int  iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1;
[2]2456
[608]2457  Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] );
2458  Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)]               );
2459
2460  if( bL == bT )
[56]2461  {
[833]2462    const Int  iTRR = ( patternStride * 2 - 1  ) - srcStride; 
2463    const Int  iLBB = ( patternStride * 2 - 1  ) * srcStride - 1;
2464    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : (abs(ptrSrc[iTRR] - ptrSrc[-(Int)srcStride]) > abs(ptrSrc[iLBB] - ptrSrc[ -1]) ? ptrSrc[iTRR] : ptrSrc[iLBB]);
[608]2465    refDC2 =      ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1;
[56]2466  }
2467  else
2468  {
[608]2469    refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR];
2470    refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM];
[56]2471  }
2472
[608]2473  predDC1 = biSegPattern[0] ? refDC1 : refDC2;
2474  predDC2 = biSegPattern[0] ? refDC2 : refDC1;
[2]2475}
2476
[608]2477Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
[56]2478{
[608]2479  if( dstStride == patternStride )
2480  {
2481    for( UInt k = 0; k < (patternStride * patternStride); k++ )
2482    {
[1196]2483      if( true == biSegPattern[k] )
2484      { 
2485        ptrDst[k] = valDC2; 
2486      }
2487      else                         
2488      { 
2489        ptrDst[k] = valDC1; 
2490      }
[608]2491    }
[443]2492  }
[608]2493  else
2494  {
2495    Pel* piTemp = ptrDst;
2496    for( UInt uiY = 0; uiY < patternStride; uiY++ )
2497    {
2498      for( UInt uiX = 0; uiX < patternStride; uiX++ )
2499      {
[1196]2500        if( true == biSegPattern[uiX] ) 
2501        { 
2502          piTemp[uiX] = valDC2; 
2503        }
2504        else                           
2505        { 
2506          piTemp[uiX] = valDC1; 
2507        }
[608]2508      }
2509      piTemp       += dstStride;
2510      biSegPattern += patternStride;
2511    }
[443]2512  }
[56]2513}
2514
[608]2515#if H_3D_DIM_DMM
[56]2516
[608]2517Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
[56]2518{
[608]2519  pcContourWedge->clear();
[56]2520
[608]2521  // get copy of co-located texture luma block
2522  TComYuv cTempYuv;
2523  cTempYuv.create( uiWidth, uiHeight ); 
2524  cTempYuv.clear();
2525  Pel* piRefBlkY = cTempYuv.getLumaAddr();
2526  xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
2527  piRefBlkY = cTempYuv.getLumaAddr();
[56]2528
[608]2529  // find contour for texture luma block
2530  UInt iDC = 0;
[1084]2531
[1039]2532  iDC  = piRefBlkY[ 0 ];
2533  iDC += piRefBlkY[ uiWidth - 1 ];
2534  iDC += piRefBlkY[ uiWidth * (uiHeight - 1) ];
2535  iDC += piRefBlkY[ uiWidth * (uiHeight - 1) + uiWidth - 1 ];
2536  iDC = iDC >> 2;
[608]2537
2538  piRefBlkY = cTempYuv.getLumaAddr();
[56]2539
[608]2540  Bool* pabContourPattern = pcContourWedge->getPattern();
2541  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
[443]2542  { 
[608]2543    pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
[443]2544  }
[608]2545
2546  cTempYuv.destroy();
[56]2547}
2548
[608]2549
2550Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
[56]2551{
[608]2552  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
2553  assert( pcPicYuvRef != NULL );
2554  Int         iRefStride = pcPicYuvRef->getStride();
2555  Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
[56]2556
[608]2557  for ( Int y = 0; y < uiHeight; y++ )
[56]2558  {
[608]2559    ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
2560    piDestBlockY += uiWidth;
2561    piRefY += iRefStride;
[56]2562  }
2563}
[655]2564#endif
[56]2565
[2]2566
[608]2567#if H_3D_DIM_SDC
2568Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
2569                                         ,UInt uiIntraMode
2570                                         ,Bool orgDC
2571                                        )
2572{
2573  Int iSumDepth[2];
2574  memset(iSumDepth, 0, sizeof(Int)*2);
2575  Int iSumPix[2];
2576  memset(iSumPix, 0, sizeof(Int)*2);
[1196]2577
[833]2578  for( Int i = 0; i < uiNumSegments; i++ )
2579  {
[1196]2580    rpSegMeans[i] = 0; 
[833]2581  }
[1196]2582
2583  if ( !orgDC )
[2]2584  {
[976]2585    Pel* pLeftTop = pOrig;
2586    Pel* pRightTop = pOrig + (uiSize-1);
2587    Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1)));
2588    Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1));
[608]2589
[976]2590    rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
[608]2591    return;
[2]2592  }
[608]2593
2594  Int subSamplePix;
2595  if ( uiSize == 64 || uiSize == 32 )
[2]2596  {
[608]2597    subSamplePix = 2;
[2]2598  }
[608]2599  else
[2]2600  {
[608]2601    subSamplePix = 1;
[2]2602  }
[1196]2603
[608]2604  for (Int y=0; y<uiSize; y+=subSamplePix)
[2]2605  {
[608]2606    for (Int x=0; x<uiSize; x+=subSamplePix)
2607    {
2608      UChar ucSegment = pMask?(UChar)pMask[x]:0;
2609      assert( ucSegment < uiNumSegments );
2610     
2611      iSumDepth[ucSegment] += pOrig[x];
2612      iSumPix[ucSegment]   += 1;
2613    }
2614   
2615    pOrig  += uiStride*subSamplePix;
2616    pMask  += uiMaskStride*subSamplePix;
[2]2617  }
[608]2618 
2619  // compute mean for each segment
2620  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
[2]2621  {
[608]2622    if( iSumPix[ucSeg] > 0 )
[1196]2623    {
[608]2624      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
[1196]2625    }
[608]2626    else
[1196]2627    {
[608]2628      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
[1196]2629    }
[2]2630  }
2631}
[608]2632#endif // H_3D_DIM_SDC
2633#endif
[1200]2634
[56]2635//! \}
Note: See TracBrowser for help on using the repository browser.