Contexts.cpp 32.9 KB
Newer Older
1
2
3
4
5
/* The copyright in this software is being made available under the BSD
 * License, included below. This software may be subject to other third party
 * and contributor rights, including patent rights, and no such rights are
 * granted under this license.
 *
6
 * Copyright (c) 2010-2019, ITU/ISO/IEC
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
 *    be used to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

/** \file     Contexts.cpp
 *  \brief    Classes providing probability descriptions and contexts (also contains context initialization values)
 */

#include "Contexts.h"

#include <algorithm>
#include <cstring>
#include <limits>


const uint8_t ProbModelTables::m_RenormTable_32[32] =
{
  6,  5,  4,  4,
  3,  3,  3,  3,
  2,  2,  2,  2,
  2,  2,  2,  2,
  1,  1,  1,  1,
  1,  1,  1,  1,
  1,  1,  1,  1,
  1,  1,  1,  1
};

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const BinFracBits ProbModelTables::m_binFracBits[256] = {
  { { 0x0005c, 0x48000 } }, { { 0x00116, 0x3b520 } }, { { 0x001d0, 0x356cb } }, { { 0x0028b, 0x318a9 } },
  { { 0x00346, 0x2ea40 } }, { { 0x00403, 0x2c531 } }, { { 0x004c0, 0x2a658 } }, { { 0x0057e, 0x28beb } },
  { { 0x0063c, 0x274ce } }, { { 0x006fc, 0x26044 } }, { { 0x007bc, 0x24dc9 } }, { { 0x0087d, 0x23cfc } },
  { { 0x0093f, 0x22d96 } }, { { 0x00a01, 0x21f60 } }, { { 0x00ac4, 0x2122e } }, { { 0x00b89, 0x205dd } },
  { { 0x00c4e, 0x1fa51 } }, { { 0x00d13, 0x1ef74 } }, { { 0x00dda, 0x1e531 } }, { { 0x00ea2, 0x1db78 } },
  { { 0x00f6a, 0x1d23c } }, { { 0x01033, 0x1c970 } }, { { 0x010fd, 0x1c10b } }, { { 0x011c8, 0x1b903 } },
  { { 0x01294, 0x1b151 } }, { { 0x01360, 0x1a9ee } }, { { 0x0142e, 0x1a2d4 } }, { { 0x014fc, 0x19bfc } },
  { { 0x015cc, 0x19564 } }, { { 0x0169c, 0x18f06 } }, { { 0x0176d, 0x188de } }, { { 0x0183f, 0x182e8 } },
  { { 0x01912, 0x17d23 } }, { { 0x019e6, 0x1778a } }, { { 0x01abb, 0x1721c } }, { { 0x01b91, 0x16cd5 } },
  { { 0x01c68, 0x167b4 } }, { { 0x01d40, 0x162b6 } }, { { 0x01e19, 0x15dda } }, { { 0x01ef3, 0x1591e } },
  { { 0x01fcd, 0x15480 } }, { { 0x020a9, 0x14fff } }, { { 0x02186, 0x14b99 } }, { { 0x02264, 0x1474e } },
  { { 0x02343, 0x1431b } }, { { 0x02423, 0x13f01 } }, { { 0x02504, 0x13afd } }, { { 0x025e6, 0x1370f } },
  { { 0x026ca, 0x13336 } }, { { 0x027ae, 0x12f71 } }, { { 0x02894, 0x12bc0 } }, { { 0x0297a, 0x12821 } },
  { { 0x02a62, 0x12494 } }, { { 0x02b4b, 0x12118 } }, { { 0x02c35, 0x11dac } }, { { 0x02d20, 0x11a51 } },
  { { 0x02e0c, 0x11704 } }, { { 0x02efa, 0x113c7 } }, { { 0x02fe9, 0x11098 } }, { { 0x030d9, 0x10d77 } },
  { { 0x031ca, 0x10a63 } }, { { 0x032bc, 0x1075c } }, { { 0x033b0, 0x10461 } }, { { 0x034a5, 0x10173 } },
  { { 0x0359b, 0x0fe90 } }, { { 0x03693, 0x0fbb9 } }, { { 0x0378c, 0x0f8ed } }, { { 0x03886, 0x0f62b } },
  { { 0x03981, 0x0f374 } }, { { 0x03a7e, 0x0f0c7 } }, { { 0x03b7c, 0x0ee23 } }, { { 0x03c7c, 0x0eb89 } },
  { { 0x03d7d, 0x0e8f9 } }, { { 0x03e7f, 0x0e671 } }, { { 0x03f83, 0x0e3f2 } }, { { 0x04088, 0x0e17c } },
  { { 0x0418e, 0x0df0e } }, { { 0x04297, 0x0dca8 } }, { { 0x043a0, 0x0da4a } }, { { 0x044ab, 0x0d7f3 } },
  { { 0x045b8, 0x0d5a5 } }, { { 0x046c6, 0x0d35d } }, { { 0x047d6, 0x0d11c } }, { { 0x048e7, 0x0cee3 } },
  { { 0x049fa, 0x0ccb0 } }, { { 0x04b0e, 0x0ca84 } }, { { 0x04c24, 0x0c85e } }, { { 0x04d3c, 0x0c63f } },
  { { 0x04e55, 0x0c426 } }, { { 0x04f71, 0x0c212 } }, { { 0x0508d, 0x0c005 } }, { { 0x051ac, 0x0bdfe } },
  { { 0x052cc, 0x0bbfc } }, { { 0x053ee, 0x0b9ff } }, { { 0x05512, 0x0b808 } }, { { 0x05638, 0x0b617 } },
  { { 0x0575f, 0x0b42a } }, { { 0x05888, 0x0b243 } }, { { 0x059b4, 0x0b061 } }, { { 0x05ae1, 0x0ae83 } },
  { { 0x05c10, 0x0acaa } }, { { 0x05d41, 0x0aad6 } }, { { 0x05e74, 0x0a907 } }, { { 0x05fa9, 0x0a73c } },
  { { 0x060e0, 0x0a575 } }, { { 0x06219, 0x0a3b3 } }, { { 0x06354, 0x0a1f5 } }, { { 0x06491, 0x0a03b } },
  { { 0x065d1, 0x09e85 } }, { { 0x06712, 0x09cd4 } }, { { 0x06856, 0x09b26 } }, { { 0x0699c, 0x0997c } },
  { { 0x06ae4, 0x097d6 } }, { { 0x06c2f, 0x09634 } }, { { 0x06d7c, 0x09495 } }, { { 0x06ecb, 0x092fa } },
  { { 0x0701d, 0x09162 } }, { { 0x07171, 0x08fce } }, { { 0x072c7, 0x08e3e } }, { { 0x07421, 0x08cb0 } },
  { { 0x0757c, 0x08b26 } }, { { 0x076da, 0x089a0 } }, { { 0x0783b, 0x0881c } }, { { 0x0799f, 0x0869c } },
  { { 0x07b05, 0x0851f } }, { { 0x07c6e, 0x083a4 } }, { { 0x07dd9, 0x0822d } }, { { 0x07f48, 0x080b9 } },
  { { 0x080b9, 0x07f48 } }, { { 0x0822d, 0x07dd9 } }, { { 0x083a4, 0x07c6e } }, { { 0x0851f, 0x07b05 } },
  { { 0x0869c, 0x0799f } }, { { 0x0881c, 0x0783b } }, { { 0x089a0, 0x076da } }, { { 0x08b26, 0x0757c } },
  { { 0x08cb0, 0x07421 } }, { { 0x08e3e, 0x072c7 } }, { { 0x08fce, 0x07171 } }, { { 0x09162, 0x0701d } },
  { { 0x092fa, 0x06ecb } }, { { 0x09495, 0x06d7c } }, { { 0x09634, 0x06c2f } }, { { 0x097d6, 0x06ae4 } },
  { { 0x0997c, 0x0699c } }, { { 0x09b26, 0x06856 } }, { { 0x09cd4, 0x06712 } }, { { 0x09e85, 0x065d1 } },
  { { 0x0a03b, 0x06491 } }, { { 0x0a1f5, 0x06354 } }, { { 0x0a3b3, 0x06219 } }, { { 0x0a575, 0x060e0 } },
  { { 0x0a73c, 0x05fa9 } }, { { 0x0a907, 0x05e74 } }, { { 0x0aad6, 0x05d41 } }, { { 0x0acaa, 0x05c10 } },
  { { 0x0ae83, 0x05ae1 } }, { { 0x0b061, 0x059b4 } }, { { 0x0b243, 0x05888 } }, { { 0x0b42a, 0x0575f } },
  { { 0x0b617, 0x05638 } }, { { 0x0b808, 0x05512 } }, { { 0x0b9ff, 0x053ee } }, { { 0x0bbfc, 0x052cc } },
  { { 0x0bdfe, 0x051ac } }, { { 0x0c005, 0x0508d } }, { { 0x0c212, 0x04f71 } }, { { 0x0c426, 0x04e55 } },
  { { 0x0c63f, 0x04d3c } }, { { 0x0c85e, 0x04c24 } }, { { 0x0ca84, 0x04b0e } }, { { 0x0ccb0, 0x049fa } },
  { { 0x0cee3, 0x048e7 } }, { { 0x0d11c, 0x047d6 } }, { { 0x0d35d, 0x046c6 } }, { { 0x0d5a5, 0x045b8 } },
  { { 0x0d7f3, 0x044ab } }, { { 0x0da4a, 0x043a0 } }, { { 0x0dca8, 0x04297 } }, { { 0x0df0e, 0x0418e } },
  { { 0x0e17c, 0x04088 } }, { { 0x0e3f2, 0x03f83 } }, { { 0x0e671, 0x03e7f } }, { { 0x0e8f9, 0x03d7d } },
  { { 0x0eb89, 0x03c7c } }, { { 0x0ee23, 0x03b7c } }, { { 0x0f0c7, 0x03a7e } }, { { 0x0f374, 0x03981 } },
  { { 0x0f62b, 0x03886 } }, { { 0x0f8ed, 0x0378c } }, { { 0x0fbb9, 0x03693 } }, { { 0x0fe90, 0x0359b } },
  { { 0x10173, 0x034a5 } }, { { 0x10461, 0x033b0 } }, { { 0x1075c, 0x032bc } }, { { 0x10a63, 0x031ca } },
  { { 0x10d77, 0x030d9 } }, { { 0x11098, 0x02fe9 } }, { { 0x113c7, 0x02efa } }, { { 0x11704, 0x02e0c } },
  { { 0x11a51, 0x02d20 } }, { { 0x11dac, 0x02c35 } }, { { 0x12118, 0x02b4b } }, { { 0x12494, 0x02a62 } },
  { { 0x12821, 0x0297a } }, { { 0x12bc0, 0x02894 } }, { { 0x12f71, 0x027ae } }, { { 0x13336, 0x026ca } },
  { { 0x1370f, 0x025e6 } }, { { 0x13afd, 0x02504 } }, { { 0x13f01, 0x02423 } }, { { 0x1431b, 0x02343 } },
  { { 0x1474e, 0x02264 } }, { { 0x14b99, 0x02186 } }, { { 0x14fff, 0x020a9 } }, { { 0x15480, 0x01fcd } },
  { { 0x1591e, 0x01ef3 } }, { { 0x15dda, 0x01e19 } }, { { 0x162b6, 0x01d40 } }, { { 0x167b4, 0x01c68 } },
  { { 0x16cd5, 0x01b91 } }, { { 0x1721c, 0x01abb } }, { { 0x1778a, 0x019e6 } }, { { 0x17d23, 0x01912 } },
  { { 0x182e8, 0x0183f } }, { { 0x188de, 0x0176d } }, { { 0x18f06, 0x0169c } }, { { 0x19564, 0x015cc } },
  { { 0x19bfc, 0x014fc } }, { { 0x1a2d4, 0x0142e } }, { { 0x1a9ee, 0x01360 } }, { { 0x1b151, 0x01294 } },
  { { 0x1b903, 0x011c8 } }, { { 0x1c10b, 0x010fd } }, { { 0x1c970, 0x01033 } }, { { 0x1d23c, 0x00f6a } },
  { { 0x1db78, 0x00ea2 } }, { { 0x1e531, 0x00dda } }, { { 0x1ef74, 0x00d13 } }, { { 0x1fa51, 0x00c4e } },
  { { 0x205dd, 0x00b89 } }, { { 0x2122e, 0x00ac4 } }, { { 0x21f60, 0x00a01 } }, { { 0x22d96, 0x0093f } },
  { { 0x23cfc, 0x0087d } }, { { 0x24dc9, 0x007bc } }, { { 0x26044, 0x006fc } }, { { 0x274ce, 0x0063c } },
  { { 0x28beb, 0x0057e } }, { { 0x2a658, 0x004c0 } }, { { 0x2c531, 0x00403 } }, { { 0x2ea40, 0x00346 } },
  { { 0x318a9, 0x0028b } }, { { 0x356cb, 0x001d0 } }, { { 0x3b520, 0x00116 } }, { { 0x48000, 0x0005c } },
};
Jie Dong's avatar
Jie Dong committed
123
#if !JVET_O0065_CABAC_INIT
124
125
126
127
128
129
130
131
132
133
const uint16_t ProbModelTables::m_inistateToCount[128] = {
  614,   647,   681,   718,   756,   797,   839,   884,   932,   982,   1034,  1089,  1148,  1209,  1274,  1342,
  1414,  1490,  1569,  1653,  1742,  1835,  1933,  2037,  2146,  2261,  2382,  2509,  2643,  2785,  2934,  3091,
  3256,  3430,  3614,  3807,  4011,  4225,  4452,  4690,  4941,  5205,  5483,  5777,  6086,  6412,  6755,  7116,
  7497,  7898,  8320,  8766,  9235,  9729,  10249, 10798, 11375, 11984, 12625, 13300, 14012, 14762, 15551, 16384,
  16384, 17216, 18005, 18755, 19467, 20142, 20783, 21392, 21969, 22518, 23038, 23532, 24001, 24447, 24869, 25270,
  25651, 26012, 26355, 26681, 26990, 27284, 27562, 27826, 28077, 28315, 28542, 28756, 28960, 29153, 29337, 29511,
  29676, 29833, 29982, 30124, 30258, 30385, 30506, 30621, 30730, 30834, 30932, 31025, 31114, 31198, 31277, 31353,
  31425, 31493, 31558, 31619, 31678, 31733, 31785, 31835, 31883, 31928, 31970, 32011, 32049, 32086, 32120, 32153
};
Jie Dong's avatar
Jie Dong committed
134
#endif
135
136
void BinProbModel_Std::init( int qp, int initId )
{
Jie Dong's avatar
Jie Dong committed
137
138
139
140
141
142
143
#if JVET_O0065_CABAC_INIT
  int slope = (initId >> 3) - 4;
  int offset = ((initId & 7) * 18) + 1;
  int inistate = ((slope   * (qp - 16)) >> 1) + offset;
  int state_clip = inistate < 1 ? 1 : inistate > 127 ? 127 : inistate;
  const int p1 = (state_clip << 8);
#else
144
145
146
  int slope     = ( ( initId >>  4 )  * 5 ) - 45;
  int offset    = ( ( initId  & 15 ) << 3 ) - 16;
  int inistate  = ( ( slope   * qp ) >> 4 ) + offset;
147
  const int p1 = m_inistateToCount[inistate < 0 ? 0 : inistate > 127 ? 127 : inistate];
Jie Dong's avatar
Jie Dong committed
148
#endif
149
150
  m_state[0]   = p1 & MASK_0;
  m_state[1]   = p1 & MASK_1;
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
}




CtxSet::CtxSet( std::initializer_list<CtxSet> ctxSets )
{
  uint16_t  minOffset = std::numeric_limits<uint16_t>::max();
  uint16_t  maxOffset = 0;
  for( auto iter = ctxSets.begin(); iter != ctxSets.end(); iter++ )
  {
    minOffset = std::min<uint16_t>( minOffset, (*iter).Offset              );
    maxOffset = std::max<uint16_t>( maxOffset, (*iter).Offset+(*iter).Size );
  }
  Offset  = minOffset;
  Size    = maxOffset - minOffset;
}





const std::vector<uint8_t>& ContextSetCfg::getInitTable( unsigned initId )
{
  CHECK( initId >= (unsigned)sm_InitTables.size(),
         "Invalid initId (" << initId << "), only " << sm_InitTables.size() << " tables defined." );
  return sm_InitTables[initId];
}


CtxSet ContextSetCfg::addCtxSet( std::initializer_list<std::initializer_list<uint8_t>> initSet2d )
{
  const std::size_t startIdx  = sm_InitTables[0].size();
  const std::size_t numValues = ( *initSet2d.begin() ).size();
        std::size_t setId     = 0;
  for( auto setIter = initSet2d.begin(); setIter != initSet2d.end() && setId < sm_InitTables.size(); setIter++, setId++ )
  {
    const std::initializer_list<uint8_t>& initSet   = *setIter;
    std::vector<uint8_t>&           initTable = sm_InitTables[setId];
    CHECK( initSet.size() != numValues,
           "Number of init values do not match for all sets (" << initSet.size() << " != " << numValues << ")." );
    initTable.resize( startIdx + numValues );
    std::size_t elemId = startIdx;
    for( auto elemIter = ( *setIter ).begin(); elemIter != ( *setIter ).end(); elemIter++, elemId++ )
    {
      initTable[elemId] = *elemIter;
    }
  }
  return CtxSet( (uint16_t)startIdx, (uint16_t)numValues );
}


Jie Dong's avatar
Jie Dong committed
203
204
205
#if JVET_O0065_CABAC_INIT
#define CNU 35
#else
206
#define CNU 154 // dummy initialization value for unused context models 'Context model Not Used'
Jie Dong's avatar
Jie Dong committed
207
#endif
208
std::vector<std::vector<uint8_t>> ContextSetCfg::sm_InitTables(NUMBER_OF_SLICE_TYPES + 1);
209

210
// clang-format off
211
212
const CtxSet ContextSetCfg::SplitFlag = ContextSetCfg::addCtxSet
({
213
214
215
216
  { 136, 153, 141, 122, 125, 156, 138, 126, 143, },
  { 122, 139, 186, 124, 125, 141, 139, 141, 158, },
  { 138, 154, 172, 124, 140, 142, 154, 142, 175, },
  {  12,  12,   8,   8,  13,  12,   5,  10,  12, },
Adam Wieckowski's avatar
Adam Wieckowski committed
217
218
219
220
});

const CtxSet ContextSetCfg::SplitQtFlag = ContextSetCfg::addCtxSet
({
221
222
223
224
  { 123, 140, 142, 136, 138, 140, },
  { 139, 126, 142, 136, 138, 125, },
  { 124, 125, 127, 136, 153, 126, },
  {   0,   8,   8,  12,  12,  12, },
Adam Wieckowski's avatar
Adam Wieckowski committed
225
226
227
228
});

const CtxSet ContextSetCfg::SplitHvFlag = ContextSetCfg::addCtxSet
({
229
230
  { 154, 168, 155, 139, 155, },
  { 169, 168, 170, 153, 170, },
231
232
  { 154, 168, 155, 153, 155, },
  {  10,   9,   9,   8,   8, },
233
234
});

Adam Wieckowski's avatar
Adam Wieckowski committed
235
236
const CtxSet ContextSetCfg::Split12Flag = ContextSetCfg::addCtxSet
({
237
238
239
240
  { 154, 155, 154, 140, },
  { 169, 141, 154, 155, },
  { 169, 170, 169, 170, },
  {  12,  12,  12,  12, },
241
242
243
244
});

const CtxSet ContextSetCfg::SkipFlag = ContextSetCfg::addCtxSet
({
245
  { 197, 214, 216, },
246
247
248
  { 211, 198, 185, },
  {   0, 152, 154, },
  {   5,   8,   8, },
249
250
251
252
});

const CtxSet ContextSetCfg::MergeFlag = ContextSetCfg::addCtxSet
({
253
254
  { 111, },
  { 111, },
255
256
  { 138, },
  {   5, },
257
});
258

259
260
const CtxSet ContextSetCfg::RegularMergeFlag = ContextSetCfg::addCtxSet
({
261
262
263
264
265
266
  { 142, 125, },
  { 141, 110, },
  { CNU, CNU, },
  {   4,   4, },
});

267
268
const CtxSet ContextSetCfg::MergeIdx = ContextSetCfg::addCtxSet
({
269
  { 137, },
270
  { 154, },
271
272
  { 138, },
  {   4, },
273
});
274

275
276
const CtxSet ContextSetCfg::MmvdFlag = ContextSetCfg::addCtxSet
({
277
278
  { 109, },
  { 124, },
279
  { CNU, },
280
  {   5, },
281
});
282
283
284

const CtxSet ContextSetCfg::MmvdMergeIdx = ContextSetCfg::addCtxSet
({
Frank Bossen's avatar
Frank Bossen committed
285
286
287
  { 154, },
  { 154, },
  { CNU, },
288
  {  10, },
289
});
290

291
292
const CtxSet ContextSetCfg::MmvdStepMvpIdx = ContextSetCfg::addCtxSet
({
293
294
  { 213, },
  { 244, },
295
  { CNU, },
296
  {   1, },
297
298
});

299
300
const CtxSet ContextSetCfg::PredMode = ContextSetCfg::addCtxSet
({
301
  { 192, 168, },
302
  { 179, 139, },
Xin Zhao's avatar
Xin Zhao committed
303
  { CNU, CNU, },
304
  {   5,   2, },
305
306
});

307
308
const CtxSet ContextSetCfg::MultiRefLineIdx = ContextSetCfg::addCtxSet
({
Frank Bossen's avatar
Frank Bossen committed
309
310
311
312
  {  90, 212, },
  { 118, 212, },
  { 134, 169, },
  {   8,   8, },
313
});
314

Frank Bossen's avatar
Frank Bossen committed
315
316
const CtxSet ContextSetCfg::IntraLumaMpmFlag = ContextSetCfg::addCtxSet
({
317
318
319
  { 154, },
  { 154, },
  { 170, },
320
  {   6, },
Frank Bossen's avatar
Frank Bossen committed
321
});
322

323
const CtxSet ContextSetCfg::IntraLumaPlanarFlag = ContextSetCfg::addCtxSet
324
({
325
326
327
328
  { 125, 125, },
  { 139, 139, },
  { 110, 154, },
  {   4,   5, },
329
330
});

Frank Bossen's avatar
Frank Bossen committed
331
const CtxSet ContextSetCfg::IntraChromaPredMode = ContextSetCfg::addCtxSet
332
({
333
334
335
336
  { 137, 139, 140, },
  { 138, 139, 169, },
  { 154, 154, 154, },
  {   5,   8,   8, },
337
338
});

339
340
const CtxSet ContextSetCfg::MipFlag = ContextSetCfg::addCtxSet
({
341
342
343
344
  { 181, 182, 183, 152, },
  { 181, 197, 183, 152, },
  { 165, 196, 168,  40, },
  {   9,  10,  10,   1, },
345
346
347
348
349
350
});

const CtxSet ContextSetCfg::MipMode = ContextSetCfg::addCtxSet
({
  { 196, },
  { 196, },
351
352
  { 182, },
  {   9, },
353
354
});

355
356
const CtxSet ContextSetCfg::DeltaQP = ContextSetCfg::addCtxSet
({
Frank Bossen's avatar
Frank Bossen committed
357
358
359
360
  { CNU, CNU, },
  { CNU, CNU, },
  { CNU, CNU, },
  { DWS, DWS, },
361
362
363
364
});

const CtxSet ContextSetCfg::InterDir = ContextSetCfg::addCtxSet
({
365
366
  { 111, 125,  95,  94, 164, },
  { 126, 111, 110, 109, 136, },
367
  { CNU, CNU, CNU, CNU, CNU, },
368
  {   0,   0,   1,   4,   0, },
369
370
371
372
});

const CtxSet ContextSetCfg::RefPic = ContextSetCfg::addCtxSet
({
373
374
375
  { 125, 139, },
  { 138, 168, },
  { CNU, CNU, },
376
  {   4,   5, },
377
378
});

379
380
381
382
383
384
385
386
387
388
#if JVET_O0500_SEP_CTX_AFFINE_SUBBLOCK_MRG
const CtxSet ContextSetCfg::SubblockMergeFlag = ContextSetCfg::addCtxSet
({
  { 183, 185, 187, },
  { 168, 169, 171, },
  { CNU, CNU, CNU, },
  {   4,   4,   4, },
  });
#endif

389
390
const CtxSet ContextSetCfg::AffineFlag = ContextSetCfg::addCtxSet
({
391
392
  { 183, 185, 187, },
  { 168, 169, 171, },
393
  { CNU, CNU, CNU, },
394
  {   4,   4,   4, },
395
396
397
398
});

const CtxSet ContextSetCfg::AffineType = ContextSetCfg::addCtxSet
({
399
  { 153, },
400
  { 153, },
401
  { CNU, },
402
  {   4, },
403
404
});

405
const CtxSet ContextSetCfg::AffMergeIdx = ContextSetCfg::addCtxSet
406
407
408
({
  { 110, },
  { 110, },
409
  { CNU, },
410
411
  {   0, },
});
412

413
414
const CtxSet ContextSetCfg::GBiIdx = ContextSetCfg::addCtxSet
({
415
  { 228, },
416
  { 228, },
417
  { CNU, },
418
  {   4, },
419
});
420

421
422
const CtxSet ContextSetCfg::Mvd = ContextSetCfg::addCtxSet
({
423
  { 169, 183, },
424
  { 155, 154, },
425
426
  { 126, 156, },
  {   9,   5, },
427
428
});

429
430
const CtxSet ContextSetCfg::BDPCMMode = ContextSetCfg::addCtxSet
({
431
432
433
434
  { 148, 154, },
  {   0, 140, },
  {  40, 169, },
  {   1,   4, },
435
436
});

437
438
const CtxSet ContextSetCfg::QtRootCbf = ContextSetCfg::addCtxSet
({
439
440
  {  94, },
  {  95, },
441
  { 110, },
442
  {   4, },
443
444
445
446
});

const CtxSet ContextSetCfg::QtCbf[] =
{
447
448
  ContextSetCfg::addCtxSet
  ({
449
450
451
452
453
454
#if JVET_O0193_REMOVE_TR_DEPTH_IN_CBF_CTX
    { 127, 111, 124, 140 },
    { 127,  79, 139, 126 },
    { 126, 138, 124, 111 },
    {   5,   1,   8,   8 },
#else
455
456
457
458
    { 142, 127, 124, 140, 111, },
    { 143, 127, 139, 126,  79, },
    { CNU, 126, 124, 111, 138, },
    {   1,   5,   8,   8,   1, },
459
#endif
460
  }),
461
462
  ContextSetCfg::addCtxSet
  ({
463
464
465
466
467
468
#if JVET_O0193_REMOVE_TR_DEPTH_IN_CBF_CTX
    { 163, },
    { 150, },
    { 124, },
    {   5, },
#else
Frank Bossen's avatar
Frank Bossen committed
469
470
471
472
    { 163, 135, },
    { 150, 121, },
    { 124, CNU, },
    {   5,   0, },
473
#endif
474
475
476
  }),
  ContextSetCfg::addCtxSet
  ({
477
478
479
480
481
    { 161, 155, },
    { 163, 155, },
    { 151, 141, },
    {   2,   2, },
  })
482
483
484
485
486
487
};

const CtxSet ContextSetCfg::SigCoeffGroup[] =
{
  ContextSetCfg::addCtxSet
  ({
488
    { 105, 170, },
489
490
    { 106, 156, },
    { 107, 158, },
491
    {   8,   5, },
492
493
494
  }),
  ContextSetCfg::addCtxSet
  ({
495
496
497
498
    { 105, 155, },
    { 105, 155, },
    {  90, 126, },
    {   5,   8, },
499
500
501
502
503
  }),
};

const CtxSet ContextSetCfg::SigFlag[] =
{
504
505
  ContextSetCfg::addCtxSet
  ({
506
507
508
509
    {  88, 166, 152, 182, 168, 154, 116, 167, 182, 168, 183, 155, 208, 213, 183, 183, 169, 185, },
    { 132, 152, 167, 168, 183, 140, 177, 182, 168, 154, 169, 155, 151, 213, 183, 169, 184, 156, },
    {  89, 138, 153, 139, 154, 140, 135, 139, 139, 140, 140, 141, 123, 185, 140, 170, 141, 157, },
    {  12,   9,   9,   9,   9,  10,   9,   9,   9,   9,   9,   9,   8,   8,   8,   8,   8,   9, },
510
511
512
  }),
  ContextSetCfg::addCtxSet
  ({
513
    {  27, 167, 153, 168, 139, 140, 180, 199, 183, 199, 199, 186, },
514
    { 133, 138, 153, 139, 154, 140, 181, 229, 169, 229, 170, 157, },
515
516
    { 104, 153, 168, 154, 154, 155, 167, 186, 170, 201, 171, 143, },
    {   9,   9,  12,   9,  12,  13,   5,   5,   8,   8,   8,   9, },
517
518
519
  }),
  ContextSetCfg::addCtxSet
  ({
520
521
522
523
    { 152, 156, 201, 186, 186, 187, 182, 249, 188, 232, 188, 191, 182, 223, 223, 223, 223, 223, },
    { 123, 142, 157, 172, 172, 218, 138, 250, 248, 248, 234, 223, 125, 223, 223, 223, 223, 223, },
    {  93, 142, 157, 143, 188, 175, 153, 223, 251, 223, 223, 238, 154, 223, 223, 223, 223, 223, },
    {   9,  12,   9,   8,   8,   8,   8,   8,   8,   8,   8,   5,   8,   0,   0,   0,   0,   0, },
524
525
526
  }),
  ContextSetCfg::addCtxSet
  ({
527
528
529
530
    { 182, 171, 157, 143, 172, 189, 183, 223, 223, 223, 223, 223, },
    { 168, 156, 173, 216, 172, 234, 169, 223, 223, 223, 223, 223, },
    { 138, 173, 142, 172, 189, 223, 170, 223, 223, 223, 223, 223, },
    {   8,   9,  12,   8,   8,   8,   4,   0,   0,   0,   0,   0, },
531
532
533
  }),
  ContextSetCfg::addCtxSet
  ({
534
535
536
537
    { 123, 159, 223, 223, 247, 237, 212, 223, 223, 237, 237, 223, 176, 223, 223, 223, 223, 223, },
    { 123, 191, 223, 190, 218, 223, 138, 223, 223, 223, 223, 223, 196, 223, 223, 223, 223, 223, },
    { 107, 175, 223, 223, 252, 223,  78, 223, 223, 238, 223, 238,  25, 223, 223, 223, 223, 223, },
    {   8,   8,   4,   8,   8,   8,   8,   0,   0,   4,   8,   4,   4,   0,   0,   0,   0,   0, },
538
539
540
  }),
  ContextSetCfg::addCtxSet
  ({
541
542
543
544
545
    { 167, 201, 223, 248, 219, 207, 181, 223, 223, 223, 223, 223, },
    { 167, 171, 223, 190, 248, 223, 152, 223, 223, 223, 223, 223, },
    { 137, 250, 223, 237, 234, 223, 123, 223, 223, 223, 223, 223, },
    {   8,   8,   1,   8,   8,   8,   4,   0,   0,   0,   0,   0, },
  })
546
547
};

548
549
550
551
const CtxSet ContextSetCfg::ParFlag[] =
{
  ContextSetCfg::addCtxSet
  ({
552
553
554
555
    { 121, 119, 121, 137, 152, 153, 119, 151, 152, 138, 168, 135, 152, 153, 168, 139, 151, 153, 139, 168, 154, },
    { 121, 104, 121, 137, 138, 153, 104, 122, 123, 153, 124, 106, 138, 153, 168, 139, 137, 153, 168, 139, 139, },
    { 121, 135, 137, 152, 138, 153,  91, 137, 138, 153, 139, 151, 138, 153, 139, 139, 138, 168, 139, 154, 139, },
    {   8,   9,  12,  13,  13,  13,  10,  13,  13,  13,  13,  13,  13,  13,  13,  13,  10,  13,  13,  13,  13, },
556
557
558
  }),
  ContextSetCfg::addCtxSet
  ({
559
560
561
562
563
    { 151, 120, 152, 138, 138, 138, 151, 168, 154, 153, 154, },
    { 150, 120, 137, 123, 138, 153, 136, 153, 168, 139, 154, },
    { 151, 135, 152, 153, 138, 153, 137, 168, 154, 139, 154, },
    {   9,  13,  12,  12,  13,  13,  10,  13,  13,  13,  13, },
  })
564
565
566
567
568
569
};

const CtxSet ContextSetCfg::GtxFlag[] =
{
  ContextSetCfg::addCtxSet
  ({
570
571
572
573
    { 104,   0, 102,  89, 150, 122,   0,  58, 134, 136, 138,   0, 148, 136, 152, 124, 133, 136, 138, 153, 140, },
    {  73,   0,  26, 104, 120, 137,   0,  57, 105, 136, 138, 116,  90, 107, 152, 153, 104, 107, 123, 153, 125, },
    { 119,  41, 148, 135, 136, 123,  43,  60, 106, 122, 109,  73, 106, 108, 109, 124, 136, 138, 139, 154, 111, },
    {   4,   5,   9,   9,   9,   6,   5,   9,  10,   9,   9,   9,   9,   9,   8,   9,   9,   8,   9,   8,   9, },
574
575
576
  }),
  ContextSetCfg::addCtxSet
  ({
577
578
579
580
    { 149,  56, 134, 136,  92, 123, 104, 122, 124, 140, 126, },
    { 103,   0,  90,  91,  92,  93, 103, 136, 138, 154, 140, },
    { 165,  87, 120, 122, 122, 123, 120, 137, 168, 154, 155, },
    {   2,   5,   8,   8,   8,   6,   6,   9,   8,   8,   8, },
581
582
583
  }),
  ContextSetCfg::addCtxSet
  ({
584
585
586
587
    {   0, 176, 151, 138, 139, 140, 162, 167, 139, 154, 155, 164, 153, 154, 169, 170, 181, 183, 184, 156, 157, },
    {   0, 133, 137, 138, 139, 125, 134, 138, 139, 154, 155, 136, 153, 154, 140, 170, 138, 154, 155, 170, 157, },
    { 134, 120, 123, 153, 139, 140, 121, 109, 139, 125, 111, 138, 154, 140, 155, 141, 154, 140, 185, 156, 143, },
    {   8,   5,   9,  13,  13,  10,   9,  10,  13,  13,  13,   9,  10,  10,  10,  10,   8,   9,   8,   9,  13, },
588
589
590
  }),
  ContextSetCfg::addCtxSet
  ({
591
592
593
594
595
    { 161, 178, 153, 154, 140, 140, 211, 170, 186, 157, 188, },
    {   0, 135, 153, 139, 125, 140, 182, 170, 156, 142, 159, },
    { 164, 151, 153, 154, 125, 140, 154, 170, 186, 172, 159, },
    {   6,   9,  10,  12,  12,  10,   5,   9,   9,   9,  12, },
  })
596
};
597
598
599
600
601

const CtxSet ContextSetCfg::LastX[] =
{
  ContextSetCfg::addCtxSet
  ({
Frank Bossen's avatar
Frank Bossen committed
602
603
604
605
    { 111, 111,  95, 111, 111, 124, 111, 126, 111, 124, 126, 126, 111, 111, 154, 154, 111, 110, 110, 124, },
    { 125, 110, 109, 125, 125, 123, 111, 111,  95, 123, 140, 111, 110,  95, 169, 125, 140, 139, 139, 138, },
    { 125, 110, 109, 140, 111, 109, 111, 111, 140, 123, 111, 126, 111, 140,  79, 155, 142, 141, 140, 198, },
    {   8,   5,   4,   5,   4,   4,   5,   4,   1,   0,   5,   1,   0,   0,   0,   1,   1,   0,   0,   0, },
606
607
608
  }),
  ContextSetCfg::addCtxSet
  ({
Frank Bossen's avatar
Frank Bossen committed
609
610
611
612
    { 137,  95,  63, },
    { 138, 123,  92, },
    { 109, 108,  77, },
    {   2,   1,   1, },
613
  })
614
615
616
617
618
619
};

const CtxSet ContextSetCfg::LastY[] =
{
  ContextSetCfg::addCtxSet
  ({
Frank Bossen's avatar
Frank Bossen committed
620
621
622
623
    { 125, 110, 139, 125, 111, 124, 111, 111,  95, 110, 140, 126, 110, 124, 155, 139, 111, 110, 124, 181, },
    {  95,  95, 109, 110, 110, 123, 125, 111, 124, 123, 140, 111, 110, 124, 154, 125, 126, 110, 124, 153, },
    { 110,  95,  94, 125, 125, 108, 111, 111,  95, 108, 111, 141, 111,  95,  78, 140, 186, 156, 125, 138, },
    {   8,   5,   8,   5,   5,   4,   5,   5,   4,   0,   5,   5,   1,   0,   0,   1,   4,   1,   0,   0, },
624
625
626
  }),
  ContextSetCfg::addCtxSet
  ({
Frank Bossen's avatar
Frank Bossen committed
627
628
629
630
    { 108, 124, 138, },
    { 108, 123,  92, },
    { 109,  94,  92, },
    {   3,   2,   2, },
631
  })
632
633
634
635
};

const CtxSet ContextSetCfg::MVPIdx = ContextSetCfg::addCtxSet
({
636
  { 153, },
637
  { 168, },
638
639
  { 153, },
  {  10, },
640
641
});

642
const CtxSet ContextSetCfg::SmvdFlag = ContextSetCfg::addCtxSet
643
({
644
  { 154, },
645
  { 139, },
646
  { CNU, },
647
648
  {   5, },
});
649

650
651
const CtxSet ContextSetCfg::SaoMergeFlag = ContextSetCfg::addCtxSet
({
652
  {  31, },
653
  { 244, },
654
655
  { 214, },
  {   0, },
656
657
658
659
});

const CtxSet ContextSetCfg::SaoTypeIdx = ContextSetCfg::addCtxSet
({
660
661
662
663
  {  46, },
  {  95, },
  {  95, },
  {   0, },
664
665
666
667
});

const CtxSet ContextSetCfg::TransquantBypassFlag = ContextSetCfg::addCtxSet
({
668
669
670
671
  { CNU, },
  { CNU, },
  { CNU, },
  { DWS, },
672
673
});

674
675
const CtxSet ContextSetCfg::LFNSTIdx = ContextSetCfg::addCtxSet
( {
676
677
678
679
  { 184, CNU, },
  { 155, CNU, },
  { 169, 155, },
  {   8,   8, },
680
681
} );

682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
#if JVET_O0119_BASE_PALETTE_444
const CtxSet ContextSetCfg::PLTFlag = ContextSetCfg::addCtxSet
({
	{ 146 },
	{ 146 },
	{ 147 },
	{ 1 }
});

const CtxSet ContextSetCfg::RotationFlag = ContextSetCfg::addCtxSet
({
	{ 153 },
	{ 138 },
	{ 168 },
	{ 5 }
});

const CtxSet ContextSetCfg::RunTypeFlag = ContextSetCfg::addCtxSet
({
	{ 167 },
	{ 167 },
	{ 167 },
	{ 8 }
});

const CtxSet ContextSetCfg::IdxRunModel = ContextSetCfg::addCtxSet
({
	{ 157, 169, 138, 170, 155 },
	{ 186, 169, 166, 186, 185 },
	{ 155, 168, 167, 155, 154 },
	{ 5,   6,   5,   9,  10 }
});

const CtxSet ContextSetCfg::CopyRunModel = ContextSetCfg::addCtxSet
({
	{ 187, 172, 156 },
	{ 187, 187, 185 },
	{ 201, 171, 155 },
	{ 0,   5,   5 }
});
#endif

724
725
const CtxSet ContextSetCfg::RdpcmFlag = ContextSetCfg::addCtxSet
({
726
727
728
729
  { CNU, CNU, },
  { CNU, CNU, },
  { CNU, CNU, },
  { DWS, DWS, },
730
731
732
733
});

const CtxSet ContextSetCfg::RdpcmDir = ContextSetCfg::addCtxSet
({
734
735
736
737
  { CNU, CNU, },
  { CNU, CNU, },
  { CNU, CNU, },
  { DWS, DWS, },
738
739
});

Tung Nguyen's avatar
Tung Nguyen committed
740
741
const CtxSet ContextSetCfg::MTSIndex = ContextSetCfg::addCtxSet
({
742
743
744
745
  { CNU, 141, 141, 140, 140, CNU, 218, 137, 153,   0, CNU, },
  { CNU, 141, 141, 126, 155, CNU, 250, 166, 153,   0, CNU, },
  { CNU, CNU, 139, 139, 154, CNU, 220,   0, 182, 161, CNU, },
  { DWS,   8,   8,   9,   8, DWS,   1,   0,   9,   0, DWS, },
746
747
});

748
749
const CtxSet ContextSetCfg::ISPMode = ContextSetCfg::addCtxSet
({
750
751
752
753
  { 165, 154, },
  { 150, 169, },
  { 151, 169, },
  {   9,   1, },
754
755
});

756
const CtxSet ContextSetCfg::SbtFlag = ContextSetCfg::addCtxSet
757
({
758
  { 197, 183, },
759
  { 211, 183, },
760
  { CNU, CNU, },
761
762
  {   4,   5, },
});
763
764

const CtxSet ContextSetCfg::SbtQuadFlag = ContextSetCfg::addCtxSet
765
({
766
767
768
  { 168, },
  { 168, },
  { CNU, },
769
770
  {   9, },
});
771
772

const CtxSet ContextSetCfg::SbtHorFlag = ContextSetCfg::addCtxSet
773
774
775
({
  { 139, 169, 139, },
  { 139, 154, 124, },
776
  { CNU, CNU, CNU, },
777
778
  {   8,   4,   4, },
});
779
780

const CtxSet ContextSetCfg::SbtPosFlag = ContextSetCfg::addCtxSet
781
({
782
783
784
  { 154, },
  { 154, },
  { CNU, },
785
786
  {  13, },
});
787

788
789
const CtxSet ContextSetCfg::CrossCompPred = ContextSetCfg::addCtxSet
({
790
791
792
793
  { CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, },
  { CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, },
  { CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, },
  { DWS, DWS, DWS, DWS, DWS, DWS, DWS, DWS, DWS, DWS, },
794
795
796
797
});

const CtxSet ContextSetCfg::ChromaQpAdjFlag = ContextSetCfg::addCtxSet
({
798
799
800
801
  { CNU, },
  { CNU, },
  { CNU, },
  { DWS, },
802
803
804
805
});

const CtxSet ContextSetCfg::ChromaQpAdjIdc = ContextSetCfg::addCtxSet
({
806
807
808
809
  { CNU, },
  { CNU, },
  { CNU, },
  { DWS, },
810
811
812
813
});

const CtxSet ContextSetCfg::ImvFlag = ContextSetCfg::addCtxSet
({
814
815
  { 212, 180, 183, 242, },
  { 213, 166, 198, 244, },
816
817
  { CNU, 182, CNU, CNU, },
  {   1,   5,   1,   0, },
818
819
});

820
821
822
823
824
825
826
const CtxSet ContextSetCfg::ctbAlfFlag = ContextSetCfg::addCtxSet
({
  { 167, 200, 174, 211, 247, 249, 151, 247, 249, },
  { 110, 142, 203, 168, 246, 248, 168, 246, 248, },
  { 223, 223, 223, 202, 204, 250, 202, 204, 221, },
  {   0,   0,   0,   0,   0,   0,   0,   0,   0, },
});
827

828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
const CtxSet ContextSetCfg::AlfUseLatestFilt = ContextSetCfg::addCtxSet
({
  { 169, },
  { 183, },
  { 159, },
  {   0, },
});

const CtxSet ContextSetCfg::AlfUseTemporalFilt = ContextSetCfg::addCtxSet
({
  { 201, },
  { 200, },
  { CNU, },
  {   0, },
});
843

844
845
const CtxSet ContextSetCfg::MHIntraFlag = ContextSetCfg::addCtxSet
({
846
847
  { 184, },
  { 185, },
848
  { CNU, },
849
  {   0, },
850
});
851
852


853

Yu Han's avatar
Yu Han committed
854
855
const CtxSet ContextSetCfg::IBCFlag = ContextSetCfg::addCtxSet
({
856
857
858
859
  {   0, 154, 156, },
  {   0, 153, 155, },
  { 133, 153, 154, },
  {   1,   5,   8, },
Yu Han's avatar
Yu Han committed
860
861
});

862
863
const CtxSet ContextSetCfg::JointCbCrFlag = ContextSetCfg::addCtxSet
({
864
865
866
867
868
869
#if JVET_O0105_ICT
  { 156, 156, 156, },
  { 156, 156, 156, },
  { 184, 184, 184, },
  {   1,   1,   1, },
#else
870
871
872
873
  { 156, },
  { 156, },
  { 184, },
  {   1, },
874
#endif
875
876
});

877
878
879
880
881
882
883
const CtxSet ContextSetCfg::TsSigCoeffGroup = ContextSetCfg::addCtxSet
({
  { 123, 139, 155, },
  { 123, 124, 140, },
  { 123, 139, 156, },
  {   5,   5,   5, },
});
884

885
886
887
888
889
890
891
const CtxSet ContextSetCfg::TsSigFlag = ContextSetCfg::addCtxSet
({
  { 150, 168, 140, },
  { 136, 124, 140, },
  { 135, 139, 126, },
  {  13,  13,   9, },
});
892

893
894
895
896
897
898
899
const CtxSet ContextSetCfg::TsParFlag = ContextSetCfg::addCtxSet
({
  { 123, },
  { 123, },
  { 138, },
  {   5, },
});
900

901
902
const CtxSet ContextSetCfg::TsGtxFlag = ContextSetCfg::addCtxSet
({
Frank Bossen's avatar
Frank Bossen committed
903
904
905
906
  { 124,  63,  79,  79,  95, },
  { 138,  47,  63,  63,  63, },
  { 124,  63,  63,  63,  63, },
  {   4,   1,   1,   1,   1, },
907
});
908

909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
#if JVET_O0122_TS_SIGN_LEVEL
const CtxSet ContextSetCfg::TsLrg1Flag = ContextSetCfg::addCtxSet
({
  { 139, 108, 124, 111 },
  { 122, 138, 139, 110 },
  { 123, 139, 110, 125 },
  {   4,   2,   1,   5 }
  });
#endif

#if JVET_O0122_TS_SIGN_LEVEL

const CtxSet ContextSetCfg::TsResidualSign =
{
  ContextSetCfg::addCtxSet
  ({
  { 139,  92, 201, 139, 122, 171 },
  { 124,  77, 171, 169, 121, 187 },
  { 124,  61, 187, 154, 121, 187 },
  {   1,   4,   1,   5,   5,   5 }
    }),
};

#else
933
934
935
936
const CtxSet ContextSetCfg::TsResidualSign =
{
  ContextSetCfg::addCtxSet
  ({
937
938
939
940
    { 154, 154, },
    { 139, 154, },
    { 124, 139, },
    {   1,   2, },
941
942
   }),
};
943
#endif
944
// clang-format on
945

946
947
948
949
const unsigned ContextSetCfg::NumberOfContexts = (unsigned)ContextSetCfg::sm_InitTables[0].size();


// combined sets
950
951
952
#if JVET_O0119_BASE_PALETTE_444 
const CtxSet ContextSetCfg::Palette = { ContextSetCfg::RotationFlag, ContextSetCfg::RunTypeFlag, ContextSetCfg::IdxRunModel, ContextSetCfg::CopyRunModel };
#endif
953
954
const CtxSet ContextSetCfg::Sao = { ContextSetCfg::SaoMergeFlag, ContextSetCfg::SaoTypeIdx };

955
const CtxSet ContextSetCfg::Alf = { ContextSetCfg::ctbAlfFlag, ContextSetCfg::AlfUseLatestFilt, ContextSetCfg::AlfUseTemporalFilt };
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980

template <class BinProbModel>
CtxStore<BinProbModel>::CtxStore()
  : m_CtxBuffer ()
  , m_Ctx       ( nullptr )
{}

template <class BinProbModel>
CtxStore<BinProbModel>::CtxStore( bool dummy )
  : m_CtxBuffer ( ContextSetCfg::NumberOfContexts )
  , m_Ctx       ( m_CtxBuffer.data() )
{}

template <class BinProbModel>
CtxStore<BinProbModel>::CtxStore( const CtxStore<BinProbModel>& ctxStore )
  : m_CtxBuffer ( ctxStore.m_CtxBuffer )
  , m_Ctx       ( m_CtxBuffer.data() )
{}

template <class BinProbModel>
void CtxStore<BinProbModel>::init( int qp, int initId )
{
  const std::vector<uint8_t>& initTable = ContextSetCfg::getInitTable( initId );
  CHECK( m_CtxBuffer.size() != initTable.size(),
        "Size of init table (" << initTable.size() << ") does not match size of context buffer (" << m_CtxBuffer.size() << ")." );
981
982
983
984
  const std::vector<uint8_t> &rateInitTable = ContextSetCfg::getInitTable(NUMBER_OF_SLICE_TYPES);
  CHECK(m_CtxBuffer.size() != rateInitTable.size(),
        "Size of rate init table (" << rateInitTable.size() << ") does not match size of context buffer ("
                                    << m_CtxBuffer.size() << ").");
985
  int clippedQP = Clip3( 0, MAX_QP, qp );
986
987
988
  for( std::size_t k = 0; k < m_CtxBuffer.size(); k++ )
  {
    m_CtxBuffer[k].init( clippedQP, initTable[k] );
989
    m_CtxBuffer[k].setLog2WindowSize(rateInitTable[k]);
990
991
992
993
994
995
996
997
998
999
1000
  }
}

template <class BinProbModel>
void CtxStore<BinProbModel>::setWinSizes( const std::vector<uint8_t>& log2WindowSizes )
{
  CHECK( m_CtxBuffer.size() != log2WindowSizes.size(),
        "Size of window size table (" << log2WindowSizes.size() << ") does not match size of context buffer (" << m_CtxBuffer.size() << ")." );
  for( std::size_t k = 0; k < m_CtxBuffer.size(); k++ )
  {
    m_CtxBuffer[k].setLog2WindowSize( log2WindowSizes[k] );