fastlz.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. FastLZ - lightning-fast lossless compression library
  3. Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
  4. Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
  5. Copyright (C) 2005 Ariya Hidayat (ariya@kde.org)
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. */
  22. #ifndef FASTLZ_H
  23. #define FASTLZ_H
  24. #include "rename.h"
  25. #define FASTLZ_VERSION 0x000100
  26. #define FASTLZ_VERSION_MAJOR 0
  27. #define FASTLZ_VERSION_MINOR 0
  28. #define FASTLZ_VERSION_REVISION 0
  29. #define FASTLZ_VERSION_STRING "0.1.0"
  30. #if defined (__cplusplus)
  31. extern "C" {
  32. #endif
  33. /**
  34. Compress a block of data in the input buffer and returns the size of
  35. compressed block. The size of input buffer is specified by length. The
  36. minimum input buffer size is 16.
  37. The output buffer must be at least 5% larger than the input buffer
  38. and can not be smaller than 66 bytes.
  39. If the input is not compressible, the return value might be larger than
  40. length (input buffer size).
  41. The input buffer and the output buffer can not overlap.
  42. */
  43. int fastlz_compress(const void* input, int length, void* output);
  44. /**
  45. Decompress a block of compressed data and returns the size of the
  46. decompressed block. If error occurs, e.g. the compressed data is
  47. corrupted or the output buffer is not large enough, then 0 (zero)
  48. will be returned instead.
  49. The input buffer and the output buffer can not overlap.
  50. Decompression is memory safe and guaranteed not to write the output buffer
  51. more than what is specified in maxout.
  52. */
  53. int fastlz_decompress(const void* input, int length, void* output, int maxout);
  54. /**
  55. Compress a block of data in the input buffer and returns the size of
  56. compressed block. The size of input buffer is specified by length. The
  57. minimum input buffer size is 16.
  58. The output buffer must be at least 5% larger than the input buffer
  59. and can not be smaller than 66 bytes.
  60. If the input is not compressible, the return value might be larger than
  61. length (input buffer size).
  62. The input buffer and the output buffer can not overlap.
  63. Compression level can be specified in parameter level. At the moment,
  64. only level 1 and level 2 are supported.
  65. Level 1 is the fastest compression and generally useful for short data.
  66. Level 2 is slightly slower but it gives better compression ratio.
  67. Note that the compressed data, regardless of the level, can always be
  68. decompressed using the function fastlz_decompress above.
  69. */
  70. int fastlz_compress_level(int level, const void* input, int length, void* output);
  71. #if defined (__cplusplus)
  72. }
  73. #endif
  74. #endif /* FASTLZ_H */