TianoCore EDK2 master
Loading...
Searching...
No Matches
LzmaDec.h
1/* LzmaDec.h -- LZMA Decoder
22018-04-21 : Igor Pavlov : Public domain */
3
4#ifndef __LZMA_DEC_H
5#define __LZMA_DEC_H
6
7#include "7zTypes.h"
8
9EXTERN_C_BEGIN
10
11/* #define _LZMA_PROB32 */
12
13/* _LZMA_PROB32 can increase the speed on some CPUs,
14 but memory usage for CLzmaDec::probs will be doubled in that case */
15
16typedef
17#ifdef _LZMA_PROB32
18 UInt32
19#else
20 UInt16
21#endif
22 CLzmaProb;
23
24/* ---------- LZMA Properties ---------- */
25
26#define LZMA_PROPS_SIZE 5
27
28typedef struct _CLzmaProps {
29 Byte lc;
30 Byte lp;
31 Byte pb;
32 Byte _pad_;
33 UInt32 dicSize;
35
36/* LzmaProps_Decode - decodes properties
37Returns:
38 SZ_OK
39 SZ_ERROR_UNSUPPORTED - Unsupported properties
40*/
41
42SRes
43LzmaProps_Decode (
44 CLzmaProps *p,
45 const Byte *data,
46 unsigned size
47 );
48
49/* ---------- LZMA Decoder state ---------- */
50
51/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
52 Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
53
54#define LZMA_REQUIRED_INPUT_MAX 20
55
56typedef struct {
57 /* Don't change this structure. ASM code can use it. */
58 CLzmaProps prop;
59 CLzmaProb *probs;
60 CLzmaProb *probs_1664;
61 Byte *dic;
62 SizeT dicBufSize;
63 SizeT dicPos;
64 const Byte *buf;
65 UInt32 range;
66 UInt32 code;
67 UInt32 processedPos;
68 UInt32 checkDicSize;
69 UInt32 reps[4];
70 UInt32 state;
71 UInt32 remainLen;
72
73 UInt32 numProbs;
74 unsigned tempBufSize;
75 Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
76} CLzmaDec;
77
78#define LzmaDec_Construct(p) { (p)->dic = NULL; (p)->probs = NULL; }
79
80void
81LzmaDec_Init (
82 CLzmaDec *p
83 );
84
85/* There are two types of LZMA streams:
86 - Stream with end mark. That end mark adds about 6 bytes to compressed size.
87 - Stream without end mark. You must know exact uncompressed size to decompress such stream. */
88
89typedef enum {
90 LZMA_FINISH_ANY, /* finish at any point */
91 LZMA_FINISH_END /* block must be finished at the end */
92} ELzmaFinishMode;
93
94/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
95
96 You must use LZMA_FINISH_END, when you know that current output buffer
97 covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
98
99 If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
100 and output value of destLen will be less than output buffer size limit.
101 You can check status result also.
102
103 You can use multiple checks to test data integrity after full decompression:
104 1) Check Result and "status" variable.
105 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
106 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
107 You must use correct finish mode in that case. */
108
109typedef enum {
110 LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
111 LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
112 LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
113 LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
114 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
115} ELzmaStatus;
116
117/* ELzmaStatus is used only as output value for function call */
118
119/* ---------- Interfaces ---------- */
120
121/* There are 3 levels of interfaces:
122 1) Dictionary Interface
123 2) Buffer Interface
124 3) One Call Interface
125 You can select any of these interfaces, but don't mix functions from different
126 groups for same object. */
127
128/* There are two variants to allocate state for Dictionary Interface:
129 1) LzmaDec_Allocate / LzmaDec_Free
130 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
131 You can use variant 2, if you set dictionary buffer manually.
132 For Buffer Interface you must always use variant 1.
133
134LzmaDec_Allocate* can return:
135 SZ_OK
136 SZ_ERROR_MEM - Memory allocation error
137 SZ_ERROR_UNSUPPORTED - Unsupported properties
138*/
139
140SRes
141LzmaDec_AllocateProbs (
142 CLzmaDec *p,
143 const Byte *props,
144 unsigned propsSize,
145 ISzAllocPtr alloc
146 );
147
148void
149LzmaDec_FreeProbs (
150 CLzmaDec *p,
151 ISzAllocPtr alloc
152 );
153
154SRes
155LzmaDec_Allocate (
156 CLzmaDec *p,
157 const Byte *props,
158 unsigned propsSize,
159 ISzAllocPtr alloc
160 );
161
162void
163LzmaDec_Free (
164 CLzmaDec *p,
165 ISzAllocPtr alloc
166 );
167
168/* ---------- Dictionary Interface ---------- */
169
170/* You can use it, if you want to eliminate the overhead for data copying from
171 dictionary to some other external buffer.
172 You must work with CLzmaDec variables directly in this interface.
173
174 STEPS:
175 LzmaDec_Construct()
176 LzmaDec_Allocate()
177 for (each new stream)
178 {
179 LzmaDec_Init()
180 while (it needs more decompression)
181 {
182 LzmaDec_DecodeToDic()
183 use data from CLzmaDec::dic and update CLzmaDec::dicPos
184 }
185 }
186 LzmaDec_Free()
187*/
188
189/* LzmaDec_DecodeToDic
190
191 The decoding to internal dictionary buffer (CLzmaDec::dic).
192 You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
193
194finishMode:
195 It has meaning only if the decoding reaches output limit (dicLimit).
196 LZMA_FINISH_ANY - Decode just dicLimit bytes.
197 LZMA_FINISH_END - Stream must be finished after dicLimit.
198
199Returns:
200 SZ_OK
201 status:
202 LZMA_STATUS_FINISHED_WITH_MARK
203 LZMA_STATUS_NOT_FINISHED
204 LZMA_STATUS_NEEDS_MORE_INPUT
205 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
206 SZ_ERROR_DATA - Data error
207*/
208
209SRes
210LzmaDec_DecodeToDic (
211 CLzmaDec *p,
212 SizeT dicLimit,
213 const Byte *src,
214 SizeT *srcLen,
215 ELzmaFinishMode finishMode,
216 ELzmaStatus *status
217 );
218
219/* ---------- Buffer Interface ---------- */
220
221/* It's zlib-like interface.
222 See LzmaDec_DecodeToDic description for information about STEPS and return results,
223 but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
224 to work with CLzmaDec variables manually.
225
226finishMode:
227 It has meaning only if the decoding reaches output limit (*destLen).
228 LZMA_FINISH_ANY - Decode just destLen bytes.
229 LZMA_FINISH_END - Stream must be finished after (*destLen).
230*/
231
232SRes
233LzmaDec_DecodeToBuf (
234 CLzmaDec *p,
235 Byte *dest,
236 SizeT *destLen,
237 const Byte *src,
238 SizeT *srcLen,
239 ELzmaFinishMode finishMode,
240 ELzmaStatus *status
241 );
242
243/* ---------- One Call Interface ---------- */
244
245/* LzmaDecode
246
247finishMode:
248 It has meaning only if the decoding reaches output limit (*destLen).
249 LZMA_FINISH_ANY - Decode just destLen bytes.
250 LZMA_FINISH_END - Stream must be finished after (*destLen).
251
252Returns:
253 SZ_OK
254 status:
255 LZMA_STATUS_FINISHED_WITH_MARK
256 LZMA_STATUS_NOT_FINISHED
257 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
258 SZ_ERROR_DATA - Data error
259 SZ_ERROR_MEM - Memory allocation error
260 SZ_ERROR_UNSUPPORTED - Unsupported properties
261 SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
262*/
263
264SRes
265LzmaDecode (
266 Byte *dest,
267 SizeT *destLen,
268 const Byte *src,
269 SizeT *srcLen,
270 const Byte *propData,
271 unsigned propSize,
272 ELzmaFinishMode finishMode,
273 ELzmaStatus *status,
274 ISzAllocPtr alloc
275 );
276
277EXTERN_C_END
278
279#endif