huffman.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Huffandpuff minimal Huffman coder
  3. *
  4. * (c)2013 Adam Ierymenko <[email protected]>
  5. * This code is in the public domain and is distributed with NO WARRANTY.
  6. */
  7. #ifndef ____HUFFMAN_H
  8. #define ____HUFFMAN_H
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /**
  13. * Required size of huffheap parameter to compress and decompress
  14. *
  15. * Note: if you change any of the data types in the _huffman_node
  16. * or _huffman_encode_table structs in huffman.c, this also must be
  17. * changed.
  18. */
  19. #define HUFFHEAP_SIZE ((sizeof(double) * 257) + (((sizeof(void *) * 4) + sizeof(double) + sizeof(unsigned long)) * (257 * 3)) + ((sizeof(unsigned long) + sizeof(unsigned long)) * 257))
  20. /**
  21. * Huffman encode a block of data
  22. *
  23. * @param in Input data
  24. * @param inlen Input data length
  25. * @param out Output buffer
  26. * @param outlen Output buffer length
  27. * @param huffheap Heap memory to use for compression (must be HUFFHEAP_SIZE in size)
  28. * @return Size of encoded result or 0 on out buffer overrun
  29. */
  30. extern unsigned long huffman_compress(const unsigned char *in,unsigned long inlen,unsigned char *out,unsigned long outlen,void *huffheap);
  31. /**
  32. * Huffman decode a block of data
  33. *
  34. * @param in Input data
  35. * @param inlen Length of input data
  36. * @param out Output buffer
  37. * @param outlen Length of output buffer
  38. * @param huffheap Heap memory to use for decompression (must be HUFFHEAP_SIZE in size)
  39. * @return Size of decoded result or 0 on out buffer overrun or corrupt input data
  40. */
  41. extern unsigned long huffman_decompress(const unsigned char *in,unsigned long inlen,unsigned char *out,unsigned long outlen,void *huffheap);
  42. #ifdef __cplusplus
  43. }
  44. #endif
  45. #endif