Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComRdCost.h


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/TLibCommon/TComRdCost.h

    r1196 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 *
     
    4646#include "TComSlice.h"
    4747#include "TComRdCostWeightPrediction.h"
    48 #if H_3D
     48#if NH_3D
    4949#include "../TLibRenderer/TRenModel.h"
     50#include "TComYuv.h"
     51#include "TComTU.h"
    5052#endif
    5153
     
    5355//! \{
    5456
    55 #define FIX203 1
    56 
    5757class DistParam;
    5858class TComPattern;
    59 #if H_3D
     59#if NH_3D
    6060class TComRdCost;
    6161#endif
     
    6666
    6767// for function pointer
    68 typedef UInt (*FpDistFunc) (DistParam*);
    69 
    70 #if H_3D
    71 #if H_3D_VSO
     68typedef Distortion (*FpDistFunc) (DistParam*); // TODO: can this pointer be replaced with a reference? - there are no NULL checks on pointer.
     69
     70#if NH_3D
     71#if NH_3D_VSO
    7272typedef Dist (TComRdCost::*FpDistFuncVSO) ( Int, Int, Pel*, Int, Pel*, Int, UInt, UInt, Bool );
    7373#endif
     
    8585  Int   iStrideOrg;
    8686  Int   iStrideCur;
    87 #if H_3D_VSO
     87#if NH_3D_VSO
    8888  // SAIT_VSO_EST_A0033
    8989  Pel*  pVirRec;
     
    9191  Int   iStrideVir;
    9292#endif
    93 #if H_3D_IC
     93#if NH_3D_IC
    9494  Bool  bUseIC;
    9595#endif
    96 #if H_3D_INTER_SDC
     96#if NH_3D_SDC_INTER
    9797  Bool  bUseSDCMRSAD;
    9898#endif
     
    103103  Int   bitDepth;
    104104
    105   Bool            bApplyWeight;     // whether weithed prediction is used or not
    106   wpScalingParam  *wpCur;           // weithed prediction scaling parameters for current ref
    107   UInt            uiComp;           // uiComp = 0 (luma Y), 1 (chroma U), 2 (chroma V)
     105  Bool            bApplyWeight;     // whether weighted prediction is used or not
     106  WPScalingParam  *wpCur;           // weighted prediction scaling parameters for current ref
     107  ComponentID     compIdx;
    108108
    109109  // (vertical) subsampling shift (for reducing complexity)
    110110  // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc.
    111111  Int   iSubShift;
    112  
     112
    113113  DistParam()
    114114  {
     
    123123    iSubShift = 0;
    124124    bitDepth = 0;
    125 #if H_3D_VSO
     125#if NH_3D_VSO
    126126    // SAIT_VSO_EST_A0033
    127127    pVirRec = NULL;
     
    129129    iStrideVir = 0;
    130130#endif
    131 #if H_3D_INTER_SDC
     131#if NH_3D_SDC_INTER
    132132    bUseSDCMRSAD = false;
    133133#endif
     
    137137/// RD cost computation class
    138138class TComRdCost
    139   : public TComRdCostWeightPrediction
    140139{
    141140private:
    142141  // for distortion
    143  
    144 #if AMP_SAD
    145   FpDistFunc              m_afpDistortFunc[64]; // [eDFunc]
    146 #else 
    147   FpDistFunc              m_afpDistortFunc[33]; // [eDFunc]
    148 #endif 
    149  
    150   Double                  m_cbDistortionWeight;
    151   Double                  m_crDistortionWeight;
     142
     143  FpDistFunc              m_afpDistortFunc[DF_TOTAL_FUNCTIONS]; // [eDFunc]
     144  CostMode                m_costMode;
     145  Double                  m_distortionWeight[MAX_NUM_COMPONENT]; // only chroma values are used.
    152146  Double                  m_dLambda;
    153147  Double                  m_sqrtLambda;
    154   UInt                    m_uiLambdaMotionSAD;
    155   UInt                    m_uiLambdaMotionSSE;
     148#if RExt__HIGH_BIT_DEPTH_SUPPORT
     149  Double                  m_dLambdaMotionSAD[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
     150  Double                  m_dLambdaMotionSSE[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
     151#else
     152  UInt                    m_uiLambdaMotionSAD[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
     153  UInt                    m_uiLambdaMotionSSE[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
     154#endif
    156155  Double                  m_dFrameLambda;
    157 #if H_3D_VSO
     156#if NH_3D_VSO
    158157  // SAIT_VSO_EST_A0033
    159158  static Double           m_dDisparityCoeff;
    160159#endif
    161  
     160
    162161  // for motion cost
    163 #if FIX203
    164162  TComMv                  m_mvPredictor;
    165 #else
    166   UInt*                   m_puiComponentCostOriginP;
    167   UInt*                   m_puiComponentCost;
    168   UInt*                   m_puiVerCost;
    169   UInt*                   m_puiHorCost;
    170 #endif
     163#if RExt__HIGH_BIT_DEPTH_SUPPORT
     164  Double                  m_dCost;
     165#else
    171166  UInt                    m_uiCost;
     167#endif
    172168  Int                     m_iCostScale;
    173 #if !FIX203
    174   Int                     m_iSearchLimit;
    175 #endif
    176  
    177 #if H_3D_DBBP
     169#if NH_3D_DBBP
    178170  Bool                    m_bUseMask;
    179171#endif
    180  
     172
    181173public:
    182174  TComRdCost();
    183175  virtual ~TComRdCost();
    184 
    185 #if H_3D_VSO
     176#if NH_3D_VSO
    186177  Double  calcRdCost  ( UInt   uiBits, Dist   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
    187178  Double  calcRdCost64( UInt64 uiBits, Dist64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
    188179#else
    189   Double  calcRdCost  ( UInt   uiBits, UInt  uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
     180  Double  calcRdCost  ( UInt   uiBits, Distortion uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
    190181  Double  calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
    191182#endif
    192183
    193  
    194   Void    setCbDistortionWeight      ( Double cbDistortionWeight) { m_cbDistortionWeight = cbDistortionWeight; };
    195   Void    setCrDistortionWeight      ( Double crDistortionWeight) { m_crDistortionWeight = crDistortionWeight; };
    196   Void    setLambda      ( Double dLambda );
     184  Void    setDistortionWeight  ( const ComponentID compID, const Double distortionWeight ) { m_distortionWeight[compID] = distortionWeight; }
     185  Void    setLambda      ( Double dLambda, const BitDepths &bitDepths );
    197186  Void    setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
    198  
     187
    199188  Double  getSqrtLambda ()   { return m_sqrtLambda; }
    200 #if H_3D_VSO
     189#if NH_3D_VSO
    201190  // SAIT_VSO_EST_A0033
    202191  Void    setDisparityCoeff( Double dDisparityCoeff ) { m_dDisparityCoeff = dDisparityCoeff; }
     
    205194
    206195  Double  getLambda() { return m_dLambda; }
    207   Double  getChromaWeight () {return((m_cbDistortionWeight+m_crDistortionWeight)/2.0);}
    208  
     196  Double  getChromaWeight () { return ((m_distortionWeight[COMPONENT_Cb] + m_distortionWeight[COMPONENT_Cr]) / 2.0); }
     197
     198  Void    setCostMode(CostMode   m )    { m_costMode = m; }
     199
    209200  // Distortion Functions
    210201  Void    init();
    211  
     202
    212203  Void    setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
    213204  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride,            DistParam& rcDistParam );
    214205  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
    215206  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
    216  
    217 #if H_3D_DBBP
     207
     208#if NH_3D_DBBP
    218209  Void    setUseMask(Bool b) { m_bUseMask = b; }
    219210#endif
    220  
    221   UInt    calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
    222  
    223 #if H_3D_FAST_DEPTH_INTRA
    224   UInt    calcVAR(Pel* pi0, Int stride, Int width, Int height, Int cuDepth);
     211
     212  Distortion calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
     213
     214#if NH_3D_ENC_DEPTH
     215  UInt    calcVAR(Pel* pi0, Int stride, Int width, Int height, Int cuDepth, UInt maxCuWidth );
    225216#endif 
     217
    226218  // for motion cost
    227 #if !FIX203
    228   Void    initRateDistortionModel( Int iSubPelSearchLimit );
    229   Void    xUninit();
    230 #endif
    231   UInt    xGetComponentBits( Int iVal );
    232   Void    getMotionCost( Bool bSad, Int iAdd ) { m_uiCost = (bSad ? m_uiLambdaMotionSAD + iAdd : m_uiLambdaMotionSSE + iAdd); }
     219  static UInt    xGetExpGolombNumberOfBits( Int iVal );
     220#if RExt__HIGH_BIT_DEPTH_SUPPORT
     221  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); }
     222#else
     223  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); }
     224#endif
    233225  Void    setPredictor( TComMv& rcMv )
    234226  {
    235 #if FIX203
    236227    m_mvPredictor = rcMv;
    237 #else
    238     m_puiHorCost = m_puiComponentCost - rcMv.getHor();
    239     m_puiVerCost = m_puiComponentCost - rcMv.getVer();
    240 #endif
    241228  }
    242229  Void    setCostScale( Int iCostScale )    { m_iCostScale = iCostScale; }
    243   __inline UInt getCost( Int x, Int y )
     230  __inline Distortion getCost( Int x, Int y )
    244231  {
    245 #if FIX203
     232#if RExt__HIGH_BIT_DEPTH_SUPPORT
     233    return Distortion((m_dCost * getBits(x, y)) / 65536.0);
     234#else
    246235    return m_uiCost * getBits(x, y) >> 16;
    247 #else
    248     return (( m_uiCost * (m_puiHorCost[ x * (1<<m_iCostScale) ] + m_puiVerCost[ y * (1<<m_iCostScale) ]) ) >> 16);
    249236#endif
    250237  }
    251   UInt    getCost( UInt b )                 { return ( m_uiCost * b ) >> 16; }
    252   UInt    getBits( Int x, Int y )         
     238#if RExt__HIGH_BIT_DEPTH_SUPPORT
     239  Distortion getCost( UInt b )                 { return Distortion(( m_dCost * b ) / 65536.0); }
     240#else
     241  Distortion getCost( UInt b )                 { return ( m_uiCost * b ) >> 16; }
     242#endif
     243  UInt    getBits( Int x, Int y )
    253244  {
    254 #if FIX203
    255     return xGetComponentBits((x << m_iCostScale) - m_mvPredictor.getHor())
    256     +      xGetComponentBits((y << m_iCostScale) - m_mvPredictor.getVer());
    257 #else
    258     return m_puiHorCost[ x * (1<<m_iCostScale)] + m_puiVerCost[ y * (1<<m_iCostScale) ];
    259 #endif
     245    return xGetExpGolombNumberOfBits((x << m_iCostScale) - m_mvPredictor.getHor())
     246    +      xGetExpGolombNumberOfBits((y << m_iCostScale) - m_mvPredictor.getVer());
    260247  }
    261  
     248
    262249private:
    263  
    264   static UInt xGetSSE           ( DistParam* pcDtParam );
    265   static UInt xGetSSE4          ( DistParam* pcDtParam );
    266   static UInt xGetSSE8          ( DistParam* pcDtParam );
    267   static UInt xGetSSE16         ( DistParam* pcDtParam );
    268   static UInt xGetSSE32         ( DistParam* pcDtParam );
    269   static UInt xGetSSE64         ( DistParam* pcDtParam );
    270   static UInt xGetSSE16N        ( DistParam* pcDtParam );
    271 #if H_3D_IC || H_3D_INTER_SDC
     250
     251  static Distortion xGetSSE           ( DistParam* pcDtParam );
     252  static Distortion xGetSSE4          ( DistParam* pcDtParam );
     253  static Distortion xGetSSE8          ( DistParam* pcDtParam );
     254  static Distortion xGetSSE16         ( DistParam* pcDtParam );
     255  static Distortion xGetSSE32         ( DistParam* pcDtParam );
     256  static Distortion xGetSSE64         ( DistParam* pcDtParam );
     257  static Distortion xGetSSE16N        ( DistParam* pcDtParam );
     258#if NH_3D_IC || NH_3D_SDC_INTER
    272259  static UInt xGetSADic         ( DistParam* pcDtParam );
    273260  static UInt xGetSAD4ic        ( DistParam* pcDtParam );
     
    278265  static UInt xGetSAD16Nic      ( DistParam* pcDtParam );
    279266#endif
    280   static UInt xGetSAD           ( DistParam* pcDtParam );
    281   static UInt xGetSAD4          ( DistParam* pcDtParam );
    282   static UInt xGetSAD8          ( DistParam* pcDtParam );
    283   static UInt xGetSAD16         ( DistParam* pcDtParam );
    284   static UInt xGetSAD32         ( DistParam* pcDtParam );
    285   static UInt xGetSAD64         ( DistParam* pcDtParam );
    286   static UInt xGetSAD16N        ( DistParam* pcDtParam );
    287  
    288 #if H_3D_VSO
     267
     268  static Distortion xGetSAD           ( DistParam* pcDtParam );
     269  static Distortion xGetSAD4          ( DistParam* pcDtParam );
     270  static Distortion xGetSAD8          ( DistParam* pcDtParam );
     271  static Distortion xGetSAD16         ( DistParam* pcDtParam );
     272  static Distortion xGetSAD32         ( DistParam* pcDtParam );
     273  static Distortion xGetSAD64         ( DistParam* pcDtParam );
     274  static Distortion xGetSAD16N        ( DistParam* pcDtParam );
     275#if NH_3D_VSO
    289276  static UInt xGetVSD           ( DistParam* pcDtParam );
    290277  static UInt xGetVSD4          ( DistParam* pcDtParam );
     
    296283#endif
    297284
    298 #if AMP_SAD
    299 #if H_3D_IC || H_3D_INTER_SDC
     285#if NH_3D_IC || NH_3D_SDC_INTER
    300286  static UInt xGetSAD12ic       ( DistParam* pcDtParam );
    301287  static UInt xGetSAD24ic       ( DistParam* pcDtParam );
    302288  static UInt xGetSAD48ic       ( DistParam* pcDtParam );
    303289#endif
    304   static UInt xGetSAD12         ( DistParam* pcDtParam );
    305   static UInt xGetSAD24         ( DistParam* pcDtParam );
    306   static UInt xGetSAD48         ( DistParam* pcDtParam );
    307 
    308 #endif
    309 
    310 #if H_3D_IC || H_3D_INTER_SDC
     290
     291  static Distortion xGetSAD12         ( DistParam* pcDtParam );
     292  static Distortion xGetSAD24         ( DistParam* pcDtParam );
     293  static Distortion xGetSAD48         ( DistParam* pcDtParam );
     294
     295
     296#if NH_3D_IC || NH_3D_SDC_INTER
    311297  static UInt xGetHADsic          ( DistParam* pcDtParam );
    312298#endif
    313   static UInt xGetHADs4         ( DistParam* pcDtParam );
    314   static UInt xGetHADs8         ( DistParam* pcDtParam );
    315   static UInt xGetHADs          ( DistParam* pcDtParam );
    316   static UInt xCalcHADs2x2      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    317   static UInt xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    318   static UInt xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    319 #if H_3D_DBBP
     299
     300  static Distortion xGetHADs          ( DistParam* pcDtParam );
     301  static Distortion xCalcHADs2x2      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
     302  static Distortion xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
     303  static Distortion xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
     304#if NH_3D_DBBP
    320305  static UInt xGetMaskedSSE     ( DistParam* pcDtParam );
    321306  static UInt xGetMaskedSAD     ( DistParam* pcDtParam );
    322307  static UInt xGetMaskedVSD     ( DistParam* pcDtParam );
    323308#endif
    324  
     309
     310
    325311public:
    326   UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText = TEXT_LUMA, DFunc eDFunc = DF_SSE );
     312
     313  Distortion   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, const ComponentID compID, DFunc eDFunc = DF_SSE );
    327314
    328315#if KWU_RC_MADPRED_E0227
     
    330317#endif
    331318
    332 #if H_3D_VSO
    333   // SAIT_VSO_EST_A0033
    334   UInt        getDistPartVSD( TComDataCU* pcCu, UInt uiPartOffset, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bHad, DFunc eDFunc = DF_VSD);
     319#if NH_3D_VSO
     320  // SAIT_VSO_EST_A0033
     321  UInt        getDistPartVSD( TComDataCU* pcCu, UInt uiPartOffset, Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bHad, DFunc eDFunc = DF_VSD);
    335322  static UInt getVSDEstimate( Int dDM, Pel* pOrg, Int iOrgStride,  Pel* pVirRec, Pel* pVirOrg, Int iVirStride, Int x, Int y );
    336323
     
    365352  Void    setRenModel       ( TRenModel* pcRenModel ) { m_pcRenModel = pcRenModel; }
    366353  TRenModel* getRenModel    ( )                       { return m_pcRenModel; }
    367   Void    setRenModelData   ( TComDataCU* pcCU, UInt uiAbsPartIndex, Pel* piData, Int iStride, Int iBlkWidth, Int iBlkHeight );
     354  Void    setRenModelData   ( const TComDataCU* pcCU, UInt uiAbsPartIndex, const TComYuv* pcYuv, const TComTURecurse* tuRecurseWithPU );
     355  Void    setRenModelData   ( const TComDataCU* pcCU, UInt uiAbsPartIndex, const Pel* piData, Int iStride, Int iBlkWidth, Int iBlkHeight );
     356
    368357  Void    setLambdaVSO      ( Double dLambda );
    369358  Void    setFrameLambdaVSO ( Double dLambda ) { m_dFrameLambdaVSO = dLambda; };
     
    384373  Double  getLambdaVSO ()       { return m_dLambdaVSO; }
    385374
    386   Dist   getDistPartVSO( TComDataCU* pcCU, UInt uiAbsPartIndex, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD );
    387   Double calcRdCostVSO ( UInt   uiBits, Dist   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
     375  Dist    getDistPartVSO( TComDataCU* pcCU, UInt uiAbsPartIndex, Int bitdDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD );
     376  Double  calcRdCostVSO ( UInt   uiBits, Dist   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
    388377
    389378  // SAIT_VSO_EST_A0033
     
    409398  Dist xGetDistVSOMode4( Int iStartPosX, Int iStartPosY, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD );
    410399
    411 #endif // H_3D_VSO
     400#endif // NH_3D_VSO
     401
    412402
    413403};// END CLASS DEFINITION TComRdCost
Note: See TracChangeset for help on using the changeset viewer.