Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Layers: Re-render keeps the backdrop when you describe the picture, and skips earlier re-renders and slivers

Claude18dfc4bc48a9
diff --git a/src/components/layers/tools.tsx b/src/components/layers/tools.tsx
index 3fa57646..a44d2f27 100644
--- a/src/components/layers/tools.tsx
+++ b/src/components/layers/tools.tsx
@@ -66,6 +66,7 @@ import {
textBlocksFrom,
textChanges,
textJobTitle,
+ TOOL_LABELS,
TOOL_MODELS,
type Box,
type EnhanceLook,
@@ -1370,7 +1371,7 @@ function RerenderTool() {
const plan = useMemo(() => layersLayout(doc, keepText ? (text?.lines ?? []) : [], words), [doc, keepText, text, words]);
const { counts } = plan;
const boxes = counts.layers + counts.text;
- const run = () => void go({ tool: "rerender", target: { kind: "whole" }, modelId, prompt: words.trim() || undefined, settings: { layout: plan.draft }, label: "Re-render from layers" });
+ const run = () => void go({ tool: "rerender", target: { kind: "whole" }, modelId, prompt: words.trim() || undefined, settings: { layout: plan.draft }, label: TOOL_LABELS.rerender });
const read = () => void go({ tool: "text-detect", target: { kind: "whole" }, modelId: detector.modelId, label: "Detect text" });
const plural = (n: number, one: string) => `${n} ${one}${n === 1 ? "" : "s"}`;
return (
diff --git a/src/lib/layers.ts b/src/lib/layers.ts
index 981ec1c0..4c2c8a62 100644
--- a/src/lib/layers.ts
+++ b/src/lib/layers.ts
@@ -1128,7 +1128,7 @@ export const LAYER_ELEMENT_KINDS: { kind: LayerElementKind; label: string; hint:
{ kind: "style", label: "Style", hint: "A look, texture or background to reuse" },
];
-const GENERIC_NAME = /^(background|original image|layer \d+|cut-out|edited layer|text edit|upscaled|relit|new angle|inpainted|enhanced|edited region|expanded fill|color graded|generated layer|original|new)$/i;
+const GENERIC_NAME = /^(background|original image|layer \d+|cut-out|edited layer|text edit|upscaled|relit|new angle|inpainted|enhanced|edited region|expanded fill|color graded|generated layer|original|new|re-render)$/i;
const PERSON = /\b(person|people|man|men|woman|women|girl|boy|child|kid|baby|face|portrait|model|character|subject|figure|hero|lady|guy|dancer|singer|athlete|cat|dog|animal|creature|robot|avatar|mascot)\b/i;
const STYLE = /\b(background|backdrop|texture|pattern|sky|wall|floor|style|look|gradient|scene|landscape|scenery)\b/i;
@@ -1222,12 +1222,19 @@ function layerWords(n: Pick<LayerNode, "name" | "prompt">): string {
export function layersLayout(doc: Pick<LayerDoc, "width" | "height" | "nodes">, text: PlacedText[] = [], words = ""): LayersLayout {
const { width: W, height: H } = doc;
const canvas: Box = [0, 0, W, H];
+ // The part on the canvas, when it is at least a pixel each way (a sliver would be a box with no size).
+ const onCanvas = (b: Box): Box | null => {
+ const box = intersect(b, canvas);
+ return box && box[2] >= 1 && box[3] >= 1 ? box : null;
+ };
const frac = (b: Box): [number, number, number, number] => [r6(b[0] / W), r6(b[1] / H), r6((b[0] + b[2]) / W), r6((b[1] + b[3]) / H)];
const backdrop: string[] = [];
const layers: { z: number; area: number; item: LayoutItem }[] = [];
for (const n of doc.nodes) {
if (n.hidden || (n.opacity ?? 1) <= 0.05 || n.role === "original") continue;
- const box = intersect(rotatedBounds(n.x, n.y, n.w, n.h, n.rotation), canvas);
+ // An earlier re-render is a repaint of the layers under it, not a layer of its own.
+ if (n.revisions[n.revision]?.label === TOOL_LABELS.rerender) continue;
+ const box = onCanvas(rotatedBounds(n.x, n.y, n.w, n.h, n.rotation));
if (!box) continue;
const area = (box[2] * box[3]) / (W * H);
const what = layerWords(n);
@@ -1242,7 +1249,7 @@ export function layersLayout(doc: Pick<LayerDoc, "width" | "height" | "nodes">,
const lines = text
.flatMap((t) => {
const line = t.text.replace(/\s+/g, " ").trim();
- const box = t.box && intersect(t.box, canvas);
+ const box = t.box && onCanvas(t.box);
return line && box ? [{ label: "text" as const, caption: "Lettering in the same typeface, colour and size as now", text: line, box: frac(box) }] : [];
})
.slice(0, RERENDER_MAX_TEXT);
diff --git a/src/server/layers.ts b/src/server/layers.ts
index 485f5063..216f2a5a 100644
--- a/src/server/layers.ts
+++ b/src/server/layers.ts
@@ -199,6 +199,19 @@ const RES_TIER = { "1K": "auto_1K", "1.5K": "auto_1.5K", "2K": "auto_2K" } as co
/** Qwen-Image-Layered's longest side per tier (640 is the trained bucket; larger is slower). */
const OPEN_MAX_SIZE = { "1K": 640, "1.5K": 832, "2K": 1024 } as const;
+/**
+ * The words for a re-render: the layout's caption, which the browser builds from the person's words plus the backdrop
+ * layers ("Behind everything: …"). Words sent beside a caption that doesn't already start with them go in front of it, so
+ * neither the person's words nor the backdrop are lost.
+ */
+export function rerenderCaption(caption: string, prompt?: string): string {
+ const said = caption.trim();
+ const words = prompt?.trim().replace(/[.\s]+$/, "") ?? "";
+ if (!words) return said;
+ if (!said || said.toLowerCase().startsWith(words.toLowerCase())) return said || words;
+ return `${words}. ${said}`;
+}
+
/** The aspect ratio in `list` nearest to `aspect` ("1400:900"), compared on a log scale; `aspect` itself when there's no list. */
export function nearestAspect(aspect: string | undefined, list: readonly string[] | undefined): string | undefined {
const value = (a: string) => {
@@ -382,7 +395,7 @@ export function jobSteps(input: LayerJobInput, opts: { batchTitle?: string } = {
// The picture's own shape, or the nearest one the model makes (the boxes are fractions, so they stay in place).
const aspectRatio = nearestAspect(s.aspect, model.options.aspectRatios);
// The plan compiles the layout for this model at the size it renders, and keeps prompt rewriting off.
- add("rerender", base(model, { op: "t2i", prompt: prompt || layout.summary.caption, params: { ...(aspectRatio && { aspectRatio }), numOutputs: 1, extra: { [LAYOUT_PARAM]: layout } } }));
+ add("rerender", base(model, { op: "t2i", prompt: rerenderCaption(layout.summary.caption, prompt), params: { ...(aspectRatio && { aspectRatio }), numOutputs: 1, extra: { [LAYOUT_PARAM]: layout } } }));
break;
}
case "expand": {
diff --git a/tests/moss-sheets.test.ts b/tests/moss-sheets.test.ts
index 36134858..6da831a1 100644
--- a/tests/moss-sheets.test.ts
+++ b/tests/moss-sheets.test.ts
@@ -5,7 +5,7 @@ import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
import { applyMeasured, imagesToMeasure } from "@/components/layers/apply";
import { getModel, getPreset } from "@/lib/catalog";
import { planGeneration } from "@/lib/catalog/plan";
-import { planOneSheet, sheetCrop, sheetCrops, sheetGrid, sheetPanelLimit, sheetPanelStyle, SHEET_MODELS } from "@/lib/catalog/storyboard";
+import { planOneSheet, sheetCrop, sheetCrops, sheetGrid, sheetPanelLimit, sheetPanelStyle, sheetState, SHEET_MODELS } from "@/lib/catalog/storyboard";
import type { GenerationRequest } from "@/lib/catalog/types";
import { layersLayout, RERENDER_MAX_LAYERS, TOOL_MODELS, type LayerDoc, type LayerJob, type LayerJobInput, type LayerNode } from "@/lib/layers";
import { readLayout } from "@/lib/layout-prompt";
@@ -19,7 +19,7 @@ process.env.COMFYUI_URL = "http://127.0.0.1:9";
const { setSetting } = await import("@/server/settings");
const { createStoryboard, estimateStoryboard } = await import("@/server/storyboard");
-const { jobSteps, nearestAspect } = await import("@/server/layers");
+const { jobSteps, nearestAspect, rerenderCaption } = await import("@/server/layers");
const { getGeneration } = await import("@/server/generations");
beforeAll(() => setSetting("demoMode", "auto"));
@@ -110,6 +110,23 @@ describe("one-sheet storyboard: who gets it", () => {
expect(sheetPanelLimit(false, test)).toBe(6);
expect(sheetPanelLimit(true, test)).toBe(6);
});
+
+ it("holds the panel count a GPU render showed on the server too, not only in the browser", () => {
+ const seven = Array.from({ length: 7 }, (_, i) => `scene ${i + 1}`);
+ const test = { date: "2026-11-02", gpu: "RTX 4090 24 GB", maxPanels: 6 };
+ expect(() => planOneSheet({ engine: "open", scenes: seven }, test)).toThrow(/at most 6 panels/);
+ expect(planOneSheet({ engine: "open", scenes: seven.slice(0, 6) }, test).frame?.sheet?.panels).toHaveLength(6);
+ expect(() => planOneSheet({ engine: "open", scenes: seven }, { ...test, maxPanels: 0 })).toThrow(/isn't available yet/);
+ expect(planOneSheet({ engine: "open", scenes: seven }).frame?.sheet?.panels).toHaveLength(7);
+ });
+
+ it("says in the board's header when the sheet failed or was cancelled, not that it is on the way", () => {
+ expect(sheetState("succeeded")).toBe("done");
+ expect(sheetState("failed")).toBe("failed");
+ expect(sheetState("canceled")).toBe("cancelled");
+ expect(sheetState("queued")).toBe("on the way");
+ expect(sheetState("running")).toBe("on the way");
+ });
});
describe("one-sheet storyboard: the request", () => {
@@ -225,6 +242,25 @@ describe("re-render from layers: the layout", () => {
expect(draft.items[0].caption).toBe("L5");
expect(draft.items.some((i) => i.caption === "Original")).toBe(false);
});
+
+ it("leaves out an earlier re-render, which repaints the layers under it rather than being a backdrop", () => {
+ const earlier = node("Re-render", 2, { w: 400, h: 200, revisions: [{ src: "/api/files/r.png", natural: [400, 200], label: "Re-render from layers", at: 2 }] });
+ const { counts, caption } = layersLayout(doc([node("Sky", 0, { w: 400, h: 200 }), node("Red mug", 1, { x: 40, y: 40 }), earlier]));
+ expect(counts).toEqual({ layers: 1, text: 0, backdrop: 1 });
+ expect(caption).not.toMatch(/Re-render/);
+ // Renamed and kept as an ordinary layer, the name alone says nothing about what it shows.
+ const renamed = layersLayout(doc([node("Re-render", 0, { w: 400, h: 200 }), node("Red mug", 1, { x: 40, y: 40 })]));
+ expect(renamed.caption).toMatch(/Behind everything: a picture element/);
+ });
+
+ it("drops a layer whose part on the canvas is under a pixel, instead of a box with no size", () => {
+ const d = doc([node("Red mug", 0, { x: 40, y: 40 }), node("Sliver", 1, { x: 399.9999, y: 0 })], 400, 200);
+ const text = [{ text: "EDGE", box: [399.5, 10, 20, 20] as [number, number, number, number] }];
+ const { draft, counts } = layersLayout(d, text);
+ expect(counts).toEqual({ layers: 1, text: 0, backdrop: 0 });
+ expect(readLayout(draft)?.items).toHaveLength(1);
+ expect(() => jobSteps({ tool: "rerender", engine: "open", frame: [0, 0, 400, 200], settings: { aspect: "400:200", layout: draft } } as LayerJobInput)).not.toThrow();
+ });
});
describe("re-render from layers: the job", () => {
@@ -245,7 +281,22 @@ describe("re-render from layers: the job", () => {
expect(p.params.enhancePrompt).toBe(false);
const ideo = plan(steps({ engine: "cloud", modelId: "ideogram-4-5" })[0].request);
expect(ideo.layout?.format).toBe("ideogram");
- expect(steps({ engine: "cloud", prompt: "A cosy kitchen" })[0].request.prompt).toBe("A cosy kitchen");
+ // Words sent beside a caption made without them go in front of it.
+ expect(steps({ engine: "cloud", prompt: "A cosy kitchen" })[0].request.prompt).toMatch(/^A cosy kitchen\. One coherent picture that keeps this arrangement: red mug\./);
+ });
+
+ it("keeps the backdrop in the words the model reads when the person describes the picture", () => {
+ const d = doc([node("a beach at dusk", 0, { w: 1400, h: 900 }), node("Red mug", 1, { x: 40, y: 40 })], 1400, 900);
+ const typed = layersLayout(d, [], "warm photo").draft;
+ expect(typed.summary.caption).toBe("warm photo. Behind everything: a beach at dusk.");
+ for (const [engine, modelId] of [["open", "oss-moss-image"], ["cloud", "moss-image"], ["cloud", "ideogram-4-5"], ["cloud", "flux-3"]] as const) {
+ const [step] = jobSteps({ tool: "rerender", engine, modelId, frame, prompt: "warm photo", settings: { aspect: "1400:900", layout: typed } } as LayerJobInput);
+ expect(step.request.prompt, modelId).toBe("warm photo. Behind everything: a beach at dusk.");
+ expect(plan(step.request).prompt, modelId).toMatch(/a beach at dusk/);
+ }
+ expect(rerenderCaption("Warm photo. Behind everything: sand.", "warm photo.")).toBe("Warm photo. Behind everything: sand.");
+ expect(rerenderCaption("", "warm photo")).toBe("warm photo");
+ expect(rerenderCaption("A caption.", undefined)).toBe("A caption.");
});
it("refuses an empty arrangement and a model that doesn't read boxes", () => {