diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2021-04-04 22:27:52 +0100 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2021-04-18 17:28:12 +0100 |
commit | 9dd7f040b1dffbe94b833aeede412054544709e8 (patch) | |
tree | 412bca740860f0131f79ff6b9cfa5a7543341a61 | |
parent | 1abac9abe5a3f4a0f1b892b9aa2e036f5871b37d (diff) | |
download | libnsgif-9dd7f040b1dffbe94b833aeede412054544709e8.tar.gz libnsgif-9dd7f040b1dffbe94b833aeede412054544709e8.tar.bz2 |
lzw: Add function for decoding multiple LZW codes at a time.
-rw-r--r-- | src/lzw.c | 26 | ||||
-rw-r--r-- | src/lzw.h | 15 |
2 files changed, 41 insertions, 0 deletions
@@ -437,3 +437,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 *restrict 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; +} @@ -91,4 +91,19 @@ lzw_result lzw_decode(struct lzw_ctx *ctx, const uint8_t *restrict *const restrict data, uint32_t *restrict used); +/** + * Read input codes until end of lzw context owned output buffer. + * + * Ensure anything in output is used before calling this, as anything + * on the there 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 *restrict used); + #endif |