From 715a3bef377aeee898c427be99b1acf440b4a5e5 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 10 May 2017 07:10:14 +0100 Subject: Factor LZ77 and Huffman routines out of deflate.c. The general routines for analysing a buffer into an LZ77ish stream of literals and matches, and for constructing a Huffman tree in canonical format, now live in their own source files so that they can be reused for other similar compression formats. Deflate-specific details like the exact file encoding are left in deflate.c. --- lz77.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lz77.h (limited to 'lz77.h') diff --git a/lz77.h b/lz77.h new file mode 100644 index 0000000..58cb9bb --- /dev/null +++ b/lz77.h @@ -0,0 +1,35 @@ +/* + * lz77.h: common LZ77 compression code between Deflate and LZX. + */ + +/* + * The parameter structure you pass to the lz77.c routines to give + * them a way to return the compressed output stream. + */ +struct LZ77InternalContext; +struct LZ77Context { + struct LZ77InternalContext *ictx; + void *userdata; + void (*literal) (struct LZ77Context *ctx, unsigned char c); + void (*match) (struct LZ77Context *ctx, int distance, int len); +}; + +/* + * Initialise the private fields of an LZ77Context. It's up to the + * user to initialise the public fields. + */ +void lz77_init(struct LZ77Context *ctx, int winsize); + +/* + * Clean up the private fields of an LZ77Context. + */ +void lz77_cleanup(struct LZ77Context *ctx); + +/* + * Supply data to be compressed. Will update the private fields of + * the LZ77Context, and will call literal() and match() to output. + * If `compress' is FALSE, it will never emit a match, but will + * instead call literal() for everything. + */ +void lz77_compress(struct LZ77Context *ctx, + const unsigned char *data, int len, int compress); -- cgit v1.1