authoravatarclover caruso<git@paperclover.net>2026-11-30 14:42:49-08:00
committeravatarclover caruso<git@paperclover.net>2026-11-30 14:55:21-08:00
log391b31560989f450dbabe5908e990bc0732aa870
tree06924767191919a85629d9903d715c2e6d00b8ff
parent0f4304f00f855af055d98da5759c54607d86d905
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Fix Loader MissingFrames=1 canvas size, Glow XGlowSize, and Merge Mirror RoI propagation (#17)


5 files changed, 556 insertions(+), 18 deletions(-)

crates/engine/src/cache.rs+3
...@@ -29,6 +29,8 @@ pub struct CachedTexture {...@@ -29,6 +29,8 @@ pub struct CachedTexture {
29 pub format: wgpu::TextureFormat,29 pub format: wgpu::TextureFormat,
30 /// Scale ratio `physical_px / logical_px` when an oversized generator (>8K) is capped to GPU limits (1.0 normally).30 /// Scale ratio `physical_px / logical_px` when an oversized generator (>8K) is capped to GPU limits (1.0 normally).
31 pub tex_scale: f32,31 pub tex_scale: f32,
32 /// Infinite RoI edge mode propagated from upstream `Merge` (`Some(1)` = Wrap, `Some(3)` = Mirror).
33 pub edge_mode: Option<u8>,
32 pub content_hash: u64,34 pub content_hash: u64,
33 pub bytes: u64,35 pub bytes: u64,
34}36}
...@@ -79,6 +81,7 @@ impl CachedTexture {...@@ -79,6 +81,7 @@ impl CachedTexture {
79 depth,81 depth,
80 format,82 format,
81 tex_scale: 1.0,83 tex_scale: 1.0,
84 edge_mode: None,
82 content_hash,85 content_hash,
83 bytes,86 bytes,
84 }87 }
crates/engine/src/eval/blur_glow.rs+118-13
...@@ -211,18 +211,40 @@ impl Engine {...@@ -211,18 +211,40 @@ impl Engine {
211 } else {211 } else {
212 src.size[0] as f32 / 720.0 * 0.86212 src.size[0] as f32 / 720.0 * 0.86
213 };213 };
214 let (raw_size, gain, thresh, combine_mode) = if is_soft_glow {214 let lock_xy = comp.eval_number(
215 let sz = comp.eval_number(node, "XGlowSize", time, 10.0, &self.expr) as f32;215 node,
216 "LockGlowSize",
217 time,
218 comp.eval_number(node, "LockXY", time, 1.0, &self.expr),
219 &self.expr,
220 ) > 0.5;
221 let (raw_size_x, raw_size_y, gain, thresh, combine_mode) = if is_soft_glow {
222 let sx = comp.eval_number(node, "XGlowSize", time, 10.0, &self.expr) as f32;
223 let sy = if lock_xy {
224 sx
225 } else {
226 comp.eval_number(node, "YGlowSize", time, sx as f64, &self.expr) as f32
227 };
216 let g = comp.eval_number(node, "Gain", time, 2.0, &self.expr) as f32;228 let g = comp.eval_number(node, "Gain", time, 2.0, &self.expr) as f32;
217 let th = comp.eval_number(node, "Threshold", time, 0.0, &self.expr).clamp(0.0, 0.999) as f32;229 let th = comp.eval_number(node, "Threshold", time, 0.0, &self.expr).clamp(0.0, 0.999) as f32;
218 (sz, g, th, 0.0f32) // Screen blend230 (sx, sy, g, th, 0.0f32) // Screen blend
219 } else {231 } else {
220 let sz = comp.eval_number(node, "GlowSize", time, 10.0, &self.expr) as f32;232 // Fusion 21.1 Glow writes `XGlowSize` (and `YGlowSize` when `LockGlowSize == 0`),
233 // while older comps/probes may write `GlowSize`. Prefer `XGlowSize`, else `GlowSize`, else 10.0.
234 let glow_fallback = comp.eval_number(node, "GlowSize", time, 10.0, &self.expr);
235 let sx = comp.eval_number(node, "XGlowSize", time, glow_fallback, &self.expr) as f32;
236 let sy = if lock_xy {
237 sx
238 } else {
239 comp.eval_number(node, "YGlowSize", time, sx as f64, &self.expr) as f32
240 };
221 let glow_p = comp.eval_number(node, "Glow", time, 0.8, &self.expr).clamp(0.0, 0.999) as f32;241 let glow_p = comp.eval_number(node, "Glow", time, 0.8, &self.expr).clamp(0.0, 0.999) as f32;
222 let g = 1.0 / (1.0 - glow_p).max(1e-3);242 let g = 1.0 / (1.0 - glow_p).max(1e-3);
223 (sz, g, 0.0f32, 1.0f32) // Replace with blurred / (1 - Glow)243 (sx, sy, g, 0.0f32, 1.0f32) // Replace with blurred / (1 - Glow)
224 };244 };
225 let size = (raw_size * scale_ref).max(0.0);245 let size_x = (raw_size_x * scale_ref).max(0.0);
246 let size_y = (raw_size_y * scale_ref).max(0.0);
247 let max_size = size_x.max(size_y);
226 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats);248 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats);
227 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);249 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);
228 let prev_sz = self.mask_target_size;250 let prev_sz = self.mask_target_size;
...@@ -239,7 +261,7 @@ impl Engine {...@@ -239,7 +261,7 @@ impl Engine {
239 if is_soft_glow { "SoftGlow" } else { "Glow" },261 if is_soft_glow { "SoftGlow" } else { "Glow" },
240 src.size,262 src.size,
241 &[src.content_hash, mask_hash, gm_hash],263 &[src.content_hash, mask_hash, gm_hash],
242 &[size, gain, thresh, blend, combine_mode, if mask_inv { 1.0 } else { 0.0 }],264 &[size_x, size_y, gain, thresh, blend, combine_mode, if mask_inv { 1.0 } else { 0.0 }],
243 );265 );
244 if let Some(hit) = self.cache.get(key, node.id, frame_i) {266 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
245 stats.cache_hits += 1;267 stats.cache_hits += 1;
...@@ -262,10 +284,10 @@ impl Engine {...@@ -262,10 +284,10 @@ impl Engine {
262 };284 };
263285
264 let dst = self.alloc_tex_dod(src.size, src.origin, src.canvas_size, src.depth, key);286 let dst = self.alloc_tex_dod(src.size, src.origin, src.canvas_size, src.depth, key);
265 let down = if self.hiq { 1u32 } else if size >= 14.0 { 4u32 } else if size >= 4.0 { 2u32 } else { 1u32 };287 let down = if self.hiq { 1u32 } else if max_size >= 14.0 { 4u32 } else if max_size >= 4.0 { 2u32 } else { 1u32 };
266 let work_size = [(src.size[0] / down).max(1), (src.size[1] / down).max(1)];288 let work_size = [(src.size[0] / down).max(1), (src.size[1] / down).max(1)];
267289
268 let blurred_tex = if size < 0.25 {290 let blurred_tex = if max_size < 0.25 {
269 glow_src291 glow_src
270 } else if down > 1 {292 } else if down > 1 {
271 let small = self.alloc_tex(work_size, src.depth, 0);293 let small = self.alloc_tex(work_size, src.depth, 0);
...@@ -277,12 +299,12 @@ impl Engine {...@@ -277,12 +299,12 @@ impl Engine {
277 self.dispatch_op(enc, ShaderOp::DisplayBlit, &glow_src.view, &self.dummy.view, &self.dummy.view, &small, &u_blit);299 self.dispatch_op(enc, ShaderOp::DisplayBlit, &glow_src.view, &self.dummy.view, &self.dummy.view, &small, &u_blit);
278300
279 let mut uh = UniformParams::default();301 let mut uh = UniformParams::default();
280 uh.p[0] = [1.0, 0.0, size / down as f32, 0.0];302 uh.p[0] = [1.0, 0.0, size_x / down as f32, 0.0];
281 uh.p[1] = [1.0, 0.0, 0.0, 1.0];303 uh.p[1] = [1.0, 0.0, 0.0, 1.0];
282 self.dispatch_op(enc, ShaderOp::Blur, &small.view, &self.dummy.view, &self.dummy.view, &tmp1, &uh);304 self.dispatch_op(enc, ShaderOp::Blur, &small.view, &self.dummy.view, &self.dummy.view, &tmp1, &uh);
283305
284 let mut uv = UniformParams::default();306 let mut uv = UniformParams::default();
285 uv.p[0] = [0.0, 1.0, size / down as f32, 0.0];307 uv.p[0] = [0.0, 1.0, size_y / down as f32, 0.0];
286 uv.p[1] = [1.0, 0.0, 0.0, 1.0];308 uv.p[1] = [1.0, 0.0, 0.0, 1.0];
287 self.dispatch_op(enc, ShaderOp::Blur, &tmp1.view, &self.dummy.view, &self.dummy.view, &tmp2, &uv);309 self.dispatch_op(enc, ShaderOp::Blur, &tmp1.view, &self.dummy.view, &self.dummy.view, &tmp2, &uv);
288 self.dispatch_op(enc, ShaderOp::DisplayBlit, &tmp2.view, &self.dummy.view, &self.dummy.view, &upscaled, &u_blit);310 self.dispatch_op(enc, ShaderOp::DisplayBlit, &tmp2.view, &self.dummy.view, &self.dummy.view, &upscaled, &u_blit);
...@@ -291,12 +313,12 @@ impl Engine {...@@ -291,12 +313,12 @@ impl Engine {
291 let tmp1 = self.alloc_tex(src.size, src.depth, 0);313 let tmp1 = self.alloc_tex(src.size, src.depth, 0);
292 let tmp2 = self.alloc_tex(src.size, src.depth, 0);314 let tmp2 = self.alloc_tex(src.size, src.depth, 0);
293 let mut uh = UniformParams::default();315 let mut uh = UniformParams::default();
294 uh.p[0] = [1.0, 0.0, size, 0.0];316 uh.p[0] = [1.0, 0.0, size_x, 0.0];
295 uh.p[1] = [1.0, 0.0, 0.0, 1.0];317 uh.p[1] = [1.0, 0.0, 0.0, 1.0];
296 self.dispatch_op(enc, ShaderOp::Blur, &glow_src.view, &self.dummy.view, &self.dummy.view, &tmp1, &uh);318 self.dispatch_op(enc, ShaderOp::Blur, &glow_src.view, &self.dummy.view, &self.dummy.view, &tmp1, &uh);
297319
298 let mut uv = UniformParams::default();320 let mut uv = UniformParams::default();
299 uv.p[0] = [0.0, 1.0, size, 0.0];321 uv.p[0] = [0.0, 1.0, size_y, 0.0];
300 uv.p[1] = [1.0, 0.0, 0.0, 1.0];322 uv.p[1] = [1.0, 0.0, 0.0, 1.0];
301 self.dispatch_op(enc, ShaderOp::Blur, &tmp1.view, &self.dummy.view, &self.dummy.view, &tmp2, &uv);323 self.dispatch_op(enc, ShaderOp::Blur, &tmp1.view, &self.dummy.view, &self.dummy.view, &tmp2, &uv);
302 tmp2324 tmp2
...@@ -862,3 +884,86 @@ impl Engine {...@@ -862,3 +884,86 @@ impl Engine {
862 }884 }
863885
864}886}
887
888#[cfg(test)]
889mod tests {
890 use super::*;
891 use crate::Engine;
892
893 #[test]
894 fn glow_reads_xglow_size_and_falls_back_to_glow_size() {
895 let src = r#"Composition {
896 CurrentTime = 0,
897 RenderRange = { 0, 1 },
898 GlobalRange = { 0, 1 },
899 Tools = ordered() {
900 BG = Background {
901 Inputs = {
902 Width = Input { Value = 128, },
903 Height = Input { Value = 128, },
904 TopLeftRed = Input { Value = 0.0, },
905 TopLeftAlpha = Input { Value = 1.0, },
906 },
907 },
908 Rect = RectangleMask {
909 Inputs = {
910 Width = Input { Value = 0.1, },
911 Height = Input { Value = 0.1, },
912 },
913 },
914 White = Background {
915 Inputs = {
916 Width = Input { Value = 128, },
917 Height = Input { Value = 128, },
918 TopLeftRed = Input { Value = 1.0, },
919 TopLeftGreen = Input { Value = 1.0, },
920 TopLeftBlue = Input { Value = 1.0, },
921 TopLeftAlpha = Input { Value = 1.0, },
922 EffectMask = Input { SourceOp = "Rect", Source = "Mask", },
923 },
924 },
925 M = Merge {
926 Inputs = {
927 Background = Input { SourceOp = "BG", Source = "Output", },
928 Foreground = Input { SourceOp = "White", Source = "Output", },
929 },
930 },
931 GlowX = Glow {
932 Inputs = {
933 XGlowSize = Input { Value = 60.0, },
934 Glow = Input { Value = 0.6, },
935 Input = Input { SourceOp = "M", Source = "Output", },
936 },
937 },
938 GlowLegacy = Glow {
939 Inputs = {
940 GlowSize = Input { Value = 60.0, },
941 Glow = Input { Value = 0.6, },
942 Input = Input { SourceOp = "M", Source = "Output", },
943 },
944 },
945 GlowDefault = Glow {
946 Inputs = {
947 Glow = Input { Value = 0.6, },
948 Input = Input { SourceOp = "M", Source = "Output", },
949 },
950 },
951 },
952 }"#;
953 let comp = Comp::from_fusion_str(src).expect("parse Glow comp");
954 let Ok(mut eng) = Engine::new_headless() else {
955 return;
956 };
957 let gx = comp.find_node("GlowX").expect("GlowX");
958 let gl = comp.find_node("GlowLegacy").expect("GlowLegacy");
959 let gd = comp.find_node("GlowDefault").expect("GlowDefault");
960 let (tx, _) = eng.evaluate(&comp, gx, 0.0);
961 let (tl, _) = eng.evaluate(&comp, gl, 0.0);
962 let (td, _) = eng.evaluate(&comp, gd, 0.0);
963 let px_x = eng.readback_rgba(&tx).expect("readback GlowX");
964 let px_l = eng.readback_rgba(&tl).expect("readback GlowLegacy");
965 let px_d = eng.readback_rgba(&td).expect("readback GlowDefault");
966 assert_eq!(px_x, px_l, "XGlowSize=60 should match GlowSize=60 identically");
967 assert_ne!(px_x, px_d, "XGlowSize=60 should differ from default GlowSize=10");
968 }
969}
crates/engine/src/eval/composite.rs+6
...@@ -204,6 +204,12 @@ impl Engine {...@@ -204,6 +204,12 @@ impl Engine {
204204
205 let mut dst = self.alloc_tex_dod(dst_size, dst_origin, bg.canvas_size, bg.depth.max(fg.depth), key);205 let mut dst = self.alloc_tex_dod(dst_size, dst_origin, bg.canvas_size, bg.depth.max(fg.depth), key);
206 dst.tex_scale = bg.tex_scale;206 dst.tex_scale = bg.tex_scale;
207 let edges_i = edges.round() as i32;
208 dst.edge_mode = if edges_i == 1 || edges_i == 3 {
209 Some(edges_i as u8)
210 } else {
211 bg.edge_mode.or(fg.edge_mode)
212 };
207 let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view);213 let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view);
208 self.dispatch_op(enc, ShaderOp::Merge, &bg.view, &fg.view, mv, &dst, &u);214 self.dispatch_op(enc, ShaderOp::Merge, &bg.view, &fg.view, mv, &dst, &u);
209 self.cache.insert(key, dst.clone(), node.id, frame_i);215 self.cache.insert(key, dst.clone(), node.id, frame_i);
crates/engine/src/eval/io.rs+172-4
...@@ -1,6 +1,45 @@...@@ -1,6 +1,45 @@
1use super::*;1use super::*;
22
3impl Engine {3impl Engine {
4 fn probe_clip_dims(clip: &model::ClipSpec) -> Option<[u32; 2]> {
5 use std::path::PathBuf;
6 use std::sync::{Mutex, OnceLock};
7 static DIMS_CACHE: OnceLock<Mutex<HashMap<PathBuf, Option<[u32; 2]>>>> = OnceLock::new();
8 let base = PathBuf::from(&clip.filename);
9 let cache = DIMS_CACHE.get_or_init(|| Mutex::new(HashMap::new()));
10 if let Ok(guard) = cache.lock() {
11 if let Some(&cached) = guard.get(&base) {
12 return cached;
13 }
14 }
15 let dims = if !base.exists() {
16 None
17 } else {
18 let ext = base
19 .extension()
20 .and_then(|e| e.to_str())
21 .map(|e| e.to_ascii_lowercase());
22 if matches!(
23 ext.as_deref(),
24 Some("mov" | "mp4" | "m4v" | "mkv" | "avi" | "webm" | "mxf")
25 ) {
26 crate::media::open_video_decoder(&base).and_then(|dec| {
27 let info = dec.info();
28 (info.width > 0 && info.height > 0).then_some([info.width, info.height])
29 })
30 } else {
31 image::image_dimensions(&base)
32 .ok()
33 .filter(|&(w, h)| w > 0 && h > 0)
34 .map(|(w, h)| [w, h])
35 }
36 };
37 if let Ok(mut guard) = cache.lock() {
38 guard.insert(base, dims);
39 }
40 dims
41 }
42
4 pub(super) fn eval_loader(43 pub(super) fn eval_loader(
5 &mut self,44 &mut self,
6 comp: &Comp,45 comp: &Comp,
...@@ -44,10 +83,55 @@ impl Engine {...@@ -44,10 +83,55 @@ impl Engine {
44 } else {83 } else {
45 std::borrow::Cow::Borrowed(clip)84 std::borrow::Cow::Borrowed(clip)
46 };85 };
47 let Some((resolved, local_idx, img, loaded_from_disk)) =86 let missing_frames = comp
48 self.media.load_clip(&effective_clip, frame_i, post_mult, exr_channels)87 .eval_number(node, "MissingFrames", time, 0.0, &self.expr)
49 else {88 .round() as i32;
50 return self.dummy.clone();89 let out_of_range_missing = missing_frames == 1
90 && !effective_clip.loop_clip
91 && effective_clip.global_end >= effective_clip.global_start
92 && (effective_clip.length.unwrap_or(0) > 1
93 || effective_clip.global_end > effective_clip.global_start)
94 && (frame_i < effective_clip.global_start - effective_clip.extend_first.max(0)
95 || frame_i > effective_clip.global_end + effective_clip.extend_last.max(0));
96 let loaded = if out_of_range_missing {
97 None
98 } else {
99 self.media
100 .load_clip(&effective_clip, frame_i, post_mult, exr_channels)
101 };
102 let Some((resolved, local_idx, img, loaded_from_disk)) = loaded else {
103 if missing_frames != 1 {
104 return self.dummy.clone();
105 }
106 // When out-of-range or missing with `MissingFrames = 1` (Output Color), return a
107 // full-resolution transparent [0,0,0,0] canvas instead of 1x1 dummy so downstream
108 // Merges preserve full canvas dimensions and keep foreground layers intact.
109 let dst_depth = self.node_depth(comp, node, time, None);
110 let mut kh = DefaultHasher::new();
111 self.cache.gpu_salt.hash(&mut kh);
112 self.hiq.hash(&mut kh);
113 self.cache.node_salt(node.id).hash(&mut kh);
114 "LoaderMissing".hash(&mut kh);
115 effective_clip.filename.hash(&mut kh);
116 self.proxy_scale.hash(&mut kh);
117 comp.width.hash(&mut kh);
118 comp.height.hash(&mut kh);
119 dst_depth.hash(&mut kh);
120 let key = kh.finish();
121 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
122 stats.cache_hits += 1;
123 return hit;
124 }
125 stats.cache_misses += 1;
126 stats.nodes_evaluated += 1;
127 let raw_dims = Self::probe_clip_dims(&effective_clip)
128 .unwrap_or([comp.width, comp.height]);
129 let dst_size = self.scaled_dims(raw_dims[0], raw_dims[1]);
130 let dst = self.alloc_tex(dst_size, dst_depth, key);
131 let u = UniformParams::default();
132 self.dispatch_op(enc, ShaderOp::Bg, &self.dummy.view, &self.dummy.view, &self.dummy.view, &dst, &u);
133 self.cache.insert(key, dst.clone(), node.id, frame_i);
134 return dst;
51 };135 };
52 if loaded_from_disk {136 if loaded_from_disk {
53 stats.source_loads += 1;137 stats.source_loads += 1;
...@@ -947,4 +1031,88 @@ Composition {...@@ -947,4 +1031,88 @@ Composition {
947 }1031 }
948 assert!(engine.cache.eviction_count() >= 1);1032 assert!(engine.cache.eviction_count() >= 1);
949 }1033 }
1034
1035 #[test]
1036 fn loader_out_of_range_missing_frames_1_outputs_full_transparent_canvas() {
1037 let dir = std::env::temp_dir().join("fission_loader_missing_frames_test");
1038 let _ = std::fs::create_dir_all(&dir);
1039 let missing_clip = dir.join("does_not_exist.mov");
1040 let existing_png = dir.join("frame_0001.png");
1041 write_solid_png(&existing_png, 64, 32, [200, 100, 50, 255]);
1042
1043 let comp_src = format!(
1044 r#"
1045Composition {{
1046 CurrentTime = 20,
1047 RenderRange = {{ 0, 30 }},
1048 GlobalRange = {{ 0, 30 }},
1049 Prefs = {{
1050 Comp = {{
1051 FrameFormat = {{ Width = 320, Height = 180, }},
1052 }},
1053 }},
1054 Tools = ordered() {{
1055 LD_Missing = Loader {{
1056 Clips = {{
1057 Clip {{
1058 ID = "Clip1",
1059 Filename = "{}",
1060 FormatID = "QuickTimeMovies",
1061 Length = 10,
1062 Loop = 0,
1063 GlobalStart = 0,
1064 GlobalEnd = 9,
1065 }}
1066 }},
1067 Inputs = {{
1068 MissingFrames = Input {{ Value = 1, }},
1069 }},
1070 }},
1071 LD_Seq = Loader {{
1072 Clips = {{
1073 Clip {{
1074 ID = "Clip1",
1075 Filename = "{}",
1076 FormatID = "PNGFormat",
1077 StartFrame = 1,
1078 Length = 10,
1079 Loop = 0,
1080 GlobalStart = 0,
1081 GlobalEnd = 9,
1082 }}
1083 }},
1084 Inputs = {{
1085 MissingFrames = Input {{ Value = 1, }},
1086 }},
1087 }},
1088 }},
1089}}
1090"#,
1091 missing_clip.display(),
1092 existing_png.display(),
1093 );
1094 let comp = Comp::from_fusion_str(&comp_src).expect("parse");
1095 let ld_missing = comp.find_node("LD_Missing").expect("LD_Missing");
1096 let ld_seq = comp.find_node("LD_Seq").expect("LD_Seq");
1097
1098 let mut engine = Engine::new_headless().expect("gpu");
1099 // Missing file with MissingFrames=1 falls back to comp dimensions (320x180), transparent [0,0,0,0].
1100 let (tex, _) = engine.evaluate(&comp, ld_missing, 20.0);
1101 assert_eq!(tex.size, [320, 180]);
1102 let rgba = engine.readback_rgba(&tex).expect("readback");
1103 assert!(rgba.iter().all(|&b| b == 0), "expected fully transparent canvas");
1104
1105 // Out-of-range sequence with MissingFrames=1 uses native clip dims (64x32), transparent [0,0,0,0].
1106 let (tex_seq, _) = engine.evaluate(&comp, ld_seq, 20.0);
1107 assert_eq!(tex_seq.size, [64, 32]);
1108 let rgba_seq = engine.readback_rgba(&tex_seq).expect("readback");
1109 assert!(rgba_seq.iter().all(|&b| b == 0), "expected transparent out-of-range sequence frame");
1110
1111 // Verify proxy_scale is honored on the fallback canvas.
1112 engine.proxy_scale = 2;
1113 let (tex_half, _) = engine.evaluate(&comp, ld_missing, 20.0);
1114 assert_eq!(tex_half.size, [160, 90]);
1115
1116 let _ = std::fs::remove_dir_all(&dir);
1117 }
950}1118}
crates/engine/src/eval/transform.rs+257-1
...@@ -1,5 +1,125 @@...@@ -1,5 +1,125 @@
1use super::*;1use super::*;
22
3/// Returns `true` if `start_id` traces back through point/passthrough ops to a `Background` generator
4/// (whose Fusion RoI extends uniformly beyond the canvas boundary).
5fn is_background_chain(comp: &Comp, start_id: NodeId, depth: usize) -> bool {
6 let mut cur = start_id;
7 for _ in 0..depth {
8 let n = comp.node(cur);
9 if n.kind == "Background" {
10 return true;
11 }
12 let next_port = if n.bypassed {
13 default_main_input_port(&n.kind)
14 } else {
15 match n.kind.as_str() {
16 "ColorCorrector"
17 | "ColorCurves"
18 | "BrightnessContrast"
19 | "ColorGain"
20 | "InvertColor"
21 | "GamutConvert"
22 | "HueCurves"
23 | "ChangeDepth"
24 | "PipeRouter"
25 | "Fuse.Wireless"
26 | "Tracker" => "Input",
27 _ => return false,
28 }
29 };
30 let Some(next_id) = n.connected_node(next_port).and_then(|s| comp.find_node(s)) else {
31 return false;
32 };
33 cur = next_id;
34 }
35 false
36}
37
38/// Walks upstream from `start_id` through point/passthrough ops (and Merges over solid Backgrounds
39/// or disabled Blurs) to detect an infinite Wrap (`1.0`) or Mirror (`3.0`) RoI edge mode produced
40/// by an upstream `Merge`.
41pub(super) fn upstream_infinite_edge_mode(
42 comp: &Comp,
43 start_id: NodeId,
44 time: f64,
45 expr: &ExprEngine,
46) -> Option<f32> {
47 fn walk(comp: &Comp, id: NodeId, time: f64, expr: &ExprEngine, depth: usize) -> Option<f32> {
48 if depth == 0 {
49 return None;
50 }
51 let n = comp.node(id);
52 if n.bypassed {
53 let port = default_main_input_port(&n.kind);
54 let prev = n.connected_node(port).and_then(|s| comp.find_node(s))?;
55 return walk(comp, prev, time, expr, depth - 1);
56 }
57 match n.kind.as_str() {
58 "Merge" => {
59 let blend = comp.eval_number(n, "Blend", time, 1.0, expr);
60 let bg_id = n.connected_node("Background").and_then(|s| comp.find_node(s));
61 if blend <= 1e-6 {
62 return bg_id.and_then(|bid| walk(comp, bid, time, expr, depth - 1));
63 }
64 let e = comp.eval_number(n, "Edges", time, 0.0, expr).round() as i32;
65 if e == 1 || e == 3 {
66 return Some(e as f32);
67 }
68 if e == 0 {
69 if let Some(bid) = bg_id {
70 if let Some(m) = walk(comp, bid, time, expr, depth - 1) {
71 return Some(m);
72 }
73 if is_background_chain(comp, bid, depth - 1) {
74 if let Some(fid) = n.connected_node("Foreground").and_then(|s| comp.find_node(s)) {
75 return walk(comp, fid, time, expr, depth - 1);
76 }
77 }
78 }
79 }
80 None
81 }
82 "ColorCorrector"
83 | "ColorCurves"
84 | "BrightnessContrast"
85 | "ColorGain"
86 | "InvertColor"
87 | "GamutConvert"
88 | "HueCurves"
89 | "ChangeDepth"
90 | "PipeRouter"
91 | "Fuse.Wireless"
92 | "Tracker"
93 | "Dimension.OpticalFlow"
94 | "OpticalFlow" => {
95 let prev = n.connected_node("Input").and_then(|s| comp.find_node(s))?;
96 walk(comp, prev, time, expr, depth - 1)
97 }
98 "DirectionalBlur" | "Blur" | "Glow" | "SoftGlow" | "Sharpen" | "Filter" | "VariBlur" | "ErodeDilate" => {
99 if comp.eval_number(n, "Blend", time, 1.0, expr) <= 1e-4 {
100 let prev = n.connected_node("Input").and_then(|s| comp.find_node(s))?;
101 walk(comp, prev, time, expr, depth - 1)
102 } else {
103 None
104 }
105 }
106 "MacroOperator" | "GroupOperator" => {
107 if let Some(out_id) = n.macro_output {
108 walk(comp, out_id, time, expr, depth - 1)
109 } else {
110 let prev = n
111 .connected_node("Input")
112 .or_else(|| n.connected_node("MainInput1"))
113 .and_then(|s| comp.find_node(s))?;
114 walk(comp, prev, time, expr, depth - 1)
115 }
116 }
117 _ => None,
118 }
119 }
120 walk(comp, start_id, time, expr, 24)
121}
122
3impl Engine {123impl Engine {
4 pub(super) fn eval_transform(124 pub(super) fn eval_transform(
5 &mut self,125 &mut self,
...@@ -33,7 +153,16 @@ impl Engine {...@@ -33,7 +153,16 @@ impl Engine {
33 (s, s * asp)153 (s, s * asp)
34 };154 };
35 let angle = (comp.eval_number(node, "Angle", time, 0.0, &self.expr) as f32).to_radians();155 let angle = (comp.eval_number(node, "Angle", time, 0.0, &self.expr) as f32).to_radians();
36 let edges = comp.eval_number(node, "Edges", time, 0.0, &self.expr) as f32;156 let mut edges = comp.eval_number(node, "Edges", time, 0.0, &self.expr) as f32;
157 if edges.round() as i32 == 0 || edges.round() as i32 == 2 {
158 if let Some(up_edges) = src
159 .edge_mode
160 .map(f32::from)
161 .or_else(|| upstream_infinite_edge_mode(comp, src_id, time, &self.expr))
162 {
163 edges = up_edges;
164 }
165 }
37 let flip_h = comp.eval_number(node, "FlipHoriz", time, 0.0, &self.expr) as f32;166 let flip_h = comp.eval_number(node, "FlipHoriz", time, 0.0, &self.expr) as f32;
38 let flip_v = comp.eval_number(node, "FlipVert", time, 0.0, &self.expr) as f32;167 let flip_v = comp.eval_number(node, "FlipVert", time, 0.0, &self.expr) as f32;
39 let nearest = if comp.eval_number(node, "FilterMethod", time, 2.0, &self.expr) < 0.5 { 1.0 } else { 0.0 };168 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 {...@@ -614,4 +743,131 @@ mod tests {
614 assert!(diff <= 2, "KScope 6-slice mirror symmetry mismatch ch={c}: {a:?} vs {b:?}");743 assert!(diff <= 2, "KScope 6-slice mirror symmetry mismatch ch={c}: {a:?} vs {b:?}");
615 }744 }
616 }745 }
746
747 #[test]
748 fn test_upstream_infinite_edge_mode_propagates_through_point_ops_and_disabled_dirblur() {
749 let src = r#"Composition {
750 CurrentTime = 3050,
751 RenderRange = { 3000, 3100 },
752 GlobalRange = { 3000, 3100 },
753 Tools = ordered() {
754 BG1 = Background {
755 Inputs = {
756 Width = Input { Value = 64, },
757 Height = Input { Value = 64, },
758 TopLeftRed = Input { Value = 0.2, },
759 TopLeftAlpha = Input { Value = 1.0, },
760 },
761 },
762 FG1 = Background {
763 Inputs = {
764 Width = Input { Value = 64, },
765 Height = Input { Value = 64, },
766 Type = Input { Value = FuID { "Horizontal" }, },
767 TopLeftRed = Input { Value = 1.0, },
768 TopLeftGreen = Input { Value = 0.0, },
769 TopLeftBlue = Input { Value = 0.0, },
770 TopRightRed = Input { Value = 0.0, },
771 TopRightGreen = Input { Value = 0.0, },
772 TopRightBlue = Input { Value = 1.0, },
773 },
774 },
775 Merge23 = Merge {
776 Inputs = {
777 Background = Input { SourceOp = "BG1", Source = "Output", },
778 Foreground = Input { SourceOp = "FG1", Source = "Output", },
779 Edges = Input { Value = 3, },
780 },
781 },
782 CC1 = ColorCorrector {
783 Inputs = {
784 Input = Input { SourceOp = "Merge23", Source = "Output", },
785 },
786 },
787 BG2 = Background {
788 Inputs = {
789 Width = Input { Value = 64, },
790 Height = Input { Value = 64, },
791 TopLeftAlpha = Input { Value = 1.0, },
792 },
793 },
794 CC_BG = ColorCorrector {
795 Inputs = {
796 Input = Input { SourceOp = "BG2", Source = "Output", },
797 },
798 },
799 Merge24 = Merge {
800 Inputs = {
801 Background = Input { SourceOp = "CC_BG", Source = "Output", },
802 Foreground = Input { SourceOp = "CC1", Source = "Output", },
803 },
804 },
805 Infrared = ColorCurves {
806 Inputs = {
807 Input = Input { SourceOp = "Merge24", Source = "Output", },
808 },
809 },
810 CC2 = ColorCorrector {
811 Inputs = {
812 Input = Input { SourceOp = "Infrared", Source = "Output", },
813 },
814 },
815 DirBlur = DirectionalBlur {
816 Inputs = {
817 Blend = Input { Value = 0.0, },
818 Length = Input { Value = 0.05, },
819 Input = Input { SourceOp = "CC2", Source = "Output", },
820 },
821 },
822 DirBlurActive = DirectionalBlur {
823 Inputs = {
824 Blend = Input { Value = 1.0, },
825 Length = Input { Value = 0.05, },
826 Input = Input { SourceOp = "CC2", Source = "Output", },
827 },
828 },
829 XF = Transform {
830 Inputs = {
831 Center = Input { Value = { 0.75, 0.5 }, },
832 Edges = Input { Value = 2, },
833 Input = Input { SourceOp = "DirBlur", Source = "Output", },
834 },
835 },
836 },
837 }"#;
838 let comp = Comp::from_fusion_str(src).expect("parse mirror propagation comp");
839 let expr = ExprEngine::new();
840 let dir_blur_id = comp.find_node("DirBlur").expect("DirBlur");
841 let dir_blur_active_id = comp.find_node("DirBlurActive").expect("DirBlurActive");
842 assert_eq!(
843 upstream_infinite_edge_mode(&comp, dir_blur_id, 3050.0, &expr),
844 Some(3.0),
845 "Merge(Edges=3) should propagate through point ops, Merge(BG=CC(Background)), and DirectionalBlur(Blend=0)"
846 );
847 assert_eq!(
848 upstream_infinite_edge_mode(&comp, dir_blur_active_id, 3050.0, &expr),
849 None,
850 "Active DirectionalBlur (Blend=1) should stop RoI edge-mode propagation"
851 );
852
853 let Ok(mut eng) = Engine::new_headless() else {
854 return;
855 };
856 let xf_id = comp.find_node("XF").expect("XF");
857 let (tex, _) = eng.evaluate(&comp, xf_id, 3050.0);
858 let rgba = eng.readback_rgba(&tex).expect("readback XF");
859 // Center.x = 0.75 shifts image right by 16px: x=0..16 samples mirrored x=16..0
860 // rather than duplicating x=0! On a red->blue gradient, x=2 should be noticeably
861 // bluer than x=15 (which sits right next to the red left edge).
862 let px = |x: usize| -> [u8; 4] {
863 let i = (32 * 64 + x) * 4;
864 [rgba[i], rgba[i + 1], rgba[i + 2], rgba[i + 3]]
865 };
866 let far_left = px(2);
867 let seam = px(15);
868 assert!(
869 far_left[2] > seam[2] + 20,
870 "expected mirrored left edge (far_left={far_left:?} bluer than seam={seam:?}), not Duplicate streak"
871 );
872 }
617}873}