46 #ifndef _ARITH_CODEC_H_ 47 #define _ARITH_CODEC_H_ 90 static const unsigned int lut[256];
123 void EncodeSymbol(
const bool symbol,
const int context_num);
125 void EncodeUInt(
const unsigned int value,
const int bin1,
const int max_bin);
127 void EncodeSInt(
const int value,
const int bin1,
const int max_bin);
143 unsigned int DecodeUInt(
const int bin1,
const int max_bin);
145 int DecodeSInt(
const int bin1,
const int max_bin);
214 const bool symbol = ( count >= range_x_prob );
258 const int info_ctx = (max_bin+1);
260 unsigned int value = 1;
264 if (bin<max_bin) bin+=1;
272 const int magnitude =
DecodeUInt(bin1, max_bin);
275 else value=magnitude;
333 const int bin1,
const int max_bin) {
334 const int value = (the_int+1);
335 const int info_ctx = (max_bin+1);
340 while (value>max_value) {
346 bool stop = (top_bit==1);
351 if ( bin < max_bin) bin+=1;
358 const int bin1,
const int max_bin) {
415 void Decompress(T & out_data,
const int num_bytes);
451 InitDecoder(num_bytes);
452 DoWorkDecode( out_data );
455 inline bool ArithCodecBase::InputBit()
457 if (m_input_bits_left == 0)
460 m_input_bits_left = 8;
464 return bool( ( (*m_data_ptr) >> m_input_bits_left ) & 1 );
Definition of class SequenceHeaderByteIO.
Definition: accessunit_byteio.h:51
int Compress(T &in_data)
Compresses the input and returns the number of bits written.
Definition: arith_codec.h:440
unsigned int DecodeUInt(const int bin1, const int max_bin)
Definition: arith_codec.h:257
Context()
Default Constructor.
Definition: arith_codec.h:93
void Decompress(T &out_data, const int num_bytes)
Decompresses the bitstream and writes into the output.
Definition: arith_codec.h:449
virtual void DoWorkDecode(T &out_data)=0
virtual decode-only functions
int m_underflow
Number of underflow bits.
Definition: arith_codec.h:185
static const unsigned int lut[256]
Definition: arith_codec.h:90
std::vector< Context > m_context_list
List of contexts.
Definition: arith_codec.h:148
void Update(bool symbol)
Updates context counts.
Definition: arith_codec.h:82
unsigned int m_range
Length of the current code range.
Definition: arith_codec.h:177
ArithCodecBase(ByteIO *p_byteio, size_t number_of_contexts)
Constructor.
virtual ~ArithCodecBase()
Destructor.
void InitDecoder(int num_bytes)
Initialise the Decoder.
bool InputBit()
Read in a bit of data.
Definition: arith_codec.h:455
virtual ~ArithCodec()
Destructor.
Definition: arith_codec.h:393
int DecodeSInt(const int bin1, const int max_bin)
Definition: arith_codec.h:270
void FlushEncoder()
flushes the output of the encoder.
bool DecodeSymbol(int context_num)
Decodes a symbol given a context number.
Definition: arith_codec.h:202
Definition: arith_codec.h:65
ArithCodec(ByteIO *p_byteio, size_t number_of_contexts)
Constructor for encoding.
Definition: arith_codec.h:434
char * m_decode_data_ptr
A pointer to the data for reading in.
Definition: arith_codec.h:188
int m_prob0
Definition: arith_codec.h:89
void EncodeUInt(const unsigned int value, const int bin1, const int max_bin)
Definition: arith_codec.h:332
void EncodeSInt(const int value, const int bin1, const int max_bin)
Definition: arith_codec.h:357
unsigned int m_code
The present input code.
Definition: arith_codec.h:197
ByteIO * m_byteio
Input/output stream of Dirac-format bytes.
Definition: arith_codec.h:180
Class ByteIO - top-level class for reading/writing bytes to a stream
Definition: byteio.h:72
unsigned int m_scount
Definition: arith_codec.h:171
Abstract binary arithmetic coding class.
Definition: arith_codec.h:374
int m_input_bits_left
The index of the bit of the byte being read.
Definition: arith_codec.h:194
virtual void DoWorkCode(T &in_data)=0
Does the work of actually coding the data.
unsigned int m_low_code
Start of the current code range.
Definition: arith_codec.h:174
ArithCodecBase & operator=(const ArithCodecBase &rhs)
private, bodyless copy operator=: class should not be assigned
void ReadAllData(int num_bytes)
Read all the data in.
unsigned int GetScaledProb0() const
Returns estimate of probability of 0 (false) scaled to 2**16.
Definition: arith_codec.h:79
void InitEncoder()
Initialises the Encoder.
Definition: arith_codec.h:95
char * m_data_ptr
A point to the byte currently being read.
Definition: arith_codec.h:191
void EncodeSymbol(const bool symbol, const int context_num)
encodes a symbol and writes to output
Definition: arith_codec.h:280
void WriteBit(const bool &bit)
Outputs a bit