/src/vvenc/source/Lib/CommonLib/SampleAdaptiveOffset.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 | | /** \file SampleAdaptiveOffset.h |
43 | | \brief sample adaptive offset class (header) |
44 | | */ |
45 | | |
46 | | #pragma once |
47 | | |
48 | | #include "CommonDef.h" |
49 | | #include "Unit.h" |
50 | | |
51 | | //! \ingroup CommonLib |
52 | | //! \{ |
53 | | |
54 | | namespace vvenc { |
55 | | |
56 | | #if defined(TARGET_SIMD_X86) && ENABLE_SIMD_OPT_SAO |
57 | | using namespace x86_simd; |
58 | | #endif |
59 | | |
60 | | template<typename T> static inline int sgn( T val ) |
61 | 0 | { |
62 | 0 | return ( T( 0 ) < val ) - ( val < T( 0 ) ); |
63 | 0 | } Unexecuted instantiation: SampleAdaptiveOffset_sse41.cpp:int vvenc::sgn<int>(int) Unexecuted instantiation: SampleAdaptiveOffset_avx2.cpp:int vvenc::sgn<int>(int) Unexecuted instantiation: SampleAdaptiveOffset.cpp:int vvenc::sgn<int>(int) Unexecuted instantiation: EncSampleAdaptiveOffset.cpp:int vvenc::sgn<int>(int) |
64 | | |
65 | | // ==================================================================================================================== |
66 | | // Constants |
67 | | // ==================================================================================================================== |
68 | | |
69 | 0 | #define MAX_SAO_TRUNCATED_BITDEPTH 10 |
70 | | |
71 | | // ==================================================================================================================== |
72 | | // Class definition |
73 | | // ==================================================================================================================== |
74 | | |
75 | | enum Available |
76 | | { |
77 | | LeftAvail = 1, |
78 | | RightAvail = 2, |
79 | | AboveAvail = 4, |
80 | | BelowAvail = 8, |
81 | | AboveLeftAvail = 16, |
82 | | AboveRightAvail = 32, |
83 | | BelowLeftAvail = 64, |
84 | | BelowRightAvail = 128, |
85 | | }; |
86 | | |
87 | | class SampleAdaptiveOffset |
88 | | { |
89 | | public: |
90 | | SampleAdaptiveOffset( bool enableOpt = true ); |
91 | | virtual ~SampleAdaptiveOffset(); |
92 | | void init ( ChromaFormat format, uint32_t maxCUWidth, uint32_t maxCUHeight, uint32_t lumaBitShift, uint32_t chromaBitShift ); |
93 | 0 | static int getMaxOffsetQVal( const int channelBitDepth) { return (1<<(std::min<int>(channelBitDepth,MAX_SAO_TRUNCATED_BITDEPTH)-5))-1; } //Table 9-32, inclusive |
94 | | |
95 | | void ( *calcSaoStatisticsBo )( int width, int endX, int endY, Pel* srcLine, Pel* orgLine, int srcStride, |
96 | | int orgStride, int channelBitDepth, int64_t* count, int64_t* diff ); |
97 | | |
98 | | protected: |
99 | | void deriveLoopFilterBoundaryAvailibility( CodingStructure& cs, const Position& pos, uint8_t& availMask ) const; |
100 | | |
101 | | void (*offsetBlock) ( const int channelBitDepth, |
102 | | const ClpRng& clpRng, |
103 | | int typeIdx, |
104 | | int* offset, |
105 | | int startIdx, |
106 | | const Pel* srcBlk, |
107 | | Pel* resBlk, |
108 | | ptrdiff_t srcStride, |
109 | | ptrdiff_t resStride, |
110 | | int width, |
111 | | int height, |
112 | | uint8_t availMask, |
113 | | std::vector<int8_t> &signLineBuf1, |
114 | | std::vector<int8_t> &signLineBuf2); |
115 | | |
116 | | |
117 | | void (*calcSaoStatisticsEo0) (int width,int startX,int endX,int endY,Pel* srcLine,Pel* orgLine,int srcStride,int orgStride, int64_t *count,int64_t *diff); |
118 | | void (*calcSaoStatisticsEo90) (int width,int endX,int startY,int endY,Pel* srcLine,Pel* orgLine,int srcStride,int orgStride,int64_t *count, int64_t *diff,int8_t *signUpLine); |
119 | | void (*calcSaoStatisticsEo135) (int width,int startX,int endX,int endY,Pel* srcLine,Pel* orgLine,int srcStride,int orgStride,int64_t *count, int64_t *diff,int8_t *signUpLine,int8_t *signDownLine); |
120 | | void (*calcSaoStatisticsEo45) (int width,int startX,int endX,int endY,Pel* srcLine,Pel* orgLine,int srcStride,int orgStride,int64_t *count, int64_t *diff,int8_t *signUpLine); |
121 | | |
122 | | void invertQuantOffsets (ComponentID compIdx, int typeIdc, int typeAuxInfo, int* dstOffsets, int* srcOffsets); |
123 | | void reconstructBlkSAOParam (SAOBlkParam& recParam, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES]); |
124 | | int getMergeList (CodingStructure& cs, int ctuRsAddr, SAOBlkParam* blkParams, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES]); |
125 | | void offsetCTU (const UnitArea& area, const CPelUnitBuf& src, PelUnitBuf& res, SAOBlkParam& saoblkParam, CodingStructure& cs); |
126 | | void xReconstructBlkSAOParams (CodingStructure& cs, SAOBlkParam* saoBlkParams); |
127 | | |
128 | | #if defined(TARGET_SIMD_X86) && ENABLE_SIMD_OPT_SAO |
129 | | void initSampleAdaptiveOffsetX86(); |
130 | | template <X86_VEXT vext> |
131 | | void _initSampleAdaptiveOffsetX86(); |
132 | | #endif |
133 | | #if defined( TARGET_SIMD_ARM ) && ENABLE_SIMD_OPT_SAO |
134 | | void initSampleAdaptiveOffsetARM(); |
135 | | template<ARM_VEXT vext> |
136 | | void _initSampleAdaptiveOffsetARM(); |
137 | | #endif |
138 | | |
139 | | protected: |
140 | | uint32_t m_offsetStepLog2[MAX_NUM_COMP]; //offset step |
141 | | uint32_t m_numberOfComponents; |
142 | | |
143 | | std::vector<int8_t> m_signLineBuf1; |
144 | | std::vector<int8_t> m_signLineBuf2; |
145 | | |
146 | | private: |
147 | | bool m_picSAOEnabled[MAX_NUM_COMP]; |
148 | | }; |
149 | | |
150 | | } // namespace vvenc |
151 | | |
152 | | //! \} |
153 | | |