Ignore:
Timestamp:
13 Nov 2015, 16:29:39 (8 years ago)
Author:
tech
Message:

Merged 15.1-dev1@1381.

File:
1 edited

Legend:

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

    r1313 r1386  
    7070  const Int             shift      = wpCur.shift;
    7171  const Int             round      = wpCur.round;
     72  const Int        distortionShift = DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
    7273
    7374  Distortion uiSum = 0;
    7475
     76#if !U0040_MODIFIED_WEIGHTEDPREDICTION_WITH_BIPRED_AND_CLIPPING
    7577  for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- )
    7678  {
     
    8082
    8183      uiSum += abs( piOrg[n] - pred );
     84    }
     85    if (pcDtParam->m_maximumDistortionForEarlyExit <  ( uiSum >> distortionShift))
     86    {
     87      return uiSum >> distortionShift;
    8288    }
    8389    piOrg += iStrideOrg;
     
    8692
    8793  pcDtParam->compIdx = MAX_NUM_COMPONENT;  // reset for DEBUG (assert test)
    88 
    89   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
     94#else
     95  // Default weight
     96  if (w0 == 1 << shift)
     97  {
     98    // no offset
     99    if (offset == 0)
     100    {
     101      for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- )
     102      {
     103        for (Int n = 0; n < iCols; n++ )
     104        {
     105          uiSum += abs( piOrg[n] - piCur[n] );
     106        }
     107        if (pcDtParam->m_maximumDistortionForEarlyExit <  ( uiSum >> distortionShift))
     108        {
     109          return uiSum >> distortionShift;
     110        }
     111        piOrg += iStrideOrg;
     112        piCur += iStrideCur;
     113      }
     114    }
     115    else
     116    {
     117      // Lets not clip for the bipredictive case since clipping should be done after
     118      // combining both elements. Unfortunately the code uses the suboptimal "subtraction"
     119      // method, which is faster but introduces the clipping issue (therefore Bipred is suboptimal).
     120      if (pcDtParam->bIsBiPred)
     121      {
     122        for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- )
     123        {
     124          for (Int n = 0; n < iCols; n++ )
     125          {
     126            uiSum += abs( piOrg[n] - (piCur[n] + offset) );
     127          }
     128          if (pcDtParam->m_maximumDistortionForEarlyExit <  ( uiSum >> distortionShift))
     129          {
     130            return uiSum >> distortionShift;
     131          }
     132
     133          piOrg += iStrideOrg;
     134          piCur += iStrideCur;
     135        }
     136      }
     137      else
     138      {
     139        const Pel iMaxValue = (Pel) ((1 << pcDtParam->bitDepth) - 1);
     140        for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- )
     141        {
     142          for (Int n = 0; n < iCols; n++ )
     143          {
     144            const Pel pred = Clip3((Pel) 0, iMaxValue, (Pel) (piCur[n] + offset)) ;
     145
     146            uiSum += abs( piOrg[n] - pred );
     147          }
     148          if (pcDtParam->m_maximumDistortionForEarlyExit <  ( uiSum >> distortionShift))
     149          {
     150            return uiSum >> distortionShift;
     151          }
     152          piOrg += iStrideOrg;
     153          piCur += iStrideCur;
     154        }
     155      }
     156    }
     157  }
     158  else
     159  {
     160    // Lets not clip for the bipredictive case since clipping should be done after
     161    // combining both elements. Unfortunately the code uses the suboptimal "subtraction"
     162    // method, which is faster but introduces the clipping issue (therefore Bipred is suboptimal).
     163    if (pcDtParam->bIsBiPred)
     164    {
     165      for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- )
     166      {
     167        for (Int n = 0; n < iCols; n++ )
     168        {
     169          const Pel pred = ( (w0*piCur[n] + round) >> shift ) + offset ;
     170          uiSum += abs( piOrg[n] - pred );
     171        }
     172        if (pcDtParam->m_maximumDistortionForEarlyExit <  ( uiSum >> distortionShift))
     173        {
     174          return uiSum >> distortionShift;
     175        }
     176
     177        piOrg += iStrideOrg;
     178        piCur += iStrideCur;
     179      }
     180    }
     181    else
     182    {
     183      const Pel iMaxValue = (Pel) ((1 << pcDtParam->bitDepth) - 1);
     184
     185      if (offset == 0)
     186      {
     187        for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- )
     188        {
     189          for (Int n = 0; n < iCols; n++ )
     190          {
     191            const Pel pred = Clip3((Pel) 0, iMaxValue, (Pel) (( (w0*piCur[n] + round) >> shift ))) ;
     192
     193            uiSum += abs( piOrg[n] - pred );
     194          }
     195          if (pcDtParam->m_maximumDistortionForEarlyExit <  ( uiSum >> distortionShift))
     196          {
     197            return uiSum >> distortionShift;
     198          }
     199          piOrg += iStrideOrg;
     200          piCur += iStrideCur;
     201        }
     202      }
     203      else
     204      {
     205        for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- )
     206        {
     207          for (Int n = 0; n < iCols; n++ )
     208          {
     209            const Pel pred = Clip3((Pel) 0, iMaxValue, (Pel) (( (w0*piCur[n] + round) >> shift ) + offset)) ;
     210
     211            uiSum += abs( piOrg[n] - pred );
     212          }
     213          if (pcDtParam->m_maximumDistortionForEarlyExit <  ( uiSum >> distortionShift))
     214          {
     215            return uiSum >> distortionShift;
     216          }
     217          piOrg += iStrideOrg;
     218          piCur += iStrideCur;
     219        }
     220      }
     221    }
     222  }
     223  //pcDtParam->compIdx = MAX_NUM_COMPONENT;  // reset for DEBUG (assert test)
     224#endif
     225
     226  return uiSum >> distortionShift;
    90227}
    91228
     
    119256  Distortion sum = 0;
    120257
     258#if !U0040_MODIFIED_WEIGHTEDPREDICTION_WITH_BIPRED_AND_CLIPPING
    121259  for(Int iRows = pcDtParam->iRows ; iRows != 0; iRows-- )
    122260  {
     
    132270
    133271  pcDtParam->compIdx = MAX_NUM_COMPONENT; // reset for DEBUG (assert test)
     272#else
     273  if (pcDtParam->bIsBiPred)
     274  {
     275    for(Int iRows = pcDtParam->iRows ; iRows != 0; iRows-- )
     276    {
     277      for (Int n = 0; n < iCols; n++ )
     278      {
     279        const Pel pred     = ( (w0*piCur[n] + round) >> shift ) + offset ;
     280        const Pel residual = piOrg[n] - pred;
     281        sum += ( Distortion(residual) * Distortion(residual) ) >> distortionShift;
     282      }
     283      piOrg += iStrideOrg;
     284      piCur += iStrideCur;
     285    }
     286  }
     287  else
     288  {
     289    const Pel iMaxValue = (Pel) ((1 << pcDtParam->bitDepth) - 1);
     290
     291    for(Int iRows = pcDtParam->iRows ; iRows != 0; iRows-- )
     292    {
     293      for (Int n = 0; n < iCols; n++ )
     294      {
     295        const Pel pred     = Clip3((Pel) 0, iMaxValue, (Pel) (( (w0*piCur[n] + round) >> shift ) + offset)) ;
     296        const Pel residual = piOrg[n] - pred;
     297        sum += ( Distortion(residual) * Distortion(residual) ) >> distortionShift;
     298      }
     299      piOrg += iStrideOrg;
     300      piCur += iStrideCur;
     301    }
     302  }
     303
     304  //pcDtParam->compIdx = MAX_NUM_COMPONENT; // reset for DEBUG (assert test)
     305#endif
    134306
    135307  return sum;
     
    416588  const ComponentID compIdx    = pcDtParam->compIdx;
    417589  assert(compIdx<MAX_NUM_COMPONENT);
    418   const WPScalingParam  wpCur    = pcDtParam->wpCur[compIdx];
     590  const WPScalingParam &wpCur  = pcDtParam->wpCur[compIdx];
    419591
    420592  Distortion uiSum = 0;
Note: See TracChangeset for help on using the changeset viewer.