Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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::G4OutBitStream ( int  size)

Definition at line 38 of file G4RTOutBitStream.cc.

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::~G4OutBitStream ( )

Definition at line 55 of file G4RTOutBitStream.cc.

56{
57 delete mBuf;
58}

Member Function Documentation

◆ CopyByte()

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

Definition at line 158 of file G4RTOutBitStream.cc.

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

Referenced by G4JpegCoder::WriteHeader().

◆ FullBit()

void G4OutBitStream::FullBit ( void  )
protected

Definition at line 125 of file G4RTOutBitStream.cc.

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

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

◆ GetStreamAddress()

u_char * G4OutBitStream::GetStreamAddress ( void  )
inline

Definition at line 54 of file G4RTOutBitStream.hh.

54{return mHeadOfBuf;};

Referenced by G4JpegCoder::GetJpegData().

◆ GetStreamSize()

int G4OutBitStream::GetStreamSize ( void  )
inline

Definition at line 55 of file G4RTOutBitStream.hh.

55{return mBuf - mHeadOfBuf;};

Referenced by G4JpegCoder::GetJpegData().

◆ IncBuf()

void G4OutBitStream::IncBuf ( void  )
protected

Definition at line 61 of file G4RTOutBitStream.cc.

62{
63 if( ++mBuf >= mEndOfBuf )
64 mWriteFlag = 0;
65}

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

◆ Set8Bits()

void G4OutBitStream::Set8Bits ( u_char  v,
int  numBits 
)
protected

Definition at line 115 of file G4RTOutBitStream.cc.

116{
117 if( mBitPos + 1 >= numBits )
118 SetFewBits( (u_char)v, numBits );
119 else
120 SetBits2Byte( (u_char)v, numBits );
121}
void SetBits2Byte(u_char v, int numBits)

Referenced by SetBits().

◆ SetBits()

void G4OutBitStream::SetBits ( int  v,
int  numBits 
)

Definition at line 70 of file G4RTOutBitStream.cc.

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}
void Set8Bits(u_char v, int numBits)

Referenced by G4JpegCoder::CodeHuffman().

◆ SetBits2Byte()

void G4OutBitStream::SetBits2Byte ( u_char  v,
int  numBits 
)
protected

Definition at line 99 of file G4RTOutBitStream.cc.

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}

Referenced by Set8Bits().

◆ SetByte()

void G4OutBitStream::SetByte ( u_char  dat)

Definition at line 132 of file G4RTOutBitStream.cc.

133{
134 if( mWriteFlag ){
135 FullBit();
136 *mBuf = dat;
137 IncBuf();
138 return;
139 }
140 throw( G4BufferError( "SetByte" ) );
141}

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

◆ SetFewBits()

void G4OutBitStream::SetFewBits ( u_char  v,
int  numBits 
)
protected

Definition at line 84 of file G4RTOutBitStream.cc.

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}

Referenced by FullBit(), and Set8Bits().

◆ SetWord()

void G4OutBitStream::SetWord ( u_int  dat)

Definition at line 144 of file G4RTOutBitStream.cc.

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}

Referenced by G4JpegCoder::WriteHeader().

Member Data Documentation

◆ mBitPos

int G4OutBitStream::mBitPos
protected

Definition at line 62 of file G4RTOutBitStream.hh.

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

◆ mBuf

u_char* G4OutBitStream::mBuf
protected

◆ mEndOfBuf

u_char* G4OutBitStream::mEndOfBuf
protected

Definition at line 61 of file G4RTOutBitStream.hh.

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

◆ mHeadOfBuf

u_char* G4OutBitStream::mHeadOfBuf
protected

Definition at line 59 of file G4RTOutBitStream.hh.

Referenced by G4OutBitStream(), GetStreamAddress(), and GetStreamSize().

◆ mWriteFlag

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: