-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrcencoder.h
52 lines (37 loc) · 1021 Bytes
/
rcencoder.h
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef RC_ENCODER_H
#define RC_ENCODER_H
#include "types.h"
#include "rcmodel.h"
class RCencoder {
public:
RCencoder() : error(false), low(0), range(-1u) {}
virtual ~RCencoder() {}
// finish encoding
void finish();
// encode a bit s
void encode(bool s);
// encode a number s : 0 <= s < 2^n
template <typename UINT>
void encode(UINT s, uint n);
// encode a number s : l <= s < h
template <typename UINT>
void encode(UINT s, UINT l, UINT h);
// encode a symbol s using probability modeling
void encode(uint s, RCmodel* rm);
// virtual function for writing byte stream
virtual void putbyte(uint byte) = 0;
// flush out any buffered bytes
virtual void flush() {}
// number of bytes written
virtual size_t bytes() const = 0;
bool error;
private:
void encode_shift(uint s, uint n);
void encode_ratio(uint s, uint n);
void put(uint n);
void normalize();
uint low; // low end of interval
uint range; // length of interval
};
#include "rcencoder.inl"
#endif