1 | /** \file TComRdCost.h |
---|
2 | \brief RD cost computation classes (header) |
---|
3 | */ |
---|
4 | |
---|
5 | #ifndef __TCOMRDCOST__ |
---|
6 | #define __TCOMRDCOST__ |
---|
7 | |
---|
8 | |
---|
9 | #include "CommonDef.h" |
---|
10 | #include "TComMVDRefData.h" |
---|
11 | #include "TComDataCU.h" |
---|
12 | #include "TComPattern.h" |
---|
13 | #include "TComMv.h" |
---|
14 | #ifdef WEIGHT_PRED |
---|
15 | #include "TComSlice.h" |
---|
16 | #include "TComRdCostWeightPrediction.h" |
---|
17 | #endif |
---|
18 | #include "TComYuv.h" |
---|
19 | #include "TComMVDRefData.h" |
---|
20 | #include "../TLibRenderer/TRenModel.h" |
---|
21 | |
---|
22 | class DistParam; |
---|
23 | class TComPattern; |
---|
24 | class TComRdCost; |
---|
25 | |
---|
26 | // ==================================================================================================================== |
---|
27 | // Type definition |
---|
28 | // ==================================================================================================================== |
---|
29 | |
---|
30 | // for function pointer |
---|
31 | typedef UInt (*FpDistFunc) (DistParam*); |
---|
32 | |
---|
33 | //GT VSO |
---|
34 | typedef Dist (TComRdCost::*FpDistFuncVSO) ( Int, Int, Pel*, Int, Pel*, Int, UInt, UInt, Bool ); |
---|
35 | //GT VSO end |
---|
36 | |
---|
37 | #ifdef ROUNDING_CONTROL_BIPRED |
---|
38 | typedef UInt (*FpDistFuncRnd) (DistParam*, Pel*, Bool); |
---|
39 | #endif |
---|
40 | |
---|
41 | // ==================================================================================================================== |
---|
42 | // Class definition |
---|
43 | // ==================================================================================================================== |
---|
44 | |
---|
45 | /// distortion parameter class |
---|
46 | class DistParam |
---|
47 | { |
---|
48 | public: |
---|
49 | Pel* pOrg; |
---|
50 | Pel* pCur; |
---|
51 | Int iStrideOrg; |
---|
52 | Int iStrideCur; |
---|
53 | Int iRows; |
---|
54 | Int iCols; |
---|
55 | Int iStep; |
---|
56 | FpDistFunc DistFunc; |
---|
57 | #ifdef ROUNDING_CONTROL_BIPRED |
---|
58 | FpDistFuncRnd DistFuncRnd; |
---|
59 | #endif |
---|
60 | #if SB_INTERVIEW_SKIP |
---|
61 | Pel* pUsed; |
---|
62 | Int iStrideUsed; |
---|
63 | #endif |
---|
64 | |
---|
65 | #ifdef WEIGHT_PRED |
---|
66 | Bool applyWeight; // whether weithed prediction is used or not |
---|
67 | wpScalingParam *wpCur, *wpRef; // weithed prediction scaling parameters for ref0 (or ref1) and ref1 (resp. ref0) |
---|
68 | UInt uiComp; // uiComp = 0 (luma Y), 1 (chroma U), 2 (chroma V) |
---|
69 | #endif |
---|
70 | |
---|
71 | // (vertical) subsampling shift (for reducing complexity) |
---|
72 | // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc. |
---|
73 | Int iSubShift; |
---|
74 | |
---|
75 | DistParam() |
---|
76 | { |
---|
77 | pOrg = NULL; |
---|
78 | pCur = NULL; |
---|
79 | iStrideOrg = 0; |
---|
80 | iStrideCur = 0; |
---|
81 | iRows = 0; |
---|
82 | iCols = 0; |
---|
83 | iStep = 1; |
---|
84 | DistFunc = NULL; |
---|
85 | #ifdef ROUNDING_CONTROL_BIPRED |
---|
86 | DistFuncRnd = NULL; |
---|
87 | #endif |
---|
88 | iSubShift = 0; |
---|
89 | #if SB_INTERVIEW_SKIP |
---|
90 | pUsed = 0; |
---|
91 | iStrideUsed = 0; |
---|
92 | #endif |
---|
93 | } |
---|
94 | }; |
---|
95 | |
---|
96 | /// RD cost computation class |
---|
97 | class TComRdCost |
---|
98 | #ifdef WEIGHT_PRED |
---|
99 | : public TComRdCostWeightPrediction |
---|
100 | #endif |
---|
101 | { |
---|
102 | private: |
---|
103 | // for distortion |
---|
104 | Int m_iBlkWidth; |
---|
105 | Int m_iBlkHeight; |
---|
106 | |
---|
107 | FpDistFunc m_afpDistortFunc[33]; // [eDFunc] |
---|
108 | #ifdef ROUNDING_CONTROL_BIPRED |
---|
109 | FpDistFuncRnd m_afpDistortFuncRnd[33]; |
---|
110 | #endif |
---|
111 | |
---|
112 | Double m_dLambda; |
---|
113 | Double m_sqrtLambda; |
---|
114 | UInt m_uiLambdaMotionSAD; |
---|
115 | UInt m_uiLambdaMotionSSE; |
---|
116 | Double m_dFrameLambda; |
---|
117 | |
---|
118 | #if SB_INTERVIEW_SKIP_LAMBDA_SCALE |
---|
119 | Double m_dLambdaScale ; |
---|
120 | #endif |
---|
121 | // for motion cost |
---|
122 | UInt* m_puiComponentCostOriginP; |
---|
123 | UInt* m_puiComponentCost; |
---|
124 | UInt* m_puiVerCost; |
---|
125 | UInt* m_puiHorCost; |
---|
126 | UInt m_uiCost; |
---|
127 | Int m_iCostScale; |
---|
128 | Int m_iSearchLimit; |
---|
129 | |
---|
130 | Bool m_bUseMultiviewReg; |
---|
131 | UInt m_uiLambdaMVReg; |
---|
132 | UInt m_uiLambdaMVRegSAD; |
---|
133 | UInt m_uiLambdaMVRegSSE; |
---|
134 | UInt* m_puiMultiviewRegCostHorOrgP; |
---|
135 | UInt* m_puiMultiviewRegCostVerOrgP; |
---|
136 | UInt* m_puiMultiviewRegCostHor; |
---|
137 | UInt* m_puiMultiviewRegCostVer; |
---|
138 | UInt* m_puiHorRegCost; |
---|
139 | UInt* m_puiVerRegCost; |
---|
140 | TComMv m_cMultiviewOrgMvPred; |
---|
141 | |
---|
142 | public: |
---|
143 | TComRdCost(); |
---|
144 | virtual ~TComRdCost(); |
---|
145 | |
---|
146 | Double calcRdCost ( UInt uiBits, Dist uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT ); |
---|
147 | Double calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT ); |
---|
148 | |
---|
149 | Void setLambda ( Double dLambda ); |
---|
150 | Void setLambdaMVReg ( Double dLambda ); |
---|
151 | Void setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; } |
---|
152 | |
---|
153 | #if SB_INTERVIEW_SKIP_LAMBDA_SCALE |
---|
154 | Void setLambdaScale ( Double dLambdaScale) { m_dLambdaScale = dLambdaScale; } |
---|
155 | Double getLambdaScale ( ) { return m_dLambdaScale ; } |
---|
156 | #endif |
---|
157 | Double getSqrtLambda () { return m_sqrtLambda; } |
---|
158 | |
---|
159 | // Distortion Functions |
---|
160 | Void init(); |
---|
161 | |
---|
162 | Void setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam ); |
---|
163 | Void setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, DistParam& rcDistParam ); |
---|
164 | Void setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false ); |
---|
165 | Void setDistParam( DistParam& rcDP, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false ); |
---|
166 | |
---|
167 | #ifdef ROUNDING_CONTROL_BIPRED |
---|
168 | Void setDistParam_Bi( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, DistParam& rcDistParam ); |
---|
169 | Void setDistParam_Bi( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false ); |
---|
170 | #endif |
---|
171 | |
---|
172 | UInt calcHAD ( Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight ); |
---|
173 | |
---|
174 | // for motion cost |
---|
175 | Void initRateDistortionModel( Int iSubPelSearchLimit ); |
---|
176 | Void xUninit(); |
---|
177 | UInt xGetComponentBits( Int iVal ); |
---|
178 | Void getMotionCost( Bool bSad, Int iAdd ) |
---|
179 | { |
---|
180 | m_uiCost = ( bSad ? m_uiLambdaMotionSAD + iAdd : m_uiLambdaMotionSSE + iAdd ); |
---|
181 | m_uiLambdaMVReg = ( bSad ? m_uiLambdaMVRegSAD : m_uiLambdaMVRegSSE ); |
---|
182 | } |
---|
183 | Void setPredictor( TComMv& rcMv ) |
---|
184 | { |
---|
185 | m_puiHorCost = m_puiComponentCost - rcMv.getHor(); |
---|
186 | m_puiVerCost = m_puiComponentCost - rcMv.getVer(); |
---|
187 | } |
---|
188 | Void setCostScale( Int iCostScale ) { m_iCostScale = iCostScale; } |
---|
189 | __inline UInt getCost( Int x, Int y ) |
---|
190 | { |
---|
191 | return (( m_uiCost * (m_puiHorCost[ x * (1<<m_iCostScale) ] + m_puiVerCost[ y * (1<<m_iCostScale) ]) ) >> 16); |
---|
192 | } |
---|
193 | UInt getCost( UInt b ) { return ( m_uiCost * b ) >> 16; } |
---|
194 | UInt getBits( Int x, Int y ) { return m_puiHorCost[ x * (1<<m_iCostScale)] + m_puiVerCost[ y * (1<<m_iCostScale) ]; } |
---|
195 | |
---|
196 | Void setMultiviewReg( TComMv* pcMv ) |
---|
197 | { |
---|
198 | if( pcMv ) |
---|
199 | { |
---|
200 | m_bUseMultiviewReg = true; |
---|
201 | m_puiHorRegCost = m_puiMultiviewRegCostHor - pcMv->getHor(); |
---|
202 | m_puiVerRegCost = m_puiMultiviewRegCostVer - pcMv->getVer(); |
---|
203 | m_cMultiviewOrgMvPred = *pcMv; |
---|
204 | } |
---|
205 | else |
---|
206 | { |
---|
207 | m_bUseMultiviewReg = false; |
---|
208 | m_puiHorRegCost = 0; |
---|
209 | m_puiVerRegCost = 0; |
---|
210 | m_cMultiviewOrgMvPred.set( 0, 0 ); |
---|
211 | } |
---|
212 | } |
---|
213 | __inline Bool useMultiviewReg () { return m_bUseMultiviewReg; } |
---|
214 | __inline TComMv& getMultiviewOrgMvPred() { return m_cMultiviewOrgMvPred; } |
---|
215 | __inline UInt getMultiviewRegCost ( Int x, Int y ) |
---|
216 | { |
---|
217 | return ( ( m_uiLambdaMVReg * ( m_puiHorRegCost[ x * ( 1 << m_iCostScale ) ] + m_puiVerRegCost[ y * ( 1 << m_iCostScale ) ] ) ) >> 16 ); |
---|
218 | } |
---|
219 | |
---|
220 | private: |
---|
221 | |
---|
222 | static UInt xGetSSE ( DistParam* pcDtParam ); |
---|
223 | static UInt xGetSSE4 ( DistParam* pcDtParam ); |
---|
224 | static UInt xGetSSE8 ( DistParam* pcDtParam ); |
---|
225 | static UInt xGetSSE16 ( DistParam* pcDtParam ); |
---|
226 | static UInt xGetSSE32 ( DistParam* pcDtParam ); |
---|
227 | static UInt xGetSSE64 ( DistParam* pcDtParam ); |
---|
228 | static UInt xGetSSE16N ( DistParam* pcDtParam ); |
---|
229 | |
---|
230 | static UInt xGetSAD ( DistParam* pcDtParam ); |
---|
231 | static UInt xGetSAD4 ( DistParam* pcDtParam ); |
---|
232 | static UInt xGetSAD8 ( DistParam* pcDtParam ); |
---|
233 | static UInt xGetSAD16 ( DistParam* pcDtParam ); |
---|
234 | static UInt xGetSAD32 ( DistParam* pcDtParam ); |
---|
235 | static UInt xGetSAD64 ( DistParam* pcDtParam ); |
---|
236 | static UInt xGetSAD16N ( DistParam* pcDtParam ); |
---|
237 | |
---|
238 | static UInt xGetSADs ( DistParam* pcDtParam ); |
---|
239 | static UInt xGetSADs4 ( DistParam* pcDtParam ); |
---|
240 | static UInt xGetSADs8 ( DistParam* pcDtParam ); |
---|
241 | static UInt xGetSADs16 ( DistParam* pcDtParam ); |
---|
242 | static UInt xGetSADs32 ( DistParam* pcDtParam ); |
---|
243 | static UInt xGetSADs64 ( DistParam* pcDtParam ); |
---|
244 | static UInt xGetSADs16N ( DistParam* pcDtParam ); |
---|
245 | |
---|
246 | static UInt xGetHADs4 ( DistParam* pcDtParam ); |
---|
247 | static UInt xGetHADs8 ( DistParam* pcDtParam ); |
---|
248 | static UInt xGetHADs ( DistParam* pcDtParam ); |
---|
249 | static UInt xCalcHADs2x2 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep ); |
---|
250 | static UInt xCalcHADs4x4 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep ); |
---|
251 | static UInt xCalcHADs8x8 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep ); |
---|
252 | |
---|
253 | #ifdef ROUNDING_CONTROL_BIPRED |
---|
254 | |
---|
255 | static UInt xGetSSE ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
256 | static UInt xGetSSE4 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
257 | static UInt xGetSSE8 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
258 | static UInt xGetSSE16 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
259 | static UInt xGetSSE32 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
260 | static UInt xGetSSE64 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
261 | static UInt xGetSSE16N ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
262 | |
---|
263 | static UInt xGetSAD ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
264 | static UInt xGetSAD4 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
265 | static UInt xGetSAD8 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
266 | static UInt xGetSAD16 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
267 | static UInt xGetSAD32 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
268 | static UInt xGetSAD64 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
269 | static UInt xGetSAD16N ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
270 | |
---|
271 | static UInt xGetSADs ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
272 | static UInt xGetSADs4 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
273 | static UInt xGetSADs8 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
274 | static UInt xGetSADs16 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
275 | static UInt xGetSADs32 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
276 | static UInt xGetSADs64 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
277 | static UInt xGetSADs16N ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
278 | |
---|
279 | static UInt xGetHADs4 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
280 | static UInt xGetHADs8 ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
281 | static UInt xGetHADs ( DistParam* pcDtParam, Pel* pRefY, Bool bRound ); |
---|
282 | static UInt xCalcHADs2x2 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep, Pel* pRefY, Int refYStride, Bool bRound ); |
---|
283 | static UInt xCalcHADs4x4 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep, Pel* pRefY, Int refYStride, Bool bRound ); |
---|
284 | static UInt xCalcHADs8x8 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep, Pel* pRefY, Int refYStride, Bool bRound ); |
---|
285 | |
---|
286 | #endif |
---|
287 | |
---|
288 | public: |
---|
289 | #if SB_INTERVIEW_SKIP |
---|
290 | UInt getDistPart( Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, Pel* piUsed, Int iUsedStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE ); |
---|
291 | #endif |
---|
292 | UInt getDistPart( Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE ); |
---|
293 | |
---|
294 | //GT VSO |
---|
295 | |
---|
296 | private: |
---|
297 | Double m_dLambdaVSO; |
---|
298 | Double m_dSqrtLambdaVSO; |
---|
299 | UInt m_uiLambdaMotionSADVSO; |
---|
300 | UInt m_uiLambdaMotionSSEVSO; |
---|
301 | Double m_dFrameLambdaVSO; |
---|
302 | |
---|
303 | #if RDO_DIST_INT |
---|
304 | Bool m_bAllowNegDist; |
---|
305 | #endif |
---|
306 | |
---|
307 | TComPicYuv * m_pcVideoPicYuv; |
---|
308 | TComPicYuv** m_apRefPics; |
---|
309 | Int *** m_paaiShiftLUTs; |
---|
310 | UInt m_uiNumberRefPics; |
---|
311 | Bool m_bUseVSO; |
---|
312 | Bool m_bUseLambdaScaleVSO; |
---|
313 | UInt m_uiVSOMode; |
---|
314 | |
---|
315 | FpDistFuncVSO m_fpDistortFuncVSO; |
---|
316 | TRenModel* m_pcRenModel; |
---|
317 | public: |
---|
318 | |
---|
319 | Void setRenModel ( TRenModel* pcRenModel ) { m_pcRenModel = pcRenModel; } |
---|
320 | Void setRenModelData ( TComDataCU* pcCU, UInt uiAbsPartIndex, Pel* piData, Int iStride, Int iBlkWidth, Int iBlkHeight ); |
---|
321 | Void setLambdaVSO ( Double dLambda ); |
---|
322 | Void setFrameLambdaVSO ( Double dLambda ) { m_dFrameLambdaVSO = dLambda; }; |
---|
323 | |
---|
324 | Void setRefDataFromMVDInfo( TComMVDRefData* pRefInfo ); |
---|
325 | |
---|
326 | Void setUseVSO ( Bool bIn ) { m_bUseVSO = bIn; }; |
---|
327 | Bool getUseVSO ( ) { return m_bUseVSO;}; |
---|
328 | |
---|
329 | Bool getUseRenModel ( ) { return (m_bUseVSO && m_uiVSOMode == 4); }; |
---|
330 | Void setUseLambdaScaleVSO(bool bIn) { m_bUseLambdaScaleVSO = bIn; }; |
---|
331 | Bool getUseLambdaScaleVSO( ) { return m_bUseLambdaScaleVSO; }; |
---|
332 | |
---|
333 | Void setVSOMode( UInt uiIn); |
---|
334 | UInt getVSOMode( ) { return m_uiVSOMode; } |
---|
335 | |
---|
336 | #if RDO_DIST_INT |
---|
337 | Void setAllowNegDist ( Bool bAllowNegDist ); |
---|
338 | #endif |
---|
339 | |
---|
340 | |
---|
341 | Double getSqrtLambdaVSO () { return m_dSqrtLambdaVSO; } |
---|
342 | Double getLambdaVSO () { return m_dLambdaVSO; } |
---|
343 | |
---|
344 | Dist getDistVS( TComDataCU* pcCU, UInt uiAbsPartIndex, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD, UInt uiPlane ); |
---|
345 | Double calcRdCostVSO( UInt uiBits, Dist uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT ); |
---|
346 | |
---|
347 | private: |
---|
348 | |
---|
349 | Dist xGetDistVSOMode1( Int iStartPosX, Int iStartPosY, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD ); |
---|
350 | Dist xGetDistVSOMode2( Int iStartPosX, Int iStartPosY, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD ); |
---|
351 | Dist xGetDistVSOMode3( Int iStartPosX, Int iStartPosY, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD ); |
---|
352 | Dist xGetDistVSOMode4( Int iStartPosX, Int iStartPosY, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD ); |
---|
353 | |
---|
354 | #if GERHARD_VQM_XCHECK |
---|
355 | Dist xGetDistXCheck( Int iStartPosX, Int iStartPosY, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD ); |
---|
356 | #endif |
---|
357 | |
---|
358 | //GT VSO end |
---|
359 | |
---|
360 | };// END CLASS DEFINITION TComRdCost |
---|
361 | |
---|
362 | |
---|
363 | #endif // __TCOMRDCOST__ |
---|
364 | |
---|