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