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.
This commit is contained in:
1 parent
ad4e8d7bd9
commit
2f9f236f13
1 file changed
+6
-4
@@ -67,18 +67,20 @@ const ico = () => {
|
|||||||
bitmap.writeUInt16LE(32, 14) // bits per pixel
|
bitmap.writeUInt16LE(32, 14) // bits per pixel
|
||||||
bitmap.writeUInt32LE(xorSize + maskSize, 20) // image size
|
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
|
let offset = 40
|
||||||
for (let y = SIZE - 1; y >= 0; y--) {
|
for (let y = SIZE - 1; y >= 0; y--) {
|
||||||
for (let x = 0; x < SIZE; x++) {
|
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++] = b
|
||||||
bitmap[offset++] = g
|
bitmap[offset++] = g
|
||||||
bitmap[offset++] = r
|
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)
|
const header = Buffer.alloc(6)
|
||||||
header.writeUInt16LE(0, 0) // reserved
|
header.writeUInt16LE(0, 0) // reserved
|
||||||
|
|||||||
Reference in new issue
Block a user