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