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