From 7d33b933107bb3fc9900cd9084ee839c45c70885 Mon Sep 17 00:00:00 2001 From: zk-phi Date: Sat, 22 Jun 2024 22:05:55 +0900 Subject: [PATCH] Use rgba4444 format for transparent animated GIFs --- src/gifworker.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gifworker.ts b/src/gifworker.ts index 53c4b567..af89b0bd 100644 --- a/src/gifworker.ts +++ b/src/gifworker.ts @@ -8,8 +8,9 @@ const encoder = GIFEncoder(); ctx.addEventListener("message", (msg) => { if (msg.data.addFrame) { const { data, transparent, width, height, delay } = msg.data.addFrame; - const palette = quantize(data, 256, { oneBitAlpha: transparent }); - const index = applyPalette(data, palette); + const format = transparent ? "rgba4444" : "rgb565"; + const palette = quantize(data, 256, { format, oneBitAlpha: transparent }); + const index = applyPalette(data, palette, format); encoder.writeFrame(index, width, height, { palette, delay, transparent }); } else if (msg.data.finish) { encoder.finish();