source: SHVCSoftware/branches/SHM-3.1-dev/source/Lib/TLibCommon/TComRdCost.h @ 462

Last change on this file since 462 was 431, checked in by seregin, 11 years ago

initial porting of HM12

  • Property svn:eol-style set to native
File size: 10.0 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
49//! \ingroup TLibCommon
50//! \{
51
52#define FIX203 1
53
54class DistParam;
55class TComPattern;
56
57// ====================================================================================================================
58// Type definition
59// ====================================================================================================================
60
61// for function pointer
62typedef UInt (*FpDistFunc) (DistParam*);
63
64// ====================================================================================================================
65// Class definition
66// ====================================================================================================================
67
68/// distortion parameter class
69class DistParam
70{
71public:
72  Pel*  pOrg;
73  Pel*  pCur;
74  Int   iStrideOrg;
75  Int   iStrideCur;
76  Int   iRows;
77  Int   iCols;
78  Int   iStep;
79  FpDistFunc DistFunc;
80  Int   bitDepth;
81
82  Bool            bApplyWeight;     // whether weithed prediction is used or not
83  wpScalingParam  *wpCur;           // weithed prediction scaling parameters for current ref
84  UInt            uiComp;           // uiComp = 0 (luma Y), 1 (chroma U), 2 (chroma V)
85
86#if NS_HAD
87  Bool            bUseNSHAD;
88#endif
89
90  // (vertical) subsampling shift (for reducing complexity)
91  // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc.
92  Int   iSubShift;
93 
94  DistParam()
95  {
96    pOrg = NULL;
97    pCur = NULL;
98    iStrideOrg = 0;
99    iStrideCur = 0;
100    iRows = 0;
101    iCols = 0;
102    iStep = 1;
103    DistFunc = NULL;
104    iSubShift = 0;
105    bitDepth = 0;
106#if NS_HAD
107    bUseNSHAD = false;
108#endif
109  }
110};
111
112/// RD cost computation class
113class TComRdCost
114  : public TComRdCostWeightPrediction
115{
116private:
117  // for distortion
118 
119#if AMP_SAD
120  FpDistFunc              m_afpDistortFunc[64]; // [eDFunc]
121#else 
122  FpDistFunc              m_afpDistortFunc[33]; // [eDFunc]
123#endif 
124 
125#if WEIGHTED_CHROMA_DISTORTION
126  Double                  m_cbDistortionWeight; 
127  Double                  m_crDistortionWeight; 
128#endif
129  Double                  m_dLambda;
130  Double                  m_sqrtLambda;
131  UInt                    m_uiLambdaMotionSAD;
132  UInt                    m_uiLambdaMotionSSE;
133  Double                  m_dFrameLambda;
134 
135  // for motion cost
136#if FIX203
137  TComMv                  m_mvPredictor;
138#else
139  UInt*                   m_puiComponentCostOriginP;
140  UInt*                   m_puiComponentCost;
141  UInt*                   m_puiVerCost;
142  UInt*                   m_puiHorCost;
143#endif
144  UInt                    m_uiCost;
145  Int                     m_iCostScale;
146#if !FIX203
147  Int                     m_iSearchLimit;
148#endif
149 
150public:
151  TComRdCost();
152  virtual ~TComRdCost();
153 
154  Double  calcRdCost  ( UInt   uiBits, UInt   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
155  Double  calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
156 
157#if WEIGHTED_CHROMA_DISTORTION
158  Void    setCbDistortionWeight      ( Double cbDistortionWeight) { m_cbDistortionWeight = cbDistortionWeight; };
159  Void    setCrDistortionWeight      ( Double crDistortionWeight) { m_crDistortionWeight = crDistortionWeight; };
160#endif
161  Void    setLambda      ( Double dLambda );
162  Void    setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
163 
164  Double  getSqrtLambda ()   { return m_sqrtLambda; }
165
166#if RATE_CONTROL_LAMBDA_DOMAIN
167  Double  getLambda() { return m_dLambda; }
168#if M0036_RC_IMPROVEMENT
169  Double  getChromaWeight () {return((m_cbDistortionWeight+m_crDistortionWeight)/2.0);}
170#endif
171#endif
172 
173  // Distortion Functions
174  Void    init();
175 
176  Void    setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
177  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride,            DistParam& rcDistParam );
178#if NS_HAD
179  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false, Bool bUseNSHAD=false );
180  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false, Bool bUseNSHAD=false );
181#else
182  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
183  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
184#endif
185 
186  UInt    calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
187 
188  // for motion cost
189#if !FIX203
190  Void    initRateDistortionModel( Int iSubPelSearchLimit );
191  Void    xUninit();
192#endif
193  UInt    xGetComponentBits( Int iVal );
194  Void    getMotionCost( Bool bSad, Int iAdd ) { m_uiCost = (bSad ? m_uiLambdaMotionSAD + iAdd : m_uiLambdaMotionSSE + iAdd); }
195  Void    setPredictor( TComMv& rcMv )
196  {
197#if FIX203
198    m_mvPredictor = rcMv;
199#else
200    m_puiHorCost = m_puiComponentCost - rcMv.getHor();
201    m_puiVerCost = m_puiComponentCost - rcMv.getVer();
202#endif
203  }
204  Void    setCostScale( Int iCostScale )    { m_iCostScale = iCostScale; }
205  __inline UInt getCost( Int x, Int y )
206  {
207#if FIX203
208    return m_uiCost * getBits(x, y) >> 16;
209#else
210    return (( m_uiCost * (m_puiHorCost[ x * (1<<m_iCostScale) ] + m_puiVerCost[ y * (1<<m_iCostScale) ]) ) >> 16);
211#endif
212  }
213  UInt    getCost( UInt b )                 { return ( m_uiCost * b ) >> 16; }
214  UInt    getBits( Int x, Int y )         
215  {
216#if FIX203
217    return xGetComponentBits((x << m_iCostScale) - m_mvPredictor.getHor())
218    +      xGetComponentBits((y << m_iCostScale) - m_mvPredictor.getVer());
219#else
220    return m_puiHorCost[ x * (1<<m_iCostScale)] + m_puiVerCost[ y * (1<<m_iCostScale) ];
221#endif
222  }
223 
224private:
225 
226  static UInt xGetSSE           ( DistParam* pcDtParam );
227  static UInt xGetSSE4          ( DistParam* pcDtParam );
228  static UInt xGetSSE8          ( DistParam* pcDtParam );
229  static UInt xGetSSE16         ( DistParam* pcDtParam );
230  static UInt xGetSSE32         ( DistParam* pcDtParam );
231  static UInt xGetSSE64         ( DistParam* pcDtParam );
232  static UInt xGetSSE16N        ( DistParam* pcDtParam );
233 
234  static UInt xGetSAD           ( DistParam* pcDtParam );
235  static UInt xGetSAD4          ( DistParam* pcDtParam );
236  static UInt xGetSAD8          ( DistParam* pcDtParam );
237  static UInt xGetSAD16         ( DistParam* pcDtParam );
238  static UInt xGetSAD32         ( DistParam* pcDtParam );
239  static UInt xGetSAD64         ( DistParam* pcDtParam );
240  static UInt xGetSAD16N        ( DistParam* pcDtParam );
241 
242#if AMP_SAD
243  static UInt xGetSAD12         ( DistParam* pcDtParam );
244  static UInt xGetSAD24         ( DistParam* pcDtParam );
245  static UInt xGetSAD48         ( DistParam* pcDtParam );
246
247#endif
248
249  static UInt xGetHADs4         ( DistParam* pcDtParam );
250  static UInt xGetHADs8         ( DistParam* pcDtParam );
251  static UInt xGetHADs          ( DistParam* pcDtParam );
252  static UInt xCalcHADs2x2      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
253  static UInt xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
254  static UInt xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
255#if NS_HAD
256  static UInt xCalcHADs16x4     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
257  static UInt xCalcHADs4x16     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
258#endif
259 
260public:
261#if WEIGHTED_CHROMA_DISTORTION
262  UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText = TEXT_LUMA, DFunc eDFunc = DF_SSE );
263#else
264  UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE );
265#endif
266
267#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
268  UInt   getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height );
269#endif
270};// END CLASS DEFINITION TComRdCost
271
272//! \}
273
274#endif // __TCOMRDCOST__
Note: See TracBrowser for help on using the repository browser.