source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibCommon/TComPic.cpp @ 1144

Last change on this file since 1144 was 1117, checked in by seregin, 9 years ago

macro cleanup: R0156_CONF_WINDOW_IN_REP_FORMAT

  • Property svn:eol-style set to native
File size: 14.7 KB
RevLine 
[313]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
[1029]4 * granted under this license.
[313]5 *
[595]6 * Copyright (c) 2010-2014, ITU/ISO/IEC
[313]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)
[595]58, m_bCheckLTMSB                           (false)
59#if SVC_EXTENSION
60, m_layerId( 0 )
[540]61#endif
[313]62{
63#if SVC_EXTENSION
64  memset( m_pcFullPelBaseRec, 0, sizeof( m_pcFullPelBaseRec ) );
65  memset( m_bSpatialEnhLayer, false, sizeof( m_bSpatialEnhLayer ) );
[901]66  memset( m_equalPictureSizeAndOffsetFlag, false, sizeof( m_equalPictureSizeAndOffsetFlag ) );
[313]67#endif
[1029]68  for(UInt i=0; i<NUM_PIC_YUV; i++)
69  {
70    m_apcPicYuv[i]      = NULL;
71  }
[313]72}
73
74TComPic::~TComPic()
75{
76}
[815]77#if SVC_EXTENSION
[494]78Void TComPic::create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
79                      Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual)
[313]80{
[1029]81  m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( chromaFormatIDC, iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
[313]82  if (!bIsVirtual)
83  {
[1029]84    m_apcPicYuv[PIC_YUV_ORG]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_ORG]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, &conformanceWindow );
85    m_apcPicYuv[PIC_YUV_TRUE_ORG]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_TRUE_ORG]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, &conformanceWindow );
[313]86  }
[1029]87  m_apcPicYuv[PIC_YUV_REC]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_REC]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, &conformanceWindow );
[313]88
89  for( Int i = 0; i < MAX_LAYERS; i++ )
90  {
91    if( m_bSpatialEnhLayer[i] )
92    {
[869]93      m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, &conformanceWindow );
[313]94    }
95  }
96
97  m_layerId = pcSps ? pcSps->getLayerId() : 0;
98
99  // there are no SEI messages associated with this picture initially
100  if (m_SEIs.size() > 0)
101  {
102    deleteSEIs (m_SEIs);
103  }
104  m_bUsedByCurr = false;
105
106  /* store conformance window parameters with picture */
107  m_conformanceWindow = conformanceWindow;
108 
109  /* store display window parameters with picture */
110  m_defaultDisplayWindow = defaultDisplayWindow;
111
112  /* store number of reorder pics with picture */
113  memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int));
114
115  return;
116}
117#else
[1029]118Void TComPic::create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
[313]119                      Int *numReorderPics, Bool bIsVirtual)
120{
[1029]121  m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( chromaFormatIDC, iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
[313]122  if (!bIsVirtual)
123  {
[1029]124    m_apcPicYuv[PIC_YUV_ORG]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_ORG]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth );
125    m_apcPicYuv[PIC_YUV_TRUE_ORG]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_TRUE_ORG]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth );
[313]126  }
[1029]127  m_apcPicYuv[PIC_YUV_REC]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_REC]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth );
128
[313]129  // there are no SEI messages associated with this picture initially
130  if (m_SEIs.size() > 0)
131  {
132    deleteSEIs (m_SEIs);
133  }
134  m_bUsedByCurr = false;
135
136  /* store conformance window parameters with picture */
137  m_conformanceWindow = conformanceWindow;
[1029]138
[313]139  /* store display window parameters with picture */
140  m_defaultDisplayWindow = defaultDisplayWindow;
141
142  /* store number of reorder pics with picture */
143  memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int));
144
145  return;
146}
147#endif
148
149Void TComPic::destroy()
150{
151  if (m_apcPicSym)
152  {
153    m_apcPicSym->destroy();
154    delete m_apcPicSym;
155    m_apcPicSym = NULL;
156  }
[1029]157
158  for(UInt i=0; i<NUM_PIC_YUV; i++)
[313]159  {
[1029]160    if (m_apcPicYuv[i])
161    {
162      m_apcPicYuv[i]->destroy();
163      delete m_apcPicYuv[i];
164      m_apcPicYuv[i]  = NULL;
165    }
[313]166  }
[1029]167
[313]168  deleteSEIs(m_SEIs);
[815]169#if SVC_EXTENSION
[313]170  for( Int i = 0; i < MAX_LAYERS; i++ )
171  {
[827]172    if( m_bSpatialEnhLayer[i] && m_pcFullPelBaseRec[i] )
[313]173    {
174      m_pcFullPelBaseRec[i]->destroy();
175      delete m_pcFullPelBaseRec[i];
176      m_pcFullPelBaseRec[i]  = NULL;
177    }
178  }
179#endif
180}
181
182Void TComPic::compressMotion()
183{
[1029]184  TComPicSym* pPicSym = getPicSym();
185  for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getNumberOfCtusInFrame(); uiCUAddr++ )
[313]186  {
[1029]187    TComDataCU* pCtu = pPicSym->getCtu(uiCUAddr);
188    pCtu->compressMV();
189  }
[313]190}
[595]191
[540]192Bool  TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr)
193{
[1029]194  Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCtuTsToRsAddrMap(getCtu(currAddr)->getSlice()->getSliceCurStartCtuTsAddr()));
[540]195  Bool mergeCtbInTile     = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr));
196  return (mergeCtbInSliceSeg && mergeCtbInTile);
197}
[313]198
[1029]199UInt TComPic::getSubstreamForCtuAddr(const UInt ctuAddr, const Bool bAddressInRaster, TComSlice *pcSlice)
200{
201  UInt subStrm;
202
203  if (pcSlice->getPPS()->getNumSubstreams() > 1) // wavefronts, and possibly tiles being used.
204  {
205    if (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag())
206    {
207      const TComPicSym &picSym            = *(getPicSym());
208      const UInt ctuRsAddr                = bAddressInRaster?ctuAddr : picSym.getCtuTsToRsAddrMap(ctuAddr);
209      const UInt frameWidthInCtus         = picSym.getFrameWidthInCtus();
210      const UInt tileIndex                = picSym.getTileIdxMap(ctuRsAddr);
211      const UInt numTileColumns           = (picSym.getNumTileColumnsMinus1()+1);
212      const TComTile *pTile               = picSym.getTComTile(tileIndex);
213      const UInt firstCtuRsAddrOfTile     = pTile->getFirstCtuRsAddr();
214      const UInt tileYInCtus              = firstCtuRsAddrOfTile / frameWidthInCtus;
215      // independent tiles => substreams are "per tile"
216      const UInt ctuLine                  = ctuRsAddr / frameWidthInCtus;
217      const UInt startingSubstreamForTile =(tileYInCtus*numTileColumns) + (pTile->getTileHeightInCtus()*(tileIndex%numTileColumns));
218      subStrm = startingSubstreamForTile + (ctuLine - tileYInCtus);
219    }
220    else
221    {
222      const TComPicSym &picSym            = *(getPicSym());
223      const UInt ctuRsAddr                = bAddressInRaster?ctuAddr : picSym.getCtuTsToRsAddrMap(ctuAddr);
224      const UInt tileIndex                = picSym.getTileIdxMap(ctuRsAddr);
225      subStrm=tileIndex;
226    }
227  }
228  else
229  {
230    // dependent tiles => substreams are "per frame".
231    subStrm = 0;
232  }
233  return subStrm;
234}
235
[442]236#if SVC_EXTENSION
[313]237Void copyOnetoOnePicture(    // SVC_NONCOLL
238                  Pel *in,       
239                  Pel *out,     
240                  Int nCols,
241                  Int nRows, 
242                  Int fullRowWidth)
243{
244  Int rX;
245
246  for (rX = 0; rX < nRows; rX++)       
247  {
248    memcpy( out, in, sizeof(Pel) * nCols );
249    in = in + fullRowWidth;
250    out = out + fullRowWidth;
251  }
252}
253
254Void TComPic::copyUpsampledPictureYuv(TComPicYuv*   pcPicYuvIn, TComPicYuv*   pcPicYuvOut)
255{
[1029]256  Int upsampledRowWidthLuma = pcPicYuvOut->getStride(COMPONENT_Y); // 2 * pcPicYuvOut->getLumaMargin() + pcPicYuvOut->getWidth();
257  Int upsampledRowWidthCroma = pcPicYuvOut->getStride(COMPONENT_Cb); //2 * pcPicYuvOut->getChromaMargin() + (pcPicYuvOut->getWidth()>>1);
[313]258
259  copyOnetoOnePicture(
[1029]260    pcPicYuvIn->getAddr(COMPONENT_Y),       
261    pcPicYuvOut->getAddr(COMPONENT_Y),     
262    pcPicYuvOut->getWidth(COMPONENT_Y), 
263    pcPicYuvOut->getHeight(COMPONENT_Y),
[313]264    upsampledRowWidthLuma);
265  copyOnetoOnePicture(
[1029]266    pcPicYuvIn->getAddr(COMPONENT_Cr),       
267    pcPicYuvOut->getAddr(COMPONENT_Cr),     
268    pcPicYuvOut->getWidth(COMPONENT_Y)>>1, 
269    pcPicYuvOut->getHeight(COMPONENT_Y)>>1,
[313]270    upsampledRowWidthCroma);
271  copyOnetoOnePicture(
[1029]272    pcPicYuvIn->getAddr(COMPONENT_Cb),       
273    pcPicYuvOut->getAddr(COMPONENT_Cb),     
274    pcPicYuvOut->getWidth(COMPONENT_Y)>>1, 
275    pcPicYuvOut->getHeight(COMPONENT_Y)>>1,
[313]276    upsampledRowWidthCroma);
277}
278
279#if REF_IDX_MFM
280Void TComPic::copyUpsampledMvField(UInt refLayerIdc, TComPic* pcPicBase)
281{
[822]282  UInt numPartitions = 1<<(g_uiMaxCUDepth<<1);
283  UInt widthMinPU    = g_uiMaxCUWidth/(1<<g_uiMaxCUDepth);
284  UInt heightMinPU   = g_uiMaxCUHeight/(1<<g_uiMaxCUDepth);
285  Int  unitNum       = max (1, (Int)((16/widthMinPU)*(16/heightMinPU)) ); 
[313]286
[1029]287  for(UInt cuIdx = 0; cuIdx < getPicSym()->getNumberOfCtusInFrame(); cuIdx++)  //each LCU
[313]288  {
[1029]289    TComDataCU* pcCUDes = getCtu(cuIdx);
[313]290
291    for(UInt absPartIdx = 0; absPartIdx < numPartitions; absPartIdx+=unitNum )  //each 16x16 unit
292    {
293      //pixel position of each unit in up-sampled layer
294      UInt  pelX = pcCUDes->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ];
295      UInt  pelY = pcCUDes->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ];
296      UInt baseCUAddr, baseAbsPartIdx;
297
298      TComDataCU *pcColCU = 0;
[822]299      pcColCU = pcCUDes->getBaseColCU(refLayerIdc, pelX, pelY, baseCUAddr, baseAbsPartIdx, true);
[313]300
[1029]301      if( pcColCU && pcColCU->getPredictionMode(baseAbsPartIdx) == MODE_INTER )  //base layer unit not skip and invalid mode
[313]302      {
303        for(UInt refPicList = 0; refPicList < 2; refPicList++)  //for each reference list
304        {
305          TComMvField sMvFieldBase, sMvField;
306          pcColCU->getMvField( pcColCU, baseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase);
307          pcCUDes->scaleBaseMV( refLayerIdc, sMvField, sMvFieldBase );
308
309          pcCUDes->getCUMvField((RefPicList)refPicList)->setMvField(sMvField, absPartIdx);
310          pcCUDes->setPredictionMode(absPartIdx, MODE_INTER);
311        }
312      }
313      else
314      {
315        TComMvField zeroMvField;  //zero MV and invalid reference index
316        pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, absPartIdx);
317        pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, absPartIdx);
318        pcCUDes->setPredictionMode(absPartIdx, MODE_INTRA);
319      }
320
321      for(UInt i = 1; i < unitNum; i++ ) 
322      {
323        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);
324        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);
325        pcCUDes->setPredictionMode(absPartIdx+i, pcCUDes->getPredictionMode(absPartIdx));
326      }
327    }
[822]328    memset( pcCUDes->getPartitionSize(), SIZE_2Nx2N, sizeof(Char)*numPartitions );
[313]329  }
330}
331
332Void TComPic::initUpsampledMvField()
333{
334  UInt uiNumPartitions   = 1<<(g_uiMaxCUDepth<<1);
335
[1029]336  for(UInt cuIdx = 0; cuIdx < getPicSym()->getNumberOfCtusInFrame(); cuIdx++)  //each LCU
[313]337  {
[1029]338    TComDataCU* pcCUDes = getCtu(cuIdx);
[313]339    TComMvField zeroMvField;
340    for(UInt list = 0; list < 2; list++)  //each reference list
341    {
342      for(UInt i = 0; i < uiNumPartitions; i++ ) 
343      {
344        pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, i);
345        pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, i);
346        pcCUDes->setPredictionMode(i, MODE_INTRA);
347        pcCUDes->setPartitionSize(i, SIZE_2Nx2N);
348      }
349    }
350  }
351  return;
352}
353#endif
354
[494]355#if MFM_ENCCONSTRAINT
356Bool TComPic::checkSameRefInfo()
357{
358  Bool bSameRefInfo = true;
359  TComSlice * pSlice0 = getSlice( 0 );
360  for( UInt uSliceID = getNumAllocatedSlice() - 1 ; bSameRefInfo && uSliceID > 0 ; uSliceID-- )
361  {
362    TComSlice * pSliceN = getSlice( uSliceID );
363    if( pSlice0->getSliceType() != pSliceN->getSliceType() )
364    {
365      bSameRefInfo = false;
366    }
367    else if( pSlice0->getSliceType() != I_SLICE )
368    {
369      Int nListNum = pSlice0->getSliceType() == B_SLICE ? 2 : 1;
370      for( Int nList = 0 ; nList < nListNum ; nList++ )
371      {
372        RefPicList eRefList = ( RefPicList )nList;
373        if( pSlice0->getNumRefIdx( eRefList ) == pSliceN->getNumRefIdx( eRefList ) )
374        {
375          for( Int refIdx = pSlice0->getNumRefIdx( eRefList ) - 1 ; refIdx >= 0 ; refIdx-- )
376          {
377            if( pSlice0->getRefPic( eRefList , refIdx ) != pSliceN->getRefPic( eRefList , refIdx ) )
378            {
379              bSameRefInfo = false;
380              break;
381            }
382          }
383        }
384        else
385        {
386          bSameRefInfo = false;
387          break;
388        }
389      }
390    }
391  }
[313]392
[494]393  return( bSameRefInfo ); 
394}
395#endif
[1029]396#endif //SVC_EXTENSION
[494]397
[313]398//! \}
Note: See TracBrowser for help on using the repository browser.