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 | #include "lencoder.h" |
21 | |
22 | #ifndef __LZMA_H |
23 | #define __LZMA_H |
24 | |
25 | namespace NCompress { |
26 | namespace NLZMA { |
27 | |
28 | const UINT32 kNumRepDistances = 4; |
29 | |
30 | const BYTE kNumStates = 12; |
31 | |
32 | const BYTE kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5}; |
33 | const BYTE kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10}; |
34 | const BYTE kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11}; |
35 | const BYTE kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11}; |
36 | |
37 | class CState |
38 | { |
39 | public: |
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 | |
53 | class CBaseCoder |
54 | { |
55 | protected: |
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 | |
70 | const int kNumPosSlotBits = 6; |
71 | const int kDicLogSizeMax = 28; |
72 | const int kDistTableSizeMax = kDicLogSizeMax * 2; |
73 | |
74 | extern UINT32 kDistStart[kDistTableSizeMax]; |
75 | const 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 | |
82 | const UINT32 kNumLenToPosStates = 4; |
83 | inline UINT32 GetLenToPosState(UINT32 aLen) |
84 | { |
85 | aLen -= 2; |
86 | if (aLen < kNumLenToPosStates) |
87 | return aLen; |
88 | return kNumLenToPosStates - 1; |
89 | } |
90 | |
91 | const int kMatchMinLen = 2; |
92 | |
93 | const int kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1; |
94 | |
95 | const int kNumAlignBits = 4; |
96 | const int kAlignTableSize = 1 << kNumAlignBits; |
97 | const UINT32 kAlignMask = (kAlignTableSize - 1); |
98 | |
99 | const int kStartPosModelIndex = 4; |
100 | const int kEndPosModelIndex = 14; |
101 | const int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex; |
102 | |
103 | const int kNumFullDistances = 1 << (kEndPosModelIndex / 2); |
104 | |
105 | |
106 | const int kMainChoiceLiteralIndex = 0; |
107 | const int kMainChoiceMatchIndex = 1; |
108 | |
109 | const int kMatchChoiceDistanceIndex= 0; |
110 | const int kMatchChoiceRepetitionIndex = 1; |
111 | |
112 | const int kNumMoveBitsForMainChoice = 5; |
113 | const int kNumMoveBitsForPosCoders = 5; |
114 | |
115 | const int kNumMoveBitsForAlignCoders = 5; |
116 | |
117 | const int kNumMoveBitsForPosSlotCoder = 5; |
118 | |
119 | const int kNumLitPosStatesBitsEncodingMax = 4; |
120 | const int kNumLitContextBitsMax = 8; |
121 | |
122 | }} |
123 | |
124 | #endif |
125 | |