source: 3DVCSoftware/branches/HTM-6.2-dev1-MediaTek/source/Lib/TLibCommon/TComPrediction.cpp @ 872

Last change on this file since 872 was 355, checked in by zhang, 12 years ago

JCT3V-D0191 (BVSP clean-ups)

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