Changeset 1389 in SHVCSoftware for branches/SHM-dev/source


Ignore:
Timestamp:
4 Aug 2015, 03:02:06 (9 years ago)
Author:
seregin
Message:

port rev 4525

Location:
branches/SHM-dev/source/Lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/SHM-dev/source/Lib/TLibCommon/TComRdCost.cpp

    r1388 r1389  
    5555
    5656// Calculate RD functions
    57 Double TComRdCost::calcRdCost( UInt uiBits, Distortion uiDistortion, Bool bFlag, DFunc eDFunc )
    58 {
    59   Double dRdCost = 0.0;
    60   Double dLambda = 0.0;
     57Double TComRdCost::calcRdCost( Double numBits, Double distortion, DFunc eDFunc )
     58{
     59  Double lambda = 1.0;
    6160
    6261  switch ( eDFunc )
     
    6665      break;
    6766    case DF_SAD:
    68 #if RExt__HIGH_BIT_DEPTH_SUPPORT
    69       dLambda = m_dLambdaMotionSAD[0]; // 0 is valid, because for lossless blocks, the cost equation is modified to compensate.
    70 #else
    71       dLambda = (Double)m_uiLambdaMotionSAD[0]; // 0 is valid, because for lossless blocks, the cost equation is modified to compensate.
    72 #endif
     67      lambda = m_dLambdaMotionSAD[0]; // 0 is valid, because for lossless blocks, the cost equation is modified to compensate.
    7368      break;
    7469    case DF_DEFAULT:
    75       dLambda =        m_dLambda;
     70      lambda = m_dLambda;
    7671      break;
    7772    case DF_SSE_FRAME:
    78       dLambda =        m_dFrameLambda;
     73      lambda = m_dFrameLambda;
    7974      break;
    8075    default:
     
    8378  }
    8479
    85   if (bFlag) //NOTE: this "bFlag" is never true
    86   {
    87     // Intra8x8, Intra4x4 Block only...
     80  if (eDFunc == DF_SAD)
     81  {
    8882    if (m_costMode != COST_STANDARD_LOSSY)
    8983    {
    90       dRdCost = (Double(uiDistortion) / dLambda) + Double(uiBits); // all lossless costs would have uiDistortion=0, and therefore this cost function can be used.
     84      return ((distortion * 65536.0) / lambda) + numBits; // all lossless costs would have uiDistortion=0, and therefore this cost function can be used.
    9185    }
    9286    else
    9387    {
    94       dRdCost = (((Double)uiDistortion) + ((Double)uiBits * dLambda));
     88      return distortion + (((numBits * lambda) ) / 65536.0);
    9589    }
    9690  }
    9791  else
    9892  {
    99     if (eDFunc == DF_SAD)
    100     {
    101       if (m_costMode != COST_STANDARD_LOSSY)
    102       {
    103         dRdCost = ((Double(uiDistortion) * 65536) / dLambda) + Double(uiBits); // all lossless costs would have uiDistortion=0, and therefore this cost function can be used.
    104       }
    105       else
    106       {
    107         dRdCost = Double(uiDistortion) + ((Double(uiBits) * dLambda) / 65536.0);
    108       }
     93    if (m_costMode != COST_STANDARD_LOSSY)
     94    {
     95      return (distortion / lambda) + numBits; // all lossless costs would have uiDistortion=0, and therefore this cost function can be used.
    10996    }
    11097    else
    11198    {
    112       if (m_costMode != COST_STANDARD_LOSSY)
    113       {
    114         dRdCost = (Double(uiDistortion) / dLambda) + Double(uiBits); // all lossless costs would have uiDistortion=0, and therefore this cost function can be used.
    115       }
    116       else
    117       {
    118         dRdCost = Double(uiDistortion) + (Double(uiBits) * dLambda);
    119       }
    120     }
    121   }
    122 
    123   return dRdCost;
    124 }
    125 
    126 Double TComRdCost::calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag, DFunc eDFunc )
    127 {
    128   Double dRdCost = 0.0;
    129   Double dLambda = 0.0;
    130 
    131   switch ( eDFunc )
    132   {
    133     case DF_SSE:
    134       assert(0);
    135       break;
    136     case DF_SAD:
    137 #if RExt__HIGH_BIT_DEPTH_SUPPORT
    138       dLambda = m_dLambdaMotionSAD[0]; // 0 is valid, because for lossless blocks, the cost equation is modified to compensate.
    139 #else
    140       dLambda = (Double)m_uiLambdaMotionSAD[0]; // 0 is valid, because for lossless blocks, the cost equation is modified to compensate.
    141 #endif
    142       break;
    143     case DF_DEFAULT:
    144       dLambda =         m_dLambda;
    145       break;
    146     case DF_SSE_FRAME:
    147       dLambda =         m_dFrameLambda;
    148       break;
    149     default:
    150       assert (0);
    151       break;
    152   }
    153 
    154   if (bFlag) //NOTE: this "bFlag" is never true
    155   {
    156     // Intra8x8, Intra4x4 Block only...
    157     if (m_costMode != COST_STANDARD_LOSSY)
    158     {
    159       dRdCost = (Double(uiDistortion) / dLambda) + Double(uiBits); // all lossless costs would have uiDistortion=0, and therefore this cost function can be used.
    160     }
    161     else
    162     {
    163       dRdCost = (((Double)(Int64)uiDistortion) + ((Double)(Int64)uiBits * dLambda));
    164     }
    165   }
    166   else
    167   {
    168     if (eDFunc == DF_SAD)
    169     {
    170       if (m_costMode != COST_STANDARD_LOSSY)
    171       {
    172         dRdCost = ((Double(uiDistortion) * 65536) / dLambda) + Double(uiBits); // all lossless costs would have uiDistortion=0, and therefore this cost function can be used.
    173       }
    174       else
    175       {
    176         dRdCost = Double(uiDistortion) + ((Double(uiBits) * dLambda) / 65536.0);
    177       }
    178     }
    179     else
    180     {
    181       if (m_costMode != COST_STANDARD_LOSSY)
    182       {
    183         dRdCost = (Double(uiDistortion) / dLambda) + Double(uiBits); // all lossless costs would have uiDistortion=0, and therefore this cost function can be used.
    184       }
    185       else
    186       {
    187         dRdCost = Double(uiDistortion) + (Double(uiBits) * dLambda);
    188       }
    189     }
    190   }
    191 
    192   return dRdCost;
     99      return distortion + (numBits * lambda);
     100    }
     101  }
    193102}
    194103
     
    197106  m_dLambda           = dLambda;
    198107  m_sqrtLambda        = sqrt(m_dLambda);
    199 #if RExt__HIGH_BIT_DEPTH_SUPPORT
    200108  m_dLambdaMotionSAD[0] = 65536.0 * m_sqrtLambda;
    201109  m_dLambdaMotionSSE[0] = 65536.0 * m_dLambda;
     
    207115  m_dLambdaMotionSAD[1] = 65536.0 * sqrt(dLambda);
    208116  m_dLambdaMotionSSE[1] = 65536.0 * dLambda;
    209 #else
    210   m_uiLambdaMotionSAD[0] = (UInt)floor(65536.0 * m_sqrtLambda);
    211   m_uiLambdaMotionSSE[0] = (UInt)floor(65536.0 * m_dLambda   );
    212 #if FULL_NBIT
    213   dLambda = 0.57 * pow(2.0, ((LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP_PRIME - 12) / 3.0));
    214 #else
    215   dLambda = 0.57 * pow(2.0, ((LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP_PRIME - 12 - 6 * (bitDepths.recon[CHANNEL_TYPE_LUMA] - 8)) / 3.0));
    216 #endif
    217   m_uiLambdaMotionSAD[1] = (UInt)floor(65536.0 * sqrt(dLambda));
    218   m_uiLambdaMotionSSE[1] = (UInt)floor(65536.0 * dLambda   );
    219 #endif
    220117}
    221118
     
    268165  m_costMode                   = COST_STANDARD_LOSSY;
    269166
    270 #if RExt__HIGH_BIT_DEPTH_SUPPORT
    271167  m_dCost                      = 0;
    272 #else
    273   m_uiCost                     = 0;
    274 #endif
    275168  m_iCostScale                 = 0;
    276169}
  • branches/SHM-dev/source/Lib/TLibCommon/TComRdCost.h

    r1341 r1389  
    112112  Double                  m_dLambda;
    113113  Double                  m_sqrtLambda;
    114 #if RExt__HIGH_BIT_DEPTH_SUPPORT
    115114  Double                  m_dLambdaMotionSAD[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
    116115  Double                  m_dLambdaMotionSSE[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
    117 #else
    118   UInt                    m_uiLambdaMotionSAD[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
    119   UInt                    m_uiLambdaMotionSSE[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
    120 #endif
    121116  Double                  m_dFrameLambda;
    122117
    123118  // for motion cost
    124119  TComMv                  m_mvPredictor;
    125 #if RExt__HIGH_BIT_DEPTH_SUPPORT
    126120  Double                  m_dCost;
    127 #else
    128   UInt                    m_uiCost;
    129 #endif
    130121  Int                     m_iCostScale;
    131122
     
    134125  virtual ~TComRdCost();
    135126
    136   Double  calcRdCost  ( UInt   uiBits, Distortion uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
    137   Double  calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
     127  Double calcRdCost( Double numBits, Double distortion, DFunc eDFunc = DF_DEFAULT );
    138128
    139129  Void    setDistortionWeight  ( const ComponentID compID, const Double distortionWeight ) { m_distortionWeight[compID] = distortionWeight; }
     
    160150  // for motion cost
    161151  static UInt    xGetExpGolombNumberOfBits( Int iVal );
    162 #if RExt__HIGH_BIT_DEPTH_SUPPORT
    163152  Void    getMotionCost( Bool bSad, Int iAdd, Bool bIsTransquantBypass ) { m_dCost = (bSad ? m_dLambdaMotionSAD[(bIsTransquantBypass && m_costMode==COST_MIXED_LOSSLESS_LOSSY_CODING) ?1:0] + iAdd : m_dLambdaMotionSSE[(bIsTransquantBypass && m_costMode==COST_MIXED_LOSSLESS_LOSSY_CODING)?1:0] + iAdd); }
    164 #else
    165   Void    getMotionCost( Bool bSad, Int iAdd, Bool bIsTransquantBypass ) { m_uiCost = (bSad ? m_uiLambdaMotionSAD[(bIsTransquantBypass && m_costMode==COST_MIXED_LOSSLESS_LOSSY_CODING) ?1:0] + iAdd : m_uiLambdaMotionSSE[(bIsTransquantBypass && m_costMode==COST_MIXED_LOSSLESS_LOSSY_CODING)?1:0] + iAdd); }
    166 #endif
    167153  Void    setPredictor( TComMv& rcMv )
    168154  {
     
    172158  __inline Distortion getCost( Int x, Int y )
    173159  {
    174 #if RExt__HIGH_BIT_DEPTH_SUPPORT
    175160    return Distortion((m_dCost * getBits(x, y)) / 65536.0);
    176 #else
    177     return m_uiCost * getBits(x, y) >> 16;
    178 #endif
    179   }
    180 #if RExt__HIGH_BIT_DEPTH_SUPPORT
     161  }
    181162  Distortion getCost( UInt b )                 { return Distortion(( m_dCost * b ) / 65536.0); }
    182 #else
    183   Distortion getCost( UInt b )                 { return ( m_uiCost * b ) >> 16; }
    184 #endif
    185163  UInt    getBits( Int x, Int y )
    186164  {
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.cpp

    r1387 r1389  
    28242824Void TEncSearch::IPCMSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv, TComYuv* pcRecoYuv )
    28252825{
    2826   UInt        uiDepth      = pcCU->getDepth(0);
    2827   const UInt  uiDistortion = 0;
    2828   UInt        uiBits;
     2826  UInt              uiDepth      = pcCU->getDepth(0);
     2827  const Distortion  uiDistortion = 0;
     2828  UInt              uiBits;
    28292829
    28302830  Double dCost;
     
    38573857  uiCost = m_pcRdCost->getDistPart( pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA), pcTemplateCand->getAddr(COMPONENT_Y, uiPartAddr), pcTemplateCand->getStride(COMPONENT_Y), pcOrgYuv->getAddr(COMPONENT_Y, uiPartAddr), pcOrgYuv->getStride(COMPONENT_Y), iSizeX, iSizeY, COMPONENT_Y, DF_SAD );
    38583858#endif
    3859   uiCost = (UInt) m_pcRdCost->calcRdCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum], uiCost, false, DF_SAD );
     3859  uiCost = (UInt) m_pcRdCost->calcRdCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum], uiCost, DF_SAD );
    38603860  return uiCost;
    38613861}
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.cpp

    r1369 r1389  
    688688
    689689    // compute RD cost and choose the best
    690     Double dPicRdCost = m_pcRdCost->calcRdCost64( m_uiPicTotalBits, uiPicDist, true, DF_SSE_FRAME); // NOTE: Is the 'true' parameter really necessary?
     690    Double dPicRdCost = m_pcRdCost->calcRdCost( (Double)m_uiPicTotalBits, (Double)uiPicDist, DF_SSE_FRAME);
    691691
    692692    if ( dPicRdCost < dPicRdCostBest )
     
    13761376#if SVC_EXTENSION
    13771377#if JCTVC_M0259_LAMBDAREFINEMENT
    1378 Double TEncSlice::xCalEnhLambdaFactor( Double deltaQP , Double beta )
    1379 {
    1380   double tmp = beta * pow( 2.0 , deltaQP / 6 );
    1381   double gamma = tmp / ( tmp + 1 );
    1382   return( gamma );
     1378Double TEncSlice::xCalEnhLambdaFactor( Double deltaQP, Double beta )
     1379{
     1380  Double tmp = beta * pow( 2.0 , deltaQP / 6 );
     1381  Double gamma = tmp / ( tmp + 1 );
     1382  return gamma;
    13831383}
    13841384#endif
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.h

    r1369 r1389  
    147147
    148148#if SVC_EXTENSION && JCTVC_M0259_LAMBDAREFINEMENT
    149   Double  xCalEnhLambdaFactor( Double deltaQP , Double beta );
     149  Double  xCalEnhLambdaFactor( Double deltaQP, Double beta );
    150150#endif
    151151};
Note: See TracChangeset for help on using the changeset viewer.