Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes
G4OutBitStream Class Reference

#include <G4RTOutBitStream.hh>

Public Member Functions

 G4OutBitStream (int size)
 
 ~G4OutBitStream ()
 
void SetBits (int v, int numBits)
 
void SetByte (u_char dat)
 
void SetWord (u_int dat)
 
void CopyByte (const char *src, int n)
 
u_charGetStreamAddress (void)
 
int GetStreamSize (void)
 

Protected Member Functions

void IncBuf (void)
 
void FullBit (void)
 
void Set8Bits (u_char v, int numBits)
 
void SetFewBits (u_char v, int numBits)
 
void SetBits2Byte (u_char v, int numBits)
 

Protected Attributes

u_charmHeadOfBuf
 
u_charmBuf
 
u_charmEndOfBuf
 
int mBitPos
 
int mWriteFlag
 

Detailed Description

Definition at line 44 of file G4RTOutBitStream.hh.

Constructor & Destructor Documentation

G4OutBitStream::G4OutBitStream ( int  size)

Definition at line 38 of file G4RTOutBitStream.cc.

References mBitPos, mBuf, mEndOfBuf, mHeadOfBuf, and mWriteFlag.

39 {
40  if(size < 1)
41  throw( G4MemoryError( size, "G4OutBitStream" ) );
42 
43  mHeadOfBuf = mBuf = new u_char[size];
44  if( mHeadOfBuf == 0 )
45  throw( G4MemoryError( size, "G4OutBitStream" ) );
46 
47  mEndOfBuf = mBuf + size;
48 
49  memset( mHeadOfBuf, 0, size );
50 
51  mBitPos = 7;
52  mWriteFlag = 1;
53 }
unsigned char u_char
Definition: G4RTJpeg.hh:40
G4OutBitStream::~G4OutBitStream ( )

Definition at line 55 of file G4RTOutBitStream.cc.

References mBuf.

56 {
57  delete mBuf;
58 }

Member Function Documentation

void G4OutBitStream::CopyByte ( const char *  src,
int  n 
)

Definition at line 158 of file G4RTOutBitStream.cc.

References FullBit(), mBuf, mEndOfBuf, and n.

Referenced by G4JpegCoder::WriteHeader().

159 {
160  if( mBuf+n < mEndOfBuf ){
161  FullBit();
162  memcpy( mBuf, src, n );
163  mBuf += n;
164  return;
165  }
166  throw( G4BufferError( "CopyByte" ) );
167 }
const G4int n
void G4OutBitStream::FullBit ( void  )
protected

Definition at line 125 of file G4RTOutBitStream.cc.

References mBitPos, and SetFewBits().

Referenced by CopyByte(), SetByte(), and SetWord().

126 {
127  if( mBitPos != 7 )
128  SetFewBits( BitFullMaskT[mBitPos], mBitPos+1 );
129 }
void SetFewBits(u_char v, int numBits)
u_char* G4OutBitStream::GetStreamAddress ( void  )
inline

Definition at line 54 of file G4RTOutBitStream.hh.

References mHeadOfBuf.

Referenced by G4JpegCoder::GetJpegData().

54 {return mHeadOfBuf;};
int G4OutBitStream::GetStreamSize ( void  )
inline

Definition at line 55 of file G4RTOutBitStream.hh.

Referenced by G4JpegCoder::GetJpegData().

55 {return mBuf - mHeadOfBuf;};
void G4OutBitStream::IncBuf ( void  )
protected

Definition at line 61 of file G4RTOutBitStream.cc.

References mBuf, mEndOfBuf, and mWriteFlag.

Referenced by SetBits2Byte(), SetByte(), SetFewBits(), and SetWord().

62 {
63  if( ++mBuf >= mEndOfBuf )
64  mWriteFlag = 0;
65 }
void G4OutBitStream::Set8Bits ( u_char  v,
int  numBits 
)
protected

Definition at line 115 of file G4RTOutBitStream.cc.

References mBitPos, SetBits2Byte(), and SetFewBits().

Referenced by SetBits().

116 {
117  if( mBitPos + 1 >= numBits )
118  SetFewBits( (u_char)v, numBits );
119  else
120  SetBits2Byte( (u_char)v, numBits );
121 }
void SetFewBits(u_char v, int numBits)
unsigned char u_char
Definition: G4RTJpeg.hh:40
void SetBits2Byte(u_char v, int numBits)
void G4OutBitStream::SetBits ( int  v,
int  numBits 
)

Definition at line 70 of file G4RTOutBitStream.cc.

References Set8Bits().

Referenced by G4JpegCoder::CodeHuffman().

71 {
72  if( numBits == 0 )
73  return;
74  if( numBits > 16 )
75  throw( G4BufferError( "SetBits:Max Bit Over" ) );
76  if( numBits > 8 ){
77  Set8Bits( u_char(v>>8), numBits-8 );
78  numBits = 8;
79  }
80  Set8Bits( u_char(v), numBits );
81 }
unsigned char u_char
Definition: G4RTJpeg.hh:40
void Set8Bits(u_char v, int numBits)
void G4OutBitStream::SetBits2Byte ( u_char  v,
int  numBits 
)
protected

Definition at line 99 of file G4RTOutBitStream.cc.

References IncBuf(), mBitPos, and mBuf.

Referenced by Set8Bits().

100 {
101  v &= BitFullMaskT[numBits-1];
102  int nextBits = numBits - (mBitPos + 1);
103  *mBuf |= ( v >> nextBits ) & BitFullMaskT[mBitPos];
104  if( *mBuf == 0xff ){
105  IncBuf();
106  *mBuf = 0;
107  }
108  IncBuf();
109 
110  *mBuf = v << (8 - nextBits);
111  mBitPos = 7 - nextBits;
112 }
void G4OutBitStream::SetByte ( u_char  dat)

Definition at line 132 of file G4RTOutBitStream.cc.

References FullBit(), IncBuf(), mBuf, and mWriteFlag.

Referenced by G4JpegCoder::WriteEOI(), and G4JpegCoder::WriteHeader().

133 {
134  if( mWriteFlag ){
135  FullBit();
136  *mBuf = dat;
137  IncBuf();
138  return;
139  }
140  throw( G4BufferError( "SetByte" ) );
141 }
void G4OutBitStream::SetFewBits ( u_char  v,
int  numBits 
)
protected

Definition at line 84 of file G4RTOutBitStream.cc.

References IncBuf(), mBitPos, and mBuf.

Referenced by FullBit(), and Set8Bits().

85 {
86  v &= BitFullMaskT[numBits-1];
87  *mBuf |= v << (mBitPos + 1 - numBits);
88  if( (mBitPos -= numBits) < 0 ){
89  if( *mBuf == 0xff ){
90  IncBuf();
91  *mBuf = 0;
92  }
93  IncBuf();
94  mBitPos = 7;
95  }
96 }
void G4OutBitStream::SetWord ( u_int  dat)

Definition at line 144 of file G4RTOutBitStream.cc.

References FullBit(), IncBuf(), mBuf, and mWriteFlag.

Referenced by G4JpegCoder::WriteHeader().

145 {
146  if( mWriteFlag ){
147  FullBit();
148  *mBuf = (dat >> 8) & 0xff;
149  IncBuf();
150  *mBuf = dat & 0xff;
151  IncBuf();
152  return;
153  }
154  throw( G4BufferError( "SetWord" ) );
155 }

Field Documentation

int G4OutBitStream::mBitPos
protected

Definition at line 62 of file G4RTOutBitStream.hh.

Referenced by FullBit(), G4OutBitStream(), Set8Bits(), SetBits2Byte(), and SetFewBits().

u_char* G4OutBitStream::mBuf
protected
u_char* G4OutBitStream::mEndOfBuf
protected

Definition at line 61 of file G4RTOutBitStream.hh.

Referenced by CopyByte(), G4OutBitStream(), and IncBuf().

u_char* G4OutBitStream::mHeadOfBuf
protected

Definition at line 55 of file G4RTOutBitStream.hh.

Referenced by G4OutBitStream(), and GetStreamAddress().

int G4OutBitStream::mWriteFlag
protected

Definition at line 63 of file G4RTOutBitStream.hh.

Referenced by G4OutBitStream(), IncBuf(), SetByte(), and SetWord().


The documentation for this class was generated from the following files: