Ignore:
Timestamp:
11 May 2012, 21:20:17 (13 years ago)
Author:
hschwarz
Message:

updated trunk (move to HM6.1)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibCommon/TComWeightPrediction.cpp

    r5 r56  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license.
     4 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2011, ISO/IEC
     6 * Copyright (c) 2010-2012, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    1515 *    this list of conditions and the following disclaimer in the documentation
    1616 *    and/or other materials provided with the distribution.
    17  *  * Neither the name of the ISO/IEC nor the names of its contributors may
     17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
    1818 *    be used to endorse or promote products derived from this software without
    1919 *    specific prior written permission.
     
    3232 */
    3333
    34 
    35 
    3634/** \file     TComWeightPrediction.h
    3735    \brief    weighting prediction class (header)
     
    4139#include "TComSlice.h"
    4240#include "TComWeightPrediction.h"
    43 
    44 #ifdef WEIGHT_PRED
     41#include "TComInterpolationFilter.h"
    4542
    4643// ====================================================================================================================
     
    5148}
    5249
     50/** weighted averaging for bi-pred
     51 * \param TComYuv* pcYuvSrc0
     52 * \param TComYuv* pcYuvSrc1
     53 * \param iPartUnitIdx
     54 * \param iWidth
     55 * \param iHeight
     56 * \param wpScalingParam *wp0
     57 * \param wpScalingParam *wp1
     58 * \param TComYuv* rpcYuvDst
     59 * \returns Void
     60 */
    5361Void TComWeightPrediction::addWeightBi( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight, wpScalingParam *wp0, wpScalingParam *wp1, TComYuv* rpcYuvDst, Bool bRound )
    5462{
     
    6977  // Luma : --------------------------------------------
    7078  Int w0      = wp0[0].w;
    71   Int o0      = wp0[0].o;
    7279  Int offset  = wp0[0].offset;
    73   Int shiftNum = 14 - (g_uiBitDepth + g_uiBitIncrement);
     80  Int shiftNum = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement );
    7481  Int shift   = wp0[0].shift + shiftNum;
    7582  Int round   = (1<<(shift-1)) * bRound;
    7683  Int w1      = wp1[0].w;
    77   Int o1      = wp1[0].o;
    7884
    7985  UInt  iSrc0Stride = pcYuvSrc0->getStride();
    8086  UInt  iSrc1Stride = pcYuvSrc1->getStride();
    8187  UInt  iDstStride  = rpcYuvDst->getStride();
    82  
    83   for ( y = iHeight-1; y >= 0; y-- )
    84   {
    85     for ( x = iWidth-1; x >= 0; )
    86     {
    87           // note: luma min width is 4
     88  for ( y = iHeight-1; y >= 0; y-- )
     89  {
     90    for ( x = iWidth-1; x >= 0; )
     91    {
     92      // note: luma min width is 4
    8893      pDstY[x] = weightBidir(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--;
    8994      pDstY[x] = weightBidir(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--;
    9095      pDstY[x] = weightBidir(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--;
    9196      pDstY[x] = weightBidir(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--;
    92         }
     97    }
    9398    pSrcY0 += iSrc0Stride;
    9499    pSrcY1 += iSrc1Stride;
    95100    pDstY  += iDstStride;
    96101  }
     102
    97103 
    98104  // Chroma U : --------------------------------------------
    99105  w0      = wp0[1].w;
    100   o0      = wp0[1].o;
    101106  offset  = wp0[1].offset;
    102107  shift   = wp0[1].shift + shiftNum;
    103108  round   = (1<<(shift-1));
    104109  w1      = wp1[1].w;
    105   o1      = wp1[1].o;
    106110
    107111  iSrc0Stride = pcYuvSrc0->getCStride();
     
    119123      pDstU[x] = weightBidir(w0,pSrcU0[x], w1,pSrcU1[x], round, shift, offset); x--;
    120124      pDstU[x] = weightBidir(w0,pSrcU0[x], w1,pSrcU1[x], round, shift, offset); x--;
    121         }
     125    }
    122126    pSrcU0 += iSrc0Stride;
    123127    pSrcU1 += iSrc1Stride;
     
    127131  // Chroma V : --------------------------------------------
    128132  w0      = wp0[2].w;
    129   o0      = wp0[2].o;
    130133  offset  = wp0[2].offset;
    131134  shift   = wp0[2].shift + shiftNum;
    132135  round   = (1<<(shift-1));
    133136  w1      = wp1[2].w;
    134   o1      = wp1[2].o;
    135137
    136138  for ( y = iHeight-1; y >= 0; y-- )
     
    139141    {
    140142      // note: chroma min width is 2
    141           pDstV[x] = weightBidir(w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x--;
    142143      pDstV[x] = weightBidir(w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x--;
    143         }
     144      pDstV[x] = weightBidir(w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x--;
     145    }
    144146    pSrcV0 += iSrc0Stride;
    145147    pSrcV1 += iSrc1Stride;
     
    148150}
    149151
     152/** weighted averaging for uni-pred
     153 * \param TComYuv* pcYuvSrc0
     154 * \param iPartUnitIdx
     155 * \param iWidth
     156 * \param iHeight
     157 * \param wpScalingParam *wp0
     158 * \param TComYuv* rpcYuvDst
     159 * \returns Void
     160 */
    150161Void TComWeightPrediction::addWeightUni( TComYuv* pcYuvSrc0, UInt iPartUnitIdx, UInt iWidth, UInt iHeight, wpScalingParam *wp0, TComYuv* rpcYuvDst )
    151162{
     
    163174  Int w0      = wp0[0].w;
    164175  Int offset  = wp0[0].offset;
    165   Int shift   = wp0[0].shift;
    166   Int round   = wp0[0].round;
    167 
     176  Int shiftNum = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement );
     177  Int shift   = wp0[0].shift + shiftNum;
     178  Int round   = (1<<(shift-1));
    168179  UInt  iSrc0Stride = pcYuvSrc0->getStride();
    169180  UInt  iDstStride  = rpcYuvDst->getStride();
     
    186197  w0      = wp0[1].w;
    187198  offset  = wp0[1].offset;
    188   shift   = wp0[1].shift;
    189   round   = wp0[1].round;
     199  shift   = wp0[1].shift + shiftNum;
     200  round   = (1<<(shift-1));
    190201
    191202  iSrc0Stride = pcYuvSrc0->getCStride();
     
    200211    {
    201212      // note: chroma min width is 2
    202           pDstU[x] = weightUnidir(w0,pSrcU0[x], round, shift, offset); x--;
    203213      pDstU[x] = weightUnidir(w0,pSrcU0[x], round, shift, offset); x--;
    204         }
     214      pDstU[x] = weightUnidir(w0,pSrcU0[x], round, shift, offset); x--;
     215    }
    205216    pSrcU0 += iSrc0Stride;
    206217    pDstU  += iDstStride;
     
    210221  w0      = wp0[2].w;
    211222  offset  = wp0[2].offset;
    212   shift   = wp0[2].shift;
    213   round   = wp0[2].round;
     223  shift   = wp0[2].shift + shiftNum;
     224  round   = (1<<(shift-1));
    214225
    215226  for ( y = iHeight-1; y >= 0; y-- )
     
    218229    {
    219230      // note: chroma min width is 2
    220           pDstV[x] = weightUnidir(w0,pSrcV0[x], round, shift, offset); x--;
    221231      pDstV[x] = weightUnidir(w0,pSrcV0[x], round, shift, offset); x--;
    222         }
     232      pDstV[x] = weightUnidir(w0,pSrcV0[x], round, shift, offset); x--;
     233    }
    223234    pSrcV0 += iSrc0Stride;
    224235    pDstV  += iDstStride;
     
    228239//=======================================================
    229240//  getWpScaling()
    230 //  When called before SAD computation, ibdi is (g_uiBitDepth+g_uiBitIncrement),
    231 //  when called before motion compensation (weighted prediction computation), ibdi is 14 (#if HIGH_ACCURACY_BI in bi-dir only).
    232241//=======================================================
    233 Void TComWeightPrediction::getWpScaling( TComDataCU* pcCU, Int iRefIdx0, Int iRefIdx1, wpScalingParam *&wp0 , wpScalingParam *&wp1 , Int ibdi)
     242/** derivation of wp tables
     243 * \param TComDataCU* pcCU
     244 * \param iRefIdx0
     245 * \param iRefIdx1
     246 * \param wpScalingParam *&wp0
     247 * \param wpScalingParam *&wp1
     248 * \param ibdi
     249 * \returns Void
     250 */
     251Void TComWeightPrediction::getWpScaling( TComDataCU* pcCU, Int iRefIdx0, Int iRefIdx1, wpScalingParam *&wp0, wpScalingParam *&wp1, Int ibdi)
    234252{
    235253  TComSlice*      pcSlice       = pcCU->getSlice();
     
    313331      wp1[yuv].w      = wp1[yuv].iWeight;
    314332      wp1[yuv].o      = wp1[yuv].iOffset * (1 << (m_ibdi-8));
    315       wp0[yuv].offset = ( ( wp0[yuv].o + wp1[yuv].o + 1 ) >> 1 );
     333      wp0[yuv].offset = wp0[yuv].o + wp1[yuv].o;
    316334      wp0[yuv].shift  = wp0[yuv].uiLog2WeightDenom + 1;
    317335      wp0[yuv].round  = (1 << wp0[yuv].uiLog2WeightDenom);
     
    346364}
    347365
    348 Void TComWeightPrediction::xWeightedPredictionUni( TComDataCU* pcCU, TComYuv* pcYuvSrc, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx )
    349 {
    350   wpScalingParam  *pwp, *pwpTmp;
    351   Int             iRefIdx   = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );           assert (iRefIdx >= 0);
    352   Int             ibdi = (g_uiBitDepth+g_uiBitIncrement);
    353 
    354   if ( eRefPicList == REF_PIC_LIST_0 )
    355   {
    356     getWpScaling(pcCU, iRefIdx, -1, pwp, pwpTmp, ibdi);
    357   }
    358   else
    359   {
    360     getWpScaling(pcCU, -1, iRefIdx, pwpTmp, pwp, ibdi);
    361   }
    362   addWeightUni( pcYuvSrc, uiPartAddr, iWidth, iHeight, pwp, rpcYuvPred );
    363 }
    364 
     366/** weighted prediction for bi-pred
     367 * \param TComDataCU* pcCU
     368 * \param TComYuv* pcYuvSrc0
     369 * \param TComYuv* pcYuvSrc1
     370 * \param iRefIdx0
     371 * \param iRefIdx1
     372 * \param uiPartIdx
     373 * \param iWidth
     374 * \param iHeight
     375 * \param TComYuv* rpcYuvDst
     376 * \returns Void
     377 */
    365378Void TComWeightPrediction::xWeightedPredictionBi( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv* rpcYuvDst )
    366379{
     
    368381  TComPPS         *pps = pcCU->getSlice()->getPPS();
    369382
    370   if ( !pps->getUseWP() ) {
    371     printf("TComWeightPrediction::xWeightedPredictionBi():\tassert failed: useWP is false.\n");
    372     exit(0);
    373   }
     383  assert( pps->getWPBiPredIdc() != 0 );
    374384
    375385  Int ibdi = (g_uiBitDepth+g_uiBitIncrement);
     
    389399  }
    390400  else
     401  {
    391402    assert (0);
    392 
    393 }
    394 
    395 #endif  // WEIGHT_PRED
    396 
     403  }
     404}
     405
     406/** weighted prediction for uni-pred
     407 * \param TComDataCU* pcCU
     408 * \param TComYuv* pcYuvSrc
     409 * \param uiPartAddr
     410 * \param iWidth
     411 * \param iHeight
     412 * \param eRefPicList
     413 * \param TComYuv*& rpcYuvPred
     414 * \param iPartIdx
     415 * \param iRefIdx
     416 * \returns Void
     417 */
     418Void TComWeightPrediction::xWeightedPredictionUni( TComDataCU* pcCU, TComYuv* pcYuvSrc, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Int iRefIdx)
     419{
     420  wpScalingParam  *pwp, *pwpTmp;
     421  if ( iRefIdx < 0 )
     422  {
     423    iRefIdx   = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
     424  }
     425  assert (iRefIdx >= 0);
     426
     427  Int ibdi = (g_uiBitDepth+g_uiBitIncrement);
     428
     429  if ( eRefPicList == REF_PIC_LIST_0 )
     430  {
     431    getWpScaling(pcCU, iRefIdx, -1, pwp, pwpTmp, ibdi);
     432  }
     433  else
     434  {
     435    getWpScaling(pcCU, -1, iRefIdx, pwpTmp, pwp, ibdi);
     436  }
     437  addWeightUni( pcYuvSrc, uiPartAddr, iWidth, iHeight, pwp, rpcYuvPred );
     438}
     439
     440
Note: See TracChangeset for help on using the changeset viewer.