]> git.cworth.org Git - vogl/blob - src/voglcore/lzma_LzmaLib.h
Initial vogl checkin
[vogl] / src / voglcore / lzma_LzmaLib.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
5  * All Rights Reserved.
6  *
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:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
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
23  * THE SOFTWARE.
24  *
25  **************************************************************************/
26
27 /* LzmaLib.h -- LZMA library interface
28 2008-08-05
29 Igor Pavlov
30 Public domain */
31
32 #ifndef __LZMALIB_H
33 #define __LZMALIB_H
34
35 #include "lzma_Types.h"
36
37 namespace vogl
38 {
39
40 #if 0
41 #ifdef __cplusplus
42 #define MY_EXTERN_C extern "C"
43 #else
44 #define MY_EXTERN_C extern
45 #endif
46
47 #define MY_STDAPI MY_EXTERN_C int MY_STD_CALL
48 #else
49 #define MY_STDAPI int MY_STD_CALL
50 #endif
51
52 #define LZMA_PROPS_SIZE 5
53
54     /*
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.
60
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).
65 */
66
67     /*
68 LzmaCompress
69 ------------
70
71 outPropsSize -
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.
74
75   LZMA Encoder will use defult values for any parameter, if it is
76   -1  for any from: level, loc, lp, pb, fb, numThreads
77    0  for dictSize
78
79 level - compression level: 0 <= level <= 9;
80
81   level dictSize algo  fb
82     0:    16 KB   0    32
83     1:    64 KB   0    32
84     2:   256 KB   0    32
85     3:     1 MB   0    32
86     4:     4 MB   0    32
87     5:    16 MB   1    32
88     6:    32 MB   1    32
89     7+:   64 MB   1    64
90
91   The default value for "level" is 5.
92
93   algo = 0 means fast method
94   algo = 1 means normal method
95
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.
102
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.
106
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.
112
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.
116
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.
121
122 numThreads - The number of thereads. 1 or 2. The default value is 2.
123      Fast mode (algo = 0) can use only 1 thread.
124
125 Out:
126   destLen  - processed output size
127 Returns:
128   SZ_OK               - OK
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)
133 */
134
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 */
144                            );
145
146     /*
147 LzmaUncompress
148 --------------
149 In:
150   dest     - output data
151   destLen  - output data size
152   src      - input data
153   srcLen   - input data size
154 Out:
155   destLen  - processed output size
156   srcLen   - processed input size
157 Returns:
158   SZ_OK                - OK
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)
163 */
164
165     MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,
166                              const unsigned char *props, size_t propsSize);
167
168 #define LZMA_COMPRESS_FUNC_EXPORT "LzmaCompress"
169 #define LZMA_UNCOMPRESS_FUNC_EXPORT "LzmaUncompress"
170 }
171
172 #endif