feat(ui): improved transparency effect

Use the min of each pixel's alpha value and lightness for the output alpha. This prevents artifacts when using the transparency effect, especially with non-black pixels with low alpha.
This commit is contained in:
psychedelicious
2024-09-06 09:52:52 +10:00
parent 96786ed62b
commit f96148ca52

View File

@@ -14,8 +14,9 @@ export const LightnessToAlphaFilter = (imageData: ImageData): void => {
const r = imageData.data[i * 4 + 0] as number;
const g = imageData.data[i * 4 + 1] as number;
const b = imageData.data[i * 4 + 2] as number;
const a = imageData.data[i * 4 + 3] as number;
const cMin = Math.min(r, g, b);
const cMax = Math.max(r, g, b);
imageData.data[i * 4 + 3] = (cMin + cMax) / 2;
imageData.data[i * 4 + 3] = Math.min(a, (cMin + cMax) / 2);
}
};