author | Ryan C. Gordon <icculus@icculus.org> |
Tue, 11 Apr 2006 14:33:48 +0000 | |
changeset 774 | 916c2e81e77f |
child 780 | 8d029fecde3a |
permissions | -rw-r--r-- |
774
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/* |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
LzmaStateDecode.c |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
LZMA Decoder (State version) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 |
http://www.7-zip.org/ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
LZMA SDK is licensed under two licenses: |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
1) GNU Lesser General Public License (GNU LGPL) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
2) Common Public License (CPL) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 |
It means that you can select one of these two licenses and |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 |
follow rules of that license. |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
SPECIAL EXCEPTION: |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
Igor Pavlov, as the author of this Code, expressly permits you to |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
statically or dynamically link your Code (or bind by name) to the |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
interfaces of this file without subjecting your linked Code to the |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
terms of the CPL or GNU LGPL. Any modifications or additions |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
to this file, however, are subject to the LGPL or CPL terms. |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 |
*/ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 |
#include "LzmaStateDecode.h" |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 |
#define kNumTopBits 24 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 |
#define kTopValue ((UInt32)1 << kNumTopBits) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 |
#define kNumBitModelTotalBits 11 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 |
#define kBitModelTotal (1 << kNumBitModelTotalBits) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
#define kNumMoveBits 5 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 |
#define RC_READ_BYTE (*Buffer++) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 |
#define RC_INIT Code = 0; Range = 0xFFFFFFFF; \ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
{ int i; for(i = 0; i < 5; i++) { Code = (Code << 8) | RC_READ_BYTE; }} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
#define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
{ UpdateBit0(p); mi <<= 1; A0; } else \ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 |
{ UpdateBit1(p); mi = (mi + mi) + 1; A1; } |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
#define RangeDecoderBitTreeDecode(probs, numLevels, res) \ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
{ int i = numLevels; res = 1; \ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 |
do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
res -= (1 << numLevels); } |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
#define kNumPosBitsMax 4 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 |
#define kNumPosStatesMax (1 << kNumPosBitsMax) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 |
#define kLenNumLowBits 3 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 |
#define kLenNumLowSymbols (1 << kLenNumLowBits) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 |
#define kLenNumMidBits 3 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
#define kLenNumMidSymbols (1 << kLenNumMidBits) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
#define kLenNumHighBits 8 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
#define kLenNumHighSymbols (1 << kLenNumHighBits) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
#define LenChoice 0 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 |
#define LenChoice2 (LenChoice + 1) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
#define LenLow (LenChoice2 + 1) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 |
#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits)) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 |
#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits)) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 |
#define kNumLenProbs (LenHigh + kLenNumHighSymbols) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
#define kNumStates 12 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
#define kNumLitStates 7 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
#define kStartPosModelIndex 4 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 |
#define kEndPosModelIndex 14 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 |
#define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 |
#define kNumPosSlotBits 6 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 |
#define kNumLenToPosStates 4 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 |
#define kNumAlignBits 4 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 |
#define kAlignTableSize (1 << kNumAlignBits) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 |
#define kMatchMinLen 2 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 |
#define IsMatch 0 |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 |
#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax)) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
#define IsRepG0 (IsRep + kNumStates) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 |
#define IsRepG1 (IsRepG0 + kNumStates) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 |
#define IsRepG2 (IsRepG1 + kNumStates) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 |
#define IsRep0Long (IsRepG2 + kNumStates) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 |
#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax)) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 |
#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits)) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 |
#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 |
#define LenCoder (Align + kAlignTableSize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
97 |
#define RepLenCoder (LenCoder + kNumLenProbs) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
98 |
#define Literal (RepLenCoder + kNumLenProbs) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
99 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 |
#if Literal != LZMA_BASE_SIZE |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 |
StopCompilingDueBUG |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 |
#endif |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 |
/* kRequiredInBufferSize = number of required input bytes for worst case: |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 |
longest match with longest distance. |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 |
kLzmaInBufferSize must be larger than kRequiredInBufferSize |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 |
23 bits = 2 (match select) + 10 (len) + 6 (distance) + 4(align) + 1 (RC_NORMALIZE) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 |
*/ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 |
#define kRequiredInBufferSize ((23 * (kNumBitModelTotalBits - kNumMoveBits + 1) + 26 + 9) / 8) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 |
#define kLzmaStreamWasFinishedId (-1) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 |
int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 |
unsigned char prop0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 |
if (size < LZMA_PROPERTIES_SIZE) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 |
return LZMA_RESULT_DATA_ERROR; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
prop0 = propsData[0]; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 |
if (prop0 >= (9 * 5 * 5)) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 |
return LZMA_RESULT_DATA_ERROR; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 |
for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5)); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 |
for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 |
propsRes->lc = prop0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 |
/* |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 |
unsigned char remainder = (unsigned char)(prop0 / 9); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 |
propsRes->lc = prop0 % 9; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 |
propsRes->pb = remainder / 5; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 |
propsRes->lp = remainder % 5; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 |
*/ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 |
int i; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 |
propsRes->DictionarySize = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 |
for (i = 0; i < 4; i++) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 |
propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 |
if (propsRes->DictionarySize == 0) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 |
propsRes->DictionarySize = 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
return LZMA_RESULT_OK; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
144 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 |
int LzmaDecode( |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 |
CLzmaDecoderState *vs, |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 |
const unsigned char *inStream, size_t inSize, size_t *inSizeProcessed, |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 |
unsigned char *outStream, size_t outSize, size_t *outSizeProcessed, |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 |
int finishDecoding) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 |
UInt32 Range = vs->Range; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 |
UInt32 Code = vs->Code; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 |
unsigned char *Buffer = vs->Buffer; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 |
int BufferSize = vs->BufferSize; /* don't change it to unsigned int */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 |
CProb *p = vs->Probs; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 |
int state = vs->State; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 |
unsigned char previousByte; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 |
UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3]; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 |
size_t nowPos = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
162 |
UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 |
UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
164 |
int lc = vs->Properties.lc; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 |
int len = vs->RemainLen; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 |
UInt32 globalPos = vs->GlobalPos; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 |
UInt32 distanceLimit = vs->DistanceLimit; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 |
unsigned char *dictionary = vs->Dictionary; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 |
UInt32 dictionarySize = vs->Properties.DictionarySize; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 |
UInt32 dictionaryPos = vs->DictionaryPos; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 |
unsigned char tempDictionary[4]; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 |
(*inSizeProcessed) = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 |
(*outSizeProcessed) = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 |
if (len == kLzmaStreamWasFinishedId) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 |
return LZMA_RESULT_OK; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 |
if (dictionarySize == 0) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 |
dictionary = tempDictionary; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 |
dictionarySize = 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 |
tempDictionary[0] = vs->TempDictionary[0]; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
185 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 |
if (len == kLzmaNeedInitId) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 |
while (inSize > 0 && BufferSize < kLzmaInBufferSize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 |
Buffer[BufferSize++] = *inStream++; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 |
(*inSizeProcessed)++; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 |
inSize--; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 |
if (BufferSize < 5) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
197 |
vs->BufferSize = BufferSize; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
198 |
return finishDecoding ? LZMA_RESULT_DATA_ERROR : LZMA_RESULT_OK; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
199 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
200 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
201 |
UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp)); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 |
UInt32 i; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 |
for (i = 0; i < numProbs; i++) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 |
p[i] = kBitModelTotal >> 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 |
rep0 = rep1 = rep2 = rep3 = 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 |
state = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
207 |
globalPos = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 |
distanceLimit = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
209 |
dictionaryPos = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 |
dictionary[dictionarySize - 1] = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 |
RC_INIT; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
212 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 |
len = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
214 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
215 |
while(len != 0 && nowPos < outSize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
216 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 |
UInt32 pos = dictionaryPos - rep0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 |
if (pos >= dictionarySize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 |
pos += dictionarySize; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 |
outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos]; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 |
if (++dictionaryPos == dictionarySize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 |
dictionaryPos = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
223 |
len--; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
225 |
if (dictionaryPos == 0) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 |
previousByte = dictionary[dictionarySize - 1]; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 |
else |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 |
previousByte = dictionary[dictionaryPos - 1]; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
230 |
while(1) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
232 |
int bufferPos = (int)(Buffer - vs->Buffer); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
233 |
if (BufferSize - bufferPos < kRequiredInBufferSize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 |
int i; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
236 |
BufferSize -= bufferPos; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 |
if (BufferSize < 0) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
238 |
return LZMA_RESULT_DATA_ERROR; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 |
for (i = 0; i < BufferSize; i++) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
240 |
vs->Buffer[i] = Buffer[i]; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 |
Buffer = vs->Buffer; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 |
while (inSize > 0 && BufferSize < kLzmaInBufferSize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
243 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
244 |
Buffer[BufferSize++] = *inStream++; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 |
(*inSizeProcessed)++; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
246 |
inSize--; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
248 |
if (BufferSize < kRequiredInBufferSize && !finishDecoding) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
249 |
break; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
250 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 |
if (nowPos >= outSize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 |
break; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
253 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 |
CProb *prob; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 |
UInt32 bound; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 |
int posState = (int)((nowPos + globalPos) & posStateMask); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
258 |
prob = p + IsMatch + (state << kNumPosBitsMax) + posState; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
259 |
IfBit0(prob) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
260 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 |
int symbol = 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 |
UpdateBit0(prob) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 |
prob = p + Literal + (LZMA_LIT_SIZE * |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 |
((((nowPos + globalPos)& literalPosMask) << lc) + (previousByte >> (8 - lc)))); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
265 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
266 |
if (state >= kNumLitStates) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 |
int matchByte; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 |
UInt32 pos = dictionaryPos - rep0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
270 |
if (pos >= dictionarySize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 |
pos += dictionarySize; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 |
matchByte = dictionary[pos]; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
273 |
do |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
274 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
275 |
int bit; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
276 |
CProb *probLit; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
277 |
matchByte <<= 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
278 |
bit = (matchByte & 0x100); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
279 |
probLit = prob + 0x100 + bit + symbol; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 |
RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
281 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
282 |
while (symbol < 0x100); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
283 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
284 |
while (symbol < 0x100) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
285 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 |
CProb *probLit = prob + symbol; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 |
RC_GET_BIT(probLit, symbol) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 |
previousByte = (unsigned char)symbol; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
290 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
291 |
outStream[nowPos++] = previousByte; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
292 |
if (distanceLimit < dictionarySize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
293 |
distanceLimit++; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
294 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
295 |
dictionary[dictionaryPos] = previousByte; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 |
if (++dictionaryPos == dictionarySize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 |
dictionaryPos = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 |
if (state < 4) state = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 |
else if (state < 10) state -= 3; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
300 |
else state -= 6; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 |
else |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
303 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
304 |
UpdateBit1(prob); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 |
prob = p + IsRep + state; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 |
IfBit0(prob) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
307 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 |
UpdateBit0(prob); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
309 |
rep3 = rep2; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
310 |
rep2 = rep1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 |
rep1 = rep0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 |
state = state < kNumLitStates ? 0 : 3; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
313 |
prob = p + LenCoder; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 |
else |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
317 |
UpdateBit1(prob); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 |
prob = p + IsRepG0 + state; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
319 |
IfBit0(prob) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
320 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
321 |
UpdateBit0(prob); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 |
prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 |
IfBit0(prob) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
324 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
325 |
UInt32 pos; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
326 |
UpdateBit0(prob); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
327 |
if (distanceLimit == 0) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
328 |
return LZMA_RESULT_DATA_ERROR; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
329 |
if (distanceLimit < dictionarySize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
330 |
distanceLimit++; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
331 |
state = state < kNumLitStates ? 9 : 11; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
332 |
pos = dictionaryPos - rep0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 |
if (pos >= dictionarySize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
334 |
pos += dictionarySize; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
335 |
previousByte = dictionary[pos]; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
336 |
dictionary[dictionaryPos] = previousByte; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
337 |
if (++dictionaryPos == dictionarySize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
338 |
dictionaryPos = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
339 |
outStream[nowPos++] = previousByte; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
340 |
continue; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
341 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
342 |
else |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
343 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
344 |
UpdateBit1(prob); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
345 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
346 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
347 |
else |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
348 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
349 |
UInt32 distance; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
350 |
UpdateBit1(prob); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
351 |
prob = p + IsRepG1 + state; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
352 |
IfBit0(prob) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
353 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
354 |
UpdateBit0(prob); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
355 |
distance = rep1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
356 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
357 |
else |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
358 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
359 |
UpdateBit1(prob); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
360 |
prob = p + IsRepG2 + state; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
361 |
IfBit0(prob) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
362 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
363 |
UpdateBit0(prob); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
364 |
distance = rep2; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
365 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
366 |
else |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
368 |
UpdateBit1(prob); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
369 |
distance = rep3; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
370 |
rep3 = rep2; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
371 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
372 |
rep2 = rep1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
373 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
374 |
rep1 = rep0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
375 |
rep0 = distance; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
376 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
377 |
state = state < kNumLitStates ? 8 : 11; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
378 |
prob = p + RepLenCoder; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
379 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
380 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
381 |
int numBits, offset; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
382 |
CProb *probLen = prob + LenChoice; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
383 |
IfBit0(probLen) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
384 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
385 |
UpdateBit0(probLen); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
386 |
probLen = prob + LenLow + (posState << kLenNumLowBits); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
387 |
offset = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
388 |
numBits = kLenNumLowBits; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
389 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
390 |
else |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
391 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
392 |
UpdateBit1(probLen); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
393 |
probLen = prob + LenChoice2; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
394 |
IfBit0(probLen) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
395 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
396 |
UpdateBit0(probLen); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
397 |
probLen = prob + LenMid + (posState << kLenNumMidBits); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
398 |
offset = kLenNumLowSymbols; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
399 |
numBits = kLenNumMidBits; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
400 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
401 |
else |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
402 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
403 |
UpdateBit1(probLen); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
404 |
probLen = prob + LenHigh; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
405 |
offset = kLenNumLowSymbols + kLenNumMidSymbols; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
406 |
numBits = kLenNumHighBits; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
407 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
408 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
409 |
RangeDecoderBitTreeDecode(probLen, numBits, len); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
410 |
len += offset; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
411 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
412 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
413 |
if (state < 4) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
414 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
415 |
int posSlot; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
416 |
state += kNumLitStates; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
417 |
prob = p + PosSlot + |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
418 |
((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
419 |
kNumPosSlotBits); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
420 |
RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
421 |
if (posSlot >= kStartPosModelIndex) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
422 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
423 |
int numDirectBits = ((posSlot >> 1) - 1); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
424 |
rep0 = (2 | ((UInt32)posSlot & 1)); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
425 |
if (posSlot < kEndPosModelIndex) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
426 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
427 |
rep0 <<= numDirectBits; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
428 |
prob = p + SpecPos + rep0 - posSlot - 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
429 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
430 |
else |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
431 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
432 |
numDirectBits -= kNumAlignBits; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
433 |
do |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
434 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
435 |
RC_NORMALIZE |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
436 |
Range >>= 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
437 |
rep0 <<= 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
438 |
if (Code >= Range) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
439 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
440 |
Code -= Range; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
441 |
rep0 |= 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
442 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
443 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
444 |
while (--numDirectBits != 0); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
445 |
prob = p + Align; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
446 |
rep0 <<= kNumAlignBits; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
447 |
numDirectBits = kNumAlignBits; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
448 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
449 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
450 |
int i = 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
451 |
int mi = 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
452 |
do |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
453 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
454 |
CProb *prob3 = prob + mi; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
455 |
RC_GET_BIT2(prob3, mi, ; , rep0 |= i); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
456 |
i <<= 1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
457 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
458 |
while(--numDirectBits != 0); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
459 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
460 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
461 |
else |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
462 |
rep0 = posSlot; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
463 |
if (++rep0 == (UInt32)(0)) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
464 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
465 |
/* it's for stream version */ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
466 |
len = kLzmaStreamWasFinishedId; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
467 |
break; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
468 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
469 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
470 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
471 |
len += kMatchMinLen; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
472 |
if (rep0 > distanceLimit) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
473 |
return LZMA_RESULT_DATA_ERROR; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
474 |
if (dictionarySize - distanceLimit > (UInt32)len) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
475 |
distanceLimit += len; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
476 |
else |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
477 |
distanceLimit = dictionarySize; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
478 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
479 |
do |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
480 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
481 |
UInt32 pos = dictionaryPos - rep0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
482 |
if (pos >= dictionarySize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
483 |
pos += dictionarySize; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
484 |
previousByte = dictionary[pos]; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
485 |
dictionary[dictionaryPos] = previousByte; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
486 |
if (++dictionaryPos == dictionarySize) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
487 |
dictionaryPos = 0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
488 |
len--; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
489 |
outStream[nowPos++] = previousByte; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
490 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
491 |
while(len != 0 && nowPos < outSize); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
492 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
493 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
494 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
495 |
RC_NORMALIZE; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
496 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
497 |
BufferSize -= (int)(Buffer - vs->Buffer); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
498 |
if (BufferSize < 0) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
499 |
return LZMA_RESULT_DATA_ERROR; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
500 |
{ |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
501 |
int i; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
502 |
for (i = 0; i < BufferSize; i++) |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
503 |
vs->Buffer[i] = Buffer[i]; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
504 |
} |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
505 |
vs->BufferSize = BufferSize; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
506 |
vs->Range = Range; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
507 |
vs->Code = Code; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
508 |
vs->DictionaryPos = dictionaryPos; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
509 |
vs->GlobalPos = (UInt32)(globalPos + nowPos); |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
510 |
vs->DistanceLimit = distanceLimit; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
511 |
vs->Reps[0] = rep0; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
512 |
vs->Reps[1] = rep1; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
513 |
vs->Reps[2] = rep2; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
514 |
vs->Reps[3] = rep3; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
515 |
vs->State = state; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
516 |
vs->RemainLen = len; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
517 |
vs->TempDictionary[0] = tempDictionary[0]; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
518 |
|
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
519 |
(*outSizeProcessed) = nowPos; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
520 |
return LZMA_RESULT_OK; |
916c2e81e77f
7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
521 |
} |