Coverage Report

Created: 2026-12-01 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/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
14
    InitGeoRom() { initGeoTemplate(); initLfnstPairs(); }
92
93
0
    ~InitGeoRom() { }
94
95
  private:
96
    void initGeoTemplate() const;
97
    void initLfnstPairs() const;
98
99
  private:
100
};
101
102
extern const ScanElement  m_scanOrderBuf[32258];
103
extern const ScanElement* m_scanOrder[SCAN_NUMBER_OF_GROUP_TYPES][MAX_TU_SIZE_IDX][MAX_TU_SIZE_IDX];
104
105
const ScanElement* const getScanOrder( int g, int w2, int h2 );
106
107
extern const int8_t g_BcwLog2WeightBase;
108
extern const int8_t g_BcwWeightBase;
109
extern const int8_t g_BcwWeights[BCW_NUM];
110
extern const int8_t g_BcwSearchOrder[BCW_NUM];
111
extern const int8_t g_BcwCodingOrder[BCW_NUM];
112
extern const int8_t g_BcwParsingOrder[BCW_NUM];
113
114
class CodingStructure;
115
int8_t getBcwWeight(uint8_t bcwIdx, uint8_t uhRefFrmList);
116
void resetBcwCodingOrder(bool bRunDecoding, const CodingStructure &cs);
117
uint32_t deriveWeightIdxBits(uint8_t bcwIdx);
118
119
extern const InitGeoRom g_scanOrderRom;
120
121
extern const uint32_t g_log2SbbSize[MAX_TU_SIZE_IDX][MAX_TU_SIZE_IDX][2];
122
extern const ScanElement g_coefTopLeftDiagScan8x8[MAX_TU_SIZE_IDX][64];
123
124
extern const int g_quantScales   [2/*0=4^n blocks, 1=2*4^n blocks*/][SCALING_LIST_REM_NUM];          // Q(QP%6)
125
extern const int g_invQuantScales[2/*0=4^n blocks, 1=2*4^n blocks*/][SCALING_LIST_REM_NUM];          // IQ(QP%6)
126
127
static const int g_numTransformMatrixSizes = 6;
128
static const int g_transformMatrixShift[TRANSFORM_NUMBER_OF_DIRECTIONS] = {  6/*, 6 */ };
129
130
131
// ====================================================================================================================
132
// Scanning order & context mapping table
133
// ====================================================================================================================
134
135
extern const uint32_t   g_uiGroupIdx[ MAX_TB_SIZEY ];
136
extern const uint32_t   g_uiMinInGroup[ LAST_SIGNIFICANT_GROUPS ];
137
extern const uint32_t   g_auiGoRiceParsCoeff     [ 32 ];
138
inline uint32_t g_auiGoRicePosCoeff0(int st, uint32_t ricePar)
139
629k
{
140
629k
  return (st < 2 ? 1 : 2) << ricePar;
141
629k
}
142
143
// ====================================================================================================================
144
// Intra prediction table
145
// ====================================================================================================================
146
147
extern const uint8_t  g_aucIntraModeNumFast_UseMPM_2D[7 - MIN_CU_LOG2 + 1][7 - MIN_CU_LOG2 + 1];
148
extern const uint8_t  g_aucIntraModeNumFast_UseMPM   [MAX_CU_DEPTH];
149
extern const uint8_t  g_aucIntraModeNumFast_NotUseMPM[MAX_CU_DEPTH];
150
151
extern const uint8_t  g_chroma422IntraAngleMappingTable[NUM_INTRA_MODE];
152
153
// ====================================================================================================================
154
// Luma QP to Chroma QP mapping
155
// ====================================================================================================================
156
static const int chromaQPMappingTableSize = (MAX_QP + 7);
157
158
extern const uint8_t  g_aucChromaScale[NUM_CHROMA_FORMAT][chromaQPMappingTableSize];
159
160
// ====================================================================================================================
161
// Mode-Dependent DST Matrices
162
// ====================================================================================================================
163
164
165
extern const TMatrixCoeff g_trCoreDCT2P2  [TRANSFORM_NUMBER_OF_DIRECTIONS][  2][  2];
166
extern const TMatrixCoeff g_trCoreDCT2P4  [TRANSFORM_NUMBER_OF_DIRECTIONS][  4][  4];
167
extern const TMatrixCoeff g_trCoreDCT2P8  [TRANSFORM_NUMBER_OF_DIRECTIONS][  8][  8];
168
extern const TMatrixCoeff g_trCoreDCT2P16 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 16][ 16];
169
extern const TMatrixCoeff g_trCoreDCT2P32 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 32][ 32];
170
extern const TMatrixCoeff g_trCoreDCT2P64 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 64][ 64];
171
172
extern const TMatrixCoeff g_trCoreDCT8P4  [TRANSFORM_NUMBER_OF_DIRECTIONS][  4][  4];
173
extern const TMatrixCoeff g_trCoreDCT8P8  [TRANSFORM_NUMBER_OF_DIRECTIONS][  8][  8];
174
extern const TMatrixCoeff g_trCoreDCT8P16 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 16][ 16];
175
extern const TMatrixCoeff g_trCoreDCT8P32 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 32][ 32];
176
177
extern const TMatrixCoeff g_trCoreDST7P4  [TRANSFORM_NUMBER_OF_DIRECTIONS][  4][  4];
178
extern const TMatrixCoeff g_trCoreDST7P8  [TRANSFORM_NUMBER_OF_DIRECTIONS][  8][  8];
179
extern const TMatrixCoeff g_trCoreDST7P16 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 16][ 16];
180
extern const TMatrixCoeff g_trCoreDST7P32 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 32][ 32];
181
182
extern const     int8_t   g_lfnstFwd8x8[ 4 ][ 2 ][ 16 ][ 48 ];
183
extern const     int8_t   g_lfnstFwd4x4[ 4 ][ 2 ][ 16 ][ 16 ];
184
extern const     int8_t   g_lfnstInv8x8[ 4 ][ 2 ][ 48 ][ 16 ];
185
extern const     int8_t   g_lfnstInv4x4[ 4 ][ 2 ][ 16 ][ 16 ];
186
187
// The LFNST matrices above in int16 with the coefficients of two adjacent inputs side by side, laid out
188
// [mode][index][input pair][output][2], for the multiply-add kernels of the x86 SIMD code: one 16-bit multiply-add of
189
// a broadcast input pair with a table row adds both products for consecutive outputs. Filled at static
190
// initialization (InitGeoRom), read-only afterwards.
191
extern           int16_t  g_lfnstFwd8x8Pairs[ 4 ][ 2 ][ 24 ][ 16 ][ 2 ];
192
extern           int16_t  g_lfnstFwd4x4Pairs[ 4 ][ 2 ][  8 ][ 16 ][ 2 ];
193
extern           int16_t  g_lfnstInv8x8Pairs[ 4 ][ 2 ][  8 ][ 48 ][ 2 ];
194
extern           int16_t  g_lfnstInv4x4Pairs[ 4 ][ 2 ][  8 ][ 16 ][ 2 ];
195
196
extern const     uint8_t  g_lfnstLut[ NUM_INTRA_MODE + NUM_EXT_LUMA_MODE - 1 ];
197
198
// ====================================================================================================================
199
// Misc.
200
// ====================================================================================================================
201
inline int Log2(uint32_t x)
202
130M
{
203
130M
  return floorLog2( x );
204
130M
}
205
206
extern const int       g_ictModes[2][4];
207
208
extern const UnitScale     g_miScaling; // scaling object for motion scaling
209
210
extern const char *MatrixType   [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM];
211
extern const char *MatrixType_DC[SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM];
212
213
extern const int g_quantTSDefault4x4   [4*4];
214
extern const int g_quantIntraDefault8x8[8*8];
215
extern const int g_quantInterDefault8x8[8*8];
216
217
extern const uint32_t g_scalingListSize [SCALING_LIST_SIZE_NUM];
218
extern const uint32_t g_scalingListSizeX[SCALING_LIST_SIZE_NUM];
219
220
class CodingStructure;
221
222
const int g_IBCBufferSize = 256 * 128;
223
224
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,
225
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,
226
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,
227
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,
228
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,
229
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,
230
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,
231
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,
232
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,
233
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8 };
234
235
//! \}
236
237
extern int16_t   g_GeoParams[GEO_NUM_PARTITION_MODE][2];
238
extern int16_t   g_globalGeoWeights[GEO_NUM_PRESTORED_MASK]   [GEO_WEIGHT_MASK_SIZE * GEO_WEIGHT_MASK_SIZE];
239
extern int16_t   g_globalGeoEncSADmask[GEO_NUM_PRESTORED_MASK][GEO_WEIGHT_MASK_SIZE * GEO_WEIGHT_MASK_SIZE];
240
extern const int8_t    g_angle2mask[GEO_NUM_ANGLES];
241
extern const int8_t    g_Dis[GEO_NUM_ANGLES];
242
extern const int8_t    g_angle2mirror[GEO_NUM_ANGLES];
243
extern int16_t   g_weightOffset[GEO_NUM_CU_SIZE][GEO_NUM_CU_SIZE][GEO_NUM_PARTITION_MODE][2];
244
245
#if ENABLE_CU_MODE_COUNTERS
246
#define E_COUNTERS_CU(E_) \
247
    E_( CU_MODES_TRIED ) \
248
    E_( CU_MODES_TESTED ) \
249
    E_( CU_RD_TESTS ) \
250
    E_( CU_CODED_FINALLY )
251
MAKE_ENUM_AND_STRINGS( E_COUNTERS_CU, CUCounterId, g_cuCounterIdNames )
252
253
extern StatCounters::StatCounter2DSet<int64_t> g_cuCounters1D;
254
extern StatCounters::StatCounter2DSet<int64_t> g_cuCounters2D;
255
#define STAT_COUNT_CU_MODES(cond,...) if(cond) {(__VA_ARGS__)++;}
256
#else
257
#define STAT_COUNT_CU_MODES(cond,...)
258
#endif
259
} // namespace vvenc
260
261
//! \}
262