Ignore:
Timestamp:
1 Sep 2013, 22:47:26 (11 years ago)
Author:
tech
Message:

Merged DEV-2.0-dev0@604.

File:
1 edited

Legend:

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

    r56 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4141#include "TComInterpolationFilter.h"
    4242
     43static inline Pel weightBidirY( Int w0, Pel P0, Int w1, Pel P1, Int round, Int shift, Int offset)
     44{
     45  return ClipY( ( (w0*(P0 + IF_INTERNAL_OFFS) + w1*(P1 + IF_INTERNAL_OFFS) + round + (offset << (shift-1))) >> shift ) );
     46}
     47static inline Pel weightBidirC( Int w0, Pel P0, Int w1, Pel P1, Int round, Int shift, Int offset)
     48{
     49  return ClipC( ( (w0*(P0 + IF_INTERNAL_OFFS) + w1*(P1 + IF_INTERNAL_OFFS) + round + (offset << (shift-1))) >> shift ) );
     50}
     51
     52static inline Pel weightUnidirY( Int w0, Pel P0, Int round, Int shift, Int offset)
     53{
     54  return ClipY( ( (w0*(P0 + IF_INTERNAL_OFFS) + round) >> shift ) + offset );
     55}
     56static inline Pel weightUnidirC( Int w0, Pel P0, Int round, Int shift, Int offset)
     57{
     58  return ClipC( ( (w0*(P0 + IF_INTERNAL_OFFS) + round) >> shift ) + offset );
     59}
     60
    4361// ====================================================================================================================
    4462// Class definition
     
    7896  Int w0      = wp0[0].w;
    7997  Int offset  = wp0[0].offset;
    80   Int shiftNum = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement );
     98  Int shiftNum = IF_INTERNAL_PREC - g_bitDepthY;
    8199  Int shift   = wp0[0].shift + shiftNum;
    82   Int round   = (1<<(shift-1)) * bRound;
     100  Int round   = shift?(1<<(shift-1)) * bRound:0;
    83101  Int w1      = wp1[0].w;
    84102
     
    91109    {
    92110      // note: luma min width is 4
    93       pDstY[x] = weightBidir(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--;
    94       pDstY[x] = weightBidir(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--;
    95       pDstY[x] = weightBidir(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--;
    96       pDstY[x] = weightBidir(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--;
     111      pDstY[x] = weightBidirY(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--;
     112      pDstY[x] = weightBidirY(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--;
     113      pDstY[x] = weightBidirY(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--;
     114      pDstY[x] = weightBidirY(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--;
    97115    }
    98116    pSrcY0 += iSrc0Stride;
     
    105123  w0      = wp0[1].w;
    106124  offset  = wp0[1].offset;
     125  shiftNum = IF_INTERNAL_PREC - g_bitDepthC;
    107126  shift   = wp0[1].shift + shiftNum;
    108   round   = (1<<(shift-1));
     127  round   = shift?(1<<(shift-1)):0;
    109128  w1      = wp1[1].w;
    110129
     
    121140    {
    122141      // note: chroma min width is 2
    123       pDstU[x] = weightBidir(w0,pSrcU0[x], w1,pSrcU1[x], round, shift, offset); x--;
    124       pDstU[x] = weightBidir(w0,pSrcU0[x], w1,pSrcU1[x], round, shift, offset); x--;
     142      pDstU[x] = weightBidirC(w0,pSrcU0[x], w1,pSrcU1[x], round, shift, offset); x--;
     143      pDstU[x] = weightBidirC(w0,pSrcU0[x], w1,pSrcU1[x], round, shift, offset); x--;
    125144    }
    126145    pSrcU0 += iSrc0Stride;
     
    133152  offset  = wp0[2].offset;
    134153  shift   = wp0[2].shift + shiftNum;
    135   round   = (1<<(shift-1));
     154  round   = shift?(1<<(shift-1)):0;
    136155  w1      = wp1[2].w;
    137156
     
    141160    {
    142161      // note: chroma min width is 2
    143       pDstV[x] = weightBidir(w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x--;
    144       pDstV[x] = weightBidir(w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x--;
     162      pDstV[x] = weightBidirC(w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x--;
     163      pDstV[x] = weightBidirC(w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x--;
    145164    }
    146165    pSrcV0 += iSrc0Stride;
     
    174193  Int w0      = wp0[0].w;
    175194  Int offset  = wp0[0].offset;
    176   Int shiftNum = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement );
     195  Int shiftNum = IF_INTERNAL_PREC - g_bitDepthY;
    177196  Int shift   = wp0[0].shift + shiftNum;
    178   Int round   = (1<<(shift-1));
     197  Int round   = shift?(1<<(shift-1)):0;
    179198  UInt  iSrc0Stride = pcYuvSrc0->getStride();
    180199  UInt  iDstStride  = rpcYuvDst->getStride();
     
    185204    {
    186205      // note: luma min width is 4
    187       pDstY[x] = weightUnidir(w0,pSrcY0[x], round, shift, offset); x--;
    188       pDstY[x] = weightUnidir(w0,pSrcY0[x], round, shift, offset); x--;
    189       pDstY[x] = weightUnidir(w0,pSrcY0[x], round, shift, offset); x--;
    190       pDstY[x] = weightUnidir(w0,pSrcY0[x], round, shift, offset); x--;
     206      pDstY[x] = weightUnidirY(w0,pSrcY0[x], round, shift, offset); x--;
     207      pDstY[x] = weightUnidirY(w0,pSrcY0[x], round, shift, offset); x--;
     208      pDstY[x] = weightUnidirY(w0,pSrcY0[x], round, shift, offset); x--;
     209      pDstY[x] = weightUnidirY(w0,pSrcY0[x], round, shift, offset); x--;
    191210    }
    192211    pSrcY0 += iSrc0Stride;
     
    197216  w0      = wp0[1].w;
    198217  offset  = wp0[1].offset;
     218  shiftNum = IF_INTERNAL_PREC - g_bitDepthC;
    199219  shift   = wp0[1].shift + shiftNum;
    200   round   = (1<<(shift-1));
     220  round   = shift?(1<<(shift-1)):0;
    201221
    202222  iSrc0Stride = pcYuvSrc0->getCStride();
     
    211231    {
    212232      // note: chroma min width is 2
    213       pDstU[x] = weightUnidir(w0,pSrcU0[x], round, shift, offset); x--;
    214       pDstU[x] = weightUnidir(w0,pSrcU0[x], round, shift, offset); x--;
     233      pDstU[x] = weightUnidirC(w0,pSrcU0[x], round, shift, offset); x--;
     234      pDstU[x] = weightUnidirC(w0,pSrcU0[x], round, shift, offset); x--;
    215235    }
    216236    pSrcU0 += iSrc0Stride;
     
    222242  offset  = wp0[2].offset;
    223243  shift   = wp0[2].shift + shiftNum;
    224   round   = (1<<(shift-1));
     244  round   = shift?(1<<(shift-1)):0;
    225245
    226246  for ( y = iHeight-1; y >= 0; y-- )
     
    229249    {
    230250      // note: chroma min width is 2
    231       pDstV[x] = weightUnidir(w0,pSrcV0[x], round, shift, offset); x--;
    232       pDstV[x] = weightUnidir(w0,pSrcV0[x], round, shift, offset); x--;
     251      pDstV[x] = weightUnidirC(w0,pSrcV0[x], round, shift, offset); x--;
     252      pDstV[x] = weightUnidirC(w0,pSrcV0[x], round, shift, offset); x--;
    233253    }
    234254    pSrcV0 += iSrc0Stride;
     
    249269 * \returns Void
    250270 */
    251 Void TComWeightPrediction::getWpScaling( TComDataCU* pcCU, Int iRefIdx0, Int iRefIdx1, wpScalingParam *&wp0, wpScalingParam *&wp1, Int ibdi)
    252 {
     271Void TComWeightPrediction::getWpScaling( TComDataCU* pcCU, Int iRefIdx0, Int iRefIdx1, wpScalingParam *&wp0, wpScalingParam *&wp1)
     272{
     273  assert(iRefIdx0 >= 0 || iRefIdx1 >= 0);
     274 
    253275  TComSlice*      pcSlice       = pcCU->getSlice();
    254276  TComPPS*        pps           = pcCU->getSlice()->getPPS();
    255   UInt            uiWPBiPredIdc = pps->getWPBiPredIdc();
     277  Bool            wpBiPred = pps->getWPBiPred();
    256278  wpScalingParam* pwp;
    257279  Bool            bBiDir        = (iRefIdx0>=0 && iRefIdx1>=0);
    258280  Bool            bUniDir       = !bBiDir;
    259281
    260   m_ibdi = ibdi;
    261 
    262   if ( bUniDir || (uiWPBiPredIdc==1) )
     282  if ( bUniDir || wpBiPred )
    263283  { // explicit --------------------
    264284    if ( iRefIdx0 >= 0 )
     
    271291    }
    272292  }
    273   else if ( uiWPBiPredIdc == 2 )
    274   { // implicit --------------------
    275     Int poc0    = pcSlice->getRefPOC(REF_PIC_LIST_0, iRefIdx0);
    276     Int poc1    = pcSlice->getRefPOC(REF_PIC_LIST_1, iRefIdx1);
    277     Int pocCur  = pcSlice->getPOC();
    278     Int td      = Clip3(-128,127,poc1 - poc0);
    279     Int tb      = Clip3(-128,127,pocCur - poc0);
    280     Int tx      = ( td != 0 ) ? ( ( 16384 + abs( td / 2 ) ) / td ) : (0);
    281     Int DistScaleFactor = Clip3( -1024, 1023, ( tb * tx + 32 ) >> 6 );
    282 
    283     Bool  implicitScale=true;
    284     if ( poc1==poc0 || (DistScaleFactor>>2)<(-64) || (DistScaleFactor>>2)>128 )
    285     {
    286       implicitScale = false;
    287     }
    288 
    289     for ( int e=0 ; e<2 ; e++ )
    290     {
    291       pwp = (e==0) ? m_wp0 : m_wp1;
    292       for ( int k=0 ; k<3 ; k++ ) // 3 components: Y,U,V
    293       {   
    294         pwp->uiLog2WeightDenom = 5;  pwp->iOffset = 0;  pwp->bPresentFlag = true; 
    295         if ( implicitScale )
    296         {
    297           pwp->iWeight = (e==0) ? (64 - (DistScaleFactor >> 2)) : (DistScaleFactor >> 2);
    298         }
    299         else
    300         {
    301           pwp->iWeight = 32;
    302         }
    303         pwp++;
    304       }
    305 
    306     }
    307 
    308     wp0 = m_wp0;
    309     wp1 = m_wp1;
    310   }
    311293  else
    312294  {
     
    325307  if ( bBiDir )
    326308  { // Bi-Dir case
    327     for ( int yuv=0 ; yuv<3 ; yuv++ )
    328     {
     309    for ( Int yuv=0 ; yuv<3 ; yuv++ )
     310    {
     311      Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY;
    329312      wp0[yuv].w      = wp0[yuv].iWeight;
    330       wp0[yuv].o      = wp0[yuv].iOffset * (1 << (m_ibdi-8));
     313      wp0[yuv].o      = wp0[yuv].iOffset * (1 << (bitDepth-8));
    331314      wp1[yuv].w      = wp1[yuv].iWeight;
    332       wp1[yuv].o      = wp1[yuv].iOffset * (1 << (m_ibdi-8));
     315      wp1[yuv].o      = wp1[yuv].iOffset * (1 << (bitDepth-8));
    333316      wp0[yuv].offset = wp0[yuv].o + wp1[yuv].o;
    334317      wp0[yuv].shift  = wp0[yuv].uiLog2WeightDenom + 1;
     
    342325  {  // Unidir
    343326    pwp = (iRefIdx0>=0) ? wp0 : wp1 ;
    344     if ( uiWPBiPredIdc == 2 )
    345     {
    346       for ( int yuv=0 ; yuv<3 ; yuv++ )
    347       {
    348         pwp[yuv].w      = 1;
    349         pwp[yuv].offset = 0;
    350         pwp[yuv].shift  = 0;
    351         pwp[yuv].round  = 0;
    352       }
    353     }
    354     else {
    355       for ( int yuv=0 ; yuv<3 ; yuv++ )
    356       {
    357         pwp[yuv].w      = pwp[yuv].iWeight;
    358         pwp[yuv].offset = pwp[yuv].iOffset * (1 << (m_ibdi-8));
    359         pwp[yuv].shift  = pwp[yuv].uiLog2WeightDenom;
    360         pwp[yuv].round  = (pwp[yuv].uiLog2WeightDenom>=1) ? (1 << (pwp[yuv].uiLog2WeightDenom-1)) : (0);
    361       }
     327    for ( Int yuv=0 ; yuv<3 ; yuv++ )
     328    {
     329      Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY;
     330      pwp[yuv].w      = pwp[yuv].iWeight;
     331      pwp[yuv].offset = pwp[yuv].iOffset * (1 << (bitDepth-8));
     332      pwp[yuv].shift  = pwp[yuv].uiLog2WeightDenom;
     333      pwp[yuv].round  = (pwp[yuv].uiLog2WeightDenom>=1) ? (1 << (pwp[yuv].uiLog2WeightDenom-1)) : (0);
    362334    }
    363335  }
     
    380352  wpScalingParam  *pwp0, *pwp1;
    381353  TComPPS         *pps = pcCU->getSlice()->getPPS();
    382 
    383   assert( pps->getWPBiPredIdc() != 0 );
    384 
    385   Int ibdi = (g_uiBitDepth+g_uiBitIncrement);
    386   getWpScaling(pcCU, iRefIdx0, iRefIdx1, pwp0, pwp1, ibdi);
     354  assert( pps->getWPBiPred());
     355
     356  getWpScaling(pcCU, iRefIdx0, iRefIdx1, pwp0, pwp1);
    387357
    388358  if( iRefIdx0 >= 0 && iRefIdx1 >= 0 )
     
    416386 * \returns Void
    417387 */
    418 Void TComWeightPrediction::xWeightedPredictionUni( TComDataCU* pcCU, TComYuv* pcYuvSrc, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Int iRefIdx)
     388Void TComWeightPrediction::xWeightedPredictionUni( TComDataCU* pcCU, TComYuv* pcYuvSrc, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iRefIdx)
    419389{
    420390  wpScalingParam  *pwp, *pwpTmp;
     
    425395  assert (iRefIdx >= 0);
    426396
    427   Int ibdi = (g_uiBitDepth+g_uiBitIncrement);
    428 
    429397  if ( eRefPicList == REF_PIC_LIST_0 )
    430398  {
    431     getWpScaling(pcCU, iRefIdx, -1, pwp, pwpTmp, ibdi);
     399    getWpScaling(pcCU, iRefIdx, -1, pwp, pwpTmp);
    432400  }
    433401  else
    434402  {
    435     getWpScaling(pcCU, -1, iRefIdx, pwpTmp, pwp, ibdi);
     403    getWpScaling(pcCU, -1, iRefIdx, pwpTmp, pwp);
    436404  }
    437405  addWeightUni( pcYuvSrc, uiPartAddr, iWidth, iHeight, pwp, rpcYuvPred );
Note: See TracChangeset for help on using the changeset viewer.