mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
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:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user