Coverage Report

Created: 2026-12-01 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/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
0
{
102
0
  layerId = _layerId;
103
0
  UnitArea::operator=( UnitArea( _chromaFormat, Area( Position{ 0, 0 }, size ) ) );
104
0
  margin            = _margin;
105
0
  m_bufs[PIC_RECONSTRUCTION].create( _chromaFormat, size, _maxCUSize, _margin, MEMORY_ALIGN_DEF_SIZE, true, _userAllocator );
106
0
}
107
108
void Picture::createWrapAroundBuf( const bool isWrapAround, const unsigned _maxCUSize )
109
0
{
110
0
  if( isWrapAround && m_bufs[PIC_RECON_WRAP].bufs.empty() )
111
0
    m_bufs[PIC_RECON_WRAP].create( chromaFormat, Y().size(), _maxCUSize, margin, MEMORY_ALIGN_DEF_SIZE );
112
0
}
113
114
void Picture::resetForUse( int _layerId )
115
0
{
116
0
  CHECK( lockedByApplication == LOCKED, "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
0
  m_subPicExtTasks.clear();
125
126
0
  m_dProcessingTime       = 0;
127
0
  subPicExtStarted        = false;
128
0
  borderExtStarted        = false;
129
0
  dpbReferenceMark        = unreferenced;
130
0
  stillReferenced         = false;
131
0
  isReferencePic          = false;
132
0
  progress                = Picture::init;
133
0
  neededForOutput         = false;
134
0
  wasLost                 = false;
135
0
  error                   = false;
136
0
  exceptionThrownOut      = false;
137
0
  topField                = false;
138
0
  fieldPic                = false;
139
0
  skippedDecCount         = 0;
140
141
0
  picCheckedDPH = false;
142
0
  subpicsCheckedDPH.clear();
143
0
  dphMismatch   = false;
144
145
0
  lockedByApplication = UNLOCKED;
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
  subPictures.clear();
160
161
0
  subLayerNonReferencePictureDueToSTSA = 0;
162
163
0
  m_divTasksCounter     .clearException();
164
0
  m_ctuTaskCounter      .clearException();
165
0
  m_borderExtTaskCounter.clearException();
166
0
  m_copyWrapBufDone     .clearException();
167
0
  reconDone             .clearException();
168
0
  parseDone             .clearException();
169
0
#if RECO_WHILE_PARSE
170
0
  std::for_each( ctuParsedBarrier.begin(), ctuParsedBarrier.end(), []( auto& b ) { b.clearException(); } );
171
0
#endif
172
173
0
  clearSliceBuffer();
174
175
0
  SEI_internal::deleteSEIs( seiMessageList );
176
177
0
  reconDone.lock();
178
0
}
179
180
void Picture::destroy()
181
0
{
182
0
  CHECK_WARN( lockedByApplication == LOCKED, "the picture can not be destroyed, because it has not been unlocked by the application." );
183
184
0
  for (uint32_t t = 0; t < NUM_PIC_TYPES; t++)
185
0
  {
186
0
    m_bufs[t].destroy();
187
0
  }
188
189
0
  if( cs )
190
0
  {
191
0
    cs->destroy();
192
0
    cs.reset();
193
0
  }
194
195
0
#if  RECO_WHILE_PARSE
196
0
  ctuParsedBarrier.clear();
197
0
#endif
198
199
0
  clearSliceBuffer();
200
201
0
  SEI_internal::deleteSEIs( seiMessageList );
202
203
0
  subpicsCheckedDPH.clear();
204
205
0
  m_divTasksCounter     .clearException();
206
0
  m_ctuTaskCounter      .clearException();
207
0
  m_borderExtTaskCounter.clearException();
208
0
  m_copyWrapBufDone     .clearException();
209
0
  reconDone             .clearException();
210
0
  parseDone             .clearException();
211
0
#if RECO_WHILE_PARSE
212
0
  std::for_each( ctuParsedBarrier.begin(), ctuParsedBarrier.end(), []( auto& b ) { b.clearException(); } );
213
0
#endif
214
0
}
215
216
0
       PelBuf     Picture::getRecoBuf(const ComponentID compID, bool wrap)       { return getBuf(compID, wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
217
0
const CPelBuf     Picture::getRecoBuf(const ComponentID compID, bool wrap) const { return getBuf(compID, wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
218
0
       PelBuf     Picture::getRecoBuf(const CompArea &blk, bool wrap)            { return getBuf(blk,    wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
219
0
const CPelBuf     Picture::getRecoBuf(const CompArea &blk, bool wrap)      const { return getBuf(blk,    wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
220
0
       PelUnitBuf Picture::getRecoBuf(const UnitArea &unit, bool wrap)           { return getBuf(unit,   wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
221
0
const CPelUnitBuf Picture::getRecoBuf(const UnitArea &unit, bool wrap)     const { return getBuf(unit,   wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
222
0
       PelUnitBuf Picture::getRecoBuf( bool wrap )                               { return wrap ? m_bufs[PIC_RECON_WRAP] : m_bufs[PIC_RECONSTRUCTION]; }
223
0
const CPelUnitBuf Picture::getRecoBuf( bool wrap )                         const { return wrap ? m_bufs[PIC_RECON_WRAP] : m_bufs[PIC_RECONSTRUCTION]; }
224
225
Picture::Picture( bool enableOpt )
226
0
{
227
0
  paddPicBorderBot = paddPicBorderBotCore;
228
0
  paddPicBorderTop = paddPicBorderTopCore;
229
0
  paddPicBorderLeftRight = paddPicBorderLeftRightCore;
230
231
0
  if( enableOpt )
232
0
  {
233
#if ENABLE_SIMD_OPT_PICTURE && defined( TARGET_SIMD_X86 )
234
    initPictureX86();
235
#endif
236
#if ENABLE_SIMD_OPT_PICTURE && defined( TARGET_SIMD_ARM )
237
    initPictureARM();
238
#endif
239
0
  }
240
0
}
241
242
void Picture::finalInit( CUChunkCache* cuChunkCache, TUChunkCache* tuChunkCache, CUMapCache* cuMapCache, CUMapCache* chromaCuMapCache, 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 )
243
0
{
244
0
  SEI_internal::deleteSEIs( seiMessageList );
245
0
  clearSliceBuffer();
246
247
0
  const ChromaFormat chromaFormatIDC = sps->getChromaFormatIdc();
248
0
  const int          iWidth          = pps->getPicWidthInLumaSamples();
249
0
  const int          iHeight         = pps->getPicHeightInLumaSamples();
250
251
0
  if( !cs )
252
0
  {
253
0
    cs = std::make_unique<CodingStructure>( cuChunkCache, tuChunkCache, cuMapCache, chromaCuMapCache );
254
0
    cs->create( chromaFormatIDC, Area( 0, 0, iWidth, iHeight ) );
255
0
  }
256
257
0
#if RECO_WHILE_PARSE
258
0
  if( ctuParsedBarrier.size() != pps->pcv->sizeInCtus )
259
0
  {
260
0
    ctuParsedBarrier = std::vector<Barrier>( pps->pcv->sizeInCtus );
261
0
  }
262
0
#endif
263
264
0
  parseDone   . lock();
265
0
  cs->picture   = this;
266
0
  cs->picHeader = ph;
267
0
  cs->pps       = pps->getSharedPtr();
268
0
  cs->sps       = sps->getSharedPtr();
269
0
  cs->pcv       = pps->pcv.get();
270
271
0
  if( ph )   // generated pictures (8.3.4) have no picture header
272
0
  {
273
0
    ph->setPic( this );
274
0
    ph->setSPSId         ( sps->getSPSId() );
275
0
    ph->setPPSId         ( pps->getPPSId() );
276
0
    ph->setLmcsAPS       ( lmcsAps        ? lmcsAps       ->getSharedPtr() : nullptr );
277
0
    ph->setScalingListAPS( scalingListAps ? scalingListAps->getSharedPtr() : nullptr );
278
0
  }
279
280
0
  for( int i = 0; i < ALF_CTB_MAX_NUM_APS; ++i )
281
0
  {
282
0
    cs->alfApss[i] = alfApss[i] ? alfApss[i]->getSharedPtr() : nullptr;
283
0
  }
284
0
  if( lmcsAps )
285
0
  {
286
0
    cs->lmcsAps = lmcsAps ? lmcsAps->getSharedPtr() : nullptr;
287
0
  }
288
289
0
  cs->allocTempInternals();
290
0
  cs->rebindPicBufs();
291
0
  cs->initStructData();
292
293
0
  if( sps->getIBCFlag() )
294
0
  {
295
0
    cs->initVIbcBuf( cs->pcv->heightInCtus, sps->getChromaFormatIdc(), sps->getMaxCUHeight() );
296
0
  }
297
298
0
  resetProcessingTime();
299
0
}
300
301
Slice* Picture::allocateNewSlice( Slice** pilot )
302
0
{
303
0
  if( pilot )
304
0
  {
305
0
    slices.push_back( *pilot );
306
0
    *pilot = new Slice;
307
0
    if( slices.size() >= 2 )
308
0
    {
309
0
      ( *pilot )->copySliceInfo( slices[slices.size() - 2] );
310
0
      ( *pilot )->initSlice();
311
0
    }
312
0
    ( *pilot )->clearSPS();
313
0
    ( *pilot )->clearPPS();
314
0
    ( *pilot )->clearVPS();
315
0
    ( *pilot )->clearAlfAPSs();
316
0
  }
317
0
  else
318
0
  {
319
0
    slices.push_back( new Slice );
320
0
    if( slices.size() >= 2 )
321
0
    {
322
0
      slices.back()->copySliceInfo( slices[slices.size() - 2] );
323
0
      slices.back()->initSlice();
324
0
    }
325
0
  }
326
327
0
  Slice* slice = slices.back();
328
329
0
  slice->setPPS( cs->pps );
330
0
  slice->setSPS( cs->sps );
331
0
  slice->setVPS( cs->vps );
332
0
  slice->setAlfApss( cs->alfApss );
333
0
  slice->setPic( this );
334
335
0
  return slice;
336
0
}
337
338
void Picture::clearSliceBuffer()
339
0
{
340
0
  for( auto &s: slices )
341
0
  {
342
0
    delete s;
343
0
  }
344
0
  slices.clear();
345
0
}
346
347
bool Picture::lastSliceOfPicPresent() const
348
0
{
349
0
  if( slices.empty() )
350
0
  {
351
0
    return false;
352
0
  }
353
0
  const Slice*   lastSlice      = slices.back();
354
0
  const unsigned lastCtuInSlice = lastSlice->getCtuAddrInSlice( lastSlice->getNumCtuInSlice() - 1 );
355
0
  return lastCtuInSlice == lastSlice->getPPS()->pcv->sizeInCtus - 1;
356
0
}
357
358
void Picture::setParseError( std::exception_ptr e )
359
0
{
360
0
  error = true;
361
0
  parseDone.setException( e );
362
0
#if RECO_WHILE_PARSE
363
  // reconstruction can already be waiting for CTUs, that will never be parsed
364
0
  for( auto& b: ctuParsedBarrier )
365
0
  {
366
0
    b.setException( e );
367
0
  }
368
0
#endif
369
0
}
370
371
void Picture::waitForAllTasks()
372
0
{
373
0
  m_ctuTaskCounter.wait_nothrow();
374
0
  m_borderExtTaskCounter.wait_nothrow();
375
0
  m_divTasksCounter.wait_nothrow();   // this waits for the slice parsing and the finishPic Task
376
0
}
377
378
void Picture::ensureUsableAsRef()
379
0
{
380
0
#if RECO_WHILE_PARSE
381
0
  ctuParsedBarrier.clear();
382
0
#endif
383
0
  neededForOutput = false;
384
385
  // 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
386
0
  dpbReferenceMark = ShortTerm;
387
0
  stillReferenced  = true;
388
0
  isReferencePic   = true;
389
390
  // ensure cs->m_colMiMap is set to zero
391
0
  cs->initStructData();
392
393
0
  CHECK_FATAL( reconDone.hasException(), "to be usable as reference the picture should not have an Exception reconDone barrier" );
394
0
}
395
396
void Picture::fillGrey( const SPS* fallbackSPS )
397
0
{
398
0
  CHECK( ( !cs || !cs->sps ) && !fallbackSPS, "No SPS accessible" );
399
400
0
  const int bitDepth = cs && cs->sps ? cs->sps->getBitDepth() : fallbackSPS->getBitDepth();
401
  // fill in grey buffer for missing reference pictures (GDR or broken bitstream)
402
0
  getRecoBuf().fill( 1 << ( bitDepth - 1 ) );
403
404
0
  progress = Picture::reconstructed;
405
0
  reconDone.unlock();
406
0
}
407
408
void Picture::extendPicBorder( bool top, bool bottom, bool leftrightT, bool leftrightB, ChannelType chType )
409
0
{
410
0
  if( cs->pps->getUseWrapAround() )
411
0
  {
412
0
    extendPicBorderWrap( top, bottom, leftrightT, leftrightB, chType );
413
0
  }
414
415
0
  extendPicBorderBuf( m_bufs[PIC_RECONSTRUCTION], top, bottom, leftrightT, leftrightB, chType );
416
0
}
417
418
void Picture::extendPicBorderWrap( bool top, bool bottom, bool leftrightT, bool leftrightB, ChannelType chType )
419
0
{
420
0
  for( int comp = 0; comp < getNumberValidComponents( cs->area.chromaFormat ); comp++ )
421
0
  {
422
0
    ComponentID compID = ComponentID( comp );
423
424
0
    if( chType != MAX_NUM_CHANNEL_TYPE && toChannelType( compID ) != chType )
425
0
      continue;
426
427
0
    PelBuf prw = m_bufs[PIC_RECON_WRAP].get( compID );
428
429
0
    const int xmargin = margin >> getComponentScaleX( compID, cs->area.chromaFormat );
430
0
    const int ymargin = margin >> getComponentScaleY( compID, cs->area.chromaFormat );
431
432
0
    int xoffset = cs->pps->getWrapAroundOffset() >> getComponentScaleX( compID, cs->area.chromaFormat );
433
0
    if( leftrightT )
434
0
    {
435
0
      Pel* piprw = prw.bufAt( 0, 1 );
436
437
0
      for( int y = 1; y < prw.height / 2; y++ )
438
0
      {
439
0
        for( int x = 0; x < xmargin; x++ )
440
0
        {
441
0
          if( x < xoffset )
442
0
          {
443
0
            piprw[-x - 1]        = piprw[-x - 1 + xoffset];
444
0
            piprw[prw.width + x] = piprw[prw.width + x - xoffset];
445
0
          }
446
0
          else
447
0
          {
448
0
            piprw[-x - 1]        = piprw[0];
449
0
            piprw[prw.width + x] = piprw[prw.width - 1];
450
0
          }
451
0
        }
452
0
        piprw += prw.stride;
453
0
      }
454
0
    }
455
0
    if( leftrightB )
456
0
    {
457
0
      Pel* piprw = prw.bufAt( 0, prw.height / 2 );
458
459
0
      for( int y = 1; y < prw.height / 2; y++ )
460
0
      {
461
0
        for( int x = 0; x < xmargin; x++ )
462
0
        {
463
0
          if( x < xoffset )
464
0
          {
465
0
            piprw[-x - 1]        = piprw[-x - 1 + xoffset];
466
0
            piprw[prw.width + x] = piprw[prw.width + x - xoffset];
467
0
          }
468
0
          else
469
0
          {
470
0
            piprw[-x - 1]        = piprw[0];
471
0
            piprw[prw.width + x] = piprw[prw.width - 1];
472
0
          }
473
0
        }
474
0
        piprw += prw.stride;
475
0
      }
476
0
    }
477
478
0
    if( bottom )
479
0
    {
480
0
      Pel* piprw = prw.bufAt( 0, prw.height - 1 );
481
482
0
      for( int x = 0; x < xmargin; x++ )
483
0
      {
484
0
        if( x < xoffset )
485
0
        {
486
0
          piprw[-x - 1]        = piprw[-x - 1 + xoffset];
487
0
          piprw[prw.width + x] = piprw[prw.width + x - xoffset];
488
0
        }
489
0
        else
490
0
        {
491
0
          piprw[-x - 1]        = piprw[0];
492
0
          piprw[prw.width + x] = piprw[prw.width - 1];
493
0
        }
494
0
      }
495
0
      piprw -= xmargin;
496
      // pi is now the (-marginX, height-1)
497
0
      for( int y = 0; y < ymargin; y++ )
498
0
      {
499
0
        ::memcpy( piprw + ( y + 1 ) * prw.stride, piprw, sizeof( Pel ) * ( prw.width + ( xmargin << 1 ) ) );
500
0
      }
501
0
    }
502
0
    if( top )
503
0
    {
504
0
      Pel* piprw = prw.bufAt( 0, 0 );
505
506
0
      for( int x = 0; x < xmargin; x++ )
507
0
      {
508
0
        if( x < xoffset )
509
0
        {
510
0
          piprw[-x - 1]        = piprw[-x - 1 + xoffset];
511
0
          piprw[prw.width + x] = piprw[prw.width + x - xoffset];
512
0
        }
513
0
        else
514
0
        {
515
0
          piprw[-x - 1]        = piprw[0];
516
0
          piprw[prw.width + x] = piprw[prw.width - 1];
517
0
        }
518
0
      }
519
0
      piprw -= xmargin;
520
      // pi is now (-marginX, 0)
521
0
      for( int y = 0; y < ymargin; y++ )
522
0
      {
523
0
        ::memcpy( piprw - ( y + 1 ) * prw.stride, piprw, sizeof( Pel ) * ( prw.width + ( xmargin << 1 ) ) );
524
0
      }
525
0
    }
526
0
  }
527
0
}
528
529
void Picture::extendPicBorderBuf( PelStorage& storage, bool top, bool bottom, bool leftrightT, bool leftrightB, ChannelType chType )
530
0
{
531
0
  for( int comp = 0; comp < getNumberValidComponents( cs->area.chromaFormat ); comp++ )
532
0
  {
533
0
    ComponentID compID = ComponentID( comp );
534
535
0
    if( chType != MAX_NUM_CHANNEL_TYPE && toChannelType( compID ) != chType )
536
0
      continue;
537
538
0
    PelBuf p = storage.bufs[compID];
539
540
0
    const int xmargin = margin >> getComponentScaleX( compID, cs->area.chromaFormat );
541
0
    const int ymargin = margin >> getComponentScaleY( compID, cs->area.chromaFormat );
542
543
0
    if( leftrightT )
544
0
    {
545
0
      Pel* pi = p.bufAt( 0, 1 );
546
0
      paddPicBorderLeftRight( pi, p.stride, p.width, xmargin, 1 + p.height / 2 );
547
0
    }
548
0
    if( leftrightB )
549
0
    {
550
0
      Pel* pi = p.bufAt( 0, p.height / 2 );
551
0
      paddPicBorderLeftRight( pi, p.stride, p.width, xmargin, 1 + p.height / 2 );
552
0
    }
553
0
    if( bottom )
554
0
    {
555
      // pi is now the (0,height) (bottom left of image within bigger picture
556
0
      Pel* pi = p.bufAt( 0, p.height - 1 );
557
0
      paddPicBorderBot( pi, p.stride, p.width, xmargin, ymargin );
558
0
    }
559
0
    if( top )
560
0
    {
561
      // pi is now the (0,height) (bottom left of image within bigger picture
562
0
      Pel* pi = p.bufAt( 0, 0 );
563
0
      paddPicBorderTop( pi, p.stride, p.width, xmargin, ymargin );
564
0
    }
565
0
  }
566
0
}
567
568
PelBuf Picture::getBuf( const CompArea &blk, const PictureType &type )
569
0
{
570
0
  if( !blk.valid() )
571
0
  {
572
0
    return PelBuf();
573
0
  }
574
575
0
  return m_bufs[type].getBuf( blk );
576
0
}
577
578
const CPelBuf Picture::getBuf( const CompArea &blk, const PictureType &type ) const
579
0
{
580
0
  if( !blk.valid() )
581
0
  {
582
0
    return PelBuf();
583
0
  }
584
585
0
  return m_bufs[type].getBuf( blk );
586
0
}
587
588
PelUnitBuf Picture::getBuf( const UnitArea &unit, const PictureType &type )
589
0
{
590
0
  if( chromaFormat == CHROMA_400 )
591
0
  {
592
0
    return PelUnitBuf( chromaFormat, getBuf( unit.Y(), type ) );
593
0
  }
594
0
  else
595
0
  {
596
0
    return PelUnitBuf( chromaFormat, getBuf( unit.Y(), type ), getBuf( unit.Cb(), type ), getBuf( unit.Cr(), type ) );
597
0
  }
598
0
}
599
600
const CPelUnitBuf Picture::getBuf( const UnitArea &unit, const PictureType &type ) const
601
0
{
602
0
  if( chromaFormat == CHROMA_400 )
603
0
  {
604
0
    return CPelUnitBuf( chromaFormat, getBuf( unit.Y(), type ) );
605
0
  }
606
0
  else
607
0
  {
608
0
    return CPelUnitBuf( chromaFormat, getBuf( unit.Y(), type ), getBuf( unit.Cb(), type ), getBuf( unit.Cr(), type ) );
609
0
  }
610
0
}
611
612
Pel* Picture::getOrigin( const PictureType &type, const ComponentID compID ) const
613
0
{
614
0
  return m_bufs[type].getOrigin( compID );
615
0
}
616
617
PelBuf Picture::getOriginBuf( const PictureType &type, const ComponentID compID )
618
0
{
619
0
  return m_bufs[type].getOriginBuf( compID );
620
0
}
621
622
Size Picture::getBufSize( const PictureType &type, const ComponentID compID ) const
623
0
{
624
0
  return m_bufs[type].getBufSize( compID );
625
0
}
626
627
void* Picture::getBufAllocator( const ComponentID compID )
628
0
{
629
0
  return m_bufs[PIC_RECONSTRUCTION].getBufAllocator( compID );
630
0
}
631
632
bool Picture::isExternAllocator() const
633
0
{
634
0
  return m_bufs[PIC_RECONSTRUCTION].isExternAllocator();
635
0
}
636
637
const UserAllocator* Picture::getUserAllocator() const
638
0
{
639
0
  return m_bufs[PIC_RECONSTRUCTION].getUserAllocator();
640
0
}
641
642
std::vector<Picture*> Picture::buildAllRefPicsVec()
643
0
{
644
0
  std::vector<Picture*> refPics;
645
0
  for( const Slice* slice : this->slices )
646
0
  {
647
0
    if( slice->isIntra() )
648
0
    {
649
0
      continue;
650
0
    }
651
652
0
    for( int iDir = REF_PIC_LIST_0; iDir < NUM_REF_PIC_LIST_01; ++iDir )
653
0
    {
654
0
      for( int iRefIdx = 0; iRefIdx < slice->getNumRefIdx( ( RefPicList ) iDir ); iRefIdx++ )
655
0
      {
656
0
        Picture* refPic = slice->getNoConstRefPic( ( RefPicList ) iDir, iRefIdx );
657
0
        if( std::find( refPics.cbegin(), refPics.cend(), refPic ) == refPics.cend() )
658
0
        {
659
0
          refPics.push_back( refPic );
660
0
        }
661
0
      }
662
0
    }
663
0
  }
664
665
0
  return refPics;
666
0
}
667
668
void Picture::startProcessingTimer()
669
0
{
670
0
  std::lock_guard<std::mutex> lock( m_timerMutex );
671
0
  m_processingStartTime = std::chrono::steady_clock::now();
672
0
}
673
674
void Picture::stopProcessingTimer()
675
0
{
676
0
  std::lock_guard<std::mutex> lock( m_timerMutex );
677
0
  auto endTime = std::chrono::steady_clock::now();
678
0
  m_dProcessingTime += std::chrono::duration<double>(endTime - m_processingStartTime).count();
679
0
}
680
681
}   // namespace vvdec