source: SHVCSoftware/branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPrediction.cpp @ 89

Last change on this file since 89 was 54, checked in by seregin, 12 years ago

port simulcast

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