source: 3DVCSoftware/tags/HTM-14.1/source/Lib/TLibDecoder/SyntaxElementParser.cpp @ 1198

Last change on this file since 1198 was 1179, checked in by tech, 10 years ago

Merged branch 13.1-dev0@1178.

File size: 5.4 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-2015, 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     SyntaxElementParser.cpp
35    \brief    Parsing functionality high level syntax
36*/
37
38//! \ingroup TLibDecoder
39//! \{
40
41#include "TLibCommon/CommonDef.h"
42#include "TLibCommon/TComRom.h"
43#include "TLibCommon/TComBitStream.h"
44#include "SyntaxElementParser.h"
45
46#if ENC_DEC_TRACE
47
48Void  SyntaxElementParser::xReadCodeTr           (UInt length, UInt& rValue, const Char *pSymbolName)
49{
50  xReadCode (length, rValue);
51#if H_MV_ENC_DEC_TRAC
52  if ( g_disableHLSTrace || !g_HLSTraceEnable )
53  {
54    return; 
55  }
56  if ( !g_disableNumbering )
57  {
58#endif
59  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
60#if H_MV_ENC_DEC_TRAC
61  }
62#endif
63
64  if (length < 10)
65  {
66    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue ); 
67  }
68  else
69  {
70    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue ); 
71  }
72  fflush ( g_hTrace );
73}
74
75Void  SyntaxElementParser::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
76{
77  xReadUvlc (rValue);
78#if H_MV_ENC_DEC_TRAC
79  if ( g_disableHLSTrace  || !g_HLSTraceEnable )
80  {
81    return; 
82  }
83  if ( !g_disableNumbering )
84  {
85#endif
86  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
87#if H_MV_ENC_DEC_TRAC
88  }
89#endif
90  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue ); 
91  fflush ( g_hTrace );
92}
93
94Void  SyntaxElementParser::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
95{
96  xReadSvlc(rValue);
97#if H_MV_ENC_DEC_TRAC
98  if ( g_disableHLSTrace  || !g_HLSTraceEnable  )
99  {
100    return; 
101  }
102  if ( !g_disableNumbering )
103  {
104#endif
105  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
106#if H_MV_ENC_DEC_TRAC
107  }
108#endif
109
110  fprintf( g_hTrace, "%-50s se(v) : %d\n", pSymbolName, rValue ); 
111  fflush ( g_hTrace );
112}
113
114Void  SyntaxElementParser::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
115{
116  xReadFlag(rValue);
117#if H_MV_ENC_DEC_TRAC
118  if ( g_disableHLSTrace  || !g_HLSTraceEnable )
119  {
120    return; 
121  }
122  if ( !g_disableNumbering )
123  {
124#endif
125  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
126#if H_MV_ENC_DEC_TRAC
127  }
128#endif
129  fprintf( g_hTrace, "%-50s u(1)  : %d\n", pSymbolName, rValue ); 
130  fflush ( g_hTrace );
131}
132
133#endif
134
135
136// ====================================================================================================================
137// Protected member functions
138// ====================================================================================================================
139
140Void SyntaxElementParser::xReadCode (UInt uiLength, UInt& ruiCode)
141{
142  assert ( uiLength > 0 );
143  m_pcBitstream->read (uiLength, ruiCode);
144}
145
146Void SyntaxElementParser::xReadUvlc( UInt& ruiVal)
147{
148  UInt uiVal = 0;
149  UInt uiCode = 0;
150  UInt uiLength;
151  m_pcBitstream->read( 1, uiCode );
152
153  if( 0 == uiCode )
154  {
155    uiLength = 0;
156
157    while( ! ( uiCode & 1 ))
158    {
159      m_pcBitstream->read( 1, uiCode );
160      uiLength++;
161    }
162
163    m_pcBitstream->read( uiLength, uiVal );
164
165    uiVal += (1 << uiLength)-1;
166  }
167
168  ruiVal = uiVal;
169}
170
171Void SyntaxElementParser::xReadSvlc( Int& riVal)
172{
173  UInt uiBits = 0;
174  m_pcBitstream->read( 1, uiBits );
175  if( 0 == uiBits )
176  {
177    UInt uiLength = 0;
178
179    while( ! ( uiBits & 1 ))
180    {
181      m_pcBitstream->read( 1, uiBits );
182      uiLength++;
183    }
184
185    m_pcBitstream->read( uiLength, uiBits );
186
187    uiBits += (1 << uiLength);
188    riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
189  }
190  else
191  {
192    riVal = 0;
193  }
194}
195
196Void SyntaxElementParser::xReadFlag (UInt& ruiCode)
197{
198  m_pcBitstream->read( 1, ruiCode );
199}
200
201
202//! \}
203
Note: See TracBrowser for help on using the repository browser.