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#include "lencoder.h"
21
22#ifndef __LZMA_H
23#define __LZMA_H
24
25namespace NCompress {
26namespace NLZMA {
27
28const UINT32 kNumRepDistances = 4;
29
30const BYTE kNumStates = 12;
31
32const BYTE kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
33const BYTE kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
34const BYTE kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
35const BYTE kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
36
37class CState
38{
39public:
40 BYTE m_Index;
41 void Init()
42 { m_Index = 0; }
43 void UpdateChar()
44 { m_Index = kLiteralNextStates[m_Index]; }
45 void UpdateMatch()
46 { m_Index = kMatchNextStates[m_Index]; }
47 void UpdateRep()
48 { m_Index = kRepNextStates[m_Index]; }
49 void UpdateShortRep()
50 { m_Index = kShortRepNextStates[m_Index]; }
51};
52
53class CBaseCoder
54{
55protected:
56 CState m_State;
57 BYTE m_PreviousByte;
58 bool m_PeviousIsMatch;
59 UINT32 m_RepDistances[kNumRepDistances];
60 void Init()
61 {
62 m_State.Init();
63 m_PreviousByte = 0;
64 m_PeviousIsMatch = false;
65 for(UINT32 i = 0 ; i < kNumRepDistances; i++)
66 m_RepDistances[i] = 0;
67 }
68};
69
70const int kNumPosSlotBits = 6;
71const int kDicLogSizeMax = 28;
72const int kDistTableSizeMax = kDicLogSizeMax * 2;
73
74extern UINT32 kDistStart[kDistTableSizeMax];
75const BYTE kDistDirectBits[kDistTableSizeMax] =
76{
77 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
78 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19,
79 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26
80};
81
82const UINT32 kNumLenToPosStates = 4;
83inline UINT32 GetLenToPosState(UINT32 aLen)
84{
85 aLen -= 2;
86 if (aLen < kNumLenToPosStates)
87 return aLen;
88 return kNumLenToPosStates - 1;
89}
90
91const int kMatchMinLen = 2;
92
93const int kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;
94
95const int kNumAlignBits = 4;
96const int kAlignTableSize = 1 << kNumAlignBits;
97const UINT32 kAlignMask = (kAlignTableSize - 1);
98
99const int kStartPosModelIndex = 4;
100const int kEndPosModelIndex = 14;
101const int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;
102
103const int kNumFullDistances = 1 << (kEndPosModelIndex / 2);
104
105
106const int kMainChoiceLiteralIndex = 0;
107const int kMainChoiceMatchIndex = 1;
108
109const int kMatchChoiceDistanceIndex= 0;
110const int kMatchChoiceRepetitionIndex = 1;
111
112const int kNumMoveBitsForMainChoice = 5;
113const int kNumMoveBitsForPosCoders = 5;
114
115const int kNumMoveBitsForAlignCoders = 5;
116
117const int kNumMoveBitsForPosSlotCoder = 5;
118
119const int kNumLitPosStatesBitsEncodingMax = 4;
120const int kNumLitContextBitsMax = 8;
121
122}}
123
124#endif
125