source: 3DVCSoftware/branches/HTM-14.1-update-dev3-Samsung-Qualcomm/source/Lib/TLibCommon/TComPic.cpp @ 1360

Last change on this file since 1360 was 1210, checked in by samsung-htm, 10 years ago

Alignment and reactivation of NBDV

  • new macro NH_3D_NBDV for NBDV
  • Property svn:eol-style set to native
File size: 15.8 KB
RevLine 
[5]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
[1200]4 * granted under this license.
[5]5 *
[1200]6 * Copyright (c) 2010-2015, ITU/ISO/IEC
[5]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.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]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 */
[2]33
34/** \file     TComPic.cpp
35    \brief    picture class
36*/
37
38#include "TComPic.h"
39#include "SEI.h"
40
[56]41//! \ingroup TLibCommon
42//! \{
43
[2]44// ====================================================================================================================
45// Constructor / destructor / create / destroy
46// ====================================================================================================================
47
48TComPic::TComPic()
[608]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)
[1200]56#if NH_MV
[964]57, m_bPicOutputFlag                        (false)
58#endif
[608]59, m_uiCurrSliceIdx                        (0)
60, m_bCheckLTMSB                           (false)
[1200]61#if NH_MV
[608]62, m_layerId                               (0)
63, m_viewId                                (0)
64#if H_3D
65, m_viewIndex                             (0)
66, m_isDepth                               (false)
67, m_aaiCodedScale                         (0)
68, m_aaiCodedOffset                        (0)
69#endif
70#endif
[1200]71
[2]72{
[1200]73  for(UInt i=0; i<NUM_PIC_YUV; i++)
74  {
75    m_apcPicYuv[i]      = NULL;
76  }
[608]77#if H_3D_QTLPC
[189]78  m_bReduceBitsQTL    = 0;
79#endif
[1210]80#if NH_3D_NBDV
[608]81  m_iNumDdvCandPics   = 0;
82  m_eRapRefList       = REF_PIC_LIST_0;
83  m_uiRapRefIdx       = 0;
[189]84#endif
[2]85}
86
87TComPic::~TComPic()
88{
89}
90
[1200]91Void TComPic::create( const TComSPS &sps, const TComPPS &pps, const Bool bIsVirtual)
92{
93  const ChromaFormat chromaFormatIDC = sps.getChromaFormatIdc();
94  const Int          iWidth          = sps.getPicWidthInLumaSamples();
95  const Int          iHeight         = sps.getPicHeightInLumaSamples();
96  const UInt         uiMaxCuWidth    = sps.getMaxCUWidth();
97  const UInt         uiMaxCuHeight   = sps.getMaxCUHeight();
98  const UInt         uiMaxDepth      = sps.getMaxTotalCUDepth();
[608]99
[1200]100  m_picSym.create( sps, pps, uiMaxDepth );
[56]101  if (!bIsVirtual)
102  {
[1200]103    m_apcPicYuv[PIC_YUV_ORG    ]   = new TComPicYuv;  m_apcPicYuv[PIC_YUV_ORG     ]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
104    m_apcPicYuv[PIC_YUV_TRUE_ORG]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_TRUE_ORG]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
[56]105  }
[1200]106  m_apcPicYuv[PIC_YUV_REC]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_REC]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
107
[608]108  // there are no SEI messages associated with this picture initially
109  if (m_SEIs.size() > 0)
110  {
111    deleteSEIs (m_SEIs);
112  }
[56]113  m_bUsedByCurr = false;
[608]114
[655]115#if H_3D_FCO
[872]116/* initialize the texture to depth reference status */
[655]117  for (int j=0; j<2; j++)
118  {
119      for (int i=0; i<MAX_NUM_REF; i++)
120      {
121          m_aiTexToDepRef[j][i] = -1;
122      }
123  }
124#endif
125
[2]126}
127
128Void TComPic::destroy()
129{
[1200]130  m_picSym.destroy();
131
132  for(UInt i=0; i<NUM_PIC_YUV; i++)
[2]133  {
[1200]134    if (m_apcPicYuv[i])
135    {
136      m_apcPicYuv[i]->destroy();
137      delete m_apcPicYuv[i];
138      m_apcPicYuv[i]  = NULL;
139    }
[2]140  }
[1200]141
[608]142  deleteSEIs(m_SEIs);
[2]143}
[1200]144#if NH_3D
[655]145Void TComPic::compressMotion(Int scale)
[608]146#else
[2]147Void TComPic::compressMotion()
[608]148#endif
[2]149{
[1200]150  TComPicSym* pPicSym = getPicSym();
151  for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getNumberOfCtusInFrame(); uiCUAddr++ )
[2]152  {
[1200]153    TComDataCU* pCtu = pPicSym->getCtu(uiCUAddr);
154#if NH_3D
155    pCtu->compressMV(scale); 
[608]156#else
[1200]157    pCtu->compressMV();
[608]158#endif
[1200]159   
160  }
[2]161}
162
[872]163Bool  TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr)
[56]164{
[1200]165  Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCtuTsToRsAddrMap(getCtu(currAddr)->getSlice()->getSliceCurStartCtuTsAddr()));
[872]166  Bool mergeCtbInTile     = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr));
167  return (mergeCtbInSliceSeg && mergeCtbInTile);
[56]168}
[2]169
[1200]170UInt TComPic::getSubstreamForCtuAddr(const UInt ctuAddr, const Bool bAddressInRaster, TComSlice *pcSlice)
171{
172  UInt subStrm;
173  const bool bWPPEnabled=pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag();
174  const TComPicSym &picSym            = *(getPicSym());
175
176  if ((bWPPEnabled && picSym.getFrameHeightInCtus()>1) || (picSym.getNumTiles()>1)) // wavefronts, and possibly tiles being used.
177  {
178    if (bWPPEnabled)
179    {
180      const UInt ctuRsAddr                = bAddressInRaster?ctuAddr : picSym.getCtuTsToRsAddrMap(ctuAddr);
181      const UInt frameWidthInCtus         = picSym.getFrameWidthInCtus();
182      const UInt tileIndex                = picSym.getTileIdxMap(ctuRsAddr);
183      const UInt numTileColumns           = (picSym.getNumTileColumnsMinus1()+1);
184      const TComTile *pTile               = picSym.getTComTile(tileIndex);
185      const UInt firstCtuRsAddrOfTile     = pTile->getFirstCtuRsAddr();
186      const UInt tileYInCtus              = firstCtuRsAddrOfTile / frameWidthInCtus;
187      // independent tiles => substreams are "per tile"
188      const UInt ctuLine                  = ctuRsAddr / frameWidthInCtus;
189      const UInt startingSubstreamForTile =(tileYInCtus*numTileColumns) + (pTile->getTileHeightInCtus()*(tileIndex%numTileColumns));
190      subStrm = startingSubstreamForTile + (ctuLine - tileYInCtus);
191    }
192    else
193    {
194      const UInt ctuRsAddr                = bAddressInRaster?ctuAddr : picSym.getCtuTsToRsAddrMap(ctuAddr);
195      const UInt tileIndex                = picSym.getTileIdxMap(ctuRsAddr);
196      subStrm=tileIndex;
197    }
198  }
199  else
200  {
201    // dependent tiles => substreams are "per frame".
202    subStrm = 0;
203  }
204  return subStrm;
205}
206
207#if NH_MV
[608]208Void TComPic::print( Bool legend )
209{
210  if ( legend )
[738]211    std::cout  << std::endl << "LId"        << "\t" << "POC"   << "\t" << "Rec"          << "\t" << "Ref"                       << "\t" << "LT"            <<  "\t" << "OutMark" <<  "\t" << "OutFlag" << std::endl;
[608]212  else
[738]213    std::cout  << getLayerId() << "\t" << getPOC()<< "\t" << getReconMark() << "\t" << getSlice(0)->isReferenced() << "\t" << getIsLongTerm() << "\t" << getOutputMark() << "\t" << getSlice(0)->getPicOutputFlag() <<std::endl;
[608]214}
[56]215
[608]216TComPic* TComPicLists::getPic( Int layerIdInNuh, Int poc )
217{
218  TComPic* pcPic = NULL;
219  for(TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin(); ( itL != m_lists.end() && pcPic == NULL ); itL++)
220  {   
221    for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() && pcPic == NULL ); itP++)
222    {
223      TComPic* currPic = (*itP); 
224      if ( ( currPic->getPOC() == poc ) && ( currPic->getLayerId() == layerIdInNuh ) )
225      {
226        pcPic = currPic ;     
227      }
228    }
229  }
230  return pcPic;
231}
[56]232
[1200]233#if NH_3D
[608]234TComPic* TComPicLists::getPic( Int viewIndex, Bool depthFlag, Int poc )
235{
236  return getPic   ( m_vps->getLayerIdInNuh( viewIndex, depthFlag ), poc );
237}
[738]238#endif
[608]239Void TComPicLists::print()
240{
241  Bool first = true;     
242  for(TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin(); ( itL != m_lists.end() ); itL++)
243  {   
244    for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() ); itP++)
245    {
246      if ( first )
247      {
248        (*itP)->print( true );       
249        first = false; 
250      }
251      (*itP)->print( false );       
252    }
253  }
254}
255
256TComPicYuv* TComPicLists::getPicYuv( Int layerIdInNuh, Int poc, Bool reconFlag )
257{
258  TComPic*    pcPic = getPic( layerIdInNuh, poc );
259  TComPicYuv* pcPicYuv = NULL;
260
261  if (pcPic != NULL)
262  {
263    if( reconFlag )
264    {
265      if ( pcPic->getReconMark() )
266      {
267        pcPicYuv = pcPic->getPicYuvRec();
268      }
269    }
270    else
271    {
272      pcPicYuv = pcPic->getPicYuvOrg();
273    }
274  };
275
276  return pcPicYuv;
277}
278
[1200]279#if NH_3D
[608]280TComPicYuv* TComPicLists::getPicYuv( Int viewIndex, Bool depthFlag, Int poc, Bool recon )
281{ 
282  Int layerIdInNuh = m_vps->getLayerIdInNuh( viewIndex, depthFlag ); 
283  return getPicYuv( layerIdInNuh, poc, recon );
284}
285#if H_3D_ARP
286TComList<TComPic*>* TComPicLists::getPicList( Int layerIdInNuh )
287{
288  TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin();
289  Int iLayer = 0;
290
291  assert( layerIdInNuh < m_lists.size() );
292
293  while( iLayer != layerIdInNuh )
294  {
295    itL++;
296    iLayer++;
297  }
298
299  return *itL;
300}
301#endif
[738]302#endif
[1200]303#endif // NH_MV
[608]304
[1210]305#if NH_3D_NBDV
306Int TComPic::getDisCandRefPictures(Int iColPOC)
[608]307{
308  UInt       uiTempLayerCurr = 7;
309  TComSlice* currSlice       = getSlice(getCurrSliceIdx());
310  UInt       numDdvCandPics  = 0;
311
[1210]312  if(!currSlice->getEnableTMVPFlag())
313  {
[608]314    return numDdvCandPics;
[1210]315  }
[608]316
317  numDdvCandPics += 1;
318
319  UInt pocCurr = currSlice->getPOC();
320  UInt pocDiff = 255;
321
[1210]322  for(UInt lpNr = 0; lpNr < (currSlice->isInterB() ? 2: 1); lpNr++)
[608]323  {
[1210]324    Bool x = lpNr ? currSlice->getColFromL0Flag() : 1 - currSlice->getColFromL0Flag();
[608]325
[1210]326    for(UInt i = 0; i < currSlice->getNumRefIdx(RefPicList(x)); i++)
[608]327    {
328      if(currSlice->getViewIndex() == currSlice->getRefPic((RefPicList)x, i)->getViewIndex() 
[1210]329         && (x == currSlice->getColFromL0Flag() || currSlice->getRefPOC((RefPicList)x, i) != iColPOC) && numDdvCandPics != 2)
[608]330      {
331        TComSlice* refSlice    = currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx());
[1210]332        Bool       bRAP        = (refSlice->getViewIndex() && refSlice->isIRAP()) ? 1 : 0; 
[608]333        UInt       uiTempLayer = currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx())->getTLayer(); 
334       
[1210]335        if(bRAP)
[608]336        {
337          this->setRapRefIdx(i);
338          this->setRapRefList((RefPicList)x);
339          numDdvCandPics = 2;
340
341          return numDdvCandPics;
342        }
343        else if (uiTempLayerCurr > uiTempLayer) 
344        {
345           uiTempLayerCurr = uiTempLayer; 
346        }
347      }
348    }
349  }
350
351  UInt z   = -1; // GT: Added to make code compile needs to be checked!
352  UInt idx = 0;
353 
[1210]354  for(UInt lpNr = 0; lpNr < (currSlice->isInterB() ? 2 : 1); lpNr++)
[608]355  {
[1210]356    Bool x = lpNr ? currSlice->getColFromL0Flag() : 1 - currSlice->getColFromL0Flag();
[608]357   
[1210]358    for(UInt i = 0; i < currSlice->getNumRefIdx(RefPicList(x)); i++)
[608]359    {
360      Int iTempPoc = currSlice->getRefPic((RefPicList)x, i)->getPOC();
[1210]361      Int iTempDiff = (iTempPoc > pocCurr) ? (iTempPoc - pocCurr) : (pocCurr - iTempPoc);
[608]362     
[1210]363      if(currSlice->getViewIndex() == currSlice->getRefPic((RefPicList)x, i)->getViewIndex() && (x == currSlice->getColFromL0Flag() || currSlice->getRefPOC((RefPicList)x, i) != iColPOC) 
364         && currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx())->getTLayer() == uiTempLayerCurr && pocDiff > iTempDiff)
[608]365      {
366        pocDiff = iTempDiff;
367        z       = x;
368        idx     = i;
369      }
370    }
371  }
372
[1210]373  if(pocDiff < 255)
[608]374  {
375    this->setRapRefIdx(idx);
[1210]376    this->setRapRefList((RefPicList) z);
[608]377    numDdvCandPics = 2;
378  }
379
380  return numDdvCandPics;
381}
[655]382
[608]383Void TComPic::checkTemporalIVRef()
384{
385  TComSlice* currSlice = getSlice(getCurrSliceIdx());
386  const Int numCandPics = this->getNumDdvCandPics();
[1210]387
[608]388  for(Int curCandPic = 0; curCandPic < numCandPics; curCandPic++)
389  {
390    RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
391    Int        curCandPicRefIdx = 0;
[1210]392    if(curCandPic == 0) 
[608]393    { 
[1210]394      eCurRefPicList   = RefPicList(currSlice->isInterB() ? 1 - currSlice->getColFromL0Flag() : 0);
[608]395      curCandPicRefIdx = currSlice->getColRefIdx();
396    }
397    else                 
398    {
399      eCurRefPicList   = this->getRapRefList();
400      curCandPicRefIdx = this->getRapRefIdx();
401    }
402
[1210]403    TComPic* pcCandColPic = currSlice->getRefPic(eCurRefPicList, curCandPicRefIdx);
404    TComSlice* pcCandColSlice = pcCandColPic->getSlice(0); // currently only support single slice
405
[608]406    if(!pcCandColSlice->isIntra())
407    {
[1210]408      for(Int iColRefDir = 0; iColRefDir < (pcCandColSlice->isInterB() ? 2 : 1); iColRefDir++)
[608]409      {
[1210]410        for(Int iColRefIdx = 0; iColRefIdx < pcCandColSlice->getNumRefIdx((RefPicList)iColRefDir); iColRefIdx++)
[608]411        {
412          m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = false;
413          Int iColViewIdx    = pcCandColSlice->getViewIndex();
[1210]414          Int iColRefViewIdx = pcCandColSlice->getRefPic((RefPicList)iColRefDir, iColRefIdx)->getViewIndex();
[608]415          if(iColViewIdx == iColRefViewIdx)
[1210]416          {
[608]417            continue;
[1210]418          }
[608]419
[1210]420          for(Int iCurrRefDir = 0; (iCurrRefDir < (currSlice->isInterB() ? 2 : 1)) && (m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] == false); iCurrRefDir++)
[608]421          {
[1210]422            for(Int iCurrRefIdx = 0; iCurrRefIdx < currSlice->getNumRefIdx((RefPicList)iCurrRefDir); iCurrRefIdx++)
[608]423            {
[1210]424              if(currSlice->getRefPic((RefPicList)iCurrRefDir, iCurrRefIdx)->getViewIndex() == iColRefViewIdx)
[608]425              { 
426                m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = true;
427                break;
428              }
429            }
430          }
431        }
432      }
433    }
434  }
435}
[1210]436
[608]437Bool TComPic::isTempIVRefValid(Int currCandPic, Int iColRefDir, Int iColRefIdx)
438{
439  return m_abTIVRINCurrRL[currCandPic][iColRefDir][iColRefIdx];
440}
[655]441
[1210]442Void TComPic::checkTextureRef()
[608]443{
444  TComSlice* pcCurrSlice = getSlice(getCurrSliceIdx());
[1210]445  TComPic* pcTextPic = pcCurrSlice->getIvPic(0, getViewIndex());
[655]446#if H_3D_FCO
447  if ( pcTextPic )
448  {
449#endif
[1200]450    TComSlice* pcTextSlice = pcTextPic->getSlice(0); // currently only support single slice
[608]451
[1210]452    for(Int iTextRefDir = 0; (iTextRefDir < (pcTextSlice->isInterB() ? 2 :1) ) && !pcTextSlice->isIntra(); iTextRefDir++)
[608]453    {
[1210]454      for(Int iTextRefIdx =0; iTextRefIdx < pcTextSlice->getNumRefIdx((RefPicList)iTextRefDir); iTextRefIdx++)
[608]455      {
[1210]456        Int iTextRefPOC    = pcTextSlice->getRefPOC((RefPicList)iTextRefDir, iTextRefIdx);
457        Int iTextRefViewId = pcTextSlice->getRefPic((RefPicList)iTextRefDir, iTextRefIdx)->getViewIndex();
[1200]458        m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = -1;
459        Int iCurrRefDir = iTextRefDir;
[1210]460
461        for(Int iCurrRefIdx = 0; (iCurrRefIdx<pcCurrSlice->getNumRefIdx((RefPicList)iCurrRefDir)) && (m_aiTexToDepRef[iTextRefDir][iTextRefIdx] < 0); iCurrRefIdx++)
[1200]462        {
[1210]463          if(pcCurrSlice->getRefPOC((RefPicList)iCurrRefDir, iCurrRefIdx ) == iTextRefPOC && 
464             pcCurrSlice->getRefPic((RefPicList)iCurrRefDir, iCurrRefIdx)->getViewIndex() == iTextRefViewId)
[1200]465          { 
466            m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = iCurrRefIdx;
467          }
[608]468        }
469      }
470    }
[655]471#if H_3D_FCO
472  }
473#endif
[608]474}
475
476Int TComPic::isTextRefValid(Int iTextRefDir, Int iTextRefIdx)
477{
478  return m_aiTexToDepRef[iTextRefDir][iTextRefIdx];
479}
480#endif
[1200]481
482
[56]483//! \}
Note: See TracBrowser for help on using the repository browser.