diff --git a/crates/engine/src/cache.rs b/crates/engine/src/cache.rs index 42fb830ffa304fd5f23371474aef4a9dfaab348b..5ee5f7f3a159576fb1f31f592e513e468923acbc 100644 --- a/crates/engine/src/cache.rs +++ b/crates/engine/src/cache.rs @@ -29,6 +29,8 @@ pub struct CachedTexture { pub format: wgpu::TextureFormat, /// Scale ratio `physical_px / logical_px` when an oversized generator (>8K) is capped to GPU limits (1.0 normally). pub tex_scale: f32, + /// Infinite RoI edge mode propagated from upstream `Merge` (`Some(1)` = Wrap, `Some(3)` = Mirror). + pub edge_mode: Option, pub content_hash: u64, pub bytes: u64, } @@ -79,6 +81,7 @@ impl CachedTexture { depth, format, tex_scale: 1.0, + edge_mode: None, content_hash, bytes, } diff --git a/crates/engine/src/eval/blur_glow.rs b/crates/engine/src/eval/blur_glow.rs index 2d34d11e909e9f029ae7778aabab2c8841b2dafd..861c07a3bc35711ed45fcce8cc34e50c0bab9881 100644 --- a/crates/engine/src/eval/blur_glow.rs +++ b/crates/engine/src/eval/blur_glow.rs @@ -211,18 +211,40 @@ impl Engine { } else { src.size[0] as f32 / 720.0 * 0.86 }; - let (raw_size, gain, thresh, combine_mode) = if is_soft_glow { - let sz = comp.eval_number(node, "XGlowSize", time, 10.0, &self.expr) as f32; + let lock_xy = comp.eval_number( + node, + "LockGlowSize", + time, + comp.eval_number(node, "LockXY", time, 1.0, &self.expr), + &self.expr, + ) > 0.5; + let (raw_size_x, raw_size_y, gain, thresh, combine_mode) = if is_soft_glow { + let sx = comp.eval_number(node, "XGlowSize", time, 10.0, &self.expr) as f32; + let sy = if lock_xy { + sx + } else { + comp.eval_number(node, "YGlowSize", time, sx as f64, &self.expr) as f32 + }; let g = comp.eval_number(node, "Gain", time, 2.0, &self.expr) as f32; let th = comp.eval_number(node, "Threshold", time, 0.0, &self.expr).clamp(0.0, 0.999) as f32; - (sz, g, th, 0.0f32) // Screen blend + (sx, sy, g, th, 0.0f32) // Screen blend } else { - let sz = comp.eval_number(node, "GlowSize", time, 10.0, &self.expr) as f32; + // Fusion 21.1 Glow writes `XGlowSize` (and `YGlowSize` when `LockGlowSize == 0`), + // while older comps/probes may write `GlowSize`. Prefer `XGlowSize`, else `GlowSize`, else 10.0. + let glow_fallback = comp.eval_number(node, "GlowSize", time, 10.0, &self.expr); + let sx = comp.eval_number(node, "XGlowSize", time, glow_fallback, &self.expr) as f32; + let sy = if lock_xy { + sx + } else { + comp.eval_number(node, "YGlowSize", time, sx as f64, &self.expr) as f32 + }; let glow_p = comp.eval_number(node, "Glow", time, 0.8, &self.expr).clamp(0.0, 0.999) as f32; let g = 1.0 / (1.0 - glow_p).max(1e-3); - (sz, g, 0.0f32, 1.0f32) // Replace with blurred / (1 - Glow) + (sx, sy, g, 0.0f32, 1.0f32) // Replace with blurred / (1 - Glow) }; - let size = (raw_size * scale_ref).max(0.0); + let size_x = (raw_size_x * scale_ref).max(0.0); + let size_y = (raw_size_y * scale_ref).max(0.0); + let max_size = size_x.max(size_y); let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); let prev_sz = self.mask_target_size; @@ -239,7 +261,7 @@ impl Engine { if is_soft_glow { "SoftGlow" } else { "Glow" }, src.size, &[src.content_hash, mask_hash, gm_hash], - &[size, gain, thresh, blend, combine_mode, if mask_inv { 1.0 } else { 0.0 }], + &[size_x, size_y, gain, thresh, blend, combine_mode, if mask_inv { 1.0 } else { 0.0 }], ); if let Some(hit) = self.cache.get(key, node.id, frame_i) { stats.cache_hits += 1; @@ -262,10 +284,10 @@ impl Engine { }; let dst = self.alloc_tex_dod(src.size, src.origin, src.canvas_size, src.depth, key); - let down = if self.hiq { 1u32 } else if size >= 14.0 { 4u32 } else if size >= 4.0 { 2u32 } else { 1u32 }; + let down = if self.hiq { 1u32 } else if max_size >= 14.0 { 4u32 } else if max_size >= 4.0 { 2u32 } else { 1u32 }; let work_size = [(src.size[0] / down).max(1), (src.size[1] / down).max(1)]; - let blurred_tex = if size < 0.25 { + let blurred_tex = if max_size < 0.25 { glow_src } else if down > 1 { let small = self.alloc_tex(work_size, src.depth, 0); @@ -277,12 +299,12 @@ impl Engine { self.dispatch_op(enc, ShaderOp::DisplayBlit, &glow_src.view, &self.dummy.view, &self.dummy.view, &small, &u_blit); let mut uh = UniformParams::default(); - uh.p[0] = [1.0, 0.0, size / down as f32, 0.0]; + uh.p[0] = [1.0, 0.0, size_x / down as f32, 0.0]; uh.p[1] = [1.0, 0.0, 0.0, 1.0]; self.dispatch_op(enc, ShaderOp::Blur, &small.view, &self.dummy.view, &self.dummy.view, &tmp1, &uh); let mut uv = UniformParams::default(); - uv.p[0] = [0.0, 1.0, size / down as f32, 0.0]; + uv.p[0] = [0.0, 1.0, size_y / down as f32, 0.0]; uv.p[1] = [1.0, 0.0, 0.0, 1.0]; self.dispatch_op(enc, ShaderOp::Blur, &tmp1.view, &self.dummy.view, &self.dummy.view, &tmp2, &uv); self.dispatch_op(enc, ShaderOp::DisplayBlit, &tmp2.view, &self.dummy.view, &self.dummy.view, &upscaled, &u_blit); @@ -291,12 +313,12 @@ impl Engine { let tmp1 = self.alloc_tex(src.size, src.depth, 0); let tmp2 = self.alloc_tex(src.size, src.depth, 0); let mut uh = UniformParams::default(); - uh.p[0] = [1.0, 0.0, size, 0.0]; + uh.p[0] = [1.0, 0.0, size_x, 0.0]; uh.p[1] = [1.0, 0.0, 0.0, 1.0]; self.dispatch_op(enc, ShaderOp::Blur, &glow_src.view, &self.dummy.view, &self.dummy.view, &tmp1, &uh); let mut uv = UniformParams::default(); - uv.p[0] = [0.0, 1.0, size, 0.0]; + uv.p[0] = [0.0, 1.0, size_y, 0.0]; uv.p[1] = [1.0, 0.0, 0.0, 1.0]; self.dispatch_op(enc, ShaderOp::Blur, &tmp1.view, &self.dummy.view, &self.dummy.view, &tmp2, &uv); tmp2 @@ -862,3 +884,86 @@ impl Engine { } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::Engine; + + #[test] + fn glow_reads_xglow_size_and_falls_back_to_glow_size() { + let src = r#"Composition { + CurrentTime = 0, + RenderRange = { 0, 1 }, + GlobalRange = { 0, 1 }, + Tools = ordered() { + BG = Background { + Inputs = { + Width = Input { Value = 128, }, + Height = Input { Value = 128, }, + TopLeftRed = Input { Value = 0.0, }, + TopLeftAlpha = Input { Value = 1.0, }, + }, + }, + Rect = RectangleMask { + Inputs = { + Width = Input { Value = 0.1, }, + Height = Input { Value = 0.1, }, + }, + }, + White = Background { + Inputs = { + Width = Input { Value = 128, }, + Height = Input { Value = 128, }, + TopLeftRed = Input { Value = 1.0, }, + TopLeftGreen = Input { Value = 1.0, }, + TopLeftBlue = Input { Value = 1.0, }, + TopLeftAlpha = Input { Value = 1.0, }, + EffectMask = Input { SourceOp = "Rect", Source = "Mask", }, + }, + }, + M = Merge { + Inputs = { + Background = Input { SourceOp = "BG", Source = "Output", }, + Foreground = Input { SourceOp = "White", Source = "Output", }, + }, + }, + GlowX = Glow { + Inputs = { + XGlowSize = Input { Value = 60.0, }, + Glow = Input { Value = 0.6, }, + Input = Input { SourceOp = "M", Source = "Output", }, + }, + }, + GlowLegacy = Glow { + Inputs = { + GlowSize = Input { Value = 60.0, }, + Glow = Input { Value = 0.6, }, + Input = Input { SourceOp = "M", Source = "Output", }, + }, + }, + GlowDefault = Glow { + Inputs = { + Glow = Input { Value = 0.6, }, + Input = Input { SourceOp = "M", Source = "Output", }, + }, + }, + }, + }"#; + let comp = Comp::from_fusion_str(src).expect("parse Glow comp"); + let Ok(mut eng) = Engine::new_headless() else { + return; + }; + let gx = comp.find_node("GlowX").expect("GlowX"); + let gl = comp.find_node("GlowLegacy").expect("GlowLegacy"); + let gd = comp.find_node("GlowDefault").expect("GlowDefault"); + let (tx, _) = eng.evaluate(&comp, gx, 0.0); + let (tl, _) = eng.evaluate(&comp, gl, 0.0); + let (td, _) = eng.evaluate(&comp, gd, 0.0); + let px_x = eng.readback_rgba(&tx).expect("readback GlowX"); + let px_l = eng.readback_rgba(&tl).expect("readback GlowLegacy"); + let px_d = eng.readback_rgba(&td).expect("readback GlowDefault"); + assert_eq!(px_x, px_l, "XGlowSize=60 should match GlowSize=60 identically"); + assert_ne!(px_x, px_d, "XGlowSize=60 should differ from default GlowSize=10"); + } +} diff --git a/crates/engine/src/eval/composite.rs b/crates/engine/src/eval/composite.rs index 3608d2eda7d4837c079961b3b6da4c0d47a36a0a..56c90438af39921411cc23b6a6a151025e953ccf 100644 --- a/crates/engine/src/eval/composite.rs +++ b/crates/engine/src/eval/composite.rs @@ -204,6 +204,12 @@ impl Engine { let mut dst = self.alloc_tex_dod(dst_size, dst_origin, bg.canvas_size, bg.depth.max(fg.depth), key); dst.tex_scale = bg.tex_scale; + let edges_i = edges.round() as i32; + dst.edge_mode = if edges_i == 1 || edges_i == 3 { + Some(edges_i as u8) + } else { + bg.edge_mode.or(fg.edge_mode) + }; let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); self.dispatch_op(enc, ShaderOp::Merge, &bg.view, &fg.view, mv, &dst, &u); self.cache.insert(key, dst.clone(), node.id, frame_i); diff --git a/crates/engine/src/eval/io.rs b/crates/engine/src/eval/io.rs index c260e86744cad573b553e4fbaa76913b54c2e62c..d9eccd7a43297ac4b6d4485c4b938f309bbb30ce 100644 --- a/crates/engine/src/eval/io.rs +++ b/crates/engine/src/eval/io.rs @@ -1,6 +1,45 @@ use super::*; impl Engine { + fn probe_clip_dims(clip: &model::ClipSpec) -> Option<[u32; 2]> { + use std::path::PathBuf; + use std::sync::{Mutex, OnceLock}; + static DIMS_CACHE: OnceLock>>> = OnceLock::new(); + let base = PathBuf::from(&clip.filename); + let cache = DIMS_CACHE.get_or_init(|| Mutex::new(HashMap::new())); + if let Ok(guard) = cache.lock() { + if let Some(&cached) = guard.get(&base) { + return cached; + } + } + let dims = if !base.exists() { + None + } else { + let ext = base + .extension() + .and_then(|e| e.to_str()) + .map(|e| e.to_ascii_lowercase()); + if matches!( + ext.as_deref(), + Some("mov" | "mp4" | "m4v" | "mkv" | "avi" | "webm" | "mxf") + ) { + crate::media::open_video_decoder(&base).and_then(|dec| { + let info = dec.info(); + (info.width > 0 && info.height > 0).then_some([info.width, info.height]) + }) + } else { + image::image_dimensions(&base) + .ok() + .filter(|&(w, h)| w > 0 && h > 0) + .map(|(w, h)| [w, h]) + } + }; + if let Ok(mut guard) = cache.lock() { + guard.insert(base, dims); + } + dims + } + pub(super) fn eval_loader( &mut self, comp: &Comp, @@ -44,10 +83,55 @@ impl Engine { } else { std::borrow::Cow::Borrowed(clip) }; - let Some((resolved, local_idx, img, loaded_from_disk)) = - self.media.load_clip(&effective_clip, frame_i, post_mult, exr_channels) - else { - return self.dummy.clone(); + let missing_frames = comp + .eval_number(node, "MissingFrames", time, 0.0, &self.expr) + .round() as i32; + let out_of_range_missing = missing_frames == 1 + && !effective_clip.loop_clip + && effective_clip.global_end >= effective_clip.global_start + && (effective_clip.length.unwrap_or(0) > 1 + || effective_clip.global_end > effective_clip.global_start) + && (frame_i < effective_clip.global_start - effective_clip.extend_first.max(0) + || frame_i > effective_clip.global_end + effective_clip.extend_last.max(0)); + let loaded = if out_of_range_missing { + None + } else { + self.media + .load_clip(&effective_clip, frame_i, post_mult, exr_channels) + }; + let Some((resolved, local_idx, img, loaded_from_disk)) = loaded else { + if missing_frames != 1 { + return self.dummy.clone(); + } + // When out-of-range or missing with `MissingFrames = 1` (Output Color), return a + // full-resolution transparent [0,0,0,0] canvas instead of 1x1 dummy so downstream + // Merges preserve full canvas dimensions and keep foreground layers intact. + let dst_depth = self.node_depth(comp, node, time, None); + let mut kh = DefaultHasher::new(); + self.cache.gpu_salt.hash(&mut kh); + self.hiq.hash(&mut kh); + self.cache.node_salt(node.id).hash(&mut kh); + "LoaderMissing".hash(&mut kh); + effective_clip.filename.hash(&mut kh); + self.proxy_scale.hash(&mut kh); + comp.width.hash(&mut kh); + comp.height.hash(&mut kh); + dst_depth.hash(&mut kh); + let key = kh.finish(); + if let Some(hit) = self.cache.get(key, node.id, frame_i) { + stats.cache_hits += 1; + return hit; + } + stats.cache_misses += 1; + stats.nodes_evaluated += 1; + let raw_dims = Self::probe_clip_dims(&effective_clip) + .unwrap_or([comp.width, comp.height]); + let dst_size = self.scaled_dims(raw_dims[0], raw_dims[1]); + let dst = self.alloc_tex(dst_size, dst_depth, key); + let u = UniformParams::default(); + self.dispatch_op(enc, ShaderOp::Bg, &self.dummy.view, &self.dummy.view, &self.dummy.view, &dst, &u); + self.cache.insert(key, dst.clone(), node.id, frame_i); + return dst; }; if loaded_from_disk { stats.source_loads += 1; @@ -947,4 +1031,88 @@ Composition { } assert!(engine.cache.eviction_count() >= 1); } + + #[test] + fn loader_out_of_range_missing_frames_1_outputs_full_transparent_canvas() { + let dir = std::env::temp_dir().join("fission_loader_missing_frames_test"); + let _ = std::fs::create_dir_all(&dir); + let missing_clip = dir.join("does_not_exist.mov"); + let existing_png = dir.join("frame_0001.png"); + write_solid_png(&existing_png, 64, 32, [200, 100, 50, 255]); + + let comp_src = format!( + r#" +Composition {{ + CurrentTime = 20, + RenderRange = {{ 0, 30 }}, + GlobalRange = {{ 0, 30 }}, + Prefs = {{ + Comp = {{ + FrameFormat = {{ Width = 320, Height = 180, }}, + }}, + }}, + Tools = ordered() {{ + LD_Missing = Loader {{ + Clips = {{ + Clip {{ + ID = "Clip1", + Filename = "{}", + FormatID = "QuickTimeMovies", + Length = 10, + Loop = 0, + GlobalStart = 0, + GlobalEnd = 9, + }} + }}, + Inputs = {{ + MissingFrames = Input {{ Value = 1, }}, + }}, + }}, + LD_Seq = Loader {{ + Clips = {{ + Clip {{ + ID = "Clip1", + Filename = "{}", + FormatID = "PNGFormat", + StartFrame = 1, + Length = 10, + Loop = 0, + GlobalStart = 0, + GlobalEnd = 9, + }} + }}, + Inputs = {{ + MissingFrames = Input {{ Value = 1, }}, + }}, + }}, + }}, +}} +"#, + missing_clip.display(), + existing_png.display(), + ); + let comp = Comp::from_fusion_str(&comp_src).expect("parse"); + let ld_missing = comp.find_node("LD_Missing").expect("LD_Missing"); + let ld_seq = comp.find_node("LD_Seq").expect("LD_Seq"); + + let mut engine = Engine::new_headless().expect("gpu"); + // Missing file with MissingFrames=1 falls back to comp dimensions (320x180), transparent [0,0,0,0]. + let (tex, _) = engine.evaluate(&comp, ld_missing, 20.0); + assert_eq!(tex.size, [320, 180]); + let rgba = engine.readback_rgba(&tex).expect("readback"); + assert!(rgba.iter().all(|&b| b == 0), "expected fully transparent canvas"); + + // Out-of-range sequence with MissingFrames=1 uses native clip dims (64x32), transparent [0,0,0,0]. + let (tex_seq, _) = engine.evaluate(&comp, ld_seq, 20.0); + assert_eq!(tex_seq.size, [64, 32]); + let rgba_seq = engine.readback_rgba(&tex_seq).expect("readback"); + assert!(rgba_seq.iter().all(|&b| b == 0), "expected transparent out-of-range sequence frame"); + + // Verify proxy_scale is honored on the fallback canvas. + engine.proxy_scale = 2; + let (tex_half, _) = engine.evaluate(&comp, ld_missing, 20.0); + assert_eq!(tex_half.size, [160, 90]); + + let _ = std::fs::remove_dir_all(&dir); + } } diff --git a/crates/engine/src/eval/transform.rs b/crates/engine/src/eval/transform.rs index 0911793d19efef9dfb920a422dbb3888c53cd7b6..d6779101634455ffa640977cf294fa0f179b3e70 100644 --- a/crates/engine/src/eval/transform.rs +++ b/crates/engine/src/eval/transform.rs @@ -1,5 +1,125 @@ use super::*; +/// Returns `true` if `start_id` traces back through point/passthrough ops to a `Background` generator +/// (whose Fusion RoI extends uniformly beyond the canvas boundary). +fn is_background_chain(comp: &Comp, start_id: NodeId, depth: usize) -> bool { + let mut cur = start_id; + for _ in 0..depth { + let n = comp.node(cur); + if n.kind == "Background" { + return true; + } + let next_port = if n.bypassed { + default_main_input_port(&n.kind) + } else { + match n.kind.as_str() { + "ColorCorrector" + | "ColorCurves" + | "BrightnessContrast" + | "ColorGain" + | "InvertColor" + | "GamutConvert" + | "HueCurves" + | "ChangeDepth" + | "PipeRouter" + | "Fuse.Wireless" + | "Tracker" => "Input", + _ => return false, + } + }; + let Some(next_id) = n.connected_node(next_port).and_then(|s| comp.find_node(s)) else { + return false; + }; + cur = next_id; + } + false +} + +/// Walks upstream from `start_id` through point/passthrough ops (and Merges over solid Backgrounds +/// or disabled Blurs) to detect an infinite Wrap (`1.0`) or Mirror (`3.0`) RoI edge mode produced +/// by an upstream `Merge`. +pub(super) fn upstream_infinite_edge_mode( + comp: &Comp, + start_id: NodeId, + time: f64, + expr: &ExprEngine, +) -> Option { + fn walk(comp: &Comp, id: NodeId, time: f64, expr: &ExprEngine, depth: usize) -> Option { + if depth == 0 { + return None; + } + let n = comp.node(id); + if n.bypassed { + let port = default_main_input_port(&n.kind); + let prev = n.connected_node(port).and_then(|s| comp.find_node(s))?; + return walk(comp, prev, time, expr, depth - 1); + } + match n.kind.as_str() { + "Merge" => { + let blend = comp.eval_number(n, "Blend", time, 1.0, expr); + let bg_id = n.connected_node("Background").and_then(|s| comp.find_node(s)); + if blend <= 1e-6 { + return bg_id.and_then(|bid| walk(comp, bid, time, expr, depth - 1)); + } + let e = comp.eval_number(n, "Edges", time, 0.0, expr).round() as i32; + if e == 1 || e == 3 { + return Some(e as f32); + } + if e == 0 { + if let Some(bid) = bg_id { + if let Some(m) = walk(comp, bid, time, expr, depth - 1) { + return Some(m); + } + if is_background_chain(comp, bid, depth - 1) { + if let Some(fid) = n.connected_node("Foreground").and_then(|s| comp.find_node(s)) { + return walk(comp, fid, time, expr, depth - 1); + } + } + } + } + None + } + "ColorCorrector" + | "ColorCurves" + | "BrightnessContrast" + | "ColorGain" + | "InvertColor" + | "GamutConvert" + | "HueCurves" + | "ChangeDepth" + | "PipeRouter" + | "Fuse.Wireless" + | "Tracker" + | "Dimension.OpticalFlow" + | "OpticalFlow" => { + let prev = n.connected_node("Input").and_then(|s| comp.find_node(s))?; + walk(comp, prev, time, expr, depth - 1) + } + "DirectionalBlur" | "Blur" | "Glow" | "SoftGlow" | "Sharpen" | "Filter" | "VariBlur" | "ErodeDilate" => { + if comp.eval_number(n, "Blend", time, 1.0, expr) <= 1e-4 { + let prev = n.connected_node("Input").and_then(|s| comp.find_node(s))?; + walk(comp, prev, time, expr, depth - 1) + } else { + None + } + } + "MacroOperator" | "GroupOperator" => { + if let Some(out_id) = n.macro_output { + walk(comp, out_id, time, expr, depth - 1) + } else { + let prev = n + .connected_node("Input") + .or_else(|| n.connected_node("MainInput1")) + .and_then(|s| comp.find_node(s))?; + walk(comp, prev, time, expr, depth - 1) + } + } + _ => None, + } + } + walk(comp, start_id, time, expr, 24) +} + impl Engine { pub(super) fn eval_transform( &mut self, @@ -33,7 +153,16 @@ impl Engine { (s, s * asp) }; let angle = (comp.eval_number(node, "Angle", time, 0.0, &self.expr) as f32).to_radians(); - let edges = comp.eval_number(node, "Edges", time, 0.0, &self.expr) as f32; + let mut edges = comp.eval_number(node, "Edges", time, 0.0, &self.expr) as f32; + if edges.round() as i32 == 0 || edges.round() as i32 == 2 { + if let Some(up_edges) = src + .edge_mode + .map(f32::from) + .or_else(|| upstream_infinite_edge_mode(comp, src_id, time, &self.expr)) + { + edges = up_edges; + } + } let flip_h = comp.eval_number(node, "FlipHoriz", time, 0.0, &self.expr) as f32; let flip_v = comp.eval_number(node, "FlipVert", time, 0.0, &self.expr) as f32; let nearest = if comp.eval_number(node, "FilterMethod", time, 2.0, &self.expr) < 0.5 { 1.0 } else { 0.0 }; @@ -614,4 +743,131 @@ mod tests { assert!(diff <= 2, "KScope 6-slice mirror symmetry mismatch ch={c}: {a:?} vs {b:?}"); } } + + #[test] + fn test_upstream_infinite_edge_mode_propagates_through_point_ops_and_disabled_dirblur() { + let src = r#"Composition { + CurrentTime = 3050, + RenderRange = { 3000, 3100 }, + GlobalRange = { 3000, 3100 }, + Tools = ordered() { + BG1 = Background { + Inputs = { + Width = Input { Value = 64, }, + Height = Input { Value = 64, }, + TopLeftRed = Input { Value = 0.2, }, + TopLeftAlpha = Input { Value = 1.0, }, + }, + }, + FG1 = Background { + Inputs = { + Width = Input { Value = 64, }, + Height = Input { Value = 64, }, + Type = Input { Value = FuID { "Horizontal" }, }, + TopLeftRed = Input { Value = 1.0, }, + TopLeftGreen = Input { Value = 0.0, }, + TopLeftBlue = Input { Value = 0.0, }, + TopRightRed = Input { Value = 0.0, }, + TopRightGreen = Input { Value = 0.0, }, + TopRightBlue = Input { Value = 1.0, }, + }, + }, + Merge23 = Merge { + Inputs = { + Background = Input { SourceOp = "BG1", Source = "Output", }, + Foreground = Input { SourceOp = "FG1", Source = "Output", }, + Edges = Input { Value = 3, }, + }, + }, + CC1 = ColorCorrector { + Inputs = { + Input = Input { SourceOp = "Merge23", Source = "Output", }, + }, + }, + BG2 = Background { + Inputs = { + Width = Input { Value = 64, }, + Height = Input { Value = 64, }, + TopLeftAlpha = Input { Value = 1.0, }, + }, + }, + CC_BG = ColorCorrector { + Inputs = { + Input = Input { SourceOp = "BG2", Source = "Output", }, + }, + }, + Merge24 = Merge { + Inputs = { + Background = Input { SourceOp = "CC_BG", Source = "Output", }, + Foreground = Input { SourceOp = "CC1", Source = "Output", }, + }, + }, + Infrared = ColorCurves { + Inputs = { + Input = Input { SourceOp = "Merge24", Source = "Output", }, + }, + }, + CC2 = ColorCorrector { + Inputs = { + Input = Input { SourceOp = "Infrared", Source = "Output", }, + }, + }, + DirBlur = DirectionalBlur { + Inputs = { + Blend = Input { Value = 0.0, }, + Length = Input { Value = 0.05, }, + Input = Input { SourceOp = "CC2", Source = "Output", }, + }, + }, + DirBlurActive = DirectionalBlur { + Inputs = { + Blend = Input { Value = 1.0, }, + Length = Input { Value = 0.05, }, + Input = Input { SourceOp = "CC2", Source = "Output", }, + }, + }, + XF = Transform { + Inputs = { + Center = Input { Value = { 0.75, 0.5 }, }, + Edges = Input { Value = 2, }, + Input = Input { SourceOp = "DirBlur", Source = "Output", }, + }, + }, + }, + }"#; + let comp = Comp::from_fusion_str(src).expect("parse mirror propagation comp"); + let expr = ExprEngine::new(); + let dir_blur_id = comp.find_node("DirBlur").expect("DirBlur"); + let dir_blur_active_id = comp.find_node("DirBlurActive").expect("DirBlurActive"); + assert_eq!( + upstream_infinite_edge_mode(&comp, dir_blur_id, 3050.0, &expr), + Some(3.0), + "Merge(Edges=3) should propagate through point ops, Merge(BG=CC(Background)), and DirectionalBlur(Blend=0)" + ); + assert_eq!( + upstream_infinite_edge_mode(&comp, dir_blur_active_id, 3050.0, &expr), + None, + "Active DirectionalBlur (Blend=1) should stop RoI edge-mode propagation" + ); + + let Ok(mut eng) = Engine::new_headless() else { + return; + }; + let xf_id = comp.find_node("XF").expect("XF"); + let (tex, _) = eng.evaluate(&comp, xf_id, 3050.0); + let rgba = eng.readback_rgba(&tex).expect("readback XF"); + // Center.x = 0.75 shifts image right by 16px: x=0..16 samples mirrored x=16..0 + // rather than duplicating x=0! On a red->blue gradient, x=2 should be noticeably + // bluer than x=15 (which sits right next to the red left edge). + let px = |x: usize| -> [u8; 4] { + let i = (32 * 64 + x) * 4; + [rgba[i], rgba[i + 1], rgba[i + 2], rgba[i + 3]] + }; + let far_left = px(2); + let seam = px(15); + assert!( + far_left[2] > seam[2] + 20, + "expected mirrored left edge (far_left={far_left:?} bluer than seam={seam:?}), not Duplicate streak" + ); + } }