From c9b99d28a0be8eb76c6eb0575c7a51b524da832c Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 6 Apr 2017 17:55:12 +0100 Subject: LZW decoder: Slight code clarity and comment improvement. --- src/lzw.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lzw.c b/src/lzw.c index 6ad95aa..743f4d3 100644 --- a/src/lzw.c +++ b/src/lzw.c @@ -316,6 +316,7 @@ lzw_result lzw_decode(struct lzw_ctx *ctx, return res; } + /* Handle the new code */ if (code_new == clear_code) { /* Got Clear code */ return lzw__clear_codes(ctx, stack_pos_out); @@ -323,11 +324,11 @@ lzw_result lzw_decode(struct lzw_ctx *ctx, } else if (code_new == ctx->eoi_code) { /* Got End of Information code */ return LZW_EOI_CODE; - } - if (code_new > current_entry) { + } else if (code_new > current_entry) { /* Code is invalid */ return LZW_BAD_CODE; + } else if (code_new < current_entry) { /* Code is in table */ code_out = code_new; @@ -357,6 +358,7 @@ lzw_result lzw_decode(struct lzw_ctx *ctx, } } + /* Store details of this code as "previous code" to the context. */ ctx->previous_code_first = table[code_new].first_value; ctx->previous_code = code_new; -- cgit v1.2.3