/work/vvdec/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) 2018-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVdeC 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 SampleAdaptiveOffset.h |
44 | | \brief sample adaptive offset class (header) |
45 | | */ |
46 | | |
47 | | #pragma once |
48 | | |
49 | | #include "CommonDef.h" |
50 | | #include "Unit.h" |
51 | | #include "Reshape.h" |
52 | | |
53 | | #include <array> |
54 | | |
55 | | namespace vvdec |
56 | | { |
57 | | |
58 | | # define SAO_NUM_OFFSETS 4 /* number of SAO offset values */ |
59 | | # define SAO_EO_NUM_CATEGORIES ( SAO_NUM_OFFSETS + 1 ) /* number of different eo categories */ |
60 | | |
61 | | template<typename T> static inline int sgn( T val ) |
62 | 0 | { |
63 | 0 | return ( T( 0 ) < val ) - ( val < T( 0 ) ); |
64 | 0 | } |
65 | | |
66 | | // ==================================================================================================================== |
67 | | // Constants |
68 | | // ==================================================================================================================== |
69 | | |
70 | 0 | #define MAX_SAO_TRUNCATED_BITDEPTH 10 |
71 | | |
72 | | // ==================================================================================================================== |
73 | | // Class definition |
74 | | // ==================================================================================================================== |
75 | | |
76 | | class SampleAdaptiveOffset |
77 | | { |
78 | | public: |
79 | | SampleAdaptiveOffset( bool enableOpt = true ); |
80 | | ~SampleAdaptiveOffset(); |
81 | | |
82 | | void create( int picWidth, int picHeight, ChromaFormat format, uint32_t maxCUWidth, uint32_t maxCUHeight, uint32_t maxCUDepth, uint32_t bitShift, PelUnitBuf& unitBuf ); |
83 | | void destroy(); |
84 | | |
85 | | // void SAOProcess( CodingStructure& cs ); |
86 | | void SAOProcessCTU ( CodingStructure& cs, const UnitArea& ctuArea ); |
87 | | void SAOProcessCTULine( CodingStructure& cs, const UnitArea& lineArea ); |
88 | | void SAOPrepareCTULine( CodingStructure& cs, const UnitArea& lineArea ); |
89 | | |
90 | 0 | static int getMaxOffsetQVal( const int channelBitDepth ) { return ( 1 << ( std::min<int>( channelBitDepth, MAX_SAO_TRUNCATED_BITDEPTH ) - 5 ) ) - 1; } // Table 9-32, inclusive |
91 | 0 | void setReshaper(Reshape * p) { m_pcReshape = p; } |
92 | | |
93 | | static void offsetBlock_core( const int channelBitDepth, |
94 | | const ClpRng& clpRng, |
95 | | int typeIdx, |
96 | | int* offset, |
97 | | int startIdx, |
98 | | const Pel* srcBlk, |
99 | | Pel* resBlk, |
100 | | ptrdiff_t srcStride, |
101 | | ptrdiff_t resStride, |
102 | | int width, |
103 | | int height, |
104 | | bool isLeftAvail, |
105 | | bool isRightAvail, |
106 | | bool isAboveAvail, |
107 | | bool isBelowAvail, |
108 | | bool isAboveLeftAvail, |
109 | | bool isAboveRightAvail, |
110 | | bool isBelowLeftAvail, |
111 | | bool isBelowRightAvail, |
112 | | std::vector<int8_t>* m_signLineBuf1, |
113 | | std::vector<int8_t>* m_signLineBuf2, |
114 | | bool isCtuCrossedByVirtualBoundaries, |
115 | | int horVirBndryPos[], |
116 | | int verVirBndryPos[], |
117 | | int numHorVirBndry, |
118 | | int numVerVirBndry ); |
119 | | |
120 | | void ( *offsetBlock )( const int channelBitDepth, |
121 | | const ClpRng& clpRng, |
122 | | int typeIdx, |
123 | | int* offset, |
124 | | int startIdx, |
125 | | const Pel* srcBlk, |
126 | | Pel* resBlk, |
127 | | ptrdiff_t srcStride, |
128 | | ptrdiff_t resStride, |
129 | | int width, |
130 | | int height, |
131 | | bool isLeftAvail, |
132 | | bool isRightAvail, |
133 | | bool isAboveAvail, |
134 | | bool isBelowAvail, |
135 | | bool isAboveLeftAvail, |
136 | | bool isAboveRightAvail, |
137 | | bool isBelowLeftAvail, |
138 | | bool isBelowRightAvail, |
139 | | std::vector<int8_t>* m_signLineBuf1, |
140 | | std::vector<int8_t>* m_signLineBuf2, |
141 | | bool isCtuCrossedByVirtualBoundaries, |
142 | | int horVirBndryPos[], |
143 | | int verVirBndryPos[], |
144 | | int numHorVirBndry, |
145 | | int numVerVirBndry ); |
146 | | |
147 | | protected: |
148 | | void deriveLoopFilterBoundaryAvailibility( CodingStructure& cs, |
149 | | const Position& pos, |
150 | | bool& isLeftAvail, |
151 | | bool& isRightAvail, |
152 | | bool& isAboveAvail, |
153 | | bool& isBelowAvail, |
154 | | bool& isAboveLeftAvail, |
155 | | bool& isAboveRightAvail, |
156 | | bool& isBelowLeftAvail, |
157 | | bool& isBelowRightAvail ) const; |
158 | | |
159 | | void invertQuantOffsets ( ComponentID compIdx, int typeIdc, int typeAuxInfo, int* dstOffsets, int* srcOffsets ) const; |
160 | | void reconstructBlkSAOParam ( SAOBlkParam& recParam, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES] ) const; |
161 | | int getMergeList ( CodingStructure& cs, int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES] ); |
162 | | void offsetCTU ( const UnitArea& area, const CPelUnitBuf& src, PelUnitBuf& res, SAOBlkParam& saoblkParam, CodingStructure& cs, std::vector<int8_t> &signLineBuf1, std::vector<int8_t> &signLineBuf2 ); |
163 | | |
164 | | static bool isProcessDisabled( int xPos, int yPos, int numVerVirBndry, int numHorVirBndry, int verVirBndryPos[], int horVirBndryPos[] ); |
165 | | Reshape* m_pcReshape; |
166 | | |
167 | | |
168 | | #if defined(TARGET_SIMD_X86) && ENABLE_SIMD_OPT_SAO |
169 | | void initSampleAdaptiveOffsetX86(); |
170 | | template <X86_VEXT vext> |
171 | | void _initSampleAdaptiveOffsetX86(); |
172 | | #endif |
173 | | |
174 | | #if defined( TARGET_SIMD_ARM ) && ENABLE_SIMD_OPT_SAO |
175 | | void initSampleAdaptiveOffsetARM(); |
176 | | template<ARM_VEXT vext> |
177 | | void _initSampleAdaptiveOffsetARM(); |
178 | | #endif |
179 | | |
180 | | protected: |
181 | | uint32_t m_offsetStepLog2; // offset step |
182 | | uint32_t m_numberOfComponents; |
183 | | PelUnitBuf m_tempBuf; |
184 | | }; |
185 | | |
186 | | } |