Ignore:
Timestamp:
13 Aug 2015, 17:38:13 (9 years ago)
Author:
tech
Message:

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibEncoder/WeightPredAnalysis.cpp

    r1179 r1313  
    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-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3636*/
    3737
    38 #include "../TLibCommon/TypeDef.h"
     38#include "../TLibCommon/CommonDef.h"
    3939#include "../TLibCommon/TComSlice.h"
    4040#include "../TLibCommon/TComPic.h"
     
    4747WeightPredAnalysis::WeightPredAnalysis()
    4848{
    49   m_weighted_pred_flag = false;
    50   m_weighted_bipred_flag = false;
    51   for ( Int iList =0 ; iList<2 ; iList++ )
    52   {
    53     for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
    54     {
    55       for ( Int comp=0 ; comp<3 ;comp++ )
    56       {
    57         wpScalingParam  *pwp   = &(m_wp[iList][iRefIdx][comp]);
     49  for ( UInt lst =0 ; lst<NUM_REF_PIC_LIST_01 ; lst++ )
     50  {
     51    for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
     52    {
     53      for ( Int comp=0 ; comp<MAX_NUM_COMPONENT ;comp++ )
     54      {
     55        WPScalingParam  *pwp   = &(m_wp[lst][iRefIdx][comp]);
    5856        pwp->bPresentFlag      = false;
    5957        pwp->uiLog2WeightDenom = 0;
     
    6563}
    6664
    67 /** calculate AC and DC values for current original image
    68  * \param TComSlice *slice
    69  * \returns Void
    70  */
    71 Bool  WeightPredAnalysis::xCalcACDCParamSlice(TComSlice *slice)
     65
     66//! calculate AC and DC values for current original image
     67Void WeightPredAnalysis::xCalcACDCParamSlice(TComSlice *const slice)
    7268{
    7369  //===== calculate AC/DC value =====
    7470  TComPicYuv*   pPic = slice->getPic()->getPicYuvOrg();
    75   Int   iSample  = 0;
    76 
    77   // calculate DC/AC value for Y
    78   Pel*  pOrg    = pPic->getLumaAddr();
    79   Int64  iOrgDCY = xCalcDCValueSlice(slice, pOrg, &iSample);
    80   Int64  iOrgNormDCY = ((iOrgDCY+(iSample>>1)) / iSample);
    81   pOrg = pPic->getLumaAddr();
    82   Int64  iOrgACY  = xCalcACValueSlice(slice, pOrg, iOrgNormDCY);
    83 
    84   // calculate DC/AC value for Cb
    85   pOrg = pPic->getCbAddr();
    86   Int64  iOrgDCCb = xCalcDCValueUVSlice(slice, pOrg, &iSample);
    87   Int64  iOrgNormDCCb = ((iOrgDCCb+(iSample>>1)) / (iSample));
    88   pOrg = pPic->getCbAddr();
    89   Int64  iOrgACCb  = xCalcACValueUVSlice(slice, pOrg, iOrgNormDCCb);
    90 
    91   // calculate DC/AC value for Cr
    92   pOrg = pPic->getCrAddr();
    93   Int64  iOrgDCCr = xCalcDCValueUVSlice(slice, pOrg, &iSample);
    94   Int64  iOrgNormDCCr = ((iOrgDCCr+(iSample>>1)) / (iSample));
    95   pOrg = pPic->getCrAddr();
    96   Int64  iOrgACCr  = xCalcACValueUVSlice(slice, pOrg, iOrgNormDCCr);
    97 
    98   wpACDCParam weightACDCParam[3];
    99   weightACDCParam[0].iAC = iOrgACY;
    100   weightACDCParam[0].iDC = iOrgNormDCY;
    101   weightACDCParam[1].iAC = iOrgACCb;
    102   weightACDCParam[1].iDC = iOrgNormDCCb;
    103   weightACDCParam[2].iAC = iOrgACCr;
    104   weightACDCParam[2].iDC = iOrgNormDCCr;
     71
     72  WPACDCParam weightACDCParam[MAX_NUM_COMPONENT];
     73
     74  for(Int componentIndex = 0; componentIndex < pPic->getNumberValidComponents(); componentIndex++)
     75  {
     76    const ComponentID compID = ComponentID(componentIndex);
     77
     78    // calculate DC/AC value for channel
     79
     80    const Int iStride = pPic->getStride(compID);
     81    const Int iWidth  = pPic->getWidth(compID);
     82    const Int iHeight = pPic->getHeight(compID);
     83
     84    const Int iSample = iWidth*iHeight;
     85
     86    Int64 iOrgDC = 0;
     87    {
     88      const Pel *pPel = pPic->getAddr(compID);
     89
     90      for(Int y = 0; y < iHeight; y++, pPel+=iStride )
     91      {
     92        for(Int x = 0; x < iWidth; x++ )
     93        {
     94          iOrgDC += (Int)( pPel[x] );
     95        }
     96      }
     97    }
     98
     99    const Int64 iOrgNormDC = ((iOrgDC+(iSample>>1)) / iSample);
     100
     101    Int64 iOrgAC = 0;
     102    {
     103      const Pel *pPel = pPic->getAddr(compID);
     104
     105      for(Int y = 0; y < iHeight; y++, pPel += iStride )
     106      {
     107        for(Int x = 0; x < iWidth; x++ )
     108        {
     109          iOrgAC += abs( (Int)pPel[x] - (Int)iOrgNormDC );
     110        }
     111      }
     112    }
     113
     114    const Int fixedBitShift = (slice->getSPS()->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag())?RExt__PREDICTION_WEIGHTING_ANALYSIS_DC_PRECISION:0;
     115    weightACDCParam[compID].iDC = (((iOrgDC<<fixedBitShift)+(iSample>>1)) / iSample);
     116    weightACDCParam[compID].iAC = iOrgAC;
     117  }
    105118
    106119  slice->setWpAcDcParam(weightACDCParam);
    107   return (true);
    108 }
    109 
    110 /** store weighted_pred_flag and weighted_bipred_idc values
    111  * \param weighted_pred_flag
    112  * \param weighted_bipred_idc
    113  * \returns Void
    114  */
    115 Void  WeightPredAnalysis::xStoreWPparam(Bool weighted_pred_flag, Bool weighted_bipred_flag)
    116 {
    117   m_weighted_pred_flag = weighted_pred_flag;
    118   m_weighted_bipred_flag = weighted_bipred_flag;
    119 }
    120 
    121 /** restore weighted_pred_flag and weighted_bipred_idc values
    122  * \param TComSlice *slice
    123  * \returns Void
    124  */
    125 Void  WeightPredAnalysis::xRestoreWPparam(TComSlice *slice)
    126 {
    127   slice->getPPS()->setUseWP(m_weighted_pred_flag);
    128   slice->getPPS()->setWPBiPred(m_weighted_bipred_flag);
    129 }
    130 
    131 /** check weighted pred or non-weighted pred
    132  * \param TComSlice *slice
    133  * \returns Void
    134  */
    135 Void  WeightPredAnalysis::xCheckWPEnable(TComSlice *slice)
    136 {
     120}
     121
     122
     123//! check weighted pred or non-weighted pred
     124Void  WeightPredAnalysis::xCheckWPEnable(TComSlice *const slice)
     125{
     126  const TComPicYuv *pPic = slice->getPic()->getPicYuvOrg();
     127
    137128  Int iPresentCnt = 0;
    138   for ( Int iList=0 ; iList<2 ; iList++ )
    139   {
    140     for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
    141     {
    142       for ( Int iComp=0 ; iComp<3 ;iComp++ )
    143       {
    144         wpScalingParam  *pwp = &(m_wp[iList][iRefIdx][iComp]);
     129  for ( UInt lst=0 ; lst<NUM_REF_PIC_LIST_01 ; lst++ )
     130  {
     131    for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
     132    {
     133      for(Int componentIndex = 0; componentIndex < pPic->getNumberValidComponents(); componentIndex++)
     134      {
     135        WPScalingParam  *pwp = &(m_wp[lst][iRefIdx][componentIndex]);
    145136        iPresentCnt += (Int)pwp->bPresentFlag;
    146137      }
     
    150141  if(iPresentCnt==0)
    151142  {
    152     slice->getPPS()->setUseWP(false);
    153     slice->getPPS()->setWPBiPred(false);
    154     for ( Int iList=0 ; iList<2 ; iList++ )
    155     {
    156       for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
    157       {
    158         for ( Int iComp=0 ; iComp<3 ;iComp++ )
    159         {
    160           wpScalingParam  *pwp = &(m_wp[iList][iRefIdx][iComp]);
     143    slice->setTestWeightPred(false);
     144    slice->setTestWeightBiPred(false);
     145
     146    for ( UInt lst=0 ; lst<NUM_REF_PIC_LIST_01 ; lst++ )
     147    {
     148      for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
     149      {
     150        for(Int componentIndex = 0; componentIndex < pPic->getNumberValidComponents(); componentIndex++)
     151        {
     152          WPScalingParam  *pwp = &(m_wp[lst][iRefIdx][componentIndex]);
     153
    161154          pwp->bPresentFlag      = false;
    162155          pwp->uiLog2WeightDenom = 0;
     
    168161    slice->setWpScaling( m_wp );
    169162  }
    170 }
    171 
    172 /** estimate wp tables for explicit wp
    173  * \param TComSlice *slice
    174  * \returns Bool
    175  */
    176 Bool  WeightPredAnalysis::xEstimateWPParamSlice(TComSlice *slice)
    177 {
    178   Int iDenom  = 6;
     163  else
     164  {
     165    slice->setTestWeightPred(slice->getPPS()->getUseWP());
     166    slice->setTestWeightBiPred(slice->getPPS()->getWPBiPred());
     167  }
     168}
     169
     170
     171//! estimate wp tables for explicit wp
     172Void WeightPredAnalysis::xEstimateWPParamSlice(TComSlice *const slice)
     173{
     174  Int  iDenom         = 6;
    179175  Bool validRangeFlag = false;
    180176
    181177  if(slice->getNumRefIdx(REF_PIC_LIST_0)>3)
    182178  {
    183     iDenom  = 7;
     179    iDenom = 7;
    184180  }
    185181
    186182  do
    187183  {
    188     validRangeFlag = xUpdatingWPParameters(slice, m_wp, iDenom);
     184    validRangeFlag = xUpdatingWPParameters(slice, iDenom);
    189185    if (!validRangeFlag)
    190186    {
     
    193189  } while (validRangeFlag == false);
    194190
    195   // selecting whether WP is used, or not
    196   xSelectWP(slice, m_wp, iDenom);
    197  
     191  // selecting whether WP is used, or not (fast search)
     192  // NOTE: This is not operating on a slice, but the entire picture.
     193  xSelectWP(slice, iDenom);
     194
    198195  slice->setWpScaling( m_wp );
    199 
    200   return (true);
    201 }
    202 
    203 /** update wp tables for explicit wp w.r.t ramge limitation
    204  * \param TComSlice *slice
    205  * \returns Bool
    206  */
    207 Bool WeightPredAnalysis::xUpdatingWPParameters(TComSlice *slice, wpScalingParam weightPredTable[2][MAX_NUM_REF][3], Int log2Denom)
    208 {
    209   Int numPredDir = slice->isInterP() ? 1 : 2;
     196}
     197
     198
     199//! update wp tables for explicit wp w.r.t range limitation
     200Bool WeightPredAnalysis::xUpdatingWPParameters(TComSlice *const slice, const Int log2Denom)
     201{
     202  const Int  numComp                    = slice->getPic()->getPicYuvOrg()->getNumberValidComponents();
     203  const Bool bUseHighPrecisionWeighting = slice->getSPS()->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag();
     204  const Int numPredDir                  = slice->isInterP() ? 1 : 2;
     205
     206  assert (numPredDir <= Int(NUM_REF_PIC_LIST_01));
     207
    210208  for ( Int refList = 0; refList < numPredDir; refList++ )
    211209  {
    212     RefPicList  eRefPicList = ( refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
     210    const RefPicList eRefPicList = ( refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
     211
    213212    for ( Int refIdxTemp = 0; refIdxTemp < slice->getNumRefIdx(eRefPicList); refIdxTemp++ )
    214213    {
    215       wpACDCParam *currWeightACDCParam, *refWeightACDCParam;
     214      WPACDCParam *currWeightACDCParam, *refWeightACDCParam;
    216215      slice->getWpAcDcParam(currWeightACDCParam);
    217216      slice->getRefPic(eRefPicList, refIdxTemp)->getSlice(0)->getWpAcDcParam(refWeightACDCParam);
    218217
    219       for ( Int comp = 0; comp < 3; comp++ )
    220       {
    221         Int bitDepth = comp ? g_bitDepthC : g_bitDepthY;
    222         Int realLog2Denom = log2Denom + bitDepth-8;
    223         Int realOffset = ((Int)1<<(realLog2Denom-1));
     218      for ( Int comp = 0; comp < numComp; comp++ )
     219      {
     220        const ComponentID compID        = ComponentID(comp);
     221        const Int         bitDepth      = slice->getSPS()->getBitDepth(toChannelType(compID));
     222        const Int         range         = bUseHighPrecisionWeighting ? (1<<bitDepth)/2 : 128;
     223        const Int         realLog2Denom = log2Denom + (bUseHighPrecisionWeighting ? RExt__PREDICTION_WEIGHTING_ANALYSIS_DC_PRECISION : (bitDepth - 8));
     224        const Int         realOffset    = ((Int)1<<(realLog2Denom-1));
    224225
    225226        // current frame
    226         Int64 currDC = currWeightACDCParam[comp].iDC;
    227         Int64 currAC = currWeightACDCParam[comp].iAC;
     227        const Int64 currDC = currWeightACDCParam[comp].iDC;
     228        const Int64 currAC = currWeightACDCParam[comp].iAC;
    228229        // reference frame
    229         Int64 refDC = refWeightACDCParam[comp].iDC;
    230         Int64 refAC = refWeightACDCParam[comp].iAC;
     230        const Int64 refDC = refWeightACDCParam[comp].iDC;
     231        const Int64 refAC = refWeightACDCParam[comp].iAC;
    231232
    232233        // calculating iWeight and iOffset params
    233         Double dWeight = (refAC==0) ? (Double)1.0 : Clip3( -16.0, 15.0, ((Double)currAC / (Double)refAC) );
    234         Int weight = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) );
    235         Int offset = (Int)( ((currDC<<log2Denom) - ((Int64)weight * refDC) + (Int64)realOffset) >> realLog2Denom );
    236 
    237         // Chroma offset range limitation
    238         if(comp)
    239         {
    240           Int pred = ( 128 - ( ( 128*weight)>>(log2Denom) ) );
    241           Int deltaOffset = Clip3( -512, 511, (offset - pred) );    // signed 10bit
    242           offset = Clip3( -128, 127, (deltaOffset + pred) );        // signed 8bit
    243         }
    244         // Luma offset range limitation
    245         else
    246         {
    247           offset = Clip3( -128, 127, offset);
     234        const Double dWeight = (refAC==0) ? (Double)1.0 : Clip3( -16.0, 15.0, ((Double)currAC / (Double)refAC) );
     235        const Int weight    = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) );
     236        const Int offset    = (Int)( ((currDC<<log2Denom) - ((Int64)weight * refDC) + (Int64)realOffset) >> realLog2Denom );
     237
     238        Int clippedOffset;
     239        if(isChroma(compID)) // Chroma offset range limination
     240        {
     241          const Int pred        = ( range - ( ( range*weight)>>(log2Denom) ) );
     242          const Int deltaOffset = Clip3( -4*range, 4*range-1, (offset - pred) ); // signed 10bit
     243
     244          clippedOffset = Clip3( -range, range-1, (deltaOffset + pred) );  // signed 8bit
     245        }
     246        else // Luma offset range limitation
     247        {
     248          clippedOffset = Clip3( -range, range-1, offset);
    248249        }
    249250
    250251        // Weighting factor limitation
    251         Int defaultWeight = (1<<log2Denom);
    252         Int deltaWeight = (defaultWeight - weight);
    253         if(deltaWeight > 127 || deltaWeight < -128)
    254           return (false);
    255 
    256         m_wp[refList][refIdxTemp][comp].bPresentFlag = true;
    257         m_wp[refList][refIdxTemp][comp].iWeight = (Int)weight;
    258         m_wp[refList][refIdxTemp][comp].iOffset = (Int)offset;
    259         m_wp[refList][refIdxTemp][comp].uiLog2WeightDenom = (Int)log2Denom;
    260       }
    261     }
    262   }
    263   return (true);
    264 }
    265 
    266 /** select whether weighted pred enables or not.
    267  * \param TComSlice *slice
    268  * \param wpScalingParam
    269  * \param iDenom
    270  * \returns Bool
    271  */
    272 Bool WeightPredAnalysis::xSelectWP(TComSlice *slice, wpScalingParam weightPredTable[2][MAX_NUM_REF][3], Int iDenom)
    273 {
    274   TComPicYuv*   pPic = slice->getPic()->getPicYuvOrg();
    275   Int iWidth  = pPic->getWidth();
    276   Int iHeight = pPic->getHeight();
    277   Int iDefaultWeight = ((Int)1<<iDenom);
    278   Int iNumPredDir = slice->isInterP() ? 1 : 2;
     252        const Int defaultWeight = (1<<log2Denom);
     253        const Int deltaWeight  = (defaultWeight - weight);
     254
     255        if(deltaWeight >= range || deltaWeight < -range)
     256        {
     257          return false;
     258        }
     259
     260        m_wp[refList][refIdxTemp][comp].bPresentFlag      = true;
     261        m_wp[refList][refIdxTemp][comp].iWeight           = weight;
     262        m_wp[refList][refIdxTemp][comp].iOffset           = clippedOffset;
     263        m_wp[refList][refIdxTemp][comp].uiLog2WeightDenom = log2Denom;
     264      }
     265    }
     266  }
     267  return true;
     268}
     269
     270
     271//! select whether weighted pred enables or not.
     272Bool WeightPredAnalysis::xSelectWP(TComSlice *const slice, const Int log2Denom)
     273{
     274        TComPicYuv *const pPic                                = slice->getPic()->getPicYuvOrg();
     275  const Int               iDefaultWeight                      = ((Int)1<<log2Denom);
     276  const Int               iNumPredDir                         = slice->isInterP() ? 1 : 2;
     277  const Bool              useHighPrecisionPredictionWeighting = slice->getSPS()->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag();
     278
     279  assert (iNumPredDir <= Int(NUM_REF_PIC_LIST_01));
    279280
    280281  for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ )
    281282  {
    282     Int64 iSADWP = 0, iSADnoWP = 0;
    283     RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
     283    const RefPicList eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
     284
    284285    for ( Int iRefIdxTemp = 0; iRefIdxTemp < slice->getNumRefIdx(eRefPicList); iRefIdxTemp++ )
    285286    {
    286       Pel*  pOrg    = pPic->getLumaAddr();
    287       Pel*  pRef    = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getLumaAddr();
    288       Int   iOrgStride = pPic->getStride();
    289       Int   iRefStride = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getStride();
    290 
    291       // calculate SAD costs with/without wp for luma
    292       iSADWP   = this->xCalcSADvalueWP(g_bitDepthY, pOrg, pRef, iWidth, iHeight, iOrgStride, iRefStride, iDenom, weightPredTable[iRefList][iRefIdxTemp][0].iWeight, weightPredTable[iRefList][iRefIdxTemp][0].iOffset);
    293       iSADnoWP = this->xCalcSADvalueWP(g_bitDepthY, pOrg, pRef, iWidth, iHeight, iOrgStride, iRefStride, iDenom, iDefaultWeight, 0);
    294 
    295       pOrg = pPic->getCbAddr();
    296       pRef = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getCbAddr();
    297       iOrgStride = pPic->getCStride();
    298       iRefStride = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getCStride();
    299 
    300       // calculate SAD costs with/without wp for chroma cb
    301       iSADWP   += this->xCalcSADvalueWP(g_bitDepthC, pOrg, pRef, iWidth>>1, iHeight>>1, iOrgStride, iRefStride, iDenom, weightPredTable[iRefList][iRefIdxTemp][1].iWeight, weightPredTable[iRefList][iRefIdxTemp][1].iOffset);
    302       iSADnoWP += this->xCalcSADvalueWP(g_bitDepthC, pOrg, pRef, iWidth>>1, iHeight>>1, iOrgStride, iRefStride, iDenom, iDefaultWeight, 0);
    303 
    304       pOrg = pPic->getCrAddr();
    305       pRef = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getCrAddr();
    306 
    307       // calculate SAD costs with/without wp for chroma cr
    308       iSADWP   += this->xCalcSADvalueWP(g_bitDepthC, pOrg, pRef, iWidth>>1, iHeight>>1, iOrgStride, iRefStride, iDenom, weightPredTable[iRefList][iRefIdxTemp][2].iWeight, weightPredTable[iRefList][iRefIdxTemp][2].iOffset);
    309       iSADnoWP += this->xCalcSADvalueWP(g_bitDepthC, pOrg, pRef, iWidth>>1, iHeight>>1, iOrgStride, iRefStride, iDenom, iDefaultWeight, 0);
    310 
    311       Double dRatio = ((Double)iSADWP / (Double)iSADnoWP);
     287      Int64 iSADWP = 0, iSADnoWP = 0;
     288
     289      for(Int comp=0; comp<pPic->getNumberValidComponents(); comp++)
     290      {
     291        const ComponentID  compID     = ComponentID(comp);
     292              Pel         *pOrg       = pPic->getAddr(compID);
     293              Pel         *pRef       = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getAddr(compID);
     294        const Int          iOrgStride = pPic->getStride(compID);
     295        const Int          iRefStride = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getStride(compID);
     296        const Int          iWidth     = pPic->getWidth(compID);
     297        const Int          iHeight    = pPic->getHeight(compID);
     298        const Int          bitDepth   = slice->getSPS()->getBitDepth(toChannelType(compID));
     299
     300        // calculate SAD costs with/without wp for luma
     301        iSADWP   += xCalcSADvalueWP(bitDepth, pOrg, pRef, iWidth, iHeight, iOrgStride, iRefStride, log2Denom, m_wp[iRefList][iRefIdxTemp][compID].iWeight, m_wp[iRefList][iRefIdxTemp][compID].iOffset, useHighPrecisionPredictionWeighting);
     302        iSADnoWP += xCalcSADvalueWP(bitDepth, pOrg, pRef, iWidth, iHeight, iOrgStride, iRefStride, log2Denom, iDefaultWeight, 0, useHighPrecisionPredictionWeighting);
     303      }
     304
     305      const Double dRatio = ((Double)iSADWP / (Double)iSADnoWP);
    312306      if(dRatio >= (Double)DTHRESH)
    313307      {
    314         for ( Int iComp = 0; iComp < 3; iComp++ )
    315         {
    316           weightPredTable[iRefList][iRefIdxTemp][iComp].bPresentFlag = false;
    317           weightPredTable[iRefList][iRefIdxTemp][iComp].iOffset = (Int)0;
    318           weightPredTable[iRefList][iRefIdxTemp][iComp].iWeight = (Int)iDefaultWeight;
    319           weightPredTable[iRefList][iRefIdxTemp][iComp].uiLog2WeightDenom = (Int)iDenom;
    320         }
    321       }
    322     }
    323   }
    324   return (true);
    325 }
    326 
    327 /** calculate DC value of original image for luma.
    328  * \param TComSlice *slice
    329  * \param Pel *pPel
    330  * \param Int *iSample
    331  * \returns Int64
    332  */
    333 Int64 WeightPredAnalysis::xCalcDCValueSlice(TComSlice *slice, Pel *pPel, Int *iSample)
    334 {
    335   TComPicYuv* pPic = slice->getPic()->getPicYuvOrg();
    336   Int iStride = pPic->getStride();
    337 
    338   *iSample = 0;
    339   Int iWidth  = pPic->getWidth();
    340   Int iHeight = pPic->getHeight();
    341   *iSample = iWidth*iHeight;
    342   Int64 iDC = xCalcDCValue(pPel, iWidth, iHeight, iStride);
    343 
    344   return (iDC);
    345 }
    346 
    347 /** calculate AC value of original image for luma.
    348  * \param TComSlice *slice
    349  * \param Pel *pPel
    350  * \param Int iDC
    351  * \returns Int64
    352  */
    353 Int64 WeightPredAnalysis::xCalcACValueSlice(TComSlice *slice, Pel *pPel, Int64 iDC)
    354 {
    355   TComPicYuv* pPic = slice->getPic()->getPicYuvOrg();
    356   Int iStride = pPic->getStride();
    357 
    358   Int iWidth  = pPic->getWidth();
    359   Int iHeight = pPic->getHeight();
    360   Int64 iAC = xCalcACValue(pPel, iWidth, iHeight, iStride, iDC);
    361 
    362   return (iAC);
    363 }
    364 
    365 /** calculate DC value of original image for chroma.
    366  * \param TComSlice *slice
    367  * \param Pel *pPel
    368  * \param Int *iSample
    369  * \returns Int64
    370  */
    371 Int64 WeightPredAnalysis::xCalcDCValueUVSlice(TComSlice *slice, Pel *pPel, Int *iSample)
    372 {
    373   TComPicYuv* pPic = slice->getPic()->getPicYuvOrg();
    374   Int iCStride = pPic->getCStride();
    375 
    376   *iSample = 0;
    377   Int iWidth  = pPic->getWidth()>>1;
    378   Int iHeight = pPic->getHeight()>>1;
    379   *iSample = iWidth*iHeight;
    380   Int64 iDC = xCalcDCValue(pPel, iWidth, iHeight, iCStride);
    381 
    382   return (iDC);
    383 }
    384 
    385 /** calculate AC value of original image for chroma.
    386  * \param TComSlice *slice
    387  * \param Pel *pPel
    388  * \param Int iDC
    389  * \returns Int64
    390  */
    391 Int64 WeightPredAnalysis::xCalcACValueUVSlice(TComSlice *slice, Pel *pPel, Int64 iDC)
    392 {
    393   TComPicYuv* pPic = slice->getPic()->getPicYuvOrg();
    394   Int iCStride = pPic->getCStride();
    395 
    396   Int iWidth  = pPic->getWidth()>>1;
    397   Int iHeight = pPic->getHeight()>>1;
    398   Int64 iAC = xCalcACValue(pPel, iWidth, iHeight, iCStride, iDC);
    399 
    400   return (iAC);
    401 }
    402 
    403 /** calculate DC value.
    404  * \param Pel *pPel
    405  * \param Int iWidth
    406  * \param Int iHeight
    407  * \param Int iStride
    408  * \returns Int64
    409  */
    410 Int64 WeightPredAnalysis::xCalcDCValue(Pel *pPel, Int iWidth, Int iHeight, Int iStride)
    411 {
    412   Int x, y;
    413   Int64 iDC = 0;
    414   for( y = 0; y < iHeight; y++ )
    415   {
    416     for( x = 0; x < iWidth; x++ )
    417     {
    418       iDC += (Int)( pPel[x] );
    419     }
    420     pPel += iStride;
    421   }
    422   return (iDC);
    423 }
    424 
    425 /** calculate AC value.
    426  * \param Pel *pPel
    427  * \param Int iWidth
    428  * \param Int iHeight
    429  * \param Int iStride
    430  * \param Int iDC
    431  * \returns Int64
    432  */
    433 Int64 WeightPredAnalysis::xCalcACValue(Pel *pPel, Int iWidth, Int iHeight, Int iStride, Int64 iDC)
    434 {
    435   Int x, y;
    436   Int64 iAC = 0;
    437   for( y = 0; y < iHeight; y++ )
    438   {
    439     for( x = 0; x < iWidth; x++ )
    440     {
    441       iAC += abs( (Int)pPel[x] - (Int)iDC );
    442     }
    443     pPel += iStride;
    444   }
    445   return (iAC);
    446 }
    447 
    448 /** calculate SAD values for both WP version and non-WP version.
    449  * \param Pel *pOrgPel
    450  * \param Pel *pRefPel
    451  * \param Int iWidth
    452  * \param Int iHeight
    453  * \param Int iOrgStride
    454  * \param Int iRefStride
    455  * \param Int iDenom
    456  * \param Int iWeight
    457  * \param Int iOffset
    458  * \returns Int64
    459  */
    460 Int64 WeightPredAnalysis::xCalcSADvalueWP(Int bitDepth, Pel *pOrgPel, Pel *pRefPel, Int iWidth, Int iHeight, Int iOrgStride, Int iRefStride, Int iDenom, Int iWeight, Int iOffset)
    461 {
    462   Int x, y;
     308        for(Int comp=0; comp<pPic->getNumberValidComponents(); comp++)
     309        {
     310          m_wp[iRefList][iRefIdxTemp][comp].bPresentFlag      = false;
     311          m_wp[iRefList][iRefIdxTemp][comp].iOffset           = 0;
     312          m_wp[iRefList][iRefIdxTemp][comp].iWeight           = iDefaultWeight;
     313          m_wp[iRefList][iRefIdxTemp][comp].uiLog2WeightDenom = log2Denom;
     314        }
     315      }
     316    }
     317  }
     318
     319  return true;
     320}
     321
     322
     323//! calculate SAD values for both WP version and non-WP version.
     324Int64 WeightPredAnalysis::xCalcSADvalueWP(const Int   bitDepth,
     325                                          const Pel  *pOrgPel,
     326                                          const Pel  *pRefPel,
     327                                          const Int   iWidth,
     328                                          const Int   iHeight,
     329                                          const Int   iOrgStride,
     330                                          const Int   iRefStride,
     331                                          const Int   iLog2Denom,
     332                                          const Int   iWeight,
     333                                          const Int   iOffset,
     334                                          const Bool  useHighPrecisionPredictionWeighting)
     335{
     336  const Int64 iSize          = iWidth*iHeight;
     337  const Int64 iRealLog2Denom = useHighPrecisionPredictionWeighting ? iLog2Denom : (iLog2Denom + (bitDepth - 8));
     338
    463339  Int64 iSAD = 0;
    464   Int64 iSize   = iWidth*iHeight;
    465   Int64 iRealDenom = iDenom + bitDepth-8;
    466   for( y = 0; y < iHeight; y++ )
    467   {
    468     for( x = 0; x < iWidth; x++ )
    469     {
    470       iSAD += ABS(( ((Int64)pOrgPel[x]<<(Int64)iDenom) - ( (Int64)pRefPel[x] * (Int64)iWeight + ((Int64)iOffset<<iRealDenom) ) ) );
     340  for( Int y = 0; y < iHeight; y++ )
     341  {
     342    for( Int x = 0; x < iWidth; x++ )
     343    {
     344      iSAD += ABS(( ((Int64)pOrgPel[x]<<(Int64)iLog2Denom) - ( (Int64)pRefPel[x] * (Int64)iWeight + ((Int64)iOffset<<iRealLog2Denom) ) ) );
    471345    }
    472346    pOrgPel += iOrgStride;
    473347    pRefPel += iRefStride;
    474348  }
     349
    475350  return (iSAD/iSize);
    476351}
    477 
    478 
Note: See TracChangeset for help on using the changeset viewer.