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