summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2021-04-04 22:27:52 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2021-04-04 22:27:52 +0100
commit18afa8d0048c86216643ab2e883503ab4c413f38 (patch)
treeae48f27a8571f051a5215d41f8d72a009691cd60
parentc8f094505a7d53997ef8f8b2d05fc114eee9315b (diff)
downloadlibnsgif-18afa8d0048c86216643ab2e883503ab4c413f38.tar.gz
libnsgif-18afa8d0048c86216643ab2e883503ab4c413f38.tar.bz2
lzw: Add function for decoding multiple LZW codes at a time.
-rw-r--r--src/lzw.c26
-rw-r--r--src/lzw.h15
2 files changed, 41 insertions, 0 deletions
diff --git a/src/lzw.c b/src/lzw.c
index 8c8911a..2f604e4 100644
--- a/src/lzw.c
+++ b/src/lzw.c
@@ -426,3 +426,29 @@ lzw_result lzw_decode(struct lzw_ctx *ctx,
return lzw__decode(ctx, ctx->stack_base, sizeof(ctx->stack_base),
lzw__write_pixels, used);
}
+
+/* Exported function, documented in lzw.h */
+lzw_result lzw_decode_continuous(struct lzw_ctx *ctx,
+ const uint8_t ** const data,
+ uint32_t *used)
+{
+ *used = 0;
+ *data = ctx->stack_base;
+
+ if (ctx->output_left != 0) {
+ *used += lzw__write_pixels(ctx,
+ ctx->stack_base, sizeof(ctx->stack_base), *used,
+ ctx->output_code, ctx->output_left);
+ }
+
+ while (*used != sizeof(ctx->stack_base)) {
+ lzw_result res = lzw__decode(ctx,
+ ctx->stack_base, sizeof(ctx->stack_base),
+ lzw__write_pixels, used);
+ if (res != LZW_OK) {
+ return res;
+ }
+ }
+
+ return LZW_OK;
+}
diff --git a/src/lzw.h b/src/lzw.h
index 4b6bfab..ec7709a 100644
--- a/src/lzw.h
+++ b/src/lzw.h
@@ -91,4 +91,19 @@ lzw_result lzw_decode(struct lzw_ctx *ctx,
const uint8_t ** const data,
uint32_t *used);
+/**
+ * Read input codes until end of input or output buffer is full.
+ *
+ * Ensure anything on the stack is used before calling this, as anything
+ * on the stack before this call will be trampled.
+ *
+ * \param[in] ctx LZW reading context, updated.
+ * \param[out] data Returns pointer to array of output values.
+ * \param[out] used Returns the number of values written to data.
+ * \return LZW_OK on success, or appropriate error code otherwise.
+ */
+lzw_result lzw_decode_continuous(struct lzw_ctx *ctx,
+ const uint8_t ** const data,
+ uint32_t *used);
+
#endif