Ignore:
Timestamp:
12 Nov 2014, 08:09:17 (10 years ago)
Author:
seregin
Message:

initial porting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/SHM-upgrade/source/Lib/TLibCommon/TComRdCost.h

    r595 r916  
    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 *
    66 * Copyright (c) 2010-2014, ITU/ISO/IEC
     
    5050//! \{
    5151
    52 #define FIX203 1
    53 
    5452class DistParam;
    5553class TComPattern;
     
    6058
    6159// for function pointer
    62 typedef UInt (*FpDistFunc) (DistParam*);
     60typedef Distortion (*FpDistFunc) (DistParam*); // TODO: can this pointer be replaced with a reference? - there are no NULL checks on pointer.
    6361
    6462// ====================================================================================================================
     
    8078  Int   bitDepth;
    8179
    82   Bool            bApplyWeight;     // whether weithed prediction is used or not
    83   wpScalingParam  *wpCur;           // weithed prediction scaling parameters for current ref
    84   UInt            uiComp;           // uiComp = 0 (luma Y), 1 (chroma U), 2 (chroma V)
     80  Bool            bApplyWeight;     // whether weighted prediction is used or not
     81  WPScalingParam  *wpCur;           // weighted prediction scaling parameters for current ref
     82  ComponentID     compIdx;
    8583
    8684  // (vertical) subsampling shift (for reducing complexity)
    8785  // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc.
    8886  Int   iSubShift;
    89  
     87
    9088  DistParam()
    9189  {
     
    105103/// RD cost computation class
    106104class TComRdCost
    107   : public TComRdCostWeightPrediction
    108105{
    109106private:
    110107  // for distortion
    111  
    112 #if AMP_SAD
    113   FpDistFunc              m_afpDistortFunc[64]; // [eDFunc]
    114 #else 
    115   FpDistFunc              m_afpDistortFunc[33]; // [eDFunc]
    116 #endif 
    117  
    118   Double                  m_cbDistortionWeight;
    119   Double                  m_crDistortionWeight;
     108
     109  FpDistFunc              m_afpDistortFunc[DF_TOTAL_FUNCTIONS]; // [eDFunc]
     110  CostMode                m_costMode;
     111  Double                  m_distortionWeight[MAX_NUM_COMPONENT]; // only chroma values are used.
    120112  Double                  m_dLambda;
    121113  Double                  m_sqrtLambda;
    122   UInt                    m_uiLambdaMotionSAD;
    123   UInt                    m_uiLambdaMotionSSE;
     114#if RExt__HIGH_BIT_DEPTH_SUPPORT
     115  Double                  m_dLambdaMotionSAD[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
     116  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
    124121  Double                  m_dFrameLambda;
    125  
     122
    126123  // for motion cost
    127 #if FIX203
    128124  TComMv                  m_mvPredictor;
    129 #else
    130   UInt*                   m_puiComponentCostOriginP;
    131   UInt*                   m_puiComponentCost;
    132   UInt*                   m_puiVerCost;
    133   UInt*                   m_puiHorCost;
    134 #endif
     125#if RExt__HIGH_BIT_DEPTH_SUPPORT
     126  Double                  m_dCost;
     127#else
    135128  UInt                    m_uiCost;
     129#endif
    136130  Int                     m_iCostScale;
    137 #if !FIX203
    138   Int                     m_iSearchLimit;
    139 #endif
    140  
     131
    141132public:
    142133  TComRdCost();
    143134  virtual ~TComRdCost();
    144  
    145   Double  calcRdCost  ( UInt   uiBits, UInt  uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
     135
     136  Double  calcRdCost  ( UInt   uiBits, Distortion uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
    146137  Double  calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
    147  
    148   Void    setCbDistortionWeight      ( Double cbDistortionWeight) { m_cbDistortionWeight = cbDistortionWeight; };
    149   Void    setCrDistortionWeight      ( Double crDistortionWeight) { m_crDistortionWeight = crDistortionWeight; };
     138
     139  Void    setDistortionWeight  ( const ComponentID compID, const Double distortionWeight ) { m_distortionWeight[compID] = distortionWeight; }
    150140  Void    setLambda      ( Double dLambda );
    151141  Void    setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
    152  
     142
    153143  Double  getSqrtLambda ()   { return m_sqrtLambda; }
    154144
    155145  Double  getLambda() { return m_dLambda; }
    156   Double  getChromaWeight () {return((m_cbDistortionWeight+m_crDistortionWeight)/2.0);}
    157  
     146  Double  getChromaWeight () { return ((m_distortionWeight[COMPONENT_Cb] + m_distortionWeight[COMPONENT_Cr]) / 2.0); }
     147
     148  Void    setCostMode(CostMode   m )    { m_costMode = m; }
     149
    158150  // Distortion Functions
    159151  Void    init();
    160  
     152
    161153  Void    setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
    162154  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride,            DistParam& rcDistParam );
    163155  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
    164156  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
    165  
    166   UInt    calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
    167  
     157
     158  Distortion calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
     159
    168160  // for motion cost
    169 #if !FIX203
    170   Void    initRateDistortionModel( Int iSubPelSearchLimit );
    171   Void    xUninit();
    172 #endif
    173161  UInt    xGetComponentBits( Int iVal );
    174   Void    getMotionCost( Bool bSad, Int iAdd ) { m_uiCost = (bSad ? m_uiLambdaMotionSAD + iAdd : m_uiLambdaMotionSSE + iAdd); }
     162#if RExt__HIGH_BIT_DEPTH_SUPPORT
     163  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
    175167  Void    setPredictor( TComMv& rcMv )
    176168  {
    177 #if FIX203
    178169    m_mvPredictor = rcMv;
    179 #else
    180     m_puiHorCost = m_puiComponentCost - rcMv.getHor();
    181     m_puiVerCost = m_puiComponentCost - rcMv.getVer();
    182 #endif
    183170  }
    184171  Void    setCostScale( Int iCostScale )    { m_iCostScale = iCostScale; }
    185   __inline UInt getCost( Int x, Int y )
    186   {
    187 #if FIX203
     172  __inline Distortion getCost( Int x, Int y )
     173  {
     174#if RExt__HIGH_BIT_DEPTH_SUPPORT
     175    return Distortion((m_dCost * getBits(x, y)) / 65536.0);
     176#else
    188177    return m_uiCost * getBits(x, y) >> 16;
    189 #else
    190     return (( m_uiCost * (m_puiHorCost[ x * (1<<m_iCostScale) ] + m_puiVerCost[ y * (1<<m_iCostScale) ]) ) >> 16);
    191 #endif
    192   }
    193   UInt    getCost( UInt b )                 { return ( m_uiCost * b ) >> 16; }
    194   UInt    getBits( Int x, Int y )         
    195   {
    196 #if FIX203
     178#endif
     179  }
     180#if RExt__HIGH_BIT_DEPTH_SUPPORT
     181  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
     185  UInt    getBits( Int x, Int y )
     186  {
    197187    return xGetComponentBits((x << m_iCostScale) - m_mvPredictor.getHor())
    198188    +      xGetComponentBits((y << m_iCostScale) - m_mvPredictor.getVer());
    199 #else
    200     return m_puiHorCost[ x * (1<<m_iCostScale)] + m_puiVerCost[ y * (1<<m_iCostScale) ];
    201 #endif
    202   }
    203  
     189  }
     190
    204191private:
    205  
    206   static UInt xGetSSE           ( DistParam* pcDtParam );
    207   static UInt xGetSSE4          ( DistParam* pcDtParam );
    208   static UInt xGetSSE8          ( DistParam* pcDtParam );
    209   static UInt xGetSSE16         ( DistParam* pcDtParam );
    210   static UInt xGetSSE32         ( DistParam* pcDtParam );
    211   static UInt xGetSSE64         ( DistParam* pcDtParam );
    212   static UInt xGetSSE16N        ( DistParam* pcDtParam );
    213  
    214   static UInt xGetSAD           ( DistParam* pcDtParam );
    215   static UInt xGetSAD4          ( DistParam* pcDtParam );
    216   static UInt xGetSAD8          ( DistParam* pcDtParam );
    217   static UInt xGetSAD16         ( DistParam* pcDtParam );
    218   static UInt xGetSAD32         ( DistParam* pcDtParam );
    219   static UInt xGetSAD64         ( DistParam* pcDtParam );
    220   static UInt xGetSAD16N        ( DistParam* pcDtParam );
    221  
     192
     193  static Distortion xGetSSE           ( DistParam* pcDtParam );
     194  static Distortion xGetSSE4          ( DistParam* pcDtParam );
     195  static Distortion xGetSSE8          ( DistParam* pcDtParam );
     196  static Distortion xGetSSE16         ( DistParam* pcDtParam );
     197  static Distortion xGetSSE32         ( DistParam* pcDtParam );
     198  static Distortion xGetSSE64         ( DistParam* pcDtParam );
     199  static Distortion xGetSSE16N        ( DistParam* pcDtParam );
     200
     201  static Distortion xGetSAD           ( DistParam* pcDtParam );
     202  static Distortion xGetSAD4          ( DistParam* pcDtParam );
     203  static Distortion xGetSAD8          ( DistParam* pcDtParam );
     204  static Distortion xGetSAD16         ( DistParam* pcDtParam );
     205  static Distortion xGetSAD32         ( DistParam* pcDtParam );
     206  static Distortion xGetSAD64         ( DistParam* pcDtParam );
     207  static Distortion xGetSAD16N        ( DistParam* pcDtParam );
     208
    222209#if AMP_SAD
    223   static UInt xGetSAD12         ( DistParam* pcDtParam );
    224   static UInt xGetSAD24         ( DistParam* pcDtParam );
    225   static UInt xGetSAD48         ( DistParam* pcDtParam );
    226 
    227 #endif
    228 
    229   static UInt xGetHADs4         ( DistParam* pcDtParam );
    230   static UInt xGetHADs8         ( DistParam* pcDtParam );
    231   static UInt xGetHADs          ( DistParam* pcDtParam );
    232   static UInt xCalcHADs2x2      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    233   static UInt xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    234   static UInt xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    235  
     210  static Distortion xGetSAD12         ( DistParam* pcDtParam );
     211  static Distortion xGetSAD24         ( DistParam* pcDtParam );
     212  static Distortion xGetSAD48         ( DistParam* pcDtParam );
     213
     214#endif
     215
     216  static Distortion xGetHADs          ( DistParam* pcDtParam );
     217  static Distortion xCalcHADs2x2      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
     218  static Distortion xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
     219  static Distortion xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
     220
     221
    236222public:
    237   UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText = TEXT_LUMA, DFunc eDFunc = DF_SSE );
     223
     224  Distortion   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, const ComponentID compID, DFunc eDFunc = DF_SSE );
    238225
    239226};// END CLASS DEFINITION TComRdCost
Note: See TracChangeset for help on using the changeset viewer.