source: SHVCSoftware/branches/0.1.1-bugfix/source/Lib/TLibCommon/TComPicSym.cpp @ 444

Last change on this file since 444 was 2, checked in by seregin, 12 years ago

Initial import by Vadim Seregin <vseregin@…>

File size: 10.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-2012, 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#if REMOVE_APS
40#include "TComSampleAdaptiveOffset.h"
41#endif
42
43//! \ingroup TLibCommon
44//! \{
45
46// ====================================================================================================================
47// Constructor / destructor / create / destroy
48// ====================================================================================================================
49
50TComPicSym::TComPicSym()
51:m_uiWidthInCU(0)
52,m_uiHeightInCU(0)
53,m_uiMaxCUWidth(0)
54,m_uiMaxCUHeight(0)
55,m_uiMinCUWidth(0)
56,m_uiMinCUHeight(0)
57,m_uhTotalDepth(0)
58,m_uiNumPartitions(0)
59,m_uiNumPartInWidth(0)
60,m_uiNumPartInHeight(0)
61,m_uiNumCUsInFrame(0)
62,m_apcTComSlice(NULL)
63,m_uiNumAllocatedSlice (0)
64,m_apcTComDataCU (NULL)
65,m_iTileBoundaryIndependenceIdr (0)
66,m_iNumColumnsMinus1 (0)
67,m_iNumRowsMinus1(0)
68,m_apcTComTile(NULL)
69,m_puiCUOrderMap(0)
70,m_puiTileIdxMap(NULL)
71,m_puiInverseCUOrderMap(NULL)
72{};
73
74
75Void TComPicSym::create  ( Int iPicWidth, Int iPicHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth )
76{
77  UInt i;
78
79  m_uhTotalDepth      = uiMaxDepth;
80  m_uiNumPartitions   = 1<<(m_uhTotalDepth<<1);
81 
82  m_uiMaxCUWidth      = uiMaxWidth;
83  m_uiMaxCUHeight     = uiMaxHeight;
84 
85  m_uiMinCUWidth      = uiMaxWidth  >> m_uhTotalDepth;
86  m_uiMinCUHeight     = uiMaxHeight >> m_uhTotalDepth;
87 
88  m_uiNumPartInWidth  = m_uiMaxCUWidth  / m_uiMinCUWidth;
89  m_uiNumPartInHeight = m_uiMaxCUHeight / m_uiMinCUHeight;
90 
91  m_uiWidthInCU       = ( iPicWidth %m_uiMaxCUWidth  ) ? iPicWidth /m_uiMaxCUWidth  + 1 : iPicWidth /m_uiMaxCUWidth;
92  m_uiHeightInCU      = ( iPicHeight%m_uiMaxCUHeight ) ? iPicHeight/m_uiMaxCUHeight + 1 : iPicHeight/m_uiMaxCUHeight;
93 
94  m_uiNumCUsInFrame   = m_uiWidthInCU * m_uiHeightInCU;
95  m_apcTComDataCU     = new TComDataCU*[m_uiNumCUsInFrame];
96 
97  if (m_uiNumAllocatedSlice>0)
98  {
99    for ( i=0; i<m_uiNumAllocatedSlice ; i++ )
100    {
101      delete m_apcTComSlice[i];
102    }
103    delete [] m_apcTComSlice;
104  }
105  m_apcTComSlice      = new TComSlice*[m_uiNumCUsInFrame*m_uiNumPartitions]; 
106  m_apcTComSlice[0]   = new TComSlice;
107  m_uiNumAllocatedSlice = 1;
108  for ( i=0; i<m_uiNumCUsInFrame ; i++ )
109  {
110    m_apcTComDataCU[i] = new TComDataCU;
111    m_apcTComDataCU[i]->create( m_uiNumPartitions, m_uiMaxCUWidth, m_uiMaxCUHeight, false, m_uiMaxCUWidth >> m_uhTotalDepth
112#if ADAPTIVE_QP_SELECTION
113      , true
114#endif     
115      );
116  }
117
118  m_puiCUOrderMap = new UInt[m_uiNumCUsInFrame+1];
119  m_puiTileIdxMap = new UInt[m_uiNumCUsInFrame];
120  m_puiInverseCUOrderMap = new UInt[m_uiNumCUsInFrame+1];
121
122  for( i=0; i<m_uiNumCUsInFrame; i++ )
123  {
124    m_puiCUOrderMap[i] = i;
125    m_puiInverseCUOrderMap[i] = i;
126  }
127#if REMOVE_APS
128  m_saoParam = NULL;
129#endif
130}
131
132Void TComPicSym::destroy()
133{
134  if (m_uiNumAllocatedSlice>0)
135  {
136    for (Int i = 0; i<m_uiNumAllocatedSlice ; i++ )
137    {
138      delete m_apcTComSlice[i];
139    }
140    delete [] m_apcTComSlice;
141  }
142  m_apcTComSlice = NULL;
143 
144  for (Int i = 0; i < m_uiNumCUsInFrame; i++)
145  {
146    m_apcTComDataCU[i]->destroy();
147    delete m_apcTComDataCU[i];
148    m_apcTComDataCU[i] = NULL;
149  }
150  delete [] m_apcTComDataCU;
151  m_apcTComDataCU = NULL;
152
153#if AVC_BASE || REF_IDX_FRAMEWORK
154  if( m_apcTComTile )
155  {
156#endif
157  for(Int i = 0; i < (m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1); i++ )
158  {
159    delete m_apcTComTile[i];
160  }
161  delete [] m_apcTComTile;
162#if AVC_BASE || REF_IDX_FRAMEWORK
163  }
164#endif
165
166  m_apcTComTile = NULL;
167
168  delete [] m_puiCUOrderMap;
169  m_puiCUOrderMap = NULL;
170
171  delete [] m_puiTileIdxMap;
172  m_puiTileIdxMap = NULL;
173
174  delete [] m_puiInverseCUOrderMap;
175  m_puiInverseCUOrderMap = NULL;
176 
177#if REMOVE_APS
178  if (m_saoParam)
179  {
180    TComSampleAdaptiveOffset::freeSaoParam(m_saoParam);
181    delete m_saoParam;
182    m_saoParam = NULL;
183  }
184#endif
185}
186
187Void TComPicSym::allocateNewSlice()
188{
189  m_apcTComSlice[m_uiNumAllocatedSlice ++] = new TComSlice;
190  if (m_uiNumAllocatedSlice>=2)
191  {
192    m_apcTComSlice[m_uiNumAllocatedSlice-1]->copySliceInfo( m_apcTComSlice[m_uiNumAllocatedSlice-2] );
193    m_apcTComSlice[m_uiNumAllocatedSlice-1]->initSlice();
194  }
195}
196
197Void TComPicSym::clearSliceBuffer()
198{
199  UInt i;
200  for (i = 1; i < m_uiNumAllocatedSlice; i++)
201  {
202    delete m_apcTComSlice[i];
203  }
204  m_uiNumAllocatedSlice = 1;
205}
206
207UInt TComPicSym::getPicSCUEncOrder( UInt SCUAddr )
208{ 
209  return getInverseCUOrderMap(SCUAddr/m_uiNumPartitions)*m_uiNumPartitions + SCUAddr%m_uiNumPartitions; 
210}
211
212UInt TComPicSym::getPicSCUAddr( UInt SCUEncOrder )
213{
214  return getCUOrderMap(SCUEncOrder/m_uiNumPartitions)*m_uiNumPartitions + SCUEncOrder%m_uiNumPartitions;
215}
216
217Void TComPicSym::xCreateTComTileArray()
218{
219  m_apcTComTile = new TComTile*[(m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1)];
220  for( UInt i=0; i<(m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1); i++ )
221  {
222    m_apcTComTile[i] = new TComTile;
223  }
224}
225
226Void TComPicSym::xInitTiles()
227{
228  UInt  uiTileIdx;
229  UInt  uiColumnIdx = 0;
230  UInt  uiRowIdx = 0;
231  UInt  uiRightEdgePosInCU;
232  UInt  uiBottomEdgePosInCU;
233  Int   i, j;
234
235  //initialize each tile of the current picture
236  for( uiRowIdx=0; uiRowIdx < m_iNumRowsMinus1+1; uiRowIdx++ )
237  {
238    for( uiColumnIdx=0; uiColumnIdx < m_iNumColumnsMinus1+1; uiColumnIdx++ )
239    {
240      uiTileIdx = uiRowIdx * (m_iNumColumnsMinus1+1) + uiColumnIdx;
241
242      //initialize the RightEdgePosInCU for each tile
243      uiRightEdgePosInCU = 0;
244      for( i=0; i <= uiColumnIdx; i++ )
245      {
246        uiRightEdgePosInCU += this->getTComTile(uiRowIdx * (m_iNumColumnsMinus1+1) + i)->getTileWidth();
247      }
248      this->getTComTile(uiTileIdx)->setRightEdgePosInCU(uiRightEdgePosInCU-1);
249
250      //initialize the BottomEdgePosInCU for each tile
251      uiBottomEdgePosInCU = 0;
252      for( i=0; i <= uiRowIdx; i++ )
253      {
254        uiBottomEdgePosInCU += this->getTComTile(i * (m_iNumColumnsMinus1+1) + uiColumnIdx)->getTileHeight();
255      }
256      this->getTComTile(uiTileIdx)->setBottomEdgePosInCU(uiBottomEdgePosInCU-1);
257
258      //initialize the FirstCUAddr for each tile
259      this->getTComTile(uiTileIdx)->setFirstCUAddr( (this->getTComTile(uiTileIdx)->getBottomEdgePosInCU() - this->getTComTile(uiTileIdx)->getTileHeight() +1)*m_uiWidthInCU + 
260        this->getTComTile(uiTileIdx)->getRightEdgePosInCU() - this->getTComTile(uiTileIdx)->getTileWidth() + 1);
261    }
262  }
263
264  //initialize the TileIdxMap
265  for( i=0; i<m_uiNumCUsInFrame; i++)
266  {
267    for(j=0; j < m_iNumColumnsMinus1+1; j++)
268    {
269      if(i % m_uiWidthInCU <= this->getTComTile(j)->getRightEdgePosInCU())
270      {
271        uiColumnIdx = j;
272        j = m_iNumColumnsMinus1+1;
273      }
274    }
275    for(j=0; j < m_iNumRowsMinus1+1; j++)
276    {
277      if(i/m_uiWidthInCU <= this->getTComTile(j*(m_iNumColumnsMinus1 + 1))->getBottomEdgePosInCU())
278      {
279        uiRowIdx = j;
280        j = m_iNumRowsMinus1 + 1;
281      }
282    }
283    m_puiTileIdxMap[i] = uiRowIdx * (m_iNumColumnsMinus1 + 1) + uiColumnIdx;
284  }
285
286}
287
288UInt TComPicSym::xCalculateNxtCUAddr( UInt uiCurrCUAddr )
289{
290  UInt  uiNxtCUAddr;
291  UInt  uiTileIdx;
292 
293  //get the tile index for the current LCU
294  uiTileIdx = this->getTileIdxMap(uiCurrCUAddr);
295
296  //get the raster scan address for the next LCU
297  if( uiCurrCUAddr % m_uiWidthInCU == this->getTComTile(uiTileIdx)->getRightEdgePosInCU() && uiCurrCUAddr / m_uiWidthInCU == this->getTComTile(uiTileIdx)->getBottomEdgePosInCU() )
298  //the current LCU is the last LCU of the tile
299  {
300    if(uiTileIdx == (m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1)-1)
301    {
302      uiNxtCUAddr = m_uiNumCUsInFrame;
303    }
304    else
305    {
306      uiNxtCUAddr = this->getTComTile(uiTileIdx+1)->getFirstCUAddr();
307    }
308  } 
309  else //the current LCU is not the last LCU of the tile
310  {
311    if( uiCurrCUAddr % m_uiWidthInCU == this->getTComTile(uiTileIdx)->getRightEdgePosInCU() )  //the current LCU is on the rightmost edge of the tile
312    {
313      uiNxtCUAddr = uiCurrCUAddr + m_uiWidthInCU - this->getTComTile(uiTileIdx)->getTileWidth() + 1;
314    }
315    else
316    {
317      uiNxtCUAddr = uiCurrCUAddr + 1;
318    }
319  }
320
321  return uiNxtCUAddr;
322}
323
324#if REMOVE_APS
325Void TComPicSym::allocSaoParam(TComSampleAdaptiveOffset *sao)
326{
327  m_saoParam = new SAOParam;
328  sao->allocSaoParam(m_saoParam);
329}
330#endif
331
332TComTile::TComTile()
333{
334}
335
336TComTile::~TComTile()
337{
338}
339//! \}
Note: See TracBrowser for help on using the repository browser.