source: 3DVCSoftware/trunk/source/Lib/TLibCommon/TComPrediction.cpp @ 17

Last change on this file since 17 was 5, checked in by hhi, 13 years ago

Clean version with cfg-files

  • Property svn:eol-style set to native
File size: 95.8 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
1509Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx, Bool bPrdDepthMap )
1510{
1511  Int         iWidth;
1512  Int         iHeight;
1513  UInt        uiPartAddr;
1514
1515  if ( iPartIdx >= 0 )
1516  {
1517    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
1518    if ( eRefPicList != REF_PIC_LIST_X )
1519    {
1520      xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap );
1521#ifdef WEIGHT_PRED
1522      if ( pcCU->getSlice()->getPPS()->getUseWP() )
1523      {
1524        xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx );
1525      }
1526#endif   
1527    }
1528    else
1529    {
1530      xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred, iPartIdx, bPrdDepthMap );
1531
1532    }
1533    return;
1534  }
1535
1536  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
1537  {
1538    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
1539
1540    if ( eRefPicList != REF_PIC_LIST_X )
1541    {
1542      xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap );
1543#ifdef WEIGHT_PRED
1544      if ( pcCU->getSlice()->getPPS()->getUseWP() )
1545      {
1546        xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx );
1547      }
1548#endif
1549    }
1550    else
1551    {
1552      xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred, iPartIdx, bPrdDepthMap );
1553    }
1554  }
1555  return;
1556}
1557
1558#if HIGH_ACCURACY_BI
1559#if DEPTH_MAP_GENERATION
1560Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap, Bool bi )
1561#else
1562Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bi )
1563#endif
1564#else
1565#if DEPTH_MAP_GENERATION
1566Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap )
1567#else
1568Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx )
1569#endif
1570#endif
1571{
1572  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
1573  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
1574  pcCU->clipMv(cMv);
1575
1576#if DEPTH_MAP_GENERATION
1577  if( bPrdDepthMap )
1578  {
1579#if HIGH_ACCURACY_BI
1580    UInt uiRShift = ( bi ? 14-g_uiBitDepth-g_uiBitIncrement : 0 );
1581#else
1582    UInt uiRShift = 0;
1583#endif
1584    xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPredDepthMap(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, uiRShift, PDM_DEPTH_MAP_MCP_FILTER );
1585    return;
1586  }
1587#endif
1588
1589#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
1590  if( pcCU->getSlice()->getSPS()->isDepth() )
1591  {
1592#if HIGH_ACCURACY_BI
1593    UInt uiRShift = ( bi ? 14-g_uiBitDepth-g_uiBitIncrement : 0 );
1594#else
1595    UInt uiRShift = 0;
1596#endif
1597    xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, uiRShift, 2 );
1598  }
1599  else
1600  {
1601#endif
1602#if HIGH_ACCURACY_BI
1603  if(!bi)
1604  {
1605    xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec()    , uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred );
1606  }
1607  else
1608  {
1609    xPredInterLumaBlk_ha  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec()    , uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred );
1610  }
1611#else
1612  xPredInterLumaBlk       ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred );
1613#endif
1614#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
1615  }
1616#endif
1617
1618#if HIGH_ACCURACY_BI
1619  if (!bi)
1620  {
1621    xPredInterChromaBlk     ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred );
1622  }
1623  else
1624  {
1625    xPredInterChromaBlk_ha ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec()    , uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred );
1626  }
1627#else
1628  xPredInterChromaBlk     ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred );
1629#endif
1630}
1631
1632Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap )
1633{
1634  TComYuv* pcMbYuv;
1635  Int      iRefIdx[2] = {-1, -1};
1636
1637  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
1638  {
1639    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
1640    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
1641
1642    if ( iRefIdx[iRefList] < 0 )
1643    {
1644      continue;
1645    }
1646
1647    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
1648
1649    pcMbYuv = &m_acYuvPred[iRefList];
1650#if HIGH_ACCURACY_BI
1651    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
1652#if DEPTH_MAP_GENERATION
1653      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, true );
1654#else
1655      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, true );
1656#endif
1657    else
1658#if DEPTH_MAP_GENERATION
1659     xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap );
1660#else
1661     xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx );
1662#endif
1663#else
1664#if DEPTH_MAP_GENERATION
1665    xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap );
1666#else
1667    xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx );
1668#endif
1669#endif
1670  }
1671
1672#ifdef WEIGHT_PRED
1673  if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() )
1674  {
1675    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1676  }
1677  else
1678#endif
1679  xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
1680}
1681
1682
1683Void
1684TComPrediction::xPredInterPrdDepthMap( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, TComYuv*& rpcYuv, UInt uiRShift, UInt uiFilterMode ) // 0:std, 1:bilin, 2:nearest neighbour
1685{
1686  AOF( uiFilterMode <= 2 );
1687
1688  Int     iFPelMask   = ~3;
1689  Int     iRefStride  = pcPicYuvRef->getStride();
1690  Int     iDstStride  = rpcYuv->getStride();
1691  Int     iHor        = ( uiFilterMode == 2 ? ( pcMv->getHor() + 2 ) & iFPelMask : pcMv->getHor() );
1692  Int     iVer        = ( uiFilterMode == 2 ? ( pcMv->getVer() + 2 ) & iFPelMask : pcMv->getVer() );
1693#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
1694  if( pcCU->getSlice()->getSPS()->isDepth() )
1695  {
1696    assert( uiFilterMode == 2 );
1697    iHor = pcMv->getHor() * 4;
1698    iVer = pcMv->getVer() * 4;
1699  }
1700#endif
1701  Int     iRefOffset  = ( iHor >> 2 ) + ( iVer >> 2 ) * iRefStride;
1702  Int     ixFrac      = iHor & 0x3;
1703  Int     iyFrac      = iVer & 0x3;
1704  Pel*    piRefY      = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
1705  Pel*    piDstY      = rpcYuv->getLumaAddr( uiPartAddr );
1706
1707  //  Integer position
1708  if( ixFrac == 0 && iyFrac == 0 )
1709  {
1710    for( Int y = 0; y < iHeight; y++, piDstY += iDstStride, piRefY += iRefStride )
1711    {
1712      for( Int x = 0; x < iWidth; x++ )
1713      {
1714        piDstY[ x ] = piRefY[ x ] << uiRShift;
1715      }
1716    }
1717    return;
1718  }
1719
1720  // bi-linear interpolation
1721  if( uiFilterMode == 1 )
1722  {
1723    Int   iW00    = ( 4 - ixFrac ) * ( 4 - iyFrac );
1724    Int   iW01    = (     ixFrac ) * ( 4 - iyFrac );
1725    Int   iW10    = ( 4 - ixFrac ) * (     iyFrac );
1726    Int   iW11    = (     ixFrac ) * (     iyFrac );
1727    Pel*  piRefY1 = piRefY + iRefStride;
1728    for( Int y = 0; y < iHeight; y++, piDstY += iDstStride, piRefY += iRefStride, piRefY1 += iRefStride )
1729    {
1730      for( Int x = 0; x < iWidth; x++ )
1731      {
1732        Int iSV     = iW00 * piRefY [ x ] + iW01 * piRefY [ x + 1 ]
1733                    + iW10 * piRefY1[ x ] + iW11 * piRefY1[ x + 1 ];
1734        iSV       <<= uiRShift;
1735        piDstY[ x ] = ( iSV + 8 ) >> 4;
1736      }
1737    }
1738    return;
1739  }
1740
1741  xPredInterLumaBlk( pcCU, pcPicYuvRef, uiPartAddr, pcMv, iWidth, iHeight, rpcYuv );
1742  return;
1743}
1744
1745
1746
1747#if HIGH_ACCURACY_BI
1748
1749Void  TComPrediction::xPredInterLumaBlk_ha( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, TComYuv*& rpcYuv )
1750{
1751  Int     iRefStride = pcPicYuvRef->getStride();
1752  Int     iDstStride = rpcYuv->getStride();
1753
1754  Int     iRefOffset = ( pcMv->getHor() >> 2 ) + ( pcMv->getVer() >> 2 ) * iRefStride;
1755  Pel*    piRefY     = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
1756
1757  Int     ixFrac  = pcMv->getHor() & 0x3;
1758  Int     iyFrac  = pcMv->getVer() & 0x3;
1759
1760  Pel* piDstY = rpcYuv->getLumaAddr( uiPartAddr );
1761    UInt shiftNum = 14-g_uiBitDepth-g_uiBitIncrement;
1762  //  Integer point
1763  if ( ixFrac == 0 && iyFrac == 0 )
1764  {
1765    for ( Int y = 0; y < iHeight; y++ )
1766    {
1767      for(Int x=0; x<iWidth; x++)
1768        piDstY[x] = piRefY[x]<<shiftNum;
1769      piDstY += iDstStride;
1770      piRefY += iRefStride;
1771    }
1772    return;
1773  }
1774
1775  //  Half-pel horizontal
1776  if ( ixFrac == 2 && iyFrac == 0 )
1777  {
1778    xCTI_FilterHalfHor_ha ( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1779    return;
1780  }
1781
1782  //  Half-pel vertical
1783  if ( ixFrac == 0 && iyFrac == 2 )
1784  {
1785    xCTI_FilterHalfVer_ha ( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1786    return;
1787  }
1788
1789  Int   iExtStride = m_iYuvExtStride;//m_cYuvExt.getStride();
1790  Int*  piExtY     = m_piYuvExt;//m_cYuvExt.getLumaAddr();
1791
1792  //  Half-pel center
1793  if ( ixFrac == 2 && iyFrac == 2 )
1794  {
1795    xCTI_FilterHalfVer (piRefY - 3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
1796    xCTI_FilterHalfHor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
1797    return;
1798  }
1799
1800  //  Quater-pel horizontal
1801  if ( iyFrac == 0)
1802  {
1803    if ( ixFrac == 1)
1804    {
1805      xCTI_FilterQuarter0Hor_ha( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1806      return;
1807    }
1808    if ( ixFrac == 3)
1809    {
1810      xCTI_FilterQuarter1Hor_ha( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1811      return;
1812    }
1813  }
1814  if ( iyFrac == 2 )
1815  {
1816    if ( ixFrac == 1)
1817    {
1818      xCTI_FilterHalfVer (piRefY -3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
1819      xCTI_FilterQuarter0Hor_ha (piExtY + 3,  iExtStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1820      return;
1821    }
1822    if ( ixFrac == 3)
1823    {
1824      xCTI_FilterHalfVer (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
1825      xCTI_FilterQuarter1Hor_ha (piExtY + 3,  iExtStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1826      return;
1827    }
1828  }
1829
1830  //  Quater-pel vertical
1831  if( ixFrac == 0 )
1832  {
1833    if( iyFrac == 1 )
1834    {
1835      xCTI_FilterQuarter0Ver_ha( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1836      return;
1837    }
1838    if( iyFrac == 3 )
1839    {
1840      xCTI_FilterQuarter1Ver_ha( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1841      return;
1842    }
1843  }
1844
1845  if( ixFrac == 2 )
1846  {
1847    if( iyFrac == 1 )
1848    {
1849      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
1850      xCTI_FilterHalfHor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
1851
1852      return;
1853    }
1854    if( iyFrac == 3 )
1855    {
1856      xCTI_FilterQuarter1Ver (piRefY -3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
1857      xCTI_FilterHalfHor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
1858      return;
1859    }
1860  }
1861
1862  /// Quarter-pel center
1863  if ( iyFrac == 1)
1864  {
1865    if ( ixFrac == 1)
1866    {
1867      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
1868      xCTI_FilterQuarter0Hor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
1869      return;
1870    }
1871    if ( ixFrac == 3)
1872    {
1873      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
1874      xCTI_FilterQuarter1Hor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
1875
1876      return;
1877    }
1878  }
1879  if ( iyFrac == 3 )
1880  {
1881    if ( ixFrac == 1)
1882    {
1883      xCTI_FilterQuarter1Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
1884      xCTI_FilterQuarter0Hor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
1885      return;
1886    }
1887    if ( ixFrac == 3)
1888    {
1889      xCTI_FilterQuarter1Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
1890      xCTI_FilterQuarter1Hor_ha (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
1891      return;
1892    }
1893  }
1894}
1895
1896#endif
1897
1898Void  TComPrediction::xPredInterLumaBlk( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, TComYuv*& rpcYuv )
1899{
1900  Int     iRefStride = pcPicYuvRef->getStride();
1901  Int     iDstStride = rpcYuv->getStride();
1902
1903  Int     iRefOffset = ( pcMv->getHor() >> 2 ) + ( pcMv->getVer() >> 2 ) * iRefStride;
1904  Pel*    piRefY     = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
1905
1906  Int     ixFrac  = pcMv->getHor() & 0x3;
1907  Int     iyFrac  = pcMv->getVer() & 0x3;
1908
1909  Pel* piDstY = rpcYuv->getLumaAddr( uiPartAddr );
1910
1911  //  Integer point
1912  if ( ixFrac == 0 && iyFrac == 0 )
1913  {
1914    for ( Int y = 0; y < iHeight; y++ )
1915    {
1916      ::memcpy(piDstY, piRefY, sizeof(Pel)*iWidth);
1917      piDstY += iDstStride;
1918      piRefY += iRefStride;
1919    }
1920    return;
1921  }
1922
1923  //  Half-pel horizontal
1924  if ( ixFrac == 2 && iyFrac == 0 )
1925  {
1926    xCTI_FilterHalfHor ( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1927    return;
1928  }
1929
1930  //  Half-pel vertical
1931  if ( ixFrac == 0 && iyFrac == 2 )
1932  {
1933    xCTI_FilterHalfVer ( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1934    return;
1935  }
1936
1937  Int   iExtStride = m_iYuvExtStride;//m_cYuvExt.getStride();
1938  Int*  piExtY     = m_piYuvExt;//m_cYuvExt.getLumaAddr();
1939
1940  //  Half-pel center
1941  if ( ixFrac == 2 && iyFrac == 2 )
1942  {
1943
1944    xCTI_FilterHalfVer (piRefY - 3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
1945    xCTI_FilterHalfHor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
1946    return;
1947  }
1948
1949  //  Quater-pel horizontal
1950  if ( iyFrac == 0)
1951  {
1952    if ( ixFrac == 1)
1953    {
1954      xCTI_FilterQuarter0Hor( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1955      return;
1956    }
1957    if ( ixFrac == 3)
1958    {
1959      xCTI_FilterQuarter1Hor( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1960      return;
1961    }
1962  }
1963  if ( iyFrac == 2 )
1964  {
1965    if ( ixFrac == 1)
1966    {
1967      xCTI_FilterHalfVer (piRefY -3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
1968      xCTI_FilterQuarter0Hor (piExtY + 3,  iExtStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1969      return;
1970    }
1971    if ( ixFrac == 3)
1972    {
1973      xCTI_FilterHalfVer (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
1974      xCTI_FilterQuarter1Hor (piExtY + 3,  iExtStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1975      return;
1976    }
1977  }
1978
1979  //  Quater-pel vertical
1980  if( ixFrac == 0 )
1981  {
1982    if( iyFrac == 1 )
1983    {
1984      xCTI_FilterQuarter0Ver( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1985      return;
1986    }
1987    if( iyFrac == 3 )
1988    {
1989      xCTI_FilterQuarter1Ver( piRefY, iRefStride, 1, iWidth, iHeight, iDstStride, 1, piDstY );
1990      return;
1991    }
1992  }
1993
1994  if( ixFrac == 2 )
1995  {
1996    if( iyFrac == 1 )
1997    {
1998      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
1999      xCTI_FilterHalfHor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2000      return;
2001    }
2002    if( iyFrac == 3 )
2003    {
2004      xCTI_FilterQuarter1Ver (piRefY -3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2005      xCTI_FilterHalfHor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2006      return;
2007    }
2008  }
2009
2010  /// Quarter-pel center
2011  if ( iyFrac == 1)
2012  {
2013    if ( ixFrac == 1)
2014    {
2015      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2016      xCTI_FilterQuarter0Hor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2017      return;
2018    }
2019    if ( ixFrac == 3)
2020    {
2021      xCTI_FilterQuarter0Ver (piRefY - 3,  iRefStride, 1, iWidth +7, iHeight, iExtStride, 1, piExtY );
2022      xCTI_FilterQuarter1Hor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2023      return;
2024    }
2025  }
2026  if ( iyFrac == 3 )
2027  {
2028    if ( ixFrac == 1)
2029    {
2030      xCTI_FilterQuarter1Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2031      xCTI_FilterQuarter0Hor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2032      return;
2033    }
2034    if ( ixFrac == 3)
2035    {
2036      xCTI_FilterQuarter1Ver (piRefY - 3,  iRefStride, 1, iWidth + 7, iHeight, iExtStride, 1, piExtY );
2037      xCTI_FilterQuarter1Hor (piExtY + 3,  iExtStride, 1, iWidth    , iHeight, iDstStride, 1, piDstY );
2038      return;
2039    }
2040  }
2041}
2042
2043#if HIGH_ACCURACY_BI
2044Void TComPrediction::xPredInterChromaBlk_ha( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, TComYuv*& rpcYuv )
2045{
2046  Int     iRefStride  = pcPicYuvRef->getCStride();
2047  Int     iDstStride  = rpcYuv->getCStride();
2048
2049  Int     iRefOffset  = (pcMv->getHor() >> 3) + (pcMv->getVer() >> 3) * iRefStride;
2050
2051  Pel*    piRefCb     = pcPicYuvRef->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2052  Pel*    piRefCr     = pcPicYuvRef->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2053
2054  Pel* piDstCb = rpcYuv->getCbAddr( uiPartAddr );
2055  Pel* piDstCr = rpcYuv->getCrAddr( uiPartAddr );
2056
2057  Int     ixFrac  = pcMv->getHor() & 0x7;
2058  Int     iyFrac  = pcMv->getVer() & 0x7;
2059  UInt    uiCWidth  = iWidth  >> 1;
2060  UInt    uiCHeight = iHeight >> 1;
2061
2062  xDCTIF_FilterC_ha(piRefCb, iRefStride,piDstCb,iDstStride,uiCWidth,uiCHeight, iyFrac, ixFrac);
2063  xDCTIF_FilterC_ha(piRefCr, iRefStride,piDstCr,iDstStride,uiCWidth,uiCHeight, iyFrac, ixFrac);
2064  return;
2065}
2066#endif
2067
2068//--
2069Void TComPrediction::xPredInterChromaBlk( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, TComYuv*& rpcYuv )
2070{
2071  Int     iRefStride  = pcPicYuvRef->getCStride();
2072  Int     iDstStride  = rpcYuv->getCStride();
2073
2074  Int     iRefOffset  = (pcMv->getHor() >> 3) + (pcMv->getVer() >> 3) * iRefStride;
2075
2076  Pel*    piRefCb     = pcPicYuvRef->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2077  Pel*    piRefCr     = pcPicYuvRef->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset;
2078
2079  Pel* piDstCb = rpcYuv->getCbAddr( uiPartAddr );
2080  Pel* piDstCr = rpcYuv->getCrAddr( uiPartAddr );
2081
2082  Int     ixFrac  = pcMv->getHor() & 0x7;
2083  Int     iyFrac  = pcMv->getVer() & 0x7;
2084  UInt    uiCWidth  = iWidth  >> 1;
2085  UInt    uiCHeight = iHeight >> 1;
2086
2087  xDCTIF_FilterC(piRefCb, iRefStride,piDstCb,iDstStride,uiCWidth,uiCHeight, iyFrac, ixFrac);
2088  xDCTIF_FilterC(piRefCr, iRefStride,piDstCr,iDstStride,uiCWidth,uiCHeight, iyFrac, ixFrac);
2089  return;
2090}
2091
2092Void  TComPrediction::xDCTIF_FilterC ( Pel*  piRefC, Int iRefStride,Pel*  piDstC,Int iDstStride,
2093                                       Int iWidth, Int iHeight,Int iMVyFrac,Int iMVxFrac)
2094{
2095  // Integer point
2096  if ( iMVxFrac == 0 && iMVyFrac == 0 )
2097  {
2098    for ( Int y = 0; y < iHeight; y++ )
2099    {
2100      ::memcpy(piDstC, piRefC, sizeof(Pel)*iWidth);
2101      piDstC += iDstStride;
2102      piRefC += iRefStride;
2103    }
2104    return;
2105  }
2106
2107  if ( iMVyFrac == 0 )
2108  {
2109    xCTI_Filter1DHorC (piRefC, iRefStride,  iWidth, iHeight, iDstStride,  piDstC, iMVxFrac );
2110    return;
2111  }
2112
2113  if ( iMVxFrac == 0 )
2114  {
2115    xCTI_Filter1DVerC (piRefC, iRefStride,  iWidth, iHeight, iDstStride,  piDstC, iMVyFrac );
2116    return;
2117}
2118
2119  Int   iExtStride = m_iYuvExtStride;
2120  Int*  piExtC     = m_piYuvExt;
2121
2122  xCTI_Filter2DVerC (piRefC - 1,  iRefStride,  iWidth + 3, iHeight, iExtStride,  piExtC, iMVyFrac );
2123  xCTI_Filter2DHorC (piExtC + 1,  iExtStride,  iWidth             , iHeight, iDstStride,  piDstC, iMVxFrac );
2124}
2125
2126#if HIGH_ACCURACY_BI
2127
2128Void  TComPrediction::xDCTIF_FilterC_ha ( Pel*  piRefC, Int iRefStride,Pel*  piDstC,Int iDstStride,
2129                                       Int iWidth, Int iHeight,Int iMVyFrac,Int iMVxFrac)
2130{
2131  UInt    shiftNumOrg = 6 - g_uiBitIncrement + 8 - g_uiBitDepth;
2132  // Integer point
2133  if ( iMVxFrac == 0 && iMVyFrac == 0 )
2134  {
2135    for (Int y = 0; y < iHeight; y++ )
2136    {
2137      for(Int x=0; x<iWidth; x++)
2138      {
2139        piDstC[x] = (piRefC[x]<<shiftNumOrg);
2140      }
2141      piDstC += iDstStride;
2142      piRefC += iRefStride;
2143    }
2144    return;
2145  }
2146
2147  if ( iMVyFrac == 0 )
2148  {
2149    xCTI_Filter1DHorC_ha (piRefC, iRefStride,  iWidth, iHeight, iDstStride,  piDstC, iMVxFrac );
2150    return;
2151
2152  }
2153
2154  if ( iMVxFrac == 0 )
2155  {
2156    xCTI_Filter1DVerC_ha (piRefC, iRefStride,  iWidth, iHeight, iDstStride,  piDstC, iMVyFrac );
2157    return;
2158  }
2159
2160  Int   iExtStride = m_iYuvExtStride;
2161  Int*  piExtC     = m_piYuvExt;
2162
2163  xCTI_Filter2DVerC (piRefC - 1,  iRefStride,  iWidth + 3, iHeight, iExtStride,  piExtC, iMVyFrac );
2164  xCTI_Filter2DHorC_ha (piExtC + 1,  iExtStride,  iWidth , iHeight, iDstStride,  piDstC, iMVxFrac );
2165  return;
2166
2167}
2168
2169#endif
2170
2171
2172Void TComPrediction::xWeightedAverage( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
2173{
2174  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
2175  {
2176#ifdef ROUNDING_CONTROL_BIPRED
2177    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight, pcCU->getSlice()->isRounding());
2178#else
2179    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
2180#endif
2181  }
2182  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
2183  {
2184    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
2185  }
2186  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
2187  {
2188    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
2189  }
2190  else
2191  {
2192    assert (0);
2193  }
2194}
2195
2196// AMVP
2197Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMvPred )
2198{
2199  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
2200
2201  if( pcCU->getAMVPMode(uiPartAddr) == AM_NONE || (pcAMVPInfo->iN <= 1 && pcCU->getAMVPMode(uiPartAddr) == AM_EXPL) )
2202  {
2203    rcMvPred = pcAMVPInfo->m_acMvCand[0];
2204
2205    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
2206    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
2207    return;
2208  }
2209
2210  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
2211  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
2212  return;
2213}
2214
2215#if ADD_PLANAR_MODE
2216/** Function for deriving planar intra prediction.
2217 * \param pSrc pointer to reconstructed sample array
2218 * \param srcStride the stride of the reconstructed sample array
2219 * \param rpDst reference to pointer for the prediction sample array
2220 * \param dstStride the stride of the prediction sample array
2221 * \param width the width of the block
2222 * \param height the height of the block
2223 * \param blkAboveAvailable boolean indication if the block above is available
2224 * \param blkLeftAvailable boolean indication if the block to the left is available
2225 *
2226 * This function derives the prediction samples for planar mode (intra coding).
2227 */
2228#if REFERENCE_SAMPLE_PADDING
2229Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height )
2230#else
2231Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, Bool blkAboveAvailable, Bool blkLeftAvailable )
2232#endif
2233{
2234  assert(width == height);
2235
2236  Int k, l, bottomLeft, topRight;
2237  Int horPred;
2238  Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
2239  UInt blkSize = width;
2240  UInt offset2D = width;
2241  UInt shift1D = g_aucConvertToBit[ width ] + 2;
2242  UInt shift2D = shift1D + 1;
2243
2244  // Get left and above reference column and row
2245#if REFERENCE_SAMPLE_PADDING
2246  for(k=0;k<blkSize;k++)
2247  {
2248    topRow[k] = pSrc[k-srcStride];
2249    leftColumn[k] = pSrc[k*srcStride-1];
2250  }
2251#else
2252  if (!blkAboveAvailable && !blkLeftAvailable)
2253  {
2254    for(k=0;k<blkSize;k++)
2255    {
2256      leftColumn[k] = topRow[k] = ( 1 << ( g_uiBitDepth + g_uiBitIncrement - 1 ) );
2257    }
2258  }
2259  else
2260  {
2261    if(blkAboveAvailable)
2262    {
2263      for(k=0;k<blkSize;k++)
2264      {
2265        topRow[k] = pSrc[k-srcStride];
2266      }
2267    }
2268    else
2269    {
2270      Int leftSample = pSrc[-1];
2271      for(k=0;k<blkSize;k++)
2272      {
2273        topRow[k] = leftSample;
2274      }
2275    }
2276    if(blkLeftAvailable)
2277    {
2278      for(k=0;k<blkSize;k++)
2279      {
2280        leftColumn[k] = pSrc[k*srcStride-1];
2281      }
2282    }
2283    else
2284    {
2285      Int aboveSample = pSrc[-srcStride];
2286      for(k=0;k<blkSize;k++)
2287      {
2288        leftColumn[k] = aboveSample;
2289      }
2290    }
2291  }
2292#endif
2293
2294  // Prepare intermediate variables used in interpolation
2295  bottomLeft = leftColumn[blkSize-1];
2296  topRight   = topRow[blkSize-1];
2297  for (k=0;k<blkSize;k++)
2298  {
2299    bottomRow[k]   = bottomLeft - topRow[k];
2300    rightColumn[k] = topRight   - leftColumn[k];
2301    topRow[k]      <<= shift1D;
2302    leftColumn[k]  <<= shift1D;
2303  }
2304
2305  // Generate prediction signal
2306  for (k=0;k<blkSize;k++)
2307  {
2308    horPred = leftColumn[k] + offset2D;
2309    for (l=0;l<blkSize;l++)
2310    {
2311      horPred += rightColumn[k];
2312      topRow[l] += bottomRow[l];
2313      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
2314    }
2315  }
2316}
2317#endif
2318
2319#if LM_CHROMA
2320/** Function for deriving chroma LM intra prediction.
2321 * \param pcPattern pointer to neighbouring pixel access pattern
2322 * \param pSrc pointer to reconstructed chroma sample array
2323 * \param pPred pointer for the prediction sample array
2324 * \param uiPredStride the stride of the prediction sample array
2325 * \param uiCWidth the width of the chroma block
2326 * \param uiCHeight the height of the chroma block
2327 * \param uiChromaId boolean indication of chroma component
2328
2329 \ This function derives the prediction samples for chroma LM mode (chroma intra coding)
2330 */
2331Void TComPrediction::predLMIntraChroma( TComPattern* pcPattern, Int* piSrc, Pel* pPred, UInt uiPredStride, UInt uiCWidth, UInt uiCHeight, UInt uiChromaId )
2332{
2333  UInt uiWidth  = uiCWidth << 1;
2334  UInt uiHeight = uiCHeight << 1;
2335
2336  if (uiChromaId == 0)
2337    xGetRecPixels( pcPattern, pcPattern->getROIY(), pcPattern->getPatternLStride(), m_pLumaRecBuffer + m_iLumaRecStride + 1, m_iLumaRecStride, uiWidth, uiHeight );
2338
2339  xGetLLSPrediction( pcPattern, piSrc+uiWidth+2, uiWidth+1, pPred, uiPredStride, uiCWidth, uiCHeight, 1 ); 
2340}
2341
2342/** Function for deriving downsampled luma sample of current chroma block and its above, left causal pixel
2343 * \param pcPattern pointer to neighbouring pixel access pattern
2344 * \param pRecSrc pointer to reconstructed luma sample array
2345 * \param iRecSrcStride the stride of reconstructed luma sample array
2346 * \param pDst0 pointer to downsampled luma sample array
2347 * \param iDstStride the stride of downsampled luma sample array
2348 * \param uiWidth0 the width of the luma block
2349 * \param uiHeight0 the height of the luma block
2350
2351 \ This function derives downsampled luma sample of current chroma block and its above, left causal pixel
2352 */
2353
2354Void TComPrediction::xGetRecPixels( TComPattern* pcPattern, Pel* pRecSrc, Int iRecSrcStride, Pel* pDst0, Int iDstStride, UInt uiWidth0, UInt uiHeight0 )
2355{
2356  Pel* pSrc = pRecSrc;
2357  Pel* pDst = pDst0;
2358
2359  Int uiCWidth = uiWidth0/2;
2360  Int uiCHeight = uiHeight0/2;
2361
2362  if( pcPattern->isLeftAvailable() )
2363  {
2364    pSrc = pSrc - 2;
2365    pDst = pDst - 1;
2366
2367    uiCWidth += 1;
2368  }
2369
2370  if( pcPattern->isAboveAvailable() )
2371  {
2372    pSrc = pSrc - 2*iRecSrcStride;
2373    pDst = pDst - iDstStride;
2374
2375    uiCHeight += 1;
2376  }
2377
2378  for( Int j = 0; j < uiCHeight; j++ )
2379    {
2380      for( Int i = 0, ii = i << 1; i < uiCWidth; i++, ii = i << 1 )
2381        pDst[i] = (pSrc[ii] + pSrc[ii + iRecSrcStride]) >> 1;
2382
2383      pDst += iDstStride;
2384      pSrc += iRecSrcStride*2;
2385    } 
2386}
2387
2388/** Function for deriving the positon of first non-zero binary bit of a value
2389 * \param x input value
2390 \ This function derives the positon of first non-zero binary bit of a value
2391 */
2392Int GetMSB( UInt x )
2393{
2394#if 1
2395  Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1;
2396
2397  while( x > 1 )
2398  {
2399    bits >>= 1;
2400    y = x >> bits;
2401
2402    if( y )
2403    {
2404      x = y;
2405      iMSB += bits;
2406    }
2407  }
2408
2409  iMSB+=y;
2410
2411#else
2412
2413  Int iMSB = 0;
2414  while( x > 0 )
2415  {
2416    x >>= 1;
2417    iMSB++;
2418  }
2419#endif
2420
2421  return iMSB;
2422}
2423
2424/** Function for deriving LM intra prediction.
2425 * \param pcPattern pointer to neighbouring pixel access pattern
2426 * \param pSrc0 pointer to reconstructed chroma sample array
2427 * \param iSrcStride the stride of reconstructed chroma sample array
2428 * \param pDst0 reference to pointer for the prediction sample array
2429 * \param iDstStride the stride of the prediction sample array
2430 * \param uiWidth the width of the chroma block
2431 * \param uiHeight the height of the chroma block
2432 * \param uiExt0 line number of neiggboirng pixels for calculating LM model parameter, default value is 1
2433
2434 \ This function derives the prediction samples for chroma LM mode (chroma intra coding)
2435 */
2436Void TComPrediction::xGetLLSPrediction( TComPattern* pcPattern, Int* pSrc0, Int iSrcStride, Pel* pDst0, Int iDstStride, UInt uiWidth, UInt uiHeight, UInt uiExt0 )
2437{
2438
2439  Pel  *pDst, *pLuma;
2440  Int  *pSrc;
2441
2442  Int  iLumaStride = m_iLumaRecStride;
2443  Pel* pLuma0 = m_pLumaRecBuffer + uiExt0 * iLumaStride + uiExt0;
2444
2445  Int i, j, iCountShift = 0;
2446
2447  UInt uiExt = uiExt0;
2448
2449  // LLS parameters estimation -->
2450
2451  Int x = 0, y = 0, xx = 0, xy = 0;
2452
2453  if( pcPattern->isAboveAvailable() )
2454  {
2455    pSrc  = pSrc0  - iSrcStride;
2456    pLuma = pLuma0 - iLumaStride;
2457
2458    for( j = 0; j < uiWidth; j++ )
2459    {
2460      x += pLuma[j];
2461      y += pSrc[j];
2462      xx += pLuma[j] * pLuma[j];
2463      xy += pLuma[j] * pSrc[j];
2464    }
2465    iCountShift += g_aucConvertToBit[ uiWidth ] + 2;
2466  }
2467
2468  if( pcPattern->isLeftAvailable() )
2469  {
2470    pSrc  = pSrc0 - uiExt;
2471    pLuma = pLuma0 - uiExt;
2472
2473    for( i = 0; i < uiHeight; i++ )
2474    {
2475      x += pLuma[0];
2476      y += pSrc[0];
2477      xx += pLuma[0] * pLuma[0];
2478      xy += pLuma[0] * pSrc[0];
2479
2480      pSrc  += iSrcStride;
2481      pLuma += iLumaStride;
2482    }
2483    iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 );
2484  }
2485
2486  Int iBitdepth = ( ( g_uiBitDepth + g_uiBitIncrement ) + g_aucConvertToBit[ uiWidth ] + 3 ) * 2;
2487  Int iTempShift = Max( ( iBitdepth - 31 + 1) / 2, 0);
2488
2489  if(iTempShift > 0)
2490  {
2491    x  = ( x +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
2492    y  = ( y +  ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
2493    xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
2494    xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift;
2495    iCountShift -= iTempShift;
2496  }
2497
2498  Int a, b, iShift = 13;
2499
2500  if( iCountShift == 0 )
2501  {
2502    a = 0;
2503    b = 128 << g_uiBitIncrement;
2504    iShift = 0;
2505  }
2506  else
2507  {
2508    Int a1 = ( xy << iCountShift ) - y * x;
2509    Int a2 = ( xx << iCountShift ) - x * x;             
2510
2511    if( a2 == 0 || a1 == 0 )
2512    {
2513      a = 0;
2514      b = ( y + ( 1 << ( iCountShift - 1 ) ) )>> iCountShift;
2515      iShift = 0;
2516    }
2517    else
2518    {
2519      const Int iShiftA2 = 6;
2520      const Int iShiftA1 = 15;
2521      const Int iAccuracyShift = 15;
2522
2523      Int iScaleShiftA2 = 0;
2524      Int iScaleShiftA1 = 0;
2525      Int a1s = a1;
2526      Int a2s = a2;
2527
2528      iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1;
2529      iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; 
2530
2531      if( iScaleShiftA1 < 0 )
2532        iScaleShiftA1 = 0;
2533
2534      if( iScaleShiftA2 < 0 )
2535        iScaleShiftA2 = 0;
2536
2537      Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
2538
2539      a2s = a2 >> iScaleShiftA2;
2540
2541      a1s = a1 >> iScaleShiftA1;
2542
2543      a = a1s * m_uiaShift[ abs( a2s ) ];
2544     
2545      if( iScaleShiftA < 0 )
2546        a = a << -iScaleShiftA;
2547      else
2548        a = a >> iScaleShiftA;
2549
2550      if( a > ( 1 << 15 ) - 1 )
2551        a = ( 1 << 15 ) - 1;
2552      else if( a < -( 1 << 15 ) )
2553        a = -( 1 << 15 );
2554
2555      b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
2556    }
2557  }   
2558
2559  // <-- end of LLS parameters estimation
2560
2561  // get prediction -->
2562  uiExt = uiExt0;
2563  pLuma = pLuma0;
2564  pDst = pDst0;
2565
2566  for( i = 0; i < uiHeight; i++ )
2567  {
2568    for( j = 0; j < uiWidth; j++ )
2569      pDst[j] = Clip( ( ( a * pLuma[j] ) >> iShift ) + b );
2570
2571    pDst  += iDstStride;
2572    pLuma += iLumaStride;
2573  }
2574  // <-- end of get prediction
2575
2576}
2577#endif
2578
2579#if MN_DC_PRED_FILTER
2580/** Function for filtering intra DC predictor.
2581 * \param pSrc pointer to reconstructed sample array
2582 * \param iSrcStride the stride of the reconstructed sample array
2583 * \param rpDst reference to pointer for the prediction sample array
2584 * \param iDstStride the stride of the prediction sample array
2585 * \param iWidth the width of the block
2586 * \param iHeight the height of the block
2587 *
2588 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
2589 */
2590Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
2591{
2592  Pel* pDst = rpDst;
2593  Int x, y, iDstStride2, iSrcStride2;
2594  Int iIntraSizeIdx = g_aucConvertToBit[ iWidth ] + 1;
2595  static const UChar g_aucDCPredFilter[7] = { 0, 3, 2, 1, 0, 0, 0};
2596
2597  switch (g_aucDCPredFilter[iIntraSizeIdx])
2598  {
2599  case 0:
2600    {}
2601    break;
2602  case 1:
2603    {
2604      // boundary pixels processing
2605      pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 6 * pDst[0] + 4) >> 3);
2606
2607      for ( x = 1; x < iWidth; x++ )
2608        pDst[x] = (Pel)((pSrc[x - iSrcStride] + 7 * pDst[x] + 4) >> 3);
2609
2610      for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
2611        pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 7 * pDst[iDstStride2] + 4) >> 3);
2612    }
2613    break;
2614  case 2:
2615    {
2616      // boundary pixels processing
2617      pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
2618
2619      for ( x = 1; x < iWidth; x++ )
2620        pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2);
2621
2622      for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
2623        pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
2624    }
2625    break;
2626  case 3:
2627    {
2628      // boundary pixels processing
2629      pDst[0] = (Pel)((3 * (pSrc[-iSrcStride] + pSrc[-1]) + 2 * pDst[0] + 4) >> 3);
2630
2631      for ( x = 1; x < iWidth; x++ )
2632        pDst[x] = (Pel)((3 * pSrc[x - iSrcStride] + 5 * pDst[x] + 4) >> 3);
2633
2634      for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
2635        pDst[iDstStride2] = (Pel)((3 * pSrc[iSrcStride2] + 5 * pDst[iDstStride2] + 4) >> 3);
2636    }
2637    break;
2638  }
2639
2640  return;
2641}
2642#endif
2643
2644#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
2645TComWedgeDist::TComWedgeDist()
2646{
2647  init();
2648}
2649
2650TComWedgeDist::~TComWedgeDist()
2651{
2652}
2653
2654Void TComWedgeDist::init()
2655{
2656  //   m_afpDistortFunc[0]  = NULL;                  // for DF_DEFAULT
2657
2658  //   m_afpDistortFunc[8]  = TComRdCost::xGetSAD;
2659  m_afpDistortFunc[0]  = TComWedgeDist::xGetSAD4;
2660  m_afpDistortFunc[1] = TComWedgeDist::xGetSAD8;
2661  m_afpDistortFunc[2] = TComWedgeDist::xGetSAD16;
2662  m_afpDistortFunc[3] = TComWedgeDist::xGetSAD32;
2663
2664  m_afpDistortFunc[4]  = TComWedgeDist::xGetSSE4;
2665  m_afpDistortFunc[5]  = TComWedgeDist::xGetSSE8;
2666  m_afpDistortFunc[6]  = TComWedgeDist::xGetSSE16;
2667  m_afpDistortFunc[7]  = TComWedgeDist::xGetSSE32;
2668
2669  //   m_afpDistortFunc[13] = TComRdCost::xGetSAD64;
2670#ifdef ROUNDING_CONTROL_BIPRED
2671  //   m_afpDistortFuncRnd[0]  = NULL;
2672  //   m_afpDistortFuncRnd[8]  = TComRdCost::xGetSAD;
2673  m_afpDistortFuncRnd[9]  = TComRdCost::xGetSAD4;
2674  m_afpDistortFuncRnd[10] = TComRdCost::xGetSAD8;
2675  m_afpDistortFuncRnd[11] = TComRdCost::xGetSAD16;
2676  m_afpDistortFuncRnd[12] = TComRdCost::xGetSAD32;
2677  //   m_afpDistortFuncRnd[13] = TComRdCost::xGetSAD64;
2678#endif
2679}
2680
2681UInt TComWedgeDist::xGetSAD4( DistParam* pcDtParam )
2682{
2683  Pel* piOrg   = pcDtParam->pOrg;
2684  Pel* piCur   = pcDtParam->pCur;
2685  Int  iRows   = pcDtParam->iRows;
2686  Int  iSubShift  = pcDtParam->iSubShift;
2687  Int  iSubStep   = ( 1 << iSubShift );
2688  Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
2689  Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
2690
2691  UInt uiSum = 0;
2692
2693  for( ; iRows != 0; iRows-=iSubStep )
2694  {
2695    uiSum += abs( piOrg[0] - piCur[0] );
2696    uiSum += abs( piOrg[1] - piCur[1] );
2697    uiSum += abs( piOrg[2] - piCur[2] );
2698    uiSum += abs( piOrg[3] - piCur[3] );
2699
2700    piOrg += iStrideOrg;
2701    piCur += iStrideCur;
2702  }
2703
2704  uiSum <<= iSubShift;
2705  return ( uiSum >> g_uiBitIncrement );
2706}
2707
2708UInt TComWedgeDist::xGetSAD8( DistParam* pcDtParam )
2709{
2710  Pel* piOrg      = pcDtParam->pOrg;
2711  Pel* piCur      = pcDtParam->pCur;
2712  Int  iRows      = pcDtParam->iRows;
2713  Int  iSubShift  = pcDtParam->iSubShift;
2714  Int  iSubStep   = ( 1 << iSubShift );
2715  Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
2716  Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
2717
2718  UInt uiSum = 0;
2719
2720  for( ; iRows != 0; iRows-=iSubStep )
2721  {
2722    uiSum += abs( piOrg[0] - piCur[0] );
2723    uiSum += abs( piOrg[1] - piCur[1] );
2724    uiSum += abs( piOrg[2] - piCur[2] );
2725    uiSum += abs( piOrg[3] - piCur[3] );
2726    uiSum += abs( piOrg[4] - piCur[4] );
2727    uiSum += abs( piOrg[5] - piCur[5] );
2728    uiSum += abs( piOrg[6] - piCur[6] );
2729    uiSum += abs( piOrg[7] - piCur[7] );
2730
2731    piOrg += iStrideOrg;
2732    piCur += iStrideCur;
2733  }
2734
2735  uiSum <<= iSubShift;
2736  return ( uiSum >> g_uiBitIncrement );
2737}
2738
2739UInt TComWedgeDist::xGetSAD16( DistParam* pcDtParam )
2740{
2741  Pel* piOrg   = pcDtParam->pOrg;
2742  Pel* piCur   = pcDtParam->pCur;
2743  Int  iRows   = pcDtParam->iRows;
2744  Int  iSubShift  = pcDtParam->iSubShift;
2745  Int  iSubStep   = ( 1 << iSubShift );
2746  Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
2747  Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
2748
2749  UInt uiSum = 0;
2750
2751  for( ; iRows != 0; iRows-=iSubStep )
2752  {
2753    uiSum += abs( piOrg[0] - piCur[0] );
2754    uiSum += abs( piOrg[1] - piCur[1] );
2755    uiSum += abs( piOrg[2] - piCur[2] );
2756    uiSum += abs( piOrg[3] - piCur[3] );
2757    uiSum += abs( piOrg[4] - piCur[4] );
2758    uiSum += abs( piOrg[5] - piCur[5] );
2759    uiSum += abs( piOrg[6] - piCur[6] );
2760    uiSum += abs( piOrg[7] - piCur[7] );
2761    uiSum += abs( piOrg[8] - piCur[8] );
2762    uiSum += abs( piOrg[9] - piCur[9] );
2763    uiSum += abs( piOrg[10] - piCur[10] );
2764    uiSum += abs( piOrg[11] - piCur[11] );
2765    uiSum += abs( piOrg[12] - piCur[12] );
2766    uiSum += abs( piOrg[13] - piCur[13] );
2767    uiSum += abs( piOrg[14] - piCur[14] );
2768    uiSum += abs( piOrg[15] - piCur[15] );
2769
2770    piOrg += iStrideOrg;
2771    piCur += iStrideCur;
2772  }
2773
2774  uiSum <<= iSubShift;
2775  return ( uiSum >> g_uiBitIncrement );
2776}
2777
2778UInt TComWedgeDist::xGetSAD32( DistParam* pcDtParam )
2779{
2780  Pel* piOrg   = pcDtParam->pOrg;
2781  Pel* piCur   = pcDtParam->pCur;
2782  Int  iRows   = pcDtParam->iRows;
2783  Int  iSubShift  = pcDtParam->iSubShift;
2784  Int  iSubStep   = ( 1 << iSubShift );
2785  Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
2786  Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
2787
2788  UInt uiSum = 0;
2789
2790  for( ; iRows != 0; iRows-=iSubStep )
2791  {
2792    uiSum += abs( piOrg[0] - piCur[0] );
2793    uiSum += abs( piOrg[1] - piCur[1] );
2794    uiSum += abs( piOrg[2] - piCur[2] );
2795    uiSum += abs( piOrg[3] - piCur[3] );
2796    uiSum += abs( piOrg[4] - piCur[4] );
2797    uiSum += abs( piOrg[5] - piCur[5] );
2798    uiSum += abs( piOrg[6] - piCur[6] );
2799    uiSum += abs( piOrg[7] - piCur[7] );
2800    uiSum += abs( piOrg[8] - piCur[8] );
2801    uiSum += abs( piOrg[9] - piCur[9] );
2802    uiSum += abs( piOrg[10] - piCur[10] );
2803    uiSum += abs( piOrg[11] - piCur[11] );
2804    uiSum += abs( piOrg[12] - piCur[12] );
2805    uiSum += abs( piOrg[13] - piCur[13] );
2806    uiSum += abs( piOrg[14] - piCur[14] );
2807    uiSum += abs( piOrg[15] - piCur[15] );
2808    uiSum += abs( piOrg[16] - piCur[16] );
2809    uiSum += abs( piOrg[17] - piCur[17] );
2810    uiSum += abs( piOrg[18] - piCur[18] );
2811    uiSum += abs( piOrg[19] - piCur[19] );
2812    uiSum += abs( piOrg[20] - piCur[20] );
2813    uiSum += abs( piOrg[21] - piCur[21] );
2814    uiSum += abs( piOrg[22] - piCur[22] );
2815    uiSum += abs( piOrg[23] - piCur[23] );
2816    uiSum += abs( piOrg[24] - piCur[24] );
2817    uiSum += abs( piOrg[25] - piCur[25] );
2818    uiSum += abs( piOrg[26] - piCur[26] );
2819    uiSum += abs( piOrg[27] - piCur[27] );
2820    uiSum += abs( piOrg[28] - piCur[28] );
2821    uiSum += abs( piOrg[29] - piCur[29] );
2822    uiSum += abs( piOrg[30] - piCur[30] );
2823    uiSum += abs( piOrg[31] - piCur[31] );
2824
2825    piOrg += iStrideOrg;
2826    piCur += iStrideCur;
2827  }
2828
2829  uiSum <<= iSubShift;
2830  return ( uiSum >> g_uiBitIncrement );
2831}
2832
2833UInt TComWedgeDist::xGetSSE4( DistParam* pcDtParam )
2834{
2835  Pel* piOrg   = pcDtParam->pOrg;
2836  Pel* piCur   = pcDtParam->pCur;
2837  Int  iRows   = pcDtParam->iRows;
2838  Int  iStrideOrg = pcDtParam->iStrideOrg;
2839  Int  iStrideCur = pcDtParam->iStrideCur;
2840
2841  UInt uiSum = 0;
2842  UInt uiShift = g_uiBitIncrement<<1;
2843
2844  Int  iTemp;
2845
2846  for( ; iRows != 0; iRows-- )
2847  {
2848
2849    iTemp = piOrg[0] - piCur[0]; uiSum += ( iTemp * iTemp ) >> uiShift;
2850    iTemp = piOrg[1] - piCur[1]; uiSum += ( iTemp * iTemp ) >> uiShift;
2851    iTemp = piOrg[2] - piCur[2]; uiSum += ( iTemp * iTemp ) >> uiShift;
2852    iTemp = piOrg[3] - piCur[3]; uiSum += ( iTemp * iTemp ) >> uiShift;
2853
2854    piOrg += iStrideOrg;
2855    piCur += iStrideCur;
2856  }
2857
2858  return ( uiSum );
2859}
2860
2861UInt TComWedgeDist::xGetSSE8( DistParam* pcDtParam )
2862{
2863  Pel* piOrg   = pcDtParam->pOrg;
2864  Pel* piCur   = pcDtParam->pCur;
2865  Int  iRows   = pcDtParam->iRows;
2866  Int  iStrideOrg = pcDtParam->iStrideOrg;
2867  Int  iStrideCur = pcDtParam->iStrideCur;
2868
2869  UInt uiSum = 0;
2870  UInt uiShift = g_uiBitIncrement<<1;
2871
2872  Int  iTemp;
2873
2874  for( ; iRows != 0; iRows-- )
2875  {
2876    iTemp = piOrg[0] - piCur[0]; uiSum += ( iTemp * iTemp ) >> uiShift;
2877    iTemp = piOrg[1] - piCur[1]; uiSum += ( iTemp * iTemp ) >> uiShift;
2878    iTemp = piOrg[2] - piCur[2]; uiSum += ( iTemp * iTemp ) >> uiShift;
2879    iTemp = piOrg[3] - piCur[3]; uiSum += ( iTemp * iTemp ) >> uiShift;
2880    iTemp = piOrg[4] - piCur[4]; uiSum += ( iTemp * iTemp ) >> uiShift;
2881    iTemp = piOrg[5] - piCur[5]; uiSum += ( iTemp * iTemp ) >> uiShift;
2882    iTemp = piOrg[6] - piCur[6]; uiSum += ( iTemp * iTemp ) >> uiShift;
2883    iTemp = piOrg[7] - piCur[7]; uiSum += ( iTemp * iTemp ) >> uiShift;
2884
2885    piOrg += iStrideOrg;
2886    piCur += iStrideCur;
2887  }
2888
2889  return ( uiSum );
2890}
2891
2892UInt TComWedgeDist::xGetSSE16( DistParam* pcDtParam )
2893{
2894  Pel* piOrg   = pcDtParam->pOrg;
2895  Pel* piCur   = pcDtParam->pCur;
2896  Int  iRows   = pcDtParam->iRows;
2897  Int  iStrideOrg = pcDtParam->iStrideOrg;
2898  Int  iStrideCur = pcDtParam->iStrideCur;
2899
2900  UInt uiSum = 0;
2901  UInt uiShift = g_uiBitIncrement<<1;
2902
2903  Int  iTemp;
2904
2905  for( ; iRows != 0; iRows-- )
2906  {
2907
2908    iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift;
2909    iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift;
2910    iTemp = piOrg[ 2] - piCur[ 2]; uiSum += ( iTemp * iTemp ) >> uiShift;
2911    iTemp = piOrg[ 3] - piCur[ 3]; uiSum += ( iTemp * iTemp ) >> uiShift;
2912    iTemp = piOrg[ 4] - piCur[ 4]; uiSum += ( iTemp * iTemp ) >> uiShift;
2913    iTemp = piOrg[ 5] - piCur[ 5]; uiSum += ( iTemp * iTemp ) >> uiShift;
2914    iTemp = piOrg[ 6] - piCur[ 6]; uiSum += ( iTemp * iTemp ) >> uiShift;
2915    iTemp = piOrg[ 7] - piCur[ 7]; uiSum += ( iTemp * iTemp ) >> uiShift;
2916    iTemp = piOrg[ 8] - piCur[ 8]; uiSum += ( iTemp * iTemp ) >> uiShift;
2917    iTemp = piOrg[ 9] - piCur[ 9]; uiSum += ( iTemp * iTemp ) >> uiShift;
2918    iTemp = piOrg[10] - piCur[10]; uiSum += ( iTemp * iTemp ) >> uiShift;
2919    iTemp = piOrg[11] - piCur[11]; uiSum += ( iTemp * iTemp ) >> uiShift;
2920    iTemp = piOrg[12] - piCur[12]; uiSum += ( iTemp * iTemp ) >> uiShift;
2921    iTemp = piOrg[13] - piCur[13]; uiSum += ( iTemp * iTemp ) >> uiShift;
2922    iTemp = piOrg[14] - piCur[14]; uiSum += ( iTemp * iTemp ) >> uiShift;
2923    iTemp = piOrg[15] - piCur[15]; uiSum += ( iTemp * iTemp ) >> uiShift;
2924
2925    piOrg += iStrideOrg;
2926    piCur += iStrideCur;
2927  }
2928
2929  return ( uiSum );
2930}
2931
2932UInt TComWedgeDist::xGetSSE32( DistParam* pcDtParam )
2933{
2934  Pel* piOrg   = pcDtParam->pOrg;
2935  Pel* piCur   = pcDtParam->pCur;
2936  Int  iRows   = pcDtParam->iRows;
2937  Int  iStrideOrg = pcDtParam->iStrideOrg;
2938  Int  iStrideCur = pcDtParam->iStrideCur;
2939
2940  UInt uiSum = 0;
2941  UInt uiShift = g_uiBitIncrement<<1;
2942  Int  iTemp;
2943
2944  for( ; iRows != 0; iRows-- )
2945  {
2946
2947    iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift;
2948    iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift;
2949    iTemp = piOrg[ 2] - piCur[ 2]; uiSum += ( iTemp * iTemp ) >> uiShift;
2950    iTemp = piOrg[ 3] - piCur[ 3]; uiSum += ( iTemp * iTemp ) >> uiShift;
2951    iTemp = piOrg[ 4] - piCur[ 4]; uiSum += ( iTemp * iTemp ) >> uiShift;
2952    iTemp = piOrg[ 5] - piCur[ 5]; uiSum += ( iTemp * iTemp ) >> uiShift;
2953    iTemp = piOrg[ 6] - piCur[ 6]; uiSum += ( iTemp * iTemp ) >> uiShift;
2954    iTemp = piOrg[ 7] - piCur[ 7]; uiSum += ( iTemp * iTemp ) >> uiShift;
2955    iTemp = piOrg[ 8] - piCur[ 8]; uiSum += ( iTemp * iTemp ) >> uiShift;
2956    iTemp = piOrg[ 9] - piCur[ 9]; uiSum += ( iTemp * iTemp ) >> uiShift;
2957    iTemp = piOrg[10] - piCur[10]; uiSum += ( iTemp * iTemp ) >> uiShift;
2958    iTemp = piOrg[11] - piCur[11]; uiSum += ( iTemp * iTemp ) >> uiShift;
2959    iTemp = piOrg[12] - piCur[12]; uiSum += ( iTemp * iTemp ) >> uiShift;
2960    iTemp = piOrg[13] - piCur[13]; uiSum += ( iTemp * iTemp ) >> uiShift;
2961    iTemp = piOrg[14] - piCur[14]; uiSum += ( iTemp * iTemp ) >> uiShift;
2962    iTemp = piOrg[15] - piCur[15]; uiSum += ( iTemp * iTemp ) >> uiShift;
2963    iTemp = piOrg[16] - piCur[16]; uiSum += ( iTemp * iTemp ) >> uiShift;
2964    iTemp = piOrg[17] - piCur[17]; uiSum += ( iTemp * iTemp ) >> uiShift;
2965    iTemp = piOrg[18] - piCur[18]; uiSum += ( iTemp * iTemp ) >> uiShift;
2966    iTemp = piOrg[19] - piCur[19]; uiSum += ( iTemp * iTemp ) >> uiShift;
2967    iTemp = piOrg[20] - piCur[20]; uiSum += ( iTemp * iTemp ) >> uiShift;
2968    iTemp = piOrg[21] - piCur[21]; uiSum += ( iTemp * iTemp ) >> uiShift;
2969    iTemp = piOrg[22] - piCur[22]; uiSum += ( iTemp * iTemp ) >> uiShift;
2970    iTemp = piOrg[23] - piCur[23]; uiSum += ( iTemp * iTemp ) >> uiShift;
2971    iTemp = piOrg[24] - piCur[24]; uiSum += ( iTemp * iTemp ) >> uiShift;
2972    iTemp = piOrg[25] - piCur[25]; uiSum += ( iTemp * iTemp ) >> uiShift;
2973    iTemp = piOrg[26] - piCur[26]; uiSum += ( iTemp * iTemp ) >> uiShift;
2974    iTemp = piOrg[27] - piCur[27]; uiSum += ( iTemp * iTemp ) >> uiShift;
2975    iTemp = piOrg[28] - piCur[28]; uiSum += ( iTemp * iTemp ) >> uiShift;
2976    iTemp = piOrg[29] - piCur[29]; uiSum += ( iTemp * iTemp ) >> uiShift;
2977    iTemp = piOrg[30] - piCur[30]; uiSum += ( iTemp * iTemp ) >> uiShift;
2978    iTemp = piOrg[31] - piCur[31]; uiSum += ( iTemp * iTemp ) >> uiShift;
2979
2980    piOrg += iStrideOrg;
2981    piCur += iStrideCur;
2982  }
2983
2984  return ( uiSum );
2985}
2986
2987Void TComWedgeDist::setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, WedgeDist eWDist, DistParam& rcDistParam )
2988{
2989  // set Block Width / Height
2990  rcDistParam.iCols    = uiBlkWidth;
2991  rcDistParam.iRows    = uiBlkHeight;
2992  rcDistParam.DistFunc = m_afpDistortFunc[eWDist + g_aucConvertToBit[ rcDistParam.iCols ] ];
2993
2994  // initialize
2995  rcDistParam.iSubShift  = 0;
2996}
2997
2998UInt TComWedgeDist::getDistPart( Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, WedgeDist eWDist )
2999{
3000  DistParam cDtParam;
3001  setDistParam( uiBlkWidth, uiBlkHeight, eWDist, cDtParam );
3002  cDtParam.pOrg       = piOrg;
3003  cDtParam.pCur       = piCur;
3004  cDtParam.iStrideOrg = iOrgStride;
3005  cDtParam.iStrideCur = iCurStride;
3006#ifdef DCM_RDCOST_TEMP_FIX //Temporary fix since DistParam is lacking a constructor and the variable iStep is not initialized
3007  cDtParam.iStep      = 1;
3008#endif
3009  return cDtParam.DistFunc( &cDtParam );
3010}
3011#endif
Note: See TracBrowser for help on using the repository browser.