From 2f9f236f13b318216784606901d008c8522bc65f Mon Sep 17 00:00:00 2001 From: Noel Sabia Date: Fri, 23 Oct 2026 21:50:17 +0200 Subject: [PATCH] fix(favicon): keep the ICO transparent when BACKGROUND is null The documented null option fell through to opaque black: the BGRA writer defaulted to #000000 and hardcoded alpha 0xff. --- scripts/generate-favicon.mjs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/generate-favicon.mjs b/scripts/generate-favicon.mjs index 516e531..f028be4 100644 --- a/scripts/generate-favicon.mjs +++ b/scripts/generate-favicon.mjs @@ -67,18 +67,20 @@ const ico = () => { bitmap.writeUInt16LE(32, 14) // bits per pixel bitmap.writeUInt32LE(xorSize + maskSize, 20) // image size - // XOR bitmap: bottom-up rows of BGRA. + // XOR bitmap: bottom-up rows of BGRA. With a null BACKGROUND the pixel stays + // zeroed and alpha 0, which is how a 32bpp ICO carries transparency. let offset = 40 for (let y = SIZE - 1; y >= 0; y--) { for (let x = 0; x < SIZE; x++) { - const [r, g, b] = hex(colorAt(x, y) ?? '#000000') + const color = colorAt(x, y) + const [r, g, b] = color ? hex(color) : [0, 0, 0] bitmap[offset++] = b bitmap[offset++] = g bitmap[offset++] = r - bitmap[offset++] = 0xff + bitmap[offset++] = color ? 0xff : 0 } } - // AND mask stays zeroed: every pixel is opaque. + // AND mask stays zeroed: 32bpp readers use the alpha channel instead. const header = Buffer.alloc(6) header.writeUInt16LE(0, 0) // reserved