forked from hxim/paq8px
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IndirectMap.cpp
48 lines (42 loc) · 1.33 KB
/
IndirectMap.cpp
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
#include "IndirectMap.hpp"
#include "Stretch.hpp"
IndirectMap::IndirectMap(const Shared* const sh, const int bitsOfContext, const int inputBits, const int scale, const int limit) :
shared(sh), data((UINT64_C(1) << bitsOfContext) * ((UINT64_C(1) << inputBits) - 1)),
sm {sh, 1, 256, 1023, StateMapType::BitHistory}, mask((1 << bitsOfContext) - 1),
maskBits(bitsOfContext), stride((1 << inputBits) - 1), bTotal(inputBits), scale(scale) {
assert(inputBits > 0 && inputBits <= 8);
assert(bitsOfContext + inputBits <= 24);
cp = nullptr;
setDirect(0);
}
void IndirectMap::setDirect(const uint32_t ctx) {
context = (ctx & mask) * stride;
bCount = b = 0;
}
void IndirectMap::set(const uint64_t ctx) {
context = (finalize64(ctx, maskBits)) * stride;
bCount = b = 0;
}
void IndirectMap::update() {
INJECT_SHARED_y
StateTable::update(cp, y, rnd);
b += static_cast<uint32_t>((y != 0) && b > 0);
}
void IndirectMap::setScale(const int Scale) { this->scale = Scale; }
void IndirectMap::mix(Mixer &m) {
shared->GetUpdateBroadcaster()->subscribe(this);
cp = &data[context + b];
const uint8_t state = *cp;
if (state == 0) {
m.add(0);
m.add(0);
}
else {
const int p1 = sm.p1(state);
m.add((stretch(p1) * scale) >> 8);
m.add(((p1 - 2048) * scale) >> 9);
}
bCount++;
b += b + 1;
assert(bCount <= bTotal);
}