source: 3DVCSoftware/branches/HTM-8.2-dev3-Samsung/source/Lib/TLibCommon/TComPrediction.cpp @ 697

Last change on this file since 697 was 697, checked in by samsung-htm, 12 years ago

Integration of F0147: DMM simplification and signalling

  • Property svn:eol-style set to native
File size: 66.9 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  m_cYuvDepthOnVsp.destroy();
66#endif
67
68  delete[] m_piYuvExt;
69
70  m_acYuvPred[0].destroy();
71  m_acYuvPred[1].destroy();
72
73  m_cYuvPredTemp.destroy();
74
75#if H_3D_ARP
76  m_acYuvPredBase[0].destroy();
77  m_acYuvPredBase[1].destroy();
78#endif
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#if H_3D_VSP
124    m_cYuvDepthOnVsp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
125#endif
126  }
127
128  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
129  {
130    m_iLumaRecStride =  (MAX_CU_SIZE>>1) + 1;
131    if (!m_pLumaRecBuffer)
132    {
133      m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ];
134    }
135  }
136#if H_3D_IC
137  m_uiaShift[0] = 0;
138  for( Int i = 1; i < 64; i++ )
139  {
140    m_uiaShift[i] = ( (1 << 15) + i/2 ) / i;
141  }
142#endif
143}
144
145// ====================================================================================================================
146// Public member functions
147// ====================================================================================================================
148
149// Function for calculating DC value of the reference samples used in Intra prediction
150Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft )
151{
152  assert(iWidth > 0 && iHeight > 0);
153  Int iInd, iSum = 0;
154  Pel pDcVal;
155
156  if (bAbove)
157  {
158    for (iInd = 0;iInd < iWidth;iInd++)
159    {
160      iSum += pSrc[iInd-iSrcStride];
161    }
162  }
163  if (bLeft)
164  {
165    for (iInd = 0;iInd < iHeight;iInd++)
166    {
167      iSum += pSrc[iInd*iSrcStride-1];
168    }
169  }
170
171  if (bAbove && bLeft)
172  {
173    pDcVal = (iSum + iWidth) / (iWidth + iHeight);
174  }
175  else if (bAbove)
176  {
177    pDcVal = (iSum + iWidth/2) / iWidth;
178  }
179  else if (bLeft)
180  {
181    pDcVal = (iSum + iHeight/2) / iHeight;
182  }
183  else
184  {
185    pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available
186  }
187 
188  return pDcVal;
189}
190
191// Function for deriving the angular Intra predictions
192
193/** Function for deriving the simplified angular intra predictions.
194 * \param pSrc pointer to reconstructed sample array
195 * \param srcStride the stride of the reconstructed sample array
196 * \param rpDst reference to pointer for the prediction sample array
197 * \param dstStride the stride of the prediction sample array
198 * \param width the width of the block
199 * \param height the height of the block
200 * \param dirMode the intra prediction mode index
201 * \param blkAboveAvailable boolean indication if the block above is available
202 * \param blkLeftAvailable boolean indication if the block to the left is available
203 *
204 * This function derives the prediction samples for the angular mode based on the prediction direction indicated by
205 * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and
206 * the reference row above the block in the case of vertical prediction or displacement of the rightmost column
207 * of the block and reference column left from the block in the case of the horizontal prediction. The displacement
208 * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples,
209 * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken
210 * from the extended main reference.
211 */
212Void TComPrediction::xPredIntraAng(Int bitDepth, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter )
213{
214  Int k,l;
215  Int blkSize        = width;
216  Pel* pDst          = rpDst;
217
218  // Map the mode index to main prediction direction and angle
219  assert( dirMode > 0 ); //no planar
220  Bool modeDC        = dirMode < 2;
221  Bool modeHor       = !modeDC && (dirMode < 18);
222  Bool modeVer       = !modeDC && !modeHor;
223  Int intraPredAngle = modeVer ? (Int)dirMode - VER_IDX : modeHor ? -((Int)dirMode - HOR_IDX) : 0;
224  Int absAng         = abs(intraPredAngle);
225  Int signAng        = intraPredAngle < 0 ? -1 : 1;
226
227  // Set bitshifts and scale the angle parameter to block size
228  Int angTable[9]    = {0,    2,    5,   9,  13,  17,  21,  26,  32};
229  Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
230  Int invAngle       = invAngTable[absAng];
231  absAng             = angTable[absAng];
232  intraPredAngle     = signAng * absAng;
233
234  // Do the DC prediction
235  if (modeDC)
236  {
237    Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable);
238
239    for (k=0;k<blkSize;k++)
240    {
241      for (l=0;l<blkSize;l++)
242      {
243        pDst[k*dstStride+l] = dcval;
244      }
245    }
246  }
247
248  // Do angular predictions
249  else
250  {
251    Pel* refMain;
252    Pel* refSide;
253    Pel  refAbove[2*MAX_CU_SIZE+1];
254    Pel  refLeft[2*MAX_CU_SIZE+1];
255
256    // Initialise the Main and Left reference array.
257    if (intraPredAngle < 0)
258    {
259      for (k=0;k<blkSize+1;k++)
260      {
261        refAbove[k+blkSize-1] = pSrc[k-srcStride-1];
262      }
263      for (k=0;k<blkSize+1;k++)
264      {
265        refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1];
266      }
267      refMain = (modeVer ? refAbove : refLeft) + (blkSize-1);
268      refSide = (modeVer ? refLeft : refAbove) + (blkSize-1);
269
270      // Extend the Main reference to the left.
271      Int invAngleSum    = 128;       // rounding for (shift by 8)
272      for (k=-1; k>blkSize*intraPredAngle>>5; k--)
273      {
274        invAngleSum += invAngle;
275        refMain[k] = refSide[invAngleSum>>8];
276      }
277    }
278    else
279    {
280      for (k=0;k<2*blkSize+1;k++)
281      {
282        refAbove[k] = pSrc[k-srcStride-1];
283      }
284      for (k=0;k<2*blkSize+1;k++)
285      {
286        refLeft[k] = pSrc[(k-1)*srcStride-1];
287      }
288      refMain = modeVer ? refAbove : refLeft;
289      refSide = modeVer ? refLeft  : refAbove;
290    }
291
292    if (intraPredAngle == 0)
293    {
294      for (k=0;k<blkSize;k++)
295      {
296        for (l=0;l<blkSize;l++)
297        {
298          pDst[k*dstStride+l] = refMain[l+1];
299        }
300      }
301
302      if ( bFilter )
303      {
304        for (k=0;k<blkSize;k++)
305        {
306          pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) );
307        }
308      }
309    }
310    else
311    {
312      Int deltaPos=0;
313      Int deltaInt;
314      Int deltaFract;
315      Int refMainIndex;
316
317      for (k=0;k<blkSize;k++)
318      {
319        deltaPos += intraPredAngle;
320        deltaInt   = deltaPos >> 5;
321        deltaFract = deltaPos & (32 - 1);
322
323        if (deltaFract)
324        {
325          // Do linear filtering
326          for (l=0;l<blkSize;l++)
327          {
328            refMainIndex        = l+deltaInt+1;
329            pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 );
330          }
331        }
332        else
333        {
334          // Just copy the integer samples
335          for (l=0;l<blkSize;l++)
336          {
337            pDst[k*dstStride+l] = refMain[l+deltaInt+1];
338          }
339        }
340      }
341    }
342
343    // Flip the block if this is the horizontal mode
344    if (modeHor)
345    {
346      Pel  tmp;
347      for (k=0;k<blkSize-1;k++)
348      {
349        for (l=k+1;l<blkSize;l++)
350        {
351          tmp                 = pDst[k*dstStride+l];
352          pDst[k*dstStride+l] = pDst[l*dstStride+k];
353          pDst[l*dstStride+k] = tmp;
354        }
355      }
356    }
357  }
358}
359
360Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
361{
362  Pel *pDst = piPred;
363  Int *ptrSrc;
364
365  assert( g_aucConvertToBit[ iWidth ] >= 0 ); //   4x  4
366  assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128
367  assert( iWidth == iHeight  );
368
369  ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
370
371  // get starting pixel in block
372  Int sw = 2 * iWidth + 1;
373
374  // Create the prediction
375  if ( uiDirMode == PLANAR_IDX )
376  {
377    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
378  }
379  else
380  {
381    if ( (iWidth > 16) || (iHeight > 16) )
382    {
383      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
384    }
385    else
386    {
387      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );
388
389      if( (uiDirMode == DC_IDX ) && bAbove && bLeft )
390      {
391        xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);
392      }
393    }
394  }
395}
396
397// Angular chroma
398Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
399{
400  Pel *pDst = piPred;
401  Int *ptrSrc = piSrc;
402
403  // get starting pixel in block
404  Int sw = 2 * iWidth + 1;
405
406  if ( uiDirMode == PLANAR_IDX )
407  {
408    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
409  }
410  else
411  {
412    // Create the prediction
413    xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
414  }
415}
416
417#if H_3D_DIM
418Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc )
419{
420  assert( iWidth == iHeight  );
421  assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE );
422  assert( isDimMode( uiIntraMode ) );
423
424  UInt dimType    = getDimType  ( uiIntraMode );
425  Bool dimDeltaDC = isDimDeltaDC( uiIntraMode );   
426  Bool isDmmMode  = (dimType <  DMM_NUM_TYPE);
427#if !SEC_DMM3_RBC_F0147
428  Bool isRbcMode  = (dimType == RBC_IDX);
429#endif
430
431  Bool* biSegPattern  = NULL;
432  UInt  patternStride = 0;
433
434  // get partiton
435#if H_3D_DIM_DMM
436  TComWedgelet* dmmSegmentation = NULL;
437  if( isDmmMode )
438  {
439    switch( dimType )
440    {
441    case( DMM1_IDX ): 
442      {
443        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]);
444      } break;
445#if !SEC_DMM3_RBC_F0147
446    case( DMM3_IDX ): 
447      {
448        UInt uiTabIdx = 0;
449        if( bFastEnc ) { uiTabIdx = pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ); }
450        else
451        {
452          uiTabIdx = xPredWedgeFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, pcCU->getDmm3IntraTabIdx( uiAbsPartIdx ) );
453          pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, uiAbsPartIdx, (pcCU->getDepth(0) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1)) );
454        }
455        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ uiTabIdx ]);
456      } break;
457#endif
458    case( DMM4_IDX ): 
459      {
460        dmmSegmentation = new TComWedgelet( iWidth, iHeight );
461        xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
462      } break;
463    default: assert(0);
464    }
465    assert( dmmSegmentation );
466    biSegPattern  = dmmSegmentation->getPattern();
467    patternStride = dmmSegmentation->getStride ();
468  }
469#endif
470#if H_3D_DIM_RBC
471  if( isRbcMode )
472  {
473    biSegPattern  = pcCU->getEdgePartition( uiAbsPartIdx );
474    patternStride = iWidth;
475  }
476#endif
477
478  // get predicted partition values
479  assert( biSegPattern );
480  Int* piMask = NULL;
481#if QC_DIM_DELTADC_UNIFY_F0132 || HHI_DIM_PREDSAMP_FIX_F0171
482  piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering
483#else
484  if( isDmmMode ) piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering for DMM
485  else            piMask = pcCU->getPattern()->getPredictorPtr( 0, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
486#endif
487  assert( piMask );
488  Int maskStride = 2*iWidth + 1; 
489  Int* ptrSrc = piMask+maskStride+1;
490  Pel predDC1 = 0; Pel predDC2 = 0;
491  xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 );
492
493  // set segment values with deltaDC offsets
494  Pel segDC1 = 0;
495  Pel segDC2 = 0;
496  if( dimDeltaDC )
497  {
498    Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx );
499    Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx );
500#if H_3D_DIM_DMM
501#if QC_DIM_DELTADC_UNIFY_F0132 && !SEC_DMM3_RBC_F0147
502    if( isDmmMode || isRbcMode)
503#else
504    if( isDmmMode )
505#endif
506    {
507#if H_3D_DIM_DLT
508      segDC1 = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 );
509      segDC2 = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 );
510#else
511      segDC1 = ClipY( predDC1 + deltaDC1 );
512      segDC2 = ClipY( predDC2 + deltaDC2 );
513#endif
514    }
515#endif
516#if H_3D_DIM_RBC && !QC_DIM_DELTADC_UNIFY_F0132
517    if( isRbcMode )
518    {
519      xDeltaDCQuantScaleUp( pcCU, deltaDC1 );
520      xDeltaDCQuantScaleUp( pcCU, deltaDC2 );
521      segDC1 = ClipY( predDC1 + deltaDC1 );
522      segDC2 = ClipY( predDC2 + deltaDC2 );
523    }
524#endif
525  }
526  else
527  {
528    segDC1 = predDC1;
529    segDC2 = predDC2;
530  }
531
532  // set prediction signal
533  Pel* pDst = piPred;
534  xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 );
535
536#if H_3D_DIM_DMM
537  if( dimType == DMM4_IDX ) { dmmSegmentation->destroy(); delete dmmSegmentation; }
538#endif
539}
540#endif
541
542/** Function for checking identical motion.
543 * \param TComDataCU* pcCU
544 * \param UInt PartAddr
545 */
546Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr )
547{
548  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() )
549  {
550    if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0)
551    {
552      Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
553      Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
554      if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
555      {
556        return true;
557      }
558    }
559  }
560  return false;
561}
562
563
564Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
565{
566  Int         iWidth;
567  Int         iHeight;
568  UInt        uiPartAddr;
569
570  if ( iPartIdx >= 0 )
571  {
572    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
573#if H_3D_VSP
574    if ( pcCU->getVSPFlag(uiPartAddr) == 0)
575    {
576#endif
577      if ( eRefPicList != REF_PIC_LIST_X )
578      {
579        if( pcCU->getSlice()->getPPS()->getUseWP())
580        {
581          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
582        }
583        else
584        {
585          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
586        }
587        if ( pcCU->getSlice()->getPPS()->getUseWP() )
588        {
589          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
590        }
591      }
592      else
593      {
594        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
595        {
596          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
597        }
598        else
599        {
600          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
601        }
602      }
603#if H_3D_VSP
604    }
605    else
606    {
607      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
608      {
609        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
610      }
611      else
612      {
613        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
614      }
615    }
616#endif
617    return;
618  }
619
620  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
621  {
622    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
623
624#if H_3D_VSP
625    if ( pcCU->getVSPFlag(uiPartAddr) == 0 )
626    {
627#endif
628      if ( eRefPicList != REF_PIC_LIST_X )
629      {
630        if( pcCU->getSlice()->getPPS()->getUseWP())
631        {
632          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
633        }
634        else
635        {
636          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
637        }
638        if ( pcCU->getSlice()->getPPS()->getUseWP() )
639        {
640          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
641        }
642      }
643      else
644      {
645        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
646        {
647          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
648        }
649        else
650        {
651          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
652        }
653      }
654#if H_3D_VSP
655    }
656    else
657    {
658      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
659      {
660        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
661      }
662      else
663      {
664        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
665      }
666    }
667#endif
668  }
669  return;
670}
671
672Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
673{
674  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
675  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
676  pcCU->clipMv(cMv);
677#if H_3D_ARP
678  if(  pcCU->getARPW( uiPartAddr ) > 0 
679    && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N
680    && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() 
681    )
682  {
683    xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi );
684  }
685  else
686  {
687#endif
688#if H_3D_IC
689    Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() );
690    xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
691#if H_3D_ARP
692      , false
693#endif
694      , bICFlag );
695    bICFlag = bICFlag && (iWidth > 8);
696    xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
697#if H_3D_ARP
698      , false
699#endif
700      , bICFlag );
701#else
702  xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
703  xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
704#endif
705#if H_3D_ARP
706  }
707#endif
708}
709
710#if H_3D_VSP
711Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
712{
713  // Get depth reference
714  Int       depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
715#if H_3D_FCO_VSP_DONBDV_E0163
716  TComPic* pRefPicBaseDepth = 0;
717  Bool     bIsCurrDepthCoded = false;
718  pRefPicBaseDepth  = pcCU->getSlice()->getIvPic( true, pcCU->getSlice()->getViewIndex() );
719  if ( pRefPicBaseDepth->getPicYuvRec() != NULL  ) 
720  {
721    bIsCurrDepthCoded = true;
722  }
723  else 
724  {
725    pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
726  }
727#else
728  TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
729#endif
730  assert(pRefPicBaseDepth != NULL);
731  TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
732  assert(pcBaseViewDepthPicYuv != NULL);
733
734  // Get texture reference
735  Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
736  assert(iRefIdx >= 0);
737  TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx );
738  TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
739  assert(pcBaseViewTxtPicYuv != NULL);
740
741  // Initialize LUT according to the reference viewIdx
742  Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex();
743  Int* pShiftLUT    = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx );
744  assert( txtRefViewIdx < pcCU->getSlice()->getViewIndex() );
745
746  // Do compensation
747  TComMv cDv  = pcCU->getDvInfo(uiPartAddr).m_acNBDV;
748  pcCU->clipMv(cDv);
749
750#if H_3D_FCO_VSP_DONBDV_E0163
751  if ( bIsCurrDepthCoded )
752  {
753      cDv.setZero();
754  }
755#endif
756  // fetch virtual depth map
757  pcBaseViewDepthPicYuv->extendPicBorder();
758  xGetVirtualDepth( pcCU, pcBaseViewDepthPicYuv, &cDv, uiPartAddr, iWidth, iHeight, &m_cYuvDepthOnVsp );
759  // sub-PU based compensation
760  xPredInterLumaBlkFromDM   ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
761  xPredInterChromaBlkFromDM ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
762}
763#endif
764
765#if H_3D_ARP
766Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
767{
768  Int         iRefIdx      = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
769  TComMv      cMv          = pNewMvFiled ? pNewMvFiled->getMv()     : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
770  Bool        bTobeScaled  = false;
771  TComPic* pcPicYuvBaseCol = NULL;
772  TComPic* pcPicYuvBaseRef = NULL;
773
774#if H_3D_NBDV
775  DisInfo cDistparity;
776  cDistparity.bDV           = pcCU->getDvInfo(uiPartAddr).bDV;
777  if( cDistparity.bDV )
778  {
779    cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV;
780    assert(pcCU->getDvInfo(uiPartAddr).bDV ==  pcCU->getDvInfo(0).bDV);
781    cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
782  }
783#else
784  assert(0); // ARP can be applied only when a DV is available
785#endif
786
787  UChar dW = cDistparity.bDV ? pcCU->getARPW ( uiPartAddr ) : 0;
788
789  if( cDistparity.bDV ) 
790  {
791    if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC()!= pcCU->getSlice()->getPOC() )
792    {
793      bTobeScaled = true;
794    }
795
796    pcPicYuvBaseCol =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(),                              cDistparity.m_aVIdxCan );
797    pcPicYuvBaseRef =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC(), cDistparity.m_aVIdxCan );
798   
799    if( ( !pcPicYuvBaseCol || pcPicYuvBaseCol->getPOC() != pcCU->getSlice()->getPOC() ) || ( !pcPicYuvBaseRef || pcPicYuvBaseRef->getPOC() != pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() ) )
800    {
801      dW = 0;
802      bTobeScaled = false;
803    }
804    else
805    {
806      assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() );
807    }
808
809    if(bTobeScaled)
810    {     
811      Int iCurrPOC    = pcCU->getSlice()->getPOC();
812      Int iColRefPOC  = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx );
813      Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList,  0);
814      Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC);
815      if ( iScale != 4096 )
816      {
817        cMv = cMv.scaleMv( iScale );
818      }
819      iRefIdx = 0;
820    }
821  }
822
823  pcCU->clipMv(cMv);
824  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec();
825  xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
826  xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
827
828  if( dW > 0 )
829  {
830    TComYuv * pYuvB0 = &m_acYuvPredBase[0];
831    TComYuv * pYuvB1  = &m_acYuvPredBase[1];
832
833    TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV;
834    pcCU->clipMv(cMVwithDisparity);
835
836    assert ( cDistparity.bDV );
837
838    pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec();
839    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
840    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
841   
842    pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec();
843    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
844    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
845
846    pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight );
847
848    if( 2 == dW )
849    {
850      pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
851    }
852    rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi );
853  }
854}
855#endif
856
857Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
858{
859  TComYuv* pcMbYuv;
860  Int      iRefIdx[2] = {-1, -1};
861
862  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
863  {
864    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
865    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
866
867    if ( iRefIdx[iRefList] < 0 )
868    {
869      continue;
870    }
871
872    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
873
874    pcMbYuv = &m_acYuvPred[iRefList];
875    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
876    {
877      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
878    }
879    else
880    {
881      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) || 
882           ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
883      {
884        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
885      }
886      else
887      {
888        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
889      }
890    }
891  }
892
893  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE  )
894  {
895    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
896  } 
897  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
898  {
899    xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); 
900  }
901  else
902  {
903    xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
904  }
905}
906
907#if H_3D_VSP
908
909Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
910{
911  TComYuv* pcMbYuv;
912  Int      iRefIdx[2] = {-1, -1};
913  Bool     bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0);
914
915  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
916  {
917    RefPicList eRefPicList = RefPicList(iRefList);
918    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
919
920    if ( iRefIdx[iRefList] < 0 )
921    {
922      continue;
923    }
924    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
925
926    pcMbYuv = &m_acYuvPred[iRefList];
927    xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi );
928  }
929
930  xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
931}
932
933#endif
934
935/**
936 * \brief Generate motion-compensated luma block
937 *
938 * \param cu       Pointer to current CU
939 * \param refPic   Pointer to reference picture
940 * \param partAddr Address of block within CU
941 * \param mv       Motion vector
942 * \param width    Width of block
943 * \param height   Height of block
944 * \param dstPic   Pointer to destination picture
945 * \param bi       Flag indicating whether bipred is used
946 */
947Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
948#if H_3D_ARP
949    , Bool filterType
950#endif
951#if H_3D_IC
952    , Bool bICFlag
953#endif
954  )
955{
956  Int refStride = refPic->getStride(); 
957  Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride;
958  Pel *ref      = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
959 
960  Int dstStride = dstPic->getStride();
961  Pel *dst      = dstPic->getLumaAddr( partAddr );
962 
963  Int xFrac = mv->getHor() & 0x3;
964  Int yFrac = mv->getVer() & 0x3;
965
966#if H_3D_IC
967  if( cu->getSlice()->getIsDepth() )
968  {
969    refOffset = mv->getHor() + mv->getVer() * refStride;
970    ref       = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
971    xFrac     = 0;
972    yFrac     = 0;
973  }
974#endif
975  if ( yFrac == 0 )
976  {
977#if H_3D_IC
978    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi || bICFlag
979#else
980    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi
981#endif
982#if H_3D_ARP
983    , filterType
984#endif
985      );
986  }
987  else if ( xFrac == 0 )
988  {
989#if H_3D_IC
990    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag
991#else
992    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi
993#endif
994#if H_3D_ARP
995    , filterType
996#endif
997      );
998  }
999  else
1000  {
1001    Int tmpStride = m_filteredBlockTmp[0].getStride();
1002    Short *tmp    = m_filteredBlockTmp[0].getLumaAddr();
1003
1004    Int filterSize = NTAPS_LUMA;
1005    Int halfFilterSize = ( filterSize >> 1 );
1006
1007    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     
1008#if H_3D_ARP
1009    , filterType
1010#endif
1011      );
1012#if H_3D_IC
1013    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi || bICFlag
1014#else
1015    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi
1016#endif
1017#if H_3D_ARP
1018    , filterType
1019#endif
1020      );   
1021  }
1022
1023#if H_3D_IC
1024  if( bICFlag )
1025  {
1026    Int a, b, i, j;
1027    const Int iShift = IC_CONST_SHIFT;
1028
1029    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA );
1030
1031
1032    for ( i = 0; i < height; i++ )
1033    {
1034      for ( j = 0; j < width; j++ )
1035      {
1036          dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
1037      }
1038      dst += dstStride;
1039    }
1040
1041    if(bi)
1042    {
1043      Pel *dst2      = dstPic->getLumaAddr( partAddr );
1044      Int shift = IF_INTERNAL_PREC - g_bitDepthY;
1045      for (i = 0; i < height; i++)
1046      {
1047        for (j = 0; j < width; j++)
1048        {
1049          Short val = dst2[j] << shift;
1050          dst2[j] = val - (Short)IF_INTERNAL_OFFS;
1051        }
1052        dst2 += dstStride;
1053      }
1054    }
1055  }
1056#endif
1057}
1058
1059/**
1060 * \brief Generate motion-compensated chroma block
1061 *
1062 * \param cu       Pointer to current CU
1063 * \param refPic   Pointer to reference picture
1064 * \param partAddr Address of block within CU
1065 * \param mv       Motion vector
1066 * \param width    Width of block
1067 * \param height   Height of block
1068 * \param dstPic   Pointer to destination picture
1069 * \param bi       Flag indicating whether bipred is used
1070 */
1071Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
1072#if H_3D_ARP
1073    , Bool filterType
1074#endif
1075#if H_3D_IC
1076    , Bool bICFlag
1077#endif
1078  )
1079{
1080  Int     refStride  = refPic->getCStride();
1081  Int     dstStride  = dstPic->getCStride();
1082 
1083  Int     refOffset  = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride;
1084 
1085  Pel*    refCb     = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1086  Pel*    refCr     = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1087 
1088  Pel* dstCb = dstPic->getCbAddr( partAddr );
1089  Pel* dstCr = dstPic->getCrAddr( partAddr );
1090 
1091  Int     xFrac  = mv->getHor() & 0x7;
1092  Int     yFrac  = mv->getVer() & 0x7;
1093  UInt    cxWidth  = width  >> 1;
1094  UInt    cxHeight = height >> 1;
1095 
1096  Int     extStride = m_filteredBlockTmp[0].getStride();
1097  Short*  extY      = m_filteredBlockTmp[0].getLumaAddr();
1098 
1099  Int filterSize = NTAPS_CHROMA;
1100 
1101  Int halfFilterSize = (filterSize>>1);
1102 
1103  if ( yFrac == 0 )
1104  {
1105#if H_3D_IC
1106    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
1107#else
1108    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi
1109#endif
1110#if H_3D_ARP
1111    , filterType
1112#endif
1113    );   
1114#if H_3D_IC
1115    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
1116#else
1117    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi
1118#endif
1119#if H_3D_ARP
1120    , filterType
1121#endif
1122    );
1123  }
1124  else if ( xFrac == 0 )
1125  {
1126#if H_3D_IC
1127    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
1128#else
1129    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1130#endif
1131#if H_3D_ARP
1132    , filterType
1133#endif
1134    );
1135#if H_3D_IC
1136    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
1137#else
1138    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1139#endif
1140#if H_3D_ARP
1141    , filterType
1142#endif
1143    );
1144  }
1145  else
1146  {
1147    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1148#if H_3D_ARP
1149    , filterType
1150#endif 
1151      );
1152#if H_3D_IC
1153    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
1154#else
1155    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1156#endif
1157#if H_3D_ARP
1158    , filterType
1159#endif
1160      );
1161   
1162    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1163#if H_3D_ARP
1164    , filterType
1165#endif
1166      );
1167#if H_3D_IC
1168    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
1169#else
1170    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1171#endif
1172#if H_3D_ARP
1173    , filterType
1174#endif
1175      );   
1176  }
1177
1178#if H_3D_IC
1179  if( bICFlag )
1180  {
1181    Int a, b, i, j;
1182    const Int iShift = IC_CONST_SHIFT;
1183    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb
1184    for ( i = 0; i < cxHeight; i++ )
1185    {
1186      for ( j = 0; j < cxWidth; j++ )
1187      {
1188          dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
1189      }
1190      dstCb += dstStride;
1191    }
1192    xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr
1193    for ( i = 0; i < cxHeight; i++ )
1194    {
1195      for ( j = 0; j < cxWidth; j++ )
1196      {
1197          dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
1198      }
1199      dstCr += dstStride;
1200    }
1201
1202    if(bi)
1203    {
1204      Pel* dstCb2 = dstPic->getCbAddr( partAddr );
1205      Pel* dstCr2 = dstPic->getCrAddr( partAddr );
1206      Int shift = IF_INTERNAL_PREC - g_bitDepthC;
1207      for (i = 0; i < cxHeight; i++)
1208      {
1209        for (j = 0; j < cxWidth; j++)
1210        {
1211          Short val = dstCb2[j] << shift;
1212          dstCb2[j] = val - (Short)IF_INTERNAL_OFFS;
1213
1214          val = dstCr2[j] << shift;
1215          dstCr2[j] = val - (Short)IF_INTERNAL_OFFS;
1216        }
1217        dstCb2 += dstStride;
1218        dstCr2 += dstStride;
1219      }
1220    }
1221  }
1222#endif
1223}
1224
1225Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
1226{
1227  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
1228  {
1229    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
1230  }
1231  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
1232  {
1233    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
1234  }
1235  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
1236  {
1237    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
1238  }
1239}
1240
1241// AMVP
1242Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
1243{
1244  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
1245  if( pcAMVPInfo->iN <= 1 )
1246  {
1247    rcMvPred = pcAMVPInfo->m_acMvCand[0];
1248
1249    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1250    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1251    return;
1252  }
1253
1254  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
1255  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
1256  return;
1257}
1258
1259/** Function for deriving planar intra prediction.
1260 * \param pSrc pointer to reconstructed sample array
1261 * \param srcStride the stride of the reconstructed sample array
1262 * \param rpDst reference to pointer for the prediction sample array
1263 * \param dstStride the stride of the prediction sample array
1264 * \param width the width of the block
1265 * \param height the height of the block
1266 *
1267 * This function derives the prediction samples for planar mode (intra coding).
1268 */
1269Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
1270{
1271  assert(width == height);
1272
1273  Int k, l, bottomLeft, topRight;
1274  Int horPred;
1275  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
1276  UInt blkSize = width;
1277  UInt offset2D = width;
1278  UInt shift1D = g_aucConvertToBit[ width ] + 2;
1279  UInt shift2D = shift1D + 1;
1280
1281  // Get left and above reference column and row
1282  for(k=0;k<blkSize+1;k++)
1283  {
1284    topRow[k] = pSrc[k-srcStride];
1285    leftColumn[k] = pSrc[k*srcStride-1];
1286  }
1287
1288  // Prepare intermediate variables used in interpolation
1289  bottomLeft = leftColumn[blkSize];
1290  topRight   = topRow[blkSize];
1291  for (k=0;k<blkSize;k++)
1292  {
1293    bottomRow[k]   = bottomLeft - topRow[k];
1294    rightColumn[k] = topRight   - leftColumn[k];
1295    topRow[k]      <<= shift1D;
1296    leftColumn[k]  <<= shift1D;
1297  }
1298
1299  // Generate prediction signal
1300  for (k=0;k<blkSize;k++)
1301  {
1302    horPred = leftColumn[k] + offset2D;
1303    for (l=0;l<blkSize;l++)
1304    {
1305      horPred += rightColumn[k];
1306      topRow[l] += bottomRow[l];
1307      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
1308    }
1309  }
1310}
1311
1312/** Function for filtering intra DC predictor.
1313 * \param pSrc pointer to reconstructed sample array
1314 * \param iSrcStride the stride of the reconstructed sample array
1315 * \param rpDst reference to pointer for the prediction sample array
1316 * \param iDstStride the stride of the prediction sample array
1317 * \param iWidth the width of the block
1318 * \param iHeight the height of the block
1319 *
1320 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
1321 */
1322Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
1323{
1324  Pel* pDst = rpDst;
1325  Int x, y, iDstStride2, iSrcStride2;
1326
1327  // boundary pixels processing
1328  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
1329
1330  for ( x = 1; x < iWidth; x++ )
1331  {
1332    pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
1333  }
1334
1335  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
1336  {
1337    pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
1338  }
1339
1340  return;
1341}
1342#if H_3D_IC
1343/** Function for deriving the position of first non-zero binary bit of a value
1344 * \param x input value
1345 *
1346 * This function derives the position of first non-zero binary bit of a value
1347 */
1348Int GetMSB( UInt x )
1349{
1350  Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1;
1351
1352  while( x > 1 )
1353  {
1354    bits >>= 1;
1355    y = x >> bits;
1356
1357    if( y )
1358    {
1359      x = y;
1360      iMSB += bits;
1361    }
1362  }
1363
1364  iMSB+=y;
1365
1366  return iMSB;
1367}
1368
1369
1370/** Function for deriving LM illumination compensation.
1371 */
1372Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType )
1373{
1374  TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
1375  Pel *pRec = NULL, *pRef = NULL;
1376  UInt uiWidth, uiHeight, uiTmpPartIdx;
1377  Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride();
1378  Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride();
1379  Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer;
1380
1381  iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
1382  iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
1383  iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 );
1384  iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 );
1385  iRefX   = iCUPelX + iHor;
1386  iRefY   = iCUPelY + iVer;
1387  if( eType != TEXT_LUMA )
1388  {
1389    iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 );
1390    iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 );
1391  }
1392  uiWidth  = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 )  : ( pcCU->getWidth( 0 )  >> 1 );
1393  uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 );
1394
1395  Int i, j, iCountShift = 0;
1396
1397  // LLS parameters estimation -->
1398
1399  Int x = 0, y = 0, xx = 0, xy = 0;
1400  Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12);
1401
1402  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 )
1403  {
1404    iRefOffset = iHor + iVer * iRefStride - iRefStride;
1405    if( eType == TEXT_LUMA )
1406    {
1407      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1408      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
1409    }
1410    else if( eType == TEXT_CHROMA_U )
1411    {
1412      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1413      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
1414    }
1415    else
1416    {
1417      assert( eType == TEXT_CHROMA_V );
1418      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1419      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
1420    }
1421
1422    for( j = 0; j < uiWidth; j+=2 )
1423    {
1424      x += pRef[j];
1425      y += pRec[j];
1426      xx += (pRef[j] * pRef[j])>>precShift;
1427      xy += (pRef[j] * pRec[j])>>precShift;
1428    }
1429    iCountShift += g_aucConvertToBit[ uiWidth ] + 1;
1430  }
1431
1432
1433  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 )
1434  {
1435    iRefOffset = iHor + iVer * iRefStride - 1;
1436    if( eType == TEXT_LUMA )
1437    {
1438      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1439      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1440    }
1441    else if( eType == TEXT_CHROMA_U )
1442    {
1443      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1444      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1445    }
1446    else
1447    {
1448      assert( eType == TEXT_CHROMA_V );
1449      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1450      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1451    }
1452
1453    for( i = 0; i < uiHeight; i+=2 )
1454    {
1455      x += pRef[0];
1456      y += pRec[0];
1457
1458      xx += (pRef[0] * pRef[0])>>precShift;
1459      xy += (pRef[0] * pRec[0])>>precShift;
1460
1461      pRef += iRefStride*2;
1462      pRec += iRecStride*2;
1463    }
1464    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 );
1465  }
1466
1467  xy += xx >> IC_REG_COST_SHIFT;
1468  xx += xx >> IC_REG_COST_SHIFT;
1469  Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift);
1470  Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift);
1471  const Int iShift = IC_CONST_SHIFT;
1472  {
1473    {
1474      const Int iShiftA2 = 6;
1475      const Int iAccuracyShift = 15;
1476
1477      Int iScaleShiftA2 = 0;
1478      Int iScaleShiftA1 = 0;
1479      Int a1s = a1;
1480      Int a2s = a2;
1481
1482      a1 = Clip3(0, 2*a2, a1);
1483      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2;
1484      iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF;
1485
1486      if( iScaleShiftA1 < 0 )
1487      {
1488        iScaleShiftA1 = 0;
1489      }
1490
1491      if( iScaleShiftA2 < 0 )
1492      {
1493        iScaleShiftA2 = 0;
1494      }
1495
1496      Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
1497
1498
1499      a2s = a2 >> iScaleShiftA2;
1500
1501      a1s = a1 >> iScaleShiftA1;
1502
1503      a = a1s * m_uiaShift[ a2s ];
1504      a = a >> iScaleShiftA;
1505      b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
1506    }
1507  }   
1508}
1509#endif
1510
1511#if H_3D_VSP
1512// not fully support iRatioTxtPerDepth* != 1
1513Void TComPrediction::xGetVirtualDepth( TComDataCU *cu, TComPicYuv *picRefDepth, TComMv *mv, UInt partAddr, Int width, Int height, TComYuv *yuvDepth, Int ratioTxtPerDepthX, Int ratioTxtPerDepthY )
1514{
1515  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
1516  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
1517
1518  Int refDepStride = picRefDepth->getStride();
1519
1520  Int refDepOffset  = ( (mv->getHor()+2) >> 2 ) + ( (mv->getVer()+2) >> 2 ) * refDepStride;
1521  Pel *refDepth     = picRefDepth->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
1522
1523  if( ratioTxtPerDepthX!=1 || ratioTxtPerDepthY!=1 )
1524  {
1525    Int posX, posY;
1526    refDepth    = picRefDepth->getLumaAddr( );
1527    cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture
1528    posX /= ratioTxtPerDepthX; // texture position -> depth postion
1529    posY /= ratioTxtPerDepthY;
1530    refDepOffset += posX + posY * refDepStride;
1531
1532    width  /= ratioTxtPerDepthX; // texture size -> depth size
1533    height /= ratioTxtPerDepthY;
1534  }
1535
1536  refDepth += refDepOffset;
1537
1538  Int depStride = yuvDepth->getStride();
1539  Pel *depth = yuvDepth->getLumaAddr();
1540
1541  if( width<8 || height<8 )
1542  { // no split
1543    Int rightOffset = width - 1;
1544    Int depStrideBlock = depStride * nTxtPerDepthY;
1545    Pel *refDepthTop = refDepth;
1546    Pel *refDepthBot = refDepthTop + (height-1)*refDepStride;
1547
1548    Pel maxDepth = refDepthTop[0] > refDepthBot[0] ? refDepthTop[0] : refDepthBot[0];
1549    if( maxDepth < refDepthTop[rightOffset] ) { maxDepth = refDepthTop[rightOffset]; }
1550    if( maxDepth < refDepthBot[rightOffset] ) { maxDepth = refDepthBot[rightOffset]; }
1551
1552    for( Int sY=0; sY<height; sY+=nTxtPerDepthY )
1553    {
1554      for( Int sX=0; sX<width; sX+=nTxtPerDepthX )
1555      {
1556        depth[sX] = maxDepth;
1557      }
1558      depth += depStrideBlock;
1559    }
1560  }
1561  else
1562  { // split to 4x8, or 8x4
1563    Int blocksize    = 8;
1564    Int subblocksize = 4;
1565    Int depStrideBlock = depStride * blocksize;
1566    Pel *depthTmp = NULL;
1567    Int depStrideTmp = depStride * nTxtPerDepthY;
1568    Int offset[4] = { 0, subblocksize-1, subblocksize, blocksize-1 };
1569    Pel *refDepthTmp[4] = { NULL, NULL, NULL, NULL };
1570    Pel repDepth4x8[2] = {0, 0};
1571    Pel repDepth8x4[2] = {0, 0};
1572
1573    Int refDepStrideBlock    = refDepStride * blocksize;
1574    Int refDepStrideSubBlock = refDepStride * subblocksize;
1575
1576    refDepthTmp[0] = refDepth;
1577    refDepthTmp[2] = refDepthTmp[0] + refDepStrideSubBlock;
1578    refDepthTmp[1] = refDepthTmp[2] - refDepStride;
1579    refDepthTmp[3] = refDepthTmp[1] + refDepStrideSubBlock;
1580
1581    for( Int y=0; y<height; y+=blocksize )
1582    {
1583      for( Int x=0; x<width; x+=blocksize )
1584      {
1585        Bool ULvsBR = false, URvsBL = false;
1586
1587        ULvsBR = refDepthTmp[0][x+offset[0]] < refDepthTmp[3][x+offset[3]];
1588        URvsBL = refDepthTmp[0][x+offset[3]] < refDepthTmp[3][x+offset[0]];
1589
1590        if( ULvsBR ^ URvsBL )
1591        { // 4x8
1592          repDepth4x8[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[1]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[1]];
1593          if( repDepth4x8[0] < refDepthTmp[3][x+offset[0]] )
1594          {
1595            repDepth4x8[0] = refDepthTmp[3][x+offset[0]];
1596          }
1597          if( repDepth4x8[0] < refDepthTmp[3][x+offset[1]] )
1598          {
1599            repDepth4x8[0] = refDepthTmp[3][x+offset[1]];
1600          }
1601          repDepth4x8[1] = refDepthTmp[0][x+offset[2]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[2]] : refDepthTmp[0][x+offset[3]];
1602          if( repDepth4x8[1] < refDepthTmp[3][x+offset[2]] )
1603          {
1604            repDepth4x8[1] = refDepthTmp[3][x+offset[2]];
1605          }
1606          if( repDepth4x8[1] < refDepthTmp[3][x+offset[3]] )
1607          {
1608            repDepth4x8[1] = refDepthTmp[3][x+offset[3]];
1609          }
1610
1611          depthTmp = &depth[x];
1612          for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY )
1613          {
1614            for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX )
1615            {
1616              depthTmp[sX] = repDepth4x8[0];
1617            }
1618            depthTmp += depStrideTmp;
1619          }
1620          depthTmp = &depth[x+subblocksize];
1621          for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY )
1622          {
1623            for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX )
1624            {
1625              depthTmp[sX] = repDepth4x8[1];
1626            }
1627            depthTmp += depStrideTmp;
1628          }
1629        }
1630        else
1631        { // 8x4
1632          repDepth8x4[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[3]];
1633          if( repDepth8x4[0] < refDepthTmp[1][x+offset[0]] )
1634          {
1635            repDepth8x4[0] = refDepthTmp[1][x+offset[0]];
1636          }
1637          if( repDepth8x4[0] < refDepthTmp[1][x+offset[3]] )
1638          {
1639            repDepth8x4[0] = refDepthTmp[1][x+offset[3]];
1640          }
1641          repDepth8x4[1] = refDepthTmp[2][x+offset[0]] > refDepthTmp[2][x+offset[3]] ? refDepthTmp[2][x+offset[0]] : refDepthTmp[2][x+offset[3]];
1642          if( repDepth8x4[1] < refDepthTmp[3][x+offset[0]] )
1643          {
1644            repDepth8x4[1] = refDepthTmp[3][x+offset[0]];
1645          }
1646          if( repDepth8x4[1] < refDepthTmp[3][x+offset[3]] )
1647          {
1648            repDepth8x4[1] = refDepthTmp[3][x+offset[3]];
1649          }
1650         
1651          depthTmp = &depth[x];
1652          for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY )
1653          {
1654            for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX )
1655            {
1656              depthTmp[sX] = repDepth8x4[0];
1657            }
1658            depthTmp += depStrideTmp;
1659          }
1660          for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY )
1661          {
1662            for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX )
1663            {
1664              depthTmp[sX] = repDepth8x4[1];
1665            }
1666            depthTmp += depStrideTmp;
1667          }
1668        }
1669      }
1670      refDepthTmp[0] += refDepStrideBlock;
1671      refDepthTmp[1] += refDepStrideBlock;
1672      refDepthTmp[2] += refDepStrideBlock;
1673      refDepthTmp[3] += refDepStrideBlock;
1674      depth       += depStrideBlock;
1675    }
1676  }
1677
1678
1679}
1680
1681Void TComPrediction::xPredInterLumaBlkFromDM( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi )
1682{
1683  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
1684  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
1685 
1686  Int refStride = picRef->getStride();
1687  Int dstStride = yuvDst->getStride();
1688  Int depStride = yuvDepth->getStride();
1689  Int refStrideBlock = refStride  * nTxtPerDepthY;
1690  Int dstStrideBlock = dstStride * nTxtPerDepthY;
1691  Int depStrideBlock = depStride * nTxtPerDepthY;
1692
1693  Pel *ref    = picRef->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
1694  Pel *dst    = yuvDst->getLumaAddr(partAddr);
1695  Pel *depth  = yuvDepth->getLumaAddr();
1696
1697#if H_3D_VSP_BLOCKSIZE == 1
1698#if H_3D_VSP_CONSTRAINED
1699  //get LUT based horizontal reference range
1700  Int range = xGetConstrainedSize(width, height);
1701
1702  // The minimum depth value
1703  Int minRelativePos = MAX_INT;
1704  Int maxRelativePos = MIN_INT;
1705
1706  Pel* depthTemp, *depthInitial=depth;
1707  for (Int yTxt = 0; yTxt < height; yTxt++)
1708  {
1709    for (Int xTxt = 0; xTxt < width; xTxt++)
1710    {
1711      if (depthPosX+xTxt < widthDepth)
1712      {
1713        depthTemp = depthInitial + xTxt;
1714      }
1715      else
1716      {
1717        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
1718      }
1719
1720      Int disparity = shiftLUT[ *depthTemp ]; // << iShiftPrec;
1721      Int disparityInt = disparity >> 2;
1722
1723      if( disparity <= 0)
1724      {
1725        if (minRelativePos > disparityInt+xTxt)
1726        {
1727          minRelativePos = disparityInt+xTxt;
1728        }
1729      }
1730      else
1731      {
1732        if (maxRelativePos < disparityInt+xTxt)
1733        {
1734          maxRelativePos = disparityInt+xTxt;
1735        }
1736      }
1737    }
1738    if (depthPosY+yTxt < heightDepth)
1739    {
1740      depthInitial = depthInitial + depStride;
1741    }
1742  }
1743
1744  Int disparity_tmp = shiftLUT[ *depth ]; // << iShiftPrec;
1745  if (disparity_tmp <= 0)
1746  {
1747    maxRelativePos = minRelativePos + range -1 ;
1748  }
1749  else
1750  {
1751    minRelativePos = maxRelativePos - range +1 ;
1752  }
1753#endif
1754#endif // H_3D_VSP_BLOCKSIZE == 1
1755
1756  TComMv dv(0, 0);
1757
1758  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
1759  {
1760    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
1761    {
1762      Pel repDepth = depth[ xTxt ];
1763      assert( repDepth >= 0 && repDepth <= 255 );
1764
1765      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec ??
1766      Int xFrac = disparity & 0x3;
1767
1768      dv.setHor( disparity );
1769      cu->clipMv( dv );
1770
1771      Int refOffset = xTxt + (dv.getHor() >> 2);
1772     
1773#if H_3D_VSP_CONSTRAINED
1774      if(refOffset<minRelativePos || refOffset>maxRelativePos)
1775      {
1776        xFrac = 0;
1777      }
1778      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
1779#endif
1780
1781      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
1782      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
1783    }
1784    ref   += refStrideBlock;
1785    dst   += dstStrideBlock;
1786    depth += depStrideBlock;
1787  }
1788
1789}
1790
1791Void TComPrediction::xPredInterChromaBlkFromDM  ( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi )
1792{
1793#if (H_3D_VSP_BLOCKSIZE==1)
1794  Int nTxtPerDepthX = 1;
1795  Int nTxtPerDepthY = 1;
1796#else
1797  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE >> 1;
1798  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE >> 1;
1799#endif
1800
1801  Int refStride = picRef->getCStride();
1802  Int dstStride = yuvDst->getCStride();
1803  Int depStride = yuvDepth->getStride();
1804  Int refStrideBlock = refStride * nTxtPerDepthY;
1805  Int dstStrideBlock = dstStride * nTxtPerDepthY;
1806  Int depStrideBlock = depStride * (nTxtPerDepthY<<1);
1807
1808  Pel *refCb  = picRef->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
1809  Pel *refCr  = picRef->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr );
1810  Pel *dstCb  = yuvDst->getCbAddr(partAddr);
1811  Pel *dstCr  = yuvDst->getCrAddr(partAddr);
1812  Pel *depth  = yuvDepth->getLumaAddr();
1813
1814#if H_3D_VSP_BLOCKSIZE == 1
1815#if H_3D_VSP_CONSTRAINED
1816  //get LUT based horizontal reference range
1817  Int range = xGetConstrainedSize(width, height, false);
1818
1819  // The minimum depth value
1820  Int minRelativePos = MAX_INT;
1821  Int maxRelativePos = MIN_INT;
1822
1823  Int depthTmp;
1824  for (Int yTxt=0; yTxt<height; yTxt++)
1825  {
1826    for (Int xTxt=0; xTxt<width; xTxt++)
1827    {
1828      depthTmp = m_pDepthBlock[xTxt+yTxt*width];
1829      Int disparity = shiftLUT[ depthTmp ]; // << iShiftPrec;
1830      Int disparityInt = disparity >> 3;//in chroma resolution
1831
1832      if (disparityInt < 0)
1833      {
1834        if (minRelativePos > disparityInt+xTxt)
1835        {
1836          minRelativePos = disparityInt+xTxt;
1837        }
1838      }
1839      else
1840      {
1841        if (maxRelativePos < disparityInt+xTxt)
1842        {
1843          maxRelativePos = disparityInt+xTxt;
1844        }
1845      }
1846    }
1847  }
1848
1849  depthTmp = m_pDepthBlock[0];
1850  Int disparity_tmp = shiftLUT[ depthTmp ]; // << iShiftPrec;
1851  if ( disparity_tmp < 0 )
1852  {
1853    maxRelativePos = minRelativePos + range - 1;
1854  }
1855  else
1856  {
1857    minRelativePos = maxRelativePos - range + 1;
1858  }
1859
1860#endif // H_3D_VSP_CONSTRAINED
1861#endif // H_3D_VSP_BLOCKSIZE == 1
1862
1863  TComMv dv(0, 0);
1864  // luma size -> chroma size
1865  height >>= 1;
1866  width  >>= 1;
1867
1868  for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY )
1869  {
1870    for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX )
1871    {
1872      Pel repDepth = depth[ xTxt<<1 ];
1873      assert( repDepth >= 0 && repDepth <= 255 );
1874
1875      Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec;
1876      Int xFrac = disparity & 0x7;
1877     
1878      dv.setHor( disparity );
1879      cu->clipMv( dv );
1880
1881      Int refOffset = xTxt + (dv.getHor() >> 3);
1882
1883#if H_3D_VSP_CONSTRAINED
1884      if(refOffset<minRelativePos || refOffset>maxRelativePos)
1885      {
1886        xFrac = 0;
1887      }
1888      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
1889#endif
1890
1891      assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
1892      assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
1893
1894      m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
1895      m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi );
1896    }
1897    refCb += refStrideBlock;
1898    refCr += refStrideBlock;
1899    dstCb += dstStrideBlock;
1900    dstCr += dstStrideBlock;
1901    depth += depStrideBlock;
1902  }
1903}
1904
1905
1906#if H_3D_VSP_CONSTRAINED
1907Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma)
1908{
1909  Int iSize = 0;
1910  if (bLuma)
1911  {
1912    Int iArea = (nPbW+7) * (nPbH+7);
1913    Int iAlpha = iArea / nPbH - nPbW - 7;
1914    iSize = iAlpha + nPbW;
1915  }
1916  else // chroma
1917  {
1918    Int iArea = (nPbW+2) * (nPbH+2);
1919    Int iAlpha = iArea / nPbH - nPbW - 4;
1920    iSize = iAlpha + nPbW;
1921  }
1922  return iSize;
1923}
1924#endif // H_3D_VSP_CONSTRAINED
1925
1926#endif // H_3D_VSP
1927
1928#if H_3D_DIM
1929Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
1930{
1931  Int  refDC1, refDC2;
1932  const Int  iTR = (   patternStride - 1        ) - srcStride;
1933  const Int  iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride;
1934  const Int  iLB = (   patternStride - 1        ) * srcStride - 1;
1935  const Int  iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1;
1936
1937  Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] );
1938  Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)]               );
1939
1940  if( bL == bT )
1941  {
1942    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : 1<<( g_bitDepthY - 1 );
1943    refDC2 =      ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1;
1944  }
1945  else
1946  {
1947    refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR];
1948    refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM];
1949  }
1950
1951  predDC1 = biSegPattern[0] ? refDC1 : refDC2;
1952  predDC2 = biSegPattern[0] ? refDC2 : refDC1;
1953}
1954
1955Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
1956{
1957  if( dstStride == patternStride )
1958  {
1959    for( UInt k = 0; k < (patternStride * patternStride); k++ )
1960    {
1961      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
1962      else                          { ptrDst[k] = valDC1; }
1963    }
1964  }
1965  else
1966  {
1967    Pel* piTemp = ptrDst;
1968    for( UInt uiY = 0; uiY < patternStride; uiY++ )
1969    {
1970      for( UInt uiX = 0; uiX < patternStride; uiX++ )
1971      {
1972        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
1973        else                            { piTemp[uiX] = valDC1; }
1974      }
1975      piTemp       += dstStride;
1976      biSegPattern += patternStride;
1977    }
1978  }
1979}
1980
1981#if H_3D_DIM_DMM
1982#if !SEC_DMM3_RBC_F0147
1983UInt TComPrediction::xPredWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx )
1984{
1985  TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
1986  assert( pcPicTex != NULL );
1987  TComDataCU*   pcColTexCU = pcPicTex->getCU(pcCU->getAddr());
1988  UInt          uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1989  Int           uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
1990
1991  assert( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 );
1992  return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx);
1993}
1994#endif
1995
1996Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
1997{
1998  pcContourWedge->clear();
1999
2000  // get copy of co-located texture luma block
2001  TComYuv cTempYuv;
2002  cTempYuv.create( uiWidth, uiHeight ); 
2003  cTempYuv.clear();
2004  Pel* piRefBlkY = cTempYuv.getLumaAddr();
2005  xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
2006  piRefBlkY = cTempYuv.getLumaAddr();
2007
2008  // find contour for texture luma block
2009  UInt iDC = 0;
2010  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2011  { 
2012    iDC += piRefBlkY[k]; 
2013  }
2014
2015  Int cuMaxLog2Size = g_aucConvertToBit[g_uiMaxCUWidth]+2;   //
2016  iDC = iDC >> (cuMaxLog2Size - pcCU->getDepth(0))*2;        //  iDC /= (uiWidth*uiHeight);
2017
2018  piRefBlkY = cTempYuv.getLumaAddr();
2019
2020  Bool* pabContourPattern = pcContourWedge->getPattern();
2021  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2022  { 
2023    pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
2024  }
2025
2026  cTempYuv.destroy();
2027}
2028
2029
2030Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
2031{
2032  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
2033  assert( pcPicYuvRef != NULL );
2034  Int         iRefStride = pcPicYuvRef->getStride();
2035  Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2036
2037  for ( Int y = 0; y < uiHeight; y++ )
2038  {
2039    ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
2040    piDestBlockY += uiWidth;
2041    piRefY += iRefStride;
2042  }
2043}
2044#endif
2045
2046#if H_3D_DIM_RBC
2047Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Pel& rDeltaDC )
2048{
2049  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
2050  UInt uiAbs  = abs( rDeltaDC );
2051
2052  Int iQp = pcCU->getQP(0);
2053  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
2054  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
2055
2056  rDeltaDC = iSign * roftoi( uiAbs * dStepSize );
2057  return;
2058}
2059
2060Void TComPrediction::xDeltaDCQuantScaleDown( TComDataCU*  pcCU, Pel& rDeltaDC )
2061{
2062  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
2063  UInt uiAbs  = abs( rDeltaDC );
2064
2065  Int iQp = pcCU->getQP(0);
2066  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
2067  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
2068
2069  rDeltaDC = iSign * roftoi( uiAbs / dStepSize );
2070  return;
2071}
2072#endif
2073#if H_3D_DIM_SDC
2074Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride
2075                                         ,UInt uiIntraMode
2076                                         ,Bool orgDC
2077                                        )
2078{
2079  Int iSumDepth[2];
2080  memset(iSumDepth, 0, sizeof(Int)*2);
2081  Int iSumPix[2];
2082  memset(iSumPix, 0, sizeof(Int)*2);
2083 
2084  if (orgDC == false)
2085  {
2086    if ( getDimType(uiIntraMode) == DMM1_IDX )
2087    {
2088      UChar ucSegmentLT = pMask[0];
2089      UChar ucSegmentRT = pMask[uiSize-1];
2090      UChar ucSegmentLB = pMask[uiMaskStride * (uiSize-1)]; 
2091      UChar ucSegmentRB = pMask[uiMaskStride * (uiSize-1) + (uiSize-1)]; 
2092
2093      rpSegMeans[ucSegmentLT] = pOrig[0];
2094      rpSegMeans[ucSegmentRT] = pOrig[uiSize-1];
2095      rpSegMeans[ucSegmentLB] = pOrig[uiStride * (uiSize-1) ];
2096      rpSegMeans[ucSegmentRB] = pOrig[uiStride * (uiSize-1) + (uiSize-1) ];
2097    }
2098    else if (uiIntraMode == PLANAR_IDX)
2099    {
2100      Pel* pLeftTop = pOrig;
2101      Pel* pRightTop = pOrig + (uiSize-1);
2102      Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1)));
2103      Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1));
2104
2105      rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2;
2106    }
2107    return;
2108  }
2109
2110  Int subSamplePix;
2111  if ( uiSize == 64 || uiSize == 32 )
2112  {
2113    subSamplePix = 2;
2114  }
2115  else
2116  {
2117    subSamplePix = 1;
2118  }
2119  for (Int y=0; y<uiSize; y+=subSamplePix)
2120  {
2121    for (Int x=0; x<uiSize; x+=subSamplePix)
2122    {
2123      UChar ucSegment = pMask?(UChar)pMask[x]:0;
2124      assert( ucSegment < uiNumSegments );
2125     
2126      iSumDepth[ucSegment] += pOrig[x];
2127      iSumPix[ucSegment]   += 1;
2128    }
2129   
2130    pOrig  += uiStride*subSamplePix;
2131    pMask  += uiMaskStride*subSamplePix;
2132  }
2133 
2134  // compute mean for each segment
2135  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
2136  {
2137    if( iSumPix[ucSeg] > 0 )
2138      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
2139    else
2140      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
2141  }
2142}
2143#endif // H_3D_DIM_SDC
2144#endif
2145//! \}
Note: See TracBrowser for help on using the repository browser.