fix: invert mask polarity so white = painted region

MaskEditor alpha comes through as 0 in painted areas; bake 255-a so the
MASK output is white where painted (region of interest).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-21 16:20:51 +02:00
parent 69968ebb20
commit d589a59fd1
+4 -5
View File
@@ -392,13 +392,12 @@ async function captureMask(node, slot, ref) {
ctx.drawImage(img, 0, 0); ctx.drawImage(img, 0, 0);
const d = ctx.getImageData(0, 0, c.width, c.height); const d = ctx.getImageData(0, 0, c.width, c.height);
const px = d.data; const px = d.data;
// MaskEditor stores the mask in the ALPHA channel (opaque = painted). Bake // MaskEditor stores the mask in the ALPHA channel, but painted areas come
// alpha into a grayscale image so the backend (reads mask as L) sees // through as alpha 0 — so invert (255 - a) when baking into a grayscale
// white = painted region of interest. If polarity is reversed in practice, // image, giving white = painted region of interest (what MASK expects).
// flip to `255 - a` here.
for (let i = 0; i < px.length; i += 4) { for (let i = 0; i < px.length; i += 4) {
const a = px[i + 3]; const a = px[i + 3];
px[i] = px[i + 1] = px[i + 2] = a; px[i] = px[i + 1] = px[i + 2] = 255 - a;
px[i + 3] = 255; px[i + 3] = 255;
} }
ctx.putImageData(d, 0, 0); ctx.putImageData(d, 0, 0);