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