| 1 | use crate::Engine; |
| 2 | use model::Comp; |
| 3 | |
| 4 | fn rgba_at(px: &[u8], w: u32, x: u32, y: u32) -> [u8; 4] { |
| 5 | let i = ((y * w + x) * 4) as usize; |
| 6 | [px[i], px[i + 1], px[i + 2], px[i + 3]] |
| 7 | } |
| 8 | |
| 9 | #[test] |
| 10 | fn coord_space_polar_and_rect_roundtrip_and_seam() { |
| 11 | let src = r#"Composition { |
| 12 | CurrentTime = 0, RenderRange = { 0, 0 }, GlobalRange = { 0, 0 }, |
| 13 | Tools = ordered() { |
| 14 | Ramp = Background { |
| 15 | Inputs = { |
| 16 | Width = Input { Value = 64, }, Height = Input { Value = 64, }, |
| 17 | Type = Input { Value = FuID { "Corner" }, }, |
| 18 | TopLeftRed = Input { Value = 0.0, }, TopLeftGreen = Input { Value = 1.0, }, TopLeftAlpha = Input { Value = 1.0, }, |
| 19 | TopRightRed = Input { Value = 1.0, }, TopRightGreen = Input { Value = 1.0, }, TopRightAlpha = Input { Value = 1.0, }, |
| 20 | BottomLeftRed = Input { Value = 0.0, }, BottomLeftGreen = Input { Value = 0.0, }, BottomLeftAlpha = Input { Value = 1.0, }, |
| 21 | BottomRightRed = Input { Value = 1.0, }, BottomRightGreen = Input { Value = 0.0, }, BottomRightAlpha = Input { Value = 1.0, }, |
| 22 | }, |
| 23 | }, |
| 24 | ToPolar = CoordSpace { |
| 25 | Inputs = { Shape = Input { Value = 0, }, Input = Input { SourceOp = "Ramp", Source = "Output", }, }, |
| 26 | }, |
| 27 | ToRect = CoordSpace { |
| 28 | Inputs = { Shape = Input { Value = 1, }, Input = Input { SourceOp = "Ramp", Source = "Output", }, }, |
| 29 | }, |
| 30 | Roundtrip = CoordSpace { |
| 31 | Inputs = { Shape = Input { Value = 1, }, Input = Input { SourceOp = "ToPolar", Source = "Output", }, }, |
| 32 | }, |
| 33 | MaskedHalf = CoordSpace { |
| 34 | Inputs = { |
| 35 | Shape = Input { Value = 1, }, |
| 36 | Blend = Input { Value = 0.0, }, |
| 37 | Input = Input { SourceOp = "Ramp", Source = "Output", }, |
| 38 | }, |
| 39 | }, |
| 40 | }, |
| 41 | }"#; |
| 42 | let comp = Comp::from_fusion_str(src).expect("parse CoordSpace comp"); |
| 43 | let Ok(mut eng) = Engine::new_headless() else { return }; |
| 44 | |
| 45 | // Shape=0 (Rect->Polar): center (32, 32) samples near (0.85, 0.5), top-mid (32, 8) is out-of-disk -> alpha 0. |
| 46 | let (t0, s0) = eng.evaluate(&comp, comp.find_node("ToPolar").unwrap(), 0.0); |
| 47 | assert!(s0.unsupported_nodes.is_empty()); |
| 48 | let p0 = eng.readback_rgba(&t0).unwrap(); |
| 49 | let mid = rgba_at(&p0, 64, 32, 32); |
| 50 | assert!(mid[0] > 200 && (mid[1] as i32 - 128).abs() <= 10 && mid[3] == 255, "ToPolar mid={mid:?}"); |
| 51 | assert_eq!(rgba_at(&p0, 64, 32, 8)[3], 0, "ToPolar top-mid should be outside source disk"); |
| 52 | |
| 53 | // Shape=1 (Polar->Rect): top (32, 4) -> u~0.75 (R~191), bottom (32, 60) -> u~0.25 (R~64), center -> v~0 (G<15). |
| 54 | let (t1, _) = eng.evaluate(&comp, comp.find_node("ToRect").unwrap(), 0.0); |
| 55 | let p1 = eng.readback_rgba(&t1).unwrap(); |
| 56 | let top = rgba_at(&p1, 64, 32, 4); |
| 57 | let bot = rgba_at(&p1, 64, 32, 60); |
| 58 | let ctr = rgba_at(&p1, 64, 32, 32); |
| 59 | assert!((top[0] as i32 - 191).abs() <= 10, "ToRect top={top:?}"); |
| 60 | assert!((bot[0] as i32 - 64).abs() <= 10, "ToRect bot={bot:?}"); |
| 61 | assert!(ctr[1] < 15 && ctr[3] == 255, "ToRect center={ctr:?}"); |
| 62 | |
| 63 | // Roundtrip (Rect->Polar->Rect) recovers original UV ramp in the interior! |
| 64 | let (tr, _) = eng.evaluate(&comp, comp.find_node("Roundtrip").unwrap(), 0.0); |
| 65 | let pr = eng.readback_rgba(&tr).unwrap(); |
| 66 | let sample = rgba_at(&pr, 64, 48, 20); // fu = (0.758, 0.680) -> R~193, G~173 |
| 67 | assert!( |
| 68 | (sample[0] as i32 - 193).abs() <= 12 && (sample[1] as i32 - 173).abs() <= 12, |
| 69 | "CoordSpace roundtrip mismatch: {sample:?}" |
| 70 | ); |
| 71 | |
| 72 | // Blend=0 passes input through unchanged. |
| 73 | let (tb, _) = eng.evaluate(&comp, comp.find_node("MaskedHalf").unwrap(), 0.0); |
| 74 | let (tsrc, _) = eng.evaluate(&comp, comp.find_node("Ramp").unwrap(), 0.0); |
| 75 | assert_eq!(eng.readback_rgba(&tb).unwrap(), eng.readback_rgba(&tsrc).unwrap()); |
| 76 | } |
| 77 | |
| 78 | #[test] |
| 79 | fn lens_distort_distort_undistort_roundtrip_and_anamorphic() { |
| 80 | let src = r#"Composition { |
| 81 | CurrentTime = 0, RenderRange = { 0, 0 }, GlobalRange = { 0, 0 }, |
| 82 | Tools = ordered() { |
| 83 | Ramp = Background { |
| 84 | Inputs = { |
| 85 | Width = Input { Value = 64, }, Height = Input { Value = 64, }, |
| 86 | Type = Input { Value = FuID { "Corner" }, }, |
| 87 | TopLeftRed = Input { Value = 0.0, }, TopLeftGreen = Input { Value = 1.0, }, TopLeftAlpha = Input { Value = 1.0, }, |
| 88 | TopRightRed = Input { Value = 1.0, }, TopRightGreen = Input { Value = 1.0, }, TopRightAlpha = Input { Value = 1.0, }, |
| 89 | BottomLeftRed = Input { Value = 0.0, }, BottomLeftGreen = Input { Value = 0.0, }, BottomLeftAlpha = Input { Value = 1.0, }, |
| 90 | BottomRightRed = Input { Value = 1.0, }, BottomRightGreen = Input { Value = 0.0, }, BottomRightAlpha = Input { Value = 1.0, }, |
| 91 | }, |
| 92 | }, |
| 93 | Dist = LensDistort { |
| 94 | Inputs = { |
| 95 | Mode = Input { Value = 0, }, |
| 96 | LensDistortionModel = Input { Value = 1, }, |
| 97 | ["DEClassicLDModel.Distortion"] = Input { Value = 0.246, }, |
| 98 | ["DEClassicLDModel.AnamorphicSqueeze"] = Input { Value = 4.0, }, |
| 99 | ["DEClassicLDModel.CurvatureX"] = Input { Value = 0.365, }, |
| 100 | ["DEClassicLDModel.CurvatureY"] = Input { Value = 0.111, }, |
| 101 | Input = Input { SourceOp = "Ramp", Source = "Output", }, |
| 102 | }, |
| 103 | }, |
| 104 | Undist = LensDistort { |
| 105 | Inputs = { |
| 106 | Mode = Input { Value = 1, }, |
| 107 | LensDistortionModel = Input { Value = 1, }, |
| 108 | ["DEClassicLDModel.Distortion"] = Input { Value = 0.246, }, |
| 109 | ["DEClassicLDModel.AnamorphicSqueeze"] = Input { Value = 4.0, }, |
| 110 | ["DEClassicLDModel.CurvatureX"] = Input { Value = 0.365, }, |
| 111 | ["DEClassicLDModel.CurvatureY"] = Input { Value = 0.111, }, |
| 112 | Input = Input { SourceOp = "Dist", Source = "Output", }, |
| 113 | }, |
| 114 | }, |
| 115 | DivDist = LensDistort { |
| 116 | Inputs = { |
| 117 | Mode = Input { Value = 1, }, |
| 118 | Model = Input { Value = FuID { "FusionRadialDiv" }, }, |
| 119 | ["FusionRadialDiv.LowOrderDistortion"] = Input { Value = 0.3, }, |
| 120 | EdgeMode = Input { Value = 1, }, |
| 121 | Input = Input { SourceOp = "Ramp", Source = "Output", }, |
| 122 | }, |
| 123 | }, |
| 124 | }, |
| 125 | }"#; |
| 126 | let comp = Comp::from_fusion_str(src).expect("parse LensDistort comp"); |
| 127 | let Ok(mut eng) = Engine::new_headless() else { return }; |
| 128 | |
| 129 | let (td, sd) = eng.evaluate(&comp, comp.find_node("Dist").unwrap(), 0.0); |
| 130 | assert!(sd.unsupported_nodes.is_empty()); |
| 131 | let pd = eng.readback_rgba(&td).unwrap(); |
| 132 | let p_top = rgba_at(&pd, 64, 32, 12); |
| 133 | let orig_top_g = ((1.0 - 12.5 / 64.0) * 255.0) as i32; |
| 134 | assert!((p_top[1] as i32 - orig_top_g).abs() >= 6, "Distort should bend vertically: {p_top:?} vs {orig_top_g}"); |
| 135 | |
| 136 | let (tu, _) = eng.evaluate(&comp, comp.find_node("Undist").unwrap(), 0.0); |
| 137 | let pu = eng.readback_rgba(&tu).unwrap(); |
| 138 | let (tr, _) = eng.evaluate(&comp, comp.find_node("Ramp").unwrap(), 0.0); |
| 139 | let pr = eng.readback_rgba(&tr).unwrap(); |
| 140 | for (x, y) in [(32, 32), (44, 32), (32, 20), (42, 22)] { |
| 141 | let a = rgba_at(&pu, 64, x, y); |
| 142 | let b = rgba_at(&pr, 64, x, y); |
| 143 | assert!( |
| 144 | (a[0] as i32 - b[0] as i32).abs() <= 4 && (a[1] as i32 - b[1] as i32).abs() <= 4, |
| 145 | "LensDistort roundtrip at ({x},{y}): got {a:?}, expected {b:?}" |
| 146 | ); |
| 147 | } |
| 148 | |
| 149 | // Division model + Duplicate EdgeMode keeps corner opaque. |
| 150 | let (tdiv, _) = eng.evaluate(&comp, comp.find_node("DivDist").unwrap(), 0.0); |
| 151 | let pdiv = eng.readback_rgba(&tdiv).unwrap(); |
| 152 | assert_eq!(rgba_at(&pdiv, 64, 0, 0)[3], 255, "Duplicate EdgeMode keeps corners opaque"); |
| 153 | } |
| 154 | |
| 155 | #[test] |
| 156 | fn triangle_mask_fill_soft_border_invert_and_chain() { |
| 157 | let src = r#"Composition { |
| 158 | CurrentTime = 0, RenderRange = { 0, 0 }, GlobalRange = { 0, 0 }, |
| 159 | Tools = ordered() { |
| 160 | TriDef = TriangleMask { |
| 161 | Inputs = { MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, }, }, |
| 162 | }, |
| 163 | TriOutline = TriangleMask { |
| 164 | Inputs = { |
| 165 | MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, }, |
| 166 | Solid = Input { Value = 0, }, BorderWidth = Input { Value = 0.06, }, |
| 167 | }, |
| 168 | }, |
| 169 | TriSoftInv = TriangleMask { |
| 170 | Inputs = { |
| 171 | MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, }, |
| 172 | SoftEdge = Input { Value = 0.08, }, Invert = Input { Value = 1, }, |
| 173 | Level = Input { Value = 0.5, }, |
| 174 | }, |
| 175 | }, |
| 176 | Rect = RectangleMask { |
| 177 | Inputs = { MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, }, Width = Input { Value = 0.5, }, Height = Input { Value = 0.5, }, }, |
| 178 | }, |
| 179 | TriSub = TriangleMask { |
| 180 | Inputs = { |
| 181 | MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, }, |
| 182 | PaintMode = Input { Value = FuID { "Subtract" }, }, |
| 183 | Point1 = Input { Value = { 0.4, 0.4 }, }, |
| 184 | Point2 = Input { Value = { 0.6, 0.4 }, }, |
| 185 | Point3 = Input { Value = { 0.5, 0.6 }, }, |
| 186 | EffectMask = Input { SourceOp = "Rect", Source = "Mask", }, |
| 187 | }, |
| 188 | }, |
| 189 | }, |
| 190 | }"#; |
| 191 | let comp = Comp::from_fusion_str(src).expect("parse TriangleMask comp"); |
| 192 | let Ok(mut eng) = Engine::new_headless() else { return }; |
| 193 | |
| 194 | let (t, s) = eng.evaluate(&comp, comp.find_node("TriDef").unwrap(), 0.0); |
| 195 | assert!(s.unsupported_nodes.is_empty()); |
| 196 | let p = eng.readback_rgba(&t).unwrap(); |
| 197 | assert_eq!(rgba_at(&p, 64, 32, 36)[3], 255, "centroid inside default triangle"); |
| 198 | assert_eq!(rgba_at(&p, 64, 2, 2)[3], 0, "top-left corner outside default triangle"); |
| 199 | |
| 200 | let (to, _) = eng.evaluate(&comp, comp.find_node("TriOutline").unwrap(), 0.0); |
| 201 | let po = eng.readback_rgba(&to).unwrap(); |
| 202 | assert_eq!(rgba_at(&po, 64, 32, 36)[3], 0, "outline center must be hollow"); |
| 203 | assert!(rgba_at(&po, 64, 32, 57)[3] > 200, "outline bottom edge must be lit"); |
| 204 | |
| 205 | let (ts, _) = eng.evaluate(&comp, comp.find_node("TriSoftInv").unwrap(), 0.0); |
| 206 | let ps = eng.readback_rgba(&ts).unwrap(); |
| 207 | assert!((rgba_at(&ps, 64, 2, 2)[3] as i32 - 128).abs() <= 6, "soft+inv corner"); |
| 208 | assert!(rgba_at(&ps, 64, 32, 36)[3] < 20, "soft+inv centroid"); |
| 209 | |
| 210 | let (tc, _) = eng.evaluate(&comp, comp.find_node("TriSub").unwrap(), 0.0); |
| 211 | let pc = eng.readback_rgba(&tc).unwrap(); |
| 212 | assert_eq!(rgba_at(&pc, 64, 32, 32)[3], 0, "subtracted center"); |
| 213 | assert_eq!(rgba_at(&pc, 64, 20, 32)[3], 255, "remaining rect region"); |
| 214 | } |
| 215 | |
| 216 | #[test] |
| 217 | fn bspline_mask_closed_weighted_and_animated_keyframes() { |
| 218 | let src = r#"Composition { |
| 219 | CurrentTime = 0, RenderRange = { 0, 10 }, GlobalRange = { 0, 10 }, |
| 220 | Tools = ordered() { |
| 221 | BSAnim = BezierSpline { |
| 222 | KeyFrames = { |
| 223 | [0] = { |
| 224 | 0, Flags = { Linear = true, LockedY = true }, |
| 225 | Value = BSplinePolyline { |
| 226 | Closed = true, |
| 227 | Points = { |
| 228 | { X = -0.3, Y = -0.3, W = 1.0 }, |
| 229 | { X = 0.3, Y = -0.3, W = 1.0 }, |
| 230 | { X = 0.3, Y = 0.3, W = 1.0 }, |
| 231 | { X = -0.3, Y = 0.3, W = 1.0 }, |
| 232 | }, |
| 233 | }, |
| 234 | }, |
| 235 | [10] = { |
| 236 | 1, Flags = { Linear = true, LockedY = true }, |
| 237 | Value = BSplinePolyline { |
| 238 | Closed = true, |
| 239 | Points = { |
| 240 | { X = 0.0, Y = -0.3, W = 1.0 }, |
| 241 | { X = 0.4, Y = -0.3, W = 1.0 }, |
| 242 | { X = 0.4, Y = 0.3, W = 1.0 }, |
| 243 | { X = 0.0, Y = 0.3, W = 1.0 }, |
| 244 | }, |
| 245 | }, |
| 246 | }, |
| 247 | }, |
| 248 | }, |
| 249 | BSMask = BSplineMask { |
| 250 | Inputs = { |
| 251 | MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, }, |
| 252 | Polyline = Input { SourceOp = "BSAnim", Source = "Value", }, |
| 253 | }, |
| 254 | }, |
| 255 | BSWeighted = BSplineMask { |
| 256 | Inputs = { |
| 257 | MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, }, |
| 258 | Polyline = Input { |
| 259 | Value = BSplinePolyline { |
| 260 | Closed = true, |
| 261 | Points = { |
| 262 | { X = -0.3, Y = -0.3, W = 1.0 }, |
| 263 | { X = 0.3, Y = -0.3, W = 1.0 }, |
| 264 | { X = 0.3, Y = 0.3, W = 12.0 }, |
| 265 | { X = -0.3, Y = 0.3, W = 1.0 }, |
| 266 | }, |
| 267 | }, |
| 268 | }, |
| 269 | }, |
| 270 | }, |
| 271 | BSOpen = BSplineMask { |
| 272 | Inputs = { |
| 273 | MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, }, |
| 274 | Solid = Input { Value = 0, }, BorderWidth = Input { Value = 0.08, }, |
| 275 | Polyline = Input { |
| 276 | Value = BSplinePolyline { |
| 277 | Closed = false, |
| 278 | Points = { |
| 279 | { X = -0.4, Y = 0.0 }, |
| 280 | { X = 0.0, Y = 0.0 }, |
| 281 | { X = 0.4, Y = 0.0 }, |
| 282 | }, |
| 283 | }, |
| 284 | }, |
| 285 | }, |
| 286 | }, |
| 287 | }, |
| 288 | }"#; |
| 289 | let comp = Comp::from_fusion_str(src).expect("parse BSplineMask comp"); |
| 290 | let Ok(mut eng) = Engine::new_headless() else { return }; |
| 291 | |
| 292 | // Frame 0: centered around (0.5, 0.5) -> covered area ~1004 px (matches Fusion 21.1 GT!). |
| 293 | let (t0, s0) = eng.evaluate(&comp, comp.find_node("BSMask").unwrap(), 0.0); |
| 294 | assert!(s0.unsupported_nodes.is_empty()); |
| 295 | let p0 = eng.readback_rgba(&t0).unwrap(); |
| 296 | let covered: usize = p0.chunks_exact(4).filter(|c| c[3] > 127).count(); |
| 297 | assert!((covered as i32 - 1004).abs() <= 40, "expected ~1004 covered px (Fusion GT), got {covered}"); |
| 298 | assert_eq!(rgba_at(&p0, 64, 32, 32)[3], 255); |
| 299 | assert_eq!(rgba_at(&p0, 64, 2, 2)[3], 0); |
| 300 | |
| 301 | // High rational weight W=12 on top-right vertex (0.3, 0.3) pulls corner outward into (48, 16)! |
| 302 | let (tw, _) = eng.evaluate(&comp, comp.find_node("BSWeighted").unwrap(), 0.0); |
| 303 | let pw = eng.readback_rgba(&tw).unwrap(); |
| 304 | assert_eq!(rgba_at(&p0, 64, 48, 16)[3], 0, "uniform W=1 misses corner (48, 16)"); |
| 305 | assert!(rgba_at(&pw, 64, 48, 16)[3] > 200, "high W=12 pulls curve into top-right corner (48, 16)"); |
| 306 | |
| 307 | // Frame 10: shifted right to X in [0.0, 0.4] -> x=45 covered, x=24 empty! |
| 308 | let (t10, _) = eng.evaluate(&comp, comp.find_node("BSMask").unwrap(), 10.0); |
| 309 | let p10 = eng.readback_rgba(&t10).unwrap(); |
| 310 | assert_eq!(rgba_at(&p10, 64, 45, 32)[3], 255, "frame 10 shifted right"); |
| 311 | assert_eq!(rgba_at(&p10, 64, 24, 32)[3], 0, "frame 10 left side empty"); |
| 312 | |
| 313 | // Open B-spline outline along y=0.5 (row 32): center lit, top empty. |
| 314 | let (topen, _) = eng.evaluate(&comp, comp.find_node("BSOpen").unwrap(), 0.0); |
| 315 | let popen = eng.readback_rgba(&topen).unwrap(); |
| 316 | assert!(rgba_at(&popen, 64, 32, 32)[3] > 200, "open B-spline stroke should cover midline"); |
| 317 | assert_eq!(rgba_at(&popen, 64, 32, 10)[3], 0, "open B-spline should not fill away from stroke"); |
| 318 | } |
| 319 | |
| 320 | #[test] |
| 321 | fn trails_deterministic_random_access_gain_offset_blur_and_restart() { |
| 322 | let src = r#"Composition { |
| 323 | CurrentTime = 0, RenderRange = { 0, 4 }, GlobalRange = { 0, 4 }, |
| 324 | Tools = ordered() { |
| 325 | DotDisp = BezierSpline { |
| 326 | KeyFrames = { |
| 327 | [0] = { 0.0, Flags = { Linear = true } }, |
| 328 | [2] = { 1.0, Flags = { Linear = true } }, |
| 329 | }, |
| 330 | }, |
| 331 | DotPath = PolyPath { |
| 332 | Inputs = { |
| 333 | Displacement = Input { SourceOp = "DotDisp", Source = "Value", }, |
| 334 | PolyLine = Input { |
| 335 | Value = Polyline { |
| 336 | Points = { |
| 337 | { Linear = true, X = -0.25, Y = 0.0 }, |
| 338 | { Linear = true, X = 0.25, Y = 0.0 }, |
| 339 | }, |
| 340 | }, |
| 341 | }, |
| 342 | }, |
| 343 | }, |
| 344 | DotMask = EllipseMask { |
| 345 | Inputs = { |
| 346 | MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, }, |
| 347 | Center = Input { SourceOp = "DotPath", Source = "Position", }, |
| 348 | Width = Input { Value = 0.2, }, Height = Input { Value = 0.2, }, |
| 349 | }, |
| 350 | }, |
| 351 | DotBG = Background { |
| 352 | Inputs = { |
| 353 | Width = Input { Value = 64, }, Height = Input { Value = 64, }, |
| 354 | TopLeftRed = Input { Value = 1.0, }, TopLeftGreen = Input { Value = 1.0, }, |
| 355 | TopLeftAlpha = Input { Value = 1.0, }, |
| 356 | EffectMask = Input { SourceOp = "DotMask", Source = "Mask", }, |
| 357 | }, |
| 358 | }, |
| 359 | Tr = Trails { |
| 360 | Inputs = { |
| 361 | GainRed = Input { Value = 0.5, }, |
| 362 | YOffset = Input { Value = 0.1, }, |
| 363 | Input = Input { SourceOp = "DotBG", Source = "Output", }, |
| 364 | }, |
| 365 | }, |
| 366 | TrRGB = Trails { |
| 367 | Inputs = { |
| 368 | LockRGBA = Input { Value = 0, }, |
| 369 | GainRed = Input { Value = 0.8, }, |
| 370 | GainGreen = Input { Value = 0.2, }, |
| 371 | GainBlue = Input { Value = 0.0, }, |
| 372 | GainAlpha = Input { Value = 0.8, }, |
| 373 | XBlurSize = Input { Value = 8.0, }, |
| 374 | Input = Input { SourceOp = "DotBG", Source = "Output", }, |
| 375 | }, |
| 376 | }, |
| 377 | TrRestart = Trails { |
| 378 | Inputs = { |
| 379 | GainRed = Input { Value = 0.5, }, |
| 380 | Restart = Input { Value = 1, }, |
| 381 | Input = Input { SourceOp = "DotBG", Source = "Output", }, |
| 382 | }, |
| 383 | }, |
| 384 | }, |
| 385 | }"#; |
| 386 | let comp = Comp::from_fusion_str(src).expect("parse Trails comp"); |
| 387 | let Ok(mut eng) = Engine::new_headless() else { return }; |
| 388 | let tr_id = comp.find_node("Tr").unwrap(); |
| 389 | |
| 390 | // Jump directly to frame 2 (random-access scrub, no prior evaluation of frames 0/1!). |
| 391 | let (t2_direct, s2) = eng.evaluate(&comp, tr_id, 2.0); |
| 392 | assert!(s2.unsupported_nodes.is_empty()); |
| 393 | let p2_direct = eng.readback_rgba(&t2_direct).unwrap(); |
| 394 | |
| 395 | let cur_dot = rgba_at(&p2_direct, 64, 48, 32); |
| 396 | let echo1 = rgba_at(&p2_direct, 64, 32, 26); |
| 397 | let echo0 = rgba_at(&p2_direct, 64, 16, 19); |
| 398 | assert!(cur_dot[0] > 240, "current frame dot at x=48: {cur_dot:?}"); |
| 399 | assert!((echo1[0] as i32 - 128).abs() <= 16, "frame-1 trail echo expected ~128, got {echo1:?}"); |
| 400 | assert!((echo0[0] as i32 - 64).abs() <= 16, "frame-0 trail echo expected ~64, got {echo0:?}"); |
| 401 | |
| 402 | // Sequential playback 0 -> 1 -> 2 must match direct random-access jump to frame 2 bit-for-bit! |
| 403 | eng.bust_all_caches(); |
| 404 | let _ = eng.evaluate(&comp, tr_id, 0.0); |
| 405 | let _ = eng.evaluate(&comp, tr_id, 1.0); |
| 406 | let (t2_seq, _) = eng.evaluate(&comp, tr_id, 2.0); |
| 407 | let p2_seq = eng.readback_rgba(&t2_seq).unwrap(); |
| 408 | assert_eq!(p2_direct, p2_seq, "Trails must be 100% deterministic / scrub-safe"); |
| 409 | |
| 410 | // LockRGBA=0 tints trails red (GainRed=0.8 > GainGreen=0.2) and XBlurSize softens edges. |
| 411 | let (trgb, _) = eng.evaluate(&comp, comp.find_node("TrRGB").unwrap(), 2.0); |
| 412 | let prgb = eng.readback_rgba(&trgb).unwrap(); |
| 413 | let e1 = rgba_at(&prgb, 64, 32, 32); |
| 414 | assert!(e1[0] > e1[1] + 80, "LockRGBA=0 should tint frame-1 echo strongly red: {e1:?}"); |
| 415 | |
| 416 | // Restart=1 suppresses prior echoes at frame 2. |
| 417 | let (t_rst, _) = eng.evaluate(&comp, comp.find_node("TrRestart").unwrap(), 2.0); |
| 418 | let p_rst = eng.readback_rgba(&t_rst).unwrap(); |
| 419 | assert_eq!(rgba_at(&p_rst, 64, 16, 32)[0], 0, "Restart=1 must clear earlier trail echoes"); |
| 420 | assert!(rgba_at(&p_rst, 64, 48, 32)[0] > 240, "Restart=1 keeps current frame"); |
| 421 | } |
| 422 | |
| 423 | #[test] |
| 424 | fn bspline_mask_huge_dimensions_clamp_without_oom_or_panic() { |
| 425 | let src = r#"Composition { |
| 426 | CurrentTime = 0, RenderRange = { 0, 0 }, GlobalRange = { 0, 0 }, |
| 427 | Tools = ordered() { |
| 428 | HugeBSpline = BSplineMask { |
| 429 | Inputs = { |
| 430 | MaskWidth = Input { Value = 1000000, }, |
| 431 | MaskHeight = Input { Value = 1000000, }, |
| 432 | Polyline = Input { |
| 433 | Value = BSplinePolyline { |
| 434 | Closed = true, |
| 435 | Points = { |
| 436 | { X = -0.3, Y = -0.3 }, |
| 437 | { X = 0.3, Y = -0.3 }, |
| 438 | { X = 0.3, Y = 0.3 }, |
| 439 | { X = -0.3, Y = 0.3 }, |
| 440 | }, |
| 441 | }, |
| 442 | }, |
| 443 | }, |
| 444 | }, |
| 445 | }, |
| 446 | }"#; |
| 447 | let comp = Comp::from_fusion_str(src).expect("parse huge BSplineMask comp"); |
| 448 | let Ok(mut eng) = Engine::new_headless() else { return }; |
| 449 | let max_dim = eng.device().limits().max_texture_dimension_2d.max(1); |
| 450 | let (tex, stats) = eng.evaluate(&comp, comp.find_node("HugeBSpline").unwrap(), 0.0); |
| 451 | assert!(stats.unsupported_nodes.is_empty()); |
| 452 | assert!(tex.size[0] <= max_dim && tex.size[1] <= max_dim, "expected clamped dims <= {max_dim}, got {:?}", tex.size); |
| 453 | assert_eq!(tex.size, [max_dim, max_dim]); |
| 454 | } |