source: SHVCSoftware/branches/SHM-3.0-dev/source/Lib/TLibCommon/TComRdCost.h @ 1423

Last change on this file since 1423 was 313, checked in by suehring, 11 years ago

set svn:eol-style=native property on all source files to do proper
automatic line break conversion on check-out and check-in

  • Property svn:eol-style set to native
File size: 10.1 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  Int                     m_iBlkWidth;
119  Int                     m_iBlkHeight;
120 
121#if AMP_SAD
122  FpDistFunc              m_afpDistortFunc[64]; // [eDFunc]
123#else 
124  FpDistFunc              m_afpDistortFunc[33]; // [eDFunc]
125#endif 
126 
127#if WEIGHTED_CHROMA_DISTORTION
128  Double                  m_cbDistortionWeight; 
129  Double                  m_crDistortionWeight; 
130#endif
131  Double                  m_dLambda;
132  Double                  m_sqrtLambda;
133  UInt                    m_uiLambdaMotionSAD;
134  UInt                    m_uiLambdaMotionSSE;
135  Double                  m_dFrameLambda;
136 
137  // for motion cost
138#if FIX203
139  TComMv                  m_mvPredictor;
140#else
141  UInt*                   m_puiComponentCostOriginP;
142  UInt*                   m_puiComponentCost;
143  UInt*                   m_puiVerCost;
144  UInt*                   m_puiHorCost;
145#endif
146  UInt                    m_uiCost;
147  Int                     m_iCostScale;
148#if !FIX203
149  Int                     m_iSearchLimit;
150#endif
151 
152public:
153  TComRdCost();
154  virtual ~TComRdCost();
155 
156  Double  calcRdCost  ( UInt   uiBits, UInt   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
157  Double  calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
158 
159#if WEIGHTED_CHROMA_DISTORTION
160  Void    setCbDistortionWeight      ( Double cbDistortionWeight) { m_cbDistortionWeight = cbDistortionWeight; };
161  Void    setCrDistortionWeight      ( Double crDistortionWeight) { m_crDistortionWeight = crDistortionWeight; };
162#endif
163  Void    setLambda      ( Double dLambda );
164  Void    setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
165 
166  Double  getSqrtLambda ()   { return m_sqrtLambda; }
167
168#if RATE_CONTROL_LAMBDA_DOMAIN
169  Double  getLambda() { return m_dLambda; }
170#if M0036_RC_IMPROVEMENT
171  Double  getChromaWeight () {return((m_cbDistortionWeight+m_crDistortionWeight)/2.0);}
172#endif
173#endif
174 
175  // Distortion Functions
176  Void    init();
177 
178  Void    setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
179  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride,            DistParam& rcDistParam );
180#if NS_HAD
181  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false, Bool bUseNSHAD=false );
182  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false, Bool bUseNSHAD=false );
183#else
184  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
185  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
186#endif
187 
188  UInt    calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
189 
190  // for motion cost
191#if !FIX203
192  Void    initRateDistortionModel( Int iSubPelSearchLimit );
193  Void    xUninit();
194#endif
195  UInt    xGetComponentBits( Int iVal );
196  Void    getMotionCost( Bool bSad, Int iAdd ) { m_uiCost = (bSad ? m_uiLambdaMotionSAD + iAdd : m_uiLambdaMotionSSE + iAdd); }
197  Void    setPredictor( TComMv& rcMv )
198  {
199#if FIX203
200    m_mvPredictor = rcMv;
201#else
202    m_puiHorCost = m_puiComponentCost - rcMv.getHor();
203    m_puiVerCost = m_puiComponentCost - rcMv.getVer();
204#endif
205  }
206  Void    setCostScale( Int iCostScale )    { m_iCostScale = iCostScale; }
207  __inline UInt getCost( Int x, Int y )
208  {
209#if FIX203
210    return m_uiCost * getBits(x, y) >> 16;
211#else
212    return (( m_uiCost * (m_puiHorCost[ x * (1<<m_iCostScale) ] + m_puiVerCost[ y * (1<<m_iCostScale) ]) ) >> 16);
213#endif
214  }
215  UInt    getCost( UInt b )                 { return ( m_uiCost * b ) >> 16; }
216  UInt    getBits( Int x, Int y )         
217  {
218#if FIX203
219    return xGetComponentBits((x << m_iCostScale) - m_mvPredictor.getHor())
220    +      xGetComponentBits((y << m_iCostScale) - m_mvPredictor.getVer());
221#else
222    return m_puiHorCost[ x * (1<<m_iCostScale)] + m_puiVerCost[ y * (1<<m_iCostScale) ];
223#endif
224  }
225 
226private:
227 
228  static UInt xGetSSE           ( DistParam* pcDtParam );
229  static UInt xGetSSE4          ( DistParam* pcDtParam );
230  static UInt xGetSSE8          ( DistParam* pcDtParam );
231  static UInt xGetSSE16         ( DistParam* pcDtParam );
232  static UInt xGetSSE32         ( DistParam* pcDtParam );
233  static UInt xGetSSE64         ( DistParam* pcDtParam );
234  static UInt xGetSSE16N        ( DistParam* pcDtParam );
235 
236  static UInt xGetSAD           ( DistParam* pcDtParam );
237  static UInt xGetSAD4          ( DistParam* pcDtParam );
238  static UInt xGetSAD8          ( DistParam* pcDtParam );
239  static UInt xGetSAD16         ( DistParam* pcDtParam );
240  static UInt xGetSAD32         ( DistParam* pcDtParam );
241  static UInt xGetSAD64         ( DistParam* pcDtParam );
242  static UInt xGetSAD16N        ( DistParam* pcDtParam );
243 
244#if AMP_SAD
245  static UInt xGetSAD12         ( DistParam* pcDtParam );
246  static UInt xGetSAD24         ( DistParam* pcDtParam );
247  static UInt xGetSAD48         ( DistParam* pcDtParam );
248
249#endif
250
251  static UInt xGetHADs4         ( DistParam* pcDtParam );
252  static UInt xGetHADs8         ( DistParam* pcDtParam );
253  static UInt xGetHADs          ( DistParam* pcDtParam );
254  static UInt xCalcHADs2x2      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
255  static UInt xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
256  static UInt xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
257#if NS_HAD
258  static UInt xCalcHADs16x4     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
259  static UInt xCalcHADs4x16     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
260#endif
261 
262public:
263#if WEIGHTED_CHROMA_DISTORTION
264  UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText = TEXT_LUMA, DFunc eDFunc = DF_SSE );
265#else
266  UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE );
267#endif
268
269#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
270  UInt   getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height );
271#endif
272};// END CLASS DEFINITION TComRdCost
273
274//! \}
275
276#endif // __TCOMRDCOST__
Note: See TracBrowser for help on using the repository browser.