blob: 35162b25e2815b3cdc460dc1411dc96cc3e296cd (
plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include "LenCoder.h"
using namespace NCompression;
using namespace NArithmetic;
namespace NLength {
void CEncoder::Init()
{
m_Choice.Init();
for (UINT32 aPosState = 0; aPosState < m_NumPosStates; aPosState++)
{
m_LowCoder[aPosState].Init();
m_MidCoder[aPosState].Init();
}
m_Choice2.Init();
m_HighCoder.Init();
}
void CEncoder::Encode(CMyRangeEncoder *aRangeEncoder, UINT32 aSymbol, UINT32 aPosState)
{
if(aSymbol < kNumLowSymbols)
{
m_Choice.Encode(aRangeEncoder, 0);
m_LowCoder[aPosState].Encode(aRangeEncoder, aSymbol);
}
else
{
aSymbol -= kNumLowSymbols;
m_Choice.Encode(aRangeEncoder, 1);
if(aSymbol < kNumMidSymbols)
{
m_Choice2.Encode(aRangeEncoder, 0);
m_MidCoder[aPosState].Encode(aRangeEncoder, aSymbol);
}
else
{
aSymbol -= kNumMidSymbols;
m_Choice2.Encode(aRangeEncoder, 1);
m_HighCoder.Encode(aRangeEncoder, aSymbol);
}
}
}
UINT32 CEncoder::GetPrice(UINT32 aSymbol, UINT32 aPosState) const
{
UINT32 aPrice = 0;
if(aSymbol < kNumLowSymbols)
{
aPrice += m_Choice.GetPrice(0);
aPrice += m_LowCoder[aPosState].GetPrice(aSymbol);
}
else
{
aSymbol -= kNumLowSymbols;
aPrice += m_Choice.GetPrice(1);
if(aSymbol < kNumMidSymbols)
{
aPrice += m_Choice2.GetPrice(0);
aPrice += m_MidCoder[aPosState].GetPrice(aSymbol);
}
else
{
aSymbol -= kNumMidSymbols;
aPrice += m_Choice2.GetPrice(1);
aPrice += m_HighCoder.GetPrice(aSymbol);
}
}
return aPrice;
}
}
|