source: 3DVCSoftware/branches/HTM-6.2-dev2-Mediatek/source/Lib/TLibCommon/TComPrediction.cpp @ 1404

Last change on this file since 1404 was 390, checked in by mediatek-htm, 12 years ago

ARP Warning Fix, the related MACRO is "QC_ARP_WARNING_FIX"

by Yu-Lin Chang (yulin.chang@…)

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