source: 3DVCSoftware/branches/HTM-6.2-dev3-RWTH/source/Lib/TLibCommon/TComPrediction.cpp @ 632

Last change on this file since 632 was 379, checked in by zhang, 12 years ago

JCT3V-D0183 (DC predictor)

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