source: 3DVCSoftware/branches/HTM-13.1-dev1-Samsung/source/Lib/TLibCommon/TComPic.cpp

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