summaryrefslogtreecommitdiff
path: root/lz77.h
blob: 58cb9bb88428c98b66185bdd520b1c34fdd28d6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);