LzmaLib.h 4.3 KB

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