lzma decoder
[swftools.git] / installer / lzma / LzmaDecode.h
1 /* 
2   LzmaDecode.h
3   LZMA Decoder interface
4
5   LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)
6   http://www.7-zip.org/
7
8   LZMA SDK is licensed under two licenses:
9   1) GNU Lesser General Public License (GNU LGPL)
10   2) Common Public License (CPL)
11   It means that you can select one of these two licenses and 
12   follow rules of that license.
13
14   SPECIAL EXCEPTION:
15   Igor Pavlov, as the author of this code, expressly permits you to 
16   statically or dynamically link your code (or bind by name) to the 
17   interfaces of this file without subjecting your linked code to the 
18   terms of the CPL or GNU LGPL. Any modifications or additions 
19   to this file, however, are subject to the LGPL or CPL terms.
20 */
21
22 #ifndef __LZMADECODE_H
23 #define __LZMADECODE_H
24
25 #include "LzmaTypes.h"
26
27 /* #define _LZMA_IN_CB */
28 /* Use callback for input data */
29
30 #define _LZMA_OUT_READ
31 /* Use read function for output data */
32
33 /* #define _LZMA_PROB32 */
34 /* It can increase speed on some 32-bit CPUs, 
35    but memory usage will be doubled in that case */
36
37 /* #define _LZMA_LOC_OPT */
38 /* Enable local speed optimizations inside code */
39
40 #ifdef _LZMA_PROB32
41 #define CProb UInt32
42 #else
43 #define CProb UInt16
44 #endif
45
46
47 #define LZMA_RESULT_OK 0
48 #define LZMA_RESULT_DATA_ERROR 1
49
50 #ifdef _LZMA_IN_CB
51 typedef struct _ILzmaInCallback
52 {
53   int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);
54 } ILzmaInCallback;
55 #endif
56
57 #define LZMA_BASE_SIZE 1846
58 #define LZMA_LIT_SIZE 768
59
60 #define LZMA_PROPERTIES_SIZE 5
61
62 typedef struct _CLzmaProperties
63 {
64   int lc;
65   int lp;
66   int pb;
67   #ifdef _LZMA_OUT_READ
68   UInt32 DictionarySize;
69   #endif
70 }CLzmaProperties;
71
72 int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);
73
74 #define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
75
76 #define kLzmaNeedInitId (-2)
77
78 typedef struct _CLzmaDecoderState
79 {
80   CLzmaProperties Properties;
81   CProb *Probs;
82
83   #ifdef _LZMA_IN_CB
84   const unsigned char *Buffer;
85   const unsigned char *BufferLim;
86   #endif
87
88   #ifdef _LZMA_OUT_READ
89   unsigned char *Dictionary;
90   UInt32 Range;
91   UInt32 Code;
92   UInt32 DictionaryPos;
93   UInt32 GlobalPos;
94   UInt32 DistanceLimit;
95   UInt32 Reps[4];
96   int State;
97   int RemainLen;
98   unsigned char TempDictionary[4];
99   #endif
100 } CLzmaDecoderState;
101
102 #ifdef _LZMA_OUT_READ
103 #define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }
104 #endif
105
106 int LzmaDecode(CLzmaDecoderState *vs,
107     #ifdef _LZMA_IN_CB
108     ILzmaInCallback *inCallback,
109     #else
110     const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
111     #endif
112     unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);
113
114 #endif