/src/vvenc/source/Lib/EncoderLib/EncSampleAdaptiveOffset.h
Line | Count | Source |
1 | | /* ----------------------------------------------------------------------------- |
2 | | The copyright in this software is being made available under the Clear BSD |
3 | | License, included below. No patent rights, trademark rights and/or |
4 | | other Intellectual Property Rights other than the copyrights concerning |
5 | | the Software are granted under this license. |
6 | | |
7 | | The Clear BSD License |
8 | | |
9 | | Copyright (c) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors. |
10 | | All rights reserved. |
11 | | |
12 | | Redistribution and use in source and binary forms, with or without modification, |
13 | | are permitted (subject to the limitations in the disclaimer below) provided that |
14 | | the following conditions are met: |
15 | | |
16 | | * Redistributions of source code must retain the above copyright notice, |
17 | | this list of conditions and the following disclaimer. |
18 | | |
19 | | * Redistributions in binary form must reproduce the above copyright |
20 | | notice, this list of conditions and the following disclaimer in the |
21 | | documentation and/or other materials provided with the distribution. |
22 | | |
23 | | * Neither the name of the copyright holder nor the names of its |
24 | | contributors may be used to endorse or promote products derived from this |
25 | | software without specific prior written permission. |
26 | | |
27 | | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY |
28 | | THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
29 | | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
30 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
31 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
32 | | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
33 | | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
34 | | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
35 | | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
36 | | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
37 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
38 | | POSSIBILITY OF SUCH DAMAGE. |
39 | | |
40 | | |
41 | | ------------------------------------------------------------------------------------------- */ |
42 | | /** |
43 | | \file EncSampleAdaptiveOffset.h |
44 | | \brief estimation part of sample adaptive offset class (header) |
45 | | */ |
46 | | |
47 | | #pragma once |
48 | | |
49 | | #include "CABACWriter.h" |
50 | | #include "CommonLib/SampleAdaptiveOffset.h" |
51 | | |
52 | | //! \ingroup EncoderLib |
53 | | //! \{ |
54 | | |
55 | | namespace vvenc { |
56 | | |
57 | | // ==================================================================================================================== |
58 | | // Class definition |
59 | | // ==================================================================================================================== |
60 | | |
61 | | struct SAOStatData //data structure for SAO statistics |
62 | | { |
63 | | int64_t diff[MAX_NUM_SAO_CLASSES]; |
64 | | int64_t count[MAX_NUM_SAO_CLASSES]; |
65 | | |
66 | 0 | SAOStatData(){} |
67 | 0 | ~SAOStatData(){} |
68 | | void reset() |
69 | 0 | { |
70 | 0 | ::memset(diff, 0, sizeof(int64_t)*MAX_NUM_SAO_CLASSES); |
71 | 0 | ::memset(count, 0, sizeof(int64_t)*MAX_NUM_SAO_CLASSES); |
72 | 0 | } |
73 | | const SAOStatData& operator=(const SAOStatData& src) |
74 | 0 | { |
75 | 0 | ::memcpy(diff, src.diff, sizeof(int64_t)*MAX_NUM_SAO_CLASSES); |
76 | 0 | ::memcpy(count, src.count, sizeof(int64_t)*MAX_NUM_SAO_CLASSES); |
77 | 0 | return *this; |
78 | 0 | } |
79 | | const SAOStatData& operator+= (const SAOStatData& src) |
80 | 0 | { |
81 | 0 | for(int i=0; i< MAX_NUM_SAO_CLASSES; i++) |
82 | 0 | { |
83 | 0 | diff[i] += src.diff[i]; |
84 | 0 | count[i] += src.count[i]; |
85 | 0 | } |
86 | 0 | return *this; |
87 | 0 | } |
88 | | }; |
89 | | |
90 | | class EncSampleAdaptiveOffset : public SampleAdaptiveOffset |
91 | | { |
92 | | public: |
93 | | EncSampleAdaptiveOffset(); |
94 | | virtual ~EncSampleAdaptiveOffset(); |
95 | | |
96 | | //interface |
97 | | void init ( const VVEncCfg& encCfg ); |
98 | | void initSlice ( const Slice* slice ); |
99 | | void setCtuEncRsrc ( CABACWriter* cabacEstimator, CtxCache* ctxCache ); |
100 | | |
101 | | static void disabledRate ( CodingStructure& cs, double saoDisabledRate[ MAX_NUM_COMP ][ VVENC_MAX_TLAYER ], SAOBlkParam* reconParams, const double saoEncodingRate, const double saoEncodingRateChroma, const ChromaFormat& chromaFormat ); |
102 | | static void decidePicParams( const CodingStructure& cs, double saoDisabledRate[ MAX_NUM_COMP ][ VVENC_MAX_TLAYER ], bool saoEnabled[ MAX_NUM_COMP ], const double saoEncodingRate, const double saoEncodingRateChroma, const ChromaFormat& chromaFormat ); |
103 | | |
104 | | void storeCtuReco ( CodingStructure& cs, const UnitArea& ctuArea, const int ctuX, const int ctuY ); |
105 | | void getCtuStatistics ( CodingStructure& cs, std::vector<SAOStatData**>& saoStatistics, const UnitArea& ctuArea, const int ctuRsAddr ); |
106 | | void decideCtuParams ( CodingStructure& cs, const std::vector<SAOStatData**>& saoStatistics, const bool saoEnabled[ MAX_NUM_COMP ], const bool allBlksDisabled, const UnitArea& ctuArea, const int ctuRsAddr, SAOBlkParam* reconParams, SAOBlkParam* codedParams ); |
107 | | |
108 | | private: |
109 | | void getStatistics (std::vector<SAOStatData**>& blkStats, PelUnitBuf& orgYuv, PelUnitBuf& srcYuv, CodingStructure& cs); |
110 | | void getBlkStats (const ComponentID compIdx, const int channelBitDepth, 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 ); |
111 | | void deriveModeNewRDO (const BitDepths &bitDepths, int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES], const bool* sliceEnabled, const std::vector<SAOStatData**>& blkStats, SAOBlkParam& modeParam, double& modeNormCost ); |
112 | | void deriveModeMergeRDO (const BitDepths &bitDepths, int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES], const bool* sliceEnabled, const std::vector<SAOStatData**>& blkStats, SAOBlkParam& modeParam, double& modeNormCost ); |
113 | | int64_t getDistortion (const int channelBitDepth, int typeIdc, int typeAuxInfo, int* offsetVal, SAOStatData& statData); |
114 | | void deriveOffsets (ComponentID compIdx, const int channelBitDepth, int typeIdc, SAOStatData& statData, int* quantOffsets, int& typeAuxInfo); |
115 | | void deriveLoopFilterBoundaryAvailibility(CodingStructure& cs, const Position& pos, bool& isLeftAvail, bool& isAboveAvail, bool& isAboveLeftAvail) const; |
116 | | inline int64_t estSaoDist (int64_t count, int64_t offset, int64_t diffSum, int shift); |
117 | | inline int estIterOffset (int typeIdx, double lambda, int offsetInput, int64_t count, int64_t diffSum, int shift, int bitIncrease, int64_t& bestDist, double& bestCost, int offsetTh ); |
118 | | |
119 | | private: |
120 | | |
121 | | const VVEncCfg* m_EncCfg; |
122 | | |
123 | | //for RDO |
124 | | CABACWriter* m_CABACEstimator; |
125 | | CtxCache* m_CtxCache; |
126 | | double m_lambda[ MAX_NUM_COMP ]; |
127 | | }; |
128 | | |
129 | | } // namespace vvenc |
130 | | |
131 | | //! \} |
132 | | |