source: 3DVCSoftware/branches/HTM-5.1-dev1-LG/source/Lib/TLibCommon/TComPrediction.cpp @ 251

Last change on this file since 251 was 251, checked in by lg, 12 years ago

Integration of JCT3V-C0044

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