HEVC Test Model (HM)  HM-16.3
TEncSampleAdaptiveOffset.h
Go to the documentation of this file.
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-2015, 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 
39 #ifndef __TENCSAMPLEADAPTIVEOFFSET__
40 #define __TENCSAMPLEADAPTIVEOFFSET__
41 
43 #include "TLibCommon/TComPic.h"
44 
45 #include "TEncEntropy.h"
46 #include "TEncSbac.h"
48 
51 
52 // ====================================================================================================================
53 // Class definition
54 // ====================================================================================================================
55 
56 enum SAOCabacStateLablesRDO //CABAC state labels
57 {
64 };
65 
66 struct SAOStatData //data structure for SAO statistics
67 {
70 
74  {
75  ::memset(diff, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
76  ::memset(count, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
77  }
78  const SAOStatData& operator=(const SAOStatData& src)
79  {
80  ::memcpy(diff, src.diff, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
81  ::memcpy(count, src.count, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
82  return *this;
83  }
84 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
85  const SAOStatData& operator+= (const SAOStatData& src)
86  {
87  for(Int i=0; i< MAX_NUM_SAO_CLASSES; i++)
88  {
89  diff[i] += src.diff[i];
90  count[i] += src.count[i];
91  }
92  return *this;
93  }
94 #endif
95 };
96 
98 {
99 public:
101  virtual ~TEncSampleAdaptiveOffset();
102 
103  //interface
104 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
105  Void createEncData(Bool isPreDBFSamplesUsed);
106 #else
108 #endif
110  Void initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) ;
111  Void SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas
113  , Bool isPreDBFSamplesUsed
114 #endif
115  );
116 public: //methods
117 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
119 #endif
120 private: //methods
121  Void getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv,TComPic* pPic
122 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
123  , Bool isCalculatePreDeblockSamples = false
124 #endif
125  );
126  Void decidePicParams(Bool* sliceEnabled, Int picTempLayer);
127  Void decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams);
128  Void getBlkStats(ComponentID compIdx, SAOStatData* statsDataTypes, Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height, Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail
129 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
130  , Bool isCalculatePreDeblockSamples
131 #endif
132  );
133  Void deriveModeNewRDO(Int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES], Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel);
134  Void deriveModeMergeRDO(Int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES], Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel);
135  Int64 getDistortion(ComponentID compIdx, Int typeIdc, Int typeAuxInfo, Int* offsetVal, SAOStatData& statData);
136  Void deriveOffsets(ComponentID compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo);
137  inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift);
138  inline Int estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64& bestDist, Double& bestCost, Int offsetTh );
139 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
140  Void addPreDBFStatistics(SAOStatData*** blkStats);
141 #endif
142 private: //members
143  //for RDO
146 #if FAST_BIT_EST
148 #else
150 #endif
152 
153  //statistics
154  SAOStatData*** m_statData; //[ctu][comp][classes]
155 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
157 #endif
158 #if SAO_ENCODING_CHOICE
160 #endif
163 };
164 
165 
167 
168 #endif
const SAOStatData & operator+=(const SAOStatData &src)
entropy encoder class (header)
sample adaptive offset class (header)
Int64 estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift)
Void deriveOffsets(ComponentID compIdx, Int typeIdc, SAOStatData &statData, Int *quantOffsets, Int &typeAuxInfo)
Void addPreDBFStatistics(SAOStatData ***blkStats)
#define MAX_NUM_SAO_CLASSES
Definition: TypeDef.h:709
Int estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64 &bestDist, Double &bestCost, Int offsetTh)
picture YUV buffer class
Definition: TComPicYuv.h:55
picture class (symbol + YUV buffers)
Definition: TComPic.h:56
Void decidePicParams(Bool *sliceEnabled, Int picTempLayer)
void Void
Definition: TypeDef.h:285
Void deriveModeMergeRDO(Int ctuRsAddr, SAOBlkParam *mergeList[NUM_SAO_MERGE_TYPES], Bool *sliceEnabled, SAOStatData ***blkStats, SAOBlkParam &modeParam, Double &modeNormCost, TEncSbac **cabacCoderRDO, Int inCabacLabel)
#define MAX_TLAYER
max number of temporal layer
Definition: CommonDef.h:192
Short Pel
pixel type
Definition: TypeDef.h:692
picture class (header)
Void initRDOCabacCoder(TEncSbac *pcRDGoOnSbacCoder, TComSlice *pcSlice)
const SAOStatData & operator=(const SAOStatData &src)
Int64 getDistortion(ComponentID compIdx, Int typeIdc, Int typeAuxInfo, Int *offsetVal, SAOStatData &statData)
Void getBlkStats(ComponentID compIdx, SAOStatData *statsDataTypes, Pel *srcBlk, Pel *orgBlk, Int srcStride, Int orgStride, Int width, Int height, Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail, Bool isCalculatePreDeblockSamples)
Double m_lambda[MAX_NUM_COMPONENT]
bool Bool
Definition: TypeDef.h:286
long long Int64
Definition: TypeDef.h:317
TEncBinCABACCounter ** m_pppcBinCoderCABAC
Void deriveModeNewRDO(Int ctuRsAddr, SAOBlkParam *mergeList[NUM_SAO_MERGE_TYPES], Bool *sliceEnabled, SAOStatData ***blkStats, SAOBlkParam &modeParam, Double &modeNormCost, TEncSbac **cabacCoderRDO, Int inCabacLabel)
Void getStatistics(SAOStatData ***blkStats, TComPicYuv *orgYuv, TComPicYuv *srcYuv, TComPic *pPic, Bool isCalculatePreDeblockSamples=false)
SAOCabacStateLablesRDO
Void SAOProcess(TComPic *pPic, Bool *sliceEnabled, const Double *lambdas, Bool isPreDBFSamplesUsed)
Context-adaptive entropy encoder class (header)
Int m_skipLinesR[MAX_NUM_COMPONENT][NUM_SAO_NEW_TYPES]
int Int
Definition: TypeDef.h:296
ComponentID
Definition: TypeDef.h:368
Int m_skipLinesB[MAX_NUM_COMPONENT][NUM_SAO_NEW_TYPES]
Double m_saoDisabledRate[MAX_NUM_COMPONENT][7]
SBAC encoder class.
Definition: TEncSbac.h:66
double Double
Definition: TypeDef.h:298
Void decideBlkParams(TComPic *pic, Bool *sliceEnabled, SAOStatData ***blkStats, TComPicYuv *srcYuv, TComPicYuv *resYuv, SAOBlkParam *reconParams, SAOBlkParam *codedParams)
Void createEncData(Bool isPreDBFSamplesUsed)
slice header class
Definition: TComSlice.h:1198
Class for counting bits (header)
#define SAO_ENCODE_ALLOW_USE_PREDEBLOCK
Definition: TypeDef.h:90