/work/vvenc/source/Lib/CommonLib/DepQuant.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) 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 | | |
43 | | #include "DepQuant.h" |
44 | | #include "TrQuant.h" |
45 | | #include "CodingStructure.h" |
46 | | #include "UnitTools.h" |
47 | | |
48 | | #include <bitset> |
49 | | |
50 | | //! \ingroup CommonLib |
51 | | //! \{ |
52 | | |
53 | | namespace vvenc { |
54 | | |
55 | | |
56 | | namespace DQIntern |
57 | | { |
58 | | static void findFirstPos( int& firstTestPos, const TCoeff* tCoeff, const DQIntern::TUParameters& tuPars, int defaultTh, |
59 | | bool zeroOutForThres, int zeroOutWidth, int zeroOutHeight ) |
60 | 1.78M | { |
61 | 197M | for( ; firstTestPos >= 0; firstTestPos-- ) |
62 | 196M | { |
63 | 196M | if( zeroOutForThres && ( tuPars.m_scanId2BlkPos[firstTestPos].x >= zeroOutWidth || |
64 | 23.7M | tuPars.m_scanId2BlkPos[firstTestPos].y >= zeroOutHeight ) ) |
65 | 0 | { |
66 | 0 | continue; |
67 | 0 | } |
68 | 196M | if( abs( tCoeff[tuPars.m_scanId2BlkPos[firstTestPos].idx] ) > defaultTh ) |
69 | 750k | { |
70 | 750k | break; |
71 | 750k | } |
72 | 196M | } |
73 | 1.78M | } |
74 | | |
75 | | void Rom::xInitScanArrays() |
76 | 1.15k | { |
77 | 1.15k | if( m_scansInitialized ) |
78 | 0 | { |
79 | 0 | return; |
80 | 0 | } |
81 | 1.15k | ::memset( m_scanId2NbInfoSbbArray, 0, sizeof(m_scanId2NbInfoSbbArray) ); |
82 | 1.15k | ::memset( m_scanId2NbInfoOutArray, 0, sizeof(m_scanId2NbInfoOutArray) ); |
83 | 1.15k | ::memset( m_tuParameters, 0, sizeof(m_tuParameters) ); |
84 | | |
85 | 1.15k | uint32_t raster2id[ MAX_CU_SIZE * MAX_CU_SIZE ]; |
86 | 1.15k | ::memset(raster2id, 0, sizeof(raster2id)); |
87 | | |
88 | 9.24k | for( int hd = 0; hd < MAX_TU_SIZE_IDX; hd++ ) |
89 | 8.09k | { |
90 | 64.7k | for( int vd = 0; vd < MAX_TU_SIZE_IDX; vd++ ) |
91 | 56.6k | { |
92 | 56.6k | if( (hd == 0 && vd <= 1) || (hd <= 1 && vd == 0) ) |
93 | 3.46k | { |
94 | 3.46k | continue; |
95 | 3.46k | } |
96 | 53.1k | const uint32_t blockWidth = (1 << hd); |
97 | 53.1k | const uint32_t blockHeight = (1 << vd); |
98 | 53.1k | const uint32_t log2CGWidth = g_log2SbbSize[hd][vd][0]; |
99 | 53.1k | const uint32_t log2CGHeight = g_log2SbbSize[hd][vd][1]; |
100 | 53.1k | const uint32_t groupWidth = 1 << log2CGWidth; |
101 | 53.1k | const uint32_t groupHeight = 1 << log2CGHeight; |
102 | 53.1k | const uint32_t groupSize = groupWidth * groupHeight; |
103 | 53.1k | const SizeType blkWidthIdx = Log2( blockWidth ); |
104 | 53.1k | const SizeType blkHeightIdx = Log2( blockHeight ); |
105 | 53.1k | const ScanElement * scanId2RP = getScanOrder( SCAN_GROUPED_4x4, blkWidthIdx, blkHeightIdx ); |
106 | 53.1k | NbInfoSbb*& sId2NbSbb = m_scanId2NbInfoSbbArray[hd][vd]; |
107 | 53.1k | NbInfoOut*& sId2NbOut = m_scanId2NbInfoOutArray[hd][vd]; |
108 | | // consider only non-zero-out region |
109 | 53.1k | const uint32_t blkWidthNZOut = std::min<unsigned>( JVET_C0024_ZERO_OUT_TH, blockWidth ); |
110 | 53.1k | const uint32_t blkHeightNZOut= std::min<unsigned>( JVET_C0024_ZERO_OUT_TH, blockHeight ); |
111 | 53.1k | const uint32_t totalValues = blkWidthNZOut * blkHeightNZOut; |
112 | | |
113 | 53.1k | sId2NbSbb = new NbInfoSbb[ totalValues ]; |
114 | 53.1k | sId2NbOut = new NbInfoOut[ totalValues ]; |
115 | | |
116 | 10.4M | for( uint32_t scanId = 0; scanId < totalValues; scanId++ ) |
117 | 10.4M | { |
118 | 10.4M | raster2id[scanId2RP[scanId].idx] = scanId; |
119 | 10.4M | sId2NbSbb[scanId].numInv = 0; |
120 | 10.4M | } |
121 | | |
122 | 10.4M | for( unsigned scanId = 0; scanId < totalValues; scanId++ ) |
123 | 10.4M | { |
124 | 10.4M | const int posX = scanId2RP[scanId].x; |
125 | 10.4M | const int posY = scanId2RP[scanId].y; |
126 | 10.4M | const int rpos = scanId2RP[scanId].idx; |
127 | 10.4M | { |
128 | | //===== inside subband neighbours ===== |
129 | 10.4M | const int begSbb = scanId - ( scanId & (groupSize-1) ); // first pos in current subblock |
130 | 10.4M | int cpos[5]; |
131 | | |
132 | 10.4M | cpos[0] = ( posX + 1 < blkWidthNZOut ? ( raster2id[rpos+1 ] < groupSize + begSbb ? raster2id[rpos+1 ] - begSbb : 0 ) : 0 ); |
133 | 10.4M | cpos[1] = ( posX + 2 < blkWidthNZOut ? ( raster2id[rpos+2 ] < groupSize + begSbb ? raster2id[rpos+2 ] - begSbb : 0 ) : 0 ); |
134 | 10.4M | cpos[2] = ( posX + 1 < blkWidthNZOut && posY + 1 < blkHeightNZOut ? ( raster2id[rpos+1+blockWidth] < groupSize + begSbb ? raster2id[rpos+1+blockWidth] - begSbb : 0 ) : 0 ); |
135 | 10.4M | cpos[3] = ( posY + 1 < blkHeightNZOut ? ( raster2id[rpos+ blockWidth] < groupSize + begSbb ? raster2id[rpos+ blockWidth] - begSbb : 0 ) : 0 ); |
136 | 10.4M | cpos[4] = ( posY + 2 < blkHeightNZOut ? ( raster2id[rpos+2*blockWidth] < groupSize + begSbb ? raster2id[rpos+2*blockWidth] - begSbb : 0 ) : 0 ); |
137 | | |
138 | 10.4M | int num = 0; |
139 | 10.4M | int inPos[5] = { 0, }; |
140 | | |
141 | 41.8M | while( true ) |
142 | 41.8M | { |
143 | 41.8M | int nk = -1; |
144 | 251M | for( int k = 0; k < 5; k++ ) |
145 | 209M | { |
146 | 209M | if( cpos[k] != 0 && ( nk < 0 || cpos[k] < cpos[nk] ) ) |
147 | 47.0M | { |
148 | 47.0M | nk = k; |
149 | 47.0M | } |
150 | 209M | } |
151 | 41.8M | if( nk < 0 ) |
152 | 10.4M | { |
153 | 10.4M | break; |
154 | 10.4M | } |
155 | 31.4M | inPos[ num++ ] = uint8_t( cpos[nk] ); |
156 | 31.4M | cpos[nk] = 0; |
157 | 31.4M | } |
158 | 31.1M | for( int k = num; k < 5; k++ ) |
159 | 20.7M | { |
160 | 20.7M | inPos[k] = 0; |
161 | 20.7M | } |
162 | 41.8M | for( int k = 0; k < num; k++ ) |
163 | 31.4M | { |
164 | 31.4M | CHECK( sId2NbSbb[begSbb + inPos[k]].numInv >= 5, "" ); |
165 | 31.4M | sId2NbSbb[begSbb + inPos[k]].invInPos[sId2NbSbb[begSbb + inPos[k]].numInv++] = scanId & ( groupSize - 1 ); |
166 | 31.4M | } |
167 | 10.4M | } |
168 | 10.4M | { |
169 | | //===== outside subband neighbours ===== |
170 | 10.4M | NbInfoOut& nbOut = sId2NbOut[ scanId ]; |
171 | 10.4M | const int begSbb = scanId - ( scanId & (groupSize-1) ); // first pos in current subblock |
172 | 10.4M | int cpos[5]; |
173 | | |
174 | 10.4M | cpos[0] = ( posX + 1 < blkWidthNZOut ? ( raster2id[rpos+1 ] >= groupSize + begSbb ? raster2id[rpos+1 ] : 0 ) : 0 ); |
175 | 10.4M | cpos[1] = ( posX + 2 < blkWidthNZOut ? ( raster2id[rpos+2 ] >= groupSize + begSbb ? raster2id[rpos+2 ] : 0 ) : 0 ); |
176 | 10.4M | cpos[2] = ( posX + 1 < blkWidthNZOut && posY + 1 < blkHeightNZOut ? ( raster2id[rpos+1+blockWidth] >= groupSize + begSbb ? raster2id[rpos+1+blockWidth] : 0 ) : 0 ); |
177 | 10.4M | cpos[3] = ( posY + 1 < blkHeightNZOut ? ( raster2id[rpos+ blockWidth] >= groupSize + begSbb ? raster2id[rpos+ blockWidth] : 0 ) : 0 ); |
178 | 10.4M | cpos[4] = ( posY + 2 < blkHeightNZOut ? ( raster2id[rpos+2*blockWidth] >= groupSize + begSbb ? raster2id[rpos+2*blockWidth] : 0 ) : 0 ); |
179 | | |
180 | 25.3M | for( nbOut.num = 0; true; ) |
181 | 25.3M | { |
182 | 25.3M | int nk = -1; |
183 | 151M | for( int k = 0; k < 5; k++ ) |
184 | 126M | { |
185 | 126M | if( cpos[k] != 0 && ( nk < 0 || cpos[k] < cpos[nk] ) ) |
186 | 21.8M | { |
187 | 21.8M | nk = k; |
188 | 21.8M | } |
189 | 126M | } |
190 | 25.3M | if( nk < 0 ) |
191 | 10.4M | { |
192 | 10.4M | break; |
193 | 10.4M | } |
194 | 14.8M | nbOut.outPos[ nbOut.num++ ] = uint16_t( cpos[nk] ); |
195 | 14.8M | cpos[nk] = 0; |
196 | 14.8M | } |
197 | 47.6M | for( int k = nbOut.num; k < 5; k++ ) |
198 | 37.2M | { |
199 | 37.2M | nbOut.outPos[k] = 0; |
200 | 37.2M | } |
201 | 10.4M | nbOut.maxDist = ( scanId == 0 ? 0 : sId2NbOut[scanId-1].maxDist ); |
202 | 25.3M | for( int k = 0; k < nbOut.num; k++ ) |
203 | 14.8M | { |
204 | 14.8M | if( nbOut.outPos[k] > nbOut.maxDist ) |
205 | 1.60M | { |
206 | 1.60M | nbOut.maxDist = nbOut.outPos[k]; |
207 | 1.60M | } |
208 | 14.8M | } |
209 | 10.4M | } |
210 | 10.4M | } |
211 | | |
212 | | // make it relative |
213 | 10.4M | for( unsigned scanId = 0; scanId < totalValues; scanId++ ) |
214 | 10.4M | { |
215 | 10.4M | NbInfoOut& nbOut = sId2NbOut[scanId]; |
216 | 10.4M | const int begSbb = scanId - ( scanId & (groupSize-1) ); // first pos in current subblock |
217 | 25.3M | for( int k = 0; k < nbOut.num; k++ ) |
218 | 14.8M | { |
219 | 14.8M | CHECK(begSbb > nbOut.outPos[k], "Position must be past sub block begin"); |
220 | 14.8M | nbOut.outPos[k] -= begSbb; |
221 | 14.8M | } |
222 | 10.4M | nbOut.maxDist -= scanId; |
223 | 10.4M | } |
224 | | |
225 | 159k | for( int chId = 0; chId < MAX_NUM_CH; chId++ ) |
226 | 106k | { |
227 | 106k | m_tuParameters[hd][vd][chId] = new TUParameters( *this, blockWidth, blockHeight, ChannelType(chId) ); |
228 | 106k | } |
229 | 53.1k | } |
230 | 8.09k | } |
231 | 1.15k | m_scansInitialized = true; |
232 | 1.15k | } |
233 | | |
234 | | void Rom::xUninitScanArrays() |
235 | 1.15k | { |
236 | 1.15k | if( !m_scansInitialized ) |
237 | 0 | { |
238 | 0 | return; |
239 | 0 | } |
240 | 9.24k | for( int hd = 0; hd < MAX_TU_SIZE_IDX; hd++ ) |
241 | 8.09k | { |
242 | 64.7k | for( int vd = 0; vd < MAX_TU_SIZE_IDX; vd++ ) |
243 | 56.6k | { |
244 | 56.6k | NbInfoSbb*& sId2NbSbb = m_scanId2NbInfoSbbArray[hd][vd]; |
245 | 56.6k | NbInfoOut*& sId2NbOut = m_scanId2NbInfoOutArray[hd][vd]; |
246 | 56.6k | if( sId2NbSbb ) |
247 | 53.1k | { |
248 | 53.1k | delete [] sId2NbSbb; |
249 | 53.1k | } |
250 | 56.6k | if( sId2NbOut ) |
251 | 53.1k | { |
252 | 53.1k | delete [] sId2NbOut; |
253 | 53.1k | } |
254 | 169k | for( int chId = 0; chId < MAX_NUM_CH; chId++ ) |
255 | 113k | { |
256 | 113k | TUParameters*& tuPars = m_tuParameters[hd][vd][chId]; |
257 | 113k | if( tuPars ) |
258 | 106k | { |
259 | 106k | delete tuPars; |
260 | 106k | } |
261 | 113k | } |
262 | 56.6k | } |
263 | 8.09k | } |
264 | 1.15k | m_scansInitialized = false; |
265 | 1.15k | } |
266 | | |
267 | | |
268 | | TUParameters::TUParameters( const Rom& rom, const unsigned width, const unsigned height, const ChannelType chType ) |
269 | 106k | { |
270 | 106k | m_chType = chType; |
271 | 106k | m_width = width; |
272 | 106k | m_height = height; |
273 | 106k | const uint32_t nonzeroWidth = std::min<uint32_t>(JVET_C0024_ZERO_OUT_TH, m_width); |
274 | 106k | const uint32_t nonzeroHeight = std::min<uint32_t>(JVET_C0024_ZERO_OUT_TH, m_height); |
275 | 106k | m_numCoeff = nonzeroWidth * nonzeroHeight; |
276 | 106k | m_log2SbbWidth = g_log2SbbSize[ Log2(m_width) ][ Log2(m_height) ][0]; |
277 | 106k | m_log2SbbHeight = g_log2SbbSize[ Log2(m_width) ][ Log2(m_height) ][1]; |
278 | 106k | m_log2SbbSize = m_log2SbbWidth + m_log2SbbHeight; |
279 | 106k | m_sbbSize = ( 1 << m_log2SbbSize ); |
280 | 106k | m_sbbMask = m_sbbSize - 1; |
281 | 106k | m_widthInSbb = nonzeroWidth >> m_log2SbbWidth; |
282 | 106k | m_heightInSbb = nonzeroHeight >> m_log2SbbHeight; |
283 | 106k | m_numSbb = m_widthInSbb * m_heightInSbb; |
284 | 106k | SizeType hsbb = Log2( m_widthInSbb ); |
285 | 106k | SizeType vsbb = Log2( m_heightInSbb ); |
286 | 106k | SizeType hsId = Log2( m_width ); |
287 | 106k | SizeType vsId = Log2( m_height ); |
288 | 106k | m_scanSbbId2SbbPos = getScanOrder( SCAN_UNGROUPED , hsbb , vsbb ); |
289 | 106k | m_scanId2BlkPos = getScanOrder( SCAN_GROUPED_4x4 , hsId , vsId ); |
290 | 106k | int log2W = Log2( m_width ); |
291 | 106k | int log2H = Log2( m_height ); |
292 | 106k | m_scanId2NbInfoSbb = rom.getNbInfoSbb( log2W, log2H ); |
293 | 106k | m_scanId2NbInfoOut = rom.getNbInfoOut( log2W, log2H ); |
294 | 106k | m_scanInfo = new ScanInfo[ m_numCoeff ]; |
295 | 20.9M | for( int scanIdx = 0; scanIdx < m_numCoeff; scanIdx++ ) |
296 | 20.8M | { |
297 | 20.8M | xSetScanInfo( m_scanInfo[scanIdx], scanIdx ); |
298 | 20.8M | } |
299 | 106k | } |
300 | | |
301 | | |
302 | | void TUParameters::xSetScanInfo( ScanInfo& scanInfo, int scanIdx ) |
303 | 20.8M | { |
304 | 20.8M | scanInfo.sbbSize = m_sbbSize; |
305 | 20.8M | scanInfo.numSbb = m_numSbb; |
306 | 20.8M | scanInfo.scanIdx = scanIdx; |
307 | 20.8M | scanInfo.rasterPos = m_scanId2BlkPos[scanIdx].idx; |
308 | 20.8M | scanInfo.sbbPos = m_scanSbbId2SbbPos[scanIdx >> m_log2SbbSize].idx; |
309 | 20.8M | scanInfo.insidePos = scanIdx & m_sbbMask; |
310 | 20.8M | scanInfo.spt = SCAN_ISCSBB; |
311 | 20.8M | if( scanInfo.insidePos == m_sbbMask && scanIdx > scanInfo.sbbSize && scanIdx < m_numCoeff - 1 ) |
312 | 1.12M | scanInfo.spt = SCAN_SOCSBB; |
313 | 19.7M | else if( scanInfo.insidePos == 0 && scanIdx > 0 && scanIdx < m_numCoeff - m_sbbSize ) |
314 | 1.12M | scanInfo.spt = SCAN_EOCSBB; |
315 | 20.8M | scanInfo.posX = m_scanId2BlkPos[scanIdx].x; |
316 | 20.8M | scanInfo.posY = m_scanId2BlkPos[scanIdx].y; |
317 | 20.8M | if( scanIdx ) |
318 | 20.7M | { |
319 | 20.7M | const int nextScanIdx = scanIdx - 1; |
320 | 20.7M | const int diag = m_scanId2BlkPos[nextScanIdx].x + m_scanId2BlkPos[nextScanIdx].y; |
321 | 20.7M | if( m_chType == CH_L ) |
322 | 10.3M | { |
323 | 10.3M | scanInfo.sigCtxOffsetNext = ( diag < 2 ? 8 : diag < 5 ? 4 : 0 ); |
324 | 10.3M | scanInfo.gtxCtxOffsetNext = ( diag < 1 ? 16 : diag < 3 ? 11 : diag < 10 ? 6 : 1 ); |
325 | 10.3M | } |
326 | 10.3M | else |
327 | 10.3M | { |
328 | 10.3M | scanInfo.sigCtxOffsetNext = ( diag < 2 ? 4 : 0 ); |
329 | 10.3M | scanInfo.gtxCtxOffsetNext = ( diag < 1 ? 6 : 1 ); |
330 | 10.3M | } |
331 | 20.7M | scanInfo.nextInsidePos = nextScanIdx & m_sbbMask; |
332 | 20.7M | scanInfo.currNbInfoSbb = m_scanId2NbInfoSbb[ scanIdx ]; |
333 | 20.7M | if( scanInfo.insidePos == 0 ) |
334 | 1.21M | { |
335 | 1.21M | const int nextSbbPos = m_scanSbbId2SbbPos[nextScanIdx >> m_log2SbbSize].idx; |
336 | 1.21M | const int nextSbbPosY = nextSbbPos / m_widthInSbb; |
337 | 1.21M | const int nextSbbPosX = nextSbbPos - nextSbbPosY * m_widthInSbb; |
338 | 1.21M | scanInfo.nextSbbRight = ( nextSbbPosX < m_widthInSbb - 1 ? nextSbbPos + 1 : 0 ); |
339 | 1.21M | scanInfo.nextSbbBelow = ( nextSbbPosY < m_heightInSbb - 1 ? nextSbbPos + m_widthInSbb : 0 ); |
340 | 1.21M | } |
341 | 20.7M | } |
342 | 20.8M | } |
343 | | |
344 | | void RateEstimator::initCtx( const TUParameters& tuPars, const TransformUnit& tu, const ComponentID compID, const FracBitsAccess& fracBitsAccess ) |
345 | 750k | { |
346 | 750k | m_scanId2Pos = tuPars.m_scanId2BlkPos; |
347 | 750k | xSetSigSbbFracBits ( fracBitsAccess, tuPars.m_chType ); |
348 | 750k | xSetSigFlagBits ( fracBitsAccess, tuPars.m_chType ); |
349 | 750k | xSetGtxFlagBits ( fracBitsAccess, tuPars.m_chType ); |
350 | 750k | xSetLastCoeffOffset ( fracBitsAccess, tuPars, tu, compID ); |
351 | 750k | } |
352 | | |
353 | | void RateEstimator::xSetLastCoeffOffset( const FracBitsAccess& fracBitsAccess, const TUParameters& tuPars, const TransformUnit& tu, const ComponentID compID ) |
354 | 750k | { |
355 | 750k | const ChannelType chType = ( compID == COMP_Y ? CH_L : CH_C ); |
356 | 750k | int32_t cbfDeltaBits = 0; |
357 | 750k | if( compID == COMP_Y && !CU::isIntra(*tu.cu) && !tu.depth ) |
358 | 266 | { |
359 | 266 | const BinFracBits bits = fracBitsAccess.getFracBitsArray( Ctx::QtRootCbf() ); |
360 | 266 | cbfDeltaBits = int32_t( bits.intBits[1] ) - int32_t( bits.intBits[0] ); |
361 | 266 | } |
362 | 750k | else |
363 | 750k | { |
364 | 750k | BinFracBits bits; |
365 | 750k | bool prevLumaCbf = false; |
366 | 750k | bool lastCbfIsInferred = false; |
367 | 750k | bool useIntraSubPartitions = tu.cu->ispMode && isLuma(chType); |
368 | 750k | if( useIntraSubPartitions ) |
369 | 10.9k | { |
370 | 10.9k | bool rootCbfSoFar = false; |
371 | 10.9k | bool isLastSubPartition = CU::isISPLast(*tu.cu, tu.Y(), compID); |
372 | 10.9k | uint32_t nTus = tu.cu->ispMode == HOR_INTRA_SUBPARTITIONS ? tu.cu->lheight() >> Log2(tu.lheight()) : tu.cu->lwidth() >> Log2(tu.lwidth()); |
373 | 10.9k | if( isLastSubPartition ) |
374 | 203 | { |
375 | 203 | TransformUnit* tuPointer = tu.cu->firstTU; |
376 | 812 | for( int tuIdx = 0; tuIdx < nTus - 1; tuIdx++ ) |
377 | 609 | { |
378 | 609 | rootCbfSoFar |= TU::getCbfAtDepth(*tuPointer, COMP_Y, tu.depth); |
379 | 609 | tuPointer = tuPointer->next; |
380 | 609 | } |
381 | 203 | if( !rootCbfSoFar ) |
382 | 0 | { |
383 | 0 | lastCbfIsInferred = true; |
384 | 0 | } |
385 | 203 | } |
386 | 10.9k | if( !lastCbfIsInferred ) |
387 | 10.9k | { |
388 | 10.9k | prevLumaCbf = TU::getPrevTuCbfAtDepth(tu, compID, tu.depth); |
389 | 10.9k | } |
390 | 10.9k | bits = fracBitsAccess.getFracBitsArray(Ctx::QtCbf[compID](DeriveCtx::CtxQtCbf(compID, prevLumaCbf, true))); |
391 | 10.9k | } |
392 | 739k | else |
393 | 739k | { |
394 | 739k | bits = fracBitsAccess.getFracBitsArray(Ctx::QtCbf[compID](DeriveCtx::CtxQtCbf(compID, tu.cbf[COMP_Cb]))); |
395 | 739k | } |
396 | 750k | cbfDeltaBits = lastCbfIsInferred ? 0 : int32_t(bits.intBits[1]) - int32_t(bits.intBits[0]); |
397 | 750k | } |
398 | | |
399 | 750k | static const unsigned prefixCtx[] = { 0, 0, 0, 3, 6, 10, 15, 21 }; |
400 | 750k | uint32_t ctxBits [ LAST_SIGNIFICANT_GROUPS ]; |
401 | 2.25M | for( unsigned xy = 0; xy < 2; xy++ ) |
402 | 1.50M | { |
403 | 1.50M | int32_t bitOffset = ( xy ? cbfDeltaBits : 0 ); |
404 | 1.50M | int32_t* lastBits = ( xy ? m_lastBitsY : m_lastBitsX ); |
405 | 1.50M | const unsigned size = ( xy ? tuPars.m_height : tuPars.m_width ); |
406 | 1.50M | const unsigned log2Size = Log2( size ); |
407 | 1.50M | const bool useYCtx = ( xy != 0 ); |
408 | 1.50M | const CtxSet& ctxSetLast = ( useYCtx ? Ctx::LastY : Ctx::LastX )[ chType ]; |
409 | 1.50M | const unsigned lastShift = ( compID == COMP_Y ? (log2Size+1)>>2 : Clip3<unsigned>(0,2,size>>3) ); |
410 | 1.50M | const unsigned lastOffset = ( compID == COMP_Y ? ( prefixCtx[log2Size] ) : 0 ); |
411 | 1.50M | uint32_t sumFBits = 0; |
412 | 1.50M | unsigned maxCtxId = g_uiGroupIdx[std::min<unsigned>(JVET_C0024_ZERO_OUT_TH, size) - 1]; |
413 | 10.0M | for( unsigned ctxId = 0; ctxId < maxCtxId; ctxId++ ) |
414 | 8.52M | { |
415 | 8.52M | const BinFracBits bits = fracBitsAccess.getFracBitsArray( ctxSetLast( lastOffset + ( ctxId >> lastShift ) ) ); |
416 | 8.52M | ctxBits[ ctxId ] = sumFBits + bits.intBits[0] + ( ctxId>3 ? ((ctxId-2)>>1)<<SCALE_BITS : 0 ) + bitOffset; |
417 | 8.52M | sumFBits += bits.intBits[1]; |
418 | 8.52M | } |
419 | 1.50M | ctxBits [ maxCtxId ] = sumFBits + ( maxCtxId>3 ? ((maxCtxId-2)>>1)<<SCALE_BITS : 0 ) + bitOffset; |
420 | 20.8M | for (unsigned pos = 0; pos < std::min<unsigned>(JVET_C0024_ZERO_OUT_TH, size); pos++) |
421 | 19.3M | { |
422 | 19.3M | lastBits[ pos ] = ctxBits[ g_uiGroupIdx[ pos ] ]; |
423 | 19.3M | } |
424 | 1.50M | } |
425 | 750k | } |
426 | | |
427 | | void RateEstimator::xSetSigSbbFracBits( const FracBitsAccess& fracBitsAccess, ChannelType chType ) |
428 | 750k | { |
429 | 750k | const CtxSet& ctxSet = Ctx::SigCoeffGroup[ chType ]; |
430 | 2.25M | for( unsigned ctxId = 0; ctxId < sm_maxNumSigSbbCtx; ctxId++ ) |
431 | 1.50M | { |
432 | 1.50M | m_sigSbbFracBits[ ctxId ] = fracBitsAccess.getFracBitsArray( ctxSet( ctxId ) ); |
433 | 1.50M | } |
434 | 750k | } |
435 | | |
436 | | void RateEstimator::xSetSigFlagBits( const FracBitsAccess& fracBitsAccess, ChannelType chType ) |
437 | 750k | { |
438 | 3.00M | for( unsigned ctxSetId = 0; ctxSetId < sm_numCtxSetsSig; ctxSetId++ ) |
439 | 2.25M | { |
440 | 2.25M | BinFracBits* bits = m_sigFracBits [ ctxSetId ]; |
441 | 2.25M | const CtxSet& ctxSet = Ctx::SigFlag [ chType + 2*ctxSetId ]; |
442 | 2.25M | const unsigned numCtx = ( chType == CH_L ? 12 : 8 ); |
443 | 20.6M | for( unsigned ctxId = 0; ctxId < numCtx; ctxId++ ) |
444 | 18.3M | { |
445 | 18.3M | bits[ ctxId ] = fracBitsAccess.getFracBitsArray( ctxSet( ctxId ) ); |
446 | 18.3M | } |
447 | 2.25M | } |
448 | 750k | } |
449 | | |
450 | | void RateEstimator::xSetGtxFlagBits( const FracBitsAccess& fracBitsAccess, ChannelType chType ) |
451 | 750k | { |
452 | 750k | const CtxSet& ctxSetPar = Ctx::ParFlag [ chType ]; |
453 | 750k | const CtxSet& ctxSetGt1 = Ctx::GtxFlag [ 2 + chType ]; |
454 | 750k | const CtxSet& ctxSetGt2 = Ctx::GtxFlag [ chType ]; |
455 | 750k | const unsigned numCtx = ( chType == CH_L ? 21 : 11 ); |
456 | 9.29M | for( unsigned ctxId = 0; ctxId < numCtx; ctxId++ ) |
457 | 8.54M | { |
458 | 8.54M | BinFracBits fbPar = fracBitsAccess.getFracBitsArray( ctxSetPar( ctxId ) ); |
459 | 8.54M | BinFracBits fbGt1 = fracBitsAccess.getFracBitsArray( ctxSetGt1( ctxId ) ); |
460 | 8.54M | BinFracBits fbGt2 = fracBitsAccess.getFracBitsArray( ctxSetGt2( ctxId ) ); |
461 | 8.54M | CoeffFracBits& cb = m_gtxFracBits[ ctxId ]; |
462 | 8.54M | int32_t par0 = (1<<SCALE_BITS) + int32_t(fbPar.intBits[0]); |
463 | 8.54M | int32_t par1 = (1<<SCALE_BITS) + int32_t(fbPar.intBits[1]); |
464 | 8.54M | cb.bits[0] = 0; |
465 | 8.54M | cb.bits[1] = fbGt1.intBits[0] + (1 << SCALE_BITS); |
466 | 8.54M | cb.bits[2] = fbGt1.intBits[1] + par0 + fbGt2.intBits[0]; |
467 | 8.54M | cb.bits[3] = fbGt1.intBits[1] + par1 + fbGt2.intBits[0]; |
468 | 8.54M | cb.bits[4] = fbGt1.intBits[1] + par0 + fbGt2.intBits[1]; |
469 | 8.54M | cb.bits[5] = fbGt1.intBits[1] + par1 + fbGt2.intBits[1]; |
470 | 8.54M | } |
471 | 750k | } |
472 | | |
473 | | void CommonCtx::update( const ScanInfo& scanInfo, const int prevId, int stateId, StateMem& curr ) |
474 | 116k | { |
475 | 116k | uint8_t* sbbFlags = m_currSbbCtx[stateId].sbbFlags; |
476 | 116k | uint8_t* levels = m_currSbbCtx[stateId].levels; |
477 | 116k | uint16_t maxDist = m_nbInfo[scanInfo.scanIdx - 1].maxDist; |
478 | 116k | uint16_t sbbSize = scanInfo.sbbSize; |
479 | 116k | std::size_t setCpSize = ( maxDist > sbbSize ? maxDist - sbbSize : 0 ) * sizeof( uint8_t ); |
480 | 116k | if( prevId >= 0 ) |
481 | 96.0k | { |
482 | 96.0k | ::memcpy( sbbFlags, m_prevSbbCtx[prevId].sbbFlags, scanInfo.numSbb * sizeof( uint8_t ) ); |
483 | 96.0k | ::memcpy( levels + scanInfo.scanIdx + sbbSize, m_prevSbbCtx[prevId].levels + scanInfo.scanIdx + sbbSize, setCpSize ); |
484 | 96.0k | } |
485 | 20.2k | else |
486 | 20.2k | { |
487 | 20.2k | ::memset( sbbFlags, 0, scanInfo.numSbb * sizeof( uint8_t ) ); |
488 | 20.2k | ::memset( levels + scanInfo.scanIdx + sbbSize, 0, setCpSize ); |
489 | 20.2k | } |
490 | 116k | sbbFlags[scanInfo.sbbPos] = !!curr.numSig[stateId]; |
491 | | |
492 | 116k | const int sigNSbb = ( ( scanInfo.nextSbbRight ? sbbFlags[scanInfo.nextSbbRight] : false ) || ( scanInfo.nextSbbBelow ? sbbFlags[scanInfo.nextSbbBelow] : false ) ? 1 : 0 ); |
493 | 116k | curr.refSbbCtxId[stateId] = stateId; |
494 | 116k | const BinFracBits sbbBits = m_sbbFlagBits[sigNSbb]; |
495 | | |
496 | 116k | curr.sbbBits0[stateId] = sbbBits.intBits[0]; |
497 | 116k | curr.sbbBits1[stateId] = sbbBits.intBits[1]; |
498 | | |
499 | 116k | if( sigNSbb || ( ( scanInfo.nextSbbRight && scanInfo.nextSbbBelow ) ? sbbFlags[scanInfo.nextSbbBelow + 1] : false ) ) |
500 | 72.5k | { |
501 | 72.5k | const int scanBeg = scanInfo.scanIdx - scanInfo.sbbSize; |
502 | 72.5k | const NbInfoOut* nbOut = m_nbInfo + scanBeg; |
503 | 72.5k | const uint8_t* absLevels = levels + scanBeg; |
504 | | |
505 | 1.23M | for( int id = 0; id < scanInfo.sbbSize; id++, nbOut++ ) |
506 | 1.16M | { |
507 | 1.16M | if( nbOut->num ) |
508 | 780k | { |
509 | 780k | TCoeff sumAbs = 0, sumAbs1 = 0, sumNum = 0; |
510 | 1.89M | #define UPDATE(k) {TCoeff t=absLevels[nbOut->outPos[k]]; sumAbs+=t; sumAbs1+=std::min<TCoeff>(4+(t&1),t); sumNum+=!!t; } |
511 | 780k | switch( nbOut->num ) |
512 | 780k | { |
513 | 0 | default: |
514 | 50.4k | case 5: |
515 | 50.4k | UPDATE( 4 ); |
516 | 151k | case 4: |
517 | 151k | UPDATE( 3 ); |
518 | 418k | case 3: |
519 | 418k | UPDATE( 2 ); |
520 | 491k | case 2: |
521 | 491k | UPDATE( 1 ); |
522 | 780k | case 1: |
523 | 780k | UPDATE( 0 ); |
524 | 780k | } |
525 | 780k | #undef UPDATE |
526 | 780k | curr.tplAcc[id][stateId] = ( sumNum << 5 ) | sumAbs1; |
527 | 780k | curr.sum1st[id][stateId] = ( uint8_t ) std::min( 255, sumAbs ); |
528 | 780k | } |
529 | 1.16M | } |
530 | 72.5k | } |
531 | 116k | } |
532 | | |
533 | | void Quantizer::initQuantBlock(const TransformUnit& tu, const ComponentID compID, const QpParam& cQP, const double lambda, int gValue) |
534 | 1.78M | { |
535 | 1.78M | CHECKD( lambda <= 0.0, "Lambda must be greater than 0" ); |
536 | | |
537 | 1.78M | const int qpDQ = cQP.Qp(tu.mtsIdx[compID]==MTS_SKIP) + 1; |
538 | 1.78M | const int qpPer = qpDQ / 6; |
539 | 1.78M | const int qpRem = qpDQ - 6 * qpPer; |
540 | 1.78M | const SPS& sps = *tu.cs->sps; |
541 | 1.78M | const CompArea& area = tu.blocks[ compID ]; |
542 | 1.78M | const ChannelType chType = toChannelType( compID ); |
543 | 1.78M | const int channelBitDepth = sps.bitDepths[ chType ]; |
544 | 1.78M | const int maxLog2TrDynamicRange = sps.getMaxLog2TrDynamicRange(); |
545 | 1.78M | const int nomTransformShift = getTransformShift( channelBitDepth, area.size(), maxLog2TrDynamicRange ); |
546 | 1.78M | const bool needsSqrt2ScaleAdjustment = TU::needsSqrt2Scale(tu, compID); |
547 | 1.78M | const int transformShift = nomTransformShift + (needsSqrt2ScaleAdjustment?-1:0); |
548 | | // quant parameters |
549 | 1.78M | m_QShift = QUANT_SHIFT - 1 + qpPer + transformShift; |
550 | 1.78M | m_QAdd = -( ( 3 << m_QShift ) >> 1 ); |
551 | 1.78M | Intermediate_Int invShift = IQUANT_SHIFT + 1 - qpPer - transformShift; |
552 | 1.78M | m_QScale = g_quantScales[needsSqrt2ScaleAdjustment?1:0][ qpRem ]; |
553 | 1.78M | const unsigned qIdxBD = std::min<unsigned>( maxLog2TrDynamicRange + 1, 8*sizeof(Intermediate_Int) + invShift - IQUANT_SHIFT - 1 ); |
554 | 1.78M | m_maxQIdx = ( 1 << (qIdxBD-1) ) - 4; |
555 | 1.78M | if( m_QShift ) |
556 | 1.78M | m_thresLast = TCoeff((int64_t(m_DqThrVal) << (m_QShift-1))); |
557 | 21 | else |
558 | 21 | m_thresLast = TCoeff((int64_t(m_DqThrVal>>1) << m_QShift)); |
559 | 1.78M | m_thresSSbb = TCoeff((int64_t(3) << m_QShift)); |
560 | | // distortion calculation parameters |
561 | 1.78M | const int64_t qScale = (gValue==-1) ? m_QScale : gValue; |
562 | 1.78M | const int nomDShift = |
563 | 1.78M | SCALE_BITS - 2 * (nomTransformShift + DISTORTION_PRECISION_ADJUSTMENT(channelBitDepth)) + m_QShift + (needsSqrt2ScaleAdjustment ? 1 : 0); |
564 | 1.78M | const double qScale2 = double( qScale * qScale ); |
565 | 1.78M | const double nomDistFactor = ( nomDShift < 0 ? 1.0/(double(int64_t(1)<<(-nomDShift))*qScale2*lambda) : double(int64_t(1)<<nomDShift)/(qScale2*lambda) ); |
566 | 1.78M | const uint32_t pow2dfShift = (uint32_t)( nomDistFactor * qScale2 ) + 1; |
567 | 1.78M | const int dfShift = ceilLog2( pow2dfShift ); |
568 | 1.78M | m_DistShift = 62 + m_QShift - 2*maxLog2TrDynamicRange - dfShift; |
569 | 1.78M | m_DistAdd = (int64_t(1) << m_DistShift) >> 1; |
570 | 1.78M | m_DistStepAdd = ((m_DistShift+m_QShift)>=64 ? (int64_t)( nomDistFactor * pow(2,m_DistShift+m_QShift) + .5 ) : (int64_t)( nomDistFactor * double(int64_t(1)<<(m_DistShift+m_QShift)) + .5 )); |
571 | 1.78M | m_DistOrgFact = (int64_t)( nomDistFactor * double(int64_t(1)<<(m_DistShift+1 )) + .5 ); |
572 | 1.78M | } |
573 | | |
574 | | void Quantizer::dequantBlock( const TransformUnit& tu, const ComponentID compID, const QpParam& cQP, CoeffBuf& recCoeff, bool enableScalingLists, int* piDequantCoef) const |
575 | 739k | { |
576 | | |
577 | | //----- set basic parameters ----- |
578 | 739k | const CompArea& area = tu.blocks[ compID ]; |
579 | 739k | const int numCoeff = area.area(); |
580 | 739k | const SizeType hsId = Log2( area.width ); |
581 | 739k | const SizeType vsId = Log2( area.height ); |
582 | 739k | const ScanElement *scan = getScanOrder( SCAN_GROUPED_4x4, hsId, vsId ); |
583 | 739k | const TCoeffSig* qCoeff = tu.getCoeffs( compID ).buf; |
584 | 739k | TCoeff* tCoeff = recCoeff.buf; |
585 | | |
586 | | //----- reset coefficients and get last scan index ----- |
587 | 739k | ::memset( tCoeff, 0, numCoeff * sizeof( TCoeff ) ); |
588 | 739k | int lastScanIdx = tu.lastPos[compID]; |
589 | 739k | if( lastScanIdx < 0 ) |
590 | 0 | { |
591 | 0 | return; |
592 | 0 | } |
593 | | |
594 | | //----- set dequant parameters ----- |
595 | 739k | const int qpDQ = cQP.Qp(tu.mtsIdx[compID]==MTS_SKIP) + 1; |
596 | 739k | const int qpPer = qpDQ / 6; |
597 | 739k | const int qpRem = qpDQ - 6 * qpPer; |
598 | 739k | const SPS& sps = *tu.cs->sps; |
599 | 739k | const ChannelType chType = toChannelType( compID ); |
600 | 739k | const int channelBitDepth = sps.bitDepths[ chType ]; |
601 | 739k | const int maxLog2TrDynamicRange = sps.getMaxLog2TrDynamicRange(); |
602 | 739k | const TCoeff minTCoeff = -( 1 << maxLog2TrDynamicRange ); |
603 | 739k | const TCoeff maxTCoeff = ( 1 << maxLog2TrDynamicRange ) - 1; |
604 | 739k | const int nomTransformShift = getTransformShift( channelBitDepth, area.size(), maxLog2TrDynamicRange ); |
605 | 739k | const bool needsSqrt2ScaleAdjustment = TU::needsSqrt2Scale(tu, compID); |
606 | 739k | const int transformShift = nomTransformShift + (needsSqrt2ScaleAdjustment?-1:0); |
607 | 739k | Intermediate_Int shift = IQUANT_SHIFT + 1 - qpPer - transformShift + (enableScalingLists ? LOG2_SCALING_LIST_NEUTRAL_VALUE : 0); |
608 | 739k | Intermediate_Int invQScale = g_invQuantScales[needsSqrt2ScaleAdjustment?1:0][ qpRem ]; |
609 | 739k | Intermediate_Int add = (shift < 0) ? 0 : ((1 << shift) >> 1); |
610 | | //----- dequant coefficients ----- |
611 | 7.82M | for( int state = 0, scanIdx = lastScanIdx; scanIdx >= 0; scanIdx-- ) |
612 | 7.08M | { |
613 | 7.08M | const unsigned rasterPos = scan[scanIdx].idx; |
614 | 7.08M | const TCoeffSig& level = qCoeff[ rasterPos ]; |
615 | | // zero levels are not skipped by a (often mispredicted) branch: their qIdx is 0, so they give the 0 of the memset |
616 | 7.08M | if (enableScalingLists) |
617 | 0 | invQScale = piDequantCoef[rasterPos];//scalingfactor*levelScale |
618 | 7.08M | if (shift < 0 && level && (enableScalingLists || scanIdx == lastScanIdx)) |
619 | 397k | { |
620 | 397k | invQScale <<= -shift; |
621 | 397k | } |
622 | 7.08M | const int sign = (level > 0) - (level < 0); // -1, 0 or 1 |
623 | 7.08M | Intermediate_Int qIdx = 2 * level - sign * (state >> 1); |
624 | 7.08M | int64_t nomTCoeff = ((int64_t)qIdx * (int64_t)invQScale + add) >> ((shift < 0) ? 0 : shift); |
625 | 7.08M | tCoeff[rasterPos] = (TCoeff)Clip3<int64_t>(minTCoeff, maxTCoeff, nomTCoeff); |
626 | 7.08M | state = ( 32040 >> ((state<<2)+((level&1)<<1)) ) & 3; // the 16-bit value "32040" represent the state transition table |
627 | 7.08M | } |
628 | 739k | } |
629 | | |
630 | | bool Quantizer::preQuantCoeff( const TCoeff absCoeff, PQData* pqData, int quanCoeff ) const |
631 | 0 | { |
632 | 0 | int64_t scaledOrg = int64_t( absCoeff ) * quanCoeff; |
633 | 0 | TCoeff qIdx = TCoeff( ( scaledOrg + m_QAdd ) >> m_QShift ); |
634 | |
|
635 | 0 | if( qIdx < 0 ) |
636 | 0 | { |
637 | 0 | int64_t scaledAdd = m_DistStepAdd - scaledOrg * m_DistOrgFact; |
638 | 0 | PQData& pq_a = pqData[1]; |
639 | 0 | PQData& pq_b = pqData[2]; |
640 | |
|
641 | 0 | pq_a.deltaDist = ( ( scaledAdd + 0 * m_DistStepAdd ) * 1 + m_DistAdd ) >> m_DistShift; |
642 | 0 | pq_a.absLevel = 1; |
643 | |
|
644 | 0 | pq_b.deltaDist = ( ( scaledAdd + 1 * m_DistStepAdd ) * 2 + m_DistAdd ) >> m_DistShift; |
645 | 0 | pq_b.absLevel = 1; |
646 | | |
647 | 0 | return true; |
648 | 0 | } |
649 | | |
650 | 0 | qIdx = std::max<TCoeff>( 1, std::min<TCoeff>( m_maxQIdx, qIdx ) ); |
651 | 0 | int64_t scaledAdd = qIdx * m_DistStepAdd - scaledOrg * m_DistOrgFact; |
652 | |
|
653 | 0 | PQData& pq_a = pqData[( qIdx + 0 ) & 3]; |
654 | 0 | PQData& pq_b = pqData[( qIdx + 1 ) & 3]; |
655 | 0 | PQData& pq_c = pqData[( qIdx + 2 ) & 3]; |
656 | 0 | PQData& pq_d = pqData[( qIdx + 3 ) & 3]; |
657 | |
|
658 | 0 | pq_a.deltaDist = ( ( scaledAdd + 0 * m_DistStepAdd ) * ( qIdx + 0 ) + m_DistAdd ) >> m_DistShift; |
659 | 0 | pq_a.absLevel = ( qIdx + 1 ) >> 1; |
660 | |
|
661 | 0 | pq_b.deltaDist = ( ( scaledAdd + 1 * m_DistStepAdd ) * ( qIdx + 1 ) + m_DistAdd ) >> m_DistShift; |
662 | 0 | pq_b.absLevel = ( qIdx + 2 ) >> 1; |
663 | |
|
664 | 0 | pq_c.deltaDist = ( ( scaledAdd + 2 * m_DistStepAdd ) * ( qIdx + 2 ) + m_DistAdd ) >> m_DistShift; |
665 | 0 | pq_c.absLevel = ( qIdx + 3 ) >> 1; |
666 | |
|
667 | 0 | pq_d.deltaDist = ( ( scaledAdd + 3 * m_DistStepAdd ) * ( qIdx + 3 ) + m_DistAdd ) >> m_DistShift; |
668 | 0 | pq_d.absLevel = ( qIdx + 4 ) >> 1; |
669 | |
|
670 | 0 | return false; |
671 | 0 | } |
672 | | |
673 | | const int32_t g_goRiceBits[4][RICEMAX] = |
674 | | { |
675 | | { 32768, 65536, 98304, 131072, 163840, 196608, 262144, 262144, 327680, 327680, 327680, 327680, 393216, 393216, 393216, 393216, 393216, 393216, 393216, 393216, 458752, 458752, 458752, 458752, 458752, 458752, 458752, 458752, 458752, 458752, 458752, 458752}, |
676 | | { 65536, 65536, 98304, 98304, 131072, 131072, 163840, 163840, 196608, 196608, 229376, 229376, 294912, 294912, 294912, 294912, 360448, 360448, 360448, 360448, 360448, 360448, 360448, 360448, 425984, 425984, 425984, 425984, 425984, 425984, 425984, 425984}, |
677 | | { 98304, 98304, 98304, 98304, 131072, 131072, 131072, 131072, 163840, 163840, 163840, 163840, 196608, 196608, 196608, 196608, 229376, 229376, 229376, 229376, 262144, 262144, 262144, 262144, 327680, 327680, 327680, 327680, 327680, 327680, 327680, 327680}, |
678 | | {131072, 131072, 131072, 131072, 131072, 131072, 131072, 131072, 163840, 163840, 163840, 163840, 163840, 163840, 163840, 163840, 196608, 196608, 196608, 196608, 196608, 196608, 196608, 196608, 229376, 229376, 229376, 229376, 229376, 229376, 229376, 229376} |
679 | | }; |
680 | | |
681 | | static inline void initStates( const int stateId, DQIntern::StateMem& state ) |
682 | 6.00M | { |
683 | 6.00M | state.rdCost[stateId] = DQIntern::rdCostInit; |
684 | 6.00M | state.ctx.cff[stateId] = 0; |
685 | 6.00M | state.ctx.sig[stateId] = 0; |
686 | 6.00M | state.numSig[stateId] = 0; |
687 | 6.00M | state.refSbbCtxId[stateId] = -1; |
688 | 6.00M | state.remRegBins[stateId] = 4; |
689 | 6.00M | state.cffBitsCtxOffset = 0; |
690 | 6.00M | state.m_goRicePar[stateId] = 0; |
691 | 6.00M | state.m_goRiceZero[stateId] = 0; |
692 | 6.00M | state.sbbBits0[stateId] = 0; |
693 | 6.00M | state.sbbBits1[stateId] = 0; |
694 | 6.00M | } |
695 | | |
696 | | template<bool rrgEnsured = false> |
697 | | static inline void checkRdCosts( const int stateId, const DQIntern::ScanPosType spt, const DQIntern::PQData& pqDataA, const DQIntern::PQData& pqDataB, DQIntern::Decisions& decisions, int idxAZ, int idxB, const DQIntern::StateMem& state ) |
698 | 23.9M | { |
699 | 23.9M | const int32_t* goRiceTab = DQIntern::g_goRiceBits[state.m_goRicePar[stateId]]; |
700 | 23.9M | int64_t rdCostA = state.rdCost[stateId] + pqDataA.deltaDist; |
701 | 23.9M | int64_t rdCostB = state.rdCost[stateId] + pqDataB.deltaDist; |
702 | 23.9M | int64_t rdCostZ = state.rdCost[stateId]; |
703 | | |
704 | 23.9M | if( rrgEnsured || state.remRegBins[stateId] >= 4 ) |
705 | 23.5M | { |
706 | 23.5M | const CoeffFracBits& cffBits = state.m_gtxFracBitsArray[state.ctx.cff[stateId]]; |
707 | 23.5M | const BinFracBits sigBits = state.m_sigFracBitsArray[stateId][state.ctx.sig[stateId]]; |
708 | | |
709 | 23.5M | if( pqDataA.absLevel < 4 ) |
710 | 5.70M | rdCostA += cffBits.bits[pqDataA.absLevel]; |
711 | 17.8M | else |
712 | 17.8M | { |
713 | 17.8M | const unsigned value = ( pqDataA.absLevel - 4 ) >> 1; |
714 | 17.8M | rdCostA += cffBits.bits[pqDataA.absLevel - ( value << 1 )] + goRiceTab[std::min<unsigned>( value, RICEMAX - 1 )]; |
715 | 17.8M | } |
716 | | |
717 | 23.5M | if( pqDataB.absLevel < 4 ) |
718 | 7.11M | rdCostB += cffBits.bits[pqDataB.absLevel]; |
719 | 16.4M | else |
720 | 16.4M | { |
721 | 16.4M | const unsigned value = ( pqDataB.absLevel - 4 ) >> 1; |
722 | 16.4M | rdCostB += cffBits.bits[pqDataB.absLevel - ( value << 1 )] + goRiceTab[std::min<unsigned>( value, RICEMAX - 1 )]; |
723 | 16.4M | } |
724 | | |
725 | 23.5M | if( spt == SCAN_ISCSBB ) |
726 | 23.4M | { |
727 | 23.4M | rdCostA += sigBits.intBits[1]; |
728 | 23.4M | rdCostB += sigBits.intBits[1]; |
729 | 23.4M | rdCostZ += sigBits.intBits[0]; |
730 | 23.4M | } |
731 | 69.9k | else if( spt == SCAN_SOCSBB ) |
732 | 12.1k | { |
733 | 12.1k | rdCostA += state.sbbBits1[stateId] + sigBits.intBits[1]; |
734 | 12.1k | rdCostB += state.sbbBits1[stateId] + sigBits.intBits[1]; |
735 | 12.1k | rdCostZ += state.sbbBits1[stateId] + sigBits.intBits[0]; |
736 | 12.1k | } |
737 | 57.7k | else if( state.numSig[stateId] ) |
738 | 56.6k | { |
739 | 56.6k | rdCostA += sigBits.intBits[1]; |
740 | 56.6k | rdCostB += sigBits.intBits[1]; |
741 | 56.6k | rdCostZ += sigBits.intBits[0]; |
742 | 56.6k | } |
743 | 1.16k | else |
744 | 1.16k | { |
745 | 1.16k | rdCostZ = rdCostInit; |
746 | 1.16k | } |
747 | 23.5M | } |
748 | 420k | else |
749 | 420k | { |
750 | 420k | rdCostA += ( 1 << SCALE_BITS ) + goRiceTab[pqDataA.absLevel <= state.m_goRiceZero[stateId] ? pqDataA.absLevel - 1 : std::min<int>( pqDataA.absLevel, RICEMAX - 1 )]; |
751 | 420k | rdCostB += ( 1 << SCALE_BITS ) + goRiceTab[pqDataB.absLevel <= state.m_goRiceZero[stateId] ? pqDataB.absLevel - 1 : std::min<int>( pqDataB.absLevel, RICEMAX - 1 )]; |
752 | 420k | rdCostZ += goRiceTab[state.m_goRiceZero[stateId]]; |
753 | 420k | } |
754 | | |
755 | 23.9M | if( rdCostA < rdCostZ && rdCostA < decisions.rdCost[idxAZ] ) |
756 | 14.9M | { |
757 | 14.9M | decisions.rdCost[idxAZ] = rdCostA; |
758 | 14.9M | decisions.absLevel[idxAZ] = pqDataA.absLevel; |
759 | 14.9M | decisions.prevId[idxAZ] = stateId; |
760 | 14.9M | } |
761 | 8.97M | else if( rdCostZ < decisions.rdCost[idxAZ] ) |
762 | 308k | { |
763 | 308k | decisions.rdCost[idxAZ] = rdCostZ; |
764 | 308k | decisions.absLevel[idxAZ] = 0; |
765 | 308k | decisions.prevId[idxAZ] = stateId; |
766 | 308k | } |
767 | | |
768 | 23.9M | if( rdCostB < decisions.rdCost[idxB] ) |
769 | 15.3M | { |
770 | 15.3M | decisions.rdCost[idxB] = rdCostB; |
771 | 15.3M | decisions.absLevel[idxB] = pqDataB.absLevel; |
772 | 15.3M | decisions.prevId[idxB] = stateId; |
773 | 15.3M | } |
774 | 23.9M | } DepQuant.cpp:void vvenc::DQIntern::checkRdCosts<true>(int, vvenc::DQIntern::ScanPosType, vvenc::DQIntern::PQData const&, vvenc::DQIntern::PQData const&, vvenc::DQIntern::Decisions&, int, int, vvenc::DQIntern::StateMem const&) Line | Count | Source | 698 | 4.28M | { | 699 | 4.28M | const int32_t* goRiceTab = DQIntern::g_goRiceBits[state.m_goRicePar[stateId]]; | 700 | 4.28M | int64_t rdCostA = state.rdCost[stateId] + pqDataA.deltaDist; | 701 | 4.28M | int64_t rdCostB = state.rdCost[stateId] + pqDataB.deltaDist; | 702 | 4.28M | int64_t rdCostZ = state.rdCost[stateId]; | 703 | | | 704 | 4.28M | if( rrgEnsured || state.remRegBins[stateId] >= 4 ) | 705 | 4.28M | { | 706 | 4.28M | const CoeffFracBits& cffBits = state.m_gtxFracBitsArray[state.ctx.cff[stateId]]; | 707 | 4.28M | const BinFracBits sigBits = state.m_sigFracBitsArray[stateId][state.ctx.sig[stateId]]; | 708 | | | 709 | 4.28M | if( pqDataA.absLevel < 4 ) | 710 | 4.28M | rdCostA += cffBits.bits[pqDataA.absLevel]; | 711 | 0 | else | 712 | 0 | { | 713 | 0 | const unsigned value = ( pqDataA.absLevel - 4 ) >> 1; | 714 | 0 | rdCostA += cffBits.bits[pqDataA.absLevel - ( value << 1 )] + goRiceTab[std::min<unsigned>( value, RICEMAX - 1 )]; | 715 | 0 | } | 716 | | | 717 | 4.28M | if( pqDataB.absLevel < 4 ) | 718 | 4.28M | rdCostB += cffBits.bits[pqDataB.absLevel]; | 719 | 0 | else | 720 | 0 | { | 721 | 0 | const unsigned value = ( pqDataB.absLevel - 4 ) >> 1; | 722 | 0 | rdCostB += cffBits.bits[pqDataB.absLevel - ( value << 1 )] + goRiceTab[std::min<unsigned>( value, RICEMAX - 1 )]; | 723 | 0 | } | 724 | | | 725 | 4.28M | if( spt == SCAN_ISCSBB ) | 726 | 4.26M | { | 727 | 4.26M | rdCostA += sigBits.intBits[1]; | 728 | 4.26M | rdCostB += sigBits.intBits[1]; | 729 | 4.26M | rdCostZ += sigBits.intBits[0]; | 730 | 4.26M | } | 731 | 27.6k | else if( spt == SCAN_SOCSBB ) | 732 | 10.0k | { | 733 | 10.0k | rdCostA += state.sbbBits1[stateId] + sigBits.intBits[1]; | 734 | 10.0k | rdCostB += state.sbbBits1[stateId] + sigBits.intBits[1]; | 735 | 10.0k | rdCostZ += state.sbbBits1[stateId] + sigBits.intBits[0]; | 736 | 10.0k | } | 737 | 17.6k | else if( state.numSig[stateId] ) | 738 | 16.8k | { | 739 | 16.8k | rdCostA += sigBits.intBits[1]; | 740 | 16.8k | rdCostB += sigBits.intBits[1]; | 741 | 16.8k | rdCostZ += sigBits.intBits[0]; | 742 | 16.8k | } | 743 | 812 | else | 744 | 812 | { | 745 | 812 | rdCostZ = rdCostInit; | 746 | 812 | } | 747 | 4.28M | } | 748 | 0 | else | 749 | 0 | { | 750 | 0 | rdCostA += ( 1 << SCALE_BITS ) + goRiceTab[pqDataA.absLevel <= state.m_goRiceZero[stateId] ? pqDataA.absLevel - 1 : std::min<int>( pqDataA.absLevel, RICEMAX - 1 )]; | 751 | 0 | rdCostB += ( 1 << SCALE_BITS ) + goRiceTab[pqDataB.absLevel <= state.m_goRiceZero[stateId] ? pqDataB.absLevel - 1 : std::min<int>( pqDataB.absLevel, RICEMAX - 1 )]; | 752 | 0 | rdCostZ += goRiceTab[state.m_goRiceZero[stateId]]; | 753 | 0 | } | 754 | | | 755 | 4.28M | if( rdCostA < rdCostZ && rdCostA < decisions.rdCost[idxAZ] ) | 756 | 2.81M | { | 757 | 2.81M | decisions.rdCost[idxAZ] = rdCostA; | 758 | 2.81M | decisions.absLevel[idxAZ] = pqDataA.absLevel; | 759 | 2.81M | decisions.prevId[idxAZ] = stateId; | 760 | 2.81M | } | 761 | 1.47M | else if( rdCostZ < decisions.rdCost[idxAZ] ) | 762 | 307k | { | 763 | 307k | decisions.rdCost[idxAZ] = rdCostZ; | 764 | 307k | decisions.absLevel[idxAZ] = 0; | 765 | 307k | decisions.prevId[idxAZ] = stateId; | 766 | 307k | } | 767 | | | 768 | 4.28M | if( rdCostB < decisions.rdCost[idxB] ) | 769 | 3.12M | { | 770 | 3.12M | decisions.rdCost[idxB] = rdCostB; | 771 | 3.12M | decisions.absLevel[idxB] = pqDataB.absLevel; | 772 | 3.12M | decisions.prevId[idxB] = stateId; | 773 | 3.12M | } | 774 | 4.28M | } |
DepQuant.cpp:void vvenc::DQIntern::checkRdCosts<false>(int, vvenc::DQIntern::ScanPosType, vvenc::DQIntern::PQData const&, vvenc::DQIntern::PQData const&, vvenc::DQIntern::Decisions&, int, int, vvenc::DQIntern::StateMem const&) Line | Count | Source | 698 | 19.6M | { | 699 | 19.6M | const int32_t* goRiceTab = DQIntern::g_goRiceBits[state.m_goRicePar[stateId]]; | 700 | 19.6M | int64_t rdCostA = state.rdCost[stateId] + pqDataA.deltaDist; | 701 | 19.6M | int64_t rdCostB = state.rdCost[stateId] + pqDataB.deltaDist; | 702 | 19.6M | int64_t rdCostZ = state.rdCost[stateId]; | 703 | | | 704 | 19.6M | if( rrgEnsured || state.remRegBins[stateId] >= 4 ) | 705 | 19.2M | { | 706 | 19.2M | const CoeffFracBits& cffBits = state.m_gtxFracBitsArray[state.ctx.cff[stateId]]; | 707 | 19.2M | const BinFracBits sigBits = state.m_sigFracBitsArray[stateId][state.ctx.sig[stateId]]; | 708 | | | 709 | 19.2M | if( pqDataA.absLevel < 4 ) | 710 | 1.41M | rdCostA += cffBits.bits[pqDataA.absLevel]; | 711 | 17.8M | else | 712 | 17.8M | { | 713 | 17.8M | const unsigned value = ( pqDataA.absLevel - 4 ) >> 1; | 714 | 17.8M | rdCostA += cffBits.bits[pqDataA.absLevel - ( value << 1 )] + goRiceTab[std::min<unsigned>( value, RICEMAX - 1 )]; | 715 | 17.8M | } | 716 | | | 717 | 19.2M | if( pqDataB.absLevel < 4 ) | 718 | 2.82M | rdCostB += cffBits.bits[pqDataB.absLevel]; | 719 | 16.4M | else | 720 | 16.4M | { | 721 | 16.4M | const unsigned value = ( pqDataB.absLevel - 4 ) >> 1; | 722 | 16.4M | rdCostB += cffBits.bits[pqDataB.absLevel - ( value << 1 )] + goRiceTab[std::min<unsigned>( value, RICEMAX - 1 )]; | 723 | 16.4M | } | 724 | | | 725 | 19.2M | if( spt == SCAN_ISCSBB ) | 726 | 19.1M | { | 727 | 19.1M | rdCostA += sigBits.intBits[1]; | 728 | 19.1M | rdCostB += sigBits.intBits[1]; | 729 | 19.1M | rdCostZ += sigBits.intBits[0]; | 730 | 19.1M | } | 731 | 42.2k | else if( spt == SCAN_SOCSBB ) | 732 | 2.09k | { | 733 | 2.09k | rdCostA += state.sbbBits1[stateId] + sigBits.intBits[1]; | 734 | 2.09k | rdCostB += state.sbbBits1[stateId] + sigBits.intBits[1]; | 735 | 2.09k | rdCostZ += state.sbbBits1[stateId] + sigBits.intBits[0]; | 736 | 2.09k | } | 737 | 40.1k | else if( state.numSig[stateId] ) | 738 | 39.7k | { | 739 | 39.7k | rdCostA += sigBits.intBits[1]; | 740 | 39.7k | rdCostB += sigBits.intBits[1]; | 741 | 39.7k | rdCostZ += sigBits.intBits[0]; | 742 | 39.7k | } | 743 | 356 | else | 744 | 356 | { | 745 | 356 | rdCostZ = rdCostInit; | 746 | 356 | } | 747 | 19.2M | } | 748 | 420k | else | 749 | 420k | { | 750 | 420k | rdCostA += ( 1 << SCALE_BITS ) + goRiceTab[pqDataA.absLevel <= state.m_goRiceZero[stateId] ? pqDataA.absLevel - 1 : std::min<int>( pqDataA.absLevel, RICEMAX - 1 )]; | 751 | 420k | rdCostB += ( 1 << SCALE_BITS ) + goRiceTab[pqDataB.absLevel <= state.m_goRiceZero[stateId] ? pqDataB.absLevel - 1 : std::min<int>( pqDataB.absLevel, RICEMAX - 1 )]; | 752 | 420k | rdCostZ += goRiceTab[state.m_goRiceZero[stateId]]; | 753 | 420k | } | 754 | | | 755 | 19.6M | if( rdCostA < rdCostZ && rdCostA < decisions.rdCost[idxAZ] ) | 756 | 12.1M | { | 757 | 12.1M | decisions.rdCost[idxAZ] = rdCostA; | 758 | 12.1M | decisions.absLevel[idxAZ] = pqDataA.absLevel; | 759 | 12.1M | decisions.prevId[idxAZ] = stateId; | 760 | 12.1M | } | 761 | 7.50M | else if( rdCostZ < decisions.rdCost[idxAZ] ) | 762 | 549 | { | 763 | 549 | decisions.rdCost[idxAZ] = rdCostZ; | 764 | 549 | decisions.absLevel[idxAZ] = 0; | 765 | 549 | decisions.prevId[idxAZ] = stateId; | 766 | 549 | } | 767 | | | 768 | 19.6M | if( rdCostB < decisions.rdCost[idxB] ) | 769 | 12.1M | { | 770 | 12.1M | decisions.rdCost[idxB] = rdCostB; | 771 | 12.1M | decisions.absLevel[idxB] = pqDataB.absLevel; | 772 | 12.1M | decisions.prevId[idxB] = stateId; | 773 | 12.1M | } | 774 | 19.6M | } |
|
775 | | |
776 | | void checkAllRdCosts( const DQIntern::ScanPosType spt, const DQIntern::PQData* pqData, DQIntern::Decisions& decisions, const DQIntern::StateMem& state ) |
777 | 1.07M | { |
778 | 1.07M | checkRdCosts<true>( 0, spt, pqData[0], pqData[2], decisions, 0, 2, state ); |
779 | 1.07M | checkRdCosts<true>( 1, spt, pqData[0], pqData[2], decisions, 2, 0, state ); |
780 | 1.07M | checkRdCosts<true>( 2, spt, pqData[3], pqData[1], decisions, 1, 3, state ); |
781 | 1.07M | checkRdCosts<true>( 3, spt, pqData[3], pqData[1], decisions, 3, 1, state ); |
782 | 1.07M | } |
783 | | |
784 | | template<bool rrgEnsured = false> |
785 | | static void checkRdCostsOdd1( const int stateId, const ScanPosType spt, const int64_t deltaDist, Decisions& decisions, int idxA, int idxZ, const StateMem& state ) |
786 | 4.73M | { |
787 | 4.73M | int64_t rdCostA = state.rdCost[stateId] + deltaDist; |
788 | 4.73M | int64_t rdCostZ = state.rdCost[stateId]; |
789 | | |
790 | 4.73M | if( rrgEnsured || state.remRegBins[stateId] >= 4 ) |
791 | 4.73M | { |
792 | 4.73M | const BinFracBits sigBits = state.m_sigFracBitsArray[stateId][state.ctx.sig[stateId]]; |
793 | | |
794 | 4.73M | rdCostA += state.cffBits1[state.ctx.cff[stateId]]; |
795 | | |
796 | 4.73M | if( spt == SCAN_ISCSBB ) |
797 | 4.61M | { |
798 | 4.61M | rdCostA += sigBits.intBits[1]; |
799 | 4.61M | rdCostZ += sigBits.intBits[0]; |
800 | 4.61M | } |
801 | 118k | else if( spt == SCAN_SOCSBB ) |
802 | 77.7k | { |
803 | 77.7k | rdCostA += state.sbbBits1[stateId] + sigBits.intBits[1]; |
804 | 77.7k | rdCostZ += state.sbbBits1[stateId] + sigBits.intBits[0]; |
805 | 77.7k | } |
806 | 40.9k | else if( state.numSig[stateId] ) |
807 | 8.28k | { |
808 | 8.28k | rdCostA += sigBits.intBits[1]; |
809 | 8.28k | rdCostZ += sigBits.intBits[0]; |
810 | 8.28k | } |
811 | 32.7k | else |
812 | 32.7k | { |
813 | 32.7k | rdCostZ = rdCostInit; |
814 | 32.7k | } |
815 | 4.73M | } |
816 | 1.72k | else |
817 | 1.72k | { |
818 | 1.72k | const int32_t* goRiceTab = g_goRiceBits[state.m_goRicePar[stateId]]; |
819 | | |
820 | 1.72k | rdCostA += ( 1 << SCALE_BITS ) + goRiceTab[0]; |
821 | 1.72k | rdCostZ += goRiceTab[state.m_goRiceZero[stateId]]; |
822 | 1.72k | } |
823 | | |
824 | 4.73M | if( rdCostA < decisions.rdCost[idxA] ) |
825 | 2.82M | { |
826 | 2.82M | decisions.rdCost[idxA] = rdCostA; |
827 | 2.82M | decisions.absLevel[idxA] = 1; |
828 | 2.82M | decisions.prevId[idxA] = stateId; |
829 | 2.82M | } |
830 | | |
831 | 4.73M | if( rdCostZ < decisions.rdCost[idxZ] ) |
832 | 3.34M | { |
833 | 3.34M | decisions.rdCost[idxZ] = rdCostZ; |
834 | 3.34M | decisions.absLevel[idxZ] = 0; |
835 | 3.34M | decisions.prevId[idxZ] = stateId; |
836 | 3.34M | } |
837 | 4.73M | } DepQuant.cpp:void vvenc::DQIntern::checkRdCostsOdd1<true>(int, vvenc::DQIntern::ScanPosType, long, vvenc::DQIntern::Decisions&, int, int, vvenc::DQIntern::StateMem const&) Line | Count | Source | 786 | 4.40M | { | 787 | 4.40M | int64_t rdCostA = state.rdCost[stateId] + deltaDist; | 788 | 4.40M | int64_t rdCostZ = state.rdCost[stateId]; | 789 | | | 790 | 4.40M | if( rrgEnsured || state.remRegBins[stateId] >= 4 ) | 791 | 4.40M | { | 792 | 4.40M | const BinFracBits sigBits = state.m_sigFracBitsArray[stateId][state.ctx.sig[stateId]]; | 793 | | | 794 | 4.40M | rdCostA += state.cffBits1[state.ctx.cff[stateId]]; | 795 | | | 796 | 4.40M | if( spt == SCAN_ISCSBB ) | 797 | 4.29M | { | 798 | 4.29M | rdCostA += sigBits.intBits[1]; | 799 | 4.29M | rdCostZ += sigBits.intBits[0]; | 800 | 4.29M | } | 801 | 118k | else if( spt == SCAN_SOCSBB ) | 802 | 77.5k | { | 803 | 77.5k | rdCostA += state.sbbBits1[stateId] + sigBits.intBits[1]; | 804 | 77.5k | rdCostZ += state.sbbBits1[stateId] + sigBits.intBits[0]; | 805 | 77.5k | } | 806 | 40.5k | else if( state.numSig[stateId] ) | 807 | 8.28k | { | 808 | 8.28k | rdCostA += sigBits.intBits[1]; | 809 | 8.28k | rdCostZ += sigBits.intBits[0]; | 810 | 8.28k | } | 811 | 32.2k | else | 812 | 32.2k | { | 813 | 32.2k | rdCostZ = rdCostInit; | 814 | 32.2k | } | 815 | 4.40M | } | 816 | 0 | else | 817 | 0 | { | 818 | 0 | const int32_t* goRiceTab = g_goRiceBits[state.m_goRicePar[stateId]]; | 819 | |
| 820 | 0 | rdCostA += ( 1 << SCALE_BITS ) + goRiceTab[0]; | 821 | 0 | rdCostZ += goRiceTab[state.m_goRiceZero[stateId]]; | 822 | 0 | } | 823 | | | 824 | 4.40M | if( rdCostA < decisions.rdCost[idxA] ) | 825 | 2.81M | { | 826 | 2.81M | decisions.rdCost[idxA] = rdCostA; | 827 | 2.81M | decisions.absLevel[idxA] = 1; | 828 | 2.81M | decisions.prevId[idxA] = stateId; | 829 | 2.81M | } | 830 | | | 831 | 4.40M | if( rdCostZ < decisions.rdCost[idxZ] ) | 832 | 3.34M | { | 833 | 3.34M | decisions.rdCost[idxZ] = rdCostZ; | 834 | 3.34M | decisions.absLevel[idxZ] = 0; | 835 | 3.34M | decisions.prevId[idxZ] = stateId; | 836 | 3.34M | } | 837 | 4.40M | } |
DepQuant.cpp:void vvenc::DQIntern::checkRdCostsOdd1<false>(int, vvenc::DQIntern::ScanPosType, long, vvenc::DQIntern::Decisions&, int, int, vvenc::DQIntern::StateMem const&) Line | Count | Source | 786 | 330k | { | 787 | 330k | int64_t rdCostA = state.rdCost[stateId] + deltaDist; | 788 | 330k | int64_t rdCostZ = state.rdCost[stateId]; | 789 | | | 790 | 330k | if( rrgEnsured || state.remRegBins[stateId] >= 4 ) | 791 | 328k | { | 792 | 328k | const BinFracBits sigBits = state.m_sigFracBitsArray[stateId][state.ctx.sig[stateId]]; | 793 | | | 794 | 328k | rdCostA += state.cffBits1[state.ctx.cff[stateId]]; | 795 | | | 796 | 328k | if( spt == SCAN_ISCSBB ) | 797 | 328k | { | 798 | 328k | rdCostA += sigBits.intBits[1]; | 799 | 328k | rdCostZ += sigBits.intBits[0]; | 800 | 328k | } | 801 | 623 | else if( spt == SCAN_SOCSBB ) | 802 | 195 | { | 803 | 195 | rdCostA += state.sbbBits1[stateId] + sigBits.intBits[1]; | 804 | 195 | rdCostZ += state.sbbBits1[stateId] + sigBits.intBits[0]; | 805 | 195 | } | 806 | 428 | else if( state.numSig[stateId] ) | 807 | 0 | { | 808 | 0 | rdCostA += sigBits.intBits[1]; | 809 | 0 | rdCostZ += sigBits.intBits[0]; | 810 | 0 | } | 811 | 428 | else | 812 | 428 | { | 813 | 428 | rdCostZ = rdCostInit; | 814 | 428 | } | 815 | 328k | } | 816 | 1.72k | else | 817 | 1.72k | { | 818 | 1.72k | const int32_t* goRiceTab = g_goRiceBits[state.m_goRicePar[stateId]]; | 819 | | | 820 | 1.72k | rdCostA += ( 1 << SCALE_BITS ) + goRiceTab[0]; | 821 | 1.72k | rdCostZ += goRiceTab[state.m_goRiceZero[stateId]]; | 822 | 1.72k | } | 823 | | | 824 | 330k | if( rdCostA < decisions.rdCost[idxA] ) | 825 | 1.30k | { | 826 | 1.30k | decisions.rdCost[idxA] = rdCostA; | 827 | 1.30k | decisions.absLevel[idxA] = 1; | 828 | 1.30k | decisions.prevId[idxA] = stateId; | 829 | 1.30k | } | 830 | | | 831 | 330k | if( rdCostZ < decisions.rdCost[idxZ] ) | 832 | 1.99k | { | 833 | 1.99k | decisions.rdCost[idxZ] = rdCostZ; | 834 | 1.99k | decisions.absLevel[idxZ] = 0; | 835 | 1.99k | decisions.prevId[idxZ] = stateId; | 836 | 1.99k | } | 837 | 330k | } |
|
838 | | |
839 | | static void checkAllRdCostsOdd1( const DQIntern::ScanPosType spt, const int64_t pq_a_dist, const int64_t pq_b_dist, DQIntern::Decisions& decisions, const DQIntern::StateMem& state ) |
840 | 1.10M | { |
841 | 1.10M | checkRdCostsOdd1<true>( 0, spt, pq_b_dist, decisions, 2, 0, state ); |
842 | 1.10M | checkRdCostsOdd1<true>( 1, spt, pq_b_dist, decisions, 0, 2, state ); |
843 | 1.10M | checkRdCostsOdd1<true>( 2, spt, pq_a_dist, decisions, 3, 1, state ); |
844 | 1.10M | checkRdCostsOdd1<true>( 3, spt, pq_a_dist, decisions, 1, 3, state ); |
845 | 1.10M | } |
846 | | |
847 | | static inline void checkRdCostStart( int32_t lastOffset, const PQData& pqData, Decisions& decisions, int idx, const StateMem& state ) |
848 | 13.1M | { |
849 | 13.1M | const CoeffFracBits& cffBits = state.m_gtxFracBitsArray[0]; |
850 | | |
851 | 13.1M | int64_t rdCost = pqData.deltaDist + lastOffset; |
852 | 13.1M | if( pqData.absLevel < 4 ) |
853 | 4.60M | { |
854 | 4.60M | rdCost += cffBits.bits[pqData.absLevel]; |
855 | 4.60M | } |
856 | 8.55M | else |
857 | 8.55M | { |
858 | 8.55M | const unsigned value = ( pqData.absLevel - 4 ) >> 1; |
859 | 8.55M | rdCost += cffBits.bits[pqData.absLevel - ( value << 1 )] + g_goRiceBits[0][value < RICEMAX ? value : RICEMAX - 1]; |
860 | 8.55M | } |
861 | | |
862 | 13.1M | if( rdCost < decisions.rdCost[idx] ) |
863 | 1.73M | { |
864 | 1.73M | decisions.rdCost[idx] = rdCost; |
865 | 1.73M | decisions.absLevel[idx] = pqData.absLevel; |
866 | 1.73M | decisions.prevId[idx] = -1; |
867 | 1.73M | } |
868 | 13.1M | } |
869 | | |
870 | | static inline void checkRdCostSkipSbb( const int stateId, Decisions& decisions, int idx, const StateMem& state ) |
871 | 111k | { |
872 | 111k | int64_t rdCost = state.rdCost[stateId] + state.sbbBits0[stateId]; |
873 | 111k | if( rdCost < decisions.rdCost[idx] ) |
874 | 38.0k | { |
875 | 38.0k | decisions.rdCost[idx] = rdCost; |
876 | 38.0k | decisions.absLevel[idx] = 0; |
877 | 38.0k | decisions.prevId[idx] = 4 | stateId; |
878 | 38.0k | } |
879 | 111k | } |
880 | | |
881 | | static inline void checkRdCostSkipSbbZeroOut( const int stateId, Decisions& decisions, int idx, const StateMem& state ) |
882 | 0 | { |
883 | 0 | int64_t rdCost = state.rdCost[stateId] + state.sbbBits0[stateId]; |
884 | 0 | decisions.rdCost[idx] = rdCost; |
885 | 0 | decisions.absLevel[idx] = 0; |
886 | 0 | decisions.prevId[idx] = 4 | stateId; |
887 | 0 | } |
888 | | |
889 | | static inline void setRiceParam( const int stateId, const ScanInfo& scanInfo, StateMem& state, bool ge4 ) |
890 | 19.5M | { |
891 | 19.5M | if( state.remRegBins[stateId] < 4 || ge4 ) |
892 | 18.2M | { |
893 | 18.2M | TCoeff sumAbs = state.sum1st[scanInfo.insidePos][stateId]; |
894 | 18.2M | int sumSub = state.remRegBins[stateId] < 4 ? 0 : 4 * 5; |
895 | 18.2M | int sumAll = std::max( std::min( 31, ( int ) sumAbs - sumSub ), 0 ); |
896 | 18.2M | state.m_goRicePar[stateId] |
897 | 18.2M | = g_auiGoRiceParsCoeff[sumAll]; |
898 | | |
899 | 18.2M | if( state.remRegBins[stateId] < 4 ) |
900 | 421k | { |
901 | 421k | state.m_goRiceZero[stateId] = g_auiGoRicePosCoeff0( stateId, state.m_goRicePar[stateId] ); |
902 | 421k | } |
903 | 18.2M | } |
904 | 19.5M | } |
905 | | |
906 | | static void update1State( int stateId, const DQIntern::ScanInfo& scanInfo, const DQIntern::Decisions& decisions, DQIntern::StateMem& curr, DQIntern::StateMem& prev ) |
907 | 25.5M | { |
908 | 25.5M | curr.rdCost[stateId] = decisions.rdCost[stateId]; |
909 | 25.5M | if( decisions.prevId[stateId] > -2 ) |
910 | 24.5M | { |
911 | 24.5M | if( decisions.prevId[stateId] >= 0 ) |
912 | 23.3M | { |
913 | 23.3M | const int prevId = decisions.prevId[stateId]; |
914 | 23.3M | curr.numSig[stateId] = prev.numSig[prevId] + !!decisions.absLevel[stateId]; |
915 | 23.3M | curr.refSbbCtxId[stateId] = prev.refSbbCtxId[prevId]; |
916 | 23.3M | curr.sbbBits0[stateId] = prev.sbbBits0[prevId]; |
917 | 23.3M | curr.sbbBits1[stateId] = prev.sbbBits1[prevId]; |
918 | 23.3M | curr.remRegBins[stateId] = prev.remRegBins[prevId] - 1; |
919 | | |
920 | 23.3M | if( curr.remRegBins[stateId] >= 4 ) |
921 | 23.0M | { |
922 | 23.0M | curr.remRegBins[stateId] -= ( decisions.absLevel[stateId] < 2 ? decisions.absLevel[stateId] : 3 ); |
923 | 23.0M | } |
924 | | |
925 | 396M | for( int i = 0; i < 16; i++ ) |
926 | 372M | { |
927 | 372M | curr.tplAcc[i][stateId] = prev.tplAcc[i][prevId]; |
928 | 372M | curr.sum1st[i][stateId] = prev.sum1st[i][prevId]; |
929 | 372M | curr.absVal[i][stateId] = prev.absVal[i][prevId]; |
930 | 372M | } |
931 | 23.3M | } |
932 | 1.21M | else |
933 | 1.21M | { |
934 | 1.21M | curr.numSig[stateId] = 1; |
935 | 1.21M | curr.refSbbCtxId[stateId] = -1; |
936 | 1.21M | curr.remRegBins[stateId] = prev.initRemRegBins; |
937 | 1.21M | curr.remRegBins[stateId] -= ( decisions.absLevel[stateId] < 2 ? decisions.absLevel[stateId] : 3 ); |
938 | | |
939 | 20.5M | for( int i = 0; i < 16; i++ ) |
940 | 19.3M | { |
941 | 19.3M | curr.tplAcc[i][stateId] = 0; |
942 | 19.3M | curr.sum1st[i][stateId] = 0; |
943 | 19.3M | curr.absVal[i][stateId] = 0; |
944 | 19.3M | } |
945 | 1.21M | } |
946 | | |
947 | 24.5M | if( decisions.absLevel[stateId] ) |
948 | 21.7M | { |
949 | 21.7M | curr.absVal[scanInfo.insidePos][stateId] = ( uint8_t ) std::min<TCoeff>( 126 + ( decisions.absLevel[stateId] & 1 ), decisions.absLevel[stateId] ); |
950 | | |
951 | 21.7M | if( scanInfo.currNbInfoSbb.numInv ) |
952 | 21.7M | { |
953 | 21.7M | int min4_or_5 = std::min<TCoeff>( 4 + ( decisions.absLevel[stateId] & 1 ), decisions.absLevel[stateId] ); |
954 | | |
955 | 21.7M | auto adds8 = []( uint8_t a, uint8_t b ) |
956 | 63.4M | { |
957 | 63.4M | uint8_t c = a + b; |
958 | 63.4M | if( c < a ) c = -1; |
959 | 63.4M | return c; |
960 | 63.4M | }; |
961 | | |
962 | 21.7M | auto update_deps = [&]( int k ) |
963 | 63.4M | { |
964 | 63.4M | curr.tplAcc[scanInfo.currNbInfoSbb.invInPos[k]][stateId] += 32 + min4_or_5; |
965 | 63.4M | curr.sum1st[scanInfo.currNbInfoSbb.invInPos[k]][stateId] = adds8( curr.sum1st[scanInfo.currNbInfoSbb.invInPos[k]][stateId], decisions.absLevel[stateId] ); |
966 | 63.4M | }; |
967 | | |
968 | 21.7M | switch( scanInfo.currNbInfoSbb.numInv ) |
969 | 21.7M | { |
970 | 0 | default: |
971 | 3.57M | case 5: |
972 | 3.57M | update_deps( 4 ); |
973 | 9.03M | case 4: |
974 | 9.03M | update_deps( 3 ); |
975 | 10.9M | case 3: |
976 | 10.9M | update_deps( 2 ); |
977 | 18.1M | case 2: |
978 | 18.1M | update_deps( 1 ); |
979 | 21.7M | case 1: |
980 | 21.7M | update_deps( 0 ); |
981 | 21.7M | } |
982 | 21.7M | } |
983 | 21.7M | } |
984 | | |
985 | 24.5M | if( curr.remRegBins[stateId] >= 4 ) |
986 | 24.1M | { |
987 | 24.1M | TCoeff sumAbs1 = curr.tplAcc[scanInfo.nextInsidePos][stateId] & 31; |
988 | 24.1M | TCoeff sumNum = curr.tplAcc[scanInfo.nextInsidePos][stateId] >> 5u; |
989 | 24.1M | int sumGt1 = sumAbs1 - sumNum; |
990 | | |
991 | 24.1M | curr.ctx.sig[stateId] = scanInfo.sigCtxOffsetNext + std::min( ( sumAbs1 + 1 ) >> 1, 3 ); |
992 | 24.1M | curr.ctx.cff[stateId] = scanInfo.gtxCtxOffsetNext + std::min( sumGt1, 4 ); |
993 | 24.1M | } |
994 | 408k | else |
995 | 408k | { |
996 | 408k | curr.anyRemRegBinsLt4 = true; |
997 | 408k | } |
998 | 24.5M | } |
999 | 25.5M | } |
1000 | | |
1001 | | static void update1StateEOS( const int stateId, const DQIntern::ScanInfo& scanInfo, const DQIntern::Decisions& decisions, const DQIntern::StateMem& skip, DQIntern::StateMem& curr, DQIntern::StateMem& prev, DQIntern::CommonCtx& commonCtx ) |
1002 | 117k | { |
1003 | 117k | curr.rdCost[stateId] = decisions.rdCost[stateId]; |
1004 | | |
1005 | 117k | if( decisions.prevId[stateId] > -2 ) |
1006 | 116k | { |
1007 | 116k | if( decisions.prevId[stateId] >= 4 ) |
1008 | 38.0k | { |
1009 | 38.0k | CHECK( decisions.absLevel[stateId] != 0, "cannot happen" ); |
1010 | | |
1011 | 38.0k | const int prevId = decisions.prevId[stateId] - 4; |
1012 | 38.0k | curr.numSig [stateId] = 0; |
1013 | 38.0k | curr.remRegBins[stateId] = skip.remRegBins[prevId]; |
1014 | 38.0k | curr.refSbbCtxId[stateId] = prevId; |
1015 | | |
1016 | 646k | for( int i = 0; i < 16; i++ ) |
1017 | 608k | { |
1018 | 608k | curr.absVal[i][stateId] = 0; |
1019 | 608k | } |
1020 | 38.0k | } |
1021 | 78.3k | else if( decisions.prevId[stateId] >= 0 ) |
1022 | 76.5k | { |
1023 | 76.5k | const int prevId = decisions.prevId[stateId]; |
1024 | 76.5k | curr.numSig[stateId] = prev.numSig[prevId] + !!decisions.absLevel[stateId]; |
1025 | 76.5k | curr.refSbbCtxId[stateId] = prev.refSbbCtxId[prevId]; |
1026 | 76.5k | curr.remRegBins[stateId] = prev.remRegBins[prevId] - 1; |
1027 | | |
1028 | 76.5k | if( curr.remRegBins[stateId] >= 4 ) |
1029 | 63.5k | { |
1030 | 63.5k | curr.remRegBins[stateId] -= ( decisions.absLevel[stateId] < 2 ? decisions.absLevel[stateId] : 3 ); |
1031 | 63.5k | } |
1032 | | |
1033 | 1.30M | for( int i = 0; i < 16; i++ ) |
1034 | 1.22M | { |
1035 | 1.22M | curr.absVal[i][stateId] = prev.absVal[i][prevId]; |
1036 | 1.22M | } |
1037 | 76.5k | } |
1038 | 1.76k | else |
1039 | 1.76k | { |
1040 | 1.76k | curr.numSig[stateId] = 1; |
1041 | 1.76k | curr.refSbbCtxId[stateId] = -1; |
1042 | 1.76k | curr.remRegBins[stateId] = prev.initRemRegBins; |
1043 | 1.76k | curr.remRegBins[stateId] -= ( decisions.absLevel[stateId] < 2 ? decisions.absLevel[stateId] : 3 ); |
1044 | | |
1045 | 29.9k | for( int i = 0; i < 16; i++ ) |
1046 | 28.2k | { |
1047 | 28.2k | curr.absVal[i][stateId] = 0; |
1048 | 28.2k | } |
1049 | 1.76k | } |
1050 | | |
1051 | 116k | curr.absVal[scanInfo.insidePos][stateId] = ( uint8_t ) std::min<TCoeff>( 126 + ( decisions.absLevel[stateId] & 1 ), decisions.absLevel[stateId] ); |
1052 | | |
1053 | 116k | uint8_t* levels[4]; |
1054 | 116k | commonCtx.getLevelPtrs( scanInfo, levels[0], levels[1], levels[2], levels[3] ); |
1055 | 1.97M | for( int i = 0; i < 16; i++ ) |
1056 | 1.86M | { |
1057 | | // save abs levels to commonCtx |
1058 | 1.86M | levels[stateId][i] = curr.absVal[i][stateId]; |
1059 | | // clean the SBB ctx |
1060 | 1.86M | curr.tplAcc[i][stateId] = 0; |
1061 | 1.86M | curr.sum1st[i][stateId] = 0; |
1062 | 1.86M | curr.absVal[i][stateId] = 0; |
1063 | 1.86M | } |
1064 | | |
1065 | 116k | commonCtx.update( scanInfo, curr.refSbbCtxId[stateId], stateId, curr ); |
1066 | | |
1067 | 116k | curr.numSig[stateId] = 0; |
1068 | | |
1069 | 116k | if( curr.remRegBins[stateId] >= 4 ) |
1070 | 103k | { |
1071 | 103k | TCoeff sumAbs1 = curr.tplAcc[scanInfo.nextInsidePos][stateId] & 31; |
1072 | 103k | TCoeff sumNum = curr.tplAcc[scanInfo.nextInsidePos][stateId] >> 5u; |
1073 | 103k | int sumGt1 = sumAbs1 - sumNum; |
1074 | | |
1075 | 103k | curr.ctx.sig[stateId] = scanInfo.sigCtxOffsetNext + std::min( ( sumAbs1 + 1 ) >> 1, 3 ); |
1076 | 103k | curr.ctx.cff[stateId] = scanInfo.gtxCtxOffsetNext + std::min( sumGt1, 4 ); |
1077 | 103k | } |
1078 | 13.2k | else |
1079 | 13.2k | { |
1080 | 13.2k | curr.anyRemRegBinsLt4 = true; |
1081 | 13.2k | } |
1082 | 116k | } |
1083 | 117k | } |
1084 | | |
1085 | | static void updateStates( const DQIntern::ScanInfo& scanInfo, const DQIntern::Decisions& decisions, DQIntern::StateMem& curr ) |
1086 | 6.39M | { |
1087 | 6.39M | DQIntern::StateMem prev = curr; |
1088 | 6.39M | curr.anyRemRegBinsLt4 = false; |
1089 | | |
1090 | 6.39M | update1State( 0, scanInfo, decisions, curr, prev ); |
1091 | 6.39M | update1State( 1, scanInfo, decisions, curr, prev ); |
1092 | 6.39M | update1State( 2, scanInfo, decisions, curr, prev ); |
1093 | 6.39M | update1State( 3, scanInfo, decisions, curr, prev ); |
1094 | | |
1095 | 6.39M | curr.cffBitsCtxOffset = scanInfo.gtxCtxOffsetNext; |
1096 | 6.39M | } |
1097 | | |
1098 | | static void updateStatesEOS( const DQIntern::ScanInfo& scanInfo, const DQIntern::Decisions& decisions, const DQIntern::StateMem& skip, DQIntern::StateMem& curr, DQIntern::CommonCtx& commonCtx ) |
1099 | 29.4k | { |
1100 | 29.4k | DQIntern::StateMem prev = curr; |
1101 | 29.4k | curr.anyRemRegBinsLt4 = false; |
1102 | | |
1103 | 29.4k | update1StateEOS( 0, scanInfo, decisions, skip, curr, prev, commonCtx ); |
1104 | 29.4k | update1StateEOS( 1, scanInfo, decisions, skip, curr, prev, commonCtx ); |
1105 | 29.4k | update1StateEOS( 2, scanInfo, decisions, skip, curr, prev, commonCtx ); |
1106 | 29.4k | update1StateEOS( 3, scanInfo, decisions, skip, curr, prev, commonCtx ); |
1107 | | |
1108 | 29.4k | curr.cffBitsCtxOffset = scanInfo.gtxCtxOffsetNext; |
1109 | 29.4k | } |
1110 | | }; // namespace DQIntern |
1111 | | |
1112 | | static const DQIntern::Decisions startDec[2] = |
1113 | | { |
1114 | | DQIntern::Decisions |
1115 | | { |
1116 | | { DQIntern::rdCostInit >> 2, DQIntern::rdCostInit >> 2, DQIntern::rdCostInit >> 2, DQIntern::rdCostInit >> 2 }, |
1117 | | { -1, -1, -1, -1 }, |
1118 | | { -2, -2, -2, -2 }, |
1119 | | }, |
1120 | | DQIntern::Decisions |
1121 | | { |
1122 | | { DQIntern::rdCostInit >> 2, DQIntern::rdCostInit >> 2, DQIntern::rdCostInit >> 2, DQIntern::rdCostInit >> 2 }, |
1123 | | { 0, 0, 0, 0 }, |
1124 | | { 4, 5, 6, 7 }, |
1125 | | } |
1126 | | }; |
1127 | | |
1128 | | void DepQuant::xQuantDQ( TransformUnit& tu, const CCoeffBuf& srcCoeff, const ComponentID compID, const QpParam& cQP, const double lambda, const Ctx& ctx, TCoeff& absSum, bool enableScalingLists, int* quantCoeff ) |
1129 | 1.78M | { |
1130 | 1.78M | using namespace DQIntern; |
1131 | | |
1132 | | //===== reset / pre-init ===== |
1133 | 1.78M | const TUParameters& tuPars = *m_scansRom->getTUPars( tu.blocks[compID], compID ); |
1134 | 1.78M | m_quant.initQuantBlock ( tu, compID, cQP, lambda ); |
1135 | 1.78M | TCoeffSig* qCoeff = tu.getCoeffs( compID ).buf; |
1136 | 1.78M | const TCoeff* tCoeff = srcCoeff.buf; |
1137 | 1.78M | const int numCoeff = tu.blocks[compID].area(); |
1138 | 1.78M | ::memset( qCoeff, 0x00, numCoeff * sizeof( TCoeffSig ) ); |
1139 | 1.78M | absSum = 0; |
1140 | | |
1141 | 1.78M | const CompArea& area = tu.blocks[ compID ]; |
1142 | 1.78M | const uint32_t width = area.width; |
1143 | 1.78M | const uint32_t height = area.height; |
1144 | 1.78M | const uint32_t lfnstIdx = tu.cu->lfnstIdx; |
1145 | | //===== scaling matrix ==== |
1146 | | //const int qpDQ = cQP.Qp + 1; |
1147 | | //const int qpPer = qpDQ / 6; |
1148 | | //const int qpRem = qpDQ - 6 * qpPer; |
1149 | | |
1150 | | //TCoeff thresTmp = thres; |
1151 | 1.78M | bool zeroOut = false; |
1152 | 1.78M | bool zeroOutforThres = false; |
1153 | 1.78M | int effWidth = tuPars.m_width, effHeight = tuPars.m_height; |
1154 | 1.78M | if( ( tu.mtsIdx[compID] > MTS_SKIP || ( tu.cs->sps->MTS && tu.cu->sbtInfo != 0 && tuPars.m_height <= 32 && tuPars.m_width <= 32 ) ) && compID == COMP_Y ) |
1155 | 0 | { |
1156 | 0 | effHeight = ( tuPars.m_height == 32 ) ? 16 : tuPars.m_height; |
1157 | 0 | effWidth = ( tuPars.m_width == 32 ) ? 16 : tuPars.m_width; |
1158 | 0 | zeroOut = ( effHeight < tuPars.m_height || effWidth < tuPars.m_width ); |
1159 | 0 | } |
1160 | 1.78M | zeroOutforThres = zeroOut || ( 32 < tuPars.m_height || 32 < tuPars.m_width ); |
1161 | | //===== find first test position ===== |
1162 | 1.78M | int firstTestPos = std::min<int>( tuPars.m_width, JVET_C0024_ZERO_OUT_TH ) * std::min<int>( tuPars.m_height, JVET_C0024_ZERO_OUT_TH ) - 1; |
1163 | 1.78M | if( lfnstIdx > 0 && tu.mtsIdx[compID] != MTS_SKIP && width >= 4 && height >= 4 ) |
1164 | 1.11M | { |
1165 | 1.11M | firstTestPos = ( ( width == 4 && height == 4 ) || ( width == 8 && height == 8 ) ) ? 7 : 15 ; |
1166 | 1.11M | } |
1167 | | |
1168 | 1.78M | const TCoeff defaultQuantisationCoefficient = (TCoeff)m_quant.getQScale(); |
1169 | 1.78M | const TCoeff thres = m_quant.getLastThreshold(); |
1170 | 1.78M | const int zeroOutWidth = ( tuPars.m_width == 32 && zeroOut ) ? 16 : 32; |
1171 | 1.78M | const int zeroOutHeight = ( tuPars.m_height == 32 && zeroOut ) ? 16 : 32; |
1172 | | |
1173 | 1.78M | if( enableScalingLists ) |
1174 | 0 | { |
1175 | 0 | for( ; firstTestPos >= 0; firstTestPos-- ) |
1176 | 0 | { |
1177 | 0 | if( zeroOutforThres && ( tuPars.m_scanId2BlkPos[firstTestPos].x >= zeroOutWidth || tuPars.m_scanId2BlkPos[firstTestPos].y >= zeroOutHeight ) ) continue; |
1178 | | |
1179 | 0 | const TCoeff thresTmp = TCoeff( thres / ( 4 * quantCoeff[tuPars.m_scanId2BlkPos[firstTestPos].idx] ) ); |
1180 | |
|
1181 | 0 | if( abs( tCoeff[tuPars.m_scanId2BlkPos[firstTestPos].idx] ) > thresTmp ) break; |
1182 | 0 | } |
1183 | 0 | } |
1184 | 1.78M | else |
1185 | 1.78M | { |
1186 | 1.78M | const TCoeff defaultTh = TCoeff( thres / ( defaultQuantisationCoefficient << 2 ) ); |
1187 | | |
1188 | 1.78M | m_findFirstPos( firstTestPos, tCoeff, tuPars, defaultTh, zeroOutforThres, zeroOutWidth, zeroOutHeight ); |
1189 | 1.78M | } |
1190 | | |
1191 | 1.78M | if( firstTestPos < 0 ) |
1192 | 1.03M | { |
1193 | 1.03M | tu.lastPos[compID] = -1; |
1194 | 1.03M | return; |
1195 | 1.03M | } |
1196 | | |
1197 | | //===== real init ===== |
1198 | 750k | RateEstimator::initCtx( tuPars, tu, compID, ctx.getFracBitsAcess() ); |
1199 | 750k | m_commonCtx.reset( tuPars, *this ); |
1200 | 3.75M | for( int k = 0; k < 4; k++ ) |
1201 | 3.00M | { |
1202 | 3.00M | DQIntern::initStates( k, m_state_curr ); |
1203 | 3.00M | DQIntern::initStates( k, m_state_skip ); |
1204 | 3.00M | m_state_curr.m_sigFracBitsArray[k] = RateEstimator::sigFlagBits(k); |
1205 | 3.00M | } |
1206 | | |
1207 | 750k | m_state_curr.m_gtxFracBitsArray = RateEstimator::gtxFracBits(); |
1208 | | //memset( m_state_curr.tplAcc, 0, sizeof( m_state_curr.tplAcc ) ); // will be set in updateStates{,EOS} before first access |
1209 | 750k | memset( m_state_curr.sum1st, 0, sizeof( m_state_curr.sum1st ) ); // will be accessed in setRiceParam before updateState{,EOS} |
1210 | | //memset( m_state_curr.absVal, 0, sizeof( m_state_curr.absVal ) ); // will be set in updateStates{,EOS} before first access |
1211 | | |
1212 | 750k | const int numCtx = isLuma( compID ) ? 21 : 11; |
1213 | 750k | const CoeffFracBits* const cffBits = gtxFracBits(); |
1214 | 9.29M | for( int i = 0; i < numCtx; i++ ) |
1215 | 8.54M | { |
1216 | 8.54M | m_state_curr.cffBits1[i] = cffBits[i].bits[1]; |
1217 | 8.54M | } |
1218 | | |
1219 | 750k | int effectWidth = std::min( 32, effWidth ); |
1220 | 750k | int effectHeight = std::min( 32, effHeight ); |
1221 | 750k | m_state_curr.initRemRegBins = ( effectWidth * effectHeight * MAX_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT ) / 16; |
1222 | 750k | m_state_curr.anyRemRegBinsLt4 = true; // for the first coeff use scalar impl., because it check against the init state, which |
1223 | | // prohibits some paths |
1224 | | |
1225 | | //===== populate trellis ===== |
1226 | 7.92M | for( int scanIdx = firstTestPos; scanIdx >= 0; scanIdx-- ) |
1227 | 7.17M | { |
1228 | 7.17M | const ScanInfo& scanInfo = tuPars.m_scanInfo[ scanIdx ]; |
1229 | 7.17M | if( enableScalingLists ) |
1230 | 0 | { |
1231 | 0 | m_quant.initQuantBlock( tu, compID, cQP, lambda, quantCoeff[scanInfo.rasterPos] ); |
1232 | 0 | xDecideAndUpdate( abs( tCoeff[scanInfo.rasterPos] ), scanInfo, zeroOut && ( scanInfo.posX >= effWidth || scanInfo.posY >= effHeight ), quantCoeff[scanInfo.rasterPos] ); |
1233 | 0 | } |
1234 | 7.17M | else |
1235 | 7.17M | xDecideAndUpdate( abs( tCoeff[scanInfo.rasterPos] ), scanInfo, zeroOut && ( scanInfo.posX >= effWidth || scanInfo.posY >= effHeight ), defaultQuantisationCoefficient ); |
1236 | 7.17M | } |
1237 | | |
1238 | | //===== find best path ===== |
1239 | 750k | int prevId = -1; |
1240 | 750k | int64_t minPathCost = 0; |
1241 | 3.75M | for( int8_t stateId = 0; stateId < 4; stateId++ ) |
1242 | 3.00M | { |
1243 | 3.00M | int64_t pathCost = m_trellis[0][0].rdCost[stateId]; |
1244 | 3.00M | if( pathCost < minPathCost ) |
1245 | 1.28M | { |
1246 | 1.28M | prevId = stateId; |
1247 | 1.28M | minPathCost = pathCost; |
1248 | 1.28M | } |
1249 | 3.00M | } |
1250 | | |
1251 | | //===== backward scanning ===== |
1252 | 750k | int scanIdx = 0; |
1253 | 7.83M | for( ; prevId >= 0; scanIdx++ ) |
1254 | 7.08M | { |
1255 | 7.08M | TCoeffSig absLevel = m_trellis[scanIdx][prevId >> 2].absLevel[prevId & 3]; |
1256 | 7.08M | int32_t blkpos = tuPars.m_scanId2BlkPos[scanIdx].idx; |
1257 | | // apply the coefficient's sign without a branch: (absLevel ^ m) - m is -absLevel for m = -1 and absLevel for m = 0 |
1258 | 7.08M | const int signMask = -int( tCoeff[blkpos] < 0 ); |
1259 | 7.08M | qCoeff[ blkpos ] = TCoeffSig( ( absLevel ^ signMask ) - signMask ); |
1260 | 7.08M | absSum += absLevel; |
1261 | 7.08M | prevId = m_trellis[scanIdx][prevId >> 2].prevId[prevId & 3]; |
1262 | 7.08M | } |
1263 | | |
1264 | 750k | tu.lastPos[compID] = scanIdx - 1; |
1265 | 750k | } |
1266 | | |
1267 | | void DepQuant::xDecide( const DQIntern::ScanInfo& scanInfo, const TCoeff absCoeff, const int lastOffset, DQIntern::Decisions& decisions, bool zeroOut, int quantCoeff ) |
1268 | 7.17M | { |
1269 | 7.17M | using namespace DQIntern; |
1270 | | |
1271 | 7.17M | ::memcpy( &decisions, startDec, sizeof( Decisions ) ); |
1272 | | |
1273 | 7.17M | StateMem& skip = m_state_skip; |
1274 | | |
1275 | 7.17M | if( zeroOut ) |
1276 | 0 | { |
1277 | 0 | if( scanInfo.spt == SCAN_EOCSBB ) |
1278 | 0 | { |
1279 | 0 | checkRdCostSkipSbbZeroOut( 0, decisions, 0, skip ); |
1280 | 0 | checkRdCostSkipSbbZeroOut( 1, decisions, 1, skip ); |
1281 | 0 | checkRdCostSkipSbbZeroOut( 2, decisions, 2, skip ); |
1282 | 0 | checkRdCostSkipSbbZeroOut( 3, decisions, 3, skip ); |
1283 | 0 | } |
1284 | 0 | return; |
1285 | 0 | } |
1286 | | |
1287 | 7.17M | StateMem& prev = m_state_curr; |
1288 | | |
1289 | | /// start inline prequant |
1290 | 7.17M | int64_t scaledOrg = int64_t( absCoeff ) * quantCoeff; |
1291 | 7.17M | TCoeff qIdx = TCoeff( ( scaledOrg + m_quant.m_QAdd ) >> m_quant.m_QShift ); |
1292 | | |
1293 | 7.17M | if( qIdx < 0 ) |
1294 | 1.18M | { |
1295 | 1.18M | int64_t scaledAdd = m_quant.m_DistStepAdd - scaledOrg * m_quant.m_DistOrgFact; |
1296 | 1.18M | int64_t pq_a_dist = ( ( scaledAdd + 0 * m_quant.m_DistStepAdd ) * 1 + m_quant.m_DistAdd ) >> m_quant.m_DistShift; |
1297 | 1.18M | int64_t pq_b_dist = ( ( scaledAdd + 1 * m_quant.m_DistStepAdd ) * 2 + m_quant.m_DistAdd ) >> m_quant.m_DistShift; |
1298 | | /// stop inline prequant |
1299 | | |
1300 | 1.18M | if( prev.anyRemRegBinsLt4 ) |
1301 | 82.5k | { |
1302 | 82.5k | setRiceParam( 0, scanInfo, prev, false ); |
1303 | 82.5k | checkRdCostsOdd1( 0, scanInfo.spt, pq_b_dist, decisions, 2, 0, prev ); |
1304 | | |
1305 | 82.5k | setRiceParam( 1, scanInfo, prev, false ); |
1306 | 82.5k | checkRdCostsOdd1( 1, scanInfo.spt, pq_b_dist, decisions, 0, 2, prev ); |
1307 | | |
1308 | 82.5k | setRiceParam( 2, scanInfo, prev, false ); |
1309 | 82.5k | checkRdCostsOdd1( 2, scanInfo.spt, pq_a_dist, decisions, 3, 1, prev ); |
1310 | | |
1311 | 82.5k | setRiceParam( 3, scanInfo, prev, false ); |
1312 | 82.5k | checkRdCostsOdd1( 3, scanInfo.spt, pq_a_dist, decisions, 1, 3, prev ); |
1313 | 82.5k | } |
1314 | 1.10M | else |
1315 | 1.10M | { |
1316 | | // has to be called as a first check, assumes no decision has been made yet |
1317 | 1.10M | m_checkAllRdCostsOdd1( scanInfo.spt, pq_a_dist, pq_b_dist, decisions, prev ); |
1318 | 1.10M | } |
1319 | | |
1320 | 1.18M | checkRdCostStart( lastOffset, PQData{ 1, pq_b_dist }, decisions, 2, prev ); |
1321 | 1.18M | } |
1322 | 5.98M | else |
1323 | 5.98M | { |
1324 | | /// start inline prequant |
1325 | 5.98M | qIdx = std::max<TCoeff>( 1, std::min<TCoeff>( m_quant.m_maxQIdx, qIdx ) ); |
1326 | 5.98M | int64_t scaledAdd = qIdx * m_quant.m_DistStepAdd - scaledOrg * m_quant.m_DistOrgFact; |
1327 | | |
1328 | 5.98M | PQData pqData[4]; |
1329 | | |
1330 | 5.98M | PQData& pq_a = pqData[( qIdx + 0 ) & 3]; |
1331 | 5.98M | PQData& pq_b = pqData[( qIdx + 1 ) & 3]; |
1332 | 5.98M | PQData& pq_c = pqData[( qIdx + 2 ) & 3]; |
1333 | 5.98M | PQData& pq_d = pqData[( qIdx + 3 ) & 3]; |
1334 | | |
1335 | 5.98M | pq_a.deltaDist = ( ( scaledAdd + 0 * m_quant.m_DistStepAdd ) * ( qIdx + 0 ) + m_quant.m_DistAdd ) >> m_quant.m_DistShift; |
1336 | 5.98M | pq_a.absLevel = ( qIdx + 1 ) >> 1; |
1337 | | |
1338 | 5.98M | pq_b.deltaDist = ( ( scaledAdd + 1 * m_quant.m_DistStepAdd ) * ( qIdx + 1 ) + m_quant.m_DistAdd ) >> m_quant.m_DistShift; |
1339 | 5.98M | pq_b.absLevel = ( qIdx + 2 ) >> 1; |
1340 | | |
1341 | 5.98M | pq_c.deltaDist = ( ( scaledAdd + 2 * m_quant.m_DistStepAdd ) * ( qIdx + 2 ) + m_quant.m_DistAdd ) >> m_quant.m_DistShift; |
1342 | 5.98M | pq_c.absLevel = ( qIdx + 3 ) >> 1; |
1343 | | |
1344 | 5.98M | pq_d.deltaDist = ( ( scaledAdd + 3 * m_quant.m_DistStepAdd ) * ( qIdx + 3 ) + m_quant.m_DistAdd ) >> m_quant.m_DistShift; |
1345 | 5.98M | pq_d.absLevel = ( qIdx + 4 ) >> 1; |
1346 | | /// stop inline prequant |
1347 | | |
1348 | 5.98M | bool cff02ge4 = pqData[0].absLevel >= 4/* || pqData[2].absLevel >= 4 */; |
1349 | 5.98M | bool cff13ge4 = /* pqData[1].absLevel >= 4 || */ pqData[3].absLevel >= 4; |
1350 | | |
1351 | 5.98M | if( cff02ge4 || cff13ge4 || prev.anyRemRegBinsLt4 ) |
1352 | 4.91M | { |
1353 | 4.91M | if( prev.anyRemRegBinsLt4 || cff02ge4 ) |
1354 | 4.68M | { |
1355 | 4.68M | setRiceParam( 0, scanInfo, prev, cff02ge4 ); |
1356 | 4.68M | setRiceParam( 1, scanInfo, prev, cff02ge4 ); |
1357 | 4.68M | } |
1358 | | |
1359 | 4.91M | if( prev.anyRemRegBinsLt4 || cff13ge4 ) |
1360 | 4.91M | { |
1361 | 4.91M | setRiceParam( 2, scanInfo, prev, cff13ge4 ); |
1362 | 4.91M | setRiceParam( 3, scanInfo, prev, cff13ge4 ); |
1363 | 4.91M | } |
1364 | | |
1365 | 4.91M | checkRdCosts( 0, scanInfo.spt, pqData[0], pqData[2], decisions, 0, 2, prev ); |
1366 | 4.91M | checkRdCosts( 1, scanInfo.spt, pqData[0], pqData[2], decisions, 2, 0, prev ); |
1367 | 4.91M | checkRdCosts( 2, scanInfo.spt, pqData[3], pqData[1], decisions, 1, 3, prev ); |
1368 | 4.91M | checkRdCosts( 3, scanInfo.spt, pqData[3], pqData[1], decisions, 3, 1, prev ); |
1369 | 4.91M | } |
1370 | 1.07M | else |
1371 | 1.07M | { |
1372 | | // has to be called as a first check, assumes no decision has been made yet |
1373 | 1.07M | m_checkAllRdCosts( scanInfo.spt, pqData, decisions, prev ); |
1374 | 1.07M | } |
1375 | | |
1376 | 5.98M | checkRdCostStart( lastOffset, pqData[0], decisions, 0, prev ); |
1377 | 5.98M | checkRdCostStart( lastOffset, pqData[2], decisions, 2, prev ); |
1378 | 5.98M | } |
1379 | | |
1380 | 7.17M | if( scanInfo.spt == SCAN_EOCSBB ) |
1381 | 27.8k | { |
1382 | 27.8k | checkRdCostSkipSbb( 0, decisions, 0, skip ); |
1383 | 27.8k | checkRdCostSkipSbb( 1, decisions, 1, skip ); |
1384 | 27.8k | checkRdCostSkipSbb( 2, decisions, 2, skip ); |
1385 | 27.8k | checkRdCostSkipSbb( 3, decisions, 3, skip ); |
1386 | 27.8k | } |
1387 | 7.17M | } |
1388 | | |
1389 | | void DepQuant::xDecideAndUpdate( const TCoeff absCoeff, const DQIntern::ScanInfo& scanInfo, bool zeroOut, int quantCoeff ) |
1390 | 7.17M | { |
1391 | 7.17M | using namespace DQIntern; |
1392 | | |
1393 | 7.17M | Decisions* decisions = &m_trellis[scanInfo.scanIdx][0]; |
1394 | | |
1395 | 7.17M | xDecide( scanInfo, absCoeff, lastOffset( scanInfo.scanIdx ), *decisions, zeroOut, quantCoeff ); |
1396 | | |
1397 | 7.17M | if( scanInfo.scanIdx ) |
1398 | 6.42M | { |
1399 | 6.42M | if( scanInfo.spt == SCAN_SOCSBB ) |
1400 | 24.5k | { |
1401 | 24.5k | memcpy( &m_state_skip, &m_state_curr, DQIntern::StateMemSkipCpySize ); |
1402 | 24.5k | } |
1403 | | |
1404 | 6.42M | if( scanInfo.insidePos == 0 ) |
1405 | 29.4k | { |
1406 | 29.4k | m_commonCtx.swap(); |
1407 | 29.4k | m_updateStatesEOS( scanInfo, *decisions, m_state_skip, m_state_curr, m_commonCtx ); |
1408 | 29.4k | ::memcpy( decisions + 1, decisions, sizeof( Decisions ) ); |
1409 | 29.4k | } |
1410 | 6.39M | else if( !zeroOut ) |
1411 | 6.39M | { |
1412 | 6.39M | m_updateStates( scanInfo, *decisions, m_state_curr ); |
1413 | 6.39M | } |
1414 | 6.42M | } |
1415 | 7.17M | } |
1416 | | |
1417 | | void DepQuant::xDequantDQ( const TransformUnit& tu, CoeffBuf& recCoeff, const ComponentID compID, const QpParam& cQP, bool enableScalingLists, int* piDequantCoef ) |
1418 | 739k | { |
1419 | 739k | m_quant.dequantBlock( tu, compID, cQP, recCoeff, enableScalingLists, piDequantCoef ); |
1420 | 739k | } |
1421 | | |
1422 | 4.62k | DepQuant::DepQuant( const Quant* other, bool enc, bool useScalingLists, bool enableOpt ) : QuantRDOQ2( other, useScalingLists, enableOpt ), RateEstimator(), m_commonCtx() |
1423 | 4.62k | { |
1424 | 4.62k | const DepQuant* dq = dynamic_cast<const DepQuant*>( other ); |
1425 | 4.62k | CHECK( other && !dq, "The DepQuant cast must be successfull!" ); |
1426 | | |
1427 | 4.62k | if( !dq ) |
1428 | 1.15k | { |
1429 | 1.15k | m_scansRom = std::make_shared<DQIntern::Rom>(); |
1430 | 1.15k | m_scansRom->init(); |
1431 | 1.15k | } |
1432 | 3.46k | else |
1433 | 3.46k | { |
1434 | 3.46k | m_scansRom = dq->m_scansRom; |
1435 | 3.46k | } |
1436 | | |
1437 | 18.9M | for( int t = 0; t < ( MAX_TB_SIZEY * MAX_TB_SIZEY ); t++ ) |
1438 | 18.9M | { |
1439 | 18.9M | memcpy( m_trellis[t], startDec, sizeof( startDec ) ); |
1440 | 18.9M | } |
1441 | | |
1442 | 4.62k | m_checkAllRdCosts = DQIntern::checkAllRdCosts; |
1443 | 4.62k | m_checkAllRdCostsOdd1 = DQIntern::checkAllRdCostsOdd1; |
1444 | 4.62k | m_updateStatesEOS = DQIntern::updateStatesEOS; |
1445 | 4.62k | m_updateStates = DQIntern::updateStates; |
1446 | 4.62k | m_findFirstPos = DQIntern::findFirstPos; |
1447 | | |
1448 | 4.62k | if( enableOpt ) |
1449 | 4.62k | { |
1450 | | #if defined( TARGET_SIMD_X86 ) && ENABLE_SIMD_OPT_QUANT |
1451 | | initDepQuantX86(); |
1452 | | #endif |
1453 | | #if defined( TARGET_SIMD_ARM ) && ENABLE_SIMD_OPT_QUANT |
1454 | | initDepQuantARM(); |
1455 | | #endif |
1456 | 4.62k | } |
1457 | 4.62k | } |
1458 | | |
1459 | | DepQuant::~DepQuant() |
1460 | 4.62k | { |
1461 | 4.62k | } |
1462 | | |
1463 | | void DepQuant::quant( TransformUnit& tu, const ComponentID compID, const CCoeffBuf& pSrc, TCoeff& uiAbsSum, const QpParam& cQP, const Ctx& ctx ) |
1464 | 1.88M | { |
1465 | 1.88M | if( tu.cs->picture->useSelectiveRdoq && !xNeedRDOQ( tu, compID, pSrc, cQP ) ) |
1466 | 0 | { |
1467 | 0 | tu.lastPos[compID] = -1; |
1468 | 0 | uiAbsSum = 0; |
1469 | 0 | } |
1470 | 1.88M | else if( tu.cs->slice->depQuantEnabled && tu.mtsIdx[compID] != MTS_SKIP ) |
1471 | 1.78M | { |
1472 | | //===== scaling matrix ==== |
1473 | 1.78M | const int qpDQ = cQP.Qp(tu.mtsIdx[compID]==MTS_SKIP) + 1; |
1474 | 1.78M | const int qpPer = qpDQ / 6; |
1475 | 1.78M | const int qpRem = qpDQ - 6 * qpPer; |
1476 | 1.78M | const CompArea &rect = tu.blocks[compID]; |
1477 | 1.78M | const int width = rect.width; |
1478 | 1.78M | const int height = rect.height; |
1479 | 1.78M | uint32_t scalingListType = getScalingListType(tu.cu->predMode, compID); |
1480 | 1.78M | CHECK(scalingListType >= SCALING_LIST_NUM, "Invalid scaling list"); |
1481 | 1.78M | const uint32_t log2TrWidth = Log2(width); |
1482 | 1.78M | const uint32_t log2TrHeight = Log2(height); |
1483 | 1.78M | const bool isLfnstApplied = tu.cu->lfnstIdx > 0 && (CU::isSepTree(*tu.cu) ? true : isLuma(compID)); |
1484 | 1.78M | const bool enableScalingLists = getUseScalingList(width, height, (tu.mtsIdx[compID] == MTS_SKIP), isLfnstApplied); |
1485 | 1.78M | xQuantDQ( tu, pSrc, compID, cQP, Quant::m_dLambda, ctx, uiAbsSum, enableScalingLists, Quant::getQuantCoeff(scalingListType, qpRem, log2TrWidth, log2TrHeight) ); |
1486 | 1.78M | } |
1487 | 98.3k | else |
1488 | 98.3k | { |
1489 | 98.3k | QuantRDOQ2::quant( tu, compID, pSrc, uiAbsSum, cQP, ctx ); |
1490 | 98.3k | } |
1491 | 1.88M | } |
1492 | | |
1493 | | void DepQuant::dequant( const TransformUnit& tu, CoeffBuf& dstCoeff, const ComponentID compID, const QpParam& cQP ) |
1494 | 785k | { |
1495 | 785k | if( tu.cs->slice->depQuantEnabled && (tu.mtsIdx[compID] != MTS_SKIP) ) |
1496 | 739k | { |
1497 | 739k | const int qpDQ = cQP.Qp(tu.mtsIdx[compID]==MTS_SKIP) + 1; |
1498 | 739k | const int qpPer = qpDQ / 6; |
1499 | 739k | const int qpRem = qpDQ - 6 * qpPer; |
1500 | 739k | const CompArea &rect = tu.blocks[compID]; |
1501 | 739k | const int width = rect.width; |
1502 | 739k | const int height = rect.height; |
1503 | 739k | uint32_t scalingListType = getScalingListType(tu.cu->predMode, compID); |
1504 | 739k | CHECK(scalingListType >= SCALING_LIST_NUM, "Invalid scaling list"); |
1505 | 739k | const uint32_t log2TrWidth = Log2(width); |
1506 | 739k | const uint32_t log2TrHeight = Log2(height); |
1507 | 739k | const bool isLfnstApplied = tu.cu->lfnstIdx > 0 && (CU::isSepTree(*tu.cu) ? true : isLuma(compID)); |
1508 | 739k | const bool enableScalingLists = getUseScalingList(width, height, (tu.mtsIdx[compID] == MTS_SKIP), isLfnstApplied); |
1509 | 739k | xDequantDQ( tu, dstCoeff, compID, cQP, enableScalingLists, Quant::getDequantCoeff(scalingListType, qpRem, log2TrWidth, log2TrHeight) ); |
1510 | 739k | } |
1511 | 46.2k | else |
1512 | 46.2k | { |
1513 | 46.2k | QuantRDOQ::dequant( tu, dstCoeff, compID, cQP ); |
1514 | 46.2k | } |
1515 | 785k | } |
1516 | | |
1517 | | void DepQuant::init( int rdoq, bool useRDOQTS, int thrVal ) |
1518 | 4.62k | { |
1519 | 4.62k | QuantRDOQ2::init( rdoq, useRDOQTS, thrVal ); |
1520 | 4.62k | m_quant.init( thrVal ); |
1521 | 4.62k | } |
1522 | | |
1523 | | } // namespace vvenc |
1524 | | |
1525 | | //! \} |
1526 | | |