Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(create): the Edit mask stays when the editor opens again and shows on the preview (C76)

purple8c40bcb844a1
diff --git a/e2e/mask-stays-c76.spec.ts b/e2e/mask-stays-c76.spec.ts
new file mode 100644
index 00000000..b71a08d8
--- /dev/null
+++ b/e2e/mask-stays-c76.spec.ts
@@ -0,0 +1,165 @@
+import { test, expect, type Page } from '@playwright/test'
+import { deflateSync } from 'node:zlib'
+import { tauriMockInit, DEFAULT_ASSISTANT_REPLY, DEFAULT_MODEL_NAME, type TauriMockOptions } from './support/tauri-mock'
+import { routeCloud, seedOnboardingDone, cloudSwitch } from './support/cloud-mock'
+import { mlxCalls } from './support/recorded'
+
+/**
+ * C76 (Discord help-chat, 11.11.2026): the mask of the Edit tab was gone when
+ * the mask editor was opened again, and the preview showed only the words
+ * "mask painted". The editor built an empty engine every time, and Apply on
+ * that empty canvas threw the painted mask away.
+ *
+ * Here, in the real app with the Tauri bridge stubbed (Mac, Qwen-Image 2.1
+ * edit): paint the left half, apply, see it on the preview, open the editor
+ * again and find it there, apply again, Create, and read the mask the run
+ * stages for mflux: white on the left, black on the right.
+ */
+
+const QWEN_MAC: TauriMockOptions = {
+ assistantReply: DEFAULT_ASSISTANT_REPLY,
+ modelName: DEFAULT_MODEL_NAME,
+ platform: 'mac',
+ mlx: { installedImages: ['sd-turbo', 'qwen-image-2.1-8bit'], mfluxEngineInstalled: true },
+}
+
+/** A grey PNG of `w` x `h`, RGB, no filter. */
+function greyPng(w: number, h: number): Buffer {
+ const crcTable = Array.from({ length: 256 }, (_, n) => {
+ let c = n
+ for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1
+ return c >>> 0
+ })
+ const crc = (buf: Buffer) => {
+ let c = 0xffffffff
+ for (const b of buf) c = crcTable[(c ^ b) & 0xff] ^ (c >>> 8)
+ return (c ^ 0xffffffff) >>> 0
+ }
+ const chunk = (type: string, data: Buffer) => {
+ const len = Buffer.alloc(4)
+ len.writeUInt32BE(data.length)
+ const body = Buffer.concat([Buffer.from(type, 'ascii'), data])
+ const sum = Buffer.alloc(4)
+ sum.writeUInt32BE(crc(body))
+ return Buffer.concat([len, body, sum])
+ }
+ const ihdr = Buffer.alloc(13)
+ ihdr.writeUInt32BE(w, 0)
+ ihdr.writeUInt32BE(h, 4)
+ ihdr[8] = 8
+ ihdr[9] = 2
+ const rows = Buffer.alloc((w * 3 + 1) * h, 0x80)
+ for (let y = 0; y < h; y++) rows[y * (w * 3 + 1)] = 0
+ return Buffer.concat([
+ Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
+ chunk('IHDR', ihdr),
+ chunk('IDAT', deflateSync(rows)),
+ chunk('IEND', Buffer.alloc(0)),
+ ])
+}
+
+const SIDE = 256
+
+async function boot(page: Page) {
+ await page.addInitScript(tauriMockInit, QWEN_MAC)
+ await seedOnboardingDone(page)
+ await routeCloud(page, { license: 'active', access: true, mediaLive: true })
+ await page.goto('/')
+ await expect(cloudSwitch(page)).toBeVisible({ timeout: 20_000 })
+ await page.getByRole('button', { name: /^Create$/ }).click()
+ await page.getByRole('radio', { name: 'Edit / Image to Image', exact: true }).click()
+ await page.locator('input[type="file"]').first().setInputFiles({ name: 'grey.png', mimeType: 'image/png', buffer: greyPng(SIDE, SIDE) })
+ await expect(page.getByRole('img', { name: 'source' })).toBeVisible({ timeout: 15_000 })
+}
+
+/** Share of painted pixels in the editor's red layer, left and right half. */
+async function editorPaint(page: Page): Promise<{ left: number; right: number }> {
+ return page.evaluate((side) => {
+ const layer = document.querySelectorAll<HTMLCanvasElement>('[role="dialog"] canvas')[1]
+ const { data } = layer.getContext('2d')!.getImageData(0, 0, side, side)
+ let left = 0, right = 0
+ for (let y = 0; y < side; y++) for (let x = 0; x < side; x++) {
+ if (data[(y * side + x) * 4 + 3] > 0) { if (x < side / 2) left++; else right++ }
+ }
+ const half = (side * side) / 2
+ return { left: left / half, right: right / half }
+ }, SIDE)
+}
+
+/** Paint the left half with a few strokes, in screen coordinates of the canvas. */
+async function paintLeftHalf(page: Page) {
+ const box = (await page.locator('[role="dialog"] canvas').first().boundingBox())!
+ for (let row = 0; row < 8; row++) {
+ const y = box.y + ((row + 0.5) / 8) * box.height
+ await page.mouse.move(box.x + box.width * 0.05, y)
+ await page.mouse.down()
+ await page.mouse.move(box.x + box.width * 0.4, y, { steps: 6 })
+ await page.mouse.up()
+ }
+}
+
+test('C76: a painted mask stays when the editor opens again, shows on the preview and reaches the edit', async ({ page }) => {
+ await boot(page)
+ const shots = process.env.LU_SHOTS
+
+ await page.getByRole('button', { name: /Paint mask/ }).click()
+ await expect(page.getByRole('dialog')).toBeVisible()
+ await paintLeftHalf(page)
+ const painted = await editorPaint(page)
+ expect(painted.left).toBeGreaterThan(0.3)
+ expect(painted.right).toBe(0)
+ await page.getByRole('button', { name: 'Apply mask' }).click()
+ await expect(page.getByRole('dialog')).toHaveCount(0)
+
+ // The preview shows the mask itself, on the picture.
+ const overlay = page.getByTestId('source-mask-overlay')
+ await expect(overlay).toBeVisible({ timeout: 5_000 })
+ const [src, img] = [await overlay.boundingBox(), await page.getByRole('img', { name: 'source' }).boundingBox()]
+ expect(src && img && Math.abs(src.x - img.x) < 1 && Math.abs(src.y - img.y) < 1 && Math.abs(src.width - img.width) < 1).toBe(true)
+ if (shots) await page.screenshot({ path: `${shots}/c76-vorschau-mit-maske.png` })
+
+ // Open again: the mask is where the editor starts.
+ await page.getByRole('button', { name: /Edit mask/ }).click()
+ await expect(page.getByRole('dialog')).toBeVisible()
+ await expect.poll(async () => (await editorPaint(page)).left, { timeout: 5_000 }).toBeGreaterThan(0.3)
+ const again = await editorPaint(page)
+ expect(Math.abs(again.left - painted.left)).toBeLessThan(0.02)
+ expect(again.right).toBe(0)
+ if (shots) { await page.waitForTimeout(500); await page.screenshot({ path: `${shots}/c76-editor-wieder-offen.png` }) }
+ // Apply without a stroke keeps it (it used to clear the mask here).
+ await page.getByRole('button', { name: 'Apply mask' }).click()
+ await expect(page.getByTestId('source-mask-overlay')).toBeVisible()
+
+ // The edit: the mask staged for mflux is white on the left, black on the right.
+ await page.locator('textarea').first().fill('make the left half blue')
+ await page.getByRole('button', { name: /^Create$/ }).last().click()
+ await expect.poll(async () => (await mlxCalls(page)).filter((c) => c.cmd === 'mlx_generate').length, { timeout: 30_000 }).toBe(1)
+ const calls = await mlxCalls(page)
+ const gen = calls.find((c) => c.cmd === 'mlx_generate')!
+ expect(gen.raw.mask).toBe('/tmp/lu-e2e/videos/start-images/e2e-start.png')
+ // Staged first the picture, then the mask.
+ const staged = calls.filter((c) => c.cmd === 'video_stage_start_image')
+ expect(staged).toHaveLength(2)
+ const maskB64 = String(staged[1].raw.data)
+ const halves = await page.evaluate(async ({ b64, side }) => {
+ const img = new Image()
+ img.src = `data:image/png;base64,${b64}`
+ await img.decode()
+ const c = document.createElement('canvas')
+ c.width = side; c.height = side
+ const ctx = c.getContext('2d')!
+ ctx.drawImage(img, 0, 0, side, side)
+ const { data } = ctx.getImageData(0, 0, side, side)
+ let left = 0, right = 0
+ for (let y = 0; y < side; y++) for (let x = 0; x < side; x++) {
+ const v = data[(y * side + x) * 4]
+ if (x < side / 2) left += v; else right += v
+ }
+ const half = (side * side) / 2
+ return { size: [img.naturalWidth, img.naturalHeight], left: left / half / 255, right: right / half / 255 }
+ }, { b64: maskB64, side: SIDE })
+ expect(halves.size).toEqual([SIDE, SIDE])
+ expect(halves.left).toBeGreaterThan(0.3)
+ // The feather softens the edge a little into the right half, no more.
+ expect(halves.right).toBeLessThan(0.05)
+})
diff --git a/e2e/support/tauri-mock.ts b/e2e/support/tauri-mock.ts
index 3f7366b0..c34683d0 100644
--- a/e2e/support/tauri-mock.ts
+++ b/e2e/support/tauri-mock.ts
@@ -1516,6 +1516,8 @@ export function tauriMockInit(opts: TauriMockOptions) {
images: m?.images,
resolution: m?.resolution,
loras: m?.loras,
+ mask: m?.mask,
+ strength: m?.strength,
})
// As in Rust: a pack with the Turbo adapter runs at its six steps,
// and an edit comes back in the shape of its image.
@@ -1695,10 +1697,14 @@ export function tauriMockInit(opts: TauriMockOptions) {
// (commands/mlx_cutout.rs). Never a ComfyUI graph.
record('__E2E_MLX_CALLS__', { cmd, image: m?.image })
return Promise.resolve({ image_base64: opts.mlx?.imageBase64 ?? TINY_PNG, width: 512, height: 512, output: '/tmp/lu-e2e/images/cutout-e2e.png' })
- case 'video_stage_start_image':
+ case 'video_stage_start_image': {
// As in Rust: the bytes land on disk and the answer is their path.
- record('__E2E_MLX_CALLS__', { cmd, bytes: String(m?.data ?? '').length })
+ // A small picture keeps its bytes in the record, so a spec can read
+ // what was staged (a painted mask, C76).
+ const data = String(m?.data ?? '')
+ record('__E2E_MLX_CALLS__', { cmd, bytes: data.length, ...(data.length < 200_000 ? { data } : {}) })
return Promise.resolve({ path: '/tmp/lu-e2e/videos/start-images/e2e-start.png' })
+ }
case 'video_stage_motion_video':
// Motion Control on a Mac: the clip lands on disk the same way.
record('__E2E_MLX_CALLS__', { cmd, bytes: String(m?.data ?? '').length })
diff --git a/src/components/create/canvas/MaskCanvasEngine.ts b/src/components/create/canvas/MaskCanvasEngine.ts
index 780aba47..b3b287ad 100644
--- a/src/components/create/canvas/MaskCanvasEngine.ts
+++ b/src/components/create/canvas/MaskCanvasEngine.ts
@@ -4,6 +4,8 @@
// LoadImageMask misaligns). Exports white-where-painted on black (ComfyUI
// mask convention). Pure TS — ports back to src/components/create unchanged.
// ─────────────────────────────────────────────────────────────────────
+import { maskToAlpha, readPixels } from './mask-pixels'
+
export type Tool = 'brush' | 'eraser'
const UNDO_CAP = 20
@@ -113,6 +115,22 @@ export class MaskCanvasEngine {
this.ctx.drawImage(tmp, 0, 0)
}
+ /**
+ * C76: start from a mask painted before (white where painted, on black, as
+ * `exportMaskBlob` writes it). The editor used to open empty every time,
+ * and Apply on the empty canvas then threw the painted mask away. Not an
+ * undo step: it is where this session of the editor begins.
+ */
+ loadMask(img: CanvasImageSource): boolean {
+ const px = readPixels(img, this.width, this.height)
+ if (!px) return false
+ maskToAlpha(px.data.data, [255, 255, 255])
+ this.ctx.globalCompositeOperation = 'source-over'
+ this.ctx.clearRect(0, 0, this.width, this.height)
+ this.ctx.putImageData(px.data, 0, 0)
+ return true
+ }
+
hasPaint(): boolean {
const { data } = this.ctx.getImageData(0, 0, this.width, this.height)
for (let i = 3; i < data.length; i += 4) if (data[i] !== 0) return true
diff --git a/src/components/create/canvas/__tests__/mask-pixels-c76.test.ts b/src/components/create/canvas/__tests__/mask-pixels-c76.test.ts
new file mode 100644
index 00000000..05bbe4a3
--- /dev/null
+++ b/src/components/create/canvas/__tests__/mask-pixels-c76.test.ts
@@ -0,0 +1,30 @@
+/**
+ * C76: the stored mask (white where painted, on black) back into what is
+ * drawn: an alpha mask for the editor, a red tint for the preview.
+ *
+ * Run: npx vitest run src/components/create/canvas/__tests__/mask-pixels-c76.test.ts
+ */
+import { describe, expect, it } from 'vitest'
+import { maskToAlpha, MASK_TINT, MASK_TINT_OPACITY } from '../mask-pixels'
+
+const px = (...rgba: number[][]) => new Uint8ClampedArray(rgba.flat())
+
+describe('a stored mask as pixels to draw', () => {
+ it('white becomes opaque, black see-through, grey keeps its share', () => {
+ const d = px([255, 255, 255, 255], [0, 0, 0, 255], [128, 128, 128, 255])
+ maskToAlpha(d, [255, 255, 255])
+ expect([...d]).toEqual([255, 255, 255, 255, 255, 255, 255, 0, 255, 255, 255, 128])
+ })
+
+ it('the preview tint is the editor\'s red at half strength', () => {
+ const d = px([255, 255, 255, 255], [0, 0, 0, 255])
+ maskToAlpha(d, MASK_TINT, MASK_TINT_OPACITY)
+ expect([...d]).toEqual([239, 68, 68, 128, 239, 68, 68, 0])
+ })
+
+ it('a see-through pixel of the file stays see-through', () => {
+ const d = px([255, 255, 255, 0])
+ maskToAlpha(d, [255, 255, 255])
+ expect(d[3]).toBe(0)
+ })
+})
diff --git a/src/components/create/canvas/mask-pixels.ts b/src/components/create/canvas/mask-pixels.ts
new file mode 100644
index 00000000..60ecb66a
--- /dev/null
+++ b/src/components/create/canvas/mask-pixels.ts
@@ -0,0 +1,44 @@
+// C76 (3.1.0): the mask as it is kept (white where painted, on black, the
+// ComfyUI LoadImageMask convention) turned back into what is drawn: an alpha
+// mask for the editor, a red tint for the preview on the Stage.
+
+/** In place: every pixel becomes `rgb` with the brightness of the stored mask
+ * as its alpha, times `opacity`. Black stays fully see-through. */
+export function maskToAlpha(data: Uint8ClampedArray, rgb: readonly [number, number, number], opacity = 1): void {
+ for (let i = 0; i < data.length; i += 4) {
+ // The brightest channel: a mask is grey, and a feathered edge keeps its share.
+ const a = Math.max(data[i], data[i + 1], data[i + 2]) * (data[i + 3] / 255)
+ data[i] = rgb[0]
+ data[i + 1] = rgb[1]
+ data[i + 2] = rgb[2]
+ data[i + 3] = Math.round(a * opacity)
+ }
+}
+
+/** The editor's tint, so the preview shows the mask as it was painted. */
+export const MASK_TINT: readonly [number, number, number] = [239, 68, 68]
+export const MASK_TINT_OPACITY = 0.5
+
+/** Draw `img` at `width` x `height` and hand back its pixels, or null where
+ * the platform has no 2D canvas. */
+export function readPixels(img: CanvasImageSource, width: number, height: number): { canvas: HTMLCanvasElement; ctx: CanvasRenderingContext2D; data: ImageData } | null {
+ const canvas = document.createElement('canvas')
+ canvas.width = width
+ canvas.height = height
+ const ctx = canvas.getContext('2d', { willReadFrequently: true })
+ if (!ctx) return null
+ ctx.drawImage(img, 0, 0, width, height)
+ return { canvas, ctx, data: ctx.getImageData(0, 0, width, height) }
+}
+
+/** The stored mask as a red, half see-through PNG for the preview. */
+export async function maskTintUrl(maskUrl: string, width: number, height: number): Promise<string | null> {
+ const img = new Image()
+ img.src = maskUrl
+ try { await img.decode() } catch { return null }
+ const px = readPixels(img, width, height)
+ if (!px) return null
+ maskToAlpha(px.data.data, MASK_TINT, MASK_TINT_OPACITY)
+ px.ctx.putImageData(px.data, 0, 0)
+ return px.canvas.toDataURL('image/png')
+}
diff --git a/src/components/create/experimental/MaskEditor.tsx b/src/components/create/experimental/MaskEditor.tsx
index 5df36239..32f1e7c2 100644
--- a/src/components/create/experimental/MaskEditor.tsx
+++ b/src/components/create/experimental/MaskEditor.tsx
@@ -114,6 +114,18 @@ function MaskEditorInner({ onClose }: { onClose: () => void }) {
}
img.src = source.url
renderOverlay()
+ // C76: a mask painted before on this picture is where the editor starts.
+ // It used to open empty, and Apply then dropped the mask that was there.
+ const painted = useCreateStore.getState().mask
+ if (painted?.url && painted.width === source.width && painted.height === source.height) {
+ const m = new Image()
+ m.onload = () => {
+ if (engineRef.current !== e) return
+ e.loadMask(m)
+ renderOverlay()
+ }
+ m.src = painted.url
+ }
// No history sync here any more: a brand-new engine has empty stacks, which
// is exactly what the state above already says for this source.
return () => { engineRef.current = null }
diff --git a/src/components/create/experimental/Stage.tsx b/src/components/create/experimental/Stage.tsx
index 2bbd3f44..7ffe3021 100644
--- a/src/components/create/experimental/Stage.tsx
+++ b/src/components/create/experimental/Stage.tsx
@@ -17,6 +17,7 @@ import { ICON_STROKE_MARK } from '../../ui/icon-size'
import { Button } from '../ui/Button'
import { cn } from '../ui/cn'
import { loadImageRef } from './loadImage'
+import { maskTintUrl } from '../canvas/mask-pixels'
import { mediaRefFrom } from './mediaRef'
import {
subscribeInstallRuns, getInstallRun, startInstallRun, cancelInstallRun, clearInstallRun,
@@ -479,6 +480,20 @@ function InputSlot() {
)
}
+/** C76: the painted mask as a red, half see-through layer for the preview,
+ * as the mask editor shows it. Null while it is made, or with no mask. */
+function useMaskTint(mask: { url: string; width: number; height: number } | null): string | null {
+ const [made, setMade] = useState<{ key: string; url: string | null } | null>(null)
+ const key = mask ? `${mask.width}x${mask.height}:${mask.url}` : ''
+ useEffect(() => {
+ if (!mask?.url) return
+ let alive = true
+ void maskTintUrl(mask.url, mask.width, mask.height).then((url) => { if (alive) setMade({ key, url }) })
+ return () => { alive = false }
+ }, [key, mask?.url, mask?.width, mask?.height])
+ return made && made.key === key ? made.url : null
+}
+
// ── Source loaded, awaiting generation ──
function SourcePreview({ onOpenMaskEditor }: { onOpenMaskEditor: () => void }) {
const source = useCreateStore((s) => s.source)
@@ -498,6 +513,7 @@ function SourcePreview({ onOpenMaskEditor }: { onOpenMaskEditor: () => void }) {
&& !editNeedsMask(modelForOp('image', 'edit', cloudImageModel || defaultCloudModel('image')?.id || ''))
const batchCount = useCreateStore((s) => s.batchSources.length)
const batchOffered = useBatchOffered()
+ const maskTint = useMaskTint(mask && !noMask ? mask : null)
// The same run over several images: no mask (it belongs to one image), and
// the list below replaces "Change image".
const batchOn = batchOffered && batchCount > 1
@@ -522,6 +538,18 @@ function SourcePreview({ onOpenMaskEditor }: { onOpenMaskEditor: () => void }) {
className={cn(!maxHeight && 'max-h-[52vh]', 'max-w-full object-contain rounded-[var(--radius-panel)] border border-white/[0.06]', intent === 'removebg' && 'lu-checker')}
style={maxHeight ? { maxHeight } : undefined}
/>
+ {/* C76: the mask itself, not only a word for it. Same box and the
+ same limits as the picture, so it lies exactly on it. */}
+ {maskTint && (
+ <img
+ src={maskTint}
+ alt=""
+ aria-hidden="true"
+ data-testid="source-mask-overlay"
+ className={cn(!maxHeight && 'max-h-[52vh]', 'pointer-events-none absolute left-0 top-0 max-w-full object-contain rounded-[var(--radius-panel)] border border-transparent')}
+ style={maxHeight ? { maxHeight } : undefined}
+ />
+ )}
{mask && !noMask && (
<div className="lu-on-dark absolute top-2 left-2 t-label text-gray-300 bg-black/50 px-2 py-1 rounded-md">mask painted</div>
)}
diff --git a/src/index.css b/src/index.css
index 0b7e590b..0d0caa1a 100644
--- a/src/index.css
+++ b/src/index.css
@@ -693,6 +693,19 @@ button:not(:disabled) {
.light {
scrollbar-color: rgba(0, 0, 0, 0.24) transparent;
}
+/* C79 (3.1.0): a native <select> in LU Dark. Its list is drawn by the
+ system, and Windows 10 drew it white while the field's light grey text
+ (text-gray-200) went with it: unreadable (Discord, help-chat 11.11.2026).
+ `color-scheme` asks for the dark list, the option colours hold where the
+ system ignores it. `.lu-field-dark` below sets its own background on top. */
+.dark select {
+ color-scheme: dark;
+}
+.dark select option,
+.dark select optgroup {
+ background-color: var(--color-lu-base);
+ color: #e5e7eb;
+}
.scrollbar-thin {
scrollbar-width: thin;
}