source: 3DVCSoftware/branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibCommon/TComRdCost.h @ 630

Last change on this file since 630 was 622, checked in by tech, 11 years ago

Merged 8.0-dev0@621 (MV-HEVC 5 HLS).

  • Property svn:eol-style set to native
File size: 16.2 KB
Line 
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-2013, 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
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"
45
46#include "TComSlice.h"
47#include "TComRdCostWeightPrediction.h"
48#if H_3D
49#include "../TLibRenderer/TRenModel.h"
50#endif
51
52//! \ingroup TLibCommon
53//! \{
54
55#define FIX203 1
56
57class DistParam;
58class TComPattern;
59#if H_3D
60class TComRdCost; 
61#endif
62
63// ====================================================================================================================
64// Type definition
65// ====================================================================================================================
66
67// for function pointer
68typedef UInt (*FpDistFunc) (DistParam*);
69
70#if H_3D
71#if H_3D_VSO
72typedef Dist (TComRdCost::*FpDistFuncVSO) ( Int, Int, Pel*, Int, Pel*, Int, UInt, UInt, Bool );
73#endif
74#endif
75// ====================================================================================================================
76// Class definition
77// ====================================================================================================================
78
79/// distortion parameter class
80class DistParam
81{
82public:
83  Pel*  pOrg;
84  Pel*  pCur;
85  Int   iStrideOrg;
86  Int   iStrideCur;
87#if H_3D_VSO
88  // SAIT_VSO_EST_A0033
89  Pel*  pVirRec;
90  Pel*  pVirOrg;
91  Int   iStrideVir;
92#endif
93#if H_3D_IC
94  Bool  bUseIC;
95#endif
96#if LGE_INTER_SDC_E0156
97  Bool  bUseSDCMRSAD;
98#endif
99  Int   iRows;
100  Int   iCols;
101  Int   iStep;
102  FpDistFunc DistFunc;
103  Int   bitDepth;
104
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)
108
109#if NS_HAD
110  Bool            bUseNSHAD;
111#endif
112
113  // (vertical) subsampling shift (for reducing complexity)
114  // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc.
115  Int   iSubShift;
116 
117  DistParam()
118  {
119    pOrg = NULL;
120    pCur = NULL;
121    iStrideOrg = 0;
122    iStrideCur = 0;
123    iRows = 0;
124    iCols = 0;
125    iStep = 1;
126    DistFunc = NULL;
127    iSubShift = 0;
128    bitDepth = 0;
129#if NS_HAD
130    bUseNSHAD = false;
131#endif
132#if H_3D_VSO
133    // SAIT_VSO_EST_A0033
134    pVirRec = NULL;
135    pVirOrg = NULL;
136    iStrideVir = 0;
137#endif
138#if LGE_INTER_SDC_E0156
139    bUseSDCMRSAD = false;
140#endif
141  }
142};
143
144/// RD cost computation class
145class TComRdCost
146  : public TComRdCostWeightPrediction
147{
148private:
149  // for distortion
150  Int                     m_iBlkWidth;
151  Int                     m_iBlkHeight;
152 
153#if AMP_SAD
154  FpDistFunc              m_afpDistortFunc[64]; // [eDFunc]
155#else 
156  FpDistFunc              m_afpDistortFunc[33]; // [eDFunc]
157#endif 
158 
159#if WEIGHTED_CHROMA_DISTORTION
160  Double                  m_cbDistortionWeight; 
161  Double                  m_crDistortionWeight; 
162#endif
163  Double                  m_dLambda;
164  Double                  m_sqrtLambda;
165  UInt                    m_uiLambdaMotionSAD;
166  UInt                    m_uiLambdaMotionSSE;
167  Double                  m_dFrameLambda;
168#if H_3D_VSO
169  // SAIT_VSO_EST_A0033
170  static Double           m_dDisparityCoeff;
171#endif
172 
173  // for motion cost
174#if FIX203
175  TComMv                  m_mvPredictor;
176#else
177  UInt*                   m_puiComponentCostOriginP;
178  UInt*                   m_puiComponentCost;
179  UInt*                   m_puiVerCost;
180  UInt*                   m_puiHorCost;
181#endif
182  UInt                    m_uiCost;
183  Int                     m_iCostScale;
184#if !FIX203
185  Int                     m_iSearchLimit;
186#endif
187 
188public:
189  TComRdCost();
190  virtual ~TComRdCost();
191
192#if H_3D_VSO
193  Double  calcRdCost  ( UInt   uiBits, Dist   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
194  Double  calcRdCost64( UInt64 uiBits, Dist64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
195#else
196  Double  calcRdCost  ( UInt   uiBits, UInt   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
197  Double  calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
198#endif
199
200 
201#if WEIGHTED_CHROMA_DISTORTION
202  Void    setCbDistortionWeight      ( Double cbDistortionWeight) { m_cbDistortionWeight = cbDistortionWeight; };
203  Void    setCrDistortionWeight      ( Double crDistortionWeight) { m_crDistortionWeight = crDistortionWeight; };
204#endif
205  Void    setLambda      ( Double dLambda );
206  Void    setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
207 
208  Double  getSqrtLambda ()   { return m_sqrtLambda; }
209#if H_3D_VSO
210  // SAIT_VSO_EST_A0033
211  Void    setDisparityCoeff( Double dDisparityCoeff ) { m_dDisparityCoeff = dDisparityCoeff; }
212  Double  getDisparityCoeff()                         { return m_dDisparityCoeff; }
213#endif
214
215#if RATE_CONTROL_LAMBDA_DOMAIN
216  Double  getLambda() { return m_dLambda; }
217#if M0036_RC_IMPROVEMENT
218  Double  getChromaWeight () {return((m_cbDistortionWeight+m_crDistortionWeight)/2.0);}
219#endif
220#endif
221 
222  // Distortion Functions
223  Void    init();
224 
225  Void    setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
226  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride,            DistParam& rcDistParam );
227#if NS_HAD
228  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false, Bool bUseNSHAD=false );
229  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false, Bool bUseNSHAD=false );
230#else
231  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
232  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
233#endif
234 
235  UInt    calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
236 
237#if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
238  UInt    calcVAR(Pel* pi0, Int stride, Int width, Int height, Int cuDepth);
239#endif 
240  // for motion cost
241#if !FIX203
242  Void    initRateDistortionModel( Int iSubPelSearchLimit );
243  Void    xUninit();
244#endif
245  UInt    xGetComponentBits( Int iVal );
246  Void    getMotionCost( Bool bSad, Int iAdd ) { m_uiCost = (bSad ? m_uiLambdaMotionSAD + iAdd : m_uiLambdaMotionSSE + iAdd); }
247  Void    setPredictor( TComMv& rcMv )
248  {
249#if FIX203
250    m_mvPredictor = rcMv;
251#else
252    m_puiHorCost = m_puiComponentCost - rcMv.getHor();
253    m_puiVerCost = m_puiComponentCost - rcMv.getVer();
254#endif
255  }
256  Void    setCostScale( Int iCostScale )    { m_iCostScale = iCostScale; }
257  __inline UInt getCost( Int x, Int y )
258  {
259#if FIX203
260    return m_uiCost * getBits(x, y) >> 16;
261#else
262    return (( m_uiCost * (m_puiHorCost[ x * (1<<m_iCostScale) ] + m_puiVerCost[ y * (1<<m_iCostScale) ]) ) >> 16);
263#endif
264  }
265  UInt    getCost( UInt b )                 { return ( m_uiCost * b ) >> 16; }
266  UInt    getBits( Int x, Int y )         
267  {
268#if FIX203
269    return xGetComponentBits((x << m_iCostScale) - m_mvPredictor.getHor())
270    +      xGetComponentBits((y << m_iCostScale) - m_mvPredictor.getVer());
271#else
272    return m_puiHorCost[ x * (1<<m_iCostScale)] + m_puiVerCost[ y * (1<<m_iCostScale) ];
273#endif
274  }
275 
276private:
277 
278  static UInt xGetSSE           ( DistParam* pcDtParam );
279  static UInt xGetSSE4          ( DistParam* pcDtParam );
280  static UInt xGetSSE8          ( DistParam* pcDtParam );
281  static UInt xGetSSE16         ( DistParam* pcDtParam );
282  static UInt xGetSSE32         ( DistParam* pcDtParam );
283  static UInt xGetSSE64         ( DistParam* pcDtParam );
284  static UInt xGetSSE16N        ( DistParam* pcDtParam );
285#if H_3D_IC || LGE_INTER_SDC_E0156
286  static UInt xGetSADic         ( DistParam* pcDtParam );
287  static UInt xGetSAD4ic        ( DistParam* pcDtParam );
288  static UInt xGetSAD8ic        ( DistParam* pcDtParam );
289  static UInt xGetSAD16ic       ( DistParam* pcDtParam );
290  static UInt xGetSAD32ic       ( DistParam* pcDtParam );
291  static UInt xGetSAD64ic       ( DistParam* pcDtParam );
292  static UInt xGetSAD16Nic      ( DistParam* pcDtParam );
293#endif
294  static UInt xGetSAD           ( DistParam* pcDtParam );
295  static UInt xGetSAD4          ( DistParam* pcDtParam );
296  static UInt xGetSAD8          ( DistParam* pcDtParam );
297  static UInt xGetSAD16         ( DistParam* pcDtParam );
298  static UInt xGetSAD32         ( DistParam* pcDtParam );
299  static UInt xGetSAD64         ( DistParam* pcDtParam );
300  static UInt xGetSAD16N        ( DistParam* pcDtParam );
301 
302#if H_3D_VSO
303  static UInt xGetVSD           ( DistParam* pcDtParam );
304  static UInt xGetVSD4          ( DistParam* pcDtParam );
305  static UInt xGetVSD8          ( DistParam* pcDtParam );
306  static UInt xGetVSD16         ( DistParam* pcDtParam );
307  static UInt xGetVSD32         ( DistParam* pcDtParam );
308  static UInt xGetVSD64         ( DistParam* pcDtParam );
309  static UInt xGetVSD16N        ( DistParam* pcDtParam );
310#endif
311
312#if AMP_SAD
313#if H_3D_IC || LGE_INTER_SDC_E0156
314  static UInt xGetSAD12ic       ( DistParam* pcDtParam );
315  static UInt xGetSAD24ic       ( DistParam* pcDtParam );
316  static UInt xGetSAD48ic       ( DistParam* pcDtParam );
317#endif
318  static UInt xGetSAD12         ( DistParam* pcDtParam );
319  static UInt xGetSAD24         ( DistParam* pcDtParam );
320  static UInt xGetSAD48         ( DistParam* pcDtParam );
321
322#endif
323
324#if H_3D_IC || LGE_INTER_SDC_E0156
325  static UInt xGetHADsic          ( DistParam* pcDtParam );
326#endif
327  static UInt xGetHADs4         ( DistParam* pcDtParam );
328  static UInt xGetHADs8         ( DistParam* pcDtParam );
329  static UInt xGetHADs          ( DistParam* pcDtParam );
330  static UInt xCalcHADs2x2      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
331  static UInt xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
332  static UInt xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
333#if NS_HAD
334  static UInt xCalcHADs16x4     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
335  static UInt xCalcHADs4x16     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
336#endif
337 
338public:
339#if WEIGHTED_CHROMA_DISTORTION
340  UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText = TEXT_LUMA, DFunc eDFunc = DF_SSE );
341#else
342  UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE );
343#endif
344
345#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
346  UInt   getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height );
347#endif
348
349#if H_3D_VSO
350  // SAIT_VSO_EST_A0033
351  UInt        getDistPartVSD( TComDataCU* pcCu, UInt uiPartOffset, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bHad, DFunc eDFunc = DF_VSD); 
352  static UInt getVSDEstimate( Int dDM, Pel* pOrg, Int iOrgStride,  Pel* pVirRec, Pel* pVirOrg, Int iVirStride, Int x, Int y );
353
354private:
355  Double                  m_dLambdaVSO;
356  Double                  m_dSqrtLambdaVSO;
357  UInt                    m_uiLambdaMotionSADVSO;
358  UInt                    m_uiLambdaMotionSSEVSO;
359  Double                  m_dFrameLambdaVSO;
360  Bool                    m_bAllowNegDist;
361  Bool                    m_bUseVSO;
362  Bool                    m_bUseLambdaScaleVSO;
363  UInt                    m_uiVSOMode;
364
365  FpDistFuncVSO           m_fpDistortFuncVSO;
366  TRenModel*              m_pcRenModel;
367
368
369  // SAIT_VSO_EST_A0033
370  TComPicYuv *            m_pcVideoRecPicYuv;
371  TComPicYuv *            m_pcDepthPicYuv;
372  Bool                    m_bUseEstimatedVSD; 
373
374  // LGE_WVSO_A0119
375  Int                     m_iDWeight;
376  Int                     m_iVSOWeight;
377  Int                     m_iVSDWeight;
378  Bool                    m_bUseWVSO;
379
380public:
381
382  Void    setRenModel       ( TRenModel* pcRenModel ) { m_pcRenModel = pcRenModel; }
383  TRenModel* getRenModel    ( )                       { return m_pcRenModel; }
384  Void    setRenModelData   ( TComDataCU* pcCU, UInt uiAbsPartIndex, Pel* piData, Int iStride, Int iBlkWidth, Int iBlkHeight );
385  Void    setLambdaVSO      ( Double dLambda );
386  Void    setFrameLambdaVSO ( Double dLambda ) { m_dFrameLambdaVSO = dLambda; };
387
388
389  Void    setUseVSO ( Bool bIn )         { m_bUseVSO = bIn; };
390  Bool    getUseVSO ( )                  { return m_bUseVSO;};
391
392  Bool    getUseRenModel ( )             { return (m_bUseVSO && m_uiVSOMode == 4); };
393  Void    setUseLambdaScaleVSO(Bool bIn) { m_bUseLambdaScaleVSO = bIn; };
394  Bool    getUseLambdaScaleVSO( )        { return m_bUseLambdaScaleVSO; };
395
396  Void    setVSOMode( UInt uiIn);
397  UInt    getVSOMode( )                  { return m_uiVSOMode; }
398  Void    setAllowNegDist ( Bool bAllowNegDist );
399
400  Double  getSqrtLambdaVSO ()   { return m_dSqrtLambdaVSO; }
401  Double  getLambdaVSO ()       { return m_dLambdaVSO; }
402
403  Dist   getDistPartVSO( TComDataCU* pcCU, UInt uiAbsPartIndex, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD );
404  Double calcRdCostVSO ( UInt   uiBits, Dist   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
405
406  // SAIT_VSO_EST_A0033
407  Bool    getUseEstimatedVSD( )           { return m_bUseEstimatedVSD; };
408  Void    setUseEstimatedVSD( Bool bIn )  { m_bUseEstimatedVSD = bIn; };
409
410  TComPicYuv* getVideoRecPicYuv ()                               { return m_pcVideoRecPicYuv; };
411  Void        setVideoRecPicYuv ( TComPicYuv* pcVideoRecPicYuv ) { m_pcVideoRecPicYuv = pcVideoRecPicYuv; };
412  TComPicYuv* getDepthPicYuv    ()                               { return m_pcDepthPicYuv; };
413  Void        setDepthPicYuv    ( TComPicYuv* pcDepthPicYuv )    { m_pcDepthPicYuv = pcDepthPicYuv; };
414
415  // LGE_WVSO_A0119
416  Void    setUseWVSO ( Bool bIn )         { m_bUseWVSO = bIn; }; 
417  Bool    getUseWVSO ( )                  { return m_bUseWVSO;};
418  Void    setDWeight   ( Int iDWeight   ) { m_iDWeight = iDWeight; };
419  Int     getDWeight   ()                 { return m_iDWeight; };
420  Void    setVSOWeight ( Int iVSOWeight ) { m_iVSOWeight = iVSOWeight; };
421  Int     getVSOWeight ()                 { return m_iVSOWeight; };
422  Void    setVSDWeight ( Int iVSDWeight ) { m_iVSDWeight = iVSDWeight; };
423  Int     getVSDWeight ()                 { return m_iVSDWeight; };
424
425private:
426  Dist xGetDistVSOMode4( Int iStartPosX, Int iStartPosY, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD );
427
428#endif // H_3D_VSO
429
430};// END CLASS DEFINITION TComRdCost
431
432//! \}
433
434#endif // __TCOMRDCOST__
Note: See TracBrowser for help on using the repository browser.