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

Last change on this file since 1313 was 1313, checked in by tech, 9 years ago

Merged 14.1-update-dev1@1312.

  • Property svn:eol-style set to native
File size: 16.2 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 *
[1313]6 * Copyright (c) 2010-2015, 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"
[1313]48#if NH_3D
[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;
[1313]59#if NH_3D
[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
[1313]70#if NH_3D
71#if NH_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;
[1313]87#if NH_3D_VSO
[608]88  // SAIT_VSO_EST_A0033
[100]89  Pel*  pVirRec;
90  Pel*  pVirOrg;
91  Int   iStrideVir;
92#endif
[1313]93#if NH_3D_IC
[608]94  Bool  bUseIC;
95#endif
[1313]96#if NH_3D_SDC_INTER
[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
[1313]105  Bool            bApplyWeight;     // whether weighted prediction is used or not
106  WPScalingParam  *wpCur;           // weighted prediction scaling parameters for current ref
107  ComponentID     compIdx;
[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()
114  {
115    pOrg = NULL;
116    pCur = NULL;
117    iStrideOrg = 0;
118    iStrideCur = 0;
119    iRows = 0;
120    iCols = 0;
121    iStep = 1;
122    DistFunc = NULL;
123    iSubShift = 0;
[608]124    bitDepth = 0;
[1313]125#if NH_3D_VSO
[608]126    // SAIT_VSO_EST_A0033
127    pVirRec = NULL;
128    pVirOrg = NULL;
129    iStrideVir = 0;
130#endif
[1313]131#if NH_3D_SDC_INTER
[608]132    bUseSDCMRSAD = false;
133#endif
[2]134  }
135};
136
137/// RD cost computation class
138class TComRdCost
139{
140private:
141  // for distortion
[1313]142
143  FpDistFunc              m_afpDistortFunc[DF_TOTAL_FUNCTIONS]; // [eDFunc]
144  CostMode                m_costMode;
145  Double                  m_distortionWeight[MAX_NUM_COMPONENT]; // only chroma values are used.
[2]146  Double                  m_dLambda;
147  Double                  m_sqrtLambda;
[1313]148#if RExt__HIGH_BIT_DEPTH_SUPPORT
149  Double                  m_dLambdaMotionSAD[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
150  Double                  m_dLambdaMotionSSE[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
151#else
152  UInt                    m_uiLambdaMotionSAD[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
153  UInt                    m_uiLambdaMotionSSE[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
154#endif
[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;
[1313]163#if RExt__HIGH_BIT_DEPTH_SUPPORT
164  Double                  m_dCost;
[56]165#else
[1313]166  UInt                    m_uiCost;
[56]167#endif
[2]168  Int                     m_iCostScale;
[1313]169#if NH_3D_DBBP
[833]170  Bool                    m_bUseMask;
171#endif
[1313]172
[2]173public:
174  TComRdCost();
175  virtual ~TComRdCost();
[1313]176#if NH_3D_VSO
[608]177  Double  calcRdCost  ( UInt   uiBits, Dist   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
178  Double  calcRdCost64( UInt64 uiBits, Dist64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
179#else
[1313]180  Double  calcRdCost  ( UInt   uiBits, Distortion uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
[2]181  Double  calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
[608]182#endif
183
[1313]184  Void    setDistortionWeight  ( const ComponentID compID, const Double distortionWeight ) { m_distortionWeight[compID] = distortionWeight; }
185  Void    setLambda      ( Double dLambda, const BitDepths &bitDepths );
[2]186  Void    setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
[1313]187
[608]188  Double  getSqrtLambda ()   { return m_sqrtLambda; }
[1313]189#if NH_3D_VSO
[608]190  // SAIT_VSO_EST_A0033
[100]191  Void    setDisparityCoeff( Double dDisparityCoeff ) { m_dDisparityCoeff = dDisparityCoeff; }
192  Double  getDisparityCoeff()                         { return m_dDisparityCoeff; }
193#endif
194
[608]195  Double  getLambda() { return m_dLambda; }
[1313]196  Double  getChromaWeight () { return ((m_distortionWeight[COMPONENT_Cb] + m_distortionWeight[COMPONENT_Cr]) / 2.0); }
197
198  Void    setCostMode(CostMode   m )    { m_costMode = m; }
199
[2]200  // Distortion Functions
201  Void    init();
[1313]202
[2]203  Void    setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
204  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride,            DistParam& rcDistParam );
205  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
[608]206  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
[1313]207
208#if NH_3D_DBBP
[833]209  Void    setUseMask(Bool b) { m_bUseMask = b; }
210#endif
[1313]211
212  Distortion calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
213
214#if NH_3D_ENC_DEPTH
215  UInt    calcVAR(Pel* pi0, Int stride, Int width, Int height, Int cuDepth, UInt maxCuWidth );
[608]216#endif 
[1313]217
[2]218  // for motion cost
[1313]219  static UInt    xGetExpGolombNumberOfBits( Int iVal );
220#if RExt__HIGH_BIT_DEPTH_SUPPORT
221  Void    getMotionCost( Bool bSad, Int iAdd, Bool bIsTransquantBypass ) { m_dCost = (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); }
222#else
223  Void    getMotionCost( Bool bSad, Int iAdd, Bool bIsTransquantBypass ) { m_uiCost = (bSad ? m_uiLambdaMotionSAD[(bIsTransquantBypass && m_costMode==COST_MIXED_LOSSLESS_LOSSY_CODING) ?1:0] + iAdd : m_uiLambdaMotionSSE[(bIsTransquantBypass && m_costMode==COST_MIXED_LOSSLESS_LOSSY_CODING)?1:0] + iAdd); }
[56]224#endif
[2]225  Void    setPredictor( TComMv& rcMv )
226  {
[56]227    m_mvPredictor = rcMv;
[2]228  }
229  Void    setCostScale( Int iCostScale )    { m_iCostScale = iCostScale; }
[1313]230  __inline Distortion getCost( Int x, Int y )
[2]231  {
[1313]232#if RExt__HIGH_BIT_DEPTH_SUPPORT
233    return Distortion((m_dCost * getBits(x, y)) / 65536.0);
234#else
[56]235    return m_uiCost * getBits(x, y) >> 16;
236#endif
[2]237  }
[1313]238#if RExt__HIGH_BIT_DEPTH_SUPPORT
239  Distortion getCost( UInt b )                 { return Distortion(( m_dCost * b ) / 65536.0); }
[56]240#else
[1313]241  Distortion getCost( UInt b )                 { return ( m_uiCost * b ) >> 16; }
[56]242#endif
[1313]243  UInt    getBits( Int x, Int y )
244  {
245    return xGetExpGolombNumberOfBits((x << m_iCostScale) - m_mvPredictor.getHor())
246    +      xGetExpGolombNumberOfBits((y << m_iCostScale) - m_mvPredictor.getVer());
[56]247  }
[1313]248
[2]249private:
[1313]250
251  static Distortion xGetSSE           ( DistParam* pcDtParam );
252  static Distortion xGetSSE4          ( DistParam* pcDtParam );
253  static Distortion xGetSSE8          ( DistParam* pcDtParam );
254  static Distortion xGetSSE16         ( DistParam* pcDtParam );
255  static Distortion xGetSSE32         ( DistParam* pcDtParam );
256  static Distortion xGetSSE64         ( DistParam* pcDtParam );
257  static Distortion xGetSSE16N        ( DistParam* pcDtParam );
258#if NH_3D_IC || NH_3D_SDC_INTER
[189]259  static UInt xGetSADic         ( DistParam* pcDtParam );
260  static UInt xGetSAD4ic        ( DistParam* pcDtParam );
261  static UInt xGetSAD8ic        ( DistParam* pcDtParam );
262  static UInt xGetSAD16ic       ( DistParam* pcDtParam );
263  static UInt xGetSAD32ic       ( DistParam* pcDtParam );
264  static UInt xGetSAD64ic       ( DistParam* pcDtParam );
265  static UInt xGetSAD16Nic      ( DistParam* pcDtParam );
266#endif
[1313]267
268  static Distortion xGetSAD           ( DistParam* pcDtParam );
269  static Distortion xGetSAD4          ( DistParam* pcDtParam );
270  static Distortion xGetSAD8          ( DistParam* pcDtParam );
271  static Distortion xGetSAD16         ( DistParam* pcDtParam );
272  static Distortion xGetSAD32         ( DistParam* pcDtParam );
273  static Distortion xGetSAD64         ( DistParam* pcDtParam );
274  static Distortion xGetSAD16N        ( DistParam* pcDtParam );
275#if NH_3D_VSO
[100]276  static UInt xGetVSD           ( DistParam* pcDtParam );
277  static UInt xGetVSD4          ( DistParam* pcDtParam );
278  static UInt xGetVSD8          ( DistParam* pcDtParam );
279  static UInt xGetVSD16         ( DistParam* pcDtParam );
280  static UInt xGetVSD32         ( DistParam* pcDtParam );
281  static UInt xGetVSD64         ( DistParam* pcDtParam );
282  static UInt xGetVSD16N        ( DistParam* pcDtParam );
283#endif
284
[1313]285#if NH_3D_IC || NH_3D_SDC_INTER
[189]286  static UInt xGetSAD12ic       ( DistParam* pcDtParam );
287  static UInt xGetSAD24ic       ( DistParam* pcDtParam );
288  static UInt xGetSAD48ic       ( DistParam* pcDtParam );
289#endif
[608]290
[1313]291  static Distortion xGetSAD12         ( DistParam* pcDtParam );
292  static Distortion xGetSAD24         ( DistParam* pcDtParam );
293  static Distortion xGetSAD48         ( DistParam* pcDtParam );
[2]294
[1313]295
296#if NH_3D_IC || NH_3D_SDC_INTER
[189]297  static UInt xGetHADsic          ( DistParam* pcDtParam );
[56]298#endif
[1313]299
300  static Distortion xGetHADs          ( DistParam* pcDtParam );
301  static Distortion xCalcHADs2x2      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
302  static Distortion xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
303  static Distortion xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
304#if NH_3D_DBBP
[833]305  static UInt xGetMaskedSSE     ( DistParam* pcDtParam );
306  static UInt xGetMaskedSAD     ( DistParam* pcDtParam );
307  static UInt xGetMaskedVSD     ( DistParam* pcDtParam );
308#endif
[1313]309
310
[2]311public:
[608]312
[1313]313  Distortion   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, const ComponentID compID, DFunc eDFunc = DF_SSE );
314
[872]315#if KWU_RC_MADPRED_E0227
[608]316  UInt   getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height );
[100]317#endif
318
[1313]319#if NH_3D_VSO
[608]320  // SAIT_VSO_EST_A0033
[1313]321  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); 
[608]322  static UInt getVSDEstimate( Int dDM, Pel* pOrg, Int iOrgStride,  Pel* pVirRec, Pel* pVirOrg, Int iVirStride, Int x, Int y );
323
[2]324private:
325  Double                  m_dLambdaVSO;
326  Double                  m_dSqrtLambdaVSO;
327  UInt                    m_uiLambdaMotionSADVSO;
328  UInt                    m_uiLambdaMotionSSEVSO;
329  Double                  m_dFrameLambdaVSO;
[608]330  Bool                    m_bAllowNegDist;
331  Bool                    m_bUseVSO;
332  Bool                    m_bUseLambdaScaleVSO;
333  UInt                    m_uiVSOMode;
[2]334
[608]335  FpDistFuncVSO           m_fpDistortFuncVSO;
336  TRenModel*              m_pcRenModel;
337
338
339  // SAIT_VSO_EST_A0033
[100]340  TComPicYuv *            m_pcVideoRecPicYuv;
341  TComPicYuv *            m_pcDepthPicYuv;
342  Bool                    m_bUseEstimatedVSD; 
[608]343
344  // LGE_WVSO_A0119
[116]345  Int                     m_iDWeight;
346  Int                     m_iVSOWeight;
[115]347  Int                     m_iVSDWeight;
[120]348  Bool                    m_bUseWVSO;
[2]349
350public:
351
352  Void    setRenModel       ( TRenModel* pcRenModel ) { m_pcRenModel = pcRenModel; }
[608]353  TRenModel* getRenModel    ( )                       { return m_pcRenModel; }
[1313]354  Void    setRenModelData   ( const TComDataCU* pcCU, UInt uiAbsPartIndex, const TComYuv* pcYuv, const TComTURecurse* tuRecurseWithPU );
355  Void    setRenModelData   ( const TComDataCU* pcCU, UInt uiAbsPartIndex, const Pel* piData, Int iStride, Int iBlkWidth, Int iBlkHeight );
356
[2]357  Void    setLambdaVSO      ( Double dLambda );
358  Void    setFrameLambdaVSO ( Double dLambda ) { m_dFrameLambdaVSO = dLambda; };
359
360
361  Void    setUseVSO ( Bool bIn )         { m_bUseVSO = bIn; };
362  Bool    getUseVSO ( )                  { return m_bUseVSO;};
[608]363
364  Bool    getUseRenModel ( )             { return (m_bUseVSO && m_uiVSOMode == 4); };
365  Void    setUseLambdaScaleVSO(Bool bIn) { m_bUseLambdaScaleVSO = bIn; };
366  Bool    getUseLambdaScaleVSO( )        { return m_bUseLambdaScaleVSO; };
367
368  Void    setVSOMode( UInt uiIn);
369  UInt    getVSOMode( )                  { return m_uiVSOMode; }
370  Void    setAllowNegDist ( Bool bAllowNegDist );
371
372  Double  getSqrtLambdaVSO ()   { return m_dSqrtLambdaVSO; }
373  Double  getLambdaVSO ()       { return m_dLambdaVSO; }
374
[1313]375  Dist    getDistPartVSO( TComDataCU* pcCU, UInt uiAbsPartIndex, Int bitdDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD );
376  Double  calcRdCostVSO ( UInt   uiBits, Dist   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
[608]377
378  // SAIT_VSO_EST_A0033
[100]379  Bool    getUseEstimatedVSD( )           { return m_bUseEstimatedVSD; };
380  Void    setUseEstimatedVSD( Bool bIn )  { m_bUseEstimatedVSD = bIn; };
[2]381
[100]382  TComPicYuv* getVideoRecPicYuv ()                               { return m_pcVideoRecPicYuv; };
383  Void        setVideoRecPicYuv ( TComPicYuv* pcVideoRecPicYuv ) { m_pcVideoRecPicYuv = pcVideoRecPicYuv; };
384  TComPicYuv* getDepthPicYuv    ()                               { return m_pcDepthPicYuv; };
385  Void        setDepthPicYuv    ( TComPicYuv* pcDepthPicYuv )    { m_pcDepthPicYuv = pcDepthPicYuv; };
386
[608]387  // LGE_WVSO_A0119
[120]388  Void    setUseWVSO ( Bool bIn )         { m_bUseWVSO = bIn; }; 
389  Bool    getUseWVSO ( )                  { return m_bUseWVSO;};
[116]390  Void    setDWeight   ( Int iDWeight   ) { m_iDWeight = iDWeight; };
391  Int     getDWeight   ()                 { return m_iDWeight; };
392  Void    setVSOWeight ( Int iVSOWeight ) { m_iVSOWeight = iVSOWeight; };
393  Int     getVSOWeight ()                 { return m_iVSOWeight; };
394  Void    setVSDWeight ( Int iVSDWeight ) { m_iVSDWeight = iVSDWeight; };
395  Int     getVSDWeight ()                 { return m_iVSDWeight; };
[2]396
397private:
398  Dist xGetDistVSOMode4( Int iStartPosX, Int iStartPosY, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD );
399
[1313]400#endif // NH_3D_VSO
[2]401
[1313]402
[2]403};// END CLASS DEFINITION TComRdCost
404
[56]405//! \}
[2]406
407#endif // __TCOMRDCOST__
Note: See TracBrowser for help on using the repository browser.