source: 3DVCSoftware/branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPicSym.cpp @ 193

Last change on this file since 193 was 193, checked in by mitsubishi-htm, 12 years ago

A second release, as planned

  • Migrate to HTM 4.1
  • Move VSP related switches to cfg file instead of #define in the source code
  • A few bug fixes
  • For VC project files, only VC9 file is updated

TODO

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