HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TComRdCost.h
Go to the documentation of this file.
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
4  * granted under this license.
5  *
6  * Copyright (c) 2010-2017, ITU/ISO/IEC
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.
17  * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
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 
38 #ifndef __TCOMRDCOST__
39 #define __TCOMRDCOST__
40 
41 
42 #include "CommonDef.h"
43 #include "TComPattern.h"
44 #include "TComMv.h"
45 
46 #include "TComSlice.h"
48 
51 
52 class DistParam;
53 class TComPattern;
54 
55 // ====================================================================================================================
56 // Type definition
57 // ====================================================================================================================
58 
59 // for function pointer
60 typedef Distortion (*FpDistFunc) (DistParam*); // TODO: can this pointer be replaced with a reference? - there are no NULL checks on pointer.
61 
62 // ====================================================================================================================
63 // Class definition
64 // ====================================================================================================================
65 
67 class DistParam
68 {
69 public:
70  const Pel* pOrg;
71  const Pel* pCur;
79 
80  Bool bApplyWeight; // whether weighted prediction is used or not
82 
83  const WPScalingParam *wpCur; // weighted prediction scaling parameters for current ref
86 
87  // (vertical) subsampling shift (for reducing complexity)
88  // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc.
90 
92  : pOrg(NULL),
93  pCur(NULL),
94  iStrideOrg(0),
95  iStrideCur(0),
96  iRows(0),
97  iCols(0),
98  iStep(1),
99  DistFunc(NULL),
100  bitDepth(0),
101  bApplyWeight(false),
102  bIsBiPred(false),
103  wpCur(NULL),
105  m_maximumDistortionForEarlyExit(std::numeric_limits<Distortion>::max()),
106  iSubShift(0)
107  { }
108 };
109 
112 {
113 private:
114  // for distortion
115 
118  Double m_distortionWeight[MAX_NUM_COMPONENT]; // only chroma values are used.
121  Double m_dLambdaMotionSAD[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
122  Double m_dLambdaMotionSSE[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
124 
125  // for motion cost
129 
130 public:
131  TComRdCost();
132  virtual ~TComRdCost();
133 
134  Double calcRdCost( Double numBits, Double distortion, DFunc eDFunc = DF_DEFAULT );
135 
136  Void setDistortionWeight ( const ComponentID compID, const Double distortionWeight ) { m_distortionWeight[compID] = distortionWeight; }
137  Void setLambda ( Double dLambda, const BitDepths &bitDepths );
138  Void setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
139 
141 
142  Double getLambda() { return m_dLambda; }
144 
146 
147  // Distortion Functions
148  Void init();
149 
150  Void setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
151  Void setDistParam( const TComPattern* const pcPatternKey, const Pel* piRefY, Int iRefStride, DistParam& rcDistParam );
152  Void setDistParam( const TComPattern* const pcPatternKey, const Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
153  Void setDistParam( DistParam& rcDP, Int bitDepth, const Pel* p1, Int iStride1, const Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
154 
155  Distortion calcHAD(Int bitDepth, const Pel* pi0, Int iStride0, const Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
156 
157  // for motion cost
158  static UInt xGetExpGolombNumberOfBits( Int iVal );
159  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); }
161  {
162  m_mvPredictor = rcMv;
163  }
164  Void setCostScale( Int iCostScale ) { m_iCostScale = iCostScale; }
165  Distortion getCost( UInt b ) { return Distortion(( m_motionLambda * b ) / 65536.0); }
167  {
168  return Distortion((m_motionLambda * getBitsOfVectorWithPredictor(x, y)) / 65536.0);
169  }
171  {
174  }
175 
176 private:
177 
178  static Distortion xGetSSE ( DistParam* pcDtParam );
179  static Distortion xGetSSE4 ( DistParam* pcDtParam );
180  static Distortion xGetSSE8 ( DistParam* pcDtParam );
181  static Distortion xGetSSE16 ( DistParam* pcDtParam );
182  static Distortion xGetSSE32 ( DistParam* pcDtParam );
183  static Distortion xGetSSE64 ( DistParam* pcDtParam );
184  static Distortion xGetSSE16N ( DistParam* pcDtParam );
185 
186  static Distortion xGetSAD ( DistParam* pcDtParam );
187  static Distortion xGetSAD4 ( DistParam* pcDtParam );
188  static Distortion xGetSAD8 ( DistParam* pcDtParam );
189  static Distortion xGetSAD16 ( DistParam* pcDtParam );
190  static Distortion xGetSAD32 ( DistParam* pcDtParam );
191  static Distortion xGetSAD64 ( DistParam* pcDtParam );
192  static Distortion xGetSAD16N ( DistParam* pcDtParam );
193 
194  static Distortion xGetSAD12 ( DistParam* pcDtParam );
195  static Distortion xGetSAD24 ( DistParam* pcDtParam );
196  static Distortion xGetSAD48 ( DistParam* pcDtParam );
197 
198  static Distortion xGetHADs ( DistParam* pcDtParam );
199  static Distortion xCalcHADs2x2 ( const Pel *piOrg, const Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
200  static Distortion xCalcHADs4x4 ( const Pel *piOrg, const Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
201  static Distortion xCalcHADs8x8 ( const Pel *piOrg, const Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep
203  , Int bitDepth
204 #endif
205  );
206 
207 public:
208 
209  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 );
210 
211 };// END CLASS DEFINITION TComRdCost
212 
214 
215 #endif // __TCOMRDCOST__
Distortion getCost(UInt b)
Definition: TComRdCost.h:165
Void setDistortionWeight(const ComponentID compID, const Double distortionWeight)
Definition: TComRdCost.h:136
Double getLambda()
Definition: TComRdCost.h:142
Distortion(* FpDistFunc)(DistParam *)
Definition: TComRdCost.h:60
Double getSqrtLambda()
Definition: TComRdCost.h:140
Double getChromaWeight()
Definition: TComRdCost.h:143
Int iCols
Definition: TComRdCost.h:75
Int getHor() const
Definition: TComMv.h:88
Int iRows
Definition: TComRdCost.h:74
Defines version information, constants and small in-line functions.
UInt Distortion
distortion measurement
Definition: TypeDef.h:260
void Void
Definition: TypeDef.h:203
static Distortion xGetSAD48(DistParam *pcDtParam)
const Pel * pCur
Definition: TComRdCost.h:71
Double m_dLambda
Definition: TComRdCost.h:119
virtual ~TComRdCost()
Definition: TComRdCost.cpp:57
static Distortion xGetHADs(DistParam *pcDtParam)
static Distortion xGetSSE4(DistParam *pcDtParam)
#define NULL
Definition: CommonDef.h:107
static Distortion xGetSAD64(DistParam *pcDtParam)
Definition: TComRdCost.cpp:974
neighbouring pixel access class for all components
Definition: TComPattern.h:55
slice header and SPS class (header)
unsigned int UInt
Definition: TypeDef.h:212
static Distortion xCalcHADs2x2(const Pel *piOrg, const Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep)
Short Pel
pixel type
Definition: TypeDef.h:249
static Distortion xGetSSE(DistParam *pcDtParam)
Double m_dLambdaMotionSAD[2]
Definition: TComRdCost.h:121
static Distortion xGetSAD32(DistParam *pcDtParam)
Definition: TComRdCost.cpp:832
#define RExt__HIGH_BIT_DEPTH_SUPPORT
0 (default) use data type definitions for 8-10 bit video, 1 = use larger data types to allow for up t...
Definition: TypeDef.h:138
general size SSE
Definition: TypeDef.h:382
static Distortion xGetSAD24(DistParam *pcDtParam)
Definition: TComRdCost.cpp:907
Void setCostMode(CostMode m)
Definition: TComRdCost.h:145
static Distortion xCalcHADs8x8(const Pel *piOrg, const Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep)
Int m_iCostScale
Definition: TComRdCost.h:128
Void init()
Definition: TComRdCost.cpp:126
Int iSubShift
During cost calculations, if distortion exceeds this value, cost calculations may early-terminate...
Definition: TComRdCost.h:89
Double m_motionLambda
Definition: TComRdCost.h:127
static Distortion xCalcHADs4x4(const Pel *piOrg, const Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep)
Int iStep
Definition: TComRdCost.h:76
bool Bool
Definition: TypeDef.h:204
Double calcRdCost(Double numBits, Double distortion, DFunc eDFunc=DF_DEFAULT)
Definition: TComRdCost.cpp:62
static Distortion xGetSAD16(DistParam *pcDtParam)
Definition: TComRdCost.cpp:676
static Distortion xGetSSE8(DistParam *pcDtParam)
distortion parameter class
Definition: TComRdCost.h:67
Int iStrideOrg
Definition: TComRdCost.h:72
TComMv m_mvPredictor
Definition: TComRdCost.h:126
static Distortion xGetSSE16(DistParam *pcDtParam)
RD cost computation class.
Definition: TComRdCost.h:111
static Distortion xGetSSE16N(DistParam *pcDtParam)
Double m_sqrtLambda
Definition: TComRdCost.h:120
Void setLambda(Double dLambda, const BitDepths &bitDepths)
Definition: TComRdCost.cpp:109
static Distortion xGetSSE64(DistParam *pcDtParam)
static Distortion xGetSAD(DistParam *pcDtParam)
Definition: TComRdCost.cpp:518
Distortion m_maximumDistortionForEarlyExit
Definition: TComRdCost.h:85
ComponentID compIdx
Definition: TComRdCost.h:84
motion vector class (header)
Double m_dLambdaMotionSSE[2]
Definition: TComRdCost.h:122
Bool bApplyWeight
Definition: TComRdCost.h:80
Int iStrideCur
Definition: TComRdCost.h:73
Distortion getCostOfVectorWithPredictor(const Int x, const Int y)
Definition: TComRdCost.h:166
Double m_distortionWeight[MAX_NUM_COMPONENT]
Definition: TComRdCost.h:118
CostMode
Definition: TypeDef.h:620
Int getVer() const
Definition: TComMv.h:89
Void setDistParam(UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam &rcDistParam)
Definition: TComRdCost.cpp:192
#define VECTOR_CODING__DISTORTION_CALCULATIONS
enable vector coding for distortion calculations 0 (default if SSE not possible) disable SSE vector c...
Definition: TypeDef.h:146
Void setPredictor(TComMv &rcMv)
Definition: TComRdCost.h:160
RD cost computation namespace (header)
static Distortion xGetSAD4(DistParam *pcDtParam)
Definition: TComRdCost.cpp:578
Double m_dFrameLambda
Definition: TComRdCost.h:123
static Distortion xGetSSE32(DistParam *pcDtParam)
static Distortion xGetSAD16N(DistParam *pcDtParam)
Definition: TComRdCost.cpp:774
Int bitDepth
Definition: TComRdCost.h:78
neighbouring pixel access classes (header)
Void setFrameLambda(Double dLambda)
Definition: TComRdCost.h:138
CostMode m_costMode
Definition: TComRdCost.h:117
Void setCostScale(Int iCostScale)
Definition: TComRdCost.h:164
FpDistFunc DistFunc
Definition: TComRdCost.h:77
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)
Definition: TComRdCost.cpp:336
int Int
Definition: TypeDef.h:211
basic motion vector class
Definition: TComMv.h:51
ComponentID
Definition: TypeDef.h:308
static UInt xGetExpGolombNumberOfBits(Int iVal)
Definition: TComRdCost.cpp:177
FpDistFunc m_afpDistortFunc[DF_TOTAL_FUNCTIONS]
Definition: TComRdCost.h:116
Bool bIsBiPred
Definition: TComRdCost.h:81
static Distortion xGetSAD12(DistParam *pcDtParam)
Definition: TComRdCost.cpp:735
const WPScalingParam * wpCur
Definition: TComRdCost.h:83
double Double
Definition: TypeDef.h:213
Distortion calcHAD(Int bitDepth, const Pel *pi0, Int iStride0, const Pel *pi1, Int iStride1, Int iWidth, Int iHeight)
Definition: TComRdCost.cpp:297
static Distortion xGetSAD8(DistParam *pcDtParam)
Definition: TComRdCost.cpp:625
const Pel * pOrg
Definition: TComRdCost.h:70
Void selectMotionLambda(Bool bSad, Int iAdd, Bool bIsTransquantBypass)
Definition: TComRdCost.h:159
UInt getBitsOfVectorWithPredictor(const Int x, const Int y)
Definition: TComRdCost.h:170
DFunc
distortion function index
Definition: TypeDef.h:379