summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2021-09-24 20:19:53 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2021-09-24 20:19:53 +0100
commit35dd8d132bf4c5433ac1e358cf26b987f566fd23 (patch)
tree84304f82de7c47a8fc2cf702cd2534c444dc8aaf
parent58c6e9393a794556bc3a192ce8227400d275d4e0 (diff)
downloadlibnsgif-35dd8d132bf4c5433ac1e358cf26b987f566fd23.tar.gz
libnsgif-35dd8d132bf4c5433ac1e358cf26b987f566fd23.tar.bz2
lzw: Optimise mapped output for frames without transparency.
-rw-r--r--src/lzw.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/lzw.c b/src/lzw.c
index babe485..710895e 100644
--- a/src/lzw.c
+++ b/src/lzw.c
@@ -568,13 +568,21 @@ static inline uint32_t lzw__map_write_fn(struct lzw_ctx *ctx,
}
output_pos += count;
- for (unsigned i = count; i != 0; i--) {
- const struct lzw_table_entry *entry = table + code;
- --output_pos;
- if (entry->value != ctx->transparency_idx) {
- *output_pos = ctx->colour_map[entry->value];
+ if (ctx->has_transparency) {
+ for (unsigned i = count; i != 0; i--) {
+ const struct lzw_table_entry *entry = table + code;
+ --output_pos;
+ if (entry->value != ctx->transparency_idx) {
+ *output_pos = ctx->colour_map[entry->value];
+ }
+ code = entry->extends;
+ }
+ } else {
+ for (unsigned i = count; i != 0; i--) {
+ const struct lzw_table_entry *entry = table + code;
+ *--output_pos = ctx->colour_map[entry->value];
+ code = entry->extends;
}
- code = entry->extends;
}
return count;