source: 3DVCSoftware/branches/HTM-6.0-dev0/source/Lib/TLibCommon/TComRdCost.h @ 312

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

Reintegrated branch 5.1-dev0 rev. 295.

  • Property svn:eol-style set to native
File size: 17.2 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-2012, 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 "TComRdCost.h"
47#include "TComSlice.h"
48#include "TComRdCostWeightPrediction.h"
49#include "../TLibRenderer/TRenModel.h"
50
51//! \ingroup TLibCommon
52//! \{
53
54#define FIX203 1
55
56class DistParam;
57class TComPattern;
58class TComRdCost; 
59
60// ====================================================================================================================
61// Type definition
62// ====================================================================================================================
63
64// for function pointer
65typedef UInt (*FpDistFunc) (DistParam*);
66
67#if HHI_VSO
68typedef Dist (TComRdCost::*FpDistFuncVSO) ( Int, Int, Pel*, Int, Pel*, Int, UInt, UInt, Bool );
69#endif
70// ====================================================================================================================
71// Class definition
72// ====================================================================================================================
73
74/// distortion parameter class
75class DistParam
76{
77public:
78  Pel*  pOrg;
79  Pel*  pCur;
80  Int   iStrideOrg;
81  Int   iStrideCur;
82#if SAIT_VSO_EST_A0033
83  Pel*  pVirRec;
84  Pel*  pVirOrg;
85  Int   iStrideVir;
86#endif
87  Int   iRows;
88  Int   iCols;
89  Int   iStep;
90#if LGE_ILLUCOMP_B0045
91  Bool  bUseIC;
92#endif
93  FpDistFunc DistFunc;
94
95#if HHI_INTERVIEW_SKIP
96  Pel*  pUsed;
97  Int   iStrideUsed;
98#endif
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#if SAIT_VSO_EST_A0033
116    pVirRec = NULL;
117    pVirOrg = NULL;;
118    iStrideVir = 0;
119#endif
120    iStrideOrg = 0;
121    iStrideCur = 0;
122    iRows = 0;
123    iCols = 0;
124    iStep = 1;
125    DistFunc = NULL;
126    iSubShift = 0;
127#if HHI_INTERVIEW_SKIP
128    pUsed       = 0;
129    iStrideUsed = 0;
130#endif
131#if NS_HAD
132    bUseNSHAD = false;
133#endif
134  }
135};
136
137/// RD cost computation class
138class TComRdCost
139  : public TComRdCostWeightPrediction
140{
141private:
142  // for distortion
143  Int                     m_iBlkWidth;
144  Int                     m_iBlkHeight;
145 
146#if AMP_SAD
147  FpDistFunc              m_afpDistortFunc[64]; // [eDFunc]
148#else 
149  FpDistFunc              m_afpDistortFunc[33]; // [eDFunc]
150#endif 
151 
152#if WEIGHTED_CHROMA_DISTORTION
153  Double                  m_chromaDistortionWeight;   
154#endif
155  Double                  m_dLambda;
156  Double                  m_sqrtLambda;
157  UInt                    m_uiLambdaMotionSAD;
158  UInt                    m_uiLambdaMotionSSE;
159  Double                  m_dFrameLambda;
160#if SAIT_VSO_EST_A0033
161  static Double           m_dDisparityCoeff;
162#endif
163 
164#if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
165  Double                  m_dLambdaScale ;
166#endif
167  // for motion cost
168#if FIX203
169  TComMv                  m_mvPredictor;
170#else
171  UInt*                   m_puiComponentCostOriginP;
172  UInt*                   m_puiComponentCost;
173  UInt*                   m_puiVerCost;
174  UInt*                   m_puiHorCost;
175#endif
176  UInt                    m_uiCost;
177  Int                     m_iCostScale;
178#if !FIX203
179  Int                     m_iSearchLimit;
180#endif
181 
182  Bool                    m_bUseMultiviewReg;
183  UInt                    m_uiLambdaMVReg;
184  UInt                    m_uiLambdaMVRegSAD;
185  UInt                    m_uiLambdaMVRegSSE;
186  UInt*                   m_puiMultiviewRegCostHorOrgP;
187  UInt*                   m_puiMultiviewRegCostVerOrgP;
188  UInt*                   m_puiMultiviewRegCostHor;
189  UInt*                   m_puiMultiviewRegCostVer;
190  UInt*                   m_puiHorRegCost;
191  UInt*                   m_puiVerRegCost;
192  TComMv                  m_cMultiviewOrgMvPred;
193 
194public:
195  TComRdCost();
196  virtual ~TComRdCost();
197 
198  Double  calcRdCost  ( UInt   uiBits, UInt   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
199  Double  calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
200 
201#if WEIGHTED_CHROMA_DISTORTION
202  Void    setChromaDistortionWeight      ( Double chromaDistortionWeight) { m_chromaDistortionWeight = chromaDistortionWeight; };
203#endif
204  Void    setLambda      ( Double dLambda );
205#if H3D_IVMP
206  Void    setLambdaMVReg ( Double dLambda );
207#endif
208  Void    setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
209 
210#if SAIT_VSO_EST_A0033
211  Void    setDisparityCoeff( Double dDisparityCoeff ) { m_dDisparityCoeff = dDisparityCoeff; }
212  Double  getDisparityCoeff()                         { return m_dDisparityCoeff; }
213#endif
214
215#if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
216  Void   setLambdaScale  ( Double dLambdaScale) { m_dLambdaScale = dLambdaScale; }
217  Double   getLambdaScale  ( ) { return m_dLambdaScale ; }
218#endif
219  Double  getSqrtLambda ()   { return m_sqrtLambda; }
220 
221  // Distortion Functions
222  Void    init();
223 
224  Void    setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
225  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride,            DistParam& rcDistParam );
226#if NS_HAD
227  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false, Bool bUseNSHAD=false );
228  Void    setDistParam( DistParam& rcDP, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false, Bool bUseNSHAD=false );
229#else
230  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
231  Void    setDistParam( DistParam& rcDP, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
232#endif
233 
234  UInt    calcHAD         ( Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
235 
236  // for motion cost
237#if !FIX203
238  Void    initRateDistortionModel( Int iSubPelSearchLimit );
239  Void    xUninit();
240#endif
241  UInt    xGetComponentBits( Int iVal );
242  Void    getMotionCost( Bool bSad, Int iAdd ) 
243{ 
244     m_uiCost = (bSad ? m_uiLambdaMotionSAD + iAdd : m_uiLambdaMotionSSE + iAdd); 
245    m_uiLambdaMVReg = ( bSad ? m_uiLambdaMVRegSAD         : m_uiLambdaMVRegSSE         );
246
247   }
248  Void    setPredictor( TComMv& rcMv )
249  {
250#if FIX203
251    m_mvPredictor = rcMv;
252#else
253    m_puiHorCost = m_puiComponentCost - rcMv.getHor();
254    m_puiVerCost = m_puiComponentCost - rcMv.getVer();
255#endif
256  }
257  Void    setCostScale( Int iCostScale )    { m_iCostScale = iCostScale; }
258  __inline UInt getCost( Int x, Int y )
259  {
260#if FIX203
261    return m_uiCost * getBits(x, y) >> 16;
262#else
263    return (( m_uiCost * (m_puiHorCost[ x * (1<<m_iCostScale) ] + m_puiVerCost[ y * (1<<m_iCostScale) ]) ) >> 16);
264#endif
265  }
266  UInt    getCost( UInt b )                 { return ( m_uiCost * b ) >> 16; }
267  UInt    getBits( Int x, Int y )         
268  {
269#if FIX203
270    return xGetComponentBits((x << m_iCostScale) - m_mvPredictor.getHor())
271    +      xGetComponentBits((y << m_iCostScale) - m_mvPredictor.getVer());
272#else
273    return m_puiHorCost[ x * (1<<m_iCostScale)] + m_puiVerCost[ y * (1<<m_iCostScale) ];
274#endif
275  }
276
277  Void    setMultiviewReg( TComMv* pcMv )
278  {
279    if( pcMv )
280    {
281      m_bUseMultiviewReg    = true;
282      m_puiHorRegCost       = m_puiMultiviewRegCostHor - pcMv->getHor();
283      m_puiVerRegCost       = m_puiMultiviewRegCostVer - pcMv->getVer();
284      m_cMultiviewOrgMvPred = *pcMv;
285    }
286    else
287    {
288      m_bUseMultiviewReg    = false;
289      m_puiHorRegCost       = 0;
290      m_puiVerRegCost       = 0;
291      m_cMultiviewOrgMvPred.set( 0, 0 );
292    }
293  }
294  __inline Bool     useMultiviewReg      () { return m_bUseMultiviewReg; }
295  __inline TComMv&  getMultiviewOrgMvPred() { return m_cMultiviewOrgMvPred; }
296  __inline UInt     getMultiviewRegCost  ( Int x, Int y )
297  {
298#if FIX203
299    return m_uiLambdaMVReg * getBits(x, y) >> 16;
300#else
301    return ( ( m_uiLambdaMVReg * ( m_puiHorRegCost[ x * ( 1 << m_iCostScale ) ] + m_puiVerRegCost[ y * ( 1 << m_iCostScale ) ] ) ) >> 16 );
302#endif
303  }
304 
305private:
306 
307#if LGE_ILLUCOMP_B0045
308  static UInt xGetSADic         ( DistParam* pcDtParam );
309  static UInt xGetSAD4ic        ( DistParam* pcDtParam );
310  static UInt xGetSAD8ic        ( DistParam* pcDtParam );
311  static UInt xGetSAD16ic       ( DistParam* pcDtParam );
312  static UInt xGetSAD32ic       ( DistParam* pcDtParam );
313  static UInt xGetSAD64ic       ( DistParam* pcDtParam );
314  static UInt xGetSAD16Nic      ( DistParam* pcDtParam );
315#endif
316  static UInt xGetSSE           ( DistParam* pcDtParam );
317  static UInt xGetSSE4          ( DistParam* pcDtParam );
318  static UInt xGetSSE8          ( DistParam* pcDtParam );
319  static UInt xGetSSE16         ( DistParam* pcDtParam );
320  static UInt xGetSSE32         ( DistParam* pcDtParam );
321  static UInt xGetSSE64         ( DistParam* pcDtParam );
322  static UInt xGetSSE16N        ( DistParam* pcDtParam );
323 
324  static UInt xGetSAD           ( DistParam* pcDtParam );
325  static UInt xGetSAD4          ( DistParam* pcDtParam );
326  static UInt xGetSAD8          ( DistParam* pcDtParam );
327  static UInt xGetSAD16         ( DistParam* pcDtParam );
328  static UInt xGetSAD32         ( DistParam* pcDtParam );
329  static UInt xGetSAD64         ( DistParam* pcDtParam );
330  static UInt xGetSAD16N        ( DistParam* pcDtParam );
331 
332#if SAIT_VSO_EST_A0033
333  static UInt xGetVSD           ( DistParam* pcDtParam );
334  static UInt xGetVSD4          ( DistParam* pcDtParam );
335  static UInt xGetVSD8          ( DistParam* pcDtParam );
336  static UInt xGetVSD16         ( DistParam* pcDtParam );
337  static UInt xGetVSD32         ( DistParam* pcDtParam );
338  static UInt xGetVSD64         ( DistParam* pcDtParam );
339  static UInt xGetVSD16N        ( DistParam* pcDtParam );
340#endif
341
342#if AMP_SAD
343#if LGE_ILLUCOMP_B0045
344  static UInt xGetSAD12ic       ( DistParam* pcDtParam );
345  static UInt xGetSAD24ic       ( DistParam* pcDtParam );
346  static UInt xGetSAD48ic       ( DistParam* pcDtParam );
347#endif
348  static UInt xGetSAD12         ( DistParam* pcDtParam );
349  static UInt xGetSAD24         ( DistParam* pcDtParam );
350  static UInt xGetSAD48         ( DistParam* pcDtParam );
351#endif
352
353#if LGE_ILLUCOMP_B0045
354  static UInt xGetHADsic          ( DistParam* pcDtParam );
355#endif
356  static UInt xGetHADs4         ( DistParam* pcDtParam );
357  static UInt xGetHADs8         ( DistParam* pcDtParam );
358  static UInt xGetHADs          ( DistParam* pcDtParam );
359
360  static UInt xCalcHADs2x2      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
361  static UInt xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
362  static UInt xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
363#if NS_HAD
364  static UInt xCalcHADs16x4     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
365  static UInt xCalcHADs4x16     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
366#endif
367 
368public:
369#if HHI_INTERVIEW_SKIP
370  UInt   getDistPart( Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, Pel* piUsed, Int iUsedStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE );
371#endif
372#if WEIGHTED_CHROMA_DISTORTION
373  UInt   getDistPart( Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bWeighted = false, DFunc eDFunc = DF_SSE );
374#else
375  UInt   getDistPart( Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE );
376#endif
377 
378#if SAIT_VSO_EST_A0033
379  UInt   getDistPart( Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, Pel* piVirRec, Pel* piVirOrg, Int iVirStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_VSD );
380  static UInt getVSDEstimate( Int dDM, Pel* pOrg, Int iOrgStride,  Pel* pVirRec, Pel* pVirOrg, Int iVirStride, Int x, Int y );
381#endif
382
383#if HHI_VSO
384private:
385  Double                  m_dLambdaVSO;
386  Double                  m_dSqrtLambdaVSO;
387  UInt                    m_uiLambdaMotionSADVSO;
388  UInt                    m_uiLambdaMotionSSEVSO;
389  Double                  m_dFrameLambdaVSO;
390
391#if HHI_VSO_DIST_INT
392  Bool                    m_bAllowNegDist;
393#endif
394#if SAIT_VSO_EST_A0033
395  TComPicYuv *            m_pcVideoRecPicYuv;
396  TComPicYuv *            m_pcDepthPicYuv;
397  Bool                    m_bUseEstimatedVSD; 
398#endif
399#if LGE_WVSO_A0119
400  Int                     m_iDWeight;
401  Int                     m_iVSOWeight;
402  Int                     m_iVSDWeight;
403  Bool                    m_bUseWVSO;
404#endif
405
406  Bool                    m_bUseVSO;
407  Bool                    m_bUseLambdaScaleVSO;
408  UInt                    m_uiVSOMode;
409
410  FpDistFuncVSO           m_fpDistortFuncVSO;
411  TRenModel*              m_pcRenModel;
412public:
413
414  Void    setRenModel       ( TRenModel* pcRenModel ) { m_pcRenModel = pcRenModel; }
415  Void    setRenModelData   ( TComDataCU* pcCU, UInt uiAbsPartIndex, Pel* piData, Int iStride, Int iBlkWidth, Int iBlkHeight );
416  Void    setLambdaVSO      ( Double dLambda );
417  Void    setFrameLambdaVSO ( Double dLambda ) { m_dFrameLambdaVSO = dLambda; };
418
419
420  Void    setUseVSO ( Bool bIn )         { m_bUseVSO = bIn; };
421  Bool    getUseVSO ( )                  { return m_bUseVSO;};
422#if SAIT_VSO_EST_A0033
423  Bool    getUseEstimatedVSD( )           { return m_bUseEstimatedVSD; };
424  Void    setUseEstimatedVSD( Bool bIn )  { m_bUseEstimatedVSD = bIn; };
425
426  TComPicYuv* getVideoRecPicYuv ()                               { return m_pcVideoRecPicYuv; };
427  Void        setVideoRecPicYuv ( TComPicYuv* pcVideoRecPicYuv ) { m_pcVideoRecPicYuv = pcVideoRecPicYuv; };
428  TComPicYuv* getDepthPicYuv    ()                               { return m_pcDepthPicYuv; };
429  Void        setDepthPicYuv    ( TComPicYuv* pcDepthPicYuv )    { m_pcDepthPicYuv = pcDepthPicYuv; };
430#endif
431
432  Bool    getUseRenModel ( )             { return (m_bUseVSO && m_uiVSOMode == 4); };
433  Void    setUseLambdaScaleVSO(bool bIn) { m_bUseLambdaScaleVSO = bIn; };
434  Bool    getUseLambdaScaleVSO( )        { return m_bUseLambdaScaleVSO; };
435
436  Void    setVSOMode( UInt uiIn);
437  UInt    getVSOMode( )                  { return m_uiVSOMode; }
438#if LGE_WVSO_A0119
439  Void    setUseWVSO ( Bool bIn )         { m_bUseWVSO = bIn; }; 
440  Bool    getUseWVSO ( )                  { return m_bUseWVSO;};
441  Void    setDWeight   ( Int iDWeight   ) { m_iDWeight = iDWeight; };
442  Int     getDWeight   ()                 { return m_iDWeight; };
443  Void    setVSOWeight ( Int iVSOWeight ) { m_iVSOWeight = iVSOWeight; };
444  Int     getVSOWeight ()                 { return m_iVSOWeight; };
445  Void    setVSDWeight ( Int iVSDWeight ) { m_iVSDWeight = iVSDWeight; };
446  Int     getVSDWeight ()                 { return m_iVSDWeight; };
447#endif
448#if HHI_VSO_DIST_INT
449  Void    setAllowNegDist ( Bool bAllowNegDist );
450#endif
451
452
453  Double  getSqrtLambdaVSO ()   { return m_dSqrtLambdaVSO; }
454  Double  getLambdaVSO ()       { return m_dLambdaVSO; }
455
456  Dist    getDistVS( TComDataCU* pcCU, UInt uiAbsPartIndex, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD, UInt uiPlane );
457  Double calcRdCostVSO( UInt   uiBits, Dist   uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
458
459private:
460  Dist xGetDistVSOMode4( Int iStartPosX, Int iStartPosY, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bSAD );
461
462#endif // HHI_VSO
463
464};// END CLASS DEFINITION TComRdCost
465
466//! \}
467
468#endif // __TCOMRDCOST__
Note: See TracBrowser for help on using the repository browser.