Blame libcelt/entdec.h

Packit 664db3
#if !defined(_entdec_H)
Packit 664db3
# define _entdec_H (1)
Packit 664db3
# include "entcode.h"
Packit 664db3
Packit 664db3
Packit 664db3
Packit 664db3
typedef struct ec_dec ec_dec;
Packit 664db3
Packit 664db3
Packit 664db3
Packit 664db3
/*The entropy decoder.*/
Packit 664db3
struct ec_dec{
Packit 664db3
   /*The buffer to decode.*/
Packit 664db3
   ec_byte_buffer *buf;
Packit 664db3
   /*The remainder of a buffered input symbol.*/
Packit 664db3
   int             rem;
Packit 664db3
   /*The number of values in the current range.*/
Packit 664db3
   ec_uint32       rng;
Packit 664db3
   /*The difference between the input value and the lowest value in the current
Packit 664db3
      range.*/
Packit 664db3
   ec_uint32       dif;
Packit 664db3
   /*Normalization factor.*/
Packit 664db3
   ec_uint32       nrm;
Packit 664db3
};
Packit 664db3
Packit 664db3
Packit 664db3
/*Initializes the decoder.
Packit 664db3
  _buf: The input buffer to use.
Packit 664db3
  Return: 0 on success, or a negative value on error.*/
Packit 664db3
void ec_dec_init(ec_dec *_this,ec_byte_buffer *_buf);
Packit 664db3
/*Calculates the cumulative frequency for the next symbol.
Packit 664db3
  This can then be fed into the probability model to determine what that
Packit 664db3
   symbol is, and the additional frequency information required to advance to
Packit 664db3
   the next symbol.
Packit 664db3
  This function cannot be called more than once without a corresponding call to
Packit 664db3
   ec_dec_update(), or decoding will not proceed correctly.
Packit 664db3
  _ft: The total frequency of the symbols in the alphabet the next symbol was
Packit 664db3
        encoded with.
Packit 664db3
  Return: A cumulative frequency representing the encoded symbol.
Packit 664db3
          If the cumulative frequency of all the symbols before the one that
Packit 664db3
           was encoded was fl, and the cumulative frequency of all the symbols
Packit 664db3
           up to and including the one encoded is fh, then the returned value
Packit 664db3
           will fall in the range [fl,fh).*/
Packit 664db3
unsigned ec_decode(ec_dec *_this,unsigned _ft);
Packit 664db3
unsigned ec_decode_bin(ec_dec *_this,unsigned bits);
Packit 664db3
/*Advance the decoder past the next symbol using the frequency information the
Packit 664db3
   symbol was encoded with.
Packit 664db3
  Exactly one call to ec_decode() must have been made so that all necessary
Packit 664db3
   intermediate calculations are performed.
Packit 664db3
  _fl:  The cumulative frequency of all symbols that come before the symbol
Packit 664db3
         decoded.
Packit 664db3
  _fh:  The cumulative frequency of all symbols up to and including the symbol
Packit 664db3
         decoded.
Packit 664db3
        Together with _fl, this defines the range [_fl,_fh) in which the value
Packit 664db3
         returned above must fall.
Packit 664db3
  _ft:  The total frequency of the symbols in the alphabet the symbol decoded
Packit 664db3
         was encoded in.
Packit 664db3
        This must be the same as passed to the preceding call to ec_decode().*/
Packit 664db3
void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,
Packit 664db3
 unsigned _ft);
Packit 664db3
/*Extracts a sequence of raw bits from the stream.
Packit 664db3
  The bits must have been encoded with ec_enc_bits().
Packit 664db3
  No call to ec_dec_update() is necessary after this call.
Packit 664db3
  _ftb: The number of bits to extract.
Packit 664db3
        This must be at least one, and no more than 32.
Packit 664db3
  Return: The decoded bits.*/
Packit 664db3
ec_uint32 ec_dec_bits(ec_dec *_this,int _ftb);
Packit 664db3
/*Extracts a sequence of raw bits from the stream.
Packit 664db3
  The bits must have been encoded with ec_enc_bits64().
Packit 664db3
  No call to ec_dec_update() is necessary after this call.
Packit 664db3
  _ftb: The number of bits to extract.
Packit 664db3
        This must be at least one, and no more than 64.
Packit 664db3
  Return: The decoded bits.*/
Packit 664db3
ec_uint64 ec_dec_bits64(ec_dec *_this,int _ftb);
Packit 664db3
/*Extracts a raw unsigned integer with a non-power-of-2 range from the stream.
Packit 664db3
  The bits must have been encoded with ec_enc_uint().
Packit 664db3
  No call to ec_dec_update() is necessary after this call.
Packit 664db3
  _ft: The number of integers that can be decoded (one more than the max).
Packit 664db3
       This must be at least one, and no more than 2**32-1.
Packit 664db3
  Return: The decoded bits.*/
Packit 664db3
ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft);
Packit 664db3
/*Extracts a raw unsigned integer with a non-power-of-2 range from the stream.
Packit 664db3
  The bits must have been encoded with ec_enc_uint64().
Packit 664db3
  No call to ec_dec_update() is necessary after this call.
Packit 664db3
  _ft: The number of integers that can be decoded (one more than the max).
Packit 664db3
       This must be at least one, and no more than 2**64-1.
Packit 664db3
  Return: The decoded bits.*/
Packit 664db3
ec_uint64 ec_dec_uint64(ec_dec *_this,ec_uint64 _ft);
Packit 664db3
Packit 664db3
/*Returns the number of bits "used" by the decoded symbols so far.
Packit 664db3
  The actual number of bits may be larger, due to rounding to whole bytes, or
Packit 664db3
   smaller, due to trailing zeros that were be stripped, so this is not an
Packit 664db3
   estimate of the true packet size.
Packit 664db3
  This same number can be computed by the encoder, and is suitable for making
Packit 664db3
   coding decisions.
Packit 664db3
  _b: The number of extra bits of precision to include.
Packit 664db3
      At most 16 will be accurate.
Packit 664db3
  Return: The number of bits scaled by 2**_b.
Packit 664db3
          This will always be slightly larger than the exact value (e.g., all
Packit 664db3
           rounding error is in the positive direction).*/
Packit 664db3
long ec_dec_tell(ec_dec *_this,int _b);
Packit 664db3
Packit 664db3
#endif