source: 3DVCSoftware/branches/HTM-6.0-Mediatek/source/Lib/TLibCommon/TComPrediction.cpp @ 303

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

Added FCO_FIX, FCO_FIX_SPS_CHANGE, and FCO_DVP_REFINE_C0132_C0170 macros to support FCO.
The new macros are default disabled in CTC.

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