source: 3DVCSoftware/branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComPic.cpp @ 1417

Last change on this file since 1417 was 852, checked in by tech, 11 years ago

Update HM-12.0 -> HM-13.0.

  • Property svn:eol-style set to native
File size: 14.1 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 H_MV
60, m_layerId                               (0)
61, m_viewId                                (0)
62#if H_3D
63, m_viewIndex                             (0)
64, m_isDepth                               (false)
65, m_aaiCodedScale                         (0)
66, m_aaiCodedOffset                        (0)
67#endif
68#endif
69{
70  m_apcPicYuv[0]      = NULL;
71  m_apcPicYuv[1]      = NULL;
72#if H_3D_QTLPC
73  m_bReduceBitsQTL    = 0;
74#endif
75#if H_3D_NBDV
76  m_iNumDdvCandPics   = 0;
77  m_eRapRefList       = REF_PIC_LIST_0;
78  m_uiRapRefIdx       = 0;
79#endif
80}
81
82TComPic::~TComPic()
83{
84}
85
86Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
87                      Int *numReorderPics, Bool bIsVirtual)
88
89{
90  m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
91  if (!bIsVirtual)
92  {
93    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
94  }
95  m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
96 
97  // there are no SEI messages associated with this picture initially
98  if (m_SEIs.size() > 0)
99  {
100    deleteSEIs (m_SEIs);
101  }
102  m_bUsedByCurr = false;
103
104  /* store conformance window parameters with picture */
105  m_conformanceWindow = conformanceWindow;
106 
107  /* store display window parameters with picture */
108  m_defaultDisplayWindow = defaultDisplayWindow;
109
110  /* store number of reorder pics with picture */
111  memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int));
112
113#if H_3D_FCO
114/* initialize the texture to depth reference status */
115  for (int j=0; j<2; j++)
116  {
117      for (int i=0; i<MAX_NUM_REF; i++)
118      {
119          m_aiTexToDepRef[j][i] = -1;
120      }
121  }
122#endif
123
124  return;
125}
126
127Void TComPic::destroy()
128{
129  if (m_apcPicSym)
130  {
131    m_apcPicSym->destroy();
132    delete m_apcPicSym;
133    m_apcPicSym = NULL;
134  }
135 
136  if (m_apcPicYuv[0])
137  {
138    m_apcPicYuv[0]->destroy();
139    delete m_apcPicYuv[0];
140    m_apcPicYuv[0]  = NULL;
141  }
142 
143  if (m_apcPicYuv[1])
144  {
145    m_apcPicYuv[1]->destroy();
146    delete m_apcPicYuv[1];
147    m_apcPicYuv[1]  = NULL;
148  }
149 
150  deleteSEIs(m_SEIs);
151}
152#if H_3D
153Void TComPic::compressMotion(Int scale)
154#else
155Void TComPic::compressMotion()
156#endif
157{
158  TComPicSym* pPicSym = getPicSym(); 
159  for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getFrameHeightInCU()*pPicSym->getFrameWidthInCU(); uiCUAddr++ )
160  {
161    TComDataCU* pcCU = pPicSym->getCU(uiCUAddr);
162#if H_3D
163    pcCU->compressMV(scale); 
164#else
165    pcCU->compressMV(); 
166#endif
167  } 
168}
169
170Bool  TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr)
171{
172  Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCUOrderMap(getCU(currAddr)->getSlice()->getSliceCurStartCUAddr()/getNumPartInCU()));
173  Bool mergeCtbInTile     = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr));
174  return (mergeCtbInSliceSeg && mergeCtbInTile);
175}
176
177#if H_MV
178Void TComPic::print( Bool legend )
179{
180  if ( legend )
181    std::cout  << std::endl << "LId"        << "\t" << "POC"   << "\t" << "Rec"          << "\t" << "Ref"                       << "\t" << "LT"            <<  "\t" << "OutMark" <<  "\t" << "OutFlag" << std::endl;
182  else
183    std::cout  << getLayerId() << "\t" << getPOC()<< "\t" << getReconMark() << "\t" << getSlice(0)->isReferenced() << "\t" << getIsLongTerm() << "\t" << getOutputMark() << "\t" << getSlice(0)->getPicOutputFlag() <<std::endl;
184}
185
186TComPic* TComPicLists::getPic( Int layerIdInNuh, Int poc )
187{
188  TComPic* pcPic = NULL;
189  for(TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin(); ( itL != m_lists.end() && pcPic == NULL ); itL++)
190  {   
191    for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() && pcPic == NULL ); itP++)
192    {
193      TComPic* currPic = (*itP); 
194      if ( ( currPic->getPOC() == poc ) && ( currPic->getLayerId() == layerIdInNuh ) )
195      {
196        pcPic = currPic ;     
197      }
198    }
199  }
200  return pcPic;
201}
202
203#if H_3D
204TComPic* TComPicLists::getPic( Int viewIndex, Bool depthFlag, Int poc )
205{
206  return getPic   ( m_vps->getLayerIdInNuh( viewIndex, depthFlag ), poc );
207}
208#endif
209Void TComPicLists::print()
210{
211  Bool first = true;     
212  for(TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin(); ( itL != m_lists.end() ); itL++)
213  {   
214    for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() ); itP++)
215    {
216      if ( first )
217      {
218        (*itP)->print( true );       
219        first = false; 
220      }
221      (*itP)->print( false );       
222    }
223  }
224}
225
226TComPicYuv* TComPicLists::getPicYuv( Int layerIdInNuh, Int poc, Bool reconFlag )
227{
228  TComPic*    pcPic = getPic( layerIdInNuh, poc );
229  TComPicYuv* pcPicYuv = NULL;
230
231  if (pcPic != NULL)
232  {
233    if( reconFlag )
234    {
235      if ( pcPic->getReconMark() )
236      {
237        pcPicYuv = pcPic->getPicYuvRec();
238      }
239    }
240    else
241    {
242      pcPicYuv = pcPic->getPicYuvOrg();
243    }
244  };
245
246  return pcPicYuv;
247}
248
249#if H_3D
250TComPicYuv* TComPicLists::getPicYuv( Int viewIndex, Bool depthFlag, Int poc, Bool recon )
251{ 
252  Int layerIdInNuh = m_vps->getLayerIdInNuh( viewIndex, depthFlag ); 
253  return getPicYuv( layerIdInNuh, poc, recon );
254}
255#if H_3D_ARP
256TComList<TComPic*>* TComPicLists::getPicList( Int layerIdInNuh )
257{
258  TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin();
259  Int iLayer = 0;
260
261  assert( layerIdInNuh < m_lists.size() );
262
263  while( iLayer != layerIdInNuh )
264  {
265    itL++;
266    iLayer++;
267  }
268
269  return *itL;
270}
271#endif
272#endif
273#endif // H_MV
274
275#if H_3D_NBDV
276Int TComPic::getDisCandRefPictures( Int iColPOC )
277{
278  UInt       uiTempLayerCurr = 7;
279  TComSlice* currSlice       = getSlice(getCurrSliceIdx());
280  UInt       numDdvCandPics  = 0;
281
282  if ( !currSlice->getEnableTMVPFlag() )
283    return numDdvCandPics;
284
285  numDdvCandPics += 1;
286
287  UInt pocCurr = currSlice->getPOC();
288  UInt pocDiff = 255;
289
290  for(UInt lpNr = 0; lpNr < (currSlice->isInterB() ? 2: 1); lpNr ++)
291  {
292    UInt x = lpNr ? currSlice->getColFromL0Flag() : 1 - currSlice->getColFromL0Flag();
293
294    for (UInt i = 0; i < currSlice->getNumRefIdx(RefPicList(x)); i++)
295    {
296      if(currSlice->getViewIndex() == currSlice->getRefPic((RefPicList)x, i)->getViewIndex() 
297        && (x == currSlice->getColFromL0Flag()||currSlice->getRefPOC((RefPicList)x, i)!= iColPOC) && numDdvCandPics!=2)
298      {
299        TComSlice* refSlice    = currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx());
300        Bool       bRAP        = (refSlice->getViewIndex() && refSlice->isIRAP())? 1: 0; 
301        UInt       uiTempLayer = currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx())->getTLayer(); 
302       
303        if( bRAP )
304        {
305          this->setRapRefIdx(i);
306          this->setRapRefList((RefPicList)x);
307          numDdvCandPics = 2;
308
309          return numDdvCandPics;
310        }
311        else if (uiTempLayerCurr > uiTempLayer) 
312        {
313           uiTempLayerCurr = uiTempLayer; 
314        }
315      }
316    }
317  }
318
319  UInt z   = -1; // GT: Added to make code compile needs to be checked!
320  UInt idx = 0;
321 
322  for(UInt lpNr = 0; lpNr < (currSlice->isInterB() ? 2: 1); lpNr ++)
323  {
324    UInt x = lpNr? currSlice->getColFromL0Flag() : 1-currSlice->getColFromL0Flag();
325   
326    for (UInt i = 0; i < currSlice->getNumRefIdx(RefPicList(x)); i++)
327    {
328      Int iTempPoc = currSlice->getRefPic((RefPicList)x, i)->getPOC();
329      Int iTempDiff = (iTempPoc > pocCurr) ? (iTempPoc - pocCurr): (pocCurr - iTempPoc);
330     
331      if(currSlice->getViewIndex() == currSlice->getRefPic((RefPicList)x, i)->getViewIndex() &&  (x == currSlice->getColFromL0Flag()||currSlice->getRefPOC((RefPicList)x, i)!= iColPOC) 
332        && currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx())->getTLayer() == uiTempLayerCurr && pocDiff > iTempDiff)
333      {
334        pocDiff = iTempDiff;
335        z       = x;
336        idx     = i;
337      }
338    }
339  }
340
341  if( pocDiff < 255 )
342  {
343    this->setRapRefIdx(idx);
344    this->setRapRefList((RefPicList) z );
345    numDdvCandPics = 2;
346  }
347
348  return numDdvCandPics;
349}
350
351Void TComPic::checkTemporalIVRef()
352{
353  TComSlice* currSlice = getSlice(getCurrSliceIdx());
354  const Int numCandPics = this->getNumDdvCandPics();
355  for(Int curCandPic = 0; curCandPic < numCandPics; curCandPic++)
356  {
357    RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
358    Int        curCandPicRefIdx = 0;
359    if( curCandPic == 0 ) 
360    { 
361      eCurRefPicList   = RefPicList(currSlice->isInterB() ? 1-currSlice->getColFromL0Flag() : 0);
362      curCandPicRefIdx = currSlice->getColRefIdx();
363    }
364    else                 
365    {
366      eCurRefPicList   = this->getRapRefList();
367      curCandPicRefIdx = this->getRapRefIdx();
368    }
369    TComPic* pcCandColPic = currSlice->getRefPic( eCurRefPicList, curCandPicRefIdx);
370    TComSlice* pcCandColSlice = pcCandColPic->getSlice(0);// currently only support single slice
371
372    if(!pcCandColSlice->isIntra())
373    {
374      for( Int iColRefDir = 0; iColRefDir < (pcCandColSlice->isInterB() ? 2: 1); iColRefDir ++ )
375      {
376        for( Int iColRefIdx =0; iColRefIdx < pcCandColSlice->getNumRefIdx(( RefPicList )iColRefDir ); iColRefIdx++)
377        {
378          m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = false;
379          Int iColViewIdx    = pcCandColSlice->getViewIndex();
380          Int iColRefViewIdx = pcCandColSlice->getRefPic( ( RefPicList )iColRefDir, iColRefIdx)->getViewIndex();
381          if(iColViewIdx == iColRefViewIdx)
382            continue;
383
384          for(Int iCurrRefDir = 0;(iCurrRefDir < (currSlice->isInterB() ? 2: 1)) && (m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] == false ); iCurrRefDir++)
385          {
386            for( Int iCurrRefIdx =0; iCurrRefIdx < currSlice->getNumRefIdx(( RefPicList )iCurrRefDir ); iCurrRefIdx++)
387            {
388              if( currSlice->getRefPic( ( RefPicList )iCurrRefDir, iCurrRefIdx )->getViewIndex() == iColRefViewIdx )
389              { 
390                m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = true;
391                break;
392              }
393            }
394          }
395        }
396      }
397    }
398  }
399}
400Bool TComPic::isTempIVRefValid(Int currCandPic, Int iColRefDir, Int iColRefIdx)
401{
402  return m_abTIVRINCurrRL[currCandPic][iColRefDir][iColRefIdx];
403}
404
405Void TComPic::checkTextureRef(  )
406{
407  TComSlice* pcCurrSlice = getSlice(getCurrSliceIdx());
408  TComPic* pcTextPic = pcCurrSlice->getTexturePic();
409#if H_3D_FCO
410  if ( pcTextPic )
411  {
412#endif
413
414  TComSlice* pcTextSlice = pcTextPic->getSlice(0); // currently only support single slice
415
416  for( Int iTextRefDir = 0; (iTextRefDir < (pcTextSlice->isInterB()? 2:1) ) && !pcTextSlice->isIntra(); iTextRefDir ++ )
417  {
418    for( Int iTextRefIdx =0; iTextRefIdx<pcTextSlice->getNumRefIdx(( RefPicList )iTextRefDir ); iTextRefIdx++)
419    {
420      Int iTextRefPOC    = pcTextSlice->getRefPOC( ( RefPicList )iTextRefDir, iTextRefIdx);
421      Int iTextRefViewId = pcTextSlice->getRefPic( ( RefPicList )iTextRefDir, iTextRefIdx)->getViewIndex();
422      m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = -1;
423      Int iCurrRefDir = iTextRefDir;
424      for( Int iCurrRefIdx =0; ( iCurrRefIdx<pcCurrSlice->getNumRefIdx(( RefPicList )iCurrRefDir ) ) && ( m_aiTexToDepRef[iTextRefDir][iTextRefIdx] < 0 ) ; iCurrRefIdx++)
425      {
426        if( pcCurrSlice->getRefPOC( ( RefPicList )iCurrRefDir, iCurrRefIdx ) == iTextRefPOC && 
427          pcCurrSlice->getRefPic( ( RefPicList )iCurrRefDir, iCurrRefIdx)->getViewIndex() == iTextRefViewId )
428        { 
429          m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = iCurrRefIdx;
430        }
431      }
432    }
433
434  }
435#if H_3D_FCO
436  }
437#endif
438
439}
440
441Int TComPic::isTextRefValid(Int iTextRefDir, Int iTextRefIdx)
442{
443  return m_aiTexToDepRef[iTextRefDir][iTextRefIdx];
444}
445#endif
446//! \}
Note: See TracBrowser for help on using the repository browser.