1/*
2Copyright (C) 2005-2006 NSRT Team ( http://nsrt.edgeemu.com )
3Copyright (C) 2002 Andrea Mazzoleni ( http://advancemame.sf.net )
4Copyright (C) 2001-4 Igor Pavlov ( http://www.7-zip.org )
5
6This library is free software; you can redistribute it and/or
7modify it under the terms of the GNU Lesser General Public
8License version 2.1 as published by the Free Software Foundation.
9
10This library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public
16License along with this library; if not, write to the Free Software
17Foundation, 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
25namespace NLength {
26
27const UINT32 kNumPosStatesBitsMax = 4;
28const int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);
29
30
31const int kNumPosStatesBitsEncodingMax = 4;
32const int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);
33
34
35const int kNumMoveBits = 5;
36
37const int kNumLenBits = 3;
38const int kNumLowSymbols = 1 << kNumLenBits;
39const int kNumMidBits = 3;
40const int kNumMidSymbols = 1 << kNumMidBits;
41
42const int kNumHighBits = 8;
43
44const int kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);
45
46const int kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;
47
48class 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;
56public:
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