}
case seq_rle: {
// "RLE_Mode : it's a single code, repeated Number_of_Sequences times."
- const u8 symb = IO_read_bits(in, 8);
+ const u8 symb = IO_read_bytes(in, 1)[0];
FSE_init_dtable_rle(table, symb);
break;
}
#define UNALIGNED() ERROR("Attempting to operate on a non-byte aligned stream")
/// Reads `num` bits from a bitstream, and updates the internal offset
static inline u64 IO_read_bits(istream_t *const in, const int num) {
- if (num > 64) {
- return -1;
+ if (num > 64 || num <= 0) {
+ ERROR("Attempt to read an invalid number of bits");
}
const size_t bytes = (num + in->bit_offset + 7) / 8;
static inline u64 read_bits_LE(const u8 *src, const int num,
const size_t offset) {
if (num > 64) {
- return -1;
+ ERROR("Attempt to read an invalid number of bits");
}
// Skip over bytes that aren't in range
return total_output;
}
+/// Initializes a Huffman table using canonical Huffman codes
+/// For more explanation on canonical Huffman codes see
+/// http://www.cs.uofs.edu/~mccloske/courses/cmps340/huff_canonical_dec2015.html
+/// Codes within a level are allocated in symbol order (i.e. smaller symbols get
+/// earlier codes)
static void HUF_init_dtable(HUF_dtable *const table, const u8 *const bits,
const int num_symbs) {
memset(table, 0, sizeof(HUF_dtable));
/******* END HUFFMAN PRIMITIVES ***********************************************/
/******* FSE PRIMITIVES *******************************************************/
+/// For more description of FSE see
+/// https://github.com/Cyan4973/FiniteStateEntropy/
+
/// Allow a symbol to be decoded without updating state
static inline u8 FSE_peek_symbol(const FSE_dtable *const dtable,
const u16 state) {