Coverage Report

Created: 2026-07-25 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vvdec/source/Lib/CommonLib/Picture.cpp
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
The copyright in this software is being made available under the Clear BSD
3
License, included below. No patent rights, trademark rights and/or 
4
other Intellectual Property Rights other than the copyrights concerning 
5
the Software are granted under this license.
6
7
The Clear BSD License
8
9
Copyright (c) 2018-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVdeC Authors.
10
All rights reserved.
11
12
Redistribution and use in source and binary forms, with or without modification,
13
are permitted (subject to the limitations in the disclaimer below) provided that
14
the following conditions are met:
15
16
     * Redistributions of source code must retain the above copyright notice,
17
     this list of conditions and the following disclaimer.
18
19
     * Redistributions in binary form must reproduce the above copyright
20
     notice, this list of conditions and the following disclaimer in the
21
     documentation and/or other materials provided with the distribution.
22
23
     * Neither the name of the copyright holder nor the names of its
24
     contributors may be used to endorse or promote products derived from this
25
     software without specific prior written permission.
26
27
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
28
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
29
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
POSSIBILITY OF SUCH DAMAGE.
39
40
41
------------------------------------------------------------------------------------------- */
42
43
/** \file     Picture.cpp
44
 *  \brief    Description of a coded picture
45
 */
46
47
#include "Picture.h"
48
#include "ChromaFormat.h"
49
50
// ---------------------------------------------------------------------------
51
// picture methods
52
// ---------------------------------------------------------------------------
53
54
namespace vvdec
55
{
56
57
static void paddPicBorderTopCore(Pel *pi, ptrdiff_t stride,int width,int xmargin,int ymargin)
58
0
{
59
0
  for( int x = 0; x < xmargin; x++ )
60
0
  {
61
0
    pi[-xmargin + x] = pi[0];
62
0
    pi[width + x] = pi[width - 1];
63
0
  }
64
0
  pi -= xmargin;
65
  // pi is now (-marginX, 0)
66
0
  for( int y = 0; y < ymargin; y++ )
67
0
  {
68
0
    ::memcpy( pi - ( y + 1 )*stride, pi, sizeof( Pel )*( width + ( xmargin << 1 ) ) );
69
0
  }
70
0
}
71
72
static void paddPicBorderBotCore(Pel *pi, ptrdiff_t stride,int width,int xmargin,int ymargin)
73
0
{
74
0
  for( int x = 0; x < xmargin; x++ )
75
0
  {
76
0
    pi[-xmargin + x] = pi[0];
77
0
    pi[width  + x] = pi[width - 1];
78
0
  }
79
0
  pi -= xmargin;
80
  // pi is now the (-marginX, height-1)
81
0
  for( int y = 0; y < ymargin; y++ )
82
0
  {
83
0
    ::memcpy( pi + ( y + 1 )*stride, pi, sizeof( Pel )*( width + ( xmargin << 1 ) ) );
84
0
  }
85
0
}
86
87
static void paddPicBorderLeftRightCore(Pel *pi, ptrdiff_t stride,int width,int xmargin,int height)
88
0
{
89
0
  for( int y = 1; y < ( height - 1 ); y++ )
90
0
   {
91
0
     for( int x = 0; x < xmargin; x++ )
92
0
     {
93
0
       pi[-xmargin + x] = pi[0];
94
0
       pi[width + x] = pi[width - 1];
95
0
     }
96
0
     pi += stride;
97
0
   }
98
0
}
99
100
void Picture::create(const ChromaFormat &_chromaFormat, const Size &size, const unsigned _maxCUSize, const unsigned _margin, const int _layerId, UserAllocator* _userAllocator )
101
714
{
102
714
  layerId = _layerId;
103
714
  UnitArea::operator=( UnitArea( _chromaFormat, Area( Position{ 0, 0 }, size ) ) );
104
714
  margin            = _margin;
105
714
  m_bufs[PIC_RECONSTRUCTION].create( _chromaFormat, size, _maxCUSize, _margin, MEMORY_ALIGN_DEF_SIZE, true, _userAllocator );
106
714
}
107
108
void Picture::createWrapAroundBuf( const bool isWrapAround, const unsigned _maxCUSize )
109
714
{
110
714
  if( isWrapAround )
111
6
    m_bufs[PIC_RECON_WRAP].create( chromaFormat, Y().size(), _maxCUSize, margin, MEMORY_ALIGN_DEF_SIZE );
112
714
}
113
114
void Picture::resetForUse( int _layerId )
115
0
{
116
0
  CHECK( lockedByApplication, "the picture can not be re-used, because it has not been unlocked by the application." );
117
118
0
  if( cs )
119
0
  {
120
0
    cs->resetForUse();
121
0
  }
122
123
0
  m_subPicRefBufs.clear();
124
125
0
  m_dProcessingTime       = 0;
126
0
  subPicExtStarted        = false;
127
0
  borderExtStarted        = false;
128
0
  dpbReferenceMark        = unreferenced;
129
0
  stillReferenced         = false;
130
0
  isReferencePic          = false;
131
0
  progress                = Picture::init;
132
0
  neededForOutput         = false;
133
0
  wasLost                 = false;
134
0
  error                   = false;
135
0
  exceptionThrownOut      = false;
136
0
  topField                = false;
137
0
  fieldPic                = false;
138
0
  nonReferencePictureFlag = false;
139
0
  skippedDecCount         = 0;
140
141
0
  picCheckedDPH = false;
142
0
  subpicsCheckedDPH.clear();
143
0
  dphMismatch   = false;
144
145
0
  lockedByApplication = false;
146
147
0
  poc                 = 0;
148
0
  cts                 = 0;
149
0
  dts                 = 0;
150
0
  tempLayer           = std::numeric_limits<uint32_t>::max();
151
0
  depth               = 0;
152
0
  layerId             = _layerId;
153
0
  eNalUnitType        = NAL_UNIT_INVALID;
154
0
  bits                = 0;
155
0
  rap                 = 0;
156
0
  userData            = nullptr;
157
0
  decodingOrderNumber = 0;
158
159
0
  sliceSubpicIdx.clear();
160
0
  subPictures.clear();
161
162
0
  subLayerNonReferencePictureDueToSTSA = 0;
163
164
0
  m_divTasksCounter     .clearException();
165
0
  m_ctuTaskCounter      .clearException();
166
0
  m_borderExtTaskCounter.clearException();
167
0
  m_copyWrapBufDone     .clearException();
168
0
  reconDone             .clearException();
169
0
  parseDone             .clearException();
170
0
#if RECO_WHILE_PARSE
171
0
  std::for_each( ctuParsedBarrier.begin(), ctuParsedBarrier.end(), []( auto& b ) { b.clearException(); } );
172
0
#endif
173
174
0
  clearSliceBuffer();
175
176
0
  SEI_internal::deleteSEIs( seiMessageList );
177
178
0
  reconDone.lock();
179
0
}
180
181
void Picture::destroy()
182
714
{
183
714
  CHECK( lockedByApplication, "the picture can not be destroyed, because it has not been unlocked by the application." );
184
185
2.14k
  for (uint32_t t = 0; t < NUM_PIC_TYPES; t++)
186
1.42k
  {
187
1.42k
    m_bufs[t].destroy();
188
1.42k
  }
189
190
714
  if( cs )
191
714
  {
192
714
    cs->destroy();
193
714
    delete cs;
194
714
    cs = nullptr;
195
714
  }
196
197
714
#if  RECO_WHILE_PARSE
198
714
  ctuParsedBarrier.clear();
199
714
#endif
200
201
714
  clearSliceBuffer();
202
203
714
  SEI_internal::deleteSEIs( seiMessageList );
204
205
714
  subpicsCheckedDPH.clear();
206
207
714
  m_divTasksCounter     .clearException();
208
714
  m_ctuTaskCounter      .clearException();
209
714
  m_borderExtTaskCounter.clearException();
210
714
  m_copyWrapBufDone     .clearException();
211
714
  reconDone             .clearException();
212
714
  parseDone             .clearException();
213
714
#if RECO_WHILE_PARSE
214
714
  std::for_each( ctuParsedBarrier.begin(), ctuParsedBarrier.end(), []( auto& b ) { b.clearException(); } );
215
714
#endif
216
714
}
217
218
0
       PelBuf     Picture::getRecoBuf(const ComponentID compID, bool wrap)       { return getBuf(compID, wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
219
0
const CPelBuf     Picture::getRecoBuf(const ComponentID compID, bool wrap) const { return getBuf(compID, wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
220
60.4k
       PelBuf     Picture::getRecoBuf(const CompArea &blk, bool wrap)            { return getBuf(blk,    wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
221
0
const CPelBuf     Picture::getRecoBuf(const CompArea &blk, bool wrap)      const { return getBuf(blk,    wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
222
0
       PelUnitBuf Picture::getRecoBuf(const UnitArea &unit, bool wrap)           { return getBuf(unit,   wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
223
0
const CPelUnitBuf Picture::getRecoBuf(const UnitArea &unit, bool wrap)     const { return getBuf(unit,   wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
224
2.13k
       PelUnitBuf Picture::getRecoBuf( bool wrap )                               { return wrap ? m_bufs[PIC_RECON_WRAP] : m_bufs[PIC_RECONSTRUCTION]; }
225
0
const CPelUnitBuf Picture::getRecoBuf( bool wrap )                         const { return wrap ? m_bufs[PIC_RECON_WRAP] : m_bufs[PIC_RECONSTRUCTION]; }
226
227
Picture::Picture( bool enableOpt )
228
714
{
229
714
  paddPicBorderBot = paddPicBorderBotCore;
230
714
  paddPicBorderTop = paddPicBorderTopCore;
231
714
  paddPicBorderLeftRight = paddPicBorderLeftRightCore;
232
233
714
  if( enableOpt )
234
714
  {
235
714
#if ENABLE_SIMD_OPT_PICTURE && defined( TARGET_SIMD_X86 )
236
714
    initPictureX86();
237
714
#endif
238
#if ENABLE_SIMD_OPT_PICTURE && defined( TARGET_SIMD_ARM )
239
    initPictureARM();
240
#endif
241
714
  }
242
714
}
243
244
void Picture::finalInit( CUChunkCache* cuChunkCache, TUChunkCache* tuChunkCache, const SPS *sps, const PPS *pps, const std::shared_ptr<PicHeader>& ph, const APS* const alfApss[ALF_CTB_MAX_NUM_APS], const APS* lmcsAps, const APS* scalingListAps, bool phPSupdate )
245
714
{
246
714
  SEI_internal::deleteSEIs( seiMessageList );
247
714
  clearSliceBuffer();
248
249
714
  const ChromaFormat chromaFormatIDC = sps->getChromaFormatIdc();
250
714
  const int          iWidth          = pps->getPicWidthInLumaSamples();
251
714
  const int          iHeight         = pps->getPicHeightInLumaSamples();
252
253
714
  if( !cs )
254
714
  {
255
714
    cs = new CodingStructure( cuChunkCache, tuChunkCache );
256
714
    cs->create( chromaFormatIDC, Area( 0, 0, iWidth, iHeight ) );
257
714
  }
258
259
714
#if RECO_WHILE_PARSE
260
714
  if( ctuParsedBarrier.size() != pps->pcv->sizeInCtus )
261
714
  {
262
714
    ctuParsedBarrier = std::vector<Barrier>( pps->pcv->sizeInCtus );
263
714
  }
264
714
#endif
265
266
714
  parseDone   . lock();
267
714
  cs->picture   = this;
268
714
  cs->picHeader = ph;
269
714
  cs->pps       = pps->getSharedPtr();
270
714
  cs->sps       = sps->getSharedPtr();
271
714
  cs->pcv       = pps->pcv.get();
272
273
714
  if( phPSupdate )
274
714
  {
275
714
    ph->setSPSId         ( sps->getSPSId() );
276
714
    ph->setPPSId         ( pps->getPPSId() );
277
714
    ph->setLmcsAPS       ( lmcsAps        ? lmcsAps       ->getSharedPtr() : nullptr );
278
714
    ph->setScalingListAPS( scalingListAps ? scalingListAps->getSharedPtr() : nullptr );
279
714
  }
280
714
  nonReferencePictureFlag = ph->getNonReferencePictureFlag();
281
282
6.42k
  for( int i = 0; i < ALF_CTB_MAX_NUM_APS; ++i )
283
5.71k
  {
284
5.71k
    cs->alfApss[i] = alfApss[i] ? alfApss[i]->getSharedPtr() : nullptr;
285
5.71k
  }
286
714
  if( lmcsAps )
287
0
  {
288
0
    cs->lmcsAps = lmcsAps ? lmcsAps->getSharedPtr() : nullptr;
289
0
  }
290
291
714
  cs->allocTempInternals();
292
714
  cs->rebindPicBufs();
293
294
714
  if( sps->getIBCFlag() )
295
707
  {
296
707
    cs->initVIbcBuf( cs->pcv->heightInCtus, sps->getChromaFormatIdc(), sps->getMaxCUHeight() );
297
707
  }
298
299
714
  resetProcessingTime();
300
714
}
301
302
Slice* Picture::allocateNewSlice( Slice** pilot )
303
714
{
304
714
  if( pilot )
305
714
  {
306
714
    slices.push_back( *pilot );
307
714
    *pilot = new Slice;
308
714
    if( slices.size() >= 2 )
309
0
    {
310
0
      ( *pilot )->copySliceInfo( slices[slices.size() - 2] );
311
0
      ( *pilot )->initSlice();
312
0
    }
313
714
    ( *pilot )->setSPS( 0 );
314
714
    ( *pilot )->setPPS( 0 );
315
714
    ( *pilot )->setVPS( 0 );
316
714
    ( *pilot )->clearAlfAPSs();
317
714
  }
318
0
  else
319
0
  {
320
0
    slices.push_back( new Slice );
321
0
    if( slices.size() >= 2 )
322
0
    {
323
0
      slices.back()->copySliceInfo( slices[slices.size() - 2] );
324
0
      slices.back()->initSlice();
325
0
    }
326
0
  }
327
328
714
  Slice* slice = slices.back();
329
330
714
  slice->setPPS( cs->pps.get() );
331
714
  slice->setSPS( cs->sps.get() );
332
714
  slice->setVPS( cs->vps.get() );
333
714
  slice->setAlfApss( cs->alfApss );
334
714
  slice->setPic( this );
335
336
714
  return slice;
337
714
}
338
339
void Picture::clearSliceBuffer()
340
1.42k
{
341
1.42k
  for( auto &s: slices )
342
714
  {
343
714
    delete s;
344
714
  }
345
1.42k
  slices.clear();
346
1.42k
}
347
348
bool Picture::lastSliceOfPicPresent() const
349
721
{
350
721
  if( slices.empty() )
351
0
  {
352
0
    return false;
353
0
  }
354
721
  const Slice*   lastSlice      = slices.back();
355
721
  const unsigned lastCtuInSlice = lastSlice->getCtuAddrInSlice( lastSlice->getNumCtuInSlice() - 1 );
356
721
  return lastCtuInSlice == lastSlice->getPPS()->pcv->sizeInCtus - 1;
357
721
}
358
359
void Picture::waitForAllTasks()
360
710
{
361
710
  m_ctuTaskCounter.wait_nothrow();
362
710
  m_borderExtTaskCounter.wait_nothrow();
363
710
  m_divTasksCounter.wait_nothrow();   // this waits for the slice parsing and the finishPic Task
364
710
}
365
366
void Picture::ensureUsableAsRef()
367
0
{
368
0
#if RECO_WHILE_PARSE
369
0
  ctuParsedBarrier.clear();
370
0
#endif
371
0
  neededForOutput = false;
372
373
  // set referenced to true, because we don't know if it has been set correctly, but that way it will be available as a reference pic
374
0
  dpbReferenceMark = ShortTerm;
375
0
  stillReferenced  = true;
376
0
  isReferencePic   = true;
377
378
  // ensure cs->m_colMiMap is set to zero
379
0
  cs->initStructData();
380
381
0
  CHECK_FATAL( reconDone.hasException(), "to be usable as reference the picture should not have an Exception reconDone barrier" );
382
0
}
383
384
void Picture::fillGrey( const SPS* fallbackSPS )
385
710
{
386
710
  CHECK( !cs && !cs->sps && !fallbackSPS, "No SPS accessible" );
387
388
710
  const int bitDepth = cs && cs->sps ? cs->sps->getBitDepth() : fallbackSPS->getBitDepth();
389
  // fill in grey buffer for missing reference pictures (GDR or broken bitstream)
390
710
  const uint32_t yFill = 1 << ( bitDepth - 1 );
391
710
  const uint32_t cFill = 1 << ( bitDepth - 1 );
392
710
  getRecoBuf().Y().fill( yFill );
393
710
  getRecoBuf().Cb().fill( cFill );
394
710
  getRecoBuf().Cr().fill( cFill );
395
396
710
  progress = Picture::reconstructed;
397
710
  reconDone.unlock();
398
710
}
399
400
void Picture::extendPicBorder( bool top, bool bottom, bool leftrightT, bool leftrightB, ChannelType chType )
401
0
{
402
0
  if( cs->pps->getUseWrapAround() )
403
0
  {
404
0
    extendPicBorderWrap( top, bottom, leftrightT, leftrightB, chType );
405
0
  }
406
407
0
  extendPicBorderBuf( m_bufs[PIC_RECONSTRUCTION], top, bottom, leftrightT, leftrightB, chType );
408
0
}
409
410
void Picture::extendPicBorderWrap( bool top, bool bottom, bool leftrightT, bool leftrightB, ChannelType chType )
411
0
{
412
0
  for( int comp = 0; comp < getNumberValidComponents( cs->area.chromaFormat ); comp++ )
413
0
  {
414
0
    ComponentID compID = ComponentID( comp );
415
416
0
    if( chType != MAX_NUM_CHANNEL_TYPE && toChannelType( compID ) != chType )
417
0
      continue;
418
419
0
    PelBuf prw = m_bufs[PIC_RECON_WRAP].get( compID );
420
421
0
    const int xmargin = margin >> getComponentScaleX( compID, cs->area.chromaFormat );
422
0
    const int ymargin = margin >> getComponentScaleY( compID, cs->area.chromaFormat );
423
424
0
    int xoffset = cs->pps->getWrapAroundOffset() >> getComponentScaleX( compID, cs->area.chromaFormat );
425
0
    if( leftrightT )
426
0
    {
427
0
      Pel* piprw = prw.bufAt( 0, 1 );
428
429
0
      for( int y = 1; y < prw.height / 2; y++ )
430
0
      {
431
0
        for( int x = 0; x < xmargin; x++ )
432
0
        {
433
0
          if( x < xoffset )
434
0
          {
435
0
            piprw[-x - 1]        = piprw[-x - 1 + xoffset];
436
0
            piprw[prw.width + x] = piprw[prw.width + x - xoffset];
437
0
          }
438
0
          else
439
0
          {
440
0
            piprw[-x - 1]        = piprw[0];
441
0
            piprw[prw.width + x] = piprw[prw.width - 1];
442
0
          }
443
0
        }
444
0
        piprw += prw.stride;
445
0
      }
446
0
    }
447
0
    if( leftrightB )
448
0
    {
449
0
      Pel* piprw = prw.bufAt( 0, prw.height / 2 );
450
451
0
      for( int y = 1; y < prw.height / 2; y++ )
452
0
      {
453
0
        for( int x = 0; x < xmargin; x++ )
454
0
        {
455
0
          if( x < xoffset )
456
0
          {
457
0
            piprw[-x - 1]        = piprw[-x - 1 + xoffset];
458
0
            piprw[prw.width + x] = piprw[prw.width + x - xoffset];
459
0
          }
460
0
          else
461
0
          {
462
0
            piprw[-x - 1]        = piprw[0];
463
0
            piprw[prw.width + x] = piprw[prw.width - 1];
464
0
          }
465
0
        }
466
0
        piprw += prw.stride;
467
0
      }
468
0
    }
469
470
0
    if( bottom )
471
0
    {
472
0
      Pel* piprw = prw.bufAt( 0, prw.height - 1 );
473
474
0
      for( int x = 0; x < xmargin; x++ )
475
0
      {
476
0
        if( x < xoffset )
477
0
        {
478
0
          piprw[-x - 1]        = piprw[-x - 1 + xoffset];
479
0
          piprw[prw.width + x] = piprw[prw.width + x - xoffset];
480
0
        }
481
0
        else
482
0
        {
483
0
          piprw[-x - 1]        = piprw[0];
484
0
          piprw[prw.width + x] = piprw[prw.width - 1];
485
0
        }
486
0
      }
487
0
      piprw -= xmargin;
488
      // pi is now the (-marginX, height-1)
489
0
      for( int y = 0; y < ymargin; y++ )
490
0
      {
491
0
        ::memcpy( piprw + ( y + 1 ) * prw.stride, piprw, sizeof( Pel ) * ( prw.width + ( xmargin << 1 ) ) );
492
0
      }
493
0
    }
494
0
    if( top )
495
0
    {
496
0
      Pel* piprw = prw.bufAt( 0, 0 );
497
498
0
      for( int x = 0; x < xmargin; x++ )
499
0
      {
500
0
        if( x < xoffset )
501
0
        {
502
0
          piprw[-x - 1]        = piprw[-x - 1 + xoffset];
503
0
          piprw[prw.width + x] = piprw[prw.width + x - xoffset];
504
0
        }
505
0
        else
506
0
        {
507
0
          piprw[-x - 1]        = piprw[0];
508
0
          piprw[prw.width + x] = piprw[prw.width - 1];
509
0
        }
510
0
      }
511
0
      piprw -= xmargin;
512
      // pi is now (-marginX, 0)
513
0
      for( int y = 0; y < ymargin; y++ )
514
0
      {
515
0
        ::memcpy( piprw - ( y + 1 ) * prw.stride, piprw, sizeof( Pel ) * ( prw.width + ( xmargin << 1 ) ) );
516
0
      }
517
0
    }
518
0
  }
519
0
}
520
521
void Picture::extendPicBorderBuf( PelStorage& storage, bool top, bool bottom, bool leftrightT, bool leftrightB, ChannelType chType )
522
0
{
523
0
  for( int comp = 0; comp < getNumberValidComponents( cs->area.chromaFormat ); comp++ )
524
0
  {
525
0
    ComponentID compID = ComponentID( comp );
526
527
0
    if( chType != MAX_NUM_CHANNEL_TYPE && toChannelType( compID ) != chType )
528
0
      continue;
529
530
0
    PelBuf p = storage.bufs[compID];
531
532
0
    const int xmargin = margin >> getComponentScaleX( compID, cs->area.chromaFormat );
533
0
    const int ymargin = margin >> getComponentScaleY( compID, cs->area.chromaFormat );
534
535
0
    if( leftrightT )
536
0
    {
537
0
      Pel* pi = p.bufAt( 0, 1 );
538
0
      paddPicBorderLeftRight( pi, p.stride, p.width, xmargin, 1 + p.height / 2 );
539
0
    }
540
0
    if( leftrightB )
541
0
    {
542
0
      Pel* pi = p.bufAt( 0, p.height / 2 );
543
0
      paddPicBorderLeftRight( pi, p.stride, p.width, xmargin, 1 + p.height / 2 );
544
0
    }
545
0
    if( bottom )
546
0
    {
547
      // pi is now the (0,height) (bottom left of image within bigger picture
548
0
      Pel* pi = p.bufAt( 0, p.height - 1 );
549
0
      paddPicBorderBot( pi, p.stride, p.width, xmargin, ymargin );
550
0
    }
551
0
    if( top )
552
0
    {
553
      // pi is now the (0,height) (bottom left of image within bigger picture
554
0
      Pel* pi = p.bufAt( 0, 0 );
555
0
      paddPicBorderTop( pi, p.stride, p.width, xmargin, ymargin );
556
0
    }
557
0
  }
558
0
}
559
560
PelBuf Picture::getBuf( const CompArea &blk, const PictureType &type )
561
60.4k
{
562
60.4k
  if( !blk.valid() )
563
0
  {
564
0
    return PelBuf();
565
0
  }
566
567
60.4k
  return m_bufs[type].getBuf( blk );
568
60.4k
}
569
570
const CPelBuf Picture::getBuf( const CompArea &blk, const PictureType &type ) const
571
0
{
572
0
  if( !blk.valid() )
573
0
  {
574
0
    return PelBuf();
575
0
  }
576
577
0
  return m_bufs[type].getBuf( blk );
578
0
}
579
580
PelUnitBuf Picture::getBuf( const UnitArea &unit, const PictureType &type )
581
0
{
582
0
  if( chromaFormat == CHROMA_400 )
583
0
  {
584
0
    return PelUnitBuf( chromaFormat, getBuf( unit.Y(), type ) );
585
0
  }
586
0
  else
587
0
  {
588
0
    return PelUnitBuf( chromaFormat, getBuf( unit.Y(), type ), getBuf( unit.Cb(), type ), getBuf( unit.Cr(), type ) );
589
0
  }
590
0
}
591
592
const CPelUnitBuf Picture::getBuf( const UnitArea &unit, const PictureType &type ) const
593
0
{
594
0
  if( chromaFormat == CHROMA_400 )
595
0
  {
596
0
    return CPelUnitBuf( chromaFormat, getBuf( unit.Y(), type ) );
597
0
  }
598
0
  else
599
0
  {
600
0
    return CPelUnitBuf( chromaFormat, getBuf( unit.Y(), type ), getBuf( unit.Cb(), type ), getBuf( unit.Cr(), type ) );
601
0
  }
602
0
}
603
604
Pel* Picture::getOrigin( const PictureType &type, const ComponentID compID ) const
605
0
{
606
0
  return m_bufs[type].getOrigin( compID );
607
0
}
608
609
PelBuf Picture::getOriginBuf( const PictureType &type, const ComponentID compID )
610
0
{
611
0
  return m_bufs[type].getOriginBuf( compID );
612
0
}
613
614
Size Picture::getBufSize( const PictureType &type, const ComponentID compID ) const
615
0
{
616
0
  return m_bufs[type].getBufSize( compID );
617
0
}
618
619
void* Picture::getBufAllocator( const ComponentID compID )
620
0
{
621
0
  return m_bufs[PIC_RECONSTRUCTION].getBufAllocator( compID );
622
0
}
623
624
bool Picture::isExternAllocator() const
625
0
{
626
0
  return m_bufs[PIC_RECONSTRUCTION].isExternAllocator();
627
0
}
628
629
const UserAllocator* Picture::getUserAllocator() const
630
713
{
631
713
  return m_bufs[PIC_RECONSTRUCTION].getUserAllocator();
632
713
}
633
634
std::vector<Picture*> Picture::buildAllRefPicsVec()
635
713
{
636
713
  std::vector<Picture*> refPics;
637
713
  for( const Slice* slice : this->slices )
638
713
  {
639
713
    if( slice->isIntra() )
640
713
    {
641
713
      continue;
642
713
    }
643
644
0
    for( int iDir = REF_PIC_LIST_0; iDir < NUM_REF_PIC_LIST_01; ++iDir )
645
0
    {
646
0
      for( int iRefIdx = 0; iRefIdx < slice->getNumRefIdx( ( RefPicList ) iDir ); iRefIdx++ )
647
0
      {
648
0
        Picture* refPic = slice->getNoConstRefPic( ( RefPicList ) iDir, iRefIdx );
649
0
        if( std::find( refPics.cbegin(), refPics.cend(), refPic ) == refPics.cend() )
650
0
        {
651
0
          refPics.push_back( refPic );
652
0
        }
653
0
      }
654
0
    }
655
0
  }
656
657
713
  return refPics;
658
713
}
659
660
void Picture::startProcessingTimer()
661
1.42k
{
662
1.42k
  std::lock_guard<std::mutex> lock( m_timerMutex );
663
1.42k
  m_processingStartTime = std::chrono::steady_clock::now();
664
1.42k
}
665
666
void Picture::stopProcessingTimer()
667
6
{
668
6
  std::lock_guard<std::mutex> lock( m_timerMutex );
669
6
  auto endTime = std::chrono::steady_clock::now();
670
6
  m_dProcessingTime += std::chrono::duration<double>(endTime - m_processingStartTime).count();
671
6
}
672
673
}   // namespace vvdec