1 /* LzmaDec.h -- LZMA Decoder
\r
2 2013-01-18 : Igor Pavlov : Public domain */
\r
11 /* #define _LZMA_PROB32 */
\r
12 /* _LZMA_PROB32 can increase the speed on some CPUs,
\r
13 but memory usage for CLzmaDec::probs will be doubled in that case */
\r
16 #define CLzmaProb UInt32
\r
18 #define CLzmaProb UInt16
\r
22 /* ---------- LZMA Properties ---------- */
\r
24 #define LZMA_PROPS_SIZE 5
\r
26 typedef struct _CLzmaProps
\r
28 unsigned lc, lp, pb;
\r
32 /* LzmaProps_Decode - decodes properties
\r
35 SZ_ERROR_UNSUPPORTED - Unsupported properties
\r
38 SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
\r
41 /* ---------- LZMA Decoder state ---------- */
\r
43 /* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
\r
44 Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
\r
46 #define LZMA_REQUIRED_INPUT_MAX 20
\r
57 UInt32 processedPos;
\r
58 UInt32 checkDicSize;
\r
65 unsigned tempBufSize;
\r
66 Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
\r
69 #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
\r
71 void LzmaDec_Init(CLzmaDec *p);
\r
73 /* There are two types of LZMA streams:
\r
74 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
\r
75 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
\r
79 LZMA_FINISH_ANY, /* finish at any point */
\r
80 LZMA_FINISH_END /* block must be finished at the end */
\r
83 /* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
\r
85 You must use LZMA_FINISH_END, when you know that current output buffer
\r
86 covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
\r
88 If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
\r
89 and output value of destLen will be less than output buffer size limit.
\r
90 You can check status result also.
\r
92 You can use multiple checks to test data integrity after full decompression:
\r
93 1) Check Result and "status" variable.
\r
94 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
\r
95 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
\r
96 You must use correct finish mode in that case. */
\r
100 LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
\r
101 LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
\r
102 LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
\r
103 LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
\r
104 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
\r
107 /* ELzmaStatus is used only as output value for function call */
\r
110 /* ---------- Interfaces ---------- */
\r
112 /* There are 3 levels of interfaces:
\r
113 1) Dictionary Interface
\r
114 2) Buffer Interface
\r
115 3) One Call Interface
\r
116 You can select any of these interfaces, but don't mix functions from different
\r
117 groups for same object. */
\r
120 /* There are two variants to allocate state for Dictionary Interface:
\r
121 1) LzmaDec_Allocate / LzmaDec_Free
\r
122 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
\r
123 You can use variant 2, if you set dictionary buffer manually.
\r
124 For Buffer Interface you must always use variant 1.
\r
126 LzmaDec_Allocate* can return:
\r
128 SZ_ERROR_MEM - Memory allocation error
\r
129 SZ_ERROR_UNSUPPORTED - Unsupported properties
\r
132 SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
\r
133 void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
\r
135 SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
\r
136 void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
\r
138 /* ---------- Dictionary Interface ---------- */
\r
140 /* You can use it, if you want to eliminate the overhead for data copying from
\r
141 dictionary to some other external buffer.
\r
142 You must work with CLzmaDec variables directly in this interface.
\r
147 for (each new stream)
\r
150 while (it needs more decompression)
\r
152 LzmaDec_DecodeToDic()
\r
153 use data from CLzmaDec::dic and update CLzmaDec::dicPos
\r
159 /* LzmaDec_DecodeToDic
\r
161 The decoding to internal dictionary buffer (CLzmaDec::dic).
\r
162 You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
\r
165 It has meaning only if the decoding reaches output limit (dicLimit).
\r
166 LZMA_FINISH_ANY - Decode just dicLimit bytes.
\r
167 LZMA_FINISH_END - Stream must be finished after dicLimit.
\r
172 LZMA_STATUS_FINISHED_WITH_MARK
\r
173 LZMA_STATUS_NOT_FINISHED
\r
174 LZMA_STATUS_NEEDS_MORE_INPUT
\r
175 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
\r
176 SZ_ERROR_DATA - Data error
\r
179 SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
\r
180 const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
\r
183 /* ---------- Buffer Interface ---------- */
\r
185 /* It's zlib-like interface.
\r
186 See LzmaDec_DecodeToDic description for information about STEPS and return results,
\r
187 but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
\r
188 to work with CLzmaDec variables manually.
\r
191 It has meaning only if the decoding reaches output limit (*destLen).
\r
192 LZMA_FINISH_ANY - Decode just destLen bytes.
\r
193 LZMA_FINISH_END - Stream must be finished after (*destLen).
\r
196 SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
\r
197 const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
\r
200 /* ---------- One Call Interface ---------- */
\r
205 It has meaning only if the decoding reaches output limit (*destLen).
\r
206 LZMA_FINISH_ANY - Decode just destLen bytes.
\r
207 LZMA_FINISH_END - Stream must be finished after (*destLen).
\r
212 LZMA_STATUS_FINISHED_WITH_MARK
\r
213 LZMA_STATUS_NOT_FINISHED
\r
214 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
\r
215 SZ_ERROR_DATA - Data error
\r
216 SZ_ERROR_MEM - Memory allocation error
\r
217 SZ_ERROR_UNSUPPORTED - Unsupported properties
\r
218 SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
\r
221 SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
\r
222 const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
\r
223 ELzmaStatus *status, ISzAlloc *alloc);
\r