/* lzwh.h : LZW compression with Horspool's phased-in coding and accelerated loading */ /* Made by a machine. PUBLIC DOMAIN (CC0-1.0) */ #ifndef LZWH_H #define LZWH_H #include #include #define LZWH_DICT_BITS_DEFAULT 16 #define LZWH_DICT_BITS_MIN 9 #define LZWH_DICT_BITS_MAX 16 #define LZWH_ACCEL_DEFAULT 1 #define LZWH_OK 0 #define LZWH_ERR (-1) #define LZWH_ERR_NOMEM (-2) #define LZWH_ERR_CORRUPT (-3) struct lzwh_params { unsigned dict_bits; unsigned accel_max; }; /** Compress src into a malloc'd buffer returned via out/out_len. * * dict_bits controls max dictionary size (9..16, default 16). * accel_max controls accelerated loading depth (1 = standard LZW, * higher = more aggressive preloading, 3-5 recommended for text). * Returns LZWH_OK on success, negative on error. */ int lzwh_compress(const uint8_t *src, size_t src_len, uint8_t **out, size_t *out_len, const struct lzwh_params *params); /** Decompress src into a malloc'd buffer returned via out/out_len. * * params must match those used during compression. * Returns LZWH_OK on success, negative on error. */ int lzwh_decompress(const uint8_t *src, size_t src_len, uint8_t **out, size_t *out_len, const struct lzwh_params *params); /** Fill params with defaults. */ void lzwh_params_init(struct lzwh_params *p); #endif /* LZWH_H */