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

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

remove REF_IDX_FRAMEWORK macro

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