/work/vvenc/source/Lib/CommonLib/ContextModelling.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 | | |
44 | | /** \file ContextModelling.cpp |
45 | | \brief Classes providing probability descriptions and contexts |
46 | | */ |
47 | | |
48 | | #include "ContextModelling.h" |
49 | | #include "UnitTools.h" |
50 | | #include "CodingStructure.h" |
51 | | #include "Picture.h" |
52 | | |
53 | | //! \ingroup CommonLib |
54 | | //! \{ |
55 | | |
56 | | namespace vvenc { |
57 | | |
58 | | const uint8_t g_sigCtxOfsSum [32] = { 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; |
59 | | const uint8_t g_sigCtxOfsDiag[MAX_NUM_CH][128] = { { 8, 8, 4, 4, 4 }, { 4, 4 } }; // 0 from there on |
60 | | const uint8_t g_absCtxOfsDiag[MAX_NUM_CH][128] = { { 15, 10, 10, 5, 5, 5, 5, 5, 5, 5 }, { 5 } }; |
61 | | |
62 | | // The fields of a CoeffCodingContext that depend only on the channel type and the block size. They are worked out for |
63 | | // every size once, when the library loads (from constant tables only), so that a context copies them. |
64 | | struct CoeffCodingContext::SizeInfo |
65 | | { |
66 | | unsigned log2CGWidth, log2CGHeight; |
67 | | unsigned widthInGroups, heightInGroups, log2WidthInGroups; |
68 | | const ScanElement* scan; |
69 | | const ScanElement* scanCG; |
70 | | unsigned maxLastPosX, maxLastPosY; |
71 | | int lastOffsetX, lastOffsetY; |
72 | | int lastShiftX, lastShiftY; |
73 | | |
74 | | SizeInfo() = default; |
75 | | SizeInfo( const ChannelType chType, const unsigned log2Width, const unsigned log2Height ) |
76 | 1.37k | { |
77 | 1.37k | const unsigned width = 1u << log2Width; |
78 | 1.37k | const unsigned height = 1u << log2Height; |
79 | 1.37k | log2CGWidth = g_log2SbbSize[log2Width][log2Height][0]; |
80 | 1.37k | log2CGHeight = g_log2SbbSize[log2Width][log2Height][1]; |
81 | 1.37k | widthInGroups = std::min<unsigned>( JVET_C0024_ZERO_OUT_TH, width ) >> log2CGWidth; |
82 | 1.37k | heightInGroups = std::min<unsigned>( JVET_C0024_ZERO_OUT_TH, height ) >> log2CGHeight; |
83 | 1.37k | log2WidthInGroups = Log2( widthInGroups ); |
84 | 1.37k | scan = getScanOrder( SCAN_GROUPED_4x4, log2Width, log2Height ); |
85 | 1.37k | scanCG = getScanOrder( SCAN_UNGROUPED, Log2( widthInGroups ), Log2( heightInGroups ) ); |
86 | 1.37k | maxLastPosX = lastPosMaxGroup( log2Width ); |
87 | 1.37k | maxLastPosY = lastPosMaxGroup( log2Height ); |
88 | 1.37k | lastOffsetX = lastPosCtxOffset( chType, log2Width ); |
89 | 1.37k | lastOffsetY = lastPosCtxOffset( chType, log2Height ); |
90 | 1.37k | lastShiftX = lastPosCtxShift( chType, log2Width ); |
91 | 1.37k | lastShiftY = lastPosCtxShift( chType, log2Height ); |
92 | 1.37k | } |
93 | | }; |
94 | | |
95 | | struct CoeffCodingContext::SizeInfoTable |
96 | | { |
97 | | SizeInfo info[MAX_NUM_CH][MAX_TU_SIZE_IDX][MAX_TU_SIZE_IDX]; |
98 | | |
99 | | SizeInfoTable() |
100 | 14 | { |
101 | 42 | for( int ch = 0; ch < MAX_NUM_CH; ch++ ) |
102 | 224 | for( unsigned log2Width = 0; log2Width < MAX_TU_SIZE_IDX; log2Width++ ) |
103 | 1.56k | for( unsigned log2Height = 0; log2Height < MAX_TU_SIZE_IDX; log2Height++ ) |
104 | 1.37k | info[ch][log2Width][log2Height] = SizeInfo( ChannelType( ch ), log2Width, log2Height ); |
105 | 14 | } |
106 | | }; |
107 | | |
108 | | const CoeffCodingContext::SizeInfoTable CoeffCodingContext::s_sizeInfo; |
109 | | |
110 | | CoeffCodingContext::CoeffCodingContext( const TransformUnit& tu, ComponentID component, bool signHide, bool bdpcm, CtxTpl* tplBuf, int scanPosLast ) |
111 | 1.24M | : CoeffCodingContext( tu, component, signHide, bdpcm, tplBuf, scanPosLast, |
112 | 1.24M | s_sizeInfo.info[toChannelType( component )][Log2( tu.block( component ).width )][Log2( tu.block( component ).height )] ) |
113 | 1.24M | { |
114 | 1.24M | } |
115 | | |
116 | | CoeffCodingContext::CoeffCodingContext( const TransformUnit& tu, ComponentID component, bool signHide, bool bdpcm, CtxTpl* tplBuf, int scanPosLast, const SizeInfo& size ) |
117 | 1.24M | : m_compID (component) |
118 | 1.24M | , m_chType (toChannelType(m_compID)) |
119 | 1.24M | , m_width (tu.block(m_compID).width) |
120 | 1.24M | , m_height (tu.block(m_compID).height) |
121 | 1.24M | , m_log2CGWidth (size.log2CGWidth) |
122 | 1.24M | , m_log2CGHeight (size.log2CGHeight) |
123 | 1.24M | , m_log2CGSize (m_log2CGWidth + m_log2CGHeight) |
124 | 1.24M | , m_widthInGroups (size.widthInGroups) |
125 | 1.24M | , m_heightInGroups (size.heightInGroups) |
126 | 1.24M | , m_log2WidthInGroups (size.log2WidthInGroups) |
127 | 1.24M | , m_log2BlockWidth (Log2(m_width)) |
128 | 1.24M | , m_log2BlockHeight (Log2(m_height)) |
129 | 1.24M | , m_maxNumCoeff (m_width * m_height) |
130 | 1.24M | , m_signHiding (signHide) |
131 | 1.24M | , m_maxLog2TrDynamicRange (tu.cs->sps->getMaxLog2TrDynamicRange()) |
132 | 1.24M | , m_scan (size.scan) |
133 | 1.24M | , m_scanCG (size.scanCG) |
134 | 1.24M | , m_CtxSetLastX (Ctx::LastX[m_chType]) |
135 | 1.24M | , m_CtxSetLastY (Ctx::LastY[m_chType]) |
136 | 1.24M | , m_maxLastPosX (size.maxLastPosX) |
137 | 1.24M | , m_maxLastPosY (size.maxLastPosY) |
138 | 1.24M | , m_lastOffsetX (size.lastOffsetX) |
139 | 1.24M | , m_lastOffsetY (size.lastOffsetY) |
140 | 1.24M | , m_lastShiftX (size.lastShiftX) |
141 | 1.24M | , m_lastShiftY (size.lastShiftY) |
142 | 1.24M | , m_scanPosLast (-1) |
143 | 1.24M | , m_subSetId (-1) |
144 | 1.24M | , m_subSetPos (-1) |
145 | 1.24M | , m_subSetPosX (-1) |
146 | 1.24M | , m_subSetPosY (-1) |
147 | 1.24M | , m_minSubPos (-1) |
148 | 1.24M | , m_maxSubPos (-1) |
149 | 1.24M | , m_sigGroupCtxId (-1) |
150 | 1.24M | , m_tmplCpSum1 (-1) |
151 | 1.24M | , m_tmplCpDiag (-1) |
152 | 1.24M | , m_sigFlagCtxSet { Ctx::SigFlag[m_chType], Ctx::SigFlag[m_chType], Ctx::SigFlag[m_chType+2], Ctx::SigFlag[m_chType+4] } |
153 | 1.24M | , m_parFlagCtxSet ( Ctx::ParFlag[m_chType] ) |
154 | 1.24M | , m_gtxFlagCtxSet { Ctx::GtxFlag[m_chType], Ctx::GtxFlag[m_chType+2] } |
155 | 1.24M | , m_sigGroupCtxIdTS (-1) |
156 | 1.24M | , m_tsSigFlagCtxSet ( Ctx::TsSigFlag ) |
157 | 1.24M | , m_tsParFlagCtxSet ( Ctx::TsParFlag ) |
158 | 1.24M | , m_tsGtxFlagCtxSet ( Ctx::TsGtxFlag ) |
159 | 1.24M | , m_tsLrg1FlagCtxSet (Ctx::TsLrg1Flag) |
160 | 1.24M | , m_tsSignFlagCtxSet (Ctx::TsResidualSign) |
161 | 1.24M | , m_sigCoeffGroupFlag () |
162 | 1.24M | , m_bdpcm (bdpcm) |
163 | 1.24M | , m_tplBuf (tplBuf + m_width * m_height - 1) |
164 | 1.24M | { |
165 | 1.24M | if( tplBuf && scanPosLast != DeferTplClear && ( tu.mtsIdx[ component ] != MTS_SKIP || tu.cu->slice->tsResidualCodingDisabled ) ) |
166 | 1.04M | { |
167 | | // With a known last position (scanPosLast >= 0) only positions up to it are read, and the templates only write to |
168 | | // positions before those. The diagonal scan of the groups and the scanned region (at most 32 rows, the zero-out) bound |
169 | | // their rows. The buffer runs backwards from position 0, so these rows are at its end. |
170 | 1.04M | unsigned rows = m_height; |
171 | 1.04M | if( scanPosLast >= 0 ) |
172 | 1.04M | { |
173 | 1.04M | const auto& lastGroup = m_scanCG[scanPosLast >> m_log2CGSize]; |
174 | 1.04M | rows = std::min<unsigned>( std::min<unsigned>( JVET_C0024_ZERO_OUT_TH, m_height ), ( lastGroup.x + lastGroup.y + 1u ) << m_log2CGHeight ); |
175 | 1.04M | } |
176 | 1.04M | memset( tplBuf + ( m_height - rows ) * m_width, 0, rows * m_width * sizeof( CtxTpl ) ); |
177 | 1.04M | } |
178 | 1.24M | } |
179 | | |
180 | | // The deferred part of the constructor (scanPosLast = DeferTplClear): clears the template buffer rows the positions up to |
181 | | // scanPosLast can read or write (as the constructor does for a known last position) |
182 | | void CoeffCodingContext::clearTemplates( int scanPosLast ) |
183 | 0 | { |
184 | 0 | CHECKD( scanPosLast < 0, "clearTemplates needs a last position" ); |
185 | 0 | const auto& lastGroup = m_scanCG[scanPosLast >> m_log2CGSize]; |
186 | 0 | const unsigned rows = std::min<unsigned>( std::min<unsigned>( JVET_C0024_ZERO_OUT_TH, m_height ), ( lastGroup.x + lastGroup.y + 1u ) << m_log2CGHeight ); |
187 | 0 | CtxTpl* tplBuf = m_tplBuf - ( m_width * m_height - 1 ); |
188 | 0 | memset( tplBuf + ( m_height - rows ) * m_width, 0, rows * m_width * sizeof( CtxTpl ) ); |
189 | 0 | } |
190 | | |
191 | | void CoeffCodingContext::initSubblock( int SubsetId, bool sigGroupFlag ) |
192 | 2.27M | { |
193 | | // the group's own flag is not among the neighbours the sig group context reads, so it can be set after it |
194 | 2.27M | initSubblockRegular( SubsetId ); |
195 | 2.27M | if( sigGroupFlag ) |
196 | 1.24M | { |
197 | 1.24M | m_sigCoeffGroupFlag.set ( m_subSetPos ); |
198 | 1.24M | } |
199 | 2.27M | unsigned sigLeft = unsigned( m_subSetPosX > 0 ? m_sigCoeffGroupFlag[m_subSetPos - 1 ] : false ); |
200 | 2.27M | unsigned sigAbove = unsigned( m_subSetPosY > 0 ? m_sigCoeffGroupFlag[m_subSetPos - m_widthInGroups] : false ); |
201 | 2.27M | m_sigGroupCtxIdTS = Ctx::TsSigCoeffGroup( sigLeft + sigAbove ); |
202 | 2.27M | } |
203 | | |
204 | | |
205 | | void DeriveCtx::determineNeighborCus( const CodingStructure& cs, const UnitArea& ua, const ChannelType ch, const TreeType _treeType ) |
206 | 567k | { |
207 | 567k | const Position& posLuma = ua.lumaPos(); |
208 | 567k | const Position& pos = ch == CH_L ? posLuma : ua.chromaPos(); |
209 | 567k | const uint32_t curSliceIdx = cs.slice->independentSliceIdx; |
210 | 567k | const uint32_t curTileIdx = cs.pps->getTileIdx( posLuma ); |
211 | | |
212 | 567k | cuRestrictedLeft[ch] = cs.getCURestricted( pos.offset(-1, 0), pos, curSliceIdx, curTileIdx, ch, _treeType ); |
213 | 567k | cuRestrictedAbove[ch] = cs.getCURestricted( pos.offset(0, -1), pos, curSliceIdx, curTileIdx, ch, _treeType ); |
214 | 567k | } |
215 | | |
216 | | void DeriveCtx::CtxSplit( const Partitioner& partitioner, unsigned& ctxSpl, unsigned& ctxQt, unsigned& ctxHv, unsigned& ctxHorBt, unsigned& ctxVerBt, const bool canSplit[6] ) const |
217 | 536k | { |
218 | 536k | const ChannelType chType = partitioner.chType; |
219 | 536k | const CodingUnit* cuLeft = cuRestrictedLeft[chType]; |
220 | 536k | const CodingUnit* cuAbove = cuRestrictedAbove[chType]; |
221 | | |
222 | | /////////////////////// |
223 | | // CTX do split (0-8) |
224 | | /////////////////////// |
225 | 536k | const unsigned widthCurr = partitioner.currArea().blocks[chType].width; |
226 | 536k | const unsigned heightCurr = partitioner.currArea().blocks[chType].height; |
227 | | |
228 | 536k | ctxSpl = 0; |
229 | | |
230 | 536k | if( cuLeft ) |
231 | 362k | { |
232 | 362k | const unsigned heightLeft = cuLeft->blocks[chType].height; |
233 | 362k | ctxSpl += ( heightLeft < heightCurr ? 1 : 0 ); |
234 | 362k | } |
235 | 536k | if( cuAbove ) |
236 | 371k | { |
237 | 371k | const unsigned widthAbove = cuAbove->blocks[chType].width; |
238 | 371k | ctxSpl += ( widthAbove < widthCurr ? 1 : 0 ); |
239 | 371k | } |
240 | | |
241 | 536k | unsigned numSplit = 0; |
242 | 536k | if( canSplit[1] ) numSplit += 2; |
243 | 536k | if( canSplit[2] ) numSplit += 1; |
244 | 536k | if( canSplit[3] ) numSplit += 1; |
245 | 536k | if( canSplit[4] ) numSplit += 1; |
246 | 536k | if( canSplit[5] ) numSplit += 1; |
247 | | |
248 | 536k | if( numSplit > 0 ) numSplit--; |
249 | | |
250 | 536k | ctxSpl += 3 * ( numSplit >> 1 ); |
251 | | |
252 | | ////////////////////////// |
253 | | // CTX is qt split (0-5) |
254 | | ////////////////////////// |
255 | 536k | ctxQt = ( cuLeft && cuLeft->qtDepth > partitioner.currQtDepth ) ? 1 : 0; |
256 | 536k | ctxQt += ( cuAbove && cuAbove->qtDepth > partitioner.currQtDepth ) ? 1 : 0; |
257 | 536k | ctxQt += partitioner.currQtDepth < 2 ? 0 : 3; |
258 | | |
259 | | //////////////////////////// |
260 | | // CTX is ver split (0-4) |
261 | | //////////////////////////// |
262 | 536k | ctxHv = 0; |
263 | | |
264 | 536k | const unsigned numHor = ( canSplit[2] ? 1 : 0 ) + ( canSplit[4] ? 1 : 0 ); |
265 | 536k | const unsigned numVer = ( canSplit[3] ? 1 : 0 ) + ( canSplit[5] ? 1 : 0 ); |
266 | | |
267 | 536k | if( numVer == numHor ) |
268 | 310k | { |
269 | 310k | const Area& area = partitioner.currArea().blocks[chType]; |
270 | | |
271 | 310k | const unsigned wAbove = cuAbove ? cuAbove->blocks[chType].width : 1; |
272 | 310k | const unsigned hLeft = cuLeft ? cuLeft ->blocks[chType].height : 1; |
273 | | |
274 | 310k | const unsigned depAbove = area.width / wAbove; |
275 | 310k | const unsigned depLeft = area.height / hLeft; |
276 | | |
277 | 310k | if( depAbove == depLeft || !cuLeft || !cuAbove ) ctxHv = 0; |
278 | 44.4k | else if( depAbove < depLeft ) ctxHv = 1; |
279 | 21.9k | else ctxHv = 2; |
280 | 310k | } |
281 | 226k | else if( numVer < numHor ) |
282 | 130k | { |
283 | 130k | ctxHv = 3; |
284 | 130k | } |
285 | 96.0k | else |
286 | 96.0k | { |
287 | 96.0k | ctxHv = 4; |
288 | 96.0k | } |
289 | | |
290 | | ////////////////////////// |
291 | | // CTX is h/v bt (0-3) |
292 | | ////////////////////////// |
293 | 536k | ctxHorBt = ( partitioner.currMtDepth <= 1 ? 1 : 0 ); |
294 | 536k | ctxVerBt = ( partitioner.currMtDepth <= 1 ? 3 : 2 ); |
295 | 536k | } |
296 | | |
297 | | |
298 | | |
299 | | void MergeCtx::setMergeInfo( CodingUnit& cu, int candIdx ) const |
300 | 180k | { |
301 | 180k | CHECK( candIdx >= numValidMergeCand, "Merge candidate does not exist" ); |
302 | 180k | cu.mergeFlag = true; |
303 | 180k | cu.mmvdMergeFlag = false; |
304 | 180k | cu.interDir = interDirNeighbours[candIdx]; |
305 | 180k | cu.imv = (!cu.geo && useAltHpelIf[candIdx]) ? IMV_HPEL : IMV_OFF; |
306 | 180k | cu.mergeIdx = candIdx; |
307 | 180k | cu.mergeType = mrgTypeNeighbours[candIdx]; |
308 | 180k | cu.mv [REF_PIC_LIST_0][0] = mvFieldNeighbours[candIdx][0].mv; |
309 | 180k | cu.mv [REF_PIC_LIST_1][0] = mvFieldNeighbours[candIdx][1].mv; |
310 | 180k | cu.mvd [REF_PIC_LIST_0][0] = Mv(); |
311 | 180k | cu.mvd [REF_PIC_LIST_1][0] = Mv(); |
312 | 180k | cu.refIdx [REF_PIC_LIST_0] = mvFieldNeighbours[candIdx][0].refIdx; |
313 | 180k | cu.refIdx [REF_PIC_LIST_1] = mvFieldNeighbours[candIdx][1].refIdx; |
314 | 180k | cu.mvpIdx [REF_PIC_LIST_0] = NOT_VALID; |
315 | 180k | cu.mvpIdx [REF_PIC_LIST_1] = NOT_VALID; |
316 | 180k | cu.mvpNum [REF_PIC_LIST_0] = NOT_VALID; |
317 | 180k | cu.mvpNum [REF_PIC_LIST_1] = NOT_VALID; |
318 | 180k | if( CU::isIBC( cu ) ) |
319 | 180k | { |
320 | 180k | cu.imv = cu.imv == IMV_HPEL ? IMV_OFF : cu.imv; |
321 | 180k | } |
322 | 180k | cu.BcwIdx = interDirNeighbours[candIdx] == 3 ? BcwIdx[candIdx] : BCW_DEFAULT; |
323 | 180k | cu.mcControl = 0; |
324 | 180k | cu.mvRefine = false; |
325 | | |
326 | 180k | CU::restrictBiPredMergeCandsOne( cu ); |
327 | 180k | } |
328 | | |
329 | | |
330 | | void MergeCtx::getMmvdDeltaMv( const Slice &slice, const MmvdIdx candIdx, Mv deltaMv[ NUM_REF_PIC_LIST_01 ] ) const |
331 | 0 | { |
332 | 0 | const int mvdBaseIdx = candIdx.pos.baseIdx; |
333 | 0 | const int mvdStep = candIdx.pos.step; |
334 | 0 | const int mvdPosition = candIdx.pos.position; |
335 | |
|
336 | 0 | int offset = 1 << ( mvdStep + MV_FRACTIONAL_BITS_DIFF ); |
337 | 0 | if( slice.picHeader->disFracMMVD ) |
338 | 0 | { |
339 | 0 | offset <<= 2; |
340 | 0 | } |
341 | 0 | const int refList0 = mmvdBaseMv[mvdBaseIdx][REF_PIC_LIST_0].refIdx; |
342 | 0 | const int refList1 = mmvdBaseMv[mvdBaseIdx][REF_PIC_LIST_1].refIdx; |
343 | |
|
344 | 0 | const Mv dMvTable[ 4 ] = { Mv( offset,0 ), Mv( -offset,0 ), Mv( 0, offset ), Mv( 0, -offset ) }; |
345 | 0 | if( ( refList0 != -1 ) && ( refList1 != -1 ) ) |
346 | 0 | { |
347 | 0 | const int poc0 = slice.getRefPOC( REF_PIC_LIST_0, refList0 ); |
348 | 0 | const int poc1 = slice.getRefPOC( REF_PIC_LIST_1, refList1 ); |
349 | 0 | const int currPoc = slice.poc; |
350 | |
|
351 | 0 | deltaMv[0] = dMvTable[mvdPosition]; |
352 | |
|
353 | 0 | if( ( poc0 - currPoc ) == ( poc1 - currPoc ) ) |
354 | 0 | { |
355 | 0 | deltaMv[1] = deltaMv[0]; |
356 | 0 | } |
357 | 0 | else if( abs( poc1 - currPoc ) > abs( poc0 - currPoc ) ) |
358 | 0 | { |
359 | 0 | const int scale = CU::getDistScaleFactor( currPoc, poc0, currPoc, poc1 ); |
360 | 0 | const bool isL0RefLongTerm = slice.getRefPic(REF_PIC_LIST_0, refList0)->isLongTerm; |
361 | 0 | const bool isL1RefLongTerm = slice.getRefPic(REF_PIC_LIST_1, refList1)->isLongTerm; |
362 | 0 | deltaMv[1] = deltaMv[0]; |
363 | |
|
364 | 0 | if( isL0RefLongTerm || isL1RefLongTerm ) |
365 | 0 | { |
366 | 0 | if( ( poc1 - currPoc ) * ( poc0 - currPoc ) > 0 ) |
367 | 0 | { |
368 | 0 | deltaMv[0] = deltaMv[1]; |
369 | 0 | } |
370 | 0 | else |
371 | 0 | { |
372 | 0 | deltaMv[0].set( -1 * deltaMv[1].hor, -1 * deltaMv[1].ver ); |
373 | 0 | } |
374 | 0 | } |
375 | 0 | else |
376 | 0 | { |
377 | 0 | deltaMv[0] = deltaMv[1].scaleMv( scale ); |
378 | 0 | } |
379 | 0 | } |
380 | 0 | else |
381 | 0 | { |
382 | 0 | const int scale = CU::getDistScaleFactor(currPoc, poc1, currPoc, poc0); |
383 | 0 | const bool isL0RefLongTerm = slice.getRefPic(REF_PIC_LIST_0, refList0)->isLongTerm; |
384 | 0 | const bool isL1RefLongTerm = slice.getRefPic(REF_PIC_LIST_1, refList1)->isLongTerm; |
385 | |
|
386 | 0 | if( isL0RefLongTerm || isL1RefLongTerm ) |
387 | 0 | { |
388 | 0 | if( ( poc1 - currPoc ) * ( poc0 - currPoc ) > 0 ) |
389 | 0 | { |
390 | 0 | deltaMv[1] = deltaMv[0]; |
391 | 0 | } |
392 | 0 | else |
393 | 0 | { |
394 | 0 | deltaMv[1].set( -1 * deltaMv[0].hor, -1 * deltaMv[0].ver ); |
395 | 0 | } |
396 | 0 | } |
397 | 0 | else |
398 | 0 | { |
399 | 0 | deltaMv[1] = deltaMv[0].scaleMv( scale ); |
400 | 0 | } |
401 | 0 | } |
402 | 0 | } |
403 | 0 | else if( refList0 != -1 ) |
404 | 0 | { |
405 | 0 | deltaMv[0] = dMvTable[mvdPosition]; |
406 | 0 | } |
407 | 0 | else if( refList1 != -1 ) |
408 | 0 | { |
409 | 0 | deltaMv[1] = dMvTable[mvdPosition]; |
410 | 0 | } |
411 | 0 | } |
412 | | |
413 | | void MergeCtx::setMmvdMergeCandiInfo( CodingUnit &cu, const MmvdIdx candIdx ) const |
414 | 0 | { |
415 | 0 | Mv tempMv[NUM_REF_PIC_LIST_01]; |
416 | |
|
417 | 0 | getMmvdDeltaMv( *cu.cs->slice, candIdx, tempMv ); |
418 | 0 | const int mvdBaseIdx = candIdx.pos.baseIdx; |
419 | |
|
420 | 0 | const int refList0 = mmvdBaseMv[mvdBaseIdx][0].refIdx; |
421 | 0 | const int refList1 = mmvdBaseMv[mvdBaseIdx][1].refIdx; |
422 | |
|
423 | 0 | if( refList0 != NOT_VALID && refList1 != NOT_VALID ) |
424 | 0 | { |
425 | 0 | cu.interDir = 3; |
426 | 0 | cu.mv [REF_PIC_LIST_0][0] = mmvdBaseMv[mvdBaseIdx][0].mv + tempMv[0]; |
427 | 0 | cu.refIdx[REF_PIC_LIST_0] = refList0; |
428 | 0 | cu.mv [REF_PIC_LIST_1][0] = mmvdBaseMv[mvdBaseIdx][1].mv + tempMv[1]; |
429 | 0 | cu.refIdx[REF_PIC_LIST_1] = refList1; |
430 | 0 | } |
431 | 0 | else if( refList0 != NOT_VALID ) |
432 | 0 | { |
433 | 0 | cu.interDir = 1; |
434 | 0 | cu.mv [REF_PIC_LIST_0][0] = mmvdBaseMv[mvdBaseIdx][0].mv + tempMv[0]; |
435 | 0 | cu.refIdx[REF_PIC_LIST_0] = refList0; |
436 | 0 | cu.mv [REF_PIC_LIST_1][0] = Mv(0, 0); |
437 | 0 | cu.refIdx[REF_PIC_LIST_1] = -1; |
438 | 0 | } |
439 | 0 | else if( refList1 != NOT_VALID ) |
440 | 0 | { |
441 | 0 | cu.interDir = 2; |
442 | 0 | cu.mv [REF_PIC_LIST_0][0] = Mv(0, 0); |
443 | 0 | cu.refIdx[REF_PIC_LIST_0] = -1; |
444 | 0 | cu.mv [REF_PIC_LIST_1][0] = mmvdBaseMv[mvdBaseIdx][1].mv + tempMv[1]; |
445 | 0 | cu.refIdx[REF_PIC_LIST_1] = refList1; |
446 | 0 | } |
447 | |
|
448 | 0 | cu.mmvdMergeFlag = true; |
449 | 0 | cu.mmvdMergeIdx = candIdx; |
450 | 0 | cu.mergeFlag = true; |
451 | 0 | cu.mergeIdx = candIdx.val; |
452 | 0 | cu.mergeType = MRG_TYPE_DEFAULT_N; |
453 | |
|
454 | 0 | cu.mvd[REF_PIC_LIST_0][0] = Mv(); |
455 | 0 | cu.mvd[REF_PIC_LIST_1][0] = Mv(); |
456 | 0 | cu.mvpIdx[REF_PIC_LIST_0] = NOT_VALID; |
457 | 0 | cu.mvpIdx[REF_PIC_LIST_1] = NOT_VALID; |
458 | 0 | cu.mvpNum[REF_PIC_LIST_0] = NOT_VALID; |
459 | 0 | cu.mvpNum[REF_PIC_LIST_1] = NOT_VALID; |
460 | 0 | cu.imv = mmvdUseAltHpelIf[mvdBaseIdx] ? IMV_HPEL : IMV_OFF; |
461 | |
|
462 | 0 | cu.BcwIdx = interDirNeighbours[mvdBaseIdx] == 3 ? BcwIdx[mvdBaseIdx] : BCW_DEFAULT; |
463 | |
|
464 | 0 | for( int refList = 0; refList < 2; refList++ ) |
465 | 0 | { |
466 | 0 | if( cu.refIdx[refList] >= 0 ) |
467 | 0 | { |
468 | 0 | cu.mv[refList][0].clipToStorageBitDepth(); |
469 | 0 | } |
470 | 0 | } |
471 | |
|
472 | 0 | CU::restrictBiPredMergeCandsOne( cu ); |
473 | 0 | } |
474 | | |
475 | | unsigned DeriveCtx::CtxMipFlag( const CodingUnit& cu ) const |
476 | 1.39M | { |
477 | 1.39M | unsigned ctxId = 0; |
478 | 1.39M | const CodingUnit *cuLeft = cuRestrictedLeft[CH_L]; |
479 | 1.39M | ctxId = (cuLeft && cuLeft->mipFlag) ? 1 : 0; |
480 | | |
481 | 1.39M | const CodingUnit *cuAbove = cuRestrictedAbove[CH_L]; |
482 | 1.39M | ctxId += (cuAbove && cuAbove->mipFlag) ? 1 : 0; |
483 | | |
484 | 1.39M | ctxId = (cu.lwidth() > 2*cu.lheight() || cu.lheight() > 2*cu.lwidth()) ? 3 : ctxId; |
485 | | |
486 | 1.39M | return ctxId; |
487 | 1.39M | } |
488 | | |
489 | | } // namespace vvenc |
490 | | |
491 | | //! \} |
492 | | |