source: 3DVCSoftware/branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComPic.cpp @ 446

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

Added missing parts.

  • Property svn:eol-style set to native
File size: 16.9 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-2013, 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_bIsUsedAsLongTerm                     (false)
53, m_apcPicSym                             (NULL)
54, m_pcPicYuvPred                          (NULL)
55, m_pcPicYuvResi                          (NULL)
56, m_bReconstructed                        (false)
57, m_bNeededForOutput                      (false)
58, m_uiCurrSliceIdx                        (0)
59, m_pSliceSUMap                           (NULL)
60, m_pbValidSlice                          (NULL)
61, m_sliceGranularityForNDBFilter          (0)
62, m_bIndependentSliceBoundaryForNDBFilter (false)
63, m_bIndependentTileBoundaryForNDBFilter  (false)
64, m_pNDBFilterYuvTmp                      (NULL)
65, m_bCheckLTMSB                           (false)
66#if H_MV
67, m_layerId                               (0)
68, m_viewId                                (0)
69#if H_3D
70, m_viewIndex                             (0)
71, m_isDepth                               (false)
72, m_aaiCodedScale                         (0)
73, m_aaiCodedOffset                        (0)
74#endif
75#endif
76{
77  m_apcPicYuv[0]      = NULL;
78  m_apcPicYuv[1]      = NULL;
79}
80
81TComPic::~TComPic()
82{
83}
84
85Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
86                      Int *numReorderPics, Bool bIsVirtual)
87
88{
89  m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
90  if (!bIsVirtual)
91  {
92    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
93  }
94  m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
95 
96  // there are no SEI messages associated with this picture initially
97  if (m_SEIs.size() > 0)
98  {
99    deleteSEIs (m_SEIs);
100  }
101  m_bUsedByCurr = false;
102
103  /* store conformance window parameters with picture */
104  m_conformanceWindow = conformanceWindow;
105 
106  /* store display window parameters with picture */
107  m_defaultDisplayWindow = defaultDisplayWindow;
108
109  /* store number of reorder pics with picture */
110  memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int));
111
112  return;
113}
114
115Void TComPic::destroy()
116{
117  if (m_apcPicSym)
118  {
119    m_apcPicSym->destroy();
120    delete m_apcPicSym;
121    m_apcPicSym = NULL;
122  }
123 
124  if (m_apcPicYuv[0])
125  {
126    m_apcPicYuv[0]->destroy();
127    delete m_apcPicYuv[0];
128    m_apcPicYuv[0]  = NULL;
129  }
130 
131  if (m_apcPicYuv[1])
132  {
133    m_apcPicYuv[1]->destroy();
134    delete m_apcPicYuv[1];
135    m_apcPicYuv[1]  = NULL;
136  }
137 
138  deleteSEIs(m_SEIs);
139}
140
141Void TComPic::compressMotion()
142{
143  TComPicSym* pPicSym = getPicSym(); 
144  for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getFrameHeightInCU()*pPicSym->getFrameWidthInCU(); uiCUAddr++ )
145  {
146    TComDataCU* pcCU = pPicSym->getCU(uiCUAddr);
147    pcCU->compressMV(); 
148  } 
149}
150
151/** Create non-deblocked filter information
152 * \param pSliceStartAddress array for storing slice start addresses
153 * \param numSlices number of slices in picture
154 * \param sliceGranularityDepth slice granularity
155 * \param bNDBFilterCrossSliceBoundary cross-slice-boundary in-loop filtering; true for "cross".
156 * \param numTiles number of tiles in picture
157 * \param bNDBFilterCrossTileBoundary cross-tile-boundary in-loop filtering; true for "cross".
158 */
159Void TComPic::createNonDBFilterInfo(std::vector<Int> sliceStartAddress, Int sliceGranularityDepth
160                                    ,std::vector<Bool>* LFCrossSliceBoundary
161                                    ,Int numTiles
162                                    ,Bool bNDBFilterCrossTileBoundary)
163{
164  UInt maxNumSUInLCU = getNumPartInCU();
165  UInt numLCUInPic   = getNumCUsInFrame();
166  UInt picWidth      = getSlice(0)->getSPS()->getPicWidthInLumaSamples();
167  UInt picHeight     = getSlice(0)->getSPS()->getPicHeightInLumaSamples();
168  Int  numLCUsInPicWidth = getFrameWidthInCU();
169  Int  numLCUsInPicHeight= getFrameHeightInCU();
170  UInt maxNumSUInLCUWidth = getNumPartInWidth();
171  UInt maxNumSUInLCUHeight= getNumPartInHeight();
172  Int  numSlices = (Int) sliceStartAddress.size() - 1;
173  m_bIndependentSliceBoundaryForNDBFilter = false;
174  if(numSlices > 1)
175  {
176    for(Int s=0; s< numSlices; s++)
177    {
178      if((*LFCrossSliceBoundary)[s] == false)
179      {
180        m_bIndependentSliceBoundaryForNDBFilter = true;
181      }
182    }
183  }
184  m_sliceGranularityForNDBFilter = sliceGranularityDepth;
185  m_bIndependentTileBoundaryForNDBFilter  = (bNDBFilterCrossTileBoundary)?(false) :((numTiles > 1)?(true):(false));
186
187  m_pbValidSlice = new Bool[numSlices];
188  for(Int s=0; s< numSlices; s++)
189  {
190    m_pbValidSlice[s] = true;
191  }
192  m_pSliceSUMap = new Int[maxNumSUInLCU * numLCUInPic];
193
194  //initialization
195  for(UInt i=0; i< (maxNumSUInLCU * numLCUInPic); i++ )
196  {
197    m_pSliceSUMap[i] = -1;
198  }
199  for( UInt CUAddr = 0; CUAddr < numLCUInPic ; CUAddr++ )
200  {
201    TComDataCU* pcCU = getCU( CUAddr );
202    pcCU->setSliceSUMap(m_pSliceSUMap + (CUAddr* maxNumSUInLCU)); 
203    pcCU->getNDBFilterBlocks()->clear();
204  }
205  m_vSliceCUDataLink.clear();
206
207  m_vSliceCUDataLink.resize(numSlices);
208
209  UInt startAddr, endAddr, firstCUInStartLCU, startLCU, endLCU, lastCUInEndLCU, uiAddr;
210  UInt LPelX, TPelY, LCUX, LCUY;
211  UInt currSU;
212  UInt startSU, endSU;
213
214  for(Int s=0; s< numSlices; s++)
215  {
216    //1st step: decide the real start address
217    startAddr = sliceStartAddress[s];
218    endAddr   = sliceStartAddress[s+1] -1;
219
220    startLCU            = startAddr / maxNumSUInLCU;
221    firstCUInStartLCU   = startAddr % maxNumSUInLCU;
222
223    endLCU              = endAddr   / maxNumSUInLCU;
224    lastCUInEndLCU      = endAddr   % maxNumSUInLCU;   
225
226    uiAddr = m_apcPicSym->getCUOrderMap(startLCU);
227
228    LCUX      = getCU(uiAddr)->getCUPelX();
229    LCUY      = getCU(uiAddr)->getCUPelY();
230    LPelX     = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[firstCUInStartLCU] ];
231    TPelY     = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[firstCUInStartLCU] ];
232    currSU    = firstCUInStartLCU;
233
234    Bool bMoveToNextLCU = false;
235    Bool bSliceInOneLCU = (startLCU == endLCU);
236
237    while(!( LPelX < picWidth ) || !( TPelY < picHeight ))
238    {
239      currSU ++;
240
241      if(bSliceInOneLCU)
242      {
243        if(currSU > lastCUInEndLCU)
244        {
245          m_pbValidSlice[s] = false;
246          break;
247        }
248      }
249
250      if(currSU >= maxNumSUInLCU )
251      {
252        bMoveToNextLCU = true;
253        break;
254      }
255
256      LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ];
257      TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ];
258
259    }
260
261
262    if(!m_pbValidSlice[s])
263    {
264      continue;
265    }
266
267    if(currSU != firstCUInStartLCU)
268    {
269      if(!bMoveToNextLCU)
270      {
271        firstCUInStartLCU = currSU;
272      }
273      else
274      {
275        startLCU++;
276        firstCUInStartLCU = 0;
277        assert( startLCU < getNumCUsInFrame());
278      }
279      assert(startLCU*maxNumSUInLCU + firstCUInStartLCU < endAddr);
280    }
281
282
283    //2nd step: assign NonDBFilterInfo to each processing block
284    for(UInt i= startLCU; i <= endLCU; i++)
285    {
286      startSU = (i == startLCU)?(firstCUInStartLCU):(0);
287      endSU   = (i == endLCU  )?(lastCUInEndLCU   ):(maxNumSUInLCU -1);
288
289      uiAddr = m_apcPicSym->getCUOrderMap(i);
290      Int iTileID= m_apcPicSym->getTileIdxMap(uiAddr);
291
292      TComDataCU* pcCU = getCU(uiAddr);
293      m_vSliceCUDataLink[s].push_back(pcCU);
294
295      createNonDBFilterInfoLCU(iTileID, s, pcCU, startSU, endSU, m_sliceGranularityForNDBFilter, picWidth, picHeight);
296    }
297  }
298
299  //step 3: border availability
300  for(Int s=0; s< numSlices; s++)
301  {
302    if(!m_pbValidSlice[s])
303    {
304      continue;
305    }
306
307    for(Int i=0; i< m_vSliceCUDataLink[s].size(); i++)
308    {
309      TComDataCU* pcCU = m_vSliceCUDataLink[s][i];
310      uiAddr = pcCU->getAddr();
311
312      if(pcCU->getPic()==0)
313      {
314        continue;
315      }
316      Int iTileID= m_apcPicSym->getTileIdxMap(uiAddr);
317      Bool bTopTileBoundary = false, bDownTileBoundary= false, bLeftTileBoundary= false, bRightTileBoundary= false;
318
319      if(m_bIndependentTileBoundaryForNDBFilter)
320      {
321        //left
322        if( uiAddr % numLCUsInPicWidth != 0)
323        {
324          bLeftTileBoundary = ( m_apcPicSym->getTileIdxMap(uiAddr -1) != iTileID )?true:false;
325        }
326        //right
327        if( (uiAddr % numLCUsInPicWidth) != (numLCUsInPicWidth -1) )
328        {
329          bRightTileBoundary = ( m_apcPicSym->getTileIdxMap(uiAddr +1) != iTileID)?true:false;
330        }
331        //top
332        if( uiAddr >= numLCUsInPicWidth)
333        {
334          bTopTileBoundary = (m_apcPicSym->getTileIdxMap(uiAddr - numLCUsInPicWidth) !=  iTileID )?true:false;
335        }
336        //down
337        if( uiAddr + numLCUsInPicWidth < numLCUInPic )
338        {
339          bDownTileBoundary = (m_apcPicSym->getTileIdxMap(uiAddr + numLCUsInPicWidth) != iTileID)?true:false;
340        }
341
342      }
343
344      pcCU->setNDBFilterBlockBorderAvailability(numLCUsInPicWidth, numLCUsInPicHeight, maxNumSUInLCUWidth, maxNumSUInLCUHeight,picWidth, picHeight
345        , *LFCrossSliceBoundary
346        ,bTopTileBoundary, bDownTileBoundary, bLeftTileBoundary, bRightTileBoundary
347        ,m_bIndependentTileBoundaryForNDBFilter);
348
349    }
350
351  }
352
353  if( m_bIndependentSliceBoundaryForNDBFilter || m_bIndependentTileBoundaryForNDBFilter)
354  {
355    m_pNDBFilterYuvTmp = new TComPicYuv();
356    m_pNDBFilterYuvTmp->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
357  }
358
359}
360
361/** Create non-deblocked filter information for LCU
362 * \param tileID tile index
363 * \param sliceID slice index
364 * \param pcCU CU data pointer
365 * \param startSU start SU index in LCU
366 * \param endSU end SU index in LCU
367 * \param sliceGranularyDepth slice granularity
368 * \param picWidth picture width
369 * \param picHeight picture height
370 */
371Void TComPic::createNonDBFilterInfoLCU(Int tileID, Int sliceID, TComDataCU* pcCU, UInt startSU, UInt endSU, Int sliceGranularyDepth, UInt picWidth, UInt picHeight)
372{
373  UInt LCUX          = pcCU->getCUPelX();
374  UInt LCUY          = pcCU->getCUPelY();
375  Int* pCUSliceMap    = pcCU->getSliceSUMap();
376  UInt maxNumSUInLCU = getNumPartInCU();
377  UInt maxNumSUInSGU = maxNumSUInLCU >> (sliceGranularyDepth << 1);
378  UInt maxNumSUInLCUWidth = getNumPartInWidth();
379  UInt LPelX, TPelY;
380  UInt currSU;
381
382
383  //get the number of valid NBFilterBLock
384  currSU   = startSU;
385  while(currSU <= endSU)
386  {
387    LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ];
388    TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ];
389
390    while(!( LPelX < picWidth ) || !( TPelY < picHeight ))
391    {
392      currSU += maxNumSUInSGU;
393      if(currSU >= maxNumSUInLCU || currSU > endSU)
394      {
395        break;
396      }
397      LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ];
398      TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ];
399    }
400
401    if(currSU >= maxNumSUInLCU || currSU > endSU)
402    {
403      break;
404    }
405
406    NDBFBlockInfo NDBFBlock;
407
408    NDBFBlock.tileID  = tileID;
409    NDBFBlock.sliceID = sliceID;
410    NDBFBlock.posY    = TPelY;
411    NDBFBlock.posX    = LPelX;
412    NDBFBlock.startSU = currSU;
413
414    UInt uiLastValidSU  = currSU;
415    UInt uiIdx, uiLPelX_su, uiTPelY_su;
416    for(uiIdx = currSU; uiIdx < currSU + maxNumSUInSGU; uiIdx++)
417    {
418      if(uiIdx > endSU)
419      {
420        break;       
421      }
422      uiLPelX_su   = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
423      uiTPelY_su   = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
424      if( !(uiLPelX_su < picWidth ) || !( uiTPelY_su < picHeight ))
425      {
426        continue;
427      }
428      pCUSliceMap[uiIdx] = sliceID;
429      uiLastValidSU = uiIdx;
430    }
431    NDBFBlock.endSU = uiLastValidSU;
432
433    UInt rTLSU = g_auiZscanToRaster[ NDBFBlock.startSU ];
434    UInt rBRSU = g_auiZscanToRaster[ NDBFBlock.endSU   ];
435    NDBFBlock.widthSU  = (rBRSU % maxNumSUInLCUWidth) - (rTLSU % maxNumSUInLCUWidth)+ 1;
436    NDBFBlock.heightSU = (UInt)(rBRSU / maxNumSUInLCUWidth) - (UInt)(rTLSU / maxNumSUInLCUWidth)+ 1;
437    NDBFBlock.width    = NDBFBlock.widthSU  * getMinCUWidth();
438    NDBFBlock.height   = NDBFBlock.heightSU * getMinCUHeight();
439
440    pcCU->getNDBFilterBlocks()->push_back(NDBFBlock);
441
442    currSU += maxNumSUInSGU;
443  }
444
445}
446
447/** destroy non-deblocked filter information for LCU
448 */
449Void TComPic::destroyNonDBFilterInfo()
450{
451  if(m_pbValidSlice != NULL)
452  {
453    delete[] m_pbValidSlice;
454    m_pbValidSlice = NULL;
455  }
456
457  if(m_pSliceSUMap != NULL)
458  {
459    delete[] m_pSliceSUMap;
460    m_pSliceSUMap = NULL;
461  }
462  for( UInt CUAddr = 0; CUAddr < getNumCUsInFrame() ; CUAddr++ )
463  {
464    TComDataCU* pcCU = getCU( CUAddr );
465    pcCU->getNDBFilterBlocks()->clear();
466  }
467
468  if( m_bIndependentSliceBoundaryForNDBFilter || m_bIndependentTileBoundaryForNDBFilter)
469  {
470    m_pNDBFilterYuvTmp->destroy();
471    delete m_pNDBFilterYuvTmp;
472    m_pNDBFilterYuvTmp = NULL;
473  }
474
475}
476#if H_MV
477Void TComPic::print( Bool legend )
478{
479  if ( legend )
480    std::cout  << "LId"        << "\t" << "POC"   << "\t" << "Rec"          << "\t" << "Ref"                       << "\t" << "LT"            << std::endl;
481  else
482    std::cout  << getLayerId() << "\t" << getPOC()<< "\t" << getReconMark() << "\t" << getSlice(0)->isReferenced() << "\t" << getIsLongTerm() << std::endl;
483}
484
485TComPic* TComPicLists::getPic( Int layerIdInNuh, Int poc )
486{
487  TComPic* pcPic = NULL;
488  for(TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin(); ( itL != m_lists.end() && pcPic == NULL ); itL++)
489  {   
490    for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() && pcPic == NULL ); itP++)
491    {
492      TComPic* currPic = (*itP); 
493      if ( ( currPic->getPOC() == poc ) && ( currPic->getLayerId() == layerIdInNuh ) )
494      {
495        pcPic = currPic ;     
496      }
497    }
498  }
499  return pcPic;
500}
501
502#if H_3D
503TComPic* TComPicLists::getPic( Int viewIndex, Bool depthFlag, Int poc )
504{
505  return getPic   ( m_vps->getLayerIdInNuh( viewIndex, depthFlag ), poc );
506}
507
508Void TComPicLists::print()
509{
510  Bool first = true;     
511  for(TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin(); ( itL != m_lists.end() ); itL++)
512  {   
513    for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() ); itP++)
514    {
515      if ( first )
516      {
517        (*itP)->print( true );       
518        first = false; 
519      }
520      (*itP)->print( false );       
521    }
522  }
523}
524
525TComPicYuv* TComPicLists::getPicYuv( Int layerIdInNuh, Int poc, Bool reconFlag )
526{
527  TComPic*    pcPic = getPic( layerIdInNuh, poc );
528  TComPicYuv* pcPicYuv = NULL;
529
530  if (pcPic != NULL)
531  {
532    if( reconFlag )
533    {
534      if ( pcPic->getReconMark() )
535      {
536        pcPicYuv = pcPic->getPicYuvRec();
537      }
538    }
539    else
540    {
541      pcPicYuv = pcPic->getPicYuvOrg();
542    }
543  };
544
545  return pcPicYuv;
546}
547
548TComPicYuv* TComPicLists::getPicYuv( Int viewIndex, Bool depthFlag, Int poc, Bool recon )
549{ 
550  Int layerIdInNuh = m_vps->getLayerIdInNuh( viewIndex, depthFlag ); 
551  return getPicYuv( layerIdInNuh, poc, recon );
552}
553#endif // H_3D
554#endif // H_MV
555//! \}
Note: See TracBrowser for help on using the repository browser.