1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
27 /* LzmaLib.h -- LZMA library interface
35 #include "lzma_Types.h"
42 #define MY_EXTERN_C extern "C"
44 #define MY_EXTERN_C extern
47 #define MY_STDAPI MY_EXTERN_C int MY_STD_CALL
49 #define MY_STDAPI int MY_STD_CALL
52 #define LZMA_PROPS_SIZE 5
55 RAM requirements for LZMA:
56 for compression: (dictSize * 11.5 + 6 MB) + state_size
57 for decompression: dictSize + state_size
58 state_size = (4 + (1.5 << (lc + lp))) KB
59 by default (lc=3, lp=0), state_size = 16 KB.
61 LZMA properties (5 bytes) format
62 Offset Size Description
63 0 1 lc, lp and pb in encoded form.
64 1 4 dictSize (little endian).
72 In: the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
73 Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
75 LZMA Encoder will use defult values for any parameter, if it is
76 -1 for any from: level, loc, lp, pb, fb, numThreads
79 level - compression level: 0 <= level <= 9;
81 level dictSize algo fb
91 The default value for "level" is 5.
93 algo = 0 means fast method
94 algo = 1 means normal method
96 dictSize - The dictionary size in bytes. The maximum value is
97 128 MB = (1 << 27) bytes for 32-bit version
98 1 GB = (1 << 30) bytes for 64-bit version
99 The default value is 16 MB = (1 << 24) bytes.
100 It's recommended to use the dictionary that is larger than 4 KB and
101 that can be calculated as (1 << N) or (3 << N) sizes.
103 lc - The number of literal context bits (high bits of previous literal).
104 It can be in the range from 0 to 8. The default value is 3.
105 Sometimes lc=4 gives the gain for big files.
107 lp - The number of literal pos bits (low bits of current position for literals).
108 It can be in the range from 0 to 4. The default value is 0.
109 The lp switch is intended for periodical data when the period is equal to 2^lp.
110 For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's
111 better to set lc=0, if you change lp switch.
113 pb - The number of pos bits (low bits of current position).
114 It can be in the range from 0 to 4. The default value is 2.
115 The pb switch is intended for periodical data when the period is equal 2^pb.
117 fb - Word size (the number of fast bytes).
118 It can be in the range from 5 to 273. The default value is 32.
119 Usually, a big number gives a little bit better compression ratio and
120 slower compression process.
122 numThreads - The number of thereads. 1 or 2. The default value is 2.
123 Fast mode (algo = 0) can use only 1 thread.
126 destLen - processed output size
129 SZ_ERROR_MEM - Memory allocation error
130 SZ_ERROR_PARAM - Incorrect paramater
131 SZ_ERROR_OUTPUT_EOF - output buffer overflow
132 SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
135 MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
136 unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */
137 int level, /* 0 <= level <= 9, default = 5 */
138 unsigned dictSize, /* default = (1 << 24) */
139 int lc, /* 0 <= lc <= 8, default = 3 */
140 int lp, /* 0 <= lp <= 4, default = 0 */
141 int pb, /* 0 <= pb <= 4, default = 2 */
142 int fb, /* 5 <= fb <= 273, default = 32 */
143 int numThreads /* 1 or 2, default = 2 */
151 destLen - output data size
153 srcLen - input data size
155 destLen - processed output size
156 srcLen - processed input size
159 SZ_ERROR_DATA - Data error
160 SZ_ERROR_MEM - Memory allocation arror
161 SZ_ERROR_UNSUPPORTED - Unsupported properties
162 SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src)
165 MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,
166 const unsigned char *props, size_t propsSize);
168 #define LZMA_COMPRESS_FUNC_EXPORT "LzmaCompress"
169 #define LZMA_UNCOMPRESS_FUNC_EXPORT "LzmaUncompress"