From c7a0bab4322ba7d3112a08c4c4c3c414e9747a0c Mon Sep 17 00:00:00 2001 From: Owen Healy Date: Thu, 1 May 2025 23:50:10 -0400 Subject: [PATCH 1/2] Restore nearest behavior --- src/SixelEncoder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SixelEncoder.ts b/src/SixelEncoder.ts index 71addf1..8ac5e2a 100644 --- a/src/SixelEncoder.ts +++ b/src/SixelEncoder.ts @@ -91,7 +91,7 @@ function processBand( // skip expensive color to palette matching if we have same color as before if (color !== oldColor) { oldColor = color; - idx = alpha(color) ? colorMap.get(color) || 0 : 0; + idx = alpha(color) ? colorMap.get(color) : 0; if (idx === undefined) { idx = nearestColorIndex(color, paletteRGB) + 1; colorMap.set(color, idx); From 78876a12f3911500752abb68e542ba7d5ea21f94 Mon Sep 17 00:00:00 2001 From: Owen Healy Date: Fri, 2 May 2025 08:23:24 -0400 Subject: [PATCH 2/2] Fix type error --- src/SixelEncoder.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/SixelEncoder.ts b/src/SixelEncoder.ts index 8ac5e2a..415922e 100644 --- a/src/SixelEncoder.ts +++ b/src/SixelEncoder.ts @@ -91,11 +91,14 @@ function processBand( // skip expensive color to palette matching if we have same color as before if (color !== oldColor) { oldColor = color; - idx = alpha(color) ? colorMap.get(color) : 0; - if (idx === undefined) { + let maybeIDX = alpha(color) ? colorMap.get(color) : 0; + if (maybeIDX === undefined) { idx = nearestColorIndex(color, paletteRGB) + 1; colorMap.set(color, idx); } + else { + idx = maybeIDX; + } // extend accu/code handling to new color if (slots[idx] === -1) { targets.push([]);