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

Last change on this file since 615 was 596, checked in by mediatek-htm, 12 years ago

Modify the software implementation related to "MTK_VSP_FIX_E0172" to be aligned with the draft text.
The MACRO is "MTK_VSP_FIX_ALIGN_WD_E0172"

By Yi-Wen Chen (yiwen.chen@…)

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