source: 3DVCSoftware/branches/HTM-DEV-2.0-dev0/source/Lib/TLibCommon/TComPrediction.cpp @ 1404

Last change on this file since 1404 was 601, checked in by tech, 12 years ago

Merged dev3: DEV-2.0-DEV3-KWU@589

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