

//#include "ssc_types.h"
#include "ssc_defines.h"

#if !defined(_entcode_H)
# define _entcode_H (1)


# include "rc_intrinsic.h"


typedef unsigned int           ec_window;
typedef struct ec_ctx         ec_ctx;


typedef struct ec_ctx         ec_dec;

# define EC_WINDOW_SIZE ((int)sizeof(ec_window)*CHAR_BIT)

/*The number of bits to use for the range-coded part of unsigned integers.*/
# define EC_UINT_BITS   (8)

/*The resolution of fractional-precision bit usage measurements, i.e.,
   3 => 1/8th bits.*/
# define BITRES 3


struct ec_ctx{

   unsigned char *buf;
   unsigned int    storage;
   unsigned int    end_offs;
   ec_window      end_window;
   int            nend_bits;
   int            nbits_total;
   unsigned int    offs;
   unsigned int    rng;
   unsigned int    val;
   unsigned int    ext;
   int            rem;
   short            error;
};




static SSC_INLINE short ec_get_error(ec_ctx *_this){
  return _this->error;
}


static SSC_INLINE int ec_tell(ec_ctx *_this){
  return _this->nbits_total-EC_ILOG(_this->rng);
}


unsigned int ec_tell_frac(ec_ctx *_this);

#endif
