_this->end_offs=0;
_this->end_window=0;
_this->nend_bits=0;
+ /*This is the offset from which ec_tell() will subtract partial bits.
+ The final value after the ec_dec_normalize() call will be the same as in
+ the encoder, but we have to compensate for the bits that are added there.*/
+ _this->nbits_total=EC_CODE_BITS+1
+ -((EC_CODE_BITS-EC_CODE_EXTRA)/EC_SYM_BITS)*EC_SYM_BITS;
_this->offs=0;
_this->rng=1U<<EC_CODE_EXTRA;
_this->rem=ec_read_byte(_this);
_this->error=0;
/*Normalize the interval.*/
ec_dec_normalize(_this);
- /*This is the offset from which ec_tell() will subtract partial bits.
- This must be after the initial ec_dec_normalize(), or you will have to
- compensate for the bits that are read there.*/
- _this->nbits_total=EC_CODE_BITS+1;
}
unsigned ec_decode(ec_dec *_this,unsigned _ft){
have been processed by the decoder so far in the variable nbits_total,
including the (possibly fractional) number of bits that are currently
buffered, but not consumed, inside the range coder.
-nbits_total is initialized to 33 just after the initial range renormalization
- process completes (or equivalently, it can be initialized to 9 before the
+nbits_total is initialized to 9 just before the initial range renormalization
+ process completes (or equivalently, it can be initialized to 33 after the
first renormalization).
The extra two bits over the actual amount buffered by the range coder
guarantees that it is an upper bound and that there is enough room for the