| 1 |
/* LzmaLib.h -- LZMA library interface |
| 2 |
2008-08-05 |
| 3 |
Igor Pavlov |
| 4 |
Public domain */ |
| 5 |
// ---------------------------------------------------------------------------- |
| 6 |
// Copyright (C) 2014 |
| 7 |
// David Freese, W1HKJ |
| 8 |
// |
| 9 |
// This file is part of flmsg |
| 10 |
// |
| 11 |
// flrig is free software; you can redistribute it and/or modify |
| 12 |
// it under the terms of the GNU General Public License as published by |
| 13 |
// the Free Software Foundation; either version 3 of the License, or |
| 14 |
// (at your option) any later version. |
| 15 |
// |
| 16 |
// flrig is distributed in the hope that it will be useful, |
| 17 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
// GNU General Public License for more details. |
| 20 |
// |
| 21 |
// You should have received a copy of the GNU General Public License |
| 22 |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 |
// ---------------------------------------------------------------------------- |
| 24 |
|
| 25 |
#ifndef __LZMALIB_H |
| 26 |
#define __LZMALIB_H |
| 27 |
|
| 28 |
#include "Types.h" |
| 29 |
|
| 30 |
#ifdef __cplusplus |
| 31 |
#define MY_EXTERN_C extern "C" |
| 32 |
#else |
| 33 |
#define MY_EXTERN_C extern |
| 34 |
#endif |
| 35 |
|
| 36 |
#define MY_STDAPI MY_EXTERN_C int MY_STD_CALL |
| 37 |
|
| 38 |
#define LZMA_PROPS_SIZE 5 |
| 39 |
|
| 40 |
/* |
| 41 |
RAM requirements for LZMA: |
| 42 |
for compression: (dictSize * 11.5 + 6 MB) + state_size |
| 43 |
for decompression: dictSize + state_size |
| 44 |
state_size = (4 + (1.5 << (lc + lp))) KB |
| 45 |
by default (lc=3, lp=0), state_size = 16 KB. |
| 46 |
|
| 47 |
LZMA properties (5 bytes) format |
| 48 |
Offset Size Description |
| 49 |
0 1 lc, lp and pb in encoded form. |
| 50 |
1 4 dictSize (little endian). |
| 51 |
*/ |
| 52 |
|
| 53 |
/* |
| 54 |
LzmaCompress |
| 55 |
------------ |
| 56 |
|
| 57 |
outPropsSize - |
| 58 |
In: the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5. |
| 59 |
Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5. |
| 60 |
|
| 61 |
LZMA Encoder will use defult values for any parameter, if it is |
| 62 |
-1 for any from: level, loc, lp, pb, fb, numThreads |
| 63 |
0 for dictSize |
| 64 |
|
| 65 |
level - compression level: 0 <= level <= 9; |
| 66 |
|
| 67 |
level dictSize algo fb |
| 68 |
0: 16 KB 0 32 |
| 69 |
1: 64 KB 0 32 |
| 70 |
2: 256 KB 0 32 |
| 71 |
3: 1 MB 0 32 |
| 72 |
4: 4 MB 0 32 |
| 73 |
5: 16 MB 1 32 |
| 74 |
6: 32 MB 1 32 |
| 75 |
7+: 64 MB 1 64 |
| 76 |
|
| 77 |
The default value for "level" is 5. |
| 78 |
|
| 79 |
algo = 0 means fast method |
| 80 |
algo = 1 means normal method |
| 81 |
|
| 82 |
dictSize - The dictionary size in bytes. The maximum value is |
| 83 |
128 MB = (1 << 27) bytes for 32-bit version |
| 84 |
1 GB = (1 << 30) bytes for 64-bit version |
| 85 |
The default value is 16 MB = (1 << 24) bytes. |
| 86 |
It's recommended to use the dictionary that is larger than 4 KB and |
| 87 |
that can be calculated as (1 << N) or (3 << N) sizes. |
| 88 |
|
| 89 |
lc - The number of literal context bits (high bits of previous literal). |
| 90 |
It can be in the range from 0 to 8. The default value is 3. |
| 91 |
Sometimes lc=4 gives the gain for big files. |
| 92 |
|
| 93 |
lp - The number of literal pos bits (low bits of current position for literals). |
| 94 |
It can be in the range from 0 to 4. The default value is 0. |
| 95 |
The lp switch is intended for periodical data when the period is equal to 2^lp. |
| 96 |
For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's |
| 97 |
better to set lc=0, if you change lp switch. |
| 98 |
|
| 99 |
pb - The number of pos bits (low bits of current position). |
| 100 |
It can be in the range from 0 to 4. The default value is 2. |
| 101 |
The pb switch is intended for periodical data when the period is equal 2^pb. |
| 102 |
|
| 103 |
fb - Word size (the number of fast bytes). |
| 104 |
It can be in the range from 5 to 273. The default value is 32. |
| 105 |
Usually, a big number gives a little bit better compression ratio and |
| 106 |
slower compression process. |
| 107 |
|
| 108 |
numThreads - The number of thereads. 1 or 2. The default value is 2. |
| 109 |
Fast mode (algo = 0) can use only 1 thread. |
| 110 |
|
| 111 |
Out: |
| 112 |
destLen - processed output size |
| 113 |
Returns: |
| 114 |
SZ_OK - OK |
| 115 |
SZ_ERROR_MEM - Memory allocation error |
| 116 |
SZ_ERROR_PARAM - Incorrect paramater |
| 117 |
SZ_ERROR_OUTPUT_EOF - output buffer overflow |
| 118 |
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) |
| 119 |
*/ |
| 120 |
|
| 121 |
MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, |
| 122 |
unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */ |
| 123 |
int level, /* 0 <= level <= 9, default = 5 */ |
| 124 |
unsigned dictSize, /* default = (1 << 24) */ |
| 125 |
int lc, /* 0 <= lc <= 8, default = 3 */ |
| 126 |
int lp, /* 0 <= lp <= 4, default = 0 */ |
| 127 |
int pb, /* 0 <= pb <= 4, default = 2 */ |
| 128 |
int fb, /* 5 <= fb <= 273, default = 32 */ |
| 129 |
int numThreads /* 1 or 2, default = 2 */ |
| 130 |
); |
| 131 |
|
| 132 |
/* |
| 133 |
LzmaUncompress |
| 134 |
-------------- |
| 135 |
In: |
| 136 |
dest - output data |
| 137 |
destLen - output data size |
| 138 |
src - input data |
| 139 |
srcLen - input data size |
| 140 |
Out: |
| 141 |
destLen - processed output size |
| 142 |
srcLen - processed input size |
| 143 |
Returns: |
| 144 |
SZ_OK - OK |
| 145 |
SZ_ERROR_DATA - Data error |
| 146 |
SZ_ERROR_MEM - Memory allocation arror |
| 147 |
SZ_ERROR_UNSUPPORTED - Unsupported properties |
| 148 |
SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src) |
| 149 |
*/ |
| 150 |
|
| 151 |
MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen, |
| 152 |
const unsigned char *props, size_t propsSize); |
| 153 |
|
| 154 |
#endif |