AI media harness for planning, generating, and editing locally
TypeScript
Use native refinement and blending in Zoom
Bittia8e6dff705e6
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.mdindex 4956f74..ac3091c 100644--- a/RELEASE_NOTES.md+++ b/RELEASE_NOTES.md@@ -5,7 +5,7 @@ This alpha update adds SeedVR2 and Real-ESRGAN export upscaling, Long Shot and B## What's new- **Sol attention in Settings.** Choose Sol attention under a generator's Performance settings for generation on CUDA GPUs. The selection is saved per generator and included in shared generator files.-- **Zoom image template (formerly Extend).** 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. Boxes inside the source regenerate the selected crop with refined detail at the target resolution. Positioned source conditioning keeps the scene anchored, while generated edges blend into the original with seam tone matching.+- **Zoom image template (formerly Extend).** 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. Boxes inside the source regenerate the selected crop with refined detail at the target resolution. Positioned source conditioning keeps the scene anchored. SlopFab 1.28 refines new surroundings with Langevin iterations and blends edges with a Gaussian mask.- **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.@@ -25,7 +25,7 @@ This alpha update adds SeedVR2 and Real-ESRGAN export upscaling, Long Shot and B## Fixes and improvements-- Zoom blends color locally along each edge and smoothly around corners, reducing visible rectangular transitions without spreading high-contrast details into halos.+- Zoom uses SlopFab's native edge blend directly, avoiding a second feather or color correction when saving. Source transparency is retained.- Generate all includes the final scene in an even-length Long Shot sequence, continuing from the preceding scene and preserving earlier joined video and audio. Four scenes generate in 1 → 3 → 2 → 4 order; adding another scene turns the final continuation into a bridge on its next generation.- Long Shot timeline playback keeps the same video player running across adjacent scenes in a joined generation, avoiding a playback restart at bridge boundaries.- Reduced memory retained between generations by releasing consumed SlopFab samples and handles, completed queue snapshots, encoder buffers on errors, and abandoned LAN generation results.diff --git a/src-tauri/core/src/slopfab/ffi/mod.rs b/src-tauri/core/src/slopfab/ffi/mod.rsindex 999e1f0..f239930 100644--- a/src-tauri/core/src/slopfab/ffi/mod.rs+++ b/src-tauri/core/src/slopfab/ffi/mod.rs@@ -118,6 +118,18 @@ impl Api {self.check(r)?;self.inner.set_image_edit_rgb(r.pointer.as_ptr(), pixels, width, height, bounds, strength, feather)}+ pub fn set_outpaint_blend_overlap(&self, r: &RequestHandle, value: i32) -> Result<(), String> {+ self.check(r)?;+ self.inner.set_outpaint_blend_overlap(r.pointer.as_ptr(), value)+ }+ #[cfg(test)]+ pub fn disable_outpaint_refinement_for_test(&mut self) {+ Arc::get_mut(&mut self.inner).expect("configure API before creating handles").disable_outpaint_refinement_for_test();+ }+ pub fn set_outpaint_langevin_steps(&self, r: &RequestHandle, value: i32) -> Result<(), String> {+ self.check(r)?;+ self.inner.set_outpaint_langevin_steps(r.pointer.as_ptr(), value)+ }pub fn set_image_edit_invert_mask(&self, r: &RequestHandle) -> Result<(), String> {self.check(r)?;self.inner.set_image_edit_invert_mask(r.pointer.as_ptr())diff --git a/src-tauri/core/src/slopfab/ffi/raw/mod.rs b/src-tauri/core/src/slopfab/ffi/raw/mod.rsindex d4ccaeb..55fff3f 100644--- a/src-tauri/core/src/slopfab/ffi/raw/mod.rs+++ b/src-tauri/core/src/slopfab/ffi/raw/mod.rs@@ -95,6 +95,8 @@ pub struct Api {set_image_edit_path: Option<SetImageEditPath>,set_image_edit_rgb: Option<SetImageEditRgb>,set_image_edit_invert_mask: Option<unsafe extern "C" fn(*mut Request, i32) -> i32>,+ set_outpaint_blend_overlap: Option<unsafe extern "C" fn(*mut Request, i32) -> i32>,+ set_outpaint_langevin_steps: Option<unsafe extern "C" fn(*mut Request, i32) -> i32>,set_save_latents: Option<unsafe extern "C" fn(*mut Request, *const c_char) -> i32>,set_continuation_file: Option<unsafe extern "C" fn(*mut Request, *const c_char, i32) -> i32>,set_latent_bridge_files: Option<unsafe extern "C" fn(*mut Request, *const c_char, *const c_char, i32, i32, i32) -> i32>,@@ -218,6 +220,8 @@ impl Api {set_image_edit_path: library.get::<SetImageEditPath>(b"slopfab_request_set_image_edit_path\0").ok().map(|symbol| *symbol),set_image_edit_rgb: library.get::<SetImageEditRgb>(b"slopfab_request_set_image_edit_rgb24\0").ok().map(|symbol| *symbol),set_image_edit_invert_mask: library.get::<unsafe extern "C" fn(*mut Request, i32) -> i32>(b"slopfab_request_set_image_edit_invert_mask\0").ok().map(|symbol| *symbol),+ set_outpaint_blend_overlap: library.get::<unsafe extern "C" fn(*mut Request, i32) -> i32>(b"slopfab_request_set_outpaint_blend_overlap\0").ok().map(|symbol| *symbol),+ set_outpaint_langevin_steps: library.get::<unsafe extern "C" fn(*mut Request, i32) -> i32>(b"slopfab_request_set_outpaint_langevin_steps\0").ok().map(|symbol| *symbol),set_steps: symbol!("slopfab_request_set_steps",unsafe extern "C" fn(*mut Request, i32) -> i32@@ -467,6 +471,14 @@ impl Api {}self.error(unsafe { set(r, pixels.as_ptr(), pixels.len(), width, height, width as usize * 3, bounds[0], bounds[1], bounds[2], bounds[3], strength, feather) })}+ pub fn set_outpaint_blend_overlap(&self, r: *mut Request, value: i32) -> Result<(), String> {+ let set = self.set_outpaint_blend_overlap.ok_or("Zoom edge refinement requires SlopFab API 1.28 or later. Update the generation runtime.")?;+ self.error(unsafe { set(r, value) })+ }+ pub fn set_outpaint_langevin_steps(&self, r: *mut Request, value: i32) -> Result<(), String> {+ let set = self.set_outpaint_langevin_steps.ok_or("Zoom edge refinement requires SlopFab API 1.28 or later. Update the generation runtime.")?;+ self.error(unsafe { set(r, value) })+ }pub fn set_image_edit_invert_mask(&self, r: *mut Request) -> Result<(), String> {let set = self.set_image_edit_invert_mask.ok_or("Seamless Zoom requires SlopFab API 1.20 or later. Update the generation runtime.")?;self.error(unsafe { set(r, 1) })@@ -585,6 +597,11 @@ impl Api {pub fn disable_outpainting_for_test(&mut self) {self.set_image_edit_invert_mask = None;}+ #[cfg(test)]+ pub fn disable_outpaint_refinement_for_test(&mut self) {+ self.set_outpaint_blend_overlap = None;+ self.set_outpaint_langevin_steps = None;+ }pub fn set_continuation_lock_overlap(&self, r: *mut Request, enabled: bool) -> Result<(), String> {let Some(set) = self.set_continuation_lock_overlap else {return if enabled { Err("Lock Overlap requires SlopFab API 1.23 or later. Update the generation runtime.".into()) } else { Ok(()) };diff --git a/src-tauri/core/src/slopfab/ffi/tests.rs b/src-tauri/core/src/slopfab/ffi/tests.rsindex 269d3c0..35e0c03 100644--- a/src-tauri/core/src/slopfab/ffi/tests.rs+++ b/src-tauri/core/src/slopfab/ffi/tests.rs@@ -49,6 +49,17 @@ fn older_runtimes_reject_outpainting_instead_of_editing_the_original() {assert!(api.resolve(&request).is_ok());}+#[test]+fn older_runtimes_reject_requested_zoom_refinement() {+ let mut api = Api::load(&crate::slopfab::default_dll_path()).unwrap();+ api.disable_outpaint_refinement_for_test();+ let request = RequestHandle::new(&api).unwrap();+ api.set_image_edit_rgb(&request, &vec![127; 64 * 64 * 3], 64, 64, [16, 16, 32, 32], 1.0, 0).unwrap();+ api.set_image_edit_invert_mask(&request).unwrap();+ assert!(api.set_outpaint_blend_overlap(&request, 9).unwrap_err().contains("API 1.28"));+ assert!(api.set_outpaint_langevin_steps(&request, 5).unwrap_err().contains("API 1.28"));+}+#[test]fn older_runtimes_report_missing_lora_preparation_without_breaking_planning() {let mut api = Api::load(&crate::slopfab::default_dll_path()).unwrap();diff --git a/src-tauri/core/src/slopfab/h3.rs b/src-tauri/core/src/slopfab/h3.rsindex e89387b..79dc22f 100644--- a/src-tauri/core/src/slopfab/h3.rs+++ b/src-tauri/core/src/slopfab/h3.rs@@ -86,6 +86,12 @@ pub(super) fn configure_request(}if step.invert_mask {api.set_image_edit_invert_mask(handle)?;+ if let Some(overlap) = step.outpaint_blend_overlap {+ api.set_outpaint_blend_overlap(handle, overlap)?;+ }+ if let Some(steps) = step.outpaint_langevin_steps {+ api.set_outpaint_langevin_steps(handle, steps)?;+ }}} else {// H3 diffusion needs complete 32-pixel patches. The encoder fits thediff --git a/src-tauri/core/src/slopfab/planning.rs b/src-tauri/core/src/slopfab/planning.rsindex a7e492a..43a8325 100644--- a/src-tauri/core/src/slopfab/planning.rs+++ b/src-tauri/core/src/slopfab/planning.rs@@ -84,6 +84,11 @@ pub(super) fn validate_generation_controls(request: &GenerationRequest) -> Resulreturn Err("Image edits require one source image and nonempty boxes inside its dimensions.".into());}for step in &edit.edits {+ if (step.outpaint_blend_overlap.is_some() || step.outpaint_langevin_steps.is_some()) && !step.invert_mask+ || step.outpaint_blend_overlap.is_some_and(|value| !(1..=51).contains(&value) || value % 2 == 0)+ || step.outpaint_langevin_steps.is_some_and(|value| !(0..=100).contains(&value)) {+ return Err("Outpaint refinement requires an inverted mask, an odd blend overlap from 1 to 51 and Langevin steps from 0 to 100.".into());+ }if step.strength.is_some_and(|strength| !strength.is_finite() || strength <= 0.0 || strength > 1.0) {return Err("Image edit strength must be greater than zero and at most one.".into());}diff --git a/src-tauri/core/src/slopfab/tests.rs b/src-tauri/core/src/slopfab/tests.rsindex 37792f2..81c4cf2 100644--- a/src-tauri/core/src/slopfab/tests.rs+++ b/src-tauri/core/src/slopfab/tests.rs@@ -79,7 +79,7 @@ fn image_edit_recipe_disables_motion_cache_and_keeps_source_geometry() {canvas_width: 65, canvas_height: 41,image_edit_pixels: Some(std::sync::Arc::new(vec![100; 65 * 41 * 3])),image_edit: Some(types::ImageEditRequest { source_relative_path: "media/source.png".into(), edits: vec![- types::ImageEditStep { prompt: "A red vase".into(), x: 30, y: 10, width: 35, height: 31, feather: None, strength: None, invert_mask: false, reference_paths: None, refmods: None }+ types::ImageEditStep { prompt: "A red vase".into(), x: 30, y: 10, width: 35, height: 31, feather: None, strength: None, invert_mask: false, outpaint_blend_overlap: None, outpaint_langevin_steps: None, reference_paths: None, refmods: None }] }), ..Default::default()};validate_generation_controls(&request).unwrap();@@ -154,12 +154,15 @@ fn outpainting_preserves_one_box_in_preview_execution_and_worker_requests() {"steps":4, "seed":0, "canvasWidth":128, "canvasHeight":64,"imageEdit":{"sourceRelativePath":"canvas.png", "edits":[{"prompt":"Continue the scene", "x":38, "y":13, "width":51, "height":38,- "feather":0, "invertMask":true+ "feather":0, "invertMask":true, "outpaintBlendOverlap":9, "outpaintLangevinSteps":5}]}})).unwrap();// This is the same serialization boundary used by LAN workers.let mut roundtrip: GenerationRequest = serde_json::from_value(serde_json::to_value(&request).unwrap()).unwrap();- assert!(roundtrip.image_edit.as_ref().unwrap().edits[0].invert_mask);+ let edit = &roundtrip.image_edit.as_ref().unwrap().edits[0];+ assert!(edit.invert_mask);+ assert_eq!(edit.outpaint_blend_overlap, Some(9));+ assert_eq!(edit.outpaint_langevin_steps, Some(5));validate_generation_controls(&roundtrip).unwrap();roundtrip.image_edit_pixels = Some(std::sync::Arc::new(vec![127; 128 * 64 * 3]));for platform in [ComputePlatform::Cuda13, ComputePlatform::Vulkan] {@@ -169,13 +172,21 @@ fn outpainting_preserves_one_box_in_preview_execution_and_worker_requests() {let plan = api.resolve(&handle).unwrap();assert_eq!((plan.canvas_width, plan.canvas_height, plan.aligned_frames), (128, 64, 1));assert_eq!(plan.num_model_evaluations, 3);- assert!(api.describe(&handle).unwrap().contains("outpaint (preserve box)"));+ let description = api.describe(&handle).unwrap();+ assert!(description.contains("outpaint (preserve box)"));+ assert!(description.contains("blend overlap 9; Langevin steps 5"));+ api.set_outpaint_blend_overlap(&handle, 1).unwrap();+ api.set_outpaint_langevin_steps(&handle, 0).unwrap();+ assert!(api.describe(&handle).unwrap().contains("blend overlap 1; Langevin steps 0"));}}for change in [serde_json::json!({"feather":16}), serde_json::json!({"feather":null}),serde_json::json!({"x":0,"y":0,"width":128,"height":64}),serde_json::json!({"width":1}), serde_json::json!({"height":1}),+ serde_json::json!({"outpaintBlendOverlap":0}), serde_json::json!({"outpaintBlendOverlap":8}),+ serde_json::json!({"outpaintBlendOverlap":53}), serde_json::json!({"outpaintLangevinSteps":-1}),+ serde_json::json!({"outpaintLangevinSteps":101}), serde_json::json!({"invertMask":false}),] {let mut value = serde_json::to_value(&request).unwrap();value["imageEdit"]["edits"][0].as_object_mut().unwrap().extend(change.as_object().unwrap().clone());@@ -188,7 +199,7 @@ fn outpainting_preserves_one_box_in_preview_execution_and_worker_requests() {positioned.canvas_height = 416;positioned.image_edit_pixels = Some(std::sync::Arc::new(vec![127; 416 * 416 * 3]));let step = &mut positioned.image_edit.as_mut().unwrap().edits[0];- step.x = 85; step.y = 85; step.width = 245; step.height = 245;+ step.x = 69; step.y = 69; step.width = 277; step.height = 277;for platform in [ComputePlatform::Cuda13, ComputePlatform::Vulkan] {let handle = RequestHandle::new(&api).unwrap();configure_request(&api, &handle, &positioned, &configuration, platform, RequestPurpose::Plan, &ReferenceVideos::default()).unwrap();diff --git a/src-tauri/core/src/slopfab/types.rs b/src-tauri/core/src/slopfab/types.rsindex 3575abb..a6b94e0 100644--- a/src-tauri/core/src/slopfab/types.rs+++ b/src-tauri/core/src/slopfab/types.rs@@ -135,6 +135,10 @@ pub struct ImageEditStep {#[serde(default)]pub invert_mask: bool,#[serde(default)]+ pub outpaint_blend_overlap: Option<i32>,+ #[serde(default)]+ pub outpaint_langevin_steps: Option<i32>,+ #[serde(default)]pub reference_paths: Option<Vec<String>>,#[serde(default)]pub refmods: Option<Vec<RefmodInput>>,diff --git a/src-tauri/src/commands/extend_image.rs b/src-tauri/src/commands/extend_image.rsindex efa6929..6bfa7ed 100644--- a/src-tauri/src/commands/extend_image.rs+++ b/src-tauri/src/commands/extend_image.rs@@ -208,8 +208,8 @@ pub(crate) fn prepare_extend_image();}let cache = root.directory(&directory(&job_id)?)?;- // Snapshot the resized source or crop. Outpainting's final preservation- // uses exactly these pixels, with no second resampling.+ // Snapshot the resized source or crop for native conditioning and final+ // transparency restoration, 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(@@ -218,149 +218,16 @@ 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) {+// SlopFab returns the final RGB blend. Restore only source transparency;+// changing RGB here would apply a second blend over the native seam.+fn restore_source_alpha(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];- // Match color locally along each seam. A whole-edge average mixes unrelated- // materials (e.g. snow and fur) and paints visible rectangular tone bands.- // Prefix sums smooth the measured residual without blurring image detail.- let mut profiles: [Vec<[f32; 3]>; 4] = std::array::from_fn(|_| Vec::new());- for edge in 0..4 {- if bands[edge] == 0 {- continue;- }- let strip = 4.min(right - left).min(bottom - top);- let length = if edge % 2 == 0 {- bottom - top- } else {- right - left- };- let mut sums = vec![[0.0f32; 4]; length as usize + 1];- for position in 0..length {- let mut sum = sums[position as usize];- for inward in 0..strip {- let (x, y) = match edge {- 0 => (left + inward, top + position),- 1 => (left + position, top + inward),- 2 => (right - 1 - inward, top + position),- _ => (left + position, bottom - 1 - inward),- };- let original = source.get_pixel(x, y);- // Hidden RGB cannot describe the generated surroundings.- if original[3] != 255 {- continue;- }- let generated =- result.get_pixel((x as i32 - bounds.x) as u32, (y as i32 - bounds.y) as u32);- // Large residuals usually represent displaced detail, not an- // exposure mismatch. Spreading them would create bright halos.- if (0..3).any(|c| original[c].abs_diff(generated[c]) > 64) {- continue;- }- for c in 0..3 {- sum[c] += original[c] as f32 - generated[c] as f32;- }- sum[3] += 1.0;- }- sums[position as usize + 1] = sum;- }- profiles[edge] = (0..length)- .map(|position| {- let from = sums[position.saturating_sub(SEAM) as usize];- let to = sums[(position + SEAM + 1).min(length) as usize];- let count = to[3] - from[3];- std::array::from_fn(|c| {- if count > 0.0 {- ((to[c] - from[c]) / count).clamp(-32.0, 32.0)- } else {- 0.0- }- })- })- .collect();- }- 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 along = [- y as i32 - py as i32,- x as i32 - px as i32,- y as i32 - py as i32,- x as i32 - px as i32,- ];- let weights: [f32; 4] = std::array::from_fn(|edge| {- if bands[edge] == 0 {- return 0.0;- }- let distance = distances[edge];- let extent = if distance >= 0.0 { bands[edge] } else { SEAM } as f32;- let position = along[edge];- let nearest = position.clamp(0, profiles[edge].len() as i32 - 1);- let tangent = (position - nearest) as f32;- // Distance to the finite edge, not its infinite horizontal/vertical- // line: corrections round the corners instead of forming a cross.- 1.0 - smoothstep(distance.hypot(tangent) / extent)- });- 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)- .filter(|edge| weights[*edge] > 0.0)- .map(|edge| {- let position =- along[edge].clamp(0, profiles[edge].len() as i32 - 1) as usize;- weights[edge] * profiles[edge][position][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 {- 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];- }+ result.get_pixel_mut((x as i32 - bounds.x) as u32, (y as i32 - bounds.y) as u32)[3] = source.get_pixel(x, y)[3];}}}@@ -391,7 +258,7 @@ pub(crate) fn save_extended_image(let mut result = RgbaImage::from_raw(bounds.width, bounds.height, pixels).ok_or("Invalid generated image pixels.")?;if !bounds.is_contained(source.width(), source.height()) {- restore_original(&mut result, &source, bounds);+ restore_source_alpha(&mut result, &source, bounds);}super::artifacts::write_generated_png_frame(&folder_path,@@ -417,19 +284,6 @@ mod tests {use super::*;/// Reuse a GPU smoke capture to compare compositing without another inference.- #[test]- #[ignore]- fn extend_reblend_smoke() {- let folder = std::path::PathBuf::from(std::env::var("SLOPUS_EXTEND_OUTPUT").unwrap());- let source = image::open(folder.join("source.png")).unwrap().to_rgba8();- let mut result = image::open(folder.join("raw.png")).unwrap().to_rgba8();- let bounds: ExtendBounds =- serde_json::from_slice(&std::fs::read(folder.join("bounds.json")).unwrap()).unwrap();- bounds.validate(source.width(), source.height()).unwrap();- restore_original(&mut result, &source, bounds);- write_png(&folder.join("reblended.png"), &result).unwrap();- }-/// Opt-in GPU smoke test. Supply an existing source image, model directory/// and artifact directory; ordinary test runs do not load any models.#[test]@@ -548,7 +402,7 @@ mod tests {let step = if regenerate {serde_json::json!({"x":0,"y":0,"width":size,"height":size,"strength":0.65,"feather":0,"prompt":prompt})} else {- serde_json::json!({"x":85,"y":85,"width":245,"height":245,"invertMask":true,"feather":0,"prompt":prompt})+ serde_json::json!({"x":69,"y":69,"width":277,"height":277,"invertMask":true,"feather":0,"outpaintBlendOverlap":9,"outpaintLangevinSteps":5,"prompt":prompt})};let mut request: GenerationRequest = serde_json::from_value(serde_json::json!({"jobId":job, "stillImage":true, "frames":1, "steps":20, "seed":17, "canvasWidth":size, "canvasHeight":size, "prompt":prompt,@@ -597,8 +451,9 @@ mod tests {assert_eq!(result, raw, "The finalizer must retain regenerated pixels");assert_ne!(result, snapshot, "Generation must change the resized crop");} else {- for y in 16..snapshot.height() - 16 {- for x in 16..snapshot.width() - 16 {+ assert_eq!(result, raw, "Saving must retain the native Gaussian blend");+ for y in 8..snapshot.height() - 8 {+ for x in 8..snapshot.width() - 8 {assert_eq!(result.get_pixel(x + 69, y + 69), snapshot.get_pixel(x, y));}}@@ -694,188 +549,26 @@ mod tests {}#[test]- 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])- });- for bounds in [- ExtendBounds {- x: -3,- y: -2,- width: 12,- height: 10,- },- ExtendBounds {- x: 2,- y: 1,- width: 9,- height: 7,- },- ExtendBounds {- x: -2,- y: -1,- width: 5,- height: 4,- },- ] {- bounds.validate(source.width(), source.height()).unwrap();- let mut result = RgbaImage::from_pixel(- bounds.width,- bounds.height,- image::Rgba([200, 201, 202, 255]),- );- restore_original(&mut result, &source, bounds);- for y in 0..bounds.height {- for x in 0..bounds.width {- let sx = x as i32 + bounds.x;- let sy = y as i32 + bounds.y;- 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 {- assert_eq!(actual, [200, 201, 202, 255]);- }- }- }- let padded = padded_source(&source, bounds);- for y in 0..bounds.height {- 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- } else {- [127, 127, 127, 255]- };- assert_eq!(padded.get_pixel(x, y).0, expected);+ fn extend_restores_only_source_alpha_for_cropped_and_extended_bounds() {+ let source = RgbaImage::from_fn(64, 64, |x, y| image::Rgba([20, 40, 60, ((x + y) % 256) as u8]));+ for x in [-32, 0, 32] {+ for y in [-32, 0, 32] {+ let bounds = ExtendBounds { x, y, width: 96, height: 96 };+ let mut result = RgbaImage::from_pixel(96, 96, image::Rgba([210, 180, 150, 255]));+ restore_source_alpha(&mut result, &source, bounds);+ for (px, py, pixel) in result.enumerate_pixels() {+ assert_eq!(&pixel.0[..3], &[210, 180, 150], "Never reblend native RGB");+ let sx = px as i32 + x;+ let sy = py as i32 + y;+ let alpha = if (0..64).contains(&sx) && (0..64).contains(&sy) {+ source.get_pixel(sx as u32, sy as u32)[3]+ } else { 255 };+ assert_eq!(pixel[3], alpha);}}}}- #[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_matches_different_materials_along_the_same_edge() {- let source = RgbaImage::from_fn(96, 128, |_, y| {- let value = if y < 64 { 60 } else { 100 };- image::Rgba([value, value, value, 255])- });- let mut result = RgbaImage::from_pixel(160, 128, image::Rgba([80, 80, 80, 255]));- restore_original(- &mut result,- &source,- ExtendBounds {- x: -64,- y: 0,- width: 160,- height: 128,- },- );- // The old whole-edge average was zero, leaving both seams visible.- for (y, expected) in [(24, 60u8), (104, 100u8)] {- assert!(result.get_pixel(63, y)[0].abs_diff(expected) <= 1);- assert!(result.get_pixel(64, y)[0].abs_diff(expected) <= 1);- assert_eq!(result.get_pixel(0, y).0, [80, 80, 80, 255]);- assert_eq!(result.get_pixel(100, y), source.get_pixel(36, y));- }- }-- #[test]- fn extend_does_not_spread_displaced_high_contrast_details_into_the_surround() {- let source = RgbaImage::from_pixel(96, 96, image::Rgba([40, 40, 40, 255]));- let mut result = RgbaImage::from_fn(128, 96, |x, _| {- let value = if (92..96).contains(&x) { 200 } else { 40 };- image::Rgba([value, value, value, 255])- });- restore_original(- &mut result,- &source,- ExtendBounds {- x: 0,- y: 0,- width: 128,- height: 96,- },- );- for y in 0..96 {- for x in 96..128 {- assert_eq!(result.get_pixel(x, y).0, [40, 40, 40, 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();@@ -1021,7 +714,7 @@ mod tests {}#[test]- fn extend_finalizer_preserves_downscaled_source_pixels_in_a_bounded_png() {+ fn extend_finalizer_retains_native_blend_and_restores_source_alpha() {struct GeneratedPixels;impl crate::rendered::FrameSource for GeneratedPixels {fn frame_rgba(&self, _: u32, width: u32, height: u32) -> Result<Vec<u8>, String> {@@ -1061,8 +754,6 @@ mod tests {},).unwrap();- let scaled =- image::imageops::resize(&source, 51, 38, image::imageops::FilterType::Lanczos3);// The original file may change while the job runs; its prepared snapshot wins.write_png(&root.existing("media/source.png").unwrap(),@@ -1096,9 +787,7 @@ mod tests {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);- }+ assert_eq!(&actual[..3], &[210, 180, 150]);} else {assert_eq!(actual, [210, 180, 150, 255]);}diff --git a/src/lib/extendImage.test.ts b/src/lib/extendImage.test.tsindex d83fef6..3266f0d 100644--- a/src/lib/extendImage.test.ts+++ b/src/lib/extendImage.test.ts@@ -33,7 +33,7 @@ it("generates the entire surround in one pass while preserving the original in afor (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({ ...extendContext(layout.preserved, layout.output), invertMask: true, feather: 0 });+ expect(edits[0]).toMatchObject({ ...extendContext(layout.preserved), invertMask: true, feather: 0, outpaintBlendOverlap: 9, outpaintLangevinSteps: 5 });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++) {@@ -104,7 +104,7 @@ it("uses the selected resolution budget and the same scaled geometry for preservconst compiled = compileExtendImage(config, source, "cache/source.png", options);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 });+ expect(compiled.edits[0]).toMatchObject({ x: 128, y: 64, width: 256, height: 192 });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);@@ -125,12 +125,12 @@ it("shrinks the source when the selection expands, and grows output when resolutexpect(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("passes the full source rectangle to native blending and retains a positioned patch", () => {+ expect(extendContext({ x: 0, y: 0, width: 256, height: 256 }))+ .toEqual({ x: 0, y: 0, width: 256, height: 256 });+ expect(extendContext({ x: 64, y: 32, width: 256, height: 256 }))+ .toEqual({ x: 64, y: 32, width: 256, height: 256 });+ expect(() => extendContext({ x: 16, y: 16, width: 32, height: 32 })).toThrow("larger area");});it("aligns resize dimensions while preserving the opposite corner and caps every sizing path", () => {diff --git a/src/lib/extendImage.ts b/src/lib/extendImage.tsindex fa9d412..095bcc7 100644--- a/src/lib/extendImage.ts+++ b/src/lib/extendImage.ts@@ -5,7 +5,8 @@ import { outputDimensions } from "./export";import type { ProjectAsset, ProjectConfig } from "./project";export const EXTEND_GRID = 32;-export const EXTEND_SEAM = 16;+export const ZOOM_BLEND_OVERLAP = 9;+export const ZOOM_LANGEVIN_STEPS = 5;// 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);@@ -89,15 +90,9 @@ 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 };+/** SlopFab blends the full source rectangle and refines its surroundings.+ * Keep at least one complete patch for positioned source conditioning. */+export function extendContext(context: ExtendBounds) {if (Math.ceil(context.x / EXTEND_GRID) >= Math.floor((context.x + context.width) / EXTEND_GRID)|| Math.ceil(context.y / EXTEND_GRID) >= Math.floor((context.y + context.height) / EXTEND_GRID)) {throw new Error("Keep a larger area of the original image inside the Zoom box, or increase the generation resolution.");@@ -110,7 +105,7 @@ export function compileExtendImage(config: ProjectConfig, source: ProjectAsset,const layout = extendLayout(config, { width: source.width, height: source.height }, options.bounds);const { preserved, output } = layout;const regenerate = layout.mode === "regenerate";- const context = regenerate ? preserved : extendContext(preserved, output);+ const context = regenerate ? preserved : extendContext(preserved);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 });@@ -121,6 +116,7 @@ export function compileExtendImage(config: ProjectConfig, source: ProjectAsset,const compiled = compileImagePrompt({ ...config, imageSettings: { ...imageSettings(config), defaultLook: null }, imageScene: scene }, regenerate ? {} : { sourceTreatment: "outpaint" });// Outpainting locks the interior and generates all borders together. Crops// refine the whole frame with partial denoising to retain the composition.- const edits = [{ ...context, prompt: compiled.prompt, feather: 0, invertMask: !regenerate, ...(regenerate ? { strength: 0.65 } : {}) }];+ const edits = [{ ...context, prompt: compiled.prompt, feather: 0, invertMask: !regenerate,+ ...(regenerate ? { strength: 0.65 } : { outpaintBlendOverlap: ZOOM_BLEND_OVERLAP, outpaintLangevinSteps: ZOOM_LANGEVIN_STEPS }) }];return { ...compiled, scene, edits, layout };}diff --git a/src/lib/extendWork.test.ts b/src/lib/extendWork.test.tsindex ef72d67..0d2ad34 100644--- a/src/lib/extendWork.test.ts+++ b/src/lib/extendWork.test.ts@@ -65,7 +65,7 @@ it.each([false, true])("extends a frozen source and saves a child with a durableconst { jobId } = request;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: 266, y: 131, width: 429, height: 314, invertMask: true, feather: 0, prompt: request.prompt }]);+ expect(request.imageEdit!.edits).toEqual([{ x: 250, y: 115, width: 461, height: 346, invertMask: true, feather: 0, outpaintBlendOverlap: 9, outpaintLangevinSteps: 5, prompt: request.prompt }]);expect(request.prompt).toContain("Source scene's setting");expect(request.prompt).not.toContain("<Picture");expect(request.prompt).not.toContain("composition anchor");diff --git a/src/lib/imageEditing.ts b/src/lib/imageEditing.tsindex d98fa55..8b570ae 100644--- a/src/lib/imageEditing.ts+++ b/src/lib/imageEditing.ts@@ -10,6 +10,9 @@ export interface ImageEditStep {strength?: number;/** Preserve this box and generate its surround in a single outpainting pass. */invertMask?: boolean;+ /** Native outpainting: odd Gaussian mask kernel (1..51) and inner iterations (0..100). */+ outpaintBlendOverlap?: number;+ outpaintLangevinSteps?: number;referencePaths?: string[];refmods?: Array<{ path: string; strength: number; copies: number }>;}