source: 3DVCSoftware/trunk/source/Lib/TLibCommon/TComRdCost.h @ 1417

Last change on this file since 1417 was 1413, checked in by tech, 6 years ago

Merged HTM-16.2-dev@1412

  • Property svn:eol-style set to native
File size: 15.8 KB
RevLine 
[5]1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
[1313]4 * granted under this license.
[5]5 *
[1413]6 * Copyright (c) 2010-2017, ITU/ISO/IEC
[5]7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
[2]34/** \file     TComRdCost.h
35    \brief    RD cost computation classes (header)
36*/
37
38#ifndef __TCOMRDCOST__
39#define __TCOMRDCOST__
40
41
42#include "CommonDef.h"
43#include "TComPattern.h"
44#include "TComMv.h"
[56]45
46#include "TComSlice.h"
47#include "TComRdCostWeightPrediction.h"
[1386]48#if NH_3D_VSO
[2]49#include "../TLibRenderer/TRenModel.h"
[1313]50#include "TComYuv.h"
51#include "TComTU.h"
[608]52#endif
[2]53
[56]54//! \ingroup TLibCommon
55//! \{
56
[2]57class DistParam;
58class TComPattern;
[1386]59#if NH_3D_VSO
[56]60class TComRdCost; 
[608]61#endif
[2]62
63// ====================================================================================================================
64// Type definition
65// ====================================================================================================================
66
67// for function pointer
[1313]68typedef Distortion (*FpDistFunc) (DistParam*); // TODO: can this pointer be replaced with a reference? - there are no NULL checks on pointer.
[2]69
[1386]70
[1313]71#if NH_3D_VSO
[2]72typedef Dist (TComRdCost::*FpDistFuncVSO) ( Int, Int, Pel*, Int, Pel*, Int, UInt, UInt, Bool );
73#endif
74// ====================================================================================================================
75// Class definition
76// ====================================================================================================================
77
78/// distortion parameter class
79class DistParam
80{
81public:
[1386]82  const Pel*            pOrg;
83  const Pel*            pCur;
[2]84  Int   iStrideOrg;
85  Int   iStrideCur;
[1313]86#if NH_3D_VSO
[608]87  // SAIT_VSO_EST_A0033
[100]88  Pel*  pVirRec;
89  Pel*  pVirOrg;
90  Int   iStrideVir;
91#endif
[1413]92#if NH_3D
[608]93  Bool  bUseIC;
94  Bool  bUseSDCMRSAD;
95#endif
[2]96  Int   iRows;
97  Int   iCols;
98  Int   iStep;
99  FpDistFunc DistFunc;
[608]100  Int   bitDepth;
[56]101
[1313]102  Bool            bApplyWeight;     // whether weighted prediction is used or not
[1386]103  Bool                  bIsBiPred;
104
105  const WPScalingParam *wpCur;           // weighted prediction scaling parameters for current ref
[1313]106  ComponentID     compIdx;
[1386]107  Distortion            m_maximumDistortionForEarlyExit; /// During cost calculations, if distortion exceeds this value, cost calculations may early-terminate.
[2]108
109  // (vertical) subsampling shift (for reducing complexity)
110  // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc.
111  Int   iSubShift;
[1313]112
[2]113  DistParam()
[1386]114   : pOrg(NULL),
115     pCur(NULL),
116     iStrideOrg(0),
117     iStrideCur(0),
118     iRows(0),
119     iCols(0),
120     iStep(1),
121     DistFunc(NULL),
122     bitDepth(0),
123     bApplyWeight(false),
124     bIsBiPred(false),
125     wpCur(NULL),
126     compIdx(MAX_NUM_COMPONENT),
127     m_maximumDistortionForEarlyExit(std::numeric_limits<Distortion>::max()),
128     iSubShift(0)
[2]129  {
[1313]130#if NH_3D_VSO
[608]131    // SAIT_VSO_EST_A0033
132    pVirRec = NULL;
133    pVirOrg = NULL;
134    iStrideVir = 0;
135#endif
[1413]136#if NH_3D
[608]137    bUseSDCMRSAD = false;
138#endif
[2]139  }
140};
141
142/// RD cost computation class
143class TComRdCost
144{
145private:
146  // for distortion
[1313]147
148  FpDistFunc              m_afpDistortFunc[DF_TOTAL_FUNCTIONS]; // [eDFunc]
149  CostMode                m_costMode;
150  Double                  m_distortionWeight[MAX_NUM_COMPONENT]; // only chroma values are used.
[2]151  Double                  m_dLambda;
152  Double                  m_sqrtLambda;
[1313]153  Double                  m_dLambdaMotionSAD[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
154  Double                  m_dLambdaMotionSSE[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
[2]155  Double                  m_dFrameLambda;
[1313]156#if NH_3D_VSO
[608]157  // SAIT_VSO_EST_A0033
[100]158  static Double           m_dDisparityCoeff;
159#endif
[1313]160
[2]161  // for motion cost
[56]162  TComMv                  m_mvPredictor;
[1386]163  Double                  m_motionLambda;
[2]164  Int                     m_iCostScale;
[1413]165#if NH_3D
[833]166  Bool                    m_bUseMask;
167#endif
[1313]168
[2]169public:
170  TComRdCost();
171  virtual ~TComRdCost();
[1313]172#if NH_3D_VSO
[1386]173  Double  calcRdCost64( UInt64 uiBits , Dist64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
174  Double  calcRdCost( Double numBits, Dist intDistortion, DFunc eDFunc  = DF_DEFAULT );
[608]175#else
[1386]176  Double calcRdCost( Double numBits, Double distortion, DFunc eDFunc = DF_DEFAULT );
[608]177#endif
178
[1386]179
[1313]180  Void    setDistortionWeight  ( const ComponentID compID, const Double distortionWeight ) { m_distortionWeight[compID] = distortionWeight; }
181  Void    setLambda      ( Double dLambda, const BitDepths &bitDepths );
[2]182  Void    setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
[1313]183
[608]184  Double  getSqrtLambda ()   { return m_sqrtLambda; }
[1313]185#if NH_3D_VSO
[608]186  // SAIT_VSO_EST_A0033
[100]187  Void    setDisparityCoeff( Double dDisparityCoeff ) { m_dDisparityCoeff = dDisparityCoeff; }
188  Double  getDisparityCoeff()                         { return m_dDisparityCoeff; }
189#endif
190
[608]191  Double  getLambda() { return m_dLambda; }
[1313]192  Double  getChromaWeight () { return ((m_distortionWeight[COMPONENT_Cb] + m_distortionWeight[COMPONENT_Cr]) / 2.0); }
193
194  Void    setCostMode(CostMode   m )    { m_costMode = m; }
195
[2]196  // Distortion Functions
197  Void    init();
[1313]198
[2]199  Void    setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
[1386]200  Void    setDistParam( const TComPattern* const pcPatternKey, const Pel* piRefY, Int iRefStride,            DistParam& rcDistParam );
201  Void    setDistParam( const TComPattern* const pcPatternKey, const Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
202  Void    setDistParam( DistParam& rcDP, Int bitDepth, const Pel* p1, Int iStride1, const Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
[1313]203
[1413]204#if NH_3D
[833]205  Void    setUseMask(Bool b) { m_bUseMask = b; }
206#endif
[1313]207
[1386]208  Distortion calcHAD(Int bitDepth, const Pel* pi0, Int iStride0, const Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
[1313]209
[1413]210#if NH_3D
[1313]211  UInt    calcVAR(Pel* pi0, Int stride, Int width, Int height, Int cuDepth, UInt maxCuWidth );
[608]212#endif 
[1313]213
[2]214  // for motion cost
[1313]215  static UInt    xGetExpGolombNumberOfBits( Int iVal );
[1386]216  Void    selectMotionLambda( Bool bSad, Int iAdd, Bool bIsTransquantBypass ) { m_motionLambda = (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); }
[2]217  Void    setPredictor( TComMv& rcMv )
218  {
[56]219    m_mvPredictor = rcMv;
[2]220  }
221  Void    setCostScale( Int iCostScale )    { m_iCostScale = iCostScale; }
[1386]222  Distortion getCost( UInt b )                 { return Distortion(( m_motionLambda * b ) / 65536.0); }
223  Distortion getCostOfVectorWithPredictor( const Int x, const Int y )
[2]224  {
[1386]225    return Distortion((m_motionLambda * getBitsOfVectorWithPredictor(x, y)) / 65536.0);
[2]226  }
[1386]227  UInt getBitsOfVectorWithPredictor( const Int x, const Int y )
[1313]228  {
229    return xGetExpGolombNumberOfBits((x << m_iCostScale) - m_mvPredictor.getHor())
230    +      xGetExpGolombNumberOfBits((y << m_iCostScale) - m_mvPredictor.getVer());
[56]231  }
[1313]232
[2]233private:
[1313]234
235  static Distortion xGetSSE           ( DistParam* pcDtParam );
236  static Distortion xGetSSE4          ( DistParam* pcDtParam );
237  static Distortion xGetSSE8          ( DistParam* pcDtParam );
238  static Distortion xGetSSE16         ( DistParam* pcDtParam );
239  static Distortion xGetSSE32         ( DistParam* pcDtParam );
240  static Distortion xGetSSE64         ( DistParam* pcDtParam );
241  static Distortion xGetSSE16N        ( DistParam* pcDtParam );
[1413]242#if NH_3D
[189]243  static UInt xGetSADic         ( DistParam* pcDtParam );
244  static UInt xGetSAD4ic        ( DistParam* pcDtParam );
245  static UInt xGetSAD8ic        ( DistParam* pcDtParam );
246  static UInt xGetSAD16ic       ( DistParam* pcDtParam );
247  static UInt xGetSAD32ic       ( DistParam* pcDtParam );
248  static UInt xGetSAD64ic       ( DistParam* pcDtParam );
249  static UInt xGetSAD16Nic      ( DistParam* pcDtParam );
250#endif
[1313]251
252  static Distortion xGetSAD           ( DistParam* pcDtParam );
253  static Distortion xGetSAD4          ( DistParam* pcDtParam );
254  static Distortion xGetSAD8          ( DistParam* pcDtParam );
255  static Distortion xGetSAD16         ( DistParam* pcDtParam );
256  static Distortion xGetSAD32         ( DistParam* pcDtParam );
257  static Distortion xGetSAD64         ( DistParam* pcDtParam );
258  static Distortion xGetSAD16N        ( DistParam* pcDtParam );
259#if NH_3D_VSO
[100]260  static UInt xGetVSD           ( DistParam* pcDtParam );
261  static UInt xGetVSD4          ( DistParam* pcDtParam );
262  static UInt xGetVSD8          ( DistParam* pcDtParam );
263  static UInt xGetVSD16         ( DistParam* pcDtParam );
264  static UInt xGetVSD32         ( DistParam* pcDtParam );
265  static UInt xGetVSD64         ( DistParam* pcDtParam );
266  static UInt xGetVSD16N        ( DistParam* pcDtParam );
267#endif
268
[1413]269#if NH_3D
[189]270  static UInt xGetSAD12ic       ( DistParam* pcDtParam );
271  static UInt xGetSAD24ic       ( DistParam* pcDtParam );
272  static UInt xGetSAD48ic       ( DistParam* pcDtParam );
273#endif
[608]274
[1313]275  static Distortion xGetSAD12         ( DistParam* pcDtParam );
276  static Distortion xGetSAD24         ( DistParam* pcDtParam );
277  static Distortion xGetSAD48         ( DistParam* pcDtParam );
[2]278
[1313]279
[1413]280#if NH_3D
[189]281  static UInt xGetHADsic          ( DistParam* pcDtParam );
[56]282#endif
[1313]283
284  static Distortion xGetHADs          ( DistParam* pcDtParam );
[1386]285  static Distortion xCalcHADs2x2      ( const Pel *piOrg, const Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
286  static Distortion xCalcHADs4x4      ( const Pel *piOrg, const Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
[1413]287  static Distortion xCalcHADs8x8      ( const Pel *piOrg, const Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep
288#if VECTOR_CODING__DISTORTION_CALCULATIONS && (RExt__HIGH_BIT_DEPTH_SUPPORT==0)
289                                      , Int bitDepth
290#endif
291                                      );
292#if NH_3D
[833]293  static UInt xGetMaskedSSE     ( DistParam* pcDtParam );
294  static UInt xGetMaskedSAD     ( DistParam* pcDtParam );
295  static UInt xGetMaskedVSD     ( DistParam* pcDtParam );
296#endif
[1313]297
298
[2]299public:
[608]300
[1386]301  Distortion   getDistPart(Int bitDepth, const Pel* piCur, Int iCurStride, const Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, const ComponentID compID, DFunc eDFunc = DF_SSE );
[1313]302
[872]303#if KWU_RC_MADPRED_E0227
[608]304  UInt   getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height );
[100]305#endif
306
[1313]307#if NH_3D_VSO
[608]308  // SAIT_VSO_EST_A0033
[1313]309  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); 
[1386]310  static UInt getVSDEstimate( Int dDM, const Pel* pOrg, Int iOrgStride,  const Pel* pVirRec, const Pel* pVirOrg, Int iVirStride, Int x, Int y );
[608]311
[2]312private:
313  Double                  m_dLambdaVSO;
314  Double                  m_dSqrtLambdaVSO;
315  UInt                    m_uiLambdaMotionSADVSO;
316  UInt                    m_uiLambdaMotionSSEVSO;
317  Double                  m_dFrameLambdaVSO;
[608]318  Bool                    m_bAllowNegDist;
319  Bool                    m_bUseVSO;
320  Bool                    m_bUseLambdaScaleVSO;
321  UInt                    m_uiVSOMode;
[2]322
[608]323  FpDistFuncVSO           m_fpDistortFuncVSO;
324  TRenModel*              m_pcRenModel;
325
326
327  // SAIT_VSO_EST_A0033
[100]328  TComPicYuv *            m_pcVideoRecPicYuv;
329  TComPicYuv *            m_pcDepthPicYuv;
330  Bool                    m_bUseEstimatedVSD; 
[608]331
332  // LGE_WVSO_A0119
[116]333  Int                     m_iDWeight;
334  Int                     m_iVSOWeight;
[115]335  Int                     m_iVSDWeight;
[120]336  Bool                    m_bUseWVSO;
[2]337
338public:
339
340  Void    setRenModel       ( TRenModel* pcRenModel ) { m_pcRenModel = pcRenModel; }
[608]341  TRenModel* getRenModel    ( )                       { return m_pcRenModel; }
[1313]342  Void    setRenModelData   ( const TComDataCU* pcCU, UInt uiAbsPartIndex, const TComYuv* pcYuv, const TComTURecurse* tuRecurseWithPU );
343  Void    setRenModelData   ( const TComDataCU* pcCU, UInt uiAbsPartIndex, const Pel* piData, Int iStride, Int iBlkWidth, Int iBlkHeight );
344
[2]345  Void    setLambdaVSO      ( Double dLambda );
346  Void    setFrameLambdaVSO ( Double dLambda ) { m_dFrameLambdaVSO = dLambda; };
347
348
349  Void    setUseVSO ( Bool bIn )         { m_bUseVSO = bIn; };
350  Bool    getUseVSO ( )                  { return m_bUseVSO;};
[608]351
352  Bool    getUseRenModel ( )             { return (m_bUseVSO && m_uiVSOMode == 4); };
353  Void    setUseLambdaScaleVSO(Bool bIn) { m_bUseLambdaScaleVSO = bIn; };
354  Bool    getUseLambdaScaleVSO( )        { return m_bUseLambdaScaleVSO; };
355
356  Void    setVSOMode( UInt uiIn);
357  UInt    getVSOMode( )                  { return m_uiVSOMode; }
358  Void    setAllowNegDist ( Bool bAllowNegDist );
359
360  Double  getSqrtLambdaVSO ()   { return m_dSqrtLambdaVSO; }
361  Double  getLambdaVSO ()       { return m_dLambdaVSO; }
362
[1313]363  Dist    getDistPartVSO( TComDataCU* pcCU, UInt uiAbsPartIndex, Int bitdDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD );
364  Double  calcRdCostVSO ( UInt   uiBits, Dist   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
[608]365
366  // SAIT_VSO_EST_A0033
[100]367  Bool    getUseEstimatedVSD( )           { return m_bUseEstimatedVSD; };
368  Void    setUseEstimatedVSD( Bool bIn )  { m_bUseEstimatedVSD = bIn; };
[2]369
[100]370  TComPicYuv* getVideoRecPicYuv ()                               { return m_pcVideoRecPicYuv; };
371  Void        setVideoRecPicYuv ( TComPicYuv* pcVideoRecPicYuv ) { m_pcVideoRecPicYuv = pcVideoRecPicYuv; };
372  TComPicYuv* getDepthPicYuv    ()                               { return m_pcDepthPicYuv; };
373  Void        setDepthPicYuv    ( TComPicYuv* pcDepthPicYuv )    { m_pcDepthPicYuv = pcDepthPicYuv; };
374
[608]375  // LGE_WVSO_A0119
[120]376  Void    setUseWVSO ( Bool bIn )         { m_bUseWVSO = bIn; }; 
377  Bool    getUseWVSO ( )                  { return m_bUseWVSO;};
[116]378  Void    setDWeight   ( Int iDWeight   ) { m_iDWeight = iDWeight; };
379  Int     getDWeight   ()                 { return m_iDWeight; };
380  Void    setVSOWeight ( Int iVSOWeight ) { m_iVSOWeight = iVSOWeight; };
381  Int     getVSOWeight ()                 { return m_iVSOWeight; };
382  Void    setVSDWeight ( Int iVSDWeight ) { m_iVSDWeight = iVSDWeight; };
383  Int     getVSDWeight ()                 { return m_iVSDWeight; };
[2]384
385private:
386  Dist xGetDistVSOMode4( Int iStartPosX, Int iStartPosY, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD );
387
[1313]388#endif // NH_3D_VSO
[2]389
[1313]390
[2]391};// END CLASS DEFINITION TComRdCost
392
[56]393//! \}
[2]394
395#endif // __TCOMRDCOST__
Note: See TracBrowser for help on using the repository browser.