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

Last change on this file since 724 was 655, checked in by tech, 11 years ago

Merged 8.1-Cleanup@654

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