Coverage Report

Created: 2026-08-13 07:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvenc/source/Lib/DecoderLib/DecCu.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     DecCu.cpp
45
    \brief    CU decoder class
46
*/
47
48
#include "DecCu.h"
49
50
#include "CommonLib/InterPrediction.h"
51
#include "CommonLib/IntraPrediction.h"
52
#include "CommonLib/Picture.h"
53
#include "CommonLib/UnitTools.h"
54
#include "CommonLib/LoopFilter.h"
55
#include "CommonLib/dtrace_buffer.h"
56
57
//! \ingroup DecoderLib
58
//! \{
59
60
namespace vvenc {
61
62
// ====================================================================================================================
63
// Constructor / destructor / create / destroy
64
// ====================================================================================================================
65
66
DecCu::DecCu()
67
19.2k
{
68
19.2k
}
69
70
DecCu::~DecCu()
71
19.2k
{
72
19.2k
  m_TmpBuffer.destroy();
73
19.2k
  m_PredBuffer.destroy();
74
19.2k
}
75
76
void DecCu::init( TrQuant* pcTrQuant, IntraPrediction* pcIntra, InterPrediction* pcInter, ChromaFormat chrFormat)
77
19.2k
{
78
19.2k
  m_pcTrQuant       = pcTrQuant;
79
19.2k
  m_pcIntraPred     = pcIntra;
80
19.2k
  m_pcInterPred     = pcInter;
81
19.2k
  m_TmpBuffer.destroy();
82
19.2k
  m_TmpBuffer.create( chrFormat, Area( 0,0, MAX_TB_SIZEY, MAX_TB_SIZEY ));
83
19.2k
  m_PredBuffer.destroy();
84
19.2k
  m_PredBuffer.create( chrFormat, Area( 0,0, MAX_CU_SIZE, MAX_CU_SIZE ));
85
19.2k
}
86
87
// ====================================================================================================================
88
// Protected member functions
89
// ====================================================================================================================
90
91
void DecCu::xIntraRecBlk( TransformUnit& tu, const ComponentID compID )
92
0
{
93
0
  if( !tu.blocks[ compID ].valid() )
94
0
  {
95
0
    return;
96
0
  }
97
98
0
        CodingStructure &cs     = *tu.cs;
99
0
  const CompArea& area          = tu.blocks[compID];
100
0
  const ChannelType chType      = toChannelType( compID );
101
0
  PelBuf piPred                 = tu.cu->ispMode && isLuma( compID ) ? cs.getPredBuf( area ) : m_PredBuffer.getCompactBuf( area );
102
0
  const CodingUnit& cu          = *tu.cu;
103
0
  const uint32_t uiChFinalMode  = CU::getFinalIntraMode( cu, chType );
104
0
  PelBuf pReco                  = cs.getRecoBuf( area );
105
106
  //===== init availability pattern =====
107
0
  CompArea areaPredReg(COMP_Y, tu.chromaFormat, area);
108
0
  bool predRegDiffFromTB = isLuma( compID ) && CU::isPredRegDiffFromTB( *tu.cu );
109
0
  bool firstTBInPredReg  = isLuma( compID ) && CU::isFirstTBInPredReg ( *tu.cu, area );
110
111
0
  if( tu.cu->ispMode && isLuma( compID ) )
112
0
  {
113
0
    if( predRegDiffFromTB )
114
0
    {
115
0
      if( firstTBInPredReg )
116
0
      {
117
0
        CU::adjustPredArea( areaPredReg );
118
0
        m_pcIntraPred->initIntraPatternChTypeISP( *tu.cu, areaPredReg, pReco );
119
0
      }
120
0
    }
121
0
    else
122
0
    {
123
0
      m_pcIntraPred->initIntraPatternChTypeISP( *tu.cu, area, pReco );
124
0
    }
125
0
  }
126
0
  else
127
0
  {
128
0
    m_pcIntraPred->initIntraPatternChType( *tu.cu, area );
129
0
  }
130
131
  //===== get prediction signal =====
132
0
  if( compID != COMP_Y && CU::isLMCMode( uiChFinalMode ) )
133
0
  {
134
0
    const CodingUnit& cu = *tu.cu;
135
0
    m_pcIntraPred->loadLMLumaRecPels( cu, area );
136
0
    m_pcIntraPred->predIntraChromaLM( compID, piPred, cu, area, uiChFinalMode );
137
0
  }
138
0
  else if( CU::isMIP( cu, chType ) )
139
0
  {
140
0
    m_pcIntraPred->initIntraMip( cu );
141
0
    m_pcIntraPred->predIntraMip( piPred, cu );
142
0
  }
143
0
  else
144
0
  {
145
0
    if (predRegDiffFromTB)
146
0
    {
147
0
      if (firstTBInPredReg)
148
0
      {
149
0
        PelBuf piPredReg = cs.getPredBuf(areaPredReg);
150
0
        m_pcIntraPred->predIntraAng(compID, piPredReg, cu);
151
0
      }
152
0
    }
153
0
    else
154
0
    {
155
0
      m_pcIntraPred->predIntraAng(compID, piPred, cu);
156
0
    }
157
0
  }
158
159
  //===== inverse transform =====
160
0
  PelBuf piResi = cs.getResiBuf( area );
161
162
0
  const QpParam cQP( tu, compID );
163
164
0
  if( tu.jointCbCr && isChroma(compID) )
165
0
  {
166
0
    if( compID == COMP_Cb )
167
0
    {
168
0
      PelBuf resiCr = cs.getResiBuf( tu.blocks[ COMP_Cr ] );
169
0
      if( tu.jointCbCr >> 1 )
170
0
      {
171
0
        m_pcTrQuant->invTransformNxN( tu, COMP_Cb, piResi, cQP );
172
0
      }
173
0
      else
174
0
      {
175
0
        const QpParam qpCr( tu, COMP_Cr );
176
0
        m_pcTrQuant->invTransformNxN( tu, COMP_Cr, resiCr, qpCr );
177
0
      }
178
0
      m_pcTrQuant->invTransformICT( tu, piResi, resiCr );
179
0
    }
180
0
  }
181
0
  else
182
0
  if( TU::getCbf( tu, compID ) )
183
0
  {
184
0
    m_pcTrQuant->invTransformNxN( tu, compID, piResi, cQP );
185
0
  }
186
0
  else
187
0
  {
188
0
    piResi.fill( 0 );
189
0
  }
190
191
  //===== reconstruction =====
192
0
  piPred.reconstruct( piPred, piResi, tu.cu->cs->slice->clpRngs[ compID ] );
193
0
  pReco.copyFrom( piPred );
194
195
0
  if( true/*isEncoder*/ )
196
0
  {
197
0
    cs.picture->getRecoBuf( area ).copyFrom( pReco );
198
0
  }
199
0
}
200
201
void DecCu::xReconIntraQT( CodingUnit &cu )
202
0
{
203
0
  const uint32_t numChType = getNumberValidChannels( cu.chromaFormat );
204
205
0
  for( uint32_t chType = CH_L; chType < numChType; chType++ )
206
0
  {
207
0
    if( cu.blocks[chType].valid() )
208
0
    {
209
0
      xIntraRecQT( cu, ChannelType( chType ) );
210
0
    }
211
0
  }
212
0
}
213
214
/** Function for deriving reconstructed PU/CU chroma samples with QTree structure
215
* \param pcRecoYuv pointer to reconstructed sample arrays
216
* \param pcPredYuv pointer to prediction sample arrays
217
* \param pcResiYuv pointer to residue sample arrays
218
* \param chType    texture channel type (luma/chroma)
219
* \param rTu       reference to transform data
220
*
221
\ This function derives reconstructed PU/CU chroma samples with QTree recursive structure
222
*/
223
224
void DecCu::xIntraRecQT(CodingUnit &cu, const ChannelType chType)
225
0
{
226
0
  for( auto &currTU : CU::traverseTUs( cu ) )
227
0
  {
228
0
    if( isLuma( chType ) )
229
0
    {
230
0
      xIntraRecBlk( currTU, COMP_Y );
231
0
    }
232
0
    else
233
0
    {
234
0
      const uint32_t numValidComp = getNumberValidComponents( cu.chromaFormat );
235
236
0
      for( uint32_t compID = COMP_Cb; compID < numValidComp; compID++ )
237
0
      {
238
0
        xIntraRecBlk( currTU, ComponentID( compID ) );
239
0
      }
240
0
    }
241
0
  }
242
0
}
243
244
245
void DecCu::xReconInter( CodingUnit &cu )
246
0
{
247
0
  CodingStructure &cs = *cu.cs;
248
249
0
  PelUnitBuf predBuf = m_PredBuffer.getCompactBuf( cu ); 
250
0
  if (cu.geo)
251
0
  {
252
0
    m_pcInterPred->motionCompensationGeo(cu, predBuf, m_geoMrgCtx);
253
0
    CU::spanGeoMotionInfo(cu, m_geoMrgCtx, cu.geoSplitDir, cu.geoMergeIdx[0], cu.geoMergeIdx[1]);
254
0
  }
255
0
  else
256
0
  {
257
0
    CHECK(CU::isIBC(cu) && cu.ciip, "IBC and Ciip cannot be used together");
258
0
    CHECK(CU::isIBC(cu) && cu.affine, "IBC and Affine cannot be used together");
259
0
    CHECK(CU::isIBC(cu) && cu.geo, "IBC and geo cannot be used together");
260
0
    CHECK(CU::isIBC(cu) && cu.mmvdMergeFlag, "IBC and MMVD cannot be used together");
261
0
    const bool luma   = cu.Y().valid();
262
0
    const bool chroma = isChromaEnabled( cu.chromaFormat ) && cu.Cb().valid();
263
264
0
    if( luma && ( chroma || !isChromaEnabled( cu.chromaFormat ) ) )
265
0
    {
266
0
      cu.mvRefine = true;
267
0
      m_pcInterPred->motionCompensation(cu, predBuf);
268
0
      cu.mvRefine = false;
269
0
    }
270
0
    else
271
0
    {
272
0
      cu.mcControl  = luma   ? 0 : 4;
273
0
      cu.mcControl |= chroma ? 0 : 2;
274
0
      m_pcInterPred->motionCompensationIBC(cu, predBuf);
275
0
      cu.mcControl  = 0;
276
0
    }
277
0
    if( cu.Y().valid() )
278
0
    {
279
0
      bool isIbcSmallBlk = CU::isIBC( cu ) && ( cu.lwidth() * cu.lheight() <= 16 );
280
      //CU::saveMotionInHMVP(cu, isIbcSmallBlk);
281
0
      if( !cu.affine && !cu.geo && !isIbcSmallBlk )
282
0
      {
283
0
        const MotionInfo &mi = cu.getMotionInfo();
284
0
        HPMVInfo hMi( mi, ( mi.interDir() == 3 ) ? cu.BcwIdx : BCW_DEFAULT, cu.imv == IMV_HPEL, CU::isIBC( cu ) );
285
0
        cs.addMiToLut( CU::isIBC( cu ) ? cu.cs->motionLut.lutIbc : cu.cs->motionLut.lut, hMi );
286
0
      }
287
0
    }
288
289
0
    if (cu.ciip)
290
0
    {
291
0
      PelBuf ciipBuf = m_TmpBuffer.getCompactBuf( cu.Y() );
292
293
0
      m_pcIntraPred->initIntraPatternChType(cu, cu.Y());
294
0
      m_pcIntraPred->predIntraAng(COMP_Y, ciipBuf, cu);
295
296
0
      const int numCiipIntra = m_pcIntraPred->getNumIntraCiip( cu );
297
0
      predBuf.Y().weightCiip( ciipBuf, numCiipIntra);
298
299
0
      if (isChromaEnabled(cu.chromaFormat) && cu.chromaSize().width > 2)
300
0
      {
301
0
        PelBuf ciipBufC = m_TmpBuffer.getCompactBuf( cu.Cb() );
302
0
        m_pcIntraPred->initIntraPatternChType(cu, cu.Cb());
303
0
        m_pcIntraPred->predIntraAng(COMP_Cb, ciipBufC, cu);
304
0
        predBuf.Cb().weightCiip( ciipBufC, numCiipIntra);
305
306
0
        m_pcIntraPred->initIntraPatternChType(cu, cu.Cr());
307
0
        m_pcIntraPred->predIntraAng(COMP_Cr, ciipBufC, cu);
308
0
        predBuf.Cr().weightCiip( ciipBufC, numCiipIntra);
309
0
      }
310
0
    }
311
0
  }
312
313
  // inter recon
314
0
  xDecodeInterTexture(cu);
315
316
0
  bool LumaOnly = ((predBuf.bufs.size() > 1) && (predBuf.bufs[1].stride != 0 && predBuf.bufs[2].stride != 0) ) ? false : true;
317
0
  if (cu.rootCbf)
318
0
  {
319
0
    if (LumaOnly)
320
0
    {
321
0
      cs.getResiBuf(cu.Y()).reconstruct(predBuf.Y(), cs.getResiBuf(cu.Y()), cs.slice->clpRngs[COMP_Y]);
322
0
      cs.getRecoBuf(cu.Y()).copyFrom(cs.getResiBuf(cu.Y()));
323
0
    }
324
0
    else
325
0
    {
326
0
      cs.getResiBuf(cu).reconstruct(predBuf, cs.getResiBuf(cu), cs.slice->clpRngs);
327
0
      cs.getRecoBuf(cu).copyFrom(cs.getResiBuf(cu));
328
0
    }
329
0
  }
330
0
  else
331
0
  {
332
0
    if (LumaOnly)
333
0
    {
334
0
      cs.getRecoBuf(cu.Y()).copyClip(predBuf.Y(), cs.slice->clpRngs[COMP_Y]);
335
0
    }
336
0
    else
337
0
    {
338
0
      cs.getRecoBuf(cu).copyClip(predBuf, cs.slice->clpRngs);
339
0
    }
340
0
  }
341
0
}
342
343
void DecCu::xDecodeInterTU( TransformUnit&  currTU, const ComponentID compID )
344
0
{
345
0
  if( !currTU.blocks[compID].valid() ) return;
346
347
0
  const CompArea& area = currTU.blocks[compID];
348
349
0
  CodingStructure& cs = *currTU.cs;
350
351
  //===== inverse transform =====
352
0
  PelBuf resiBuf  = cs.getResiBuf(area);
353
354
0
  const QpParam cQP(currTU, compID);
355
356
0
  if( currTU.jointCbCr && isChroma(compID) )
357
0
  {
358
0
    if( compID == COMP_Cb )
359
0
    {
360
0
      PelBuf resiCr = cs.getResiBuf( currTU.blocks[ COMP_Cr ] );
361
0
      if( currTU.jointCbCr >> 1 )
362
0
      {
363
0
        m_pcTrQuant->invTransformNxN( currTU, COMP_Cb, resiBuf, cQP );
364
0
      }
365
0
      else
366
0
      {
367
0
        const QpParam qpCr( currTU, COMP_Cr );
368
0
        m_pcTrQuant->invTransformNxN( currTU, COMP_Cr, resiCr, qpCr );
369
0
      }
370
0
      m_pcTrQuant->invTransformICT( currTU, resiBuf, resiCr );
371
0
    }
372
0
  }
373
0
  else
374
0
  if( TU::getCbf( currTU, compID ) )
375
0
  {
376
0
    m_pcTrQuant->invTransformNxN( currTU, compID, resiBuf, cQP );
377
0
  }
378
0
  else
379
0
  {
380
0
    resiBuf.fill( 0 );
381
0
  }
382
0
}
383
384
void DecCu::xDecodeInterTexture(CodingUnit &cu)
385
0
{
386
0
  if( !cu.rootCbf )
387
0
  {
388
0
    return;
389
0
  }
390
391
0
  const uint32_t uiNumVaildComp = getNumberValidComponents(cu.chromaFormat);
392
0
  for (uint32_t ch = 0; ch < uiNumVaildComp; ch++)
393
0
  {
394
0
    const ComponentID compID = ComponentID(ch);
395
396
0
    for( auto& currTU : CU::traverseTUs( cu ) )
397
0
    {
398
0
      xDecodeInterTU( currTU, compID );
399
0
    }
400
0
  }
401
0
}
402
403
void DecCu::xDeriveCUMV( CodingUnit &cu )
404
0
{
405
0
  if( cu.mergeFlag )
406
0
  {
407
0
    MergeCtx mrgCtx;
408
409
0
    if (cu.mmvdMergeFlag || cu.mmvdSkip)
410
0
    {
411
0
      CHECK( cu.ciip, "invalid CIIP" );
412
0
      CU::getInterMergeCandidates    ( cu, mrgCtx, 1,  cu.mmvdMergeIdx.pos.baseIdx + 1 );
413
0
      CU::getInterMMVDMergeCandidates( cu, mrgCtx );
414
0
      mrgCtx.setMmvdMergeCandiInfo   ( cu, cu.mmvdMergeIdx );
415
0
      CU::spanMotionInfo             ( cu );
416
0
    }
417
0
    else
418
0
    {
419
0
      if (cu.geo)
420
0
      {
421
0
        CU::getGeoMergeCandidates(cu, m_geoMrgCtx);
422
0
      }
423
0
      else
424
0
      {
425
0
        AffineMergeCtx affineMergeCtx;
426
0
        if (cu.affine)
427
0
        {
428
0
          if (cu.cs->sps->SbtMvp)
429
0
          {
430
0
            Size bufSize                  = g_miScaling.scale(cu.lumaSize());
431
0
            affineMergeCtx.subPuMvpMiBuf  = MotionBuf(m_subPuMiBuf, bufSize);
432
0
          }
433
0
          CU::getAffineMergeCand(cu, affineMergeCtx, cu.mergeIdx);
434
0
          cu.interDir           =    affineMergeCtx.interDirNeighbours[cu.mergeIdx];
435
0
          cu.affineType         =    affineMergeCtx.affineType        [cu.mergeIdx];
436
0
          cu.BcwIdx             =    affineMergeCtx.BcwIdx            [cu.mergeIdx];
437
0
          cu.mergeType          =    affineMergeCtx.mergeType         [cu.mergeIdx];
438
439
0
          if (cu.mergeType == MRG_TYPE_SUBPU_ATMVP)
440
0
          {
441
0
            cu.refIdx[0] = affineMergeCtx.mvFieldNeighbours[cu.mergeIdx][0][0].refIdx;
442
0
            cu.refIdx[1] = affineMergeCtx.mvFieldNeighbours[cu.mergeIdx][1][0].refIdx;
443
0
          }
444
0
          else
445
0
          {
446
0
            for (int i = 0; i < 2; ++i)
447
0
            {
448
0
              if (cu.cs->slice->numRefIdx[RefPicList(i)] > 0)
449
0
              {
450
0
                MvField *mvField = affineMergeCtx.mvFieldNeighbours[cu.mergeIdx][i];
451
0
                cu.mvpIdx[i]     = 0;
452
0
                cu.mvpNum[i]     = 0;
453
0
                cu.mvd[i][0]     = Mv();
454
0
                CU::setAllAffineMvField(cu, mvField, RefPicList(i));
455
0
              }
456
0
            }
457
0
          }
458
0
        }
459
0
        else
460
0
        {
461
0
          if (CU::isIBC(cu))
462
0
          {
463
0
            CU::getIBCMergeCandidates(cu, mrgCtx, cu.mergeIdx);
464
0
          }
465
0
          else
466
0
          {
467
0
            CU::getInterMergeCandidates(cu, mrgCtx, 0, cu.mergeIdx);
468
0
          }
469
0
          mrgCtx.setMergeInfo(cu, cu.mergeIdx);
470
0
        }
471
472
0
        CU::spanMotionInfo(cu, &affineMergeCtx);
473
0
      }
474
0
    }
475
0
  } 
476
0
  else
477
0
  {
478
0
    if (cu.affine)
479
0
    {
480
0
      for (uint32_t uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++)
481
0
      {
482
0
        RefPicList eRefList = RefPicList(uiRefListIdx);
483
0
        if (cu.cs->slice->numRefIdx[eRefList] > 0 && (cu.interDir & (1 << uiRefListIdx)))
484
0
        {
485
0
          AffineAMVPInfo affineAMVPInfo;
486
0
          CU::fillAffineMvpCand(cu, eRefList, cu.refIdx[eRefList], affineAMVPInfo);
487
488
0
          const unsigned mvp_idx = cu.mvpIdx[eRefList];
489
490
0
          cu.mvpNum[eRefList] = affineAMVPInfo.numCand;
491
492
          //    Mv mv[3];
493
0
          CHECK(cu.refIdx[eRefList] < 0, "Unexpected negative refIdx.");
494
0
          if (!true/*isEncoder*/)
495
0
          {
496
0
            cu.mvd[eRefList][0].changeAffinePrecAmvr2Internal(cu.imv);
497
0
            cu.mvd[eRefList][1].changeAffinePrecAmvr2Internal(cu.imv);
498
0
            if (cu.affineType == AFFINEMODEL_6PARAM)
499
0
            {
500
0
              cu.mvd[eRefList][2].changeAffinePrecAmvr2Internal(cu.imv);
501
0
            }
502
0
          }
503
504
0
          Mv mvLT = affineAMVPInfo.mvCandLT[mvp_idx] + cu.mvd[eRefList][0];
505
0
          Mv mvRT = affineAMVPInfo.mvCandRT[mvp_idx] + cu.mvd[eRefList][1];
506
0
          mvRT += cu.mvd[eRefList][0];
507
508
0
          Mv mvLB;
509
0
          if (cu.affineType == AFFINEMODEL_6PARAM)
510
0
          {
511
0
            mvLB = affineAMVPInfo.mvCandLB[mvp_idx] + cu.mvd[eRefList][2];
512
0
            mvLB += cu.mvd[eRefList][0];
513
0
          }
514
0
          CU::setAllAffineMv(cu, mvLT, mvRT, mvLB, eRefList, true);
515
0
        }
516
0
      }
517
0
    }
518
0
    else if (CU::isIBC(cu) && cu.interDir == 1)
519
0
    {
520
0
      AMVPInfo amvpInfo;
521
0
      CU::fillIBCMvpCand(cu, amvpInfo);
522
0
      cu.mvpNum[REF_PIC_LIST_0] = amvpInfo.numCand;
523
0
      Mv mvd = cu.mvd[REF_PIC_LIST_0][0];
524
0
      if (!true/*isEncoder*/)
525
0
      {
526
0
        mvd.changeIbcPrecAmvr2Internal(cu.imv);
527
0
      }
528
0
      if (cu.cs->sps->maxNumIBCMergeCand == 1)
529
0
      {
530
0
        CHECK(cu.mvpIdx[REF_PIC_LIST_0], "mvpIdx for IBC mode should be 0");
531
0
      }
532
0
      cu.mv[REF_PIC_LIST_0][0] = amvpInfo.mvCand[cu.mvpIdx[REF_PIC_LIST_0]] + mvd;
533
0
      cu.mv[REF_PIC_LIST_0][0].mvCliptoStorageBitDepth();
534
0
    }
535
0
    else
536
0
    {
537
0
      for ( uint32_t uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
538
0
      {
539
0
        RefPicList eRefList = RefPicList( uiRefListIdx );
540
0
        if ((cu.cs->slice->numRefIdx[eRefList] > 0 || (eRefList == REF_PIC_LIST_0 && CU::isIBC(cu))) && (cu.interDir & (1 << uiRefListIdx)))
541
0
        {
542
0
          AMVPInfo amvpInfo;
543
0
          CU::fillMvpCand(cu, eRefList, cu.refIdx[eRefList], amvpInfo);
544
0
          cu.mvpNum [eRefList] = amvpInfo.numCand;
545
0
          if (!true/*isEncoder*/)
546
0
          {
547
0
            cu.mvd[eRefList][0].changeTransPrecAmvr2Internal(cu.imv);
548
0
          }
549
0
          cu.mv[eRefList][0] = amvpInfo.mvCand[cu.mvpIdx[eRefList]] + cu.mvd[eRefList][0];
550
0
          cu.mv[eRefList][0].mvCliptoStorageBitDepth();
551
0
        }
552
0
      }
553
0
    }
554
0
    CU::spanMotionInfo( cu );
555
0
  }
556
0
  if (CU::isIBC(cu)) //only check
557
0
  {
558
0
    const int cuPelX = cu.Y().x;
559
0
    const int cuPelY = cu.Y().y;
560
0
    int roiWidth = cu.lwidth();
561
0
    int roiHeight = cu.lheight();
562
0
    const unsigned int  lcuWidth = cu.cs->slice->sps->CTUSize;
563
0
    int xPred = cu.mv[0][0].hor >> MV_FRACTIONAL_BITS_INTERNAL;
564
0
    int yPred = cu.mv[0][0].ver >> MV_FRACTIONAL_BITS_INTERNAL;
565
0
    CHECK(!m_pcInterPred->isLumaBvValidIBC(lcuWidth, cuPelX, cuPelY, roiWidth, roiHeight, xPred, yPred), "invalid block vector for IBC detected.");
566
0
  }
567
0
}
568
569
} // namespace vvenc
570
571
//! \}
572