source: SHVCSoftware/trunk/source/Lib/TLibCommon/TComPic.cpp @ 1166

Last change on this file since 1166 was 906, checked in by seregin, 10 years ago

merge SHM-dev

  • Property svn:eol-style set to native
File size: 15.7 KB
Line 
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-2014, 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
34/** \file     TComPic.cpp
35    \brief    picture class
36*/
37
38#include "TComPic.h"
39#include "SEI.h"
40
41//! \ingroup TLibCommon
42//! \{
43
44// ====================================================================================================================
45// Constructor / destructor / create / destroy
46// ====================================================================================================================
47
48TComPic::TComPic()
49: m_uiTLayer                              (0)
50, m_bUsedByCurr                           (false)
51, m_bIsLongTerm                           (false)
52, m_apcPicSym                             (NULL)
53, m_pcPicYuvPred                          (NULL)
54, m_pcPicYuvResi                          (NULL)
55, m_bReconstructed                        (false)
56, m_bNeededForOutput                      (false)
57, m_uiCurrSliceIdx                        (0)
58, m_bCheckLTMSB                           (false)
59#if SVC_EXTENSION
60, m_layerId( 0 )
61#endif
62{
63#if SVC_EXTENSION
64  memset( m_pcFullPelBaseRec, 0, sizeof( m_pcFullPelBaseRec ) );
65  memset( m_bSpatialEnhLayer, false, sizeof( m_bSpatialEnhLayer ) );
66  memset( m_equalPictureSizeAndOffsetFlag, false, sizeof( m_equalPictureSizeAndOffsetFlag ) );
67#endif
68  m_apcPicYuv[0]      = NULL;
69  m_apcPicYuv[1]      = NULL;
70}
71
72TComPic::~TComPic()
73{
74}
75#if SVC_EXTENSION
76#if AUXILIARY_PICTURES
77Void TComPic::create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
78                      Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual)
79#else
80Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
81                      Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual)
82#endif
83{
84  m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
85  if (!bIsVirtual)
86  {
87#if R0156_CONF_WINDOW_IN_REP_FORMAT
88#if AUXILIARY_PICTURES
89    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, &conformanceWindow );
90#else
91    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, &conformanceWindow );
92#endif
93#else
94#if AUXILIARY_PICTURES
95    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
96#else
97    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
98#endif
99#endif
100  }
101#if R0156_CONF_WINDOW_IN_REP_FORMAT
102#if AUXILIARY_PICTURES
103  m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, &conformanceWindow );
104#else
105  m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, &conformanceWindow );
106#endif
107#else
108#if AUXILIARY_PICTURES
109  m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
110#else
111  m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
112#endif
113#endif
114
115  for( Int i = 0; i < MAX_LAYERS; i++ )
116  {
117    if( m_bSpatialEnhLayer[i] )
118    {
119#if R0156_CONF_WINDOW_IN_REP_FORMAT
120#if AUXILIARY_PICTURES
121      m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, &conformanceWindow );
122#else
123      m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, &conformanceWindow );
124#endif
125#else
126#if AUXILIARY_PICTURES
127      m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
128#else
129      m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
130#endif
131#endif
132    }
133  }
134
135  m_layerId = pcSps ? pcSps->getLayerId() : 0;
136
137  // there are no SEI messages associated with this picture initially
138  if (m_SEIs.size() > 0)
139  {
140    deleteSEIs (m_SEIs);
141  }
142  m_bUsedByCurr = false;
143
144  /* store conformance window parameters with picture */
145  m_conformanceWindow = conformanceWindow;
146 
147  /* store display window parameters with picture */
148  m_defaultDisplayWindow = defaultDisplayWindow;
149
150  /* store number of reorder pics with picture */
151  memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int));
152
153  return;
154}
155#else
156Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
157                      Int *numReorderPics, Bool bIsVirtual)
158
159{
160  m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
161  if (!bIsVirtual)
162  {
163    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
164  }
165  m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
166 
167  // there are no SEI messages associated with this picture initially
168  if (m_SEIs.size() > 0)
169  {
170    deleteSEIs (m_SEIs);
171  }
172  m_bUsedByCurr = false;
173
174  /* store conformance window parameters with picture */
175  m_conformanceWindow = conformanceWindow;
176 
177  /* store display window parameters with picture */
178  m_defaultDisplayWindow = defaultDisplayWindow;
179
180  /* store number of reorder pics with picture */
181  memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int));
182
183  return;
184}
185#endif
186
187Void TComPic::destroy()
188{
189  if (m_apcPicSym)
190  {
191    m_apcPicSym->destroy();
192    delete m_apcPicSym;
193    m_apcPicSym = NULL;
194  }
195 
196  if (m_apcPicYuv[0])
197  {
198    m_apcPicYuv[0]->destroy();
199    delete m_apcPicYuv[0];
200    m_apcPicYuv[0]  = NULL;
201  }
202 
203  if (m_apcPicYuv[1])
204  {
205    m_apcPicYuv[1]->destroy();
206    delete m_apcPicYuv[1];
207    m_apcPicYuv[1]  = NULL;
208  }
209 
210  deleteSEIs(m_SEIs);
211#if SVC_EXTENSION
212  for( Int i = 0; i < MAX_LAYERS; i++ )
213  {
214    if( m_bSpatialEnhLayer[i] && m_pcFullPelBaseRec[i] )
215    {
216      m_pcFullPelBaseRec[i]->destroy();
217      delete m_pcFullPelBaseRec[i];
218      m_pcFullPelBaseRec[i]  = NULL;
219    }
220  }
221#endif
222}
223
224Void TComPic::compressMotion()
225{
226  TComPicSym* pPicSym = getPicSym(); 
227  for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getFrameHeightInCU()*pPicSym->getFrameWidthInCU(); uiCUAddr++ )
228  {
229    TComDataCU* pcCU = pPicSym->getCU(uiCUAddr);
230    pcCU->compressMV(); 
231  } 
232}
233
234Bool  TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr)
235{
236  Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCUOrderMap(getCU(currAddr)->getSlice()->getSliceCurStartCUAddr()/getNumPartInCU()));
237  Bool mergeCtbInTile     = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr));
238  return (mergeCtbInSliceSeg && mergeCtbInTile);
239}
240
241#if SVC_EXTENSION
242Void copyOnetoOnePicture(    // SVC_NONCOLL
243                  Pel *in,       
244                  Pel *out,     
245                  Int nCols,
246                  Int nRows, 
247                  Int fullRowWidth)
248{
249  Int rX;
250
251  for (rX = 0; rX < nRows; rX++)       
252  {
253    memcpy( out, in, sizeof(Pel) * nCols );
254    in = in + fullRowWidth;
255    out = out + fullRowWidth;
256  }
257}
258
259Void TComPic::copyUpsampledPictureYuv(TComPicYuv*   pcPicYuvIn, TComPicYuv*   pcPicYuvOut)
260{
261  Int upsampledRowWidthLuma = pcPicYuvOut->getStride(); // 2 * pcPicYuvOut->getLumaMargin() + pcPicYuvOut->getWidth();
262  Int upsampledRowWidthCroma = pcPicYuvOut->getCStride(); //2 * pcPicYuvOut->getChromaMargin() + (pcPicYuvOut->getWidth()>>1);
263
264  copyOnetoOnePicture(
265    pcPicYuvIn->getLumaAddr(),       
266    pcPicYuvOut->getLumaAddr(),     
267    pcPicYuvOut->getWidth(), 
268    pcPicYuvOut->getHeight(),
269    upsampledRowWidthLuma);
270  copyOnetoOnePicture(
271    pcPicYuvIn->getCrAddr(),       
272    pcPicYuvOut->getCrAddr(),     
273    pcPicYuvOut->getWidth()>>1, 
274    pcPicYuvOut->getHeight()>>1,
275    upsampledRowWidthCroma);
276  copyOnetoOnePicture(
277    pcPicYuvIn->getCbAddr(),       
278    pcPicYuvOut->getCbAddr(),     
279    pcPicYuvOut->getWidth()>>1, 
280    pcPicYuvOut->getHeight()>>1,
281    upsampledRowWidthCroma);
282}
283
284#if REF_IDX_MFM
285Void TComPic::copyUpsampledMvField(UInt refLayerIdc, TComPic* pcPicBase)
286{
287  UInt numPartitions = 1<<(g_uiMaxCUDepth<<1);
288  UInt widthMinPU    = g_uiMaxCUWidth/(1<<g_uiMaxCUDepth);
289  UInt heightMinPU   = g_uiMaxCUHeight/(1<<g_uiMaxCUDepth);
290  Int  unitNum       = max (1, (Int)((16/widthMinPU)*(16/heightMinPU)) ); 
291
292  for(UInt cuIdx = 0; cuIdx < getPicSym()->getNumberOfCUsInFrame(); cuIdx++)  //each LCU
293  {
294    TComDataCU* pcCUDes = getCU(cuIdx);
295
296    for(UInt absPartIdx = 0; absPartIdx < numPartitions; absPartIdx+=unitNum )  //each 16x16 unit
297    {
298      //pixel position of each unit in up-sampled layer
299      UInt  pelX = pcCUDes->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ];
300      UInt  pelY = pcCUDes->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ];
301      UInt baseCUAddr, baseAbsPartIdx;
302
303      TComDataCU *pcColCU = 0;
304      pcColCU = pcCUDes->getBaseColCU(refLayerIdc, pelX, pelY, baseCUAddr, baseAbsPartIdx, true);
305
306      if( pcColCU && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_NONE) && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
307      {
308        for(UInt refPicList = 0; refPicList < 2; refPicList++)  //for each reference list
309        {
310          TComMvField sMvFieldBase, sMvField;
311          pcColCU->getMvField( pcColCU, baseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase);
312          pcCUDes->scaleBaseMV( refLayerIdc, sMvField, sMvFieldBase );
313
314          pcCUDes->getCUMvField((RefPicList)refPicList)->setMvField(sMvField, absPartIdx);
315          pcCUDes->setPredictionMode(absPartIdx, MODE_INTER);
316        }
317      }
318      else
319      {
320        TComMvField zeroMvField;  //zero MV and invalid reference index
321        pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, absPartIdx);
322        pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, absPartIdx);
323        pcCUDes->setPredictionMode(absPartIdx, MODE_INTRA);
324      }
325
326      for(UInt i = 1; i < unitNum; i++ ) 
327      {
328        pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_0)->getMv(absPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_0)->getRefIdx(absPartIdx), absPartIdx + i);
329        pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_1)->getMv(absPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_1)->getRefIdx(absPartIdx), absPartIdx + i);
330        pcCUDes->setPredictionMode(absPartIdx+i, pcCUDes->getPredictionMode(absPartIdx));
331      }
332    }
333    memset( pcCUDes->getPartitionSize(), SIZE_2Nx2N, sizeof(Char)*numPartitions );
334  }
335}
336
337Void TComPic::initUpsampledMvField()
338{
339  UInt uiNumPartitions   = 1<<(g_uiMaxCUDepth<<1);
340
341  for(UInt cuIdx = 0; cuIdx < getPicSym()->getNumberOfCUsInFrame(); cuIdx++)  //each LCU
342  {
343    TComDataCU* pcCUDes = getCU(cuIdx);
344    TComMvField zeroMvField;
345    for(UInt list = 0; list < 2; list++)  //each reference list
346    {
347      for(UInt i = 0; i < uiNumPartitions; i++ ) 
348      {
349        pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, i);
350        pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, i);
351        pcCUDes->setPredictionMode(i, MODE_INTRA);
352        pcCUDes->setPartitionSize(i, SIZE_2Nx2N);
353      }
354    }
355  }
356  return;
357}
358#endif
359#endif
360
361#if MFM_ENCCONSTRAINT
362Bool TComPic::checkSameRefInfo()
363{
364  Bool bSameRefInfo = true;
365  TComSlice * pSlice0 = getSlice( 0 );
366  for( UInt uSliceID = getNumAllocatedSlice() - 1 ; bSameRefInfo && uSliceID > 0 ; uSliceID-- )
367  {
368    TComSlice * pSliceN = getSlice( uSliceID );
369    if( pSlice0->getSliceType() != pSliceN->getSliceType() )
370    {
371      bSameRefInfo = false;
372    }
373    else if( pSlice0->getSliceType() != I_SLICE )
374    {
375      Int nListNum = pSlice0->getSliceType() == B_SLICE ? 2 : 1;
376      for( Int nList = 0 ; nList < nListNum ; nList++ )
377      {
378        RefPicList eRefList = ( RefPicList )nList;
379        if( pSlice0->getNumRefIdx( eRefList ) == pSliceN->getNumRefIdx( eRefList ) )
380        {
381          for( Int refIdx = pSlice0->getNumRefIdx( eRefList ) - 1 ; refIdx >= 0 ; refIdx-- )
382          {
383            if( pSlice0->getRefPic( eRefList , refIdx ) != pSliceN->getRefPic( eRefList , refIdx ) )
384            {
385              bSameRefInfo = false;
386              break;
387            }
388          }
389        }
390        else
391        {
392          bSameRefInfo = false;
393          break;
394        }
395      }
396    }
397  }
398
399  return( bSameRefInfo ); 
400}
401#endif
402
403#if WPP_FIX
404UInt TComPic::getSubstreamForLCUAddr(const UInt uiLCUAddr, const Bool bAddressInRaster, TComSlice *pcSlice)
405{
406  const Int iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
407  UInt uiSubStrm;
408
409  if (iNumSubstreams > 1) // wavefronts, and possibly tiles being used.
410  {
411    TComPicSym &picSym=*(getPicSym());
412    const UInt uiLCUAddrRaster = bAddressInRaster?uiLCUAddr : picSym.getCUOrderMap(uiLCUAddr);
413    const UInt uiWidthInLCUs  = picSym.getFrameWidthInCU();
414    const UInt uiTileIndex=picSym.getTileIdxMap(uiLCUAddrRaster);
415    const UInt widthInTiles=(picSym.getNumColumnsMinus1()+1);
416    TComTile *pTile=picSym.getTComTile(uiTileIndex);
417    const UInt uiTileStartLCU = pTile->getFirstCUAddr();
418    const UInt uiTileLCUY = uiTileStartLCU / uiWidthInLCUs;
419    // independent tiles => substreams are "per tile".  iNumSubstreams has already been multiplied.
420    const UInt uiLin = uiLCUAddrRaster / uiWidthInLCUs;
421          UInt uiStartingSubstreamForTile=(uiTileLCUY*widthInTiles) + (pTile->getTileHeight()*(uiTileIndex%widthInTiles));
422    uiSubStrm = uiStartingSubstreamForTile + (uiLin-uiTileLCUY);
423  }
424  else
425  {
426    // dependent tiles => substreams are "per frame".
427    uiSubStrm = 0;//uiLin % iNumSubstreams; // x modulo 1 = 0 !
428  }
429  return uiSubStrm;
430}
431#endif
432
433
434//! \}
Note: See TracBrowser for help on using the repository browser.