source: 3DVCSoftware/branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPrediction.cpp @ 28

Last change on this file since 28 was 28, checked in by poznan-univ, 13 years ago

Poznan Tools

  • Encoding only disoccluded CUs in depended views
  • Depth based motion prediction
  • Texture QP adjustment based on depth data
  • Nonlinear depth representation
  • Property svn:eol-style set to native
File size: 125.4 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-2011, 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 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
35
36/** \file     TComPrediction.cpp
37    \brief    prediction class
38*/
39
40#include <memory.h>
41#include "TComPrediction.h"
42
43// ====================================================================================================================
44// Constructor / destructor / initialize
45// ====================================================================================================================
46
47TComPrediction::TComPrediction()
48: m_pLumaRecBuffer(0)
49{
50  m_piYuvExt = NULL;
51}
52
53TComPrediction::~TComPrediction()
54{
55  m_cYuvExt.destroy();
56
57  delete[] m_piYuvExt;
58
59  m_acYuvPred[0].destroy();
60  m_acYuvPred[1].destroy();
61
62  m_cYuvPredTemp.destroy();
63
64#if LM_CHROMA 
65  if( m_pLumaRecBuffer )
66    delete [] m_pLumaRecBuffer; 
67#endif
68}
69
70Void TComPrediction::initTempBuff()
71{
72  if( m_piYuvExt == NULL )
73  {
74    m_iYuvExtHeight  = ((g_uiMaxCUHeight + 2) << 4);
75    m_iYuvExtStride = ((g_uiMaxCUWidth  + 8) << 4);
76    m_cYuvExt.create( m_iYuvExtStride, m_iYuvExtHeight );
77    m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
78
79    // new structure
80    m_acYuvPred[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
81    m_acYuvPred[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
82
83    m_cYuvPredTemp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
84  }
85
86#if LM_CHROMA                     
87  m_iLumaRecStride =  (g_uiMaxCUWidth>>1) + 1;
88  m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ];
89
90  for( Int i = 1; i < 66; i++ )
91    m_uiaShift[i-1] = ( (1 << 15) + i/2 ) / i;
92#endif
93}
94
95// ====================================================================================================================
96// Public member functions
97// ====================================================================================================================
98
99// Function for calculating DC value of the reference samples used in Intra prediction
100Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft )
101{
102  Int iInd, iSum = 0;
103  Pel pDcVal;
104
105  if (bAbove)
106  {
107    for (iInd = 0;iInd < iWidth;iInd++)
108      iSum += pSrc[iInd-iSrcStride];
109  }
110  if (bLeft)
111  {
112    for (iInd = 0;iInd < iHeight;iInd++)
113      iSum += pSrc[iInd*iSrcStride-1];
114  }
115
116  if (bAbove && bLeft)
117    pDcVal = (iSum + iWidth) / (iWidth + iHeight);
118  else if (bAbove)
119    pDcVal = (iSum + iWidth/2) / iWidth;
120  else if (bLeft)
121    pDcVal = (iSum + iHeight/2) / iHeight;
122  else
123    pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available
124
125  return pDcVal;
126}
127
128// Function for deriving the angular Intra predictions
129
130/** Function for deriving the simplified angular intra predictions.
131 * \param pSrc pointer to reconstructed sample array
132 * \param srcStride the stride of the reconstructed sample array
133 * \param rpDst reference to pointer for the prediction sample array
134 * \param dstStride the stride of the prediction sample array
135 * \param width the width of the block
136 * \param height the height of the block
137 * \param dirMode the intra prediction mode index
138 * \param blkAboveAvailable boolean indication if the block above is available
139 * \param blkLeftAvailable boolean indication if the block to the left is available
140 *
141 * This function derives the prediction samples for the angular mode based on the prediction direction indicated by
142 * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and
143 * the reference row above the block in the case of vertical prediction or displacement of the rightmost column
144 * of the block and reference column left from the block in the case of the horizontal prediction. The displacement
145 * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples,
146 * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken
147 * from the extended main reference.
148 */
149Void TComPrediction::xPredIntraAng( Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable )
150{
151  Int k,l;
152  Int blkSize        = width;
153  Pel* pDst          = rpDst;
154
155  // Map the mode index to main prediction direction and angle
156  Bool modeDC        = dirMode == 0;
157  Bool modeVer       = !modeDC && (dirMode < 18);
158  Bool modeHor       = !modeDC && !modeVer;
159  Int intraPredAngle = modeVer ? dirMode - 9 : modeHor ? dirMode - 25 : 0;
160  Int absAng         = abs(intraPredAngle);
161  Int signAng        = intraPredAngle < 0 ? -1 : 1;
162
163  // Set bitshifts and scale the angle parameter to block size
164  Int angTable[9]    = {0,    2,    5,   9,  13,  17,  21,  26,  32};
165  Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
166  Int invAngle       = invAngTable[absAng];
167  absAng             = angTable[absAng];
168  intraPredAngle     = signAng * absAng;
169
170  // Do the DC prediction
171  if (modeDC)
172  {
173    Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable);
174
175    for (k=0;k<blkSize;k++)
176    {
177      for (l=0;l<blkSize;l++)
178      {
179        pDst[k*dstStride+l] = dcval;
180      }
181    }
182  }
183
184  // Do angular predictions
185  else
186  {
187    Pel* refMain;
188    Pel* refSide;
189    Pel  refAbove[2*MAX_CU_SIZE+1];
190    Pel  refLeft[2*MAX_CU_SIZE+1];
191
192    // Initialise the Main and Left reference array.
193    if (intraPredAngle < 0)
194    {
195      for (k=0;k<blkSize+1;k++)
196      {
197        refAbove[k+blkSize-1] = pSrc[k-srcStride-1];
198      }
199      for (k=0;k<blkSize+1;k++)
200      {
201        refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1];
202      }
203      refMain = (modeVer ? refAbove : refLeft) + (blkSize-1);
204      refSide = (modeVer ? refLeft : refAbove) + (blkSize-1);
205
206      // Extend the Main reference to the left.
207      Int invAngleSum    = 128;       // rounding for (shift by 8)
208      for (k=-1; k>blkSize*intraPredAngle>>5; k--)
209      {
210        invAngleSum += invAngle;
211        refMain[k] = refSide[invAngleSum>>8];
212      }
213    }
214    else
215    {
216      for (k=0;k<2*blkSize+1;k++)
217      {
218        refAbove[k] = pSrc[k-srcStride-1];
219      }
220      for (k=0;k<2*blkSize+1;k++)
221      {
222        refLeft[k] = pSrc[(k-1)*srcStride-1];
223      }
224      refMain = modeVer ? refAbove : refLeft;
225    }
226
227    if (intraPredAngle == 0)
228    {
229      for (k=0;k<blkSize;k++)
230      {
231        for (l=0;l<blkSize;l++)
232        {
233          pDst[k*dstStride+l] = refMain[l+1];
234        }
235      }
236    }
237    else
238    {
239      Int deltaPos=0;
240      Int deltaInt;
241      Int deltaFract;
242      Int refMainIndex;
243
244      for (k=0;k<blkSize;k++)
245      {
246        deltaPos += intraPredAngle;
247        deltaInt   = deltaPos >> 5;
248        deltaFract = deltaPos & (32 - 1);
249
250        if (deltaFract)
251        {
252          // Do linear filtering
253          for (l=0;l<blkSize;l++)
254          {
255            refMainIndex        = l+deltaInt+1;
256            pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 );
257          }
258        }
259        else
260        {
261          // Just copy the integer samples
262          for (l=0;l<blkSize;l++)
263          {
264            pDst[k*dstStride+l] = refMain[l+deltaInt+1];
265          }
266        }
267      }
268    }
269
270    // Flip the block if this is the horizontal mode
271    if (modeHor)
272    {
273      Pel  tmp;
274      for (k=0;k<blkSize-1;k++)
275      {
276        for (l=k+1;l<blkSize;l++)
277        {
278          tmp                 = pDst[k*dstStride+l];
279          pDst[k*dstStride+l] = pDst[l*dstStride+k];
280          pDst[l*dstStride+k] = tmp;
281        }
282      }
283    }
284  }
285}
286
287Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight,  TComDataCU* pcCU, Bool bAbove, Bool bLeft )
288{
289  Pel *pDst = piPred;
290  Int *ptrSrc;
291
292  // only assign variable in debug mode
293#ifndef NDEBUG
294  // get intra direction
295  Int iIntraSizeIdx = g_aucConvertToBit[ iWidth ] + 1;
296
297  assert( iIntraSizeIdx >= 1 ); //   4x  4
298  assert( iIntraSizeIdx <= 6 ); // 128x128
299  assert( iWidth == iHeight  );
300#endif //NDEBUG
301
302#if QC_MDIS
303  ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 1, iWidth, iHeight, m_piYuvExt );
304#else
305  ptrSrc = pcTComPattern->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt );
306#endif //QC_MDIS
307
308  // get starting pixel in block
309  Int sw = ( iWidth<<1 ) + 1;
310
311#if ADD_PLANAR_MODE
312  if ( uiDirMode == PLANAR_IDX )
313  {
314#if REFERENCE_SAMPLE_PADDING
315    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
316#else
317    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, bAbove, bLeft );
318#endif
319    return;
320  }
321#endif
322
323  // get converted direction
324  uiDirMode = g_aucAngIntraModeOrder[ uiDirMode ];
325
326  // Create the prediction
327  xPredIntraAng( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove,  bLeft );
328
329#if MN_DC_PRED_FILTER
330  if ((uiDirMode == 0) && pcTComPattern->getDCPredFilterFlag())
331    xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);
332#endif
333}
334
335
336Void
337TComPrediction::predIntraDepthAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight )
338{
339  Pel*  pDst    = piPred;
340  Int*  ptrSrc  = pcTComPattern->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt );
341  Int   sw      = ( iWidth<<1 ) + 1;
342  uiDirMode     = g_aucAngIntraModeOrder[ uiDirMode ];
343  xPredIntraAngDepth( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode );
344}
345
346Int
347TComPrediction::xGetDCDepth( Int* pSrc, Int iDelta, Int iBlkSize )
348{
349  Int iDC    = PDM_UNDEFINED_DEPTH;
350  Int iSum   = 0;
351  Int iNum   = 0;
352  for( Int k = 0; k < iBlkSize; k++, pSrc += iDelta )
353  {
354    if( *pSrc != PDM_UNDEFINED_DEPTH )
355    {
356      iSum += *pSrc;
357      iNum ++;
358    }
359  }
360  if( iNum )
361  {
362    iDC = ( iSum + ( iNum >> 1 ) ) / iNum;
363  }
364  return iDC;
365}
366
367Int
368TComPrediction::xGetDCValDepth( Int iVal1, Int iVal2, Int iVal3, Int iVal4 )
369{
370  if     ( iVal1 != PDM_UNDEFINED_DEPTH )   return iVal1;
371  else if( iVal2 != PDM_UNDEFINED_DEPTH )   return iVal2;
372  else if( iVal3 != PDM_UNDEFINED_DEPTH )   return iVal3;
373  return   iVal4;
374}
375
376Void
377TComPrediction::xPredIntraAngDepth( Int* pSrc, Int srcStride, Pel* pDst, Int dstStride, UInt width, UInt height, UInt dirMode )
378{
379  AOF( width == height );
380  Int blkSize       = width;
381  Int iDCAbove      = xGetDCDepth( pSrc - srcStride,                               1, blkSize );
382  Int iDCAboveRight = xGetDCDepth( pSrc - srcStride + blkSize,                     1, blkSize );
383  Int iDCLeft       = xGetDCDepth( pSrc -         1,                       srcStride, blkSize );
384  Int iDCBelowLeft  = xGetDCDepth( pSrc -         1 + blkSize * srcStride, srcStride, blkSize );
385  Int iWgt, iDC1, iDC2;
386  if( dirMode == 0 ) // 0
387  {
388    iDC1  = xGetDCValDepth( iDCAbove, iDCAboveRight, iDCLeft,  iDCBelowLeft  );
389    iDC2  = xGetDCValDepth( iDCLeft,  iDCBelowLeft,  iDCAbove, iDCAboveRight );
390    iWgt  = 8;
391  }
392  else if( dirMode < 10 ) // 1..9
393  {
394    iDC1  = xGetDCValDepth( iDCAbove, iDCAboveRight, iDCLeft,  iDCBelowLeft  );
395    iDC2  = xGetDCValDepth( iDCLeft,  iDCBelowLeft,  iDCAbove, iDCAboveRight );
396    iWgt  = 7 + dirMode;
397  }
398  else if( dirMode < 18 ) // 10..17
399  {
400    iDC1  = xGetDCValDepth( iDCAbove, iDCAboveRight, iDCLeft,  iDCBelowLeft  );
401    iDC2  = xGetDCValDepth( iDCAboveRight, iDCAbove, iDCLeft,  iDCBelowLeft  );
402    iWgt  = 25 - dirMode;
403  }
404  else if( dirMode < 26 ) // 18..25
405  {
406    iDC1  = xGetDCValDepth( iDCAbove, iDCAboveRight, iDCLeft,  iDCBelowLeft  );
407    iDC2  = xGetDCValDepth( iDCLeft,  iDCBelowLeft,  iDCAbove, iDCAboveRight );
408    iWgt  = 25 - dirMode;
409  }
410  else if( dirMode < 34 )  // 26..33
411  {
412    iDC1  = xGetDCValDepth( iDCLeft,  iDCBelowLeft,  iDCAbove, iDCAboveRight );
413    iDC2  = xGetDCValDepth( iDCBelowLeft,  iDCLeft,  iDCAbove, iDCAboveRight );
414    iWgt  = 41 - dirMode;
415  }
416  else // 34 (wedgelet -> use simple DC prediction
417  {
418    iDC1  = xGetDCValDepth( iDCAbove, iDCAboveRight, iDCLeft,  iDCBelowLeft  );
419    iDC2  = xGetDCValDepth( iDCLeft,  iDCBelowLeft,  iDCAbove, iDCAboveRight );
420    iWgt  = 8;
421  }
422  Int iWgt2   = 16 - iWgt;
423  Int iDCVal  = ( iWgt * iDC1 + iWgt2 * iDC2 + 8 ) >> 4;
424 
425  // set depth
426  for( Int iY = 0; iY < blkSize; iY++, pDst += dstStride )
427  {
428    for( Int iX = 0; iX < blkSize; iX++ )
429    {
430      pDst[ iX ] = iDCVal;
431    }
432  }
433}
434
435
436// Angular chroma
437Void TComPrediction::predIntraChromaAng( TComPattern* pcTComPattern, Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, TComDataCU* pcCU, Bool bAbove, Bool bLeft )
438{
439  Pel *pDst = piPred;
440  Int *ptrSrc = piSrc;
441
442  // get starting pixel in block
443  Int sw = ( iWidth<<1 ) + 1;
444
445#if ADD_PLANAR_MODE
446  if ( uiDirMode == PLANAR_IDX )
447  {
448#if REFERENCE_SAMPLE_PADDING
449    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
450#else
451    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, bAbove, bLeft );
452#endif
453    return;
454  }
455#endif
456
457  // get converted direction
458  uiDirMode = g_aucAngIntraModeOrder[ uiDirMode ];
459
460  // Create the prediction
461  xPredIntraAng( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove,  bLeft );
462}
463
464#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
465Void TComPrediction::predIntraLumaDMM( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder )
466{
467#if HHI_DMM_WEDGE_INTRA
468  if( uiMode == DMM_WEDGE_FULL_IDX          ) { xPredIntraWedgeFull      ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, false, pcCU->getWedgeFullTabIdx ( uiAbsPartIdx ) ); }
469  if( uiMode == DMM_WEDGE_FULL_D_IDX        ) { xPredIntraWedgeFull      ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, true,  pcCU->getWedgeFullTabIdx( uiAbsPartIdx ), pcCU->getWedgeFullDeltaDC1( uiAbsPartIdx ), pcCU->getWedgeFullDeltaDC2( uiAbsPartIdx ) ); }
470  if( uiMode == DMM_WEDGE_PREDDIR_IDX     ) { xPredIntraWedgeDir       ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, false, pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ) ); }
471  if( uiMode == DMM_WEDGE_PREDDIR_D_IDX   ) { xPredIntraWedgeDir       ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, true,  pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ), pcCU->getWedgePredDirDeltaDC1( uiAbsPartIdx ), pcCU->getWedgePredDirDeltaDC2( uiAbsPartIdx ) ); }
472#endif
473#if HHI_DMM_PRED_TEX
474  if( uiMode == DMM_WEDGE_PREDTEX_IDX       ) { xPredIntraWedgeTex       ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, false ); }
475  if( uiMode == DMM_WEDGE_PREDTEX_D_IDX     ) { xPredIntraWedgeTex       ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, true, pcCU->getWedgePredTexDeltaDC1( uiAbsPartIdx ), pcCU->getWedgePredTexDeltaDC2( uiAbsPartIdx ) ); }
476  if( uiMode == DMM_CONTOUR_PREDTEX_IDX     ) { xPredIntraContourTex     ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, false ); }
477  if( uiMode == DMM_CONTOUR_PREDTEX_D_IDX   ) { xPredIntraContourTex     ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, true, pcCU->getContourPredTexDeltaDC1( uiAbsPartIdx ), pcCU->getContourPredTexDeltaDC2( uiAbsPartIdx ) ); }
478#endif
479}
480
481Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Int& riDeltaDC )
482{
483  Int  iSign  = riDeltaDC < 0 ? -1 : 1;
484  UInt uiAbs  = abs( riDeltaDC );
485
486  Int iQp = pcCU->getQP(0);
487  Int iMax = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) );
488  Double dStepSize = Clip3( 1, iMax, pow( 2.0, iQp/10.0 + g_dDeltaDCsQuantOffset ) );
489
490  riDeltaDC = iSign * roftoi( uiAbs * dStepSize );
491  return;
492}
493
494Void TComPrediction::calcWedgeDCs( TComWedgelet* pcWedgelet, Pel* piOrig, UInt uiStride, Int& riDC1, Int& riDC2 )
495{
496  UInt uiDC1 = 0;
497  UInt uiDC2 = 0;
498  UInt uiNumPixDC1 = 0, uiNumPixDC2 = 0;
499  Bool* pabWedgePattern = pcWedgelet->getPattern();
500  if( uiStride == pcWedgelet->getStride() )
501  {
502    for( UInt k = 0; k < (pcWedgelet->getWidth() * pcWedgelet->getHeight()); k++ )
503    {
504      if( true == pabWedgePattern[k] ) 
505      {
506        uiDC2 += piOrig[k];
507        uiNumPixDC2++;
508      }
509      else
510      {
511        uiDC1 += piOrig[k];
512        uiNumPixDC1++;
513      }
514    }
515  }
516  else
517  {
518    Pel* piTemp = piOrig;
519    UInt uiWedgeStride = pcWedgelet->getStride();
520    for( UInt uiY = 0; uiY < pcWedgelet->getHeight(); uiY++ )
521    {
522      for( UInt uiX = 0; uiX < pcWedgelet->getWidth(); uiX++ )
523      {
524        if( true == pabWedgePattern[uiX] ) 
525        {
526          uiDC2 += piTemp[uiX];
527          uiNumPixDC2++;
528        }
529        else
530        {
531          uiDC1 += piTemp[uiX];
532          uiNumPixDC1++;
533        }
534      }
535      piTemp          += uiStride;
536      pabWedgePattern += uiWedgeStride;
537    }
538  }
539
540  if( uiNumPixDC1 > 0 ) { riDC1 = uiDC1 / uiNumPixDC1; }
541  else                  { riDC1 = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) ); }
542
543  if( uiNumPixDC2 > 0 ) { riDC2 = uiDC2 / uiNumPixDC2; }
544  else                  { riDC2 = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) ); }
545}
546
547Void TComPrediction::assignWedgeDCs2Pred( TComWedgelet* pcWedgelet, Pel* piPred, UInt uiStride, Int iDC1, Int iDC2 )
548{
549  Bool* pabWedgePattern = pcWedgelet->getPattern();
550
551  if( uiStride == pcWedgelet->getStride() )
552  {
553    for( UInt k = 0; k < (pcWedgelet->getWidth() * pcWedgelet->getHeight()); k++ )
554    {
555      if( true == pabWedgePattern[k] ) 
556      {
557        piPred[k] = iDC2;
558      }
559      else
560      {
561        piPred[k] = iDC1;
562      }
563    }
564  }
565  else
566  {
567    Pel* piTemp = piPred;
568    UInt uiWedgeStride = pcWedgelet->getStride();
569    for( UInt uiY = 0; uiY < pcWedgelet->getHeight(); uiY++ )
570    {
571      for( UInt uiX = 0; uiX < pcWedgelet->getWidth(); uiX++ )
572      {
573        if( true == pabWedgePattern[uiX] ) 
574        {
575          piTemp[uiX] = iDC2;
576        }
577        else
578  {
579          piTemp[uiX] = iDC1;
580        }
581      }
582      piTemp          += uiStride;
583      pabWedgePattern += uiWedgeStride;
584    }
585  }
586}
587
588Void TComPrediction::getWedgePredDCs( TComWedgelet* pcWedgelet, Int* piMask, Int iMaskStride, Int& riPredDC1, Int& riPredDC2, Bool bAbove, Bool bLeft )
589{
590  riPredDC1 = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) ); //pred val, if no neighbors are available
591  riPredDC2 = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) );
592
593  if( !bAbove && !bLeft ) { return; }
594
595  UInt uiNumSmpDC1 = 0, uiNumSmpDC2 = 0;
596  Int iPredDC1 = 0, iPredDC2 = 0;
597
598  Bool* pabWedgePattern = pcWedgelet->getPattern();
599  UInt  uiWedgeStride   = pcWedgelet->getStride();
600
601  if( bAbove )
602  {
603    for( Int k = 0; k < pcWedgelet->getWidth(); k++ )
604    {
605      if( true == pabWedgePattern[k] )
606      {
607        iPredDC2 += piMask[k-iMaskStride];
608        uiNumSmpDC2++;
609      }
610      else
611      {
612        iPredDC1 += piMask[k-iMaskStride];
613        uiNumSmpDC1++;
614      }
615    }
616  }
617  if( bLeft )
618  {
619    for( Int k = 0; k < pcWedgelet->getHeight(); k++ )
620    {
621      if( true == pabWedgePattern[k*uiWedgeStride] )
622      {
623        iPredDC2 += piMask[k*iMaskStride-1];
624        uiNumSmpDC2++;
625      } 
626      else
627      {
628        iPredDC1 += piMask[k*iMaskStride-1];
629        uiNumSmpDC1++;
630      }
631    }
632  }
633
634  if( uiNumSmpDC1 > 0 )
635  {
636    iPredDC1 /= uiNumSmpDC1;
637    riPredDC1 = iPredDC1;
638  }
639  if( uiNumSmpDC2 > 0 )
640  {
641    iPredDC2 /= uiNumSmpDC2;
642    riPredDC2 = iPredDC2;
643  }
644}
645#endif
646
647#if HHI_DMM_WEDGE_INTRA
648Void TComPrediction::xPredIntraWedgeFull( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder, Bool bDelta, UInt uiTabIdx, Int iDeltaDC1, Int iDeltaDC2 )
649{
650  assert( iWidth >= DMM_WEDGEMODEL_MIN_SIZE && iWidth <= DMM_WEDGEMODEL_MAX_SIZE );
651  WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[iWidth])];
652  TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiTabIdx));
653
654  // get wedge pred DCs
655  Int iPredDC1 = 0;
656  Int iPredDC2 = 0;
657
658  Int* piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt );
659  Int iMaskStride = ( iWidth<<1 ) + 1;
660  piMask += iMaskStride+1;
661  getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft );
662
663  if( bDelta ) 
664  {
665    xDeltaDCQuantScaleUp( pcCU, iDeltaDC1 );
666    xDeltaDCQuantScaleUp( pcCU, iDeltaDC2 );
667  }
668
669  // assign wedge pred DCs to prediction
670  if( bDelta ) { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) ); }
671  else         { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, iPredDC1,           iPredDC2           ); }
672}
673
674UInt TComPrediction::getBestContinueWedge( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd )
675{
676  UInt uiThisBlockSize = uiWidth;
677  assert( uiThisBlockSize >= DMM_WEDGEMODEL_MIN_SIZE && uiThisBlockSize <= DMM_WEDGEMODEL_MAX_SIZE );
678  WedgeList*    pacContDWedgeList    = &g_aacWedgeLists   [(g_aucConvertToBit[uiThisBlockSize])];
679  WedgeRefList* pacContDWedgeRefList = &g_aacWedgeRefLists[(g_aucConvertToBit[uiThisBlockSize])];
680
681  UInt uiPredDirWedgeTabIdx = 0;
682  TComDataCU* pcTempCU;
683  UInt        uiTempPartIdx;
684  // 1st: try continue above wedgelet
685  pcTempCU = pcCU->getPUAbove( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
686  if( pcTempCU )
687  {
688    UChar uhLumaIntraDir = pcTempCU->getLumaIntraDir( uiTempPartIdx );
689    if( DMM_WEDGE_FULL_IDX      == uhLumaIntraDir || 
690        DMM_WEDGE_FULL_D_IDX    == uhLumaIntraDir || 
691        DMM_WEDGE_PREDDIR_IDX   == uhLumaIntraDir || 
692        DMM_WEDGE_PREDDIR_D_IDX == uhLumaIntraDir
693#if HHI_DMM_PRED_TEX
694                                                  ||
695        DMM_WEDGE_PREDTEX_IDX   == uhLumaIntraDir ||
696        DMM_WEDGE_PREDTEX_D_IDX == uhLumaIntraDir   
697#endif
698       )
699    {
700      UInt uiRefWedgeSize = (UInt)g_aucIntraSizeIdxToWedgeSize[pcTempCU->getIntraSizeIdx( uiTempPartIdx )];
701      WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[uiRefWedgeSize])];
702
703      // get offset between current and reference block
704      UInt uiOffsetX = 0;
705      UInt uiOffsetY = 0;
706      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
707
708      // get reference wedgelet
709  UInt uiRefWedgeTabIdx = 0;
710      switch( uhLumaIntraDir )
711      {
712      case( DMM_WEDGE_FULL_IDX      ): { uiRefWedgeTabIdx = pcTempCU->getWedgeFullTabIdx   ( uiTempPartIdx ); } break;
713      case( DMM_WEDGE_FULL_D_IDX    ): { uiRefWedgeTabIdx = pcTempCU->getWedgeFullTabIdx   ( uiTempPartIdx ); } break;
714      case( DMM_WEDGE_PREDDIR_IDX   ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredDirTabIdx( uiTempPartIdx ); } break;
715      case( DMM_WEDGE_PREDDIR_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredDirTabIdx( uiTempPartIdx ); } break;
716#if HHI_DMM_PRED_TEX
717      case( DMM_WEDGE_PREDTEX_IDX   ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredTexTabIdx( uiTempPartIdx ); } break;
718      case( DMM_WEDGE_PREDTEX_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredTexTabIdx( uiTempPartIdx ); } break;
719#endif
720      default: { assert( 0 ); return uiPredDirWedgeTabIdx; }
721      }
722      TComWedgelet* pcRefWedgelet;
723      pcRefWedgelet = &(pacWedgeList->at( uiRefWedgeTabIdx ));
724     
725      // find reference wedgelet, if direction is suitable for continue wedge
726      if( pcRefWedgelet->checkPredDirAbovePossible( uiThisBlockSize, uiOffsetX ) )
727      {
728        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
729        pcRefWedgelet->getPredDirStartEndAbove( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetX, iDeltaEnd );
730        getWedgeListIdx( pacContDWedgeList, pacContDWedgeRefList, uiPredDirWedgeTabIdx, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
731        return uiPredDirWedgeTabIdx;
732      }
733    }
734  }
735
736  // 2nd: try continue left wedglelet
737  pcTempCU = pcCU->getPULeft( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx );
738  if( pcTempCU )
739  {
740    UChar uhLumaIntraDir = pcTempCU->getLumaIntraDir( uiTempPartIdx );
741    if( DMM_WEDGE_FULL_IDX      == uhLumaIntraDir || 
742        DMM_WEDGE_FULL_D_IDX    == uhLumaIntraDir || 
743        DMM_WEDGE_PREDDIR_IDX   == uhLumaIntraDir || 
744        DMM_WEDGE_PREDDIR_D_IDX == uhLumaIntraDir
745#if HHI_DMM_PRED_TEX
746                                                  ||
747        DMM_WEDGE_PREDTEX_IDX   == uhLumaIntraDir ||
748        DMM_WEDGE_PREDTEX_D_IDX == uhLumaIntraDir   
749#endif
750      )
751    {
752      UInt uiRefWedgeSize = (UInt)g_aucIntraSizeIdxToWedgeSize[pcTempCU->getIntraSizeIdx( uiTempPartIdx )];
753      WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[uiRefWedgeSize])];
754
755      // get offset between current and reference block
756      UInt uiOffsetX = 0;
757      UInt uiOffsetY = 0;
758      xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY );
759
760      // get reference wedgelet
761      UInt uiRefWedgeTabIdx = 0;
762      switch( uhLumaIntraDir )
763      {
764      case( DMM_WEDGE_FULL_IDX      ): { uiRefWedgeTabIdx = pcTempCU->getWedgeFullTabIdx   ( uiTempPartIdx ); } break;
765      case( DMM_WEDGE_FULL_D_IDX    ): { uiRefWedgeTabIdx = pcTempCU->getWedgeFullTabIdx   ( uiTempPartIdx ); } break;
766      case( DMM_WEDGE_PREDDIR_IDX   ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredDirTabIdx( uiTempPartIdx ); } break;
767      case( DMM_WEDGE_PREDDIR_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredDirTabIdx( uiTempPartIdx ); } break;
768#if HHI_DMM_PRED_TEX
769      case( DMM_WEDGE_PREDTEX_IDX   ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredTexTabIdx( uiTempPartIdx ); } break;
770      case( DMM_WEDGE_PREDTEX_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredTexTabIdx( uiTempPartIdx ); } break;
771#endif
772      default: { assert( 0 ); return uiPredDirWedgeTabIdx; }
773      }
774      TComWedgelet* pcRefWedgelet;
775      pcRefWedgelet = &(pacWedgeList->at( uiRefWedgeTabIdx ));
776
777      // find reference wedgelet, if direction is suitable for continue wedge
778      if( pcRefWedgelet->checkPredDirLeftPossible( uiThisBlockSize, uiOffsetY ) )
779      {
780        UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
781        pcRefWedgelet->getPredDirStartEndLeft( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetY, iDeltaEnd );
782        getWedgeListIdx( pacContDWedgeList, pacContDWedgeRefList, uiPredDirWedgeTabIdx, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
783        return uiPredDirWedgeTabIdx;
784      }
785    }
786  }
787
788  // 3rd: (default) make wedglet from intra dir and max slope point
789  Int iSlopeX = 0;
790  Int iSlopeY = 0;
791  UInt uiStartPosX = 0;
792  UInt uiStartPosY = 0;
793  if( xGetWedgeIntraDirPredData( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY ) )
794  {
795    UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye;
796    xGetWedgeIntraDirStartEnd( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, iDeltaEnd );
797    getWedgeListIdx( pacContDWedgeList, pacContDWedgeRefList, uiPredDirWedgeTabIdx, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye );
798    return uiPredDirWedgeTabIdx;
799  }
800
801  return uiPredDirWedgeTabIdx;
802}
803
804Void TComPrediction::xGetBlockOffset( TComDataCU* pcCU, UInt uiAbsPartIdx, TComDataCU* pcRefCU, UInt uiRefAbsPartIdx, UInt& ruiOffsetX, UInt& ruiOffsetY )
805{
806  ruiOffsetX = 0;
807  ruiOffsetY = 0;
808
809  // get offset between current and above/left block
810  UInt uiThisOriginX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
811  UInt uiThisOriginY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
812
813  UInt uiNumPartInRefCU = pcRefCU->getTotalNumPart();
814  UInt uiMaxDepthRefCU = 0;
815  while( uiNumPartInRefCU > 1 )
816  {
817    uiNumPartInRefCU >>= 2;
818    uiMaxDepthRefCU++;
819  }
820
821  UInt uiDepthRefPU = (pcRefCU->getDepth(uiRefAbsPartIdx)) + (pcRefCU->getPartitionSize(uiRefAbsPartIdx) == SIZE_2Nx2N ? 0 : 1);
822  UInt uiShifts = (uiMaxDepthRefCU - uiDepthRefPU)*2;
823  UInt uiRefBlockOriginPartIdx = (uiRefAbsPartIdx>>uiShifts)<<uiShifts;
824
825  UInt uiRefOriginX = pcRefCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ];
826  UInt uiRefOriginY = pcRefCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ];
827
828  if( (uiThisOriginX - uiRefOriginX) > 0 ) { ruiOffsetX = (UInt)(uiThisOriginX - uiRefOriginX); }
829  if( (uiThisOriginY - uiRefOriginY) > 0 ) { ruiOffsetY = (UInt)(uiThisOriginY - uiRefOriginY); }
830}
831
832Bool TComPrediction::xGetWedgeIntraDirPredData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int& riSlopeX, Int& riSlopeY, UInt& ruiStartPosX, UInt& ruiStartPosY )
833{
834  riSlopeX     = 0;
835  riSlopeY     = 0;
836  ruiStartPosX = 0;
837  ruiStartPosY = 0;
838
839  // 1st step: get wedge start point (max. slope)
840  Int* piSource = pcCU->getPattern()->getAdiOrgBuf( uiBlockSize, uiBlockSize, m_piYuvExt );
841  Int iSourceStride = ( uiBlockSize<<1 ) + 1;
842
843  UInt uiSlopeMaxAbove = 0;
844  UInt uiPosSlopeMaxAbove = 0;
845  for( UInt uiPosHor = 0; uiPosHor < (uiBlockSize-1); uiPosHor++ )
846  {
847    if( abs( piSource[uiPosHor+1] - piSource[uiPosHor] ) > uiSlopeMaxAbove )
848    {
849      uiSlopeMaxAbove = abs( piSource[uiPosHor+1] - piSource[uiPosHor] );
850      uiPosSlopeMaxAbove = uiPosHor;
851    }
852  }
853
854  UInt uiSlopeMaxLeft = 0;
855  UInt uiPosSlopeMaxLeft = 0;
856  for( UInt uiPosVer = 0; uiPosVer < (uiBlockSize-1); uiPosVer++ )
857  {
858    if( abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] ) > uiSlopeMaxLeft )
859    {
860      uiSlopeMaxLeft = abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] );
861      uiPosSlopeMaxLeft = uiPosVer;
862    }
863  }
864
865  if( uiSlopeMaxAbove == 0 && uiSlopeMaxLeft == 0 ) 
866  { 
867    return false; 
868  }
869
870  if( uiSlopeMaxAbove > uiSlopeMaxLeft )
871  {
872    ruiStartPosX = uiPosSlopeMaxAbove;
873    ruiStartPosY = 0;
874  }
875  else
876  {
877    ruiStartPosX = 0;
878    ruiStartPosY = uiPosSlopeMaxLeft;
879  }
880
881  // 2nd step: derive wedge direction
882  Int angTable[9] = {0,2,5,9,13,17,21,26,32};
883
884  Int uiPreds[2] = {-1, -1};
885  Int uiPredNum = pcCU->getIntraDirLumaPredictor( uiAbsPartIdx, uiPreds );
886
887  UInt uiDirMode = 0;
888  if( uiPredNum == 1 )
889  {
890    uiDirMode = g_aucAngIntraModeOrder[uiPreds[0]];
891  }
892  else if( uiPredNum == 2 )
893  {
894    uiDirMode = g_aucAngIntraModeOrder[uiPreds[1]];
895  }
896
897  if( uiDirMode == 0 ) 
898  { 
899    return false; 
900  }
901
902  Bool modeVer       = (uiDirMode < 18);
903  Bool modeHor       = !modeVer;
904  Int intraPredAngle = modeVer ? uiDirMode - 9 : modeHor ? uiDirMode - 25 : 0;
905  Int absAng         = abs(intraPredAngle);
906  Int signAng        = intraPredAngle < 0 ? -1 : 1;
907  absAng             = angTable[absAng];
908  intraPredAngle     = signAng * absAng;
909
910  // 3rd step: set slope for direction
911  if( modeHor )
912    {
913    if( intraPredAngle > 0 )
914    {
915      riSlopeX = -32;
916      riSlopeY = intraPredAngle;
917    }
918    else
919    {
920      riSlopeX = 32;
921      riSlopeY = -intraPredAngle;
922    }
923    }
924  else if( modeVer )
925  {
926    if( intraPredAngle > 0 )
927    {
928      riSlopeX = intraPredAngle;
929      riSlopeY = -32;
930  }
931  else
932  {
933      riSlopeX = -intraPredAngle;
934      riSlopeY = 32;
935    }
936  }
937
938    return true;
939}
940
941Void 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 )
942{
943  ruhXs = 0;
944  ruhYs = 0;
945  ruhXe = 0;
946  ruhYe = 0;
947  UInt uiOri;
948
949  // scaling of start pos and block size to wedge resolution
950  UInt uiScaledStartPosX = 0;
951  UInt uiScaledStartPosY = 0;
952  UInt uiScaledBlockSize = 0;
953  WedgeResolution eWedgeRes = g_aeWedgeResolutionList[(UInt)g_aucConvertToBit[uiBlockSize]];
954  switch( eWedgeRes )
955  {
956  case( DOUBLE_PEL ): { uiScaledStartPosX = (uiPMSPosX>>1); uiScaledStartPosY = (uiPMSPosY>>1); uiScaledBlockSize = (uiBlockSize>>1); break; }
957  case(   FULL_PEL ): { uiScaledStartPosX =  uiPMSPosX;     uiScaledStartPosY =  uiPMSPosY;     uiScaledBlockSize =  uiBlockSize;     break; }
958  case(   HALF_PEL ): { uiScaledStartPosX = (uiPMSPosX<<1); uiScaledStartPosY = (uiPMSPosY<<1); uiScaledBlockSize = (uiBlockSize<<1); break; }
959}
960
961  // case above
962  if( uiScaledStartPosX > 0 && uiScaledStartPosY == 0 )
963  {
964    ruhXs = (UChar)uiScaledStartPosX;
965    ruhYs = 0;
966
967    if( iDeltaY == 0 )
968{
969      if( iDeltaX < 0 )
970      {
971        uiOri = 0;
972        ruhXe = 0;
973        ruhYe = (UChar)Min( Max( iDeltaEnd, 0 ), (uiScaledBlockSize-1) );
974        return;
975      }
976      else
977      {
978        uiOri = 1;
979        ruhXe = (UChar)(uiScaledBlockSize-1); ;
980        ruhYe = (UChar)Min( Max( -iDeltaEnd, 0 ), (uiScaledBlockSize-1) );
981        std::swap( ruhXs, ruhXe );
982        std::swap( ruhYs, ruhYe );
983        return;
984      }
985    }
986
987    // regular case
988    Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)(uiScaledBlockSize-1) * ((Double)iDeltaX / (Double)iDeltaY) );
989
990    if( iVirtualEndX < 0 )
991    {
992      Int iYe = roftoi( (Double)(0 - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) + iDeltaEnd;
993      if( iYe < (Int)uiScaledBlockSize )
994      {
995        uiOri = 0;
996        ruhXe = 0;
997        ruhYe = (UChar)Max( iYe, 0 );
998        return;
999      }
1000      else
1001      {
1002        uiOri = 4;
1003        ruhXe = (UChar)Min( (iYe - (uiScaledBlockSize-1)), (uiScaledBlockSize-1) );
1004        ruhYe = (UChar)(uiScaledBlockSize-1);
1005        return;
1006      }
1007    }
1008    else if( iVirtualEndX > (uiScaledBlockSize-1) )
1009    {
1010      Int iYe = roftoi( (Double)((Int)(uiScaledBlockSize-1) - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd;
1011      if( iYe < (Int)uiScaledBlockSize )
1012      {
1013        uiOri = 1;
1014        ruhXe = (UChar)(uiScaledBlockSize-1);
1015        ruhYe = (UChar)Max( iYe, 0 );
1016        std::swap( ruhXs, ruhXe );
1017        std::swap( ruhYs, ruhYe );
1018        return;
1019      }
1020      else
1021      {
1022        uiOri = 4;
1023        ruhXe = (UChar)Max( ((uiScaledBlockSize-1) - (iYe - (uiScaledBlockSize-1))), 0 );
1024        ruhYe = (UChar)(uiScaledBlockSize-1);
1025        return;
1026      }
1027    }
1028    else
1029    {
1030      Int iXe = iVirtualEndX + iDeltaEnd;
1031      if( iXe < 0 )
1032      {
1033        uiOri = 0;
1034        ruhXe = 0;
1035        ruhYe = (UChar)Max( ((uiScaledBlockSize-1) + iXe), 0 );
1036        return;
1037      }
1038      else if( iXe > (uiScaledBlockSize-1) )
1039      {
1040        uiOri = 1;
1041        ruhXe = (UChar)(uiScaledBlockSize-1);
1042        ruhYe = (UChar)Max( ((uiScaledBlockSize-1) - (iXe - (uiScaledBlockSize-1))), 0 );
1043        std::swap( ruhXs, ruhXe );
1044        std::swap( ruhYs, ruhYe );
1045        return;
1046      }
1047      else
1048      {
1049        uiOri = 4;
1050        ruhXe = (UChar)iXe;
1051        ruhYe = (UChar)(uiScaledBlockSize-1);
1052        return;
1053      }
1054    }
1055  }
1056
1057  // case left
1058  if( uiScaledStartPosY > 0 && uiScaledStartPosX == 0 )
1059  {
1060    ruhXs = 0;
1061    ruhYs = (UChar)uiScaledStartPosY;
1062
1063    if( iDeltaX == 0 )
1064    {
1065      if( iDeltaY < 0 )
1066      {
1067        uiOri = 0;
1068        ruhXe = (UChar)Min( Max( -iDeltaEnd, 0 ), (uiScaledBlockSize-1) );
1069        ruhYe = 0;
1070        std::swap( ruhXs, ruhXe );
1071        std::swap( ruhYs, ruhYe );
1072        return;
1073      }
1074      else
1075      {
1076        uiOri = 3;
1077        ruhXe = (UChar)Min( Max( iDeltaEnd, 0 ), (uiScaledBlockSize-1) );
1078        ruhYe = (UChar)(uiScaledBlockSize-1); 
1079        return; 
1080      }
1081    }
1082
1083    // regular case
1084    Int iVirtualEndY = (Int)ruhYs + roftoi( (Double)(uiScaledBlockSize-1) * ((Double)iDeltaY / (Double)iDeltaX) );
1085
1086    if( iVirtualEndY < 0 )
1087    {
1088      Int iXe = roftoi( (Double)(0 - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) - iDeltaEnd;
1089      if( iXe < (Int)uiScaledBlockSize )
1090      {
1091        uiOri = 0;
1092        ruhXe = (UChar)Max( iXe, 0 );
1093        ruhYe = 0;
1094        std::swap( ruhXs, ruhXe );
1095        std::swap( ruhYs, ruhYe );
1096        return;
1097      }
1098      else
1099      {
1100        uiOri = 5;
1101        ruhXe = (UChar)(uiScaledBlockSize-1);
1102        ruhYe = (UChar)Min( (iXe - (uiScaledBlockSize-1)), (uiScaledBlockSize-1) );
1103        std::swap( ruhXs, ruhXe );
1104        std::swap( ruhYs, ruhYe );
1105        return;
1106      }
1107    }
1108    else if( iVirtualEndY > (uiScaledBlockSize-1) )
1109    {
1110      Int iXe = roftoi( (Double)((Int)(uiScaledBlockSize-1) - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) + iDeltaEnd;
1111      if( iXe < (Int)uiScaledBlockSize )
1112      {
1113        uiOri = 3;
1114        ruhXe = (UChar)Max( iXe, 0 );
1115        ruhYe = (UChar)(uiScaledBlockSize-1);
1116        return;
1117      }
1118      else
1119      {
1120        uiOri = 5;
1121        ruhXe = (UChar)(uiScaledBlockSize-1);
1122        ruhYe = (UChar)Max( ((uiScaledBlockSize-1) - (iXe - (uiScaledBlockSize-1))), 0 );
1123        std::swap( ruhXs, ruhXe );
1124        std::swap( ruhYs, ruhYe );
1125        return;
1126      }
1127    }
1128    else
1129    {
1130      Int iYe = iVirtualEndY - iDeltaEnd;
1131      if( iYe < 0 )
1132      {
1133        uiOri = 0;
1134        ruhXe = (UChar)Max( ((uiScaledBlockSize-1) + iYe), 0 );
1135        ruhYe = 0;
1136        std::swap( ruhXs, ruhXe );
1137        std::swap( ruhYs, ruhYe );
1138        return;
1139      }
1140      else if( iYe > (uiScaledBlockSize-1) )
1141      {
1142        uiOri = 3;
1143        ruhXe = (UChar)Max( ((uiScaledBlockSize-1) - (iYe - (uiScaledBlockSize-1))), 0 );
1144        ruhYe = (UChar)(uiScaledBlockSize-1);
1145        return;
1146      }
1147      else
1148      {
1149        uiOri = 5;
1150        ruhXe = (UChar)(uiScaledBlockSize-1);
1151        ruhYe = (UChar)iYe;
1152        std::swap( ruhXs, ruhXe );
1153        std::swap( ruhYs, ruhYe );
1154        return;
1155      }
1156    }
1157  }
1158
1159  // case origin
1160  if( uiScaledStartPosX == 0 && uiScaledStartPosY == 0 )
1161  {
1162    if( iDeltaX*iDeltaY < 0 )
1163    {
1164      return;
1165    }
1166
1167    ruhXs = 0;
1168    ruhYs = 0;
1169
1170    if( iDeltaY == 0 )
1171    {
1172      uiOri = 1;
1173      ruhXe = (UChar)(uiScaledBlockSize-1);
1174      ruhYe = 0;
1175      std::swap( ruhXs, ruhXe );
1176      std::swap( ruhYs, ruhYe );
1177      return;
1178  }
1179
1180    if( iDeltaX == 0 )
1181    {
1182      uiOri = 0;
1183      ruhXe = 0;
1184      ruhYe = (UChar)(uiScaledBlockSize-1);
1185      return;
1186  }
1187
1188    Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)(uiScaledBlockSize-1) * ((Double)iDeltaX / (Double)iDeltaY) );
1189
1190    if( iVirtualEndX > (uiScaledBlockSize-1) )
1191    {
1192      Int iYe = roftoi( (Double)((Int)(uiScaledBlockSize-1) - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd;
1193      if( iYe < (Int)uiScaledBlockSize )
1194      {
1195        uiOri = 1;
1196        ruhXe = (UChar)(uiScaledBlockSize-1);
1197        ruhYe = (UChar)Max( iYe, 0 );
1198        std::swap( ruhXs, ruhXe );
1199        std::swap( ruhYs, ruhYe );
1200        return;
1201      }
1202      else
1203      {
1204        uiOri = 3;
1205        ruhXe = (UChar)Max( ((uiScaledBlockSize-1) - (iYe - (uiScaledBlockSize-1))), 0 );
1206        ruhYe = (UChar)(uiScaledBlockSize-1);
1207        return;
1208      }
1209    }
1210    else
1211    {
1212      Int iXe = iVirtualEndX + iDeltaEnd;
1213      if( iXe < 0 )
1214      {
1215        uiOri = 0;
1216        ruhXe = 0;
1217        ruhYe = (UChar)Max( ((uiScaledBlockSize-1) + iXe), 0 );
1218        return;
1219      }
1220      else if( iXe > (uiScaledBlockSize-1) )
1221      {
1222        uiOri = 1;
1223        ruhXe = (UChar)(uiScaledBlockSize-1);
1224        ruhYe = (UChar)Max( ((uiScaledBlockSize-1) - (iXe - (uiScaledBlockSize-1))), 0 );
1225        std::swap( ruhXs, ruhXe );
1226        std::swap( ruhYs, ruhYe );
1227        return;
1228      }
1229      else
1230      {
1231        uiOri = 3;
1232        ruhXe = (UChar)iXe;
1233        ruhYe = (UChar)(uiScaledBlockSize-1);
1234        return;
1235      }
1236    }
1237  }
1238}
1239
1240Bool TComPrediction::getWedgeListIdx( WedgeList* pcWedgeList, WedgeRefList* pcWedgeRefList, UInt& ruiTabIdx, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe )
1241{
1242  ruiTabIdx = 0;
1243
1244  for( UInt uiIdx = 0; uiIdx < pcWedgeList->size(); uiIdx++ )
1245  {
1246    TComWedgelet* pcTestWedge = &(pcWedgeList->at(uiIdx));
1247
1248    if( pcTestWedge->getStartX() == uhXs &&
1249        pcTestWedge->getStartY() == uhYs &&
1250        pcTestWedge->getEndX()   == uhXe &&
1251        pcTestWedge->getEndY()   == uhYe    )
1252    {
1253      ruiTabIdx = uiIdx;
1254      return true;
1255    }
1256  }
1257
1258  // additionally search in WedgeRef lists of duplicated patterns
1259  for( UInt uiIdx = 0; uiIdx < pcWedgeRefList->size(); uiIdx++ )
1260  {
1261    TComWedgeRef* pcTestWedgeRef = &(pcWedgeRefList->at(uiIdx));
1262
1263    if( pcTestWedgeRef->getStartX() == uhXs &&
1264        pcTestWedgeRef->getStartY() == uhYs &&
1265        pcTestWedgeRef->getEndX()   == uhXe &&
1266        pcTestWedgeRef->getEndY()   == uhYe    )
1267    {
1268      ruiTabIdx = pcTestWedgeRef->getRefIdx();
1269      return true;
1270    }
1271  }
1272
1273  return false;
1274}
1275
1276Void TComPrediction::xPredIntraWedgeDir( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder, Bool bDelta, Int iWedgeDeltaEnd, Int iDeltaDC1, Int iDeltaDC2 )
1277{
1278  assert( iWidth >= DMM_WEDGEMODEL_MIN_SIZE && iWidth <= DMM_WEDGEMODEL_MAX_SIZE );
1279  WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[iWidth])];
1280
1281  // get wedge pattern
1282  UInt uiDirWedgeTabIdx = 0;
1283  if( bEncoder )
1284  {
1285    // encoder: load stored wedge pattern from CU
1286    uiDirWedgeTabIdx = pcCU->getWedgePredDirTabIdx( uiAbsPartIdx );
1287  }
1288  else
1289  {
1290    uiDirWedgeTabIdx = getBestContinueWedge( pcCU, uiAbsPartIdx, iWidth, iHeight, iWedgeDeltaEnd );
1291
1292    UInt uiDepth = (pcCU->getDepth(0)) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1);
1293    pcCU->setWedgePredDirTabIdxSubParts( uiDirWedgeTabIdx, uiAbsPartIdx, uiDepth );
1294  }
1295  TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiDirWedgeTabIdx));
1296
1297  // get wedge pred DCs
1298  Int iPredDC1 = 0;
1299  Int iPredDC2 = 0;
1300
1301  Int* piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt );
1302  Int iMaskStride = ( iWidth<<1 ) + 1;
1303  piMask += iMaskStride+1;
1304  getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft );
1305
1306  if( bDelta ) 
1307  {
1308    xDeltaDCQuantScaleUp( pcCU, iDeltaDC1 );
1309    xDeltaDCQuantScaleUp( pcCU, iDeltaDC2 );
1310  }
1311
1312  // assign wedge pred DCs to prediction
1313  if( bDelta ) { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip ( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) ); }
1314  else         { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride,        iPredDC1,                   iPredDC2             ); }
1315}
1316#endif
1317
1318#if HHI_DMM_PRED_TEX
1319Void TComPrediction::xPredIntraWedgeTex( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder, Bool bDelta, Int iDeltaDC1, Int iDeltaDC2 )
1320{
1321  assert( iWidth >= DMM_WEDGEMODEL_MIN_SIZE && iWidth <= DMM_WEDGEMODEL_MAX_SIZE );
1322  WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[iWidth])];
1323
1324  // get wedge pattern
1325  UInt uiTextureWedgeTabIdx = 0;
1326  if( bEncoder ) 
1327  {
1328     // encoder: load stored wedge pattern from CU
1329    uiTextureWedgeTabIdx = pcCU->getWedgePredTexTabIdx( uiAbsPartIdx );
1330  }
1331  else
1332  {
1333    // decoder: get and store wedge pattern in CU
1334    uiTextureWedgeTabIdx = getBestWedgeFromText( pcCU, uiAbsPartIdx, (UInt)iWidth, (UInt)iHeight );
1335    UInt uiDepth = (pcCU->getDepth(0)) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1);
1336    pcCU->setWedgePredTexTabIdxSubParts( uiTextureWedgeTabIdx, uiAbsPartIdx, uiDepth );
1337  }
1338  TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiTextureWedgeTabIdx));
1339
1340  // get wedge pred DCs
1341  Int iPredDC1 = 0;
1342  Int iPredDC2 = 0;
1343  Int* piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt );
1344  Int iMaskStride = ( iWidth<<1 ) + 1;
1345  piMask += iMaskStride+1;
1346  getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft );
1347
1348  if( bDelta ) 
1349  {
1350    xDeltaDCQuantScaleUp( pcCU, iDeltaDC1 );
1351    xDeltaDCQuantScaleUp( pcCU, iDeltaDC2 );
1352  }
1353
1354  // assign wedge pred DCs to prediction
1355  if( bDelta ) { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip ( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) ); }
1356  else         { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride,        iPredDC1,                   iPredDC2           ); }
1357}
1358
1359Void TComPrediction::xPredIntraContourTex( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder, Bool bDelta, Int iDeltaDC1, Int iDeltaDC2 )
1360{
1361  // get contour pattern
1362  TComWedgelet* pcContourWedge = new TComWedgelet( iWidth, iHeight );
1363  getBestContourFromText( pcCU, uiAbsPartIdx, (UInt)iWidth, (UInt)iHeight, pcContourWedge );
1364
1365  // get wedge pred DCs
1366  Int iPredDC1 = 0;
1367  Int iPredDC2 = 0;
1368  Int* piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt );
1369  Int iMaskStride = ( iWidth<<1 ) + 1;
1370  piMask += iMaskStride+1;
1371  getWedgePredDCs( pcContourWedge, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft );
1372
1373  if( bDelta ) 
1374  {
1375    xDeltaDCQuantScaleUp( pcCU, iDeltaDC1 );
1376    xDeltaDCQuantScaleUp( pcCU, iDeltaDC2 );
1377  }
1378
1379  // assign wedge pred DCs to prediction
1380  if( bDelta ) { assignWedgeDCs2Pred( pcContourWedge, piPred, uiStride, Clip ( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) ); }
1381  else         { assignWedgeDCs2Pred( pcContourWedge, piPred, uiStride,        iPredDC1,                   iPredDC2           ); }
1382
1383  pcContourWedge->destroy();
1384  delete pcContourWedge;
1385}
1386
1387Void TComPrediction::getBestContourFromText( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge, Pel* piTextureBlock )
1388{
1389  pcContourWedge->clear();
1390  Bool* pabContourPattern = pcContourWedge->getPattern();
1391
1392  // get copy of according texture luma block
1393  Pel* piTempY = NULL;
1394  TComYuv cTempYuv;
1395
1396  if ( piTextureBlock )
1397  {
1398    piTempY = piTextureBlock;
1399  }
1400  else
1401  {
1402    cTempYuv.create( uiWidth, uiHeight ); cTempYuv.clear();
1403    piTempY      = cTempYuv.getLumaAddr();
1404
1405    fillTexturePicTempBlock( pcCU, uiAbsPartIdx, piTempY, uiWidth, uiHeight );
1406
1407    piTempY = cTempYuv.getLumaAddr();
1408  }
1409
1410  // find contour for texture luma block
1411  UInt iDC = 0;
1412  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) { iDC += piTempY[k]; }
1413  iDC /= (uiWidth*uiHeight);
1414
1415  if ( piTextureBlock )
1416  {
1417    piTempY = piTextureBlock;
1418  }
1419  else
1420  {
1421    piTempY = cTempYuv.getLumaAddr();
1422  }
1423
1424  for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) 
1425  { 
1426    pabContourPattern[k] = (piTempY[k] > iDC) ? true : false;
1427  }
1428
1429  cTempYuv.destroy();
1430}
1431
1432UInt TComPrediction::getBestWedgeFromText( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, WedgeDist eWedgeDist, Pel* piTextureBlock )
1433{
1434  assert( uiWidth >= DMM_WEDGEMODEL_MIN_SIZE && uiWidth <= DMM_WEDGEMODEL_MAX_SIZE );
1435  WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[uiWidth])];
1436
1437  // get copy of according texture luma block
1438  Pel* piTempY = NULL;   
1439  TComYuv     cTempYuv; 
1440
1441  if ( piTextureBlock )
1442  {
1443    piTempY = piTextureBlock;
1444  } 
1445  else
1446  {
1447    cTempYuv.create( uiWidth, uiHeight ); cTempYuv.clear();
1448    piTempY      = cTempYuv.getLumaAddr();
1449
1450    fillTexturePicTempBlock( pcCU, uiAbsPartIdx, piTempY, uiWidth, uiHeight );
1451
1452    piTempY = cTempYuv.getLumaAddr();
1453  }
1454 
1455  TComWedgeDist cWedgeDist;
1456  UInt uiTextureWedgeTabIdx = 0;
1457
1458  // local pred buffer
1459  TComYuv cPredYuv; 
1460  cPredYuv.create( uiWidth, uiHeight ); 
1461  cPredYuv.clear();
1462
1463  UInt uiPredStride = cPredYuv.getStride();
1464  Pel* piPred       = cPredYuv.getLumaAddr();
1465
1466  Int  iDC1 = 0;
1467  Int  iDC2 = 0;
1468  // regular wedge search
1469  UInt uiBestDist   = MAX_UINT;
1470  UInt uiBestTabIdx = 0;
1471
1472  for( UInt uiIdx = 0; uiIdx < pacWedgeList->size(); uiIdx++ )
1473  {
1474    calcWedgeDCs       ( &(pacWedgeList->at(uiIdx)), piTempY,  uiWidth,  iDC1, iDC2 );
1475    assignWedgeDCs2Pred( &(pacWedgeList->at(uiIdx)), piPred, uiPredStride, iDC1, iDC2 );
1476
1477    UInt uiActDist = cWedgeDist.getDistPart( piPred, uiPredStride, piTempY, uiWidth, uiWidth, uiHeight, eWedgeDist );
1478
1479    if( uiActDist < uiBestDist || uiBestDist == MAX_UINT )
1480    {
1481      uiBestDist   = uiActDist;
1482      uiBestTabIdx = uiIdx;
1483    }
1484  }
1485  uiTextureWedgeTabIdx = uiBestTabIdx;
1486
1487  cPredYuv.destroy();
1488  cTempYuv.destroy();
1489  return uiTextureWedgeTabIdx;
1490}
1491
1492Void TComPrediction::fillTexturePicTempBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piTempBlockY, UInt uiWidth, UInt uiHeight )
1493{
1494  TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec();
1495  Int         iRefStride = pcPicYuvRef->getStride();
1496  Pel*        piRefY;
1497
1498  piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx );
1499
1500  for ( Int y = 0; y < uiHeight; y++ )
1501  {
1502    ::memcpy(piTempBlockY, piRefY, sizeof(Pel)*uiWidth);
1503    piTempBlockY += uiWidth;
1504    piRefY += iRefStride;
1505  }
1506}
1507#endif
1508
1509#if DEPTH_MAP_GENERATION
1510Void TComPrediction::motionCompensation( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY )
1511#else
1512Void TComPrediction::motionCompensation( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
1513#endif
1514{
1515  Int         iWidth;
1516  Int         iHeight;
1517  UInt        uiPartAddr;
1518
1519  if ( iPartIdx >= 0 )
1520  {
1521    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
1522
1523#if POZNAN_DBMP
1524        if(pcCU->getMergeIndex(uiPartAddr)==POZNAN_DBMP_MRG_CAND) 
1525        {
1526#if DEPTH_MAP_GENERATION
1527                motionCompensation_DBMP( pcCU, pcYuvPred, eRefPicList, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY );
1528#else
1529                motionCompensation_DBMP( pcCU, pcYuvPred, eRefPicList, iPartIdx );
1530#endif
1531                return;
1532        }
1533#endif
1534
1535#if DEPTH_MAP_GENERATION
1536    if( bPrdDepthMap )
1537    {
1538      iWidth  >>= uiSubSampExpX;
1539      iHeight >>= uiSubSampExpY;
1540    }
1541#endif
1542
1543    if ( eRefPicList != REF_PIC_LIST_X )
1544    {
1545#if DEPTH_MAP_GENERATION
1546      xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY );
1547#else
1548      xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx );
1549#endif
1550#ifdef WEIGHT_PRED
1551      if ( pcCU->getSlice()->getPPS()->getUseWP() )
1552      {
1553        xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx );
1554      }
1555#endif   
1556    }
1557    else
1558    {
1559#if DEPTH_MAP_GENERATION
1560      xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, pcYuvPred, iPartIdx, bPrdDepthMap );
1561#else
1562      xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred, iPartIdx );
1563#endif
1564    }
1565    return;
1566  }
1567
1568  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
1569  {
1570    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
1571
1572#if POZNAN_DBMP
1573        if(pcCU->getMergeIndex(uiPartAddr)==POZNAN_DBMP_MRG_CAND) 
1574        {
1575#if DEPTH_MAP_GENERATION
1576                motionCompensation_DBMP( pcCU, pcYuvPred, eRefPicList, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY );
1577#else
1578                motionCompensation_DBMP( pcCU, pcYuvPred, eRefPicList, iPartIdx );
1579#endif
1580                continue;
1581        }
1582#endif
1583
1584#if DEPTH_MAP_GENERATION
1585    if( bPrdDepthMap )
1586    {
1587      iWidth  >>= uiSubSampExpX;
1588      iHeight >>= uiSubSampExpY;
1589    }
1590#endif
1591
1592    if ( eRefPicList != REF_PIC_LIST_X )
1593    {
1594#if DEPTH_MAP_GENERATION
1595      xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY );
1596#else
1597      xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx );
1598#endif
1599#ifdef WEIGHT_PRED
1600      if ( pcCU->getSlice()->getPPS()->getUseWP() )
1601      {
1602        xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx );
1603      }
1604#endif
1605    }
1606    else
1607    {
1608#if DEPTH_MAP_GENERATION
1609      xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, pcYuvPred, iPartIdx, bPrdDepthMap );
1610#else
1611      xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred, iPartIdx );
1612#endif
1613    }
1614  }
1615  return;
1616}
1617
1618#if POZNAN_DBMP
1619#if DEPTH_MAP_GENERATION
1620Void TComPrediction::motionCompensation_DBMP ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY )
1621#else
1622Void TComPrediction::motionCompensation_DBMP ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
1623#endif
1624{
1625  if(!pcCU->getSlice()->getMP()->isDBMPEnabled()) return;
1626
1627  Int         iPartIdxOrg = iPartIdx;
1628  Int         iWidth;
1629  Int         iHeight;
1630  UInt        uiPartAddr;
1631
1632  Int             x,y;
1633  Int             px,py,iCUBaseX,iCUBaseY;
1634  Int             ref_frame0, ref_frame1;
1635  Int             ref_frame0_idx, ref_frame1_idx;
1636  TComMv          mv0,mv1;
1637 
1638  Int             ref_frame0_idx_2nd, ref_frame1_idx_2nd;
1639  TComMv          mv0_2nd,mv1_2nd;
1640
1641  Pel* piDstCb;
1642  Pel* piDstCr;
1643  Pel aiUTab[MAX_CU_SIZE];
1644  Pel aiVTab[MAX_CU_SIZE];
1645  Pel iULast;
1646  Pel iVLast;
1647  Pel iTemp;
1648
1649  TComMP* pcMP = pcCU->getSlice()->getMP();
1650  UInt uiViewId = pcCU->getSlice()->getSPS()->getViewId();
1651  Bool bIsDepth = pcCU->getSlice()->getSPS()->isDepth();
1652
1653#if POZNAN_DBMP_CALC_PRED_DATA
1654  UInt uiPointCnt;
1655#endif
1656   
1657  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
1658  {
1659        if ( iPartIdxOrg >= 0 ) iPartIdx = iPartIdxOrg;
1660
1661    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
1662
1663        //get motion data used for no-MP predicted points
1664#if POZNAN_DBMP_CALC_PRED_DATA
1665        ref_frame0_idx_2nd = pcCU->getCUMvField2nd(REF_PIC_LIST_0)->getRefIdx(uiPartAddr);
1666        mv0_2nd = pcCU->getCUMvField2nd( REF_PIC_LIST_0 )->getMv( uiPartAddr );
1667
1668        ref_frame1_idx_2nd = pcCU->getCUMvField2nd(REF_PIC_LIST_1)->getRefIdx(uiPartAddr);
1669        mv1_2nd = pcCU->getCUMvField2nd( REF_PIC_LIST_1 )->getMv( uiPartAddr );
1670#else
1671        ref_frame0_idx_2nd = pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(uiPartAddr);
1672        mv0_2nd = pcCU->getCUMvField( REF_PIC_LIST_0 )->getMv( uiPartAddr );
1673
1674        ref_frame1_idx_2nd = pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(uiPartAddr);
1675        mv1_2nd = pcCU->getCUMvField( REF_PIC_LIST_1 )->getMv( uiPartAddr );
1676#endif
1677
1678        iCUBaseX = pcCU->getCUPelX()+g_auiRasterToPelX[ g_auiZscanToRaster[uiPartAddr] ];
1679        iCUBaseY = pcCU->getCUPelY()+g_auiRasterToPelY[ g_auiZscanToRaster[uiPartAddr] ];
1680
1681#if DEPTH_MAP_GENERATION
1682    if( bPrdDepthMap )
1683    {
1684      iWidth  >>= uiSubSampExpX;
1685      iHeight >>= uiSubSampExpY;
1686    }
1687#endif
1688
1689#if POZNAN_DBMP_CALC_PRED_DATA
1690        uiPointCnt = 0;
1691#endif
1692
1693        for( py = 0; py < iHeight; py++)
1694        {
1695                for( px = 0; px < iWidth; px++)
1696                {
1697#if DEPTH_MAP_GENERATION
1698                        if( bPrdDepthMap )
1699                        {
1700                                x = iCUBaseX+(px<<uiSubSampExpX);
1701                                y = iCUBaseY+(py<<uiSubSampExpY);
1702                        }
1703                        else
1704#endif
1705                        {
1706                                x = iCUBaseX+px;
1707                                y = iCUBaseY+py;
1708                        }
1709
1710                        pcMP->getDBMPPredData(pcCU, x, y, ref_frame0, ref_frame0_idx, mv0, ref_frame0_idx_2nd, mv0_2nd, 
1711                                                                                ref_frame1, ref_frame1_idx, mv1, ref_frame1_idx_2nd, mv1_2nd);
1712
1713                        pcCU->getCUMvField(REF_PIC_LIST_0)->setRefIdx(ref_frame0_idx, uiPartAddr);
1714                        pcCU->getCUMvField( REF_PIC_LIST_0 )->setMv( mv0, uiPartAddr );
1715
1716                        pcCU->getCUMvField(REF_PIC_LIST_1)->setRefIdx(ref_frame1_idx, uiPartAddr);
1717                        pcCU->getCUMvField( REF_PIC_LIST_1 )->setMv( mv1, uiPartAddr );
1718
1719                        if ( eRefPicList != REF_PIC_LIST_X )
1720                        {
1721#if DEPTH_MAP_GENERATION
1722                          xPredInterUni_DBMP (pcCU, uiPartAddr, px, py, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY );
1723#else
1724                          xPredInterUni_DBMP (pcCU, uiPartAddr, px, py, eRefPicList, pcYuvPred, iPartIdx );
1725#endif
1726#ifdef WEIGHT_PRED
1727                          if ( pcCU->getSlice()->getPPS()->getUseWP() )
1728                          {
1729                            xWeightedPredictionUni_DBMP( pcCU, pcYuvPred, uiPartAddr, px, py, eRefPicList, pcYuvPred, iPartIdx );
1730                          }
1731#endif
1732                        }
1733                        else
1734                        {
1735#if DEPTH_MAP_GENERATION
1736                          xPredInterBi_DBMP  (pcCU, uiPartAddr, px, py, uiSubSampExpX, uiSubSampExpY, pcYuvPred, iPartIdx, bPrdDepthMap );
1737#else
1738                          xPredInterBi_DBMP  (pcCU, uiPartAddr, px, py, pcYuvPred, iPartIdx );
1739#endif
1740                        }                       
1741
1742                        if(!pcCU->getSlice()->getSPS()->isDepth()) // Chroma check only for non depth
1743                        {
1744                        piDstCb = pcYuvPred->getCbAddr( uiPartAddr ) + (py>>1)*pcYuvPred->getCStride();
1745                        piDstCr = pcYuvPred->getCrAddr( uiPartAddr ) + (py>>1)*pcYuvPred->getCStride();
1746
1747                        //Chroma decimation 16x16 -> 8x8:
1748                        if(py%2 && px%2)
1749                        {
1750                                iTemp = (aiUTab[px-1] + aiUTab[px] + iULast + piDstCb[px>>1] + 2)>>2;
1751                                aiUTab[px-1] = iULast;
1752                                iULast = piDstCb[px>>1];
1753                                piDstCb[px>>1] = iTemp;
1754
1755                                iTemp = (aiVTab[px-1] + aiVTab[px] + iVLast + piDstCr[px>>1] + 2)>>2;
1756                                aiVTab[px-1] = iVLast;
1757                                iVLast = piDstCr[px>>1];
1758                                piDstCr[px>>1] = iTemp;
1759                        }
1760                        else
1761                        {
1762                                aiUTab[(px==0)? iWidth-1 : (px-1)] = iULast;   
1763                                iULast = piDstCb[px>>1];
1764
1765                                aiVTab[(px==0)? iWidth-1 : (px-1)] = iVLast;                           
1766                                iVLast = piDstCr[px>>1];
1767                        }       
1768                        }
1769
1770#if !POZNAN_DBMP_COMPRESS_ME_DATA
1771                        //save motion data for every CU point
1772#if DEPTH_MAP_GENERATION
1773                        if( !bPrdDepthMap )
1774#endif
1775                        {
1776                                pcMP->setL0RefPOC(uiViewId,bIsDepth,x,y,ref_frame0);
1777                                pcMP->setL0MvX(uiViewId,bIsDepth,x,y,mv0.getHor());
1778                                pcMP->setL0MvY(uiViewId,bIsDepth,x,y,mv0.getVer());
1779
1780                                pcMP->setL1RefPOC(uiViewId,bIsDepth,x,y,ref_frame1);
1781                                pcMP->setL1MvX(uiViewId,bIsDepth,x,y,mv1.getHor());
1782                                pcMP->setL1MvY(uiViewId,bIsDepth,x,y,mv1.getVer());
1783                        }
1784#endif
1785
1786#if POZNAN_DBMP_CALC_PRED_DATA
1787#if DEPTH_MAP_GENERATION
1788                        if( !bPrdDepthMap )
1789#endif
1790                        {
1791                                pcMP->getTempL0RefIdx()[uiPointCnt] = ref_frame0_idx;
1792                                pcMP->getTempL0MvX()[uiPointCnt] = mv0.getHor();
1793                                pcMP->getTempL0MvY()[uiPointCnt] = mv0.getVer();
1794
1795                                pcMP->getTempL1RefIdx()[uiPointCnt] = ref_frame1_idx;
1796                                pcMP->getTempL1MvX()[uiPointCnt] = mv1.getHor();
1797                                pcMP->getTempL1MvY()[uiPointCnt] = mv1.getVer();                       
1798                        }
1799                        uiPointCnt++;
1800#endif
1801
1802                }
1803        }
1804
1805        //set motion data representing CU with DBMP
1806#if DEPTH_MAP_GENERATION
1807        if( !bPrdDepthMap )
1808#endif
1809        {
1810                PartSize ePartSize = pcCU->getPartitionSize( uiPartAddr ); //PartSize ePartSize = pcCU->getPartitionSize( 0 );
1811#if POZNAN_DBMP_CALC_PRED_DATA
1812                pcMP->xCalcDBMPPredData(uiPointCnt, ref_frame0_idx, mv0, ref_frame1_idx, mv1);
1813               
1814                pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( mv0, ref_frame0_idx, ePartSize, uiPartAddr, iPartIdx, 0 );         
1815                pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( mv1, ref_frame1_idx, ePartSize, uiPartAddr, iPartIdx, 0 );
1816#else
1817                pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( mv0_2nd, ref_frame0_idx_2nd, ePartSize, uiPartAddr, iPartIdx, 0 );
1818                pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( mv1_2nd, ref_frame1_idx_2nd, ePartSize, uiPartAddr, iPartIdx, 0 );
1819#endif
1820        }
1821
1822        if ( iPartIdxOrg >= 0 ) break;
1823  }
1824  return;
1825}
1826#endif
1827
1828#if HIGH_ACCURACY_BI
1829#if DEPTH_MAP_GENERATION
1830Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY, Bool bi )
1831#else
1832Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bi )
1833#endif
1834#else
1835#if DEPTH_MAP_GENERATION
1836Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY )
1837#else
1838Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx )
1839#endif
1840#endif
1841{
1842  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
1843  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
1844  pcCU->clipMv(cMv);
1845
1846#if DEPTH_MAP_GENERATION
1847  if( bPrdDepthMap )
1848  {
1849    UInt uiRShift = 0;
1850    xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPredDepthMap(), uiPartAddr, &cMv, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, rpcYuvPred, uiRShift );
1851    return;
1852  }
1853#endif
1854
1855#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
1856  if( pcCU->getSlice()->getSPS()->isDepth() )
1857  {
1858#if HIGH_ACCURACY_BI
1859    UInt uiRShift = ( bi ? 14-g_uiBitDepth-g_uiBitIncrement : 0 );
1860#else
1861    UInt uiRShift = 0;
1862#endif
1863#if DEPTH_MAP_GENERATION
1864    xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, 0, 0, rpcYuvPred, uiRShift );
1865#else
1866    xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, uiRShift );
1867#endif
1868  }
1869  else
1870  {
1871#endif
1872#if HIGH_ACCURACY_BI
1873  if(!bi)
1874  {
1875    xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec()    , uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred );
1876  }
1877  else
1878  {
1879    xPredInterLumaBlk_ha  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec()    , uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred );
1880  }
1881#else
1882  xPredInterLumaBlk       ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred );
1883#endif
1884#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
1885  }
1886#endif
1887
1888#if HIGH_ACCURACY_BI
1889  if (!bi)
1890  {
1891    xPredInterChromaBlk     ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred );
1892  }
1893  else
1894  {
1895    xPredInterChromaBlk_ha ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec()    , uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred );
1896  }
1897#else
1898  xPredInterChromaBlk     ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred );
1899#endif
1900}
1901
1902#if DEPTH_MAP_GENERATION
1903Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap )
1904#else
1905Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred, Int iPartIdx )
1906#endif
1907{
1908  TComYuv* pcMbYuv;
1909  Int      iRefIdx[2] = {-1, -1};
1910
1911  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
1912  {
1913    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
1914    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
1915
1916    if ( iRefIdx[iRefList] < 0 )
1917    {
1918      continue;
1919    }
1920
1921    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
1922
1923    pcMbYuv = &m_acYuvPred[iRefList];
1924#if HIGH_ACCURACY_BI
1925    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
1926#if DEPTH_MAP_GENERATION
1927      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
1928#else
1929      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, true );
1930#endif
1931    else
1932#if DEPTH_MAP_GENERATION
1933     xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY );
1934#else
1935     xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx );
1936#endif
1937#else
1938#if DEPTH_MAP_GENERATION
1939    xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY );
1940#else
1941    xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx );
1942#endif
1943#endif
1944  }
1945
1946#ifdef WEIGHT_PRED
1947  if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() )
1948  {
1949    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1950  }
1951  else
1952#endif
1953
1954#if DEPTH_MAP_GENERATION
1955  if ( bPrdDepthMap )
1956  {
1957    xWeightedAveragePdm( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred, uiSubSampExpX, uiSubSampExpY );
1958  }
1959  else
1960  {
1961    xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1962  }
1963#else
1964  xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1965#endif
1966
1967}
1968
1969
1970Void
1971#if DEPTH_MAP_GENERATION
1972TComPrediction::xPredInterPrdDepthMap( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY, TComYuv*& rpcYuv, UInt uiRShift )
1973#else
1974TComPrediction::xPredInterPrdDepthMap( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, TComYuv*& rpcYuv, UInt uiRShift )
1975#endif
1976{
1977#if DEPTH_MAP_GENERATION
1978  Int     iShiftX     = 2 + uiSubSampExpX;
1979  Int     iShiftY     = 2 + uiSubSampExpY;
1980  Int     iAddX       = ( 1 << iShiftX ) >> 1;
1981  Int     iAddY       = ( 1 << iShiftY ) >> 1;
1982  Int     iHor        = ( pcMv->getHor() + iAddX ) >> iShiftX;
1983  Int     iVer        = ( pcMv->getVer() + iAddY ) >> iShiftY;
1984#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
1985  if( pcCU->getSlice()->getSPS()->isDepth() )
1986  {
1987    iHor = pcMv->getHor();
1988    iVer = pcMv->getVer();
1989  }
1990#endif
1991  Int     iRefStride  = pcPicYuvRef->getStride();
1992  Int     iDstStride  = rpcYuv->getStride();
1993  Int     iRefOffset  = iHor + iVer * iRefStride;
1994#else
1995  Int     iFPelMask   = ~3;
1996  Int     iRefStride  = pcPicYuvRef->getStride();
1997  Int     iDstStride  = rpcYuv->getStride();
1998  Int     iHor        = ( pcMv->getHor() + 2 ) & iFPelMask;
1999  Int     iVer        = ( pcMv->getVer() + 2 ) & iFPelMask;
2000#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
2001  if( pcCU->getSlice()->getSPS()->isDepth() )
2002  {
2003    iHor = pcMv->getHor() * 4;
2004    iVer = pcMv->getVer() * 4;
2005  }
2006#endif
2007  Int     ixFrac      = iHor & 0x3;
2008  Int     iyFrac      = iVer & 0x3;
2009  Int     iRefOffset  = ( iHor >> 2 ) + ( iVer >> 2 ) * iRefStride;
2010#endif
2011
2012  Pel*    piRefY      = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2013  Pel*    piDstY      = rpcYuv->getLumaAddr( uiPartAddr );
2014
2015    for( Int y = 0; y < iHeight; y++, piDstY += iDstStride, piRefY += iRefStride )
2016    {
2017      for( Int x = 0; x < iWidth; x++ )
2018      {
2019        piDstY[ x ] = piRefY[ x ] << uiRShift;
2020      }
2021    }
2022}
2023
2024
2025
2026#if HIGH_ACCURACY_BI
2027
2028Void  TComPrediction::xPredInterLumaBlk_ha( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, TComYuv*& rpcYuv )
2029{
2030  Int     iRefStride = pcPicYuvRef->getStride();
2031  Int     iDstStride = rpcYuv->getStride();
2032
2033  Int     iRefOffset = ( pcMv->getHor() >> 2 ) + ( pcMv->getVer() >> 2 ) * iRefStride;
2034  Pel*    piRefY     = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2035
2036  Int     ixFrac  = pcMv->getHor() & 0x3;
2037  Int     iyFrac  = pcMv->getVer() & 0x3;
2038
2039  Pel* piDstY = rpcYuv->getLumaAddr( uiPartAddr );
2040    UInt shiftNum = 14-g_uiBitDepth-g_uiBitIncrement;
2041  //  Integer point
2042  if ( ixFrac == 0 && iyFrac == 0 )
2043  {
2044    for ( Int y = 0; y < iHeight; y++ )
2045    {
2046      for(Int x=0; x<iWidth; x++)
2047        piDstY[x] = piRefY[x]<<shiftNum;
2048      piDstY += iDstStride;
2049      piRefY += iRefStride;
2050    }
2051    return;
2052  }
2053
2054  //  Half-pel horizontal
2055  if ( ixFrac == 2 && iyFrac == 0 )
2056  {
2057    xCTI_FilterHalfHor_ha ( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2058    return;
2059  }
2060
2061  //  Half-pel vertical
2062  if ( ixFrac == 0 && iyFrac == 2 )
2063  {
2064    xCTI_FilterHalfVer_ha ( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2065    return;
2066  }
2067
2068  Int   iExtStride = m_iYuvExtStride;//m_cYuvExt.getStride();
2069  Int*  piExtY     = m_piYuvExt;//m_cYuvExt.getLumaAddr();
2070
2071  //  Half-pel center
2072  if ( ixFrac == 2 && iyFrac == 2 )
2073  {
2074    xCTI_FilterHalfVer (piRefY - 3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
2075    xCTI_FilterHalfHor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2076    return;
2077  }
2078
2079  //  Quater-pel horizontal
2080  if ( iyFrac == 0)
2081  {
2082    if ( ixFrac == 1)
2083    {
2084      xCTI_FilterQuarter0Hor_ha( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2085      return;
2086    }
2087    if ( ixFrac == 3)
2088    {
2089      xCTI_FilterQuarter1Hor_ha( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2090      return;
2091    }
2092  }
2093  if ( iyFrac == 2 )
2094  {
2095    if ( ixFrac == 1)
2096    {
2097      xCTI_FilterHalfVer (piRefY -3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
2098      xCTI_FilterQuarter0Hor_ha (piExtY + 3,  iExtStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2099      return;
2100    }
2101    if ( ixFrac == 3)
2102    {
2103      xCTI_FilterHalfVer (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2104      xCTI_FilterQuarter1Hor_ha (piExtY + 3,  iExtStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2105      return;
2106    }
2107  }
2108
2109  //  Quater-pel vertical
2110  if( ixFrac == 0 )
2111  {
2112    if( iyFrac == 1 )
2113    {
2114      xCTI_FilterQuarter0Ver_ha( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2115      return;
2116    }
2117    if( iyFrac == 3 )
2118    {
2119      xCTI_FilterQuarter1Ver_ha( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2120      return;
2121    }
2122  }
2123
2124  if( ixFrac == 2 )
2125  {
2126    if( iyFrac == 1 )
2127    {
2128      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2129      xCTI_FilterHalfHor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2130
2131      return;
2132    }
2133    if( iyFrac == 3 )
2134    {
2135      xCTI_FilterQuarter1Ver (piRefY -3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2136      xCTI_FilterHalfHor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2137      return;
2138    }
2139  }
2140
2141  /// Quarter-pel center
2142  if ( iyFrac == 1)
2143  {
2144    if ( ixFrac == 1)
2145    {
2146      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2147      xCTI_FilterQuarter0Hor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2148      return;
2149    }
2150    if ( ixFrac == 3)
2151    {
2152      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
2153      xCTI_FilterQuarter1Hor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2154
2155      return;
2156    }
2157  }
2158  if ( iyFrac == 3 )
2159  {
2160    if ( ixFrac == 1)
2161    {
2162      xCTI_FilterQuarter1Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2163      xCTI_FilterQuarter0Hor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2164      return;
2165    }
2166    if ( ixFrac == 3)
2167    {
2168      xCTI_FilterQuarter1Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2169      xCTI_FilterQuarter1Hor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2170      return;
2171    }
2172  }
2173}
2174
2175#endif
2176
2177Void  TComPrediction::xPredInterLumaBlk( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, TComYuv*& rpcYuv )
2178{
2179  Int     iRefStride = pcPicYuvRef->getStride();
2180  Int     iDstStride = rpcYuv->getStride();
2181
2182  Int     iRefOffset = ( pcMv->getHor() >> 2 ) + ( pcMv->getVer() >> 2 ) * iRefStride;
2183  Pel*    piRefY     = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2184
2185  Int     ixFrac  = pcMv->getHor() & 0x3;
2186  Int     iyFrac  = pcMv->getVer() & 0x3;
2187
2188  Pel* piDstY = rpcYuv->getLumaAddr( uiPartAddr );
2189
2190  //  Integer point
2191  if ( ixFrac == 0 && iyFrac == 0 )
2192  {
2193    for ( Int y = 0; y < iHeight; y++ )
2194    {
2195      ::memcpy(piDstY, piRefY, sizeof(Pel)*iWidth);
2196      piDstY += iDstStride;
2197      piRefY += iRefStride;
2198    }
2199    return;
2200  }
2201
2202  //  Half-pel horizontal
2203  if ( ixFrac == 2 && iyFrac == 0 )
2204  {
2205    xCTI_FilterHalfHor ( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2206    return;
2207  }
2208
2209  //  Half-pel vertical
2210  if ( ixFrac == 0 && iyFrac == 2 )
2211  {
2212    xCTI_FilterHalfVer ( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2213    return;
2214  }
2215
2216  Int   iExtStride = m_iYuvExtStride;//m_cYuvExt.getStride();
2217  Int*  piExtY     = m_piYuvExt;//m_cYuvExt.getLumaAddr();
2218
2219  //  Half-pel center
2220  if ( ixFrac == 2 && iyFrac == 2 )
2221  {
2222
2223    xCTI_FilterHalfVer (piRefY - 3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
2224    xCTI_FilterHalfHor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2225    return;
2226  }
2227
2228  //  Quater-pel horizontal
2229  if ( iyFrac == 0)
2230  {
2231    if ( ixFrac == 1)
2232    {
2233      xCTI_FilterQuarter0Hor( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2234      return;
2235    }
2236    if ( ixFrac == 3)
2237    {
2238      xCTI_FilterQuarter1Hor( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2239      return;
2240    }
2241  }
2242  if ( iyFrac == 2 )
2243  {
2244    if ( ixFrac == 1)
2245    {
2246      xCTI_FilterHalfVer (piRefY -3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
2247      xCTI_FilterQuarter0Hor (piExtY + 3,  iExtStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2248      return;
2249    }
2250    if ( ixFrac == 3)
2251    {
2252      xCTI_FilterHalfVer (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2253      xCTI_FilterQuarter1Hor (piExtY + 3,  iExtStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2254      return;
2255    }
2256  }
2257
2258  //  Quater-pel vertical
2259  if( ixFrac == 0 )
2260  {
2261    if( iyFrac == 1 )
2262    {
2263      xCTI_FilterQuarter0Ver( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2264      return;
2265    }
2266    if( iyFrac == 3 )
2267    {
2268      xCTI_FilterQuarter1Ver( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2269      return;
2270    }
2271  }
2272
2273  if( ixFrac == 2 )
2274  {
2275    if( iyFrac == 1 )
2276    {
2277      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2278      xCTI_FilterHalfHor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2279      return;
2280    }
2281    if( iyFrac == 3 )
2282    {
2283      xCTI_FilterQuarter1Ver (piRefY -3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2284      xCTI_FilterHalfHor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2285      return;
2286    }
2287  }
2288
2289  /// Quarter-pel center
2290  if ( iyFrac == 1)
2291  {
2292    if ( ixFrac == 1)
2293    {
2294      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2295      xCTI_FilterQuarter0Hor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2296      return;
2297    }
2298    if ( ixFrac == 3)
2299    {
2300      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
2301      xCTI_FilterQuarter1Hor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2302      return;
2303    }
2304  }
2305  if ( iyFrac == 3 )
2306  {
2307    if ( ixFrac == 1)
2308    {
2309      xCTI_FilterQuarter1Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2310      xCTI_FilterQuarter0Hor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2311      return;
2312    }
2313    if ( ixFrac == 3)
2314    {
2315      xCTI_FilterQuarter1Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2316      xCTI_FilterQuarter1Hor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2317      return;
2318    }
2319  }
2320}
2321
2322#if HIGH_ACCURACY_BI
2323Void TComPrediction::xPredInterChromaBlk_ha( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, TComYuv*& rpcYuv )
2324{
2325  Int     iRefStride  = pcPicYuvRef->getCStride();
2326  Int     iDstStride  = rpcYuv->getCStride();
2327
2328  Int     iRefOffset  = (pcMv->getHor() >> 3) + (pcMv->getVer() >> 3) * iRefStride;
2329
2330  Pel*    piRefCb     = pcPicYuvRef->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2331  Pel*    piRefCr     = pcPicYuvRef->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2332
2333  Pel* piDstCb = rpcYuv->getCbAddr( uiPartAddr );
2334  Pel* piDstCr = rpcYuv->getCrAddr( uiPartAddr );
2335
2336  Int     ixFrac  = pcMv->getHor() & 0x7;
2337  Int     iyFrac  = pcMv->getVer() & 0x7;
2338  UInt    uiCWidth  = iWidth  >> 1;
2339  UInt    uiCHeight = iHeight >> 1;
2340
2341  xDCTIF_FilterC_ha(piRefCb, iRefStride,piDstCb,iDstStride,uiCWidth,uiCHeight, iyFrac, ixFrac);
2342  xDCTIF_FilterC_ha(piRefCr, iRefStride,piDstCr,iDstStride,uiCWidth,uiCHeight, iyFrac, ixFrac);
2343  return;
2344}
2345#endif
2346
2347//--
2348Void TComPrediction::xPredInterChromaBlk( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, TComYuv*& rpcYuv )
2349{
2350  Int     iRefStride  = pcPicYuvRef->getCStride();
2351  Int     iDstStride  = rpcYuv->getCStride();
2352
2353  Int     iRefOffset  = (pcMv->getHor() >> 3) + (pcMv->getVer() >> 3) * iRefStride;
2354
2355  Pel*    piRefCb     = pcPicYuvRef->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2356  Pel*    piRefCr     = pcPicYuvRef->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2357
2358  Pel* piDstCb = rpcYuv->getCbAddr( uiPartAddr );
2359  Pel* piDstCr = rpcYuv->getCrAddr( uiPartAddr );
2360
2361  Int     ixFrac  = pcMv->getHor() & 0x7;
2362  Int     iyFrac  = pcMv->getVer() & 0x7;
2363  UInt    uiCWidth  = iWidth  >> 1;
2364  UInt    uiCHeight = iHeight >> 1;
2365
2366  xDCTIF_FilterC(piRefCb, iRefStride,piDstCb,iDstStride,uiCWidth,uiCHeight, iyFrac, ixFrac);
2367  xDCTIF_FilterC(piRefCr, iRefStride,piDstCr,iDstStride,uiCWidth,uiCHeight, iyFrac, ixFrac);
2368  return;
2369}
2370
2371
2372
2373#if POZNAN_DBMP
2374
2375#if HIGH_ACCURACY_BI
2376#if DEPTH_MAP_GENERATION
2377Void TComPrediction::xPredInterUni_DBMP ( TComDataCU* pcCU, UInt uiPartAddr, Int iPosX, Int iPosY, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY, Bool bi )
2378#else
2379Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iPosX, Int iPosY, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bi )
2380#endif
2381#else
2382#if DEPTH_MAP_GENERATION
2383Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iPosX, Int iPosY, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY )
2384#else
2385Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iPosX, Int iPosY, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx )
2386#endif
2387#endif
2388{
2389  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
2390  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
2391  pcCU->clipMv(cMv);
2392
2393#if DEPTH_MAP_GENERATION
2394  if( bPrdDepthMap )
2395  {
2396        UInt uiRShift = 0;
2397        xPredInterPrdDepthMap_DBMP( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPredDepthMap(), uiPartAddr, &cMv, iPosX, iPosY, uiSubSampExpX, uiSubSampExpY, rpcYuvPred, uiRShift );
2398    return;
2399  }
2400#endif
2401
2402#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
2403  if( pcCU->getSlice()->getSPS()->isDepth() )
2404  {
2405#if HIGH_ACCURACY_BI
2406    UInt uiRShift = ( bi ? 14-g_uiBitDepth-g_uiBitIncrement : 0 );
2407#else
2408    UInt uiRShift = 0;
2409#endif
2410#if DEPTH_MAP_GENERATION
2411    xPredInterPrdDepthMap_DBMP( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iPosX, iPosY, 0, 0, rpcYuvPred, uiRShift );
2412#else
2413    xPredInterPrdDepthMap_DBMP( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iPosX, iPosY, rpcYuvPred, uiRShift );
2414#endif
2415  }
2416  else
2417  {
2418#endif
2419#if HIGH_ACCURACY_BI
2420  if(!bi)
2421  {
2422    xPredInterLumaBlk_DBMP ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iPosX, iPosY, rpcYuvPred );
2423  }
2424  else
2425  {
2426    xPredInterLumaBlk_DBMP_ha  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iPosX, iPosY, rpcYuvPred );
2427  }
2428#else
2429  xPredInterLumaBlk_DBMP       ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iPosX, iPosY, rpcYuvPred );
2430#endif
2431#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
2432  }
2433#endif
2434
2435#if HIGH_ACCURACY_BI
2436  if (!bi)
2437  {
2438        xPredInterChromaBlk_DBMP     ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iPosX, iPosY, rpcYuvPred );
2439  }
2440  else
2441  {
2442        xPredInterChromaBlk_DBMP_ha ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec()    , uiPartAddr, &cMv, iPosX, iPosY, rpcYuvPred );
2443  }
2444#else
2445  xPredInterChromaBlk_DBMP     ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iPosX, iPosY, rpcYuvPred );
2446#endif
2447}
2448
2449#if DEPTH_MAP_GENERATION
2450Void TComPrediction::xPredInterBi_DBMP ( TComDataCU* pcCU, UInt uiPartAddr, Int iPosX, Int iPosY, UInt uiSubSampExpX, UInt uiSubSampExpY, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap )
2451#else
2452Void TComPrediction::xPredInterBi_DBMP ( TComDataCU* pcCU, UInt uiPartAddr, Int iPosX, Int iPosY, TComYuv*& rpcYuvPred, Int iPartIdx )
2453#endif
2454{
2455  TComYuv* pcMbYuv;
2456  Int      iRefIdx[2] = {-1, -1};
2457
2458  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
2459  {
2460    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
2461    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
2462
2463    if ( iRefIdx[iRefList] < 0 )
2464    {
2465      continue;
2466    }
2467
2468    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
2469
2470    pcMbYuv = &m_acYuvPred[iRefList];
2471#if HIGH_ACCURACY_BI
2472    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
2473#if DEPTH_MAP_GENERATION
2474      xPredInterUni_DBMP ( pcCU, uiPartAddr, iPosX, iPosY, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
2475#else
2476      xPredInterUni_DBMP ( pcCU, uiPartAddr, iPosX, iPosY, eRefPicList, pcMbYuv, iPartIdx, true );
2477#endif
2478    else
2479#if DEPTH_MAP_GENERATION
2480      xPredInterUni_DBMP ( pcCU, uiPartAddr, iPosX, iPosY, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY );
2481#else
2482      xPredInterUni_DBMP ( pcCU, uiPartAddr, iPosX, iPosY, eRefPicList, pcMbYuv, iPartIdx );
2483#endif
2484#else
2485#if DEPTH_MAP_GENERATION
2486    xPredInterUni_DBMP ( pcCU, uiPartAddr, iPosX, iPosY, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY );
2487#else
2488    xPredInterUni_DBMP ( pcCU, uiPartAddr, iPosX, iPosY, eRefPicList, pcMbYuv, iPartIdx );
2489#endif
2490#endif
2491  }
2492
2493#ifdef WEIGHT_PRED
2494  if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() )
2495  {
2496    xWeightedPredictionBi_DBMP( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iPosX, iPosY, rpcYuvPred );
2497  }
2498  else
2499#endif
2500
2501#if DEPTH_MAP_GENERATION
2502  if ( bPrdDepthMap )
2503  {
2504    xWeightedAveragePdm_DBMP( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iPosX, iPosY, rpcYuvPred, uiSubSampExpX, uiSubSampExpY );
2505  }
2506  else
2507  {
2508    xWeightedAverage_DBMP( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iPosX, iPosY, rpcYuvPred );
2509  }
2510#else
2511  xWeightedAverage_DBMP( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iPosX, iPosY, rpcYuvPred );
2512#endif
2513}
2514
2515Void
2516#if DEPTH_MAP_GENERATION
2517TComPrediction::xPredInterPrdDepthMap_DBMP( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iPosX, Int iPosY, UInt uiSubSampExpX, UInt uiSubSampExpY, TComYuv*& rpcYuv, UInt uiRShift )
2518#else
2519TComPrediction::xPredInterPrdDepthMap_DBMP( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iPosX, Int iPosY, TComYuv*& rpcYuv, UInt uiRShift )
2520#endif
2521{
2522#if DEPTH_MAP_GENERATION
2523  Int     iShiftX     = 2 + uiSubSampExpX;
2524  Int     iShiftY     = 2 + uiSubSampExpY;
2525  Int     iAddX       = ( 1 << iShiftX ) >> 1;
2526  Int     iAddY       = ( 1 << iShiftY ) >> 1;
2527  Int     iHor        = ( pcMv->getHor() + iAddX ) >> iShiftX;
2528  Int     iVer        = ( pcMv->getVer() + iAddY ) >> iShiftY;
2529#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
2530  if( pcCU->getSlice()->getSPS()->isDepth() )
2531  {
2532    iHor = pcMv->getHor();
2533    iVer = pcMv->getVer();
2534  }
2535#endif
2536  Int     iRefStride  = pcPicYuvRef->getStride();
2537  Int     iDstStride  = rpcYuv->getStride();
2538  Int     iRefOffset  = iHor + iVer * iRefStride;
2539#else
2540  Int     iFPelMask   = ~3;
2541  Int     iRefStride  = pcPicYuvRef->getStride();
2542  Int     iDstStride  = rpcYuv->getStride();
2543  Int     iHor        = ( pcMv->getHor() + 2 ) & iFPelMask;
2544  Int     iVer        = ( pcMv->getVer() + 2 ) & iFPelMask;
2545#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
2546  if( pcCU->getSlice()->getSPS()->isDepth() )
2547  {
2548    iHor = pcMv->getHor() * 4;
2549    iVer = pcMv->getVer() * 4;
2550  }
2551#endif
2552  Int     ixFrac      = iHor & 0x3;
2553  Int     iyFrac      = iVer & 0x3;
2554  Int     iRefOffset  = ( iHor >> 2 ) + ( iVer >> 2 ) * iRefStride;
2555#endif
2556
2557  Pel*    piRefY      = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2558  Pel*    piDstY      = rpcYuv->getLumaAddr( uiPartAddr );
2559
2560  piDstY[ iPosY*iDstStride + iPosX ] = piRefY[ iPosY*iRefStride + iPosX ] << uiRShift;
2561}
2562
2563
2564#if HIGH_ACCURACY_BI
2565
2566Void  TComPrediction::xPredInterLumaBlk_DBMP_ha( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iPosX, Int iPosY, TComYuv*& rpcYuv )
2567{
2568  Int     iRefStride = pcPicYuvRef->getStride();
2569  Int     iDstStride = rpcYuv->getStride();
2570
2571  Int     iRefOffset = ( pcMv->getHor() >> 2 ) + ( pcMv->getVer() >> 2 ) * iRefStride;
2572  Pel*    piRefY     = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2573
2574  Int     ixFrac  = pcMv->getHor() & 0x3;
2575  Int     iyFrac  = pcMv->getVer() & 0x3;
2576
2577  Pel* piDstY = rpcYuv->getLumaAddr( uiPartAddr );
2578  UInt shiftNum = 14-g_uiBitDepth-g_uiBitIncrement;
2579
2580  piDstY += iPosY*iDstStride+iPosX;
2581  piRefY += iPosY*iRefStride+iPosX;
2582
2583  //  Integer point
2584  if ( ixFrac == 0 && iyFrac == 0 )
2585  {
2586    *piDstY = (*piRefY)<<shiftNum;
2587    return;
2588  }
2589
2590  Int iWidth = 1;
2591  Int iHeight = 1;
2592
2593  //  Half-pel horizontal
2594  if ( ixFrac == 2 && iyFrac == 0 )
2595  {
2596    xCTI_FilterHalfHor_ha ( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2597    return;
2598  }
2599
2600  //  Half-pel vertical
2601  if ( ixFrac == 0 && iyFrac == 2 )
2602  {
2603    xCTI_FilterHalfVer_ha ( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2604    return;
2605  }
2606
2607  Int   iExtStride = m_iYuvExtStride;//m_cYuvExt.getStride();
2608  Int*  piExtY     = m_piYuvExt;//m_cYuvExt.getLumaAddr();
2609
2610  //  Half-pel center
2611  if ( ixFrac == 2 && iyFrac == 2 )
2612  {
2613    xCTI_FilterHalfVer (piRefY - 3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
2614    xCTI_FilterHalfHor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2615    return;
2616  }
2617
2618  //  Quater-pel horizontal
2619  if ( iyFrac == 0)
2620  {
2621    if ( ixFrac == 1)
2622    {
2623      xCTI_FilterQuarter0Hor_ha( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2624      return;
2625    }
2626    if ( ixFrac == 3)
2627    {
2628      xCTI_FilterQuarter1Hor_ha( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2629      return;
2630    }
2631  }
2632  if ( iyFrac == 2 )
2633  {
2634    if ( ixFrac == 1)
2635    {
2636      xCTI_FilterHalfVer (piRefY -3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
2637      xCTI_FilterQuarter0Hor_ha (piExtY + 3,  iExtStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2638      return;
2639    }
2640    if ( ixFrac == 3)
2641    {
2642      xCTI_FilterHalfVer (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2643      xCTI_FilterQuarter1Hor_ha (piExtY + 3,  iExtStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2644      return;
2645    }
2646  }
2647
2648  //  Quater-pel vertical
2649  if( ixFrac == 0 )
2650  {
2651    if( iyFrac == 1 )
2652    {
2653      xCTI_FilterQuarter0Ver_ha( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2654      return;
2655    }
2656    if( iyFrac == 3 )
2657    {
2658      xCTI_FilterQuarter1Ver_ha( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2659      return;
2660    }
2661  }
2662
2663  if( ixFrac == 2 )
2664  {
2665    if( iyFrac == 1 )
2666    {
2667      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2668      xCTI_FilterHalfHor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2669
2670      return;
2671    }
2672    if( iyFrac == 3 )
2673    {
2674      xCTI_FilterQuarter1Ver (piRefY -3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2675      xCTI_FilterHalfHor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2676      return;
2677    }
2678  }
2679
2680  /// Quarter-pel center
2681  if ( iyFrac == 1)
2682  {
2683    if ( ixFrac == 1)
2684    {
2685      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2686      xCTI_FilterQuarter0Hor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2687      return;
2688    }
2689    if ( ixFrac == 3)
2690    {
2691      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
2692      xCTI_FilterQuarter1Hor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2693
2694      return;
2695    }
2696  }
2697  if ( iyFrac == 3 )
2698  {
2699    if ( ixFrac == 1)
2700    {
2701      xCTI_FilterQuarter1Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2702      xCTI_FilterQuarter0Hor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2703      return;
2704    }
2705    if ( ixFrac == 3)
2706    {
2707      xCTI_FilterQuarter1Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2708      xCTI_FilterQuarter1Hor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2709      return;
2710    }
2711  }
2712}
2713
2714#endif
2715
2716Void  TComPrediction::xPredInterLumaBlk_DBMP( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iPosX, Int iPosY, TComYuv*& rpcYuv )
2717{
2718  Int     iRefStride = pcPicYuvRef->getStride();
2719  Int     iDstStride = rpcYuv->getStride();
2720
2721  Int     iRefOffset = ( pcMv->getHor() >> 2 ) + ( pcMv->getVer() >> 2 ) * iRefStride;
2722  Pel*    piRefY     = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2723
2724  Int     ixFrac  = pcMv->getHor() & 0x3;
2725  Int     iyFrac  = pcMv->getVer() & 0x3;
2726
2727  Pel* piDstY = rpcYuv->getLumaAddr( uiPartAddr );
2728 
2729  piDstY += iPosY*iDstStride+iPosX;
2730  piRefY += iPosY*iRefStride+iPosX;
2731
2732  //  Integer point
2733  if ( ixFrac == 0 && iyFrac == 0 )
2734  {
2735    ::memcpy(piDstY, piRefY, sizeof(Pel));
2736    return;
2737  }
2738
2739  Int iWidth = 1;
2740  Int iHeight = 1;
2741
2742  //  Half-pel horizontal
2743  if ( ixFrac == 2 && iyFrac == 0 )
2744  {
2745    xCTI_FilterHalfHor ( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2746    return;
2747  }
2748
2749  //  Half-pel vertical
2750  if ( ixFrac == 0 && iyFrac == 2 )
2751  {
2752    xCTI_FilterHalfVer ( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2753    return;
2754  }
2755
2756  Int   iExtStride = m_iYuvExtStride;//m_cYuvExt.getStride();
2757  Int*  piExtY     = m_piYuvExt;//m_cYuvExt.getLumaAddr();
2758
2759  //  Half-pel center
2760  if ( ixFrac == 2 && iyFrac == 2 )
2761  {
2762
2763    xCTI_FilterHalfVer (piRefY - 3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
2764    xCTI_FilterHalfHor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2765    return;
2766  }
2767
2768  //  Quater-pel horizontal
2769  if ( iyFrac == 0)
2770  {
2771    if ( ixFrac == 1)
2772    {
2773      xCTI_FilterQuarter0Hor( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2774      return;
2775    }
2776    if ( ixFrac == 3)
2777    {
2778      xCTI_FilterQuarter1Hor( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2779      return;
2780    }
2781  }
2782  if ( iyFrac == 2 )
2783  {
2784    if ( ixFrac == 1)
2785    {
2786      xCTI_FilterHalfVer (piRefY -3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
2787      xCTI_FilterQuarter0Hor (piExtY + 3,  iExtStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2788      return;
2789    }
2790    if ( ixFrac == 3)
2791    {
2792      xCTI_FilterHalfVer (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2793      xCTI_FilterQuarter1Hor (piExtY + 3,  iExtStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2794      return;
2795    }
2796  }
2797
2798  //  Quater-pel vertical
2799  if( ixFrac == 0 )
2800  {
2801    if( iyFrac == 1 )
2802    {
2803      xCTI_FilterQuarter0Ver( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2804      return;
2805    }
2806    if( iyFrac == 3 )
2807    {
2808      xCTI_FilterQuarter1Ver( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
2809      return;
2810    }
2811  }
2812
2813  if( ixFrac == 2 )
2814  {
2815    if( iyFrac == 1 )
2816    {
2817      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2818      xCTI_FilterHalfHor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2819      return;
2820    }
2821    if( iyFrac == 3 )
2822    {
2823      xCTI_FilterQuarter1Ver (piRefY -3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2824      xCTI_FilterHalfHor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2825      return;
2826    }
2827  }
2828
2829  /// Quarter-pel center
2830  if ( iyFrac == 1)
2831  {
2832    if ( ixFrac == 1)
2833    {
2834      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2835      xCTI_FilterQuarter0Hor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2836      return;
2837    }
2838    if ( ixFrac == 3)
2839    {
2840      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
2841      xCTI_FilterQuarter1Hor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2842      return;
2843    }
2844  }
2845  if ( iyFrac == 3 )
2846  {
2847    if ( ixFrac == 1)
2848    {
2849      xCTI_FilterQuarter1Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2850      xCTI_FilterQuarter0Hor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2851      return;
2852    }
2853    if ( ixFrac == 3)
2854    {
2855      xCTI_FilterQuarter1Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2856      xCTI_FilterQuarter1Hor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2857      return;
2858    }
2859  }
2860}
2861
2862#if HIGH_ACCURACY_BI
2863Void TComPrediction::xPredInterChromaBlk_DBMP_ha( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iPosX, Int iPosY, TComYuv*& rpcYuv )
2864{
2865  Int     iRefStride  = pcPicYuvRef->getCStride();
2866  Int     iDstStride  = rpcYuv->getCStride();
2867
2868  Int     iRefOffset  = (pcMv->getHor() >> 3) + (pcMv->getVer() >> 3) * iRefStride;
2869
2870  Pel*    piRefCb     = pcPicYuvRef->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2871  Pel*    piRefCr     = pcPicYuvRef->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2872
2873  Pel* piDstCb = rpcYuv->getCbAddr( uiPartAddr );
2874  Pel* piDstCr = rpcYuv->getCrAddr( uiPartAddr );
2875
2876  Int     ixFrac  = pcMv->getHor() & 0x7;
2877  Int     iyFrac  = pcMv->getVer() & 0x7;
2878  UInt    uiCWidth  = 1;
2879  UInt    uiCHeight = 1;
2880
2881  piDstCb += (iPosY>>1)*iDstStride+(iPosX>>1);
2882  piDstCr += (iPosY>>1)*iDstStride+(iPosX>>1);
2883  piRefCb += (iPosY>>1)*iRefStride+(iPosX>>1);
2884  piRefCr += (iPosY>>1)*iRefStride+(iPosX>>1);
2885
2886  xDCTIF_FilterC_ha(piRefCb, iRefStride,piDstCb,iDstStride,uiCWidth,uiCHeight, iyFrac, ixFrac);
2887  xDCTIF_FilterC_ha(piRefCr, iRefStride,piDstCr,iDstStride,uiCWidth,uiCHeight, iyFrac, ixFrac);
2888  return;
2889}
2890#endif
2891
2892//--
2893Void TComPrediction::xPredInterChromaBlk_DBMP( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iPosX, Int iPosY, TComYuv*& rpcYuv )
2894{
2895  Int     iRefStride  = pcPicYuvRef->getCStride();
2896  Int     iDstStride  = rpcYuv->getCStride();
2897
2898  Int     iRefOffset  = (pcMv->getHor() >> 3) + (pcMv->getVer() >> 3) * iRefStride;
2899
2900  Pel*    piRefCb     = pcPicYuvRef->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2901  Pel*    piRefCr     = pcPicYuvRef->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2902
2903  Pel* piDstCb = rpcYuv->getCbAddr( uiPartAddr );
2904  Pel* piDstCr = rpcYuv->getCrAddr( uiPartAddr );
2905
2906  Int     ixFrac  = pcMv->getHor() & 0x7;
2907  Int     iyFrac  = pcMv->getVer() & 0x7;
2908  UInt    uiCWidth  = 1;
2909  UInt    uiCHeight = 1;
2910
2911  piDstCb += (iPosY>>1)*iDstStride+(iPosX>>1);
2912  piDstCr += (iPosY>>1)*iDstStride+(iPosX>>1);
2913  piRefCb += (iPosY>>1)*iRefStride+(iPosX>>1);
2914  piRefCr += (iPosY>>1)*iRefStride+(iPosX>>1);
2915
2916  xDCTIF_FilterC(piRefCb, iRefStride,piDstCb,iDstStride,uiCWidth,uiCHeight, iyFrac, ixFrac);
2917  xDCTIF_FilterC(piRefCr, iRefStride,piDstCr,iDstStride,uiCWidth,uiCHeight, iyFrac, ixFrac);
2918  return;
2919}
2920
2921#endif
2922
2923
2924Void  TComPrediction::xDCTIF_FilterC ( Pel*  piRefC, Int iRefStride,Pel*  piDstC,Int iDstStride,
2925                                       Int iWidth, Int iHeight,Int iMVyFrac,Int iMVxFrac)
2926{
2927  // Integer point
2928  if ( iMVxFrac == 0 && iMVyFrac == 0 )
2929  {
2930    for ( Int y = 0; y < iHeight; y++ )
2931    {
2932      ::memcpy(piDstC, piRefC, sizeof(Pel)*iWidth);
2933      piDstC += iDstStride;
2934      piRefC += iRefStride;
2935    }
2936    return;
2937  }
2938
2939  if ( iMVyFrac == 0 )
2940  {
2941    xCTI_Filter1DHorC (piRefC, iRefStride,  iWidth, iHeight, iDstStride,  piDstC, iMVxFrac );
2942    return;
2943  }
2944
2945  if ( iMVxFrac == 0 )
2946  {
2947    xCTI_Filter1DVerC (piRefC, iRefStride,  iWidth, iHeight, iDstStride,  piDstC, iMVyFrac );
2948    return;
2949}
2950
2951  Int   iExtStride = m_iYuvExtStride;
2952  Int*  piExtC     = m_piYuvExt;
2953
2954  xCTI_Filter2DVerC (piRefC - 1,  iRefStride,  iWidth + 3, iHeight, iExtStride,  piExtC, iMVyFrac );
2955  xCTI_Filter2DHorC (piExtC + 1,  iExtStride,  iWidth             , iHeight, iDstStride,  piDstC, iMVxFrac );
2956}
2957
2958#if HIGH_ACCURACY_BI
2959
2960Void  TComPrediction::xDCTIF_FilterC_ha ( Pel*  piRefC, Int iRefStride,Pel*  piDstC,Int iDstStride,
2961                                       Int iWidth, Int iHeight,Int iMVyFrac,Int iMVxFrac)
2962{
2963  UInt    shiftNumOrg = 6 - g_uiBitIncrement + 8 - g_uiBitDepth;
2964  // Integer point
2965  if ( iMVxFrac == 0 && iMVyFrac == 0 )
2966  {
2967    for (Int y = 0; y < iHeight; y++ )
2968    {
2969      for(Int x=0; x<iWidth; x++)
2970      {
2971        piDstC[x] = (piRefC[x]<<shiftNumOrg);
2972      }
2973      piDstC += iDstStride;
2974      piRefC += iRefStride;
2975    }
2976    return;
2977  }
2978
2979  if ( iMVyFrac == 0 )
2980  {
2981    xCTI_Filter1DHorC_ha (piRefC, iRefStride,  iWidth, iHeight, iDstStride,  piDstC, iMVxFrac );
2982    return;
2983
2984  }
2985
2986  if ( iMVxFrac == 0 )
2987  {
2988    xCTI_Filter1DVerC_ha (piRefC, iRefStride,  iWidth, iHeight, iDstStride,  piDstC, iMVyFrac );
2989    return;
2990  }
2991
2992  Int   iExtStride = m_iYuvExtStride;
2993  Int*  piExtC     = m_piYuvExt;
2994
2995  xCTI_Filter2DVerC (piRefC - 1,  iRefStride,  iWidth + 3, iHeight, iExtStride,  piExtC, iMVyFrac );
2996  xCTI_Filter2DHorC_ha (piExtC + 1,  iExtStride,  iWidth , iHeight, iDstStride,  piDstC, iMVxFrac );
2997  return;
2998
2999}
3000
3001#endif
3002
3003#if DEPTH_MAP_GENERATION
3004Void TComPrediction::xWeightedAveragePdm( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst, UInt uiSubSampExpX, UInt uiSubSampExpY )
3005{
3006  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
3007  {
3008    rpcYuvDst->addAvgPdm( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY );
3009  }
3010  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
3011  {
3012    pcYuvSrc0->copyPartToPartYuvPdm( rpcYuvDst, uiPartIdx, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY );
3013  }
3014  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
3015  {
3016    pcYuvSrc1->copyPartToPartYuvPdm( rpcYuvDst, uiPartIdx, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY );
3017  }
3018  else
3019  {
3020    assert (0);
3021  }
3022}
3023#endif
3024
3025
3026Void TComPrediction::xWeightedAverage( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
3027{
3028  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
3029  {
3030#ifdef ROUNDING_CONTROL_BIPRED
3031    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight, pcCU->getSlice()->isRounding());
3032#else
3033    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
3034#endif
3035  }
3036  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
3037  {
3038    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
3039  }
3040  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
3041  {
3042    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
3043  }
3044  else
3045  {
3046    assert (0);
3047  }
3048}
3049
3050#if POZNAN_DBMP
3051
3052#if DEPTH_MAP_GENERATION
3053Void TComPrediction::xWeightedAveragePdm_DBMP( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iPosX, Int iPosY, TComYuv*& rpcYuvDst, UInt uiSubSampExpX, UInt uiSubSampExpY )
3054{
3055  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
3056  {
3057    rpcYuvDst->addAvgPdm_DBMP( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iPosX, iPosY, uiSubSampExpX, uiSubSampExpY );
3058  }
3059  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
3060  {
3061    pcYuvSrc0->copyPartToPartYuvPdm_DBMP( rpcYuvDst, uiPartIdx, iPosX, iPosY, uiSubSampExpX, uiSubSampExpY );
3062  }
3063  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
3064  {
3065    pcYuvSrc1->copyPartToPartYuvPdm_DBMP( rpcYuvDst, uiPartIdx, iPosX, iPosY, uiSubSampExpX, uiSubSampExpY );
3066  }
3067  else
3068  {
3069    assert (0);
3070  }
3071}
3072#endif
3073
3074Void TComPrediction::xWeightedAverage_DBMP( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iPosX, Int iPosY, TComYuv*& rpcYuvDst )
3075{
3076  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
3077  {
3078#ifdef ROUNDING_CONTROL_BIPRED
3079    rpcYuvDst->addAvg_DBMP( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iPosX, iPosY, pcCU->getSlice()->isRounding());
3080#else
3081    rpcYuvDst->addAvg_DBMP( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iPosX, iPosY );
3082#endif
3083  }
3084  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
3085  {
3086    pcYuvSrc0->copyPartToPartYuv_DBMP( rpcYuvDst, uiPartIdx, iPosX, iPosY );
3087  }
3088  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
3089  {
3090    pcYuvSrc1->copyPartToPartYuv_DBMP( rpcYuvDst, uiPartIdx, iPosX, iPosY );
3091  }
3092  else
3093  {
3094    assert (0);
3095  }
3096}
3097#endif
3098
3099// AMVP
3100Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMvPred )
3101{
3102  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
3103
3104  if( pcCU->getAMVPMode(uiPartAddr) == AM_NONE || (pcAMVPInfo->iN <= 1 && pcCU->getAMVPMode(uiPartAddr) == AM_EXPL) )
3105  {
3106    rcMvPred = pcAMVPInfo->m_acMvCand[0];
3107
3108    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
3109    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
3110    return;
3111  }
3112
3113  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
3114  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
3115  return;
3116}
3117
3118#if ADD_PLANAR_MODE
3119/** Function for deriving planar intra prediction.
3120 * \param pSrc pointer to reconstructed sample array
3121 * \param srcStride the stride of the reconstructed sample array
3122 * \param rpDst reference to pointer for the prediction sample array
3123 * \param dstStride the stride of the prediction sample array
3124 * \param width the width of the block
3125 * \param height the height of the block
3126 * \param blkAboveAvailable boolean indication if the block above is available
3127 * \param blkLeftAvailable boolean indication if the block to the left is available
3128 *
3129 * This function derives the prediction samples for planar mode (intra coding).
3130 */
3131#if REFERENCE_SAMPLE_PADDING
3132Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height )
3133#else
3134Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, Bool blkAboveAvailable, Bool blkLeftAvailable )
3135#endif
3136{
3137  assert(width == height);
3138
3139  Int k, l, bottomLeft, topRight;
3140  Int horPred;
3141  Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
3142  UInt blkSize = width;
3143  UInt offset2D = width;
3144  UInt shift1D = g_aucConvertToBit[ width ] + 2;
3145  UInt shift2D = shift1D + 1;
3146
3147  // Get left and above reference column and row
3148#if REFERENCE_SAMPLE_PADDING
3149  for(k=0;k<blkSize;k++)
3150  {
3151    topRow[k] = pSrc[k-srcStride];
3152    leftColumn[k] = pSrc[k*srcStride-1];
3153  }
3154#else
3155  if (!blkAboveAvailable && !blkLeftAvailable)
3156  {
3157    for(k=0;k<blkSize;k++)
3158    {
3159      leftColumn[k] = topRow[k] = ( 1 << ( g_uiBitDepth + g_uiBitIncrement - 1 ) );
3160    }
3161  }
3162  else
3163  {
3164    if(blkAboveAvailable)
3165    {
3166      for(k=0;k<blkSize;k++)
3167      {
3168        topRow[k] = pSrc[k-srcStride];
3169      }
3170    }
3171    else
3172    {
3173      Int leftSample = pSrc[-1];
3174      for(k=0;k<blkSize;k++)
3175      {
3176        topRow[k] = leftSample;
3177      }
3178    }
3179    if(blkLeftAvailable)
3180    {
3181      for(k=0;k<blkSize;k++)
3182      {
3183        leftColumn[k] = pSrc[k*srcStride-1];
3184      }
3185    }
3186    else
3187    {
3188      Int aboveSample = pSrc[-srcStride];
3189      for(k=0;k<blkSize;k++)
3190      {
3191        leftColumn[k] = aboveSample;
3192      }
3193    }
3194  }
3195#endif
3196
3197  // Prepare intermediate variables used in interpolation
3198  bottomLeft = leftColumn[blkSize-1];
3199  topRight   = topRow[blkSize-1];
3200  for (k=0;k<blkSize;k++)
3201  {
3202    bottomRow[k]   = bottomLeft - topRow[k];
3203    rightColumn[k] = topRight   - leftColumn[k];
3204    topRow[k]      <<= shift1D;
3205    leftColumn[k]  <<= shift1D;
3206  }
3207
3208  // Generate prediction signal
3209  for (k=0;k<blkSize;k++)
3210  {
3211    horPred = leftColumn[k] + offset2D;
3212    for (l=0;l<blkSize;l++)
3213    {
3214      horPred += rightColumn[k];
3215      topRow[l] += bottomRow[l];
3216      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
3217    }
3218  }
3219}
3220#endif
3221
3222#if LM_CHROMA
3223/** Function for deriving chroma LM intra prediction.
3224 * \param pcPattern pointer to neighbouring pixel access pattern
3225 * \param pSrc pointer to reconstructed chroma sample array
3226 * \param pPred pointer for the prediction sample array
3227 * \param uiPredStride the stride of the prediction sample array
3228 * \param uiCWidth the width of the chroma block
3229 * \param uiCHeight the height of the chroma block
3230 * \param uiChromaId boolean indication of chroma component
3231
3232 \ This function derives the prediction samples for chroma LM mode (chroma intra coding)
3233 */
3234Void TComPrediction::predLMIntraChroma( TComPattern* pcPattern, Int* piSrc, Pel* pPred, UInt uiPredStride, UInt uiCWidth, UInt uiCHeight, UInt uiChromaId )
3235{
3236  UInt uiWidth  = uiCWidth << 1;
3237  UInt uiHeight = uiCHeight << 1;
3238
3239  if (uiChromaId == 0)
3240    xGetRecPixels( pcPattern, pcPattern->getROIY(), pcPattern->getPatternLStride(), m_pLumaRecBuffer + m_iLumaRecStride + 1, m_iLumaRecStride, uiWidth, uiHeight );
3241
3242  xGetLLSPrediction( pcPattern, piSrc+uiWidth+2, uiWidth+1, pPred, uiPredStride, uiCWidth, uiCHeight, 1 ); 
3243}
3244
3245/** Function for deriving downsampled luma sample of current chroma block and its above, left causal pixel
3246 * \param pcPattern pointer to neighbouring pixel access pattern
3247 * \param pRecSrc pointer to reconstructed luma sample array
3248 * \param iRecSrcStride the stride of reconstructed luma sample array
3249 * \param pDst0 pointer to downsampled luma sample array
3250 * \param iDstStride the stride of downsampled luma sample array
3251 * \param uiWidth0 the width of the luma block
3252 * \param uiHeight0 the height of the luma block
3253
3254 \ This function derives downsampled luma sample of current chroma block and its above, left causal pixel
3255 */
3256
3257Void TComPrediction::xGetRecPixels( TComPattern* pcPattern, Pel* pRecSrc, Int iRecSrcStride, Pel* pDst0, Int iDstStride, UInt uiWidth0, UInt uiHeight0 )
3258{
3259  Pel* pSrc = pRecSrc;
3260  Pel* pDst = pDst0;
3261
3262  Int uiCWidth = uiWidth0/2;
3263  Int uiCHeight = uiHeight0/2;
3264
3265  if( pcPattern->isLeftAvailable() )
3266  {
3267    pSrc = pSrc - 2;
3268    pDst = pDst - 1;
3269
3270    uiCWidth += 1;
3271  }
3272
3273  if( pcPattern->isAboveAvailable() )
3274  {
3275    pSrc = pSrc - 2*iRecSrcStride;
3276    pDst = pDst - iDstStride;
3277
3278    uiCHeight += 1;
3279  }
3280
3281  for( Int j = 0; j < uiCHeight; j++ )
3282    {
3283      for( Int i = 0, ii = i << 1; i < uiCWidth; i++, ii = i << 1 )
3284        pDst[i] = (pSrc[ii] + pSrc[ii + iRecSrcStride]) >> 1;
3285
3286      pDst += iDstStride;
3287      pSrc += iRecSrcStride*2;
3288    } 
3289}
3290
3291/** Function for deriving the positon of first non-zero binary bit of a value
3292 * \param x input value
3293 \ This function derives the positon of first non-zero binary bit of a value
3294 */
3295Int GetMSB( UInt x )
3296{
3297#if 1
3298  Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1;
3299
3300  while( x > 1 )
3301  {
3302    bits >>= 1;
3303    y = x >> bits;
3304
3305    if( y )
3306    {
3307      x = y;
3308      iMSB += bits;
3309    }
3310  }
3311
3312  iMSB+=y;
3313
3314#else
3315
3316  Int iMSB = 0;
3317  while( x > 0 )
3318  {
3319    x >>= 1;
3320    iMSB++;
3321  }
3322#endif
3323
3324  return iMSB;
3325}
3326
3327/** Function for deriving LM intra prediction.
3328 * \param pcPattern pointer to neighbouring pixel access pattern
3329 * \param pSrc0 pointer to reconstructed chroma sample array
3330 * \param iSrcStride the stride of reconstructed chroma sample array
3331 * \param pDst0 reference to pointer for the prediction sample array
3332 * \param iDstStride the stride of the prediction sample array
3333 * \param uiWidth the width of the chroma block
3334 * \param uiHeight the height of the chroma block
3335 * \param uiExt0 line number of neiggboirng pixels for calculating LM model parameter, default value is 1
3336
3337 \ This function derives the prediction samples for chroma LM mode (chroma intra coding)
3338 */
3339Void TComPrediction::xGetLLSPrediction( TComPattern* pcPattern, Int* pSrc0, Int iSrcStride, Pel* pDst0, Int iDstStride, UInt uiWidth, UInt uiHeight, UInt uiExt0 )
3340{
3341
3342  Pel  *pDst, *pLuma;
3343  Int  *pSrc;
3344
3345  Int  iLumaStride = m_iLumaRecStride;
3346  Pel* pLuma0 = m_pLumaRecBuffer + uiExt0 * iLumaStride + uiExt0;
3347
3348  Int i, j, iCountShift = 0;
3349
3350  UInt uiExt = uiExt0;
3351
3352  // LLS parameters estimation -->
3353
3354  Int x = 0, y = 0, xx = 0, xy = 0;
3355
3356  if( pcPattern->isAboveAvailable() )
3357  {
3358    pSrc  = pSrc0  - iSrcStride;
3359    pLuma = pLuma0 - iLumaStride;
3360
3361    for( j = 0; j < uiWidth; j++ )
3362    {
3363      x += pLuma[j];
3364      y += pSrc[j];
3365      xx += pLuma[j] * pLuma[j];
3366      xy += pLuma[j] * pSrc[j];
3367    }
3368    iCountShift += g_aucConvertToBit[ uiWidth ] + 2;
3369  }
3370
3371  if( pcPattern->isLeftAvailable() )
3372  {
3373    pSrc  = pSrc0 - uiExt;
3374    pLuma = pLuma0 - uiExt;
3375
3376    for( i = 0; i < uiHeight; i++ )
3377    {
3378      x += pLuma[0];
3379      y += pSrc[0];
3380      xx += pLuma[0] * pLuma[0];
3381      xy += pLuma[0] * pSrc[0];
3382
3383      pSrc  += iSrcStride;
3384      pLuma += iLumaStride;
3385    }
3386    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 );
3387  }
3388
3389  Int iBitdepth = ( ( g_uiBitDepth + g_uiBitIncrement ) + g_aucConvertToBit[ uiWidth ] + 3 ) * 2;
3390  Int iTempShift = Max( ( iBitdepth - 31 + 1) / 2, 0);
3391
3392  if(iTempShift > 0)
3393  {
3394    x  = ( x +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
3395    y  = ( y +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
3396    xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
3397    xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
3398    iCountShift -= iTempShift;
3399  }
3400
3401  Int a, b, iShift = 13;
3402
3403  if( iCountShift == 0 )
3404  {
3405    a = 0;
3406    b = 128 << g_uiBitIncrement;
3407    iShift = 0;
3408  }
3409  else
3410  {
3411    Int a1 = ( xy << iCountShift ) - y * x;
3412    Int a2 = ( xx << iCountShift ) - x * x;             
3413
3414    if( a2 == 0 || a1 == 0 )
3415    {
3416      a = 0;
3417      b = ( y + ( 1 << ( iCountShift - 1 ) ) )>> iCountShift;
3418      iShift = 0;
3419    }
3420    else
3421    {
3422      const Int iShiftA2 = 6;
3423      const Int iShiftA1 = 15;
3424      const Int iAccuracyShift = 15;
3425
3426      Int iScaleShiftA2 = 0;
3427      Int iScaleShiftA1 = 0;
3428      Int a1s = a1;
3429      Int a2s = a2;
3430
3431      iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1;
3432      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; 
3433
3434      if( iScaleShiftA1 < 0 )
3435        iScaleShiftA1 = 0;
3436
3437      if( iScaleShiftA2 < 0 )
3438        iScaleShiftA2 = 0;
3439
3440      Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
3441
3442      a2s = a2 >> iScaleShiftA2;
3443
3444      a1s = a1 >> iScaleShiftA1;
3445
3446      a = a1s * m_uiaShift[ abs( a2s ) ];
3447     
3448      if( iScaleShiftA < 0 )
3449        a = a << -iScaleShiftA;
3450      else
3451        a = a >> iScaleShiftA;
3452
3453      if( a > ( 1 << 15 ) - 1 )
3454        a = ( 1 << 15 ) - 1;
3455      else if( a < -( 1 << 15 ) )
3456        a = -( 1 << 15 );
3457
3458      b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
3459    }
3460  }   
3461
3462  // <-- end of LLS parameters estimation
3463
3464  // get prediction -->
3465  uiExt = uiExt0;
3466  pLuma = pLuma0;
3467  pDst = pDst0;
3468
3469  for( i = 0; i < uiHeight; i++ )
3470  {
3471    for( j = 0; j < uiWidth; j++ )
3472      pDst[j] = Clip( ( ( a * pLuma[j] ) >> iShift ) + b );
3473
3474    pDst  += iDstStride;
3475    pLuma += iLumaStride;
3476  }
3477  // <-- end of get prediction
3478
3479}
3480#endif
3481
3482#if MN_DC_PRED_FILTER
3483/** Function for filtering intra DC predictor.
3484 * \param pSrc pointer to reconstructed sample array
3485 * \param iSrcStride the stride of the reconstructed sample array
3486 * \param rpDst reference to pointer for the prediction sample array
3487 * \param iDstStride the stride of the prediction sample array
3488 * \param iWidth the width of the block
3489 * \param iHeight the height of the block
3490 *
3491 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
3492 */
3493Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
3494{
3495  Pel* pDst = rpDst;
3496  Int x, y, iDstStride2, iSrcStride2;
3497  Int iIntraSizeIdx = g_aucConvertToBit[ iWidth ] + 1;
3498  static const UChar g_aucDCPredFilter[7] = { 0, 3, 2, 1, 0, 0, 0};
3499
3500  switch (g_aucDCPredFilter[iIntraSizeIdx])
3501  {
3502  case 0:
3503    {}
3504    break;
3505  case 1:
3506    {
3507      // boundary pixels processing
3508      pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 6 * pDst[0] + 4) >> 3);
3509
3510      for ( x = 1; x < iWidth; x++ )
3511        pDst[x] = (Pel)((pSrc[x - iSrcStride] + 7 * pDst[x] + 4) >> 3);
3512
3513      for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
3514        pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 7 * pDst[iDstStride2] + 4) >> 3);
3515    }
3516    break;
3517  case 2:
3518    {
3519      // boundary pixels processing
3520      pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
3521
3522      for ( x = 1; x < iWidth; x++ )
3523        pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2);
3524
3525      for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
3526        pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
3527    }
3528    break;
3529  case 3:
3530    {
3531      // boundary pixels processing
3532      pDst[0] = (Pel)((3 * (pSrc[-iSrcStride] + pSrc[-1]) + 2 * pDst[0] + 4) >> 3);
3533
3534      for ( x = 1; x < iWidth; x++ )
3535        pDst[x] = (Pel)((3 * pSrc[x - iSrcStride] + 5 * pDst[x] + 4) >> 3);
3536
3537      for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
3538        pDst[iDstStride2] = (Pel)((3 * pSrc[iSrcStride2] + 5 * pDst[iDstStride2] + 4) >> 3);
3539    }
3540    break;
3541  }
3542
3543  return;
3544}
3545#endif
3546
3547#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
3548TComWedgeDist::TComWedgeDist()
3549{
3550  init();
3551}
3552
3553TComWedgeDist::~TComWedgeDist()
3554{
3555}
3556
3557Void TComWedgeDist::init()
3558{
3559  //   m_afpDistortFunc[0]  = NULL;                  // for DF_DEFAULT
3560
3561  //   m_afpDistortFunc[8]  = TComRdCost::xGetSAD;
3562  m_afpDistortFunc[0]  = TComWedgeDist::xGetSAD4;
3563  m_afpDistortFunc[1] = TComWedgeDist::xGetSAD8;
3564  m_afpDistortFunc[2] = TComWedgeDist::xGetSAD16;
3565  m_afpDistortFunc[3] = TComWedgeDist::xGetSAD32;
3566
3567  m_afpDistortFunc[4]  = TComWedgeDist::xGetSSE4;
3568  m_afpDistortFunc[5]  = TComWedgeDist::xGetSSE8;
3569  m_afpDistortFunc[6]  = TComWedgeDist::xGetSSE16;
3570  m_afpDistortFunc[7]  = TComWedgeDist::xGetSSE32;
3571
3572  //   m_afpDistortFunc[13] = TComRdCost::xGetSAD64;
3573#ifdef ROUNDING_CONTROL_BIPRED
3574  //   m_afpDistortFuncRnd[0]  = NULL;
3575  //   m_afpDistortFuncRnd[8]  = TComRdCost::xGetSAD;
3576  m_afpDistortFuncRnd[9]  = TComRdCost::xGetSAD4;
3577  m_afpDistortFuncRnd[10] = TComRdCost::xGetSAD8;
3578  m_afpDistortFuncRnd[11] = TComRdCost::xGetSAD16;
3579  m_afpDistortFuncRnd[12] = TComRdCost::xGetSAD32;
3580  //   m_afpDistortFuncRnd[13] = TComRdCost::xGetSAD64;
3581#endif
3582}
3583
3584UInt TComWedgeDist::xGetSAD4( DistParam* pcDtParam )
3585{
3586  Pel* piOrg   = pcDtParam->pOrg;
3587  Pel* piCur   = pcDtParam->pCur;
3588  Int  iRows   = pcDtParam->iRows;
3589  Int  iSubShift  = pcDtParam->iSubShift;
3590  Int  iSubStep   = ( 1 << iSubShift );
3591  Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
3592  Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
3593
3594  UInt uiSum = 0;
3595
3596  for( ; iRows != 0; iRows-=iSubStep )
3597  {
3598    uiSum += abs( piOrg[0] - piCur[0] );
3599    uiSum += abs( piOrg[1] - piCur[1] );
3600    uiSum += abs( piOrg[2] - piCur[2] );
3601    uiSum += abs( piOrg[3] - piCur[3] );
3602
3603    piOrg += iStrideOrg;
3604    piCur += iStrideCur;
3605  }
3606
3607  uiSum <<= iSubShift;
3608  return ( uiSum >> g_uiBitIncrement );
3609}
3610
3611UInt TComWedgeDist::xGetSAD8( DistParam* pcDtParam )
3612{
3613  Pel* piOrg      = pcDtParam->pOrg;
3614  Pel* piCur      = pcDtParam->pCur;
3615  Int  iRows      = pcDtParam->iRows;
3616  Int  iSubShift  = pcDtParam->iSubShift;
3617  Int  iSubStep   = ( 1 << iSubShift );
3618  Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
3619  Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
3620
3621  UInt uiSum = 0;
3622
3623  for( ; iRows != 0; iRows-=iSubStep )
3624  {
3625    uiSum += abs( piOrg[0] - piCur[0] );
3626    uiSum += abs( piOrg[1] - piCur[1] );
3627    uiSum += abs( piOrg[2] - piCur[2] );
3628    uiSum += abs( piOrg[3] - piCur[3] );
3629    uiSum += abs( piOrg[4] - piCur[4] );
3630    uiSum += abs( piOrg[5] - piCur[5] );
3631    uiSum += abs( piOrg[6] - piCur[6] );
3632    uiSum += abs( piOrg[7] - piCur[7] );
3633
3634    piOrg += iStrideOrg;
3635    piCur += iStrideCur;
3636  }
3637
3638  uiSum <<= iSubShift;
3639  return ( uiSum >> g_uiBitIncrement );
3640}
3641
3642UInt TComWedgeDist::xGetSAD16( DistParam* pcDtParam )
3643{
3644  Pel* piOrg   = pcDtParam->pOrg;
3645  Pel* piCur   = pcDtParam->pCur;
3646  Int  iRows   = pcDtParam->iRows;
3647  Int  iSubShift  = pcDtParam->iSubShift;
3648  Int  iSubStep   = ( 1 << iSubShift );
3649  Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
3650  Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
3651
3652  UInt uiSum = 0;
3653
3654  for( ; iRows != 0; iRows-=iSubStep )
3655  {
3656    uiSum += abs( piOrg[0] - piCur[0] );
3657    uiSum += abs( piOrg[1] - piCur[1] );
3658    uiSum += abs( piOrg[2] - piCur[2] );
3659    uiSum += abs( piOrg[3] - piCur[3] );
3660    uiSum += abs( piOrg[4] - piCur[4] );
3661    uiSum += abs( piOrg[5] - piCur[5] );
3662    uiSum += abs( piOrg[6] - piCur[6] );
3663    uiSum += abs( piOrg[7] - piCur[7] );
3664    uiSum += abs( piOrg[8] - piCur[8] );
3665    uiSum += abs( piOrg[9] - piCur[9] );
3666    uiSum += abs( piOrg[10] - piCur[10] );
3667    uiSum += abs( piOrg[11] - piCur[11] );
3668    uiSum += abs( piOrg[12] - piCur[12] );
3669    uiSum += abs( piOrg[13] - piCur[13] );
3670    uiSum += abs( piOrg[14] - piCur[14] );
3671    uiSum += abs( piOrg[15] - piCur[15] );
3672
3673    piOrg += iStrideOrg;
3674    piCur += iStrideCur;
3675  }
3676
3677  uiSum <<= iSubShift;
3678  return ( uiSum >> g_uiBitIncrement );
3679}
3680
3681UInt TComWedgeDist::xGetSAD32( DistParam* pcDtParam )
3682{
3683  Pel* piOrg   = pcDtParam->pOrg;
3684  Pel* piCur   = pcDtParam->pCur;
3685  Int  iRows   = pcDtParam->iRows;
3686  Int  iSubShift  = pcDtParam->iSubShift;
3687  Int  iSubStep   = ( 1 << iSubShift );
3688  Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
3689  Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
3690
3691  UInt uiSum = 0;
3692
3693  for( ; iRows != 0; iRows-=iSubStep )
3694  {
3695    uiSum += abs( piOrg[0] - piCur[0] );
3696    uiSum += abs( piOrg[1] - piCur[1] );
3697    uiSum += abs( piOrg[2] - piCur[2] );
3698    uiSum += abs( piOrg[3] - piCur[3] );
3699    uiSum += abs( piOrg[4] - piCur[4] );
3700    uiSum += abs( piOrg[5] - piCur[5] );
3701    uiSum += abs( piOrg[6] - piCur[6] );
3702    uiSum += abs( piOrg[7] - piCur[7] );
3703    uiSum += abs( piOrg[8] - piCur[8] );
3704    uiSum += abs( piOrg[9] - piCur[9] );
3705    uiSum += abs( piOrg[10] - piCur[10] );
3706    uiSum += abs( piOrg[11] - piCur[11] );
3707    uiSum += abs( piOrg[12] - piCur[12] );
3708    uiSum += abs( piOrg[13] - piCur[13] );
3709    uiSum += abs( piOrg[14] - piCur[14] );
3710    uiSum += abs( piOrg[15] - piCur[15] );
3711    uiSum += abs( piOrg[16] - piCur[16] );
3712    uiSum += abs( piOrg[17] - piCur[17] );
3713    uiSum += abs( piOrg[18] - piCur[18] );
3714    uiSum += abs( piOrg[19] - piCur[19] );
3715    uiSum += abs( piOrg[20] - piCur[20] );
3716    uiSum += abs( piOrg[21] - piCur[21] );
3717    uiSum += abs( piOrg[22] - piCur[22] );
3718    uiSum += abs( piOrg[23] - piCur[23] );
3719    uiSum += abs( piOrg[24] - piCur[24] );
3720    uiSum += abs( piOrg[25] - piCur[25] );
3721    uiSum += abs( piOrg[26] - piCur[26] );
3722    uiSum += abs( piOrg[27] - piCur[27] );
3723    uiSum += abs( piOrg[28] - piCur[28] );
3724    uiSum += abs( piOrg[29] - piCur[29] );
3725    uiSum += abs( piOrg[30] - piCur[30] );
3726    uiSum += abs( piOrg[31] - piCur[31] );
3727
3728    piOrg += iStrideOrg;
3729    piCur += iStrideCur;
3730  }
3731
3732  uiSum <<= iSubShift;
3733  return ( uiSum >> g_uiBitIncrement );
3734}
3735
3736UInt TComWedgeDist::xGetSSE4( DistParam* pcDtParam )
3737{
3738  Pel* piOrg   = pcDtParam->pOrg;
3739  Pel* piCur   = pcDtParam->pCur;
3740  Int  iRows   = pcDtParam->iRows;
3741  Int  iStrideOrg = pcDtParam->iStrideOrg;
3742  Int  iStrideCur = pcDtParam->iStrideCur;
3743
3744  UInt uiSum = 0;
3745  UInt uiShift = g_uiBitIncrement<<1;
3746
3747  Int  iTemp;
3748
3749  for( ; iRows != 0; iRows-- )
3750  {
3751
3752    iTemp = piOrg[0] - piCur[0]; uiSum += ( iTemp * iTemp ) >> uiShift;
3753    iTemp = piOrg[1] - piCur[1]; uiSum += ( iTemp * iTemp ) >> uiShift;
3754    iTemp = piOrg[2] - piCur[2]; uiSum += ( iTemp * iTemp ) >> uiShift;
3755    iTemp = piOrg[3] - piCur[3]; uiSum += ( iTemp * iTemp ) >> uiShift;
3756
3757    piOrg += iStrideOrg;
3758    piCur += iStrideCur;
3759  }
3760
3761  return ( uiSum );
3762}
3763
3764UInt TComWedgeDist::xGetSSE8( DistParam* pcDtParam )
3765{
3766  Pel* piOrg   = pcDtParam->pOrg;
3767  Pel* piCur   = pcDtParam->pCur;
3768  Int  iRows   = pcDtParam->iRows;
3769  Int  iStrideOrg = pcDtParam->iStrideOrg;
3770  Int  iStrideCur = pcDtParam->iStrideCur;
3771
3772  UInt uiSum = 0;
3773  UInt uiShift = g_uiBitIncrement<<1;
3774
3775  Int  iTemp;
3776
3777  for( ; iRows != 0; iRows-- )
3778  {
3779    iTemp = piOrg[0] - piCur[0]; uiSum += ( iTemp * iTemp ) >> uiShift;
3780    iTemp = piOrg[1] - piCur[1]; uiSum += ( iTemp * iTemp ) >> uiShift;
3781    iTemp = piOrg[2] - piCur[2]; uiSum += ( iTemp * iTemp ) >> uiShift;
3782    iTemp = piOrg[3] - piCur[3]; uiSum += ( iTemp * iTemp ) >> uiShift;
3783    iTemp = piOrg[4] - piCur[4]; uiSum += ( iTemp * iTemp ) >> uiShift;
3784    iTemp = piOrg[5] - piCur[5]; uiSum += ( iTemp * iTemp ) >> uiShift;
3785    iTemp = piOrg[6] - piCur[6]; uiSum += ( iTemp * iTemp ) >> uiShift;
3786    iTemp = piOrg[7] - piCur[7]; uiSum += ( iTemp * iTemp ) >> uiShift;
3787
3788    piOrg += iStrideOrg;
3789    piCur += iStrideCur;
3790  }
3791
3792  return ( uiSum );
3793}
3794
3795UInt TComWedgeDist::xGetSSE16( DistParam* pcDtParam )
3796{
3797  Pel* piOrg   = pcDtParam->pOrg;
3798  Pel* piCur   = pcDtParam->pCur;
3799  Int  iRows   = pcDtParam->iRows;
3800  Int  iStrideOrg = pcDtParam->iStrideOrg;
3801  Int  iStrideCur = pcDtParam->iStrideCur;
3802
3803  UInt uiSum = 0;
3804  UInt uiShift = g_uiBitIncrement<<1;
3805
3806  Int  iTemp;
3807
3808  for( ; iRows != 0; iRows-- )
3809  {
3810
3811    iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift;
3812    iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift;
3813    iTemp = piOrg[ 2] - piCur[ 2]; uiSum += ( iTemp * iTemp ) >> uiShift;
3814    iTemp = piOrg[ 3] - piCur[ 3]; uiSum += ( iTemp * iTemp ) >> uiShift;
3815    iTemp = piOrg[ 4] - piCur[ 4]; uiSum += ( iTemp * iTemp ) >> uiShift;
3816    iTemp = piOrg[ 5] - piCur[ 5]; uiSum += ( iTemp * iTemp ) >> uiShift;
3817    iTemp = piOrg[ 6] - piCur[ 6]; uiSum += ( iTemp * iTemp ) >> uiShift;
3818    iTemp = piOrg[ 7] - piCur[ 7]; uiSum += ( iTemp * iTemp ) >> uiShift;
3819    iTemp = piOrg[ 8] - piCur[ 8]; uiSum += ( iTemp * iTemp ) >> uiShift;
3820    iTemp = piOrg[ 9] - piCur[ 9]; uiSum += ( iTemp * iTemp ) >> uiShift;
3821    iTemp = piOrg[10] - piCur[10]; uiSum += ( iTemp * iTemp ) >> uiShift;
3822    iTemp = piOrg[11] - piCur[11]; uiSum += ( iTemp * iTemp ) >> uiShift;
3823    iTemp = piOrg[12] - piCur[12]; uiSum += ( iTemp * iTemp ) >> uiShift;
3824    iTemp = piOrg[13] - piCur[13]; uiSum += ( iTemp * iTemp ) >> uiShift;
3825    iTemp = piOrg[14] - piCur[14]; uiSum += ( iTemp * iTemp ) >> uiShift;
3826    iTemp = piOrg[15] - piCur[15]; uiSum += ( iTemp * iTemp ) >> uiShift;
3827
3828    piOrg += iStrideOrg;
3829    piCur += iStrideCur;
3830  }
3831
3832  return ( uiSum );
3833}
3834
3835UInt TComWedgeDist::xGetSSE32( DistParam* pcDtParam )
3836{
3837  Pel* piOrg   = pcDtParam->pOrg;
3838  Pel* piCur   = pcDtParam->pCur;
3839  Int  iRows   = pcDtParam->iRows;
3840  Int  iStrideOrg = pcDtParam->iStrideOrg;
3841  Int  iStrideCur = pcDtParam->iStrideCur;
3842
3843  UInt uiSum = 0;
3844  UInt uiShift = g_uiBitIncrement<<1;
3845  Int  iTemp;
3846
3847  for( ; iRows != 0; iRows-- )
3848  {
3849
3850    iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift;
3851    iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift;
3852    iTemp = piOrg[ 2] - piCur[ 2]; uiSum += ( iTemp * iTemp ) >> uiShift;
3853    iTemp = piOrg[ 3] - piCur[ 3]; uiSum += ( iTemp * iTemp ) >> uiShift;
3854    iTemp = piOrg[ 4] - piCur[ 4]; uiSum += ( iTemp * iTemp ) >> uiShift;
3855    iTemp = piOrg[ 5] - piCur[ 5]; uiSum += ( iTemp * iTemp ) >> uiShift;
3856    iTemp = piOrg[ 6] - piCur[ 6]; uiSum += ( iTemp * iTemp ) >> uiShift;
3857    iTemp = piOrg[ 7] - piCur[ 7]; uiSum += ( iTemp * iTemp ) >> uiShift;
3858    iTemp = piOrg[ 8] - piCur[ 8]; uiSum += ( iTemp * iTemp ) >> uiShift;
3859    iTemp = piOrg[ 9] - piCur[ 9]; uiSum += ( iTemp * iTemp ) >> uiShift;
3860    iTemp = piOrg[10] - piCur[10]; uiSum += ( iTemp * iTemp ) >> uiShift;
3861    iTemp = piOrg[11] - piCur[11]; uiSum += ( iTemp * iTemp ) >> uiShift;
3862    iTemp = piOrg[12] - piCur[12]; uiSum += ( iTemp * iTemp ) >> uiShift;
3863    iTemp = piOrg[13] - piCur[13]; uiSum += ( iTemp * iTemp ) >> uiShift;
3864    iTemp = piOrg[14] - piCur[14]; uiSum += ( iTemp * iTemp ) >> uiShift;
3865    iTemp = piOrg[15] - piCur[15]; uiSum += ( iTemp * iTemp ) >> uiShift;
3866    iTemp = piOrg[16] - piCur[16]; uiSum += ( iTemp * iTemp ) >> uiShift;
3867    iTemp = piOrg[17] - piCur[17]; uiSum += ( iTemp * iTemp ) >> uiShift;
3868    iTemp = piOrg[18] - piCur[18]; uiSum += ( iTemp * iTemp ) >> uiShift;
3869    iTemp = piOrg[19] - piCur[19]; uiSum += ( iTemp * iTemp ) >> uiShift;
3870    iTemp = piOrg[20] - piCur[20]; uiSum += ( iTemp * iTemp ) >> uiShift;
3871    iTemp = piOrg[21] - piCur[21]; uiSum += ( iTemp * iTemp ) >> uiShift;
3872    iTemp = piOrg[22] - piCur[22]; uiSum += ( iTemp * iTemp ) >> uiShift;
3873    iTemp = piOrg[23] - piCur[23]; uiSum += ( iTemp * iTemp ) >> uiShift;
3874    iTemp = piOrg[24] - piCur[24]; uiSum += ( iTemp * iTemp ) >> uiShift;
3875    iTemp = piOrg[25] - piCur[25]; uiSum += ( iTemp * iTemp ) >> uiShift;
3876    iTemp = piOrg[26] - piCur[26]; uiSum += ( iTemp * iTemp ) >> uiShift;
3877    iTemp = piOrg[27] - piCur[27]; uiSum += ( iTemp * iTemp ) >> uiShift;
3878    iTemp = piOrg[28] - piCur[28]; uiSum += ( iTemp * iTemp ) >> uiShift;
3879    iTemp = piOrg[29] - piCur[29]; uiSum += ( iTemp * iTemp ) >> uiShift;
3880    iTemp = piOrg[30] - piCur[30]; uiSum += ( iTemp * iTemp ) >> uiShift;
3881    iTemp = piOrg[31] - piCur[31]; uiSum += ( iTemp * iTemp ) >> uiShift;
3882
3883    piOrg += iStrideOrg;
3884    piCur += iStrideCur;
3885  }
3886
3887  return ( uiSum );
3888}
3889
3890Void TComWedgeDist::setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, WedgeDist eWDist, DistParam& rcDistParam )
3891{
3892  // set Block Width / Height
3893  rcDistParam.iCols    = uiBlkWidth;
3894  rcDistParam.iRows    = uiBlkHeight;
3895  rcDistParam.DistFunc = m_afpDistortFunc[eWDist + g_aucConvertToBit[ rcDistParam.iCols ] ];
3896
3897  // initialize
3898  rcDistParam.iSubShift  = 0;
3899}
3900
3901UInt TComWedgeDist::getDistPart( Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, WedgeDist eWDist )
3902{
3903  DistParam cDtParam;
3904  setDistParam( uiBlkWidth, uiBlkHeight, eWDist, cDtParam );
3905  cDtParam.pOrg       = piOrg;
3906  cDtParam.pCur       = piCur;
3907  cDtParam.iStrideOrg = iOrgStride;
3908  cDtParam.iStrideCur = iCurStride;
3909#ifdef DCM_RDCOST_TEMP_FIX //Temporary fix since DistParam is lacking a constructor and the variable iStep is not initialized
3910  cDtParam.iStep      = 1;
3911#endif
3912  return cDtParam.DistFunc( &cDtParam );
3913}
3914#endif
Note: See TracBrowser for help on using the repository browser.