source: 3DVCSoftware/branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPrediction.cpp @ 1364

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