source: SHVCSoftware/branches/SHM-6-dev/source/Lib/TLibCommon/TComPicSym.cpp @ 693

Last change on this file since 693 was 595, checked in by seregin, 11 years ago

merge with SHM-5.0-dev branch

  • Property svn:eol-style set to native
File size: 15.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-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     TComPicSym.cpp
35    \brief    picture symbol class
36*/
37
38#include "TComPicSym.h"
39#include "TComSampleAdaptiveOffset.h"
40
41//! \ingroup TLibCommon
42//! \{
43
44// ====================================================================================================================
45// Constructor / destructor / create / destroy
46// ====================================================================================================================
47
48TComPicSym::TComPicSym()
49:m_uiWidthInCU(0)
50,m_uiHeightInCU(0)
51,m_uiMaxCUWidth(0)
52,m_uiMaxCUHeight(0)
53,m_uiMinCUWidth(0)
54,m_uiMinCUHeight(0)
55,m_uhTotalDepth(0)
56,m_uiNumPartitions(0)
57,m_uiNumPartInWidth(0)
58,m_uiNumPartInHeight(0)
59,m_uiNumCUsInFrame(0)
60,m_apcTComSlice(NULL)
61,m_uiNumAllocatedSlice (0)
62,m_apcTComDataCU (NULL)
63,m_iNumColumnsMinus1 (0)
64,m_iNumRowsMinus1(0)
65,m_apcTComTile(NULL)
66,m_puiCUOrderMap(0)
67,m_puiTileIdxMap(NULL)
68,m_puiInverseCUOrderMap(NULL)
69,m_saoBlkParams(NULL)
70{};
71
72
73Void TComPicSym::create  ( Int iPicWidth, Int iPicHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth )
74{
75  UInt i;
76
77  m_uhTotalDepth      = uiMaxDepth;
78  m_uiNumPartitions   = 1<<(m_uhTotalDepth<<1);
79 
80  m_uiMaxCUWidth      = uiMaxWidth;
81  m_uiMaxCUHeight     = uiMaxHeight;
82 
83  m_uiMinCUWidth      = uiMaxWidth  >> m_uhTotalDepth;
84  m_uiMinCUHeight     = uiMaxHeight >> m_uhTotalDepth;
85 
86  m_uiNumPartInWidth  = m_uiMaxCUWidth  / m_uiMinCUWidth;
87  m_uiNumPartInHeight = m_uiMaxCUHeight / m_uiMinCUHeight;
88 
89  m_uiWidthInCU       = ( iPicWidth %m_uiMaxCUWidth  ) ? iPicWidth /m_uiMaxCUWidth  + 1 : iPicWidth /m_uiMaxCUWidth;
90  m_uiHeightInCU      = ( iPicHeight%m_uiMaxCUHeight ) ? iPicHeight/m_uiMaxCUHeight + 1 : iPicHeight/m_uiMaxCUHeight;
91 
92  m_uiNumCUsInFrame   = m_uiWidthInCU * m_uiHeightInCU;
93  m_apcTComDataCU     = new TComDataCU*[m_uiNumCUsInFrame];
94 
95  if (m_uiNumAllocatedSlice>0)
96  {
97    for ( i=0; i<m_uiNumAllocatedSlice ; i++ )
98    {
99      delete m_apcTComSlice[i];
100    }
101    delete [] m_apcTComSlice;
102  }
103  m_apcTComSlice      = new TComSlice*[m_uiNumCUsInFrame*m_uiNumPartitions]; 
104  m_apcTComSlice[0]   = new TComSlice;
105  m_uiNumAllocatedSlice = 1;
106  for ( i=0; i<m_uiNumCUsInFrame ; i++ )
107  {
108    m_apcTComDataCU[i] = new TComDataCU;
109    m_apcTComDataCU[i]->create( m_uiNumPartitions, m_uiMaxCUWidth, m_uiMaxCUHeight, false, m_uiMaxCUWidth >> m_uhTotalDepth
110#if ADAPTIVE_QP_SELECTION
111      , true
112#endif     
113      );
114  }
115
116  m_puiCUOrderMap = new UInt[m_uiNumCUsInFrame+1];
117  m_puiTileIdxMap = new UInt[m_uiNumCUsInFrame];
118#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
119  m_piTileSetIdxMap = new Int[m_uiNumCUsInFrame];
120  m_pucTileSetType = new UChar[m_uiNumCUsInFrame];
121  m_pbSkippedTileSetFlag = new Bool[m_uiNumCUsInFrame];
122#endif
123  m_puiInverseCUOrderMap = new UInt[m_uiNumCUsInFrame+1];
124
125  for( i=0; i<m_uiNumCUsInFrame; i++ )
126  {
127    m_puiCUOrderMap[i] = i;
128    m_puiInverseCUOrderMap[i] = i;
129  }
130
131  m_saoBlkParams = new SAOBlkParam[m_uiNumCUsInFrame];
132}
133
134Void TComPicSym::destroy()
135{
136  if (m_uiNumAllocatedSlice>0)
137  {
138    for (Int i = 0; i<m_uiNumAllocatedSlice ; i++ )
139    {
140      delete m_apcTComSlice[i];
141    }
142    delete [] m_apcTComSlice;
143  }
144  m_apcTComSlice = NULL;
145 
146  for (Int i = 0; i < m_uiNumCUsInFrame; i++)
147  {
148    m_apcTComDataCU[i]->destroy();
149    delete m_apcTComDataCU[i];
150    m_apcTComDataCU[i] = NULL;
151  }
152  delete [] m_apcTComDataCU;
153  m_apcTComDataCU = NULL;
154
155#if SVC_EXTENSION
156  if( m_apcTComTile )
157  {
158#endif
159  for(Int i = 0; i < (m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1); i++ )
160  {
161    delete m_apcTComTile[i];
162  }
163  delete [] m_apcTComTile;
164#if SVC_EXTENSION
165  }
166#endif
167
168  m_apcTComTile = NULL;
169
170  delete [] m_puiCUOrderMap;
171  m_puiCUOrderMap = NULL;
172
173  delete [] m_puiTileIdxMap;
174  m_puiTileIdxMap = NULL;
175#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
176  delete [] m_piTileSetIdxMap;
177  m_piTileSetIdxMap = NULL;
178  delete [] m_pucTileSetType;
179  m_pucTileSetType = NULL;
180  delete [] m_pbSkippedTileSetFlag;
181  m_pbSkippedTileSetFlag = NULL;
182#endif
183
184  delete [] m_puiInverseCUOrderMap;
185  m_puiInverseCUOrderMap = NULL;
186 
187  if(m_saoBlkParams)
188  {
189    delete[] m_saoBlkParams; m_saoBlkParams = NULL;
190  }
191}
192
193Void TComPicSym::allocateNewSlice()
194{
195  m_apcTComSlice[m_uiNumAllocatedSlice ++] = new TComSlice;
196  if (m_uiNumAllocatedSlice>=2)
197  {
198    m_apcTComSlice[m_uiNumAllocatedSlice-1]->copySliceInfo( m_apcTComSlice[m_uiNumAllocatedSlice-2] );
199#if SVC_EXTENSION
200    m_apcTComSlice[m_uiNumAllocatedSlice-1]->initSlice( m_apcTComSlice[m_uiNumAllocatedSlice-1]->getLayerId() );
201#else
202    m_apcTComSlice[m_uiNumAllocatedSlice-1]->initSlice();
203#endif
204  }
205}
206
207Void TComPicSym::clearSliceBuffer()
208{
209  UInt i;
210  for (i = 1; i < m_uiNumAllocatedSlice; i++)
211  {
212    delete m_apcTComSlice[i];
213  }
214  m_uiNumAllocatedSlice = 1;
215}
216
217UInt TComPicSym::getPicSCUEncOrder( UInt SCUAddr )
218{ 
219  return getInverseCUOrderMap(SCUAddr/m_uiNumPartitions)*m_uiNumPartitions + SCUAddr%m_uiNumPartitions; 
220}
221
222UInt TComPicSym::getPicSCUAddr( UInt SCUEncOrder )
223{
224  return getCUOrderMap(SCUEncOrder/m_uiNumPartitions)*m_uiNumPartitions + SCUEncOrder%m_uiNumPartitions;
225}
226
227Void TComPicSym::xCreateTComTileArray()
228{
229  m_apcTComTile = new TComTile*[(m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1)];
230  for( UInt i=0; i<(m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1); i++ )
231  {
232    m_apcTComTile[i] = new TComTile;
233  }
234}
235
236Void TComPicSym::xInitTiles()
237{
238  UInt  uiTileIdx;
239  UInt  uiColumnIdx = 0;
240  UInt  uiRowIdx = 0;
241  UInt  uiRightEdgePosInCU;
242  UInt  uiBottomEdgePosInCU;
243  Int   i, j;
244
245  //initialize each tile of the current picture
246  for( uiRowIdx=0; uiRowIdx < m_iNumRowsMinus1+1; uiRowIdx++ )
247  {
248    for( uiColumnIdx=0; uiColumnIdx < m_iNumColumnsMinus1+1; uiColumnIdx++ )
249    {
250      uiTileIdx = uiRowIdx * (m_iNumColumnsMinus1+1) + uiColumnIdx;
251
252      //initialize the RightEdgePosInCU for each tile
253      uiRightEdgePosInCU = 0;
254      for( i=0; i <= uiColumnIdx; i++ )
255      {
256        uiRightEdgePosInCU += this->getTComTile(uiRowIdx * (m_iNumColumnsMinus1+1) + i)->getTileWidth();
257      }
258      this->getTComTile(uiTileIdx)->setRightEdgePosInCU(uiRightEdgePosInCU-1);
259
260      //initialize the BottomEdgePosInCU for each tile
261      uiBottomEdgePosInCU = 0;
262      for( i=0; i <= uiRowIdx; i++ )
263      {
264        uiBottomEdgePosInCU += this->getTComTile(i * (m_iNumColumnsMinus1+1) + uiColumnIdx)->getTileHeight();
265      }
266      this->getTComTile(uiTileIdx)->setBottomEdgePosInCU(uiBottomEdgePosInCU-1);
267
268      //initialize the FirstCUAddr for each tile
269      this->getTComTile(uiTileIdx)->setFirstCUAddr( (this->getTComTile(uiTileIdx)->getBottomEdgePosInCU() - this->getTComTile(uiTileIdx)->getTileHeight() +1)*m_uiWidthInCU + 
270        this->getTComTile(uiTileIdx)->getRightEdgePosInCU() - this->getTComTile(uiTileIdx)->getTileWidth() + 1);
271    }
272  }
273
274  //initialize the TileIdxMap
275  for( i=0; i<m_uiNumCUsInFrame; i++)
276  {
277    for(j=0; j < m_iNumColumnsMinus1+1; j++)
278    {
279      if(i % m_uiWidthInCU <= this->getTComTile(j)->getRightEdgePosInCU())
280      {
281        uiColumnIdx = j;
282        j = m_iNumColumnsMinus1+1;
283      }
284    }
285    for(j=0; j < m_iNumRowsMinus1+1; j++)
286    {
287      if(i/m_uiWidthInCU <= this->getTComTile(j*(m_iNumColumnsMinus1 + 1))->getBottomEdgePosInCU())
288      {
289        uiRowIdx = j;
290        j = m_iNumRowsMinus1 + 1;
291      }
292    }
293    m_puiTileIdxMap[i] = uiRowIdx * (m_iNumColumnsMinus1 + 1) + uiColumnIdx;
294  }
295
296}
297
298UInt TComPicSym::xCalculateNxtCUAddr( UInt uiCurrCUAddr )
299{
300  UInt  uiNxtCUAddr;
301  UInt  uiTileIdx;
302 
303  //get the tile index for the current LCU
304  uiTileIdx = this->getTileIdxMap(uiCurrCUAddr);
305
306  //get the raster scan address for the next LCU
307  if( uiCurrCUAddr % m_uiWidthInCU == this->getTComTile(uiTileIdx)->getRightEdgePosInCU() && uiCurrCUAddr / m_uiWidthInCU == this->getTComTile(uiTileIdx)->getBottomEdgePosInCU() )
308  //the current LCU is the last LCU of the tile
309  {
310    if(uiTileIdx == (m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1)-1)
311    {
312      uiNxtCUAddr = m_uiNumCUsInFrame;
313    }
314    else
315    {
316      uiNxtCUAddr = this->getTComTile(uiTileIdx+1)->getFirstCUAddr();
317    }
318  } 
319  else //the current LCU is not the last LCU of the tile
320  {
321    if( uiCurrCUAddr % m_uiWidthInCU == this->getTComTile(uiTileIdx)->getRightEdgePosInCU() )  //the current LCU is on the rightmost edge of the tile
322    {
323      uiNxtCUAddr = uiCurrCUAddr + m_uiWidthInCU - this->getTComTile(uiTileIdx)->getTileWidth() + 1;
324    }
325    else
326    {
327      uiNxtCUAddr = uiCurrCUAddr + 1;
328    }
329  }
330
331  return uiNxtCUAddr;
332}
333
334Void TComPicSym::deriveLoopFilterBoundaryAvailibility(Int ctu,
335                                                      Bool& isLeftAvail,
336                                                      Bool& isRightAvail,
337                                                      Bool& isAboveAvail,
338                                                      Bool& isBelowAvail,
339                                                      Bool& isAboveLeftAvail,
340                                                      Bool& isAboveRightAvail,
341                                                      Bool& isBelowLeftAvail,
342                                                      Bool& isBelowRightAvail
343                                                      )
344{
345
346  isLeftAvail      = (ctu % m_uiWidthInCU != 0);
347  isRightAvail     = (ctu % m_uiWidthInCU != m_uiWidthInCU-1);
348  isAboveAvail     = (ctu >= m_uiWidthInCU );
349  isBelowAvail     = (ctu <  m_uiNumCUsInFrame - m_uiWidthInCU);
350  isAboveLeftAvail = (isAboveAvail && isLeftAvail);
351  isAboveRightAvail= (isAboveAvail && isRightAvail);
352  isBelowLeftAvail = (isBelowAvail && isLeftAvail);
353  isBelowRightAvail= (isBelowAvail && isRightAvail);
354
355  Bool isLoopFiltAcrossTilePPS = getCU(ctu)->getSlice()->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
356
357  {
358    TComDataCU* ctuCurr  = getCU(ctu);
359    TComDataCU* ctuLeft  = isLeftAvail ?getCU(ctu-1):NULL;
360    TComDataCU* ctuRight = isRightAvail?getCU(ctu+1):NULL;
361    TComDataCU* ctuAbove = isAboveAvail?getCU(ctu-m_uiWidthInCU):NULL;
362    TComDataCU* ctuBelow = isBelowAvail?getCU(ctu+m_uiWidthInCU):NULL;
363    TComDataCU* ctuAboveLeft  = isAboveLeftAvail ? getCU(ctu-m_uiWidthInCU-1):NULL;
364    TComDataCU* ctuAboveRigtht= isAboveRightAvail? getCU(ctu-m_uiWidthInCU+1):NULL;
365    TComDataCU* ctuBelowLeft  = isBelowLeftAvail ? getCU(ctu+m_uiWidthInCU-1):NULL;
366    TComDataCU* ctuBelowRight = isBelowRightAvail? getCU(ctu+m_uiWidthInCU+1):NULL;
367
368    {
369      //left
370      if(ctuLeft != NULL)
371      {
372        isLeftAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuLeft->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true;
373      }
374      //above
375      if(ctuAbove != NULL)
376      {
377        isAboveAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuAbove->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true;
378      }
379      //right
380      if(ctuRight != NULL)
381      {
382        isRightAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuRight->getSlice()->getSliceCurStartCUAddr())?ctuRight->getSlice()->getLFCrossSliceBoundaryFlag():true;
383      }
384      //below
385      if(ctuBelow != NULL)
386      {
387        isBelowAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuBelow->getSlice()->getSliceCurStartCUAddr())?ctuBelow->getSlice()->getLFCrossSliceBoundaryFlag():true;
388      }
389      //above-left
390      if(ctuAboveLeft != NULL)
391      {
392        isAboveLeftAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuAboveLeft->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true;
393      }
394      //below-right
395      if(ctuBelowRight != NULL)
396      {
397        isBelowRightAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuBelowRight->getSlice()->getSliceCurStartCUAddr())?ctuBelowRight->getSlice()->getLFCrossSliceBoundaryFlag():true;
398      }
399
400
401      //above-right
402      if(ctuAboveRigtht != NULL)
403      {
404        Int curSliceStartEncOrder  = ctuCurr->getSlice()->getSliceCurStartCUAddr();
405        Int aboveRigthtSliceStartEncOrder = ctuAboveRigtht->getSlice()->getSliceCurStartCUAddr();
406
407        isAboveRightAvail = (curSliceStartEncOrder == aboveRigthtSliceStartEncOrder)?(true):
408          (
409          (curSliceStartEncOrder > aboveRigthtSliceStartEncOrder)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag())
410          :(ctuAboveRigtht->getSlice()->getLFCrossSliceBoundaryFlag())
411          );         
412      }
413      //below-left
414      if(ctuBelowLeft != NULL)
415      {
416        Int curSliceStartEncOrder  = ctuCurr->getSlice()->getSliceCurStartCUAddr();
417        Int belowLeftSliceStartEncOrder = ctuBelowLeft->getSlice()->getSliceCurStartCUAddr();
418
419        isBelowLeftAvail = (curSliceStartEncOrder == belowLeftSliceStartEncOrder)?(true):
420          (
421          (curSliceStartEncOrder > belowLeftSliceStartEncOrder)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag())
422          :(ctuBelowLeft->getSlice()->getLFCrossSliceBoundaryFlag())
423          );
424      }       
425    }
426
427    if(!isLoopFiltAcrossTilePPS)
428    {     
429      isLeftAvail      = (!isLeftAvail      ) ?false:(getTileIdxMap( ctuLeft->getAddr()         ) == getTileIdxMap( ctu ));
430      isAboveAvail     = (!isAboveAvail     ) ?false:(getTileIdxMap( ctuAbove->getAddr()        ) == getTileIdxMap( ctu ));
431      isRightAvail     = (!isRightAvail     ) ?false:(getTileIdxMap( ctuRight->getAddr()        ) == getTileIdxMap( ctu ));
432      isBelowAvail     = (!isBelowAvail     ) ?false:(getTileIdxMap( ctuBelow->getAddr()        ) == getTileIdxMap( ctu ));
433      isAboveLeftAvail = (!isAboveLeftAvail ) ?false:(getTileIdxMap( ctuAboveLeft->getAddr()    ) == getTileIdxMap( ctu ));
434      isAboveRightAvail= (!isAboveRightAvail) ?false:(getTileIdxMap( ctuAboveRigtht->getAddr()  ) == getTileIdxMap( ctu ));
435      isBelowLeftAvail = (!isBelowLeftAvail ) ?false:(getTileIdxMap( ctuBelowLeft->getAddr()    ) == getTileIdxMap( ctu ));
436      isBelowRightAvail= (!isBelowRightAvail) ?false:(getTileIdxMap( ctuBelowRight->getAddr()   ) == getTileIdxMap( ctu ));
437    }
438  }
439
440}
441
442TComTile::TComTile()
443{
444}
445
446TComTile::~TComTile()
447{
448}
449//! \}
Note: See TracBrowser for help on using the repository browser.