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

Last change on this file since 446 was 446, checked in by tech, 11 years ago

Added missing parts.

  • Property svn:eol-style set to native
File size: 15.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#if H_3D
49#include "../TLibRenderer/TRenModel.h"
50#endif
51
52//! \ingroup TLibCommon
53//! \{
54
55#define FIX203 1
56
57class DistParam;
58class TComPattern;
59#if H_3D
60class TComRdCost; 
61#endif
62
63// ====================================================================================================================
64// Type definition
65// ====================================================================================================================
66
67// for function pointer
68typedef UInt (*FpDistFunc) (DistParam*);
69
70#if H_3D
71#if H_3D_VSO
72typedef Dist (TComRdCost::*FpDistFuncVSO) ( Int, Int, Pel*, Int, Pel*, Int, UInt, UInt, Bool );
73#endif
74#endif
75// ====================================================================================================================
76// Class definition
77// ====================================================================================================================
78
79/// distortion parameter class
80class DistParam
81{
82public:
83  Pel*  pOrg;
84  Pel*  pCur;
85  Int   iStrideOrg;
86  Int   iStrideCur;
87#if H_3D_VSO
88  // SAIT_VSO_EST_A0033
89  Pel*  pVirRec;
90  Pel*  pVirOrg;
91  Int   iStrideVir;
92#endif
93  Int   iRows;
94  Int   iCols;
95  Int   iStep;
96  FpDistFunc DistFunc;
97  Int   bitDepth;
98
99  Bool            bApplyWeight;     // whether weithed prediction is used or not
100  wpScalingParam  *wpCur;           // weithed prediction scaling parameters for current ref
101  UInt            uiComp;           // uiComp = 0 (luma Y), 1 (chroma U), 2 (chroma V)
102
103#if NS_HAD
104  Bool            bUseNSHAD;
105#endif
106
107  // (vertical) subsampling shift (for reducing complexity)
108  // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc.
109  Int   iSubShift;
110 
111  DistParam()
112  {
113    pOrg = NULL;
114    pCur = NULL;
115    iStrideOrg = 0;
116    iStrideCur = 0;
117    iRows = 0;
118    iCols = 0;
119    iStep = 1;
120    DistFunc = NULL;
121    iSubShift = 0;
122    bitDepth = 0;
123#if NS_HAD
124    bUseNSHAD = false;
125#endif
126#if H_3D_VSO
127    // SAIT_VSO_EST_A0033
128    pVirRec = NULL;
129    pVirOrg = NULL;
130    iStrideVir = 0;
131#endif
132  }
133};
134
135/// RD cost computation class
136class TComRdCost
137  : public TComRdCostWeightPrediction
138{
139private:
140  // for distortion
141  Int                     m_iBlkWidth;
142  Int                     m_iBlkHeight;
143 
144#if AMP_SAD
145  FpDistFunc              m_afpDistortFunc[64]; // [eDFunc]
146#else 
147  FpDistFunc              m_afpDistortFunc[33]; // [eDFunc]
148#endif 
149 
150#if WEIGHTED_CHROMA_DISTORTION
151  Double                  m_cbDistortionWeight; 
152  Double                  m_crDistortionWeight; 
153#endif
154  Double                  m_dLambda;
155  Double                  m_sqrtLambda;
156  UInt                    m_uiLambdaMotionSAD;
157  UInt                    m_uiLambdaMotionSSE;
158  Double                  m_dFrameLambda;
159#if H_3D_VSO
160  // SAIT_VSO_EST_A0033
161  static Double           m_dDisparityCoeff;
162#endif
163 
164  // for motion cost
165#if FIX203
166  TComMv                  m_mvPredictor;
167#else
168  UInt*                   m_puiComponentCostOriginP;
169  UInt*                   m_puiComponentCost;
170  UInt*                   m_puiVerCost;
171  UInt*                   m_puiHorCost;
172#endif
173  UInt                    m_uiCost;
174  Int                     m_iCostScale;
175#if !FIX203
176  Int                     m_iSearchLimit;
177#endif
178 
179public:
180  TComRdCost();
181  virtual ~TComRdCost();
182
183#if H_3D_VSO
184  Double  calcRdCost  ( UInt   uiBits, Dist   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
185  Double  calcRdCost64( UInt64 uiBits, Dist64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
186#else
187  Double  calcRdCost  ( UInt   uiBits, UInt   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
188  Double  calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
189#endif
190
191 
192#if WEIGHTED_CHROMA_DISTORTION
193  Void    setCbDistortionWeight      ( Double cbDistortionWeight) { m_cbDistortionWeight = cbDistortionWeight; };
194  Void    setCrDistortionWeight      ( Double crDistortionWeight) { m_crDistortionWeight = crDistortionWeight; };
195#endif
196  Void    setLambda      ( Double dLambda );
197  Void    setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
198 
199  Double  getSqrtLambda ()   { return m_sqrtLambda; }
200#if H_3D_VSO
201  // SAIT_VSO_EST_A0033
202  Void    setDisparityCoeff( Double dDisparityCoeff ) { m_dDisparityCoeff = dDisparityCoeff; }
203  Double  getDisparityCoeff()                         { return m_dDisparityCoeff; }
204#endif
205
206#if RATE_CONTROL_LAMBDA_DOMAIN
207  Double  getLambda() { return m_dLambda; }
208#endif
209 
210  // Distortion Functions
211  Void    init();
212 
213  Void    setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
214  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride,            DistParam& rcDistParam );
215#if NS_HAD
216  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false, Bool bUseNSHAD=false );
217  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false, Bool bUseNSHAD=false );
218#else
219  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
220  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
221#endif
222 
223  UInt    calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
224 
225  // for motion cost
226#if !FIX203
227  Void    initRateDistortionModel( Int iSubPelSearchLimit );
228  Void    xUninit();
229#endif
230  UInt    xGetComponentBits( Int iVal );
231  Void    getMotionCost( Bool bSad, Int iAdd ) { m_uiCost = (bSad ? m_uiLambdaMotionSAD + iAdd : m_uiLambdaMotionSSE + iAdd); }
232  Void    setPredictor( TComMv& rcMv )
233  {
234#if FIX203
235    m_mvPredictor = rcMv;
236#else
237    m_puiHorCost = m_puiComponentCost - rcMv.getHor();
238    m_puiVerCost = m_puiComponentCost - rcMv.getVer();
239#endif
240  }
241  Void    setCostScale( Int iCostScale )    { m_iCostScale = iCostScale; }
242  __inline UInt getCost( Int x, Int y )
243  {
244#if FIX203
245    return m_uiCost * getBits(x, y) >> 16;
246#else
247    return (( m_uiCost * (m_puiHorCost[ x * (1<<m_iCostScale) ] + m_puiVerCost[ y * (1<<m_iCostScale) ]) ) >> 16);
248#endif
249  }
250  UInt    getCost( UInt b )                 { return ( m_uiCost * b ) >> 16; }
251  UInt    getBits( Int x, Int y )         
252  {
253#if FIX203
254    return xGetComponentBits((x << m_iCostScale) - m_mvPredictor.getHor())
255    +      xGetComponentBits((y << m_iCostScale) - m_mvPredictor.getVer());
256#else
257    return m_puiHorCost[ x * (1<<m_iCostScale)] + m_puiVerCost[ y * (1<<m_iCostScale) ];
258#endif
259  }
260 
261private:
262 
263  static UInt xGetSSE           ( DistParam* pcDtParam );
264  static UInt xGetSSE4          ( DistParam* pcDtParam );
265  static UInt xGetSSE8          ( DistParam* pcDtParam );
266  static UInt xGetSSE16         ( DistParam* pcDtParam );
267  static UInt xGetSSE32         ( DistParam* pcDtParam );
268  static UInt xGetSSE64         ( DistParam* pcDtParam );
269  static UInt xGetSSE16N        ( DistParam* pcDtParam );
270 
271  static UInt xGetSAD           ( DistParam* pcDtParam );
272  static UInt xGetSAD4          ( DistParam* pcDtParam );
273  static UInt xGetSAD8          ( DistParam* pcDtParam );
274  static UInt xGetSAD16         ( DistParam* pcDtParam );
275  static UInt xGetSAD32         ( DistParam* pcDtParam );
276  static UInt xGetSAD64         ( DistParam* pcDtParam );
277  static UInt xGetSAD16N        ( DistParam* pcDtParam );
278 
279#if H_3D_VSO
280  static UInt xGetVSD           ( DistParam* pcDtParam );
281  static UInt xGetVSD4          ( DistParam* pcDtParam );
282  static UInt xGetVSD8          ( DistParam* pcDtParam );
283  static UInt xGetVSD16         ( DistParam* pcDtParam );
284  static UInt xGetVSD32         ( DistParam* pcDtParam );
285  static UInt xGetVSD64         ( DistParam* pcDtParam );
286  static UInt xGetVSD16N        ( DistParam* pcDtParam );
287#endif
288
289#if AMP_SAD
290  static UInt xGetSAD12         ( DistParam* pcDtParam );
291  static UInt xGetSAD24         ( DistParam* pcDtParam );
292  static UInt xGetSAD48         ( DistParam* pcDtParam );
293
294#endif
295
296  static UInt xGetHADs4         ( DistParam* pcDtParam );
297  static UInt xGetHADs8         ( DistParam* pcDtParam );
298  static UInt xGetHADs          ( DistParam* pcDtParam );
299  static UInt xCalcHADs2x2      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
300  static UInt xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
301  static UInt xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
302#if NS_HAD
303  static UInt xCalcHADs16x4     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
304  static UInt xCalcHADs4x16     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
305#endif
306 
307public:
308#if WEIGHTED_CHROMA_DISTORTION
309  UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText = TEXT_LUMA, DFunc eDFunc = DF_SSE );
310#else
311  UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE );
312#endif
313
314#if RATE_CONTROL_LAMBDA_DOMAIN
315  UInt   getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height );
316#endif
317
318#if H_3D_VSO
319  // SAIT_VSO_EST_A0033
320  UInt        getDistPartVSD( TComDataCU* pcCu, UInt uiPartOffset, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bHad, DFunc eDFunc = DF_VSD); 
321  static UInt getVSDEstimate( Int dDM, Pel* pOrg, Int iOrgStride,  Pel* pVirRec, Pel* pVirOrg, Int iVirStride, Int x, Int y );
322
323private:
324  Double                  m_dLambdaVSO;
325  Double                  m_dSqrtLambdaVSO;
326  UInt                    m_uiLambdaMotionSADVSO;
327  UInt                    m_uiLambdaMotionSSEVSO;
328  Double                  m_dFrameLambdaVSO;
329  Bool                    m_bAllowNegDist;
330  Bool                    m_bUseVSO;
331  Bool                    m_bUseLambdaScaleVSO;
332  UInt                    m_uiVSOMode;
333
334  FpDistFuncVSO           m_fpDistortFuncVSO;
335  TRenModel*              m_pcRenModel;
336
337
338  // SAIT_VSO_EST_A0033
339  TComPicYuv *            m_pcVideoRecPicYuv;
340  TComPicYuv *            m_pcDepthPicYuv;
341  Bool                    m_bUseEstimatedVSD; 
342
343  // LGE_WVSO_A0119
344  Int                     m_iDWeight;
345  Int                     m_iVSOWeight;
346  Int                     m_iVSDWeight;
347  Bool                    m_bUseWVSO;
348
349public:
350
351  Void    setRenModel       ( TRenModel* pcRenModel ) { m_pcRenModel = pcRenModel; }
352  TRenModel* getRenModel    ( )                       { return m_pcRenModel; }
353  Void    setRenModelData   ( TComDataCU* pcCU, UInt uiAbsPartIndex, Pel* piData, Int iStride, Int iBlkWidth, Int iBlkHeight );
354  Void    setLambdaVSO      ( Double dLambda );
355  Void    setFrameLambdaVSO ( Double dLambda ) { m_dFrameLambdaVSO = dLambda; };
356
357
358  Void    setUseVSO ( Bool bIn )         { m_bUseVSO = bIn; };
359  Bool    getUseVSO ( )                  { return m_bUseVSO;};
360
361  Bool    getUseRenModel ( )             { return (m_bUseVSO && m_uiVSOMode == 4); };
362  Void    setUseLambdaScaleVSO(Bool bIn) { m_bUseLambdaScaleVSO = bIn; };
363  Bool    getUseLambdaScaleVSO( )        { return m_bUseLambdaScaleVSO; };
364
365  Void    setVSOMode( UInt uiIn);
366  UInt    getVSOMode( )                  { return m_uiVSOMode; }
367  Void    setAllowNegDist ( Bool bAllowNegDist );
368
369  Double  getSqrtLambdaVSO ()   { return m_dSqrtLambdaVSO; }
370  Double  getLambdaVSO ()       { return m_dLambdaVSO; }
371
372  Dist   getDistPartVSO( TComDataCU* pcCU, UInt uiAbsPartIndex, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD );
373  Double calcRdCostVSO ( UInt   uiBits, Dist   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
374
375  // SAIT_VSO_EST_A0033
376  Bool    getUseEstimatedVSD( )           { return m_bUseEstimatedVSD; };
377  Void    setUseEstimatedVSD( Bool bIn )  { m_bUseEstimatedVSD = bIn; };
378
379  TComPicYuv* getVideoRecPicYuv ()                               { return m_pcVideoRecPicYuv; };
380  Void        setVideoRecPicYuv ( TComPicYuv* pcVideoRecPicYuv ) { m_pcVideoRecPicYuv = pcVideoRecPicYuv; };
381  TComPicYuv* getDepthPicYuv    ()                               { return m_pcDepthPicYuv; };
382  Void        setDepthPicYuv    ( TComPicYuv* pcDepthPicYuv )    { m_pcDepthPicYuv = pcDepthPicYuv; };
383
384  // LGE_WVSO_A0119
385  Void    setUseWVSO ( Bool bIn )         { m_bUseWVSO = bIn; }; 
386  Bool    getUseWVSO ( )                  { return m_bUseWVSO;};
387  Void    setDWeight   ( Int iDWeight   ) { m_iDWeight = iDWeight; };
388  Int     getDWeight   ()                 { return m_iDWeight; };
389  Void    setVSOWeight ( Int iVSOWeight ) { m_iVSOWeight = iVSOWeight; };
390  Int     getVSOWeight ()                 { return m_iVSOWeight; };
391  Void    setVSDWeight ( Int iVSDWeight ) { m_iVSDWeight = iVSDWeight; };
392  Int     getVSDWeight ()                 { return m_iVSDWeight; };
393
394private:
395  Dist xGetDistVSOMode4( Int iStartPosX, Int iStartPosY, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD );
396
397#endif // H_3D_VSO
398
399};// END CLASS DEFINITION TComRdCost
400
401//! \}
402
403#endif // __TCOMRDCOST__
Note: See TracBrowser for help on using the repository browser.