forked from hxim/paq8px
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArithmeticEncoder.hpp
More file actions
27 lines (24 loc) · 854 Bytes
/
ArithmeticEncoder.hpp
File metadata and controls
27 lines (24 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef PAQ8PX_ARITHMETICENCODER_HPP
#define PAQ8PX_ARITHMETICENCODER_HPP
#include "file/FileDisk.hpp"
class ArithmeticEncoder {
public:
ArithmeticEncoder(File* archive);
constexpr static int PRECISION = 31; //31 bit precision
static_assert(PRECISION < 32, "Arithmetic encoder supports max 31 bits of probability precision");
uint32_t x1, x2; /**< Range, initially [0, 1), scaled by 2^32 */
uint32_t x; /**< Decompress mode: last 4 input bytes of archive */
uint32_t pending_bits;
uint8_t B; /**< a byte from the archive */
uint32_t bits_in_B;
File *archive; /**< Compressed data file */
void prefetch();
void flush();
void encodeBit(uint32_t p, int bit);
int decodeBit(uint32_t p);
private:
int bit_read();
void bit_write(int bit);
void bit_write_with_pending(const int bit);
};
#endif //PAQ8PX_ARITHMETICENCODER_HPP