source: 3DVCSoftware/trunk/source/Lib/TLibCommon/TComPicSym.cpp @ 638

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

Merged DEV-2.0-dev0@604.

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