HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TComPic.cpp
Go to the documentation of this file.
1 /* The copyright in this software is being made available under the BSD
2  * License, included below. This software may be subject to other third party
3  * and contributor rights, including patent rights, and no such rights are
4  * granted under this license.
5  *
6  * Copyright (c) 2010-2017, ITU/ISO/IEC
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18  * be used to endorse or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
38 #include "TComPic.h"
39 #include "SEI.h"
40 
43 
44 // ====================================================================================================================
45 // Constructor / destructor / create / destroy
46 // ====================================================================================================================
47 
49 : m_uiTLayer (0)
50 , m_bUsedByCurr (false)
51 , m_bIsLongTerm (false)
52 , m_pcPicYuvPred (NULL)
53 , m_pcPicYuvResi (NULL)
54 , m_bReconstructed (false)
55 , m_bNeededForOutput (false)
56 , m_uiCurrSliceIdx (0)
57 , m_bCheckLTMSB (false)
58 {
59  for(UInt i=0; i<NUM_PIC_YUV; i++)
60  {
61  m_apcPicYuv[i] = NULL;
62  }
63 }
64 
66 {
67  destroy();
68 }
69 
70 #if REDUCED_ENCODER_MEMORY
71 Void TComPic::create( const TComSPS &sps, const TComPPS &pps, const Bool bCreateEncoderSourcePicYuv, const Bool bCreateForImmediateReconstruction )
72 #else
73 Void TComPic::create( const TComSPS &sps, const TComPPS &pps, const Bool bIsVirtual)
74 #endif
75 {
76  destroy();
77 
78  const ChromaFormat chromaFormatIDC = sps.getChromaFormatIdc();
79  const Int iWidth = sps.getPicWidthInLumaSamples();
80  const Int iHeight = sps.getPicHeightInLumaSamples();
81  const UInt uiMaxCuWidth = sps.getMaxCUWidth();
82  const UInt uiMaxCuHeight = sps.getMaxCUHeight();
83  const UInt uiMaxDepth = sps.getMaxTotalCUDepth();
84 
85 #if REDUCED_ENCODER_MEMORY
86  m_picSym.create( sps, pps, uiMaxDepth, bCreateForImmediateReconstruction );
87  if (bCreateEncoderSourcePicYuv)
88 #else
89  m_picSym.create( sps, pps, uiMaxDepth );
90  if (!bIsVirtual)
91 #endif
92  {
93  m_apcPicYuv[PIC_YUV_ORG ] = new TComPicYuv; m_apcPicYuv[PIC_YUV_ORG ]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
94  m_apcPicYuv[PIC_YUV_TRUE_ORG] = new TComPicYuv; m_apcPicYuv[PIC_YUV_TRUE_ORG]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
95  }
96 #if REDUCED_ENCODER_MEMORY
97  if (bCreateForImmediateReconstruction)
98  {
99 #endif
100  m_apcPicYuv[PIC_YUV_REC] = new TComPicYuv; m_apcPicYuv[PIC_YUV_REC]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
101 #if REDUCED_ENCODER_MEMORY
102  }
103 #endif
104 
105  // there are no SEI messages associated with this picture initially
106  if (m_SEIs.size() > 0)
107  {
108  deleteSEIs (m_SEIs);
109  }
110  m_bUsedByCurr = false;
111 }
112 
113 #if REDUCED_ENCODER_MEMORY
115 {
116  const TComSPS &sps=m_picSym.getSPS();
117 
118  const ChromaFormat chromaFormatIDC = sps.getChromaFormatIdc();
119  const Int iWidth = sps.getPicWidthInLumaSamples();
120  const Int iHeight = sps.getPicHeightInLumaSamples();
121  const UInt uiMaxCuWidth = sps.getMaxCUWidth();
122  const UInt uiMaxCuHeight = sps.getMaxCUHeight();
123  const UInt uiMaxDepth = sps.getMaxTotalCUDepth();
124 
126  {
127  m_apcPicYuv[PIC_YUV_ORG ] = new TComPicYuv; m_apcPicYuv[PIC_YUV_ORG ]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
128  }
130  {
131  m_apcPicYuv[PIC_YUV_TRUE_ORG] = new TComPicYuv; m_apcPicYuv[PIC_YUV_TRUE_ORG]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
132  }
133 }
134 
136 {
137  if (m_apcPicYuv[PIC_YUV_REC] == NULL)
138  {
139  const TComSPS &sps=m_picSym.getSPS();
140  const ChromaFormat chromaFormatIDC = sps.getChromaFormatIdc();
141  const Int iWidth = sps.getPicWidthInLumaSamples();
142  const Int iHeight = sps.getPicHeightInLumaSamples();
143  const UInt uiMaxCuWidth = sps.getMaxCUWidth();
144  const UInt uiMaxCuHeight = sps.getMaxCUHeight();
145  const UInt uiMaxDepth = sps.getMaxTotalCUDepth();
146 
147  m_apcPicYuv[PIC_YUV_REC] = new TComPicYuv; m_apcPicYuv[PIC_YUV_REC]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
148  }
149 
150  // mark it should be extended
152 
154 }
155 
157 {
159 }
160 
162 {
163  if (m_apcPicYuv[PIC_YUV_ORG ])
164  {
166  delete m_apcPicYuv[PIC_YUV_ORG];
168  }
170  {
174  }
175 }
176 
178 {
179  if (m_apcPicYuv[PIC_YUV_REC ])
180  {
182  delete m_apcPicYuv[PIC_YUV_REC];
184  }
186 }
187 #endif
188 
190 {
191  m_picSym.destroy();
192 
193  for(UInt i=0; i<NUM_PIC_YUV; i++)
194  {
195  if (m_apcPicYuv[i])
196  {
197  m_apcPicYuv[i]->destroy();
198  delete m_apcPicYuv[i];
199  m_apcPicYuv[i] = NULL;
200  }
201  }
202 
204 }
205 
207 {
208  TComPicSym* pPicSym = getPicSym();
209  for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getNumberOfCtusInFrame(); uiCUAddr++ )
210  {
211  TComDataCU* pCtu = pPicSym->getCtu(uiCUAddr);
212  pCtu->compressMV();
213  }
214 }
215 
217 {
218  Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCtuTsToRsAddrMap(getCtu(currAddr)->getSlice()->getSliceCurStartCtuTsAddr()));
219  Bool mergeCtbInTile = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr));
220  return (mergeCtbInSliceSeg && mergeCtbInTile);
221 }
222 
223 UInt TComPic::getSubstreamForCtuAddr(const UInt ctuAddr, const Bool bAddressInRaster, TComSlice *pcSlice)
224 {
225  UInt subStrm;
226  const bool bWPPEnabled=pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag();
227  const TComPicSym &picSym = *(getPicSym());
228 
229  if ((bWPPEnabled && picSym.getFrameHeightInCtus()>1) || (picSym.getNumTiles()>1)) // wavefronts, and possibly tiles being used.
230  {
231  if (bWPPEnabled)
232  {
233  const UInt ctuRsAddr = bAddressInRaster?ctuAddr : picSym.getCtuTsToRsAddrMap(ctuAddr);
234  const UInt frameWidthInCtus = picSym.getFrameWidthInCtus();
235  const UInt tileIndex = picSym.getTileIdxMap(ctuRsAddr);
236  const UInt numTileColumns = (picSym.getNumTileColumnsMinus1()+1);
237  const TComTile *pTile = picSym.getTComTile(tileIndex);
238  const UInt firstCtuRsAddrOfTile = pTile->getFirstCtuRsAddr();
239  const UInt tileYInCtus = firstCtuRsAddrOfTile / frameWidthInCtus;
240  // independent tiles => substreams are "per tile"
241  const UInt ctuLine = ctuRsAddr / frameWidthInCtus;
242  const UInt startingSubstreamForTile =(tileYInCtus*numTileColumns) + (pTile->getTileHeightInCtus()*(tileIndex%numTileColumns));
243  subStrm = startingSubstreamForTile + (ctuLine - tileYInCtus);
244  }
245  else
246  {
247  const UInt ctuRsAddr = bAddressInRaster?ctuAddr : picSym.getCtuTsToRsAddrMap(ctuAddr);
248  const UInt tileIndex = picSym.getTileIdxMap(ctuRsAddr);
249  subStrm=tileIndex;
250  }
251  }
252  else
253  {
254  // dependent tiles => substreams are "per frame".
255  subStrm = 0;
256  }
257  return subStrm;
258 }
259 
260 
Void releaseEncoderSourceImageData()
Definition: TComPic.cpp:161
virtual Void destroy()
Definition: TComPic.cpp:189
virtual ~TComPic()
Definition: TComPic.cpp:65
UInt getFirstCtuRsAddr() const
Definition: TComPicSym.h:79
UInt getCtuTsToRsAddrMap(Int ctuTsAddr) const
Definition: TComPicSym.h:183
picture YUV buffer class
Definition: TComPicYuv.h:55
CU data structure class.
Definition: TComDataCU.h:64
void Void
Definition: TypeDef.h:203
Void deleteSEIs(SEIMessages &seiList)
delete list of SEI messages (freeing the referenced objects)
Definition: SEI.cpp:77
Int getNumTileColumnsMinus1() const
Definition: TComPicSym.h:178
#define NULL
Definition: CommonDef.h:107
TComSlice * getSlice(Int i)
Definition: TComPic.h:113
unsigned int UInt
Definition: TypeDef.h:212
UInt getMaxCUHeight() const
Definition: TComSlice.h:859
Void releaseAllReconstructionData()
Definition: TComPicSym.cpp:221
Void create(const TComSPS &sps, const TComPPS &pps, const Bool bCreateEncoderSourcePicYuv, const Bool bCreateForImmediateReconstruction)
Definition: TComPic.cpp:71
picture class (header)
ChromaFormat getChromaFormatIdc() const
Definition: TComSlice.h:826
TComPicSym m_picSym
Definition: TComPic.h:67
UInt getFrameWidthInCtus() const
Definition: TComPicSym.h:156
SEIMessages m_SEIs
Any SEI messages that have been received. If !NULL we own the object.
Definition: TComPic.h:82
UInt getMaxTotalCUDepth() const
Definition: TComSlice.h:861
Void prepareForEncoderSourcePicYuv()
Definition: TComPic.cpp:114
UInt getTileIdxMap(Int ctuRsAddr) const
Definition: TComPicSym.h:184
Bool getSAOMergeAvailability(Int currAddr, Int mergeAddr)
Definition: TComPic.cpp:216
bool Bool
Definition: TypeDef.h:204
UInt getSubstreamForCtuAddr(const UInt ctuAddr, const Bool bAddressInRaster, TComSlice *pcSlice)
Definition: TComPic.cpp:223
Void prepareForReconstruction()
Definition: TComPic.cpp:135
Int getNumTiles() const
Definition: TComPicSym.h:180
PPS class.
Definition: TComSlice.h:1034
Void compressMV()
UInt getPicHeightInLumaSamples() const
Definition: TComSlice.h:836
Void releaseReconstructionIntermediateData()
Definition: TComPic.cpp:156
Void destroy()
Definition: TComPicSym.cpp:242
TComPicSym * getPicSym()
Definition: TComPic.h:111
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Definition: TypeDef.h:292
const TComPPS * getPPS() const
Definition: TComSlice.h:1332
UInt getPicWidthInLumaSamples() const
Definition: TComSlice.h:834
UInt getFrameHeightInCtus() const
Definition: TComPicSym.h:157
UInt getTileHeightInCtus() const
Definition: TComPicSym.h:73
const TComSPS & getSPS() const
Definition: TComPicSym.h:163
Bool getEntropyCodingSyncEnabledFlag() const
Definition: TComSlice.h:1151
TComDataCU * getCtu(UInt ctuRsAddr)
Definition: TComPicSym.h:161
Void releaseAllReconstructionData()
Definition: TComPic.cpp:177
TComDataCU * getCtu(UInt ctuRsAddr)
Definition: TComPic.h:116
Void compressMotion()
Definition: TComPic.cpp:206
Void prepareForReconstruction()
Definition: TComPicSym.cpp:166
TComTile * getTComTile(UInt tileIdx)
Definition: TComPicSym.h:181
Void create(const Int picWidth, const Int picHeight, const ChromaFormat chromaFormatIDC, const UInt maxCUWidth, const UInt maxCUHeight, const UInt maxCUDepth, const Bool bUseMargin)
if true, then a margin of uiMaxCUWidth+16 and uiMaxCUHeight+16 is created around the image...
Definition: TComPicYuv.cpp:121
UInt getNumberOfCtusInFrame() const
Definition: TComPicSym.h:160
int Int
Definition: TypeDef.h:211
TComPic()
Definition: TComPic.cpp:48
Void releaseReconstructionIntermediateData()
Definition: TComPicSym.cpp:203
TComPicYuv * m_apcPicYuv[NUM_PIC_YUV]
Definition: TComPic.h:68
Void setBorderExtension(Bool b)
Definition: TComPicYuv.h:170
slice header class
Definition: TComSlice.h:1225
Void destroy()
Definition: TComPicYuv.cpp:168
picture symbol class
Definition: TComPicSym.h:83
UInt getMaxCUWidth() const
Definition: TComSlice.h:857
SPS class.
Definition: TComSlice.h:740