/src/vvenc/source/Lib/CommonLib/AlfParameters.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 AlfParameters.h |
43 | | \brief Define types for storing ALF parameters |
44 | | */ |
45 | | |
46 | | #pragma once |
47 | | |
48 | | #include <vector> |
49 | | #include "CommonDef.h" |
50 | | |
51 | | //! \ingroup CommonLib |
52 | | //! \{ |
53 | | |
54 | | namespace vvenc { |
55 | | |
56 | | enum AlfFilterType |
57 | | { |
58 | | ALF_FILTER_5, |
59 | | ALF_FILTER_7, |
60 | | CC_ALF, |
61 | | ALF_NUM_OF_FILTER_TYPES |
62 | | }; |
63 | | |
64 | | static const int size_CC_ALF = -1; |
65 | | |
66 | | struct AlfFilterShape |
67 | | { |
68 | | AlfFilterShape( int size ) |
69 | 0 | : filterLength( size ), |
70 | 0 | numCoeff( size * size / 4 + 1 ), |
71 | 0 | filterSize( size * size / 2 + 1 ) |
72 | 0 | { |
73 | 0 | if( size == 5 ) |
74 | 0 | { |
75 | 0 | pattern = { |
76 | 0 | 0, |
77 | 0 | 1, 2, 3, |
78 | 0 | 4, 5, 6, 5, 4, |
79 | 0 | 3, 2, 1, |
80 | 0 | 0 |
81 | 0 | }; |
82 | |
|
83 | 0 | weights = { |
84 | 0 | 2, |
85 | 0 | 2, 2, 2, |
86 | 0 | 2, 2, 1, 1 |
87 | 0 | }; |
88 | |
|
89 | 0 | filterType = ALF_FILTER_5; |
90 | 0 | } |
91 | 0 | else if( size == 7 ) |
92 | 0 | { |
93 | 0 | pattern = { |
94 | 0 | 0, |
95 | 0 | 1, 2, 3, |
96 | 0 | 4, 5, 6, 7, 8, |
97 | 0 | 9, 10, 11, 12, 11, 10, 9, |
98 | 0 | 8, 7, 6, 5, 4, |
99 | 0 | 3, 2, 1, |
100 | 0 | 0 |
101 | 0 | }; |
102 | |
|
103 | 0 | weights = { |
104 | 0 | 2, |
105 | 0 | 2, 2, 2, |
106 | 0 | 2, 2, 2, 2, 2, |
107 | 0 | 2, 2, 2, 1, 1 |
108 | 0 | }; |
109 | |
|
110 | 0 | filterType = ALF_FILTER_7; |
111 | 0 | } |
112 | 0 | else if (size == size_CC_ALF) |
113 | 0 | { |
114 | 0 | size = 4; |
115 | 0 | filterLength = 8; |
116 | 0 | numCoeff = 8; |
117 | 0 | filterSize = 8; |
118 | 0 | filterType = CC_ALF; |
119 | 0 | } |
120 | 0 | else |
121 | 0 | { |
122 | 0 | filterType = ALF_NUM_OF_FILTER_TYPES; |
123 | 0 | CHECK( 0, "Wrong ALF filter shape" ); |
124 | 0 | } |
125 | 0 | } |
126 | | |
127 | | AlfFilterType filterType; |
128 | | int filterLength; |
129 | | int numCoeff; //TO DO: check whether we need both numCoeff and filterSize |
130 | | int filterSize; |
131 | | std::vector<int> pattern; |
132 | | std::vector<int> weights; |
133 | | }; |
134 | | |
135 | | struct AlfParam |
136 | | { |
137 | | bool alfEnabled[MAX_NUM_COMP]; // alf_slice_enable_flag, alf_chroma_idc |
138 | | bool nonLinearFlag[MAX_NUM_CH]; // alf_[luma/chroma]_clip_flag |
139 | | short lumaCoeff[MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF]; // alf_coeff_luma_delta[i][j] |
140 | | short lumaClipp[MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF]; // alf_clipp_luma_[i][j] |
141 | | int numAlternativesChroma; // alf_chroma_num_alts_minus_one + 1 |
142 | | short chromaCoeff[VVENC_MAX_NUM_ALF_ALTERNATIVES_CHROMA][MAX_NUM_ALF_CHROMA_COEFF]; // alf_coeff_chroma[i] |
143 | | short chromaClipp[VVENC_MAX_NUM_ALF_ALTERNATIVES_CHROMA][MAX_NUM_ALF_CHROMA_COEFF]; // alf_clipp_chroma[i] |
144 | | short filterCoeffDeltaIdx[MAX_NUM_ALF_CLASSES]; // filter_coeff_delta[i] |
145 | | bool alfLumaCoeffFlag[MAX_NUM_ALF_CLASSES]; // alf_luma_coeff_flag[i] |
146 | | int numLumaFilters; // number_of_filters_minus1 + 1 |
147 | | bool alfLumaCoeffDeltaFlag; // alf_luma_coeff_delta_flag |
148 | | bool newFilterFlag[MAX_NUM_CH]; |
149 | | |
150 | | AlfParam() |
151 | 0 | { |
152 | 0 | reset(); |
153 | 0 | } |
154 | | |
155 | | void reset() |
156 | 0 | { |
157 | 0 | std::memset( alfEnabled, false, sizeof( alfEnabled ) ); |
158 | 0 | std::memset( nonLinearFlag, false, sizeof( nonLinearFlag ) ); |
159 | 0 | std::memset( lumaCoeff, 0, sizeof( lumaCoeff ) ); |
160 | 0 | std::memset( lumaClipp, 0, sizeof( lumaClipp ) ); |
161 | 0 | numAlternativesChroma = 1; |
162 | 0 | std::memset( chromaCoeff, 0, sizeof( chromaCoeff ) ); |
163 | 0 | std::memset( chromaClipp, 0, sizeof( chromaClipp ) ); |
164 | 0 | std::memset( filterCoeffDeltaIdx, 0, sizeof( filterCoeffDeltaIdx ) ); |
165 | 0 | std::memset( alfLumaCoeffFlag, true, sizeof( alfLumaCoeffFlag ) ); |
166 | 0 | numLumaFilters = 1; |
167 | 0 | alfLumaCoeffDeltaFlag = false; |
168 | 0 | memset(newFilterFlag, 0, sizeof(newFilterFlag)); |
169 | 0 | } |
170 | | |
171 | | }; |
172 | | |
173 | | struct CcAlfFilterParam |
174 | | { |
175 | | bool ccAlfFilterEnabled[2]; |
176 | | bool ccAlfFilterIdxEnabled[2][MAX_NUM_CC_ALF_FILTERS]; |
177 | | uint8_t ccAlfFilterCount[2]; |
178 | | short ccAlfCoeff[2][MAX_NUM_CC_ALF_FILTERS][MAX_NUM_CC_ALF_CHROMA_COEFF]; |
179 | | int newCcAlfFilter[2]; |
180 | | int numberValidComponents; |
181 | | |
182 | | CcAlfFilterParam() |
183 | 0 | { |
184 | 0 | reset(); |
185 | 0 | } |
186 | | |
187 | | void reset() |
188 | 0 | { |
189 | 0 | std::memset( ccAlfFilterEnabled, false, sizeof( ccAlfFilterEnabled ) ); |
190 | 0 | std::memset( ccAlfFilterIdxEnabled, false, sizeof( ccAlfFilterIdxEnabled ) ); |
191 | 0 | std::memset( ccAlfCoeff, 0, sizeof( ccAlfCoeff ) ); |
192 | 0 | ccAlfFilterCount[0] = ccAlfFilterCount[1] = MAX_NUM_CC_ALF_FILTERS; |
193 | 0 | numberValidComponents = 3; |
194 | 0 | newCcAlfFilter[0] = newCcAlfFilter[1] = 0; |
195 | 0 | } |
196 | | }; |
197 | | } // namespace vvenc |
198 | | |
199 | | //! \} |
200 | | |