summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2021-04-04 10:37:13 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2021-04-06 09:03:19 +0100
commit602dcec85a1fc6f932bd32b49008354016c29bec (patch)
treef17351f98463b57227e5b4973b6728a87d6eea2d
parentf434088537e3c8a4bde836fcea3c159b44fe8983 (diff)
downloadlibnsgif-602dcec85a1fc6f932bd32b49008354016c29bec.tar.gz
libnsgif-602dcec85a1fc6f932bd32b49008354016c29bec.tar.bz2
lzw: Remove written member from context.
Not needed now that clear codes are handled normally.
-rw-r--r--src/lzw.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/lzw.c b/src/lzw.c
index ac710a7..a589221 100644
--- a/src/lzw.c
+++ b/src/lzw.c
@@ -83,7 +83,6 @@ struct lzw_ctx {
uint32_t table_size; /**< Next position in table to fill. */
/** Output value stack. */
- uint32_t written;
uint8_t stack_base[LZW_TABLE_ENTRY_MAX];
/** LZW code table. Generated during decode. */
@@ -302,13 +301,14 @@ static inline void lzw__table_add_entry(
/**
* Write values for this code to the output stack.
*
- * \param[in] ctx LZW reading context, updated.
- * \param[in] code LZW code to output values for.
+ * \param[in] ctx LZW reading context, updated.
+ * \param[in] code LZW code to output values for.
+ * \return Number of pixel values written.
*/
-static inline void lzw__write_pixels(struct lzw_ctx *ctx,
+static inline uint32_t lzw__write_pixels(struct lzw_ctx *ctx,
uint32_t code)
{
- uint8_t *stack_pos = ctx->stack_base + ctx->written;
+ uint8_t *stack_pos = ctx->stack_base;
struct lzw_table_entry * const table = ctx->table;
uint32_t count = table[code].count;
@@ -319,8 +319,7 @@ static inline void lzw__write_pixels(struct lzw_ctx *ctx,
code = entry->extends;
}
- ctx->written += count;
- return;
+ return count;
}
/* Exported function, documented in lzw.h */
@@ -330,8 +329,6 @@ lzw_result lzw_decode(struct lzw_ctx *ctx,
lzw_result res;
uint32_t code;
- ctx->written = 0;
-
/* Get a new code from the input */
res = lzw__read_code(&ctx->input, ctx->code_size, &code);
if (res != LZW_OK) {
@@ -365,7 +362,7 @@ lzw_result lzw_decode(struct lzw_ctx *ctx,
}
}
- lzw__write_pixels(ctx, code);
+ *written += lzw__write_pixels(ctx, code);
}
/* Store details of this code as "previous code" to the context. */
@@ -373,7 +370,5 @@ lzw_result lzw_decode(struct lzw_ctx *ctx,
ctx->prev_code_count = ctx->table[code].count;
ctx->prev_code = code;
- *written = ctx->written;
-
return LZW_OK;
}