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

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