1/*
2  LzmaDecode.h
3  LZMA Decoder interface
4
5  LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)
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/* #define _LZMA_IN_CB */
26/* Use callback for input data */
27
28/* #define _LZMA_OUT_READ */
29/* Use read function for output data */
30
31/* #define _LZMA_PROB32 */
32/* It can increase speed on some 32-bit CPUs,
33   but memory usage will be doubled in that case */
34
35/* #define _LZMA_LOC_OPT */
36/* Enable local speed optimizations inside code */
37
38/* #define _LZMA_SYSTEM_SIZE_T */
39/* Use system's size_t. You can use it to enable 64-bit sizes supporting*/
40
41#ifndef UInt32
42#ifdef _LZMA_UINT32_IS_ULONG
43#define UInt32 unsigned long
44#else
45#define UInt32 unsigned int
46#endif
47#endif
48
49#ifndef SizeT
50#ifdef _LZMA_SYSTEM_SIZE_T
51#include <stddef.h>
52#define SizeT size_t
53#else
54#define SizeT UInt32
55#endif
56#endif
57
58#ifdef _LZMA_PROB32
59#define CProb UInt32
60#else
61#define CProb unsigned short
62#endif
63
64#define LZMA_RESULT_OK 0
65#define LZMA_RESULT_DATA_ERROR 1
66
67#ifdef _LZMA_IN_CB
68typedef struct _ILzmaInCallback
69{
70  int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);
71} ILzmaInCallback;
72#endif
73
74#define LZMA_BASE_SIZE 1846
75#define LZMA_LIT_SIZE 768
76
77#define LZMA_PROPERTIES_SIZE 5
78
79typedef struct _CLzmaProperties
80{
81  int lc;
82  int lp;
83  int pb;
84  #ifdef _LZMA_OUT_READ
85  UInt32 DictionarySize;
86  #endif
87}CLzmaProperties;
88
89int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);
90
91#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
92
93#define kLzmaNeedInitId (-2)
94
95typedef struct _CLzmaDecoderState
96{
97  CLzmaProperties Properties;
98  CProb *Probs;
99
100  #ifdef _LZMA_IN_CB
101  const unsigned char *Buffer;
102  const unsigned char *BufferLim;
103  #endif
104
105  #ifdef _LZMA_OUT_READ
106  unsigned char *Dictionary;
107  UInt32 Range;
108  UInt32 Code;
109  UInt32 DictionaryPos;
110  UInt32 GlobalPos;
111  UInt32 DistanceLimit;
112  UInt32 Reps[4];
113  int State;
114  int RemainLen;
115  unsigned char TempDictionary[4];
116  #endif
117} CLzmaDecoderState;
118
119#ifdef _LZMA_OUT_READ
120#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }
121#endif
122
123int LzmaDecode(CLzmaDecoderState *vs,
124    #ifdef _LZMA_IN_CB
125    ILzmaInCallback *inCallback,
126    #else
127    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
128    #endif
129    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);
130
131#endif
132