xref: /third_party/lzma/C/LzmaLib.h (revision 370b324c)
1/* LzmaLib.h -- LZMA library interface
22023-04-02 : Igor Pavlov : Public domain */
3
4#ifndef ZIP7_INC_LZMA_LIB_H
5#define ZIP7_INC_LZMA_LIB_H
6
7#include "7zTypes.h"
8
9EXTERN_C_BEGIN
10
11#define Z7_STDAPI int Z7_STDCALL
12
13#define LZMA_PROPS_SIZE 5
14
15/*
16RAM requirements for LZMA:
17  for compression:   (dictSize * 11.5 + 6 MB) + state_size
18  for decompression: dictSize + state_size
19    state_size = (4 + (1.5 << (lc + lp))) KB
20    by default (lc=3, lp=0), state_size = 16 KB.
21
22LZMA properties (5 bytes) format
23    Offset Size  Description
24      0     1    lc, lp and pb in encoded form.
25      1     4    dictSize (little endian).
26*/
27
28/*
29LzmaCompress
30------------
31
32outPropsSize -
33     In:  the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
34     Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
35
36  LZMA Encoder will use defult values for any parameter, if it is
37  -1  for any from: level, loc, lp, pb, fb, numThreads
38   0  for dictSize
39
40level - compression level: 0 <= level <= 9;
41
42  level dictSize algo  fb
43    0:    64 KB   0    32
44    1:   256 KB   0    32
45    2:     1 MB   0    32
46    3:     4 MB   0    32
47    4:    16 MB   0    32
48    5:    16 MB   1    32
49    6:    32 MB   1    32
50    7:    32 MB   1    64
51    8:    64 MB   1    64
52    9:    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
88In:
89  dest     - output data buffer
90  destLen  - output data buffer size
91  src      - input data
92  srcLen   - input data size
93Out:
94  destLen  - processed output size
95Returns:
96  SZ_OK               - OK
97  SZ_ERROR_MEM        - Memory allocation error
98  SZ_ERROR_PARAM      - Incorrect paramater
99  SZ_ERROR_OUTPUT_EOF - output buffer overflow
100  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)
101*/
102
103Z7_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
104  unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */
105  int level,      /* 0 <= level <= 9, default = 5 */
106  unsigned dictSize,  /* default = (1 << 24) */
107  int lc,        /* 0 <= lc <= 8, default = 3  */
108  int lp,        /* 0 <= lp <= 4, default = 0  */
109  int pb,        /* 0 <= pb <= 4, default = 2  */
110  int fb,        /* 5 <= fb <= 273, default = 32 */
111  int numThreads /* 1 or 2, default = 2 */
112  );
113
114/*
115LzmaUncompress
116--------------
117In:
118  dest     - output data buffer
119  destLen  - output data buffer size
120  src      - input data
121  srcLen   - input data size
122Out:
123  destLen  - processed output size
124  srcLen   - processed input size
125Returns:
126  SZ_OK                - OK
127  SZ_ERROR_DATA        - Data error
128  SZ_ERROR_MEM         - Memory allocation arror
129  SZ_ERROR_UNSUPPORTED - Unsupported properties
130  SZ_ERROR_INPUT_EOF   - it needs more bytes in input buffer (src)
131*/
132
133Z7_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,
134  const unsigned char *props, size_t propsSize);
135
136EXTERN_C_END
137
138#endif
139