Simplifies convoluted raw bits calls.
This commit is contained in:
parent
f9fdbffb72
commit
aaedf1711c
6 changed files with 7 additions and 39 deletions
|
@ -60,23 +60,6 @@ int ec_byte_read1(ec_byte_buffer *_b){
|
|||
else return *(_b->ptr++);
|
||||
}
|
||||
|
||||
|
||||
ec_uint32 ec_dec_bits(ec_dec *_this,int _ftb){
|
||||
ec_uint32 t;
|
||||
unsigned s;
|
||||
t=0;
|
||||
while(_ftb>EC_UNIT_BITS){
|
||||
s=ec_decode_raw(_this,EC_UNIT_BITS);
|
||||
/*ec_dec_update(_this,s,s+1,EC_UNIT_MASK+1);*/
|
||||
t=t<<EC_UNIT_BITS|s;
|
||||
_ftb-=EC_UNIT_BITS;
|
||||
}
|
||||
s=ec_decode_raw(_this,_ftb);
|
||||
/*ec_dec_update(_this,s,s+1,ft);*/
|
||||
t=t<<_ftb|s;
|
||||
return t;
|
||||
}
|
||||
|
||||
ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){
|
||||
ec_uint32 t;
|
||||
unsigned ft;
|
||||
|
@ -93,7 +76,7 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){
|
|||
s=ec_decode(_this,ft);
|
||||
ec_dec_update(_this,s,s+1,ft);
|
||||
t=t<<EC_UNIT_BITS|s;
|
||||
t = t<<ftb|ec_dec_bits(_this,ftb);
|
||||
t = t<<ftb|ec_dec_bits(_this,ftb&(1<<ftb)-1);
|
||||
if (t>_ft)
|
||||
{
|
||||
_this->error |= 1;
|
||||
|
|
|
@ -80,7 +80,6 @@ void ec_dec_init(ec_dec *_this,ec_byte_buffer *_buf);
|
|||
will fall in the range [fl,fh).*/
|
||||
unsigned ec_decode(ec_dec *_this,unsigned _ft);
|
||||
unsigned ec_decode_bin(ec_dec *_this,unsigned _bits);
|
||||
unsigned ec_decode_raw(ec_dec *_this,unsigned bits);
|
||||
|
||||
/*Advance the decoder past the next symbol using the frequency information the
|
||||
symbol was encoded with.
|
||||
|
@ -103,7 +102,7 @@ void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,
|
|||
_ftb: The number of bits to extract.
|
||||
This must be at least one, and no more than 32.
|
||||
Return: The decoded bits.*/
|
||||
ec_uint32 ec_dec_bits(ec_dec *_this,int _ftb);
|
||||
ec_uint32 ec_dec_bits(ec_dec *_this,unsigned _ftb);
|
||||
/*Extracts a raw unsigned integer with a non-power-of-2 range from the stream.
|
||||
The bits must have been encoded with ec_enc_uint().
|
||||
No call to ec_dec_update() is necessary after this call.
|
||||
|
|
|
@ -70,20 +70,6 @@ int ec_byte_write_at_end(ec_byte_buffer *_b,unsigned _value){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,int _ftb){
|
||||
unsigned fl;
|
||||
unsigned ft;
|
||||
while(_ftb>EC_UNIT_BITS){
|
||||
_ftb-=EC_UNIT_BITS;
|
||||
fl=(unsigned)(_fl>>_ftb)&EC_UNIT_MASK;
|
||||
ec_encode_raw(_this,fl,fl+1,EC_UNIT_BITS);
|
||||
}
|
||||
ft=1<<_ftb;
|
||||
fl=(unsigned)_fl&ft-1;
|
||||
ec_encode_raw(_this,fl,fl+1,_ftb);
|
||||
}
|
||||
|
||||
void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){
|
||||
unsigned ft;
|
||||
unsigned fl;
|
||||
|
@ -97,7 +83,7 @@ void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){
|
|||
ft=(_ft>>ftb)+1;
|
||||
fl=(unsigned)(_fl>>ftb);
|
||||
ec_encode(_this,fl,fl+1,ft);
|
||||
ec_enc_bits(_this,_fl,ftb);
|
||||
ec_enc_bits(_this,_fl&(1<<ftb)-1,ftb);
|
||||
} else {
|
||||
ec_encode(_this,_fl,_fl+1,_ft+1);
|
||||
}
|
||||
|
|
|
@ -81,12 +81,12 @@ void ec_enc_init(ec_enc *_this,ec_byte_buffer *_buf);
|
|||
_ft: The sum of the frequencies of all the symbols*/
|
||||
void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft);
|
||||
void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits);
|
||||
void ec_encode_raw(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits);
|
||||
/*Encodes a sequence of raw bits in the stream.
|
||||
_fl: The bits to encode.
|
||||
_ftb: The number of bits to encode.
|
||||
This must be at least one, and no more than 32.*/
|
||||
void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,int _ftb);
|
||||
void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,unsigned _ftb);
|
||||
|
||||
/*Encodes a raw unsigned integer in the stream.
|
||||
_fl: The integer to encode.
|
||||
_ft: The number of integers that can be encoded (one more than the max).
|
||||
|
|
|
@ -162,7 +162,7 @@ unsigned ec_decode_bin(ec_dec *_this,unsigned _bits){
|
|||
return (1<<_bits)-EC_MINI(s+1,1<<_bits);
|
||||
}
|
||||
|
||||
unsigned ec_decode_raw(ec_dec *_this,unsigned bits){
|
||||
unsigned ec_dec_bits(ec_dec *_this,unsigned bits){
|
||||
unsigned value=0;
|
||||
int count=0;
|
||||
_this->nb_end_bits += bits;
|
||||
|
|
|
@ -153,7 +153,7 @@ void ec_enc_bit_prob(ec_enc *_this,int _val,unsigned _prob){
|
|||
ec_enc_normalize(_this);
|
||||
}
|
||||
|
||||
void ec_encode_raw(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits){
|
||||
void ec_enc_bits(ec_enc *_this,unsigned _fl,unsigned bits){
|
||||
_this->nb_end_bits += bits;
|
||||
while (bits >= _this->end_bits_left)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue