-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrcencoder.inl
40 lines (37 loc) · 927 Bytes
/
rcencoder.inl
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
// The static for loops below enable unrolling or even elimination
// of otherwise data dependent loops for basic integer types. Here
// 'for () if (c)' replaces 'while (c)', and we (safely) assume that
// n does not exceed the number of bits in a UINT.
template <typename UINT>
inline void RCencoder::encode(UINT s, uint n)
{
for (uint i = 1; i < (uint)sizeof(s) / 2; i++)
if (n > 16) {
encode_shift(s & 0xffff, 16);
s >>= 16;
n -= 16;
}
encode_shift(static_cast<uint>(s), n);
}
template <typename UINT>
inline void RCencoder::encode(UINT s, UINT l, UINT h)
{
s -= l;
h -= l;
for (uint i = 1; i < (uint)sizeof(s) / 2; i++)
if ((h >> 16)) {
encode_shift(s & 0xffff, 16);
s >>= 16;
h >>= 16;
h++;
}
encode_ratio(s, h);
}
// output n bytes
inline void RCencoder::put(uint n)
{
for (uint i = 0; i < n; i++) {
putbyte(low >> 24);
low <<= 8;
}
}