source: SHVCSoftware/branches/SHM-2.0-dev/source/Lib/TLibCommon/TComPrediction.cpp

Last change on this file was 175, checked in by qualcomm, 12 years ago

Scaled reference layer offsets in SPS (MACRO: SCALED_REF_LAYER_OFFSETS)

M0309: Signal scaled reference layer offsets in the SPS and use it for upsampling and MV prediction.

From: Adarsh K. Ramasubramonian <aramasub@…>

File size: 26.1 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  = MAX_CU_SIZE + 16; 
86    Int extHeight = MAX_CU_SIZE + 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  = ((MAX_CU_SIZE + 2) << 4);
97    m_iYuvExtStride = ((MAX_CU_SIZE  + 8) << 4);
98    m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
99
100    // new structure
101    m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE );
102    m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE );
103
104    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE );
105  }
106
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  }
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
496#if REF_IDX_ME_ZEROMV
497  assert( ( pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(pcCU->getLayerId()) && cMv.getHor() == 0 && cMv.getVer() == 0 ) || pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(pcCU->getLayerId()) == false );
498#endif
499
500  xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
501  xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
502}
503
504Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
505{
506  TComYuv* pcMbYuv;
507  Int      iRefIdx[2] = {-1, -1};
508
509  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
510  {
511    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
512    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
513
514    if ( iRefIdx[iRefList] < 0 )
515    {
516      continue;
517    }
518
519    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
520
521    pcMbYuv = &m_acYuvPred[iRefList];
522    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
523    {
524      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
525    }
526    else
527    {
528      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) || 
529           ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
530      {
531        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
532      }
533      else
534      {
535        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
536      }
537    }
538  }
539
540  if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE  )
541  {
542    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
543  } 
544  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
545  {
546    xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); 
547  }
548  else
549  {
550    xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
551  }
552}
553
554/**
555 * \brief Generate motion-compensated luma block
556 *
557 * \param cu       Pointer to current CU
558 * \param refPic   Pointer to reference picture
559 * \param partAddr Address of block within CU
560 * \param mv       Motion vector
561 * \param width    Width of block
562 * \param height   Height of block
563 * \param dstPic   Pointer to destination picture
564 * \param bi       Flag indicating whether bipred is used
565 */
566Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi )
567{
568  Int refStride = refPic->getStride(); 
569  Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride;
570  Pel *ref      = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
571 
572  Int dstStride = dstPic->getStride();
573  Pel *dst      = dstPic->getLumaAddr( partAddr );
574 
575  Int xFrac = mv->getHor() & 0x3;
576  Int yFrac = mv->getVer() & 0x3;
577
578  if ( yFrac == 0 )
579  {
580    m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi );
581  }
582  else if ( xFrac == 0 )
583  {
584    m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi );
585  }
586  else
587  {
588    Int tmpStride = m_filteredBlockTmp[0].getStride();
589    Short *tmp    = m_filteredBlockTmp[0].getLumaAddr();
590
591    Int filterSize = NTAPS_LUMA;
592    Int halfFilterSize = ( filterSize >> 1 );
593
594    m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false     );
595    m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi);   
596  }
597}
598
599/**
600 * \brief Generate motion-compensated chroma block
601 *
602 * \param cu       Pointer to current CU
603 * \param refPic   Pointer to reference picture
604 * \param partAddr Address of block within CU
605 * \param mv       Motion vector
606 * \param width    Width of block
607 * \param height   Height of block
608 * \param dstPic   Pointer to destination picture
609 * \param bi       Flag indicating whether bipred is used
610 */
611Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi )
612{
613  Int     refStride  = refPic->getCStride();
614  Int     dstStride  = dstPic->getCStride();
615 
616  Int     refOffset  = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride;
617 
618  Pel*    refCb     = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
619  Pel*    refCr     = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
620 
621  Pel* dstCb = dstPic->getCbAddr( partAddr );
622  Pel* dstCr = dstPic->getCrAddr( partAddr );
623 
624  Int     xFrac  = mv->getHor() & 0x7;
625  Int     yFrac  = mv->getVer() & 0x7;
626  UInt    cxWidth  = width  >> 1;
627  UInt    cxHeight = height >> 1;
628 
629  Int     extStride = m_filteredBlockTmp[0].getStride();
630  Short*  extY      = m_filteredBlockTmp[0].getLumaAddr();
631 
632  Int filterSize = NTAPS_CHROMA;
633 
634  Int halfFilterSize = (filterSize>>1);
635 
636  if ( yFrac == 0 )
637  {
638    m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi);   
639    m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi);   
640  }
641  else if ( xFrac == 0 )
642  {
643    m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi);   
644    m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi);   
645  }
646  else
647  {
648    m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false);
649    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi);
650   
651    m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY,  extStride, cxWidth, cxHeight+filterSize-1, xFrac, false);
652    m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi);   
653  }
654}
655
656Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst )
657{
658  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
659  {
660    rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight );
661  }
662  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
663  {
664    pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
665  }
666  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
667  {
668    pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight );
669  }
670}
671
672// AMVP
673Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
674{
675  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
676  if( pcAMVPInfo->iN <= 1 )
677  {
678    rcMvPred = pcAMVPInfo->m_acMvCand[0];
679
680    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
681    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
682    return;
683  }
684
685  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
686  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
687  return;
688}
689
690/** Function for deriving planar intra prediction.
691 * \param pSrc pointer to reconstructed sample array
692 * \param srcStride the stride of the reconstructed sample array
693 * \param rpDst reference to pointer for the prediction sample array
694 * \param dstStride the stride of the prediction sample array
695 * \param width the width of the block
696 * \param height the height of the block
697 *
698 * This function derives the prediction samples for planar mode (intra coding).
699 */
700Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
701{
702  assert(width == height);
703
704  Int k, l, bottomLeft, topRight;
705  Int horPred;
706  Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
707  UInt blkSize = width;
708  UInt offset2D = width;
709  UInt shift1D = g_aucConvertToBit[ width ] + 2;
710  UInt shift2D = shift1D + 1;
711
712  // Get left and above reference column and row
713  for(k=0;k<blkSize+1;k++)
714  {
715    topRow[k] = pSrc[k-srcStride];
716    leftColumn[k] = pSrc[k*srcStride-1];
717  }
718
719  // Prepare intermediate variables used in interpolation
720  bottomLeft = leftColumn[blkSize];
721  topRight   = topRow[blkSize];
722  for (k=0;k<blkSize;k++)
723  {
724    bottomRow[k]   = bottomLeft - topRow[k];
725    rightColumn[k] = topRight   - leftColumn[k];
726    topRow[k]      <<= shift1D;
727    leftColumn[k]  <<= shift1D;
728  }
729
730  // Generate prediction signal
731  for (k=0;k<blkSize;k++)
732  {
733    horPred = leftColumn[k] + offset2D;
734    for (l=0;l<blkSize;l++)
735    {
736      horPred += rightColumn[k];
737      topRow[l] += bottomRow[l];
738      rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );
739    }
740  }
741}
742
743/** Function for filtering intra DC predictor.
744 * \param pSrc pointer to reconstructed sample array
745 * \param iSrcStride the stride of the reconstructed sample array
746 * \param rpDst reference to pointer for the prediction sample array
747 * \param iDstStride the stride of the prediction sample array
748 * \param iWidth the width of the block
749 * \param iHeight the height of the block
750 *
751 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
752 */
753Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
754{
755  Pel* pDst = rpDst;
756  Int x, y, iDstStride2, iSrcStride2;
757
758  // boundary pixels processing
759  pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
760
761  for ( x = 1; x < iWidth; x++ )
762  {
763    pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
764  }
765
766  for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
767  {
768    pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
769  }
770
771  return;
772}
773
774#if SVC_UPSAMPLING
775#if SCALED_REF_LAYER_OFFSETS
776Void TComPrediction::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window)
777{
778  m_cUsf.upsampleBasePic( pcUsPic, pcBasePic, pcTempPic, window);
779}
780#else
781Void TComPrediction::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic)
782{
783  m_cUsf.upsampleBasePic( pcUsPic, pcBasePic, pcTempPic);
784}
785#endif
786#endif
787//! \}
Note: See TracBrowser for help on using the repository browser.