source: SHVCSoftware/branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h @ 1263

Last change on this file since 1263 was 532, checked in by seregin, 11 years ago

update to HM-12.1 base

  • Property svn:eol-style set to native
File size: 10.5 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/**
35 \file     TEncSampleAdaptiveOffset.h
36 \brief    estimation part of sample adaptive offset class (header)
37 */
38
39#ifndef __TENCSAMPLEADAPTIVEOFFSET__
40#define __TENCSAMPLEADAPTIVEOFFSET__
41
42#include "TLibCommon/TComSampleAdaptiveOffset.h"
43#include "TLibCommon/TComPic.h"
44
45#include "TEncEntropy.h"
46#include "TEncSbac.h"
47#include "TLibCommon/TComBitCounter.h"
48
49//! \ingroup TLibEncoder
50//! \{
51
52// ====================================================================================================================
53// Class definition
54// ====================================================================================================================
55
56#if HM_CLEANUP_SAO
57enum SAOCabacStateLablesRDO //CABAC state labels
58{
59  SAO_CABACSTATE_PIC_INIT =0,
60  SAO_CABACSTATE_BLK_CUR,
61  SAO_CABACSTATE_BLK_NEXT,
62  SAO_CABACSTATE_BLK_MID,
63  SAO_CABACSTATE_BLK_TEMP,
64  NUM_SAO_CABACSTATE_LABELS
65};
66
67struct SAOStatData //data structure for SAO statistics
68{
69  Int64 diff[MAX_NUM_SAO_CLASSES];
70  Int64 count[MAX_NUM_SAO_CLASSES];
71
72  SAOStatData(){}
73  ~SAOStatData(){}
74  Void reset()
75  {
76    ::memset(diff, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
77    ::memset(count, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
78  }
79  const SAOStatData& operator=(const SAOStatData& src)
80  {
81    ::memcpy(diff, src.diff, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
82    ::memcpy(count, src.count, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
83    return *this;
84  }
85#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
86  const SAOStatData& operator+= (const SAOStatData& src)
87  {
88    for(Int i=0; i< MAX_NUM_SAO_CLASSES; i++)
89    {
90      diff[i] += src.diff[i];
91      count[i] += src.count[i];
92    }
93    return *this;
94  }
95#endif
96};
97
98class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset
99{
100public:
101  TEncSampleAdaptiveOffset();
102  virtual ~TEncSampleAdaptiveOffset();
103
104  //interface
105#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
106  Void createEncData(Bool isPreDBFSamplesUsed);
107#else
108  Void createEncData();
109#endif
110  Void destroyEncData();
111  Void initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) ;
112  Void SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas
113#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
114                , Bool isPreDBFSamplesUsed
115#endif
116                ); 
117public: //methods
118#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
119  Void getPreDBFStatistics(TComPic* pPic); 
120#endif
121private: //methods
122  Void getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv,TComPic* pPic
123#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
124                   , Bool isCalculatePreDeblockSamples = false
125#endif
126                   );
127  Void decidePicParams(Bool* sliceEnabled, Int picTempLayer);
128  Void decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams);
129  Void getBlkStats(Int 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
130#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
131                  , Bool isCalculatePreDeblockSamples
132#endif
133                  );
134  Void deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel);
135  Void deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel);
136  Int64 getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* offsetVal, SAOStatData& statData);
137  Void deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo);
138  inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift);
139  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 );
140#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
141  Void addPreDBFStatistics(SAOStatData*** blkStats);
142#endif
143private: //members
144  //for RDO
145  TEncSbac**             m_pppcRDSbacCoder;           
146  TEncSbac*              m_pcRDGoOnSbacCoder;
147  TEncBinCABACCounter**  m_pppcBinCoderCABAC;   
148  Double                 m_labmda[NUM_SAO_COMPONENTS];
149
150  //statistics
151  SAOStatData***         m_statData; //[ctu][comp][classes]
152#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
153  SAOStatData***         m_preDBFstatData;
154#endif
155#if SAO_ENCODING_CHOICE
156  Double                 m_saoDisabledRate[NUM_SAO_COMPONENTS][MAX_TLAYER];
157#endif
158  Int                    m_skipLinesR[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES];
159  Int                    m_skipLinesB[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES];
160};
161#else
162
163
164class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset
165{
166private:
167  TEncEntropy*      m_pcEntropyCoder;
168  TEncSbac***       m_pppcRDSbacCoder;              ///< for CABAC
169  TEncSbac*         m_pcRDGoOnSbacCoder;
170#if FAST_BIT_EST
171  TEncBinCABACCounter*** m_pppcBinCoderCABAC;            ///< temporal CABAC state storage for RD computation
172#else
173  TEncBinCABAC***   m_pppcBinCoderCABAC;            ///< temporal CABAC state storage for RD computation
174#endif
175 
176  Int64  ***m_iCount;      //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
177  Int64  ***m_iOffset;     //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
178  Int64  ***m_iOffsetOrg;  //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
179  Int64  ****m_count_PreDblk;      //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
180  Int64  ****m_offsetOrg_PreDblk;  //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
181  Int64  **m_iRate;        //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
182  Int64  **m_iDist;        //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
183  Double **m_dCost;        //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
184  Double *m_dCostPartBest; //[MAX_NUM_SAO_PART];
185  Int64  *m_iDistOrg;      //[MAX_NUM_SAO_PART];
186  Int    *m_iTypePartBest; //[MAX_NUM_SAO_PART];
187  Int     m_iOffsetThY;
188  Int     m_iOffsetThC;
189  Bool    m_bUseSBACRD;
190#if SAO_ENCODING_CHOICE
191#if SAO_ENCODING_CHOICE_CHROMA
192  Double  m_depthSaoRate[2][4];
193#else
194  Double  m_depth0SaoRate;
195#endif
196#endif
197
198public:
199  TEncSampleAdaptiveOffset         ();
200  virtual ~TEncSampleAdaptiveOffset();
201
202  Void startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder);
203  Void endSaoEnc();
204  Void resetStats();
205#if SAO_ENCODING_CHOICE
206  Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma, Int depth);
207#else
208  Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma);
209#endif
210
211  Void runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr);
212  Void rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr);
213 
214  Void disablePartTree(SAOQTPart *psQTPart, Int iPartIdx);
215  Void getSaoStats(SAOQTPart *psQTPart, Int iYCbCr);
216  Void calcSaoStatsCu(Int iAddr, Int iPartIdx, Int iYCbCr);
217  Void calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr);
218  Void calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr);
219  Void calcSaoStatsCu_BeforeDblk( TComPic* pcPic );
220  Void destroyEncBuffer();
221  Void createEncBuffer();
222  Void assignSaoUnitSyntax(SaoLcuParam* saoLcuParam,  SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr);
223  Void checkMerge(SaoLcuParam * lcuParamCurr,SaoLcuParam * lcuParamCheck, Int dir);
224#if SAO_ENCODING_CHOICE
225  Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth);
226#else
227  Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma);
228#endif
229  Void saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *distortion);
230  Void sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion);
231  inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift);
232  inline Int64 estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int64 offsetInput, Int64 count, Int64 offsetOrg, Int shift, Int bitIncrease, Int *currentDistortionTableBo, Double *currentRdCostTableBo, Int offsetTh );
233  inline Int64 estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo);
234  Void setMaxNumOffsetsPerPic(Int iVal) {m_maxNumOffsetsPerPic = iVal; }
235  Int  getMaxNumOffsetsPerPic() {return m_maxNumOffsetsPerPic; }
236};
237#endif
238//! \}
239
240#endif
Note: See TracBrowser for help on using the repository browser.