source: 3DVCSoftware/branches/HTM-14.1-update-dev4-RWTH/source/Lib/TLibCommon/TComPic.cpp @ 1417

Last change on this file since 1417 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
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-2015, 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_pcPicYuvPred                          (NULL)
53, m_pcPicYuvResi                          (NULL)
54, m_bReconstructed                        (false)
55, m_bNeededForOutput                      (false)
56#if NH_MV
57, m_bPicOutputFlag                        (false)
58#endif
59, m_uiCurrSliceIdx                        (0)
60, m_bCheckLTMSB                           (false)
61#if NH_MV
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
71
72{
73  for(UInt i=0; i<NUM_PIC_YUV; i++)
74  {
75    m_apcPicYuv[i]      = NULL;
76  }
77#if H_3D_QTLPC
78  m_bReduceBitsQTL    = 0;
79#endif
80#if NH_3D_NBDV
81  m_iNumDdvCandPics   = 0;
82  m_eRapRefList       = REF_PIC_LIST_0;
83  m_uiRapRefIdx       = 0;
84#endif
85}
86
87TComPic::~TComPic()
88{
89}
90
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();
99
100  m_picSym.create( sps, pps, uiMaxDepth );
101  if (!bIsVirtual)
102  {
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 );
105  }
106  m_apcPicYuv[PIC_YUV_REC]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_REC]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
107
108  // there are no SEI messages associated with this picture initially
109  if (m_SEIs.size() > 0)
110  {
111    deleteSEIs (m_SEIs);
112  }
113  m_bUsedByCurr = false;
114
115#if H_3D_FCO
116/* initialize the texture to depth reference status */
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
126}
127
128Void TComPic::destroy()
129{
130  m_picSym.destroy();
131
132  for(UInt i=0; i<NUM_PIC_YUV; i++)
133  {
134    if (m_apcPicYuv[i])
135    {
136      m_apcPicYuv[i]->destroy();
137      delete m_apcPicYuv[i];
138      m_apcPicYuv[i]  = NULL;
139    }
140  }
141
142  deleteSEIs(m_SEIs);
143}
144#if NH_3D
145Void TComPic::compressMotion(Int scale)
146#else
147Void TComPic::compressMotion()
148#endif
149{
150  TComPicSym* pPicSym = getPicSym();
151  for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getNumberOfCtusInFrame(); uiCUAddr++ )
152  {
153    TComDataCU* pCtu = pPicSym->getCtu(uiCUAddr);
154#if NH_3D
155    pCtu->compressMV(scale); 
156#else
157    pCtu->compressMV();
158#endif
159   
160  }
161}
162
163Bool  TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr)
164{
165  Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCtuTsToRsAddrMap(getCtu(currAddr)->getSlice()->getSliceCurStartCtuTsAddr()));
166  Bool mergeCtbInTile     = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr));
167  return (mergeCtbInSliceSeg && mergeCtbInTile);
168}
169
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
208Void TComPic::print( Bool legend )
209{
210  if ( legend )
211    std::cout  << std::endl << "LId"        << "\t" << "POC"   << "\t" << "Rec"          << "\t" << "Ref"                       << "\t" << "LT"            <<  "\t" << "OutMark" <<  "\t" << "OutFlag" << std::endl;
212  else
213    std::cout  << getLayerId() << "\t" << getPOC()<< "\t" << getReconMark() << "\t" << getSlice(0)->isReferenced() << "\t" << getIsLongTerm() << "\t" << getOutputMark() << "\t" << getSlice(0)->getPicOutputFlag() <<std::endl;
214}
215
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}
232
233#if NH_3D
234TComPic* TComPicLists::getPic( Int viewIndex, Bool depthFlag, Int poc )
235{
236  return getPic   ( m_vps->getLayerIdInNuh( viewIndex, depthFlag ), poc );
237}
238#endif
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
279#if NH_3D
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
302#endif
303#endif // NH_MV
304
305#if NH_3D_NBDV
306Int TComPic::getDisCandRefPictures(Int iColPOC)
307{
308  UInt       uiTempLayerCurr = 7;
309  TComSlice* currSlice       = getSlice(getCurrSliceIdx());
310  UInt       numDdvCandPics  = 0;
311
312  if(!currSlice->getEnableTMVPFlag())
313  {
314    return numDdvCandPics;
315  }
316
317  numDdvCandPics += 1;
318
319  UInt pocCurr = currSlice->getPOC();
320  UInt pocDiff = 255;
321
322  for(UInt lpNr = 0; lpNr < (currSlice->isInterB() ? 2: 1); lpNr++)
323  {
324    Bool x = lpNr ? currSlice->getColFromL0Flag() : 1 - currSlice->getColFromL0Flag();
325
326    for(UInt i = 0; i < currSlice->getNumRefIdx(RefPicList(x)); i++)
327    {
328      if(currSlice->getViewIndex() == currSlice->getRefPic((RefPicList)x, i)->getViewIndex() 
329         && (x == currSlice->getColFromL0Flag() || currSlice->getRefPOC((RefPicList)x, i) != iColPOC) && numDdvCandPics != 2)
330      {
331        TComSlice* refSlice    = currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx());
332        Bool       bRAP        = (refSlice->getViewIndex() && refSlice->isIRAP()) ? 1 : 0; 
333        UInt       uiTempLayer = currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx())->getTLayer(); 
334       
335        if(bRAP)
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 
354  for(UInt lpNr = 0; lpNr < (currSlice->isInterB() ? 2 : 1); lpNr++)
355  {
356    Bool x = lpNr ? currSlice->getColFromL0Flag() : 1 - currSlice->getColFromL0Flag();
357   
358    for(UInt i = 0; i < currSlice->getNumRefIdx(RefPicList(x)); i++)
359    {
360      Int iTempPoc = currSlice->getRefPic((RefPicList)x, i)->getPOC();
361      Int iTempDiff = (iTempPoc > pocCurr) ? (iTempPoc - pocCurr) : (pocCurr - iTempPoc);
362     
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)
365      {
366        pocDiff = iTempDiff;
367        z       = x;
368        idx     = i;
369      }
370    }
371  }
372
373  if(pocDiff < 255)
374  {
375    this->setRapRefIdx(idx);
376    this->setRapRefList((RefPicList) z);
377    numDdvCandPics = 2;
378  }
379
380  return numDdvCandPics;
381}
382
383Void TComPic::checkTemporalIVRef()
384{
385  TComSlice* currSlice = getSlice(getCurrSliceIdx());
386  const Int numCandPics = this->getNumDdvCandPics();
387
388  for(Int curCandPic = 0; curCandPic < numCandPics; curCandPic++)
389  {
390    RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
391    Int        curCandPicRefIdx = 0;
392    if(curCandPic == 0) 
393    { 
394      eCurRefPicList   = RefPicList(currSlice->isInterB() ? 1 - currSlice->getColFromL0Flag() : 0);
395      curCandPicRefIdx = currSlice->getColRefIdx();
396    }
397    else                 
398    {
399      eCurRefPicList   = this->getRapRefList();
400      curCandPicRefIdx = this->getRapRefIdx();
401    }
402
403    TComPic* pcCandColPic = currSlice->getRefPic(eCurRefPicList, curCandPicRefIdx);
404    TComSlice* pcCandColSlice = pcCandColPic->getSlice(0); // currently only support single slice
405
406    if(!pcCandColSlice->isIntra())
407    {
408      for(Int iColRefDir = 0; iColRefDir < (pcCandColSlice->isInterB() ? 2 : 1); iColRefDir++)
409      {
410        for(Int iColRefIdx = 0; iColRefIdx < pcCandColSlice->getNumRefIdx((RefPicList)iColRefDir); iColRefIdx++)
411        {
412          m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = false;
413          Int iColViewIdx    = pcCandColSlice->getViewIndex();
414          Int iColRefViewIdx = pcCandColSlice->getRefPic((RefPicList)iColRefDir, iColRefIdx)->getViewIndex();
415          if(iColViewIdx == iColRefViewIdx)
416          {
417            continue;
418          }
419
420          for(Int iCurrRefDir = 0; (iCurrRefDir < (currSlice->isInterB() ? 2 : 1)) && (m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] == false); iCurrRefDir++)
421          {
422            for(Int iCurrRefIdx = 0; iCurrRefIdx < currSlice->getNumRefIdx((RefPicList)iCurrRefDir); iCurrRefIdx++)
423            {
424              if(currSlice->getRefPic((RefPicList)iCurrRefDir, iCurrRefIdx)->getViewIndex() == iColRefViewIdx)
425              { 
426                m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = true;
427                break;
428              }
429            }
430          }
431        }
432      }
433    }
434  }
435}
436
437Bool TComPic::isTempIVRefValid(Int currCandPic, Int iColRefDir, Int iColRefIdx)
438{
439  return m_abTIVRINCurrRL[currCandPic][iColRefDir][iColRefIdx];
440}
441
442Void TComPic::checkTextureRef()
443{
444  TComSlice* pcCurrSlice = getSlice(getCurrSliceIdx());
445  TComPic* pcTextPic = pcCurrSlice->getIvPic(0, getViewIndex());
446#if H_3D_FCO
447  if ( pcTextPic )
448  {
449#endif
450    TComSlice* pcTextSlice = pcTextPic->getSlice(0); // currently only support single slice
451
452    for(Int iTextRefDir = 0; (iTextRefDir < (pcTextSlice->isInterB() ? 2 :1) ) && !pcTextSlice->isIntra(); iTextRefDir++)
453    {
454      for(Int iTextRefIdx =0; iTextRefIdx < pcTextSlice->getNumRefIdx((RefPicList)iTextRefDir); iTextRefIdx++)
455      {
456        Int iTextRefPOC    = pcTextSlice->getRefPOC((RefPicList)iTextRefDir, iTextRefIdx);
457        Int iTextRefViewId = pcTextSlice->getRefPic((RefPicList)iTextRefDir, iTextRefIdx)->getViewIndex();
458        m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = -1;
459        Int iCurrRefDir = iTextRefDir;
460
461        for(Int iCurrRefIdx = 0; (iCurrRefIdx<pcCurrSlice->getNumRefIdx((RefPicList)iCurrRefDir)) && (m_aiTexToDepRef[iTextRefDir][iTextRefIdx] < 0); iCurrRefIdx++)
462        {
463          if(pcCurrSlice->getRefPOC((RefPicList)iCurrRefDir, iCurrRefIdx ) == iTextRefPOC && 
464             pcCurrSlice->getRefPic((RefPicList)iCurrRefDir, iCurrRefIdx)->getViewIndex() == iTextRefViewId)
465          { 
466            m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = iCurrRefIdx;
467          }
468        }
469      }
470    }
471#if H_3D_FCO
472  }
473#endif
474}
475
476Int TComPic::isTextRefValid(Int iTextRefDir, Int iTextRefIdx)
477{
478  return m_aiTexToDepRef[iTextRefDir][iTextRefIdx];
479}
480#endif
481
482
483//! \}
Note: See TracBrowser for help on using the repository browser.