Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
RishiRecon
GitHub Repository: RishiRecon/exploits
Path: blob/main/misc/emulator/xnes/snes9x/jma/lencoder.h
28798 views
1
/*
2
Copyright (C) 2005-2006 NSRT Team ( http://nsrt.edgeemu.com )
3
Copyright (C) 2002 Andrea Mazzoleni ( http://advancemame.sf.net )
4
Copyright (C) 2001-4 Igor Pavlov ( http://www.7-zip.org )
5
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License version 2.1 as published by the Free Software Foundation.
9
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
14
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*/
19
20
#ifndef __LENCODER_H
21
#define __LENCODER_H
22
23
#include "btreecd.h"
24
25
namespace NLength {
26
27
const UINT32 kNumPosStatesBitsMax = 4;
28
const int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);
29
30
31
const int kNumPosStatesBitsEncodingMax = 4;
32
const int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);
33
34
35
const int kNumMoveBits = 5;
36
37
const int kNumLenBits = 3;
38
const int kNumLowSymbols = 1 << kNumLenBits;
39
const int kNumMidBits = 3;
40
const int kNumMidSymbols = 1 << kNumMidBits;
41
42
const int kNumHighBits = 8;
43
44
const int kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);
45
46
const int kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;
47
48
class CDecoder
49
{
50
CMyBitDecoder<kNumMoveBits> m_Choice;
51
CBitTreeDecoder<kNumMoveBits, kNumLenBits> m_LowCoder[kNumPosStatesMax];
52
CMyBitDecoder<kNumMoveBits> m_Choice2;
53
CBitTreeDecoder<kNumMoveBits, kNumMidBits> m_MidCoder[kNumPosStatesMax];
54
CBitTreeDecoder<kNumMoveBits, kNumHighBits> m_HighCoder;
55
UINT32 m_NumPosStates;
56
public:
57
void Create(UINT32 aNumPosStates)
58
{ m_NumPosStates = aNumPosStates; }
59
void Init()
60
{
61
m_Choice.Init();
62
for (UINT32 aPosState = 0; aPosState < m_NumPosStates; aPosState++)
63
{
64
m_LowCoder[aPosState].Init();
65
m_MidCoder[aPosState].Init();
66
}
67
m_Choice2.Init();
68
m_HighCoder.Init();
69
}
70
UINT32 Decode(CMyRangeDecoder *aRangeDecoder, UINT32 aPosState)
71
{
72
if(m_Choice.Decode(aRangeDecoder) == 0)
73
return m_LowCoder[aPosState].Decode(aRangeDecoder);
74
else
75
{
76
UINT32 aSymbol = kNumLowSymbols;
77
if(m_Choice2.Decode(aRangeDecoder) == 0)
78
aSymbol += m_MidCoder[aPosState].Decode(aRangeDecoder);
79
else
80
{
81
aSymbol += kNumMidSymbols;
82
aSymbol += m_HighCoder.Decode(aRangeDecoder);
83
}
84
return aSymbol;
85
}
86
}
87
88
};
89
90
}
91
92
93
#endif
94
95