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