source: 3DVCSoftware/branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TComRdCost.h @ 368

Last change on this file since 368 was 324, checked in by tech, 12 years ago

Initial development version for update to latest HM version.
Includes MV-HEVC and basic extensions for 3D-HEVC.

  • Property svn:eol-style set to native
File size: 9.9 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#endif
171 
172  // Distortion Functions
173  Void    init();
174 
175  Void    setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
176  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride,            DistParam& rcDistParam );
177#if NS_HAD
178  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false, Bool bUseNSHAD=false );
179  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false, Bool bUseNSHAD=false );
180#else
181  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
182  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
183#endif
184 
185  UInt    calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
186 
187  // for motion cost
188#if !FIX203
189  Void    initRateDistortionModel( Int iSubPelSearchLimit );
190  Void    xUninit();
191#endif
192  UInt    xGetComponentBits( Int iVal );
193  Void    getMotionCost( Bool bSad, Int iAdd ) { m_uiCost = (bSad ? m_uiLambdaMotionSAD + iAdd : m_uiLambdaMotionSSE + iAdd); }
194  Void    setPredictor( TComMv& rcMv )
195  {
196#if FIX203
197    m_mvPredictor = rcMv;
198#else
199    m_puiHorCost = m_puiComponentCost - rcMv.getHor();
200    m_puiVerCost = m_puiComponentCost - rcMv.getVer();
201#endif
202  }
203  Void    setCostScale( Int iCostScale )    { m_iCostScale = iCostScale; }
204  __inline UInt getCost( Int x, Int y )
205  {
206#if FIX203
207    return m_uiCost * getBits(x, y) >> 16;
208#else
209    return (( m_uiCost * (m_puiHorCost[ x * (1<<m_iCostScale) ] + m_puiVerCost[ y * (1<<m_iCostScale) ]) ) >> 16);
210#endif
211  }
212  UInt    getCost( UInt b )                 { return ( m_uiCost * b ) >> 16; }
213  UInt    getBits( Int x, Int y )         
214  {
215#if FIX203
216    return xGetComponentBits((x << m_iCostScale) - m_mvPredictor.getHor())
217    +      xGetComponentBits((y << m_iCostScale) - m_mvPredictor.getVer());
218#else
219    return m_puiHorCost[ x * (1<<m_iCostScale)] + m_puiVerCost[ y * (1<<m_iCostScale) ];
220#endif
221  }
222 
223private:
224 
225  static UInt xGetSSE           ( DistParam* pcDtParam );
226  static UInt xGetSSE4          ( DistParam* pcDtParam );
227  static UInt xGetSSE8          ( DistParam* pcDtParam );
228  static UInt xGetSSE16         ( DistParam* pcDtParam );
229  static UInt xGetSSE32         ( DistParam* pcDtParam );
230  static UInt xGetSSE64         ( DistParam* pcDtParam );
231  static UInt xGetSSE16N        ( DistParam* pcDtParam );
232 
233  static UInt xGetSAD           ( DistParam* pcDtParam );
234  static UInt xGetSAD4          ( DistParam* pcDtParam );
235  static UInt xGetSAD8          ( DistParam* pcDtParam );
236  static UInt xGetSAD16         ( DistParam* pcDtParam );
237  static UInt xGetSAD32         ( DistParam* pcDtParam );
238  static UInt xGetSAD64         ( DistParam* pcDtParam );
239  static UInt xGetSAD16N        ( DistParam* pcDtParam );
240 
241#if AMP_SAD
242  static UInt xGetSAD12         ( DistParam* pcDtParam );
243  static UInt xGetSAD24         ( DistParam* pcDtParam );
244  static UInt xGetSAD48         ( DistParam* pcDtParam );
245
246#endif
247
248  static UInt xGetHADs4         ( DistParam* pcDtParam );
249  static UInt xGetHADs8         ( DistParam* pcDtParam );
250  static UInt xGetHADs          ( DistParam* pcDtParam );
251  static UInt xCalcHADs2x2      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
252  static UInt xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
253  static UInt xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
254#if NS_HAD
255  static UInt xCalcHADs16x4     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
256  static UInt xCalcHADs4x16     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
257#endif
258 
259public:
260#if WEIGHTED_CHROMA_DISTORTION
261  UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText = TEXT_LUMA, DFunc eDFunc = DF_SSE );
262#else
263  UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE );
264#endif
265
266#if RATE_CONTROL_LAMBDA_DOMAIN
267  UInt   getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height );
268#endif
269};// END CLASS DEFINITION TComRdCost
270
271//! \}
272
273#endif // __TCOMRDCOST__
Note: See TracBrowser for help on using the repository browser.