Imported Upstream version 9.20
[platform/upstream/7zip.git] / C / LzmaLib.h
1 /* LzmaLib.h -- LZMA library interface\r
2 2009-04-07 : Igor Pavlov : Public domain */\r
3 \r
4 #ifndef __LZMA_LIB_H\r
5 #define __LZMA_LIB_H\r
6 \r
7 #include "Types.h"\r
8 \r
9 #ifdef __cplusplus\r
10 extern "C" {\r
11 #endif\r
12 \r
13 #define MY_STDAPI int MY_STD_CALL\r
14 \r
15 #define LZMA_PROPS_SIZE 5\r
16 \r
17 /*\r
18 RAM requirements for LZMA:\r
19   for compression:   (dictSize * 11.5 + 6 MB) + state_size\r
20   for decompression: dictSize + state_size\r
21     state_size = (4 + (1.5 << (lc + lp))) KB\r
22     by default (lc=3, lp=0), state_size = 16 KB.\r
23 \r
24 LZMA properties (5 bytes) format\r
25     Offset Size  Description\r
26       0     1    lc, lp and pb in encoded form.\r
27       1     4    dictSize (little endian).\r
28 */\r
29 \r
30 /*\r
31 LzmaCompress\r
32 ------------\r
33 \r
34 outPropsSize -\r
35      In:  the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\r
36      Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\r
37 \r
38   LZMA Encoder will use defult values for any parameter, if it is\r
39   -1  for any from: level, loc, lp, pb, fb, numThreads\r
40    0  for dictSize\r
41   \r
42 level - compression level: 0 <= level <= 9;\r
43 \r
44   level dictSize algo  fb\r
45     0:    16 KB   0    32\r
46     1:    64 KB   0    32\r
47     2:   256 KB   0    32\r
48     3:     1 MB   0    32\r
49     4:     4 MB   0    32\r
50     5:    16 MB   1    32\r
51     6:    32 MB   1    32\r
52     7+:   64 MB   1    64\r
53  \r
54   The default value for "level" is 5.\r
55 \r
56   algo = 0 means fast method\r
57   algo = 1 means normal method\r
58 \r
59 dictSize - The dictionary size in bytes. The maximum value is\r
60         128 MB = (1 << 27) bytes for 32-bit version\r
61           1 GB = (1 << 30) bytes for 64-bit version\r
62      The default value is 16 MB = (1 << 24) bytes.\r
63      It's recommended to use the dictionary that is larger than 4 KB and\r
64      that can be calculated as (1 << N) or (3 << N) sizes.\r
65 \r
66 lc - The number of literal context bits (high bits of previous literal).\r
67      It can be in the range from 0 to 8. The default value is 3.\r
68      Sometimes lc=4 gives the gain for big files.\r
69 \r
70 lp - The number of literal pos bits (low bits of current position for literals).\r
71      It can be in the range from 0 to 4. The default value is 0.\r
72      The lp switch is intended for periodical data when the period is equal to 2^lp.\r
73      For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's\r
74      better to set lc=0, if you change lp switch.\r
75 \r
76 pb - The number of pos bits (low bits of current position).\r
77      It can be in the range from 0 to 4. The default value is 2.\r
78      The pb switch is intended for periodical data when the period is equal 2^pb.\r
79 \r
80 fb - Word size (the number of fast bytes).\r
81      It can be in the range from 5 to 273. The default value is 32.\r
82      Usually, a big number gives a little bit better compression ratio and\r
83      slower compression process.\r
84 \r
85 numThreads - The number of thereads. 1 or 2. The default value is 2.\r
86      Fast mode (algo = 0) can use only 1 thread.\r
87 \r
88 Out:\r
89   destLen  - processed output size\r
90 Returns:\r
91   SZ_OK               - OK\r
92   SZ_ERROR_MEM        - Memory allocation error\r
93   SZ_ERROR_PARAM      - Incorrect paramater\r
94   SZ_ERROR_OUTPUT_EOF - output buffer overflow\r
95   SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r
96 */\r
97 \r
98 MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,\r
99   unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */\r
100   int level,      /* 0 <= level <= 9, default = 5 */\r
101   unsigned dictSize,  /* default = (1 << 24) */\r
102   int lc,        /* 0 <= lc <= 8, default = 3  */\r
103   int lp,        /* 0 <= lp <= 4, default = 0  */\r
104   int pb,        /* 0 <= pb <= 4, default = 2  */\r
105   int fb,        /* 5 <= fb <= 273, default = 32 */\r
106   int numThreads /* 1 or 2, default = 2 */\r
107   );\r
108 \r
109 /*\r
110 LzmaUncompress\r
111 --------------\r
112 In:\r
113   dest     - output data\r
114   destLen  - output data size\r
115   src      - input data\r
116   srcLen   - input data size\r
117 Out:\r
118   destLen  - processed output size\r
119   srcLen   - processed input size\r
120 Returns:\r
121   SZ_OK                - OK\r
122   SZ_ERROR_DATA        - Data error\r
123   SZ_ERROR_MEM         - Memory allocation arror\r
124   SZ_ERROR_UNSUPPORTED - Unsupported properties\r
125   SZ_ERROR_INPUT_EOF   - it needs more bytes in input buffer (src)\r
126 */\r
127 \r
128 MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,\r
129   const unsigned char *props, size_t propsSize);\r
130 \r
131 #ifdef __cplusplus\r
132 }\r
133 #endif\r
134 \r
135 #endif\r