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

Last change on this file since 1417 was 1256, checked in by liu, 10 years ago

-Integration of QTL

  • 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 NH_3D_QTLPC
78  m_bReduceBitsQTL    = 0;
79#endif
80#if H_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 H_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    return numDdvCandPics;
314
315  numDdvCandPics += 1;
316
317  UInt pocCurr = currSlice->getPOC();
318  UInt pocDiff = 255;
319
320  for(UInt lpNr = 0; lpNr < (currSlice->isInterB() ? 2: 1); lpNr ++)
321  {
322    UInt x = lpNr ? currSlice->getColFromL0Flag() : 1 - currSlice->getColFromL0Flag();
323
324    for (UInt i = 0; i < currSlice->getNumRefIdx(RefPicList(x)); i++)
325    {
326      if(currSlice->getViewIndex() == currSlice->getRefPic((RefPicList)x, i)->getViewIndex() 
327        && (x == currSlice->getColFromL0Flag()||currSlice->getRefPOC((RefPicList)x, i)!= iColPOC) && numDdvCandPics!=2)
328      {
329        TComSlice* refSlice    = currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx());
330        Bool       bRAP        = (refSlice->getViewIndex() && refSlice->isIRAP())? 1: 0; 
331        UInt       uiTempLayer = currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx())->getTLayer(); 
332       
333        if( bRAP )
334        {
335          this->setRapRefIdx(i);
336          this->setRapRefList((RefPicList)x);
337          numDdvCandPics = 2;
338
339          return numDdvCandPics;
340        }
341        else if (uiTempLayerCurr > uiTempLayer) 
342        {
343           uiTempLayerCurr = uiTempLayer; 
344        }
345      }
346    }
347  }
348
349  UInt z   = -1; // GT: Added to make code compile needs to be checked!
350  UInt idx = 0;
351 
352  for(UInt lpNr = 0; lpNr < (currSlice->isInterB() ? 2: 1); lpNr ++)
353  {
354    UInt x = lpNr? currSlice->getColFromL0Flag() : 1-currSlice->getColFromL0Flag();
355   
356    for (UInt i = 0; i < currSlice->getNumRefIdx(RefPicList(x)); i++)
357    {
358      Int iTempPoc = currSlice->getRefPic((RefPicList)x, i)->getPOC();
359      Int iTempDiff = (iTempPoc > pocCurr) ? (iTempPoc - pocCurr): (pocCurr - iTempPoc);
360     
361      if(currSlice->getViewIndex() == currSlice->getRefPic((RefPicList)x, i)->getViewIndex() &&  (x == currSlice->getColFromL0Flag()||currSlice->getRefPOC((RefPicList)x, i)!= iColPOC) 
362        && currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx())->getTLayer() == uiTempLayerCurr && pocDiff > iTempDiff)
363      {
364        pocDiff = iTempDiff;
365        z       = x;
366        idx     = i;
367      }
368    }
369  }
370
371  if( pocDiff < 255 )
372  {
373    this->setRapRefIdx(idx);
374    this->setRapRefList((RefPicList) z );
375    numDdvCandPics = 2;
376  }
377
378  return numDdvCandPics;
379}
380
381Void TComPic::checkTemporalIVRef()
382{
383  TComSlice* currSlice = getSlice(getCurrSliceIdx());
384  const Int numCandPics = this->getNumDdvCandPics();
385  for(Int curCandPic = 0; curCandPic < numCandPics; curCandPic++)
386  {
387    RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
388    Int        curCandPicRefIdx = 0;
389    if( curCandPic == 0 ) 
390    { 
391      eCurRefPicList   = RefPicList(currSlice->isInterB() ? 1-currSlice->getColFromL0Flag() : 0);
392      curCandPicRefIdx = currSlice->getColRefIdx();
393    }
394    else                 
395    {
396      eCurRefPicList   = this->getRapRefList();
397      curCandPicRefIdx = this->getRapRefIdx();
398    }
399    TComPic* pcCandColPic = currSlice->getRefPic( eCurRefPicList, curCandPicRefIdx);
400    TComSlice* pcCandColSlice = pcCandColPic->getSlice(0);// currently only support single slice
401
402    if(!pcCandColSlice->isIntra())
403    {
404      for( Int iColRefDir = 0; iColRefDir < (pcCandColSlice->isInterB() ? 2: 1); iColRefDir ++ )
405      {
406        for( Int iColRefIdx =0; iColRefIdx < pcCandColSlice->getNumRefIdx(( RefPicList )iColRefDir ); iColRefIdx++)
407        {
408          m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = false;
409          Int iColViewIdx    = pcCandColSlice->getViewIndex();
410          Int iColRefViewIdx = pcCandColSlice->getRefPic( ( RefPicList )iColRefDir, iColRefIdx)->getViewIndex();
411          if(iColViewIdx == iColRefViewIdx)
412            continue;
413
414          for(Int iCurrRefDir = 0;(iCurrRefDir < (currSlice->isInterB() ? 2: 1)) && (m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] == false ); iCurrRefDir++)
415          {
416            for( Int iCurrRefIdx =0; iCurrRefIdx < currSlice->getNumRefIdx(( RefPicList )iCurrRefDir ); iCurrRefIdx++)
417            {
418              if( currSlice->getRefPic( ( RefPicList )iCurrRefDir, iCurrRefIdx )->getViewIndex() == iColRefViewIdx )
419              { 
420                m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = true;
421                break;
422              }
423            }
424          }
425        }
426      }
427    }
428  }
429}
430Bool TComPic::isTempIVRefValid(Int currCandPic, Int iColRefDir, Int iColRefIdx)
431{
432  return m_abTIVRINCurrRL[currCandPic][iColRefDir][iColRefIdx];
433}
434
435Void TComPic::checkTextureRef(  )
436{
437  TComSlice* pcCurrSlice = getSlice(getCurrSliceIdx());
438  TComPic* pcTextPic = pcCurrSlice->getTexturePic();
439#if H_3D_FCO
440  if ( pcTextPic )
441  {
442#endif
443
444    TComSlice* pcTextSlice = pcTextPic->getSlice(0); // currently only support single slice
445
446    for( Int iTextRefDir = 0; (iTextRefDir < (pcTextSlice->isInterB()? 2:1) ) && !pcTextSlice->isIntra(); iTextRefDir ++ )
447    {
448      for( Int iTextRefIdx =0; iTextRefIdx<pcTextSlice->getNumRefIdx(( RefPicList )iTextRefDir ); iTextRefIdx++)
449      {
450        Int iTextRefPOC    = pcTextSlice->getRefPOC( ( RefPicList )iTextRefDir, iTextRefIdx);
451        Int iTextRefViewId = pcTextSlice->getRefPic( ( RefPicList )iTextRefDir, iTextRefIdx)->getViewIndex();
452        m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = -1;
453        Int iCurrRefDir = iTextRefDir;
454        for( Int iCurrRefIdx =0; ( iCurrRefIdx<pcCurrSlice->getNumRefIdx(( RefPicList )iCurrRefDir ) ) && ( m_aiTexToDepRef[iTextRefDir][iTextRefIdx] < 0 ) ; iCurrRefIdx++)
455        {
456          if( pcCurrSlice->getRefPOC( ( RefPicList )iCurrRefDir, iCurrRefIdx ) == iTextRefPOC && 
457            pcCurrSlice->getRefPic( ( RefPicList )iCurrRefDir, iCurrRefIdx)->getViewIndex() == iTextRefViewId )
458          { 
459            m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = iCurrRefIdx;
460          }
461        }
462      }
463
464    }
465#if H_3D_FCO
466  }
467#endif
468}
469
470Int TComPic::isTextRefValid(Int iTextRefDir, Int iTextRefIdx)
471{
472  return m_aiTexToDepRef[iTextRefDir][iTextRefIdx];
473}
474#endif
475
476
477//! \}
Note: See TracBrowser for help on using the repository browser.