/src/vvenc/source/Lib/CommonLib/Rom.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 Rom.h |
43 | | \brief global variables & functions (header) |
44 | | */ |
45 | | |
46 | | #pragma once |
47 | | |
48 | | #include "CommonDef.h" |
49 | | #include "Common.h" |
50 | | #if ENABLE_TRACING |
51 | | #include "dtrace.h" |
52 | | #endif |
53 | | #include "TimeProfiler.h" |
54 | | |
55 | | #include <iostream> |
56 | | |
57 | | //! \ingroup CommonLib |
58 | | //! \{ |
59 | | |
60 | | namespace vvenc { |
61 | | |
62 | | /*! Sophisticated Trace-logging */ |
63 | | #if ENABLE_TRACING |
64 | | extern CDTrace* g_trace_ctx; |
65 | | #endif |
66 | | |
67 | | #if ENABLE_TIME_PROFILING |
68 | | extern TProfiler *g_timeProfiler; |
69 | | #if ENABLE_TIME_PROFILING_MT_MODE |
70 | | extern thread_local std::unique_ptr<TProfiler> ptls; |
71 | | #endif |
72 | | #endif |
73 | | |
74 | | // ==================================================================================================================== |
75 | | // Data structure related table & variable |
76 | | // ==================================================================================================================== |
77 | | |
78 | | |
79 | | // flexible conversion from relative to absolute index |
80 | | struct ScanElement |
81 | | { |
82 | | uint16_t idx; |
83 | | uint8_t x; |
84 | | uint8_t y; |
85 | | }; |
86 | | |
87 | | |
88 | | class InitGeoRom |
89 | | { |
90 | | public: |
91 | 256 | InitGeoRom() { initGeoTemplate(); } |
92 | | |
93 | 0 | ~InitGeoRom() { } |
94 | | |
95 | | private: |
96 | | void initGeoTemplate() const; |
97 | | |
98 | | private: |
99 | | }; |
100 | | |
101 | | extern const ScanElement m_scanOrderBuf[32258]; |
102 | | extern const ScanElement* m_scanOrder[SCAN_NUMBER_OF_GROUP_TYPES][MAX_TU_SIZE_IDX][MAX_TU_SIZE_IDX]; |
103 | | |
104 | | const ScanElement* const getScanOrder( int g, int w2, int h2 ); |
105 | | |
106 | | extern const int8_t g_BcwLog2WeightBase; |
107 | | extern const int8_t g_BcwWeightBase; |
108 | | extern const int8_t g_BcwWeights[BCW_NUM]; |
109 | | extern const int8_t g_BcwSearchOrder[BCW_NUM]; |
110 | | extern const int8_t g_BcwCodingOrder[BCW_NUM]; |
111 | | extern const int8_t g_BcwParsingOrder[BCW_NUM]; |
112 | | |
113 | | class CodingStructure; |
114 | | int8_t getBcwWeight(uint8_t bcwIdx, uint8_t uhRefFrmList); |
115 | | void resetBcwCodingOrder(bool bRunDecoding, const CodingStructure &cs); |
116 | | uint32_t deriveWeightIdxBits(uint8_t bcwIdx); |
117 | | |
118 | | extern const InitGeoRom g_scanOrderRom; |
119 | | |
120 | | extern const uint32_t g_log2SbbSize[MAX_TU_SIZE_IDX][MAX_TU_SIZE_IDX][2]; |
121 | | extern const ScanElement g_coefTopLeftDiagScan8x8[MAX_TU_SIZE_IDX][64]; |
122 | | |
123 | | extern const int g_quantScales [2/*0=4^n blocks, 1=2*4^n blocks*/][SCALING_LIST_REM_NUM]; // Q(QP%6) |
124 | | extern const int g_invQuantScales[2/*0=4^n blocks, 1=2*4^n blocks*/][SCALING_LIST_REM_NUM]; // IQ(QP%6) |
125 | | |
126 | | static const int g_numTransformMatrixSizes = 6; |
127 | | static const int g_transformMatrixShift[TRANSFORM_NUMBER_OF_DIRECTIONS] = { 6/*, 6 */ }; |
128 | | |
129 | | |
130 | | // ==================================================================================================================== |
131 | | // Scanning order & context mapping table |
132 | | // ==================================================================================================================== |
133 | | |
134 | | extern const uint32_t g_uiGroupIdx[ MAX_TB_SIZEY ]; |
135 | | extern const uint32_t g_uiMinInGroup[ LAST_SIGNIFICANT_GROUPS ]; |
136 | | extern const uint32_t g_auiGoRiceParsCoeff [ 32 ]; |
137 | | inline uint32_t g_auiGoRicePosCoeff0(int st, uint32_t ricePar) |
138 | 0 | { |
139 | 0 | return (st < 2 ? 1 : 2) << ricePar; |
140 | 0 | } |
141 | | |
142 | | // ==================================================================================================================== |
143 | | // Intra prediction table |
144 | | // ==================================================================================================================== |
145 | | |
146 | | extern const uint8_t g_aucIntraModeNumFast_UseMPM_2D[7 - MIN_CU_LOG2 + 1][7 - MIN_CU_LOG2 + 1]; |
147 | | extern const uint8_t g_aucIntraModeNumFast_UseMPM [MAX_CU_DEPTH]; |
148 | | extern const uint8_t g_aucIntraModeNumFast_NotUseMPM[MAX_CU_DEPTH]; |
149 | | |
150 | | extern const uint8_t g_chroma422IntraAngleMappingTable[NUM_INTRA_MODE]; |
151 | | |
152 | | // ==================================================================================================================== |
153 | | // Luma QP to Chroma QP mapping |
154 | | // ==================================================================================================================== |
155 | | static const int chromaQPMappingTableSize = (MAX_QP + 7); |
156 | | |
157 | | extern const uint8_t g_aucChromaScale[NUM_CHROMA_FORMAT][chromaQPMappingTableSize]; |
158 | | |
159 | | // ==================================================================================================================== |
160 | | // Mode-Dependent DST Matrices |
161 | | // ==================================================================================================================== |
162 | | |
163 | | |
164 | | extern const TMatrixCoeff g_trCoreDCT2P2 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 2][ 2]; |
165 | | extern const TMatrixCoeff g_trCoreDCT2P4 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 4][ 4]; |
166 | | extern const TMatrixCoeff g_trCoreDCT2P8 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 8][ 8]; |
167 | | extern const TMatrixCoeff g_trCoreDCT2P16 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 16][ 16]; |
168 | | extern const TMatrixCoeff g_trCoreDCT2P32 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 32][ 32]; |
169 | | extern const TMatrixCoeff g_trCoreDCT2P64 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 64][ 64]; |
170 | | |
171 | | extern const TMatrixCoeff g_trCoreDCT8P4 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 4][ 4]; |
172 | | extern const TMatrixCoeff g_trCoreDCT8P8 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 8][ 8]; |
173 | | extern const TMatrixCoeff g_trCoreDCT8P16 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 16][ 16]; |
174 | | extern const TMatrixCoeff g_trCoreDCT8P32 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 32][ 32]; |
175 | | |
176 | | extern const TMatrixCoeff g_trCoreDST7P4 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 4][ 4]; |
177 | | extern const TMatrixCoeff g_trCoreDST7P8 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 8][ 8]; |
178 | | extern const TMatrixCoeff g_trCoreDST7P16 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 16][ 16]; |
179 | | extern const TMatrixCoeff g_trCoreDST7P32 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 32][ 32]; |
180 | | |
181 | | extern const int8_t g_lfnstFwd8x8[ 4 ][ 2 ][ 16 ][ 48 ]; |
182 | | extern const int8_t g_lfnstFwd4x4[ 4 ][ 2 ][ 16 ][ 16 ]; |
183 | | extern const int8_t g_lfnstInv8x8[ 4 ][ 2 ][ 48 ][ 16 ]; |
184 | | extern const int8_t g_lfnstInv4x4[ 4 ][ 2 ][ 16 ][ 16 ]; |
185 | | |
186 | | extern const uint8_t g_lfnstLut[ NUM_INTRA_MODE + NUM_EXT_LUMA_MODE - 1 ]; |
187 | | |
188 | | // ==================================================================================================================== |
189 | | // Misc. |
190 | | // ==================================================================================================================== |
191 | | inline int Log2(uint32_t x) |
192 | 0 | { |
193 | 0 | return floorLog2( x ); |
194 | 0 | } |
195 | | |
196 | | extern const int g_ictModes[2][4]; |
197 | | |
198 | | extern const UnitScale g_miScaling; // scaling object for motion scaling |
199 | | |
200 | | extern const char *MatrixType [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; |
201 | | extern const char *MatrixType_DC[SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; |
202 | | |
203 | | extern const int g_quantTSDefault4x4 [4*4]; |
204 | | extern const int g_quantIntraDefault8x8[8*8]; |
205 | | extern const int g_quantInterDefault8x8[8*8]; |
206 | | |
207 | | extern const uint32_t g_scalingListSize [SCALING_LIST_SIZE_NUM]; |
208 | | extern const uint32_t g_scalingListSizeX[SCALING_LIST_SIZE_NUM]; |
209 | | |
210 | | class CodingStructure; |
211 | | |
212 | | const int g_IBCBufferSize = 256 * 128; |
213 | | |
214 | | constexpr uint8_t g_tbMax[257] = { 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
215 | | 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
216 | | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
217 | | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
218 | | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, |
219 | | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
220 | | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
221 | | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
222 | | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
223 | | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8 }; |
224 | | |
225 | | //! \} |
226 | | |
227 | | extern int16_t g_GeoParams[GEO_NUM_PARTITION_MODE][2]; |
228 | | extern int16_t g_globalGeoWeights[GEO_NUM_PRESTORED_MASK] [GEO_WEIGHT_MASK_SIZE * GEO_WEIGHT_MASK_SIZE]; |
229 | | extern int16_t g_globalGeoEncSADmask[GEO_NUM_PRESTORED_MASK][GEO_WEIGHT_MASK_SIZE * GEO_WEIGHT_MASK_SIZE]; |
230 | | extern const int8_t g_angle2mask[GEO_NUM_ANGLES]; |
231 | | extern const int8_t g_Dis[GEO_NUM_ANGLES]; |
232 | | extern const int8_t g_angle2mirror[GEO_NUM_ANGLES]; |
233 | | extern int16_t g_weightOffset[GEO_NUM_CU_SIZE][GEO_NUM_CU_SIZE][GEO_NUM_PARTITION_MODE][2]; |
234 | | |
235 | | #if ENABLE_CU_MODE_COUNTERS |
236 | | #define E_COUNTERS_CU(E_) \ |
237 | | E_( CU_MODES_TRIED ) \ |
238 | | E_( CU_MODES_TESTED ) \ |
239 | | E_( CU_RD_TESTS ) \ |
240 | | E_( CU_CODED_FINALLY ) |
241 | | MAKE_ENUM_AND_STRINGS( E_COUNTERS_CU, CUCounterId, g_cuCounterIdNames ) |
242 | | |
243 | | extern StatCounters::StatCounter2DSet<int64_t> g_cuCounters1D; |
244 | | extern StatCounters::StatCounter2DSet<int64_t> g_cuCounters2D; |
245 | | #define STAT_COUNT_CU_MODES(cond,...) if(cond) {(__VA_ARGS__)++;} |
246 | | #else |
247 | | #define STAT_COUNT_CU_MODES(cond,...) |
248 | | #endif |
249 | | } // namespace vvenc |
250 | | |
251 | | //! \} |
252 | | |