Documentation fixes and a couple of other minor edits.
This commit is contained in:
parent
9d35ccdaea
commit
d710177d0a
7 changed files with 37 additions and 26 deletions
|
@ -49,6 +49,7 @@ unsigned ec_decode(ec_dec *_this,unsigned _ft);
|
||||||
_fl: The cumulative frequency of all symbols that come before the symbol
|
_fl: The cumulative frequency of all symbols that come before the symbol
|
||||||
decoded.
|
decoded.
|
||||||
_fh: The cumulative frequency of all symbols up to and including the symbol
|
_fh: The cumulative frequency of all symbols up to and including the symbol
|
||||||
|
decoded.
|
||||||
Together with _fl, this defines the range [_fl,_fh) in which the value
|
Together with _fl, this defines the range [_fl,_fh) in which the value
|
||||||
returned above must fall.
|
returned above must fall.
|
||||||
_ft: The total frequency of the symbols in the alphabet the symbol decoded
|
_ft: The total frequency of the symbols in the alphabet the symbol decoded
|
||||||
|
|
|
@ -15,7 +15,7 @@ struct ec_enc{
|
||||||
ec_byte_buffer *buf;
|
ec_byte_buffer *buf;
|
||||||
/*A buffered output symbol, awaiting carry propagation.*/
|
/*A buffered output symbol, awaiting carry propagation.*/
|
||||||
int rem;
|
int rem;
|
||||||
/*Number of extra carry propogating symbols.*/
|
/*Number of extra carry propagating symbols.*/
|
||||||
size_t ext;
|
size_t ext;
|
||||||
/*The number of values in the current range.*/
|
/*The number of values in the current range.*/
|
||||||
ec_uint32 rng;
|
ec_uint32 rng;
|
||||||
|
@ -34,10 +34,14 @@ void ec_enc_init(ec_enc *_this,ec_byte_buffer *_buf);
|
||||||
It is allowable to change the frequency information, or even the entire
|
It is allowable to change the frequency information, or even the entire
|
||||||
source alphabet, so long as the decoder can tell from the context of the
|
source alphabet, so long as the decoder can tell from the context of the
|
||||||
previously encoded information that it is supposed to do so as well.
|
previously encoded information that it is supposed to do so as well.
|
||||||
_fl: The sum of the frequencies of symbols before the one to be encoded.
|
_fl: The cumulative frequency of all symbols that come before the one to be
|
||||||
_fs: The frequency of the symbol to be encoded.
|
encoded.
|
||||||
|
_fh: The cumulative frequency of all symbols up to and including the one to
|
||||||
|
be encoded.
|
||||||
|
Together with _fl, this defines the range [_fl,_fh) in which the
|
||||||
|
decoded value will fall.
|
||||||
_ft: The sum of the frequencies of all the symbols*/
|
_ft: The sum of the frequencies of all the symbols*/
|
||||||
void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fs,unsigned _ft);
|
void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft);
|
||||||
/*Encodes a sequence of raw bits in the stream.
|
/*Encodes a sequence of raw bits in the stream.
|
||||||
_fl: The bits to encode.
|
_fl: The bits to encode.
|
||||||
_ftb: The number of bits to encode.
|
_ftb: The number of bits to encode.
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
# define EC_CODE_TOP (1U<<EC_CODE_BITS-1)
|
# define EC_CODE_TOP (1U<<EC_CODE_BITS-1)
|
||||||
/*Low-order bit of the high-order range symbol.*/
|
/*Low-order bit of the high-order range symbol.*/
|
||||||
# define EC_CODE_BOT (EC_CODE_TOP>>EC_SYM_BITS)
|
# define EC_CODE_BOT (EC_CODE_TOP>>EC_SYM_BITS)
|
||||||
/*Code for which propogating carries are possible.*/
|
/*Code for which propagating carries are possible.*/
|
||||||
# define EC_CODE_CARRY (EC_SYM_MAX<<EC_CODE_SHIFT)
|
# define EC_CODE_CARRY (EC_SYM_MAX<<EC_CODE_SHIFT)
|
||||||
/*The number of bits available for the last, partial symbol in the code field.*/
|
/*The number of bits available for the last, partial symbol in the code field.*/
|
||||||
# define EC_CODE_EXTRA ((EC_CODE_BITS-2)%EC_SYM_BITS+1)
|
# define EC_CODE_EXTRA ((EC_CODE_BITS-2)%EC_SYM_BITS+1)
|
||||||
|
|
|
@ -90,7 +90,7 @@
|
||||||
|
|
||||||
@PHDTHESIS{Pas76,
|
@PHDTHESIS{Pas76,
|
||||||
author="Richard Clark Pasco",
|
author="Richard Clark Pasco",
|
||||||
title="Sorce coding algorithms for fast data compression",
|
title="Source coding algorithms for fast data compression",
|
||||||
school="Dept. of Electrical Engineering, Stanford University",
|
school="Dept. of Electrical Engineering, Stanford University",
|
||||||
address="Stanford, CA",
|
address="Stanford, CA",
|
||||||
month=May,
|
month=May,
|
||||||
|
@ -159,8 +159,8 @@ static int ec_dec_in(ec_dec *_this){
|
||||||
else return ret;
|
else return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Normalizes the contents of low and rng so that rng is contained in the
|
/*Normalizes the contents of dif and rng so that rng lies entirely in the
|
||||||
high-order symbol of low.*/
|
high-order symbol.*/
|
||||||
static void ec_dec_normalize(ec_dec *_this){
|
static void ec_dec_normalize(ec_dec *_this){
|
||||||
/*If the range is too small, rescale it and input some bits.*/
|
/*If the range is too small, rescale it and input some bits.*/
|
||||||
while(_this->rng<=EC_CODE_BOT){
|
while(_this->rng<=EC_CODE_BOT){
|
||||||
|
@ -176,7 +176,7 @@ static void ec_dec_normalize(ec_dec *_this){
|
||||||
/*dif can never be larger than EC_CODE_TOP.
|
/*dif can never be larger than EC_CODE_TOP.
|
||||||
This is equivalent to the slightly more readable:
|
This is equivalent to the slightly more readable:
|
||||||
if(_this->dif>EC_CODE_TOP)_this->dif-=EC_CODE_TOP;*/
|
if(_this->dif>EC_CODE_TOP)_this->dif-=EC_CODE_TOP;*/
|
||||||
_this->dif^=(_this->dif&_this->dif-1)&EC_CODE_TOP;
|
_this->dif^=_this->dif&_this->dif-1&EC_CODE_TOP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ int ec_dec_done(ec_dec *_this){
|
||||||
msk=EC_CODE_TOP-1;
|
msk=EC_CODE_TOP-1;
|
||||||
do{
|
do{
|
||||||
msk>>=1;
|
msk>>=1;
|
||||||
end=(low+msk)&~msk|msk+1;
|
end=low+msk&~msk|msk+1;
|
||||||
}
|
}
|
||||||
while(end-low>=_this->rng);
|
while(end-low>=_this->rng);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,15 +41,18 @@
|
||||||
|
|
||||||
|
|
||||||
/*Outputs a symbol, with a carry bit.
|
/*Outputs a symbol, with a carry bit.
|
||||||
If there is a potential to propogate a carry over several symbols, they are
|
If there is a potential to propagate a carry over several symbols, they are
|
||||||
buffered until it can be determined whether or not an actual carry will
|
buffered until it can be determined whether or not an actual carry will
|
||||||
occur.
|
occur.
|
||||||
If the counter for the buffered symbols overflows, then the range is
|
If the counter for the buffered symbols overflows, then the stream becomes
|
||||||
truncated to force a carry to occur, towards whichever side maximizes the
|
undecodable.
|
||||||
remaining range.*/
|
This gives a theoretical limit of a few billion symbols in a single packet on
|
||||||
|
32-bit systems.
|
||||||
|
The alternative is to truncate the range in order to force a carry, but
|
||||||
|
requires similar carry tracking in the decoder, needlessly slowing it down.*/
|
||||||
static void ec_enc_carry_out(ec_enc *_this,int _c){
|
static void ec_enc_carry_out(ec_enc *_this,int _c){
|
||||||
if(_c!=EC_SYM_MAX){
|
if(_c!=EC_SYM_MAX){
|
||||||
/*No further carry propogation possible, flush buffer.*/
|
/*No further carry propagation possible, flush buffer.*/
|
||||||
int carry;
|
int carry;
|
||||||
carry=_c>>EC_SYM_BITS;
|
carry=_c>>EC_SYM_BITS;
|
||||||
/*Don't output a byte on the first write.
|
/*Don't output a byte on the first write.
|
||||||
|
@ -129,7 +132,7 @@ void ec_enc_done(ec_enc *_this){
|
||||||
msk=EC_CODE_TOP-1;
|
msk=EC_CODE_TOP-1;
|
||||||
do{
|
do{
|
||||||
msk>>=1;
|
msk>>=1;
|
||||||
end=(_this->low+msk)&~msk|msk+1;
|
end=_this->low+msk&~msk|msk+1;
|
||||||
}
|
}
|
||||||
while(end-_this->low>=_this->rng);
|
while(end-_this->low>=_this->rng);
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@
|
||||||
|
|
||||||
@PHDTHESIS{Pas76,
|
@PHDTHESIS{Pas76,
|
||||||
author="Richard Clark Pasco",
|
author="Richard Clark Pasco",
|
||||||
title="Sorce coding algorithms for fast data compression",
|
title="Source coding algorithms for fast data compression",
|
||||||
school="Dept. of Electrical Engineering, Stanford University",
|
school="Dept. of Electrical Engineering, Stanford University",
|
||||||
address="Stanford, CA",
|
address="Stanford, CA",
|
||||||
month=May,
|
month=May,
|
||||||
|
@ -159,8 +159,8 @@ static int ec_dec_in(ec_dec *_this){
|
||||||
else return ret;
|
else return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Normalizes the contents of low and rng so that rng is contained in the
|
/*Normalizes the contents of dif and rng so that rng lies entirely in the
|
||||||
high-order symbol of low.*/
|
high-order symbol.*/
|
||||||
static void ec_dec_normalize(ec_dec *_this){
|
static void ec_dec_normalize(ec_dec *_this){
|
||||||
/*If the range is too small, rescale it and input some bits.*/
|
/*If the range is too small, rescale it and input some bits.*/
|
||||||
while(_this->rng<=EC_CODE_BOT){
|
while(_this->rng<=EC_CODE_BOT){
|
||||||
|
@ -176,7 +176,7 @@ static void ec_dec_normalize(ec_dec *_this){
|
||||||
/*dif can never be larger than EC_CODE_TOP.
|
/*dif can never be larger than EC_CODE_TOP.
|
||||||
This is equivalent to the slightly more readable:
|
This is equivalent to the slightly more readable:
|
||||||
if(_this->dif>EC_CODE_TOP)_this->dif-=EC_CODE_TOP;*/
|
if(_this->dif>EC_CODE_TOP)_this->dif-=EC_CODE_TOP;*/
|
||||||
_this->dif^=(_this->dif&_this->dif-1)&EC_CODE_TOP;
|
_this->dif^=_this->dif&_this->dif-1&EC_CODE_TOP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,15 +41,18 @@
|
||||||
|
|
||||||
|
|
||||||
/*Outputs a symbol, with a carry bit.
|
/*Outputs a symbol, with a carry bit.
|
||||||
If there is a potential to propogate a carry over several symbols, they are
|
If there is a potential to propagate a carry over several symbols, they are
|
||||||
buffered until it can be determined whether or not an actual carry will
|
buffered until it can be determined whether or not an actual carry will
|
||||||
occur.
|
occur.
|
||||||
If the counter for the buffered symbols overflows, then the range is
|
If the counter for the buffered symbols overflows, then the stream becomes
|
||||||
truncated to force a carry to occur, towards whichever side maximizes the
|
undecodable.
|
||||||
remaining range.*/
|
This gives a theoretical limit of a few billion symbols in a single packet on
|
||||||
|
32-bit systems.
|
||||||
|
The alternative is to truncate the range in order to force a carry, but
|
||||||
|
requires similar carry tracking in the decoder, needlessly slowing it down.*/
|
||||||
static void ec_enc_carry_out(ec_enc *_this,int _c){
|
static void ec_enc_carry_out(ec_enc *_this,int _c){
|
||||||
if(_c!=EC_SYM_MAX){
|
if(_c!=EC_SYM_MAX){
|
||||||
/*No further carry propogation possible, flush buffer.*/
|
/*No further carry propagation possible, flush buffer.*/
|
||||||
int carry;
|
int carry;
|
||||||
carry=_c>>EC_SYM_BITS;
|
carry=_c>>EC_SYM_BITS;
|
||||||
/*Don't output a byte on the first write.
|
/*Don't output a byte on the first write.
|
||||||
|
@ -110,7 +113,7 @@ void ec_enc_done(ec_enc *_this){
|
||||||
msk=EC_CODE_TOP-1;
|
msk=EC_CODE_TOP-1;
|
||||||
do{
|
do{
|
||||||
msk>>=1;
|
msk>>=1;
|
||||||
end=(_this->low+msk)&~msk|msk+1;
|
end=_this->low+msk&~msk|msk+1;
|
||||||
}
|
}
|
||||||
while(end-_this->low>=_this->rng);
|
while(end-_this->low>=_this->rng);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue