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

Last change on this file since 1606 was 1550, checked in by seregin, 9 years ago

port rev 4732, update copyright notice to include 2016

  • Property svn:eol-style set to native
File size: 30.3 KB
RevLine 
[1238]1/* The copyright in this software is being made available under the BSD
[313]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
[1029]4 * granted under this license.
[313]5 *
[1550]6 * Copyright (c) 2010-2016, ITU/ISO/IEC
[313]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"
[1262]40#include "TComPic.h"
[1029]41#include "TComTU.h"
[313]42
43//! \ingroup TLibCommon
44//! \{
45
46// ====================================================================================================================
[1029]47// Tables
48// ====================================================================================================================
49
50const UChar TComPrediction::m_aucIntraFilter[MAX_NUM_CHANNEL_TYPE][MAX_INTRA_FILTER_DEPTHS] =
51{
52  { // Luma
53    10, //4x4
54    7, //8x8
55    1, //16x16
56    0, //32x32
57    10, //64x64
58  },
59  { // Chroma
60    10, //4xn
61    7, //8xn
62    1, //16xn
63    0, //32xn
64    10, //64xn
65  }
66
67};
68
69// ====================================================================================================================
[313]70// Constructor / destructor / initialize
71// ====================================================================================================================
72
73TComPrediction::TComPrediction()
74: m_pLumaRecBuffer(0)
75, m_iLumaRecStride(0)
76{
[1029]77  for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
78  {
79    for(UInt buf=0; buf<2; buf++)
80    {
81      m_piYuvExt[ch][buf] = NULL;
82    }
83  }
[313]84}
85
86TComPrediction::~TComPrediction()
87{
[1029]88  destroy();
89}
[313]90
[1029]91Void TComPrediction::destroy()
92{
93  for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
94  {
95    for(UInt buf=0; buf<NUM_PRED_BUF; buf++)
96    {
97      delete [] m_piYuvExt[ch][buf];
98      m_piYuvExt[ch][buf] = NULL;
99    }
100  }
[313]101
[1029]102  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
103  {
104    m_acYuvPred[i].destroy();
105  }
106
[313]107  m_cYuvPredTemp.destroy();
108
109  if( m_pLumaRecBuffer )
110  {
111    delete [] m_pLumaRecBuffer;
[1029]112    m_pLumaRecBuffer = 0;
[313]113  }
[1029]114  m_iLumaRecStride = 0;
115
116  for (UInt i = 0; i < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; i++)
[313]117  {
[1029]118    for (UInt j = 0; j < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; j++)
[313]119    {
120      m_filteredBlock[i][j].destroy();
121    }
122    m_filteredBlockTmp[i].destroy();
123  }
124}
125
[1029]126Void TComPrediction::initTempBuff(ChromaFormat chromaFormatIDC)
[313]127{
[1029]128  // if it has been initialised before, but the chroma format has changed, release the memory and start again.
129  if( m_piYuvExt[COMPONENT_Y][PRED_BUF_UNFILTERED] != NULL && m_cYuvPredTemp.getChromaFormat()!=chromaFormatIDC)
[313]130  {
[1029]131    destroy();
132  }
133
134  if( m_piYuvExt[COMPONENT_Y][PRED_BUF_UNFILTERED] == NULL ) // check if first is null (in which case, nothing initialised yet)
135  {
136    Int extWidth  = MAX_CU_SIZE + 16;
[313]137    Int extHeight = MAX_CU_SIZE + 1;
[1029]138
139    for (UInt i = 0; i < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; i++)
[313]140    {
[1029]141      m_filteredBlockTmp[i].create(extWidth, extHeight + 7, chromaFormatIDC);
142      for (UInt j = 0; j < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; j++)
[313]143      {
[1029]144        m_filteredBlock[i][j].create(extWidth, extHeight, chromaFormatIDC);
[313]145      }
146    }
147
[1029]148    m_iYuvExtSize = (MAX_CU_SIZE*2+1) * (MAX_CU_SIZE*2+1);
149    for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
150    {
151      for(UInt buf=0; buf<NUM_PRED_BUF; buf++)
152      {
153        m_piYuvExt[ch][buf] = new Pel[ m_iYuvExtSize ];
154      }
155    }
156
[313]157    // new structure
[1029]158    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
159    {
160      m_acYuvPred[i] .create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );
161    }
[313]162
[1029]163    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC );
[313]164  }
165
[1029]166
[313]167  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
168  {
169    m_iLumaRecStride =  (MAX_CU_SIZE>>1) + 1;
170    if (!m_pLumaRecBuffer)
171    {
172      m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ];
173    }
174  }
175}
176
177// ====================================================================================================================
178// Public member functions
179// ====================================================================================================================
180
181// Function for calculating DC value of the reference samples used in Intra prediction
[1029]182//NOTE: Bit-Limit - 25-bit source
[1368]183Pel TComPrediction::predIntraGetPredValDC( const Pel* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight)
[313]184{
185  assert(iWidth > 0 && iHeight > 0);
186  Int iInd, iSum = 0;
187  Pel pDcVal;
188
[1368]189  for (iInd = 0;iInd < iWidth;iInd++)
[313]190  {
[1368]191    iSum += pSrc[iInd-iSrcStride];
[313]192  }
[1368]193  for (iInd = 0;iInd < iHeight;iInd++)
[313]194  {
[1368]195    iSum += pSrc[iInd*iSrcStride-1];
[313]196  }
197
[1368]198  pDcVal = (iSum + iWidth) / (iWidth + iHeight);
[1029]199
[313]200  return pDcVal;
201}
202
203// Function for deriving the angular Intra predictions
204
205/** Function for deriving the simplified angular intra predictions.
[1260]206 * \param bitDepth           bit depth
207 * \param pSrc               pointer to reconstructed sample array
208 * \param srcStride          the stride of the reconstructed sample array
209 * \param pTrueDst           reference to pointer for the prediction sample array
210 * \param dstStrideTrue      the stride of the prediction sample array
211 * \param uiWidth            the width of the block
212 * \param uiHeight           the height of the block
213 * \param channelType        type of pel array (luma/chroma)
214 * \param format             chroma format
215 * \param dirMode            the intra prediction mode index
216 * \param blkAboveAvailable  boolean indication if the block above is available
217 * \param blkLeftAvailable   boolean indication if the block to the left is available
218 * \param bEnableEdgeFilters indication whether to enable edge filters
[313]219 *
220 * This function derives the prediction samples for the angular mode based on the prediction direction indicated by
221 * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and
222 * the reference row above the block in the case of vertical prediction or displacement of the rightmost column
223 * of the block and reference column left from the block in the case of the horizontal prediction. The displacement
224 * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples,
225 * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken
226 * from the extended main reference.
227 */
[1029]228//NOTE: Bit-Limit - 25-bit source
229Void TComPrediction::xPredIntraAng(       Int bitDepth,
230                                    const Pel* pSrc,     Int srcStride,
231                                          Pel* pTrueDst, Int dstStrideTrue,
[1307]232                                          UInt uiWidth, UInt uiHeight, ChannelType channelType,
[1368]233                                          UInt dirMode, const Bool bEnableEdgeFilters
[1029]234                                  )
[313]235{
[1029]236  Int width=Int(uiWidth);
237  Int height=Int(uiHeight);
[313]238
239  // Map the mode index to main prediction direction and angle
[1029]240  assert( dirMode != PLANAR_IDX ); //no planar
241  const Bool modeDC        = dirMode==DC_IDX;
[313]242
243  // Do the DC prediction
244  if (modeDC)
245  {
[1368]246    const Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height);
[313]247
[1029]248    for (Int y=height;y>0;y--, pTrueDst+=dstStrideTrue)
[313]249    {
[1029]250      for (Int x=0; x<width;) // width is always a multiple of 4.
[313]251      {
[1029]252        pTrueDst[x++] = dcval;
[313]253      }
254    }
255  }
[1029]256  else // Do angular predictions
257  {
258    const Bool       bIsModeVer         = (dirMode >= 18);
259    const Int        intraPredAngleMode = (bIsModeVer) ? (Int)dirMode - VER_IDX :  -((Int)dirMode - HOR_IDX);
260    const Int        absAngMode         = abs(intraPredAngleMode);
261    const Int        signAng            = intraPredAngleMode < 0 ? -1 : 1;
262    const Bool       edgeFilter         = bEnableEdgeFilters && isLuma(channelType) && (width <= MAXIMUM_INTRA_FILTERED_WIDTH) && (height <= MAXIMUM_INTRA_FILTERED_HEIGHT);
[313]263
[1029]264    // Set bitshifts and scale the angle parameter to block size
265    static const Int angTable[9]    = {0,    2,    5,   9,  13,  17,  21,  26,  32};
266    static const Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
267    Int invAngle                    = invAngTable[absAngMode];
268    Int absAng                      = angTable[absAngMode];
269    Int intraPredAngle              = signAng * absAng;
270
[313]271    Pel* refMain;
272    Pel* refSide;
[1029]273
[313]274    Pel  refAbove[2*MAX_CU_SIZE+1];
275    Pel  refLeft[2*MAX_CU_SIZE+1];
276
[1368]277    // Initialize the Main and Left reference array.
[313]278    if (intraPredAngle < 0)
279    {
[1029]280      const Int refMainOffsetPreScale = (bIsModeVer ? height : width ) - 1;
281      const Int refMainOffset         = height - 1;
282      for (Int x=0;x<width+1;x++)
[313]283      {
[1029]284        refAbove[x+refMainOffset] = pSrc[x-srcStride-1];
[313]285      }
[1029]286      for (Int y=0;y<height+1;y++)
[313]287      {
[1029]288        refLeft[y+refMainOffset] = pSrc[(y-1)*srcStride-1];
[313]289      }
[1029]290      refMain = (bIsModeVer ? refAbove : refLeft)  + refMainOffset;
291      refSide = (bIsModeVer ? refLeft  : refAbove) + refMainOffset;
[313]292
293      // Extend the Main reference to the left.
294      Int invAngleSum    = 128;       // rounding for (shift by 8)
[1029]295      for (Int k=-1; k>(refMainOffsetPreScale+1)*intraPredAngle>>5; k--)
[313]296      {
297        invAngleSum += invAngle;
298        refMain[k] = refSide[invAngleSum>>8];
299      }
300    }
301    else
302    {
[1029]303      for (Int x=0;x<2*width+1;x++)
[313]304      {
[1029]305        refAbove[x] = pSrc[x-srcStride-1];
[313]306      }
[1029]307      for (Int y=0;y<2*height+1;y++)
[313]308      {
[1029]309        refLeft[y] = pSrc[(y-1)*srcStride-1];
[313]310      }
[1029]311      refMain = bIsModeVer ? refAbove : refLeft ;
312      refSide = bIsModeVer ? refLeft  : refAbove;
[313]313    }
314
[1029]315    // swap width/height if we are doing a horizontal mode:
316    Pel tempArray[MAX_CU_SIZE*MAX_CU_SIZE];
317    const Int dstStride = bIsModeVer ? dstStrideTrue : MAX_CU_SIZE;
318    Pel *pDst = bIsModeVer ? pTrueDst : tempArray;
319    if (!bIsModeVer)
[313]320    {
[1029]321      std::swap(width, height);
322    }
323
324    if (intraPredAngle == 0)  // pure vertical or pure horizontal
325    {
326      for (Int y=0;y<height;y++)
[313]327      {
[1029]328        for (Int x=0;x<width;x++)
[313]329        {
[1029]330          pDst[y*dstStride+x] = refMain[x+1];
[313]331        }
332      }
333
[1029]334      if (edgeFilter)
[313]335      {
[1029]336        for (Int y=0;y<height;y++)
[313]337        {
[1029]338          pDst[y*dstStride] = Clip3 (0, ((1 << bitDepth) - 1), pDst[y*dstStride] + (( refSide[y+1] - refSide[0] ) >> 1) );
[313]339        }
340      }
341    }
342    else
343    {
[1029]344      Pel *pDsty=pDst;
[313]345
[1029]346      for (Int y=0, deltaPos=intraPredAngle; y<height; y++, deltaPos+=intraPredAngle, pDsty+=dstStride)
[313]347      {
[1029]348        const Int deltaInt   = deltaPos >> 5;
349        const Int deltaFract = deltaPos & (32 - 1);
[313]350
351        if (deltaFract)
352        {
353          // Do linear filtering
[1029]354          const Pel *pRM=refMain+deltaInt+1;
355          Int lastRefMainPel=*pRM++;
356          for (Int x=0;x<width;pRM++,x++)
[313]357          {
[1029]358            Int thisRefMainPel=*pRM;
359            pDsty[x+0] = (Pel) ( ((32-deltaFract)*lastRefMainPel + deltaFract*thisRefMainPel +16) >> 5 );
360            lastRefMainPel=thisRefMainPel;
[313]361          }
362        }
363        else
364        {
365          // Just copy the integer samples
[1029]366          for (Int x=0;x<width; x++)
[313]367          {
[1029]368            pDsty[x] = refMain[x+deltaInt+1];
[313]369          }
370        }
371      }
372    }
373
374    // Flip the block if this is the horizontal mode
[1029]375    if (!bIsModeVer)
[313]376    {
[1029]377      for (Int y=0; y<height; y++)
[313]378      {
[1029]379        for (Int x=0; x<width; x++)
[313]380        {
[1029]381          pTrueDst[x*dstStrideTrue] = pDst[x];
[313]382        }
[1029]383        pTrueDst++;
384        pDst+=dstStride;
[313]385      }
386    }
387  }
388}
389
[1368]390Void TComPrediction::predIntraAng( const ComponentID compID, UInt uiDirMode, Pel* piOrg /* Will be null for decoding */, UInt uiOrgStride, Pel* piPred, UInt uiStride, TComTU &rTu, const Bool bUseFilteredPredSamples, const Bool bUseLosslessDPCM )
[313]391{
[1029]392  const ChannelType    channelType = toChannelType(compID);
393  const TComRectangle &rect        = rTu.getRect(isLuma(compID) ? COMPONENT_Y : COMPONENT_Cb);
394  const Int            iWidth      = rect.width;
395  const Int            iHeight     = rect.height;
[313]396
397  assert( g_aucConvertToBit[ iWidth ] >= 0 ); //   4x  4
398  assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128
[1029]399  //assert( iWidth == iHeight  );
[313]400
[1029]401        Pel *pDst = piPred;
[313]402
403  // get starting pixel in block
[1029]404  const Int sw = (2 * iWidth + 1);
[313]405
[1029]406  if ( bUseLosslessDPCM )
[313]407  {
[1029]408    const Pel *ptrSrc = getPredictorPtr( compID, false );
409    // Sample Adaptive intra-Prediction (SAP)
410    if (uiDirMode==HOR_IDX)
411    {
412      // left column filled with reference samples
413      // remaining columns filled with piOrg data (if available).
414      for(Int y=0; y<iHeight; y++)
415      {
416        piPred[y*uiStride+0] = ptrSrc[(y+1)*sw];
417      }
418      if (piOrg!=0)
419      {
420        piPred+=1; // miss off first column
421        for(Int y=0; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride)
422        {
423          memcpy(piPred, piOrg, (iWidth-1)*sizeof(Pel));
424        }
425      }
426    }
427    else // VER_IDX
428    {
429      // top row filled with reference samples
430      // remaining rows filled with piOrd data (if available)
431      for(Int x=0; x<iWidth; x++)
432      {
433        piPred[x] = ptrSrc[x+1];
434      }
435      if (piOrg!=0)
436      {
437        piPred+=uiStride; // miss off the first row
438        for(Int y=1; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride)
439        {
440          memcpy(piPred, piOrg, iWidth*sizeof(Pel));
441        }
442      }
443    }
[313]444  }
445  else
446  {
[1029]447    const Pel *ptrSrc = getPredictorPtr( compID, bUseFilteredPredSamples );
448
449    if ( uiDirMode == PLANAR_IDX )
[313]450    {
[1307]451      xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
[313]452    }
453    else
454    {
[1029]455      // Create the prediction
456            TComDataCU *const pcCU              = rTu.getCU();
457      const UInt              uiAbsPartIdx      = rTu.GetAbsPartIdxTU();
458      const Bool              enableEdgeFilters = !(pcCU->isRDPCMEnabled(uiAbsPartIdx) && pcCU->getCUTransquantBypass(uiAbsPartIdx));
459#if O0043_BEST_EFFORT_DECODING
[1287]460      const Int channelsBitDepthForPrediction = rTu.getCU()->getSlice()->getSPS()->getStreamBitDepth(channelType);
[1029]461#else
[1287]462      const Int channelsBitDepthForPrediction = rTu.getCU()->getSlice()->getSPS()->getBitDepth(channelType);
[1029]463#endif
[1368]464      xPredIntraAng( channelsBitDepthForPrediction, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, uiDirMode, enableEdgeFilters );
[1029]465
[1368]466      if( uiDirMode == DC_IDX )
[313]467      {
[1029]468        xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType );
[313]469      }
470    }
471  }
472
473}
474
[1260]475/** Check for identical motion in both motion vector direction of a bi-directional predicted CU
476  * \returns true, if motion vectors and reference pictures match
[313]477 */
478Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr )
479{
480  if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() )
481  {
482    if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0)
483    {
484      Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
485      Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
[1468]486#if SVC_EXTENSION
487      Int layerIdL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getLayerId();
488      Int layerIdL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getLayerId();
489
490      if( layerIdL0 == layerIdL1 && RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr) )
491#else
[313]492      if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
[1468]493#endif
[313]494      {
495        return true;
496      }
497    }
498  }
499  return false;
500}
501
502Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
503{
504  Int         iWidth;
505  Int         iHeight;
506  UInt        uiPartAddr;
[1393]507  const TComSlice *pSlice    = pcCU->getSlice();
508  const SliceType  sliceType = pSlice->getSliceType();
509  const TComPPS   &pps       = *(pSlice->getPPS());
[313]510
511  if ( iPartIdx >= 0 )
512  {
513    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
514    if ( eRefPicList != REF_PIC_LIST_X )
515    {
[1393]516      if( (sliceType == P_SLICE && pps.getUseWP()) || (sliceType == B_SLICE && pps.getWPBiPred()))
[313]517      {
518        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
[1393]519        xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
[313]520      }
521      else
522      {
523        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
524      }
525    }
526    else
527    {
528      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
529      {
530        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
531      }
532      else
533      {
534        xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
535      }
536    }
537    return;
538  }
539
[713]540  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ )
[313]541  {
542    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
543
544    if ( eRefPicList != REF_PIC_LIST_X )
545    {
[1393]546      if( (sliceType == P_SLICE && pps.getUseWP()) || (sliceType == B_SLICE && pps.getWPBiPred()))
[313]547      {
548        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
[1393]549        xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
[313]550      }
551      else
552      {
553        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
554      }
555    }
556    else
557    {
558      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
559      {
560        xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
561      }
562      else
563      {
564        xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
565      }
566    }
567  }
568  return;
569}
570
[1029]571Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv* pcYuvPred, Bool bi )
[313]572{
573  Int         iRefIdx     = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
574  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
575  pcCU->clipMv(cMv);
576
[815]577#if SVC_EXTENSION
[1483]578  if( pcCU->getPic()->getLayerId() > 0 )
[815]579  {
580    TComPic* refPic = pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx);
581
[1483]582    if( refPic->isILR(pcCU->getPic()->getLayerId()) )
[815]583    {
584      // It is a requirement of bitstream conformance that when the reference picture represented by the variable refIdxLX is an inter-layer reference picture,
585      // VpsInterLayerSamplePredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture
[1483]586      assert( pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getPic()->getLayerIdx(), refPic->getLayerIdx() ) );
[1534]587#if VIEW_SCALABILITY
588      if( pcCU->getSlice()->getSPS()->getInterViewMvVertConstraintFlag() )
589      {
590        assert( cMv.getVer()<= (56<<2) );
591      }
592#endif
[313]593#if REF_IDX_ME_ZEROMV
[1453]594      // It is a requirement of bitstream conformance that the variables mvLX[ 0 ] and mvLX[ 1 ] shall be equal to 0 if the value of refIdxLX corresponds to an inter-layer reference picture.
595      if( pcCU->getSlice()->getVPS()->getScalabilityMask( SCALABILITY_ID ) )
596      {
597        assert( cMv.getHor() == 0 && cMv.getVer() == 0 );
598      }
[313]599#endif
[815]600    }
[313]601
[815]602  }
603#endif
604
[1287]605  for (UInt comp=COMPONENT_Y; comp<pcYuvPred->getNumberValidComponents(); comp++)
[1246]606  {
[1287]607    const ComponentID compID=ComponentID(comp);
608    xPredInterBlk  (compID,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)) );
[1246]609  }
[313]610}
611
[1029]612Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv* pcYuvPred )
[313]613{
614  TComYuv* pcMbYuv;
[1029]615  Int      iRefIdx[NUM_REF_PIC_LIST_01] = {-1, -1};
[313]616
[1029]617  for ( UInt refList = 0; refList < NUM_REF_PIC_LIST_01; refList++ )
[313]618  {
[1029]619    RefPicList eRefPicList = (refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
620    iRefIdx[refList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
[313]621
[1029]622    if ( iRefIdx[refList] < 0 )
[313]623    {
624      continue;
625    }
626
[1029]627    assert( iRefIdx[refList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
[313]628
[1029]629    pcMbYuv = &m_acYuvPred[refList];
[313]630    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
631    {
632      xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
633    }
634    else
635    {
[1029]636      if ( ( pcCU->getSlice()->getPPS()->getUseWP()       && pcCU->getSlice()->getSliceType() == P_SLICE ) ||
637           ( pcCU->getSlice()->getPPS()->getWPBiPred()    && pcCU->getSlice()->getSliceType() == B_SLICE ) )
[313]638      {
639        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
640      }
641      else
642      {
643        xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
644      }
645    }
646  }
647
[1029]648  if ( pcCU->getSlice()->getPPS()->getWPBiPred()    && pcCU->getSlice()->getSliceType() == B_SLICE  )
[313]649  {
[1029]650    xWeightedPredictionBi( pcCU, &m_acYuvPred[REF_PIC_LIST_0], &m_acYuvPred[REF_PIC_LIST_1], iRefIdx[REF_PIC_LIST_0], iRefIdx[REF_PIC_LIST_1], uiPartAddr, iWidth, iHeight, pcYuvPred );
651  }
[313]652  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
653  {
[1029]654    xWeightedPredictionUni( pcCU, &m_acYuvPred[REF_PIC_LIST_0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
[313]655  }
656  else
657  {
[1287]658    xWeightedAverage( &m_acYuvPred[REF_PIC_LIST_0], &m_acYuvPred[REF_PIC_LIST_1], iRefIdx[REF_PIC_LIST_0], iRefIdx[REF_PIC_LIST_1], uiPartAddr, iWidth, iHeight, pcYuvPred, pcCU->getSlice()->getSPS()->getBitDepths() );
[313]659  }
660}
661
662/**
[1029]663 * \brief Generate motion-compensated block
[313]664 *
[1305]665 * \param compID     Colour component ID
666 * \param cu         Pointer to current CU
667 * \param refPic     Pointer to reference picture
668 * \param partAddr   Address of block within CU
669 * \param mv         Motion vector
670 * \param width      Width of block
671 * \param height     Height of block
672 * \param dstPic     Pointer to destination picture
673 * \param bi         Flag indicating whether bipred is used
674 * \param  bitDepth  Bit depth
[313]675 */
[1029]676
677
[1287]678Void TComPrediction::xPredInterBlk(const ComponentID compID, TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *dstPic, Bool bi, const Int bitDepth )
[313]679{
[1029]680  Int     refStride  = refPic->getStride(compID);
681  Int     dstStride  = dstPic->getStride(compID);
682  Int shiftHor=(2+refPic->getComponentScaleX(compID));
683  Int shiftVer=(2+refPic->getComponentScaleY(compID));
[313]684
[1029]685  Int     refOffset  = (mv->getHor() >> shiftHor) + (mv->getVer() >> shiftVer) * refStride;
[313]686
[1029]687  Pel*    ref     = refPic->getAddr(compID, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refOffset;
[313]688
[1029]689  Pel*    dst = dstPic->getAddr( compID, partAddr );
[313]690
[1029]691  Int     xFrac  = mv->getHor() & ((1<<shiftHor)-1);
692  Int     yFrac  = mv->getVer() & ((1<<shiftVer)-1);
693  UInt    cxWidth  = width  >> refPic->getComponentScaleX(compID);
694  UInt    cxHeight = height >> refPic->getComponentScaleY(compID);
695
696  const ChromaFormat chFmt = cu->getPic()->getChromaFormat();
697
[313]698  if ( yFrac == 0 )
699  {
[1287]700    m_if.filterHor(compID, ref, refStride, dst,  dstStride, cxWidth, cxHeight, xFrac, !bi, chFmt, bitDepth);
[313]701  }
702  else if ( xFrac == 0 )
703  {
[1287]704    m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi, chFmt, bitDepth);
[313]705  }
706  else
707  {
[1029]708    Int   tmpStride = m_filteredBlockTmp[0].getStride(compID);
709    Pel*  tmp       = m_filteredBlockTmp[0].getAddr(compID);
710
711    const Int vFilterSize = isLuma(compID) ? NTAPS_LUMA : NTAPS_CHROMA;
712
[1287]713    m_if.filterHor(compID, ref - ((vFilterSize>>1) -1)*refStride, refStride, tmp, tmpStride, cxWidth, cxHeight+vFilterSize-1, xFrac, false,      chFmt, bitDepth);
714    m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight,               yFrac, false, !bi, chFmt, bitDepth);
[313]715  }
716}
717
[1287]718Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv* pcYuvDst, const BitDepths &clipBitDepths )
[313]719{
720  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
721  {
[1287]722    pcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight, clipBitDepths );
[313]723  }
724  else if ( iRefIdx0 >= 0 && iRefIdx1 <  0 )
725  {
[1029]726    pcYuvSrc0->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight );
[313]727  }
728  else if ( iRefIdx0 <  0 && iRefIdx1 >= 0 )
729  {
[1029]730    pcYuvSrc1->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight );
[313]731  }
732}
733
734// AMVP
735Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred )
736{
737  AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
[1029]738
[313]739  if( pcAMVPInfo->iN <= 1 )
740  {
741    rcMvPred = pcAMVPInfo->m_acMvCand[0];
742
743    pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
744    pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
745    return;
746  }
747
748  assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0);
749  rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)];
750  return;
751}
752
753/** Function for deriving planar intra prediction.
[1260]754 * \param pSrc        pointer to reconstructed sample array
755 * \param srcStride   the stride of the reconstructed sample array
756 * \param rpDst       reference to pointer for the prediction sample array
757 * \param dstStride   the stride of the prediction sample array
758 * \param width       the width of the block
759 * \param height      the height of the block
760 * \param channelType type of pel array (luma, chroma)
761 * \param format      chroma format
[313]762 *
763 * This function derives the prediction samples for planar mode (intra coding).
764 */
[1029]765//NOTE: Bit-Limit - 24-bit source
[1307]766Void TComPrediction::xPredIntraPlanar( const Pel* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
[313]767{
[1029]768  assert(width <= height);
[313]769
[442]770  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
[1029]771  UInt shift1Dhor = g_aucConvertToBit[ width ] + 2;
772  UInt shift1Dver = g_aucConvertToBit[ height ] + 2;
[313]773
774  // Get left and above reference column and row
[1029]775  for(Int k=0;k<width+1;k++)
[313]776  {
777    topRow[k] = pSrc[k-srcStride];
[1029]778  }
779
780  for (Int k=0; k < height+1; k++)
781  {
[313]782    leftColumn[k] = pSrc[k*srcStride-1];
783  }
784
785  // Prepare intermediate variables used in interpolation
[1029]786  Int bottomLeft = leftColumn[height];
787  Int topRight   = topRow[width];
788
789  for(Int k=0;k<width;k++)
[313]790  {
[1029]791    bottomRow[k]  = bottomLeft - topRow[k];
792    topRow[k]     <<= shift1Dver;
[313]793  }
794
[1029]795  for(Int k=0;k<height;k++)
796  {
797    rightColumn[k]  = topRight - leftColumn[k];
798    leftColumn[k]   <<= shift1Dhor;
799  }
800
801  const UInt topRowShift = 0;
802
[313]803  // Generate prediction signal
[1029]804  for (Int y=0;y<height;y++)
[313]805  {
[1029]806    Int horPred = leftColumn[y] + width;
807    for (Int x=0;x<width;x++)
[313]808    {
[1029]809      horPred += rightColumn[y];
810      topRow[x] += bottomRow[x];
811
812      Int vertPred = ((topRow[x] + topRowShift)>>topRowShift);
813      rpDst[y*dstStride+x] = ( horPred + vertPred ) >> (shift1Dhor+1);
[313]814    }
815  }
816}
817
818/** Function for filtering intra DC predictor.
819 * \param pSrc pointer to reconstructed sample array
820 * \param iSrcStride the stride of the reconstructed sample array
[1260]821 * \param pDst reference to pointer for the prediction sample array
[313]822 * \param iDstStride the stride of the prediction sample array
823 * \param iWidth the width of the block
824 * \param iHeight the height of the block
[1260]825 * \param channelType type of pel array (luma, chroma)
[313]826 *
827 * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
828 */
[1029]829Void TComPrediction::xDCPredFiltering( const Pel* pSrc, Int iSrcStride, Pel* pDst, Int iDstStride, Int iWidth, Int iHeight, ChannelType channelType )
[313]830{
831  Int x, y, iDstStride2, iSrcStride2;
832
[1029]833  if (isLuma(channelType) && (iWidth <= MAXIMUM_INTRA_FILTERED_WIDTH) && (iHeight <= MAXIMUM_INTRA_FILTERED_HEIGHT))
[313]834  {
[1029]835    //top-left
836    pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
[313]837
[1029]838    //top row (vertical filter)
839    for ( x = 1; x < iWidth; x++ )
840    {
841      pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2);
842    }
843
844    //left column (horizontal filter)
845    for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
846    {
847      pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2);
848    }
[313]849  }
850
851  return;
852}
853
[1029]854/* Static member function */
855Bool TComPrediction::UseDPCMForFirstPassIntraEstimation(TComTU &rTu, const UInt uiDirMode)
856{
857  return (rTu.getCU()->isRDPCMEnabled(rTu.GetAbsPartIdxTU()) ) &&
858          rTu.getCU()->getCUTransquantBypass(rTu.GetAbsPartIdxTU()) &&
859          (uiDirMode==HOR_IDX || uiDirMode==VER_IDX);
860}
861
[815]862#if SVC_EXTENSION
[1287]863Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Int refBitDepthLuma, const Int refBitDepthChroma )
[944]864{
[1287]865  m_cUsf.upsampleBasePic( currSlice, refLayerIdc, pcUsPic, pcBasePic, pcTempPic, refBitDepthLuma, refBitDepthChroma );
[944]866}
[815]867#endif //SVC_EXTENSION
[313]868//! \}
Note: See TracBrowser for help on using the repository browser.