LzmaLib.h 4.4 KB

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