summaryrefslogtreecommitdiff
path: root/lz77.h
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2017-05-10 07:10:14 +0100
committerSimon Tatham <anakin@pobox.com>2017-05-13 18:22:09 +0100
commit715a3bef377aeee898c427be99b1acf440b4a5e5 (patch)
tree6ff1d6eecb42df91a4e174644adb0954da44d9fa /lz77.h
parente446ba3cf1f72dca390e9c9a5fe987f3dcccd440 (diff)
downloadhalibut-715a3bef377aeee898c427be99b1acf440b4a5e5.zip
halibut-715a3bef377aeee898c427be99b1acf440b4a5e5.tar.gz
halibut-715a3bef377aeee898c427be99b1acf440b4a5e5.tar.bz2
halibut-715a3bef377aeee898c427be99b1acf440b4a5e5.tar.xz
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.
Diffstat (limited to 'lz77.h')
-rw-r--r--lz77.h35
1 files changed, 35 insertions, 0 deletions
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);