source: SHVCSoftware/branches/SHM-upgrade/source/Lib/TLibCommon/TComRdCost.h @ 918

Last change on this file since 918 was 916, checked in by seregin, 10 years ago

initial porting

  • Property svn:eol-style set to native
File size: 9.3 KB
RevLine 
[313]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
[916]4 * granted under this license.
[313]5 *
[595]6 * Copyright (c) 2010-2014, ITU/ISO/IEC
[313]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
49//! \ingroup TLibCommon
50//! \{
51
52class DistParam;
53class TComPattern;
54
55// ====================================================================================================================
56// Type definition
57// ====================================================================================================================
58
59// for function pointer
[916]60typedef Distortion (*FpDistFunc) (DistParam*); // TODO: can this pointer be replaced with a reference? - there are no NULL checks on pointer.
[313]61
62// ====================================================================================================================
63// Class definition
64// ====================================================================================================================
65
66/// distortion parameter class
67class DistParam
68{
69public:
70  Pel*  pOrg;
71  Pel*  pCur;
72  Int   iStrideOrg;
73  Int   iStrideCur;
74  Int   iRows;
75  Int   iCols;
76  Int   iStep;
77  FpDistFunc DistFunc;
78  Int   bitDepth;
79
[916]80  Bool            bApplyWeight;     // whether weighted prediction is used or not
81  WPScalingParam  *wpCur;           // weighted prediction scaling parameters for current ref
82  ComponentID     compIdx;
[313]83
84  // (vertical) subsampling shift (for reducing complexity)
85  // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc.
86  Int   iSubShift;
[916]87
[313]88  DistParam()
89  {
90    pOrg = NULL;
91    pCur = NULL;
92    iStrideOrg = 0;
93    iStrideCur = 0;
94    iRows = 0;
95    iCols = 0;
96    iStep = 1;
97    DistFunc = NULL;
98    iSubShift = 0;
99    bitDepth = 0;
100  }
101};
102
103/// RD cost computation class
104class TComRdCost
105{
106private:
107  // for distortion
[916]108
109  FpDistFunc              m_afpDistortFunc[DF_TOTAL_FUNCTIONS]; // [eDFunc]
110  CostMode                m_costMode;
111  Double                  m_distortionWeight[MAX_NUM_COMPONENT]; // only chroma values are used.
[313]112  Double                  m_dLambda;
113  Double                  m_sqrtLambda;
[916]114#if RExt__HIGH_BIT_DEPTH_SUPPORT
115  Double                  m_dLambdaMotionSAD[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
116  Double                  m_dLambdaMotionSSE[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
117#else
118  UInt                    m_uiLambdaMotionSAD[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
119  UInt                    m_uiLambdaMotionSSE[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/];
120#endif
[313]121  Double                  m_dFrameLambda;
[916]122
[313]123  // for motion cost
124  TComMv                  m_mvPredictor;
[916]125#if RExt__HIGH_BIT_DEPTH_SUPPORT
126  Double                  m_dCost;
[313]127#else
[916]128  UInt                    m_uiCost;
[313]129#endif
130  Int                     m_iCostScale;
[916]131
[313]132public:
133  TComRdCost();
134  virtual ~TComRdCost();
[916]135
136  Double  calcRdCost  ( UInt   uiBits, Distortion uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
[313]137  Double  calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
[916]138
139  Void    setDistortionWeight  ( const ComponentID compID, const Double distortionWeight ) { m_distortionWeight[compID] = distortionWeight; }
[313]140  Void    setLambda      ( Double dLambda );
141  Void    setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
[916]142
[313]143  Double  getSqrtLambda ()   { return m_sqrtLambda; }
144
145  Double  getLambda() { return m_dLambda; }
[916]146  Double  getChromaWeight () { return ((m_distortionWeight[COMPONENT_Cb] + m_distortionWeight[COMPONENT_Cr]) / 2.0); }
147
148  Void    setCostMode(CostMode   m )    { m_costMode = m; }
149
[313]150  // Distortion Functions
151  Void    init();
[916]152
[313]153  Void    setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
154  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride,            DistParam& rcDistParam );
155  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
156  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
[916]157
158  Distortion calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
159
[313]160  // for motion cost
[916]161  UInt    xGetComponentBits( Int iVal );
162#if RExt__HIGH_BIT_DEPTH_SUPPORT
163  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); }
164#else
165  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); }
[313]166#endif
167  Void    setPredictor( TComMv& rcMv )
168  {
169    m_mvPredictor = rcMv;
170  }
171  Void    setCostScale( Int iCostScale )    { m_iCostScale = iCostScale; }
[916]172  __inline Distortion getCost( Int x, Int y )
[313]173  {
[916]174#if RExt__HIGH_BIT_DEPTH_SUPPORT
175    return Distortion((m_dCost * getBits(x, y)) / 65536.0);
176#else
[313]177    return m_uiCost * getBits(x, y) >> 16;
[916]178#endif
179  }
180#if RExt__HIGH_BIT_DEPTH_SUPPORT
181  Distortion getCost( UInt b )                 { return Distortion(( m_dCost * b ) / 65536.0); }
[313]182#else
[916]183  Distortion getCost( UInt b )                 { return ( m_uiCost * b ) >> 16; }
[313]184#endif
[916]185  UInt    getBits( Int x, Int y )
[313]186  {
187    return xGetComponentBits((x << m_iCostScale) - m_mvPredictor.getHor())
188    +      xGetComponentBits((y << m_iCostScale) - m_mvPredictor.getVer());
189  }
[916]190
[313]191private:
[916]192
193  static Distortion xGetSSE           ( DistParam* pcDtParam );
194  static Distortion xGetSSE4          ( DistParam* pcDtParam );
195  static Distortion xGetSSE8          ( DistParam* pcDtParam );
196  static Distortion xGetSSE16         ( DistParam* pcDtParam );
197  static Distortion xGetSSE32         ( DistParam* pcDtParam );
198  static Distortion xGetSSE64         ( DistParam* pcDtParam );
199  static Distortion xGetSSE16N        ( DistParam* pcDtParam );
200
201  static Distortion xGetSAD           ( DistParam* pcDtParam );
202  static Distortion xGetSAD4          ( DistParam* pcDtParam );
203  static Distortion xGetSAD8          ( DistParam* pcDtParam );
204  static Distortion xGetSAD16         ( DistParam* pcDtParam );
205  static Distortion xGetSAD32         ( DistParam* pcDtParam );
206  static Distortion xGetSAD64         ( DistParam* pcDtParam );
207  static Distortion xGetSAD16N        ( DistParam* pcDtParam );
208
[313]209#if AMP_SAD
[916]210  static Distortion xGetSAD12         ( DistParam* pcDtParam );
211  static Distortion xGetSAD24         ( DistParam* pcDtParam );
212  static Distortion xGetSAD48         ( DistParam* pcDtParam );
[313]213
214#endif
215
[916]216  static Distortion xGetHADs          ( DistParam* pcDtParam );
217  static Distortion xCalcHADs2x2      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
218  static Distortion xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
219  static Distortion xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
220
221
[313]222public:
223
[916]224  Distortion   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, const ComponentID compID, DFunc eDFunc = DF_SSE );
225
[313]226};// END CLASS DEFINITION TComRdCost
227
228//! \}
229
230#endif // __TCOMRDCOST__
Note: See TracBrowser for help on using the repository browser.