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