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

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

Further minor cleanups.

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