nuclear@14: /* LzmaLib.h -- LZMA library interface
nuclear@14: 2008-08-05
nuclear@14: Igor Pavlov
nuclear@14: Public domain */
nuclear@14: 
nuclear@14: #ifndef __LZMALIB_H
nuclear@14: #define __LZMALIB_H
nuclear@14: 
nuclear@14: #include "Types.h"
nuclear@14: 
nuclear@14: #ifdef __cplusplus
nuclear@14:   #define MY_EXTERN_C extern "C"
nuclear@14: #else
nuclear@14:   #define MY_EXTERN_C extern
nuclear@14: #endif
nuclear@14: 
nuclear@14: #define MY_STDAPI MY_EXTERN_C int MY_STD_CALL
nuclear@14: 
nuclear@14: #define LZMA_PROPS_SIZE 5
nuclear@14: 
nuclear@14: /*
nuclear@14: RAM requirements for LZMA:
nuclear@14:   for compression:   (dictSize * 11.5 + 6 MB) + state_size
nuclear@14:   for decompression: dictSize + state_size
nuclear@14:     state_size = (4 + (1.5 << (lc + lp))) KB
nuclear@14:     by default (lc=3, lp=0), state_size = 16 KB.
nuclear@14: 
nuclear@14: LZMA properties (5 bytes) format
nuclear@14:     Offset Size  Description
nuclear@14:       0     1    lc, lp and pb in encoded form.
nuclear@14:       1     4    dictSize (little endian).
nuclear@14: */
nuclear@14: 
nuclear@14: /*
nuclear@14: LzmaCompress
nuclear@14: ------------
nuclear@14: 
nuclear@14: outPropsSize -
nuclear@14:      In:  the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
nuclear@14:      Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
nuclear@14: 
nuclear@14:   LZMA Encoder will use defult values for any parameter, if it is
nuclear@14:   -1  for any from: level, loc, lp, pb, fb, numThreads
nuclear@14:    0  for dictSize
nuclear@14:   
nuclear@14: level - compression level: 0 <= level <= 9;
nuclear@14: 
nuclear@14:   level dictSize algo  fb
nuclear@14:     0:    16 KB   0    32
nuclear@14:     1:    64 KB   0    32
nuclear@14:     2:   256 KB   0    32
nuclear@14:     3:     1 MB   0    32
nuclear@14:     4:     4 MB   0    32
nuclear@14:     5:    16 MB   1    32
nuclear@14:     6:    32 MB   1    32
nuclear@14:     7+:   64 MB   1    64
nuclear@14:  
nuclear@14:   The default value for "level" is 5.
nuclear@14: 
nuclear@14:   algo = 0 means fast method
nuclear@14:   algo = 1 means normal method
nuclear@14: 
nuclear@14: dictSize - The dictionary size in bytes. The maximum value is
nuclear@14:         128 MB = (1 << 27) bytes for 32-bit version
nuclear@14:           1 GB = (1 << 30) bytes for 64-bit version
nuclear@14:      The default value is 16 MB = (1 << 24) bytes.
nuclear@14:      It's recommended to use the dictionary that is larger than 4 KB and
nuclear@14:      that can be calculated as (1 << N) or (3 << N) sizes.
nuclear@14: 
nuclear@14: lc - The number of literal context bits (high bits of previous literal).
nuclear@14:      It can be in the range from 0 to 8. The default value is 3.
nuclear@14:      Sometimes lc=4 gives the gain for big files.
nuclear@14: 
nuclear@14: lp - The number of literal pos bits (low bits of current position for literals).
nuclear@14:      It can be in the range from 0 to 4. The default value is 0.
nuclear@14:      The lp switch is intended for periodical data when the period is equal to 2^lp.
nuclear@14:      For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's
nuclear@14:      better to set lc=0, if you change lp switch.
nuclear@14: 
nuclear@14: pb - The number of pos bits (low bits of current position).
nuclear@14:      It can be in the range from 0 to 4. The default value is 2.
nuclear@14:      The pb switch is intended for periodical data when the period is equal 2^pb.
nuclear@14: 
nuclear@14: fb - Word size (the number of fast bytes).
nuclear@14:      It can be in the range from 5 to 273. The default value is 32.
nuclear@14:      Usually, a big number gives a little bit better compression ratio and
nuclear@14:      slower compression process.
nuclear@14: 
nuclear@14: numThreads - The number of thereads. 1 or 2. The default value is 2.
nuclear@14:      Fast mode (algo = 0) can use only 1 thread.
nuclear@14: 
nuclear@14: Out:
nuclear@14:   destLen  - processed output size
nuclear@14: Returns:
nuclear@14:   SZ_OK               - OK
nuclear@14:   SZ_ERROR_MEM        - Memory allocation error
nuclear@14:   SZ_ERROR_PARAM      - Incorrect paramater
nuclear@14:   SZ_ERROR_OUTPUT_EOF - output buffer overflow
nuclear@14:   SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)
nuclear@14: */
nuclear@14: 
nuclear@14: MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
nuclear@14:   unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */
nuclear@14:   int level,      /* 0 <= level <= 9, default = 5 */
nuclear@14:   unsigned dictSize,  /* default = (1 << 24) */
nuclear@14:   int lc,         /* 0 <= lc <= 8, default = 3  */
nuclear@14:   int lp,         /* 0 <= lp <= 4, default = 0  */
nuclear@14:   int pb,         /* 0 <= pb <= 4, default = 2  */
nuclear@14:   int fb,         /* 5 <= fb <= 273, default = 32 */
nuclear@14:   int numThreads, /* 1 or 2, default = 2 */
nuclear@14:   int algo        /* 0 = fast, 1 = normal, default = 0 for level < 5, 1 for level >= 5 */
nuclear@14:   );
nuclear@14: 
nuclear@14: /*
nuclear@14: LzmaUncompress
nuclear@14: --------------
nuclear@14: In:
nuclear@14:   dest     - output data
nuclear@14:   destLen  - output data size
nuclear@14:   src      - input data
nuclear@14:   srcLen   - input data size
nuclear@14: Out:
nuclear@14:   destLen  - processed output size
nuclear@14:   srcLen   - processed input size
nuclear@14: Returns:
nuclear@14:   SZ_OK                - OK
nuclear@14:   SZ_ERROR_DATA        - Data error
nuclear@14:   SZ_ERROR_MEM         - Memory allocation arror
nuclear@14:   SZ_ERROR_UNSUPPORTED - Unsupported properties
nuclear@14:   SZ_ERROR_INPUT_EOF   - it needs more bytes in input buffer (src)
nuclear@14: */
nuclear@14: 
nuclear@14: MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,
nuclear@14:   const unsigned char *props, size_t propsSize);
nuclear@14: 
nuclear@14: #endif