source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPrediction.cpp @ 537

Last change on this file since 537 was 537, checked in by tech, 11 years ago

Update to HM 11.0.

  • Property svn:eol-style set to native
File size: 81.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-2013, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TComPrediction.cpp
35    \brief    prediction class
36*/
37
38#include <memory.h>
39#include "TComPrediction.h"
40
41//! \ingroup TLibCommon
42//! \{
43
44// ====================================================================================================================
45// Constructor / destructor / initialize
46// ====================================================================================================================
47
48TComPrediction::TComPrediction()
49: m_pLumaRecBuffer(0)
50, m_iLumaRecStride(0)
51{
52  m_piYuvExt = NULL;
53#if H_3D_VSP
54  m_pDepthBlock = (Int*) malloc(MAX_NUM_SPU_W*MAX_NUM_SPU_W*sizeof(Int));
55  if (m_pDepthBlock == NULL)
56      printf("ERROR: UKTGHU, No memory allocated.\n");
57#endif
58}
59
60TComPrediction::~TComPrediction()
61{
62#if H_3D_VSP
63  if (m_pDepthBlock != NULL)
64      free(m_pDepthBlock);
65#endif
66
67  delete[] m_piYuvExt;
68
69  m_acYuvPred[0].destroy();
70  m_acYuvPred[1].destroy();
71
72  m_cYuvPredTemp.destroy();
73
74#if H_3D_ARP
75  m_acYuvPredBase[0].destroy();
76  m_acYuvPredBase[1].destroy();
77#endif
78  if( m_pLumaRecBuffer )
79  {
80    delete [] m_pLumaRecBuffer;
81  }
82 
83  Int i, j;
84  for (i = 0; i < 4; i++)
85  {
86    for (j = 0; j < 4; j++)
87    {
88      m_filteredBlock[i][j].destroy();
89    }
90    m_filteredBlockTmp[i].destroy();
91  }
92}
93
94Void TComPrediction::initTempBuff()
95{
96  if( m_piYuvExt == NULL )
97  {
98    Int extWidth  = MAX_CU_SIZE + 16; 
99    Int extHeight = MAX_CU_SIZE + 1;
100    Int i, j;
101    for (i = 0; i < 4; i++)
102    {
103      m_filteredBlockTmp[i].create(extWidth, extHeight + 7);
104      for (j = 0; j < 4; j++)
105      {
106        m_filteredBlock[i][j].create(extWidth, extHeight);
107      }
108    }
109    m_iYuvExtHeight  = ((MAX_CU_SIZE + 2) << 4);
110    m_iYuvExtStride = ((MAX_CU_SIZE  + 8) << 4);
111    m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
112
113    // new structure
114    m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE );
115    m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE );
116
117    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE );
118#if H_3D_ARP
119    m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
120    m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
121#endif
122  }
123
124  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
125  {
126    m_iLumaRecStride =  (MAX_CU_SIZE>>1) + 1;
127    if (!m_pLumaRecBuffer)
128    {
129      m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ];
130    }
131  }
132#if H_3D_IC
133  for( Int i = 1; i < 64; i++ )
134  {
135    m_uiaShift[i-1] = ( (1 << 15) + i/2 ) / i;
136  }
137#endif
138}
139
140// ====================================================================================================================
141// Public member functions
142// ====================================================================================================================
143
144// Function for calculating DC value of the reference samples used in Intra prediction
145Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft )
146{
147  assert(iWidth > 0 && iHeight > 0);
148  Int iInd, iSum = 0;
149  Pel pDcVal;
150
151  if (bAbove)
152  {
153    for (iInd = 0;iInd < iWidth;iInd++)
154    {
155      iSum += pSrc[iInd-iSrcStride];
156    }
157  }
158  if (bLeft)
159  {
160    for (iInd = 0;iInd < iHeight;iInd++)
161    {
162      iSum += pSrc[iInd*iSrcStride-1];
163    }
164  }
165
166  if (bAbove && bLeft)
167  {
168    pDcVal = (iSum + iWidth) / (iWidth + iHeight);
169  }
170  else if (bAbove)
171  {
172    pDcVal = (iSum + iWidth/2) / iWidth;
173  }
174  else if (bLeft)
175  {
176    pDcVal = (iSum + iHeight/2) / iHeight;
177  }
178  else
179  {
180    pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available
181  }
182 
183  return pDcVal;
184}
185
186// Function for deriving the angular Intra predictions
187
188/** Function for deriving the simplified angular intra predictions.
189 * \param pSrc pointer to reconstructed sample array
190 * \param srcStride the stride of the reconstructed sample array
191 * \param rpDst reference to pointer for the prediction sample array
192 * \param dstStride the stride of the prediction sample array
193 * \param width the width of the block
194 * \param height the height of the block
195 * \param dirMode the intra prediction mode index
196 * \param blkAboveAvailable boolean indication if the block above is available
197 * \param blkLeftAvailable boolean indication if the block to the left is available
198 *
199 * This function derives the prediction samples for the angular mode based on the prediction direction indicated by
200 * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and
201 * the reference row above the block in the case of vertical prediction or displacement of the rightmost column
202 * of the block and reference column left from the block in the case of the horizontal prediction. The displacement
203 * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples,
204 * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken
205 * from the extended main reference.
206 */
207Void TComPrediction::xPredIntraAng(Int bitDepth, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter )
208{
209  Int k,l;
210  Int blkSize        = width;
211  Pel* pDst          = rpDst;
212
213  // Map the mode index to main prediction direction and angle
214  assert( dirMode > 0 ); //no planar
215  Bool modeDC        = dirMode < 2;
216  Bool modeHor       = !modeDC && (dirMode < 18);
217  Bool modeVer       = !modeDC && !modeHor;
218  Int intraPredAngle = modeVer ? (Int)dirMode - VER_IDX : modeHor ? -((Int)dirMode - HOR_IDX) : 0;
219  Int absAng         = abs(intraPredAngle);
220  Int signAng        = intraPredAngle < 0 ? -1 : 1;
221
222  // Set bitshifts and scale the angle parameter to block size
223  Int angTable[9]    = {0,    2,    5,   9,  13,  17,  21,  26,  32};
224  Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
225  Int invAngle       = invAngTable[absAng];
226  absAng             = angTable[absAng];
227  intraPredAngle     = signAng * absAng;
228
229  // Do the DC prediction
230  if (modeDC)
231  {
232    Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable);
233
234    for (k=0;k<blkSize;k++)
235    {
236      for (l=0;l<blkSize;l++)
237      {
238        pDst[k*dstStride+l] = dcval;
239      }
240    }
241  }
242
243  // Do angular predictions
244  else
245  {
246    Pel* refMain;
247    Pel* refSide;
248    Pel  refAbove[2*MAX_CU_SIZE+1];
249    Pel  refLeft[2*MAX_CU_SIZE+1];
250
251    // Initialise the Main and Left reference array.
252    if (intraPredAngle < 0)
253    {
254      for (k=0;k<blkSize+1;k++)
255      {
256        refAbove[k+blkSize-1] = pSrc[k-srcStride-1];
257      }
258      for (k=0;k<blkSize+1;k++)
259      {
260        refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1];
261      }
262      refMain = (modeVer ? refAbove : refLeft) + (blkSize-1);
263      refSide = (modeVer ? refLeft : refAbove) + (blkSize-1);
264
265      // Extend the Main reference to the left.
266      Int invAngleSum    = 128;       // rounding for (shift by 8)
267      for (k=-1; k>blkSize*intraPredAngle>>5; k--)
268      {
269        invAngleSum += invAngle;
270        refMain[k] = refSide[invAngleSum>>8];
271      }
272    }
273    else
274    {
275      for (k=0;k<2*blkSize+1;k++)
276      {
277        refAbove[k] = pSrc[k-srcStride-1];
278      }
279      for (k=0;k<2*blkSize+1;k++)
280      {
281        refLeft[k] = pSrc[(k-1)*srcStride-1];
282      }
283      refMain = modeVer ? refAbove : refLeft;
284      refSide = modeVer ? refLeft  : refAbove;
285    }
286
287    if (intraPredAngle == 0)
288    {
289      for (k=0;k<blkSize;k++)
290      {
291        for (l=0;l<blkSize;l++)
292        {
293          pDst[k*dstStride+l] = refMain[l+1];
294        }
295      }
296
297      if ( bFilter )
298      {
299        for (k=0;k<blkSize;k++)
300        {
301          pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) );
302        }
303      }
304    }
305    else
306    {
307      Int deltaPos=0;
308      Int deltaInt;
309      Int deltaFract;
310      Int refMainIndex;
311
312      for (k=0;k<blkSize;k++)
313      {
314        deltaPos += intraPredAngle;
315        deltaInt   = deltaPos >> 5;
316        deltaFract = deltaPos & (32 - 1);
317
318        if (deltaFract)
319        {
320          // Do linear filtering
321          for (l=0;l<blkSize;l++)
322          {
323            refMainIndex        = l+deltaInt+1;
324            pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 );
325          }
326        }
327        else
328        {
329          // Just copy the integer samples
330          for (l=0;l<blkSize;l++)
331          {
332            pDst[k*dstStride+l] = refMain[l+deltaInt+1];
333          }
334        }
335      }
336    }
337
338    // Flip the block if this is the horizontal mode
339    if (modeHor)
340    {
341      Pel  tmp;
342      for (k=0;k<blkSize-1;k++)
343      {
344        for (l=k+1;l<blkSize;l++)
345        {
346          tmp                 = pDst[k*dstStride+l];
347          pDst[k*dstStride+l] = pDst[l*dstStride+k];
348          pDst[l*dstStride+k] = tmp;
349        }
350      }
351    }
352  }
353}
354
355Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
356{
357  Pel *pDst = piPred;
358  Int *ptrSrc;
359
360  assert( g_aucConvertToBit[ iWidth ] >= 0 ); //   4x  4
361  assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128
362  assert( iWidth == iHeight  );
363
364  ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
365
366  // get starting pixel in block
367  Int sw = 2 * iWidth + 1;
368
369  // Create the prediction
370  if ( uiDirMode == PLANAR_IDX )
371  {
372    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
373  }
374  else
375  {
376    if ( (iWidth > 16) || (iHeight > 16) )
377    {
378      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
379    }
380    else
381    {
382      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );
383
384      if( (uiDirMode == DC_IDX ) && bAbove && bLeft )
385      {
386        xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);
387      }
388    }
389  }
390}
391
392// Angular chroma
393Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
394{
395  Pel *pDst = piPred;
396  Int *ptrSrc = piSrc;
397
398  // get starting pixel in block
399  Int sw = 2 * iWidth + 1;
400
401  if ( uiDirMode == PLANAR_IDX )
402  {
403    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
404  }
405  else
406  {
407    // Create the prediction
408    xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
409  }
410}
411
412#if H_3D_DIM
413Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc )
414{
415  assert( iWidth == iHeight  );
416  assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE );
417  assert( isDimMode( uiIntraMode ) );
418
419  UInt dimType    = getDimType  ( uiIntraMode );
420  Bool dimDeltaDC = isDimDeltaDC( uiIntraMode );   
421  Bool isDmmMode  = (dimType <  DMM_NUM_TYPE);
422  Bool isRbcMode  = (dimType == RBC_IDX);
423
424  Bool* biSegPattern  = NULL;
425  UInt  patternStride = 0;
426
427  // get partiton
428#if H_3D_DIM_DMM
429  TComWedgelet* dmmSegmentation = NULL;
430  if( isDmmMode )
431  {
432    switch( dimType )
433    {
434    case( DMM1_IDX ): 
435      {
436        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]);
437      } break;
438    case( DMM2_IDX ):
439      {
440        UInt uiTabIdx = 0;
441        if( bFastEnc ) { uiTabIdx = pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ); }
442        else
443        {
444          uiTabIdx = xPredWedgeFromIntra( pcCU, uiAbsPartIdx, iWidth, iHeight, pcCU->getDmm2DeltaEnd( uiAbsPartIdx ) );
445          pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, uiAbsPartIdx, (pcCU->getDepth(0) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1)) );
446        }
447        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ uiTabIdx ]);
448      } break;
449    case( DMM3_IDX ): 
450      {
451        UInt uiTabIdx = 0;
452        if( bFastEnc ) { uiTabIdx = pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ); }
453        else
454        {
455          uiTabIdx = xPredWedgeFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, pcCU->getDmm3IntraTabIdx( uiAbsPartIdx ) );
456          pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, uiAbsPartIdx, (pcCU->getDepth(0) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1)) );
457        }
458        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ uiTabIdx ]);
459      } break;
460    case( DMM4_IDX ): 
461      {
462        dmmSegmentation = new TComWedgelet( iWidth, iHeight );
463        xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
464      } break;
465    default: assert(0);
466    }
467    assert( dmmSegmentation );
468    biSegPattern  = dmmSegmentation->getPattern();
469    patternStride = dmmSegmentation->getStride ();
470  }
471#endif
472#if H_3D_DIM_RBC
473  if( isRbcMode )
474  {
475    biSegPattern  = pcCU->getEdgePartition( uiAbsPartIdx );
476    patternStride = iWidth;
477  }
478#endif
479
480  // get predicted partition values
481  assert( biSegPattern );
482  Int* piMask = NULL;
483  if( isDmmMode ) piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering for DMM
484  else            piMask = pcCU->getPattern()->getPredictorPtr( 0, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
485  assert( piMask );
486  Int maskStride = 2*iWidth + 1; 
487  Int* ptrSrc = piMask+maskStride+1;
488  Pel predDC1 = 0; Pel predDC2 = 0;
489  xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 );
490
491  // set segment values with deltaDC offsets
492  Pel segDC1 = 0;
493  Pel segDC2 = 0;
494  if( dimDeltaDC )
495  {
496    Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx );
497    Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx );
498#if H_3D_DIM_DMM
499    if( isDmmMode )
500    {
501#if H_3D_DIM_DLT
502      segDC1 = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 );
503      segDC2 = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 );
504#else
505      segDC1 = ClipY( predDC1 + deltaDC1 );
506      segDC2 = ClipY( predDC2 + deltaDC2 );
507#endif
508    }
509#endif
510#if H_3D_DIM_RBC
511    if( isRbcMode )
512    {
513      xDeltaDCQuantScaleUp( pcCU, deltaDC1 );
514      xDeltaDCQuantScaleUp( pcCU, deltaDC2 );
515      segDC1 = ClipY( predDC1 + deltaDC1 );
516      segDC2 = ClipY( predDC2 + deltaDC2 );
517    }
518#endif
519  }
520  else
521  {
522    segDC1 = predDC1;
523    segDC2 = predDC2;
524  }
525
526  // set prediction signal
527  Pel* pDst = piPred;
528  xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 );
529
530#if H_3D_DIM_DMM
531  if( dimType == DMM4_IDX ) { dmmSegmentation->destroy(); delete dmmSegmentation; }
532#endif
533}
534#endif
535
536/** Function for checking identical motion.
537 * \param TComDataCU* pcCU
538 * \param UInt PartAddr
539 */
540Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr )
541{
542  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() )
543  {
544    if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0)
545    {
546      Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
547      Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
548      if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
549      {
550        return true;
551      }
552    }
553  }
554  return false;
555}
556
557
558Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
559{
560  Int         iWidth;
561  Int         iHeight;
562  UInt        uiPartAddr;
563
564  if ( iPartIdx >= 0 )
565  {
566    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
567#if H_3D_VSP
568    if ( 0 == pcCU->getVSPFlag(uiPartAddr) )
569    {
570#endif
571      if ( eRefPicList != REF_PIC_LIST_X )
572      {
573        if( pcCU->getSlice()->getPPS()->getUseWP())
574        {
575          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
576        }
577        else
578        {
579          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
580        }
581        if ( pcCU->getSlice()->getPPS()->getUseWP() )
582        {
583          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
584        }
585      }
586      else
587      {
588        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
589        {
590          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
591        }
592        else
593        {
594          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
595        }
596      }
597#if H_3D_VSP
598    }
599    else
600    {
601      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
602        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
603      else
604        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
605    }
606#endif
607    return;
608  }
609
610  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
611  {
612    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
613
614#if H_3D_VSP
615    if ( 0 == pcCU->getVSPFlag(uiPartAddr) )
616    {
617#endif
618      if ( eRefPicList != REF_PIC_LIST_X )
619      {
620        if( pcCU->getSlice()->getPPS()->getUseWP())
621        {
622          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
623        }
624        else
625        {
626          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
627        }
628        if ( pcCU->getSlice()->getPPS()->getUseWP() )
629        {
630          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
631        }
632      }
633      else
634      {
635        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
636        {
637          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
638        }
639        else
640        {
641          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
642        }
643      }
644#if H_3D_VSP
645    }
646    else
647    {
648      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
649        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
650      else
651        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
652    }
653#endif
654  }
655  return;
656}
657
658Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
659{
660  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
661  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
662  pcCU->clipMv(cMv);
663#if H_3D_ARP
664  if(  pcCU->getARPW( uiPartAddr ) > 0 
665    && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N
666    && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() 
667    )
668  {
669    xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi );
670  }
671  else
672  {
673#endif
674#if H_3D_IC
675    Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() );
676    xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
677#if H_3D_ARP
678      , false
679#endif
680      , bICFlag );
681    xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
682#if H_3D_ARP
683      , false
684#endif
685      , bICFlag );
686#else
687  xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
688  xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
689#endif
690#if H_3D_ARP
691  }
692#endif
693}
694
695#if H_3D_VSP
696Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
697{
698  // Get depth reference
699  Int depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
700  TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
701  assert(pRefPicBaseDepth != NULL);
702  TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
703  assert(pcBaseViewDepthPicYuv != NULL);
704
705  // Get texture reference
706  Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
707  assert(iRefIdx >= 0);
708  TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx );
709  TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
710  assert(pcBaseViewTxtPicYuv != NULL);
711
712  // Initialize LUT according to the reference viewIdx
713  Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex();
714  Int* pShiftLUT    = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx );
715  assert( txtRefViewIdx < pcCU->getSlice()->getViewIndex() );
716
717  // Do compensation
718  TComMv cDv  = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); // cDv is the disparity vector derived from the neighbors
719  pcCU->clipMv(cDv);
720  UInt uiAbsPartIdx = pcCU->getZorderIdxInCU();
721  Int iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
722  Int iBlkY = ( pcCU->getAddr() / pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
723  xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
724  xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
725}
726#endif
727
728#if H_3D_ARP
729Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
730{
731  Int         iRefIdx      = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
732  TComMv      cMv          = pNewMvFiled ? pNewMvFiled->getMv()     : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
733  Bool        bTobeScaled  = false;
734  TComPic* pcPicYuvBaseCol = NULL;
735  TComPic* pcPicYuvBaseRef = NULL;
736
737#if H_3D_NBDV
738  DisInfo cDistparity;
739  cDistparity.bDV           = pcCU->getDvInfo(uiPartAddr).bDV;
740  if( cDistparity.bDV )
741  {
742    cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV;
743    assert(pcCU->getDvInfo(uiPartAddr).bDV ==  pcCU->getDvInfo(0).bDV);
744    cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
745  }
746#else
747  assert(0); // ARP can be applied only when a DV is available
748#endif
749
750  UChar dW = cDistparity.bDV ? pcCU->getARPW ( uiPartAddr ) : 0;
751
752  if( cDistparity.bDV ) 
753  {
754    if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC()!= pcCU->getSlice()->getPOC() )
755    {
756      bTobeScaled = true;
757    }
758
759    pcPicYuvBaseCol =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(),                              cDistparity.m_aVIdxCan );
760    pcPicYuvBaseRef =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC(), cDistparity.m_aVIdxCan );
761   
762    if( ( !pcPicYuvBaseCol || pcPicYuvBaseCol->getPOC() != pcCU->getSlice()->getPOC() ) || ( !pcPicYuvBaseRef || pcPicYuvBaseRef->getPOC() != pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() ) )
763    {
764      dW = 0;
765      bTobeScaled = false;
766    }
767    else
768    {
769      assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() );
770    }
771
772    if(bTobeScaled)
773    {     
774      Int iCurrPOC    = pcCU->getSlice()->getPOC();
775      Int iColRefPOC  = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx );
776      Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList,  0);
777      Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC);
778      if ( iScale != 4096 )
779      {
780        cMv = cMv.scaleMv( iScale );
781      }
782      iRefIdx = 0;
783    }
784  }
785
786  pcCU->clipMv(cMv);
787  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec();
788  xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
789  xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
790
791  if( dW > 0 )
792  {
793    TComYuv * pYuvB0 = &m_acYuvPredBase[0];
794    TComYuv * pYuvB1  = &m_acYuvPredBase[1];
795
796    TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV;
797    pcCU->clipMv(cMVwithDisparity);
798
799    assert ( cDistparity.bDV );
800
801    pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec();
802    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
803    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
804   
805    pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec();
806    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
807    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
808
809    pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight );
810
811    if( 2 == dW )
812    {
813      pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
814    }
815    rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi );
816  }
817}
818#endif
819
820Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
821{
822  TComYuv* pcMbYuv;
823  Int      iRefIdx[2] = {-1, -1};
824
825  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
826  {
827    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
828    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
829
830    if ( iRefIdx[iRefList] < 0 )
831    {
832      continue;
833    }
834
835    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
836
837    pcMbYuv = &m_acYuvPred[iRefList];
838    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
839    {
840      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
841    }
842    else
843    {
844      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) || 
845           ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
846      {
847        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
848      }
849      else
850      {
851        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
852      }
853    }
854  }
855
856  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE  )
857  {
858    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
859  } 
860  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
861  {
862    xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); 
863  }
864  else
865  {
866    xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
867  }
868}
869
870#if H_3D_VSP
871
872Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
873{
874  TComYuv* pcMbYuv;
875  Int      iRefIdx[2] = {-1, -1};
876  Bool     bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0);
877
878  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
879  {
880    RefPicList eRefPicList = RefPicList(iRefList);
881    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
882
883    if ( iRefIdx[iRefList] < 0 )
884      continue;
885    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
886
887    pcMbYuv = &m_acYuvPred[iRefList];
888    xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi );
889  }
890
891  xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
892}
893
894#endif
895
896/**
897 * \brief Generate motion-compensated luma block
898 *
899 * \param cu       Pointer to current CU
900 * \param refPic   Pointer to reference picture
901 * \param partAddr Address of block within CU
902 * \param mv       Motion vector
903 * \param width    Width of block
904 * \param height   Height of block
905 * \param dstPic   Pointer to destination picture
906 * \param bi       Flag indicating whether bipred is used
907 */
908Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
909#if H_3D_ARP
910    , Bool filterType
911#endif
912#if H_3D_IC
913    , Bool bICFlag
914#endif
915  )
916{
917  Int refStride = refPic->getStride(); 
918  Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride;
919  Pel *ref      = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
920 
921  Int dstStride = dstPic->getStride();
922  Pel *dst      = dstPic->getLumaAddr( partAddr );
923 
924  Int xFrac = mv->getHor() & 0x3;
925  Int yFrac = mv->getVer() & 0x3;
926
927#if H_3D_IC
928  if( cu->getSlice()->getIsDepth() )
929  {
930    refOffset = mv->getHor() + mv->getVer() * refStride;
931    ref       = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
932    xFrac     = 0;
933    yFrac     = 0;
934  }
935#endif
936  if ( yFrac == 0 )
937  {
938    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi
939#if H_3D_ARP
940    , filterType
941#endif
942      );
943  }
944  else if ( xFrac == 0 )
945  {
946    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi
947#if H_3D_ARP
948    , filterType
949#endif
950      );
951  }
952  else
953  {
954    Int tmpStride = m_filteredBlockTmp[0].getStride();
955    Short *tmp    = m_filteredBlockTmp[0].getLumaAddr();
956
957    Int filterSize = NTAPS_LUMA;
958    Int halfFilterSize = ( filterSize >> 1 );
959
960    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     
961#if H_3D_ARP
962    , filterType
963#endif
964      );
965    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi
966#if H_3D_ARP
967    , filterType
968#endif
969      );   
970  }
971
972#if H_3D_IC
973  if( bICFlag )
974  {
975    Int a, b, iShift, i, j;
976
977    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_LUMA );
978
979    for ( i = 0; i < height; i++ )
980    {
981      for ( j = 0; j < width; j++ )
982      {
983        if( bi )
984        {
985          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthY;
986          dst[j] = ( ( a*dst[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1 << iIFshift ) - IF_INTERNAL_OFFS;
987        }
988        else
989          dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
990      }
991      dst += dstStride;
992    }
993  }
994#endif
995}
996
997/**
998 * \brief Generate motion-compensated chroma block
999 *
1000 * \param cu       Pointer to current CU
1001 * \param refPic   Pointer to reference picture
1002 * \param partAddr Address of block within CU
1003 * \param mv       Motion vector
1004 * \param width    Width of block
1005 * \param height   Height of block
1006 * \param dstPic   Pointer to destination picture
1007 * \param bi       Flag indicating whether bipred is used
1008 */
1009Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
1010#if H_3D_ARP
1011    , Bool filterType
1012#endif
1013#if H_3D_IC
1014    , Bool bICFlag
1015#endif
1016  )
1017{
1018  Int     refStride  = refPic->getCStride();
1019  Int     dstStride  = dstPic->getCStride();
1020 
1021  Int     refOffset  = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride;
1022 
1023  Pel*    refCb     = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1024  Pel*    refCr     = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1025 
1026  Pel* dstCb = dstPic->getCbAddr( partAddr );
1027  Pel* dstCr = dstPic->getCrAddr( partAddr );
1028 
1029  Int     xFrac  = mv->getHor() & 0x7;
1030  Int     yFrac  = mv->getVer() & 0x7;
1031  UInt    cxWidth  = width  >> 1;
1032  UInt    cxHeight = height >> 1;
1033 
1034  Int     extStride = m_filteredBlockTmp[0].getStride();
1035  Short*  extY      = m_filteredBlockTmp[0].getLumaAddr();
1036 
1037  Int filterSize = NTAPS_CHROMA;
1038 
1039  Int halfFilterSize = (filterSize>>1);
1040 
1041  if ( yFrac == 0 )
1042  {
1043    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi
1044#if H_3D_ARP
1045    , filterType
1046#endif
1047    );   
1048    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi
1049#if H_3D_ARP
1050    , filterType
1051#endif
1052    );
1053  }
1054  else if ( xFrac == 0 )
1055  {
1056    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1057#if H_3D_ARP
1058    , filterType
1059#endif
1060    );
1061    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1062#if H_3D_ARP
1063    , filterType
1064#endif
1065    );
1066  }
1067  else
1068  {
1069    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1070#if H_3D_ARP
1071    , filterType
1072#endif 
1073      );
1074    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1075#if H_3D_ARP
1076    , filterType
1077#endif
1078      );
1079   
1080    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1081#if H_3D_ARP
1082    , filterType
1083#endif
1084      );
1085    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1086#if H_3D_ARP
1087    , filterType
1088#endif
1089      );   
1090  }
1091
1092#if H_3D_IC
1093  if( bICFlag )
1094  {
1095    Int a, b, iShift, i, j;
1096    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_U ); // Cb
1097    for ( i = 0; i < cxHeight; i++ )
1098    {
1099      for ( j = 0; j < cxWidth; j++ )
1100      {
1101        if( bi )
1102        {
1103          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC;
1104          dstCb[j] = ( ( a*dstCb[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS;
1105        }
1106        else
1107          dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
1108      }
1109      dstCb += dstStride;
1110    }
1111    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_V ); // Cr
1112    for ( i = 0; i < cxHeight; i++ )
1113    {
1114      for ( j = 0; j < cxWidth; j++ )
1115      {
1116        if( bi )
1117        {
1118          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC;
1119          dstCr[j] = ( ( a*dstCr[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS;
1120        }
1121        else
1122          dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
1123      }
1124      dstCr += dstStride;
1125    }
1126  }
1127#endif
1128}
1129
1130Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
1131{
1132  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
1133  {
1134    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
1135  }
1136  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
1137  {
1138    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
1139  }
1140  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
1141  {
1142    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
1143  }
1144}
1145
1146// AMVP
1147Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
1148{
1149  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
1150  if( pcAMVPInfo->iN <= 1 )
1151  {
1152    rcMvPred = pcAMVPInfo->m_acMvCand[0];
1153
1154    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1155    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1156    return;
1157  }
1158
1159  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
1160  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
1161  return;
1162}
1163
1164/** Function for deriving planar intra prediction.
1165 * \param pSrc pointer to reconstructed sample array
1166 * \param srcStride the stride of the reconstructed sample array
1167 * \param rpDst reference to pointer for the prediction sample array
1168 * \param dstStride the stride of the prediction sample array
1169 * \param width the width of the block
1170 * \param height the height of the block
1171 *
1172 * This function derives the prediction samples for planar mode (intra coding).
1173 */
1174Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
1175{
1176  assert(width == height);
1177
1178  Int k, l, bottomLeft, topRight;
1179  Int horPred;
1180  Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
1181  UInt blkSize = width;
1182  UInt offset2D = width;
1183  UInt shift1D = g_aucConvertToBit[ width ] + 2;
1184  UInt shift2D = shift1D + 1;
1185
1186  // Get left and above reference column and row
1187  for(k=0;k<blkSize+1;k++)
1188  {
1189    topRow[k] = pSrc[k-srcStride];
1190    leftColumn[k] = pSrc[k*srcStride-1];
1191  }
1192
1193  // Prepare intermediate variables used in interpolation
1194  bottomLeft = leftColumn[blkSize];
1195  topRight   = topRow[blkSize];
1196  for (k=0;k<blkSize;k++)
1197  {
1198    bottomRow[k]   = bottomLeft - topRow[k];
1199    rightColumn[k] = topRight   - leftColumn[k];
1200    topRow[k]      <<= shift1D;
1201    leftColumn[k]  <<= shift1D;
1202  }
1203
1204  // Generate prediction signal
1205  for (k=0;k<blkSize;k++)
1206  {
1207    horPred = leftColumn[k] + offset2D;
1208    for (l=0;l<blkSize;l++)
1209    {
1210      horPred += rightColumn[k];
1211      topRow[l] += bottomRow[l];
1212      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
1213    }
1214  }
1215}
1216
1217/** Function for filtering intra DC predictor.
1218 * \param pSrc pointer to reconstructed sample array
1219 * \param iSrcStride the stride of the reconstructed sample array
1220 * \param rpDst reference to pointer for the prediction sample array
1221 * \param iDstStride the stride of the prediction sample array
1222 * \param iWidth the width of the block
1223 * \param iHeight the height of the block
1224 *
1225 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
1226 */
1227Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
1228{
1229  Pel* pDst = rpDst;
1230  Int x, y, iDstStride2, iSrcStride2;
1231
1232  // boundary pixels processing
1233  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
1234
1235  for ( x = 1; x < iWidth; x++ )
1236  {
1237    pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
1238  }
1239
1240  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
1241  {
1242    pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
1243  }
1244
1245  return;
1246}
1247#if H_3D_IC
1248/** Function for deriving the position of first non-zero binary bit of a value
1249 * \param x input value
1250 *
1251 * This function derives the position of first non-zero binary bit of a value
1252 */
1253Int GetMSB( UInt x )
1254{
1255  Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1;
1256
1257  while( x > 1 )
1258  {
1259    bits >>= 1;
1260    y = x >> bits;
1261
1262    if( y )
1263    {
1264      x = y;
1265      iMSB += bits;
1266    }
1267  }
1268
1269  iMSB+=y;
1270
1271  return iMSB;
1272}
1273
1274/** Function for counting leading number of zeros/ones
1275 * \param x input value
1276 \ This function counts leading number of zeros for positive numbers and
1277 \ leading number of ones for negative numbers. This can be implemented in
1278 \ single instructure cycle on many processors.
1279 */
1280
1281Short CountLeadingZerosOnes (Short x)
1282{
1283  Short clz;
1284  Short i;
1285
1286  if(x == 0)
1287  {
1288    clz = 0;
1289  }
1290  else
1291  {
1292    if (x == -1)
1293    {
1294      clz = 15;
1295    }
1296    else
1297    {
1298      if(x < 0)
1299      {
1300        x = ~x;
1301      }
1302      clz = 15;
1303      for(i = 0;i < 15;++i)
1304      {
1305        if(x) 
1306        {
1307          clz --;
1308        }
1309        x = x >> 1;
1310      }
1311    }
1312  }
1313  return clz;
1314}
1315
1316/** Function for deriving LM illumination compensation.
1317 */
1318Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, Int &iShift, TextType eType )
1319{
1320  TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
1321  Pel *pRec = NULL, *pRef = NULL;
1322  UInt uiWidth, uiHeight, uiTmpPartIdx;
1323  Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride();
1324  Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride();
1325  Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer;
1326
1327  iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
1328  iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
1329  iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 );
1330  iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 );
1331  iRefX   = iCUPelX + iHor;
1332  iRefY   = iCUPelY + iVer;
1333  if( eType != TEXT_LUMA )
1334  {
1335    iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 );
1336    iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 );
1337  }
1338  uiWidth  = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 )  : ( pcCU->getWidth( 0 )  >> 1 );
1339  uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 );
1340
1341  Int i, j, iCountShift = 0;
1342
1343  // LLS parameters estimation -->
1344
1345  Int x = 0, y = 0, xx = 0, xy = 0;
1346
1347  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 )
1348  {
1349    iRefOffset = iHor + iVer * iRefStride - iRefStride;
1350    if( eType == TEXT_LUMA )
1351    {
1352      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1353      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
1354    }
1355    else if( eType == TEXT_CHROMA_U )
1356    {
1357      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1358      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
1359    }
1360    else
1361    {
1362      assert( eType == TEXT_CHROMA_V );
1363      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1364      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
1365    }
1366
1367    for( j = 0; j < uiWidth; j++ )
1368    {
1369      x += pRef[j];
1370      y += pRec[j];
1371      xx += pRef[j] * pRef[j];
1372      xy += pRef[j] * pRec[j];
1373    }
1374    iCountShift += g_aucConvertToBit[ uiWidth ] + 2;
1375  }
1376
1377
1378  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 )
1379  {
1380    iRefOffset = iHor + iVer * iRefStride - 1;
1381    if( eType == TEXT_LUMA )
1382    {
1383      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1384      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1385    }
1386    else if( eType == TEXT_CHROMA_U )
1387    {
1388      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1389      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1390    }
1391    else
1392    {
1393      assert( eType == TEXT_CHROMA_V );
1394      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1395      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1396    }
1397
1398    for( i = 0; i < uiHeight; i++ )
1399    {
1400      x += pRef[0];
1401      y += pRec[0];
1402      xx += pRef[0] * pRef[0];
1403      xy += pRef[0] * pRec[0];
1404
1405      pRef += iRefStride;
1406      pRec += iRecStride;
1407    }
1408    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 );
1409  }
1410
1411  Int iTempShift = ( ( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC ) + g_aucConvertToBit[ uiWidth ] + 3 - 15;
1412
1413  if( iTempShift > 0 )
1414  {
1415    x  = ( x +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
1416    y  = ( y +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
1417    xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
1418    xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
1419    iCountShift -= iTempShift;
1420  }
1421
1422  iShift = 13;
1423
1424  if( iCountShift == 0 )
1425  {
1426    a = 1;
1427    b = 0;
1428    iShift = 0;
1429  }
1430  else
1431  {
1432    Int a1 = ( xy << iCountShift ) - y * x;
1433    Int a2 = ( xx << iCountShift ) - x * x;             
1434
1435    {
1436      const Int iShiftA2 = 6;
1437      const Int iShiftA1 = 15;
1438      const Int iAccuracyShift = 15;
1439
1440      Int iScaleShiftA2 = 0;
1441      Int iScaleShiftA1 = 0;
1442      Int a1s = a1;
1443      Int a2s = a2;
1444
1445      iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1;
1446      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; 
1447
1448      if( iScaleShiftA1 < 0 )
1449      {
1450        iScaleShiftA1 = 0;
1451      }
1452
1453      if( iScaleShiftA2 < 0 )
1454      {
1455        iScaleShiftA2 = 0;
1456      }
1457
1458      Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
1459
1460      a2s = a2 >> iScaleShiftA2;
1461
1462      a1s = a1 >> iScaleShiftA1;
1463
1464      if (a2s >= 1)
1465      {
1466        a = a1s * m_uiaShift[ a2s - 1];
1467      }
1468      else
1469      {
1470        a = 0;
1471      }
1472
1473      if( iScaleShiftA < 0 )
1474      {
1475        a = a << -iScaleShiftA;
1476      }
1477      else
1478      {
1479        a = a >> iScaleShiftA;
1480      }
1481
1482      a = Clip3( -( 1 << 15 ), ( 1 << 15 ) - 1, a ); 
1483
1484      Int minA = -(1 << (6));
1485      Int maxA = (1 << 6) - 1;
1486      if( a <= maxA && a >= minA )
1487      {
1488        // do nothing
1489      }
1490      else
1491      {
1492        Short n = CountLeadingZerosOnes( a );
1493        a = a >> (9-n);
1494        iShift -= (9-n);
1495      }
1496
1497      b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
1498    }
1499  }   
1500}
1501#endif
1502
1503#if H_3D_VSP
1504// Input:
1505// refPic: Ref picture. Full picture, with padding
1506// posX, posY:     PU position, texture
1507// sizeX, sizeY: PU size
1508// partAddr: z-order index
1509// dv: disparity vector. derived from neighboring blocks
1510//
1511// Output: dstPic, PU predictor 64x64
1512Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr,Int posX, Int posY
1513                                            , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi )
1514{
1515  Int widthLuma;
1516  Int heightLuma;
1517
1518  if (isDepth)
1519  {
1520    widthLuma   =  pPicBaseDepth->getWidth();
1521    heightLuma  =  pPicBaseDepth->getHeight();
1522  }
1523  else
1524  {
1525    widthLuma   =  refPic->getWidth();
1526    heightLuma  =  refPic->getHeight();
1527  }
1528
1529#if H_3D_VSP_BLOCKSIZE != 1
1530  Int widthDepth  = pPicBaseDepth->getWidth();
1531  Int heightDepth = pPicBaseDepth->getHeight();
1532#endif
1533
1534#if H_3D_VSP_CONSTRAINED
1535  Int widthDepth  = pPicBaseDepth->getWidth();
1536  Int heightDepth = pPicBaseDepth->getHeight();
1537#endif
1538
1539  Int nTxtPerDepthX = widthLuma  / ( pPicBaseDepth->getWidth() );  // texture pixel # per depth pixel
1540  Int nTxtPerDepthY = heightLuma / ( pPicBaseDepth->getHeight() );
1541
1542  Int refStride = refPic->getStride();
1543  Int dstStride = dstPic->getStride();
1544  Int depStride =  pPicBaseDepth->getStride();
1545  Int depthPosX = Clip3(0,   widthLuma - sizeX,  (posX/nTxtPerDepthX) + ((dv->getHor()+2)>>2));
1546  Int depthPosY = Clip3(0,   heightLuma- sizeY,  (posY/nTxtPerDepthY) + ((dv->getVer()+2)>>2));
1547  Pel *ref    = refPic->getLumaAddr() + posX + posY * refStride;
1548  Pel *dst    = dstPic->getLumaAddr(partAddr);
1549  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;
1550
1551#if H_3D_VSP_BLOCKSIZE != 1
1552#if H_3D_VSP_BLOCKSIZE == 2
1553  Int  dW = sizeX>>1;
1554  Int  dH = sizeY>>1;
1555#endif
1556#if H_3D_VSP_BLOCKSIZE == 4
1557  Int  dW = sizeX>>2;
1558  Int  dH = sizeY>>2;
1559#endif
1560  {
1561    Pel* depthi = depth;
1562    for (Int j = 0; j < dH; j++)
1563    {
1564      for (Int i = 0; i < dW; i++)
1565      {
1566        Pel* depthTmp;
1567#if H_3D_VSP_BLOCKSIZE == 2
1568        if (depthPosX + (i<<1) < widthDepth)
1569          depthTmp = depthi + (i << 1);
1570        else
1571          depthTmp = depthi + (widthDepth - depthPosX - 1);
1572#endif
1573#if H_3D_VSP_BLOCKSIZE == 4
1574        if (depthPosX + (i<<2) < widthDepth)
1575          depthTmp = depthi + (i << 2);
1576        else
1577          depthTmp = depthi + (widthDepth - depthPosX - 1);
1578#endif
1579        Int maxV = 0;
1580        for (Int blockj = 0; blockj < H_3D_VSP_BLOCKSIZE; blockj+=(H_3D_VSP_BLOCKSIZE-1))
1581        {
1582          Int iX = 0;
1583          for (Int blocki = 0; blocki < H_3D_VSP_BLOCKSIZE; blocki+=(H_3D_VSP_BLOCKSIZE-1))
1584          {
1585            if (maxV < depthTmp[iX])
1586              maxV = depthTmp[iX];
1587#if H_3D_VSP_BLOCKSIZE == 2
1588            if (depthPosX + (i<<1) + blocki < widthDepth - 1)
1589#else // H_3D_VSP_BLOCKSIZE == 4
1590            if (depthPosX + (i<<2) + blocki < widthDepth - 1)
1591#endif
1592              iX = (H_3D_VSP_BLOCKSIZE-1);
1593          }
1594#if H_3D_VSP_BLOCKSIZE == 2
1595          if (depthPosY + (j<<1) + blockj < heightDepth - 1)
1596#else // H_3D_VSP_BLOCKSIZE == 4
1597          if (depthPosY + (j<<2) + blockj < heightDepth - 1)
1598#endif
1599            depthTmp += depStride * (H_3D_VSP_BLOCKSIZE-1);
1600        }
1601        m_pDepthBlock[i+j*dW] = maxV;
1602      } // end of i < dW
1603#if H_3D_VSP_BLOCKSIZE == 2
1604      if (depthPosY + ((j+1)<<1) < heightDepth)
1605        depthi += (depStride << 1);
1606      else
1607        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
1608#endif
1609#if H_3D_VSP_BLOCKSIZE == 4
1610      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
1611        depthi += (depStride << 2);
1612      else
1613        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
1614#endif
1615    }
1616  }
1617#endif // H_3D_VSP_BLOCKSIZE != 1
1618
1619#if H_3D_VSP_BLOCKSIZE == 1
1620#if H_3D_VSP_CONSTRAINED
1621  //get LUT based horizontal reference range
1622  Int range = xGetConstrainedSize(sizeX, sizeY);
1623
1624  // The minimum depth value
1625  Int minRelativePos = MAX_INT;
1626  Int maxRelativePos = MIN_INT;
1627
1628  Pel* depthTemp, *depthInitial=depth;
1629  for (Int yTxt = 0; yTxt < sizeY; yTxt++)
1630  {
1631    for (Int xTxt = 0; xTxt < sizeX; xTxt++)
1632    {
1633      if (depthPosX+xTxt < widthDepth)
1634        depthTemp = depthInitial + xTxt;
1635      else
1636        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
1637
1638      Int disparity = pShiftLUT[ *depthTemp ]; // << iShiftPrec;
1639      Int disparityInt = disparity >> 2;
1640
1641      if( disparity <= 0)
1642      {
1643        if (minRelativePos > disparityInt+xTxt)
1644            minRelativePos = disparityInt+xTxt;
1645      }
1646      else
1647      {
1648        if (maxRelativePos < disparityInt+xTxt)
1649            maxRelativePos = disparityInt+xTxt;
1650      }
1651    }
1652    if (depthPosY+yTxt < heightDepth)
1653      depthInitial = depthInitial + depStride;
1654  }
1655
1656  Int disparity_tmp = pShiftLUT[ *depth ]; // << iShiftPrec;
1657  if (disparity_tmp <= 0)
1658    maxRelativePos = minRelativePos + range -1 ;
1659  else
1660    minRelativePos = maxRelativePos - range +1 ;
1661#endif
1662#endif // H_3D_VSP_BLOCKSIZE == 1
1663
1664#if H_3D_VSP_BLOCKSIZE != 1
1665  Int yDepth = 0;
1666#endif
1667  for ( Int yTxt = 0; yTxt < sizeY; yTxt += nTxtPerDepthY )
1668  {
1669    for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth++ )
1670    {
1671      Pel repDepth = 0; // to store the depth value used for warping
1672#if H_3D_VSP_BLOCKSIZE == 1
1673      repDepth = depth[xDepth];
1674#endif
1675#if H_3D_VSP_BLOCKSIZE == 2
1676      repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW];
1677#endif
1678#if H_3D_VSP_BLOCKSIZE == 4
1679      repDepth = m_pDepthBlock[(xTxt>>2) + (yTxt>>2)*dW];
1680#endif
1681
1682      assert( repDepth >= 0 && repDepth <= 255 );
1683      Int disparity = pShiftLUT[ repDepth ]; // remove << iShiftPrec ??
1684      Int refOffset = xTxt + (disparity >> 2);
1685      Int xFrac = disparity & 0x3;
1686#if H_3D_VSP_CONSTRAINED
1687      if(refOffset<minRelativePos || refOffset>maxRelativePos)
1688        xFrac = 0;
1689      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
1690#endif
1691      Int absX  = posX + refOffset;
1692
1693      if (xFrac == 0)
1694        absX = Clip3(0, widthLuma-1, absX);
1695      else
1696        absX = Clip3(4, widthLuma-5, absX);
1697
1698      refOffset = absX - posX;
1699
1700      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
1701      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi );
1702    }
1703    ref   += refStride*nTxtPerDepthY;
1704    dst   += dstStride*nTxtPerDepthY;
1705    depth += depStride;
1706#if H_3D_VSP_BLOCKSIZE != 1
1707    yDepth++;
1708#endif
1709
1710  }
1711}
1712
1713Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv*dv, UInt partAddr, Int posX, Int posY
1714                                               , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi)
1715{
1716  Int refStride = refPic->getCStride();
1717  Int dstStride = dstPic->getCStride();
1718  Int depStride = pPicBaseDepth->getStride();
1719
1720  Int widthChroma, heightChroma;
1721  if( isDepth)
1722  {
1723     widthChroma   = pPicBaseDepth->getWidth()>>1;
1724     heightChroma  = pPicBaseDepth->getHeight()>>1;
1725  }
1726  else
1727  {
1728     widthChroma   = refPic->getWidth()>>1;
1729     heightChroma  = refPic->getHeight()>>1;
1730  }
1731
1732  // Below is only for Texture chroma component
1733
1734  Int widthDepth  = pPicBaseDepth->getWidth();
1735  Int heightDepth = pPicBaseDepth->getHeight();
1736
1737  Int nTxtPerDepthX, nTxtPerDepthY;  // Number of texture samples per one depth sample
1738  Int nDepthPerTxtX, nDepthPerTxtY;  // Number of depth samples per one texture sample
1739
1740  Int depthPosX;  // Starting position in depth image
1741  Int depthPosY;
1742
1743  if ( widthChroma > widthDepth )
1744  {
1745    nTxtPerDepthX = widthChroma / widthDepth;
1746    nDepthPerTxtX = 1;
1747    depthPosX = posX / nTxtPerDepthX + ((dv->getHor()+2)>>2);
1748  }
1749  else
1750  {
1751    nTxtPerDepthX = 1;
1752    nDepthPerTxtX = widthDepth / widthChroma;
1753    depthPosX = posX * nDepthPerTxtX + ((dv->getHor()+2)>>2);
1754  }
1755  depthPosX = Clip3(0, widthDepth - (sizeX<<1), depthPosX);
1756  if ( heightChroma > heightDepth )
1757  {
1758    nTxtPerDepthY = heightChroma / heightDepth;
1759    nDepthPerTxtY = 1;
1760    depthPosY = posY / nTxtPerDepthY + ((dv->getVer()+2)>>2);
1761  }
1762  else
1763  {
1764    nTxtPerDepthY = 1;
1765    nDepthPerTxtY = heightDepth / heightChroma;
1766    depthPosY = posY * nDepthPerTxtY + ((dv->getVer()+2)>>2);
1767  }
1768  depthPosY = Clip3(0, heightDepth - (sizeY<<1), depthPosY);
1769
1770  Pel *refCb  = refPic->getCbAddr() + posX + posY * refStride;
1771  Pel *refCr  = refPic->getCrAddr() + posX + posY * refStride;
1772  Pel *dstCb  = dstPic->getCbAddr(partAddr);
1773  Pel *dstCr  = dstPic->getCrAddr(partAddr);
1774  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;  // move the pointer to the current depth pixel position
1775
1776  Int refStrideBlock = refStride * nTxtPerDepthY;
1777  Int dstStrideBlock = dstStride * nTxtPerDepthY;
1778  Int depStrideBlock = depStride * nDepthPerTxtY;
1779
1780  if ( widthChroma > widthDepth ) // We assume
1781  {
1782    assert( heightChroma > heightDepth );
1783    printf("This branch should never been reached.\n");
1784    exit(0);
1785  }
1786  else
1787  {
1788#if H_3D_VSP_BLOCKSIZE == 1
1789  Int  dW = sizeX;
1790  Int  dH = sizeY;
1791  Int  sW = 2; // search window size
1792  Int  sH = 2;
1793#endif
1794#if H_3D_VSP_BLOCKSIZE == 2
1795  Int  dW = sizeX;
1796  Int  dH = sizeY;
1797  Int  sW = 2; // search window size
1798  Int  sH = 2;
1799#endif
1800#if H_3D_VSP_BLOCKSIZE == 4
1801  Int  dW = sizeX>>1;
1802  Int  dH = sizeY>>1;
1803  Int  sW = 4; // search window size
1804  Int  sH = 4;
1805#endif
1806
1807  {
1808    Pel* depthi = depth;
1809    for (Int j = 0; j < dH; j++)
1810    {
1811      for (Int i = 0; i < dW; i++)
1812      {
1813        Pel* depthTmp;
1814#if H_3D_VSP_BLOCKSIZE == 1
1815        depthTmp = depthi + (i << 1);
1816#endif
1817#if H_3D_VSP_BLOCKSIZE == 2
1818        if (depthPosX + (i<<1) < widthDepth)
1819          depthTmp = depthi + (i << 1);
1820        else
1821          depthTmp = depthi + (widthDepth - depthPosX - 1);
1822#endif
1823#if H_3D_VSP_BLOCKSIZE == 4
1824        if (depthPosX + (i<<2) < widthDepth)
1825          depthTmp = depthi + (i << 2);
1826        else
1827          depthTmp = depthi + (widthDepth - depthPosX - 1);
1828#endif
1829        Int maxV = 0;
1830        for (Int blockj = 0; blockj < sH; blockj+=(sH-1))
1831        {
1832          Int iX = 0;
1833          for (Int blocki = 0; blocki < sW; blocki+=(sW-1))
1834          {
1835            if (maxV < depthTmp[iX])
1836              maxV = depthTmp[iX];
1837            if (depthPosX + i*sW + blocki < widthDepth - 1)
1838                iX = (sW-1);
1839          }
1840          if (depthPosY + j*sH + blockj < heightDepth - 1)
1841                depthTmp += depStride * (sH-1);
1842        }
1843        m_pDepthBlock[i+j*dW] = maxV;
1844      } // end of i < dW
1845#if H_3D_VSP_BLOCKSIZE == 1
1846      if (depthPosY + ((j+1)<<1) < heightDepth)
1847        depthi += (depStride << 1);
1848      else
1849        depthi  = depth + (heightDepth-1)*depStride;
1850#endif
1851#if H_3D_VSP_BLOCKSIZE == 2
1852      if (depthPosY + ((j+1)<<1) < heightDepth)
1853        depthi += (depStride << 1);
1854      else
1855        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
1856#endif
1857#if H_3D_VSP_BLOCKSIZE == 4
1858      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
1859        depthi += (depStride << 2);
1860      else
1861        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
1862#endif
1863    }
1864  }
1865
1866
1867#if H_3D_VSP_BLOCKSIZE == 1
1868#if H_3D_VSP_CONSTRAINED
1869  //get LUT based horizontal reference range
1870  Int range = xGetConstrainedSize(sizeX, sizeY, false);
1871
1872  // The minimum depth value
1873  Int minRelativePos = MAX_INT;
1874  Int maxRelativePos = MIN_INT;
1875
1876  Int depthTmp;
1877  for (Int yTxt=0; yTxt<sizeY; yTxt++)
1878  {
1879    for (Int xTxt=0; xTxt<sizeX; xTxt++)
1880    {
1881      depthTmp = m_pDepthBlock[xTxt+yTxt*dW];
1882      Int disparity = pShiftLUT[ depthTmp ]; // << iShiftPrec;
1883      Int disparityInt = disparity >> 3;//in chroma resolution
1884
1885      if (disparityInt < 0)
1886      {
1887        if (minRelativePos > disparityInt+xTxt)
1888            minRelativePos = disparityInt+xTxt;
1889      }
1890      else
1891      {
1892        if (maxRelativePos < disparityInt+xTxt)
1893            maxRelativePos = disparityInt+xTxt;
1894      }
1895    }
1896  }
1897
1898  depthTmp = m_pDepthBlock[0];
1899  Int disparity_tmp = pShiftLUT[ depthTmp ]; // << iShiftPrec;
1900  if ( disparity_tmp < 0 )
1901    maxRelativePos = minRelativePos + range - 1;
1902  else
1903    minRelativePos = maxRelativePos - range + 1;
1904
1905#endif // H_3D_VSP_CONSTRAINED
1906#endif // H_3D_VSP_BLOCKSIZE == 1
1907
1908    // (sizeX, sizeY) is Chroma block size
1909    for ( Int yTxt = 0, yDepth = 0; yTxt < sizeY; yTxt += nTxtPerDepthY, yDepth += nDepthPerTxtY )
1910    {
1911      for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth += nDepthPerTxtX )
1912      {
1913        Pel repDepth = 0; // to store the depth value used for warping
1914#if H_3D_VSP_BLOCKSIZE == 1
1915        repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW];
1916#endif
1917#if H_3D_VSP_BLOCKSIZE == 2
1918        repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW];
1919#endif
1920#if H_3D_VSP_BLOCKSIZE == 4
1921        repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW];
1922#endif
1923
1924      // calculate the offset in the reference picture
1925        Int disparity = pShiftLUT[ repDepth ]; // Remove << iShiftPrec;
1926        Int refOffset = xTxt + (disparity >> 3); // in integer pixel in chroma image
1927        Int xFrac = disparity & 0x7;
1928#if H_3D_VSP_CONSTRAINED
1929        if(refOffset < minRelativePos || refOffset > maxRelativePos)
1930          xFrac = 0;
1931        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
1932#endif
1933        Int absX  = posX + refOffset;
1934
1935        if (xFrac == 0)
1936          absX = Clip3(0, widthChroma-1, absX);
1937        else
1938          absX = Clip3(4, widthChroma-5, absX);
1939
1940        refOffset = absX - posX;
1941
1942        assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
1943        assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
1944        m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
1945        m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
1946      }
1947      refCb += refStrideBlock;
1948      refCr += refStrideBlock;
1949      dstCb += dstStrideBlock;
1950      dstCr += dstStrideBlock;
1951      depth += depStrideBlock;
1952    }
1953  }
1954
1955}
1956
1957#if H_3D_VSP_CONSTRAINED
1958Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma)
1959{
1960  Int iSize = 0;
1961  if (bLuma)
1962  {
1963    Int iArea = (nPbW+7) * (nPbH+7);
1964    Int iAlpha = iArea / nPbH - nPbW - 7;
1965    iSize = iAlpha + nPbW;
1966  }
1967  else // chroma
1968  {
1969    Int iArea = (nPbW+2) * (nPbH+2);
1970    Int iAlpha = iArea / nPbH - nPbW - 4;
1971    iSize = iAlpha + nPbW;
1972  }
1973  return iSize;
1974}
1975#endif // H_3D_VSP_CONSTRAINED
1976
1977#endif // H_3D_VSP
1978
1979#if H_3D_DIM
1980Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
1981{
1982  Int  refDC1, refDC2;
1983  const Int  iTR = (   patternStride - 1        ) - srcStride;
1984  const Int  iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride;
1985  const Int  iLB = (   patternStride - 1        ) * srcStride - 1;
1986  const Int  iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1;
1987
1988  Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] );
1989  Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)]               );
1990
1991  if( bL == bT )
1992  {
1993    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : 1<<( g_bitDepthY - 1 );
1994    refDC2 =      ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1;
1995  }
1996  else
1997  {
1998    refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR];
1999    refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM];
2000  }
2001
2002  predDC1 = biSegPattern[0] ? refDC1 : refDC2;
2003  predDC2 = biSegPattern[0] ? refDC2 : refDC1;
2004}
2005
2006Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
2007{
2008  if( dstStride == patternStride )
2009  {
2010    for( UInt k = 0; k < (patternStride * patternStride); k++ )
2011    {
2012      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
2013      else                          { ptrDst[k] = valDC1; }
2014    }
2015  }
2016  else
2017  {
2018    Pel* piTemp = ptrDst;
2019    for( UInt uiY = 0; uiY < patternStride; uiY++ )
2020    {
2021      for( UInt uiX = 0; uiX < patternStride; uiX++ )
2022      {
2023        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
2024        else                            { piTemp[uiX] = valDC1; }
2025      }
2026      piTemp       += dstStride;
2027      biSegPattern += patternStride;
2028    }
2029  }
2030}
2031
2032#if H_3D_DIM_DMM
2033UInt TComPrediction::xPredWedgeFromIntra( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd )
2034{
2035  UInt uiThisBlockSize = uiWidth;
2036
2037  TComDataCU* pcTempCU;
2038  UInt        uiTempPartIdx;
2039  // 1st: try continue above wedgelet
2040  pcTempCU = pcCU->getPUAbove( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2041  if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) )
2042  {
2043    UInt dimType =  getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
2044    if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
2045    {
2046      // get offset between current and reference block
2047      UInt uiOffsetX = 0, uiOffsetY = 0;
2048      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
2049
2050      // get reference wedgelet
2051      WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])];
2052      TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) );
2053
2054      // find wedgelet, if direction is suitable for continue wedge
2055      if( pcRefWedgelet->checkPredDirAbovePossible( uiThisBlockSize, uiOffsetX ) )
2056      {
2057        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
2058        pcRefWedgelet->getPredDirStartEndAbove( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetX, iDeltaEnd );
2059        return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
2060      }
2061    }
2062  }
2063
2064  // 2nd: try continue left wedglelet
2065  pcTempCU = pcCU->getPULeft( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2066  if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) )
2067  {
2068    UInt dimType = getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
2069    if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
2070    {
2071      // get offset between current and reference block
2072      UInt uiOffsetX = 0, uiOffsetY = 0;
2073      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
2074
2075      // get reference wedgelet
2076      WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])];
2077      TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) );
2078
2079      // find wedgelet, if direction is suitable for continue wedge
2080      if( pcRefWedgelet->checkPredDirLeftPossible( uiThisBlockSize, uiOffsetY ) )
2081      {
2082        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
2083        pcRefWedgelet->getPredDirStartEndLeft( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetY, iDeltaEnd );
2084        return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
2085      }
2086    }
2087  }
2088
2089  // 3rd: (default) make wedglet from intra dir and max slope point
2090  Int iSlopeX = 0, iSlopeY = 0;
2091  UInt uiStartPosX = 0, uiStartPosY = 0;
2092  if( xGetWedgeIntraDirPredData( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY ) )
2093  {
2094    UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
2095    xGetWedgeIntraDirStartEnd( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, iDeltaEnd );
2096    return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
2097  }
2098
2099  return 0;
2100}
2101
2102UInt TComPrediction::xPredWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx )
2103{
2104  TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
2105  assert( pcPicTex != NULL );
2106  TComDataCU*   pcColTexCU = pcPicTex->getCU(pcCU->getAddr());
2107  UInt          uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
2108  Int           uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
2109
2110  if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 ) { return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx); }
2111  else                                                     { return g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])].at(intraTabIdx).getPatternIdx(); }
2112}
2113
2114Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
2115{
2116  pcContourWedge->clear();
2117
2118  // get copy of co-located texture luma block
2119  TComYuv cTempYuv;
2120  cTempYuv.create( uiWidth, uiHeight ); 
2121  cTempYuv.clear();
2122  Pel* piRefBlkY = cTempYuv.getLumaAddr();
2123  xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
2124  piRefBlkY = cTempYuv.getLumaAddr();
2125
2126  // find contour for texture luma block
2127  UInt iDC = 0;
2128  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2129  { 
2130    iDC += piRefBlkY[k]; 
2131  }
2132  iDC /= (uiWidth*uiHeight);
2133  piRefBlkY = cTempYuv.getLumaAddr();
2134
2135  Bool* pabContourPattern = pcContourWedge->getPattern();
2136  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2137  { 
2138    pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
2139  }
2140
2141  cTempYuv.destroy();
2142}
2143
2144
2145Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
2146{
2147  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
2148  assert( pcPicYuvRef != NULL );
2149  Int         iRefStride = pcPicYuvRef->getStride();
2150  Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2151
2152  for ( Int y = 0; y < uiHeight; y++ )
2153  {
2154    ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
2155    piDestBlockY += uiWidth;
2156    piRefY += iRefStride;
2157  }
2158}
2159
2160Void TComPrediction::xGetBlockOffset( TComDataCU* pcCU, UInt uiAbsPartIdx, TComDataCU* pcRefCU, UInt uiRefAbsPartIdx, UInt& ruiOffsetX, UInt& ruiOffsetY )
2161{
2162  ruiOffsetX = 0;
2163  ruiOffsetY = 0;
2164
2165  // get offset between current and above/left block
2166  UInt uiThisOriginX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
2167  UInt uiThisOriginY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
2168
2169  UInt uiNumPartInRefCU = pcRefCU->getTotalNumPart();
2170  UInt uiMaxDepthRefCU = 0;
2171  while( uiNumPartInRefCU > 1 )
2172  {
2173    uiNumPartInRefCU >>= 2;
2174    uiMaxDepthRefCU++;
2175  }
2176
2177  UInt uiDepthRefPU = (pcRefCU->getDepth(uiRefAbsPartIdx)) + (pcRefCU->getPartitionSize(uiRefAbsPartIdx) == SIZE_2Nx2N ? 0 : 1);
2178  UInt uiShifts = (uiMaxDepthRefCU - uiDepthRefPU)*2;
2179  UInt uiRefBlockOriginPartIdx = (uiRefAbsPartIdx>>uiShifts)<<uiShifts;
2180
2181  UInt uiRefOriginX = pcRefCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ];
2182  UInt uiRefOriginY = pcRefCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ];
2183
2184  if( (uiThisOriginX - uiRefOriginX) > 0 ) { ruiOffsetX = (UInt)(uiThisOriginX - uiRefOriginX); }
2185  if( (uiThisOriginY - uiRefOriginY) > 0 ) { ruiOffsetY = (UInt)(uiThisOriginY - uiRefOriginY); }
2186}
2187
2188Bool TComPrediction::xGetWedgeIntraDirPredData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int& riSlopeX, Int& riSlopeY, UInt& ruiStartPosX, UInt& ruiStartPosY )
2189{
2190  riSlopeX = 0, riSlopeY = 0, ruiStartPosX = 0, ruiStartPosY = 0;
2191
2192  // 1st step: get wedge start point (max. slope)
2193  Int* piSource = pcCU->getPattern()->getAdiOrgBuf( uiBlockSize, uiBlockSize, m_piYuvExt );
2194  Int iSourceStride = ( uiBlockSize<<1 ) + 1;
2195
2196  UInt uiSlopeMaxAbove = 0, uiPosSlopeMaxAbove = 0;
2197  for( UInt uiPosHor = 0; uiPosHor < (uiBlockSize-1); uiPosHor++ )
2198  {
2199    if( abs( piSource[uiPosHor+1] - piSource[uiPosHor] ) > uiSlopeMaxAbove )
2200    {
2201      uiSlopeMaxAbove = abs( piSource[uiPosHor+1] - piSource[uiPosHor] );
2202      uiPosSlopeMaxAbove = uiPosHor;
2203    }
2204  }
2205
2206  UInt uiSlopeMaxLeft = 0, uiPosSlopeMaxLeft = 0;
2207  for( UInt uiPosVer = 0; uiPosVer < (uiBlockSize-1); uiPosVer++ )
2208  {
2209    if( abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] ) > uiSlopeMaxLeft )
2210    {
2211      uiSlopeMaxLeft = abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] );
2212      uiPosSlopeMaxLeft = uiPosVer;
2213    }
2214  }
2215
2216  if( uiSlopeMaxAbove == 0 && uiSlopeMaxLeft == 0 ) 
2217  { 
2218    return false; 
2219  }
2220
2221  ruiStartPosX = ( uiSlopeMaxAbove >  uiSlopeMaxLeft  ) ? uiPosSlopeMaxAbove : 0;
2222  ruiStartPosY = ( uiSlopeMaxLeft  >= uiSlopeMaxAbove ) ? uiPosSlopeMaxLeft  : 0;
2223
2224  // 2nd step: derive wedge direction
2225  Int uiPreds[3] = {-1, -1, -1};
2226  Int iMode = -1;
2227  Int iPredNum = pcCU->getIntraDirLumaPredictor( uiAbsPartIdx, uiPreds, &iMode ); 
2228
2229  UInt uiDirMode = 0;
2230  if( iMode >= 0 ) { iPredNum = iMode; }
2231  if( iPredNum == 1 ) { uiDirMode = uiPreds[0]; }
2232  if( iPredNum == 2 ) { uiDirMode = uiPreds[1]; }
2233
2234  if( uiDirMode < 2 ) { return false; } // no planar & DC
2235
2236  Bool modeHor       = (uiDirMode < 18);
2237  Bool modeVer       = !modeHor;
2238  Int intraPredAngle = modeVer ? (Int)uiDirMode - VER_IDX : modeHor ? -((Int)uiDirMode - HOR_IDX) : 0;
2239  Int absAng         = abs(intraPredAngle);
2240  Int signAng        = intraPredAngle < 0 ? -1 : 1;
2241  Int angTable[9]    = {0,2,5,9,13,17,21,26,32};
2242  absAng             = angTable[absAng];
2243  intraPredAngle     = signAng * absAng;
2244
2245  // 3rd step: set slope for direction
2246  if( modeHor )
2247  {
2248    riSlopeX = ( intraPredAngle > 0 ) ?            -32 :              32;
2249    riSlopeY = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle;
2250  }
2251  else if( modeVer )
2252  {
2253    riSlopeX = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle;
2254    riSlopeY = ( intraPredAngle > 0 ) ?            -32 :              32;
2255  }
2256
2257  return true;
2258}
2259
2260Void TComPrediction::xGetWedgeIntraDirStartEnd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int iDeltaX, Int iDeltaY, UInt uiPMSPosX, UInt uiPMSPosY, UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, Int iDeltaEnd )
2261{
2262  ruhXs = 0;
2263  ruhYs = 0;
2264  ruhXe = 0;
2265  ruhYe = 0;
2266
2267  // scaling of start pos and block size to wedge resolution
2268  UInt uiScaledStartPosX = 0;
2269  UInt uiScaledStartPosY = 0;
2270  UInt uiScaledBlockSize = 0;
2271  WedgeResolution eWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiBlockSize]];
2272  switch( eWedgeRes )
2273  {
2274  case( DOUBLE_PEL ): { uiScaledStartPosX = (uiPMSPosX>>1); uiScaledStartPosY = (uiPMSPosY>>1); uiScaledBlockSize = (uiBlockSize>>1); break; }
2275  case(   FULL_PEL ): { uiScaledStartPosX =  uiPMSPosX;     uiScaledStartPosY =  uiPMSPosY;     uiScaledBlockSize =  uiBlockSize;     break; }
2276  case(   HALF_PEL ): { uiScaledStartPosX = (uiPMSPosX<<1); uiScaledStartPosY = (uiPMSPosY<<1); uiScaledBlockSize = (uiBlockSize<<1); break; }
2277  }
2278  Int iMaxPos = (Int)uiScaledBlockSize - 1;
2279
2280  // case above
2281  if( uiScaledStartPosX > 0 && uiScaledStartPosY == 0 )
2282  {
2283    ruhXs = (UChar)uiScaledStartPosX;
2284    ruhYs = 0;
2285
2286    if( iDeltaY == 0 )
2287    {
2288      if( iDeltaX < 0 )
2289      {
2290        ruhXe = 0;
2291        ruhYe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos );
2292        return;
2293      }
2294      else
2295      {
2296        ruhXe = (UChar)iMaxPos;
2297        ruhYe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos );
2298        std::swap( ruhXs, ruhXe );
2299        std::swap( ruhYs, ruhYe );
2300        return;
2301      }
2302    }
2303
2304    // regular case
2305    Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) );
2306
2307    if( iVirtualEndX < 0 )
2308    {
2309      Int iYe = roftoi( (Double)(0 - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) + iDeltaEnd;
2310      if( iYe < (Int)uiScaledBlockSize )
2311      {
2312        ruhXe = 0;
2313        ruhYe = (UChar)std::max( iYe, 0 );
2314        return;
2315      }
2316      else
2317      {
2318        ruhXe = (UChar)std::min( (iYe - iMaxPos), iMaxPos );
2319        ruhYe = (UChar)iMaxPos;
2320        return;
2321      }
2322    }
2323    else if( iVirtualEndX > iMaxPos )
2324    {
2325      Int iYe = roftoi( (Double)(iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd;
2326      if( iYe < (Int)uiScaledBlockSize )
2327      {
2328        ruhXe = (UChar)iMaxPos;
2329        ruhYe = (UChar)std::max( iYe, 0 );
2330        std::swap( ruhXs, ruhXe );
2331        std::swap( ruhYs, ruhYe );
2332        return;
2333      }
2334      else
2335      {
2336        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
2337        ruhYe = (UChar)iMaxPos;
2338        return;
2339      }
2340    }
2341    else
2342    {
2343      Int iXe = iVirtualEndX + iDeltaEnd;
2344      if( iXe < 0 )
2345      {
2346        ruhXe = 0;
2347        ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 );
2348        return;
2349      }
2350      else if( iXe > iMaxPos )
2351      {
2352        ruhXe = (UChar)iMaxPos;
2353        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
2354        std::swap( ruhXs, ruhXe );
2355        std::swap( ruhYs, ruhYe );
2356        return;
2357      }
2358      else
2359      {
2360        ruhXe = (UChar)iXe;
2361        ruhYe = (UChar)iMaxPos;
2362        return;
2363      }
2364    }
2365  }
2366
2367  // case left
2368  if( uiScaledStartPosY > 0 && uiScaledStartPosX == 0 )
2369  {
2370    ruhXs = 0;
2371    ruhYs = (UChar)uiScaledStartPosY;
2372
2373    if( iDeltaX == 0 )
2374    {
2375      if( iDeltaY < 0 )
2376      {
2377        ruhXe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos );
2378        ruhYe = 0;
2379        std::swap( ruhXs, ruhXe );
2380        std::swap( ruhYs, ruhYe );
2381        return;
2382      }
2383      else
2384      {
2385        ruhXe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos );
2386        ruhYe = (UChar)iMaxPos;
2387        return; 
2388      }
2389    }
2390
2391    // regular case
2392    Int iVirtualEndY = (Int)ruhYs + roftoi( (Double)iMaxPos * ((Double)iDeltaY / (Double)iDeltaX) );
2393
2394    if( iVirtualEndY < 0 )
2395    {
2396      Int iXe = roftoi( (Double)(0 - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) - iDeltaEnd;
2397      if( iXe < (Int)uiScaledBlockSize )
2398      {
2399        ruhXe = (UChar)std::max( iXe, 0 );
2400        ruhYe = 0;
2401        std::swap( ruhXs, ruhXe );
2402        std::swap( ruhYs, ruhYe );
2403        return;
2404      }
2405      else
2406      {
2407        ruhXe = (UChar)iMaxPos;
2408        ruhYe = (UChar)std::min( (iXe - iMaxPos), iMaxPos );
2409        std::swap( ruhXs, ruhXe );
2410        std::swap( ruhYs, ruhYe );
2411        return;
2412      }
2413    }
2414    else if( iVirtualEndY > (uiScaledBlockSize-1) )
2415    {
2416      Int iXe = roftoi( (Double)((Int)(uiScaledBlockSize-1) - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) + iDeltaEnd;
2417      if( iXe < (Int)uiScaledBlockSize )
2418      {
2419        ruhXe = (UChar)std::max( iXe, 0 );
2420        ruhYe = (UChar)(uiScaledBlockSize-1);
2421        return;
2422      }
2423      else
2424      {
2425        ruhXe = (UChar)iMaxPos;
2426        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
2427        std::swap( ruhXs, ruhXe );
2428        std::swap( ruhYs, ruhYe );
2429        return;
2430      }
2431    }
2432    else
2433    {
2434      Int iYe = iVirtualEndY - iDeltaEnd;
2435      if( iYe < 0 )
2436      {
2437        ruhXe = (UChar)std::max( (iMaxPos + iYe), 0 );
2438        ruhYe = 0;
2439        std::swap( ruhXs, ruhXe );
2440        std::swap( ruhYs, ruhYe );
2441        return;
2442      }
2443      else if( iYe > iMaxPos )
2444      {
2445        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
2446        ruhYe = (UChar)iMaxPos;
2447        return;
2448      }
2449      else
2450      {
2451        ruhXe = (UChar)iMaxPos;
2452        ruhYe = (UChar)iYe;
2453        std::swap( ruhXs, ruhXe );
2454        std::swap( ruhYs, ruhYe );
2455        return;
2456      }
2457    }
2458  }
2459
2460  // case origin
2461  if( uiScaledStartPosX == 0 && uiScaledStartPosY == 0 )
2462  {
2463    if( iDeltaX*iDeltaY < 0 )
2464    {
2465      return;
2466    }
2467
2468    ruhXs = 0;
2469    ruhYs = 0;
2470
2471    if( iDeltaY == 0 )
2472    {
2473      ruhXe = (UChar)iMaxPos;
2474      ruhYe = 0;
2475      std::swap( ruhXs, ruhXe );
2476      std::swap( ruhYs, ruhYe );
2477      return;
2478    }
2479
2480    if( iDeltaX == 0 )
2481    {
2482      ruhXe = 0;
2483      ruhYe = (UChar)iMaxPos;
2484      return;
2485    }
2486
2487    Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) );
2488
2489    if( iVirtualEndX > iMaxPos )
2490    {
2491      Int iYe = roftoi( (Double)((Int)iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd;
2492      if( iYe < (Int)uiScaledBlockSize )
2493      {
2494        ruhXe = (UChar)(uiScaledBlockSize-1);
2495        ruhYe = (UChar)std::max( iYe, 0 );
2496        std::swap( ruhXs, ruhXe );
2497        std::swap( ruhYs, ruhYe );
2498        return;
2499      }
2500      else
2501      {
2502        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
2503        ruhYe = (UChar)(uiScaledBlockSize-1);
2504        return;
2505      }
2506    }
2507    else
2508    {
2509      Int iXe = iVirtualEndX + iDeltaEnd;
2510      if( iXe < 0 )
2511      {
2512        ruhXe = 0;
2513        ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 );
2514        return;
2515      }
2516      else if( iXe > iMaxPos )
2517      {
2518        ruhXe = (UChar)(uiScaledBlockSize-1);
2519        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
2520        std::swap( ruhXs, ruhXe );
2521        std::swap( ruhYs, ruhYe );
2522        return;
2523      }
2524      else
2525      {
2526        ruhXe = (UChar)iXe;
2527        ruhYe = (UChar)(uiScaledBlockSize-1);
2528        return;
2529      }
2530    }
2531  }
2532}
2533
2534UInt TComPrediction::xGetWedgePatternIdx( UInt uiBlockSize, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe )
2535{
2536  WedgeRefList* pcWedgeRefList = &g_dmmWedgeRefLists[(g_aucConvertToBit[uiBlockSize])];
2537  for( UInt uiIdx = 0; uiIdx < pcWedgeRefList->size(); uiIdx++ )
2538  {
2539    TComWedgeRef* pcTestWedgeRef = &(pcWedgeRefList->at(uiIdx));
2540    if( pcTestWedgeRef->getStartX() == uhXs && pcTestWedgeRef->getStartY() == uhYs && pcTestWedgeRef->getEndX() == uhXe && pcTestWedgeRef->getEndY() == uhYe )
2541    {
2542      return pcTestWedgeRef->getRefIdx();
2543    }
2544  }
2545  return 0;
2546}
2547#endif
2548#if H_3D_DIM_RBC
2549Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Pel& rDeltaDC )
2550{
2551  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
2552  UInt uiAbs  = abs( rDeltaDC );
2553
2554  Int iQp = pcCU->getQP(0);
2555  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
2556  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
2557
2558  rDeltaDC = iSign * roftoi( uiAbs * dStepSize );
2559  return;
2560}
2561
2562Void TComPrediction::xDeltaDCQuantScaleDown( TComDataCU*  pcCU, Pel& rDeltaDC )
2563{
2564  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
2565  UInt uiAbs  = abs( rDeltaDC );
2566
2567  Int iQp = pcCU->getQP(0);
2568  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
2569  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
2570
2571  rDeltaDC = iSign * roftoi( uiAbs / dStepSize );
2572  return;
2573}
2574#endif
2575#if H_3D_DIM_SDC
2576Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride )
2577{
2578  Int iSumDepth[2];
2579  memset(iSumDepth, 0, sizeof(Int)*2);
2580  Int iSumPix[2];
2581  memset(iSumPix, 0, sizeof(Int)*2);
2582 
2583  Int subSamplePix;
2584  if ( uiSize == 64 || uiSize == 32 )
2585  {
2586    subSamplePix = 2;
2587  }
2588  else
2589  {
2590    subSamplePix = 1;
2591  }
2592  for (Int y=0; y<uiSize; y+=subSamplePix)
2593  {
2594    for (Int x=0; x<uiSize; x+=subSamplePix)
2595    {
2596      UChar ucSegment = pMask?(UChar)pMask[x]:0;
2597      assert( ucSegment < uiNumSegments );
2598     
2599      iSumDepth[ucSegment] += pOrig[x];
2600      iSumPix[ucSegment]   += 1;
2601    }
2602   
2603    pOrig  += uiStride*subSamplePix;
2604    pMask  += uiMaskStride*subSamplePix;
2605  }
2606 
2607  // compute mean for each segment
2608  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
2609  {
2610    if( iSumPix[ucSeg] > 0 )
2611      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
2612    else
2613      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
2614  }
2615}
2616#endif // H_3D_DIM_SDC
2617#endif
2618//! \}
Note: See TracBrowser for help on using the repository browser.