Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Restore Extend with bounded sizing and blended edges

Bittie428019e268a
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index a033d90..20230e8 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -4,6 +4,7 @@ This alpha update adds SeedVR2 and Real-ESRGAN export upscaling, Long Shot and B
## What's new
+- **Extend image template restored.** Draw or resize the output box, choose a generation resolution, and optionally describe the new surroundings. Output follows the box's aspect ratio and selected pixel budget, resizing the source to fit. Source interiors stay intact while generated edges blend into the original with seam tone matching.
- **SeedVR2 upscaling for images and videos.** Restore exports at the selected output size using SeedVR2 3B FP16 and its VAE. Run on the local NVIDIA CUDA GPU or a selected CUDA LAN worker. Workers download missing standard weights or receive your selected local weight files.
- **Real-ESRGAN upscaling for images and videos.** Use RealESRGAN x4plus during export, with the result resized to your chosen output dimensions. CUDA and Vulkan are supported. Choose None to export without an upscaler.
- **Other weights settings.** Settings → Generator now includes downloads and optional local file paths for Real-ESRGAN, SeedVR2 and the MiniMax H3 latent upscaler. Upscaler downloads share the generator and LoRA download queue, with progress and cancellation in Work Queue.
diff --git a/docs/slopfab-compatibility.md b/docs/slopfab-compatibility.md
index 9acdd4a..54587b0 100644
--- a/docs/slopfab-compatibility.md
+++ b/docs/slopfab-compatibility.md
@@ -121,6 +121,25 @@ cache and progress/cancellation commands; paths remain machine-local.
## API 1.20: single-pass image outpainting
+The restored image Extend template uses the existing API with a 16-pixel
+inset on each source edge facing generated space. This frees the VAE boundary
+row while keeping the source interior pinned. Canvas edges without new space
+are not inset. Slopus tone-matches generated bands using opaque source seam
+samples and composites the source with a smoothstep fade over those 16 pixels;
+the interior and original alpha remain exact. The prompt is optional and uses
+the runtime's `Source scene` context without zoom-out instructions or duplicate
+reference pictures. This adapts the edge handling in
+[ComfyUI-H3VideoOutpaint](https://github.com/TwoAbove/ComfyUI-H3VideoOutpaint)
+to single-image generation; it does not add video windows or positioned FL2VA
+keyframe rows to the runtime.
+
+The drawn box sets the aspect ratio. The selected image resolution and aspect
+preset set the pixel budget, rounded down to the 32-pixel grid and bounded by
+the maximum generation dimensions. The source scales into that output, so a
+larger selection reduces its footprint unless the resolution also increases.
+Preparation, preview, generation and final PNG use the same mapped geometry.
+No runtime or worker protocol change is required.
+
The bundled Windows and Linux runtimes come from SlopFab commit `b7486be`,
built with `SLOPFAB_WITH_FFMPEG=OFF`. The additive
`slopfab_request_set_image_edit_invert_mask` setter makes an image-edit box
diff --git a/src-tauri/src/commands/extend_image.rs b/src-tauri/src/commands/extend_image.rs
index 4cdf17e..d3d1a55 100644
--- a/src-tauri/src/commands/extend_image.rs
+++ b/src-tauri/src/commands/extend_image.rs
@@ -54,12 +54,12 @@ fn scaled_layout(
|| output.height == 0
|| output.width % 32 != 0
|| output.height % 32 != 0
- || output.width > bounds.width
- || output.height > bounds.height
- || u64::from(output.width) * u64::from(output.height) > u64::from(width) * u64::from(height)
+ || output.width > MAX_GENERATION_EDGE
+ || output.height > MAX_GENERATION_EDGE
+ || u64::from(output.width) * u64::from(output.height) > MAX_GENERATION_PIXELS
{
return Err(
- "Extend output must be aligned to 32 pixels and cannot increase the source resolution."
+ "Extend output must be aligned to 32 pixels within the maximum generation resolution."
.into(),
);
}
@@ -186,8 +186,8 @@ pub(crate) fn prepare_extend_image(
);
}
let cache = root.directory(&directory(&job_id)?)?;
- // Snapshot the downscaled original. Generation and final preservation use
- // exactly these pixels, with no second resampling or model changes to them.
+ // Snapshot the resized original. Generation and final preservation use
+ // exactly these pixels, with no second resampling.
write_png(&cache.join("original.png"), &source)?;
write_png(&cache.join("canvas.png"), &padded_source(&source, bounds))?;
crate::storage::atomic::write_atomically(
@@ -196,18 +196,112 @@ pub(crate) fn prepare_extend_image(
)
}
+// Match EXTEND_SEAM in extendImage.ts. Only edges facing new pixels are free
+// during denoising; keep the interior exact and fade across that free row.
+const SEAM: u32 = 16;
+
+fn smoothstep(value: f32) -> f32 {
+ let t = value.clamp(0.0, 1.0);
+ t * t * (3.0 - 2.0 * t)
+}
+
fn restore_original(result: &mut RgbaImage, source: &RgbaImage, bounds: ExtendBounds) {
let left = bounds.x.max(0) as u32;
let top = bounds.y.max(0) as u32;
let right = (bounds.x + bounds.width as i32).min(source.width() as i32) as u32;
let bottom = (bounds.y + bounds.height as i32).min(source.height() as i32) as u32;
+ let px = (left as i32 - bounds.x) as u32;
+ let py = (top as i32 - bounds.y) as u32;
+ let pr = px + right - left;
+ let pb = py + bottom - top;
+ let bands = [px, py, bounds.width - pr, bounds.height - pb];
+ // Estimate the RGB mismatch on the same scene pixels, before compositing.
+ // Fade the correction across each new band. Ignore transparent source
+ // pixels, whose hidden RGB cannot describe the generated surroundings.
+ let mut offsets = [[0.0f32; 3]; 4];
+ for edge in 0..4 {
+ if bands[edge] == 0 {
+ continue;
+ }
+ let mut count = 0;
+ let strip = 4.min(right - left).min(bottom - top);
+ let (x0, y0, x1, y1) = match edge {
+ 0 => (left, top, left + strip, bottom),
+ 1 => (left, top, right, top + strip),
+ 2 => (right - strip, top, right, bottom),
+ _ => (left, bottom - strip, right, bottom),
+ };
+ for y in y0..y1 {
+ for x in x0..x1 {
+ let original = source.get_pixel(x, y);
+ if original[3] != 255 {
+ continue;
+ }
+ let generated =
+ result.get_pixel((x as i32 - bounds.x) as u32, (y as i32 - bounds.y) as u32);
+ for c in 0..3 {
+ offsets[edge][c] += original[c] as f32 - generated[c] as f32;
+ }
+ count += 1;
+ }
+ }
+ if count > 0 {
+ for delta in &mut offsets[edge] {
+ *delta /= count as f32;
+ }
+ }
+ }
+ for (x, y, pixel) in result.enumerate_pixels_mut() {
+ // Signed distances are positive outside the source and negative inside.
+ let distances = [
+ px as f32 - x as f32 - 0.5,
+ py as f32 - y as f32 - 0.5,
+ x as f32 + 0.5 - pr as f32,
+ y as f32 + 0.5 - pb as f32,
+ ];
+ let weights: [f32; 4] = std::array::from_fn(|edge| {
+ if bands[edge] == 0 {
+ return 0.0;
+ }
+ let distance = distances[edge];
+ if distance >= 0.0 {
+ 1.0 - smoothstep(distance / bands[edge] as f32)
+ } else {
+ 1.0 - smoothstep(-distance / SEAM as f32)
+ }
+ });
+ let sum: f32 = weights.iter().sum();
+ let strength = weights.iter().copied().fold(0.0f32, f32::max);
+ if sum > 0.0 {
+ for c in 0..3 {
+ let correction: f32 = (0..4).map(|edge| weights[edge] * offsets[edge][c]).sum();
+ pixel[c] = (pixel[c] as f32 + correction / sum * strength)
+ .round()
+ .clamp(0.0, 255.0) as u8;
+ }
+ }
+ }
for y in top..bottom {
for x in left..right {
- result.put_pixel(
- (x as i32 - bounds.x) as u32,
- (y as i32 - bounds.y) as u32,
- *source.get_pixel(x, y),
- );
+ let distances = [x - left, y - top, right - 1 - x, bottom - 1 - y];
+ let distance = (0..4)
+ .filter(|edge| bands[*edge] > 0)
+ .map(|edge| distances[edge])
+ .min()
+ .unwrap_or(SEAM);
+ let original = source.get_pixel(x, y);
+ let pixel =
+ result.get_pixel_mut((x as i32 - bounds.x) as u32, (y as i32 - bounds.y) as u32);
+ let weight = smoothstep((distance as f32 + 0.5) / SEAM as f32);
+ if weight == 1.0 || original[3] == 0 {
+ *pixel = *original;
+ } else {
+ for c in 0..3 {
+ pixel[c] = (pixel[c] as f32 * (1.0 - weight) + original[c] as f32 * weight)
+ .round() as u8;
+ }
+ pixel[3] = original[3];
+ }
}
}
}
@@ -261,8 +355,160 @@ pub(crate) fn discard_extend_image(folder_path: String, job_id: String) -> Resul
mod tests {
use super::*;
+ /// Opt-in GPU smoke test. Supply an existing source image, model directory
+ /// and artifact directory; ordinary test runs do not load any models.
+ #[test]
+ #[ignore]
+ fn extend_gpu_smoke() {
+ use slopus_core::{
+ settings::{ProviderOption, ProviderSetting},
+ slopfab::{GenerationRequest, NativeEvent, SlopfabRuntime},
+ };
+ use std::{
+ collections::BTreeMap,
+ sync::{mpsc, Arc},
+ time::Duration,
+ };
+ let weights = std::path::PathBuf::from(std::env::var("SLOPUS_E2E_WEIGHTS").unwrap());
+ let source_path = std::env::var("SLOPUS_EXTEND_SOURCE").unwrap();
+ let artifact_dir = std::path::PathBuf::from(std::env::var("SLOPUS_EXTEND_OUTPUT").unwrap());
+ std::fs::create_dir_all(&artifact_dir).unwrap();
+ let find = |part: &str| {
+ std::fs::read_dir(&weights)
+ .unwrap()
+ .filter_map(Result::ok)
+ .map(|entry| entry.path())
+ .find(|path| {
+ path.to_string_lossy().contains(part)
+ && path.extension().is_some_and(|ext| ext == "safetensors")
+ })
+ .unwrap_or_else(|| panic!("no {part} weights"))
+ .to_string_lossy()
+ .into_owned()
+ };
+ let options = BTreeMap::from([
+ (
+ "dllPath".into(),
+ ProviderOption::String(
+ std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
+ .join("../lib/slopfab/slopfab.dll")
+ .to_string_lossy()
+ .into_owned(),
+ ),
+ ),
+ (
+ "transformer".into(),
+ ProviderOption::String(
+ std::env::var("SLOPUS_EXTEND_TRANSFORMER")
+ .unwrap_or_else(|_| find("fl2va_pruned_int8")),
+ ),
+ ),
+ (
+ "textEncoder".into(),
+ ProviderOption::String(find("qwen3vl_32b_minimax_h3_nvfp4")),
+ ),
+ (
+ "videoVae".into(),
+ ProviderOption::String(find("video_vae_fp16")),
+ ),
+ ("motionCache".into(), ProviderOption::Boolean(false)),
+ ]);
+ let settings = BTreeMap::from([(
+ "slopfab".into(),
+ ProviderSetting {
+ enabled: true,
+ model: None,
+ options,
+ },
+ )]);
+ let source = image::open(source_path).unwrap().to_rgba8();
+ let source =
+ image::imageops::resize(&source, 256, 256, image::imageops::FilterType::Lanczos3);
+ let folder = tempfile::tempdir().unwrap();
+ let mut config = crate::tests::created_fixture();
+ config.assets.push(serde_json::from_value(serde_json::json!({
+ "id":"source", "kind":"image", "name":"Source", "relativePath":"source.png", "mimeType":"image/png",
+ "width":256, "height":256, "createdAt":config.created_at
+ })).unwrap());
+ crate::project::storage::write_project(folder.path(), &config).unwrap();
+ write_png(&folder.path().join("source.png"), &source).unwrap();
+ let path = folder.path().to_string_lossy().into_owned();
+ let job = "extend-gpu-smoke";
+ // A 1.5x square selection rendered at 416p, matching the TS compiler.
+ prepare_extend_image(
+ path.clone(),
+ job.into(),
+ "source".into(),
+ ExtendBounds {
+ x: -64,
+ y: -64,
+ width: 384,
+ height: 384,
+ },
+ ExtendSize {
+ width: 416,
+ height: 416,
+ },
+ )
+ .unwrap();
+ let cache = folder.path().join(directory(job).unwrap());
+ let snapshot = image::open(cache.join("original.png")).unwrap().to_rgba8();
+ let canvas = cache.join("canvas.png");
+ std::fs::copy(&canvas, artifact_dir.join("canvas.png")).unwrap();
+ let prompt = "integrated_multimodal_description: [Shot 1] Match the source scene's visual style. One continuous scene matching Source scene's setting, perspective, subject scale, lighting and textures. The existing subjects remain at their canvas positions.\n\noverall_soundscape: N/A\n\nnon_diegetic_music: N/A";
+ let mut request: GenerationRequest = serde_json::from_value(serde_json::json!({
+ "jobId":job, "stillImage":true, "frames":1, "steps":20, "seed":17, "canvasWidth":416, "canvasHeight":416, "prompt":prompt,
+ "imageEdit":{"sourceRelativePath":"canvas.png", "edits":[{"x":85,"y":85,"width":245,"height":245,"invertMask":true,"feather":0,"prompt":prompt}]}
+ })).unwrap();
+ request.image_edit_path = Some(canvas);
+ let runtime = SlopfabRuntime::default();
+ let (send, receive) = mpsc::channel();
+ runtime
+ .enqueue(
+ Arc::new(move |event| {
+ send.send(event).unwrap();
+ }),
+ request,
+ &settings,
+ )
+ .unwrap();
+ loop {
+ match receive.recv_timeout(Duration::from_secs(600)).unwrap() {
+ NativeEvent::Progress(event) => {
+ eprintln!("{}", serde_json::to_value(event).unwrap())
+ }
+ NativeEvent::Job(event) => {
+ let event = serde_json::to_value(event).unwrap();
+ if event["state"] == "framesReady" {
+ break;
+ }
+ assert!(
+ event["state"] != "failed" && event["state"] != "cancelled",
+ "{event}"
+ );
+ }
+ }
+ }
+ let saved = save_extended_image(path.clone(), job.into()).unwrap();
+ let final_path = folder.path().join(saved.relative_path);
+ let result = image::open(&final_path).unwrap().to_rgba8();
+ assert_eq!(result.dimensions(), (416, 416));
+ for y in 16..snapshot.height() - 16 {
+ for x in 16..snapshot.width() - 16 {
+ assert_eq!(result.get_pixel(x + 69, y + 69), snapshot.get_pixel(x, y));
+ }
+ }
+ assert!(result
+ .enumerate_pixels()
+ .filter(|(x, y, _)| *x < 69 || *y < 69)
+ .any(|(_, _, pixel)| pixel.0 != [127, 127, 127, 255]));
+ std::fs::copy(final_path, artifact_dir.join("result.png")).unwrap();
+ discard_extend_image(path, job.into()).unwrap();
+ eprintln!("Inspect {}", artifact_dir.join("result.png").display());
+ }
+
#[test]
- fn extend_layout_matches_the_scaled_generation_canvas_and_rejects_growth() {
+ fn extend_layout_matches_the_scaled_generation_canvas_and_allows_selected_resolution() {
let bounds = ExtendBounds {
x: -64,
y: -32,
@@ -285,13 +531,27 @@ mod tests {
),
(51, 38, -38, -13, 128, 64)
);
+ let (source, mapped) = scaled_layout(
+ 128,
+ 96,
+ bounds,
+ ExtendSize {
+ width: 512,
+ height: 320,
+ },
+ )
+ .unwrap();
+ assert_eq!(
+ (source.width, source.height, mapped.x, mapped.y),
+ (256, 192, -128, -64)
+ );
assert!(scaled_layout(
128,
96,
bounds,
ExtendSize {
- width: 256,
- height: 160
+ width: 3648,
+ height: 3648
}
)
.is_err());
@@ -329,7 +589,7 @@ mod tests {
}
#[test]
- fn extend_preserves_original_pixels_including_alpha_and_cropped_intersections() {
+ fn extend_preserves_alpha_and_blends_only_inside_source_intersections() {
let source = RgbaImage::from_fn(7, 5, |x, y| {
image::Rgba([x as u8, y as u8, 80, (x * 25) as u8])
});
@@ -364,12 +624,19 @@ mod tests {
for x in 0..bounds.width {
let sx = x as i32 + bounds.x;
let sy = y as i32 + bounds.y;
- let expected = if sx >= 0 && sy >= 0 && sx < 7 && sy < 5 {
- source.get_pixel(sx as u32, sy as u32).0
+ let actual = result.get_pixel(x, y).0;
+ if sx >= 0 && sy >= 0 && sx < 7 && sy < 5 {
+ let original = source.get_pixel(sx as u32, sy as u32).0;
+ assert_eq!(actual[3], original[3]);
+ if original[3] == 0 {
+ assert_eq!(actual, original);
+ }
+ for c in 0..3 {
+ assert!((original[c]..=[200, 201, 202][c]).contains(&actual[c]));
+ }
} else {
- [200, 201, 202, 255]
- };
- assert_eq!(result.get_pixel(x, y).0, expected);
+ assert_eq!(actual, [200, 201, 202, 255]);
+ }
}
}
let padded = padded_source(&source, bounds);
@@ -388,6 +655,72 @@ mod tests {
}
}
+ #[test]
+ fn extend_matches_seam_tone_and_retains_interior_and_far_band_pixels() {
+ // Exercise every direction, including a source cropped against canvas
+ // edges. A constant exposure shift must not become a rectangular seam.
+ let source = RgbaImage::from_pixel(96, 96, image::Rgba([80, 100, 120, 255]));
+ for (x, y) in [(-64, -64), (0, 0), (32, -64), (-64, 32)] {
+ let bounds = ExtendBounds {
+ x,
+ y,
+ width: 224,
+ height: 224,
+ };
+ let mut result = RgbaImage::from_pixel(224, 224, image::Rgba([110, 130, 150, 255]));
+ restore_original(&mut result, &source, bounds);
+ let left = (-x).max(0) as u32;
+ let top = (-y).max(0) as u32;
+ let right = (96 - x) as u32;
+ let bottom = (96 - y) as u32;
+ assert_eq!(
+ result.get_pixel((left + right) / 2, (top + bottom) / 2).0,
+ [80, 100, 120, 255]
+ );
+ for (a, b) in [
+ ((right - 1, (top + bottom) / 2), (right, (top + bottom) / 2)),
+ (
+ ((left + right) / 2, bottom - 1),
+ ((left + right) / 2, bottom),
+ ),
+ ] {
+ for c in 0..3 {
+ assert!(
+ result.get_pixel(a.0, a.1)[c].abs_diff(result.get_pixel(b.0, b.1)[c]) <= 1
+ );
+ }
+ }
+ assert_eq!(result.get_pixel(223, 223).0, [110, 130, 150, 255]);
+ }
+ }
+
+ #[test]
+ fn extend_fades_details_at_generated_edges_but_keeps_the_interior_exact() {
+ // Nonopaque input bypasses tone matching, isolating the seam blend.
+ let source = RgbaImage::from_pixel(96, 96, image::Rgba([40, 60, 80, 123]));
+ let mut result = RgbaImage::from_pixel(128, 96, image::Rgba([200, 200, 200, 255]));
+ restore_original(
+ &mut result,
+ &source,
+ ExtendBounds {
+ x: 0,
+ y: 0,
+ width: 128,
+ height: 96,
+ },
+ );
+ for y in 0..96 {
+ for x in 0..80 {
+ assert_eq!(result.get_pixel(x, y).0, [40, 60, 80, 123]);
+ }
+ for x in 80..96 {
+ assert_eq!(result.get_pixel(x, y)[3], 123);
+ assert!(result.get_pixel(x, y)[0] >= result.get_pixel(x - 1, y)[0]);
+ }
+ assert_eq!(result.get_pixel(96, y).0, [200, 200, 200, 255]);
+ }
+ }
+
#[test]
fn extend_snapshots_source_validates_bounds_and_cleans_only_its_cache() {
let folder = tempfile::tempdir().unwrap();
@@ -567,14 +900,15 @@ mod tests {
assert_eq!(image.dimensions(), (128, 64));
for y in 0..64 {
for x in 0..128 {
- assert_eq!(
- image.get_pixel(x, y).0,
- if (38..89).contains(&x) && (13..51).contains(&y) {
- scaled.get_pixel(x - 38, y - 13).0
- } else {
- [210, 180, 150, 255]
+ let actual = image.get_pixel(x, y).0;
+ if (38..89).contains(&x) && (13..51).contains(&y) {
+ assert_eq!(actual[3], 123);
+ if (54..73).contains(&x) && (29..35).contains(&y) {
+ assert_eq!(actual, scaled.get_pixel(x - 38, y - 13).0);
}
- );
+ } else {
+ assert_eq!(actual, [210, 180, 150, 255]);
+ }
}
}
crate::rendered::release(job);
diff --git a/src/components/workspace/Extend.test.tsx b/src/components/workspace/Extend.test.tsx
index fbc8dc0..2f3fabc 100644
--- a/src/components/workspace/Extend.test.tsx
+++ b/src/components/workspace/Extend.test.tsx
@@ -7,19 +7,53 @@ import { ImageEditor } from "./ImageEditor";
import { ExtendCanvas } from "./ExtendCanvas";
import { parseProjectConfig } from "../../lib/project";
import * as persistence from "../../lib/persistence";
+import * as settings from "../../lib/settings";
+import { choose } from "./comboTestUtils";
import fixture from "../../../fixtures/project-v1-image.json";
import type { ExtendBounds } from "../../lib/extendImage";
afterEach(() => { cleanup(); localStorage.clear(); vi.restoreAllMocks(); });
const source = { id: "source", name: "Source", kind: "image" as const, relativePath: "media/source.png", mimeType: "image/png", width: 400, height: 300, createdAt: "2026-10-04T00:00:00Z" };
-it("temporarily hides Extend from Template while keeping Character sheet available", () => {
+it("opens Extend from Template with box controls and returns to image settings", () => {
vi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue(null);
const config = parseProjectConfig(fixture); config.assets = [source]; config.imageScene!.outputAssetId = source.id;
render(<ImageEditor config={config} folderPath="D:/Images" onChange={vi.fn()} onGenerate={vi.fn()} onCancel={vi.fn()} onGenerateExtend={vi.fn()} />);
fireEvent.click(screen.getByRole("button", { name: "Template" }));
- expect(screen.queryByRole("menuitem", { name: "Extend" })).not.toBeInTheDocument();
+ expect(screen.getByRole("menuitem", { name: "Extend" })).toBeEnabled();
expect(screen.getByRole("menuitem", { name: "Character sheet" })).toBeEnabled();
+ fireEvent.click(screen.getByRole("menuitem", { name: "Extend" }));
+ expect(screen.getByLabelText("Extend bounding box tool")).toBeInTheDocument();
+ expect(screen.getByLabelText("Extend width")).toHaveValue(608);
+ expect(screen.getByLabelText("Extend resolution")).toBeEnabled();
+ expect(screen.getByLabelText("Extend prompt")).toBeInTheDocument();
+ fireEvent.click(screen.getByRole("button", { name: "Close template settings" }));
+ expect(screen.queryByLabelText("Extend bounding box tool")).not.toBeInTheDocument();
+});
+
+it("executes an optional-prompt extension at the changed resolution without changing video settings", () => {
+ vi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue(null);
+ vi.spyOn(persistence, "isTauri").mockReturnValue(true);
+ vi.spyOn(settings, "templateUsable").mockReturnValue(true);
+ const generator = settings.createGeneratorTemplate("Extend generator");
+ settings.saveGeneratorTemplateSettings({ templates: [generator], defaultTemplateId: generator.id });
+ const initial = parseProjectConfig(fixture);
+ initial.assets = [source]; initial.imageScene!.outputAssetId = source.id;
+ let latest = initial;
+ const execute = vi.fn();
+ function Harness() {
+ const [config, setConfig] = useState(initial); latest = config;
+ return <ImageEditor config={config} folderPath="D:/Images" onChange={setConfig} onGenerate={vi.fn()} onCancel={vi.fn()} onGenerateExtend={execute} />;
+ }
+ render(<Harness />);
+ fireEvent.click(screen.getByRole("button", { name: "Template" }));
+ fireEvent.click(screen.getByRole("menuitem", { name: "Extend" }));
+ choose("Extend resolution", "1088p");
+ expect(latest.imageSettings?.resolution).toBe("1088p");
+ expect(latest.settings).toEqual(initial.settings);
+ fireEvent.click(screen.getByRole("button", { name: "Execute" }));
+ expect(execute).toHaveBeenCalledWith(expect.objectContaining({ id: generator.id }), source.id,
+ expect.objectContaining({ prompt: "", bounds: { x: -104, y: -74, width: 608, height: 448 } }));
});
it("moves, resizes, redraws and cancels box drags in original pixel coordinates", () => {
diff --git a/src/components/workspace/ExtendSettings.tsx b/src/components/workspace/ExtendSettings.tsx
index 228ef13..953a521 100644
--- a/src/components/workspace/ExtendSettings.tsx
+++ b/src/components/workspace/ExtendSettings.tsx
@@ -1,15 +1,17 @@
import { useMemo } from "react";
import { alignExtendBounds, compileExtendImage, initialExtendBounds, EXTEND_GRID, EXTEND_MAX_EDGE, type ExtendOptions } from "../../lib/extendImage";
-import type { ProjectAsset, ProjectConfig } from "../../lib/project";
-import { InfoBar, ItemHeader, PropRow } from "../ui";
+import { PROJECT_RESOLUTIONS, type ProjectAsset, type ProjectConfig } from "../../lib/project";
+import { imageSettings } from "../../lib/imageSettings";
+import { ComboBox, InfoBar, ItemHeader, PropRow } from "../ui";
import { Dismiss16, Sparkle16 } from "../ui/icons";
import { PromptTextField, type PromptReference } from "./PromptTextField";
import { TemplateDebugPrompt } from "./TemplateDebugPrompt";
-export function ExtendSettings({ config, source, options, onChange, references, missingLabel, busy, disabledReason, onExecute, onClose }: {
+export function ExtendSettings({ config, source, options, onChange, onResolutionChange, references, missingLabel, busy, disabledReason, onExecute, onClose }: {
config: ProjectConfig; source: ProjectAsset; options: ExtendOptions; onChange: (options: ExtendOptions) => void;
references: PromptReference[]; missingLabel: (id: string) => string; busy: boolean; disabledReason: string | null;
onExecute: () => void; onClose: () => void;
+ onResolutionChange?: (resolution: ProjectConfig["settings"]["resolution"]) => void;
}) {
const validation = useMemo(() => {
try {
@@ -22,10 +24,14 @@ export function ExtendSettings({ config, source, options, onChange, references,
<ItemHeader name="Extend" meta="Template" actions={<button type="button" className="icon-button" aria-label="Close template settings" data-tooltip="Back to image settings" onClick={onClose}><Dismiss16 aria-hidden="true" /></button>} />
<form className="image-template-settings__form" onSubmit={(event) => { event.preventDefault(); if (!busy && !disabledReason && !validation.message) onExecute(); }}>
<div className="image-inspector__fields image-template-settings__fields">
+ <PropRow label="Resolution" htmlFor="extend-resolution" tooltip="The box sets the aspect ratio. The selected resolution sets the pixel budget; expanding the box makes the source smaller within that output.">
+ <ComboBox id="extend-resolution" aria-label="Extend resolution" value={imageSettings(config).resolution} options={PROJECT_RESOLUTIONS.map((value) => ({ value, label: value }))}
+ disabled={busy || !onResolutionChange} onChange={(value) => onResolutionChange?.(value)} />
+ </PropRow>
{validation.output && <p className="image-inspector__caption">Output: {validation.output.width} × {validation.output.height} px</p>}
<p className="image-inspector__caption">Source: {source.name} · {source.width} × {source.height} px</p>
{(["x", "y", "width", "height"] as const).map((field) => <PropRow key={field} label={field === "x" ? "X" : field === "y" ? "Y" : field === "width" ? "Width" : "Height"} htmlFor={`extend-${field}`}
- tooltip={field === "x" || field === "y" ? "Drag the box or its handles, or drag outside it to draw a new box." : "Sizes use 32-pixel increments. The original is downscaled to make room for generated areas; output stays within the source pixel count and selected generation resolution."}>
+ tooltip={field === "x" || field === "y" ? "Drag the box or its handles, or drag outside it to draw a new box." : "Sizes use 32-pixel increments. The source is resized to fit the box at the selected generation resolution."}>
<input id={`extend-${field}`} aria-label={`Extend ${field}`} className="text-field" type="number" step={field === "x" || field === "y" ? 1 : EXTEND_GRID} min={field === "x" || field === "y" ? -8192 : EXTEND_GRID} max={field === "x" || field === "y" ? 8192 : EXTEND_MAX_EDGE} required disabled={busy}
value={options.bounds[field]} onChange={(event) => {
const value = event.target.valueAsNumber; if (!Number.isFinite(value)) return;
@@ -38,7 +44,7 @@ export function ExtendSettings({ config, source, options, onChange, references,
value={Number.isNaN(options.steps) ? "" : options.steps} onChange={(event) => onChange({ ...options, steps: event.target.valueAsNumber })} /></PropRow>
<PropRow label="Seed" htmlFor="extend-seed" tooltip="Use -1 for a random seed."><input id="extend-seed" className="text-field" type="number" min="-1" max={Number.MAX_SAFE_INTEGER} step="1" required disabled={busy}
value={Number.isNaN(options.seed) ? "" : options.seed} onChange={(event) => onChange({ ...options, seed: event.target.valueAsNumber })} /></PropRow>
- <div className="image-inspector__area"><span>Prompt</span><PromptTextField aria-label="Extend prompt" value={options.prompt} onChange={(prompt) => onChange({ ...options, prompt })}
+ <div className="image-inspector__area"><span>Prompt (optional)</span><PromptTextField aria-label="Extend prompt" value={options.prompt} onChange={(prompt) => onChange({ ...options, prompt })}
references={references} missingLabel={missingLabel} disabled={busy} placeholder="Describe what should appear beyond the image…" /></div>
{validation.message && <InfoBar severity="error" title="Adjust the Extend settings" message={validation.message} />}
</div>
diff --git a/src/components/workspace/ImageEditor.tsx b/src/components/workspace/ImageEditor.tsx
index ccafcd1..3eff9eb 100644
--- a/src/components/workspace/ImageEditor.tsx
+++ b/src/components/workspace/ImageEditor.tsx
@@ -19,7 +19,7 @@ import { ImageBar } from "./ImageBar";
import { CharacterSheetSettings } from "./CharacterSheetSettings";
import { ExtendSettings } from "./ExtendSettings";
import { ExtendCanvas } from "./ExtendCanvas";
-import { extendOutputDimensions, type ExtendOptions } from "../../lib/extendImage";
+import { extendOutputDimensions, initialExtendBounds, type ExtendOptions } from "../../lib/extendImage";
import type { CharacterSheetOptions } from "../../lib/characterSheet";
import { referenceMediaTypes } from "../../lib/referenceSelection";
import { DebugPromptDialog } from "./DebugPromptDialog";
@@ -584,6 +584,12 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene
disabled={!output || (!output.relativePath && !output.sourcePath)}
onClick={(event) => templateMenu.open(event.currentTarget, [{ label: "Character sheet", icon: <Image16 />,
onSelect: () => { setExtendSourceId(null); setTemplateSourceId(output!.id); },
+ }, { label: "Extend", icon: <Boxes16 />, disabled: !output?.width || !output?.height || Boolean(active),
+ onSelect: () => {
+ setTemplateSourceId(null); setExtendSourceId(output!.id);
+ setExtendOptions({ bounds: initialExtendBounds(output!.width!, output!.height!), prompt: "", steps: template?.defaultSteps ?? 20, seed: -1 });
+ setDrawKind(null); setView({ zoom: 1, x: 0, y: 0 });
+ },
}], { "aria-label": "Image templates", placement: "bottom-end" })}>
Template <ChevronDown14 aria-hidden="true" />
</button>
@@ -678,6 +684,7 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene
</section>
<Splitter {...inspectorPane.splitterProps} reverse aria-label="Resize inspector" />
{extendMode && output && extendOptions ? <ExtendSettings config={config} source={output} options={extendOptions} onChange={setExtendOptions}
+ onResolutionChange={(resolution) => onChange((current) => ({ ...current, imageSettings: { ...imageSettings(current), resolution } }))}
references={promptReferences} missingLabel={missingReference} busy={Boolean(active)}
disabledReason={!isTauri() ? "Template execution is available in the desktop app." : !onGenerateExtend || !template || !templateUsable(template) ? "Choose a downloaded generator to execute this template." : null}
onExecute={() => attempt(() => onGenerateExtend?.(template!, output.id, extendOptions))} onClose={() => setExtendSourceId(null)}
diff --git a/src/lib/extendImage.test.ts b/src/lib/extendImage.test.ts
index f067127..3890d1b 100644
--- a/src/lib/extendImage.test.ts
+++ b/src/lib/extendImage.test.ts
@@ -1,5 +1,5 @@
import { expect, it } from "vitest";
-import { alignExtendBounds, compileExtendImage, extendLayout, extendRegions, extendSourceDimensions, EXTEND_MAX_EDGE, EXTEND_MAX_PIXELS, initialExtendBounds } from "./extendImage";
+import { alignExtendBounds, compileExtendImage, extendContext, extendLayout, extendRegions, extendSourceDimensions, EXTEND_MAX_EDGE, EXTEND_MAX_PIXELS, initialExtendBounds } from "./extendImage";
import { createProjectConfig } from "./project";
it("partitions only new pixels for every combination of extension directions and crops", () => {
@@ -34,12 +34,14 @@ it("generates the entire surround in one pass while preserving the original in a
for (const x of [-64, 0, 32]) for (const y of [-32, 0, 32]) {
const { layout, edits } = compileExtendImage(config, source, "cache/canvas.png", { bounds: { x, y, width: 192, height: 128 }, prompt: "Forest", steps: 20, seed: 0 });
expect(edits).toHaveLength(1);
- expect(edits[0]).toMatchObject({ ...layout.preserved, invertMask: true, feather: 0 });
+ expect(edits[0]).toMatchObject({ ...extendContext(layout.preserved, layout.output), invertMask: true, feather: 0 });
const contains = (r: { x: number; y: number; width: number; height: number }, px: number, py: number) => px >= r.x && py >= r.y && px < r.x + r.width && py < r.y + r.height;
+ let allNewPixelsGenerated = true;
for (let py = 0; py < layout.output.height; py++) for (let px = 0; px < layout.output.width; px++) {
const generated = edits[0].invertMask && !contains(edits[0], px, py);
- expect(generated).toBe(!contains(layout.preserved, px, py));
+ if (!contains(layout.preserved, px, py) && !generated) allNewPixelsGenerated = false;
}
+ expect(allNewPixelsGenerated).toBe(true);
}
});
@@ -51,7 +53,8 @@ it("uses the positioned canvas as context and reserves picture labels only for c
const withoutReferences = compile("");
expect(withoutReferences.prompt).toMatch(/^integrated_multimodal_description:/);
expect(withoutReferences.prompt).not.toContain("<Picture");
- expect(withoutReferences.prompt).toContain("as if the view were zoomed out");
+ expect(withoutReferences.prompt).toContain("Source scene's setting");
+ expect(withoutReferences.prompt).not.toMatch(/zoomed out|continues above|continues below/);
expect(withoutReferences.edits.every((edit) => edit.prompt === withoutReferences.prompt)).toBe(true);
config.references = [{ id: "mood", name: "Mood", kind: "text", content: "Misty woodland", description: "", intendedUse: [], createdAt: config.createdAt }];
expect(compile("@[ref:mood]").prompt).not.toContain("<Picture");
@@ -70,11 +73,11 @@ it("rejects an extension with too little preserved image to condition the genera
const config = createProjectConfig({ name: "Extend", prompt: "", aspectRatio: "1:1", resolution: "768p", targetDurationSeconds: 15 });
const source = { id: "source", name: "Source", kind: "image" as const, mimeType: "image/png", width: 128, height: 96, createdAt: config.createdAt };
expect(() => compileExtendImage(config, source, "cache/canvas.png", {
- bounds: { x: 120, y: 0, width: 192, height: 192 }, prompt: "", steps: 20, seed: 0,
+ bounds: { x: 127, y: 0, width: 192, height: 192 }, prompt: "", steps: 20, seed: 0,
})).toThrow("Keep a larger area");
});
-it("keeps selection and output on the generation grid without increasing the source pixel count", () => {
+it("uses the selected output budget independently of source size, within the generation grid", () => {
const config = createProjectConfig({ name: "Extend", prompt: "", aspectRatio: "16:9", resolution: "2048p", targetDurationSeconds: 15 });
for (const source of [{ width: 400, height: 300 }, { width: 3648, height: 2048 }, { width: 2048, height: 3648 }, { width: 8192, height: 8192 }]) {
const bounds = initialExtendBounds(source.width, source.height);
@@ -84,9 +87,9 @@ it("keeps selection and output on the generation grid without increasing the sou
expect(Math.max(size.width, size.height)).toBeLessThanOrEqual(EXTEND_MAX_EDGE);
expect(size.width * size.height).toBeLessThanOrEqual(EXTEND_MAX_PIXELS);
}
- expect(layout.output.width * layout.output.height).toBeLessThanOrEqual(source.width * source.height);
- expect(layout.source.width).toBeLessThan(source.width);
- expect(layout.source.height).toBeLessThan(source.height);
+ expect(layout.output.width * layout.output.height).toBeGreaterThan(EXTEND_MAX_PIXELS * 0.96);
+ expect(layout.source.width).toBeLessThan(layout.output.width);
+ expect(layout.source.height).toBeLessThan(layout.output.height);
expect(Math.abs(layout.source.width / source.width - layout.source.height / source.height)).toBeLessThan(1 / Math.min(source.width, source.height));
expect(layout.regions).toHaveLength(4);
const workspace = extendSourceDimensions(source.width, source.height);
@@ -100,15 +103,37 @@ it("uses the selected resolution budget and the same scaled geometry for preserv
const source = { id: "source", name: "Source", kind: "image" as const, mimeType: "image/png", width: 128, height: 96, createdAt: config.createdAt };
const options = { bounds: { x: -64, y: -32, width: 256, height: 160 }, prompt: "Forest", steps: 20, seed: 0 };
const compiled = compileExtendImage(config, source, "cache/source.png", options);
- expect(compiled.layout).toMatchObject({ output: { width: 128, height: 64 }, source: { width: 51, height: 38 }, bounds: { x: -38, y: -13, width: 128, height: 64 }, preserved: { x: 38, y: 13, width: 51, height: 38 } });
- expect(compiled.scene.sourceImage).toMatchObject({ width: 128, height: 64 });
- for (const edit of compiled.edits) { expect(edit.x + edit.width).toBeLessThanOrEqual(128); expect(edit.y + edit.height).toBeLessThanOrEqual(64); }
+ expect(compiled.layout).toMatchObject({ output: { width: 512, height: 320 }, source: { width: 256, height: 192 }, bounds: { x: -128, y: -64, width: 512, height: 320 }, preserved: { x: 128, y: 64, width: 256, height: 192 } });
+ expect(compiled.scene.sourceImage).toMatchObject({ width: 512, height: 320 });
+ expect(compiled.edits[0]).toMatchObject({ x: 144, y: 80, width: 224, height: 160 });
const large = { width: 2048, height: 2048 };
const layout = extendLayout(config, large, initialExtendBounds(large.width, large.height));
expect(layout.output.width * layout.output.height).toBeLessThanOrEqual(416 * 416);
expect(() => compileExtendImage(config, source, "cache/source.png", { ...options, bounds: { ...options.bounds, width: 257 } })).toThrow("multiples of 32");
});
+it("shrinks the source when the selection expands, and grows output when resolution increases", () => {
+ const config = createProjectConfig({ name: "Extend", prompt: "", aspectRatio: "1:1", resolution: "768p", targetDurationSeconds: 15 });
+ const source = { width: 768, height: 768 };
+ const small = extendLayout(config, source, { x: -192, y: -192, width: 1152, height: 1152 });
+ const large = extendLayout(config, source, { x: -384, y: -384, width: 1536, height: 1536 });
+ expect(small.output).toEqual({ width: 768, height: 768 });
+ expect(large.output).toEqual(small.output);
+ expect(small.source).toEqual({ width: 512, height: 512 });
+ expect(large.source).toEqual({ width: 384, height: 384 });
+ const higher = extendLayout({ ...config, imageSettings: { ...config.settings, resolution: "1088p" } }, source, { x: -384, y: -384, width: 1536, height: 1536 });
+ expect(higher.output).toEqual({ width: 1088, height: 1088 });
+ expect(higher.source).toEqual({ width: 544, height: 544 });
+});
+
+it("frees seam rows only on edges that face generated space", () => {
+ expect(extendContext({ x: 0, y: 0, width: 256, height: 256 }, { width: 384, height: 256 }))
+ .toEqual({ x: 0, y: 0, width: 240, height: 256 });
+ expect(extendContext({ x: 64, y: 32, width: 256, height: 256 }, { width: 384, height: 320 }))
+ .toEqual({ x: 80, y: 48, width: 224, height: 224 });
+ expect(() => extendContext({ x: 16, y: 16, width: 32, height: 32 }, { width: 64, height: 64 })).toThrow("larger area");
+});
+
it("aligns resize dimensions while preserving the opposite corner and caps every sizing path", () => {
expect(alignExtendBounds({ x: -10, y: -7, width: 610, height: 455 }, "nw")).toEqual({ x: -8, y: 0, width: 608, height: 448 });
for (const mode of ["draw", "nw", "e", "s"]) {
diff --git a/src/lib/extendImage.ts b/src/lib/extendImage.ts
index 970a0cd..e27e390 100644
--- a/src/lib/extendImage.ts
+++ b/src/lib/extendImage.ts
@@ -5,6 +5,7 @@ import { outputDimensions } from "./export";
import type { ProjectAsset, ProjectConfig } from "./project";
export const EXTEND_GRID = 32;
+export const EXTEND_SEAM = 16;
// Largest current generation preset (2048p landscape), also usable in portrait.
const MAX_GENERATION_SIZE = outputDimensions("2048p", "16:9");
export const EXTEND_MAX_EDGE = Math.max(MAX_GENERATION_SIZE.width, MAX_GENERATION_SIZE.height);
@@ -38,10 +39,10 @@ export function initialExtendBounds(width: number, height: number): ExtendBounds
return { ...box, x: Math.round((source.width - box.width) / 2), y: Math.round((source.height - box.height) / 2) };
}
-export function extendOutputDimensions(config: ProjectConfig, source: { width: number; height: number }, bounds: ExtendBounds) {
+export function extendOutputDimensions(config: ProjectConfig, _source: { width: number; height: number }, bounds: ExtendBounds) {
const selected = outputDimensions(imageSettings(config).resolution, imageSettings(config).aspectRatio);
- const pixelBudget = Math.min(source.width * source.height, selected.width * selected.height, EXTEND_MAX_PIXELS);
- const scale = Math.min(1, Math.sqrt(pixelBudget / (bounds.width * bounds.height)), EXTEND_MAX_EDGE / bounds.width, EXTEND_MAX_EDGE / bounds.height);
+ const pixelBudget = Math.min(selected.width * selected.height, EXTEND_MAX_PIXELS);
+ const scale = Math.min(Math.sqrt(pixelBudget / (bounds.width * bounds.height)), EXTEND_MAX_EDGE / bounds.width, EXTEND_MAX_EDGE / bounds.height);
const width = Math.floor(bounds.width * scale / EXTEND_GRID) * EXTEND_GRID;
const height = Math.floor(bounds.height * scale / EXTEND_GRID) * EXTEND_GRID;
if (width < EXTEND_GRID || height < EXTEND_GRID) throw new Error("The Extend box is too narrow for a 32-pixel generation grid at this resolution.");
@@ -83,22 +84,35 @@ export function extendRegions(source: { width: number; height: number }, bounds:
return { preserved: { x: left, y: top, width: right - left, height: bottom - top }, regions };
}
+/** Leave one VAE cell free at each edge facing generated space. Canvas edges
+ * stay pinned; only the source interior must contain a complete latent cell. */
+export function extendContext(preserved: ExtendBounds, output: { width: number; height: number }) {
+ const left = preserved.x > 0 ? EXTEND_SEAM : 0;
+ const top = preserved.y > 0 ? EXTEND_SEAM : 0;
+ const right = preserved.x + preserved.width < output.width ? EXTEND_SEAM : 0;
+ const bottom = preserved.y + preserved.height < output.height ? EXTEND_SEAM : 0;
+ const context = { x: preserved.x + left, y: preserved.y + top,
+ width: preserved.width - left - right, height: preserved.height - top - bottom };
+ if (Math.ceil(context.x / 16) >= Math.floor((context.x + context.width) / 16)
+ || Math.ceil(context.y / 16) >= Math.floor((context.y + context.height) / 16)) {
+ throw new Error("Keep a larger area of the original image inside the Extend box, or increase the generation resolution.");
+ }
+ return context;
+}
+
export function compileExtendImage(config: ProjectConfig, source: ProjectAsset, sourceRelativePath: string, options: ExtendOptions) {
if (!source.width || !source.height) throw new Error("Wait for the source image dimensions to load.");
const layout = extendLayout(config, { width: source.width, height: source.height }, options.bounds);
const { preserved, output } = layout;
- if (Math.ceil(preserved.x / 16) >= Math.floor((preserved.x + preserved.width) / 16)
- || Math.ceil(preserved.y / 16) >= Math.floor((preserved.y + preserved.height) / 16)) {
- throw new Error("Keep a larger area of the original image inside the Extend box.");
- }
+ const context = extendContext(preserved, output);
if (!Number.isInteger(options.steps) || options.steps < 2 || options.steps > 1000) throw new Error("Steps must be a whole number from 2 to 1000.");
if (!Number.isSafeInteger(options.seed) || options.seed < -1) throw new Error("Seed must be -1 for random or a non-negative safe integer.");
const scene = createImageEditScene({ relativePath: sourceRelativePath, name: source.name, ...output });
scene.steps = options.steps; scene.seed = options.seed;
- scene.nodes[0].description = "A wider view of the source scene, as if the view were zoomed out. Continue the same surroundings beyond the visible edges, matching perspective, scale, lighting and textures. One continuous scene, with the original content in its existing position. " + options.prompt.trim();
+ scene.nodes[0].description = "One continuous scene matching Source scene's setting, perspective, subject scale, lighting and textures. The existing subjects remain at their canvas positions. " + options.prompt.trim();
const compiled = compileImagePrompt({ ...config, imageSettings: { ...imageSettings(config), defaultLook: null }, imageScene: scene }, { sourceTreatment: "outpaint" });
- // Preserve the original throughout denoising while generating every new
+ // Preserve the interior throughout denoising while generating every new
// region together. Separate border passes break shared context at the seams.
- const edits = [{ ...preserved, prompt: compiled.prompt, feather: 0, invertMask: true }];
+ const edits = [{ ...context, prompt: compiled.prompt, feather: 0, invertMask: true }];
return { ...compiled, scene, edits, layout };
}
diff --git a/src/lib/extendWork.test.ts b/src/lib/extendWork.test.ts
index 51aba49..729015b 100644
--- a/src/lib/extendWork.test.ts
+++ b/src/lib/extendWork.test.ts
@@ -18,7 +18,7 @@ vi.mock("./runtime", () => ({ cancelSlopfabGeneration: vi.fn(), enqueueSlopfabGe
const handlers = new Map<string, (event: { payload: unknown }) => void>();
const template: GeneratorTemplate = { id: "h3", name: "H3", modelType: "minimax-h3", defaultSteps: 20, attention: "sage2", paths: { ...EMPTY_ENGINE_SETTINGS, transformer: "C:/h3.safetensors" } };
const options = (): ExtendOptions => ({ bounds: { x: -64, y: -32, width: 256, height: 160 }, prompt: "Continue the forest", steps: 25, seed: 0 });
-const result = { relativePath: "media/generated/extended.png", width: 128, height: 64 };
+const result = { relativePath: "media/generated/extended.png", width: 960, height: 576 };
let stop: (() => void) | undefined;
beforeEach(() => {
localStorage.clear(); vi.resetAllMocks(); handlers.clear();
@@ -55,7 +55,7 @@ it.each([false, true])("extends a frozen source and saves a child with a durable
expect(queue.getSnapshot()).toHaveLength(1);
const pending = parseProjectConfig(JSON.parse(JSON.stringify(session.getSnapshot().config)));
const entry = pending.assets.at(-1)!;
- expect(entry).toMatchObject({ id: queue.getSnapshot()[0].id, imageDraft: true, parentAssetId: "root", width: 128, height: 64,
+ expect(entry).toMatchObject({ id: queue.getSnapshot()[0].id, imageDraft: true, parentAssetId: "root", width: 960, height: 576,
imageGeneration: { template: { kind: "extend", sourceId: "source", sourceName: "source", generatorName: "H3", ...options() } } });
expect(entry.relativePath).toBeUndefined();
expect(pending.imageScene!.outputAssetId).toBe(entry.id);
@@ -63,15 +63,15 @@ it.each([false, true])("extends a frozen source and saves a child with a durable
expect(saveImageDraft(restoreGeneratedImage(pending, entry.id)).assets).toEqual(pending.assets);
const request = await submitted();
const { jobId } = request;
- expect(request).toMatchObject({ stillImage: true, frames: 1, seed: 0, steps: 25, canvasWidth: 128, canvasHeight: 64,
+ expect(request).toMatchObject({ stillImage: true, frames: 1, seed: 0, steps: 25, canvasWidth: 960, canvasHeight: 576,
imageEdit: { sourceRelativePath: `cache/extend-images/${jobId}/canvas.png` }, referencePaths: [] });
- expect(request.imageEdit!.edits).toEqual([{ x: 38, y: 13, width: 51, height: 38, invertMask: true, feather: 0, prompt: request.prompt }]);
- expect(request.prompt).toContain("as if the view were zoomed out");
+ expect(request.imageEdit!.edits).toEqual([{ x: 266, y: 131, width: 429, height: 314, invertMask: true, feather: 0, prompt: request.prompt }]);
+ expect(request.prompt).toContain("Source scene's setting");
expect(request.prompt).not.toContain("<Picture");
expect(request.prompt).not.toContain("composition anchor");
expect(request.prompt).toContain("Continue the forest");
expect(request.prompt).not.toContain("Changed");
- expect(invoke).toHaveBeenCalledWith("prepare_extend_image", { folderPath: "C:/Extend", jobId, sourceId: "source", bounds: options().bounds, output: { width: 128, height: 64 } });
+ expect(invoke).toHaveBeenCalledWith("prepare_extend_image", { folderPath: "C:/Extend", jobId, sourceId: "source", bounds: options().bounds, output: { width: 960, height: 576 } });
if (changed) session.update((config) => restoreGeneratedImage(config, "source"));
emit("framesReady", jobId);
await waitFor(() => expect(queue.getSnapshot()[0].status).toBe("completed"));
diff --git a/src/lib/imagePrompt.ts b/src/lib/imagePrompt.ts
index 26c373b..658e604 100644
--- a/src/lib/imagePrompt.ts
+++ b/src/lib/imagePrompt.ts
@@ -15,8 +15,8 @@ export function compileImagePrompt(config: ProjectConfig, options: { referenceTr
return reference;
});
// Ordinary edits submit the source before the selected reference pictures.
- // Outpainting uses only the positioned inpainting canvas for source context;
- // submitting the original as a separate picture would lose that placement.
+ // The runtime supplies the preserved outpaint crop to Qwen as "Source scene"
+ // and its positioned canvas to denoising; it does not consume a Picture slot.
const editing = scene.rootType === "image" && Boolean(scene.sourceImage);
const outpainting = editing && options.sourceTreatment === "outpaint";
const sourcePicture = editing && !outpainting;