source: 3DVCSoftware/branches/HTM-14.0-MV-draft-3/source/Lib/TLibCommon/TComPrediction.cpp

Last change on this file was 1191, checked in by tech, 10 years ago

Removed 3D-HEVC.

  • Property svn:eol-style set to native
File size: 25.2 KB
RevLine 
[5]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
[56]4 * granted under this license. 
[5]5 *
[1179]6* Copyright (c) 2010-2015, ITU/ISO/IEC
[5]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.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]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 */
[2]33
34/** \file     TComPrediction.cpp
35    \brief    prediction class
36*/
37
38#include <memory.h>
39#include "TComPrediction.h"
40
[56]41//! \ingroup TLibCommon
42//! \{
43
[2]44// ====================================================================================================================
45// Constructor / destructor / initialize
46// ====================================================================================================================
47
48TComPrediction::TComPrediction()
49: m_pLumaRecBuffer(0)
[608]50, m_iLumaRecStride(0)
[2]51{
52  m_piYuvExt = NULL;
53}
54
55TComPrediction::~TComPrediction()
56{
[608]57
[2]58  delete[] m_piYuvExt;
59
60  m_acYuvPred[0].destroy();
61  m_acYuvPred[1].destroy();
62
63  m_cYuvPredTemp.destroy();
[608]64
[2]65  if( m_pLumaRecBuffer )
[56]66  {
67    delete [] m_pLumaRecBuffer;
68  }
69 
70  Int i, j;
71  for (i = 0; i < 4; i++)
72  {
73    for (j = 0; j < 4; j++)
74    {
75      m_filteredBlock[i][j].destroy();
76    }
77    m_filteredBlockTmp[i].destroy();
78  }
[2]79}
80
81Void TComPrediction::initTempBuff()
82{
83  if( m_piYuvExt == NULL )
84  {
[608]85    Int extWidth  = MAX_CU_SIZE + 16; 
86    Int extHeight = MAX_CU_SIZE + 1;
[56]87    Int i, j;
88    for (i = 0; i < 4; i++)
89    {
90      m_filteredBlockTmp[i].create(extWidth, extHeight + 7);
91      for (j = 0; j < 4; j++)
92      {
93        m_filteredBlock[i][j].create(extWidth, extHeight);
94      }
95    }
[608]96    m_iYuvExtHeight  = ((MAX_CU_SIZE + 2) << 4);
97    m_iYuvExtStride = ((MAX_CU_SIZE  + 8) << 4);
[2]98    m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
99
100    // new structure
[608]101    m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE );
102    m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE );
[2]103
[608]104    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE );
[2]105  }
106
[608]107  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
108  {
109    m_iLumaRecStride =  (MAX_CU_SIZE>>1) + 1;
110    if (!m_pLumaRecBuffer)
111    {
112      m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ];
113    }
114  }
[2]115}
116
117// ====================================================================================================================
118// Public member functions
119// ====================================================================================================================
120
121// Function for calculating DC value of the reference samples used in Intra prediction
122Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft )
123{
[608]124  assert(iWidth > 0 && iHeight > 0);
[2]125  Int iInd, iSum = 0;
126  Pel pDcVal;
127
128  if (bAbove)
129  {
130    for (iInd = 0;iInd < iWidth;iInd++)
[56]131    {
[2]132      iSum += pSrc[iInd-iSrcStride];
[56]133    }
[2]134  }
135  if (bLeft)
136  {
137    for (iInd = 0;iInd < iHeight;iInd++)
[56]138    {
[2]139      iSum += pSrc[iInd*iSrcStride-1];
[56]140    }
[2]141  }
142
143  if (bAbove && bLeft)
[56]144  {
[2]145    pDcVal = (iSum + iWidth) / (iWidth + iHeight);
[56]146  }
[2]147  else if (bAbove)
[56]148  {
[2]149    pDcVal = (iSum + iWidth/2) / iWidth;
[56]150  }
[2]151  else if (bLeft)
[56]152  {
[2]153    pDcVal = (iSum + iHeight/2) / iHeight;
[56]154  }
[2]155  else
[56]156  {
[2]157    pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available
[56]158  }
159 
[2]160  return pDcVal;
161}
162
163// Function for deriving the angular Intra predictions
164
165/** Function for deriving the simplified angular intra predictions.
166 * \param pSrc pointer to reconstructed sample array
167 * \param srcStride the stride of the reconstructed sample array
168 * \param rpDst reference to pointer for the prediction sample array
169 * \param dstStride the stride of the prediction sample array
170 * \param width the width of the block
171 * \param height the height of the block
172 * \param dirMode the intra prediction mode index
173 * \param blkAboveAvailable boolean indication if the block above is available
174 * \param blkLeftAvailable boolean indication if the block to the left is available
175 *
176 * This function derives the prediction samples for the angular mode based on the prediction direction indicated by
177 * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and
178 * the reference row above the block in the case of vertical prediction or displacement of the rightmost column
179 * of the block and reference column left from the block in the case of the horizontal prediction. The displacement
180 * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples,
181 * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken
182 * from the extended main reference.
183 */
[608]184Void TComPrediction::xPredIntraAng(Int bitDepth, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter )
[2]185{
186  Int k,l;
187  Int blkSize        = width;
188  Pel* pDst          = rpDst;
189
190  // Map the mode index to main prediction direction and angle
[56]191  assert( dirMode > 0 ); //no planar
192  Bool modeDC        = dirMode < 2;
193  Bool modeHor       = !modeDC && (dirMode < 18);
194  Bool modeVer       = !modeDC && !modeHor;
195  Int intraPredAngle = modeVer ? (Int)dirMode - VER_IDX : modeHor ? -((Int)dirMode - HOR_IDX) : 0;
[2]196  Int absAng         = abs(intraPredAngle);
197  Int signAng        = intraPredAngle < 0 ? -1 : 1;
198
199  // Set bitshifts and scale the angle parameter to block size
200  Int angTable[9]    = {0,    2,    5,   9,  13,  17,  21,  26,  32};
201  Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
202  Int invAngle       = invAngTable[absAng];
203  absAng             = angTable[absAng];
204  intraPredAngle     = signAng * absAng;
205
206  // Do the DC prediction
207  if (modeDC)
208  {
209    Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable);
210
211    for (k=0;k<blkSize;k++)
212    {
213      for (l=0;l<blkSize;l++)
214      {
215        pDst[k*dstStride+l] = dcval;
216      }
217    }
218  }
219
220  // Do angular predictions
221  else
222  {
223    Pel* refMain;
224    Pel* refSide;
225    Pel  refAbove[2*MAX_CU_SIZE+1];
226    Pel  refLeft[2*MAX_CU_SIZE+1];
227
228    // Initialise the Main and Left reference array.
229    if (intraPredAngle < 0)
230    {
231      for (k=0;k<blkSize+1;k++)
232      {
233        refAbove[k+blkSize-1] = pSrc[k-srcStride-1];
234      }
235      for (k=0;k<blkSize+1;k++)
236      {
237        refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1];
238      }
239      refMain = (modeVer ? refAbove : refLeft) + (blkSize-1);
240      refSide = (modeVer ? refLeft : refAbove) + (blkSize-1);
241
242      // Extend the Main reference to the left.
243      Int invAngleSum    = 128;       // rounding for (shift by 8)
244      for (k=-1; k>blkSize*intraPredAngle>>5; k--)
245      {
246        invAngleSum += invAngle;
247        refMain[k] = refSide[invAngleSum>>8];
248      }
249    }
250    else
251    {
252      for (k=0;k<2*blkSize+1;k++)
253      {
254        refAbove[k] = pSrc[k-srcStride-1];
255      }
256      for (k=0;k<2*blkSize+1;k++)
257      {
258        refLeft[k] = pSrc[(k-1)*srcStride-1];
259      }
260      refMain = modeVer ? refAbove : refLeft;
[56]261      refSide = modeVer ? refLeft  : refAbove;
[2]262    }
263
264    if (intraPredAngle == 0)
265    {
266      for (k=0;k<blkSize;k++)
267      {
268        for (l=0;l<blkSize;l++)
269        {
270          pDst[k*dstStride+l] = refMain[l+1];
271        }
272      }
[56]273
274      if ( bFilter )
275      {
276        for (k=0;k<blkSize;k++)
277        {
[608]278          pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) );
[56]279        }
280      }
[2]281    }
282    else
283    {
284      Int deltaPos=0;
285      Int deltaInt;
286      Int deltaFract;
287      Int refMainIndex;
288
289      for (k=0;k<blkSize;k++)
290      {
291        deltaPos += intraPredAngle;
292        deltaInt   = deltaPos >> 5;
293        deltaFract = deltaPos & (32 - 1);
294
295        if (deltaFract)
296        {
297          // Do linear filtering
298          for (l=0;l<blkSize;l++)
299          {
300            refMainIndex        = l+deltaInt+1;
301            pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 );
302          }
303        }
304        else
305        {
306          // Just copy the integer samples
307          for (l=0;l<blkSize;l++)
308          {
309            pDst[k*dstStride+l] = refMain[l+deltaInt+1];
310          }
311        }
312      }
313    }
314
315    // Flip the block if this is the horizontal mode
316    if (modeHor)
317    {
318      Pel  tmp;
319      for (k=0;k<blkSize-1;k++)
320      {
321        for (l=k+1;l<blkSize;l++)
322        {
323          tmp                 = pDst[k*dstStride+l];
324          pDst[k*dstStride+l] = pDst[l*dstStride+k];
325          pDst[l*dstStride+k] = tmp;
326        }
327      }
328    }
329  }
330}
331
[608]332Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
[2]333{
334  Pel *pDst = piPred;
335  Int *ptrSrc;
336
[56]337  assert( g_aucConvertToBit[ iWidth ] >= 0 ); //   4x  4
338  assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128
[2]339  assert( iWidth == iHeight  );
340
[56]341  ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
342
343  // get starting pixel in block
344  Int sw = 2 * iWidth + 1;
345
346  // Create the prediction
347  if ( uiDirMode == PLANAR_IDX )
348  {
349    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
350  }
351  else
352  {
[608]353    if ( (iWidth > 16) || (iHeight > 16) )
[56]354    {
[608]355      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
[56]356    }
[608]357    else
358    {
359      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );
360
361      if( (uiDirMode == DC_IDX ) && bAbove && bLeft )
362      {
363        xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);
364      }
365    }
[56]366  }
367}
368
369// Angular chroma
[608]370Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft )
[56]371{
372  Pel *pDst = piPred;
373  Int *ptrSrc = piSrc;
374
[2]375  // get starting pixel in block
[56]376  Int sw = 2 * iWidth + 1;
[2]377
378  if ( uiDirMode == PLANAR_IDX )
379  {
380    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
[56]381  }
382  else
383  {
384    // Create the prediction
[608]385    xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
[56]386  }
387}
388
389
[608]390/** Function for checking identical motion.
391 * \param TComDataCU* pcCU
392 * \param UInt PartAddr
393 */
394Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr )
[100]395{
[608]396  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() )
[100]397  {
[608]398    if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0)
[100]399    {
[608]400      Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
401      Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
402      if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
[100]403      {
[608]404        return true;
[100]405      }
406    }
407  }
[608]408  return false;
[100]409}
410
[1084]411
[608]412
[56]413Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
414{
415  Int         iWidth;
416  Int         iHeight;
417  UInt        uiPartAddr;
418
419  if ( iPartIdx >= 0 )
420  {
421    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
[608]422      if ( eRefPicList != REF_PIC_LIST_X )
[56]423      {
[608]424        if( pcCU->getSlice()->getPPS()->getUseWP())
425        {
426          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
427        }
428        else
429        {
430          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
431        }
432        if ( pcCU->getSlice()->getPPS()->getUseWP() )
433        {
434          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
435        }
[56]436      }
437      else
438      {
[724]439          if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
440          {
441            xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
442          }
443          else
444          {
445            xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
446          }
[56]447      }
[2]448    return;
449  }
[56]450
[964]451  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ )
[56]452  {
453    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
454
[608]455      if ( eRefPicList != REF_PIC_LIST_X )
[56]456      {
[608]457        if( pcCU->getSlice()->getPPS()->getUseWP())
458        {
459          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
460        }
461        else
462        {
463          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
464        }
465        if ( pcCU->getSlice()->getPPS()->getUseWP() )
466        {
467          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
468        }
[56]469      }
[608]470      else
[56]471      {
[608]472        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
473        {
474          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
475        }
476        else
477        {
478          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
479        }
[56]480      }
481  }
482  return;
483}
[2]484
[608]485Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
[296]486{
[608]487  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
488  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
489  pcCU->clipMv(cMv);
[1179]490#if SONY_MV_V_CONST_C0078
491  pcCU->checkMV_V(cMv, eRefPicList, iRefIdx );
492#endif
[773]493      xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
494      xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
[443]495}
496
[833]497
498
[608]499Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
[2]500{
[56]501  TComYuv* pcMbYuv;
502  Int      iRefIdx[2] = {-1, -1};
503
504  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
505  {
506    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
507    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
508
509    if ( iRefIdx[iRefList] < 0 )
510    {
511      continue;
512    }
513
514    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
515
516    pcMbYuv = &m_acYuvPred[iRefList];
517    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
518    {
[608]519      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
[56]520    }
521    else
522    {
[608]523      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) || 
524           ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
[56]525      {
[608]526        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
[56]527      }
528      else
529      {
[608]530        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
[56]531      }
532    }
533  }
[608]534
535  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE  )
[56]536  {
537    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
[608]538  } 
[313]539  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
540  {
[608]541    xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); 
[313]542  }
[56]543  else
544  {
[608]545    xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
[56]546  }
[2]547}
548
[296]549
[56]550/**
551 * \brief Generate motion-compensated luma block
552 *
553 * \param cu       Pointer to current CU
554 * \param refPic   Pointer to reference picture
555 * \param partAddr Address of block within CU
556 * \param mv       Motion vector
557 * \param width    Width of block
558 * \param height   Height of block
559 * \param dstPic   Pointer to destination picture
560 * \param bi       Flag indicating whether bipred is used
561 */
[608]562Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
563  )
[56]564{
565  Int refStride = refPic->getStride(); 
566  Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride;
567  Pel *ref      = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
568 
569  Int dstStride = dstPic->getStride();
570  Pel *dst      = dstPic->getLumaAddr( partAddr );
571 
572  Int xFrac = mv->getHor() & 0x3;
573  Int yFrac = mv->getVer() & 0x3;
574
575  if ( yFrac == 0 )
[2]576  {
[608]577    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi
578      );
[2]579  }
[56]580  else if ( xFrac == 0 )
581  {
[608]582    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi
583      );
[56]584  }
585  else
586  {
587    Int tmpStride = m_filteredBlockTmp[0].getStride();
588    Short *tmp    = m_filteredBlockTmp[0].getLumaAddr();
589
590    Int filterSize = NTAPS_LUMA;
591    Int halfFilterSize = ( filterSize >> 1 );
592
[443]593    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     
[608]594      );
[443]595    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi
[608]596      );   
[56]597  }
[189]598
[2]599}
600
[56]601/**
602 * \brief Generate motion-compensated chroma block
603 *
604 * \param cu       Pointer to current CU
605 * \param refPic   Pointer to reference picture
606 * \param partAddr Address of block within CU
607 * \param mv       Motion vector
608 * \param width    Width of block
609 * \param height   Height of block
610 * \param dstPic   Pointer to destination picture
611 * \param bi       Flag indicating whether bipred is used
612 */
[608]613Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi
[443]614  )
[2]615{
[56]616  Int     refStride  = refPic->getCStride();
617  Int     dstStride  = dstPic->getCStride();
618 
619  Int     refOffset  = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride;
620 
621  Pel*    refCb     = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
622  Pel*    refCr     = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
623 
624  Pel* dstCb = dstPic->getCbAddr( partAddr );
625  Pel* dstCr = dstPic->getCrAddr( partAddr );
626 
627  Int     xFrac  = mv->getHor() & 0x7;
628  Int     yFrac  = mv->getVer() & 0x7;
629  UInt    cxWidth  = width  >> 1;
630  UInt    cxHeight = height >> 1;
631 
632  Int     extStride = m_filteredBlockTmp[0].getStride();
633  Short*  extY      = m_filteredBlockTmp[0].getLumaAddr();
634 
635  Int filterSize = NTAPS_CHROMA;
636 
637  Int halfFilterSize = (filterSize>>1);
638 
639  if ( yFrac == 0 )
640  {
[443]641    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi
642    );   
643    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi
[608]644    );
[56]645  }
646  else if ( xFrac == 0 )
647  {
[443]648    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi
[608]649    );
[443]650    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi
[608]651    );
[56]652  }
653  else
654  {
[443]655    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
[608]656      );
[443]657    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
[608]658      );
[56]659   
[443]660    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false
[608]661      );
[443]662    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi
[608]663      );   
[56]664  }
[608]665
[296]666}
667
[608]668Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
[2]669{
[56]670  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
[2]671  {
[56]672    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
[2]673  }
[56]674  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
[2]675  {
[56]676    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
[2]677  }
[56]678  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
[2]679  {
[56]680    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
681  }
682}
683
684// AMVP
[608]685Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
[56]686{
687  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
[608]688  if( pcAMVPInfo->iN <= 1 )
[56]689  {
690    rcMvPred = pcAMVPInfo->m_acMvCand[0];
691
692    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
693    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
694    return;
695  }
696
697  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
698  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
699  return;
700}
701
702/** Function for deriving planar intra prediction.
703 * \param pSrc pointer to reconstructed sample array
704 * \param srcStride the stride of the reconstructed sample array
705 * \param rpDst reference to pointer for the prediction sample array
706 * \param dstStride the stride of the prediction sample array
707 * \param width the width of the block
708 * \param height the height of the block
709 *
710 * This function derives the prediction samples for planar mode (intra coding).
711 */
712Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
713{
714  assert(width == height);
715
716  Int k, l, bottomLeft, topRight;
717  Int horPred;
[655]718  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
[56]719  UInt blkSize = width;
720  UInt offset2D = width;
721  UInt shift1D = g_aucConvertToBit[ width ] + 2;
722  UInt shift2D = shift1D + 1;
723
724  // Get left and above reference column and row
725  for(k=0;k<blkSize+1;k++)
726  {
727    topRow[k] = pSrc[k-srcStride];
728    leftColumn[k] = pSrc[k*srcStride-1];
729  }
730
731  // Prepare intermediate variables used in interpolation
732  bottomLeft = leftColumn[blkSize];
733  topRight   = topRow[blkSize];
734  for (k=0;k<blkSize;k++)
735  {
736    bottomRow[k]   = bottomLeft - topRow[k];
737    rightColumn[k] = topRight   - leftColumn[k];
738    topRow[k]      <<= shift1D;
739    leftColumn[k]  <<= shift1D;
740  }
741
742  // Generate prediction signal
743  for (k=0;k<blkSize;k++)
744  {
745    horPred = leftColumn[k] + offset2D;
746    for (l=0;l<blkSize;l++)
[2]747    {
[56]748      horPred += rightColumn[k];
749      topRow[l] += bottomRow[l];
750      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
[2]751    }
752  }
753}
754
[608]755/** Function for filtering intra DC predictor.
756 * \param pSrc pointer to reconstructed sample array
757 * \param iSrcStride the stride of the reconstructed sample array
758 * \param rpDst reference to pointer for the prediction sample array
759 * \param iDstStride the stride of the prediction sample array
760 * \param iWidth the width of the block
761 * \param iHeight the height of the block
[56]762 *
[608]763 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
[56]764 */
[608]765Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
[56]766{
[608]767  Pel* pDst = rpDst;
768  Int x, y, iDstStride2, iSrcStride2;
[2]769
[608]770  // boundary pixels processing
771  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
[56]772
[608]773  for ( x = 1; x < iWidth; x++ )
[2]774  {
[608]775    pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
[2]776  }
777
[608]778  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
[56]779  {
[608]780    pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
[56]781  }
[2]782
[608]783  return;
[2]784}
[56]785
786//! \}
Note: See TracBrowser for help on using the repository browser.