summaryrefslogtreecommitdiff
path: root/src/lzw.h
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2017-04-03 10:14:25 +0100
committerMichael Drake <michael.drake@codethink.co.uk>2017-04-05 11:06:23 +0100
commit86ebd63cc1e9570cf247da26635375e31fc57d40 (patch)
treef214edddb90d031d37e96f3adbeb39119ad35429 /src/lzw.h
parent960c3b6d2229dcc7cc4a4ef60838329b78880e66 (diff)
downloadlibnsgif-86ebd63cc1e9570cf247da26635375e31fc57d40.tar.gz
libnsgif-86ebd63cc1e9570cf247da26635375e31fc57d40.tar.bz2
New LZW decoder: Add client calls to initialise LZW, and perform decode.
Diffstat (limited to 'src/lzw.h')
-rw-r--r--src/lzw.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/lzw.h b/src/lzw.h
index a908414..5812c0d 100644
--- a/src/lzw.h
+++ b/src/lzw.h
@@ -17,6 +17,10 @@
*/
+/** Maximum LZW code size in bits */
+#define LZW_CODE_MAX 12
+
+
/* Declare lzw internal context structure */
struct lzw_ctx;
@@ -27,6 +31,10 @@ typedef enum lzw_result {
LZW_OK_EOD, /**< Success; reached zero-length sub-block */
LZW_NO_MEM, /**< Error: Out of memory */
LZW_NO_DATA, /**< Error: Out of data */
+ LZW_EOI_CODE, /**< Error: End of Information code */
+ LZW_BAD_ICODE, /**< Error: Bad initial LZW code */
+ LZW_BAD_CODE, /**< Error: Bad LZW code */
+ LZW_BAD_DATA, /**< Error: Bad data */
} lzw_result;
@@ -48,5 +56,51 @@ lzw_result lzw_context_create(
void lzw_context_destroy(
struct lzw_ctx *ctx);
+/**
+ * Initialise an LZW decompression context for decoding.
+ *
+ * Caller owns neither `stack_base_out` or `stack_pos_out`.
+ *
+ * \param[in] ctx The LZW decompression context to initialise.
+ * \param[in] compressed_data The compressed data.
+ * \param[in] compressed_data_len Byte length of compressed data.
+ * \param[in] compressed_data_pos Start position in data. Must be position
+ * of a size byte at sub-block start.
+ * \param[in] code_size The initial LZW code size to use.
+ * \param[out] stack_base_out Returns base of decompressed data stack.
+ * \param[out] stack_pos_out Returns current stack position.
+ * There are `stack_pos_out - stack_base_out`
+ * current stack entries.
+ * \return LZW_OK on success, or appropriate error code otherwise.
+ */
+lzw_result lzw_decode_init(
+ struct lzw_ctx *ctx,
+ const uint8_t *compressed_data,
+ uint32_t compressed_data_len,
+ uint32_t compressed_data_pos,
+ uint8_t code_size,
+ const uint8_t ** const stack_base_out,
+ const uint8_t ** const stack_pos_out);
+
+/**
+ * Fill the LZW stack with decompressed data
+ *
+ * Ensure anything on the stack is used before calling this, as anything
+ * on the stack before this call will be trampled.
+ *
+ * Caller does not own `stack_pos_out`.
+ *
+ * \param[in] ctx LZW reading context, updated.
+ * \param[out] stack_pos_out Returns current stack position.
+ * Use with `stack_base_out` value from previous
+ * lzw_decode_init() call.
+ * There are `stack_pos_out - stack_base_out`
+ * current stack entries.
+ * \return LZW_OK on success, or appropriate error code otherwise.
+ */
+lzw_result lzw_decode(
+ struct lzw_ctx *ctx,
+ const uint8_t ** const stack_pos_out);
+
#endif