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

Last change on this file since 532 was 532, checked in by tech, 11 years ago
  • Fixed cfg files.
  • Fixed several memory leaks.
  • Fixed encoder/decoder mismatch and aligned order of vps syntax elements with draft text.
  • Added missing iv_mv_scaling flag.
  • 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
79  if( m_pLumaRecBuffer )
80  {
81    delete [] m_pLumaRecBuffer;
82  }
83 
84  Int i, j;
85  for (i = 0; i < 4; i++)
86  {
87    for (j = 0; j < 4; j++)
88    {
89      m_filteredBlock[i][j].destroy();
90    }
91    m_filteredBlockTmp[i].destroy();
92  }
93}
94
95Void TComPrediction::initTempBuff()
96{
97  if( m_piYuvExt == NULL )
98  {
99    Int extWidth  = MAX_CU_SIZE + 16; 
100    Int extHeight = MAX_CU_SIZE + 1;
101    Int i, j;
102    for (i = 0; i < 4; i++)
103    {
104      m_filteredBlockTmp[i].create(extWidth, extHeight + 7);
105      for (j = 0; j < 4; j++)
106      {
107        m_filteredBlock[i][j].create(extWidth, extHeight);
108      }
109    }
110    m_iYuvExtHeight  = ((MAX_CU_SIZE + 2) << 4);
111    m_iYuvExtStride = ((MAX_CU_SIZE  + 8) << 4);
112    m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
113
114    // new structure
115    m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE );
116    m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE );
117
118    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE );
119#if H_3D_ARP
120    m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
121    m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
122#endif
123  }
124
125  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
126  {
127    m_iLumaRecStride =  (MAX_CU_SIZE>>1) + 1;
128    if (!m_pLumaRecBuffer)
129    {
130      m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ];
131    }
132  }
133#if H_3D_IC
134  for( Int i = 1; i < 64; i++ )
135  {
136    m_uiaShift[i-1] = ( (1 << 15) + i/2 ) / i;
137  }
138#endif
139}
140
141// ====================================================================================================================
142// Public member functions
143// ====================================================================================================================
144
145// Function for calculating DC value of the reference samples used in Intra prediction
146Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft )
147{
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
937  if ( yFrac == 0 )
938  {
939    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi
940#if H_3D_ARP
941    , filterType
942#endif
943      );
944  }
945  else if ( xFrac == 0 )
946  {
947    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi
948#if H_3D_ARP
949    , filterType
950#endif
951      );
952  }
953  else
954  {
955    Int tmpStride = m_filteredBlockTmp[0].getStride();
956    Short *tmp    = m_filteredBlockTmp[0].getLumaAddr();
957
958    Int filterSize = NTAPS_LUMA;
959    Int halfFilterSize = ( filterSize >> 1 );
960
961    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     
962#if H_3D_ARP
963    , filterType
964#endif
965      );
966    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi
967#if H_3D_ARP
968    , filterType
969#endif
970      );   
971  }
972
973#if H_3D_IC
974  if( bICFlag )
975  {
976    Int a, b, iShift, i, j;
977
978    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_LUMA );
979
980    for ( i = 0; i < height; i++ )
981    {
982      for ( j = 0; j < width; j++ )
983      {
984        if( bi )
985        {
986          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthY;
987          dst[j] = ( ( a*dst[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1 << iIFshift ) - IF_INTERNAL_OFFS;
988        }
989        else
990          dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
991      }
992      dst += dstStride;
993    }
994  }
995#endif
996}
997
998/**
999 * \brief Generate motion-compensated chroma block
1000 *
1001 * \param cu       Pointer to current CU
1002 * \param refPic   Pointer to reference picture
1003 * \param partAddr Address of block within CU
1004 * \param mv       Motion vector
1005 * \param width    Width of block
1006 * \param height   Height of block
1007 * \param dstPic   Pointer to destination picture
1008 * \param bi       Flag indicating whether bipred is used
1009 */
1010Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
1011#if H_3D_ARP
1012    , Bool filterType
1013#endif
1014#if H_3D_IC
1015    , Bool bICFlag
1016#endif
1017  )
1018{
1019  Int     refStride  = refPic->getCStride();
1020  Int     dstStride  = dstPic->getCStride();
1021 
1022  Int     refOffset  = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride;
1023 
1024  Pel*    refCb     = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1025  Pel*    refCr     = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1026 
1027  Pel* dstCb = dstPic->getCbAddr( partAddr );
1028  Pel* dstCr = dstPic->getCrAddr( partAddr );
1029 
1030  Int     xFrac  = mv->getHor() & 0x7;
1031  Int     yFrac  = mv->getVer() & 0x7;
1032  UInt    cxWidth  = width  >> 1;
1033  UInt    cxHeight = height >> 1;
1034 
1035  Int     extStride = m_filteredBlockTmp[0].getStride();
1036  Short*  extY      = m_filteredBlockTmp[0].getLumaAddr();
1037 
1038  Int filterSize = NTAPS_CHROMA;
1039 
1040  Int halfFilterSize = (filterSize>>1);
1041 
1042  if ( yFrac == 0 )
1043  {
1044    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi
1045#if H_3D_ARP
1046    , filterType
1047#endif
1048    );   
1049    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi
1050#if H_3D_ARP
1051    , filterType
1052#endif
1053    );
1054  }
1055  else if ( xFrac == 0 )
1056  {
1057    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1058#if H_3D_ARP
1059    , filterType
1060#endif
1061    );
1062    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1063#if H_3D_ARP
1064    , filterType
1065#endif
1066    );
1067  }
1068  else
1069  {
1070    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1071#if H_3D_ARP
1072    , filterType
1073#endif 
1074      );
1075    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1076#if H_3D_ARP
1077    , filterType
1078#endif
1079      );
1080   
1081    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1082#if H_3D_ARP
1083    , filterType
1084#endif
1085      );
1086    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1087#if H_3D_ARP
1088    , filterType
1089#endif
1090      );   
1091  }
1092
1093#if H_3D_IC
1094  if( bICFlag )
1095  {
1096    Int a, b, iShift, i, j;
1097    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_U ); // Cb
1098    for ( i = 0; i < cxHeight; i++ )
1099    {
1100      for ( j = 0; j < cxWidth; j++ )
1101      {
1102        if( bi )
1103        {
1104          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC;
1105          dstCb[j] = ( ( a*dstCb[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS;
1106        }
1107        else
1108          dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
1109      }
1110      dstCb += dstStride;
1111    }
1112    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_V ); // Cr
1113    for ( i = 0; i < cxHeight; i++ )
1114    {
1115      for ( j = 0; j < cxWidth; j++ )
1116      {
1117        if( bi )
1118        {
1119          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC;
1120          dstCr[j] = ( ( a*dstCr[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS;
1121        }
1122        else
1123          dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
1124      }
1125      dstCr += dstStride;
1126    }
1127  }
1128#endif
1129}
1130
1131Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
1132{
1133  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
1134  {
1135    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
1136  }
1137  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
1138  {
1139    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
1140  }
1141  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
1142  {
1143    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
1144  }
1145}
1146
1147// AMVP
1148Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
1149{
1150  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
1151  if( pcAMVPInfo->iN <= 1 )
1152  {
1153    rcMvPred = pcAMVPInfo->m_acMvCand[0];
1154
1155    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1156    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1157    return;
1158  }
1159
1160  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
1161  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
1162  return;
1163}
1164
1165/** Function for deriving planar intra prediction.
1166 * \param pSrc pointer to reconstructed sample array
1167 * \param srcStride the stride of the reconstructed sample array
1168 * \param rpDst reference to pointer for the prediction sample array
1169 * \param dstStride the stride of the prediction sample array
1170 * \param width the width of the block
1171 * \param height the height of the block
1172 *
1173 * This function derives the prediction samples for planar mode (intra coding).
1174 */
1175Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
1176{
1177  assert(width == height);
1178
1179  Int k, l, bottomLeft, topRight;
1180  Int horPred;
1181  Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
1182  UInt blkSize = width;
1183  UInt offset2D = width;
1184  UInt shift1D = g_aucConvertToBit[ width ] + 2;
1185  UInt shift2D = shift1D + 1;
1186
1187  // Get left and above reference column and row
1188  for(k=0;k<blkSize+1;k++)
1189  {
1190    topRow[k] = pSrc[k-srcStride];
1191    leftColumn[k] = pSrc[k*srcStride-1];
1192  }
1193
1194  // Prepare intermediate variables used in interpolation
1195  bottomLeft = leftColumn[blkSize];
1196  topRight   = topRow[blkSize];
1197  for (k=0;k<blkSize;k++)
1198  {
1199    bottomRow[k]   = bottomLeft - topRow[k];
1200    rightColumn[k] = topRight   - leftColumn[k];
1201    topRow[k]      <<= shift1D;
1202    leftColumn[k]  <<= shift1D;
1203  }
1204
1205  // Generate prediction signal
1206  for (k=0;k<blkSize;k++)
1207  {
1208    horPred = leftColumn[k] + offset2D;
1209    for (l=0;l<blkSize;l++)
1210    {
1211      horPred += rightColumn[k];
1212      topRow[l] += bottomRow[l];
1213      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
1214    }
1215  }
1216}
1217
1218/** Function for filtering intra DC predictor.
1219 * \param pSrc pointer to reconstructed sample array
1220 * \param iSrcStride the stride of the reconstructed sample array
1221 * \param rpDst reference to pointer for the prediction sample array
1222 * \param iDstStride the stride of the prediction sample array
1223 * \param iWidth the width of the block
1224 * \param iHeight the height of the block
1225 *
1226 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
1227 */
1228Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
1229{
1230  Pel* pDst = rpDst;
1231  Int x, y, iDstStride2, iSrcStride2;
1232
1233  // boundary pixels processing
1234  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
1235
1236  for ( x = 1; x < iWidth; x++ )
1237  {
1238    pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
1239  }
1240
1241  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
1242  {
1243    pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
1244  }
1245
1246  return;
1247}
1248
1249#if H_3D_IC
1250/** Function for deriving the position of first non-zero binary bit of a value
1251 * \param x input value
1252 *
1253 * This function derives the position of first non-zero binary bit of a value
1254 */
1255Int GetMSB( UInt x )
1256{
1257  Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1;
1258
1259  while( x > 1 )
1260  {
1261    bits >>= 1;
1262    y = x >> bits;
1263
1264    if( y )
1265    {
1266      x = y;
1267      iMSB += bits;
1268    }
1269  }
1270
1271  iMSB+=y;
1272
1273  return iMSB;
1274}
1275
1276/** Function for counting leading number of zeros/ones
1277 * \param x input value
1278 \ This function counts leading number of zeros for positive numbers and
1279 \ leading number of ones for negative numbers. This can be implemented in
1280 \ single instructure cycle on many processors.
1281 */
1282
1283Short CountLeadingZerosOnes (Short x)
1284{
1285  Short clz;
1286  Short i;
1287
1288  if(x == 0)
1289  {
1290    clz = 0;
1291  }
1292  else
1293  {
1294    if (x == -1)
1295    {
1296      clz = 15;
1297    }
1298    else
1299    {
1300      if(x < 0)
1301      {
1302        x = ~x;
1303      }
1304      clz = 15;
1305      for(i = 0;i < 15;++i)
1306      {
1307        if(x) 
1308        {
1309          clz --;
1310        }
1311        x = x >> 1;
1312      }
1313    }
1314  }
1315  return clz;
1316}
1317
1318/** Function for deriving LM illumination compensation.
1319 */
1320Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, Int &iShift, TextType eType )
1321{
1322  TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
1323  Pel *pRec = NULL, *pRef = NULL;
1324  UInt uiWidth, uiHeight, uiTmpPartIdx;
1325  Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride();
1326  Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride();
1327  Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer;
1328
1329  iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
1330  iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
1331  iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 );
1332  iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 );
1333  iRefX   = iCUPelX + iHor;
1334  iRefY   = iCUPelY + iVer;
1335  if( eType != TEXT_LUMA )
1336  {
1337    iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 );
1338    iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 );
1339  }
1340  uiWidth  = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 )  : ( pcCU->getWidth( 0 )  >> 1 );
1341  uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 );
1342
1343  Int i, j, iCountShift = 0;
1344
1345  // LLS parameters estimation -->
1346
1347  Int x = 0, y = 0, xx = 0, xy = 0;
1348
1349  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 )
1350  {
1351    iRefOffset = iHor + iVer * iRefStride - iRefStride;
1352    if( eType == TEXT_LUMA )
1353    {
1354      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1355      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
1356    }
1357    else if( eType == TEXT_CHROMA_U )
1358    {
1359      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1360      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
1361    }
1362    else
1363    {
1364      assert( eType == TEXT_CHROMA_V );
1365      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1366      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
1367    }
1368
1369    for( j = 0; j < uiWidth; j++ )
1370    {
1371      x += pRef[j];
1372      y += pRec[j];
1373      xx += pRef[j] * pRef[j];
1374      xy += pRef[j] * pRec[j];
1375    }
1376    iCountShift += g_aucConvertToBit[ uiWidth ] + 2;
1377  }
1378
1379
1380  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 )
1381  {
1382    iRefOffset = iHor + iVer * iRefStride - 1;
1383    if( eType == TEXT_LUMA )
1384    {
1385      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1386      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1387    }
1388    else if( eType == TEXT_CHROMA_U )
1389    {
1390      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1391      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1392    }
1393    else
1394    {
1395      assert( eType == TEXT_CHROMA_V );
1396      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1397      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1398    }
1399
1400    for( i = 0; i < uiHeight; i++ )
1401    {
1402      x += pRef[0];
1403      y += pRec[0];
1404      xx += pRef[0] * pRef[0];
1405      xy += pRef[0] * pRec[0];
1406
1407      pRef += iRefStride;
1408      pRec += iRecStride;
1409    }
1410    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 );
1411  }
1412
1413  Int iTempShift = ( ( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC ) + g_aucConvertToBit[ uiWidth ] + 3 - 15;
1414
1415  if( iTempShift > 0 )
1416  {
1417    x  = ( x +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
1418    y  = ( y +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
1419    xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
1420    xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
1421    iCountShift -= iTempShift;
1422  }
1423
1424  iShift = 13;
1425
1426  if( iCountShift == 0 )
1427  {
1428    a = 1;
1429    b = 0;
1430    iShift = 0;
1431  }
1432  else
1433  {
1434    Int a1 = ( xy << iCountShift ) - y * x;
1435    Int a2 = ( xx << iCountShift ) - x * x;             
1436
1437    {
1438      const Int iShiftA2 = 6;
1439      const Int iShiftA1 = 15;
1440      const Int iAccuracyShift = 15;
1441
1442      Int iScaleShiftA2 = 0;
1443      Int iScaleShiftA1 = 0;
1444      Int a1s = a1;
1445      Int a2s = a2;
1446
1447      iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1;
1448      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; 
1449
1450      if( iScaleShiftA1 < 0 )
1451      {
1452        iScaleShiftA1 = 0;
1453      }
1454
1455      if( iScaleShiftA2 < 0 )
1456      {
1457        iScaleShiftA2 = 0;
1458      }
1459
1460      Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
1461
1462      a2s = a2 >> iScaleShiftA2;
1463
1464      a1s = a1 >> iScaleShiftA1;
1465
1466      if (a2s >= 1)
1467      {
1468        a = a1s * m_uiaShift[ a2s - 1];
1469      }
1470      else
1471      {
1472        a = 0;
1473      }
1474
1475      if( iScaleShiftA < 0 )
1476      {
1477        a = a << -iScaleShiftA;
1478      }
1479      else
1480      {
1481        a = a >> iScaleShiftA;
1482      }
1483
1484      a = Clip3( -( 1 << 15 ), ( 1 << 15 ) - 1, a ); 
1485
1486      Int minA = -(1 << (6));
1487      Int maxA = (1 << 6) - 1;
1488      if( a <= maxA && a >= minA )
1489      {
1490        // do nothing
1491      }
1492      else
1493      {
1494        Short n = CountLeadingZerosOnes( a );
1495        a = a >> (9-n);
1496        iShift -= (9-n);
1497      }
1498
1499      b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
1500    }
1501  }   
1502}
1503#endif
1504
1505#if H_3D_VSP
1506// Input:
1507// refPic: Ref picture. Full picture, with padding
1508// posX, posY:     PU position, texture
1509// sizeX, sizeY: PU size
1510// partAddr: z-order index
1511// dv: disparity vector. derived from neighboring blocks
1512//
1513// Output: dstPic, PU predictor 64x64
1514Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr,Int posX, Int posY
1515                                            , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi )
1516{
1517  Int widthLuma;
1518  Int heightLuma;
1519
1520  if (isDepth)
1521  {
1522    widthLuma   =  pPicBaseDepth->getWidth();
1523    heightLuma  =  pPicBaseDepth->getHeight();
1524  }
1525  else
1526  {
1527    widthLuma   =  refPic->getWidth();
1528    heightLuma  =  refPic->getHeight();
1529  }
1530
1531#if H_3D_VSP_BLOCKSIZE != 1
1532  Int widthDepth  = pPicBaseDepth->getWidth();
1533  Int heightDepth = pPicBaseDepth->getHeight();
1534#endif
1535
1536#if H_3D_VSP_CONSTRAINED
1537  Int widthDepth  = pPicBaseDepth->getWidth();
1538  Int heightDepth = pPicBaseDepth->getHeight();
1539#endif
1540
1541  Int nTxtPerDepthX = widthLuma  / ( pPicBaseDepth->getWidth() );  // texture pixel # per depth pixel
1542  Int nTxtPerDepthY = heightLuma / ( pPicBaseDepth->getHeight() );
1543
1544  Int refStride = refPic->getStride();
1545  Int dstStride = dstPic->getStride();
1546  Int depStride =  pPicBaseDepth->getStride();
1547  Int depthPosX = Clip3(0,   widthLuma - sizeX,  (posX/nTxtPerDepthX) + ((dv->getHor()+2)>>2));
1548  Int depthPosY = Clip3(0,   heightLuma- sizeY,  (posY/nTxtPerDepthY) + ((dv->getVer()+2)>>2));
1549  Pel *ref    = refPic->getLumaAddr() + posX + posY * refStride;
1550  Pel *dst    = dstPic->getLumaAddr(partAddr);
1551  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;
1552
1553#if H_3D_VSP_BLOCKSIZE != 1
1554#if H_3D_VSP_BLOCKSIZE == 2
1555  Int  dW = sizeX>>1;
1556  Int  dH = sizeY>>1;
1557#endif
1558#if H_3D_VSP_BLOCKSIZE == 4
1559  Int  dW = sizeX>>2;
1560  Int  dH = sizeY>>2;
1561#endif
1562  {
1563    Pel* depthi = depth;
1564    for (Int j = 0; j < dH; j++)
1565    {
1566      for (Int i = 0; i < dW; i++)
1567      {
1568        Pel* depthTmp;
1569#if H_3D_VSP_BLOCKSIZE == 2
1570        if (depthPosX + (i<<1) < widthDepth)
1571          depthTmp = depthi + (i << 1);
1572        else
1573          depthTmp = depthi + (widthDepth - depthPosX - 1);
1574#endif
1575#if H_3D_VSP_BLOCKSIZE == 4
1576        if (depthPosX + (i<<2) < widthDepth)
1577          depthTmp = depthi + (i << 2);
1578        else
1579          depthTmp = depthi + (widthDepth - depthPosX - 1);
1580#endif
1581        Int maxV = 0;
1582        for (Int blockj = 0; blockj < H_3D_VSP_BLOCKSIZE; blockj+=(H_3D_VSP_BLOCKSIZE-1))
1583        {
1584          Int iX = 0;
1585          for (Int blocki = 0; blocki < H_3D_VSP_BLOCKSIZE; blocki+=(H_3D_VSP_BLOCKSIZE-1))
1586          {
1587            if (maxV < depthTmp[iX])
1588              maxV = depthTmp[iX];
1589#if H_3D_VSP_BLOCKSIZE == 2
1590            if (depthPosX + (i<<1) + blocki < widthDepth - 1)
1591#else // H_3D_VSP_BLOCKSIZE == 4
1592            if (depthPosX + (i<<2) + blocki < widthDepth - 1)
1593#endif
1594              iX = (H_3D_VSP_BLOCKSIZE-1);
1595          }
1596#if H_3D_VSP_BLOCKSIZE == 2
1597          if (depthPosY + (j<<1) + blockj < heightDepth - 1)
1598#else // H_3D_VSP_BLOCKSIZE == 4
1599          if (depthPosY + (j<<2) + blockj < heightDepth - 1)
1600#endif
1601            depthTmp += depStride * (H_3D_VSP_BLOCKSIZE-1);
1602        }
1603        m_pDepthBlock[i+j*dW] = maxV;
1604      } // end of i < dW
1605#if H_3D_VSP_BLOCKSIZE == 2
1606      if (depthPosY + ((j+1)<<1) < heightDepth)
1607        depthi += (depStride << 1);
1608      else
1609        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
1610#endif
1611#if H_3D_VSP_BLOCKSIZE == 4
1612      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
1613        depthi += (depStride << 2);
1614      else
1615        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
1616#endif
1617    }
1618  }
1619#endif // H_3D_VSP_BLOCKSIZE != 1
1620
1621#if H_3D_VSP_BLOCKSIZE == 1
1622#if H_3D_VSP_CONSTRAINED
1623  //get LUT based horizontal reference range
1624  Int range = xGetConstrainedSize(sizeX, sizeY);
1625
1626  // The minimum depth value
1627  Int minRelativePos = MAX_INT;
1628  Int maxRelativePos = MIN_INT;
1629
1630  Pel* depthTemp, *depthInitial=depth;
1631  for (Int yTxt = 0; yTxt < sizeY; yTxt++)
1632  {
1633    for (Int xTxt = 0; xTxt < sizeX; xTxt++)
1634    {
1635      if (depthPosX+xTxt < widthDepth)
1636        depthTemp = depthInitial + xTxt;
1637      else
1638        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
1639
1640      Int disparity = pShiftLUT[ *depthTemp ]; // << iShiftPrec;
1641      Int disparityInt = disparity >> 2;
1642
1643      if( disparity <= 0)
1644      {
1645        if (minRelativePos > disparityInt+xTxt)
1646            minRelativePos = disparityInt+xTxt;
1647      }
1648      else
1649      {
1650        if (maxRelativePos < disparityInt+xTxt)
1651            maxRelativePos = disparityInt+xTxt;
1652      }
1653    }
1654    if (depthPosY+yTxt < heightDepth)
1655      depthInitial = depthInitial + depStride;
1656  }
1657
1658  Int disparity_tmp = pShiftLUT[ *depth ]; // << iShiftPrec;
1659  if (disparity_tmp <= 0)
1660    maxRelativePos = minRelativePos + range -1 ;
1661  else
1662    minRelativePos = maxRelativePos - range +1 ;
1663#endif
1664#endif // H_3D_VSP_BLOCKSIZE == 1
1665
1666#if H_3D_VSP_BLOCKSIZE != 1
1667  Int yDepth = 0;
1668#endif
1669  for ( Int yTxt = 0; yTxt < sizeY; yTxt += nTxtPerDepthY )
1670  {
1671    for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth++ )
1672    {
1673      Pel repDepth = 0; // to store the depth value used for warping
1674#if H_3D_VSP_BLOCKSIZE == 1
1675      repDepth = depth[xDepth];
1676#endif
1677#if H_3D_VSP_BLOCKSIZE == 2
1678      repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW];
1679#endif
1680#if H_3D_VSP_BLOCKSIZE == 4
1681      repDepth = m_pDepthBlock[(xTxt>>2) + (yTxt>>2)*dW];
1682#endif
1683
1684      assert( repDepth >= 0 && repDepth <= 255 );
1685      Int disparity = pShiftLUT[ repDepth ]; // remove << iShiftPrec ??
1686      Int refOffset = xTxt + (disparity >> 2);
1687      Int xFrac = disparity & 0x3;
1688#if H_3D_VSP_CONSTRAINED
1689      if(refOffset<minRelativePos || refOffset>maxRelativePos)
1690        xFrac = 0;
1691      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
1692#endif
1693      Int absX  = posX + refOffset;
1694
1695      if (xFrac == 0)
1696        absX = Clip3(0, widthLuma-1, absX);
1697      else
1698        absX = Clip3(4, widthLuma-5, absX);
1699
1700      refOffset = absX - posX;
1701
1702      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
1703      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi );
1704    }
1705    ref   += refStride*nTxtPerDepthY;
1706    dst   += dstStride*nTxtPerDepthY;
1707    depth += depStride;
1708#if H_3D_VSP_BLOCKSIZE != 1
1709    yDepth++;
1710#endif
1711
1712  }
1713}
1714
1715Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv*dv, UInt partAddr, Int posX, Int posY
1716                                               , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi)
1717{
1718  Int refStride = refPic->getCStride();
1719  Int dstStride = dstPic->getCStride();
1720  Int depStride = pPicBaseDepth->getStride();
1721
1722  Int widthChroma, heightChroma;
1723  if( isDepth)
1724  {
1725     widthChroma   = pPicBaseDepth->getWidth()>>1;
1726     heightChroma  = pPicBaseDepth->getHeight()>>1;
1727  }
1728  else
1729  {
1730     widthChroma   = refPic->getWidth()>>1;
1731     heightChroma  = refPic->getHeight()>>1;
1732  }
1733
1734  // Below is only for Texture chroma component
1735
1736  Int widthDepth  = pPicBaseDepth->getWidth();
1737  Int heightDepth = pPicBaseDepth->getHeight();
1738
1739  Int nTxtPerDepthX, nTxtPerDepthY;  // Number of texture samples per one depth sample
1740  Int nDepthPerTxtX, nDepthPerTxtY;  // Number of depth samples per one texture sample
1741
1742  Int depthPosX;  // Starting position in depth image
1743  Int depthPosY;
1744
1745  if ( widthChroma > widthDepth )
1746  {
1747    nTxtPerDepthX = widthChroma / widthDepth;
1748    nDepthPerTxtX = 1;
1749    depthPosX = posX / nTxtPerDepthX + ((dv->getHor()+2)>>2);
1750  }
1751  else
1752  {
1753    nTxtPerDepthX = 1;
1754    nDepthPerTxtX = widthDepth / widthChroma;
1755    depthPosX = posX * nDepthPerTxtX + ((dv->getHor()+2)>>2);
1756  }
1757  depthPosX = Clip3(0, widthDepth - (sizeX<<1), depthPosX);
1758  if ( heightChroma > heightDepth )
1759  {
1760    nTxtPerDepthY = heightChroma / heightDepth;
1761    nDepthPerTxtY = 1;
1762    depthPosY = posY / nTxtPerDepthY + ((dv->getVer()+2)>>2);
1763  }
1764  else
1765  {
1766    nTxtPerDepthY = 1;
1767    nDepthPerTxtY = heightDepth / heightChroma;
1768    depthPosY = posY * nDepthPerTxtY + ((dv->getVer()+2)>>2);
1769  }
1770  depthPosY = Clip3(0, heightDepth - (sizeY<<1), depthPosY);
1771
1772  Pel *refCb  = refPic->getCbAddr() + posX + posY * refStride;
1773  Pel *refCr  = refPic->getCrAddr() + posX + posY * refStride;
1774  Pel *dstCb  = dstPic->getCbAddr(partAddr);
1775  Pel *dstCr  = dstPic->getCrAddr(partAddr);
1776  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;  // move the pointer to the current depth pixel position
1777
1778  Int refStrideBlock = refStride * nTxtPerDepthY;
1779  Int dstStrideBlock = dstStride * nTxtPerDepthY;
1780  Int depStrideBlock = depStride * nDepthPerTxtY;
1781
1782  if ( widthChroma > widthDepth ) // We assume
1783  {
1784    assert( heightChroma > heightDepth );
1785    printf("This branch should never been reached.\n");
1786    exit(0);
1787  }
1788  else
1789  {
1790#if H_3D_VSP_BLOCKSIZE == 1
1791  Int  dW = sizeX;
1792  Int  dH = sizeY;
1793  Int  sW = 2; // search window size
1794  Int  sH = 2;
1795#endif
1796#if H_3D_VSP_BLOCKSIZE == 2
1797  Int  dW = sizeX;
1798  Int  dH = sizeY;
1799  Int  sW = 2; // search window size
1800  Int  sH = 2;
1801#endif
1802#if H_3D_VSP_BLOCKSIZE == 4
1803  Int  dW = sizeX>>1;
1804  Int  dH = sizeY>>1;
1805  Int  sW = 4; // search window size
1806  Int  sH = 4;
1807#endif
1808
1809  {
1810    Pel* depthi = depth;
1811    for (Int j = 0; j < dH; j++)
1812    {
1813      for (Int i = 0; i < dW; i++)
1814      {
1815        Pel* depthTmp;
1816#if H_3D_VSP_BLOCKSIZE == 1
1817        depthTmp = depthi + (i << 1);
1818#endif
1819#if H_3D_VSP_BLOCKSIZE == 2
1820        if (depthPosX + (i<<1) < widthDepth)
1821          depthTmp = depthi + (i << 1);
1822        else
1823          depthTmp = depthi + (widthDepth - depthPosX - 1);
1824#endif
1825#if H_3D_VSP_BLOCKSIZE == 4
1826        if (depthPosX + (i<<2) < widthDepth)
1827          depthTmp = depthi + (i << 2);
1828        else
1829          depthTmp = depthi + (widthDepth - depthPosX - 1);
1830#endif
1831        Int maxV = 0;
1832        for (Int blockj = 0; blockj < sH; blockj+=(sH-1))
1833        {
1834          Int iX = 0;
1835          for (Int blocki = 0; blocki < sW; blocki+=(sW-1))
1836          {
1837            if (maxV < depthTmp[iX])
1838              maxV = depthTmp[iX];
1839            if (depthPosX + i*sW + blocki < widthDepth - 1)
1840                iX = (sW-1);
1841          }
1842          if (depthPosY + j*sH + blockj < heightDepth - 1)
1843                depthTmp += depStride * (sH-1);
1844        }
1845        m_pDepthBlock[i+j*dW] = maxV;
1846      } // end of i < dW
1847#if H_3D_VSP_BLOCKSIZE == 1
1848      if (depthPosY + ((j+1)<<1) < heightDepth)
1849        depthi += (depStride << 1);
1850      else
1851        depthi  = depth + (heightDepth-1)*depStride;
1852#endif
1853#if H_3D_VSP_BLOCKSIZE == 2
1854      if (depthPosY + ((j+1)<<1) < heightDepth)
1855        depthi += (depStride << 1);
1856      else
1857        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
1858#endif
1859#if H_3D_VSP_BLOCKSIZE == 4
1860      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
1861        depthi += (depStride << 2);
1862      else
1863        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
1864#endif
1865    }
1866  }
1867
1868
1869#if H_3D_VSP_BLOCKSIZE == 1
1870#if H_3D_VSP_CONSTRAINED
1871  //get LUT based horizontal reference range
1872  Int range = xGetConstrainedSize(sizeX, sizeY, false);
1873
1874  // The minimum depth value
1875  Int minRelativePos = MAX_INT;
1876  Int maxRelativePos = MIN_INT;
1877
1878  Int depthTmp;
1879  for (Int yTxt=0; yTxt<sizeY; yTxt++)
1880  {
1881    for (Int xTxt=0; xTxt<sizeX; xTxt++)
1882    {
1883      depthTmp = m_pDepthBlock[xTxt+yTxt*dW];
1884      Int disparity = pShiftLUT[ depthTmp ]; // << iShiftPrec;
1885      Int disparityInt = disparity >> 3;//in chroma resolution
1886
1887      if (disparityInt < 0)
1888      {
1889        if (minRelativePos > disparityInt+xTxt)
1890            minRelativePos = disparityInt+xTxt;
1891      }
1892      else
1893      {
1894        if (maxRelativePos < disparityInt+xTxt)
1895            maxRelativePos = disparityInt+xTxt;
1896      }
1897    }
1898  }
1899
1900  depthTmp = m_pDepthBlock[0];
1901  Int disparity_tmp = pShiftLUT[ depthTmp ]; // << iShiftPrec;
1902  if ( disparity_tmp < 0 )
1903    maxRelativePos = minRelativePos + range - 1;
1904  else
1905    minRelativePos = maxRelativePos - range + 1;
1906
1907#endif // H_3D_VSP_CONSTRAINED
1908#endif // H_3D_VSP_BLOCKSIZE == 1
1909
1910    // (sizeX, sizeY) is Chroma block size
1911    for ( Int yTxt = 0, yDepth = 0; yTxt < sizeY; yTxt += nTxtPerDepthY, yDepth += nDepthPerTxtY )
1912    {
1913      for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth += nDepthPerTxtX )
1914      {
1915        Pel repDepth = 0; // to store the depth value used for warping
1916#if H_3D_VSP_BLOCKSIZE == 1
1917        repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW];
1918#endif
1919#if H_3D_VSP_BLOCKSIZE == 2
1920        repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW];
1921#endif
1922#if H_3D_VSP_BLOCKSIZE == 4
1923        repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW];
1924#endif
1925
1926      // calculate the offset in the reference picture
1927        Int disparity = pShiftLUT[ repDepth ]; // Remove << iShiftPrec;
1928        Int refOffset = xTxt + (disparity >> 3); // in integer pixel in chroma image
1929        Int xFrac = disparity & 0x7;
1930#if H_3D_VSP_CONSTRAINED
1931        if(refOffset < minRelativePos || refOffset > maxRelativePos)
1932          xFrac = 0;
1933        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
1934#endif
1935        Int absX  = posX + refOffset;
1936
1937        if (xFrac == 0)
1938          absX = Clip3(0, widthChroma-1, absX);
1939        else
1940          absX = Clip3(4, widthChroma-5, absX);
1941
1942        refOffset = absX - posX;
1943
1944        assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
1945        assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
1946        m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
1947        m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
1948      }
1949      refCb += refStrideBlock;
1950      refCr += refStrideBlock;
1951      dstCb += dstStrideBlock;
1952      dstCr += dstStrideBlock;
1953      depth += depStrideBlock;
1954    }
1955  }
1956
1957}
1958
1959#if H_3D_VSP_CONSTRAINED
1960Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma)
1961{
1962  Int iSize = 0;
1963  if (bLuma)
1964  {
1965    Int iArea = (nPbW+7) * (nPbH+7);
1966    Int iAlpha = iArea / nPbH - nPbW - 7;
1967    iSize = iAlpha + nPbW;
1968  }
1969  else // chroma
1970  {
1971    Int iArea = (nPbW+2) * (nPbH+2);
1972    Int iAlpha = iArea / nPbH - nPbW - 4;
1973    iSize = iAlpha + nPbW;
1974  }
1975  return iSize;
1976}
1977#endif // H_3D_VSP_CONSTRAINED
1978
1979#endif // H_3D_VSP
1980
1981#if H_3D_DIM
1982Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
1983{
1984  Int  refDC1, refDC2;
1985  const Int  iTR = (   patternStride - 1        ) - srcStride;
1986  const Int  iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride;
1987  const Int  iLB = (   patternStride - 1        ) * srcStride - 1;
1988  const Int  iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1;
1989
1990  Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] );
1991  Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)]               );
1992
1993  if( bL == bT )
1994  {
1995    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : 1<<( g_bitDepthY - 1 );
1996    refDC2 =      ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1;
1997  }
1998  else
1999  {
2000    refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR];
2001    refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM];
2002  }
2003
2004  predDC1 = biSegPattern[0] ? refDC1 : refDC2;
2005  predDC2 = biSegPattern[0] ? refDC2 : refDC1;
2006}
2007
2008Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
2009{
2010  if( dstStride == patternStride )
2011  {
2012    for( UInt k = 0; k < (patternStride * patternStride); k++ )
2013    {
2014      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
2015      else                          { ptrDst[k] = valDC1; }
2016    }
2017  }
2018  else
2019  {
2020    Pel* piTemp = ptrDst;
2021    for( UInt uiY = 0; uiY < patternStride; uiY++ )
2022    {
2023      for( UInt uiX = 0; uiX < patternStride; uiX++ )
2024      {
2025        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
2026        else                            { piTemp[uiX] = valDC1; }
2027      }
2028      piTemp       += dstStride;
2029      biSegPattern += patternStride;
2030    }
2031  }
2032}
2033
2034#if H_3D_DIM_DMM
2035UInt TComPrediction::xPredWedgeFromIntra( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd )
2036{
2037  UInt uiThisBlockSize = uiWidth;
2038
2039  TComDataCU* pcTempCU;
2040  UInt        uiTempPartIdx;
2041  // 1st: try continue above wedgelet
2042  pcTempCU = pcCU->getPUAbove( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2043  if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) )
2044  {
2045    UInt dimType =  getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
2046    if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
2047    {
2048      // get offset between current and reference block
2049      UInt uiOffsetX = 0, uiOffsetY = 0;
2050      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
2051
2052      // get reference wedgelet
2053      WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])];
2054      TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) );
2055
2056      // find wedgelet, if direction is suitable for continue wedge
2057      if( pcRefWedgelet->checkPredDirAbovePossible( uiThisBlockSize, uiOffsetX ) )
2058      {
2059        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
2060        pcRefWedgelet->getPredDirStartEndAbove( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetX, iDeltaEnd );
2061        return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
2062      }
2063    }
2064  }
2065
2066  // 2nd: try continue left wedglelet
2067  pcTempCU = pcCU->getPULeft( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2068  if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) )
2069  {
2070    UInt dimType = getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
2071    if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
2072    {
2073      // get offset between current and reference block
2074      UInt uiOffsetX = 0, uiOffsetY = 0;
2075      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
2076
2077      // get reference wedgelet
2078      WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])];
2079      TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) );
2080
2081      // find wedgelet, if direction is suitable for continue wedge
2082      if( pcRefWedgelet->checkPredDirLeftPossible( uiThisBlockSize, uiOffsetY ) )
2083      {
2084        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
2085        pcRefWedgelet->getPredDirStartEndLeft( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetY, iDeltaEnd );
2086        return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
2087      }
2088    }
2089  }
2090
2091  // 3rd: (default) make wedglet from intra dir and max slope point
2092  Int iSlopeX = 0, iSlopeY = 0;
2093  UInt uiStartPosX = 0, uiStartPosY = 0;
2094  if( xGetWedgeIntraDirPredData( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY ) )
2095  {
2096    UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
2097    xGetWedgeIntraDirStartEnd( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, iDeltaEnd );
2098    return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
2099  }
2100
2101  return 0;
2102}
2103
2104UInt TComPrediction::xPredWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx )
2105{
2106  TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
2107  assert( pcPicTex != NULL );
2108  TComDataCU*   pcColTexCU = pcPicTex->getCU(pcCU->getAddr());
2109  UInt          uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
2110  Int           uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
2111
2112  if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 ) { return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx); }
2113  else                                                     { return g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])].at(intraTabIdx).getPatternIdx(); }
2114}
2115
2116Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
2117{
2118  pcContourWedge->clear();
2119
2120  // get copy of co-located texture luma block
2121  TComYuv cTempYuv;
2122  cTempYuv.create( uiWidth, uiHeight ); 
2123  cTempYuv.clear();
2124  Pel* piRefBlkY = cTempYuv.getLumaAddr();
2125  xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
2126  piRefBlkY = cTempYuv.getLumaAddr();
2127
2128  // find contour for texture luma block
2129  UInt iDC = 0;
2130  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2131  { 
2132    iDC += piRefBlkY[k]; 
2133  }
2134  iDC /= (uiWidth*uiHeight);
2135  piRefBlkY = cTempYuv.getLumaAddr();
2136
2137  Bool* pabContourPattern = pcContourWedge->getPattern();
2138  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2139  { 
2140    pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
2141  }
2142
2143  cTempYuv.destroy();
2144}
2145
2146
2147Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
2148{
2149  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
2150  assert( pcPicYuvRef != NULL );
2151  Int         iRefStride = pcPicYuvRef->getStride();
2152  Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2153
2154  for ( Int y = 0; y < uiHeight; y++ )
2155  {
2156    ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
2157    piDestBlockY += uiWidth;
2158    piRefY += iRefStride;
2159  }
2160}
2161
2162Void TComPrediction::xGetBlockOffset( TComDataCU* pcCU, UInt uiAbsPartIdx, TComDataCU* pcRefCU, UInt uiRefAbsPartIdx, UInt& ruiOffsetX, UInt& ruiOffsetY )
2163{
2164  ruiOffsetX = 0;
2165  ruiOffsetY = 0;
2166
2167  // get offset between current and above/left block
2168  UInt uiThisOriginX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
2169  UInt uiThisOriginY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
2170
2171  UInt uiNumPartInRefCU = pcRefCU->getTotalNumPart();
2172  UInt uiMaxDepthRefCU = 0;
2173  while( uiNumPartInRefCU > 1 )
2174  {
2175    uiNumPartInRefCU >>= 2;
2176    uiMaxDepthRefCU++;
2177  }
2178
2179  UInt uiDepthRefPU = (pcRefCU->getDepth(uiRefAbsPartIdx)) + (pcRefCU->getPartitionSize(uiRefAbsPartIdx) == SIZE_2Nx2N ? 0 : 1);
2180  UInt uiShifts = (uiMaxDepthRefCU - uiDepthRefPU)*2;
2181  UInt uiRefBlockOriginPartIdx = (uiRefAbsPartIdx>>uiShifts)<<uiShifts;
2182
2183  UInt uiRefOriginX = pcRefCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ];
2184  UInt uiRefOriginY = pcRefCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ];
2185
2186  if( (uiThisOriginX - uiRefOriginX) > 0 ) { ruiOffsetX = (UInt)(uiThisOriginX - uiRefOriginX); }
2187  if( (uiThisOriginY - uiRefOriginY) > 0 ) { ruiOffsetY = (UInt)(uiThisOriginY - uiRefOriginY); }
2188}
2189
2190Bool TComPrediction::xGetWedgeIntraDirPredData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int& riSlopeX, Int& riSlopeY, UInt& ruiStartPosX, UInt& ruiStartPosY )
2191{
2192  riSlopeX = 0, riSlopeY = 0, ruiStartPosX = 0, ruiStartPosY = 0;
2193
2194  // 1st step: get wedge start point (max. slope)
2195  Int* piSource = pcCU->getPattern()->getAdiOrgBuf( uiBlockSize, uiBlockSize, m_piYuvExt );
2196  Int iSourceStride = ( uiBlockSize<<1 ) + 1;
2197
2198  UInt uiSlopeMaxAbove = 0, uiPosSlopeMaxAbove = 0;
2199  for( UInt uiPosHor = 0; uiPosHor < (uiBlockSize-1); uiPosHor++ )
2200  {
2201    if( abs( piSource[uiPosHor+1] - piSource[uiPosHor] ) > uiSlopeMaxAbove )
2202    {
2203      uiSlopeMaxAbove = abs( piSource[uiPosHor+1] - piSource[uiPosHor] );
2204      uiPosSlopeMaxAbove = uiPosHor;
2205    }
2206  }
2207
2208  UInt uiSlopeMaxLeft = 0, uiPosSlopeMaxLeft = 0;
2209  for( UInt uiPosVer = 0; uiPosVer < (uiBlockSize-1); uiPosVer++ )
2210  {
2211    if( abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] ) > uiSlopeMaxLeft )
2212    {
2213      uiSlopeMaxLeft = abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] );
2214      uiPosSlopeMaxLeft = uiPosVer;
2215    }
2216  }
2217
2218  if( uiSlopeMaxAbove == 0 && uiSlopeMaxLeft == 0 ) 
2219  { 
2220    return false; 
2221  }
2222
2223  ruiStartPosX = ( uiSlopeMaxAbove >  uiSlopeMaxLeft  ) ? uiPosSlopeMaxAbove : 0;
2224  ruiStartPosY = ( uiSlopeMaxLeft  >= uiSlopeMaxAbove ) ? uiPosSlopeMaxLeft  : 0;
2225
2226  // 2nd step: derive wedge direction
2227  Int uiPreds[3] = {-1, -1, -1};
2228  Int iMode = -1;
2229  Int iPredNum = pcCU->getIntraDirLumaPredictor( uiAbsPartIdx, uiPreds, &iMode ); 
2230
2231  UInt uiDirMode = 0;
2232  if( iMode >= 0 ) { iPredNum = iMode; }
2233  if( iPredNum == 1 ) { uiDirMode = uiPreds[0]; }
2234  if( iPredNum == 2 ) { uiDirMode = uiPreds[1]; }
2235
2236  if( uiDirMode < 2 ) { return false; } // no planar & DC
2237
2238  Bool modeHor       = (uiDirMode < 18);
2239  Bool modeVer       = !modeHor;
2240  Int intraPredAngle = modeVer ? (Int)uiDirMode - VER_IDX : modeHor ? -((Int)uiDirMode - HOR_IDX) : 0;
2241  Int absAng         = abs(intraPredAngle);
2242  Int signAng        = intraPredAngle < 0 ? -1 : 1;
2243  Int angTable[9]    = {0,2,5,9,13,17,21,26,32};
2244  absAng             = angTable[absAng];
2245  intraPredAngle     = signAng * absAng;
2246
2247  // 3rd step: set slope for direction
2248  if( modeHor )
2249  {
2250    riSlopeX = ( intraPredAngle > 0 ) ?            -32 :              32;
2251    riSlopeY = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle;
2252  }
2253  else if( modeVer )
2254  {
2255    riSlopeX = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle;
2256    riSlopeY = ( intraPredAngle > 0 ) ?            -32 :              32;
2257  }
2258
2259  return true;
2260}
2261
2262Void 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 )
2263{
2264  ruhXs = 0;
2265  ruhYs = 0;
2266  ruhXe = 0;
2267  ruhYe = 0;
2268
2269  // scaling of start pos and block size to wedge resolution
2270  UInt uiScaledStartPosX = 0;
2271  UInt uiScaledStartPosY = 0;
2272  UInt uiScaledBlockSize = 0;
2273  WedgeResolution eWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiBlockSize]];
2274  switch( eWedgeRes )
2275  {
2276  case( DOUBLE_PEL ): { uiScaledStartPosX = (uiPMSPosX>>1); uiScaledStartPosY = (uiPMSPosY>>1); uiScaledBlockSize = (uiBlockSize>>1); break; }
2277  case(   FULL_PEL ): { uiScaledStartPosX =  uiPMSPosX;     uiScaledStartPosY =  uiPMSPosY;     uiScaledBlockSize =  uiBlockSize;     break; }
2278  case(   HALF_PEL ): { uiScaledStartPosX = (uiPMSPosX<<1); uiScaledStartPosY = (uiPMSPosY<<1); uiScaledBlockSize = (uiBlockSize<<1); break; }
2279  }
2280  Int iMaxPos = (Int)uiScaledBlockSize - 1;
2281
2282  // case above
2283  if( uiScaledStartPosX > 0 && uiScaledStartPosY == 0 )
2284  {
2285    ruhXs = (UChar)uiScaledStartPosX;
2286    ruhYs = 0;
2287
2288    if( iDeltaY == 0 )
2289    {
2290      if( iDeltaX < 0 )
2291      {
2292        ruhXe = 0;
2293        ruhYe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos );
2294        return;
2295      }
2296      else
2297      {
2298        ruhXe = (UChar)iMaxPos;
2299        ruhYe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos );
2300        std::swap( ruhXs, ruhXe );
2301        std::swap( ruhYs, ruhYe );
2302        return;
2303      }
2304    }
2305
2306    // regular case
2307    Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) );
2308
2309    if( iVirtualEndX < 0 )
2310    {
2311      Int iYe = roftoi( (Double)(0 - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) + iDeltaEnd;
2312      if( iYe < (Int)uiScaledBlockSize )
2313      {
2314        ruhXe = 0;
2315        ruhYe = (UChar)std::max( iYe, 0 );
2316        return;
2317      }
2318      else
2319      {
2320        ruhXe = (UChar)std::min( (iYe - iMaxPos), iMaxPos );
2321        ruhYe = (UChar)iMaxPos;
2322        return;
2323      }
2324    }
2325    else if( iVirtualEndX > iMaxPos )
2326    {
2327      Int iYe = roftoi( (Double)(iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd;
2328      if( iYe < (Int)uiScaledBlockSize )
2329      {
2330        ruhXe = (UChar)iMaxPos;
2331        ruhYe = (UChar)std::max( iYe, 0 );
2332        std::swap( ruhXs, ruhXe );
2333        std::swap( ruhYs, ruhYe );
2334        return;
2335      }
2336      else
2337      {
2338        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
2339        ruhYe = (UChar)iMaxPos;
2340        return;
2341      }
2342    }
2343    else
2344    {
2345      Int iXe = iVirtualEndX + iDeltaEnd;
2346      if( iXe < 0 )
2347      {
2348        ruhXe = 0;
2349        ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 );
2350        return;
2351      }
2352      else if( iXe > iMaxPos )
2353      {
2354        ruhXe = (UChar)iMaxPos;
2355        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
2356        std::swap( ruhXs, ruhXe );
2357        std::swap( ruhYs, ruhYe );
2358        return;
2359      }
2360      else
2361      {
2362        ruhXe = (UChar)iXe;
2363        ruhYe = (UChar)iMaxPos;
2364        return;
2365      }
2366    }
2367  }
2368
2369  // case left
2370  if( uiScaledStartPosY > 0 && uiScaledStartPosX == 0 )
2371  {
2372    ruhXs = 0;
2373    ruhYs = (UChar)uiScaledStartPosY;
2374
2375    if( iDeltaX == 0 )
2376    {
2377      if( iDeltaY < 0 )
2378      {
2379        ruhXe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos );
2380        ruhYe = 0;
2381        std::swap( ruhXs, ruhXe );
2382        std::swap( ruhYs, ruhYe );
2383        return;
2384      }
2385      else
2386      {
2387        ruhXe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos );
2388        ruhYe = (UChar)iMaxPos;
2389        return; 
2390      }
2391    }
2392
2393    // regular case
2394    Int iVirtualEndY = (Int)ruhYs + roftoi( (Double)iMaxPos * ((Double)iDeltaY / (Double)iDeltaX) );
2395
2396    if( iVirtualEndY < 0 )
2397    {
2398      Int iXe = roftoi( (Double)(0 - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) - iDeltaEnd;
2399      if( iXe < (Int)uiScaledBlockSize )
2400      {
2401        ruhXe = (UChar)std::max( iXe, 0 );
2402        ruhYe = 0;
2403        std::swap( ruhXs, ruhXe );
2404        std::swap( ruhYs, ruhYe );
2405        return;
2406      }
2407      else
2408      {
2409        ruhXe = (UChar)iMaxPos;
2410        ruhYe = (UChar)std::min( (iXe - iMaxPos), iMaxPos );
2411        std::swap( ruhXs, ruhXe );
2412        std::swap( ruhYs, ruhYe );
2413        return;
2414      }
2415    }
2416    else if( iVirtualEndY > (uiScaledBlockSize-1) )
2417    {
2418      Int iXe = roftoi( (Double)((Int)(uiScaledBlockSize-1) - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) + iDeltaEnd;
2419      if( iXe < (Int)uiScaledBlockSize )
2420      {
2421        ruhXe = (UChar)std::max( iXe, 0 );
2422        ruhYe = (UChar)(uiScaledBlockSize-1);
2423        return;
2424      }
2425      else
2426      {
2427        ruhXe = (UChar)iMaxPos;
2428        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
2429        std::swap( ruhXs, ruhXe );
2430        std::swap( ruhYs, ruhYe );
2431        return;
2432      }
2433    }
2434    else
2435    {
2436      Int iYe = iVirtualEndY - iDeltaEnd;
2437      if( iYe < 0 )
2438      {
2439        ruhXe = (UChar)std::max( (iMaxPos + iYe), 0 );
2440        ruhYe = 0;
2441        std::swap( ruhXs, ruhXe );
2442        std::swap( ruhYs, ruhYe );
2443        return;
2444      }
2445      else if( iYe > iMaxPos )
2446      {
2447        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
2448        ruhYe = (UChar)iMaxPos;
2449        return;
2450      }
2451      else
2452      {
2453        ruhXe = (UChar)iMaxPos;
2454        ruhYe = (UChar)iYe;
2455        std::swap( ruhXs, ruhXe );
2456        std::swap( ruhYs, ruhYe );
2457        return;
2458      }
2459    }
2460  }
2461
2462  // case origin
2463  if( uiScaledStartPosX == 0 && uiScaledStartPosY == 0 )
2464  {
2465    if( iDeltaX*iDeltaY < 0 )
2466    {
2467      return;
2468    }
2469
2470    ruhXs = 0;
2471    ruhYs = 0;
2472
2473    if( iDeltaY == 0 )
2474    {
2475      ruhXe = (UChar)iMaxPos;
2476      ruhYe = 0;
2477      std::swap( ruhXs, ruhXe );
2478      std::swap( ruhYs, ruhYe );
2479      return;
2480    }
2481
2482    if( iDeltaX == 0 )
2483    {
2484      ruhXe = 0;
2485      ruhYe = (UChar)iMaxPos;
2486      return;
2487    }
2488
2489    Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) );
2490
2491    if( iVirtualEndX > iMaxPos )
2492    {
2493      Int iYe = roftoi( (Double)((Int)iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd;
2494      if( iYe < (Int)uiScaledBlockSize )
2495      {
2496        ruhXe = (UChar)(uiScaledBlockSize-1);
2497        ruhYe = (UChar)std::max( iYe, 0 );
2498        std::swap( ruhXs, ruhXe );
2499        std::swap( ruhYs, ruhYe );
2500        return;
2501      }
2502      else
2503      {
2504        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
2505        ruhYe = (UChar)(uiScaledBlockSize-1);
2506        return;
2507      }
2508    }
2509    else
2510    {
2511      Int iXe = iVirtualEndX + iDeltaEnd;
2512      if( iXe < 0 )
2513      {
2514        ruhXe = 0;
2515        ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 );
2516        return;
2517      }
2518      else if( iXe > iMaxPos )
2519      {
2520        ruhXe = (UChar)(uiScaledBlockSize-1);
2521        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
2522        std::swap( ruhXs, ruhXe );
2523        std::swap( ruhYs, ruhYe );
2524        return;
2525      }
2526      else
2527      {
2528        ruhXe = (UChar)iXe;
2529        ruhYe = (UChar)(uiScaledBlockSize-1);
2530        return;
2531      }
2532    }
2533  }
2534}
2535
2536UInt TComPrediction::xGetWedgePatternIdx( UInt uiBlockSize, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe )
2537{
2538  WedgeRefList* pcWedgeRefList = &g_dmmWedgeRefLists[(g_aucConvertToBit[uiBlockSize])];
2539  for( UInt uiIdx = 0; uiIdx < pcWedgeRefList->size(); uiIdx++ )
2540  {
2541    TComWedgeRef* pcTestWedgeRef = &(pcWedgeRefList->at(uiIdx));
2542    if( pcTestWedgeRef->getStartX() == uhXs && pcTestWedgeRef->getStartY() == uhYs && pcTestWedgeRef->getEndX() == uhXe && pcTestWedgeRef->getEndY() == uhYe )
2543    {
2544      return pcTestWedgeRef->getRefIdx();
2545    }
2546  }
2547  return 0;
2548}
2549#endif
2550#if H_3D_DIM_RBC
2551Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Pel& rDeltaDC )
2552{
2553  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
2554  UInt uiAbs  = abs( rDeltaDC );
2555
2556  Int iQp = pcCU->getQP(0);
2557  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
2558  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
2559
2560  rDeltaDC = iSign * roftoi( uiAbs * dStepSize );
2561  return;
2562}
2563
2564Void TComPrediction::xDeltaDCQuantScaleDown( TComDataCU*  pcCU, Pel& rDeltaDC )
2565{
2566  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
2567  UInt uiAbs  = abs( rDeltaDC );
2568
2569  Int iQp = pcCU->getQP(0);
2570  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
2571  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
2572
2573  rDeltaDC = iSign * roftoi( uiAbs / dStepSize );
2574  return;
2575}
2576#endif
2577#if H_3D_DIM_SDC
2578Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride )
2579{
2580  Int iSumDepth[2];
2581  memset(iSumDepth, 0, sizeof(Int)*2);
2582  Int iSumPix[2];
2583  memset(iSumPix, 0, sizeof(Int)*2);
2584 
2585  Int subSamplePix;
2586  if ( uiSize == 64 || uiSize == 32 )
2587  {
2588    subSamplePix = 2;
2589  }
2590  else
2591  {
2592    subSamplePix = 1;
2593  }
2594  for (Int y=0; y<uiSize; y+=subSamplePix)
2595  {
2596    for (Int x=0; x<uiSize; x+=subSamplePix)
2597    {
2598      UChar ucSegment = pMask?(UChar)pMask[x]:0;
2599      assert( ucSegment < uiNumSegments );
2600     
2601      iSumDepth[ucSegment] += pOrig[x];
2602      iSumPix[ucSegment]   += 1;
2603    }
2604   
2605    pOrig  += uiStride*subSamplePix;
2606    pMask  += uiMaskStride*subSamplePix;
2607  }
2608 
2609  // compute mean for each segment
2610  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
2611  {
2612    if( iSumPix[ucSeg] > 0 )
2613      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
2614    else
2615      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
2616  }
2617}
2618#endif // H_3D_DIM_SDC
2619#endif
2620//! \}
Note: See TracBrowser for help on using the repository browser.