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