From 960c3b6d2229dcc7cc4a4ef60838329b78880e66 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Mon, 3 Apr 2017 10:07:23 +0100 Subject: New LZW decoder: Add client calls to create/destroy LZW contexts. --- src/lzw.c | 28 ++++++++++++++++++++++++++++ src/lzw.h | 24 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/lzw.c b/src/lzw.c index 23c815e..4f7ff8f 100644 --- a/src/lzw.c +++ b/src/lzw.c @@ -41,6 +41,34 @@ struct lzw_read_ctx { uint32_t sb_bit_count; /**< Bit count in sub-block */ }; +/** + * LZW decompression context. + */ +struct lzw_ctx { + /** Input reading context */ + struct lzw_read_ctx input; +}; + + +/* Exported function, documented in lzw.h */ +lzw_result lzw_context_create(struct lzw_ctx **ctx) +{ + struct lzw_ctx *c = malloc(sizeof(*c)); + if (c == NULL) { + return LZW_NO_MEM; + } + + *ctx = c; + return LZW_OK; +} + + +/* Exported function, documented in lzw.h */ +void lzw_context_destroy(struct lzw_ctx *ctx) +{ + free(ctx); +} + /** * Advance the context to the next sub-block in the input data. diff --git a/src/lzw.h b/src/lzw.h index 0683ad0..a908414 100644 --- a/src/lzw.h +++ b/src/lzw.h @@ -17,12 +17,36 @@ */ +/* Declare lzw internal context structure */ +struct lzw_ctx; + + /** LZW decoding response codes */ typedef enum lzw_result { LZW_OK, /**< Success */ LZW_OK_EOD, /**< Success; reached zero-length sub-block */ + LZW_NO_MEM, /**< Error: Out of memory */ LZW_NO_DATA, /**< Error: Out of data */ } lzw_result; +/** + * Create an LZW decompression context. + * + * \param[out] ctx Returns an LZW decompression context. Caller owned, + * free with lzw_context_destroy(). + * \return LZW_OK on success, or appropriate error code otherwise. + */ +lzw_result lzw_context_create( + struct lzw_ctx **ctx); + +/** + * Destroy an LZW decompression context. + * + * \param[in] ctx The LZW decompression context to destroy. + */ +void lzw_context_destroy( + struct lzw_ctx *ctx); + + #endif -- cgit v1.2.3