source: SHVCSoftware/branches/SHM-3.1-dev/source/Lib/TLibCommon/TComPicSym.cpp @ 431

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

initial porting of HM12

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