Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vvdec/source/Lib/CommonLib/Contexts.cpp
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     Contexts.cpp
44
 *  \brief    Classes providing probability descriptions and contexts (also contains context initialization values)
45
 */
46
47
#include "Contexts.h"
48
49
#include <algorithm>
50
#include <cstring>
51
#include <limits>
52
53
namespace vvdec
54
{
55
56
const uint8_t ProbModelTables::m_RenormTable_32[32] =
57
{
58
  6,  5,  4,  4,
59
  3,  3,  3,  3,
60
  2,  2,  2,  2,
61
  2,  2,  2,  2,
62
  1,  1,  1,  1,
63
  1,  1,  1,  1,
64
  1,  1,  1,  1,
65
  1,  1,  1,  1
66
};
67
68
69
void BinProbModel::init( int qp, int initId )
70
0
{
71
0
  int slope       =   ( initId >> 3 ) -  4;
72
0
  int offset      = ( ( initId  & 7 ) * 18 ) + 1;
73
0
  int inistate    = ( ( slope   * ( qp - 16 ) ) >> 1 ) + offset;
74
0
  int state_clip  = inistate < 1 ? 1 : inistate > 127 ? 127 : inistate;
75
0
  int p1          = ( state_clip << 8 );
76
77
0
  m_state[0]      = p1 & MASK_0;
78
0
  m_state[1]      = p1 & MASK_1;
79
0
}
80
81
CtxSet::CtxSet( std::initializer_list<CtxSet> ctxSets )
82
512
{
83
512
  uint16_t minOffset = std::numeric_limits<uint16_t>::max();
84
512
  uint16_t maxOffset = 0;
85
512
  for( auto& set: ctxSets )
86
1.28k
  {
87
1.28k
    minOffset = std::min<uint16_t>( minOffset, set.Offset );
88
1.28k
    maxOffset = std::max<uint16_t>( maxOffset, set.Offset + set.Size );
89
1.28k
  }
90
512
  Offset = minOffset;
91
512
  Size   = maxOffset - minOffset;
92
512
}
93
94
const std::vector<uint8_t>& ContextSetCfg::getInitTable( unsigned initId )
95
0
{
96
0
  CHECK( initId >= (unsigned)sm_InitTables.size(),
97
0
                     "Invalid initId (" << initId << "), only " << sm_InitTables.size() << " tables defined." );
98
0
  return sm_InitTables[initId];
99
0
}
100
101
102
CtxSet ContextSetCfg::addCtxSet( std::initializer_list<std::initializer_list<uint8_t>> initSet2d )
103
20.9k
{
104
20.9k
  const std::size_t startIdx  = sm_InitTables[0].size();
105
20.9k
  const std::size_t numValues = ( *initSet2d.begin() ).size();
106
20.9k
        std::size_t setId     = 0;
107
20.9k
  for( auto& initSet: initSet2d )
108
83.9k
  {
109
83.9k
    if( setId >= sm_InitTables.size() )
110
0
      break;
111
112
83.9k
    CHECK( initSet.size() != numValues,
113
83.9k
                       "Number of init values do not match for all sets (" << initSet.size() << " != " << numValues << ")." );
114
115
83.9k
    for( auto& elemIter: initSet )
116
380k
    {
117
380k
      sm_InitTables[setId].push_back( elemIter );
118
380k
    }
119
120
83.9k
    setId++;
121
83.9k
  }
122
20.9k
  return CtxSet( (uint16_t)startIdx, (uint16_t)numValues );
123
20.9k
}
124
125
126
std::array<std::vector<uint8_t>, NUMBER_OF_SLICE_TYPES + 1> ContextSetCfg::sm_InitTables;
127
128
// clang-format off
129
const CtxSet ContextSetCfg::SplitFlag = ContextSetCfg::addCtxSet
130
({
131
  {  18,  27,  15,  18,  28,  45,  26,   7,  23, },
132
  {  11,  35,  53,  12,   6,  30,  13,  15,  31, },
133
  {  19,  28,  38,  27,  29,  38,  20,  30,  31, },
134
  {  12,  13,   8,   8,  13,  12,   5,   9,   9, },
135
});
136
137
const CtxSet ContextSetCfg::SplitQtFlag = ContextSetCfg::addCtxSet
138
({
139
  {  26,  36,  38,  18,  34,  21, },
140
  {  20,  14,  23,  18,  19,   6, },
141
  {  27,   6,  15,  25,  19,  37, },
142
  {   0,   8,   8,  12,  12,   8, },
143
});
144
145
const CtxSet ContextSetCfg::SplitHvFlag = ContextSetCfg::addCtxSet
146
({
147
  {  43,  42,  37,  42,  44, },
148
  {  43,  35,  37,  34,  52, },
149
  {  43,  42,  29,  27,  44, },
150
  {   9,   8,   9,   8,   5, },
151
});
152
153
const CtxSet ContextSetCfg::Split12Flag = ContextSetCfg::addCtxSet
154
({
155
  {  28,  29,  28,  29, },
156
  {  43,  37,  21,  22, },
157
  {  36,  45,  36,  45, },
158
  {  12,  13,  12,  13, },
159
});
160
161
const CtxSet ContextSetCfg::ModeConsFlag = ContextSetCfg::addCtxSet
162
({
163
  {  25,  20, },
164
  {  25,  12, },
165
  { CNU, CNU, },
166
  {   1,   0, },
167
});
168
169
const CtxSet ContextSetCfg::SkipFlag = ContextSetCfg::addCtxSet
170
({
171
  {  57,  60,  46, },
172
  {  57,  59,  45, },
173
  {   0,  26,  28, },
174
  {   5,   4,   8, },
175
});
176
177
const CtxSet ContextSetCfg::MergeFlag = ContextSetCfg::addCtxSet
178
({
179
  {   6, },
180
  {  21, },
181
  {  26, },
182
  {   4, },
183
});
184
185
const CtxSet ContextSetCfg::RegularMergeFlag = ContextSetCfg::addCtxSet
186
({
187
  {  46,  15, },
188
  {  38,   7, },
189
  { CNU, CNU, },
190
  {   5,   5, },
191
});
192
193
const CtxSet ContextSetCfg::MergeIdx = ContextSetCfg::addCtxSet
194
({
195
  {  18, },
196
  {  20, },
197
  {  34, },
198
  {   4, },
199
});
200
201
const CtxSet ContextSetCfg::MmvdFlag = ContextSetCfg::addCtxSet
202
({
203
  {  25, },
204
  {  26, },
205
  { CNU, },
206
  {   4, },
207
});
208
209
const CtxSet ContextSetCfg::MmvdMergeIdx = ContextSetCfg::addCtxSet
210
({
211
  {  43, },
212
  {  43, },
213
  { CNU, },
214
  {  10, },
215
});
216
217
const CtxSet ContextSetCfg::MmvdStepMvpIdx = ContextSetCfg::addCtxSet
218
({
219
  {  59, },
220
  {  60, },
221
  { CNU, },
222
  {   0, },
223
});
224
225
const CtxSet ContextSetCfg::PredMode = ContextSetCfg::addCtxSet
226
({
227
  {  40,  35, },
228
  {  40,  35, },
229
  { CNU, CNU, },
230
  {   5,   1, },
231
});
232
233
const CtxSet ContextSetCfg::MultiRefLineIdx = ContextSetCfg::addCtxSet
234
({
235
  {  25,  59, },
236
  {  25,  58, },
237
  {  25,  60, },
238
  {   5,   8, },
239
});
240
241
const CtxSet ContextSetCfg::IPredMode[] =
242
{
243
  ContextSetCfg::addCtxSet
244
  ({
245
    {  44, },
246
    {  36, },
247
    {  45, },
248
    {   6, },
249
  }),
250
  ContextSetCfg::addCtxSet
251
  ({
252
    {  25, },
253
    {  25, },
254
    {  34, },
255
    {   5, },
256
  })
257
};
258
259
const CtxSet ContextSetCfg::IntraLumaPlanarFlag = ContextSetCfg::addCtxSet
260
({
261
  {  13,   6, },
262
  {  12,  20, },
263
  {  13,  28, },
264
  {   1,   5, },
265
});
266
267
const CtxSet ContextSetCfg::CclmModeFlag = ContextSetCfg::addCtxSet
268
({
269
  {  26, },
270
  {  34, },
271
  {  59, },
272
  {   4, },
273
});
274
275
const CtxSet ContextSetCfg::CclmModeIdx = ContextSetCfg::addCtxSet
276
({
277
  {  27, },
278
  {  27, },
279
  {  27, },
280
  {   9, },
281
});
282
283
const CtxSet ContextSetCfg::MipFlag = ContextSetCfg::addCtxSet
284
({
285
  {  56,  57,  50,  26, },
286
  {  41,  57,  58,  26, },
287
  {  33,  49,  50,  25, },
288
  {   9,  10,   9,   6, },
289
});
290
291
const CtxSet ContextSetCfg::DeltaQP = ContextSetCfg::addCtxSet
292
({
293
  { CNU, CNU, },
294
  { CNU, CNU, },
295
  { CNU, CNU, },
296
  { DWS, DWS, },
297
});
298
299
const CtxSet ContextSetCfg::InterDir = ContextSetCfg::addCtxSet
300
({
301
  {  14,  13,   5,   4,   3,  40, },
302
  {   7,   6,   5,  12,   4,  40, },
303
  { CNU, CNU, CNU, CNU, CNU, CNU, },
304
  {   0,   0,   1,   4,   4,   0, },
305
});
306
307
const CtxSet ContextSetCfg::RefPic = ContextSetCfg::addCtxSet
308
({
309
  {   5,  35, },
310
  {  20,  35, },
311
  { CNU, CNU, },
312
  {   0,   4, },
313
});
314
315
const CtxSet ContextSetCfg::SubblockMergeFlag = ContextSetCfg::addCtxSet
316
({
317
  {  25,  58,  45, },
318
  {  48,  57,  44, },
319
  { CNU, CNU, CNU, },
320
  {   4,   4,   4, },
321
});
322
323
const CtxSet ContextSetCfg::AffineFlag = ContextSetCfg::addCtxSet
324
({
325
  {  19,  13,   6, },
326
  {  12,  13,  14, },
327
  { CNU, CNU, CNU, },
328
  {   4,   0,   0, },
329
});
330
331
const CtxSet ContextSetCfg::AffineType = ContextSetCfg::addCtxSet
332
({
333
  {  35, },
334
  {  35, },
335
  { CNU, },
336
  {   4, },
337
});
338
339
const CtxSet ContextSetCfg::AffMergeIdx = ContextSetCfg::addCtxSet
340
({
341
  {   4, },
342
  {   5, },
343
  { CNU, },
344
  {   0, },
345
});
346
347
const CtxSet ContextSetCfg::BcwIdx = ContextSetCfg::addCtxSet
348
({
349
  {   5, },
350
  {   4, },
351
  { CNU, },
352
  {   1, },
353
});
354
355
const CtxSet ContextSetCfg::Mvd = ContextSetCfg::addCtxSet
356
({
357
  {  51,  36, },
358
  {  44,  43, },
359
  {  14,  45, },
360
  {   9,   5, },
361
});
362
363
const CtxSet ContextSetCfg::BDPCMMode = ContextSetCfg::addCtxSet
364
({
365
  {  19,  21,   0,  28, },
366
  {  40,  36,   0,  13, },
367
  {  19,  35,   1,  27, },
368
  {   1,   4,   1,   0, },
369
});
370
371
const CtxSet ContextSetCfg::QtRootCbf = ContextSetCfg::addCtxSet
372
({
373
  {  12, },
374
  {   5, },
375
  {   6, },
376
  {   4, },
377
});
378
379
const CtxSet ContextSetCfg::ACTFlag = ContextSetCfg::addCtxSet
380
({
381
  {  46, },
382
  {  46, },
383
  {  52, },
384
  {   1, },
385
});
386
387
const CtxSet ContextSetCfg::QtCbf[] =
388
{
389
  ContextSetCfg::addCtxSet
390
  ({
391
    {  15,   6,   5,  14, },
392
    {  23,   5,  20,   7, },
393
    {  15,  12,   5,   7, },
394
    {   5,   1,   8,   9, },
395
  }),
396
  ContextSetCfg::addCtxSet
397
  ({
398
    {  25,  37, },
399
    {  25,  28, },
400
    {  12,  21, },
401
    {   5,   0, },
402
  }),
403
  ContextSetCfg::addCtxSet
404
  ({
405
    {   9,  36,  45, },
406
    {  25,  29,  45, },
407
    {  33,  28,  36, },
408
    {   2,   1,   0, },
409
  })
410
};
411
412
const CtxSet ContextSetCfg::SigCoeffGroup[] =
413
{
414
  ContextSetCfg::addCtxSet
415
  ({
416
    {  25,  45, },
417
    {  25,  30, },
418
    {  18,  31, },
419
    {   8,   5, },
420
  }),
421
  ContextSetCfg::addCtxSet
422
  ({
423
    {  25,  14, },
424
    {  25,  45, },
425
    {  25,  15, },
426
    {   5,   8, },
427
  })
428
};
429
430
const CtxSet ContextSetCfg::SigFlag[] =
431
{
432
  ContextSetCfg::addCtxSet
433
  ({
434
    {  17,  41,  49,  36,   1,  49,  50,  37,  48,  51,  58,  45, },
435
    {  17,  41,  42,  29,  25,  49,  43,  37,  33,  58,  51,  30, },
436
    {  25,  19,  28,  14,  25,  20,  29,  30,  19,  37,  30,  38, },
437
    {  12,   9,   9,  10,   9,   9,   9,  10,   8,   8,   8,  10, },
438
  }),
439
  ContextSetCfg::addCtxSet
440
  ({
441
    {   9,  49,  50,  36,  48,  59,  59,  38, },
442
    {  17,  34,  35,  21,  41,  59,  60,  38, },
443
    {  25,  27,  28,  37,  34,  53,  53,  46, },
444
    {  12,  12,   9,  13,   4,   5,   8,   9, },
445
  }),
446
  ContextSetCfg::addCtxSet
447
  ({
448
    {  26,  45,  53,  46,  49,  54,  61,  39,  35,  39,  39,  39, },
449
    {  19,  38,  38,  46,  34,  54,  54,  39,   6,  39,  39,  39, },
450
    {  11,  38,  46,  54,  27,  39,  39,  39,  44,  39,  39,  39, },
451
    {   9,  13,   8,   8,   8,   8,   8,   5,   8,   0,   0,   0, },
452
  }),
453
  ContextSetCfg::addCtxSet
454
  ({
455
    {  34,  45,  38,  31,  58,  39,  39,  39, },
456
    {  35,  45,  53,  54,  44,  39,  39,  39, },
457
    {  19,  46,  38,  39,  52,  39,  39,  39, },
458
    {   8,  12,  12,   8,   4,   0,   0,   0, },
459
  }),
460
  ContextSetCfg::addCtxSet
461
  ({
462
    {  19,  54,  39,  39,  50,  39,  39,  39,   0,  39,  39,  39, },
463
    {  19,  39,  54,  39,  19,  39,  39,  39,  56,  39,  39,  39, },
464
    {  18,  39,  39,  39,  27,  39,  39,  39,   0,  39,  39,  39, },
465
    {   8,   8,   8,   8,   8,   0,   4,   4,   0,   0,   0,   0, },
466
  }),
467
  ContextSetCfg::addCtxSet
468
  ({
469
    {  34,  38,  54,  39,  41,  39,  39,  39, },
470
    {  34,  38,  62,  39,  26,  39,  39,  39, },
471
    {  11,  39,  39,  39,  19,  39,  39,  39, },
472
    {   8,   8,   8,   8,   4,   0,   0,   0, },
473
  })
474
};
475
476
const CtxSet ContextSetCfg::ParFlag[] =
477
{
478
  ContextSetCfg::addCtxSet
479
  ({
480
    {  33,  40,  25,  41,  26,  42,  25,  33,  26,  34,  27,  25,  41,  42,  42,  35,  33,  27,  35,  42,  43, },
481
    {  18,  17,  33,  18,  26,  42,  25,  33,  26,  42,  27,  25,  34,  42,  42,  35,  26,  27,  42,  20,  20, },
482
    {  33,  25,  18,  26,  34,  27,  25,  26,  19,  42,  35,  33,  19,  27,  35,  35,  34,  42,  20,  43,  20, },
483
    {   8,   9,  12,  13,  13,  13,  10,  13,  13,  13,  13,  13,  13,  13,  13,  13,  10,  13,  13,  13,  13, },
484
  }),
485
  ContextSetCfg::addCtxSet
486
  ({
487
    {  33,  25,  26,  34,  19,  27,  33,  42,  43,  35,  43, },
488
    {  25,  25,  26,  11,  19,  27,  33,  42,  35,  35,  43, },
489
    {  33,  25,  26,  42,  19,  27,  26,  50,  35,  20,  43, },
490
    {   8,  12,  12,  12,  13,  13,  13,  13,  13,  13,  13, },
491
  })
492
};
493
494
const CtxSet ContextSetCfg::GtxFlag[] =
495
{
496
  ContextSetCfg::addCtxSet
497
  ({
498
    {  25,   0,   0,  17,  25,  26,   0,   9,  25,  33,  19,   0,  25,  33,  26,  20,  25,  33,  27,  35,  22, },
499
    {  17,   0,   1,  17,  25,  18,   0,   9,  25,  33,  34,   9,  25,  18,  26,  20,  25,  18,  19,  27,  29, },
500
    {  25,   1,  40,  25,  33,  11,  17,  25,  25,  18,   4,  17,  33,  26,  19,  13,  33,  19,  20,  28,  22, },
501
    {   1,   5,   9,   9,   9,   6,   5,   9,  10,  10,   9,   9,   9,   9,   9,   9,   6,   8,   9,   9,  10, },
502
  }),
503
  ContextSetCfg::addCtxSet
504
  ({
505
    {  25,   1,  25,  33,  26,  12,  25,  33,  27,  28,  37, },
506
    {  17,   9,  25,  10,  18,   4,  17,  33,  19,  20,  29, },
507
    {  40,   9,  25,  18,  26,  35,  25,  26,  35,  28,  37, },
508
    {   1,   5,   8,   8,   9,   6,   6,   9,   8,   8,   9, },
509
  }),
510
  ContextSetCfg::addCtxSet
511
  ({
512
    {   0,   0,  33,  34,  35,  21,  25,  34,  35,  28,  29,  40,  42,  43,  29,  30,  49,  36,  37,  45,  38, },
513
    {   0,  17,  26,  19,  35,  21,  25,  34,  20,  28,  29,  33,  27,  28,  29,  22,  34,  28,  44,  37,  38, },
514
    {  25,  25,  11,  27,  20,  21,  33,  12,  28,  21,  22,  34,  28,  29,  29,  30,  36,  29,  45,  30,  23, },
515
    {   9,   5,  10,  13,  13,  10,   9,  10,  13,  13,  13,   9,  10,  10,  10,  13,   8,   9,  10,  10,  13, },
516
  }),
517
  ContextSetCfg::addCtxSet
518
  ({
519
    {   0,  40,  34,  43,  36,  37,  57,  52,  45,  38,  46, },
520
    {   0,  25,  19,  20,  13,  14,  57,  44,  30,  30,  23, },
521
    {  40,  33,  27,  28,  21,  37,  36,  37,  45,  38,  46, },
522
    {   8,   8,   9,  12,  12,  10,   5,   9,   9,   9,  13, },
523
  })
524
};
525
526
const CtxSet ContextSetCfg::LastX[] =
527
{
528
  ContextSetCfg::addCtxSet
529
  ({
530
    {   6,   6,  12,  14,   6,   4,  14,   7,   6,   4,  29,   7,   6,   6,  12,  28,   7,  13,  13,  35, },
531
    {   6,  13,  12,   6,   6,  12,  14,  14,  13,  12,  29,   7,   6,  13,  36,  28,  14,  13,   5,  26, },
532
    {  13,   5,   4,  21,  14,   4,   6,  14,  21,  11,  14,   7,  14,   5,  11,  21,  30,  22,  13,  42, },
533
    {   8,   5,   4,   5,   4,   4,   5,   4,   1,   0,   4,   1,   0,   0,   0,   0,   1,   0,   0,   0, },
534
  }),
535
  ContextSetCfg::addCtxSet
536
  ({
537
    {  19,   5,   4, },
538
    {  12,   4,  18, },
539
    {  12,   4,   3, },
540
    {   5,   4,   4, },
541
  })
542
};
543
544
const CtxSet ContextSetCfg::LastY[] =
545
{
546
  ContextSetCfg::addCtxSet
547
  ({
548
    {   5,   5,  20,  13,  13,  19,  21,   6,  12,  12,  14,  14,   5,   4,  12,  13,   7,  13,  12,  41, },
549
    {   5,   5,  12,   6,   6,   4,   6,  14,   5,  12,  14,   7,  13,   5,  13,  21,  14,  20,  12,  34, },
550
    {  13,   5,   4,   6,  13,  11,  14,   6,   5,   3,  14,  22,   6,   4,   3,   6,  22,  29,  20,  34, },
551
    {   8,   5,   8,   5,   5,   4,   5,   5,   4,   0,   5,   4,   1,   0,   0,   1,   4,   0,   0,   0, },
552
  }),
553
  ContextSetCfg::addCtxSet
554
  ({
555
    {  11,   5,  27, },
556
    {  11,   4,  18, },
557
    {  12,   4,   3, },
558
    {   6,   5,   5, },
559
  })
560
};
561
562
const CtxSet ContextSetCfg::MVPIdx = ContextSetCfg::addCtxSet
563
({
564
  {  34, },
565
  {  34, },
566
  {  42, },
567
  {  12, },
568
});
569
570
const CtxSet ContextSetCfg::SmvdFlag = ContextSetCfg::addCtxSet
571
({
572
  {  28, },
573
  {  28, },
574
  { CNU, },
575
  {   5, },
576
});
577
578
const CtxSet ContextSetCfg::SaoMergeFlag = ContextSetCfg::addCtxSet
579
({
580
  {   2, },
581
  {  60, },
582
  {  60, },
583
  {   0, },
584
});
585
586
const CtxSet ContextSetCfg::SaoTypeIdx = ContextSetCfg::addCtxSet
587
({
588
  {   2, },
589
  {   5, },
590
  {  13, },
591
  {   4, },
592
});
593
594
const CtxSet ContextSetCfg::LFNSTIdx = ContextSetCfg::addCtxSet
595
({
596
  {  52,  37,  27, },
597
  {  37,  45,  27, },
598
  {  28,  52,  42, },
599
  {   9,   9,  10, },
600
});
601
602
const CtxSet ContextSetCfg::RdpcmFlag = ContextSetCfg::addCtxSet
603
({
604
  { CNU, CNU, },
605
  { CNU, CNU, },
606
  { CNU, CNU, },
607
  { DWS, DWS, },
608
});
609
610
const CtxSet ContextSetCfg::RdpcmDir = ContextSetCfg::addCtxSet
611
({
612
  { CNU, CNU, },
613
  { CNU, CNU, },
614
  { CNU, CNU, },
615
  { DWS, DWS, },
616
});
617
618
const CtxSet ContextSetCfg::MTSIndex = ContextSetCfg::addCtxSet
619
({
620
  {  45,  25,  27,   0,  25,   17, },
621
  {  45,  40,  27,   0,  25,    9, },
622
  {  29,   0,  28,   0,  25,    9, },
623
  {   8,   0,   9,   0,   1,    1, },
624
});
625
626
const CtxSet ContextSetCfg::ISPMode = ContextSetCfg::addCtxSet
627
({
628
  {  33,  43, },
629
  {  33,  36, },
630
  {  33,  43, },
631
  {   9,   2, },
632
});
633
634
const CtxSet ContextSetCfg::SbtFlag = ContextSetCfg::addCtxSet
635
({
636
  {  41,  57, },
637
  {  56,  57, },
638
  { CNU, CNU, },
639
  {   1,   5, },
640
});
641
642
const CtxSet ContextSetCfg::SbtQuadFlag = ContextSetCfg::addCtxSet
643
({
644
  {  42, },
645
  {  42, },
646
  { CNU, },
647
  {  10, },
648
});
649
650
const CtxSet ContextSetCfg::SbtHorFlag = ContextSetCfg::addCtxSet
651
({
652
  {  35,  51,  27, },
653
  {  20,  43,  12, },
654
  { CNU, CNU, CNU, },
655
  {   8,   4,   1, },
656
});
657
658
const CtxSet ContextSetCfg::SbtPosFlag = ContextSetCfg::addCtxSet
659
({
660
  {  28, },
661
  {  28, },
662
  { CNU, },
663
  {  13, },
664
});
665
666
const CtxSet ContextSetCfg::ChromaQpAdjFlag = ContextSetCfg::addCtxSet
667
({
668
  { CNU, },
669
  { CNU, },
670
  { CNU, },
671
  { DWS, },
672
});
673
674
const CtxSet ContextSetCfg::ChromaQpAdjIdc = ContextSetCfg::addCtxSet
675
({
676
  { CNU, },
677
  { CNU, },
678
  { CNU, },
679
  { DWS, },
680
});
681
682
const CtxSet ContextSetCfg::ImvFlag = ContextSetCfg::addCtxSet
683
({
684
  {  59,  26,  50,  60,  38, },
685
  {  59,  48,  58,  60,  60, },
686
  { CNU,  34, CNU, CNU, CNU, },
687
  {   0,   5,   0,   0,   4, },
688
});
689
690
const CtxSet ContextSetCfg::ctbAlfFlag = ContextSetCfg::addCtxSet
691
({
692
  {  33,  52,  46,  25,  61,  54,  25,  61,  54, },
693
  {  13,  23,  46,   4,  61,  54,  19,  46,  54, },
694
  {  62,  39,  39,  54,  39,  39,  31,  39,  39, },
695
  {   0,   0,   0,   4,   0,   0,   1,   0,   0, },
696
});
697
698
const CtxSet ContextSetCfg::ctbAlfAlternative = ContextSetCfg::addCtxSet
699
({
700
  {  11,  26, },
701
  {  20,  12, },
702
  {  11,  11, },
703
  {   0,   0, },
704
});
705
706
const CtxSet ContextSetCfg::AlfUseTemporalFilt = ContextSetCfg::addCtxSet
707
({
708
  {  46, },
709
  {  46, },
710
  {  46, },
711
  {   0, },
712
});
713
714
const CtxSet ContextSetCfg::CcAlfFilterControlFlag = ContextSetCfg::addCtxSet
715
({
716
  {  25,  35,  38,  25,  28,  38, },
717
  {  18,  21,  38,  18,  21,  38, },
718
  {  18,  30,  31,  18,  30,  31, },
719
  {   4,   1,   4,   4,   1,   4, },
720
});
721
722
const CtxSet ContextSetCfg::CiipFlag = ContextSetCfg::addCtxSet
723
({
724
  {  57, },
725
  {  57, },
726
  { CNU, },
727
  {   1, },
728
});
729
730
const CtxSet ContextSetCfg::IBCFlag = ContextSetCfg::addCtxSet
731
({
732
  {   0,  43,  45, },
733
  {   0,  57,  44, },
734
  {  17,  42,  36, },
735
  {   1,   5,   8, },
736
});
737
738
const CtxSet ContextSetCfg::JointCbCrFlag = ContextSetCfg::addCtxSet
739
({
740
  {  42,  43,  52, },
741
  {  27,  36,  45, },
742
  {  12,  21,  35, },
743
  {   1,   1,   0, },
744
});
745
746
const CtxSet ContextSetCfg::TsSigCoeffGroup = ContextSetCfg::addCtxSet
747
({
748
  {  18,  35,  45, },
749
  {  18,  12,  29, },
750
  {  18,  20,  38, },
751
  {   5,   8,   8, },
752
});
753
754
const CtxSet ContextSetCfg::TsSigFlag = ContextSetCfg::addCtxSet
755
({
756
  {  25,  50,  37, },
757
  {  40,  35,  44, },
758
  {  25,  28,  38, },
759
  {  13,  13,   8, },
760
});
761
762
const CtxSet ContextSetCfg::TsParFlag = ContextSetCfg::addCtxSet
763
({
764
  {  11, },
765
  {   3, },
766
  {  11, },
767
  {   6, },
768
});
769
770
const CtxSet ContextSetCfg::TsGtxFlag = ContextSetCfg::addCtxSet
771
({
772
  { CNU,   3,   4,   4,   5, },
773
  { CNU,   2,  10,   3,   3, },
774
  { CNU,  10,   3,   3,   3, },
775
  { DWS,   1,   1,   1,   1, },
776
});
777
778
const CtxSet ContextSetCfg::TsLrg1Flag = ContextSetCfg::addCtxSet
779
({
780
  {  19,  11,   4,   6, },
781
  {  18,  11,   4,  28, },
782
  {  11,   5,   5,  14, },
783
  {   4,   2,   1,   6, },
784
});
785
786
const CtxSet ContextSetCfg::TsResidualSign = ContextSetCfg::addCtxSet
787
({
788
  {  35,  25,  46,  28,  33,  38, },
789
  {   5,  10,  53,  43,  25,  46, },
790
  {  12,  17,  46,  28,  25,  46, },
791
  {   1,   4,   4,   5,   8,   8, },
792
});
793
// clang-format on
794
795
const unsigned ContextSetCfg::NumberOfContexts = (unsigned)ContextSetCfg::sm_InitTables[0].size();
796
797
// combined sets
798
const CtxSet ContextSetCfg::Sao = { ContextSetCfg::SaoMergeFlag, ContextSetCfg::SaoTypeIdx };
799
800
const CtxSet ContextSetCfg::Alf = { ContextSetCfg::ctbAlfFlag, ContextSetCfg::ctbAlfAlternative, ContextSetCfg::AlfUseTemporalFilt };
801
802
803
void Ctx::init(int qp, int initId)
804
0
{
805
0
  const auto& initTable = ContextSetCfg::getInitTable( initId );
806
0
  CHECK( m_CtxBuffer.size() != initTable.size(),
807
0
                     "Size of init table (" << initTable.size() << ") does not match size of context buffer (" << m_CtxBuffer.size() << ")." );
808
809
0
  const auto& rateInitTable = ContextSetCfg::getInitTable( NUMBER_OF_SLICE_TYPES );
810
0
  CHECK( m_CtxBuffer.size() != rateInitTable.size(),
811
0
                     "Size of rate init table (" << rateInitTable.size() << ") does not match size of context buffer (" << m_CtxBuffer.size() << ")." );
812
813
0
  const int clippedQP = Clip3( 0, MAX_QP, qp );
814
0
  for( std::size_t k = 0; k < m_CtxBuffer.size(); k++ )
815
0
  {
816
0
    m_CtxBuffer[k].init( clippedQP, initTable[k] );
817
0
    m_CtxBuffer[k].setLog2WindowSize( rateInitTable[k] );
818
0
  }
819
0
}
820
821
}