source: 3DVCSoftware/branches/HTM-DEV-2.0-dev1-NTT/source/Lib/TLibCommon/TComPrediction.cpp @ 576

Last change on this file since 576 was 576, checked in by ntt, 12 years ago

Integration for the adoptions in E0207, E0208, and E0141 by NTT.

  • Property svn:eol-style set to native
File size: 99.3 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#if NTT_VSP_COMMON_E0207_E0208
66  m_cYuvDepthOnVsp.destroy();
67#endif
68#endif
69
70  delete[] m_piYuvExt;
71
72  m_acYuvPred[0].destroy();
73  m_acYuvPred[1].destroy();
74
75  m_cYuvPredTemp.destroy();
76
77#if H_3D_ARP
78  m_acYuvPredBase[0].destroy();
79  m_acYuvPredBase[1].destroy();
80#endif
81  if( m_pLumaRecBuffer )
82  {
83    delete [] m_pLumaRecBuffer;
84  }
85 
86  Int i, j;
87  for (i = 0; i < 4; i++)
88  {
89    for (j = 0; j < 4; j++)
90    {
91      m_filteredBlock[i][j].destroy();
92    }
93    m_filteredBlockTmp[i].destroy();
94  }
95}
96
97Void TComPrediction::initTempBuff()
98{
99  if( m_piYuvExt == NULL )
100  {
101    Int extWidth  = MAX_CU_SIZE + 16; 
102    Int extHeight = MAX_CU_SIZE + 1;
103    Int i, j;
104    for (i = 0; i < 4; i++)
105    {
106      m_filteredBlockTmp[i].create(extWidth, extHeight + 7);
107      for (j = 0; j < 4; j++)
108      {
109        m_filteredBlock[i][j].create(extWidth, extHeight);
110      }
111    }
112    m_iYuvExtHeight  = ((MAX_CU_SIZE + 2) << 4);
113    m_iYuvExtStride = ((MAX_CU_SIZE  + 8) << 4);
114    m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
115
116    // new structure
117    m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE );
118    m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE );
119
120    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE );
121#if H_3D_ARP
122    m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
123    m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
124#endif
125#if NTT_VSP_COMMON_E0207_E0208
126    m_cYuvDepthOnVsp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
127#endif
128  }
129
130  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
131  {
132    m_iLumaRecStride =  (MAX_CU_SIZE>>1) + 1;
133    if (!m_pLumaRecBuffer)
134    {
135      m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ];
136    }
137  }
138#if H_3D_IC
139  for( Int i = 1; i < 64; i++ )
140  {
141    m_uiaShift[i-1] = ( (1 << 15) + i/2 ) / i;
142  }
143#endif
144}
145
146// ====================================================================================================================
147// Public member functions
148// ====================================================================================================================
149
150// Function for calculating DC value of the reference samples used in Intra prediction
151Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft )
152{
153  assert(iWidth > 0 && iHeight > 0);
154  Int iInd, iSum = 0;
155  Pel pDcVal;
156
157  if (bAbove)
158  {
159    for (iInd = 0;iInd < iWidth;iInd++)
160    {
161      iSum += pSrc[iInd-iSrcStride];
162    }
163  }
164  if (bLeft)
165  {
166    for (iInd = 0;iInd < iHeight;iInd++)
167    {
168      iSum += pSrc[iInd*iSrcStride-1];
169    }
170  }
171
172  if (bAbove && bLeft)
173  {
174    pDcVal = (iSum + iWidth) / (iWidth + iHeight);
175  }
176  else if (bAbove)
177  {
178    pDcVal = (iSum + iWidth/2) / iWidth;
179  }
180  else if (bLeft)
181  {
182    pDcVal = (iSum + iHeight/2) / iHeight;
183  }
184  else
185  {
186    pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available
187  }
188 
189  return pDcVal;
190}
191
192// Function for deriving the angular Intra predictions
193
194/** Function for deriving the simplified angular intra predictions.
195 * \param pSrc pointer to reconstructed sample array
196 * \param srcStride the stride of the reconstructed sample array
197 * \param rpDst reference to pointer for the prediction sample array
198 * \param dstStride the stride of the prediction sample array
199 * \param width the width of the block
200 * \param height the height of the block
201 * \param dirMode the intra prediction mode index
202 * \param blkAboveAvailable boolean indication if the block above is available
203 * \param blkLeftAvailable boolean indication if the block to the left is available
204 *
205 * This function derives the prediction samples for the angular mode based on the prediction direction indicated by
206 * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and
207 * the reference row above the block in the case of vertical prediction or displacement of the rightmost column
208 * of the block and reference column left from the block in the case of the horizontal prediction. The displacement
209 * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples,
210 * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken
211 * from the extended main reference.
212 */
213Void TComPrediction::xPredIntraAng(Int bitDepth, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter )
214{
215  Int k,l;
216  Int blkSize        = width;
217  Pel* pDst          = rpDst;
218
219  // Map the mode index to main prediction direction and angle
220  assert( dirMode > 0 ); //no planar
221  Bool modeDC        = dirMode < 2;
222  Bool modeHor       = !modeDC && (dirMode < 18);
223  Bool modeVer       = !modeDC && !modeHor;
224  Int intraPredAngle = modeVer ? (Int)dirMode - VER_IDX : modeHor ? -((Int)dirMode - HOR_IDX) : 0;
225  Int absAng         = abs(intraPredAngle);
226  Int signAng        = intraPredAngle < 0 ? -1 : 1;
227
228  // Set bitshifts and scale the angle parameter to block size
229  Int angTable[9]    = {0,    2,    5,   9,  13,  17,  21,  26,  32};
230  Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
231  Int invAngle       = invAngTable[absAng];
232  absAng             = angTable[absAng];
233  intraPredAngle     = signAng * absAng;
234
235  // Do the DC prediction
236  if (modeDC)
237  {
238    Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable);
239
240    for (k=0;k<blkSize;k++)
241    {
242      for (l=0;l<blkSize;l++)
243      {
244        pDst[k*dstStride+l] = dcval;
245      }
246    }
247  }
248
249  // Do angular predictions
250  else
251  {
252    Pel* refMain;
253    Pel* refSide;
254    Pel  refAbove[2*MAX_CU_SIZE+1];
255    Pel  refLeft[2*MAX_CU_SIZE+1];
256
257    // Initialise the Main and Left reference array.
258    if (intraPredAngle < 0)
259    {
260      for (k=0;k<blkSize+1;k++)
261      {
262        refAbove[k+blkSize-1] = pSrc[k-srcStride-1];
263      }
264      for (k=0;k<blkSize+1;k++)
265      {
266        refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1];
267      }
268      refMain = (modeVer ? refAbove : refLeft) + (blkSize-1);
269      refSide = (modeVer ? refLeft : refAbove) + (blkSize-1);
270
271      // Extend the Main reference to the left.
272      Int invAngleSum    = 128;       // rounding for (shift by 8)
273      for (k=-1; k>blkSize*intraPredAngle>>5; k--)
274      {
275        invAngleSum += invAngle;
276        refMain[k] = refSide[invAngleSum>>8];
277      }
278    }
279    else
280    {
281      for (k=0;k<2*blkSize+1;k++)
282      {
283        refAbove[k] = pSrc[k-srcStride-1];
284      }
285      for (k=0;k<2*blkSize+1;k++)
286      {
287        refLeft[k] = pSrc[(k-1)*srcStride-1];
288      }
289      refMain = modeVer ? refAbove : refLeft;
290      refSide = modeVer ? refLeft  : refAbove;
291    }
292
293    if (intraPredAngle == 0)
294    {
295      for (k=0;k<blkSize;k++)
296      {
297        for (l=0;l<blkSize;l++)
298        {
299          pDst[k*dstStride+l] = refMain[l+1];
300        }
301      }
302
303      if ( bFilter )
304      {
305        for (k=0;k<blkSize;k++)
306        {
307          pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) );
308        }
309      }
310    }
311    else
312    {
313      Int deltaPos=0;
314      Int deltaInt;
315      Int deltaFract;
316      Int refMainIndex;
317
318      for (k=0;k<blkSize;k++)
319      {
320        deltaPos += intraPredAngle;
321        deltaInt   = deltaPos >> 5;
322        deltaFract = deltaPos & (32 - 1);
323
324        if (deltaFract)
325        {
326          // Do linear filtering
327          for (l=0;l<blkSize;l++)
328          {
329            refMainIndex        = l+deltaInt+1;
330            pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 );
331          }
332        }
333        else
334        {
335          // Just copy the integer samples
336          for (l=0;l<blkSize;l++)
337          {
338            pDst[k*dstStride+l] = refMain[l+deltaInt+1];
339          }
340        }
341      }
342    }
343
344    // Flip the block if this is the horizontal mode
345    if (modeHor)
346    {
347      Pel  tmp;
348      for (k=0;k<blkSize-1;k++)
349      {
350        for (l=k+1;l<blkSize;l++)
351        {
352          tmp                 = pDst[k*dstStride+l];
353          pDst[k*dstStride+l] = pDst[l*dstStride+k];
354          pDst[l*dstStride+k] = tmp;
355        }
356      }
357    }
358  }
359}
360
361Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
362{
363  Pel *pDst = piPred;
364  Int *ptrSrc;
365
366  assert( g_aucConvertToBit[ iWidth ] >= 0 ); //   4x  4
367  assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128
368  assert( iWidth == iHeight  );
369
370  ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
371
372  // get starting pixel in block
373  Int sw = 2 * iWidth + 1;
374
375  // Create the prediction
376  if ( uiDirMode == PLANAR_IDX )
377  {
378    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
379  }
380  else
381  {
382    if ( (iWidth > 16) || (iHeight > 16) )
383    {
384      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
385    }
386    else
387    {
388      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );
389
390      if( (uiDirMode == DC_IDX ) && bAbove && bLeft )
391      {
392        xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);
393      }
394    }
395  }
396}
397
398// Angular chroma
399Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
400{
401  Pel *pDst = piPred;
402  Int *ptrSrc = piSrc;
403
404  // get starting pixel in block
405  Int sw = 2 * iWidth + 1;
406
407  if ( uiDirMode == PLANAR_IDX )
408  {
409    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
410  }
411  else
412  {
413    // Create the prediction
414    xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
415  }
416}
417
418#if H_3D_DIM
419Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc )
420{
421  assert( iWidth == iHeight  );
422  assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE );
423  assert( isDimMode( uiIntraMode ) );
424
425  UInt dimType    = getDimType  ( uiIntraMode );
426  Bool dimDeltaDC = isDimDeltaDC( uiIntraMode );   
427  Bool isDmmMode  = (dimType <  DMM_NUM_TYPE);
428  Bool isRbcMode  = (dimType == RBC_IDX);
429
430  Bool* biSegPattern  = NULL;
431  UInt  patternStride = 0;
432
433  // get partiton
434#if H_3D_DIM_DMM
435  TComWedgelet* dmmSegmentation = NULL;
436  if( isDmmMode )
437  {
438    switch( dimType )
439    {
440    case( DMM1_IDX ): 
441      {
442        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]);
443      } break;
444    case( DMM2_IDX ):
445      {
446        UInt uiTabIdx = 0;
447        if( bFastEnc ) { uiTabIdx = pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ); }
448        else
449        {
450          uiTabIdx = xPredWedgeFromIntra( pcCU, uiAbsPartIdx, iWidth, iHeight, pcCU->getDmm2DeltaEnd( uiAbsPartIdx ) );
451          pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, uiAbsPartIdx, (pcCU->getDepth(0) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1)) );
452        }
453        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ uiTabIdx ]);
454      } break;
455    case( DMM3_IDX ): 
456      {
457        UInt uiTabIdx = 0;
458        if( bFastEnc ) { uiTabIdx = pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ); }
459        else
460        {
461          uiTabIdx = xPredWedgeFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, pcCU->getDmm3IntraTabIdx( uiAbsPartIdx ) );
462          pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, uiAbsPartIdx, (pcCU->getDepth(0) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1)) );
463        }
464        dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ uiTabIdx ]);
465      } break;
466    case( DMM4_IDX ): 
467      {
468        dmmSegmentation = new TComWedgelet( iWidth, iHeight );
469        xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation );
470      } break;
471    default: assert(0);
472    }
473    assert( dmmSegmentation );
474    biSegPattern  = dmmSegmentation->getPattern();
475    patternStride = dmmSegmentation->getStride ();
476  }
477#endif
478#if H_3D_DIM_RBC
479  if( isRbcMode )
480  {
481    biSegPattern  = pcCU->getEdgePartition( uiAbsPartIdx );
482    patternStride = iWidth;
483  }
484#endif
485
486  // get predicted partition values
487  assert( biSegPattern );
488  Int* piMask = NULL;
489  if( isDmmMode ) piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering for DMM
490  else            piMask = pcCU->getPattern()->getPredictorPtr( 0, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
491  assert( piMask );
492  Int maskStride = 2*iWidth + 1; 
493  Int* ptrSrc = piMask+maskStride+1;
494  Pel predDC1 = 0; Pel predDC2 = 0;
495  xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 );
496
497  // set segment values with deltaDC offsets
498  Pel segDC1 = 0;
499  Pel segDC2 = 0;
500  if( dimDeltaDC )
501  {
502    Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx );
503    Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx );
504#if H_3D_DIM_DMM
505    if( isDmmMode )
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
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 ( 0 == pcCU->getVSPFlag(uiPartAddr) )
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        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
609      else
610        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
611    }
612#endif
613    return;
614  }
615
616  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
617  {
618    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
619
620#if H_3D_VSP
621    if ( 0 == pcCU->getVSPFlag(uiPartAddr) )
622    {
623#endif
624      if ( eRefPicList != REF_PIC_LIST_X )
625      {
626        if( pcCU->getSlice()->getPPS()->getUseWP())
627        {
628          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
629        }
630        else
631        {
632          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
633        }
634        if ( pcCU->getSlice()->getPPS()->getUseWP() )
635        {
636          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
637        }
638      }
639      else
640      {
641        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
642        {
643          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
644        }
645        else
646        {
647          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
648        }
649      }
650#if H_3D_VSP
651    }
652    else
653    {
654      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
655        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
656      else
657        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
658    }
659#endif
660  }
661  return;
662}
663
664Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
665{
666  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
667  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
668  pcCU->clipMv(cMv);
669#if H_3D_ARP
670  if(  pcCU->getARPW( uiPartAddr ) > 0 
671    && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N
672    && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() 
673    )
674  {
675    xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi );
676  }
677  else
678  {
679#endif
680#if H_3D_IC
681    Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() );
682    xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
683#if H_3D_ARP
684      , false
685#endif
686      , bICFlag );
687    xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
688#if H_3D_ARP
689      , false
690#endif
691      , bICFlag );
692#else
693  xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
694  xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
695#endif
696#if H_3D_ARP
697  }
698#endif
699}
700
701#if H_3D_VSP
702Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
703{
704  // Get depth reference
705#if MTK_VSP_FIX_E0172
706  Int vspDir = pcCU->getVSPDir( uiPartAddr );
707  RefPicList privateRefPicList = (vspDir == 0) ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
708  Int privateRefIdx = pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
709  Int depthRefViewIdx = pcCU->getSlice()->getRefPic(privateRefPicList, privateRefIdx)->getViewIndex();
710#else
711  Int depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
712#endif
713  TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
714  assert(pRefPicBaseDepth != NULL);
715  TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
716  assert(pcBaseViewDepthPicYuv != NULL);
717
718  // Get texture reference
719  Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
720  assert(iRefIdx >= 0);
721  TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx );
722  TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
723  assert(pcBaseViewTxtPicYuv != NULL);
724
725  // Initialize LUT according to the reference viewIdx
726  Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex();
727  Int* pShiftLUT    = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx );
728  assert( txtRefViewIdx < pcCU->getSlice()->getViewIndex() );
729
730  // Do compensation
731#if MTK_VSP_FIX_E0172
732  TComMv cDv  = pcCU->getCUMvField( privateRefPicList )->getMv( uiPartAddr );
733#else
734  TComMv cDv  = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); // cDv is the disparity vector derived from the neighbors
735#endif
736  pcCU->clipMv(cDv);
737
738#if NTT_VSP_COMMON_E0207_E0208
739  // fetch virtual depth map
740#if NTT_VSP_VECTOR_CLIP_E0208
741  pcBaseViewDepthPicYuv->extendPicBorder();
742#endif
743  xGetVirtualDepth( pcCU, pcBaseViewDepthPicYuv, &cDv, uiPartAddr, iWidth, iHeight, &m_cYuvDepthOnVsp );
744  // sub-PU based compensation
745  xPredInterLumaBlkFromDM   ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
746  xPredInterChromaBlkFromDM ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
747#else
748  UInt uiAbsPartIdx = pcCU->getZorderIdxInCU();
749  Int iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
750  Int iBlkY = ( pcCU->getAddr() / pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
751  xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
752  xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
753#endif
754
755}
756#endif
757
758#if H_3D_ARP
759Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled )
760{
761  Int         iRefIdx      = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           
762  TComMv      cMv          = pNewMvFiled ? pNewMvFiled->getMv()     : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
763  Bool        bTobeScaled  = false;
764  TComPic* pcPicYuvBaseCol = NULL;
765  TComPic* pcPicYuvBaseRef = NULL;
766
767#if H_3D_NBDV
768  DisInfo cDistparity;
769  cDistparity.bDV           = pcCU->getDvInfo(uiPartAddr).bDV;
770  if( cDistparity.bDV )
771  {
772    cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV;
773    assert(pcCU->getDvInfo(uiPartAddr).bDV ==  pcCU->getDvInfo(0).bDV);
774    cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
775  }
776#else
777  assert(0); // ARP can be applied only when a DV is available
778#endif
779
780  UChar dW = cDistparity.bDV ? pcCU->getARPW ( uiPartAddr ) : 0;
781
782  if( cDistparity.bDV ) 
783  {
784    if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC()!= pcCU->getSlice()->getPOC() )
785    {
786      bTobeScaled = true;
787    }
788
789    pcPicYuvBaseCol =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(),                              cDistparity.m_aVIdxCan );
790    pcPicYuvBaseRef =  pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC(), cDistparity.m_aVIdxCan );
791   
792    if( ( !pcPicYuvBaseCol || pcPicYuvBaseCol->getPOC() != pcCU->getSlice()->getPOC() ) || ( !pcPicYuvBaseRef || pcPicYuvBaseRef->getPOC() != pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() ) )
793    {
794      dW = 0;
795      bTobeScaled = false;
796    }
797    else
798    {
799      assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() );
800    }
801
802    if(bTobeScaled)
803    {     
804      Int iCurrPOC    = pcCU->getSlice()->getPOC();
805      Int iColRefPOC  = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx );
806      Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList,  0);
807      Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC);
808      if ( iScale != 4096 )
809      {
810        cMv = cMv.scaleMv( iScale );
811      }
812      iRefIdx = 0;
813    }
814  }
815
816  pcCU->clipMv(cMv);
817  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec();
818  xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
819  xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true );
820
821  if( dW > 0 )
822  {
823    TComYuv * pYuvB0 = &m_acYuvPredBase[0];
824    TComYuv * pYuvB1  = &m_acYuvPredBase[1];
825
826    TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV;
827    pcCU->clipMv(cMVwithDisparity);
828
829    assert ( cDistparity.bDV );
830
831    pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec();
832    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
833    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true );
834   
835    pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec();
836    xPredInterLumaBlk  ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
837    xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true );
838
839    pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight );
840
841    if( 2 == dW )
842    {
843      pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW );
844    }
845    rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi );
846  }
847}
848#endif
849
850Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
851{
852  TComYuv* pcMbYuv;
853  Int      iRefIdx[2] = {-1, -1};
854
855  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
856  {
857    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
858    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
859
860    if ( iRefIdx[iRefList] < 0 )
861    {
862      continue;
863    }
864
865    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
866
867    pcMbYuv = &m_acYuvPred[iRefList];
868    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
869    {
870      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
871    }
872    else
873    {
874      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) || 
875           ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
876      {
877        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
878      }
879      else
880      {
881        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
882      }
883    }
884  }
885
886  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE  )
887  {
888    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
889  } 
890  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
891  {
892    xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); 
893  }
894  else
895  {
896    xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
897  }
898}
899
900#if H_3D_VSP
901
902Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
903{
904  TComYuv* pcMbYuv;
905  Int      iRefIdx[2] = {-1, -1};
906  Bool     bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0);
907
908  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
909  {
910    RefPicList eRefPicList = RefPicList(iRefList);
911    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
912
913    if ( iRefIdx[iRefList] < 0 )
914      continue;
915    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
916
917    pcMbYuv = &m_acYuvPred[iRefList];
918    xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi );
919  }
920
921  xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
922}
923
924#endif
925
926/**
927 * \brief Generate motion-compensated luma block
928 *
929 * \param cu       Pointer to current CU
930 * \param refPic   Pointer to reference picture
931 * \param partAddr Address of block within CU
932 * \param mv       Motion vector
933 * \param width    Width of block
934 * \param height   Height of block
935 * \param dstPic   Pointer to destination picture
936 * \param bi       Flag indicating whether bipred is used
937 */
938Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
939#if H_3D_ARP
940    , Bool filterType
941#endif
942#if H_3D_IC
943    , Bool bICFlag
944#endif
945  )
946{
947  Int refStride = refPic->getStride(); 
948  Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride;
949  Pel *ref      = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
950 
951  Int dstStride = dstPic->getStride();
952  Pel *dst      = dstPic->getLumaAddr( partAddr );
953 
954  Int xFrac = mv->getHor() & 0x3;
955  Int yFrac = mv->getVer() & 0x3;
956
957#if H_3D_IC
958  if( cu->getSlice()->getIsDepth() )
959  {
960    refOffset = mv->getHor() + mv->getVer() * refStride;
961    ref       = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
962    xFrac     = 0;
963    yFrac     = 0;
964  }
965#endif
966  if ( yFrac == 0 )
967  {
968    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi
969#if H_3D_ARP
970    , filterType
971#endif
972      );
973  }
974  else if ( xFrac == 0 )
975  {
976    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi
977#if H_3D_ARP
978    , filterType
979#endif
980      );
981  }
982  else
983  {
984    Int tmpStride = m_filteredBlockTmp[0].getStride();
985    Short *tmp    = m_filteredBlockTmp[0].getLumaAddr();
986
987    Int filterSize = NTAPS_LUMA;
988    Int halfFilterSize = ( filterSize >> 1 );
989
990    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     
991#if H_3D_ARP
992    , filterType
993#endif
994      );
995    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi
996#if H_3D_ARP
997    , filterType
998#endif
999      );   
1000  }
1001
1002#if H_3D_IC
1003  if( bICFlag )
1004  {
1005    Int a, b, iShift, i, j;
1006
1007    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_LUMA );
1008
1009    for ( i = 0; i < height; i++ )
1010    {
1011      for ( j = 0; j < width; j++ )
1012      {
1013        if( bi )
1014        {
1015          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthY;
1016          dst[j] = ( ( a*dst[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1 << iIFshift ) - IF_INTERNAL_OFFS;
1017        }
1018        else
1019          dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
1020      }
1021      dst += dstStride;
1022    }
1023  }
1024#endif
1025}
1026
1027/**
1028 * \brief Generate motion-compensated chroma block
1029 *
1030 * \param cu       Pointer to current CU
1031 * \param refPic   Pointer to reference picture
1032 * \param partAddr Address of block within CU
1033 * \param mv       Motion vector
1034 * \param width    Width of block
1035 * \param height   Height of block
1036 * \param dstPic   Pointer to destination picture
1037 * \param bi       Flag indicating whether bipred is used
1038 */
1039Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
1040#if H_3D_ARP
1041    , Bool filterType
1042#endif
1043#if H_3D_IC
1044    , Bool bICFlag
1045#endif
1046  )
1047{
1048  Int     refStride  = refPic->getCStride();
1049  Int     dstStride  = dstPic->getCStride();
1050 
1051  Int     refOffset  = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride;
1052 
1053  Pel*    refCb     = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1054  Pel*    refCr     = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
1055 
1056  Pel* dstCb = dstPic->getCbAddr( partAddr );
1057  Pel* dstCr = dstPic->getCrAddr( partAddr );
1058 
1059  Int     xFrac  = mv->getHor() & 0x7;
1060  Int     yFrac  = mv->getVer() & 0x7;
1061  UInt    cxWidth  = width  >> 1;
1062  UInt    cxHeight = height >> 1;
1063 
1064  Int     extStride = m_filteredBlockTmp[0].getStride();
1065  Short*  extY      = m_filteredBlockTmp[0].getLumaAddr();
1066 
1067  Int filterSize = NTAPS_CHROMA;
1068 
1069  Int halfFilterSize = (filterSize>>1);
1070 
1071  if ( yFrac == 0 )
1072  {
1073    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi
1074#if H_3D_ARP
1075    , filterType
1076#endif
1077    );   
1078    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi
1079#if H_3D_ARP
1080    , filterType
1081#endif
1082    );
1083  }
1084  else if ( xFrac == 0 )
1085  {
1086    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1087#if H_3D_ARP
1088    , filterType
1089#endif
1090    );
1091    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi
1092#if H_3D_ARP
1093    , filterType
1094#endif
1095    );
1096  }
1097  else
1098  {
1099    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1100#if H_3D_ARP
1101    , filterType
1102#endif 
1103      );
1104    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1105#if H_3D_ARP
1106    , filterType
1107#endif
1108      );
1109   
1110    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
1111#if H_3D_ARP
1112    , filterType
1113#endif
1114      );
1115    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
1116#if H_3D_ARP
1117    , filterType
1118#endif
1119      );   
1120  }
1121
1122#if H_3D_IC
1123  if( bICFlag )
1124  {
1125    Int a, b, iShift, i, j;
1126    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_U ); // Cb
1127    for ( i = 0; i < cxHeight; i++ )
1128    {
1129      for ( j = 0; j < cxWidth; j++ )
1130      {
1131        if( bi )
1132        {
1133          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC;
1134          dstCb[j] = ( ( a*dstCb[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS;
1135        }
1136        else
1137          dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
1138      }
1139      dstCb += dstStride;
1140    }
1141    xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_V ); // Cr
1142    for ( i = 0; i < cxHeight; i++ )
1143    {
1144      for ( j = 0; j < cxWidth; j++ )
1145      {
1146        if( bi )
1147        {
1148          Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC;
1149          dstCr[j] = ( ( a*dstCr[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS;
1150        }
1151        else
1152          dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
1153      }
1154      dstCr += dstStride;
1155    }
1156  }
1157#endif
1158}
1159
1160Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
1161{
1162  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
1163  {
1164    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
1165  }
1166  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
1167  {
1168    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
1169  }
1170  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
1171  {
1172    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
1173  }
1174}
1175
1176// AMVP
1177Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
1178{
1179  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
1180  if( pcAMVPInfo->iN <= 1 )
1181  {
1182    rcMvPred = pcAMVPInfo->m_acMvCand[0];
1183
1184    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1185    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
1186    return;
1187  }
1188
1189  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
1190  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
1191  return;
1192}
1193
1194/** Function for deriving planar intra prediction.
1195 * \param pSrc pointer to reconstructed sample array
1196 * \param srcStride the stride of the reconstructed sample array
1197 * \param rpDst reference to pointer for the prediction sample array
1198 * \param dstStride the stride of the prediction sample array
1199 * \param width the width of the block
1200 * \param height the height of the block
1201 *
1202 * This function derives the prediction samples for planar mode (intra coding).
1203 */
1204Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
1205{
1206  assert(width == height);
1207
1208  Int k, l, bottomLeft, topRight;
1209  Int horPred;
1210  Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
1211  UInt blkSize = width;
1212  UInt offset2D = width;
1213  UInt shift1D = g_aucConvertToBit[ width ] + 2;
1214  UInt shift2D = shift1D + 1;
1215
1216  // Get left and above reference column and row
1217  for(k=0;k<blkSize+1;k++)
1218  {
1219    topRow[k] = pSrc[k-srcStride];
1220    leftColumn[k] = pSrc[k*srcStride-1];
1221  }
1222
1223  // Prepare intermediate variables used in interpolation
1224  bottomLeft = leftColumn[blkSize];
1225  topRight   = topRow[blkSize];
1226  for (k=0;k<blkSize;k++)
1227  {
1228    bottomRow[k]   = bottomLeft - topRow[k];
1229    rightColumn[k] = topRight   - leftColumn[k];
1230    topRow[k]      <<= shift1D;
1231    leftColumn[k]  <<= shift1D;
1232  }
1233
1234  // Generate prediction signal
1235  for (k=0;k<blkSize;k++)
1236  {
1237    horPred = leftColumn[k] + offset2D;
1238    for (l=0;l<blkSize;l++)
1239    {
1240      horPred += rightColumn[k];
1241      topRow[l] += bottomRow[l];
1242      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
1243    }
1244  }
1245}
1246
1247/** Function for filtering intra DC predictor.
1248 * \param pSrc pointer to reconstructed sample array
1249 * \param iSrcStride the stride of the reconstructed sample array
1250 * \param rpDst reference to pointer for the prediction sample array
1251 * \param iDstStride the stride of the prediction sample array
1252 * \param iWidth the width of the block
1253 * \param iHeight the height of the block
1254 *
1255 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
1256 */
1257Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
1258{
1259  Pel* pDst = rpDst;
1260  Int x, y, iDstStride2, iSrcStride2;
1261
1262  // boundary pixels processing
1263  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
1264
1265  for ( x = 1; x < iWidth; x++ )
1266  {
1267    pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
1268  }
1269
1270  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
1271  {
1272    pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
1273  }
1274
1275  return;
1276}
1277#if H_3D_IC
1278/** Function for deriving the position of first non-zero binary bit of a value
1279 * \param x input value
1280 *
1281 * This function derives the position of first non-zero binary bit of a value
1282 */
1283Int GetMSB( UInt x )
1284{
1285  Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1;
1286
1287  while( x > 1 )
1288  {
1289    bits >>= 1;
1290    y = x >> bits;
1291
1292    if( y )
1293    {
1294      x = y;
1295      iMSB += bits;
1296    }
1297  }
1298
1299  iMSB+=y;
1300
1301  return iMSB;
1302}
1303
1304/** Function for counting leading number of zeros/ones
1305 * \param x input value
1306 \ This function counts leading number of zeros for positive numbers and
1307 \ leading number of ones for negative numbers. This can be implemented in
1308 \ single instructure cycle on many processors.
1309 */
1310
1311Short CountLeadingZerosOnes (Short x)
1312{
1313  Short clz;
1314  Short i;
1315
1316  if(x == 0)
1317  {
1318    clz = 0;
1319  }
1320  else
1321  {
1322    if (x == -1)
1323    {
1324      clz = 15;
1325    }
1326    else
1327    {
1328      if(x < 0)
1329      {
1330        x = ~x;
1331      }
1332      clz = 15;
1333      for(i = 0;i < 15;++i)
1334      {
1335        if(x) 
1336        {
1337          clz --;
1338        }
1339        x = x >> 1;
1340      }
1341    }
1342  }
1343  return clz;
1344}
1345
1346/** Function for deriving LM illumination compensation.
1347 */
1348Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, Int &iShift, TextType eType )
1349{
1350  TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
1351  Pel *pRec = NULL, *pRef = NULL;
1352  UInt uiWidth, uiHeight, uiTmpPartIdx;
1353  Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride();
1354  Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride();
1355  Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer;
1356
1357  iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
1358  iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]];
1359  iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 );
1360  iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 );
1361  iRefX   = iCUPelX + iHor;
1362  iRefY   = iCUPelY + iVer;
1363  if( eType != TEXT_LUMA )
1364  {
1365    iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 );
1366    iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 );
1367  }
1368  uiWidth  = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 )  : ( pcCU->getWidth( 0 )  >> 1 );
1369  uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 );
1370
1371  Int i, j, iCountShift = 0;
1372
1373  // LLS parameters estimation -->
1374
1375  Int x = 0, y = 0, xx = 0, xy = 0;
1376
1377  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 )
1378  {
1379    iRefOffset = iHor + iVer * iRefStride - iRefStride;
1380    if( eType == TEXT_LUMA )
1381    {
1382      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1383      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
1384    }
1385    else if( eType == TEXT_CHROMA_U )
1386    {
1387      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1388      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
1389    }
1390    else
1391    {
1392      assert( eType == TEXT_CHROMA_V );
1393      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1394      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
1395    }
1396
1397    for( j = 0; j < uiWidth; j++ )
1398    {
1399      x += pRef[j];
1400      y += pRec[j];
1401      xx += pRef[j] * pRef[j];
1402      xy += pRef[j] * pRec[j];
1403    }
1404    iCountShift += g_aucConvertToBit[ uiWidth ] + 2;
1405  }
1406
1407
1408  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 )
1409  {
1410    iRefOffset = iHor + iVer * iRefStride - 1;
1411    if( eType == TEXT_LUMA )
1412    {
1413      pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1414      pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1415    }
1416    else if( eType == TEXT_CHROMA_U )
1417    {
1418      pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1419      pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1420    }
1421    else
1422    {
1423      assert( eType == TEXT_CHROMA_V );
1424      pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
1425      pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
1426    }
1427
1428    for( i = 0; i < uiHeight; i++ )
1429    {
1430      x += pRef[0];
1431      y += pRec[0];
1432      xx += pRef[0] * pRef[0];
1433      xy += pRef[0] * pRec[0];
1434
1435      pRef += iRefStride;
1436      pRec += iRecStride;
1437    }
1438    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 );
1439  }
1440
1441  Int iTempShift = ( ( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC ) + g_aucConvertToBit[ uiWidth ] + 3 - 15;
1442
1443  if( iTempShift > 0 )
1444  {
1445    x  = ( x +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
1446    y  = ( y +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
1447    xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
1448    xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
1449    iCountShift -= iTempShift;
1450  }
1451
1452  iShift = 13;
1453
1454  if( iCountShift == 0 )
1455  {
1456    a = 1;
1457    b = 0;
1458    iShift = 0;
1459  }
1460  else
1461  {
1462    Int a1 = ( xy << iCountShift ) - y * x;
1463    Int a2 = ( xx << iCountShift ) - x * x;             
1464
1465    {
1466      const Int iShiftA2 = 6;
1467      const Int iShiftA1 = 15;
1468      const Int iAccuracyShift = 15;
1469
1470      Int iScaleShiftA2 = 0;
1471      Int iScaleShiftA1 = 0;
1472      Int a1s = a1;
1473      Int a2s = a2;
1474
1475      iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1;
1476      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; 
1477
1478      if( iScaleShiftA1 < 0 )
1479      {
1480        iScaleShiftA1 = 0;
1481      }
1482
1483      if( iScaleShiftA2 < 0 )
1484      {
1485        iScaleShiftA2 = 0;
1486      }
1487
1488      Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
1489
1490      a2s = a2 >> iScaleShiftA2;
1491
1492      a1s = a1 >> iScaleShiftA1;
1493
1494      if (a2s >= 1)
1495      {
1496        a = a1s * m_uiaShift[ a2s - 1];
1497      }
1498      else
1499      {
1500        a = 0;
1501      }
1502
1503      if( iScaleShiftA < 0 )
1504      {
1505        a = a << -iScaleShiftA;
1506      }
1507      else
1508      {
1509        a = a >> iScaleShiftA;
1510      }
1511
1512      a = Clip3( -( 1 << 15 ), ( 1 << 15 ) - 1, a ); 
1513
1514      Int minA = -(1 << (6));
1515      Int maxA = (1 << 6) - 1;
1516      if( a <= maxA && a >= minA )
1517      {
1518        // do nothing
1519      }
1520      else
1521      {
1522        Short n = CountLeadingZerosOnes( a );
1523        a = a >> (9-n);
1524        iShift -= (9-n);
1525      }
1526
1527      b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
1528    }
1529  }   
1530}
1531#endif
1532
1533#if H_3D_VSP
1534
1535#if NTT_VSP_COMMON_E0207_E0208
1536// not fully support iRatioTxtPerDepth* != 1
1537Void TComPrediction::xGetVirtualDepth( TComDataCU *pcCU, TComPicYuv *pcPicRefDepth, TComMv *pcMv, UInt partAddr, Int iWidth, Int iHeight, TComYuv *pcYuvDepth, Int iRatioTxtPerDepthX, Int iRatioTxtPerDepthY )
1538{
1539  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
1540  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
1541
1542  Int refDepStride = pcPicRefDepth->getStride();
1543
1544#if NTT_VSP_VECTOR_CLIP_E0208
1545
1546  Int refDepOffset = ( (pcMv->getHor()+2) >> 2 ) + ( (pcMv->getVer()+2) >> 2 ) * refDepStride;
1547
1548#if 1 // // iRatioTxtPerDepthX==1 && iRatioTxtPerDepthY==1
1549  Pel *refDepth    = pcPicRefDepth->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + partAddr );
1550#else
1551  Pel *refDepth    = pcPicRefDepth->getLumaAddr( );
1552  Int iPosX, iPosY;
1553  pcCU->getPic()->getPicYuvRec()->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + partAddr, iPosX, iPosY ); // top-left position in texture
1554  iPosX /= iRatioTxtPerDepthX; // texture position -> depth postion
1555  iPosY /= iRatioTxtPerDepthY;
1556  refDepOffset += iPosX + iPosY * refDepStride;
1557
1558  iWidth  /= iRatioTxtPerDepthX; // texture size -> depth size
1559  iHeight /= iRatioTxtPerDepthY;
1560#endif
1561
1562  refDepth += refDepOffset;
1563
1564#else // NTT_VSP_VECTOR_CLIP_E0208
1565
1566  Int widthDepth = pcPicRefDepth->getWidth();
1567  Int heightDepth = pcPicRefDepth->getHeight();
1568  Int iPosX, iPosY;
1569  pcCU->getPic()->getPicYuvRec()->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + partAddr, iPosX, iPosY ); // top-left position in texture
1570  iPosX /= iRatioTxtPerDepthX; // texture position -> depth postion
1571  iPosY /= iRatioTxtPerDepthY;
1572 
1573  iPosX = Clip3(0, widthDepth-iWidth,   iPosX + ((pcMv->getHor()+2)>>2));
1574  iPosY = Clip3(0, heightDepth-iHeight, iPosY + ((pcMv->getVer()+2)>>2));
1575 
1576  Pel *refDepth  = pcPicRefDepth->getLumaAddr() + iPosX + iPosY * refDepStride;
1577
1578#endif // NTT_VSP_VECTOR_CLIP_E0208
1579
1580  Int depStride = pcYuvDepth->getStride();
1581  Pel *depth = pcYuvDepth->getLumaAddr();
1582
1583#if NTT_VSP_ADAPTIVE_SPLIT_E0207
1584
1585  if( iWidth<8 || iHeight<8 )
1586  { // no split
1587    Int rightOffset = iWidth - 1;
1588    Int depStrideBlock = depStride * nTxtPerDepthY;
1589    Pel *refDepthTop = refDepth;
1590    Pel *refDepthBot = refDepthTop + (iHeight-1)*refDepStride;
1591
1592    Pel maxDepth = refDepthTop[0] > refDepthBot[0] ? refDepthTop[0] : refDepthBot[0];
1593    if( maxDepth < refDepthTop[rightOffset] ) maxDepth = refDepthTop[rightOffset];
1594    if( maxDepth < refDepthBot[rightOffset] ) maxDepth = refDepthBot[rightOffset];
1595
1596    for( Int sY=0; sY<iHeight; sY+=nTxtPerDepthY )
1597    {
1598      for( Int sX=0; sX<iWidth; sX+=nTxtPerDepthX )
1599      {
1600        depth[sX] = maxDepth;
1601      }
1602      depth += depStrideBlock;
1603    }
1604  }
1605  else
1606  { // split to 4x8, or 8x4
1607    Int blocksize    = 8;
1608    Int subblocksize = 4;
1609    Int depStrideBlock = depStride * blocksize;
1610    Pel *depthTmp = NULL;
1611    Int depStrideTmp = depStride * nTxtPerDepthY;
1612    Int offset[4] = { 0, subblocksize-1, subblocksize, blocksize-1 };
1613    Pel *refDepthTmp[4] = { NULL, NULL, NULL, NULL };
1614    Pel repDepth4x8[2] = {0, 0};
1615    Pel repDepth8x4[2] = {0, 0};
1616
1617    Int refDepStrideBlock    = refDepStride * blocksize;
1618    Int refDepStrideSubBlock = refDepStride * subblocksize;
1619
1620    refDepthTmp[0] = refDepth;
1621    refDepthTmp[2] = refDepthTmp[0] + refDepStrideSubBlock;
1622    refDepthTmp[1] = refDepthTmp[2] - refDepStride;
1623    refDepthTmp[3] = refDepthTmp[1] + refDepStrideSubBlock;
1624
1625    for( Int y=0; y<iHeight; y+=blocksize )
1626    {
1627      for( Int x=0; x<iWidth; x+=blocksize )
1628      {
1629        Bool ULvsBR = false, URvsBL = false;
1630
1631        ULvsBR = refDepthTmp[0][x+offset[0]] < refDepthTmp[3][x+offset[3]];
1632        URvsBL = refDepthTmp[0][x+offset[3]] < refDepthTmp[3][x+offset[0]];
1633
1634        if( ULvsBR ^ URvsBL )
1635        { // 4x8
1636          repDepth4x8[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[1]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[1]];
1637          if( repDepth4x8[0] < refDepthTmp[3][x+offset[0]] ) repDepth4x8[0] = refDepthTmp[3][x+offset[0]];
1638          if( repDepth4x8[0] < refDepthTmp[3][x+offset[1]] ) repDepth4x8[0] = refDepthTmp[3][x+offset[1]];
1639          repDepth4x8[1] = refDepthTmp[0][x+offset[2]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[2]] : refDepthTmp[0][x+offset[3]];
1640          if( repDepth4x8[1] < refDepthTmp[3][x+offset[2]] ) repDepth4x8[1] = refDepthTmp[3][x+offset[2]];
1641          if( repDepth4x8[1] < refDepthTmp[3][x+offset[3]] ) repDepth4x8[1] = refDepthTmp[3][x+offset[3]];
1642
1643          depthTmp = &depth[x];
1644          for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY )
1645          {
1646            for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX )
1647            {
1648              depthTmp[sX] = repDepth4x8[0];
1649            }
1650            depthTmp += depStrideTmp;
1651          }
1652          depthTmp = &depth[x+subblocksize];
1653          for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY )
1654          {
1655            for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX )
1656            {
1657              depthTmp[sX] = repDepth4x8[1];
1658            }
1659            depthTmp += depStrideTmp;
1660          }
1661        }
1662        else
1663        { // 8x4
1664          repDepth8x4[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[3]];
1665          if( repDepth8x4[0] < refDepthTmp[1][x+offset[0]] ) repDepth8x4[0] = refDepthTmp[1][x+offset[0]];
1666          if( repDepth8x4[0] < refDepthTmp[1][x+offset[3]] ) repDepth8x4[0] = refDepthTmp[1][x+offset[3]];
1667          repDepth8x4[1] = refDepthTmp[2][x+offset[0]] > refDepthTmp[2][x+offset[3]] ? refDepthTmp[2][x+offset[0]] : refDepthTmp[2][x+offset[3]];
1668          if( repDepth8x4[1] < refDepthTmp[3][x+offset[0]] ) repDepth8x4[1] = refDepthTmp[3][x+offset[0]];
1669          if( repDepth8x4[1] < refDepthTmp[3][x+offset[3]] ) repDepth8x4[1] = refDepthTmp[3][x+offset[3]];
1670         
1671          depthTmp = &depth[x];
1672          for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY )
1673          {
1674            for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX )
1675            {
1676              depthTmp[sX] = repDepth8x4[0];
1677            }
1678            depthTmp += depStrideTmp;
1679          }
1680          for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY )
1681          {
1682            for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX )
1683            {
1684              depthTmp[sX] = repDepth8x4[1];
1685            }
1686            depthTmp += depStrideTmp;
1687          }
1688        }
1689      }
1690      refDepthTmp[0] += refDepStrideBlock;
1691      refDepthTmp[1] += refDepStrideBlock;
1692      refDepthTmp[2] += refDepStrideBlock;
1693      refDepthTmp[3] += refDepStrideBlock;
1694      depth       += depStrideBlock;
1695    }
1696  }
1697
1698#else // NTT_VSP_ADAPTIVE_SPLIT_E0207
1699
1700  Int rightOffset = nTxtPerDepthX - 1;
1701  Int depStrideBlock = depStride * nTxtPerDepthY;
1702  Int refDepStrideBlock = refDepStride * nTxtPerDepthY;
1703  Pel *refDepthTop = refDepth;
1704  Pel *refDepthBot = refDepthTop + (nTxtPerDepthY-1)*refDepStride;
1705
1706  for( Int y=0; y<iHeight; y+= nTxtPerDepthY )
1707  {
1708    for( Int x=0; x<iWidth; x+=nTxtPerDepthX )
1709    {
1710      Pel maxDepth = refDepthTop[x] > refDepthBot[x] ? refDepthTop[x] : refDepthBot[x]; 
1711
1712      if( maxDepth < refDepthTop[x+rightOffset] ) maxDepth = refDepthTop[x+rightOffset];
1713      if( maxDepth < refDepthBot[x+rightOffset] ) maxDepth = refDepthBot[x+rightOffset];
1714
1715      depth[x] = maxDepth;
1716
1717    }
1718    refDepthTop += refDepStrideBlock;
1719    refDepthBot += refDepStrideBlock;
1720    depth       += depStrideBlock;
1721  }
1722
1723#endif // NTT_VSP_ADAPTIVE_SPLIT_E0207
1724}
1725
1726Void TComPrediction::xPredInterLumaBlkFromDM( TComDataCU *pcCU, TComPicYuv *pcPicRef, TComYuv *pcYuvDepth, Int* pShiftLUT, TComMv *pcMv, UInt partAddr, Int iWidth, Int iHeight, Bool bIsDepth, TComYuv *&pcYuvDst, Bool bIsBi )
1727{
1728  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE;
1729  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE;
1730 
1731  Int refStride = pcPicRef->getStride();
1732  Int dstStride = pcYuvDst->getStride();
1733  Int depStride = pcYuvDepth->getStride();
1734  Int refStrideBlock = refStride  * nTxtPerDepthY;
1735  Int dstStrideBlock = dstStride * nTxtPerDepthY;
1736  Int depStrideBlock = depStride * nTxtPerDepthY;
1737
1738  Pel *ref    = pcPicRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + partAddr );
1739  Pel *dst    = pcYuvDst->getLumaAddr(partAddr);
1740  Pel *depth  = pcYuvDepth->getLumaAddr();
1741 
1742#if !(NTT_VSP_DC_BUGFIX_E0208)
1743  Int widthLuma = pcPicRef->getWidth();
1744  Int iPosX, iPosY;
1745  pcCU->getPic()->getPicYuvRec()->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + partAddr, iPosX, iPosY ); // top-left position in texture
1746#endif
1747
1748#if H_3D_VSP_BLOCKSIZE == 1
1749#if H_3D_VSP_CONSTRAINED
1750  //get LUT based horizontal reference range
1751  Int range = xGetConstrainedSize(iWidth, iHeight);
1752
1753  // The minimum depth value
1754  Int minRelativePos = MAX_INT;
1755  Int maxRelativePos = MIN_INT;
1756
1757  Pel* depthTemp, *depthInitial=depth;
1758  for (Int yTxt = 0; yTxt < iHeight; yTxt++)
1759  {
1760    for (Int xTxt = 0; xTxt < iWidth; xTxt++)
1761    {
1762      if (depthPosX+xTxt < widthDepth)
1763        depthTemp = depthInitial + xTxt;
1764      else
1765        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
1766
1767      Int disparity = pShiftLUT[ *depthTemp ]; // << iShiftPrec;
1768      Int disparityInt = disparity >> 2;
1769
1770      if( disparity <= 0)
1771      {
1772        if (minRelativePos > disparityInt+xTxt)
1773            minRelativePos = disparityInt+xTxt;
1774      }
1775      else
1776      {
1777        if (maxRelativePos < disparityInt+xTxt)
1778            maxRelativePos = disparityInt+xTxt;
1779      }
1780    }
1781    if (depthPosY+yTxt < heightDepth)
1782      depthInitial = depthInitial + depStride;
1783  }
1784
1785  Int disparity_tmp = pShiftLUT[ *depth ]; // << iShiftPrec;
1786  if (disparity_tmp <= 0)
1787    maxRelativePos = minRelativePos + range -1 ;
1788  else
1789    minRelativePos = maxRelativePos - range +1 ;
1790#endif
1791#endif // H_3D_VSP_BLOCKSIZE == 1
1792
1793  TComMv cDv(0, 0);
1794
1795  for ( Int yTxt = 0; yTxt < iHeight; yTxt += nTxtPerDepthY )
1796  {
1797    for ( Int xTxt = 0; xTxt < iWidth; xTxt += nTxtPerDepthX )
1798    {
1799      Pel repDepth = depth[ xTxt ];
1800      assert( repDepth >= 0 && repDepth <= 255 );
1801
1802      Int disparity = pShiftLUT[ repDepth ]; // remove << iShiftPrec ??
1803      Int xFrac = disparity & 0x3;
1804
1805#if NTT_VSP_DC_BUGFIX_E0208
1806
1807      cDv.setHor( disparity );
1808      pcCU->clipMv( cDv );
1809
1810      Int refOffset = xTxt + (cDv.getHor() >> 2);
1811     
1812#if H_3D_VSP_CONSTRAINED
1813      if(refOffset<minRelativePos || refOffset>maxRelativePos)
1814        xFrac = 0;
1815      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
1816#endif
1817
1818      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
1819      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bIsBi );
1820
1821#else // NTT_VSP_DC_BUGFIX_E0208
1822
1823      for( Int j=0; j < nTxtPerDepthX; j++ )
1824      {
1825        Int refOffset = xTxt+j + (disparity >> 2);
1826#if H_3D_VSP_CONSTRAINED
1827        if(refOffset<minRelativePos || refOffset>maxRelativePos)
1828          xFrac = 0;
1829        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
1830#endif
1831        Int absX  = iPosX + refOffset;
1832
1833        if (xFrac == 0)
1834          absX = Clip3(0, widthLuma-1, absX);
1835        else
1836          absX = Clip3(4, widthLuma-5, absX);
1837
1838        refOffset = absX - iPosX;
1839        assert( ref[refOffset] >= 0 && ref[refOffset] <= 255 );
1840       
1841        m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt+j], dstStride, 1, nTxtPerDepthY, xFrac, !bIsBi );
1842      }
1843
1844#endif // NTT_VSP_DC_BUGFIX_E0208
1845
1846    }
1847    ref   += refStrideBlock;
1848    dst   += dstStrideBlock;
1849    depth += depStrideBlock;
1850  }
1851
1852}
1853
1854Void TComPrediction::xPredInterChromaBlkFromDM  ( TComDataCU *pcCU, TComPicYuv *pcPicRef, TComYuv *pcYuvDepth, Int* pShiftLUT, TComMv *pcMv, UInt partAddr, Int iWidth, Int iHeight, Bool bIsDepth, TComYuv *&pcYuvDst, Bool bIsBi )
1855{
1856#if (H_3D_VSP_BLOCKSIZE==1)
1857  Int nTxtPerDepthX = 1;
1858  Int nTxtPerDepthY = 1;
1859#else
1860  Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE >> 1;
1861  Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE >> 1;
1862#endif
1863
1864  Int refStride = pcPicRef->getCStride();
1865  Int dstStride = pcYuvDst->getCStride();
1866  Int depStride = pcYuvDepth->getStride();
1867  Int refStrideBlock = refStride * nTxtPerDepthY;
1868  Int dstStrideBlock = dstStride * nTxtPerDepthY;
1869  Int depStrideBlock = depStride * (nTxtPerDepthY<<1);
1870
1871  Pel *refCb  = pcPicRef->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + partAddr );
1872  Pel *refCr  = pcPicRef->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + partAddr );
1873  Pel *dstCb  = pcYuvDst->getCbAddr(partAddr);
1874  Pel *dstCr  = pcYuvDst->getCrAddr(partAddr);
1875  Pel *depth  = pcYuvDepth->getLumaAddr();
1876
1877#if 0 // not necessary??
1878  if (bIsDepth)
1879  {
1880    Pel val = 128;
1881    iHeight >>=1; // luma to chroma
1882    iWidth >>=1;
1883    if ( bIsBi )
1884    {
1885      Int shift = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement );
1886      val = (val << shift) - (Pel)IF_INTERNAL_OFFS;
1887    }
1888    for (Int y = 0; y < iHeight; y++)
1889    {
1890      for (Int x = 0; x < iWidth; x++)
1891      {
1892        dstCb[x] = val;
1893        dstCr[x] = val;
1894      }
1895      dstCb += dstStride;
1896      dstCr += dstStride;
1897    }
1898    return;
1899  }
1900#endif
1901
1902#if !(NTT_VSP_DC_BUGFIX_E0208)
1903  Int widthChroma = pcPicRef->getWidth() >> 1;
1904  Int iPosX, iPosY;
1905  pcCU->getPic()->getPicYuvRec()->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + partAddr, iPosX, iPosY ); // top-left position in texture
1906  iPosX >>= 1;
1907  iPosY >>= 1;
1908#endif
1909 
1910#if H_3D_VSP_BLOCKSIZE == 1
1911#if H_3D_VSP_CONSTRAINED
1912  //get LUT based horizontal reference range
1913  Int range = xGetConstrainedSize(iWidth, iHeight, false);
1914
1915  // The minimum depth value
1916  Int minRelativePos = MAX_INT;
1917  Int maxRelativePos = MIN_INT;
1918
1919  Int depthTmp;
1920  for (Int yTxt=0; yTxt<iHeight; yTxt++)
1921  {
1922    for (Int xTxt=0; xTxt<iWidth; xTxt++)
1923    {
1924      depthTmp = m_pDepthBlock[xTxt+yTxt*dW];
1925      Int disparity = pShiftLUT[ depthTmp ]; // << iShiftPrec;
1926      Int disparityInt = disparity >> 3;//in chroma resolution
1927
1928      if (disparityInt < 0)
1929      {
1930        if (minRelativePos > disparityInt+xTxt)
1931            minRelativePos = disparityInt+xTxt;
1932      }
1933      else
1934      {
1935        if (maxRelativePos < disparityInt+xTxt)
1936            maxRelativePos = disparityInt+xTxt;
1937      }
1938    }
1939  }
1940
1941  depthTmp = m_pDepthBlock[0];
1942  Int disparity_tmp = pShiftLUT[ depthTmp ]; // << iShiftPrec;
1943  if ( disparity_tmp < 0 )
1944    maxRelativePos = minRelativePos + range - 1;
1945  else
1946    minRelativePos = maxRelativePos - range + 1;
1947
1948#endif // H_3D_VSP_CONSTRAINED
1949#endif // H_3D_VSP_BLOCKSIZE == 1
1950
1951  TComMv cDv(0, 0);
1952  // luma size -> chroma size
1953  iHeight >>= 1;
1954  iWidth  >>= 1;
1955
1956  for ( Int yTxt = 0; yTxt < iHeight; yTxt += nTxtPerDepthY )
1957  {
1958    for ( Int xTxt = 0; xTxt < iWidth; xTxt += nTxtPerDepthX )
1959    {
1960      Pel repDepth = depth[ xTxt<<1 ];
1961      assert( repDepth >= 0 && repDepth <= 255 );
1962
1963      Int disparity = pShiftLUT[ repDepth ]; // remove << iShiftPrec;
1964      Int xFrac = disparity & 0x7;
1965     
1966#if NTT_VSP_DC_BUGFIX_E0208
1967
1968      cDv.setHor( disparity );
1969      pcCU->clipMv( cDv );
1970
1971      Int refOffset = xTxt + (cDv.getHor() >> 3);
1972
1973#if H_3D_VSP_CONSTRAINED
1974      if(refOffset<minRelativePos || refOffset>maxRelativePos)
1975        xFrac = 0;
1976      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
1977#endif
1978
1979      assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
1980      assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
1981
1982      m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bIsBi );
1983      m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bIsBi );
1984
1985#else // NTT_VSP_DC_BUGFIX_E0208
1986     
1987      for( Int j=0; j < nTxtPerDepthX; j++ )
1988      {
1989        Int refOffset = xTxt+j + (disparity >> 3);
1990#if H_3D_VSP_CONSTRAINED
1991        if(refOffset<minRelativePos || refOffset>maxRelativePos)
1992          xFrac = 0;
1993        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
1994#endif
1995        Int absX  = iPosX + refOffset;
1996
1997        if (xFrac == 0)
1998          absX = Clip3(0, widthChroma-1, absX);
1999        else
2000          absX = Clip3(4, widthChroma-5, absX);
2001
2002        refOffset = absX - iPosX;
2003        assert( refCb[refOffset] >= 0 && refCb[refOffset] <= 255 );
2004        assert( refCr[refOffset] >= 0 && refCr[refOffset] <= 255 );
2005
2006        m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt+j], dstStride, 1, nTxtPerDepthY, xFrac, !bIsBi );
2007        m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt+j], dstStride, 1, nTxtPerDepthY, xFrac, !bIsBi );
2008      }
2009
2010#endif // NTT_VSP_DC_BUGFIX_E0208
2011    }
2012    refCb += refStrideBlock;
2013    refCr += refStrideBlock;
2014    dstCb += dstStrideBlock;
2015    dstCr += dstStrideBlock;
2016    depth += depStrideBlock;
2017  }
2018
2019}
2020#else // NTT_VSP_COMMON_E0207_E0208
2021
2022// Input:
2023// refPic: Ref picture. Full picture, with padding
2024// posX, posY:     PU position, texture
2025// sizeX, sizeY: PU size
2026// partAddr: z-order index
2027// dv: disparity vector. derived from neighboring blocks
2028//
2029// Output: dstPic, PU predictor 64x64
2030Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr,Int posX, Int posY
2031                                            , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi )
2032{
2033  Int widthLuma;
2034  Int heightLuma;
2035
2036  if (isDepth)
2037  {
2038    widthLuma   =  pPicBaseDepth->getWidth();
2039    heightLuma  =  pPicBaseDepth->getHeight();
2040  }
2041  else
2042  {
2043    widthLuma   =  refPic->getWidth();
2044    heightLuma  =  refPic->getHeight();
2045  }
2046
2047#if H_3D_VSP_BLOCKSIZE != 1
2048  Int widthDepth  = pPicBaseDepth->getWidth();
2049  Int heightDepth = pPicBaseDepth->getHeight();
2050#endif
2051
2052#if H_3D_VSP_CONSTRAINED
2053  Int widthDepth  = pPicBaseDepth->getWidth();
2054  Int heightDepth = pPicBaseDepth->getHeight();
2055#endif
2056
2057  Int nTxtPerDepthX = widthLuma  / ( pPicBaseDepth->getWidth() );  // texture pixel # per depth pixel
2058  Int nTxtPerDepthY = heightLuma / ( pPicBaseDepth->getHeight() );
2059
2060  Int refStride = refPic->getStride();
2061  Int dstStride = dstPic->getStride();
2062  Int depStride =  pPicBaseDepth->getStride();
2063  Int depthPosX = Clip3(0,   widthLuma - sizeX,  (posX/nTxtPerDepthX) + ((dv->getHor()+2)>>2));
2064  Int depthPosY = Clip3(0,   heightLuma- sizeY,  (posY/nTxtPerDepthY) + ((dv->getVer()+2)>>2));
2065  Pel *ref    = refPic->getLumaAddr() + posX + posY * refStride;
2066  Pel *dst    = dstPic->getLumaAddr(partAddr);
2067  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;
2068
2069#if H_3D_VSP_BLOCKSIZE != 1
2070#if H_3D_VSP_BLOCKSIZE == 2
2071  Int  dW = sizeX>>1;
2072  Int  dH = sizeY>>1;
2073#endif
2074#if H_3D_VSP_BLOCKSIZE == 4
2075  Int  dW = sizeX>>2;
2076  Int  dH = sizeY>>2;
2077#endif
2078  {
2079    Pel* depthi = depth;
2080    for (Int j = 0; j < dH; j++)
2081    {
2082      for (Int i = 0; i < dW; i++)
2083      {
2084        Pel* depthTmp;
2085#if H_3D_VSP_BLOCKSIZE == 2
2086        if (depthPosX + (i<<1) < widthDepth)
2087          depthTmp = depthi + (i << 1);
2088        else
2089          depthTmp = depthi + (widthDepth - depthPosX - 1);
2090#endif
2091#if H_3D_VSP_BLOCKSIZE == 4
2092        if (depthPosX + (i<<2) < widthDepth)
2093          depthTmp = depthi + (i << 2);
2094        else
2095          depthTmp = depthi + (widthDepth - depthPosX - 1);
2096#endif
2097        Int maxV = 0;
2098        for (Int blockj = 0; blockj < H_3D_VSP_BLOCKSIZE; blockj+=(H_3D_VSP_BLOCKSIZE-1))
2099        {
2100          Int iX = 0;
2101          for (Int blocki = 0; blocki < H_3D_VSP_BLOCKSIZE; blocki+=(H_3D_VSP_BLOCKSIZE-1))
2102          {
2103            if (maxV < depthTmp[iX])
2104              maxV = depthTmp[iX];
2105#if H_3D_VSP_BLOCKSIZE == 2
2106            if (depthPosX + (i<<1) + blocki < widthDepth - 1)
2107#else // H_3D_VSP_BLOCKSIZE == 4
2108            if (depthPosX + (i<<2) + blocki < widthDepth - 1)
2109#endif
2110              iX = (H_3D_VSP_BLOCKSIZE-1);
2111          }
2112#if H_3D_VSP_BLOCKSIZE == 2
2113          if (depthPosY + (j<<1) + blockj < heightDepth - 1)
2114#else // H_3D_VSP_BLOCKSIZE == 4
2115          if (depthPosY + (j<<2) + blockj < heightDepth - 1)
2116#endif
2117            depthTmp += depStride * (H_3D_VSP_BLOCKSIZE-1);
2118        }
2119        m_pDepthBlock[i+j*dW] = maxV;
2120      } // end of i < dW
2121#if H_3D_VSP_BLOCKSIZE == 2
2122      if (depthPosY + ((j+1)<<1) < heightDepth)
2123        depthi += (depStride << 1);
2124      else
2125        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
2126#endif
2127#if H_3D_VSP_BLOCKSIZE == 4
2128      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
2129        depthi += (depStride << 2);
2130      else
2131        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
2132#endif
2133    }
2134  }
2135#endif // H_3D_VSP_BLOCKSIZE != 1
2136
2137#if H_3D_VSP_BLOCKSIZE == 1
2138#if H_3D_VSP_CONSTRAINED
2139  //get LUT based horizontal reference range
2140  Int range = xGetConstrainedSize(sizeX, sizeY);
2141
2142  // The minimum depth value
2143  Int minRelativePos = MAX_INT;
2144  Int maxRelativePos = MIN_INT;
2145
2146  Pel* depthTemp, *depthInitial=depth;
2147  for (Int yTxt = 0; yTxt < sizeY; yTxt++)
2148  {
2149    for (Int xTxt = 0; xTxt < sizeX; xTxt++)
2150    {
2151      if (depthPosX+xTxt < widthDepth)
2152        depthTemp = depthInitial + xTxt;
2153      else
2154        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
2155
2156      Int disparity = pShiftLUT[ *depthTemp ]; // << iShiftPrec;
2157      Int disparityInt = disparity >> 2;
2158
2159      if( disparity <= 0)
2160      {
2161        if (minRelativePos > disparityInt+xTxt)
2162            minRelativePos = disparityInt+xTxt;
2163      }
2164      else
2165      {
2166        if (maxRelativePos < disparityInt+xTxt)
2167            maxRelativePos = disparityInt+xTxt;
2168      }
2169    }
2170    if (depthPosY+yTxt < heightDepth)
2171      depthInitial = depthInitial + depStride;
2172  }
2173
2174  Int disparity_tmp = pShiftLUT[ *depth ]; // << iShiftPrec;
2175  if (disparity_tmp <= 0)
2176    maxRelativePos = minRelativePos + range -1 ;
2177  else
2178    minRelativePos = maxRelativePos - range +1 ;
2179#endif
2180#endif // H_3D_VSP_BLOCKSIZE == 1
2181
2182#if H_3D_VSP_BLOCKSIZE != 1
2183  Int yDepth = 0;
2184#endif
2185  for ( Int yTxt = 0; yTxt < sizeY; yTxt += nTxtPerDepthY )
2186  {
2187    for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth++ )
2188    {
2189      Pel repDepth = 0; // to store the depth value used for warping
2190#if H_3D_VSP_BLOCKSIZE == 1
2191      repDepth = depth[xDepth];
2192#endif
2193#if H_3D_VSP_BLOCKSIZE == 2
2194      repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW];
2195#endif
2196#if H_3D_VSP_BLOCKSIZE == 4
2197      repDepth = m_pDepthBlock[(xTxt>>2) + (yTxt>>2)*dW];
2198#endif
2199
2200      assert( repDepth >= 0 && repDepth <= 255 );
2201      Int disparity = pShiftLUT[ repDepth ]; // remove << iShiftPrec ??
2202      Int refOffset = xTxt + (disparity >> 2);
2203      Int xFrac = disparity & 0x3;
2204#if H_3D_VSP_CONSTRAINED
2205      if(refOffset<minRelativePos || refOffset>maxRelativePos)
2206        xFrac = 0;
2207      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
2208#endif
2209      Int absX  = posX + refOffset;
2210
2211      if (xFrac == 0)
2212        absX = Clip3(0, widthLuma-1, absX);
2213      else
2214        absX = Clip3(4, widthLuma-5, absX);
2215
2216      refOffset = absX - posX;
2217
2218      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
2219      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi );
2220    }
2221    ref   += refStride*nTxtPerDepthY;
2222    dst   += dstStride*nTxtPerDepthY;
2223    depth += depStride;
2224#if H_3D_VSP_BLOCKSIZE != 1
2225    yDepth++;
2226#endif
2227
2228  }
2229}
2230
2231Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv*dv, UInt partAddr, Int posX, Int posY
2232                                               , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi)
2233{
2234  Int refStride = refPic->getCStride();
2235  Int dstStride = dstPic->getCStride();
2236  Int depStride = pPicBaseDepth->getStride();
2237
2238  Int widthChroma, heightChroma;
2239  if( isDepth)
2240  {
2241     widthChroma   = pPicBaseDepth->getWidth()>>1;
2242     heightChroma  = pPicBaseDepth->getHeight()>>1;
2243  }
2244  else
2245  {
2246     widthChroma   = refPic->getWidth()>>1;
2247     heightChroma  = refPic->getHeight()>>1;
2248  }
2249
2250  // Below is only for Texture chroma component
2251
2252  Int widthDepth  = pPicBaseDepth->getWidth();
2253  Int heightDepth = pPicBaseDepth->getHeight();
2254
2255  Int nTxtPerDepthX, nTxtPerDepthY;  // Number of texture samples per one depth sample
2256  Int nDepthPerTxtX, nDepthPerTxtY;  // Number of depth samples per one texture sample
2257
2258  Int depthPosX;  // Starting position in depth image
2259  Int depthPosY;
2260
2261  if ( widthChroma > widthDepth )
2262  {
2263    nTxtPerDepthX = widthChroma / widthDepth;
2264    nDepthPerTxtX = 1;
2265    depthPosX = posX / nTxtPerDepthX + ((dv->getHor()+2)>>2);
2266  }
2267  else
2268  {
2269    nTxtPerDepthX = 1;
2270    nDepthPerTxtX = widthDepth / widthChroma;
2271    depthPosX = posX * nDepthPerTxtX + ((dv->getHor()+2)>>2);
2272  }
2273  depthPosX = Clip3(0, widthDepth - (sizeX<<1), depthPosX);
2274  if ( heightChroma > heightDepth )
2275  {
2276    nTxtPerDepthY = heightChroma / heightDepth;
2277    nDepthPerTxtY = 1;
2278    depthPosY = posY / nTxtPerDepthY + ((dv->getVer()+2)>>2);
2279  }
2280  else
2281  {
2282    nTxtPerDepthY = 1;
2283    nDepthPerTxtY = heightDepth / heightChroma;
2284    depthPosY = posY * nDepthPerTxtY + ((dv->getVer()+2)>>2);
2285  }
2286  depthPosY = Clip3(0, heightDepth - (sizeY<<1), depthPosY);
2287
2288  Pel *refCb  = refPic->getCbAddr() + posX + posY * refStride;
2289  Pel *refCr  = refPic->getCrAddr() + posX + posY * refStride;
2290  Pel *dstCb  = dstPic->getCbAddr(partAddr);
2291  Pel *dstCr  = dstPic->getCrAddr(partAddr);
2292  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;  // move the pointer to the current depth pixel position
2293
2294  Int refStrideBlock = refStride * nTxtPerDepthY;
2295  Int dstStrideBlock = dstStride * nTxtPerDepthY;
2296  Int depStrideBlock = depStride * nDepthPerTxtY;
2297
2298  if ( widthChroma > widthDepth ) // We assume
2299  {
2300    assert( heightChroma > heightDepth );
2301    printf("This branch should never been reached.\n");
2302    exit(0);
2303  }
2304  else
2305  {
2306#if H_3D_VSP_BLOCKSIZE == 1
2307  Int  dW = sizeX;
2308  Int  dH = sizeY;
2309  Int  sW = 2; // search window size
2310  Int  sH = 2;
2311#endif
2312#if H_3D_VSP_BLOCKSIZE == 2
2313  Int  dW = sizeX;
2314  Int  dH = sizeY;
2315  Int  sW = 2; // search window size
2316  Int  sH = 2;
2317#endif
2318#if H_3D_VSP_BLOCKSIZE == 4
2319  Int  dW = sizeX>>1;
2320  Int  dH = sizeY>>1;
2321  Int  sW = 4; // search window size
2322  Int  sH = 4;
2323#endif
2324
2325  {
2326    Pel* depthi = depth;
2327    for (Int j = 0; j < dH; j++)
2328    {
2329      for (Int i = 0; i < dW; i++)
2330      {
2331        Pel* depthTmp;
2332#if H_3D_VSP_BLOCKSIZE == 1
2333        depthTmp = depthi + (i << 1);
2334#endif
2335#if H_3D_VSP_BLOCKSIZE == 2
2336        if (depthPosX + (i<<1) < widthDepth)
2337          depthTmp = depthi + (i << 1);
2338        else
2339          depthTmp = depthi + (widthDepth - depthPosX - 1);
2340#endif
2341#if H_3D_VSP_BLOCKSIZE == 4
2342        if (depthPosX + (i<<2) < widthDepth)
2343          depthTmp = depthi + (i << 2);
2344        else
2345          depthTmp = depthi + (widthDepth - depthPosX - 1);
2346#endif
2347        Int maxV = 0;
2348        for (Int blockj = 0; blockj < sH; blockj+=(sH-1))
2349        {
2350          Int iX = 0;
2351          for (Int blocki = 0; blocki < sW; blocki+=(sW-1))
2352          {
2353            if (maxV < depthTmp[iX])
2354              maxV = depthTmp[iX];
2355            if (depthPosX + i*sW + blocki < widthDepth - 1)
2356                iX = (sW-1);
2357          }
2358          if (depthPosY + j*sH + blockj < heightDepth - 1)
2359                depthTmp += depStride * (sH-1);
2360        }
2361        m_pDepthBlock[i+j*dW] = maxV;
2362      } // end of i < dW
2363#if H_3D_VSP_BLOCKSIZE == 1
2364      if (depthPosY + ((j+1)<<1) < heightDepth)
2365        depthi += (depStride << 1);
2366      else
2367        depthi  = depth + (heightDepth-1)*depStride;
2368#endif
2369#if H_3D_VSP_BLOCKSIZE == 2
2370      if (depthPosY + ((j+1)<<1) < heightDepth)
2371        depthi += (depStride << 1);
2372      else
2373        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
2374#endif
2375#if H_3D_VSP_BLOCKSIZE == 4
2376      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
2377        depthi += (depStride << 2);
2378      else
2379        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
2380#endif
2381    }
2382  }
2383
2384
2385#if H_3D_VSP_BLOCKSIZE == 1
2386#if H_3D_VSP_CONSTRAINED
2387  //get LUT based horizontal reference range
2388  Int range = xGetConstrainedSize(sizeX, sizeY, false);
2389
2390  // The minimum depth value
2391  Int minRelativePos = MAX_INT;
2392  Int maxRelativePos = MIN_INT;
2393
2394  Int depthTmp;
2395  for (Int yTxt=0; yTxt<sizeY; yTxt++)
2396  {
2397    for (Int xTxt=0; xTxt<sizeX; xTxt++)
2398    {
2399      depthTmp = m_pDepthBlock[xTxt+yTxt*dW];
2400      Int disparity = pShiftLUT[ depthTmp ]; // << iShiftPrec;
2401      Int disparityInt = disparity >> 3;//in chroma resolution
2402
2403      if (disparityInt < 0)
2404      {
2405        if (minRelativePos > disparityInt+xTxt)
2406            minRelativePos = disparityInt+xTxt;
2407      }
2408      else
2409      {
2410        if (maxRelativePos < disparityInt+xTxt)
2411            maxRelativePos = disparityInt+xTxt;
2412      }
2413    }
2414  }
2415
2416  depthTmp = m_pDepthBlock[0];
2417  Int disparity_tmp = pShiftLUT[ depthTmp ]; // << iShiftPrec;
2418  if ( disparity_tmp < 0 )
2419    maxRelativePos = minRelativePos + range - 1;
2420  else
2421    minRelativePos = maxRelativePos - range + 1;
2422
2423#endif // H_3D_VSP_CONSTRAINED
2424#endif // H_3D_VSP_BLOCKSIZE == 1
2425
2426    // (sizeX, sizeY) is Chroma block size
2427    for ( Int yTxt = 0, yDepth = 0; yTxt < sizeY; yTxt += nTxtPerDepthY, yDepth += nDepthPerTxtY )
2428    {
2429      for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth += nDepthPerTxtX )
2430      {
2431        Pel repDepth = 0; // to store the depth value used for warping
2432#if H_3D_VSP_BLOCKSIZE == 1
2433        repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW];
2434#endif
2435#if H_3D_VSP_BLOCKSIZE == 2
2436        repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW];
2437#endif
2438#if H_3D_VSP_BLOCKSIZE == 4
2439        repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW];
2440#endif
2441
2442      // calculate the offset in the reference picture
2443        Int disparity = pShiftLUT[ repDepth ]; // Remove << iShiftPrec;
2444        Int refOffset = xTxt + (disparity >> 3); // in integer pixel in chroma image
2445        Int xFrac = disparity & 0x7;
2446#if H_3D_VSP_CONSTRAINED
2447        if(refOffset < minRelativePos || refOffset > maxRelativePos)
2448          xFrac = 0;
2449        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
2450#endif
2451        Int absX  = posX + refOffset;
2452
2453        if (xFrac == 0)
2454          absX = Clip3(0, widthChroma-1, absX);
2455        else
2456          absX = Clip3(4, widthChroma-5, absX);
2457
2458        refOffset = absX - posX;
2459
2460        assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
2461        assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
2462        m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
2463        m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
2464      }
2465      refCb += refStrideBlock;
2466      refCr += refStrideBlock;
2467      dstCb += dstStrideBlock;
2468      dstCr += dstStrideBlock;
2469      depth += depStrideBlock;
2470    }
2471  }
2472
2473}
2474
2475#endif // NTT_VSP_COMMON_E0207_E0208
2476
2477#if H_3D_VSP_CONSTRAINED
2478Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma)
2479{
2480  Int iSize = 0;
2481  if (bLuma)
2482  {
2483    Int iArea = (nPbW+7) * (nPbH+7);
2484    Int iAlpha = iArea / nPbH - nPbW - 7;
2485    iSize = iAlpha + nPbW;
2486  }
2487  else // chroma
2488  {
2489    Int iArea = (nPbW+2) * (nPbH+2);
2490    Int iAlpha = iArea / nPbH - nPbW - 4;
2491    iSize = iAlpha + nPbW;
2492  }
2493  return iSize;
2494}
2495#endif // H_3D_VSP_CONSTRAINED
2496
2497#endif // H_3D_VSP
2498
2499#if H_3D_DIM
2500Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 )
2501{
2502  Int  refDC1, refDC2;
2503  const Int  iTR = (   patternStride - 1        ) - srcStride;
2504  const Int  iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride;
2505  const Int  iLB = (   patternStride - 1        ) * srcStride - 1;
2506  const Int  iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1;
2507
2508  Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] );
2509  Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)]               );
2510
2511  if( bL == bT )
2512  {
2513    refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : 1<<( g_bitDepthY - 1 );
2514    refDC2 =      ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1;
2515  }
2516  else
2517  {
2518    refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR];
2519    refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM];
2520  }
2521
2522  predDC1 = biSegPattern[0] ? refDC1 : refDC2;
2523  predDC2 = biSegPattern[0] ? refDC2 : refDC1;
2524}
2525
2526Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 )
2527{
2528  if( dstStride == patternStride )
2529  {
2530    for( UInt k = 0; k < (patternStride * patternStride); k++ )
2531    {
2532      if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; }
2533      else                          { ptrDst[k] = valDC1; }
2534    }
2535  }
2536  else
2537  {
2538    Pel* piTemp = ptrDst;
2539    for( UInt uiY = 0; uiY < patternStride; uiY++ )
2540    {
2541      for( UInt uiX = 0; uiX < patternStride; uiX++ )
2542      {
2543        if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; }
2544        else                            { piTemp[uiX] = valDC1; }
2545      }
2546      piTemp       += dstStride;
2547      biSegPattern += patternStride;
2548    }
2549  }
2550}
2551
2552#if H_3D_DIM_DMM
2553UInt TComPrediction::xPredWedgeFromIntra( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd )
2554{
2555  UInt uiThisBlockSize = uiWidth;
2556
2557  TComDataCU* pcTempCU;
2558  UInt        uiTempPartIdx;
2559  // 1st: try continue above wedgelet
2560  pcTempCU = pcCU->getPUAbove( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2561  if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) )
2562  {
2563    UInt dimType =  getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
2564    if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
2565    {
2566      // get offset between current and reference block
2567      UInt uiOffsetX = 0, uiOffsetY = 0;
2568      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
2569
2570      // get reference wedgelet
2571      WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])];
2572      TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) );
2573
2574      // find wedgelet, if direction is suitable for continue wedge
2575      if( pcRefWedgelet->checkPredDirAbovePossible( uiThisBlockSize, uiOffsetX ) )
2576      {
2577        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
2578        pcRefWedgelet->getPredDirStartEndAbove( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetX, iDeltaEnd );
2579        return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
2580      }
2581    }
2582  }
2583
2584  // 2nd: try continue left wedglelet
2585  pcTempCU = pcCU->getPULeft( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2586  if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) )
2587  {
2588    UInt dimType = getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) );
2589    if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType )
2590    {
2591      // get offset between current and reference block
2592      UInt uiOffsetX = 0, uiOffsetY = 0;
2593      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
2594
2595      // get reference wedgelet
2596      WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])];
2597      TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) );
2598
2599      // find wedgelet, if direction is suitable for continue wedge
2600      if( pcRefWedgelet->checkPredDirLeftPossible( uiThisBlockSize, uiOffsetY ) )
2601      {
2602        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
2603        pcRefWedgelet->getPredDirStartEndLeft( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetY, iDeltaEnd );
2604        return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
2605      }
2606    }
2607  }
2608
2609  // 3rd: (default) make wedglet from intra dir and max slope point
2610  Int iSlopeX = 0, iSlopeY = 0;
2611  UInt uiStartPosX = 0, uiStartPosY = 0;
2612  if( xGetWedgeIntraDirPredData( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY ) )
2613  {
2614    UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
2615    xGetWedgeIntraDirStartEnd( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, iDeltaEnd );
2616    return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
2617  }
2618
2619  return 0;
2620}
2621
2622UInt TComPrediction::xPredWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx )
2623{
2624  TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
2625  assert( pcPicTex != NULL );
2626  TComDataCU*   pcColTexCU = pcPicTex->getCU(pcCU->getAddr());
2627  UInt          uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
2628  Int           uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
2629
2630  if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 ) { return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx); }
2631  else                                                     { return g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])].at(intraTabIdx).getPatternIdx(); }
2632}
2633
2634Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge )
2635{
2636  pcContourWedge->clear();
2637
2638  // get copy of co-located texture luma block
2639  TComYuv cTempYuv;
2640  cTempYuv.create( uiWidth, uiHeight ); 
2641  cTempYuv.clear();
2642  Pel* piRefBlkY = cTempYuv.getLumaAddr();
2643  xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight );
2644  piRefBlkY = cTempYuv.getLumaAddr();
2645
2646  // find contour for texture luma block
2647  UInt iDC = 0;
2648  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2649  { 
2650    iDC += piRefBlkY[k]; 
2651  }
2652  iDC /= (uiWidth*uiHeight);
2653  piRefBlkY = cTempYuv.getLumaAddr();
2654
2655  Bool* pabContourPattern = pcContourWedge->getPattern();
2656  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
2657  { 
2658    pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false;
2659  }
2660
2661  cTempYuv.destroy();
2662}
2663
2664
2665Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight )
2666{
2667  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
2668  assert( pcPicYuvRef != NULL );
2669  Int         iRefStride = pcPicYuvRef->getStride();
2670  Pel*        piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
2671
2672  for ( Int y = 0; y < uiHeight; y++ )
2673  {
2674    ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth);
2675    piDestBlockY += uiWidth;
2676    piRefY += iRefStride;
2677  }
2678}
2679
2680Void TComPrediction::xGetBlockOffset( TComDataCU* pcCU, UInt uiAbsPartIdx, TComDataCU* pcRefCU, UInt uiRefAbsPartIdx, UInt& ruiOffsetX, UInt& ruiOffsetY )
2681{
2682  ruiOffsetX = 0;
2683  ruiOffsetY = 0;
2684
2685  // get offset between current and above/left block
2686  UInt uiThisOriginX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
2687  UInt uiThisOriginY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
2688
2689  UInt uiNumPartInRefCU = pcRefCU->getTotalNumPart();
2690  UInt uiMaxDepthRefCU = 0;
2691  while( uiNumPartInRefCU > 1 )
2692  {
2693    uiNumPartInRefCU >>= 2;
2694    uiMaxDepthRefCU++;
2695  }
2696
2697  UInt uiDepthRefPU = (pcRefCU->getDepth(uiRefAbsPartIdx)) + (pcRefCU->getPartitionSize(uiRefAbsPartIdx) == SIZE_2Nx2N ? 0 : 1);
2698  UInt uiShifts = (uiMaxDepthRefCU - uiDepthRefPU)*2;
2699  UInt uiRefBlockOriginPartIdx = (uiRefAbsPartIdx>>uiShifts)<<uiShifts;
2700
2701  UInt uiRefOriginX = pcRefCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ];
2702  UInt uiRefOriginY = pcRefCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ];
2703
2704  if( (uiThisOriginX - uiRefOriginX) > 0 ) { ruiOffsetX = (UInt)(uiThisOriginX - uiRefOriginX); }
2705  if( (uiThisOriginY - uiRefOriginY) > 0 ) { ruiOffsetY = (UInt)(uiThisOriginY - uiRefOriginY); }
2706}
2707
2708Bool TComPrediction::xGetWedgeIntraDirPredData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int& riSlopeX, Int& riSlopeY, UInt& ruiStartPosX, UInt& ruiStartPosY )
2709{
2710  riSlopeX = 0, riSlopeY = 0, ruiStartPosX = 0, ruiStartPosY = 0;
2711
2712  // 1st step: get wedge start point (max. slope)
2713  Int* piSource = pcCU->getPattern()->getAdiOrgBuf( uiBlockSize, uiBlockSize, m_piYuvExt );
2714  Int iSourceStride = ( uiBlockSize<<1 ) + 1;
2715
2716  UInt uiSlopeMaxAbove = 0, uiPosSlopeMaxAbove = 0;
2717  for( UInt uiPosHor = 0; uiPosHor < (uiBlockSize-1); uiPosHor++ )
2718  {
2719    if( abs( piSource[uiPosHor+1] - piSource[uiPosHor] ) > uiSlopeMaxAbove )
2720    {
2721      uiSlopeMaxAbove = abs( piSource[uiPosHor+1] - piSource[uiPosHor] );
2722      uiPosSlopeMaxAbove = uiPosHor;
2723    }
2724  }
2725
2726  UInt uiSlopeMaxLeft = 0, uiPosSlopeMaxLeft = 0;
2727  for( UInt uiPosVer = 0; uiPosVer < (uiBlockSize-1); uiPosVer++ )
2728  {
2729    if( abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] ) > uiSlopeMaxLeft )
2730    {
2731      uiSlopeMaxLeft = abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] );
2732      uiPosSlopeMaxLeft = uiPosVer;
2733    }
2734  }
2735
2736  if( uiSlopeMaxAbove == 0 && uiSlopeMaxLeft == 0 ) 
2737  { 
2738    return false; 
2739  }
2740
2741  ruiStartPosX = ( uiSlopeMaxAbove >  uiSlopeMaxLeft  ) ? uiPosSlopeMaxAbove : 0;
2742  ruiStartPosY = ( uiSlopeMaxLeft  >= uiSlopeMaxAbove ) ? uiPosSlopeMaxLeft  : 0;
2743
2744  // 2nd step: derive wedge direction
2745  Int uiPreds[3] = {-1, -1, -1};
2746  Int iMode = -1;
2747  Int iPredNum = pcCU->getIntraDirLumaPredictor( uiAbsPartIdx, uiPreds, &iMode ); 
2748
2749  UInt uiDirMode = 0;
2750  if( iMode >= 0 ) { iPredNum = iMode; }
2751  if( iPredNum == 1 ) { uiDirMode = uiPreds[0]; }
2752  if( iPredNum == 2 ) { uiDirMode = uiPreds[1]; }
2753
2754  if( uiDirMode < 2 ) { return false; } // no planar & DC
2755
2756  Bool modeHor       = (uiDirMode < 18);
2757  Bool modeVer       = !modeHor;
2758  Int intraPredAngle = modeVer ? (Int)uiDirMode - VER_IDX : modeHor ? -((Int)uiDirMode - HOR_IDX) : 0;
2759  Int absAng         = abs(intraPredAngle);
2760  Int signAng        = intraPredAngle < 0 ? -1 : 1;
2761  Int angTable[9]    = {0,2,5,9,13,17,21,26,32};
2762  absAng             = angTable[absAng];
2763  intraPredAngle     = signAng * absAng;
2764
2765  // 3rd step: set slope for direction
2766  if( modeHor )
2767  {
2768    riSlopeX = ( intraPredAngle > 0 ) ?            -32 :              32;
2769    riSlopeY = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle;
2770  }
2771  else if( modeVer )
2772  {
2773    riSlopeX = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle;
2774    riSlopeY = ( intraPredAngle > 0 ) ?            -32 :              32;
2775  }
2776
2777  return true;
2778}
2779
2780Void 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 )
2781{
2782  ruhXs = 0;
2783  ruhYs = 0;
2784  ruhXe = 0;
2785  ruhYe = 0;
2786
2787  // scaling of start pos and block size to wedge resolution
2788  UInt uiScaledStartPosX = 0;
2789  UInt uiScaledStartPosY = 0;
2790  UInt uiScaledBlockSize = 0;
2791  WedgeResolution eWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiBlockSize]];
2792  switch( eWedgeRes )
2793  {
2794  case( DOUBLE_PEL ): { uiScaledStartPosX = (uiPMSPosX>>1); uiScaledStartPosY = (uiPMSPosY>>1); uiScaledBlockSize = (uiBlockSize>>1); break; }
2795  case(   FULL_PEL ): { uiScaledStartPosX =  uiPMSPosX;     uiScaledStartPosY =  uiPMSPosY;     uiScaledBlockSize =  uiBlockSize;     break; }
2796  case(   HALF_PEL ): { uiScaledStartPosX = (uiPMSPosX<<1); uiScaledStartPosY = (uiPMSPosY<<1); uiScaledBlockSize = (uiBlockSize<<1); break; }
2797  }
2798  Int iMaxPos = (Int)uiScaledBlockSize - 1;
2799
2800  // case above
2801  if( uiScaledStartPosX > 0 && uiScaledStartPosY == 0 )
2802  {
2803    ruhXs = (UChar)uiScaledStartPosX;
2804    ruhYs = 0;
2805
2806    if( iDeltaY == 0 )
2807    {
2808      if( iDeltaX < 0 )
2809      {
2810        ruhXe = 0;
2811        ruhYe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos );
2812        return;
2813      }
2814      else
2815      {
2816        ruhXe = (UChar)iMaxPos;
2817        ruhYe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos );
2818        std::swap( ruhXs, ruhXe );
2819        std::swap( ruhYs, ruhYe );
2820        return;
2821      }
2822    }
2823
2824    // regular case
2825    Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) );
2826
2827    if( iVirtualEndX < 0 )
2828    {
2829      Int iYe = roftoi( (Double)(0 - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) + iDeltaEnd;
2830      if( iYe < (Int)uiScaledBlockSize )
2831      {
2832        ruhXe = 0;
2833        ruhYe = (UChar)std::max( iYe, 0 );
2834        return;
2835      }
2836      else
2837      {
2838        ruhXe = (UChar)std::min( (iYe - iMaxPos), iMaxPos );
2839        ruhYe = (UChar)iMaxPos;
2840        return;
2841      }
2842    }
2843    else if( iVirtualEndX > iMaxPos )
2844    {
2845      Int iYe = roftoi( (Double)(iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd;
2846      if( iYe < (Int)uiScaledBlockSize )
2847      {
2848        ruhXe = (UChar)iMaxPos;
2849        ruhYe = (UChar)std::max( iYe, 0 );
2850        std::swap( ruhXs, ruhXe );
2851        std::swap( ruhYs, ruhYe );
2852        return;
2853      }
2854      else
2855      {
2856        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
2857        ruhYe = (UChar)iMaxPos;
2858        return;
2859      }
2860    }
2861    else
2862    {
2863      Int iXe = iVirtualEndX + iDeltaEnd;
2864      if( iXe < 0 )
2865      {
2866        ruhXe = 0;
2867        ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 );
2868        return;
2869      }
2870      else if( iXe > iMaxPos )
2871      {
2872        ruhXe = (UChar)iMaxPos;
2873        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
2874        std::swap( ruhXs, ruhXe );
2875        std::swap( ruhYs, ruhYe );
2876        return;
2877      }
2878      else
2879      {
2880        ruhXe = (UChar)iXe;
2881        ruhYe = (UChar)iMaxPos;
2882        return;
2883      }
2884    }
2885  }
2886
2887  // case left
2888  if( uiScaledStartPosY > 0 && uiScaledStartPosX == 0 )
2889  {
2890    ruhXs = 0;
2891    ruhYs = (UChar)uiScaledStartPosY;
2892
2893    if( iDeltaX == 0 )
2894    {
2895      if( iDeltaY < 0 )
2896      {
2897        ruhXe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos );
2898        ruhYe = 0;
2899        std::swap( ruhXs, ruhXe );
2900        std::swap( ruhYs, ruhYe );
2901        return;
2902      }
2903      else
2904      {
2905        ruhXe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos );
2906        ruhYe = (UChar)iMaxPos;
2907        return; 
2908      }
2909    }
2910
2911    // regular case
2912    Int iVirtualEndY = (Int)ruhYs + roftoi( (Double)iMaxPos * ((Double)iDeltaY / (Double)iDeltaX) );
2913
2914    if( iVirtualEndY < 0 )
2915    {
2916      Int iXe = roftoi( (Double)(0 - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) - iDeltaEnd;
2917      if( iXe < (Int)uiScaledBlockSize )
2918      {
2919        ruhXe = (UChar)std::max( iXe, 0 );
2920        ruhYe = 0;
2921        std::swap( ruhXs, ruhXe );
2922        std::swap( ruhYs, ruhYe );
2923        return;
2924      }
2925      else
2926      {
2927        ruhXe = (UChar)iMaxPos;
2928        ruhYe = (UChar)std::min( (iXe - iMaxPos), iMaxPos );
2929        std::swap( ruhXs, ruhXe );
2930        std::swap( ruhYs, ruhYe );
2931        return;
2932      }
2933    }
2934    else if( iVirtualEndY > (uiScaledBlockSize-1) )
2935    {
2936      Int iXe = roftoi( (Double)((Int)(uiScaledBlockSize-1) - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) + iDeltaEnd;
2937      if( iXe < (Int)uiScaledBlockSize )
2938      {
2939        ruhXe = (UChar)std::max( iXe, 0 );
2940        ruhYe = (UChar)(uiScaledBlockSize-1);
2941        return;
2942      }
2943      else
2944      {
2945        ruhXe = (UChar)iMaxPos;
2946        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
2947        std::swap( ruhXs, ruhXe );
2948        std::swap( ruhYs, ruhYe );
2949        return;
2950      }
2951    }
2952    else
2953    {
2954      Int iYe = iVirtualEndY - iDeltaEnd;
2955      if( iYe < 0 )
2956      {
2957        ruhXe = (UChar)std::max( (iMaxPos + iYe), 0 );
2958        ruhYe = 0;
2959        std::swap( ruhXs, ruhXe );
2960        std::swap( ruhYs, ruhYe );
2961        return;
2962      }
2963      else if( iYe > iMaxPos )
2964      {
2965        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
2966        ruhYe = (UChar)iMaxPos;
2967        return;
2968      }
2969      else
2970      {
2971        ruhXe = (UChar)iMaxPos;
2972        ruhYe = (UChar)iYe;
2973        std::swap( ruhXs, ruhXe );
2974        std::swap( ruhYs, ruhYe );
2975        return;
2976      }
2977    }
2978  }
2979
2980  // case origin
2981  if( uiScaledStartPosX == 0 && uiScaledStartPosY == 0 )
2982  {
2983    if( iDeltaX*iDeltaY < 0 )
2984    {
2985      return;
2986    }
2987
2988    ruhXs = 0;
2989    ruhYs = 0;
2990
2991    if( iDeltaY == 0 )
2992    {
2993      ruhXe = (UChar)iMaxPos;
2994      ruhYe = 0;
2995      std::swap( ruhXs, ruhXe );
2996      std::swap( ruhYs, ruhYe );
2997      return;
2998    }
2999
3000    if( iDeltaX == 0 )
3001    {
3002      ruhXe = 0;
3003      ruhYe = (UChar)iMaxPos;
3004      return;
3005    }
3006
3007    Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) );
3008
3009    if( iVirtualEndX > iMaxPos )
3010    {
3011      Int iYe = roftoi( (Double)((Int)iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd;
3012      if( iYe < (Int)uiScaledBlockSize )
3013      {
3014        ruhXe = (UChar)(uiScaledBlockSize-1);
3015        ruhYe = (UChar)std::max( iYe, 0 );
3016        std::swap( ruhXs, ruhXe );
3017        std::swap( ruhYs, ruhYe );
3018        return;
3019      }
3020      else
3021      {
3022        ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 );
3023        ruhYe = (UChar)(uiScaledBlockSize-1);
3024        return;
3025      }
3026    }
3027    else
3028    {
3029      Int iXe = iVirtualEndX + iDeltaEnd;
3030      if( iXe < 0 )
3031      {
3032        ruhXe = 0;
3033        ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 );
3034        return;
3035      }
3036      else if( iXe > iMaxPos )
3037      {
3038        ruhXe = (UChar)(uiScaledBlockSize-1);
3039        ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 );
3040        std::swap( ruhXs, ruhXe );
3041        std::swap( ruhYs, ruhYe );
3042        return;
3043      }
3044      else
3045      {
3046        ruhXe = (UChar)iXe;
3047        ruhYe = (UChar)(uiScaledBlockSize-1);
3048        return;
3049      }
3050    }
3051  }
3052}
3053
3054UInt TComPrediction::xGetWedgePatternIdx( UInt uiBlockSize, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe )
3055{
3056  WedgeRefList* pcWedgeRefList = &g_dmmWedgeRefLists[(g_aucConvertToBit[uiBlockSize])];
3057  for( UInt uiIdx = 0; uiIdx < pcWedgeRefList->size(); uiIdx++ )
3058  {
3059    TComWedgeRef* pcTestWedgeRef = &(pcWedgeRefList->at(uiIdx));
3060    if( pcTestWedgeRef->getStartX() == uhXs && pcTestWedgeRef->getStartY() == uhYs && pcTestWedgeRef->getEndX() == uhXe && pcTestWedgeRef->getEndY() == uhYe )
3061    {
3062      return pcTestWedgeRef->getRefIdx();
3063    }
3064  }
3065  return 0;
3066}
3067#endif
3068#if H_3D_DIM_RBC
3069Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Pel& rDeltaDC )
3070{
3071  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
3072  UInt uiAbs  = abs( rDeltaDC );
3073
3074  Int iQp = pcCU->getQP(0);
3075  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
3076  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
3077
3078  rDeltaDC = iSign * roftoi( uiAbs * dStepSize );
3079  return;
3080}
3081
3082Void TComPrediction::xDeltaDCQuantScaleDown( TComDataCU*  pcCU, Pel& rDeltaDC )
3083{
3084  Int  iSign  = rDeltaDC < 0 ? -1 : 1;
3085  UInt uiAbs  = abs( rDeltaDC );
3086
3087  Int iQp = pcCU->getQP(0);
3088  Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) );
3089  Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) );
3090
3091  rDeltaDC = iSign * roftoi( uiAbs / dStepSize );
3092  return;
3093}
3094#endif
3095#if H_3D_DIM_SDC
3096Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride )
3097{
3098  Int iSumDepth[2];
3099  memset(iSumDepth, 0, sizeof(Int)*2);
3100  Int iSumPix[2];
3101  memset(iSumPix, 0, sizeof(Int)*2);
3102 
3103  Int subSamplePix;
3104  if ( uiSize == 64 || uiSize == 32 )
3105  {
3106    subSamplePix = 2;
3107  }
3108  else
3109  {
3110    subSamplePix = 1;
3111  }
3112  for (Int y=0; y<uiSize; y+=subSamplePix)
3113  {
3114    for (Int x=0; x<uiSize; x+=subSamplePix)
3115    {
3116      UChar ucSegment = pMask?(UChar)pMask[x]:0;
3117      assert( ucSegment < uiNumSegments );
3118     
3119      iSumDepth[ucSegment] += pOrig[x];
3120      iSumPix[ucSegment]   += 1;
3121    }
3122   
3123    pOrig  += uiStride*subSamplePix;
3124    pMask  += uiMaskStride*subSamplePix;
3125  }
3126 
3127  // compute mean for each segment
3128  for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ )
3129  {
3130    if( iSumPix[ucSeg] > 0 )
3131      rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg];
3132    else
3133      rpSegMeans[ucSeg] = 0;  // this happens for zero-segments
3134  }
3135}
3136#endif // H_3D_DIM_SDC
3137#endif
3138//! \}
Note: See TracBrowser for help on using the repository browser.