source: 3DVCSoftware/branches/HTM-14.0-MV-draft-3/source/Lib/TLibCommon/TComRdCost.h @ 1417

Last change on this file since 1417 was 1191, checked in by tech, 10 years ago

Removed 3D-HEVC.

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