Adds a range coder call to encode a single bit with arbitrary probability

This commit is contained in:
Jean-Marc Valin 2010-05-27 16:23:52 -04:00
parent c4ac57023c
commit 8035b6589d
4 changed files with 35 additions and 0 deletions

View file

@ -111,3 +111,21 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){
return t;
}
}
/* The probability of having a "one" is given in 1/256 */
int ec_dec_bit_prob(ec_dec *_this,int _prob)
{
int val;
int fl=0, fh=256-_prob;
val = ec_decode_bin(_this, 8);
if (val >= fh)
{
val = 1;
fl=fh;
fh=256;
} else {
val = 0;
}
ec_dec_update(_this,fl,fh,256);
return val;
}

View file

@ -111,6 +111,9 @@ ec_uint32 ec_dec_bits(ec_dec *_this,int _ftb);
Return: The decoded bits.*/
ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft);
/* Decode a bit that has a _prob/256 probability of being a one */
int ec_dec_bit_prob(ec_dec *_this,int _prob);
/*Returns the number of bits "used" by the decoded symbols so far.
The actual number of bits may be larger, due to rounding to whole bytes, or
smaller, due to trailing zeros that were be stripped, so this is not an

View file

@ -101,3 +101,14 @@ void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){
}
}
/* The probability of having a "one" is given in 1/256 */
void ec_enc_bit_prob(ec_enc *_this,int val,int _prob)
{
int fl=0, fh=256-_prob;
if (val)
{
fl=fh;
fh=256;
}
ec_encode_bin(_this,fl,fh,8);
}

View file

@ -91,6 +91,9 @@ void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,int _ftb);
This must be at least one, and no more than 2**32-1.*/
void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft);
/* Encode a bit that has a _prob/256 probability of being a one */
void ec_enc_bit_prob(ec_enc *_this,int val,int _prob);
/*Returns the number of bits "used" by the encoded symbols so far.
The actual number of bits may be larger, due to rounding to whole bytes, or
smaller, due to trailing zeros that can be stripped, so this is not an