From d10991eff3b405aa8f1e3171ece47cde0bd764e2 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Thu, 5 Nov 2026 14:45:39 +0100 Subject: [PATCH 01/40] AEP import: map HDR Highlight Compression, Echo, Linear Wipe, Offset and Color Stabilizer The importer reported these five effects as lost. They now become EffectCraft's effects of the same name with every parameter After Effects stores (ranges, defaults and popup items from our own After Effects 2026 project, documented in docs/aep-format.md 3.7): - ADBE HDR ToneMap -> ec.utility.hdrcompression (Amount) - ADBE Echo -> ec.time.echo (Echo Time, Number Of Echoes, Starting Intensity, Decay, Echo Operator by item name) - ADBE Linear Wipe -> ec.transition.linearwipe - ADBE Offset -> ec.distort.offset (Blend With Original is a stored 0..1 fraction, a percentage here) - ADBE Deflicker -> ec.color.colorstabilizer (fresh Stabilize default Levels, points, Sample Size) A table row can name the range EffectCraft's effect works in (ParamMap::limit): Echo values or keys beyond 255 echoes or a Decay of 1 are imported as stored and reported. Tests build each effect into the committed synthetic.aep (fx_inject.rs, which also checks its pard layout reads back). On the sample project the effect losses go from 75 to 3 (the out-of-range Echo values). Co-Authored-By: Claude Opus 5.5 --- crates/aep/src/container/effect_map.rs | 62 +++- crates/aep/src/import/effects.rs | 16 +- crates/aep/tests/it/import.rs | 2 + crates/aep/tests/it/import/effects.rs | 2 +- .../aep/tests/it/import/effects_quickwins.rs | 149 ++++++++ crates/aep/tests/it/import/fx_inject.rs | 322 ++++++++++++++++++ docs/aep-format.md | 14 + docs/aep-import.md | 17 + 8 files changed, 581 insertions(+), 3 deletions(-) create mode 100644 crates/aep/tests/it/import/effects_quickwins.rs create mode 100644 crates/aep/tests/it/import/fx_inject.rs diff --git a/crates/aep/src/container/effect_map.rs b/crates/aep/src/container/effect_map.rs index a7c9bbd48..5b872450f 100644 --- a/crates/aep/src/container/effect_map.rs +++ b/crates/aep/src/container/effect_map.rs @@ -120,6 +120,10 @@ pub struct ParamMap { /// The EffectCraft parameter id. pub target: &'static str, pub conv: Conv, + /// The range EffectCraft's effect works in when it is narrower than the range After Effects + /// accepts (the effect limits the value there): a stored value or key outside it is imported + /// as it is and reported. `None`: no narrower range. + pub limit: Option<(f64, f64)>, } /// Values of an effect that are not ordinary parameters. @@ -147,7 +151,12 @@ pub struct EffectMap { } const fn pm(index: usize, kind: ParamKind, target: &'static str, conv: Conv) -> ParamMap { - ParamMap { index, kind, target, conv } + ParamMap { index, kind, target, conv, limit: None } +} + +/// [`pm`] for a parameter EffectCraft's effect limits to `lo..=hi` (see [`ParamMap::limit`]). +const fn pm_limited(index: usize, kind: ParamKind, target: &'static str, conv: Conv, lo: f64, hi: f64) -> ParamMap { + ParamMap { index, kind, target, conv, limit: Some((lo, hi)) } } const fn fx(match_name: &'static str, effect: &'static str, params: &'static [ParamMap]) -> EffectMap { @@ -339,6 +348,13 @@ pub const MATTE_USE: &[&str] = &["Red Channel", "Green Channel", "Blue Channel", /// 903. pub const SHUTTER_CONTROL: &[&str] = &["Manual", "Automatic"]; +// After Effects' popup items of the #3110 effects as the 2026-11-05 importer block stores them +// (`pdnm`; the `echo-*` and `colstab-*` compositions). +/// Echo's Echo Operator (`echo-05` ... `echo-10`). +pub const ECHO_OPERATOR: &[&str] = &["Add", "Maximum", "Minimum", "Screen", "Composite In Back", "Composite In Front", "Blend"]; +/// Color Stabilizer's Stabilize (`colstab-02`, `colstab-03`; the fresh default is Levels). +pub const STABILIZE: &[&str] = &["Brightness", "Levels", "Curves"]; + /// The effects the importer converts. pub const EFFECTS: &[EffectMap] = &[ // Tint (356-364): Map Black To, Map White To, Amount to Tint; 4 = Swap Colors (a button). @@ -1006,6 +1022,50 @@ pub const EFFECTS: &[EffectMap] = &[ pm(4, K::FloatSlider, "vectorDetail", Conv::Plain { valid_max: 100.0 }), ], ), + // HDR Highlight Compression (importer block 2026-11-05, `hdr-*`): Amount a float slider in + // percent (valid 0..100, default 100). + fx("ADBE HDR ToneMap", "ec.utility.hdrcompression", &[pm(1, K::FloatSlider, "amount", Conv::Plain { valid_max: 100.0 })]), + // Echo (`echo-*`): Echo Time in seconds (valid -30 000..30 000), Number Of Echoes an integer + // (valid 0..30 000), Starting Intensity 0..1, Decay (valid 0..100, slider 0..1), Echo + // Operator. EffectCraft's Echo uses at most 255 echoes and a Decay up to 1. + fx( + "ADBE Echo", + "ec.time.echo", + &[ + pm(1, K::FloatSlider, "echoTime", Conv::Plain { valid_max: 30000.0 }), + pm_limited(2, K::IntSlider, "numberOfEchoes", Conv::Plain { valid_max: 30000.0 }, 0.0, 255.0), + pm(3, K::FloatSlider, "startingIntensity", Conv::Plain { valid_max: 1.0 }), + pm_limited(4, K::FloatSlider, "decay", Conv::Plain { valid_max: 100.0 }, 0.0, 1.0), + pm(5, K::Popup, "echoOperator", Conv::Popup { default: 1, items: ECHO_OPERATOR }), + ], + ), + // Linear Wipe (`linwipe-*`): Transition Completion and Feather fixed sliders (valid 100 and + // 32 000), Wipe Angle in degrees. + fx( + "ADBE Linear Wipe", + "ec.transition.linearwipe", + &[ + pm(1, K::FixedSlider, "completion", Conv::Plain { valid_max: 100.0 }), + pm(2, K::Angle, "angle", Conv::Angle), + pm(3, K::FixedSlider, "feather", Conv::Plain { valid_max: 32000.0 }), + ], + ), + // Offset (`offset-*`): Blend With Original is a 0..1 fraction, a percentage here. + fx("ADBE Offset", "ec.distort.offset", &[pm(1, K::Point, "shift", Conv::Point), pm(2, K::FixedSlider, "blend", Conv::Percent { valid_max: 1.0 })]), + // Color Stabilizer (`colstab-*`): Stabilize (fresh default Levels), the three sample points, + // Sample Size a fixed slider (valid 50, default 3). The reference frame (Set Frame) is not a + // parameter in the file and is not imported. + fx( + "ADBE Deflicker", + "ec.color.colorstabilizer", + &[ + pm(1, K::Popup, "stabilize", Conv::Popup { default: 2, items: STABILIZE }), + pm(2, K::Point, "blackPoint", Conv::Point), + pm(3, K::Point, "midPoint", Conv::Point), + pm(4, K::Point, "whitePoint", Conv::Point), + pm(5, K::FixedSlider, "sampleSize", Conv::Plain { valid_max: 50.0 }), + ], + ), // Layer Control (076, 220, 320, 321): the default is the owning layer, None is unset. fx("ADBE Layer Control", "ec.control.layer", &[pm(1, K::Layer, "layer", Conv::LayerRef { own: true })]), fx("ADBE Slider Control", "ec.control.slider", &[pm(1, K::FloatSlider, "slider", Conv::Plain { valid_max: 1_000_000.0 })]), diff --git a/crates/aep/src/import/effects.rs b/crates/aep/src/import/effects.rs index 477a25df4..1d20a9dd1 100644 --- a/crates/aep/src/import/effects.rs +++ b/crates/aep/src/import/effects.rs @@ -266,6 +266,7 @@ fn import_param(fx: &AepEffect<'_, '_>, map: &EffectMap, p: &EffectParam<'_, '_> if let Some(map) = &popup_map { remap_popup_keys(prop, map, &here, &label, col); } + report_beyond_limit(m.limit, prop.keys.iter().map(|k| &k.value), &here, &label, col); } return; } @@ -298,11 +299,24 @@ fn import_param(fx: &AepEffect<'_, '_>, map: &EffectMap, p: &EffectParam<'_, '_> _ => convert(value, kind), }; match converted { - Some(v) => prop.value = v, + Some(v) => { + report_beyond_limit(m.limit, std::iter::once(&v), &here, &label, col); + prop.value = v; + } None => col.lose(LossCategory::DamagedData, format!("{here}: parameter {label} holds a value that is not valid ({value:?}), default used")), } } +/// Reports a value After Effects accepts but EffectCraft's effect limits (`ParamMap::limit`): it is +/// imported as it is, and the effect renders it as the nearest end of its range. +fn report_beyond_limit<'v>(limit: Option<(f64, f64)>, values: impl Iterator, here: &str, label: &str, col: &mut Collector) { + let Some((lo, hi)) = limit else { return }; + let beyond: Vec = values.filter_map(|v| if let Value::Scalar(x) = v { Some(*x) } else { None }).filter(|x| *x < lo || *x > hi).collect(); + if let Some(x) = beyond.first() { + col.lose(LossCategory::Effects, format!("{here}: parameter {label} is {x}, EffectCraft's effect uses {lo} to {hi} (rendered as the nearest of them)")); + } +} + /// A layer parameter: None stays unset, the owning layer is itself (`own`) or unset, another layer /// is resolved by [`resolve_layer_refs`] once the composition's layers exist. /// `names` is `(here, label)`, the effect and the parameter for the report. diff --git a/crates/aep/tests/it/import.rs b/crates/aep/tests/it/import.rs index 95dced570..178dd2bb3 100644 --- a/crates/aep/tests/it/import.rs +++ b/crates/aep/tests/it/import.rs @@ -11,8 +11,10 @@ mod combined; mod ease_round2; mod effects; mod effects_batch5; +mod effects_quickwins; mod effects_round2; mod effects_round3; +mod fx_inject; mod markers; mod masks; mod mattes; diff --git a/crates/aep/tests/it/import/effects.rs b/crates/aep/tests/it/import/effects.rs index be1293b9a..aa4180567 100644 --- a/crates/aep/tests/it/import/effects.rs +++ b/crates/aep/tests/it/import/effects.rs @@ -72,7 +72,7 @@ fn the_table_names_tint_gradient_ramp_and_exposure() { ] { assert!(t.contains(&want), "{want:?}"); } - assert_eq!(t.len(), 57); + assert_eq!(t.len(), 62); for (_, id) in t { assert!(effectcraft_effects::find(id).is_some(), "{id}"); } diff --git a/crates/aep/tests/it/import/effects_quickwins.rs b/crates/aep/tests/it/import/effects_quickwins.rs new file mode 100644 index 000000000..792e08d74 --- /dev/null +++ b/crates/aep/tests/it/import/effects_quickwins.rs @@ -0,0 +1,149 @@ +//! HDR Highlight Compression, Echo, Linear Wipe, Offset and Color Stabilizer (#3110) arrive as +//! EffectCraft's effects of the same name. Each is built into `synthetic.aep` (`fx_inject`) with +//! the definitions After Effects 2026 wrote for it in the importer block of 2026-11-05 (valid +//! ranges, defaults, popup items) and the values of that block's compositions. + +use crate::import::fx_inject::{Default, Fx, losses, near, num, other, popup, pt, run, slider, v}; +use effectcraft_aep::ParamKind as K; +use effectcraft_aep::import::LossCategory; +use effectcraft_keyframe::Value; + +const ECHO_OPS: &[&str] = &["Add", "Maximum", "Minimum", "Screen", "Composite In Back", "Composite In Front", "Blend"]; + +fn echo(values: Vec<(usize, f64)>) -> Fx { + Fx { + match_name: "ADBE Echo", + name: "Echo", + defs: vec![ + slider(K::FloatSlider, "Echo Time (seconds)", -1.0 / 30.0, (-30000.0, 30000.0)), + slider(K::IntSlider, "Number Of Echoes", 1.0, (0.0, 30000.0)), + slider(K::FloatSlider, "Starting Intensity", 1.0, (0.0, 1.0)), + slider(K::FloatSlider, "Decay", 1.0, (0.0, 100.0)), + popup("Echo Operator", 1, ECHO_OPS), + ], + values, + data: vec![], + } +} + +#[test] +fn hdr_highlight_compression_amount() { + let fx = |values| Fx { + match_name: "ADBE HDR ToneMap", + name: "HDR Highlight Compression", + defs: vec![slider(K::FloatSlider, "Amount", 100.0, (0.0, 100.0))], + values, + data: vec![], + }; + // `hdr-01-set-all`: 90; `hdr-00-defaults`: no record, 100. + for (values, want) in [(vec![(1, 90.0)], 90.0), (vec![], 100.0)] { + let (g, r) = run(&fx(values), "ec.utility.hdrcompression"); + assert_eq!(losses(&r, LossCategory::Effects, "ADBE HDR ToneMap"), Vec::::new()); + near(&g.expect("imported"), "amount", want); + } +} + +#[test] +fn echo_values_and_operator() { + // `echo-01-set-all` (without its Decay 20, below) and `echo-09-pop5-6`. + let (g, r) = run(&echo(vec![(1, 9.967), (2, 14.0), (3, 0.0), (5, 6.0)]), "ec.time.echo"); + assert_eq!(losses(&r, LossCategory::Effects, "ADBE Echo"), Vec::::new()); + let g = g.expect("imported"); + near(&g, "echoTime", 9.967); + near(&g, "numberOfEchoes", 14.0); + near(&g, "startingIntensity", 0.0); + near(&g, "decay", 1.0); + assert_eq!(v(&g, "echoOperator"), Value::Enum(5), "Composite In Front"); + // `echo-00-defaults`: one echo a frame back (1/30 s), Add. + let (g, _) = run(&echo(vec![]), "ec.time.echo"); + let g = g.expect("imported"); + assert!((num(&g, "echoTime") + 1.0 / 30.0).abs() < 1e-6); + assert_eq!((num(&g, "numberOfEchoes"), v(&g, "echoOperator")), (1.0, Value::Enum(0))); +} + +#[test] +fn echo_values_beyond_effectcrafts_range_are_reported() { + // `echo-03-max`: 30 000 echoes and Decay 100; EffectCraft's Echo uses at most 255 and 1. + let (g, r) = run(&echo(vec![(2, 30000.0), (4, 100.0)]), "ec.time.echo"); + let found = losses(&r, LossCategory::Effects, "ADBE Echo"); + assert_eq!(found.len(), 2, "{found:?}"); + assert!(found.iter().any(|d| d.contains("Number Of Echoes") && d.contains("0 to 255")), "{found:?}"); + assert!(found.iter().any(|d| d.contains("Decay") && d.contains("0 to 1")), "{found:?}"); + // Kept as stored. + let g = g.expect("still imported"); + near(&g, "numberOfEchoes", 30000.0); + near(&g, "decay", 100.0); +} + +#[test] +fn linear_wipe_values() { + let fx = |values| Fx { + match_name: "ADBE Linear Wipe", + name: "Linear Wipe", + defs: vec![ + slider(K::FixedSlider, "Transition Completion", 0.0, (0.0, 100.0)), + other(K::Angle, "Wipe Angle", Default::Number(90.0)), + slider(K::FixedSlider, "Feather", 0.0, (0.0, 32000.0)), + ], + values, + data: vec![], + }; + // `linwipe-01-set-all`. + let (g, r) = run(&fx(vec![(1, 10.0), (2, 77.0), (3, 16.0)]), "ec.transition.linearwipe"); + assert_eq!(losses(&r, LossCategory::Effects, "ADBE Linear Wipe"), Vec::::new()); + let g = g.expect("imported"); + near(&g, "completion", 10.0); + near(&g, "angle", 77.0); + near(&g, "feather", 16.0); + // `linwipe-00-defaults`: the Wipe Angle default 90. + near(&run(&fx(vec![]), "ec.transition.linearwipe").0.expect("imported"), "angle", 90.0); +} + +#[test] +fn offset_blend_is_a_fraction_and_the_centre_a_point() { + let fx = |values| Fx { + match_name: "ADBE Offset", + name: "Offset", + defs: vec![other(K::Point, "Shift Center To", Default::Point(0.5, 0.5)), slider(K::FixedSlider, "Blend With Original", 0.0, (0.0, 1.0))], + values, + data: vec![], + }; + // `offset-02-chk-toggled`: Blend With Original stored 1.0 is 100 %. + let (g, r) = run(&fx(vec![(2, 1.0)]), "ec.distort.offset"); + assert_eq!(losses(&r, LossCategory::Effects, "ADBE Offset"), Vec::::new()); + let g = g.expect("imported"); + near(&g, "blend", 100.0); + // The default centre is the layer's centre (synthetic.aep's layer is 8x8). + pt(&g, "shift", [4.0, 4.0]); + near(&run(&fx(vec![(2, 0.25)]), "ec.distort.offset").0.expect("imported"), "blend", 25.0); +} + +#[test] +fn color_stabilizer_points_sample_size_and_stabilize() { + let fx = |values| Fx { + match_name: "ADBE Deflicker", + name: "Color Stabilizer", + defs: vec![ + popup("Stabilize", 2, &["Brightness", "Levels", "Curves"]), + other(K::Point, "Black Point", Default::Point(0.2, 0.5)), + other(K::Point, "Mid Point", Default::Point(0.5, 0.5)), + other(K::Point, "White Point", Default::Point(0.8, 0.5)), + slider(K::FixedSlider, "Sample Size", 3.0, (0.0, 50.0)), + ], + values, + data: vec![], + }; + // `colstab-00-defaults`: Levels, the points at 20 %, 50 % and 80 % of the width. + let (g, r) = run(&fx(vec![]), "ec.color.colorstabilizer"); + assert_eq!(losses(&r, LossCategory::Effects, "ADBE Deflicker"), Vec::::new()); + let g = g.expect("imported"); + assert_eq!(v(&g, "stabilize"), Value::Enum(1), "Levels"); + pt(&g, "blackPoint", [1.6, 4.0]); + pt(&g, "whitePoint", [6.4, 4.0]); + near(&g, "sampleSize", 3.0); + // `colstab-03-pop1-3` and `colstab-27-pop5-25`. + let (g, _) = run(&fx(vec![(1, 3.0), (5, 25.0)]), "ec.color.colorstabilizer"); + let g = g.expect("imported"); + assert_eq!(v(&g, "stabilize"), Value::Enum(2), "Curves"); + near(&g, "sampleSize", 25.0); +} diff --git a/crates/aep/tests/it/import/fx_inject.rs b/crates/aep/tests/it/import/fx_inject.rs new file mode 100644 index 000000000..9687e2d6c --- /dev/null +++ b/crates/aep/tests/it/import/fx_inject.rs @@ -0,0 +1,322 @@ +//! Builds an effect instance into the committed `synthetic.aep` in place of its Glow (the instance +//! on the layer and the project's shared definitions), so an effect mapping can be tested without +//! the external corpus. The parameter definitions are written in the `pard` layout of +//! docs/aep-format.md 3.7 (type at byte 15, name at 16, default at 56, a float slider's valid +//! range as `f32` at 104 / 108 and its slider range at 112 / 116, a fixed or integer slider's valid +//! maximum at 128, a popup's item count at 60); `pard_layout_decodes_as_written` reads them back. +//! The ranges and defaults the tests use are the ones After Effects 2026 wrote in the importer +//! block of 2026-11-05 (`1100-quickwins.aep`, `1300-thirdparty.aep`, own projects). + +use effectcraft_aep::import::{ImportOptions, ImportResult, LossCategory, import}; +use effectcraft_aep::{Body, Chunk, ParamKind, ParamValue, Project as AepProject, parse, write}; +use effectcraft_keyframe::Value; +use effectcraft_project::{Project, PropGroup}; + +const SYNTHETIC: &[u8] = include_bytes!("../../fixtures/synthetic.aep"); + +/// A parameter definition. +#[derive(Clone)] +pub struct Def { + pub kind: ParamKind, + pub name: &'static str, + pub default: Default, + /// A float slider's valid range, a fixed or integer slider's valid maximum (`.1`). + pub valid: (f64, f64), + /// A popup's items. + pub items: &'static [&'static str], +} + +/// The default a definition holds at byte 56. +#[derive(Clone, Copy)] +pub enum Default { + None, + Number(f64), + Index(u32), + Point(f64, f64), + /// ARGB 0..255. + Color([u8; 4]), +} + +fn kind_code(k: ParamKind) -> u8 { + match k { + ParamKind::Layer => 0, + ParamKind::IntSlider => 1, + ParamKind::FixedSlider => 2, + ParamKind::Angle => 3, + ParamKind::Checkbox => 4, + ParamKind::Color => 5, + ParamKind::Point => 6, + ParamKind::Popup => 7, + ParamKind::NoData => 9, + ParamKind::FloatSlider => 10, + ParamKind::ArbitraryData => 11, + ParamKind::GroupStart => 13, + ParamKind::GroupEnd => 14, + ParamKind::Button => 15, + _ => 9, + } +} + +fn fixed(v: f64) -> [u8; 4] { + ((v * 65536.0).round() as i32).to_be_bytes() +} + +pub fn pard(d: &Def) -> Chunk<'static> { + let mut b = vec![0u8; 148]; + b[15] = kind_code(d.kind); + b[16..16 + d.name.len()].copy_from_slice(d.name.as_bytes()); + match (d.kind, d.default) { + (ParamKind::FloatSlider, Default::Number(v)) => b[56..64].copy_from_slice(&v.to_be_bytes()), + (ParamKind::FixedSlider | ParamKind::Angle, Default::Number(v)) => b[56..60].copy_from_slice(&fixed(v)), + (ParamKind::IntSlider | ParamKind::Checkbox, Default::Number(v)) => b[56..60].copy_from_slice(&(v as i32).to_be_bytes()), + (ParamKind::Popup, Default::Index(i)) => b[56..60].copy_from_slice(&i.to_be_bytes()), + (ParamKind::Point, Default::Point(x, y)) => { + b[56..60].copy_from_slice(&fixed(x)); + b[60..64].copy_from_slice(&fixed(y)); + } + (ParamKind::Color, Default::Color(c)) => b[56..60].copy_from_slice(&c), + _ => {} + } + match d.kind { + ParamKind::FloatSlider => { + b[104..108].copy_from_slice(&(d.valid.0 as f32).to_be_bytes()); + b[108..112].copy_from_slice(&(d.valid.1 as f32).to_be_bytes()); + b[112..116].copy_from_slice(&(d.valid.0 as f32).to_be_bytes()); + b[116..120].copy_from_slice(&(d.valid.1 as f32).to_be_bytes()); + } + ParamKind::FixedSlider => b[128..132].copy_from_slice(&fixed(d.valid.1)), + ParamKind::IntSlider => b[128..132].copy_from_slice(&(d.valid.1 as i32).to_be_bytes()), + ParamKind::Popup => b[60..62].copy_from_slice(&(d.items.len() as u16).to_be_bytes()), + _ => {} + } + Chunk::data(*b"pard", b) +} + +/// A match name chunk (`tdmn`, 40 bytes). +pub fn tdmn(name: &str) -> Chunk<'static> { + let mut b = name.as_bytes().to_vec(); + b.resize(40, 0); + Chunk::data(*b"tdmn", b) +} + +fn utf8(s: &str) -> Chunk<'static> { + Chunk::data(*b"Utf8", s.as_bytes().to_vec()) +} + +/// A chunk whose body is chunks without being a `LIST` (`pdnm`, `fnam`: `NESTED_IDS`). +fn nested(id: [u8; 4], children: Vec>) -> Chunk<'static> { + Chunk { id, body: Body::Chunks(children), pad: None } +} + +/// A static value record holding `v`, after the one After Effects wrote for Glow's A & B Midpoint +/// (its header; without the expression). +fn record(template: &Chunk<'_>, v: f64) -> Chunk<'static> { + let mut kids = Vec::new(); + for c in template.children() { + match &c.body { + Body::Data(d) if c.id == *b"tdsb" || c.id == *b"tdb4" => kids.push(Chunk::data(c.id, d.to_vec())), + Body::Data(_) if c.id == *b"cdat" => { + let mut d = vec![0u8; 40]; + d[..8].copy_from_slice(&v.to_be_bytes()); + kids.push(Chunk::data(*b"cdat", d)); + } + _ => {} + } + } + Chunk::list(*b"tdbs", kids) +} + +/// An effect instance: its match name, display name, parameter definitions (after the input +/// layer, before the built-in entry), the 1-D values stored (`parT` index, value) and the +/// arbitrary data stored (`parT` index, bytes). +pub struct Fx { + pub match_name: &'static str, + pub name: &'static str, + pub defs: Vec, + pub values: Vec<(usize, f64)>, + pub data: Vec<(usize, Vec)>, +} + +fn param_name(fx: &Fx, i: usize) -> String { + format!("{}-{i:04}", fx.match_name) +} + +fn sspc(fx: &Fx, template: &Chunk<'_>) -> Chunk<'static> { + let n = fx.defs.len() + 2; + let mut part = vec![ + Chunk::data(*b"parn", (n as u32).to_be_bytes().to_vec()), + tdmn(¶m_name(fx, 0)), + pard(&Def { kind: ParamKind::Layer, name: "", default: Default::None, valid: (0.0, 0.0), items: &[] }), + ]; + for (i, d) in fx.defs.iter().enumerate() { + part.push(tdmn(¶m_name(fx, i + 1))); + part.push(pard(d)); + if d.kind == ParamKind::Popup { + part.push(nested(*b"pdnm", vec![utf8(&d.items.join("|"))])); + } + } + part.push(tdmn("ADBE Effect Built In Params")); + part.push(pard(&Def { kind: ParamKind::NoData, name: "", default: Default::None, valid: (0.0, 0.0), items: &[] })); + let mut values = vec![Chunk::data(*b"tdsb", 1u32.to_be_bytes().to_vec())]; + for (i, v) in &fx.values { + values.push(tdmn(¶m_name(fx, *i))); + values.push(record(template, *v)); + if let Some((_, d)) = fx.data.iter().find(|(j, _)| j == i) { + values.push(Chunk::list(*b"aRbs", vec![Chunk::data(*b"aRbp", d.clone())])); + } + } + Chunk::list(*b"sspc", vec![nested(*b"fnam", vec![utf8(fx.name)]), Chunk::list(*b"parT", part), Chunk::list(*b"tdgp", values)]) +} + +/// The value record of Glow's A & B Midpoint (`ADBE Glo2-0011`): a 1-D static record. +fn find_glow_template(chunks: &[Chunk<'_>]) -> Option> { + for c in chunks { + let kids = c.children(); + if let Some(at) = kids.iter().position(|k| k.is(b"tdmn") && k.bytes().is_some_and(|b| b.starts_with(b"ADBE Glo2-0011\0"))) + && let Some(record) = kids.get(at + 1).filter(|k| k.is_list(b"tdbs")) + { + return Some(Chunk::list( + *b"tdbs", + record + .children() + .iter() + .map(|k| match &k.body { + Body::Data(d) => Chunk::data(k.id, d.to_vec()), + _ => Chunk::data(k.id, Vec::new()), + }) + .collect(), + )); + } + if let Some(t) = find_glow_template(kids) { + return Some(t); + } + } + None +} + +fn replace_glow(chunks: &mut [Chunk<'_>], fx: &Fx, template: &Chunk<'_>) -> usize { + let mut n = 0; + for ch in chunks { + let kids = ch.children_mut(); + if let Some(at) = kids.iter().position(|k| k.is(b"tdmn") && k.bytes().is_some_and(|b| b.starts_with(b"ADBE Glo2\0"))) + && kids.get(at + 1).is_some_and(|k| k.is_list(b"sspc")) + { + kids[at] = tdmn(fx.match_name); + kids[at + 1] = sspc(fx, template); + n += 1; + } + n += replace_glow(kids, fx, template); + } + n +} + +/// `synthetic.aep` with `fx` in place of the Glow effect. +pub fn bytes_with(fx: &Fx) -> Vec { + let file = parse(SYNTHETIC).unwrap(); + let template = find_glow_template(&file.chunks).expect("Glow's A & B Midpoint record"); + let mut file = parse(SYNTHETIC).unwrap(); + assert_eq!(replace_glow(&mut file.chunks, fx, &template), 2, "the Glow effect and its shared definitions"); + write(&file).unwrap() +} + +/// Imports `synthetic.aep` with `fx` in place of its Glow: the EffectCraft effect `effect` (if +/// imported) and the result. +pub fn run(fx: &Fx, effect: &str) -> (Option, ImportResult) { + let bytes = bytes_with(fx); + let mut project = Project::default(); + let none = |_: &str| false; + let r = import(&mut project, &bytes, &ImportOptions { allow_losses: true, ..ImportOptions::new(&none) }).unwrap(); + let g = project + .comps() + .flat_map(|(_, c)| c.layers.iter()) + .find_map(|l| l.props.sub("effects").and_then(|fx| fx.children.iter().filter_map(|n| n.as_group()).find(|g| g.match_id == effect).cloned())); + (g, r) +} + +/// The losses of `category` that name the effect `match_name`. +pub fn losses(r: &ImportResult, category: LossCategory, match_name: &str) -> Vec { + let tag = format!("({match_name})"); + r.report.losses.iter().filter(|l| l.category == category).flat_map(|l| l.details.clone()).filter(|d| d.contains(&tag)).collect() +} + +pub fn v(g: &PropGroup, id: &str) -> Value { + g.prop(id).unwrap_or_else(|| panic!("no {id} in {}", g.match_id)).value.clone() +} + +pub fn num(g: &PropGroup, id: &str) -> f64 { + match v(g, id) { + Value::Scalar(x) => x, + other => panic!("{id}: {other:?}"), + } +} + +pub fn near(g: &PropGroup, id: &str, want: f64) { + let got = num(g, id); + assert!((got - want).abs() <= want.abs().max(1.0) * 1e-6, "{} {id}: {got} != {want}", g.match_id); +} + +pub fn pt(g: &PropGroup, id: &str, want: [f64; 2]) { + let Value::Vec2(a) = v(g, id) else { panic!("{id}") }; + assert!((a[0] - want[0]).abs() < 1e-2 && (a[1] - want[1]).abs() < 1e-2, "{} {id}: {a:?} != {want:?}", g.match_id); +} + +/// A slider definition. +pub fn slider(kind: ParamKind, name: &'static str, default: f64, valid: (f64, f64)) -> Def { + Def { kind, name, default: Default::Number(default), valid, items: &[] } +} + +pub fn popup(name: &'static str, default: u32, items: &'static [&'static str]) -> Def { + Def { kind: ParamKind::Popup, name, default: Default::Index(default), valid: (0.0, 0.0), items } +} + +pub fn other(kind: ParamKind, name: &'static str, default: Default) -> Def { + Def { kind, name, default, valid: (0.0, 0.0), items: &[] } +} + +#[test] +fn pard_layout_decodes_as_written() { + // Echo's Decay (float, valid 0..100, default 1), Linear Wipe's Feather (fixed, valid max + // 32 000), Echo's Number Of Echoes (integer, max 30 000, default 1), Offset's centre point, + // Color Stabilizer's Stabilize (default 2 of 3): what the sample dump of 2026-11-05 read. + let fx = Fx { + match_name: "Test FX", + name: "Test FX", + defs: vec![ + slider(ParamKind::FloatSlider, "Decay", 1.0, (0.0, 100.0)), + slider(ParamKind::FixedSlider, "Feather", 0.0, (0.0, 32000.0)), + slider(ParamKind::IntSlider, "Number Of Echoes", 1.0, (0.0, 30000.0)), + other(ParamKind::Point, "Shift Center To", Default::Point(0.5, 0.5)), + popup("Stabilize", 2, &["Brightness", "Levels", "Curves"]), + other(ParamKind::Color, "Shadows Unbalance", Default::Color([0, 0, 0, 0])), + ], + values: vec![(1, 20.0)], + data: vec![], + }; + let bytes = bytes_with(&fx); + let file = parse(&bytes).unwrap(); + let proj = AepProject::new(&file).unwrap(); + let defs = proj.effect_definition_index(); + let found = proj + .all_items() + .into_iter() + .filter_map(|i| i.comp()) + .flat_map(|c| c.layers().collect::>()) + .flat_map(|l| l.effects()) + .find(|e| e.match_name() == "Test FX") + .expect("the effect"); + let p = defs.params(&found); + let by = |i: usize| p.iter().find(|q| q.index == i).expect("parameter").clone(); + let decay = by(1); + assert_eq!( + (decay.kind, decay.name.as_str(), decay.valid_min(), decay.valid_max(), decay.pard_default()), + (ParamKind::FloatSlider, "Decay", Some(0.0), Some(100.0), Some(ParamValue::Number(1.0))) + ); + assert_eq!(decay.stored_value(), Some(ParamValue::Number(20.0))); + assert_eq!((by(2).kind, by(2).valid_max(), by(2).pard_default()), (ParamKind::FixedSlider, Some(32000.0), Some(ParamValue::Number(0.0)))); + assert_eq!((by(3).kind, by(3).valid_max(), by(3).pard_default()), (ParamKind::IntSlider, Some(30000.0), Some(ParamValue::Number(1.0)))); + assert_eq!(by(4).pard_default(), Some(ParamValue::Point([0.5, 0.5]))); + let stab = by(5); + assert_eq!((stab.popup_item_count(), stab.items.clone()), (Some(3), Some(vec!["Brightness".to_string(), "Levels".into(), "Curves".into()]))); + assert_eq!(found.display_name().as_deref(), Some("Test FX")); + assert_eq!(by(6).pard_default(), Some(ParamValue::Argb([0.0, 0.0, 0.0, 0.0]))); +} diff --git a/docs/aep-format.md b/docs/aep-format.md index fcc8f53be..32ec74854 100644 --- a/docs/aep-format.md +++ b/docs/aep-format.md @@ -519,6 +519,20 @@ popup_selected_item, borrowed_definition}`, `Effect::has_own_definitions`, (356, 357, 361, 363, 364, 366, 368, 369, 371, 374, 377, 378, 380, 382, 383), `tests/effects_exposure.rs` (389-391, 393-397). +**Importer block 2026-11-05, #3110 (`1100-quickwins.aep`, After Effects 26.2.1; V for every +row: defaults from the defaults composition, the valid ranges from the minimum and maximum +compositions, the items from one composition per popup item).** Each set value is stored as set +(Decay 20 is `20.0`, Blend With Original 100 % is `1.0`); a value set to the default leaves no record +(HDR Amount 100): + +| Effect (match name) | Parameters (`parT` index: type, valid range, default) | +|---|---| +| `ADBE HDR ToneMap` (HDR Highlight Compression) | 1 Amount: float, 0..100 (slider 0..100), default 100 | +| `ADBE Echo` | 1 Echo Time (seconds): float, -30 000..30 000 (slider -5..5), default -1/30 (float32); 2 Number Of Echoes: integer, max 30 000, default 1; 3 Starting Intensity: float, 0..1, default 1; 4 Decay: float, **valid 0..100, slider 0..1**, default 1; 5 Echo Operator: popup (Add, Maximum, Minimum, Screen, Composite In Back, Composite In Front, Blend), default 1 | +| `ADBE Linear Wipe` | 1 Transition Completion: fixed, max 100, default 0; 2 Wipe Angle: angle, default 90; 3 Feather: fixed, max 32 000, default 0 | +| `ADBE Offset` | 1 Shift Center To: point, default the layer centre; 2 Blend With Original: fixed, **max 1 (a 0..1 fraction)**, default 0 | +| `ADBE Deflicker` (Color Stabilizer) | 1 Stabilize: popup (Brightness, Levels, Curves), **default 2 (Levels)**; 2 Black Point, 3 Mid Point, 4 White Point: points, defaults 0.2 / 0.5 / 0.8 of the width at half the height; 5 Sample Size: fixed, max 50, default 3. The reference frame the Set Frame button picks is not among the parameters | + **Curves and Mesh Warp** (961-965, 985; applied from presets, the data is not scriptable): their arbitrary-data parameter (type 11) always has a record (`tdbs` with a 4-byte `cdat`) and a `LIST aRbs` / `aRbp`, also at the default. Curves (`ADBE CurvesCustom-0001`, 1644 bytes): `u16` 1, 1; diff --git a/docs/aep-import.md b/docs/aep-import.md index baeb8d0e1..1926274f0 100644 --- a/docs/aep-import.md +++ b/docs/aep-import.md @@ -178,6 +178,7 @@ parameter gets the file's value: | `ADBE HUE SATURATION` 1 Channel Control, 2 Channel Range data, 6 Colorize, 7 Colorize Hue, 8 Colorize Saturation, 9 Colorize Lightness | `channelControl`; `hue`, `saturation`, `lightness` from the data; `colorize`, `colorizeHue`, `colorizeSaturation`, `colorizeLightness` | popup by name; the master hue (degrees), saturation and lightness are the `i32` of the arbitrary data (the visible Master parameters keep no record); the colour ranges are reported when they are not at their defaults (not sampled) | 443-450 | | `ADBE Easy Levels2` 1 Channel, 2 Histogram data, 8 / 9 Clip To Output Black / White | `channel`; `inBlack`, `inWhite`, `gamma`, `outBlack`, `outWhite` from the data; `clipToOutputBlack`, `clipToOutputWhite` | popups by name (After Effects' items On, Off, Off for 32 bpc Color are in another order here); the RGB values are the `f32` of the arbitrary data; the per-channel values are reported when they are not at their defaults (not sampled) | 511-516 | | Batch 6 (903 defaults, 904 / 905 set values): `ADBE Brightness & Contrast 2`, `ADBE Turbulent Displace`, `ADBE Fractal Noise`, `ADBE Laser` (Beam), `CC Radial Fast Blur`, `ADBE Noise2`, `ADBE Pro Levels2` (Levels (Individual Controls)), `ADBE Corner Pin`, `ADBE Grid`, `ADBE Sharpen`, `ADBE Linear Color Key2`, `ADBE Radial Wipe`, `ADBE Remove Color Matting`, `CC Bend It`, `CC Power Pin`, `ADBE 4ColorGradient`, `ADBE Change Color`, `ADBE Extract`, `ADBE Noise HLS2`, `ADBE Scatter`, `CC Light Sweep`, `ADBE Compound Blur`, `ADBE Displacement Map`, `ADBE Set Matte3`, `ADBE Gaussian Blur` (legacy), `ADBE OFMotionBlur` (Pixel Motion Blur), `ADBE Layer Control` | the EffectCraft effect of the same name, every parameter EffectCraft has | sliders as stored (each checked against its valid maximum); Beam Length, Time and Softness and CC Power Pin Perspective are 0..1 fractions, percentages here; points as layer pixels; popups by item name (Set Matte's `Red Channel` ... is `Red` ...); twirl-down group markers and the Levels histogram carry nothing; **layer parameters** (below) | 903, 904, 905; 220, 320, 321 | +| Importer block 2026-11-05 (`1100-quickwins.aep`: per effect defaults, set values, minimum and maximum, every popup item, a keyed and an expression parameter): `ADBE HDR ToneMap` (HDR Highlight Compression) 1 Amount; `ADBE Echo` 1 Echo Time, 2 Number Of Echoes, 3 Starting Intensity, 4 Decay, 5 Echo Operator; `ADBE Linear Wipe` 1 Transition Completion, 2 Wipe Angle, 3 Feather; `ADBE Offset` 1 Shift Center To, 2 Blend With Original; `ADBE Deflicker` (Color Stabilizer) 1 Stabilize, 2-4 Black / Mid / White Point, 5 Sample Size | `ec.utility.hdrcompression` `amount`; `ec.time.echo` `echoTime`, `numberOfEchoes`, `startingIntensity`, `decay`, `echoOperator`; `ec.transition.linearwipe` `completion`, `angle`, `feather`; `ec.distort.offset` `shift`, `blend`; `ec.color.colorstabilizer` `stabilize`, `blackPoint`, `midPoint`, `whitePoint`, `sampleSize` | percent (float, valid 0..100, default 100); seconds (float, valid ±30 000), integer (valid 30 000), 0..1 (float), Decay as stored (float, valid 0..100), popup by name: EffectCraft's Echo uses at most 255 echoes and a Decay up to 1, a value or key beyond that is imported as stored and **reported**; percent (fixed, 100), degrees, pixels (fixed, 32 000); point in layer pixels, Blend 0..1 x 100 = percent; popup by name (**fresh default Levels**), points in layer pixels, Sample Size as stored (fixed, valid 50, default 3; its unit, pixels here, is not verified). Color Stabilizer's reference frame (Set Frame) is not a parameter in the file and is not imported (EffectCraft's Reference Frame stays 0 s) | `tests/it/import/effects_quickwins.rs`; render comparison below | | `ADBE Slider Control`, `ADBE Angle Control`, `ADBE Checkbox Control`, `ADBE Color Control`, `ADBE Point Control` (parameter 1) | `ec.control.slider` `slider`, `ec.control.angle` `angle`, `ec.control.checkbox` `checkbox`, `ec.control.color` `color`, `ec.control.point` `point` | float (valid max 1 000 000) as stored; degrees; checkbox; colour; point in layer pixels | 071, 073, 217-219, 221, 304, 310 | - **Nothing to import:** the implicit input-layer parameter (index 0), the Swap Colors buttons @@ -308,6 +309,22 @@ frame blending, 3D material options, audio levels, guides, the mask colour, lock between them (363: 50 at 1 s; 364: grey at 1 s; 382: [950, 500] at 1 s), the defaults equal to EffectCraft's, stack order with a reported Gaussian Blur (366), the second instance (383), and lossless imports without `allowLosses`. +- `crates/aep/tests/it/import/effects_quickwins.rs` (#3110): HDR Highlight Compression, Echo, + Linear Wipe, Offset and Color Stabilizer, each built into `synthetic.aep` (`fx_inject.rs`, which + also checks that its `pard` layout reads back) with the definitions and values of the importer + block of 2026-11-05. Render check of that block's 75 compositions (320x180, 32 bpc, working space + None, 0.5 s) against After Effects' frames (its `saveFrameToPng` of a 32 bpc project writes + `floor(value x 25)` per channel, so values are compared at that quantisation): Offset (5), Linear + Wipe defaults / min / max, Echo with the Add, Maximum, Minimum, Screen operators and the keyed and + expression variants, Color Stabilizer with every Stabilize item and Sample Size up to 25 match + within one level. Differences, all in EffectCraft's effects and not in the mapping: HDR + Highlight Compression's curve (up to 6 of 25 levels on 19 % of the pixels at Amount 100, equal + at Amount 0); Echo's Blend operator (After Effects' frame is as bright as Add's, EffectCraft + averages) and the edge of the moving square with Composite In Back / Front (0.5 % of the + pixels); Linear Wipe's feathered edge (0.6 % of the pixels); Color Stabilizer with a Sample Size + over 25 (EffectCraft's samples drift, After Effects' frame stays unchanged) and with keyed + sample points. The renders do not exercise a Decay above 1 (After Effects' set value has + Starting Intensity 0) or what Color Stabilizer corrects (the test card does not flicker). - `crates/aep/tests/it/import/combined.rs`: masks and effects on the same layer, an effect on a text layer, and the same through `.aepx` (built in-test from the fixtures: the effect parade of one fixture grafted onto the layer of another). From 77e91199e88ff4aa353990f08b8b725e601fca47 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Thu, 5 Nov 2026 14:55:01 +0100 Subject: [PATCH 02/40] AEP import: map CC Color Neutralizer, EXtractoR and IDentifier The importer reported these three plug-ins as lost effects. They now become EffectCraft's effects of the same name (parameter lists and data layouts from our own After Effects 2026 project, docs/aep-format.md 3.7): - CS Color Neutralizer -> ec.color.cccolorneutralizer: Pinning and Blend w. Original. After Effects' correction is the per-range Red / Green / Blue sliders (the Unbalance colours are pickers that keep no record), plus View and Black / White Point; EffectCraft's effect has none of them, so each is reported when stored. - EXtractoR -> ec.3d.extractor: Black / White Point, UnMult, and the default Channel Info (R, G, B, (copy)) as EffectCraft's R, G, B, A (ExtractorChannels). Other channels are reported: only the default layout is sampled. - IDentifier -> ec.3d.identifier: Display by item name, ID. Its Channel Info names only the channel type (Object ID, identifier_channel_type), not the channel After Effects reads; After Effects left the sampled EXR unchanged where EffectCraft draws the footage's object ID channel, so every instance is reported. On the sample project no effect is lost any more (29 before); the parameters above are reported instead. Co-Authored-By: Claude Opus 5.5 --- crates/aep/src/container.rs | 2 +- crates/aep/src/container/arbitrary.rs | 51 +++++ crates/aep/src/container/effect_map.rs | 42 ++++ crates/aep/src/import/effects.rs | 38 +++- crates/aep/src/lib.rs | 14 +- crates/aep/tests/it/import.rs | 1 + crates/aep/tests/it/import/effects.rs | 2 +- .../aep/tests/it/import/effects_thirdparty.rs | 179 ++++++++++++++++++ docs/aep-format.md | 16 ++ docs/aep-import.md | 13 ++ 10 files changed, 347 insertions(+), 11 deletions(-) create mode 100644 crates/aep/tests/it/import/effects_thirdparty.rs diff --git a/crates/aep/src/container.rs b/crates/aep/src/container.rs index 4aa0f393a..0a4746f68 100644 --- a/crates/aep/src/container.rs +++ b/crates/aep/src/container.rs @@ -36,7 +36,7 @@ mod values; mod write; pub use aepx::{is_aepx, parse_any, read_aepx, read_aepx_with_limits}; -pub use arbitrary::{CURVE_IDENTITY, CurvesData, HueSaturationData, LevelsData, MeshData, curve_lut}; +pub use arbitrary::{CURVE_IDENTITY, CurvesData, ExtractorChannels, HueSaturationData, LevelsData, MeshData, curve_lut, identifier_channel_type}; pub use camera::{CameraPosition, DEFAULT_CAMERA_ZOOM}; pub use chunk::{AepFile, Body, Chunk, LIST, NESTED_IDS, Walk}; pub use effects::{DefinitionSource, Effect, EffectDefinitions, EffectParam, LayerRef, ParamKind, ParamValue}; diff --git a/crates/aep/src/container/arbitrary.rs b/crates/aep/src/container/arbitrary.rs index dea70d22c..7b47e83c7 100644 --- a/crates/aep/src/container/arbitrary.rs +++ b/crates/aep/src/container/arbitrary.rs @@ -307,3 +307,54 @@ impl MeshData { Some(out) } } + +/// EXtractoR's Channel Info data (`EXtractoR-0013`, 688 bytes, the plug-in's own little-endian +/// layout; read from the default instances of the importer block of 2026-11-05, where no channel +/// was changed): a `u32` 1 and 28 bytes, then four records of 164 bytes (Red, Green, Blue, Alpha), +/// each a `u32` kind (1 a named channel, 2 the input's channel: `(copy)` on Alpha) and the channel +/// name from byte 35, NUL-terminated. Only the default (`R`, `G`, `B`, `(copy)`) is sampled. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ExtractorChannels { + /// Per output channel (red, green, blue, alpha): the kind and the name. + pub channels: [(u32, String); 4], +} + +impl ExtractorChannels { + /// The data's length. + pub const LEN: usize = 688; + const RECORD: usize = 164; + + /// `None` when the data does not have this layout. + pub fn parse(data: &[u8]) -> Option { + if data.len() != Self::LEN || data.get(..4)? != 1u32.to_le_bytes() { + return None; + } + let mut channels: [(u32, String); 4] = Default::default(); + for (k, slot) in channels.iter_mut().enumerate() { + let at = 32usize.checked_add(k.checked_mul(Self::RECORD)?)?; + let rec = data.get(at..at.checked_add(Self::RECORD)?)?; + let kind = u32::from_le_bytes(*rec.first_chunk::<4>()?); + let name = rec.get(35..)?; + let end = name.iter().position(|b| *b == 0)?; + let name = std::str::from_utf8(name.get(..end)?).ok()?; + *slot = (kind, name.to_string()); + } + Some(Self { channels }) + } + + /// The channels of a fresh EXtractoR: Red, Green and Blue from the channels of those names, + /// Alpha copied from the input. + pub fn is_default(&self) -> bool { + let want = [(1, "R"), (1, "G"), (1, "B"), (2, "(copy)")]; + self.channels.iter().zip(want).all(|((k, n), (wk, wn))| *k == wk && n == wn) + } +} + +/// IDentifier's Channel Info data (`IDentifier-0005`, 148 bytes): the channel type's name, +/// NUL-terminated from byte 19 (`Object ID` in every sample of the importer block of 2026-11-05; +/// the bytes around it differ between instances with the same settings and are not read). +pub fn identifier_channel_type(data: &[u8]) -> Option<&str> { + let s = data.get(19..)?; + let end = s.iter().position(|b| *b == 0)?; + std::str::from_utf8(s.get(..end)?).ok() +} diff --git a/crates/aep/src/container/effect_map.rs b/crates/aep/src/container/effect_map.rs index 5b872450f..46fcf39ea 100644 --- a/crates/aep/src/container/effect_map.rs +++ b/crates/aep/src/container/effect_map.rs @@ -138,6 +138,10 @@ pub enum Extra { Curves, /// Mesh Warp's Distortion Mesh (965, 985, `MeshData`). MeshWarp, + /// EXtractoR's Channel Info (`ExtractorChannels`): the default channels only. + Extractor, + /// IDentifier's Channel Info (`identifier_channel_type`): Object ID only. + Identifier, } /// One mapped effect. @@ -354,6 +358,8 @@ pub const SHUTTER_CONTROL: &[&str] = &["Manual", "Automatic"]; pub const ECHO_OPERATOR: &[&str] = &["Add", "Maximum", "Minimum", "Screen", "Composite In Back", "Composite In Front", "Blend"]; /// Color Stabilizer's Stabilize (`colstab-02`, `colstab-03`; the fresh default is Levels). pub const STABILIZE: &[&str] = &["Brightness", "Levels", "Curves"]; +/// IDentifier's Display (`identifier-04` ... `identifier-06`, `1300-thirdparty.aep`). +pub const IDENTIFIER_DISPLAY: &[&str] = &["Colors", "Luma Matte", "Alpha Matte", "Raw"]; /// The effects the importer converts. pub const EFFECTS: &[EffectMap] = &[ @@ -1066,6 +1072,40 @@ pub const EFFECTS: &[EffectMap] = &[ pm(5, K::FixedSlider, "sampleSize", Conv::Plain { valid_max: 50.0 }), ], ), + // CC Color Neutralizer (importer block 2026-11-05, `ccneutral-*`): Pinning and Blend w. + // Original are float sliders in percent (valid 0..100). After Effects' correction is the Red / + // Green / Blue slider of each range (3-5, 9-11, 15-17; the Unbalance colours are pickers that + // set them and keep no record), then View (22) and Black / White Point (23, 24): + // EffectCraft's CC Color Neutralizer has none of them, so they are reported when stored. + fx( + "CS Color Neutralizer", + "ec.color.cccolorneutralizer", + &[pm(19, K::FloatSlider, "pinning", Conv::Plain { valid_max: 100.0 }), pm(20, K::FloatSlider, "blendWOriginal", Conv::Plain { valid_max: 100.0 })], + ), + // EXtractoR (`extractor-*`): 1 Channel Info (arbitrary data, `Extra::Extractor`), 2 / 6 the + // Process group, Black and White Point float sliders (valid ±3.4e38, the float32 range), + // UnMult. EffectCraft's Clip has no counterpart and stays off. + EffectMap { + match_name: "EXtractoR", + effect: "ec.3d.extractor", + params: &[ + pm(3, K::FloatSlider, "blackPoint", Conv::Plain { valid_max: F32_MAX }), + pm(4, K::FloatSlider, "whitePoint", Conv::Plain { valid_max: F32_MAX }), + pm(5, K::Checkbox, "unMult", Conv::Checkbox), + ], + extra: Extra::Extractor, + }, + // IDentifier (`identifier-*`): 1 Channel Info (arbitrary data, `Extra::Identifier`), 2 Display, + // 3 ID an integer slider (valid 0..2 147 483 647). + EffectMap { + match_name: "IDentifier", + effect: "ec.3d.identifier", + params: &[ + pm(2, K::Popup, "display", Conv::Popup { default: 1, items: IDENTIFIER_DISPLAY }), + pm(3, K::IntSlider, "id", Conv::Plain { valid_max: 2_147_483_647.0 }), + ], + extra: Extra::Identifier, + }, // Layer Control (076, 220, 320, 321): the default is the owning layer, None is unset. fx("ADBE Layer Control", "ec.control.layer", &[pm(1, K::Layer, "layer", Conv::LayerRef { own: true })]), fx("ADBE Slider Control", "ec.control.slider", &[pm(1, K::FloatSlider, "slider", Conv::Plain { valid_max: 1_000_000.0 })]), @@ -1079,6 +1119,8 @@ pub const EFFECTS: &[EffectMap] = &[ pub const EXPOSURE: Conv = Conv::Plain { valid_max: 100.0 }; pub const OFFSET: Conv = Conv::Plain { valid_max: 2.0 }; pub const GAMMA: Conv = Conv::Plain { valid_max: 10.0 }; +/// The largest float32, the valid maximum of EXtractoR's Black and White Point. +pub const F32_MAX: f64 = f32::MAX as f64; /// The valid maximum of Glow's A & B Midpoint (16.16 of 0.99, 427). pub const GLOW_MIDPOINT_MAX: f64 = 0.990_005_493_164_062_5; diff --git a/crates/aep/src/import/effects.rs b/crates/aep/src/import/effects.rs index 1d20a9dd1..a9fa3c2c7 100644 --- a/crates/aep/src/import/effects.rs +++ b/crates/aep/src/import/effects.rs @@ -36,8 +36,8 @@ use crate::effect_map::{Conv, EFFECTS, EffectMap, Extra, HUE_SATURATION_MASTER, LEVELS_RGB, popup_key}; use crate::{ - CurvesData, DefinitionSource, Effect as AepEffect, EffectDefinitions, EffectParam, HueSaturationData, Layer as AepLayer, LayerRef, LevelsData, MeshData, - ParamKind, ParamValue, + CurvesData, DefinitionSource, Effect as AepEffect, EffectDefinitions, EffectParam, ExtractorChannels, HueSaturationData, Layer as AepLayer, LayerRef, + LevelsData, MeshData, ParamKind, ParamValue, }; use effectcraft_keyframe::Value; use effectcraft_project::build::Ids; @@ -465,6 +465,40 @@ fn import_extra(fx: &AepEffect<'_, '_>, extra: Extra, p: &EffectParam<'_, '_>, h Some(m) => import_mesh(&m, here, size, group, col), None => col.lose(LossCategory::DamagedData, format!("{here}: the Distortion Mesh is unreadable, defaults used")), }, + Extra::Extractor => match ExtractorChannels::parse(data) { + // The fresh channels: EffectCraft's own R, G, B, A (its A is the input's alpha, After + // Effects' `(copy)`). + Some(c) if c.is_default() => { + for (id, name) in [("red", "R"), ("green", "G"), ("blue", "B"), ("alpha", "A")] { + if let Some(prop) = group.prop_mut(id) { + prop.value = Value::Str(name.into()); + } + } + } + Some(c) => { + let names: Vec<&str> = c.channels.iter().map(|(_, n)| n.as_str()).collect(); + col.lose( + LossCategory::Effects, + format!("{here}: the channels {} are not imported (only the default channels are sampled), R, G, B, A used", names.join(", ")), + ); + } + None => col.lose(LossCategory::Effects, format!("{here}: the Channel Info data is not in the sampled layout, R, G, B, A used")), + }, + Extra::Identifier => match crate::identifier_channel_type(data) { + Some("Object ID") => { + if let Some(prop) = group.prop_mut("channelType") { + prop.value = Value::Enum(0); + } + // The data names the type, not the channel After Effects reads: with this Channel + // Info After Effects left the sampled EXR unchanged, where EffectCraft draws the + // footage's object ID channel. + col.lose( + LossCategory::Effects, + format!("{here}: the channel IDentifier reads (Channel Info) is not decoded; EffectCraft uses the footage's object ID channel"), + ); + } + other => col.lose(LossCategory::Effects, format!("{here}: the channel type {other:?} is not imported (only Object ID is sampled), Object ID used")), + }, Extra::None => {} } } diff --git a/crates/aep/src/lib.rs b/crates/aep/src/lib.rs index c8b37d716..dba3136ee 100644 --- a/crates/aep/src/lib.rs +++ b/crates/aep/src/lib.rs @@ -14,11 +14,11 @@ pub mod import; pub use container::{ AepError, AepFile, AutoKern, BlendMode, Body, CURVE_IDENTITY, CameraPosition, Caps, Chunk, Comp, CompHeader, CueType, CurvesData, DEFAULT_CAMERA_ZOOM, - DefinitionSource, Effect, EffectDefinitions, EffectParam, ExpressionFlags, FontBaseline, Footage, GradientType, HueSaturationData, Interpolation, Item, - ItemKind, Justification, KernRun, KeyEase, KeyLayout, KeyList, Keyframe, KeyframeKind, LIST, Layer, LayerHeader, LayerRef, LayerType, LevelsData, - LightType, Limits, ListHeader, Marker, Mask, MaskAtom, MaskMode, MatteMode, MeshData, NESTED_IDS, Orientation, OrientationKey, ParagraphRun, ParamKind, - ParamValue, PathVertex, PolystarType, Project, ProjectSettings, PropEntry, PropGroup, PropNode, Property, Quality, Rational, Renderer, SequenceInfo, - ShapeDetail, ShapeGroup, ShapeItem, ShapePath, SpatialKey, Stroke, StrokeCap, StrokeJoin, StyleRun, TextBox, TextDocument, TextValue, TimeBase, - TimeDisplay, TimeRemap, TimeRemapKey, TrackMatte, Tracked, Transform, ValueSource, Walk, WorkingSpace, curve_lut, effect_map, is_aepx, parse, parse_any, - parse_text_dict, parse_with_limits, read_aepx, read_aepx_with_limits, style_map, write, write_to, + DefinitionSource, Effect, EffectDefinitions, EffectParam, ExpressionFlags, ExtractorChannels, FontBaseline, Footage, GradientType, HueSaturationData, + Interpolation, Item, ItemKind, Justification, KernRun, KeyEase, KeyLayout, KeyList, Keyframe, KeyframeKind, LIST, Layer, LayerHeader, LayerRef, LayerType, + LevelsData, LightType, Limits, ListHeader, Marker, Mask, MaskAtom, MaskMode, MatteMode, MeshData, NESTED_IDS, Orientation, OrientationKey, ParagraphRun, + ParamKind, ParamValue, PathVertex, PolystarType, Project, ProjectSettings, PropEntry, PropGroup, PropNode, Property, Quality, Rational, Renderer, + SequenceInfo, ShapeDetail, ShapeGroup, ShapeItem, ShapePath, SpatialKey, Stroke, StrokeCap, StrokeJoin, StyleRun, TextBox, TextDocument, TextValue, + TimeBase, TimeDisplay, TimeRemap, TimeRemapKey, TrackMatte, Tracked, Transform, ValueSource, Walk, WorkingSpace, curve_lut, effect_map, + identifier_channel_type, is_aepx, parse, parse_any, parse_text_dict, parse_with_limits, read_aepx, read_aepx_with_limits, style_map, write, write_to, }; diff --git a/crates/aep/tests/it/import.rs b/crates/aep/tests/it/import.rs index 178dd2bb3..a24f9af26 100644 --- a/crates/aep/tests/it/import.rs +++ b/crates/aep/tests/it/import.rs @@ -14,6 +14,7 @@ mod effects_batch5; mod effects_quickwins; mod effects_round2; mod effects_round3; +mod effects_thirdparty; mod fx_inject; mod markers; mod masks; diff --git a/crates/aep/tests/it/import/effects.rs b/crates/aep/tests/it/import/effects.rs index aa4180567..fbb28b406 100644 --- a/crates/aep/tests/it/import/effects.rs +++ b/crates/aep/tests/it/import/effects.rs @@ -72,7 +72,7 @@ fn the_table_names_tint_gradient_ramp_and_exposure() { ] { assert!(t.contains(&want), "{want:?}"); } - assert_eq!(t.len(), 62); + assert_eq!(t.len(), 65); for (_, id) in t { assert!(effectcraft_effects::find(id).is_some(), "{id}"); } diff --git a/crates/aep/tests/it/import/effects_thirdparty.rs b/crates/aep/tests/it/import/effects_thirdparty.rs new file mode 100644 index 000000000..20f0b8230 --- /dev/null +++ b/crates/aep/tests/it/import/effects_thirdparty.rs @@ -0,0 +1,179 @@ +//! CC Color Neutralizer, EXtractoR and IDentifier (#3112) arrive as EffectCraft's effects of the +//! same name. Each is built into `synthetic.aep` (`fx_inject`) with the definitions After Effects +//! 2026 wrote for it in the importer block of 2026-11-05 (`1300-thirdparty.aep`) and the values +//! of that block's compositions; the Channel Info data is laid out as those instances store it. + +use crate::import::fx_inject::{Default, Fx, losses, near, other, popup, run, slider, v}; +use effectcraft_aep::import::LossCategory; +use effectcraft_aep::{ExtractorChannels, ParamKind as K, identifier_channel_type}; +use effectcraft_keyframe::Value; + +fn neutralizer(values: Vec<(usize, f64)>) -> Fx { + let range = |name| slider(K::FloatSlider, name, 0.0, (-100.0, 100.0)); + let group = |name| other(K::GroupStart, name, Default::None); + let end = || other(K::GroupEnd, "", Default::None); + Fx { + match_name: "CS Color Neutralizer", + name: "CC Color Neutralizer", + defs: vec![ + other(K::Color, "Shadows Unbalance", Default::Color([0, 0, 0, 0])), + group("Shadows"), + range("Red - Shadows"), + range("Green - Shadows"), + range("Blue - Shadows"), + end(), + other(K::Color, "Midtones Unbalance", Default::Color([255, 127, 127, 127])), + group("Midtones"), + range("Red - Midtones"), + range("Green - Midtones"), + range("Blue - Midtones"), + end(), + other(K::Color, "Highlights Unbalance", Default::Color([255, 255, 255, 255])), + group("Highlights"), + range("Red - Highlights"), + range("Green - Highlights"), + range("Blue - Highlights"), + end(), + slider(K::FloatSlider, "Pinning", 0.0, (0.0, 100.0)), + slider(K::FloatSlider, "Blend w. Original", 0.0, (0.0, 100.0)), + group("Special"), + popup("View", 1, &["Final Result", "Correction B to W", "Correction Stair"]), + slider(K::FloatSlider, "Black Point", 0.0, (0.0, 49.9)), + slider(K::FloatSlider, "White Point", 100.0, (50.1, 100.0)), + end(), + ], + values, + data: vec![], + } +} + +#[test] +fn cc_color_neutralizer_pinning_and_blend() { + // `ccneutral-00-defaults` and the Pinning / Blend of `ccneutral-01-set-all`. + let (g, r) = run(&neutralizer(vec![(19, 16.0), (20, 19.0)]), "ec.color.cccolorneutralizer"); + assert_eq!(losses(&r, LossCategory::Effects, "CS Color Neutralizer"), Vec::::new()); + let g = g.expect("imported"); + near(&g, "pinning", 16.0); + near(&g, "blendWOriginal", 19.0); + // EffectCraft's own (identity) balance stays. + assert_eq!(v(&g, "midtonesUnbalance"), v(&g, "midtonesBalance")); +} + +#[test] +fn cc_color_neutralizer_corrections_without_a_counterpart_are_reported() { + // `ccneutral-03-sec-shadows`, `ccneutral-09-pop22-2`, `ccneutral-06-sec-special`. + let (g, r) = run(&neutralizer(vec![(3, 13.0), (4, 16.0), (5, 19.0), (22, 2.0), (23, 10.0), (24, 87.0)]), "ec.color.cccolorneutralizer"); + let found = losses(&r, LossCategory::Effects, "CS Color Neutralizer"); + for name in ["Red - Shadows", "Green - Shadows", "Blue - Shadows", "View", "Black Point", "White Point"] { + assert!(found.iter().any(|d| d.contains(&format!("parameter {name} (")) && d.contains("not imported")), "{name}: {found:?}"); + } + assert_eq!(found.len(), 6, "{found:?}"); + assert!(g.is_some(), "the effect itself is imported"); +} + +/// EXtractoR's Channel Info data with these record kinds and names. +fn channels(recs: [(u32, &str); 4]) -> Vec { + let mut d = vec![0u8; ExtractorChannels::LEN]; + d[..4].copy_from_slice(&1u32.to_le_bytes()); + for (k, (kind, name)) in recs.iter().enumerate() { + let at = 32 + k * 164; + d[at..at + 4].copy_from_slice(&kind.to_le_bytes()); + d[at + 35..at + 35 + name.len()].copy_from_slice(name.as_bytes()); + } + d +} + +const DEFAULT_CHANNELS: [(u32, &str); 4] = [(1, "R"), (1, "G"), (1, "B"), (2, "(copy)")]; + +fn extractor(values: Vec<(usize, f64)>, data: Vec) -> Fx { + let mut values = values; + values.insert(0, (1, 0.0)); + Fx { + match_name: "EXtractoR", + name: "EXtractoR", + defs: vec![ + other(K::ArbitraryData, "Channel Info", Default::None), + other(K::GroupStart, "Process", Default::None), + slider(K::FloatSlider, "Black Point", 0.0, (-f64::from(f32::MAX), f64::from(f32::MAX))), + slider(K::FloatSlider, "White Point", 1.0, (-f64::from(f32::MAX), f64::from(f32::MAX))), + other(K::Checkbox, "", Default::Number(0.0)), + other(K::GroupEnd, "", Default::None), + ], + values, + data: vec![(1, data)], + } +} + +#[test] +fn extractor_channel_info_layout() { + let c = ExtractorChannels::parse(&channels(DEFAULT_CHANNELS)).expect("the default layout"); + assert!(c.is_default()); + let c = ExtractorChannels::parse(&channels([(1, "Z"), (1, "G"), (1, "B"), (2, "(copy)")])).expect("parses"); + assert!(!c.is_default()); + assert_eq!(c.channels[0], (1, "Z".to_string())); + assert_eq!(ExtractorChannels::parse(&[0u8; 10]), None); +} + +#[test] +fn extractor_points_unmult_and_default_channels() { + // `extractor-01-set-all`: Black Point 10, White Point 14, UnMult on. + let (g, r) = run(&extractor(vec![(3, 10.0), (4, 14.0), (5, 1.0)], channels(DEFAULT_CHANNELS)), "ec.3d.extractor"); + assert_eq!(losses(&r, LossCategory::Effects, "EXtractoR"), Vec::::new()); + let g = g.expect("imported"); + near(&g, "blackPoint", 10.0); + near(&g, "whitePoint", 14.0); + assert_eq!((v(&g, "unMult"), v(&g, "clip")), (Value::Bool(true), Value::Bool(false))); + // After Effects' `(copy)` Alpha is the input's alpha: EffectCraft's A. + for (id, want) in [("red", "R"), ("green", "G"), ("blue", "B"), ("alpha", "A")] { + assert_eq!(v(&g, id), Value::Str(want.into()), "{id}"); + } +} + +#[test] +fn extractor_channels_other_than_the_default_are_reported() { + let (g, r) = run(&extractor(vec![], channels([(1, "Z"), (1, "Z"), (1, "Z"), (2, "(copy)")])), "ec.3d.extractor"); + let found = losses(&r, LossCategory::Effects, "EXtractoR"); + assert!(found.len() == 1 && found[0].contains("the channels Z, Z, Z, (copy) are not imported"), "{found:?}"); + assert_eq!(v(&g.expect("imported"), "red"), Value::Str("R".into())); +} + +/// IDentifier's Channel Info: the channel type's name at 19 among bytes that are not read. +fn id_info(name: &str) -> Vec { + let mut d: Vec = (0..148u32).map(|i| (i * 37 % 251) as u8 | 1).collect(); + d[19..19 + name.len()].copy_from_slice(name.as_bytes()); + d[19 + name.len()] = 0; + d +} + +fn identifier(values: Vec<(usize, f64)>, data: Vec) -> Fx { + let mut values = values; + values.insert(0, (1, 0.0)); + Fx { + match_name: "IDentifier", + name: "IDentifier", + defs: vec![ + other(K::ArbitraryData, "Channel Info", Default::None), + popup("Display", 1, &["Colors", "Luma Matte", "Alpha Matte", "Raw"]), + slider(K::IntSlider, "ID", 0.0, (0.0, 2_147_483_647.0)), + ], + values, + data: vec![(1, data)], + } +} + +#[test] +fn identifier_display_id_and_channel_type() { + assert_eq!(identifier_channel_type(&id_info("Object ID")), Some("Object ID")); + // `identifier-01-set-all` (ID 10) and `identifier-05-pop2-3` (Alpha Matte). + let (g, r) = run(&identifier(vec![(2, 3.0), (3, 10.0)], id_info("Object ID")), "ec.3d.identifier"); + // Which channel After Effects reads is not decoded (it left the sampled EXR unchanged): reported. + let found = losses(&r, LossCategory::Effects, "IDentifier"); + assert!(found.len() == 1 && found[0].contains("is not decoded"), "{found:?}"); + let g = g.expect("imported"); + assert_eq!((v(&g, "display"), v(&g, "channelType")), (Value::Enum(2), Value::Enum(0))); + near(&g, "id", 10.0); + // A channel type that is not sampled is reported. + let (_, r) = run(&identifier(vec![], id_info("Material ID")), "ec.3d.identifier"); + let found = losses(&r, LossCategory::Effects, "IDentifier"); + assert!(found.len() == 1 && found[0].contains("\"Material ID\""), "{found:?}"); +} diff --git a/docs/aep-format.md b/docs/aep-format.md index 32ec74854..29ee51963 100644 --- a/docs/aep-format.md +++ b/docs/aep-format.md @@ -533,6 +533,22 @@ compositions, the items from one composition per popup item).** Each set value i | `ADBE Offset` | 1 Shift Center To: point, default the layer centre; 2 Blend With Original: fixed, **max 1 (a 0..1 fraction)**, default 0 | | `ADBE Deflicker` (Color Stabilizer) | 1 Stabilize: popup (Brightness, Levels, Curves), **default 2 (Levels)**; 2 Black Point, 3 Mid Point, 4 White Point: points, defaults 0.2 / 0.5 / 0.8 of the width at half the height; 5 Sample Size: fixed, max 50, default 3. The reference frame the Set Frame button picks is not among the parameters | +**Importer block 2026-11-05, #3112 (`1300-thirdparty.aep`; V for the parameter lists, H for the +data layouts, read from default instances only):** + +| Effect (match name, plug-in version) | Parameters (`parT` index: type, valid range, default) | +|---|---| +| `CS Color Neutralizer` (CC Color Neutralizer, 1.3) | 1 / 7 / 13 Shadows / Midtones / Highlights Unbalance: colours (black, 127 grey, white; pickers: setting one sets the range's sliders, e.g. [0.27, 0.55, 0.85] gives Red 42.94, Green 1.18, Blue -44.12 = (mean - channel) x 150 / 255 on 8-bit values, and leaves no colour record); 2-6, 8-12, 14-18 a group per range (start, Red, Green, Blue, end) with float sliders -100..100 (slider -50..50), default 0; 19 Pinning: float 0..100 (slider 0..50); 20 Blend w. Original: float 0..100; 21-25 the Special group: 22 View popup (Final Result, Correction B to W, Correction Stair), default 1, 23 Black Point float 0..49.9, default 0, 24 White Point float 50.1..100, default 100 | +| `EXtractoR` (2.6.6) | 1 Channel Info (`EXtractoR-0013`): arbitrary data, 688 bytes, below; 2-6 the Process group: 3 Black Point and 4 White Point float sliders, valid ±3.4028235e38 (the float32 range; slider ±1 000), default 0 / 1; 5 UnMult: checkbox (empty `pard` name, the label in `pdnm`), default off | +| `IDentifier` (2.6.6) | 1 Channel Info (`IDentifier-0005`): arbitrary data, 148 bytes, below; 2 Display: popup (Colors, Luma Matte, Alpha Matte, Raw), default 1; 3 ID: integer slider, max 2 147 483 647, default 0 | + +EXtractoR's Channel Info is the plug-in's own **little-endian** layout: `u32` 1 and 28 zero bytes, +then four 164-byte records (Red, Green, Blue, Alpha), each a `u32` kind (1 in R, G, B; 2 in Alpha, +whose name is `(copy)`) and the channel name NUL-terminated from record byte 35 (`R`, `G`, `B`). +The data is the same in every composition of the block. IDentifier's data differs between +instances with the same settings except for the channel type's name, NUL-terminated from byte 19 +(`Object ID`); the other bytes are not read. API: `ExtractorChannels`, `identifier_channel_type`. + **Curves and Mesh Warp** (961-965, 985; applied from presets, the data is not scriptable): their arbitrary-data parameter (type 11) always has a record (`tdbs` with a 4-byte `cdat`) and a `LIST aRbs` / `aRbp`, also at the default. Curves (`ADBE CurvesCustom-0001`, 1644 bytes): `u16` 1, 1; diff --git a/docs/aep-import.md b/docs/aep-import.md index 1926274f0..f14141156 100644 --- a/docs/aep-import.md +++ b/docs/aep-import.md @@ -179,6 +179,7 @@ parameter gets the file's value: | `ADBE Easy Levels2` 1 Channel, 2 Histogram data, 8 / 9 Clip To Output Black / White | `channel`; `inBlack`, `inWhite`, `gamma`, `outBlack`, `outWhite` from the data; `clipToOutputBlack`, `clipToOutputWhite` | popups by name (After Effects' items On, Off, Off for 32 bpc Color are in another order here); the RGB values are the `f32` of the arbitrary data; the per-channel values are reported when they are not at their defaults (not sampled) | 511-516 | | Batch 6 (903 defaults, 904 / 905 set values): `ADBE Brightness & Contrast 2`, `ADBE Turbulent Displace`, `ADBE Fractal Noise`, `ADBE Laser` (Beam), `CC Radial Fast Blur`, `ADBE Noise2`, `ADBE Pro Levels2` (Levels (Individual Controls)), `ADBE Corner Pin`, `ADBE Grid`, `ADBE Sharpen`, `ADBE Linear Color Key2`, `ADBE Radial Wipe`, `ADBE Remove Color Matting`, `CC Bend It`, `CC Power Pin`, `ADBE 4ColorGradient`, `ADBE Change Color`, `ADBE Extract`, `ADBE Noise HLS2`, `ADBE Scatter`, `CC Light Sweep`, `ADBE Compound Blur`, `ADBE Displacement Map`, `ADBE Set Matte3`, `ADBE Gaussian Blur` (legacy), `ADBE OFMotionBlur` (Pixel Motion Blur), `ADBE Layer Control` | the EffectCraft effect of the same name, every parameter EffectCraft has | sliders as stored (each checked against its valid maximum); Beam Length, Time and Softness and CC Power Pin Perspective are 0..1 fractions, percentages here; points as layer pixels; popups by item name (Set Matte's `Red Channel` ... is `Red` ...); twirl-down group markers and the Levels histogram carry nothing; **layer parameters** (below) | 903, 904, 905; 220, 320, 321 | | Importer block 2026-11-05 (`1100-quickwins.aep`: per effect defaults, set values, minimum and maximum, every popup item, a keyed and an expression parameter): `ADBE HDR ToneMap` (HDR Highlight Compression) 1 Amount; `ADBE Echo` 1 Echo Time, 2 Number Of Echoes, 3 Starting Intensity, 4 Decay, 5 Echo Operator; `ADBE Linear Wipe` 1 Transition Completion, 2 Wipe Angle, 3 Feather; `ADBE Offset` 1 Shift Center To, 2 Blend With Original; `ADBE Deflicker` (Color Stabilizer) 1 Stabilize, 2-4 Black / Mid / White Point, 5 Sample Size | `ec.utility.hdrcompression` `amount`; `ec.time.echo` `echoTime`, `numberOfEchoes`, `startingIntensity`, `decay`, `echoOperator`; `ec.transition.linearwipe` `completion`, `angle`, `feather`; `ec.distort.offset` `shift`, `blend`; `ec.color.colorstabilizer` `stabilize`, `blackPoint`, `midPoint`, `whitePoint`, `sampleSize` | percent (float, valid 0..100, default 100); seconds (float, valid ±30 000), integer (valid 30 000), 0..1 (float), Decay as stored (float, valid 0..100), popup by name: EffectCraft's Echo uses at most 255 echoes and a Decay up to 1, a value or key beyond that is imported as stored and **reported**; percent (fixed, 100), degrees, pixels (fixed, 32 000); point in layer pixels, Blend 0..1 x 100 = percent; popup by name (**fresh default Levels**), points in layer pixels, Sample Size as stored (fixed, valid 50, default 3; its unit, pixels here, is not verified). Color Stabilizer's reference frame (Set Frame) is not a parameter in the file and is not imported (EffectCraft's Reference Frame stays 0 s) | `tests/it/import/effects_quickwins.rs`; render comparison below | +| Importer block 2026-11-05 (`1300-thirdparty.aep`), plug-ins that ship with After Effects: `CS Color Neutralizer` (CC Color Neutralizer) 19 Pinning, 20 Blend w. Original; `EXtractoR` 1 Channel Info data, 3 Black Point, 4 White Point, 5 UnMult; `IDentifier` 1 Channel Info data, 2 Display, 3 ID | `ec.color.cccolorneutralizer` `pinning`, `blendWOriginal`; `ec.3d.extractor` `red`, `green`, `blue`, `alpha`, `blackPoint`, `whitePoint`, `unMult`; `ec.3d.identifier` `channelType`, `display`, `id` | CC Color Neutralizer: percent (float, valid 100); its correction is the Red / Green / Blue slider of each range (the Unbalance colours are pickers that set them and keep no record), with View and Black / White Point: **EffectCraft's effect has no counterpart, each is reported when stored** (EffectCraft's Unbalance / Balance stay at their identity defaults). EXtractoR: the default channels (R, G, B, `(copy)`) are EffectCraft's R, G, B, A, other channels are reported (`ExtractorChannels`; only the default is sampled), Black and White Point as stored (float, valid ±3.4e38; a value beyond ±1e9 is reported as damaged data, as for every number), UnMult a checkbox, Clip stays off. IDentifier: Display by name, ID as stored (integer, valid 2 147 483 647); the Channel Info names only the channel type (Object ID, `identifier_channel_type`; another is reported), not the channel After Effects reads, so **every instance is reported**: EffectCraft draws the footage's object ID channel where After Effects left the sampled EXR unchanged | `tests/it/import/effects_thirdparty.rs`; render comparison below | | `ADBE Slider Control`, `ADBE Angle Control`, `ADBE Checkbox Control`, `ADBE Color Control`, `ADBE Point Control` (parameter 1) | `ec.control.slider` `slider`, `ec.control.angle` `angle`, `ec.control.checkbox` `checkbox`, `ec.control.color` `color`, `ec.control.point` `point` | float (valid max 1 000 000) as stored; degrees; checkbox; colour; point in layer pixels | 071, 073, 217-219, 221, 304, 310 | - **Nothing to import:** the implicit input-layer parameter (index 0), the Swap Colors buttons @@ -325,6 +326,18 @@ frame blending, 3D material options, audio levels, guides, the mask colour, lock over 25 (EffectCraft's samples drift, After Effects' frame stays unchanged) and with keyed sample points. The renders do not exercise a Decay above 1 (After Effects' set value has Starting Intensity 0) or what Color Stabilizer corrects (the test card does not flicker). +- `crates/aep/tests/it/import/effects_thirdparty.rs` (#3112): CC Color Neutralizer, EXtractoR and + IDentifier built into `synthetic.aep` like the #3110 effects. Render check of the 29 compositions + of `1300-thirdparty.aep` (as above): CC Color Neutralizer at its defaults and the minimum and + maximum compositions match within one level (no composition isolates Pinning: the maximum has + Blend w. Original 100, which shows the original), the compositions with reported Red / + Green / Blue corrections or View differ as reported (up to 5 levels, View 25); EXtractoR at its + defaults and with UnMult within 3 levels on 6 % of the pixels, keyed and expression Black Point + within one level, the ±3.4e38 compositions differ (reported as damaged data). IDentifier: After + Effects' frame is the unchanged EXR in every variant (its default Object ID finds no channel in + that EXR), while EffectCraft's IDentifier finds the EXR's `ID` channel and draws it; the import + reports this for every IDentifier. No sample changes EXtractoR's channels or IDentifier's channel + type (the presets for that were missing from the block). - `crates/aep/tests/it/import/combined.rs`: masks and effects on the same layer, an effect on a text layer, and the same through `.aepx` (built in-test from the fixtures: the effect parade of one fixture grafted onto the layer of another). From ce3a5b3673a17dd0c766c322c19f551ad9eae9a3 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Thu, 5 Nov 2026 15:23:55 +0100 Subject: [PATCH 03/40] AEP import: map Lumetri Color (ADBE Lumetri) to EffectCraft's Lumetri Color The importer now converts After Effects' Lumetri Color. Its parameters are found by match-name suffix, not by parT index: After Effects inserted -0127 ... -0130 mid-list and five tone sliders share one valid range. - Values are read from every value record, also those in the default state (tdsb 3), where Lumetri keeps High Dynamic Range, HDR Specular and the second Look popup (EffectParam::recorded_value; stored_value is unchanged). - A switched-off section, and HSL Secondary without a picked key colour, draws nothing in After Effects: its set values are reported in one line and not imported. - The HSL key data is decoded into hue / saturation / lightness ranges. - LUTs and Looks (by name), controls without a counterpart, eyedropper colours and undecoded curves, wheels and Split Toning are reported. - EffectCraft's Lumetri sliders take After Effects' valid ranges. - import_param is split into lookup plus import_mapped for reuse. Evidence: 1200 samples (After Effects 2026). The 62 read-backs of mapped controls in sections that act equal the imported values. The other 61 lie in sections that do nothing and are reported. Renders of identity grades are within 1/255. Part of #3111 Co-Authored-By: Claude Opus 5.5 --- crates/aep/src/container/effect_map.rs | 6 + crates/aep/src/container/effects.rs | 15 +- crates/aep/src/import.rs | 1 + crates/aep/src/import/effects.rs | 56 ++- crates/aep/src/import/lumetri.rs | 642 +++++++++++++++++++++++++ crates/aep/tests/it/import.rs | 1 + crates/aep/tests/it/import/effects.rs | 2 +- crates/aep/tests/it/import/lumetri.rs | 448 +++++++++++++++++ crates/effects/src/color3.rs | 41 +- docs/aep-format.md | 38 ++ docs/aep-import.md | 29 +- docs/file-format-parity.md | 2 +- 12 files changed, 1244 insertions(+), 37 deletions(-) create mode 100644 crates/aep/src/import/lumetri.rs create mode 100644 crates/aep/tests/it/import/lumetri.rs diff --git a/crates/aep/src/container/effect_map.rs b/crates/aep/src/container/effect_map.rs index a7c9bbd48..312332e8f 100644 --- a/crates/aep/src/container/effect_map.rs +++ b/crates/aep/src/container/effect_map.rs @@ -134,6 +134,9 @@ pub enum Extra { Curves, /// Mesh Warp's Distortion Mesh (965, 985, `MeshData`). MeshWarp, + /// Lumetri Color: every parameter goes through its own table, keyed by match name + /// (`import/lumetri.rs`, 1200). + Lumetri, } /// One mapped effect. @@ -509,6 +512,9 @@ pub const EFFECTS: &[EffectMap] = &[ ], extra: Extra::MeshWarp, }, + // Lumetri Color (1200): the parameters are mapped by match name, not by `parT` index + // (`import/lumetri.rs`). + EffectMap { match_name: "ADBE Lumetri", effect: "ec.color.lumetri", params: &[], extra: Extra::Lumetri }, // Expression controls (070-077, 217-221, 310). // Directional Blur (711): Direction in degrees, Blur Length in pixels (valid max 1 000). fx( diff --git a/crates/aep/src/container/effects.rs b/crates/aep/src/container/effects.rs index df1c2b9c1..597710587 100644 --- a/crates/aep/src/container/effects.rs +++ b/crates/aep/src/container/effects.rs @@ -375,11 +375,24 @@ impl<'f, 'a> EffectParam<'f, 'a> { /// colours, popups and layer controls. A record counts when its `tdsb` is 1 and it has no /// keyframes; a layer control reads the `tdpi` chunk; a button has no value. pub fn stored_value(&self) -> Option { + let p = self.stored?; + if self.kind != ParamKind::Layer && p.flags() != Some(1) { + return None; + } + self.recorded_value() + } + + /// The value in the value record whatever the record's state (`tdsb`): what + /// [`EffectParam::stored_value`] reads, also from a record in the default state (`tdsb` 3). + /// Lumetri Color writes the values of its hidden parameters so (High Dynamic Range, HDR + /// Specular, Look: 1200 `lumetri-01-set-all`, `-02-sec-top`, `-06-sec-light`; After Effects + /// reads back the recorded values). `None` with keyframes or without a record. + pub fn recorded_value(&self) -> Option { let p = self.stored?; if self.kind == ParamKind::Layer { return be_u32(p.chunk().child(b"tdpi")?.bytes()?, 0).map(ParamValue::Layer); } - if p.flags() != Some(1) || p.is_animated() { + if p.is_animated() { return None; } let v = p.static_value()?; diff --git a/crates/aep/src/import.rs b/crates/aep/src/import.rs index 1ffe3ec48..eb4eee8c8 100644 --- a/crates/aep/src/import.rs +++ b/crates/aep/src/import.rs @@ -27,6 +27,7 @@ mod build; mod camera; mod effects; +mod lumetri; mod markers; mod masks; mod props; diff --git a/crates/aep/src/import/effects.rs b/crates/aep/src/import/effects.rs index 477a25df4..2ef912e00 100644 --- a/crates/aep/src/import/effects.rs +++ b/crates/aep/src/import/effects.rs @@ -34,7 +34,7 @@ //! import. Hue/Saturation's master values and Levels' values are arbitrary data, decoded by the //! reader (444-446, 512-516). -use crate::effect_map::{Conv, EFFECTS, EffectMap, Extra, HUE_SATURATION_MASTER, LEVELS_RGB, popup_key}; +use crate::effect_map::{Conv, EFFECTS, EffectMap, Extra, HUE_SATURATION_MASTER, LEVELS_RGB, ParamMap, popup_key}; use crate::{ CurvesData, DefinitionSource, Effect as AepEffect, EffectDefinitions, EffectParam, HueSaturationData, Layer as AepLayer, LayerRef, LevelsData, MeshData, ParamKind, ParamValue, @@ -99,8 +99,12 @@ pub(crate) fn import_effects<'f, 'a>( None => col.lose(LossCategory::DamagedData, format!("{}: '{}': the fx switch of '{shown}' is unreadable, imported switched on", cx.comp, cx.layer)), } let params = defs.params(&fx); - for p in ¶ms { - import_param(&fx, map, p, cx, &shown, ParamOut { group: &mut group, refs: &mut *refs, col: &mut *col }); + if map.extra == Extra::Lumetri { + crate::import::lumetri::import_lumetri(&fx, ¶ms, cx, &shown, ParamOut { group: &mut group, refs: &mut *refs, col: &mut *col }); + } else { + for p in ¶ms { + import_param(&fx, map, p, cx, &shown, ParamOut { group: &mut group, refs: &mut *refs, col: &mut *col }); + } } col.imported.effects = col.imported.effects.saturating_add(1); target.children.push(Node::Group(group)); @@ -108,7 +112,7 @@ pub(crate) fn import_effects<'f, 'a>( } /// Parameters that never carry a value to import. -fn carries_nothing(p: &EffectParam<'_, '_>) -> bool { +pub(crate) fn carries_nothing(p: &EffectParam<'_, '_>) -> bool { matches!(p.kind, ParamKind::Button | ParamKind::NoData | ParamKind::GroupStart | ParamKind::GroupEnd) || (p.index == 0 && p.kind == ParamKind::Layer) } @@ -127,10 +131,15 @@ pub(crate) struct PendingLayerRef { /// Where a parameter is imported to: the effect's group, the layer parameters still to resolve /// and the report. -struct ParamOut<'a> { - group: &'a mut PropGroup, - refs: &'a mut Vec, - col: &'a mut Collector, +pub(crate) struct ParamOut<'a> { + pub group: &'a mut PropGroup, + pub refs: &'a mut Vec, + pub col: &'a mut Collector, +} + +/// How a parameter is named in the report: its name and match name. +pub(crate) fn param_label(p: &EffectParam<'_, '_>) -> String { + if p.name.trim().is_empty() { p.match_name.clone() } else { format!("{} ({})", p.name.trim(), p.match_name) } } fn import_param(fx: &AepEffect<'_, '_>, map: &EffectMap, p: &EffectParam<'_, '_>, cx: &LayerCtx<'_>, shown: &str, out: ParamOut<'_>) { @@ -138,7 +147,7 @@ fn import_param(fx: &AepEffect<'_, '_>, map: &EffectMap, p: &EffectParam<'_, '_> if carries_nothing(p) { return; } - let label = if p.name.is_empty() { p.match_name.clone() } else { format!("{} ({})", p.name, p.match_name) }; + let label = param_label(p); let here = format!("{}: '{}' effect '{shown}' ({})", cx.comp, cx.layer, fx.match_name()); if p.kind == ParamKind::ArbitraryData && map.extra != Extra::None { import_extra(fx, map.extra, p, &here, cx.size, group, col); @@ -152,6 +161,27 @@ fn import_param(fx: &AepEffect<'_, '_>, map: &EffectMap, p: &EffectParam<'_, '_> } return; }; + import_mapped(p, m, cx, (&here, &label), ParamOut { group, refs, col }, ValueRecord::Written); +} + +/// Which value records count. +#[derive(Clone, Copy, PartialEq, Eq)] +pub(crate) enum ValueRecord { + /// Only written records (`tdsb` 1, [`EffectParam::stored_value`]). + Written, + /// Every record, also one in the default state (Lumetri Color, [`EffectParam::recorded_value`]). + Any, +} + +/// Imports parameter `p` into the property `m` names, converted by `m.conv`. `names` is +/// `(here, label)`, the effect and the parameter for the report. +pub(crate) fn import_mapped(p: &EffectParam<'_, '_>, m: &ParamMap, cx: &LayerCtx<'_>, names: (&str, &str), out: ParamOut<'_>, records: ValueRecord) { + let (here, label) = names; + let ParamOut { group, refs, col } = out; + let read = |p: &EffectParam<'_, '_>| match records { + ValueRecord::Written => p.stored_value(), + ValueRecord::Any => p.recorded_value(), + }; if p.kind != m.kind { col.lose(LossCategory::Effects, format!("{here}: parameter {label} has type {:?}, expected {:?}; not imported", p.kind, m.kind)); return; @@ -159,7 +189,7 @@ fn import_param(fx: &AepEffect<'_, '_>, map: &EffectMap, p: &EffectParam<'_, '_> match m.conv { Conv::Skip => return, Conv::LayerRef { own } => { - import_layer_ref(p, m.target, own, cx, (&here, &label), ParamOut { group, refs, col }); + import_layer_ref(p, m.target, own, cx, (here, label), ParamOut { group, refs, col }); return; } _ => {} @@ -264,12 +294,12 @@ fn import_param(fx: &AepEffect<'_, '_>, map: &EffectMap, p: &EffectParam<'_, '_> col.lose(LossCategory::DamagedData, format!("{here}: parameter {label} has no readable keyframe, default used")); } if let Some(map) = &popup_map { - remap_popup_keys(prop, map, &here, &label, col); + remap_popup_keys(prop, map, here, label, col); } } return; } - let value = match (p.stored(), p.stored_value()) { + let value = match (p.stored(), read(p)) { (Some(_), Some(v)) => Some(v), (Some(_), None) => { col.lose(LossCategory::DamagedData, format!("{here}: parameter {label} holds an unreadable value, default used")); @@ -451,7 +481,7 @@ fn import_extra(fx: &AepEffect<'_, '_>, extra: Extra, p: &EffectParam<'_, '_>, h Some(m) => import_mesh(&m, here, size, group, col), None => col.lose(LossCategory::DamagedData, format!("{here}: the Distortion Mesh is unreadable, defaults used")), }, - Extra::None => {} + Extra::None | Extra::Lumetri => {} } } diff --git a/crates/aep/src/import/lumetri.rs b/crates/aep/src/import/lumetri.rs new file mode 100644 index 000000000..22f28b1aa --- /dev/null +++ b/crates/aep/src/import/lumetri.rs @@ -0,0 +1,642 @@ +//! Lumetri Color (`ADBE Lumetri`) to EffectCraft's Lumetri Color (`ec.color.lumetri`). +//! +//! The parameters are found by their match name (`ADBE Lumetri-0011` is Exposure), not by their +//! place in `parT`: After Effects has added parameters in the middle of the list over the +//! versions (`-0127` ... `-0130` sit between older ones), and several sliders share a valid range +//! (Contrast, Highlights, Shadows, Whites and Blacks are all -150..150), so a shifted index +//! would map silently to the wrong control. Evidence: the 1200 samples (After Effects 2026, +//! `docs/aep-format.md` 3.7). +//! +//! - **Values in any record state.** Lumetri writes the values of its hidden controls (High +//! Dynamic Range, HDR Specular, the second Look popup, ...) in records in the default state +//! (`tdsb` 3); After Effects reads them back as set, so every record counts here +//! ([`EffectParam::recorded_value`]). +//! - **Section switches.** Each section (Basic Correction, Creative, Curves, RGB Curves, the five +//! hue / saturation curves, Color Wheels, HSL Secondary, Vignette) has an on / off checkbox in +//! After Effects; EffectCraft's Lumetri has none. A section that is off does nothing in After +//! Effects (1200 `lumetri-03-sec-basic-correction`, `-17-sec-vignette` render as `-00-defaults`), +//! so its values are not imported (the effect looks the same) and are listed in the report. +//! - **Arbitrary data** (`ParamKind::ArbitraryData`, every instance stores it): the hue / +//! saturation curves (a curve type, a point count, points as `f64` x, y with y an offset from +//! neutral) are imported when neutral and reported otherwise (no sample moves a point); the +//! HSL Secondary key ([`HslKey`]) is imported; the RGB curves, the colour wheels, Split Toning +//! and the correction wheels are reported when they are not the default (not sampled). +//! - **LUTs and looks.** The Input LUT and the Look are files After Effects names (the Look's name +//! is UTF-16 text in `-0096`, the popups only index a list of the installed ones); they are not +//! in the project, so a set one is reported by name and EffectCraft's popup stays None. +//! - **Eyedropper colours** (White Balance, the hue curve selectors, the key's Set / Add / +//! Remove colours) only set other controls in After Effects; they are reported when set. +//! - The `Blob` (`-0001`, an XML copy of the grade After Effects writes when a Look changes and does +//! not keep current: 1200 `-01-set-all` holds the defaults of controls set after the Look) and +//! the Auto Tone analysis (`-0121`, `-0122`) are derived data and not read. + +use crate::effect_map::{Conv, ParamMap}; +use crate::{Effect as AepEffect, EffectParam, ParamKind, ParamValue}; +use effectcraft_keyframe::Value; + +use crate::import::effects::{LayerCtx, ParamOut, ValueRecord, carries_nothing, import_mapped, param_label}; +use crate::import::report::LossCategory; +use ParamKind as K; + +/// After Effects' Show Mask styles (`-0075`, `pdnm`), EffectCraft's in the same order. +pub const MASK_STYLE: &[&str] = &["Color/Gray", "Color/Black", "White/Black"]; + +/// A part of the effect with its own on / off switch. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Section { + /// No switch (High Dynamic Range and the controls outside the sections). + Always, + BasicCorrection, + Creative, + RgbCurves, + /// The five hue / saturation curves (0 Hue vs Sat ... 4 Sat vs Sat). + HueSat(u8), + ColorWheels, + HslSecondary, + Vignette, + SpeedGradeCustom, +} + +impl Section { + fn name(self) -> &'static str { + match self { + Section::Always => "", + Section::BasicCorrection => "Basic Correction", + Section::Creative => "Creative", + Section::RgbCurves => "RGB Curves", + Section::HueSat(0) => "Hue vs Sat", + Section::HueSat(1) => "Hue vs Hue", + Section::HueSat(2) => "Hue vs Luma", + Section::HueSat(3) => "Luma vs Sat", + Section::HueSat(_) => "Sat vs Sat", + Section::ColorWheels => "Color Wheels", + Section::HslSecondary => "HSL Secondary", + Section::Vignette => "Vignette", + Section::SpeedGradeCustom => "SpeedGrade Custom", + } + } +} + +/// Arbitrary data the importer reads. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Data { + /// The four RGB curves (4 x 520 bytes). + RgbCurves, + /// One hue / saturation curve (520 bytes); the EffectCraft parameter it belongs to. + HueSatCurve, + /// Color Wheels (4 x 3 `f64`, each wheel 0, 0.5, 0 by default). + Wheels, + /// HSL Secondary's correction wheels (8 x 3 `f64`, the same default). + CorrectionWheels, + /// Split Toning (32 zero bytes by default). + SplitToning, + /// HSL Secondary's key ([`HslKey`]). + HslKey, + /// Data without a counterpart, empty by default (`fe fe` or zero bytes). + Other, +} + +/// What a Lumetri parameter is. +#[derive(Clone, Copy, Debug)] +enum Role { + /// An EffectCraft parameter and the conversion. + To(&'static str, Conv), + /// The on / off switch of a section. + Switch, + /// No counterpart: reported when not at the default. + Missing, + /// An eyedropper colour: reported when set. + Eyedropper, + /// The Input LUT (`lut` true) or the Look: a popup, a name or an asset. + Lut { + lut: bool, + }, + /// The Look's colour space (its popup and the space's id): goes with the Look. + LookSpace, + Data(Data), + /// Derived data, not read. + Derived, +} + +struct Row { + suffix: u16, + section: Section, + kind: Option, + role: Role, +} + +const fn row(suffix: u16, section: Section, kind: Option, role: Role) -> Row { + Row { suffix, section, kind, role } +} + +const fn to(suffix: u16, section: Section, kind: ParamKind, target: &'static str, conv: Conv) -> Row { + row(suffix, section, Some(kind), Role::To(target, conv)) +} + +const fn plain(valid_max: f64) -> Conv { + Conv::Plain { valid_max } +} + +use Section as S; + +/// Every Lumetri parameter by match-name suffix (1200: `dump.props` and the `pard` of +/// `lumetri-00-defaults`). The valid maxima are After Effects 2026's; the stored numbers are the +/// values After Effects shows (read back in every variant). +const ROWS: &[Row] = &[ + to(62, S::Always, K::Checkbox, "highDynamicRange", Conv::Checkbox), + // Basic Correction: 3 the switch; 4 / 95 the Input LUT's name data, 5 / 127 its popups. + row(3, S::BasicCorrection, Some(K::Checkbox), Role::Switch), + row(4, S::BasicCorrection, Some(K::ArbitraryData), Role::Lut { lut: true }), + row(95, S::BasicCorrection, Some(K::ArbitraryData), Role::Lut { lut: true }), + row(5, S::BasicCorrection, Some(K::Popup), Role::Lut { lut: true }), + row(127, S::BasicCorrection, Some(K::Popup), Role::Lut { lut: true }), + to(63, S::BasicCorrection, K::FloatSlider, "basicCorrection/tone/hdrWhite", plain(1000.0)), + // The Auto tone's Intensity (next to the Auto and Reset buttons 120, 119). + row(123, S::BasicCorrection, Some(K::FloatSlider), Role::Missing), + row(94, S::BasicCorrection, Some(K::Color), Role::Eyedropper), + to(7, S::BasicCorrection, K::FloatSlider, "basicCorrection/whiteBalance/temperature", plain(300.0)), + to(8, S::BasicCorrection, K::FloatSlider, "basicCorrection/whiteBalance/tint", plain(300.0)), + to(20, S::BasicCorrection, K::FloatSlider, "basicCorrection/saturation", plain(300.0)), + to(11, S::BasicCorrection, K::FloatSlider, "basicCorrection/tone/exposure", plain(7.0)), + to(12, S::BasicCorrection, K::FloatSlider, "basicCorrection/tone/contrast", plain(150.0)), + to(13, S::BasicCorrection, K::FloatSlider, "basicCorrection/tone/highlights", plain(150.0)), + to(14, S::BasicCorrection, K::FloatSlider, "basicCorrection/tone/shadows", plain(150.0)), + to(15, S::BasicCorrection, K::FloatSlider, "basicCorrection/tone/whites", plain(150.0)), + to(16, S::BasicCorrection, K::FloatSlider, "basicCorrection/tone/blacks", plain(150.0)), + to(64, S::BasicCorrection, K::FloatSlider, "basicCorrection/tone/hdrSpecular", plain(150.0)), + // Creative: 23 the switch; 24 / 96 the Look's name, 25 / 128 its popups, 129 / 130 its colour + // space. + row(23, S::Creative, Some(K::Checkbox), Role::Switch), + row(24, S::Creative, Some(K::ArbitraryData), Role::Lut { lut: false }), + row(96, S::Creative, Some(K::ArbitraryData), Role::Lut { lut: false }), + row(25, S::Creative, Some(K::Popup), Role::Lut { lut: false }), + row(128, S::Creative, Some(K::Popup), Role::Lut { lut: false }), + row(129, S::Creative, Some(K::ArbitraryData), Role::LookSpace), + row(130, S::Creative, Some(K::Popup), Role::LookSpace), + to(26, S::Creative, K::FloatSlider, "creative/lookIntensity", plain(200.0)), + to(28, S::Creative, K::FloatSlider, "creative/adjustments/fadedFilm", plain(150.0)), + to(29, S::Creative, K::FloatSlider, "creative/adjustments/sharpen", plain(100.0)), + to(30, S::Creative, K::FloatSlider, "creative/adjustments/vibrance", plain(100.0)), + to(31, S::Creative, K::FloatSlider, "creative/adjustments/creativeSaturation", plain(300.0)), + row(32, S::Creative, Some(K::ArbitraryData), Role::Data(Data::SplitToning)), + to(33, S::Creative, K::FloatSlider, "creative/adjustments/tintBalance", plain(150.0)), + // Curves: 37 switches all curves, 118 the RGB curves, 104 ... 111 each hue / saturation curve. + row(37, S::RgbCurves, Some(K::Checkbox), Role::Switch), + row(118, S::RgbCurves, Some(K::Checkbox), Role::Switch), + row(65, S::RgbCurves, Some(K::FloatSlider), Role::Missing), + row(39, S::RgbCurves, Some(K::ArbitraryData), Role::Data(Data::RgbCurves)), + row(104, S::HueSat(0), Some(K::Checkbox), Role::Switch), + row(113, S::HueSat(0), Some(K::Color), Role::Eyedropper), + row(42, S::HueSat(0), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve)), + row(105, S::HueSat(1), Some(K::Checkbox), Role::Switch), + row(114, S::HueSat(1), Some(K::Color), Role::Eyedropper), + row(106, S::HueSat(1), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve)), + row(107, S::HueSat(2), Some(K::Checkbox), Role::Switch), + row(115, S::HueSat(2), Some(K::Color), Role::Eyedropper), + row(108, S::HueSat(2), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve)), + row(109, S::HueSat(3), Some(K::Checkbox), Role::Switch), + row(116, S::HueSat(3), Some(K::Color), Role::Eyedropper), + row(110, S::HueSat(3), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve)), + row(111, S::HueSat(4), Some(K::Checkbox), Role::Switch), + row(117, S::HueSat(4), Some(K::Color), Role::Eyedropper), + row(112, S::HueSat(4), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve)), + // Color Wheels: 46 the switch, 102 Face Detection (on by default), 66 HDR White, 47 the wheels. + row(46, S::ColorWheels, Some(K::Checkbox), Role::Switch), + row(102, S::ColorWheels, Some(K::Checkbox), Role::Missing), + row(66, S::ColorWheels, Some(K::FloatSlider), Role::Missing), + row(47, S::ColorWheels, Some(K::ArbitraryData), Role::Data(Data::Wheels)), + // HSL Secondary: 68 the switch; the key (70-76), Refine (81, 82), Correction (85-90). + row(68, S::HslSecondary, Some(K::Checkbox), Role::Switch), + row(70, S::HslSecondary, Some(K::Color), Role::Eyedropper), + row(71, S::HslSecondary, Some(K::Color), Role::Eyedropper), + row(72, S::HslSecondary, Some(K::Color), Role::Eyedropper), + row(73, S::HslSecondary, Some(K::ArbitraryData), Role::Data(Data::HslKey)), + to(74, S::HslSecondary, K::Checkbox, "hslSecondary/key/showMask", Conv::Checkbox), + to(75, S::HslSecondary, K::Popup, "hslSecondary/key/maskStyle", Conv::Popup { default: 1, items: MASK_STYLE }), + to(76, S::HslSecondary, K::Checkbox, "hslSecondary/key/invertMask", Conv::Checkbox), + to(81, S::HslSecondary, K::FloatSlider, "hslSecondary/refine/denoise", plain(100.0)), + to(82, S::HslSecondary, K::FloatSlider, "hslSecondary/refine/blur", plain(1000.0)), + row(85, S::HslSecondary, Some(K::ArbitraryData), Role::Data(Data::CorrectionWheels)), + // The correction wheel's mode (4 zero bytes by default). + row(93, S::HslSecondary, Some(K::ArbitraryData), Role::Data(Data::Other)), + to(86, S::HslSecondary, K::FloatSlider, "hslSecondary/correction/temperature", plain(300.0)), + to(87, S::HslSecondary, K::FloatSlider, "hslSecondary/correction/tint", plain(300.0)), + to(88, S::HslSecondary, K::FloatSlider, "hslSecondary/correction/contrast", plain(150.0)), + to(89, S::HslSecondary, K::FloatSlider, "hslSecondary/correction/sharpen", plain(100.0)), + to(90, S::HslSecondary, K::FloatSlider, "hslSecondary/correction/saturation", plain(300.0)), + // Vignette: 50 the switch. + row(50, S::Vignette, Some(K::Checkbox), Role::Switch), + to(51, S::Vignette, K::FloatSlider, "vignette/vignetteAmount", plain(5.0)), + to(52, S::Vignette, K::FloatSlider, "vignette/vignetteMidpoint", plain(100.0)), + to(53, S::Vignette, K::FloatSlider, "vignette/vignetteRoundness", plain(100.0)), + to(54, S::Vignette, K::FloatSlider, "vignette/vignetteFeather", plain(100.0)), + // SpeedGrade Custom: 57 Custom Layer (on by default), 60 its data. + row(57, S::SpeedGradeCustom, Some(K::Checkbox), Role::Switch), + row(60, S::SpeedGradeCustom, Some(K::ArbitraryData), Role::Data(Data::Other)), + // Outside the sections: Legacy Tone And Saturation, the embedded LUTs, Auto Tone, Auto Color, + // the LUT and Look assets. + row(97, S::Always, Some(K::Checkbox), Role::Missing), + row(98, S::Always, Some(K::ArbitraryData), Role::Data(Data::Other)), + row(99, S::Always, Some(K::ArbitraryData), Role::Data(Data::Other)), + row(100, S::Always, Some(K::ArbitraryData), Role::Data(Data::Other)), + row(124, S::Always, Some(K::Checkbox), Role::Missing), + row(125, S::Always, Some(K::ArbitraryData), Role::Lut { lut: true }), + row(126, S::Always, Some(K::ArbitraryData), Role::Lut { lut: false }), + row(1, S::Always, Some(K::ArbitraryData), Role::Derived), + row(121, S::Always, Some(K::FloatSlider), Role::Derived), + row(122, S::Always, Some(K::ArbitraryData), Role::Derived), +]; + +/// The names After Effects shows for the parameters whose `pard` name is blank (`dump.props`). +fn blank_name(suffix: u16) -> Option<&'static str> { + Some(match suffix { + 62 => "High Dynamic Range", + 3 | 23 | 37 | 118 | 104 | 105 | 107 | 109 | 111 | 46 | 68 | 50 => "Active", + 4 | 95 => "Input LUT data", + 24 | 96 => "Look name", + 102 => "Face Detection", + 74 => "Show Mask", + 75 => "Mask style", + 76 => "Invert Mask", + 97 => "Legacy Tone And Saturation", + 124 => "Auto Color Active", + _ => return None, + }) +} + +/// The parameter's name for the report: its own, else the one After Effects shows. +fn name_of(p: &EffectParam<'_, '_>) -> String { + match (p.name.trim(), suffix(&p.match_name).and_then(blank_name)) { + ("", Some(n)) => n.to_string(), + ("", None) => p.match_name.clone(), + (n, _) => n.to_string(), + } +} + +/// The match-name suffix of a Lumetri parameter (`ADBE Lumetri-0011` is 11). +fn suffix(match_name: &str) -> Option { + match_name.strip_prefix("ADBE Lumetri-")?.parse().ok() +} + +/// The parameter's value: the recorded one, else the `pard` default. +fn value_of(p: &EffectParam<'_, '_>) -> Option { + p.recorded_value().or_else(|| p.pard_default()) +} + +/// True when the parameter has keyframes, an expression, or a recorded value other than its +/// default (a record without a readable default counts as set). +fn is_set(p: &EffectParam<'_, '_>) -> bool { + if p.is_animated() || p.stored().is_some_and(|s| s.expression().is_some()) { + return true; + } + match (p.recorded_value(), p.pard_default()) { + (Some(v), Some(d)) => !same(v, d), + (Some(_), None) => true, + (None, _) => false, + } +} + +/// Equal within the float noise of a stored `f64` / `f32`. +fn same(a: ParamValue, b: ParamValue) -> bool { + let close = |x: f64, y: f64| (x - y).abs() <= 1e-6 * x.abs().max(y.abs()).max(1.0); + match (a, b) { + (ParamValue::Number(x), ParamValue::Number(y)) => close(x, y), + (ParamValue::Argb(x), ParamValue::Argb(y)) => x.iter().zip(y).skip(1).all(|(x, y)| close(*x, y)), + _ => a == b, + } +} + +/// A value as the report shows it. +fn shown_value(v: Option) -> String { + match v { + Some(ParamValue::Number(n)) => { + let s = format!("{n:.3}"); + s.trim_end_matches('0').trim_end_matches('.').to_string() + } + Some(ParamValue::Bool(b)) => if b { "on" } else { "off" }.to_string(), + Some(ParamValue::Index(i)) => format!("item {i}"), + Some(ParamValue::Argb([_, r, g, b])) => format!("RGB {:.3} {:.3} {:.3}", r, g, b), + Some(other) => format!("{other:?}"), + None => "set".to_string(), + } +} + +/// Empty data: absent, `fe fe` (no text, no asset) or only zero bytes. +fn is_empty_data(d: Option<&[u8]>) -> bool { + match d { + None => true, + Some(d) => d == [0xfe, 0xfe] || d.iter().all(|b| *b == 0), + } +} + +fn le_u32(d: &[u8], at: usize) -> Option { + Some(u32::from_le_bytes(*d.get(at..at.checked_add(4)?)?.first_chunk::<4>()?)) +} + +fn le_f32(d: &[u8], at: usize) -> Option { + Some(f32::from_le_bytes(*d.get(at..at.checked_add(4)?)?.first_chunk::<4>()?)) +} + +fn le_f64(d: &[u8], at: usize) -> Option { + Some(f64::from_le_bytes(*d.get(at..at.checked_add(8)?)?.first_chunk::<8>()?)) +} + +/// A UTF-16LE text up to its NUL (the Look's name, `-0096`: `SL BLUE ICE` in 1200 `-01-set-all`); +/// `None` for empty data. +fn utf16_text(d: &[u8]) -> Option { + if is_empty_data(Some(d)) { + return None; + } + let units: Vec = d.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes(*c)).take_while(|u| *u != 0).collect(); + let s = String::from_utf16_lossy(&units); + let s = s.trim(); + (!s.is_empty()).then(|| s.to_string()) +} + +/// A Lumetri curve (520 bytes): `i32` curve type at 0 (3 for the hue curves, which wrap; 2 for +/// Luma vs Sat and Sat vs Sat; 0 for an RGB curve), the `u32` point count at 4, then the points +/// as little-endian `f64` pairs x, y from byte 8 (at most 32). `None` when the count does not fit. +fn curve_points(d: &[u8]) -> Option> { + let n = usize::try_from(le_u32(d, 4)?).ok()?; + if n > d.len().saturating_sub(8) / 16 { + return None; + } + (0..n).map(|i| Some((le_f64(d, 8 + 16 * i)?, le_f64(d, 16 + 16 * i)?))).collect() +} + +/// HSL Secondary's key (`-0073`, 40 bytes): a flag byte (1 once a key colour was picked, 0 for a +/// fresh effect), then hue, saturation and lightness, each three little-endian `f32` (centre, +/// range, tolerance; fractions of the full hue circle / of 0..1) and an enabled byte. A fresh effect +/// stores flag 0 and centre 0.5, range 0, tolerance 0, enabled for each (1200 `-00-defaults`); +/// After Effects' own copy in `-0001` names the same fields (`middleHLS`, `rangeHLS`, +/// `toleranceHLS`, `enableHLS`, hue in degrees: centre 180). Picking Set color RGB 0.02 0.55 0.85 +/// gives hue centre 0.5605 (that colour's hue, 201.8 degrees) and lightness centre 0.435 (its +/// HSL lightness) with range 0.05 and tolerance 0.1 (`-01-set-all`). +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct HslKey { + pub picked: bool, + /// Hue, saturation, lightness: centre, range, tolerance, enabled. + pub channels: [(f32, f32, f32, bool); 3], +} + +impl HslKey { + pub fn parse(d: &[u8]) -> Option { + if d.len() != 40 { + return None; + } + let picked = match d.first()? { + 0 => false, + 1 => true, + _ => return None, + }; + let ch = |at: usize| -> Option<(f32, f32, f32, bool)> { + let (c, r, t) = (le_f32(d, at)?, le_f32(d, at + 4)?, le_f32(d, at + 8)?); + let on = match d.get(at + 12)? { + 0 => false, + 1 => true, + _ => return None, + }; + (c.is_finite() && r.is_finite() && t.is_finite()).then_some((c, r, t, on)) + }; + Some(HslKey { picked, channels: [ch(1)?, ch(14)?, ch(27)?] }) + } + + fn is_default(&self) -> bool { + !self.picked && self.channels.iter().all(|c| *c == (0.5, 0.0, 0.0, true)) + } +} + +/// The colour wheel data: triples of `f64`, each wheel `0, 0.5, 0` by default. +fn wheels_default(d: &[u8], wheels: usize) -> bool { + d.len() == wheels * 24 && (0..wheels).all(|w| le_f64(d, w * 24) == Some(0.0) && le_f64(d, w * 24 + 8) == Some(0.5) && le_f64(d, w * 24 + 16) == Some(0.0)) +} + +/// Is the data of `data` at After Effects' default (as far as it can be told)? +fn data_default(data: Data, d: Option<&[u8]>) -> bool { + let Some(d) = d else { return true }; + match data { + Data::RgbCurves => { + d.len() == 4 * 520 && d.as_chunks::<520>().0.iter().all(|c| curve_points(c).is_some_and(|pts| pts.iter().all(|(x, y)| (x - y).abs() < 1e-9))) + } + Data::HueSatCurve => curve_points(d).is_some_and(|pts| pts.iter().all(|(_, y)| *y == 0.0)), + Data::Wheels => wheels_default(d, 4), + Data::CorrectionWheels => wheels_default(d, 8), + Data::SplitToning | Data::Other => is_empty_data(Some(d)), + Data::HslKey => HslKey::parse(d).is_some_and(|k| k.is_default()), + } +} + +/// What the Input LUT or the Look holds: names, a popup item, an asset. +#[derive(Default)] +struct LutState { + names: Vec, + item: Option, + asset: bool, +} + +/// How a set parameter of a section that does nothing is listed in the report; `None` when it is +/// at its default. +fn off_text(p: &EffectParam<'_, '_>, role: Role, data: Option<&[u8]>) -> Option { + match role { + Role::Data(d) => (!data_default(d, data)).then(|| name_of(p)), + // A LUT by its name (the popups index the same choice). + Role::Lut { lut } if p.kind == K::ArbitraryData => { + let what = if lut { "Input LUT" } else { "Look" }; + data.and_then(utf16_text).map(|n| format!("{what} '{n}'")).or_else(|| (!is_empty_data(data)).then(|| what.to_string())) + } + // The Look's colour space goes with the Look. + Role::Lut { .. } | Role::LookSpace | Role::Derived => None, + _ => is_set(p).then(|| format!("{} {}", name_of(p), shown_value(p.recorded_value()))), + } +} + +/// Notes what an Input LUT or Look parameter holds: a popup item, an asset or a name. +fn note_lut(p: &EffectParam<'_, '_>, suffix: u16, data: Option<&[u8]>, st: &mut LutState) { + if p.kind == K::Popup { + // The popup indexes the LUTs installed with After Effects; item 1 is None. + if let Some(ParamValue::Index(i)) = p.recorded_value() + && i > 1 + { + st.item = usize::try_from(i).ok().and_then(|i| p.items.as_ref()?.get(i - 1).cloned()).or(Some(format!("item {i}"))); + } + } else if suffix == 125 || suffix == 126 { + st.asset |= !is_empty_data(data); + } else if let Some(name) = data.and_then(utf16_text) + && !st.names.contains(&name) + { + st.names.push(name); + } +} + +/// Imports a Lumetri Color instance's parameters into `out.group` and reports what does not arrive. +pub(crate) fn import_lumetri(fx: &AepEffect<'_, '_>, params: &[EffectParam<'_, '_>], cx: &LayerCtx<'_>, shown: &str, out: ParamOut<'_>) { + let ParamOut { group, refs, col } = out; + let here = format!("{}: '{}' effect '{shown}' ({})", cx.comp, cx.layer, fx.match_name()); + let find = |s: u16| params.iter().find(|p| suffix(&p.match_name) == Some(s)); + // The switches: on unless a record says off. Keys or an expression on a switch are not + // imported (the static value counts). + let switch_on = |s: u16| -> bool { + match find(s) { + Some(p) => !matches!(value_of(p), Some(ParamValue::Bool(false))), + None => true, + } + }; + // HSL Secondary without a picked key colour selects nothing: After Effects applies none of + // its correction (1200 `-16-sec-correction`, `-15-sec-refine` render as `-00-defaults`); + // EffectCraft's default key is the whole image, so the values are left out too. + // Unreadable or missing key data does not count as unpicked (it is reported or older). + let key_picked = find(73).and_then(|p| fx.arbitrary_data(&p.match_name)).and_then(HslKey::parse).is_none_or(|k| k.picked); + let section_on = |sec: Section| -> bool { + match sec { + Section::Always => true, + Section::BasicCorrection => switch_on(3), + Section::Creative => switch_on(23), + Section::RgbCurves => switch_on(37) && switch_on(118), + Section::HueSat(i) => switch_on(37) && switch_on([104, 105, 107, 109, 111].get(usize::from(i)).copied().unwrap_or(104)), + Section::ColorWheels => switch_on(46), + Section::HslSecondary => switch_on(68) && key_picked, + Section::Vignette => switch_on(50), + // Custom Layer off is itself reported (a switch without counterpart). + Section::SpeedGradeCustom => true, + } + }; + let mut off: Vec<(Section, Vec)> = Vec::new(); + let mut eyedroppers: Vec = Vec::new(); + let mut luts = [LutState::default(), LutState::default()]; + for p in params { + if carries_nothing(p) || p.match_name == "ADBE Effect Built In Params" { + continue; + } + let label = if p.name.trim().is_empty() { format!("{} ({})", name_of(p), p.match_name) } else { param_label(p) }; + let Some(row) = suffix(&p.match_name).and_then(|s| ROWS.iter().find(|r| r.suffix == s)) else { + // A parameter this table does not know (a newer version): lost when set. + if p.stored().is_some() + && (p.kind != K::ArbitraryData && is_set(p) || p.kind == K::ArbitraryData && !is_empty_data(fx.arbitrary_data(&p.match_name))) + { + col.lose(LossCategory::Effects, format!("{here}: parameter {label} not imported")); + } + continue; + }; + if row.kind.is_some_and(|k| k != p.kind) { + if p.stored().is_some() { + col.lose(LossCategory::Effects, format!("{here}: parameter {label} has type {:?}, expected {:?}; not imported", p.kind, row.kind)); + } + continue; + } + let data = || fx.arbitrary_data(&p.match_name); + // A switched-off section: its set values are listed, not imported. + if !matches!(row.role, Role::Switch) && !section_on(row.section) { + let text = off_text(p, row.role, data()); + if let Some(text) = text { + match off.iter_mut().find(|(s, _)| *s == row.section) { + Some((_, list)) => { + if !list.contains(&text) { + list.push(text); + } + } + None => off.push((row.section, vec![text])), + } + } + continue; + } + match row.role { + Role::To(target, conv) => { + let m = ParamMap { index: p.index, kind: p.kind, target, conv }; + import_mapped(p, &m, cx, (&here, &label), ParamOut { group: &mut *group, refs: &mut *refs, col: &mut *col }, ValueRecord::Any); + } + Role::Switch => { + if p.is_animated() || p.stored().is_some_and(|s| s.expression().is_some()) { + col.lose(LossCategory::Effects, format!("{here}: keyframes or an expression on the switch {label} are not imported")); + } + if row.section == Section::SpeedGradeCustom && !switch_on(row.suffix) { + col.lose(LossCategory::Effects, format!("{here}: parameter {label} is off and has no counterpart")); + } + } + Role::Missing => { + if is_set(p) { + col.lose( + LossCategory::Effects, + format!("{here}: parameter {label} is {} and has no counterpart, not imported", shown_value(p.recorded_value())), + ); + } + } + Role::Eyedropper => { + if is_set(p) { + eyedroppers.push(name_of(p)); + } + } + Role::Lut { lut } => note_lut(p, row.suffix, data(), &mut luts[usize::from(!lut)]), + // The Look's colour space only applies to a Look, which is reported. + Role::LookSpace => {} + Role::Data(Data::HslKey) => import_hsl_key(data(), &here, &mut *group, &mut *col), + Role::Data(d) => { + if p.is_animated() || p.stored().is_some_and(|s| s.expression().is_some()) { + col.lose(LossCategory::Effects, format!("{here}: keyframes or an expression on {label} are not imported")); + } + if !data_default(d, data()) { + let why = match d { + Data::HueSatCurve => "the curve's points are moved; no sample tells their scale", + Data::RgbCurves | Data::Wheels | Data::CorrectionWheels | Data::SplitToning => "the data is not decoded (not sampled)", + Data::HslKey | Data::Other => "no counterpart", + }; + col.lose(LossCategory::Effects, format!("{here}: parameter {label} is not imported ({why})")); + } + } + Role::Derived => {} + } + } + for (sec, list) in off { + let why = if sec == Section::HslSecondary && switch_on(68) { + "has no key colour picked (After Effects applies it to nothing)" + } else { + "is switched off (EffectCraft's Lumetri has no section switch)" + }; + col.lose(LossCategory::Effects, format!("{here}: section {} {why}, its values are not imported: {}", sec.name(), list.join(", "))); + } + if !eyedroppers.is_empty() { + col.lose(LossCategory::Effects, format!("{here}: the eyedropper colours {} are not imported (they only set other controls)", eyedroppers.join(", "))); + } + for (st, what) in luts.iter().zip(["Input LUT", "Look"]) { + let name = st.names.first().cloned().or_else(|| st.item.clone()); + if name.is_some() || st.asset { + let name = name.map(|n| format!(" '{n}'")).unwrap_or_default(); + col.lose( + LossCategory::Effects, + format!("{here}: the {what}{name} is not imported (the LUT file is not in the project; EffectCraft's {what} stays None)"), + ); + } + } +} + +/// HSL Secondary's key as EffectCraft's hue centre / range / softness (degrees) and saturation and +/// lightness bands (percent): range is taken as the half width, tolerance as the softness. A key +/// that was never picked keeps EffectCraft's default (the whole image). +fn import_hsl_key(d: Option<&[u8]>, here: &str, group: &mut effectcraft_project::PropGroup, col: &mut crate::import::report::Collector) { + let Some(d) = d else { return }; + let Some(key) = HslKey::parse(d) else { + col.lose(LossCategory::DamagedData, format!("{here}: the HSL Secondary key data is unreadable, the default key used")); + return; + }; + if !key.picked { + if !key.is_default() { + col.lose(LossCategory::Effects, format!("{here}: the HSL Secondary key holds values without a picked colour, not imported")); + } + return; + } + let mut set = |id: &str, v: Value| { + if let Some(prop) = group.prop_mut(&format!("hslSecondary/key/{id}")) { + prop.value = v; + } + }; + let [h, s, l] = key.channels.map(|(c, r, t, on)| (f64::from(c), f64::from(r), f64::from(t), on)); + set("hueEnabled", Value::Bool(h.3)); + set("hueCenter", Value::Scalar((h.0 * 360.0).rem_euclid(360.0))); + set("hueRange", Value::Scalar((h.1 * 360.0).clamp(0.0, 180.0))); + set("hueSoftness", Value::Scalar((h.2 * 360.0).clamp(0.0, 180.0))); + for ((c, r, t, on), id) in [(s.0, s.1, s.2, s.3), (l.0, l.1, l.2, l.3)].into_iter().zip(["saturation", "lightness"]) { + set(&format!("{id}Enabled"), Value::Bool(on)); + set(&format!("{id}Low"), Value::Scalar(((c - r) * 100.0).clamp(0.0, 100.0))); + set(&format!("{id}High"), Value::Scalar(((c + r) * 100.0).clamp(0.0, 100.0))); + set(&format!("{id}Softness"), Value::Scalar((t * 100.0).clamp(0.0, 100.0))); + } +} diff --git a/crates/aep/tests/it/import.rs b/crates/aep/tests/it/import.rs index 95dced570..122d18c2b 100644 --- a/crates/aep/tests/it/import.rs +++ b/crates/aep/tests/it/import.rs @@ -13,6 +13,7 @@ mod effects; mod effects_batch5; mod effects_round2; mod effects_round3; +mod lumetri; mod markers; mod masks; mod mattes; diff --git a/crates/aep/tests/it/import/effects.rs b/crates/aep/tests/it/import/effects.rs index be1293b9a..010df44d5 100644 --- a/crates/aep/tests/it/import/effects.rs +++ b/crates/aep/tests/it/import/effects.rs @@ -72,7 +72,7 @@ fn the_table_names_tint_gradient_ramp_and_exposure() { ] { assert!(t.contains(&want), "{want:?}"); } - assert_eq!(t.len(), 57); + assert_eq!(t.len(), 58); for (_, id) in t { assert!(effectcraft_effects::find(id).is_some(), "{id}"); } diff --git a/crates/aep/tests/it/import/lumetri.rs b/crates/aep/tests/it/import/lumetri.rs new file mode 100644 index 000000000..526f43648 --- /dev/null +++ b/crates/aep/tests/it/import/lumetri.rs @@ -0,0 +1,448 @@ +//! Lumetri Color (`ADBE Lumetri`) arrives as EffectCraft's Lumetri Color (`ec.color.lumetri`), +//! its parameters found by match name. The effect is built into the committed `synthetic.aep` in +//! place of its Glow, in the layout of the 1200 samples (After Effects 2026, docs/aep-format.md +//! 3.7): the definitions are a subset in an order of our own, so a mapping by `parT` index fails. + +use effectcraft_aep::import::{ImportOptions, ImportResult, LossCategory, import}; +use effectcraft_aep::{Body, Chunk, parse, write}; +use effectcraft_keyframe::Value; +use effectcraft_project::{Project, PropGroup}; + +const SYNTHETIC: &[u8] = include_bytes!("../../fixtures/synthetic.aep"); + +fn tdmn(name: &str) -> Chunk<'static> { + let mut b = name.as_bytes().to_vec(); + b.resize(40, 0); + Chunk::data(*b"tdmn", b) +} + +/// A chunk holding chunks (`pdnm`, `fnam`: `NESTED_IDS`) with one `Utf8`. +fn nested(id: [u8; 4], text: &[u8]) -> Chunk<'static> { + Chunk { id, body: Body::Chunks(vec![Chunk::data(*b"Utf8", text.to_vec())]), pad: None } +} + +fn mn(suffix: u16) -> String { + format!("ADBE Lumetri-{suffix:04}") +} + +/// A parameter definition (`pard`, 148 bytes): the type at byte 15, the name at 16, the default at +/// 56 (a float slider's `f64`, a checkbox's or popup's `u32`), a popup's item count at 60, a float +/// slider's valid range at 104 / 108 and slider range at 112 / 116 (`f32`). +#[derive(Clone)] +enum Def { + Float { name: &'static str, default: f64, min: f32, max: f32 }, + Check { default: bool }, + Popup { name: &'static str, items: &'static [&'static str] }, + Data { name: &'static str }, + Group { name: &'static str, end: bool }, +} + +fn pard(d: &Def) -> Vec> { + let mut b = vec![0u8; 148]; + let name = |b: &mut Vec, n: &str| b[16..16 + n.len()].copy_from_slice(n.as_bytes()); + let mut extra = Vec::new(); + match d { + Def::Float { name: n, default, min, max } => { + b[15] = 10; + name(&mut b, n); + b[56..64].copy_from_slice(&default.to_be_bytes()); + b[104..108].copy_from_slice(&min.to_be_bytes()); + b[108..112].copy_from_slice(&max.to_be_bytes()); + b[112..116].copy_from_slice(&min.to_be_bytes()); + b[116..120].copy_from_slice(&max.to_be_bytes()); + } + Def::Check { default } => { + b[15] = 4; + name(&mut b, " "); + b[56..60].copy_from_slice(&u32::from(*default).to_be_bytes()); + } + Def::Popup { name: n, items } => { + b[15] = 7; + name(&mut b, n); + b[56..60].copy_from_slice(&1u32.to_be_bytes()); + b[60..62].copy_from_slice(&u16::try_from(items.len()).unwrap().to_be_bytes()); + extra.push(nested(*b"pdnm", items.join("|").as_bytes())); + } + Def::Data { name: n } => { + b[15] = 11; + name(&mut b, n); + } + Def::Group { name: n, end } => { + b[15] = if *end { 14 } else { 13 }; + name(&mut b, n); + } + } + let mut v = vec![Chunk::data(*b"pard", b)]; + v.extend(extra); + v +} + +/// A stored value. +#[derive(Clone)] +enum Rec { + /// A number in a record of state `tdsb` (1 written, 3 the default state). + Num(f64, u32), + /// Arbitrary data. + Data(Vec), +} + +/// A static value record after the one After Effects wrote for Glow's A & B Midpoint (its header, +/// one component). +fn record(template: &Chunk<'_>, tdsb: u32, v: f64) -> Chunk<'static> { + let mut kids = Vec::new(); + for c in template.children() { + match &c.body { + Body::Data(_) if c.id == *b"tdsb" => kids.push(Chunk::data(*b"tdsb", tdsb.to_be_bytes().to_vec())), + Body::Data(d) if c.id == *b"tdb4" => kids.push(Chunk::data(c.id, d.to_vec())), + Body::Data(_) if c.id == *b"cdat" => { + let mut d = vec![0u8; 40]; + d[..8].copy_from_slice(&v.to_be_bytes()); + kids.push(Chunk::data(*b"cdat", d)); + } + _ => {} + } + } + Chunk::list(*b"tdbs", kids) +} + +/// The defaults of a fresh instance's data (1200 `lumetri-00-defaults`). +fn empty() -> Vec { + vec![0xfe, 0xfe] +} + +/// A Lumetri curve: type, point count, points (`f64` x, y), padded to 520 bytes. +fn curve(kind: i32, pts: &[(f64, f64)]) -> Vec { + let mut d = kind.to_le_bytes().to_vec(); + d.extend(u32::try_from(pts.len()).unwrap().to_le_bytes()); + for (x, y) in pts { + d.extend(x.to_le_bytes()); + d.extend(y.to_le_bytes()); + } + d.resize(520, 0); + d +} + +fn rgb_curves() -> Vec { + (0..4).flat_map(|_| curve(0, &[(0.0, 0.0), (1.0, 1.0)])).collect() +} + +fn wheels(n: usize) -> Vec { + (0..n).flat_map(|_| [0.0f64, 0.5, 0.0].into_iter().flat_map(f64::to_le_bytes)).collect() +} + +fn utf16(s: &str) -> Vec { + s.encode_utf16().chain([0]).flat_map(u16::to_le_bytes).collect() +} + +/// HSL Secondary's key data as 1200 `lumetri-01-set-all` stores it (Set color RGB 0.02 0.55 0.85). +const HSL_PICKED: &str = "01327f0f3fcdcc4c3dcdcccc3d01d519683f2e57c93dcade173e01dfdede3ecdcc4c3dcdcccc3d01"; +/// A fresh instance's key data (`-00-defaults`). +const HSL_FRESH: &str = "000000003f0000000000000000010000003f0000000000000000010000003f000000000000000001"; + +fn hex(s: &str) -> Vec { + (0..s.len()).step_by(2).map(|i| u8::from_str_radix(&s[i..i + 2], 16).unwrap()).collect() +} + +const MASK_STYLE: &[&str] = &["Color/Gray", "Color/Black", "White/Black"]; +const LOOKS: &[&str] = &["None", "[Custom]", "Browse...", "(-", "SL BIG", "SL BLUE ICE"]; + +/// The definitions, an order of our own (not After Effects' `parT` order) and without the ones +/// After Effects 2026 added late (-0127 ... -0130). +fn defs() -> Vec<(u16, Def)> { + let f = |name, default, min, max| Def::Float { name, default, min, max }; + vec![ + (1, Def::Data { name: "Blob" }), + (62, Def::Check { default: false }), + (2, Def::Group { name: "Basic Correction", end: false }), + (3, Def::Check { default: true }), + (95, Def::Data { name: " " }), + (64, f("HDR Specular", 0.0, -150.0, 150.0)), + (16, f("Blacks", 0.0, -150.0, 150.0)), + (11, f("Exposure", 0.0, -7.0, 7.0)), + (12, f("Contrast", 0.0, -150.0, 150.0)), + (7, f("Temperature", 0.0, -300.0, 300.0)), + (21, Def::Group { name: "", end: true }), + (22, Def::Group { name: "Creative", end: false }), + (23, Def::Check { default: true }), + (96, Def::Data { name: " " }), + (25, Def::Popup { name: "Look", items: LOOKS }), + (26, f("Intensity", 100.0, 0.0, 200.0)), + (32, Def::Data { name: "Split Toning" }), + (35, Def::Group { name: "", end: true }), + (39, Def::Data { name: "RGB Curve" }), + (104, Def::Check { default: true }), + (42, Def::Data { name: "Hue vs Sat" }), + (47, Def::Data { name: "Wheels" }), + (68, Def::Check { default: true }), + (73, Def::Data { name: "HSL Sliders" }), + (74, Def::Check { default: false }), + (75, Def::Popup { name: " ", items: MASK_STYLE }), + (85, Def::Data { name: "Color Wheels" }), + (86, f("Temperature", 0.0, -300.0, 300.0)), + (50, Def::Check { default: true }), + (51, f("Amount", 0.0, -5.0, 5.0)), + (54, f("Feather", 50.0, 0.0, 100.0)), + (97, Def::Check { default: false }), + ] +} + +/// The data every instance stores, at the defaults. +fn default_data() -> Vec<(u16, Rec)> { + vec![ + (1, Rec::Data(empty())), + (95, Rec::Data(empty())), + (96, Rec::Data(empty())), + (32, Rec::Data(vec![0; 32])), + (39, Rec::Data(rgb_curves())), + (42, Rec::Data(curve(3, &[]))), + (47, Rec::Data(wheels(4))), + (73, Rec::Data(hex(HSL_FRESH))), + (85, Rec::Data(wheels(8))), + ] +} + +/// The Lumetri instance: the definitions, then the stored values `recs` (data replaces the +/// default data of the same parameter). +fn sspc(defs: &[(u16, Def)], recs: &[(u16, Rec)], template: &Chunk<'_>) -> Chunk<'static> { + let mut part = vec![Chunk::data(*b"parn", u32::try_from(defs.len() + 2).unwrap().to_be_bytes().to_vec()), tdmn(&mn(0))]; + let mut layer = vec![0u8; 148]; + layer[15] = 0; + part.push(Chunk::data(*b"pard", layer)); + for (s, d) in defs { + part.push(tdmn(&mn(*s))); + part.extend(pard(d)); + } + part.push(tdmn("ADBE Effect Built In Params")); + let mut end = vec![0u8; 148]; + end[15] = 9; + part.push(Chunk::data(*b"pard", end)); + let mut all: Vec<(u16, Rec)> = default_data().into_iter().filter(|(s, _)| !recs.iter().any(|(r, _)| r == s)).collect(); + all.extend(recs.iter().cloned()); + let mut values = vec![Chunk::data(*b"tdsb", 1u32.to_be_bytes().to_vec())]; + for (s, r) in all { + values.push(tdmn(&mn(s))); + match r { + Rec::Num(v, tdsb) => values.push(record(template, tdsb, v)), + Rec::Data(d) => { + values.push(record(template, 1, 0.0)); + values.push(Chunk::list(*b"aRbs", vec![Chunk::data(*b"aRbp", d)])); + } + } + } + Chunk::list(*b"sspc", vec![nested(*b"fnam", b"Lumetri Color"), Chunk::list(*b"parT", part), Chunk::list(*b"tdgp", values)]) +} + +fn find_glow_template<'a>(chunks: &'a [Chunk<'a>]) -> Option> { + for c in chunks { + let kids = c.children(); + if let Some(at) = kids.iter().position(|k| k.is(b"tdmn") && k.bytes().is_some_and(|b| b.starts_with(b"ADBE Glo2-0011\0"))) + && let Some(record) = kids.get(at + 1).filter(|k| k.is_list(b"tdbs")) + { + return Some(record.clone()); + } + if let Some(t) = find_glow_template(kids) { + return Some(t); + } + } + None +} + +/// Puts the instance in place of the Glow effect (in the effect parade and the project's shared +/// definitions); the number of places. +fn replace_glow(chunks: &mut [Chunk<'_>], instance: &Chunk<'static>) -> usize { + let mut n = 0; + for ch in chunks { + let kids = ch.children_mut(); + if let Some(at) = kids.iter().position(|k| k.is(b"tdmn") && k.bytes().is_some_and(|b| b.starts_with(b"ADBE Glo2\0"))) + && kids.get(at + 1).is_some_and(|k| k.is_list(b"sspc")) + { + kids[at] = tdmn("ADBE Lumetri"); + kids[at + 1] = instance.clone(); + n += 1; + } + n += replace_glow(kids, instance); + } + n +} + +fn run_with(defs: &[(u16, Def)], recs: &[(u16, Rec)]) -> (PropGroup, ImportResult) { + let file = parse(SYNTHETIC).unwrap(); + let template = find_glow_template(&file.chunks).expect("Glow's A & B Midpoint record"); + let instance = sspc(defs, recs, &template); + let mut file = parse(SYNTHETIC).unwrap(); + assert_eq!(replace_glow(&mut file.chunks, &instance), 2, "the Glow effect and its shared definitions"); + let bytes = write(&file).unwrap(); + let mut project = Project::default(); + let none = |_: &str| false; + let r = import(&mut project, &bytes, &ImportOptions { allow_losses: true, ..ImportOptions::new(&none) }).unwrap(); + let g = project + .comps() + .flat_map(|(_, c)| c.layers.iter()) + .find_map(|l| l.props.sub("effects").and_then(|fx| fx.children.iter().filter_map(|n| n.as_group()).find(|g| g.match_id == "ec.color.lumetri").cloned())) + .expect("an EffectCraft Lumetri Color"); + (g, r) +} + +fn run(recs: &[(u16, Rec)]) -> (PropGroup, ImportResult) { + run_with(&defs(), recs) +} + +fn losses(r: &ImportResult) -> Vec { + r.report + .losses + .iter() + .filter(|l| matches!(l.category, LossCategory::Effects | LossCategory::DamagedData)) + .flat_map(|l| l.details.clone()) + .filter(|d| d.contains("Lumetri")) + .collect() +} + +fn num(g: &PropGroup, id: &str) -> f64 { + g.prop(id).unwrap_or_else(|| panic!("no {id}")).value.as_f64() +} + +fn val(g: &PropGroup, id: &str) -> Value { + g.prop(id).unwrap_or_else(|| panic!("no {id}")).value.clone() +} + +#[test] +fn a_fresh_lumetri_arrives_without_losses() { + let (g, r) = run(&[]); + assert_eq!(losses(&r), Vec::::new()); + assert_eq!((num(&g, "basicCorrection/tone/exposure"), num(&g, "creative/lookIntensity"), num(&g, "vignette/vignetteFeather")), (0.0, 100.0, 50.0)); + assert_eq!(val(&g, "creative/look"), Value::Enum(0)); +} + +#[test] +fn lumetri_values_arrive_by_match_name_also_from_default_state_records() { + // 1200 `lumetri-01-set-all` / `-06-sec-light`: High Dynamic Range and HDR Specular are + // recorded in the default state (`tdsb` 3) and read back as set. + let (g, r) = run(&[ + (62, Rec::Num(1.0, 3)), + (64, Rec::Num(22.0, 3)), + (11, Rec::Num(2.589_999_914_169_311_5, 1)), + (12, Rec::Num(37.0, 1)), + (16, Rec::Num(-150.0, 1)), + (7, Rec::Num(300.0, 1)), + (26, Rec::Num(134.0, 1)), + (51, Rec::Num(1.85, 1)), + (74, Rec::Num(1.0, 1)), + (75, Rec::Num(3.0, 1)), + (73, Rec::Data(hex(HSL_PICKED))), + ]); + assert_eq!(losses(&r), Vec::::new()); + assert_eq!(val(&g, "highDynamicRange"), Value::Bool(true)); + for (id, want) in [ + ("basicCorrection/tone/hdrSpecular", 22.0), + ("basicCorrection/tone/exposure", 2.589_999_914_169_311_5), + ("basicCorrection/tone/contrast", 37.0), + ("basicCorrection/tone/blacks", -150.0), + // Past EffectCraft's old slider range: kept (the range is After Effects' now). + ("basicCorrection/whiteBalance/temperature", 300.0), + ("creative/lookIntensity", 134.0), + ("vignette/vignetteAmount", 1.85), + ] { + assert_eq!(num(&g, id), want, "{id}"); + } + assert_eq!((val(&g, "hslSecondary/key/showMask"), val(&g, "hslSecondary/key/maskStyle")), (Value::Bool(true), Value::Enum(2))); +} + +#[test] +fn a_switched_off_section_is_reported_and_not_applied() { + // 1200 `-03-sec-basic-correction`, `-17-sec-vignette`: a section that is off does nothing. + let (g, r) = run(&[(3, Rec::Num(0.0, 1)), (11, Rec::Num(2.0, 1)), (50, Rec::Num(0.0, 1)), (51, Rec::Num(-2.0, 1)), (12, Rec::Num(37.0, 1))]); + assert_eq!((num(&g, "basicCorrection/tone/exposure"), num(&g, "basicCorrection/tone/contrast"), num(&g, "vignette/vignetteAmount")), (0.0, 0.0, 0.0)); + let l = losses(&r); + assert_eq!(l.len(), 2, "{l:?}"); + assert!(l[0].contains("section Basic Correction is switched off") && l[0].contains("Exposure 2, Contrast 37"), "{l:?}"); + assert!(l[1].contains("section Vignette is switched off") && l[1].contains("Amount -2"), "{l:?}"); +} + +#[test] +fn a_look_is_reported_by_name() { + // 1200 `-01-set-all`: the Look's name in -0096, the popup's record in the default state. + let (g, r) = run(&[(96, Rec::Data(utf16("SL BLUE ICE"))), (25, Rec::Num(6.0, 3))]); + assert_eq!(val(&g, "creative/look"), Value::Enum(0)); + let l = losses(&r); + assert_eq!(l.len(), 1, "{l:?}"); + assert!(l[0].contains("the Look 'SL BLUE ICE' is not imported"), "{l:?}"); + // Only the popup: its item. + let (_, r) = run(&[(25, Rec::Num(5.0, 1))]); + assert!(losses(&r).iter().any(|d| d.contains("the Look 'SL BIG' is not imported")), "{:?}", losses(&r)); +} + +#[test] +fn hue_saturation_curves_with_neutral_points_arrive_moved_ones_are_reported() { + // 1200 `-11-sec-hue-saturation-curves`: the selector put three neutral points on the curve. + let neutral = curve(3, &[(0.742_483, 0.0), (0.798_038, 0.0), (0.853_594, 0.0)]); + let (g, r) = run(&[(42, Rec::Data(neutral))]); + assert_eq!(losses(&r), Vec::::new()); + assert_eq!(val(&g, "curves/hueSaturationCurves/hueVsSat"), Value::Str(String::new())); + let (_, r) = run(&[(42, Rec::Data(curve(3, &[(0.5, 0.25)])))]); + let l = losses(&r); + assert!(l.len() == 1 && l[0].contains("Hue vs Sat (ADBE Lumetri-0042) is not imported"), "{l:?}"); + // A point count past the data: not a default, reported, no panic. + let mut bad = curve(3, &[]); + bad[4..8].copy_from_slice(&1000u32.to_le_bytes()); + let (_, r) = run(&[(42, Rec::Data(bad))]); + assert_eq!(losses(&r).len(), 1); +} + +#[test] +fn the_picked_hsl_key_becomes_hue_saturation_and_lightness_ranges() { + let (g, r) = run(&[(73, Rec::Data(hex(HSL_PICKED)))]); + assert_eq!(losses(&r), Vec::::new()); + let close = |id: &str, want: f64| assert!((num(&g, id) - want).abs() < 0.01, "{id}: {} != {want}", num(&g, id)); + // Hue centre 0.5605 of the circle, range 0.05, tolerance 0.1. + close("hslSecondary/key/hueCenter", 201.79); + close("hslSecondary/key/hueRange", 18.0); + close("hslSecondary/key/hueSoftness", 36.0); + // Lightness centre 0.435 +- 0.05, tolerance 0.1, as percent. + close("hslSecondary/key/lightnessLow", 38.53); + close("hslSecondary/key/lightnessHigh", 48.53); + close("hslSecondary/key/lightnessSoftness", 10.0); + assert_eq!(val(&g, "hslSecondary/key/hueEnabled"), Value::Bool(true)); + // With the key picked the correction applies; without, After Effects applies it to nothing + // (1200 `-16-sec-correction` renders as `-00-defaults`): left out and reported. + let (g, _) = run(&[(73, Rec::Data(hex(HSL_PICKED))), (86, Rec::Num(19.0, 1))]); + assert_eq!(num(&g, "hslSecondary/correction/temperature"), 19.0); + let (g, r) = run(&[(86, Rec::Num(19.0, 1))]); + assert_eq!(num(&g, "hslSecondary/correction/temperature"), 0.0); + let l = losses(&r); + assert!(l.len() == 1 && l[0].contains("HSL Secondary has no key colour picked") && l[0].contains("Temperature 19"), "{l:?}"); + // Damaged key data: reported, the default key kept. + let (g, r) = run(&[(73, Rec::Data(vec![7; 40]))]); + assert!(losses(&r).iter().any(|d| d.contains("HSL Secondary key data is unreadable")), "{:?}", losses(&r)); + assert_eq!(num(&g, "hslSecondary/key/hueRange"), 180.0); +} + +#[test] +fn undecoded_data_and_controls_without_counterpart_are_reported_when_set() { + let mut split = vec![0u8; 32]; + split[0] = 1; + let mut w = wheels(4); + w[8] = 1; + let (_, r) = run(&[(32, Rec::Data(split)), (47, Rec::Data(w)), (97, Rec::Num(1.0, 3)), (95, Rec::Data(utf16("my.cube")))]); + let l = losses(&r); + assert_eq!(l.len(), 4, "{l:?}"); + assert!(l.iter().any(|d| d.contains("Split Toning (ADBE Lumetri-0032) is not imported")), "{l:?}"); + assert!(l.iter().any(|d| d.contains("Wheels (ADBE Lumetri-0047) is not imported")), "{l:?}"); + assert!(l.iter().any(|d| d.contains("Legacy Tone And Saturation (ADBE Lumetri-0097) is on")), "{l:?}"); + assert!(l.iter().any(|d| d.contains("the Input LUT 'my.cube' is not imported")), "{l:?}"); +} + +#[test] +fn an_unknown_scale_or_parameter_is_reported_not_guessed() { + let mut d = defs(); + // Exposure with another valid range (an older or newer version): not guessed at. + if let Some((_, Def::Float { min, max, .. })) = d.iter_mut().find(|(s, _)| *s == 11) { + (*min, *max) = (-100.0, 100.0); + } + // A parameter this importer does not know, set. + d.push((200, Def::Float { name: "Future", default: 0.0, min: -1.0, max: 1.0 })); + let (g, r) = run_with(&d, &[(11, Rec::Num(3.0, 1)), (200, Rec::Num(0.5, 1))]); + assert_eq!(num(&g, "basicCorrection/tone/exposure"), 0.0); + let l = losses(&r); + assert!(l.iter().any(|x| x.contains("Exposure (ADBE Lumetri-0011) has the valid maximum Some(100.0), expected 7")), "{l:?}"); + assert!(l.iter().any(|x| x.contains("Future (ADBE Lumetri-0200) not imported")), "{l:?}"); +} diff --git a/crates/effects/src/color3.rs b/crates/effects/src/color3.rs index 4850710ab..d4cdedd98 100644 --- a/crates/effects/src/color3.rs +++ b/crates/effects/src/color3.rs @@ -705,32 +705,37 @@ fn lumetri(ctx: &EffectCtx, mut b: Buf) -> Buf { pub fn specs() -> Vec { let grey = || col(0.5, 0.5, 0.5); + // After Effects' valid ranges (a value past the slider's drag range is still kept: .aep + // import, 1200), the slider over the range After Effects' slider covers. + let wb = || slider(-300.0, 300.0, -100.0, 100.0, 1); + let tone = || slider(-150.0, 150.0, -100.0, 100.0, 1); + let sat = || slider(0.0, 300.0, 0.0, 200.0, 1); let mut lum = vec![ p("highDynamicRange", "High Dynamic Range", Value::Bool(false), ParamUi::Checkbox), p("basicCorrection/inputLut", "Input LUT", Value::Enum(0), popup(&["None", "Custom"])), // A .cube file path (or the file's text) for Input LUT = Custom. p("basicCorrection/inputLutFile", "Input LUT File", Value::Str(String::new()), ParamUi::Text), - p("basicCorrection/whiteBalance/temperature", "Temperature", num(0.0), bipolar()), - p("basicCorrection/whiteBalance/tint", "Tint", num(0.0), bipolar()), - p("basicCorrection/tone/exposure", "Exposure", num(0.0), slider(-5.0, 5.0, -5.0, 5.0, 2)), - p("basicCorrection/tone/contrast", "Contrast", num(0.0), bipolar()), - p("basicCorrection/tone/highlights", "Highlights", num(0.0), bipolar()), - p("basicCorrection/tone/shadows", "Shadows", num(0.0), bipolar()), - p("basicCorrection/tone/whites", "Whites", num(0.0), bipolar()), - p("basicCorrection/tone/blacks", "Blacks", num(0.0), bipolar()), + p("basicCorrection/whiteBalance/temperature", "Temperature", num(0.0), wb()), + p("basicCorrection/whiteBalance/tint", "Tint", num(0.0), wb()), + p("basicCorrection/tone/exposure", "Exposure", num(0.0), slider(-7.0, 7.0, -5.0, 5.0, 2)), + p("basicCorrection/tone/contrast", "Contrast", num(0.0), tone()), + p("basicCorrection/tone/highlights", "Highlights", num(0.0), tone()), + p("basicCorrection/tone/shadows", "Shadows", num(0.0), tone()), + p("basicCorrection/tone/whites", "Whites", num(0.0), tone()), + p("basicCorrection/tone/blacks", "Blacks", num(0.0), tone()), p("basicCorrection/tone/hdrWhite", "HDR White", num(100.0), slider(100.0, 10000.0, 100.0, 4000.0, 0)), - p("basicCorrection/tone/hdrSpecular", "HDR Specular", num(0.0), bipolar()), - p("basicCorrection/saturation", "Saturation", num(100.0), slider(0.0, 200.0, 0.0, 200.0, 1)), + p("basicCorrection/tone/hdrSpecular", "HDR Specular", num(0.0), tone()), + p("basicCorrection/saturation", "Saturation", num(100.0), sat()), p("creative/look", "Look", Value::Enum(0), popup(&LUMETRI_LOOKS)), p("creative/lookFile", "Look File", Value::Str(String::new()), ParamUi::Text), p("creative/lookIntensity", "Intensity", num(100.0), slider(0.0, 200.0, 0.0, 200.0, 1)), - p("creative/adjustments/fadedFilm", "Faded Film", num(0.0), pct()), + p("creative/adjustments/fadedFilm", "Faded Film", num(0.0), slider(0.0, 150.0, 0.0, 100.0, 1)), p("creative/adjustments/sharpen", "Sharpen", num(0.0), bipolar()), p("creative/adjustments/vibrance", "Vibrance", num(0.0), bipolar()), - p("creative/adjustments/creativeSaturation", "Saturation", num(100.0), slider(0.0, 200.0, 0.0, 200.0, 1)), + p("creative/adjustments/creativeSaturation", "Saturation", num(100.0), sat()), p("creative/adjustments/shadowTint", "Shadow Tint", grey(), ParamUi::Color), p("creative/adjustments/highlightTint", "Highlight Tint", grey(), ParamUi::Color), - p("creative/adjustments/tintBalance", "Tint Balance", num(0.0), bipolar()), + p("creative/adjustments/tintBalance", "Tint Balance", num(0.0), tone()), ]; const CURVES: [(&str, &str); 12] = [ ("curves/curveMasterShadows", "RGB Curve Shadows"), @@ -786,13 +791,13 @@ pub fn specs() -> Vec { p("hslSecondary/key/maskStyle", "Mask Style", Value::Enum(0), popup(&HSL_MASK_STYLES)), p("hslSecondary/key/invertMask", "Invert Mask", Value::Bool(false), ParamUi::Checkbox), p("hslSecondary/refine/denoise", "Denoise", num(0.0), pct()), - p("hslSecondary/refine/blur", "Blur", num(0.0), pct()), + p("hslSecondary/refine/blur", "Blur", num(0.0), slider(0.0, 1000.0, 0.0, 100.0, 1)), p("hslSecondary/correction/correctionWheel", "Correction", grey(), ParamUi::Color), - p("hslSecondary/correction/temperature", "Temperature", num(0.0), bipolar()), - p("hslSecondary/correction/tint", "Tint", num(0.0), bipolar()), - p("hslSecondary/correction/contrast", "Contrast", num(0.0), bipolar()), + p("hslSecondary/correction/temperature", "Temperature", num(0.0), wb()), + p("hslSecondary/correction/tint", "Tint", num(0.0), wb()), + p("hslSecondary/correction/contrast", "Contrast", num(0.0), tone()), p("hslSecondary/correction/sharpen", "Sharpen", num(0.0), bipolar()), - p("hslSecondary/correction/saturation", "Saturation", num(100.0), slider(0.0, 200.0, 0.0, 200.0, 1)), + p("hslSecondary/correction/saturation", "Saturation", num(100.0), sat()), p("vignette/vignetteAmount", "Amount", num(0.0), slider(-5.0, 5.0, -5.0, 5.0, 2)), p("vignette/vignetteMidpoint", "Midpoint", num(50.0), pct()), p("vignette/vignetteRoundness", "Roundness", num(0.0), bipolar()), diff --git a/docs/aep-format.md b/docs/aep-format.md index fcc8f53be..9a37b384f 100644 --- a/docs/aep-format.md +++ b/docs/aep-format.md @@ -534,6 +534,44 @@ suffix is a parameter id, not the `parT` position (Curves -0002 Channel before - -0005 Quality before -0004). API: `CurvesData`, `MeshData`, `curve_lut`. [V; details: corpus FORMAT S] +**Lumetri Color** (`ADBE Lumetri`, 1200: 58 compositions made by script in After Effects 2026, 32 bpc, +working space None; defaults, all set, one per section, valid minima and maxima, every popup item the +script can set, checkboxes toggled, keys, an expression): 131 `parT` entries. The `-NNNN` suffix is a +parameter id, not the position (`-0127` ... `-0130` sit between `-0005` and `-0026`), so the importer +keys by suffix. Float sliders (type 10) store the value After Effects shows; the valid ranges (`pard` +104 / 108) are wider than the slider's (112 / 116): Temperature / Tint -300..300 (slider -100..100), +Saturation 0..300 (0..200), Exposure -7..7 (-5..5), Contrast, Highlights, Shadows, Whites, Blacks, +HDR Specular, Tint Balance -150..150 (-100..100), Faded Film 0..150 (0..100), HDR White 100..1000, +HDR Range 100..10000, Refine Blur 0..1000 (0..30), Vignette Amount -5..5 (-3..3); the read-backs of +`-19-min` / `-20-max` equal the stored numbers. **Hidden controls are recorded in the default state** +(`tdsb` 3) and still hold the value After Effects reads back: High Dynamic Range `-0062` (1.0), +HDR Specular `-0064` (22), the second Look popup `-0128` (26.16 as set, read back 26), Legacy Tone And +Saturation `-0097`, Auto Color `-0124`, Face Detection `-0102`, the Auto Intensity `-0123` +(`EffectParam::recorded_value`). Each section has an Active checkbox (blank `pard` name; `-0003` Basic +Correction, `-0023` Creative, `-0037` Curves, `-0118` RGB Curves, `-0104` / `-0105` / `-0107` / `-0109` / +`-0111` the hue / saturation curves, `-0046` Color Wheels, `-0068` HSL Secondary, `-0050` Vignette, on +by default); off, the section does nothing (`-03-sec-basic-correction`, `-17-sec-vignette` render as +`-00-defaults`). Arbitrary data (type 11, a record and `aRbs` in every instance; empty is `fe fe`): +`-0001` an XML copy of the grade written only when the Look changes (not kept current: `-01-set-all` +holds defaults for controls set after the Look); `-0096` the Look's name, UTF-16LE (`SL BLUE ICE`; the +popup `-0025` itself has no record, `-0128` can disagree with it: `-07-sec-creative` names item 20 +while `-0128` holds 23), `-0095` likewise for the Input LUT (H, by analogy: no sample sets a LUT); +`-0129` the Look colour space's 16-byte id (the GUID `LookColorSpace` of `-0001`, byte-swapped; zero +for None; the Color Space popup `-0130` writes no record of its own, `-22-pop38-1` ... `-53-pop38-33`); +`-0032` Split Toning (32 zero bytes); `-0039` the four RGB curves and `-0042`, `-0106`, `-0108`, +`-0110`, `-0112` the hue / saturation curves, 520 bytes each: `i32` type (3 for the hue curves, 2 for +Luma vs Sat and Sat vs Sat, 0 for an RGB curve), `u32` point count, then little-endian `f64` pairs x, y +(RGB: (0, 0), (1, 1) by default; hue / saturation: no points, and the selector colours `-0113` ... +`-0117` add three points at y = 0, the hue picked +- 0.0556; no sample moves a point, so y's scale is +H); `-0047` Color Wheels (4 x `f64` triples, 0, 0.5, 0 each) and `-0085` the HSL correction wheels (8 +triples, the same); `-0073` the HSL key, 40 bytes: a flag byte (1 once a colour was picked), then hue, +saturation, lightness, each centre, range, tolerance (`f32` LE, fractions) and an enabled byte (fresh: +0.5, 0, 0, on; picking RGB 0.02 0.55 0.85 gives hue centre 0.5605 = that colour's hue and lightness +centre 0.435 = its HSL lightness, range 0.05, tolerance 0.1: `-01-set-all`; whether range is the half +or full width is H); `-0122` the Auto Tone analysis (UTF-16 JSON). Curves, LUTs and wheels are not +scriptable: the presets for them are still to be made. [V for the sliders, checkboxes, popups and the +`tdsb` 3 values; H where marked] + ### 3.8 Masks and bezier paths (`tdgp[ADBE Mask Parade]`) | Field | Chunk path | Offset | Type | Meaning | Evidence | Conf. | diff --git a/docs/aep-import.md b/docs/aep-import.md index baeb8d0e1..07c089782 100644 --- a/docs/aep-import.md +++ b/docs/aep-import.md @@ -1,6 +1,6 @@ # After Effects project import -> **Last reviewed:** 2026-10-19 · **Last updated:** 2026-10-19 · **Change:** Curves and Mesh Warp are imported (961-965, 985; FORMAT S of the corpus); before that: a shape item's eye switch is imported (bit 0 of its group flags, 986 / 987: a switched-off Fill under Trim Paths is no longer drawn, render equal to After Effects), and a layer style's (switch group `tdsb` 0, 988); before that: a negative time stretch (Time Reverse Layer) is imported: in and out point in order, the layer plays backwards (981-983: render equal to After Effects at 7 points); before that: After Effects' None on Compound Blur, Displacement Map and Set Matte arrives as an explicit None (`NO_LAYER`), not as the owning layer; before that: layer styles are imported (the nine styles and Blending Options, 951-979; Global Light becomes the composition's); before that: the 27 effects of round 3 are in the table (`effectcraft_aep::effect_map`); before that: a layer of a clip, sequence or sound ends at its source's end (After Effects ends it there when it opens a project, read-back test f1), unless it is remapped or looped or runs less than a frame past; before that: keys of shape colours are read (the reader took their 152-byte spatial records for plain ones: `tdb4` byte 7 is 0 there, 854); before that: the effect table moved to `effectcraft_aep::effect_map`; point defaults in percent and a popup default slot of 0 (After Effects' save of a project it opened, e1 / e2 re-saves) are read; before that: the justification of right-to-left paragraphs is read relative to the direction (t7); before that: 24 more layer blend modes (906, 907); before that: 27 more effects are imported (batch 6: 903-905), with layer parameters; before that: a Rec. 709 working space also sets the output space (After Effects renders in the working space, 902); before that: a mask whose path was never set arrives as the source rectangle (900, 901); before that: Offset Paths' Copy Offset arrives as EffectCraft's (After Effects' value minus 1, 828); before that: project settings, image sequences, conformed clips and effect instance names are imported, next to the mattes, shapes, text settings and animators, effects, markers, time remapping, cameras and lights); before that: parallel and ambient lights (701, 702) and keyed Orientation (703) are imported; before that: masks on text and shape layers (705, 706: AE vs EffectCraft render 12 and 0 of 5184 points, glyph edges) and Merge Paths, Offset Paths, Repeater (707-710, 731; merge renders equal but for edges; Repeater copy opacity and Offset Paths' outline differ in EffectCraft's renderer) are imported; before that: keyframes: the ease of Anchor Point, effect point, effect colour and mask path keys is imported (597-599, 700, 730: within 0.5 px of After Effects' read-backs); before that: effects: Directional Blur, Radial Blur, CC Radial Blur, Venetian Blinds, Channel Blur, Black & White, Tritone, Luma Key, Simple Choker, Matte Choker and Transform are imported (711-723; render checks: CC Radial Blur and Channel Blur equal, Directional Blur within 5/255; Venetian Blinds, Radial Blur, Black & White (8/255), Tritone (19/255), Luma Key, Matte Choker and Transform differ in EffectCraft's renderer, see STATUS); before that: text: character and paragraph settings (stroke, scales, baseline shift, kerning, ligatures, tsume, indents, spacing, justified text, composer, direction, vertical text; 538-578) and text animators with range selectors (579-594, 114) are imported; render checks 594 (keyed range selector at 0 / 0.5 / 1 / 1.5 / 2.5 s), 595, 596 equal but for glyph edges; before that: cameras, spot and point lights, X / Y Rotation and Orientation, Timewarp and expressions on effect parameters are imported (render checks 486, 535-537 equal but for edges; 488 differs by 5.25 %, cause in EffectCraft's renderer not isolated); before that: text: superscript and subscript are imported (526-528); before that: effects: Invert, Fast Box Blur, Gaussian Blur, Drop Shadow, Glow, Fill, Hue/Saturation, Levels and five expression controls are imported, popups are mapped by item name, checkbox defaults come from the file; before that: shape layers are imported (groups, paths, paints, trim paths, round corners; 451-484, 519 added); before that: markers and Time Remapping are imported (509, 510 added); before that: track mattes are imported (402-408); before that: text: automatic leading is verified (400); effects: Exposure is imported (Channels, all twelve sliders, Bypass, keys), next to Tint and Gradient Ramp; before that: text: U+0003 is a paragraph break (386, 387); before that: a stored text Anchor Point is pixels (385, now V); before that: effects: Tint and Gradient Ramp are imported (all parameters and keys), other effects stay reported; `.aepx` is accepted; text layers are imported (Source Text with style runs, paragraphs and box text; fonts by PostScript name, missing fonts listed); layer styles are reported; before that: layer masks · **Target:** Adobe After Effects 2026 +> **Last reviewed:** 2026-11-05 · **Last updated:** 2026-11-05 · **Change:** Lumetri Color is imported (1200: every slider, checkbox and popup with a counterpart, by match name, also from records in the default state; switched-off sections, LUTs, looks, undecoded curves and wheels are reported); before that: Curves and Mesh Warp are imported (961-965, 985; FORMAT S of the corpus); before that: a shape item's eye switch is imported (bit 0 of its group flags, 986 / 987: a switched-off Fill under Trim Paths is no longer drawn, render equal to After Effects), and a layer style's (switch group `tdsb` 0, 988); before that: a negative time stretch (Time Reverse Layer) is imported: in and out point in order, the layer plays backwards (981-983: render equal to After Effects at 7 points); before that: After Effects' None on Compound Blur, Displacement Map and Set Matte arrives as an explicit None (`NO_LAYER`), not as the owning layer; before that: layer styles are imported (the nine styles and Blending Options, 951-979; Global Light becomes the composition's); before that: the 27 effects of round 3 are in the table (`effectcraft_aep::effect_map`); before that: a layer of a clip, sequence or sound ends at its source's end (After Effects ends it there when it opens a project, read-back test f1), unless it is remapped or looped or runs less than a frame past; before that: keys of shape colours are read (the reader took their 152-byte spatial records for plain ones: `tdb4` byte 7 is 0 there, 854); before that: the effect table moved to `effectcraft_aep::effect_map`; point defaults in percent and a popup default slot of 0 (After Effects' save of a project it opened, e1 / e2 re-saves) are read; before that: the justification of right-to-left paragraphs is read relative to the direction (t7); before that: 24 more layer blend modes (906, 907); before that: 27 more effects are imported (batch 6: 903-905), with layer parameters; before that: a Rec. 709 working space also sets the output space (After Effects renders in the working space, 902); before that: a mask whose path was never set arrives as the source rectangle (900, 901); before that: Offset Paths' Copy Offset arrives as EffectCraft's (After Effects' value minus 1, 828); before that: project settings, image sequences, conformed clips and effect instance names are imported, next to the mattes, shapes, text settings and animators, effects, markers, time remapping, cameras and lights); before that: parallel and ambient lights (701, 702) and keyed Orientation (703) are imported; before that: masks on text and shape layers (705, 706: AE vs EffectCraft render 12 and 0 of 5184 points, glyph edges) and Merge Paths, Offset Paths, Repeater (707-710, 731; merge renders equal but for edges; Repeater copy opacity and Offset Paths' outline differ in EffectCraft's renderer) are imported; before that: keyframes: the ease of Anchor Point, effect point, effect colour and mask path keys is imported (597-599, 700, 730: within 0.5 px of After Effects' read-backs); before that: effects: Directional Blur, Radial Blur, CC Radial Blur, Venetian Blinds, Channel Blur, Black & White, Tritone, Luma Key, Simple Choker, Matte Choker and Transform are imported (711-723; render checks: CC Radial Blur and Channel Blur equal, Directional Blur within 5/255; Venetian Blinds, Radial Blur, Black & White (8/255), Tritone (19/255), Luma Key, Matte Choker and Transform differ in EffectCraft's renderer, see STATUS); before that: text: character and paragraph settings (stroke, scales, baseline shift, kerning, ligatures, tsume, indents, spacing, justified text, composer, direction, vertical text; 538-578) and text animators with range selectors (579-594, 114) are imported; render checks 594 (keyed range selector at 0 / 0.5 / 1 / 1.5 / 2.5 s), 595, 596 equal but for glyph edges; before that: cameras, spot and point lights, X / Y Rotation and Orientation, Timewarp and expressions on effect parameters are imported (render checks 486, 535-537 equal but for edges; 488 differs by 5.25 %, cause in EffectCraft's renderer not isolated); before that: text: superscript and subscript are imported (526-528); before that: effects: Invert, Fast Box Blur, Gaussian Blur, Drop Shadow, Glow, Fill, Hue/Saturation, Levels and five expression controls are imported, popups are mapped by item name, checkbox defaults come from the file; before that: shape layers are imported (groups, paths, paints, trim paths, round corners; 451-484, 519 added); before that: markers and Time Remapping are imported (509, 510 added); before that: track mattes are imported (402-408); before that: text: automatic leading is verified (400); effects: Exposure is imported (Channels, all twelve sliders, Bypass, keys), next to Tint and Gradient Ramp; before that: text: U+0003 is a paragraph break (386, 387); before that: a stored text Anchor Point is pixels (385, now V); before that: effects: Tint and Gradient Ramp are imported (all parameters and keys), other effects stay reported; `.aepx` is accepted; text layers are imported (Source Text with style runs, paragraphs and box text; fonts by PostScript name, missing fonts listed); layer styles are reported; before that: layer masks · **Target:** Adobe After Effects 2026 File ▸ Import ▸ After Effects Project… (`file.importAep`) reads an `.aep` or its XML form `.aepx` and adds its items to the open project, in a folder named after the file (as After Effects does when it imports a project). @@ -58,7 +58,7 @@ outside the sampled ones keeps the current value and is reported as `project set | Text | the Source Text of a text layer: the text (paragraphs separated by CR; a hard line break is a CR too; U+0003 is laid out by After Effects exactly like a CR (386 against 387) and becomes a CR), per style run the font (PostScript name), size, fill and stroke colour, whether fill and stroke are drawn, stroke width, stroke over fill (one switch for the text), tracking, leading (automatic or explicit), faux bold, faux italic, all caps, small caps, superscript and subscript (526-528), horizontal and vertical scale, baseline shift, automatic kerning (metrics, optical, none), ligatures, tsume (538-578); per paragraph the justification (left, centre, right and the four justified variants), first-line / start / end indent, space before / after, direction, composer, hanging punctuation (in a right-to-left paragraph the stored justification is relative to the direction: After Effects lays 0 and 3 out flush right and 1 and 4 flush left, read-back test t7, so they arrive as right / left); point text or box text (box size and top-left in layer pixels); vertical right-to-left text (575) | | Text animators | every animator with its name and its range selectors (Start, End, Offset, or the Index range when Units is Index; Units, Based On, Mode, Amount, Shape, Smoothness, Ease High / Low, Randomize Order, Random Seed) and the properties Anchor Point, Position, Scale, Skew, Skew Axis, Rotation, Opacity, Fill Color, Stroke Color, Stroke Width, Tracking Amount, Line Spacing, Blur, Character Offset and Character Range, with keys and expressions (579-594, 114, 728). Values are stored as After Effects shows them; popups are 1-based in the file | | Masks | every mask of an imported layer, in stack order (on text and shape layers, which have no source, the stored mask box is in layer pixels: 705, 706): name, path (vertices and tangents in layer pixels, open or closed), mode (None, Add, Subtract, Intersect, Lighten, Darken, Difference), inverted, feather (x, y in pixels), opacity (percent), expansion (pixels); path keyframes (time, linear or hold sides, roving, label), feather / opacity / expansion keyframes with ease | -| Effects | **Curves** (961-964: the five curves' points from the arbitrary data as EffectCraft's `x,y` points in 0..1; render within 6 levels: EffectCraft interpolates monotone, After Effects stores a natural spline) and **Mesh Warp** (965, 985: Rows, Columns, Quality and the Distortion Mesh as per-vertex offsets in layer pixels; Bezier handles moved on their own are kept as eight extra numbers of the vertex for the export and reported, EffectCraft draws the mesh bilinear; the header is rows + 1, columns + 1; render 985: 1.4 % of pixels > 2 levels around the moved vertex), **Tint**, **Gradient Ramp**, **Exposure**, **Invert**, **Fast Box Blur**, **Gaussian Blur**, **Drop Shadow**, **Glow**, **Fill**, **Hue/Saturation**, **Levels**, **Timewarp** (Method, Adjust Time By, Speed with keys, Source Frame; 529-533), **Directional Blur**, **Radial Blur**, **CC Radial Blur**, **Venetian Blinds**, **Channel Blur**, **Black & White**, **Tritone**, **Luma Key**, **Simple Choker**, **Matte Choker**, **Transform** (all parameters; 711-723) and the expression controls **Slider**, **Angle**, **Checkbox**, **Color** and **Point Control** (table below) on any imported layer (also text and shape layers and layers with masks), in stack order, with the instance name, every parameter (static value or default) and its keyframes; also the second and later instances of a type, whose parameter definitions are only in the project's shared definition list. Other effects are reported (below) | +| Effects | **Lumetri Color** (1200; see *Lumetri Color* below), **Curves** (961-964: the five curves' points from the arbitrary data as EffectCraft's `x,y` points in 0..1; render within 6 levels: EffectCraft interpolates monotone, After Effects stores a natural spline) and **Mesh Warp** (965, 985: Rows, Columns, Quality and the Distortion Mesh as per-vertex offsets in layer pixels; Bezier handles moved on their own are kept as eight extra numbers of the vertex for the export and reported, EffectCraft draws the mesh bilinear; the header is rows + 1, columns + 1; render 985: 1.4 % of pixels > 2 levels around the moved vertex), **Tint**, **Gradient Ramp**, **Exposure**, **Invert**, **Fast Box Blur**, **Gaussian Blur**, **Drop Shadow**, **Glow**, **Fill**, **Hue/Saturation**, **Levels**, **Timewarp** (Method, Adjust Time By, Speed with keys, Source Frame; 529-533), **Directional Blur**, **Radial Blur**, **CC Radial Blur**, **Venetian Blinds**, **Channel Blur**, **Black & White**, **Tritone**, **Luma Key**, **Simple Choker**, **Matte Choker**, **Transform** (all parameters; 711-723) and the expression controls **Slider**, **Angle**, **Checkbox**, **Color** and **Point Control** (table below) on any imported layer (also text and shape layers and layers with masks), in stack order, with the instance name, every parameter (static value or default) and its keyframes; also the second and later instances of a type, whose parameter definitions are only in the project's shared definition list. Other effects are reported (below) | | Layer styles | Drop Shadow, Inner Shadow, Outer Glow, Inner Glow, Bevel and Emboss, Satin, Color Overlay, Gradient Overlay and Stroke when applied (switch group `tdsb` 1): every parameter, starting from After Effects' defaults (Use Global Light is off there), with keys on scalars and colours and expressions; Blending Options: Fill Opacity, the channel switches, Blend Interior Styles as Group, Use Blend Ranges, and Global Light Angle / Altitude, which the composition adopts (one setting per composition here). Units and popups through `effectcraft_aep::style_map` (aep-format 3.12b). Render check against After Effects (`proof\styles`): drop shadow, inner shadow, satin, colour overlay, stroke within a few levels; glow and bevel intensities and the Gradient Overlay direction differ in EffectCraft's renderer | | Shape layers | groups (nested, with anchor, position, scale, skew, skew axis, rotation, opacity), rectangle (size, position, roundness), ellipse (size, position), polystar (star or polygon, points, position, rotation, radii, roundness), bezier path (vertices and tangents in layer pixels, path keys), fill (colour, opacity, fill rule), stroke (colour, opacity, width, cap, join, miter limit), gradient fill and stroke (linear or radial, start and end point; the default white-to-black colours), trim paths (start, end, offset, trim multiple shapes), round corners (radius), merge paths (mode; 707, 708), offset paths (amount, line join, miter limit, copies, copy offset; 710; After Effects offsets copy *i* by Amount x (*i* + Copy Offset), default 1, EffectCraft by Amount x (*i* + 1 + copyOffset), so the copy offset arrives 1 less, also its keys; an expression on it is kept and reported; 826-828, 828 renders equal to After Effects on every grid point), repeater (copies, offset, composite, transform; 709), in file order, with keyframes and expressions, the operators' defaults as After Effects reads them back (731); the layer anchor in pixels; 238-242, 330-333, 451-484, 519, 705-710, 731 | | Markers | layer and composition markers: time (layer time for layer markers, exact frames), duration (1/600 s units, 509, 510), comment, chapter, URL, frame target, label, cue point (name, event or navigation, parameters); 122, 123, 249, 347-349, 509, 510 | @@ -179,6 +179,7 @@ parameter gets the file's value: | `ADBE Easy Levels2` 1 Channel, 2 Histogram data, 8 / 9 Clip To Output Black / White | `channel`; `inBlack`, `inWhite`, `gamma`, `outBlack`, `outWhite` from the data; `clipToOutputBlack`, `clipToOutputWhite` | popups by name (After Effects' items On, Off, Off for 32 bpc Color are in another order here); the RGB values are the `f32` of the arbitrary data; the per-channel values are reported when they are not at their defaults (not sampled) | 511-516 | | Batch 6 (903 defaults, 904 / 905 set values): `ADBE Brightness & Contrast 2`, `ADBE Turbulent Displace`, `ADBE Fractal Noise`, `ADBE Laser` (Beam), `CC Radial Fast Blur`, `ADBE Noise2`, `ADBE Pro Levels2` (Levels (Individual Controls)), `ADBE Corner Pin`, `ADBE Grid`, `ADBE Sharpen`, `ADBE Linear Color Key2`, `ADBE Radial Wipe`, `ADBE Remove Color Matting`, `CC Bend It`, `CC Power Pin`, `ADBE 4ColorGradient`, `ADBE Change Color`, `ADBE Extract`, `ADBE Noise HLS2`, `ADBE Scatter`, `CC Light Sweep`, `ADBE Compound Blur`, `ADBE Displacement Map`, `ADBE Set Matte3`, `ADBE Gaussian Blur` (legacy), `ADBE OFMotionBlur` (Pixel Motion Blur), `ADBE Layer Control` | the EffectCraft effect of the same name, every parameter EffectCraft has | sliders as stored (each checked against its valid maximum); Beam Length, Time and Softness and CC Power Pin Perspective are 0..1 fractions, percentages here; points as layer pixels; popups by item name (Set Matte's `Red Channel` ... is `Red` ...); twirl-down group markers and the Levels histogram carry nothing; **layer parameters** (below) | 903, 904, 905; 220, 320, 321 | | `ADBE Slider Control`, `ADBE Angle Control`, `ADBE Checkbox Control`, `ADBE Color Control`, `ADBE Point Control` (parameter 1) | `ec.control.slider` `slider`, `ec.control.angle` `angle`, `ec.control.checkbox` `checkbox`, `ec.control.color` `color`, `ec.control.point` `point` | float (valid max 1 000 000) as stored; degrees; checkbox; colour; point in layer pixels | 071, 073, 217-219, 221, 304, 310 | +| `ADBE Lumetri` by match-name suffix (1200), not by index: -0062 High Dynamic Range; -0063 HDR White; -0007 / -0008 Temperature / Tint; -0020 Saturation; -0011 Exposure; -0012 ... -0016 Contrast, Highlights, Shadows, Whites, Blacks; -0064 HDR Specular; -0026 Look Intensity; -0028 Faded Film; -0029 Sharpen; -0030 Vibrance; -0031 Saturation; -0033 Tint Balance; -0074 Show Mask; -0075 mask style; -0076 Invert Mask; -0081 Denoise; -0082 Blur; -0086 ... -0090 the HSL correction's Temperature, Tint, Contrast, Sharpen, Saturation; -0051 ... -0054 Vignette Amount, Midpoint, Roundness, Feather; -0073 the HSL key data | `highDynamicRange`, `basicCorrection/tone/hdrWhite`, `basicCorrection/whiteBalance/temperature` / `tint`, `basicCorrection/saturation`, `basicCorrection/tone/exposure`, `.../contrast`, `highlights`, `shadows`, `whites`, `blacks`, `hdrSpecular`, `creative/lookIntensity`, `creative/adjustments/fadedFilm`, `sharpen`, `vibrance`, `creativeSaturation`, `tintBalance`, `hslSecondary/key/showMask`, `maskStyle`, `invertMask`, `hslSecondary/refine/denoise`, `blur`, `hslSecondary/correction/*`, `vignette/*`; `hslSecondary/key/hue*`, `saturation*`, `lightness*` | sliders: the stored number x 1 (valid maxima 1000, 300, 300, 7, 150, 200, 150, 100, 100, 300, 150, 100, 1000, 5, 100 as in `pard`); checkboxes and the popup as elsewhere, **also from records in the default state** (`tdsb` 3); the key: hue centre x 360 degrees, range x 360 as the half width, tolerance x 360 as the softness, saturation and lightness centre +- range x 100 percent, tolerance x 100, once a colour was picked | 1200: all 62 read-backs of mapped controls in sections that act equal after import (min, max, sections, popups); the other 61 lie in sections that do nothing and are reported; keys and the expression on HDR White (`-56-keys`, `-57-expr`) | - **Nothing to import:** the implicit input-layer parameter (index 0), the Swap Colors buttons (Tint 4, Ramp 8: they always have a record and hold no value), Exposure's twirl-down group @@ -230,6 +231,28 @@ parameter gets the file's value: column just outside the layer: After Effects' Glow draws a dark halo about 10 px wide outside the layer (red 0.55, 0.65, 0.74, 0.92 at 0, 1, 2, 5 px), EffectCraft's Glow none (an effect difference, recorded for a separate fix). +- **Lumetri Color** (1200, `crates/aep/src/import/lumetri.rs`). The parameters are found by match + name (After Effects inserted `-0127` ... `-0130` mid-list; five tone sliders share one valid range, + so an index shift would not be caught). Values come from every value record, also those in the + default state (`tdsb` 3), where Lumetri keeps High Dynamic Range, HDR Specular and the second Look + popup. EffectCraft's Lumetri has no section switches: a section that is off in After Effects + (Basic Correction, Creative, Curves / RGB Curves, each hue / saturation curve, Color Wheels, HSL + Secondary, Vignette), and HSL Secondary without a picked key colour, does nothing there, so its set + values are listed in one report line and not imported (the frame stays as After Effects draws it). + The Input LUT and the Look are reported by name (LUT files are not in the project). Controls + without a counterpart (the Auto tone's Intensity, RGB Curves' HDR Range, Color Wheels' HDR White and + Face Detection, Legacy Tone And Saturation, Auto Color, SpeedGrade Custom Layer), the eyedropper + colours, and the RGB curves, colour wheels, Split Toning, HSL correction wheels and moved hue / + saturation curve points (not sampled) are reported when set. Render check at 0.5 s against After + Effects' 32 bpc PNGs (stored as value x 6553.5 in 16 bits, so read as raw / 6553.5): every + composition whose grade After Effects draws as identity (defaults, set-all with every section off, + the switched-off sections, the popups, keys, expression) is within 1/255 in EffectCraft; the + graded ones differ by EffectCraft's Lumetri formulas, not by the import: White Balance (sec-color: + After Effects warms and brightens, max 0.10 above the default; EffectCraft darkens, mean error + 0.015), Exposure / tone (sec-light: After Effects rolls highlights off and lifts the blacks to 0.18, + EffectCraft clips at 1 and keeps black at 0; mean 0.12), Creative adjustments (sec-adjustments: + Faded Film lifts black to 0.07 in After Effects, 0.035 here) and the extremes (min / max: mean 0.063 / + 0.454; max: After Effects' vignette at +5 and the tone sliders give mid grey, EffectCraft white). - **Colour.** After Effects stores the colour its picker shows as ARGB doubles 0..255 in the project's working-space encoding; EffectCraft's parameter colours are straight RGBA 0..1 that the render pipeline hands to the effect as stored (`crates/render/src/color.rs`: authored colours are @@ -389,5 +412,5 @@ crate yet. ## Not done yet -Effects outside the table (Lumetri; EXtractoR: its channel choice is arbitrary data; Stroke: its path is a mask reference), environment lights, the ease of bezier Orientation keys, wiggly and expression selectors and the other text animator properties (Character Value, Character Alignment other than its default, the Hue / Saturation / Brightness / Opacity variants, 3D rotations, variable font axes), manual kerning, No Break, the stroke line join, the Japanese leading model, Source Text keyframes, layer-style gradients, Pattern Overlay and the switch state 3, Mesh Warp handles moved on their own, +Lumetri Color's section switches (a switched-off section is reported and its values left out), its LUTs and looks (files After Effects names: reported by name), its RGB curves, colour wheels, Split Toning and HSL correction wheels (not sampled: reported when set) and moved hue / saturation curve points (the scale of y is not sampled); effects outside the table (EXtractoR: its channel choice is arbitrary data; Stroke: its path is a mask reference), environment lights, the ease of bezier Orientation keys, wiggly and expression selectors and the other text animator properties (Character Value, Character Alignment other than its default, the Hue / Saturation / Brightness / Opacity variants, 3D rotations, variable font axes), manual kerning, No Break, the stroke line join, the Japanese leading model, Source Text keyframes, layer-style gradients, Pattern Overlay and the switch state 3, Mesh Warp handles moved on their own, separated dimensions and footage interpretation need verified layouts in the reader first. diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index 5ef21511d..f94fc3789 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -22,7 +22,7 @@ trips and renders, checked by tests, not against After Effects), **partial** (na | Format | After Effects | EffectCraft read | Write | Fidelity / notes | Tested by | |---|---|---|---|---|---| -| Project `.aep` | R/W (native) | partial | none | Main file format; the clean-room method is in [aep-format.md](aep-format.md), the maintainers' decision on it is open (#190). `crates/aep` reads and writes the RIFX container losslessly (byte-identical round trip) with a typed view of the decoded fields, from our own generated files only ([aep-format.md](aep-format.md)). File ▸ Import ▸ After Effects Project… (`file.importAep`, `effectcraft_aep::import`): folders, project settings, compositions, every layer kind, Transform, keyframes, expressions, masks, text with animators, shapes, cameras, lights, track mattes, markers, time remapping, layer styles, the built-in effects of a table (Curves, Levels, Glow, Fractal Noise, Gradient Ramp, … and the expression controls), footage and image sequences; everything else is reported ([aep-import.md](aep-import.md)). Export to `.aep` is not built yet. Effects outside the table (plug-ins, Lumetri, …) are not converted | `crates/aep` tests (`tests/it`: `container`, `import`) | +| Project `.aep` | R/W (native) | partial | none | Main file format; the clean-room method is in [aep-format.md](aep-format.md), the maintainers' decision on it is open (#190). `crates/aep` reads and writes the RIFX container losslessly (byte-identical round trip) with a typed view of the decoded fields, from our own generated files only ([aep-format.md](aep-format.md)). File ▸ Import ▸ After Effects Project… (`file.importAep`, `effectcraft_aep::import`): folders, project settings, compositions, every layer kind, Transform, keyframes, expressions, masks, text with animators, shapes, cameras, lights, track mattes, markers, time remapping, layer styles, the built-in effects of a table (Lumetri Color, Curves, Levels, Glow, Fractal Noise, Gradient Ramp, … and the expression controls), footage and image sequences; everything else is reported ([aep-import.md](aep-import.md)). Export to `.aep` is not built yet. Effects outside the table (plug-ins, …) are not converted | `crates/aep` tests (`tests/it`: `container`, `import`) | | XML project `.aepx` | R/W | partial | none | Read into the same chunk tree as `.aep` by `crates/aep` (`read_aepx`; mapping in [aep-format.md](aep-format.md) section 1), so `file.importAep` imports it with the same coverage as `.aep`; not written | `crates/aep` `aepx` tests (container and import) | | Templates `.aet` / `.aetx` | R/W | none | none | Own `.ectemplate` (Home ▸ Templates, Save as Template) | `templates.rs` tests | | Motion Graphics template `.mogrt` | W (and R in Premiere) | none | none | Own `.ectemplate` Essential Graphics templates; FilmCraft rejects our `.fcgt` export (#611) | `essential.rs` tests | From 9c25944c700ab7ac8463462b006f34425b8e6a39 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Thu, 5 Nov 2026 17:45:19 +0100 Subject: [PATCH 04/40] AEP import: EXtractoR's and IDentifier's chosen channels by name Presets of our own (blocks 1300 and 1310) show what the Channel Info stores for a chosen channel. - EXtractoR: each record is a kind in byte 0 and the channel name. Named channels are imported by name (Z, Z, Z renders equal to After Effects) and `(copy)` as the input's own channel. The kind is byte 0 only: one definition default has `02 00 00 32`. - IDentifier: byte 19 holds the chosen channel's name, `Object ID` when none is chosen. After Effects lists only UINT channels and leaves the layer unchanged without one, which the loss now says. A chosen `ObjectID` / `MaterialID` channel (any case) is the one EffectCraft reads itself, so it imports without a loss; other names are reported. Co-Authored-By: Claude Opus 5.5 --- crates/aep/src/container/arbitrary.rs | 39 +++++++++--- crates/aep/src/container/effect_map.rs | 4 +- crates/aep/src/import/effects.rs | 49 +++++++++++---- .../aep/tests/it/import/effects_thirdparty.rs | 62 +++++++++++++++---- docs/aep-format.md | 24 +++++-- docs/aep-import.md | 14 ++++- 6 files changed, 149 insertions(+), 43 deletions(-) diff --git a/crates/aep/src/container/arbitrary.rs b/crates/aep/src/container/arbitrary.rs index 7b47e83c7..cbcc56c53 100644 --- a/crates/aep/src/container/arbitrary.rs +++ b/crates/aep/src/container/arbitrary.rs @@ -309,10 +309,14 @@ impl MeshData { } /// EXtractoR's Channel Info data (`EXtractoR-0013`, 688 bytes, the plug-in's own little-endian -/// layout; read from the default instances of the importer block of 2026-11-05, where no channel -/// was changed): a `u32` 1 and 28 bytes, then four records of 164 bytes (Red, Green, Blue, Alpha), -/// each a `u32` kind (1 a named channel, 2 the input's channel: `(copy)` on Alpha) and the channel -/// name from byte 35, NUL-terminated. Only the default (`R`, `G`, `B`, `(copy)`) is sampled. +/// layout; read from the instances of the importer block of 2026-11-05: the defaults and a preset +/// of our own that reads `Z` into Red, Green and Blue): a `u32` 1 and 28 bytes, then four records +/// of 164 bytes (Red, Green, Blue, Alpha), each a kind in byte 0 (1 a channel of the footage by +/// name, 2 the input's own channel: `(copy)`; bytes 1..4 are not always zero, `0x32` at 3 in one +/// definition's default, so only byte 0 is read) and the channel name from byte 35, +/// NUL-terminated. The other bytes are not read (they differ between instances with the same +/// channels; the `u32` at 4 of a chosen channel looks like its position in the footage's sorted +/// channel list, 13 of 14 for `Z`, where the defaults hold 0). Only the name is read. #[derive(Debug, Clone, PartialEq, Eq)] pub struct ExtractorChannels { /// Per output channel (red, green, blue, alpha): the kind and the name. @@ -333,7 +337,7 @@ impl ExtractorChannels { for (k, slot) in channels.iter_mut().enumerate() { let at = 32usize.checked_add(k.checked_mul(Self::RECORD)?)?; let rec = data.get(at..at.checked_add(Self::RECORD)?)?; - let kind = u32::from_le_bytes(*rec.first_chunk::<4>()?); + let kind = u32::from(*rec.first()?); let name = rec.get(35..)?; let end = name.iter().position(|b| *b == 0)?; let name = std::str::from_utf8(name.get(..end)?).ok()?; @@ -348,11 +352,30 @@ impl ExtractorChannels { let want = [(1, "R"), (1, "G"), (1, "B"), (2, "(copy)")]; self.channels.iter().zip(want).all(|((k, n), (wk, wn))| *k == wk && n == wn) } + + /// Per output channel (red, green, blue, alpha) the channel it reads, `Err` with the + /// position of the first record of another kind or without a name: a named channel by its + /// name, `(copy)` as the input's own channel of the same position (`R`, `G`, `B`, `A`). + pub fn sources(&self) -> Result<[String; 4], usize> { + const OWN: [&str; 4] = ["R", "G", "B", "A"]; + let mut out: [String; 4] = Default::default(); + for (k, ((kind, name), slot)) in self.channels.iter().zip(out.iter_mut()).enumerate() { + *slot = match (kind, name.trim()) { + (1, n) if !n.is_empty() => n.to_string(), + (2, _) => OWN.get(k).ok_or(k)?.to_string(), + _ => return Err(k), + }; + } + Ok(out) + } } -/// IDentifier's Channel Info data (`IDentifier-0005`, 148 bytes): the channel type's name, -/// NUL-terminated from byte 19 (`Object ID` in every sample of the importer block of 2026-11-05; -/// the bytes around it differ between instances with the same settings and are not read). +/// IDentifier's Channel Info data (`IDentifier-0005`, 148 bytes): the chosen channel's name, +/// NUL-terminated from byte 19, or `Object ID` when none is chosen (importer blocks 1300 and 1310 +/// of 2026-11-05: `objectId` in a preset of our own that chose that UINT channel, `Object ID` in +/// every other instance). The bytes around it differ between instances with the same settings +/// and are not read (a chosen channel has 15 at byte 4, which looks like its position in the +/// EXR's sorted channel list, as for EXtractoR). pub fn identifier_channel_type(data: &[u8]) -> Option<&str> { let s = data.get(19..)?; let end = s.iter().position(|b| *b == 0)?; diff --git a/crates/aep/src/container/effect_map.rs b/crates/aep/src/container/effect_map.rs index 46fcf39ea..7f426bcd1 100644 --- a/crates/aep/src/container/effect_map.rs +++ b/crates/aep/src/container/effect_map.rs @@ -138,9 +138,9 @@ pub enum Extra { Curves, /// Mesh Warp's Distortion Mesh (965, 985, `MeshData`). MeshWarp, - /// EXtractoR's Channel Info (`ExtractorChannels`): the default channels only. + /// EXtractoR's Channel Info (`ExtractorChannels`): the channels by name. Extractor, - /// IDentifier's Channel Info (`identifier_channel_type`): Object ID only. + /// IDentifier's Channel Info (`identifier_channel_type`): the chosen channel by name. Identifier, } diff --git a/crates/aep/src/import/effects.rs b/crates/aep/src/import/effects.rs index a9fa3c2c7..5a8a60285 100644 --- a/crates/aep/src/import/effects.rs +++ b/crates/aep/src/import/effects.rs @@ -465,44 +465,67 @@ fn import_extra(fx: &AepEffect<'_, '_>, extra: Extra, p: &EffectParam<'_, '_>, h Some(m) => import_mesh(&m, here, size, group, col), None => col.lose(LossCategory::DamagedData, format!("{here}: the Distortion Mesh is unreadable, defaults used")), }, - Extra::Extractor => match ExtractorChannels::parse(data) { - // The fresh channels: EffectCraft's own R, G, B, A (its A is the input's alpha, After - // Effects' `(copy)`). - Some(c) if c.is_default() => { - for (id, name) in [("red", "R"), ("green", "G"), ("blue", "B"), ("alpha", "A")] { + Extra::Extractor => match ExtractorChannels::parse(data).map(|c| (c.sources(), c)) { + // Each output channel reads the footage's channel of the stored name, which + // EffectCraft's EXtractoR finds by the same name (`Z`); After Effects' `(copy)` is the + // input's own channel, EffectCraft's R, G, B or A (the fresh channels are R, G, B, A). + Some((Ok(names), _)) => { + for (id, name) in ["red", "green", "blue", "alpha"].into_iter().zip(names) { if let Some(prop) = group.prop_mut(id) { - prop.value = Value::Str(name.into()); + prop.value = Value::Str(name); } } } - Some(c) => { + Some((Err(k), c)) => { let names: Vec<&str> = c.channels.iter().map(|(_, n)| n.as_str()).collect(); col.lose( LossCategory::Effects, - format!("{here}: the channels {} are not imported (only the default channels are sampled), R, G, B, A used", names.join(", ")), + format!( + "{here}: the channels {} are not imported (record {} is of an unknown kind or names no channel), R, G, B, A used", + names.join(", "), + k.saturating_add(1) + ), ); } None => col.lose(LossCategory::Effects, format!("{here}: the Channel Info data is not in the sampled layout, R, G, B, A used")), }, Extra::Identifier => match crate::identifier_channel_type(data) { + // No channel chosen (the type's label): After Effects lists only the footage's integer + // (UINT) channels and, with none chosen, leaves the layer unchanged, where EffectCraft + // draws the footage's object ID channel. Some("Object ID") => { if let Some(prop) = group.prop_mut("channelType") { prop.value = Value::Enum(0); } - // The data names the type, not the channel After Effects reads: with this Channel - // Info After Effects left the sampled EXR unchanged, where EffectCraft draws the - // footage's object ID channel. col.lose( LossCategory::Effects, - format!("{here}: the channel IDentifier reads (Channel Info) is not decoded; EffectCraft uses the footage's object ID channel"), + format!("{here}: no ID channel is chosen (Channel Info), so After Effects leaves the layer unchanged; EffectCraft draws the footage's object ID channel"), ); } - other => col.lose(LossCategory::Effects, format!("{here}: the channel type {other:?} is not imported (only Object ID is sampled), Object ID used")), + // A chosen channel, by name. EffectCraft's IDentifier has no channel of its own: it + // reads the footage's first `ObjectID` (`MaterialID`) channel, names compared without + // regard to case, so a channel of that name is the one After Effects reads. + Some(name) => match IDENTIFIER_OWN.iter().position(|own| own.eq_ignore_ascii_case(name.trim())) { + Some(kind) => { + if let Some(prop) = group.prop_mut("channelType") { + prop.value = Value::Enum(u32::try_from(kind).unwrap_or(0)); + } + } + None => col.lose( + LossCategory::Effects, + format!("{here}: the ID channel '{name}' (Channel Info) is not imported; EffectCraft reads the footage's object ID channel (ObjectID, object_id, objectId, id)"), + ), + }, + None => col.lose(LossCategory::Effects, format!("{here}: the Channel Info data is not in the sampled layout, the object ID channel used")), }, Extra::None => {} } } +/// The channels EffectCraft's IDentifier reads first for its Channel Type Object ID and Material +/// ID (`AuxChannels::object_id`, `material_id`). +const IDENTIFIER_OWN: [&str; 2] = ["ObjectID", "MaterialID"]; + /// Curves' EffectCraft parameters, in the stored order (RGB, Red, Green, Blue, Alpha). const CURVE_IDS: [&str; 5] = ["rgb", "red", "green", "blue", "alpha"]; diff --git a/crates/aep/tests/it/import/effects_thirdparty.rs b/crates/aep/tests/it/import/effects_thirdparty.rs index 20f0b8230..7bf1ad3c8 100644 --- a/crates/aep/tests/it/import/effects_thirdparty.rs +++ b/crates/aep/tests/it/import/effects_thirdparty.rs @@ -112,6 +112,11 @@ fn extractor_channel_info_layout() { assert!(!c.is_default()); assert_eq!(c.channels[0], (1, "Z".to_string())); assert_eq!(ExtractorChannels::parse(&[0u8; 10]), None); + // The kind is byte 0 of a record: the definition default of `extractor-00-defaults` has + // `02 00 00 32` on Alpha, still the input's own channel. + let c = ExtractorChannels::parse(&channels([(1, "R"), (1, "G"), (1, "B"), (0x3200_0002, "(copy)")])).expect("parses"); + assert!(c.is_default()); + assert_eq!(c.sources(), Ok(["R", "G", "B", "A"].map(String::from))); } #[test] @@ -129,12 +134,32 @@ fn extractor_points_unmult_and_default_channels() { } } +/// `extractor-07-preset-channel-z` (a preset of our own): `Z` into Red, Green and Blue, Alpha +/// `(copy)`. EffectCraft's EXtractoR reads the footage's channel by the same name. #[test] -fn extractor_channels_other_than_the_default_are_reported() { +fn extractor_channels_are_imported_by_name() { let (g, r) = run(&extractor(vec![], channels([(1, "Z"), (1, "Z"), (1, "Z"), (2, "(copy)")])), "ec.3d.extractor"); - let found = losses(&r, LossCategory::Effects, "EXtractoR"); - assert!(found.len() == 1 && found[0].contains("the channels Z, Z, Z, (copy) are not imported"), "{found:?}"); - assert_eq!(v(&g.expect("imported"), "red"), Value::Str("R".into())); + assert_eq!(losses(&r, LossCategory::Effects, "EXtractoR"), Vec::::new()); + let g = g.expect("imported"); + for (id, want) in [("red", "Z"), ("green", "Z"), ("blue", "Z"), ("alpha", "A")] { + assert_eq!(v(&g, id), Value::Str(want.into()), "{id}"); + } + // `(copy)` on another channel is that channel of the input. + let (g, _) = run(&extractor(vec![], channels([(2, "(copy)"), (1, "CryptoObject00.R"), (2, "(copy)"), (1, "Z")])), "ec.3d.extractor"); + let g = g.expect("imported"); + for (id, want) in [("red", "R"), ("green", "CryptoObject00.R"), ("blue", "B"), ("alpha", "Z")] { + assert_eq!(v(&g, id), Value::Str(want.into()), "{id}"); + } +} + +#[test] +fn extractor_channels_of_an_unknown_kind_are_reported() { + for recs in [[(1, "Z"), (3, "Z"), (1, "Z"), (2, "(copy)")], [(1, "Z"), (1, ""), (1, "Z"), (2, "(copy)")]] { + let (g, r) = run(&extractor(vec![], channels(recs)), "ec.3d.extractor"); + let found = losses(&r, LossCategory::Effects, "EXtractoR"); + assert!(found.len() == 1 && found[0].contains("are not imported (record 2 is of an unknown kind or names no channel)"), "{recs:?}: {found:?}"); + assert_eq!(v(&g.expect("imported"), "red"), Value::Str("R".into()), "{recs:?}"); + } } /// IDentifier's Channel Info: the channel type's name at 19 among bytes that are not read. @@ -164,16 +189,31 @@ fn identifier(values: Vec<(usize, f64)>, data: Vec) -> Fx { #[test] fn identifier_display_id_and_channel_type() { assert_eq!(identifier_channel_type(&id_info("Object ID")), Some("Object ID")); - // `identifier-01-set-all` (ID 10) and `identifier-05-pop2-3` (Alpha Matte). + // `identifier-01-set-all` (ID 10) and `identifier-05-pop2-3` (Alpha Matte): no channel chosen + // (After Effects found none or none was picked), so After Effects leaves the layer unchanged. let (g, r) = run(&identifier(vec![(2, 3.0), (3, 10.0)], id_info("Object ID")), "ec.3d.identifier"); - // Which channel After Effects reads is not decoded (it left the sampled EXR unchanged): reported. let found = losses(&r, LossCategory::Effects, "IDentifier"); - assert!(found.len() == 1 && found[0].contains("is not decoded"), "{found:?}"); + assert!(found.len() == 1 && found[0].contains("no ID channel is chosen"), "{found:?}"); let g = g.expect("imported"); assert_eq!((v(&g, "display"), v(&g, "channelType")), (Value::Enum(2), Value::Enum(0))); near(&g, "id", 10.0); - // A channel type that is not sampled is reported. - let (_, r) = run(&identifier(vec![], id_info("Material ID")), "ec.3d.identifier"); - let found = losses(&r, LossCategory::Effects, "IDentifier"); - assert!(found.len() == 1 && found[0].contains("\"Material ID\""), "{found:?}"); +} + +/// `identifier-09-preset-channel-objectid-id2` (1310, a preset of our own): the UINT channel +/// `objectId` chosen and ID 2. EffectCraft's IDentifier reads that channel itself (`ObjectID` +/// without regard to case), so nothing is lost; another name is reported. +#[test] +fn identifier_chosen_channels_by_name() { + for (name, kind) in [("objectId", 0), ("ObjectID", 0), ("materialid", 1)] { + let (g, r) = run(&identifier(vec![(3, 2.0)], id_info(name)), "ec.3d.identifier"); + assert_eq!(losses(&r, LossCategory::Effects, "IDentifier"), Vec::::new(), "{name}"); + let g = g.expect("imported"); + assert_eq!(v(&g, "channelType"), Value::Enum(kind), "{name}"); + near(&g, "id", 2.0); + } + for name in ["IndexOB.X", "ID", "Material ID"] { + let (_, r) = run(&identifier(vec![], id_info(name)), "ec.3d.identifier"); + let found = losses(&r, LossCategory::Effects, "IDentifier"); + assert!(found.len() == 1 && found[0].contains(&format!("the ID channel '{name}' (Channel Info) is not imported")), "{name}: {found:?}"); + } } diff --git a/docs/aep-format.md b/docs/aep-format.md index 29ee51963..7b9e67981 100644 --- a/docs/aep-format.md +++ b/docs/aep-format.md @@ -542,12 +542,24 @@ data layouts, read from default instances only):** | `EXtractoR` (2.6.6) | 1 Channel Info (`EXtractoR-0013`): arbitrary data, 688 bytes, below; 2-6 the Process group: 3 Black Point and 4 White Point float sliders, valid ±3.4028235e38 (the float32 range; slider ±1 000), default 0 / 1; 5 UnMult: checkbox (empty `pard` name, the label in `pdnm`), default off | | `IDentifier` (2.6.6) | 1 Channel Info (`IDentifier-0005`): arbitrary data, 148 bytes, below; 2 Display: popup (Colors, Luma Matte, Alpha Matte, Raw), default 1; 3 ID: integer slider, max 2 147 483 647, default 0 | -EXtractoR's Channel Info is the plug-in's own **little-endian** layout: `u32` 1 and 28 zero bytes, -then four 164-byte records (Red, Green, Blue, Alpha), each a `u32` kind (1 in R, G, B; 2 in Alpha, -whose name is `(copy)`) and the channel name NUL-terminated from record byte 35 (`R`, `G`, `B`). -The data is the same in every composition of the block. IDentifier's data differs between -instances with the same settings except for the channel type's name, NUL-terminated from byte 19 -(`Object ID`); the other bytes are not read. API: `ExtractorChannels`, `identifier_channel_type`. +EXtractoR's Channel Info is the plug-in's own **little-endian** layout: `u32` 1 and 28 bytes, then +four 164-byte records (Red, Green, Blue, Alpha), each a kind in byte 0 (1 a channel of the footage by +name: `R`, `G`, `B` by default; 2 the input's own channel, named `(copy)`: Alpha by default) and the +channel name NUL-terminated from record byte 35. The rest is not read: it differs between instances +with the same channels (uninitialised-looking values, also in bytes 1..4 of a record: `02 00 00 32` +on Alpha in one definition's default, which is why only byte 0 is the kind). **A chosen channel** +(`extractor-07-preset-channel-z`, a preset of our own that reads `Z` into Red, Green and Blue) is kind +1 with its name (`Z`), and the `u32` at record byte 4 is then 13, which looks like the channel's +position in the EXR's sorted channel list of 14 (the defaults hold 0 there: H). IDentifier's data +differs between instances with the same settings except for **the chosen channel's name**, +NUL-terminated from byte 19, which is `Object ID` when no channel is chosen. After Effects lists +only integer (UINT) channels: in 1300's EXR (a FLOAT `ID` channel) it found none ("No ID channels +available"), so that block's preset `identifier-09-preset-channel-id` only sets ID 2; in 1310's +EXR (UINT `objectId` and `IndexOB.X` added) the preset `identifier-09-preset-channel-objectid-id2` +stores `objectId`, with 15 at byte 4 (the channel's position in the sorted list of 16, as for +EXtractoR: H). Without a chosen channel After Effects leaves the layer unchanged (1300 and 1310 +defaults). The other bytes are not read. API: `ExtractorChannels`, +`identifier_channel_type`. **Curves and Mesh Warp** (961-965, 985; applied from presets, the data is not scriptable): their arbitrary-data parameter (type 11) always has a record (`tdbs` with a 4-byte `cdat`) and a `LIST diff --git a/docs/aep-import.md b/docs/aep-import.md index f14141156..cb61cd2ab 100644 --- a/docs/aep-import.md +++ b/docs/aep-import.md @@ -179,7 +179,7 @@ parameter gets the file's value: | `ADBE Easy Levels2` 1 Channel, 2 Histogram data, 8 / 9 Clip To Output Black / White | `channel`; `inBlack`, `inWhite`, `gamma`, `outBlack`, `outWhite` from the data; `clipToOutputBlack`, `clipToOutputWhite` | popups by name (After Effects' items On, Off, Off for 32 bpc Color are in another order here); the RGB values are the `f32` of the arbitrary data; the per-channel values are reported when they are not at their defaults (not sampled) | 511-516 | | Batch 6 (903 defaults, 904 / 905 set values): `ADBE Brightness & Contrast 2`, `ADBE Turbulent Displace`, `ADBE Fractal Noise`, `ADBE Laser` (Beam), `CC Radial Fast Blur`, `ADBE Noise2`, `ADBE Pro Levels2` (Levels (Individual Controls)), `ADBE Corner Pin`, `ADBE Grid`, `ADBE Sharpen`, `ADBE Linear Color Key2`, `ADBE Radial Wipe`, `ADBE Remove Color Matting`, `CC Bend It`, `CC Power Pin`, `ADBE 4ColorGradient`, `ADBE Change Color`, `ADBE Extract`, `ADBE Noise HLS2`, `ADBE Scatter`, `CC Light Sweep`, `ADBE Compound Blur`, `ADBE Displacement Map`, `ADBE Set Matte3`, `ADBE Gaussian Blur` (legacy), `ADBE OFMotionBlur` (Pixel Motion Blur), `ADBE Layer Control` | the EffectCraft effect of the same name, every parameter EffectCraft has | sliders as stored (each checked against its valid maximum); Beam Length, Time and Softness and CC Power Pin Perspective are 0..1 fractions, percentages here; points as layer pixels; popups by item name (Set Matte's `Red Channel` ... is `Red` ...); twirl-down group markers and the Levels histogram carry nothing; **layer parameters** (below) | 903, 904, 905; 220, 320, 321 | | Importer block 2026-11-05 (`1100-quickwins.aep`: per effect defaults, set values, minimum and maximum, every popup item, a keyed and an expression parameter): `ADBE HDR ToneMap` (HDR Highlight Compression) 1 Amount; `ADBE Echo` 1 Echo Time, 2 Number Of Echoes, 3 Starting Intensity, 4 Decay, 5 Echo Operator; `ADBE Linear Wipe` 1 Transition Completion, 2 Wipe Angle, 3 Feather; `ADBE Offset` 1 Shift Center To, 2 Blend With Original; `ADBE Deflicker` (Color Stabilizer) 1 Stabilize, 2-4 Black / Mid / White Point, 5 Sample Size | `ec.utility.hdrcompression` `amount`; `ec.time.echo` `echoTime`, `numberOfEchoes`, `startingIntensity`, `decay`, `echoOperator`; `ec.transition.linearwipe` `completion`, `angle`, `feather`; `ec.distort.offset` `shift`, `blend`; `ec.color.colorstabilizer` `stabilize`, `blackPoint`, `midPoint`, `whitePoint`, `sampleSize` | percent (float, valid 0..100, default 100); seconds (float, valid ±30 000), integer (valid 30 000), 0..1 (float), Decay as stored (float, valid 0..100), popup by name: EffectCraft's Echo uses at most 255 echoes and a Decay up to 1, a value or key beyond that is imported as stored and **reported**; percent (fixed, 100), degrees, pixels (fixed, 32 000); point in layer pixels, Blend 0..1 x 100 = percent; popup by name (**fresh default Levels**), points in layer pixels, Sample Size as stored (fixed, valid 50, default 3; its unit, pixels here, is not verified). Color Stabilizer's reference frame (Set Frame) is not a parameter in the file and is not imported (EffectCraft's Reference Frame stays 0 s) | `tests/it/import/effects_quickwins.rs`; render comparison below | -| Importer block 2026-11-05 (`1300-thirdparty.aep`), plug-ins that ship with After Effects: `CS Color Neutralizer` (CC Color Neutralizer) 19 Pinning, 20 Blend w. Original; `EXtractoR` 1 Channel Info data, 3 Black Point, 4 White Point, 5 UnMult; `IDentifier` 1 Channel Info data, 2 Display, 3 ID | `ec.color.cccolorneutralizer` `pinning`, `blendWOriginal`; `ec.3d.extractor` `red`, `green`, `blue`, `alpha`, `blackPoint`, `whitePoint`, `unMult`; `ec.3d.identifier` `channelType`, `display`, `id` | CC Color Neutralizer: percent (float, valid 100); its correction is the Red / Green / Blue slider of each range (the Unbalance colours are pickers that set them and keep no record), with View and Black / White Point: **EffectCraft's effect has no counterpart, each is reported when stored** (EffectCraft's Unbalance / Balance stay at their identity defaults). EXtractoR: the default channels (R, G, B, `(copy)`) are EffectCraft's R, G, B, A, other channels are reported (`ExtractorChannels`; only the default is sampled), Black and White Point as stored (float, valid ±3.4e38; a value beyond ±1e9 is reported as damaged data, as for every number), UnMult a checkbox, Clip stays off. IDentifier: Display by name, ID as stored (integer, valid 2 147 483 647); the Channel Info names only the channel type (Object ID, `identifier_channel_type`; another is reported), not the channel After Effects reads, so **every instance is reported**: EffectCraft draws the footage's object ID channel where After Effects left the sampled EXR unchanged | `tests/it/import/effects_thirdparty.rs`; render comparison below | +| Importer block 2026-11-05 (`1300-thirdparty.aep`), plug-ins that ship with After Effects: `CS Color Neutralizer` (CC Color Neutralizer) 19 Pinning, 20 Blend w. Original; `EXtractoR` 1 Channel Info data, 3 Black Point, 4 White Point, 5 UnMult; `IDentifier` 1 Channel Info data, 2 Display, 3 ID | `ec.color.cccolorneutralizer` `pinning`, `blendWOriginal`; `ec.3d.extractor` `red`, `green`, `blue`, `alpha`, `blackPoint`, `whitePoint`, `unMult`; `ec.3d.identifier` `channelType`, `display`, `id` | CC Color Neutralizer: percent (float, valid 100); its correction is the Red / Green / Blue slider of each range (the Unbalance colours are pickers that set them and keep no record), with View and Black / White Point: **EffectCraft's effect has no counterpart, each is reported when stored** (EffectCraft's Unbalance / Balance stay at their identity defaults). EXtractoR: each output channel by the footage channel's name, which EffectCraft's EXtractoR reads by the same name (the default R, G, B; `Z` from our preset), and `(copy)` as the input's own channel of that position (EffectCraft's R, G, B or A; the default Alpha is A); a record of another kind or without a name is reported and R, G, B, A used (`ExtractorChannels`), Black and White Point as stored (float, valid ±3.4e38; a value beyond ±1e9 is reported as damaged data, as for every number), UnMult a checkbox, Clip stays off. IDentifier: Display by name, ID as stored (integer, valid 2 147 483 647); the Channel Info names the chosen channel (`identifier_channel_type`): After Effects lists only the footage's integer (UINT) channels, and with none chosen (the data then says `Object ID`) it leaves the layer unchanged, where EffectCraft draws the footage's object ID channel: **reported**; a chosen channel named `ObjectID` or `MaterialID` (without regard to case, `objectId` in our preset) is the one EffectCraft's IDentifier reads itself (Channel Type Object ID or Material ID), any other name is reported (EffectCraft's IDentifier has no channel choice) | `tests/it/import/effects_thirdparty.rs`; render comparison below | | `ADBE Slider Control`, `ADBE Angle Control`, `ADBE Checkbox Control`, `ADBE Color Control`, `ADBE Point Control` (parameter 1) | `ec.control.slider` `slider`, `ec.control.angle` `angle`, `ec.control.checkbox` `checkbox`, `ec.control.color` `color`, `ec.control.point` `point` | float (valid max 1 000 000) as stored; degrees; checkbox; colour; point in layer pixels | 071, 073, 217-219, 221, 304, 310 | - **Nothing to import:** the implicit input-layer parameter (index 0), the Swap Colors buttons @@ -336,8 +336,16 @@ frame blending, 3D material options, audio levels, guides, the mask colour, lock within one level, the ±3.4e38 compositions differ (reported as damaged data). IDentifier: After Effects' frame is the unchanged EXR in every variant (its default Object ID finds no channel in that EXR), while EffectCraft's IDentifier finds the EXR's `ID` channel and draws it; the import - reports this for every IDentifier. No sample changes EXtractoR's channels or IDentifier's channel - type (the presets for that were missing from the block). + reports this for every IDentifier. The follow-up presets (our own): `extractor-07-preset-channel-z` + (`Z` into Red, Green and Blue) imports without a loss and renders equal to After Effects (within + 3e-5 at After Effects' 1/10 PNG scale; the background's Z of 100 clips there in both). IDentifier + needs an integer channel: block 1310 (`1310-identifier-uint.aep`, the EXR with UINT channels + `objectId` and `IndexOB.X` added) with the preset `identifier-09-preset-channel-objectid-id2` + (`objectId`, ID 2) imports without a loss, and EffectCraft's IDentifier finds the same channel: + the ID regions are the same pixels (8 449, 2 400, 1 515, 1 256, 780), the colours differ (After + Effects draws flat colours per ID and does not highlight the chosen ID, EffectCraft draws its + own ID colours with the chosen ID white). At its defaults (no channel chosen) After Effects + leaves the EXR unchanged in 1310 too. - `crates/aep/tests/it/import/combined.rs`: masks and effects on the same layer, an effect on a text layer, and the same through `.aepx` (built in-test from the fixtures: the effect parade of one fixture grafted onto the layer of another). From 6a67b4dac1f989d3ae4be3ef01656404b7144f11 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Thu, 5 Nov 2026 17:48:29 +0100 Subject: [PATCH 05/40] AEP import: Lumetri Color's master RGB curve, Hue vs Sat and colour wheels After Effects 2026 presets made by hand (1200 lumetri-58 ... -62) decode the data the scripted samples could not set. - RGB curve (-0039): the first of the four curves is the master curve and arrives as curves/rgbCurves/master. A moved red, green or blue curve is reported: no sample tells which slot is which channel. - Hue vs Sat (-0042): y is the offset from neutral, 1 doubling the saturation (in linear light), so EffectCraft's y is 0.5 + y / 2. The other four hue / saturation curves stay reported when moved. - Color Wheels (-0047): four triples of hue (degrees), brightness slider (0.5 neutral) and distance. Shadows, Midtones and Highlights become EffectCraft's wheel colours (HSL of that hue, saturation = distance, lightness 0.5); the brightness sliders and the fourth wheel are reported. - Damaged curve or wheel data is reported as damaged. - Legacy Tone And Saturation is reported when a record says on: its pard default turns from off to on when the project is saved again (the 25.x / 24.x / 26 copies of 1200), so comparing with it missed it. - The Input LUT and Look presets confirm -0095 / -0096 hold the names; the LUT files are After Effects' own and are not embedded. Evidence: the 62 read-backs still equal the imported values in the new 63-composition 1200 file. The version copies store the same Lumetri definitions, ranges and values and give the same report. Renders: master curve within 0.024 (After Effects uses a natural spline, EffectCraft's Lumetri a monotone one), Hue vs Sat mean 0.008, wheels mean 0.042. Part of #3111 Co-Authored-By: Claude Opus 5.5 --- crates/aep/src/import/lumetri.rs | 190 +++++++++++++++++++++++--- crates/aep/tests/it/import/lumetri.rs | 129 +++++++++++++++-- docs/aep-format.md | 52 ++++--- docs/aep-import.md | 26 +++- 4 files changed, 348 insertions(+), 49 deletions(-) diff --git a/crates/aep/src/import/lumetri.rs b/crates/aep/src/import/lumetri.rs index 22f28b1aa..9369155f4 100644 --- a/crates/aep/src/import/lumetri.rs +++ b/crates/aep/src/import/lumetri.rs @@ -16,11 +16,18 @@ //! After Effects; EffectCraft's Lumetri has none. A section that is off does nothing in After //! Effects (1200 `lumetri-03-sec-basic-correction`, `-17-sec-vignette` render as `-00-defaults`), //! so its values are not imported (the effect looks the same) and are listed in the report. -//! - **Arbitrary data** (`ParamKind::ArbitraryData`, every instance stores it): the hue / -//! saturation curves (a curve type, a point count, points as `f64` x, y with y an offset from -//! neutral) are imported when neutral and reported otherwise (no sample moves a point); the -//! HSL Secondary key ([`HslKey`]) is imported; the RGB curves, the colour wheels, Split Toning -//! and the correction wheels are reported when they are not the default (not sampled). +//! - **Arbitrary data** (`ParamKind::ArbitraryData`, every instance stores it). Curves are a +//! curve type, a point count and points as `f64` x, y ([`curve_points`]). +//! - The RGB curve (`-0039`) holds four curves; the first is the master (white) curve (1200 +//! `lumetri-60-preset-curves-rgb`), imported. The other three are reported when moved: no +//! sample tells which is which channel. +//! - Hue vs Sat (`-0042`): y is an offset from neutral, 1 doubling the saturation (`-61`), so +//! EffectCraft's y is `0.5 + y / 2`. The other four hue / saturation curves have no sample +//! of their scale and are reported when moved. +//! - Color Wheels (`-0047`): Shadows, Midtones, Highlights and a fourth wheel, each hue, +//! brightness slider, distance ([`import_wheels`], `-62`). +//! - The HSL Secondary key ([`HslKey`]) is imported; Split Toning and the correction wheels are +//! reported when they are not the default (not sampled). //! - **LUTs and looks.** The Input LUT and the Look are files After Effects names (the Look's name //! is UTF-16 text in `-0096`, the popups only index a list of the installed ones); they are not //! in the project, so a set one is reported by name and EffectCraft's popup stays None. @@ -82,8 +89,9 @@ impl Section { enum Data { /// The four RGB curves (4 x 520 bytes). RgbCurves, - /// One hue / saturation curve (520 bytes); the EffectCraft parameter it belongs to. - HueSatCurve, + /// One hue / saturation curve (520 bytes); the EffectCraft parameter when the scale of its y + /// is known (Hue vs Sat). + HueSatCurve(Option<&'static str>), /// Color Wheels (4 x 3 `f64`, each wheel 0, 0.5, 0 by default). Wheels, /// HSL Secondary's correction wheels (8 x 3 `f64`, the same default). @@ -105,6 +113,11 @@ enum Role { Switch, /// No counterpart: reported when not at the default. Missing, + /// A checkbox without counterpart whose `pard` default is not reliable: reported when a + /// record says on. Legacy Tone And Saturation (`-0097`) is off in a fresh instance, but its + /// `pard` default reads off in 1200 as saved by the script and on after the project was + /// opened and saved again (`versions/1200-lumetri-26`, `-25x`, `-24x`). + MissingWhenOn, /// An eyedropper colour: reported when set. Eyedropper, /// The Input LUT (`lut` true) or the Look: a popup, a name or an asset. @@ -187,19 +200,19 @@ const ROWS: &[Row] = &[ row(39, S::RgbCurves, Some(K::ArbitraryData), Role::Data(Data::RgbCurves)), row(104, S::HueSat(0), Some(K::Checkbox), Role::Switch), row(113, S::HueSat(0), Some(K::Color), Role::Eyedropper), - row(42, S::HueSat(0), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve)), + row(42, S::HueSat(0), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve(Some("curves/hueSaturationCurves/hueVsSat")))), row(105, S::HueSat(1), Some(K::Checkbox), Role::Switch), row(114, S::HueSat(1), Some(K::Color), Role::Eyedropper), - row(106, S::HueSat(1), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve)), + row(106, S::HueSat(1), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve(None))), row(107, S::HueSat(2), Some(K::Checkbox), Role::Switch), row(115, S::HueSat(2), Some(K::Color), Role::Eyedropper), - row(108, S::HueSat(2), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve)), + row(108, S::HueSat(2), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve(None))), row(109, S::HueSat(3), Some(K::Checkbox), Role::Switch), row(116, S::HueSat(3), Some(K::Color), Role::Eyedropper), - row(110, S::HueSat(3), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve)), + row(110, S::HueSat(3), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve(None))), row(111, S::HueSat(4), Some(K::Checkbox), Role::Switch), row(117, S::HueSat(4), Some(K::Color), Role::Eyedropper), - row(112, S::HueSat(4), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve)), + row(112, S::HueSat(4), Some(K::ArbitraryData), Role::Data(Data::HueSatCurve(None))), // Color Wheels: 46 the switch, 102 Face Detection (on by default), 66 HDR White, 47 the wheels. row(46, S::ColorWheels, Some(K::Checkbox), Role::Switch), row(102, S::ColorWheels, Some(K::Checkbox), Role::Missing), @@ -235,7 +248,7 @@ const ROWS: &[Row] = &[ row(60, S::SpeedGradeCustom, Some(K::ArbitraryData), Role::Data(Data::Other)), // Outside the sections: Legacy Tone And Saturation, the embedded LUTs, Auto Tone, Auto Color, // the LUT and Look assets. - row(97, S::Always, Some(K::Checkbox), Role::Missing), + row(97, S::Always, Some(K::Checkbox), Role::MissingWhenOn), row(98, S::Always, Some(K::ArbitraryData), Role::Data(Data::Other)), row(99, S::Always, Some(K::ArbitraryData), Role::Data(Data::Other)), row(100, S::Always, Some(K::ArbitraryData), Role::Data(Data::Other)), @@ -355,7 +368,11 @@ fn utf16_text(d: &[u8]) -> Option { /// A Lumetri curve (520 bytes): `i32` curve type at 0 (3 for the hue curves, which wrap; 2 for /// Luma vs Sat and Sat vs Sat; 0 for an RGB curve), the `u32` point count at 4, then the points -/// as little-endian `f64` pairs x, y from byte 8 (at most 32). `None` when the count does not fit. +/// as little-endian `f64` pairs x, y from byte 8 (at most 32), sorted by x. Bytes after the +/// counted points are stale (a fresh hue curve has count 0 and old points behind it). An RGB +/// curve's x and y are 0..1 (2 points 0,0 and 1,1 by default); a hue / saturation curve's x is +/// the hue (0 red, 1/3 green) or the luma / saturation, 0..1, and y its offset from neutral. +/// `None` when the count does not fit. fn curve_points(d: &[u8]) -> Option> { let n = usize::try_from(le_u32(d, 4)?).ok()?; if n > d.len().saturating_sub(8) / 16 { @@ -418,7 +435,7 @@ fn data_default(data: Data, d: Option<&[u8]>) -> bool { Data::RgbCurves => { d.len() == 4 * 520 && d.as_chunks::<520>().0.iter().all(|c| curve_points(c).is_some_and(|pts| pts.iter().all(|(x, y)| (x - y).abs() < 1e-9))) } - Data::HueSatCurve => curve_points(d).is_some_and(|pts| pts.iter().all(|(_, y)| *y == 0.0)), + Data::HueSatCurve(_) => curve_points(d).is_some_and(|pts| pts.iter().all(|(_, y)| *y == 0.0)), Data::Wheels => wheels_default(d, 4), Data::CorrectionWheels => wheels_default(d, 8), Data::SplitToning | Data::Other => is_empty_data(Some(d)), @@ -552,6 +569,11 @@ pub(crate) fn import_lumetri(fx: &AepEffect<'_, '_>, params: &[EffectParam<'_, ' col.lose(LossCategory::Effects, format!("{here}: parameter {label} is off and has no counterpart")); } } + Role::MissingWhenOn => { + if p.is_animated() || matches!(p.recorded_value(), Some(ParamValue::Bool(true))) { + col.lose(LossCategory::Effects, format!("{here}: parameter {label} is on and has no counterpart, not imported")); + } + } Role::Missing => { if is_set(p) { col.lose( @@ -575,8 +597,20 @@ pub(crate) fn import_lumetri(fx: &AepEffect<'_, '_>, params: &[EffectParam<'_, ' } if !data_default(d, data()) { let why = match d { - Data::HueSatCurve => "the curve's points are moved; no sample tells their scale", - Data::RgbCurves | Data::Wheels | Data::CorrectionWheels | Data::SplitToning => "the data is not decoded (not sampled)", + Data::RgbCurves => { + import_rgb_curves(data(), (&here, &label), &mut *group, &mut *col); + continue; + } + Data::HueSatCurve(Some(target)) => { + import_hue_sat_curve(data(), target, (&here, &label), &mut *group, &mut *col); + continue; + } + Data::Wheels => { + import_wheels(data(), (&here, &label), &mut *group, &mut *col); + continue; + } + Data::HueSatCurve(None) => "the curve's points are moved; no sample tells their scale", + Data::CorrectionWheels | Data::SplitToning => "the data is not decoded (not sampled)", Data::HslKey | Data::Other => "no counterpart", }; col.lose(LossCategory::Effects, format!("{here}: parameter {label} is not imported ({why})")); @@ -640,3 +674,125 @@ fn import_hsl_key(d: Option<&[u8]>, here: &str, group: &mut effectcraft_project: set(&format!("{id}Softness"), Value::Scalar((t * 100.0).clamp(0.0, 100.0))); } } + +/// A parameter of `group` set to `v` (ids the spec does not have are skipped). +fn set_prop(group: &mut effectcraft_project::PropGroup, id: &str, v: Value) { + if let Some(prop) = group.prop_mut(id) { + prop.value = v; + } +} + +/// Curve points as EffectCraft's `x,y x,y ...` text, x and y clamped to 0..1; `None` when a value +/// is not finite. +fn points_text(pts: impl IntoIterator) -> Option { + let mut out: Vec = Vec::new(); + for (x, y) in pts { + if !x.is_finite() || !y.is_finite() { + return None; + } + out.push(format!("{},{}", x.clamp(0.0, 1.0), y.clamp(0.0, 1.0))); + } + Some(out.join(" ")) +} + +/// The RGB curve (`-0039`, four curves of 520 bytes). The first is the master curve (1200 +/// `lumetri-60-preset-curves-rgb`: its midpoint raised to 0.787 lifts R, G and B alike) and +/// becomes `curves/rgbCurves/master`. The other three are the channel curves, but no sample moves +/// one, so which is red, green or blue is not known: a moved one is reported. +fn import_rgb_curves(d: Option<&[u8]>, (here, label): (&str, &str), group: &mut effectcraft_project::PropGroup, col: &mut crate::import::report::Collector) { + let Some(d) = d else { return }; + let curves: Option>> = if d.len() == 4 * 520 { d.as_chunks::<520>().0.iter().map(|c| curve_points(c)).collect() } else { None }; + let Some(curves) = curves else { + col.lose(LossCategory::DamagedData, format!("{here}: the data of {label} is unreadable, the curves are not imported")); + return; + }; + let identity = |pts: &[(f64, f64)]| pts.iter().all(|(x, y)| (x - y).abs() < 1e-9); + if let Some(master) = curves.first().filter(|c| !identity(c)) { + match points_text(master.iter().copied()) { + Some(text) => set_prop(group, "curves/rgbCurves/master", Value::Str(text)), + None => col.lose(LossCategory::DamagedData, format!("{here}: the master curve of {label} has unreadable points, not imported")), + } + } + let moved = curves.iter().skip(1).filter(|c| !identity(c)).count(); + if moved > 0 { + col.lose( + LossCategory::Effects, + format!("{here}: {moved} channel curve(s) of {label} are not imported (no sample tells which curve is red, green or blue)"), + ); + } +} + +/// Hue vs Sat (`-0042`): After Effects' y is an offset from neutral where 1 doubles the +/// saturation (1200 `lumetri-61-preset-curves-huesat`: a point at hue 0.0155, y 0.97 scales pure +/// red's saturation by about 1.96 in linear light; pins at -0.03 and -0.02 scale green, blue and +/// cyan by 0.97). EffectCraft's y = 1 doubles it and 0.5 is neutral, so y becomes `0.5 + y / 2`. +/// x is the hue in both (0 red, 1/3 green). +fn import_hue_sat_curve( + d: Option<&[u8]>, + target: &str, + (here, label): (&str, &str), + group: &mut effectcraft_project::PropGroup, + col: &mut crate::import::report::Collector, +) { + let Some(d) = d else { return }; + match curve_points(d).and_then(|pts| points_text(pts.into_iter().map(|(x, y)| (x, 0.5 + y / 2.0)))) { + Some(text) => set_prop(group, target, Value::Str(text)), + None => col.lose(LossCategory::DamagedData, format!("{here}: the data of {label} is unreadable, the curve is not imported")), + } +} + +/// The colour EffectCraft's wheel takes for After Effects' hue (degrees, 0 red, 120 green) and +/// distance from the centre (0..1): the HSL colour of that hue with saturation = distance and +/// lightness 0.5 (grey 0.5 at distance 0). EffectCraft's wheel adds that colour's offset from its +/// grey, so the direction is After Effects' and the strength grows with the distance. +fn wheel_colour(hue: f64, distance: f64) -> [f64; 4] { + let c = distance.clamp(0.0, 1.0); + let h = hue.rem_euclid(360.0) / 60.0; + let x = c * (1.0 - (h.rem_euclid(2.0) - 1.0).abs()); + let (r, g, b) = match h { + h if h < 1.0 => (c, x, 0.0), + h if h < 2.0 => (x, c, 0.0), + h if h < 3.0 => (0.0, c, x), + h if h < 4.0 => (0.0, x, c), + h if h < 5.0 => (x, 0.0, c), + _ => (c, 0.0, x), + }; + let m = 0.5 - c / 2.0; + [r + m, g + m, b + m, 1.0] +} + +/// Color Wheels (`-0047`, 96 bytes): four wheels of three little-endian `f64`, the hue in degrees, +/// the brightness slider (0..1, 0.5 neutral) and the distance from the centre (0..1); `0, 0.5, 0` +/// each by default. The first three are Shadows, Midtones and Highlights (1200 +/// `lumetri-62-preset-wheels`: Shadows 229 degrees (blue), slider 0.37, distance 0.55; Midtones +/// 0.1 degrees (red), 0.5, 0.39; Highlights 93 degrees (yellow-green), 0.73, 0.32); the fourth is +/// not known. Hue and distance become EffectCraft's wheel colour ([`wheel_colour`]); the brightness +/// sliders and a set fourth wheel have no counterpart and are reported. +fn import_wheels(d: Option<&[u8]>, (here, label): (&str, &str), group: &mut effectcraft_project::PropGroup, col: &mut crate::import::report::Collector) { + let Some(d) = d else { return }; + let wheels: Option> = if d.len() == 4 * 24 { + (0..4).map(|w| Some([le_f64(d, w * 24)?, le_f64(d, w * 24 + 8)?, le_f64(d, w * 24 + 16)?]).filter(|v| v.iter().all(|x| x.is_finite()))).collect() + } else { + None + }; + let Some(wheels) = wheels else { + col.lose(LossCategory::DamagedData, format!("{here}: the data of {label} is unreadable, the colour wheels are not imported")); + return; + }; + let mut lost: Vec = Vec::new(); + for (w, (id, name)) in wheels.iter().zip([("shadowsWheel", "Shadows"), ("midtonesWheel", "Midtones"), ("highlightsWheel", "Highlights")]) { + let [hue, brightness, distance] = *w; + if distance != 0.0 { + set_prop(group, &format!("colorWheels/{id}"), Value::Color(wheel_colour(hue, distance))); + } + if (brightness - 0.5).abs() > 1e-9 { + lost.push(format!("{name} brightness {brightness:.3} (0.5 is neutral)")); + } + } + if wheels.get(3).is_some_and(|w| *w != [0.0, 0.5, 0.0]) { + lost.push("the fourth wheel (its role is not known)".to_string()); + } + if !lost.is_empty() { + col.lose(LossCategory::Effects, format!("{here}: {label}: {} not imported (no counterpart)", lost.join(", "))); + } +} diff --git a/crates/aep/tests/it/import/lumetri.rs b/crates/aep/tests/it/import/lumetri.rs index 526f43648..a3ec9138b 100644 --- a/crates/aep/tests/it/import/lumetri.rs +++ b/crates/aep/tests/it/import/lumetri.rs @@ -172,6 +172,7 @@ fn defs() -> Vec<(u16, Def)> { (39, Def::Data { name: "RGB Curve" }), (104, Def::Check { default: true }), (42, Def::Data { name: "Hue vs Sat" }), + (106, Def::Data { name: "Hue vs Hue" }), (47, Def::Data { name: "Wheels" }), (68, Def::Check { default: true }), (73, Def::Data { name: "HSL Sliders" }), @@ -195,6 +196,7 @@ fn default_data() -> Vec<(u16, Rec)> { (32, Rec::Data(vec![0; 32])), (39, Rec::Data(rgb_curves())), (42, Rec::Data(curve(3, &[]))), + (106, Rec::Data(curve(3, &[]))), (47, Rec::Data(wheels(4))), (73, Rec::Data(hex(HSL_FRESH))), (85, Rec::Data(wheels(8))), @@ -372,20 +374,112 @@ fn a_look_is_reported_by_name() { } #[test] -fn hue_saturation_curves_with_neutral_points_arrive_moved_ones_are_reported() { +fn hue_vs_sat_arrives_with_its_y_scaled_other_moved_curves_are_reported() { // 1200 `-11-sec-hue-saturation-curves`: the selector put three neutral points on the curve. let neutral = curve(3, &[(0.742_483, 0.0), (0.798_038, 0.0), (0.853_594, 0.0)]); let (g, r) = run(&[(42, Rec::Data(neutral))]); assert_eq!(losses(&r), Vec::::new()); assert_eq!(val(&g, "curves/hueSaturationCurves/hueVsSat"), Value::Str(String::new())); - let (_, r) = run(&[(42, Rec::Data(curve(3, &[(0.5, 0.25)])))]); + // 1200 `-61-preset-curves-huesat`: red raised to 0.97 (After Effects nearly doubles its + // saturation), the neighbours pinned near 0. EffectCraft's y: 0.5 + y / 2. + let preset = curve(3, &[(0.015_463_917_525_773_196, 0.97), (0.262_886_597_938_144_34, -0.03), (0.764_604_810_996_563_5, -0.02)]); + let (g, r) = run(&[(42, Rec::Data(preset))]); + assert_eq!(losses(&r), Vec::::new()); + let Value::Str(text) = val(&g, "curves/hueSaturationCurves/hueVsSat") else { panic!("a point list") }; + let pts: Vec<(f64, f64)> = text + .split(' ') + .map(|p| { + let (x, y) = p.split_once(',').unwrap(); + (x.parse().unwrap(), y.parse().unwrap()) + }) + .collect(); + let want = [(0.015_464, 0.985), (0.262_887, 0.485), (0.764_605, 0.49)]; + assert_eq!(pts.len(), 3, "{text}"); + for ((x, y), (wx, wy)) in pts.iter().zip(want) { + assert!((x - wx).abs() < 1e-5 && (y - wy).abs() < 1e-9, "{text}"); + } + // Hue vs Hue moved: no sample tells its scale, reported and left neutral. + let (g, r) = run(&[(106, Rec::Data(curve(3, &[(0.5, 0.25)])))]); let l = losses(&r); - assert!(l.len() == 1 && l[0].contains("Hue vs Sat (ADBE Lumetri-0042) is not imported"), "{l:?}"); - // A point count past the data: not a default, reported, no panic. + assert!(l.len() == 1 && l[0].contains("Hue vs Hue (ADBE Lumetri-0106) is not imported"), "{l:?}"); + assert_eq!(val(&g, "curves/hueSaturationCurves/hueVsHue"), Value::Str(String::new())); + // A point count past the data: not a default, reported as damaged, no panic. let mut bad = curve(3, &[]); bad[4..8].copy_from_slice(&1000u32.to_le_bytes()); - let (_, r) = run(&[(42, Rec::Data(bad))]); - assert_eq!(losses(&r).len(), 1); + let (g, r) = run(&[(42, Rec::Data(bad))]); + let l = losses(&r); + assert!(l.len() == 1 && l[0].contains("Hue vs Sat (ADBE Lumetri-0042) is unreadable"), "{l:?}"); + assert_eq!(val(&g, "curves/hueSaturationCurves/hueVsSat"), Value::Str(String::new())); +} + +#[test] +fn the_master_rgb_curve_arrives_moved_channel_curves_are_reported() { + // 1200 `-60-preset-curves-rgb`: the first of the four curves, its midpoint raised. + let master = curve(0, &[(0.0, 0.0), (0.491_408_934_707_903_76, 0.786_885_245_901_639_3), (1.0, 1.0)]); + let identity = curve(0, &[(0.0, 0.0), (1.0, 1.0)]); + let mut d = master.clone(); + (0..3).for_each(|_| d.extend(&identity)); + let (g, r) = run(&[(39, Rec::Data(d))]); + assert_eq!(losses(&r), Vec::::new()); + assert_eq!(val(&g, "curves/rgbCurves/master"), Value::Str("0,0 0.49140893470790376,0.7868852459016393 1,1".into())); + assert_eq!(val(&g, "curves/rgbCurves/red"), Value::Str("0,0 1,1".into())); + // A moved channel curve: which channel it is is not known, reported. + let mut d = identity.clone(); + d.extend(&master); + (0..2).for_each(|_| d.extend(&identity)); + let (g, r) = run(&[(39, Rec::Data(d))]); + let l = losses(&r); + assert!(l.len() == 1 && l[0].contains("1 channel curve(s) of RGB Curve (ADBE Lumetri-0039) are not imported"), "{l:?}"); + assert_eq!(val(&g, "curves/rgbCurves/master"), Value::Str("0,0 1,1".into())); + // Damaged: the wrong length. + let (_, r) = run(&[(39, Rec::Data(master))]); + assert!(losses(&r).iter().any(|x| x.contains("RGB Curve (ADBE Lumetri-0039) is unreadable")), "{:?}", losses(&r)); +} + +#[test] +fn colour_wheels_arrive_as_colours_their_brightness_is_reported() { + // 1200 `-62-preset-wheels`: Shadows towards blue with the slider down, Midtones towards red, + // Highlights towards yellow-green with the slider up; the fourth wheel at its default. + let w: Vec = [ + 229.119_895_976_548_18, + 0.369_892_467_494_294_2, + 0.547_209_348_004_638, + 0.104_745_366_878_020_72, + 0.5, + 0.394_961_840_132_529_44, + 93.374_076_744_668_57, + 0.726_881_718_523_399_9, + 0.318_976_840_675_999_35, + 0.0, + 0.5, + 0.0, + ] + .into_iter() + .flat_map(f64::to_le_bytes) + .collect(); + let (g, r) = run(&[(47, Rec::Data(w.clone()))]); + let colour = |id: &str| match val(&g, id) { + Value::Color(c) => c, + other => panic!("{id}: {other:?}"), + }; + // The hue's direction: blue strongest in Shadows, red in Midtones, green in Highlights. + let s = colour("colorWheels/shadowsWheel"); + assert!(s[2] > 0.77 && s[0] < 0.23 && (s[0] + s[2] - 1.0).abs() < 1e-9, "{s:?}"); + let m = colour("colorWheels/midtonesWheel"); + assert!((m[0] - 0.697_480_920_066_264_7).abs() < 1e-9 && m[1] > m[2], "{m:?}"); + let h = colour("colorWheels/highlightsWheel"); + assert!(h[1] > h[0] && h[0] > h[2], "{h:?}"); + let l = losses(&r); + assert!(l.len() == 1 && l[0].contains("Shadows brightness 0.370") && l[0].contains("Highlights brightness 0.727"), "{l:?}"); + assert!(!l[0].contains("Midtones") && !l[0].contains("fourth"), "{l:?}"); + // The fourth wheel set: reported; damaged data: reported, the wheels stay grey. + let mut w4 = w; + w4[88..96].copy_from_slice(&0.3f64.to_le_bytes()); + let (_, r) = run(&[(47, Rec::Data(w4))]); + assert!(losses(&r).iter().any(|x| x.contains("the fourth wheel")), "{:?}", losses(&r)); + let (g, r) = run(&[(47, Rec::Data(vec![1; 95]))]); + assert!(losses(&r).iter().any(|x| x.contains("Wheels (ADBE Lumetri-0047) is unreadable")), "{:?}", losses(&r)); + assert_eq!(val(&g, "colorWheels/shadowsWheel"), Value::Color([0.5, 0.5, 0.5, 1.0])); } #[test] @@ -420,17 +514,30 @@ fn the_picked_hsl_key_becomes_hue_saturation_and_lightness_ranges() { fn undecoded_data_and_controls_without_counterpart_are_reported_when_set() { let mut split = vec![0u8; 32]; split[0] = 1; - let mut w = wheels(4); - w[8] = 1; - let (_, r) = run(&[(32, Rec::Data(split)), (47, Rec::Data(w)), (97, Rec::Num(1.0, 3)), (95, Rec::Data(utf16("my.cube")))]); + let (_, r) = run(&[(32, Rec::Data(split)), (97, Rec::Num(1.0, 3)), (95, Rec::Data(utf16("my.cube")))]); let l = losses(&r); - assert_eq!(l.len(), 4, "{l:?}"); + assert_eq!(l.len(), 3, "{l:?}"); assert!(l.iter().any(|d| d.contains("Split Toning (ADBE Lumetri-0032) is not imported")), "{l:?}"); - assert!(l.iter().any(|d| d.contains("Wheels (ADBE Lumetri-0047) is not imported")), "{l:?}"); assert!(l.iter().any(|d| d.contains("Legacy Tone And Saturation (ADBE Lumetri-0097) is on")), "{l:?}"); assert!(l.iter().any(|d| d.contains("the Input LUT 'my.cube' is not imported")), "{l:?}"); } +#[test] +fn legacy_tone_on_is_reported_whatever_the_pard_default_says() { + // After the project is opened and saved again, the `pard` default of Legacy Tone And + // Saturation reads on (versions/1200-lumetri-26 / -25x / -24x; off in 1200 as the script + // saved it): a record that says on is still reported, a missing record is not. + let mut d = defs(); + if let Some((_, Def::Check { default })) = d.iter_mut().find(|(s, _)| *s == 97) { + *default = true; + } + let (_, r) = run_with(&d, &[(97, Rec::Num(1.0, 3))]); + let l = losses(&r); + assert!(l.len() == 1 && l[0].contains("Legacy Tone And Saturation (ADBE Lumetri-0097) is on"), "{l:?}"); + let (_, r) = run_with(&d, &[]); + assert_eq!(losses(&r), Vec::::new()); +} + #[test] fn an_unknown_scale_or_parameter_is_reported_not_guessed() { let mut d = defs(); diff --git a/docs/aep-format.md b/docs/aep-format.md index 9a37b384f..639c0a013 100644 --- a/docs/aep-format.md +++ b/docs/aep-format.md @@ -534,9 +534,10 @@ suffix is a parameter id, not the `parT` position (Curves -0002 Channel before - -0005 Quality before -0004). API: `CurvesData`, `MeshData`, `curve_lut`. [V; details: corpus FORMAT S] -**Lumetri Color** (`ADBE Lumetri`, 1200: 58 compositions made by script in After Effects 2026, 32 bpc, -working space None; defaults, all set, one per section, valid minima and maxima, every popup item the -script can set, checkboxes toggled, keys, an expression): 131 `parT` entries. The `-NNNN` suffix is a +**Lumetri Color** (`ADBE Lumetri`, 1200: 63 compositions in After Effects 2026, 32 bpc, working space +None; by script: defaults, all set, one per section, valid minima and maxima, every popup item the script +can set, checkboxes toggled, keys, an expression; from presets made by hand, `-58` ... `-62`: an Input +LUT, a Look, the RGB curve, Hue vs Sat, the colour wheels): 131 `parT` entries. The `-NNNN` suffix is a parameter id, not the position (`-0127` ... `-0130` sit between `-0005` and `-0026`), so the importer keys by suffix. Float sliders (type 10) store the value After Effects shows; the valid ranges (`pard` 104 / 108) are wider than the slider's (112 / 116): Temperature / Tint -300..300 (slider -100..100), @@ -546,31 +547,50 @@ HDR Range 100..10000, Refine Blur 0..1000 (0..30), Vignette Amount -5..5 (-3..3) `-19-min` / `-20-max` equal the stored numbers. **Hidden controls are recorded in the default state** (`tdsb` 3) and still hold the value After Effects reads back: High Dynamic Range `-0062` (1.0), HDR Specular `-0064` (22), the second Look popup `-0128` (26.16 as set, read back 26), Legacy Tone And -Saturation `-0097`, Auto Color `-0124`, Face Detection `-0102`, the Auto Intensity `-0123` +Saturation `-0097` (its `pard` default reads off as the script saved the project and on once the +project was opened and saved again, `versions/1200-lumetri-26`, `-25x`, `-24x`; a fresh instance reads +back off), Auto Color `-0124`, Face Detection `-0102`, the Auto Intensity `-0123` (`EffectParam::recorded_value`). Each section has an Active checkbox (blank `pard` name; `-0003` Basic Correction, `-0023` Creative, `-0037` Curves, `-0118` RGB Curves, `-0104` / `-0105` / `-0107` / `-0109` / `-0111` the hue / saturation curves, `-0046` Color Wheels, `-0068` HSL Secondary, `-0050` Vignette, on by default); off, the section does nothing (`-03-sec-basic-correction`, `-17-sec-vignette` render as `-00-defaults`). Arbitrary data (type 11, a record and `aRbs` in every instance; empty is `fe fe`): `-0001` an XML copy of the grade written only when the Look changes (not kept current: `-01-set-all` -holds defaults for controls set after the Look); `-0096` the Look's name, UTF-16LE (`SL BLUE ICE`; the -popup `-0025` itself has no record, `-0128` can disagree with it: `-07-sec-creative` names item 20 -while `-0128` holds 23), `-0095` likewise for the Input LUT (H, by analogy: no sample sets a LUT); -`-0129` the Look colour space's 16-byte id (the GUID `LookColorSpace` of `-0001`, byte-swapped; zero -for None; the Color Space popup `-0130` writes no record of its own, `-22-pop38-1` ... `-53-pop38-33`); +holds defaults for controls set after the Look; it names the LUT file, `Fuji F125 Kodak 2393 (by +Adobe).cube`); `-0096` the Look's name, UTF-16LE (`SL BLUE ICE`, `Fuji F125 Kodak 2393 (by Adobe)` in +`-59-preset-look-lut`; the popup `-0025` itself has no record, `-0128` can disagree with it: +`-07-sec-creative` names item 20 while `-0128` holds 23), `-0095` likewise for the Input LUT +(`ALEXA_Default_LogC2Rec709`, `-58-preset-input-lut`; the popups `-0005` / `-0127` keep no record, +`-0004`, `-0024` and the assets `-0125` / `-0126` stay `fe fe`: the LUTs are After Effects' own files, +named, not embedded); `-0129` the Look colour space's 16-byte id (the GUID `LookColorSpace` of `-0001` +in Windows layout: the first 4, 2 and 2 bytes little-endian; zero for None; the Color Space popup +`-0130` writes no record of its own, `-22-pop38-1` ... `-53-pop38-33`); `-0032` Split Toning (32 zero bytes); `-0039` the four RGB curves and `-0042`, `-0106`, `-0108`, `-0110`, `-0112` the hue / saturation curves, 520 bytes each: `i32` type (3 for the hue curves, 2 for Luma vs Sat and Sat vs Sat, 0 for an RGB curve), `u32` point count, then little-endian `f64` pairs x, y -(RGB: (0, 0), (1, 1) by default; hue / saturation: no points, and the selector colours `-0113` ... -`-0117` add three points at y = 0, the hue picked +- 0.0556; no sample moves a point, so y's scale is -H); `-0047` Color Wheels (4 x `f64` triples, 0, 0.5, 0 each) and `-0085` the HSL correction wheels (8 -triples, the same); `-0073` the HSL key, 40 bytes: a flag byte (1 once a colour was picked), then hue, +sorted by x (bytes after the counted points are stale). RGB: x and y 0..1, (0, 0), (1, 1) by default; +the first of the four is the master curve (`-60-preset-curves-rgb`: (0.491, 0.787) lifts R, G and B +alike, and the render follows a natural cubic spline through the points within 0.003); the order of +the other three is H (the `-0001` XML names `ToneCurvesLuma`, `Red`, `Green`, `Blue`; no sample moves +one). Hue / saturation: x the hue (0 red, 1/3 green) or the luma / saturation 0..1, y the offset from +neutral 0; a fresh curve has no points, the selector colours `-0113` ... `-0117` add three at y = 0, +the hue picked +- 0.0556. Hue vs Sat's y scales the saturation by 1 + y in linear light +(`-61-preset-curves-huesat`: (0.0155, 0.97) takes pure red's linear saturation to 1.96 times, (0.263, +-0.03) and (0.765, -0.02) green, cyan and blue to 0.97); the other four curves' scale is H. `-0047` +Color Wheels, 4 `f64` triples: hue in degrees (0 red, 120 green), brightness slider 0..1 (0.5 +neutral), distance from the centre 0..1; 0, 0.5, 0 each by default; Shadows, Midtones, Highlights, then +a fourth wheel of unknown role (`-62-preset-wheels`: Shadows 229.1, 0.370, 0.547 towards blue with the +slider down; Midtones 0.1, 0.5, 0.395 towards red; Highlights 93.4, 0.727, 0.319 towards yellow-green +with the slider up; the fourth at its default); `-0085` the HSL correction wheels (8 triples, the same +default; layout H); `-0073` the HSL key, 40 bytes: a flag byte (1 once a colour was picked), then hue, saturation, lightness, each centre, range, tolerance (`f32` LE, fractions) and an enabled byte (fresh: 0.5, 0, 0, on; picking RGB 0.02 0.55 0.85 gives hue centre 0.5605 = that colour's hue and lightness centre 0.435 = its HSL lightness, range 0.05, tolerance 0.1: `-01-set-all`; whether range is the half -or full width is H); `-0122` the Auto Tone analysis (UTF-16 JSON). Curves, LUTs and wheels are not -scriptable: the presets for them are still to be made. [V for the sliders, checkboxes, popups and the -`tdsb` 3 values; H where marked] +or full width is H); `-0122` the Auto Tone analysis (UTF-16 JSON). The project saved as 25.x and 24.x +copies (`versions/1200-lumetri-25x`, `-24x`: the 58 scripted compositions, saved by After Effects +2026) stores every Lumetri definition, valid range and value as the 26 save does. [V for the sliders, +checkboxes, popups, the `tdsb` 3 values, the master RGB curve, Hue vs Sat, the colour wheels and the +LUT names; H where marked] ### 3.8 Masks and bezier paths (`tdgp[ADBE Mask Parade]`) diff --git a/docs/aep-import.md b/docs/aep-import.md index 07c089782..f09f0ba1a 100644 --- a/docs/aep-import.md +++ b/docs/aep-import.md @@ -1,6 +1,6 @@ # After Effects project import -> **Last reviewed:** 2026-11-05 · **Last updated:** 2026-11-05 · **Change:** Lumetri Color is imported (1200: every slider, checkbox and popup with a counterpart, by match name, also from records in the default state; switched-off sections, LUTs, looks, undecoded curves and wheels are reported); before that: Curves and Mesh Warp are imported (961-965, 985; FORMAT S of the corpus); before that: a shape item's eye switch is imported (bit 0 of its group flags, 986 / 987: a switched-off Fill under Trim Paths is no longer drawn, render equal to After Effects), and a layer style's (switch group `tdsb` 0, 988); before that: a negative time stretch (Time Reverse Layer) is imported: in and out point in order, the layer plays backwards (981-983: render equal to After Effects at 7 points); before that: After Effects' None on Compound Blur, Displacement Map and Set Matte arrives as an explicit None (`NO_LAYER`), not as the owning layer; before that: layer styles are imported (the nine styles and Blending Options, 951-979; Global Light becomes the composition's); before that: the 27 effects of round 3 are in the table (`effectcraft_aep::effect_map`); before that: a layer of a clip, sequence or sound ends at its source's end (After Effects ends it there when it opens a project, read-back test f1), unless it is remapped or looped or runs less than a frame past; before that: keys of shape colours are read (the reader took their 152-byte spatial records for plain ones: `tdb4` byte 7 is 0 there, 854); before that: the effect table moved to `effectcraft_aep::effect_map`; point defaults in percent and a popup default slot of 0 (After Effects' save of a project it opened, e1 / e2 re-saves) are read; before that: the justification of right-to-left paragraphs is read relative to the direction (t7); before that: 24 more layer blend modes (906, 907); before that: 27 more effects are imported (batch 6: 903-905), with layer parameters; before that: a Rec. 709 working space also sets the output space (After Effects renders in the working space, 902); before that: a mask whose path was never set arrives as the source rectangle (900, 901); before that: Offset Paths' Copy Offset arrives as EffectCraft's (After Effects' value minus 1, 828); before that: project settings, image sequences, conformed clips and effect instance names are imported, next to the mattes, shapes, text settings and animators, effects, markers, time remapping, cameras and lights); before that: parallel and ambient lights (701, 702) and keyed Orientation (703) are imported; before that: masks on text and shape layers (705, 706: AE vs EffectCraft render 12 and 0 of 5184 points, glyph edges) and Merge Paths, Offset Paths, Repeater (707-710, 731; merge renders equal but for edges; Repeater copy opacity and Offset Paths' outline differ in EffectCraft's renderer) are imported; before that: keyframes: the ease of Anchor Point, effect point, effect colour and mask path keys is imported (597-599, 700, 730: within 0.5 px of After Effects' read-backs); before that: effects: Directional Blur, Radial Blur, CC Radial Blur, Venetian Blinds, Channel Blur, Black & White, Tritone, Luma Key, Simple Choker, Matte Choker and Transform are imported (711-723; render checks: CC Radial Blur and Channel Blur equal, Directional Blur within 5/255; Venetian Blinds, Radial Blur, Black & White (8/255), Tritone (19/255), Luma Key, Matte Choker and Transform differ in EffectCraft's renderer, see STATUS); before that: text: character and paragraph settings (stroke, scales, baseline shift, kerning, ligatures, tsume, indents, spacing, justified text, composer, direction, vertical text; 538-578) and text animators with range selectors (579-594, 114) are imported; render checks 594 (keyed range selector at 0 / 0.5 / 1 / 1.5 / 2.5 s), 595, 596 equal but for glyph edges; before that: cameras, spot and point lights, X / Y Rotation and Orientation, Timewarp and expressions on effect parameters are imported (render checks 486, 535-537 equal but for edges; 488 differs by 5.25 %, cause in EffectCraft's renderer not isolated); before that: text: superscript and subscript are imported (526-528); before that: effects: Invert, Fast Box Blur, Gaussian Blur, Drop Shadow, Glow, Fill, Hue/Saturation, Levels and five expression controls are imported, popups are mapped by item name, checkbox defaults come from the file; before that: shape layers are imported (groups, paths, paints, trim paths, round corners; 451-484, 519 added); before that: markers and Time Remapping are imported (509, 510 added); before that: track mattes are imported (402-408); before that: text: automatic leading is verified (400); effects: Exposure is imported (Channels, all twelve sliders, Bypass, keys), next to Tint and Gradient Ramp; before that: text: U+0003 is a paragraph break (386, 387); before that: a stored text Anchor Point is pixels (385, now V); before that: effects: Tint and Gradient Ramp are imported (all parameters and keys), other effects stay reported; `.aepx` is accepted; text layers are imported (Source Text with style runs, paragraphs and box text; fonts by PostScript name, missing fonts listed); layer styles are reported; before that: layer masks · **Target:** Adobe After Effects 2026 +> **Last reviewed:** 2026-11-05 · **Last updated:** 2026-11-05 · **Change:** Lumetri Color's master RGB curve, Hue vs Sat curve and colour wheels are imported (1200 presets made by hand); before that: Lumetri Color is imported (1200: every slider, checkbox and popup with a counterpart, by match name, also from records in the default state; switched-off sections, LUTs, looks, undecoded curves and wheels are reported); before that: Curves and Mesh Warp are imported (961-965, 985; FORMAT S of the corpus); before that: a shape item's eye switch is imported (bit 0 of its group flags, 986 / 987: a switched-off Fill under Trim Paths is no longer drawn, render equal to After Effects), and a layer style's (switch group `tdsb` 0, 988); before that: a negative time stretch (Time Reverse Layer) is imported: in and out point in order, the layer plays backwards (981-983: render equal to After Effects at 7 points); before that: After Effects' None on Compound Blur, Displacement Map and Set Matte arrives as an explicit None (`NO_LAYER`), not as the owning layer; before that: layer styles are imported (the nine styles and Blending Options, 951-979; Global Light becomes the composition's); before that: the 27 effects of round 3 are in the table (`effectcraft_aep::effect_map`); before that: a layer of a clip, sequence or sound ends at its source's end (After Effects ends it there when it opens a project, read-back test f1), unless it is remapped or looped or runs less than a frame past; before that: keys of shape colours are read (the reader took their 152-byte spatial records for plain ones: `tdb4` byte 7 is 0 there, 854); before that: the effect table moved to `effectcraft_aep::effect_map`; point defaults in percent and a popup default slot of 0 (After Effects' save of a project it opened, e1 / e2 re-saves) are read; before that: the justification of right-to-left paragraphs is read relative to the direction (t7); before that: 24 more layer blend modes (906, 907); before that: 27 more effects are imported (batch 6: 903-905), with layer parameters; before that: a Rec. 709 working space also sets the output space (After Effects renders in the working space, 902); before that: a mask whose path was never set arrives as the source rectangle (900, 901); before that: Offset Paths' Copy Offset arrives as EffectCraft's (After Effects' value minus 1, 828); before that: project settings, image sequences, conformed clips and effect instance names are imported, next to the mattes, shapes, text settings and animators, effects, markers, time remapping, cameras and lights); before that: parallel and ambient lights (701, 702) and keyed Orientation (703) are imported; before that: masks on text and shape layers (705, 706: AE vs EffectCraft render 12 and 0 of 5184 points, glyph edges) and Merge Paths, Offset Paths, Repeater (707-710, 731; merge renders equal but for edges; Repeater copy opacity and Offset Paths' outline differ in EffectCraft's renderer) are imported; before that: keyframes: the ease of Anchor Point, effect point, effect colour and mask path keys is imported (597-599, 700, 730: within 0.5 px of After Effects' read-backs); before that: effects: Directional Blur, Radial Blur, CC Radial Blur, Venetian Blinds, Channel Blur, Black & White, Tritone, Luma Key, Simple Choker, Matte Choker and Transform are imported (711-723; render checks: CC Radial Blur and Channel Blur equal, Directional Blur within 5/255; Venetian Blinds, Radial Blur, Black & White (8/255), Tritone (19/255), Luma Key, Matte Choker and Transform differ in EffectCraft's renderer, see STATUS); before that: text: character and paragraph settings (stroke, scales, baseline shift, kerning, ligatures, tsume, indents, spacing, justified text, composer, direction, vertical text; 538-578) and text animators with range selectors (579-594, 114) are imported; render checks 594 (keyed range selector at 0 / 0.5 / 1 / 1.5 / 2.5 s), 595, 596 equal but for glyph edges; before that: cameras, spot and point lights, X / Y Rotation and Orientation, Timewarp and expressions on effect parameters are imported (render checks 486, 535-537 equal but for edges; 488 differs by 5.25 %, cause in EffectCraft's renderer not isolated); before that: text: superscript and subscript are imported (526-528); before that: effects: Invert, Fast Box Blur, Gaussian Blur, Drop Shadow, Glow, Fill, Hue/Saturation, Levels and five expression controls are imported, popups are mapped by item name, checkbox defaults come from the file; before that: shape layers are imported (groups, paths, paints, trim paths, round corners; 451-484, 519 added); before that: markers and Time Remapping are imported (509, 510 added); before that: track mattes are imported (402-408); before that: text: automatic leading is verified (400); effects: Exposure is imported (Channels, all twelve sliders, Bypass, keys), next to Tint and Gradient Ramp; before that: text: U+0003 is a paragraph break (386, 387); before that: a stored text Anchor Point is pixels (385, now V); before that: effects: Tint and Gradient Ramp are imported (all parameters and keys), other effects stay reported; `.aepx` is accepted; text layers are imported (Source Text with style runs, paragraphs and box text; fonts by PostScript name, missing fonts listed); layer styles are reported; before that: layer masks · **Target:** Adobe After Effects 2026 File ▸ Import ▸ After Effects Project… (`file.importAep`) reads an `.aep` or its XML form `.aepx` and adds its items to the open project, in a folder named after the file (as After Effects does when it imports a project). @@ -179,7 +179,7 @@ parameter gets the file's value: | `ADBE Easy Levels2` 1 Channel, 2 Histogram data, 8 / 9 Clip To Output Black / White | `channel`; `inBlack`, `inWhite`, `gamma`, `outBlack`, `outWhite` from the data; `clipToOutputBlack`, `clipToOutputWhite` | popups by name (After Effects' items On, Off, Off for 32 bpc Color are in another order here); the RGB values are the `f32` of the arbitrary data; the per-channel values are reported when they are not at their defaults (not sampled) | 511-516 | | Batch 6 (903 defaults, 904 / 905 set values): `ADBE Brightness & Contrast 2`, `ADBE Turbulent Displace`, `ADBE Fractal Noise`, `ADBE Laser` (Beam), `CC Radial Fast Blur`, `ADBE Noise2`, `ADBE Pro Levels2` (Levels (Individual Controls)), `ADBE Corner Pin`, `ADBE Grid`, `ADBE Sharpen`, `ADBE Linear Color Key2`, `ADBE Radial Wipe`, `ADBE Remove Color Matting`, `CC Bend It`, `CC Power Pin`, `ADBE 4ColorGradient`, `ADBE Change Color`, `ADBE Extract`, `ADBE Noise HLS2`, `ADBE Scatter`, `CC Light Sweep`, `ADBE Compound Blur`, `ADBE Displacement Map`, `ADBE Set Matte3`, `ADBE Gaussian Blur` (legacy), `ADBE OFMotionBlur` (Pixel Motion Blur), `ADBE Layer Control` | the EffectCraft effect of the same name, every parameter EffectCraft has | sliders as stored (each checked against its valid maximum); Beam Length, Time and Softness and CC Power Pin Perspective are 0..1 fractions, percentages here; points as layer pixels; popups by item name (Set Matte's `Red Channel` ... is `Red` ...); twirl-down group markers and the Levels histogram carry nothing; **layer parameters** (below) | 903, 904, 905; 220, 320, 321 | | `ADBE Slider Control`, `ADBE Angle Control`, `ADBE Checkbox Control`, `ADBE Color Control`, `ADBE Point Control` (parameter 1) | `ec.control.slider` `slider`, `ec.control.angle` `angle`, `ec.control.checkbox` `checkbox`, `ec.control.color` `color`, `ec.control.point` `point` | float (valid max 1 000 000) as stored; degrees; checkbox; colour; point in layer pixels | 071, 073, 217-219, 221, 304, 310 | -| `ADBE Lumetri` by match-name suffix (1200), not by index: -0062 High Dynamic Range; -0063 HDR White; -0007 / -0008 Temperature / Tint; -0020 Saturation; -0011 Exposure; -0012 ... -0016 Contrast, Highlights, Shadows, Whites, Blacks; -0064 HDR Specular; -0026 Look Intensity; -0028 Faded Film; -0029 Sharpen; -0030 Vibrance; -0031 Saturation; -0033 Tint Balance; -0074 Show Mask; -0075 mask style; -0076 Invert Mask; -0081 Denoise; -0082 Blur; -0086 ... -0090 the HSL correction's Temperature, Tint, Contrast, Sharpen, Saturation; -0051 ... -0054 Vignette Amount, Midpoint, Roundness, Feather; -0073 the HSL key data | `highDynamicRange`, `basicCorrection/tone/hdrWhite`, `basicCorrection/whiteBalance/temperature` / `tint`, `basicCorrection/saturation`, `basicCorrection/tone/exposure`, `.../contrast`, `highlights`, `shadows`, `whites`, `blacks`, `hdrSpecular`, `creative/lookIntensity`, `creative/adjustments/fadedFilm`, `sharpen`, `vibrance`, `creativeSaturation`, `tintBalance`, `hslSecondary/key/showMask`, `maskStyle`, `invertMask`, `hslSecondary/refine/denoise`, `blur`, `hslSecondary/correction/*`, `vignette/*`; `hslSecondary/key/hue*`, `saturation*`, `lightness*` | sliders: the stored number x 1 (valid maxima 1000, 300, 300, 7, 150, 200, 150, 100, 100, 300, 150, 100, 1000, 5, 100 as in `pard`); checkboxes and the popup as elsewhere, **also from records in the default state** (`tdsb` 3); the key: hue centre x 360 degrees, range x 360 as the half width, tolerance x 360 as the softness, saturation and lightness centre +- range x 100 percent, tolerance x 100, once a colour was picked | 1200: all 62 read-backs of mapped controls in sections that act equal after import (min, max, sections, popups); the other 61 lie in sections that do nothing and are reported; keys and the expression on HDR White (`-56-keys`, `-57-expr`) | +| `ADBE Lumetri` by match-name suffix (1200), not by index: -0062 High Dynamic Range; -0063 HDR White; -0007 / -0008 Temperature / Tint; -0020 Saturation; -0011 Exposure; -0012 ... -0016 Contrast, Highlights, Shadows, Whites, Blacks; -0064 HDR Specular; -0026 Look Intensity; -0028 Faded Film; -0029 Sharpen; -0030 Vibrance; -0031 Saturation; -0033 Tint Balance; -0074 Show Mask; -0075 mask style; -0076 Invert Mask; -0081 Denoise; -0082 Blur; -0086 ... -0090 the HSL correction's Temperature, Tint, Contrast, Sharpen, Saturation; -0051 ... -0054 Vignette Amount, Midpoint, Roundness, Feather; -0073 the HSL key data; -0039 the first of the four RGB curves; -0042 Hue vs Sat; -0047 the Shadows, Midtones and Highlights wheels | `highDynamicRange`, `basicCorrection/tone/hdrWhite`, `basicCorrection/whiteBalance/temperature` / `tint`, `basicCorrection/saturation`, `basicCorrection/tone/exposure`, `.../contrast`, `highlights`, `shadows`, `whites`, `blacks`, `hdrSpecular`, `creative/lookIntensity`, `creative/adjustments/fadedFilm`, `sharpen`, `vibrance`, `creativeSaturation`, `tintBalance`, `hslSecondary/key/showMask`, `maskStyle`, `invertMask`, `hslSecondary/refine/denoise`, `blur`, `hslSecondary/correction/*`, `vignette/*`; `hslSecondary/key/hue*`, `saturation*`, `lightness*`; `curves/rgbCurves/master`; `curves/hueSaturationCurves/hueVsSat`; `colorWheels/shadowsWheel`, `midtonesWheel`, `highlightsWheel` | sliders: the stored number x 1 (valid maxima 1000, 300, 300, 7, 150, 200, 150, 100, 100, 300, 150, 100, 1000, 5, 100 as in `pard`); checkboxes and the popup as elsewhere, **also from records in the default state** (`tdsb` 3); the key: hue centre x 360 degrees, range x 360 as the half width, tolerance x 360 as the softness, saturation and lightness centre +- range x 100 percent, tolerance x 100, once a colour was picked; the master curve's points as `x,y` (0..1); Hue vs Sat's points with y as `0.5 + y / 2` (After Effects' y 1 doubles the saturation, EffectCraft's y 1 too); a wheel's hue (degrees) and distance as the HSL colour of that hue with saturation = distance and lightness 0.5 | 1200: all 62 read-backs of mapped controls in sections that act equal after import (min, max, sections, popups); the other 61 lie in sections that do nothing and are reported; keys and the expression on HDR White (`-56-keys`, `-57-expr`); the presets `-60-preset-curves-rgb`, `-61-preset-curves-huesat`, `-62-preset-wheels` | - **Nothing to import:** the implicit input-layer parameter (index 0), the Swap Colors buttons (Tint 4, Ramp 8: they always have a record and hold no value), Exposure's twirl-down group @@ -242,8 +242,15 @@ parameter gets the file's value: The Input LUT and the Look are reported by name (LUT files are not in the project). Controls without a counterpart (the Auto tone's Intensity, RGB Curves' HDR Range, Color Wheels' HDR White and Face Detection, Legacy Tone And Saturation, Auto Color, SpeedGrade Custom Layer), the eyedropper - colours, and the RGB curves, colour wheels, Split Toning, HSL correction wheels and moved hue / - saturation curve points (not sampled) are reported when set. Render check at 0.5 s against After + colours, the red, green and blue curves (only the master curve is sampled, so which is which is + not known), the colour wheels' brightness sliders and their fourth wheel, Split Toning, the HSL + correction wheels and moved points of the other four hue / saturation curves (not sampled) are + reported when set. The master RGB curve arrives as its points; Hue vs Sat with y as `0.5 + y / 2` + (After Effects' y is the offset from neutral, 1 doubling the saturation; EffectCraft's y = 1 + doubles it); a colour wheel's hue and distance as the HSL colour of that hue with saturation = + distance, lightness 0.5 (EffectCraft's wheels have no brightness slider). Legacy Tone And + Saturation is reported when a record says on: its `pard` default turns from off to on when the + project is saved again. Render check at 0.5 s against After Effects' 32 bpc PNGs (stored as value x 6553.5 in 16 bits, so read as raw / 6553.5): every composition whose grade After Effects draws as identity (defaults, set-all with every section off, the switched-off sections, the popups, keys, expression) is within 1/255 in EffectCraft; the @@ -253,6 +260,15 @@ parameter gets the file's value: EffectCraft clips at 1 and keeps black at 0; mean 0.12), Creative adjustments (sec-adjustments: Faded Film lifts black to 0.07 in After Effects, 0.035 here) and the extremes (min / max: mean 0.063 / 0.454; max: After Effects' vignette at +5 and the tone sliders give mid grey, EffectCraft white). + The 32 bpc PNGs hold the pixel value with no transfer curve (the defaults' ramp reads x / 320 + exactly), so values above 1 survive up to about 10; the comparison clips After Effects at 1 as + EffectCraft's 8-bit frame does. The hand-made presets: the master RGB curve within 0.024 (mean + 0.009; After Effects' curve is a natural cubic spline through the points, within 0.003, while + EffectCraft's Lumetri interpolates monotone); Hue vs Sat mean 0.008, max 0.18 (After Effects + scales the saturation in linear light, red reaching 1.26; EffectCraft in display values, 8.3 % of + pixels > 2 levels); the colour wheels mean 0.042, max 0.13 (the hues go the same way: Shadows + lift blue at black by 0.13 in After Effects, 0.21 here; Highlights add green; the brightness + sliders are not imported); the Input LUT and the Look are not imported (mean 0.088 / 0.076). - **Colour.** After Effects stores the colour its picker shows as ARGB doubles 0..255 in the project's working-space encoding; EffectCraft's parameter colours are straight RGBA 0..1 that the render pipeline hands to the effect as stored (`crates/render/src/color.rs`: authored colours are @@ -412,5 +428,5 @@ crate yet. ## Not done yet -Lumetri Color's section switches (a switched-off section is reported and its values left out), its LUTs and looks (files After Effects names: reported by name), its RGB curves, colour wheels, Split Toning and HSL correction wheels (not sampled: reported when set) and moved hue / saturation curve points (the scale of y is not sampled); effects outside the table (EXtractoR: its channel choice is arbitrary data; Stroke: its path is a mask reference), environment lights, the ease of bezier Orientation keys, wiggly and expression selectors and the other text animator properties (Character Value, Character Alignment other than its default, the Hue / Saturation / Brightness / Opacity variants, 3D rotations, variable font axes), manual kerning, No Break, the stroke line join, the Japanese leading model, Source Text keyframes, layer-style gradients, Pattern Overlay and the switch state 3, Mesh Warp handles moved on their own, +Lumetri Color's section switches (a switched-off section is reported and its values left out), its LUTs and looks (files After Effects names: reported by name), its red, green and blue curves (no sample tells which is which), the colour wheels' brightness sliders and the fourth wheel, Split Toning and the HSL correction wheels (not sampled: reported when set) and moved points of the four hue / saturation curves other than Hue vs Sat (the scale of y is not sampled); effects outside the table (EXtractoR: its channel choice is arbitrary data; Stroke: its path is a mask reference), environment lights, the ease of bezier Orientation keys, wiggly and expression selectors and the other text animator properties (Character Value, Character Alignment other than its default, the Hue / Saturation / Brightness / Opacity variants, 3D rotations, variable font axes), manual kerning, No Break, the stroke line join, the Japanese leading model, Source Text keyframes, layer-style gradients, Pattern Overlay and the switch state 3, Mesh Warp handles moved on their own, separated dimensions and footage interpretation need verified layouts in the reader first. From 337299ddf6eb9af6b9644a1ef21698171b7048c0 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Thu, 5 Nov 2026 17:50:28 +0100 Subject: [PATCH 06/40] AEP import docs: Lumetri wheel render figure measured at the same pixel The EffectCraft value for the Shadows wheel's blue lift at black was read at input 0.05; at input 0 it is 0.17 (After Effects 0.13). Part of #3111 Co-Authored-By: Claude Opus 5.5 --- docs/aep-import.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/aep-import.md b/docs/aep-import.md index f09f0ba1a..7ad0efb83 100644 --- a/docs/aep-import.md +++ b/docs/aep-import.md @@ -267,7 +267,7 @@ parameter gets the file's value: EffectCraft's Lumetri interpolates monotone); Hue vs Sat mean 0.008, max 0.18 (After Effects scales the saturation in linear light, red reaching 1.26; EffectCraft in display values, 8.3 % of pixels > 2 levels); the colour wheels mean 0.042, max 0.13 (the hues go the same way: Shadows - lift blue at black by 0.13 in After Effects, 0.21 here; Highlights add green; the brightness + lift blue at black by 0.13 in After Effects, 0.17 here; Highlights add green; the brightness sliders are not imported); the Input LUT and the Look are not imported (mean 0.088 / 0.076). - **Colour.** After Effects stores the colour its picker shows as ARGB doubles 0..255 in the project's working-space encoding; EffectCraft's parameter colours are straight RGBA 0..1 that the From 495221aac67f1b8491455fe8bd1bd1fe3f40428f Mon Sep 17 00:00:00 2001 From: vangel76 Date: Thu, 5 Nov 2026 18:36:56 +0100 Subject: [PATCH 07/40] AEP import: doc comments on the quick-win test helpers and tests Co-Authored-By: Claude Opus 5.5 --- crates/aep/src/import/effects.rs | 2 ++ crates/aep/tests/it/import/effects_quickwins.rs | 7 +++++++ crates/aep/tests/it/import/fx_inject.rs | 15 +++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/crates/aep/src/import/effects.rs b/crates/aep/src/import/effects.rs index 1d20a9dd1..c078f7b76 100644 --- a/crates/aep/src/import/effects.rs +++ b/crates/aep/src/import/effects.rs @@ -133,6 +133,8 @@ struct ParamOut<'a> { col: &'a mut Collector, } +/// Imports one parameter of `fx` into its EffectCraft property: its keyframes, the value in its +/// record or the `pard` default, with a loss for what cannot be read or mapped. fn import_param(fx: &AepEffect<'_, '_>, map: &EffectMap, p: &EffectParam<'_, '_>, cx: &LayerCtx<'_>, shown: &str, out: ParamOut<'_>) { let ParamOut { group, refs, col } = out; if carries_nothing(p) { diff --git a/crates/aep/tests/it/import/effects_quickwins.rs b/crates/aep/tests/it/import/effects_quickwins.rs index 792e08d74..0d4ed61ec 100644 --- a/crates/aep/tests/it/import/effects_quickwins.rs +++ b/crates/aep/tests/it/import/effects_quickwins.rs @@ -10,6 +10,7 @@ use effectcraft_keyframe::Value; const ECHO_OPS: &[&str] = &["Add", "Maximum", "Minimum", "Screen", "Composite In Back", "Composite In Front", "Blend"]; +/// Echo with the definitions After Effects 2026 wrote and the stored `values`. fn echo(values: Vec<(usize, f64)>) -> Fx { Fx { match_name: "ADBE Echo", @@ -26,6 +27,7 @@ fn echo(values: Vec<(usize, f64)>) -> Fx { } } +/// HDR Highlight Compression's Amount, set and default. #[test] fn hdr_highlight_compression_amount() { let fx = |values| Fx { @@ -43,6 +45,7 @@ fn hdr_highlight_compression_amount() { } } +/// Echo's values and operator, set and default. #[test] fn echo_values_and_operator() { // `echo-01-set-all` (without its Decay 20, below) and `echo-09-pop5-6`. @@ -61,6 +64,7 @@ fn echo_values_and_operator() { assert_eq!((num(&g, "numberOfEchoes"), v(&g, "echoOperator")), (1.0, Value::Enum(0))); } +/// Echo values beyond EffectCraft's ranges are imported as stored and reported. #[test] fn echo_values_beyond_effectcrafts_range_are_reported() { // `echo-03-max`: 30 000 echoes and Decay 100; EffectCraft's Echo uses at most 255 and 1. @@ -75,6 +79,7 @@ fn echo_values_beyond_effectcrafts_range_are_reported() { near(&g, "decay", 100.0); } +/// Linear Wipe's values, set and default. #[test] fn linear_wipe_values() { let fx = |values| Fx { @@ -99,6 +104,7 @@ fn linear_wipe_values() { near(&run(&fx(vec![]), "ec.transition.linearwipe").0.expect("imported"), "angle", 90.0); } +/// Offset's Blend With Original as a percentage and its centre as a point. #[test] fn offset_blend_is_a_fraction_and_the_centre_a_point() { let fx = |values| Fx { @@ -118,6 +124,7 @@ fn offset_blend_is_a_fraction_and_the_centre_a_point() { near(&run(&fx(vec![(2, 0.25)]), "ec.distort.offset").0.expect("imported"), "blend", 25.0); } +/// Color Stabilizer's points, Sample Size and Stabilize, default and set. #[test] fn color_stabilizer_points_sample_size_and_stabilize() { let fx = |values| Fx { diff --git a/crates/aep/tests/it/import/fx_inject.rs b/crates/aep/tests/it/import/fx_inject.rs index 9687e2d6c..bf9f08ea2 100644 --- a/crates/aep/tests/it/import/fx_inject.rs +++ b/crates/aep/tests/it/import/fx_inject.rs @@ -37,6 +37,7 @@ pub enum Default { Color([u8; 4]), } +/// The parameter type code `pard` byte 15 holds for `k`. fn kind_code(k: ParamKind) -> u8 { match k { ParamKind::Layer => 0, @@ -57,10 +58,12 @@ fn kind_code(k: ParamKind) -> u8 { } } +/// `v` as a big-endian 16.16 fixed-point value. fn fixed(v: f64) -> [u8; 4] { ((v * 65536.0).round() as i32).to_be_bytes() } +/// The 148-byte parameter definition (`pard`) of `d`: type, name, default and range. pub fn pard(d: &Def) -> Chunk<'static> { let mut b = vec![0u8; 148]; b[15] = kind_code(d.kind); @@ -99,6 +102,7 @@ pub fn tdmn(name: &str) -> Chunk<'static> { Chunk::data(*b"tdmn", b) } +/// A UTF-8 string chunk (`Utf8`). fn utf8(s: &str) -> Chunk<'static> { Chunk::data(*b"Utf8", s.as_bytes().to_vec()) } @@ -137,10 +141,13 @@ pub struct Fx { pub data: Vec<(usize, Vec)>, } +/// The match name of parameter `i` of `fx` (`-NNNN`). fn param_name(fx: &Fx, i: usize) -> String { format!("{}-{i:04}", fx.match_name) } +/// The effect's `sspc`: its name, the parameter definitions (`parT`) and the stored values +/// (`tdgp`), each value record copied from `template`. fn sspc(fx: &Fx, template: &Chunk<'_>) -> Chunk<'static> { let n = fx.defs.len() + 2; let mut part = vec![ @@ -194,6 +201,7 @@ fn find_glow_template(chunks: &[Chunk<'_>]) -> Option> { None } +/// Replaces every Glow (`ADBE Glo2` with its `sspc`) below `chunks` with `fx`; the number replaced. fn replace_glow(chunks: &mut [Chunk<'_>], fx: &Fx, template: &Chunk<'_>) -> usize { let mut n = 0; for ch in chunks { @@ -239,10 +247,12 @@ pub fn losses(r: &ImportResult, category: LossCategory, match_name: &str) -> Vec r.report.losses.iter().filter(|l| l.category == category).flat_map(|l| l.details.clone()).filter(|d| d.contains(&tag)).collect() } +/// The value of property `id` of `g` (panics when it is missing). pub fn v(g: &PropGroup, id: &str) -> Value { g.prop(id).unwrap_or_else(|| panic!("no {id} in {}", g.match_id)).value.clone() } +/// The scalar value of property `id` of `g`. pub fn num(g: &PropGroup, id: &str) -> f64 { match v(g, id) { Value::Scalar(x) => x, @@ -250,11 +260,13 @@ pub fn num(g: &PropGroup, id: &str) -> f64 { } } +/// Asserts that property `id` of `g` is `want` (relative 1e-6). pub fn near(g: &PropGroup, id: &str, want: f64) { let got = num(g, id); assert!((got - want).abs() <= want.abs().max(1.0) * 1e-6, "{} {id}: {got} != {want}", g.match_id); } +/// Asserts that the point property `id` of `g` is `want` (within 0.01). pub fn pt(g: &PropGroup, id: &str, want: [f64; 2]) { let Value::Vec2(a) = v(g, id) else { panic!("{id}") }; assert!((a[0] - want[0]).abs() < 1e-2 && (a[1] - want[1]).abs() < 1e-2, "{} {id}: {a:?} != {want:?}", g.match_id); @@ -265,14 +277,17 @@ pub fn slider(kind: ParamKind, name: &'static str, default: f64, valid: (f64, f6 Def { kind, name, default: Default::Number(default), valid, items: &[] } } +/// A popup definition: default item (1-based) and items. pub fn popup(name: &'static str, default: u32, items: &'static [&'static str]) -> Def { Def { kind: ParamKind::Popup, name, default: Default::Index(default), valid: (0.0, 0.0), items } } +/// A definition of another kind (angle, point, colour, ...) with `default`. pub fn other(kind: ParamKind, name: &'static str, default: Default) -> Def { Def { kind, name, default, valid: (0.0, 0.0), items: &[] } } +/// The definitions written here read back as the reader decodes After Effects' `pard`. #[test] fn pard_layout_decodes_as_written() { // Echo's Decay (float, valid 0..100, default 1), Linear Wipe's Feather (fixed, valid max From c32aa7cfbc1c63d1f8b9cba1c5e34419fd498d7e Mon Sep 17 00:00:00 2001 From: vangel76 Date: Thu, 5 Nov 2026 23:58:35 +0100 Subject: [PATCH 08/40] AEP import: Echo keyframe regression for the range loss Co-Authored-By: Claude Sonnet 5.5 --- .../aep/tests/it/import/effects_quickwins.rs | 23 +++++++++++++++ crates/aep/tests/it/import/fx_inject.rs | 29 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/crates/aep/tests/it/import/effects_quickwins.rs b/crates/aep/tests/it/import/effects_quickwins.rs index 0d4ed61ec..f2b0594b6 100644 --- a/crates/aep/tests/it/import/effects_quickwins.rs +++ b/crates/aep/tests/it/import/effects_quickwins.rs @@ -24,6 +24,7 @@ fn echo(values: Vec<(usize, f64)>) -> Fx { ], values, data: vec![], + keys: vec![], } } @@ -36,6 +37,7 @@ fn hdr_highlight_compression_amount() { defs: vec![slider(K::FloatSlider, "Amount", 100.0, (0.0, 100.0))], values, data: vec![], + keys: vec![], }; // `hdr-01-set-all`: 90; `hdr-00-defaults`: no record, 100. for (values, want) in [(vec![(1, 90.0)], 90.0), (vec![], 100.0)] { @@ -79,6 +81,24 @@ fn echo_values_beyond_effectcrafts_range_are_reported() { near(&g, "decay", 100.0); } +/// A keyframed Echo parameter keeps its keys as stored and reports the range loss. +#[test] +fn echo_keys_beyond_effectcrafts_range_are_kept_and_reported() { + // Number Of Echoes keyed 10 -> 30 000: the second key is beyond EffectCraft's 255. + let mut fx = echo(vec![]); + fx.keys = vec![(2, vec![(0, 10.0), (1000, 30000.0)])]; + let (g, r) = run(&fx, "ec.time.echo"); + let found = losses(&r, LossCategory::Effects, "ADBE Echo"); + assert_eq!(found.len(), 1, "{found:?}"); + assert!(found[0].contains("Number Of Echoes") && found[0].contains("30000") && found[0].contains("0 to 255"), "{found:?}"); + assert!(losses(&r, LossCategory::DamagedData, "ADBE Echo").is_empty()); + // Both keys arrive with their values. + let g = g.expect("still imported"); + let keys = &g.prop("numberOfEchoes").expect("numberOfEchoes").keys; + let values: Vec = keys.iter().map(|k| k.value.clone()).collect(); + assert_eq!(values, [Value::Scalar(10.0), Value::Scalar(30000.0)]); +} + /// Linear Wipe's values, set and default. #[test] fn linear_wipe_values() { @@ -92,6 +112,7 @@ fn linear_wipe_values() { ], values, data: vec![], + keys: vec![], }; // `linwipe-01-set-all`. let (g, r) = run(&fx(vec![(1, 10.0), (2, 77.0), (3, 16.0)]), "ec.transition.linearwipe"); @@ -113,6 +134,7 @@ fn offset_blend_is_a_fraction_and_the_centre_a_point() { defs: vec![other(K::Point, "Shift Center To", Default::Point(0.5, 0.5)), slider(K::FixedSlider, "Blend With Original", 0.0, (0.0, 1.0))], values, data: vec![], + keys: vec![], }; // `offset-02-chk-toggled`: Blend With Original stored 1.0 is 100 %. let (g, r) = run(&fx(vec![(2, 1.0)]), "ec.distort.offset"); @@ -139,6 +161,7 @@ fn color_stabilizer_points_sample_size_and_stabilize() { ], values, data: vec![], + keys: vec![], }; // `colstab-00-defaults`: Levels, the points at 20 %, 50 % and 80 % of the width. let (g, r) = run(&fx(vec![]), "ec.color.colorstabilizer"); diff --git a/crates/aep/tests/it/import/fx_inject.rs b/crates/aep/tests/it/import/fx_inject.rs index bf9f08ea2..81e6a821a 100644 --- a/crates/aep/tests/it/import/fx_inject.rs +++ b/crates/aep/tests/it/import/fx_inject.rs @@ -130,6 +130,27 @@ fn record(template: &Chunk<'_>, v: f64) -> Chunk<'static> { Chunk::list(*b"tdbs", kids) } +/// A keyframed value record: `record`'s header with a key list of linear one-component keys. +fn keyed_record(template: &Chunk<'_>, keys: &[(i32, f64)]) -> Chunk<'static> { + let Body::List { children, .. } = record(template, keys.first().map_or(0.0, |k| k.1)).body else { unreachable!("record builds a LIST") }; + let mut children = children; + let mut lhd3 = vec![0u8; 52]; + lhd3[0..4].copy_from_slice(&0x00d0_0beeu32.to_be_bytes()); + lhd3[8..12].copy_from_slice(&(keys.len() as u32).to_be_bytes()); + lhd3[16..20].copy_from_slice(&48u32.to_be_bytes()); + let mut ldat = Vec::new(); + for (time, value) in keys { + let mut rec = vec![0u8; 48]; + rec[0..4].copy_from_slice(&time.to_be_bytes()); + rec[4] = 1; + rec[5] = 1; + rec[8..16].copy_from_slice(&value.to_be_bytes()); + ldat.extend(rec); + } + children.push(Chunk::list(*b"list", vec![Chunk::data(*b"lhd3", lhd3), Chunk::data(*b"ldat", ldat)])); + Chunk::list(*b"tdbs", children) +} + /// An effect instance: its match name, display name, parameter definitions (after the input /// layer, before the built-in entry), the 1-D values stored (`parT` index, value) and the /// arbitrary data stored (`parT` index, bytes). @@ -139,6 +160,9 @@ pub struct Fx { pub defs: Vec, pub values: Vec<(usize, f64)>, pub data: Vec<(usize, Vec)>, + /// Keyframed 1-D parameters (`parT` index, (time units, value) per key), linear keys; the + /// parameter then has no entry in `values`. + pub keys: Vec<(usize, Vec<(i32, f64)>)>, } /// The match name of parameter `i` of `fx` (`-NNNN`). @@ -172,6 +196,10 @@ fn sspc(fx: &Fx, template: &Chunk<'_>) -> Chunk<'static> { values.push(Chunk::list(*b"aRbs", vec![Chunk::data(*b"aRbp", d.clone())])); } } + for (i, keys) in &fx.keys { + values.push(tdmn(¶m_name(fx, *i))); + values.push(keyed_record(template, keys)); + } Chunk::list(*b"sspc", vec![nested(*b"fnam", vec![utf8(fx.name)]), Chunk::list(*b"parT", part), Chunk::list(*b"tdgp", values)]) } @@ -306,6 +334,7 @@ fn pard_layout_decodes_as_written() { ], values: vec![(1, 20.0)], data: vec![], + keys: vec![], }; let bytes = bytes_with(&fx); let file = parse(&bytes).unwrap(); From 0f882368846d75bd30212abfe9ae5b4e11bb3eb9 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Fri, 6 Nov 2026 00:05:54 +0100 Subject: [PATCH 09/40] AEP import: negative cases for EXtractoR and IDentifier channel names and a missing Channel Info payload Co-Authored-By: Claude Sonnet 5.5 --- .../aep/tests/it/import/effects_thirdparty.rs | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/crates/aep/tests/it/import/effects_thirdparty.rs b/crates/aep/tests/it/import/effects_thirdparty.rs index 7bf1ad3c8..7c7ec190c 100644 --- a/crates/aep/tests/it/import/effects_thirdparty.rs +++ b/crates/aep/tests/it/import/effects_thirdparty.rs @@ -44,6 +44,7 @@ fn neutralizer(values: Vec<(usize, f64)>) -> Fx { ], values, data: vec![], + keys: vec![], } } @@ -101,6 +102,7 @@ fn extractor(values: Vec<(usize, f64)>, data: Vec) -> Fx { ], values, data: vec![(1, data)], + keys: vec![], } } @@ -183,6 +185,7 @@ fn identifier(values: Vec<(usize, f64)>, data: Vec) -> Fx { ], values, data: vec![(1, data)], + keys: vec![], } } @@ -217,3 +220,71 @@ fn identifier_chosen_channels_by_name() { assert!(found.len() == 1 && found[0].contains(&format!("the ID channel '{name}' (Channel Info) is not imported")), "{name}: {found:?}"); } } + +/// EXtractoR's data with the name of record `k` from byte 35 replaced by `name` (no NUL added; the +/// rest of the record's name field is left as `fill`). +fn channels_with_raw_name(k: usize, name: &[u8], fill: u8) -> Vec { + let mut d = channels(DEFAULT_CHANNELS); + let at = 32 + k * 164 + 35; + d[at..at + 129].fill(fill); + d[at..at + name.len()].copy_from_slice(name); + d +} + +/// A channel name that never ends (no NUL up to the end of its record) or is not UTF-8 is +/// refused by the decoder and reported at the importer; the defaults R, G, B, A stay. +#[test] +fn extractor_names_without_a_terminator_or_in_invalid_utf8_are_refused() { + let unterminated = channels_with_raw_name(2, b"Z", b'Z'); + let invalid = channels_with_raw_name(1, &[0x5a, 0xff, 0xfe, 0x00], 0); + for (what, data) in [("unterminated", unterminated), ("invalid UTF-8", invalid)] { + assert_eq!(ExtractorChannels::parse(&data), None, "{what}"); + let (g, r) = run(&extractor(vec![], data), "ec.3d.extractor"); + let found = losses(&r, LossCategory::Effects, "EXtractoR"); + assert!(found.len() == 1 && found[0].contains("not in the sampled layout"), "{what}: {found:?}"); + let g = g.expect("imported"); + for (id, want) in [("red", "R"), ("green", "G"), ("blue", "B"), ("alpha", "A")] { + assert_eq!(v(&g, id), Value::Str(want.into()), "{what}: {id}"); + } + } +} + +/// The same for IDentifier: a channel name without NUL up to the end of the data, or in invalid +/// UTF-8, is refused and reported; the Object ID channel stays. +#[test] +fn identifier_names_without_a_terminator_or_in_invalid_utf8_are_refused() { + let mut unterminated = id_info("objectId"); + unterminated[19..].fill(b'x'); + let mut invalid = id_info("objectId"); + invalid[19..22].copy_from_slice(&[b'o', 0xff, 0]); + for (what, data) in [("unterminated", unterminated), ("invalid UTF-8", invalid)] { + assert_eq!(identifier_channel_type(&data), None, "{what}"); + let (g, r) = run(&identifier(vec![], data), "ec.3d.identifier"); + let found = losses(&r, LossCategory::Effects, "IDentifier"); + assert!(found.len() == 1 && found[0].contains("not in the sampled layout"), "{what}: {found:?}"); + assert_eq!(v(&g.expect("imported"), "channelType"), Value::Enum(0), "{what}"); + } + // Data too short to reach the name. + assert_eq!(identifier_channel_type(&[1; 10]), None); +} + +/// A Channel Info value record without its arbitrary data (no `aRbs`): the effect still imports, +/// with the defaults, and nothing panics. +#[test] +fn a_missing_channel_info_payload_leaves_the_defaults() { + let mut fx = extractor(vec![], vec![]); + fx.data.clear(); + let (g, r) = run(&fx, "ec.3d.extractor"); + assert_eq!(losses(&r, LossCategory::Effects, "EXtractoR"), Vec::::new()); + let g = g.expect("imported"); + for (id, want) in [("red", "R"), ("green", "G"), ("blue", "B"), ("alpha", "A")] { + assert_eq!(v(&g, id), Value::Str(want.into()), "{id}"); + } + let mut fx = identifier(vec![(3, 5.0)], vec![]); + fx.data.clear(); + let (g, r) = run(&fx, "ec.3d.identifier"); + assert_eq!(losses(&r, LossCategory::Effects, "IDentifier"), Vec::::new()); + let g = g.expect("imported"); + assert_eq!(v(&g, "channelType"), Value::Enum(0)); + near(&g, "id", 5.0); +} From 692cc5228903ce421f79a51fa1b65789cd3d8ee7 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Fri, 6 Nov 2026 00:15:17 +0100 Subject: [PATCH 10/40] AEP import: Lumetri value records without their arbitrary data are reported as damaged Co-Authored-By: Claude Sonnet 5.5 --- crates/aep/src/import/lumetri.rs | 5 +++++ crates/aep/tests/it/import/lumetri.rs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/crates/aep/src/import/lumetri.rs b/crates/aep/src/import/lumetri.rs index 9369155f4..194afe15f 100644 --- a/crates/aep/src/import/lumetri.rs +++ b/crates/aep/src/import/lumetri.rs @@ -590,6 +590,11 @@ pub(crate) fn import_lumetri(fx: &AepEffect<'_, '_>, params: &[EffectParam<'_, ' Role::Lut { lut } => note_lut(p, row.suffix, data(), &mut luts[usize::from(!lut)]), // The Look's colour space only applies to a Look, which is reported. Role::LookSpace => {} + Role::Data(_) if p.stored().is_some() && data().is_none() => { + // The value record is there but its aRbs/aRbp payload is not: damaged, not the + // default (a parameter without a record is the default). + col.lose(LossCategory::DamagedData, format!("{here}: the data of {label} is missing, not imported (the default used)")); + } Role::Data(Data::HslKey) => import_hsl_key(data(), &here, &mut *group, &mut *col), Role::Data(d) => { if p.is_animated() || p.stored().is_some_and(|s| s.expression().is_some()) { diff --git a/crates/aep/tests/it/import/lumetri.rs b/crates/aep/tests/it/import/lumetri.rs index a3ec9138b..d31960cef 100644 --- a/crates/aep/tests/it/import/lumetri.rs +++ b/crates/aep/tests/it/import/lumetri.rs @@ -84,6 +84,8 @@ enum Rec { Num(f64, u32), /// Arbitrary data. Data(Vec), + /// A value record whose arbitrary data (`aRbs`) is missing. + NoData, } /// A static value record after the one After Effects wrote for Glow's A & B Midpoint (its header, @@ -229,6 +231,7 @@ fn sspc(defs: &[(u16, Def)], recs: &[(u16, Rec)], template: &Chunk<'_>) -> Chunk values.push(record(template, 1, 0.0)); values.push(Chunk::list(*b"aRbs", vec![Chunk::data(*b"aRbp", d)])); } + Rec::NoData => values.push(record(template, 1, 0.0)), } } Chunk::list(*b"sspc", vec![nested(*b"fnam", b"Lumetri Color"), Chunk::list(*b"parT", part), Chunk::list(*b"tdgp", values)]) @@ -436,6 +439,21 @@ fn the_master_rgb_curve_arrives_moved_channel_curves_are_reported() { assert!(losses(&r).iter().any(|x| x.contains("RGB Curve (ADBE Lumetri-0039) is unreadable")), "{:?}", losses(&r)); } +/// A value record without its arbitrary data is damaged, not the default: reported for the RGB +/// curve and the HSL key, the neighbours stay as they were. +#[test] +fn a_value_record_without_its_data_is_reported_as_damaged() { + for (suffix, name) in [(39, "RGB Curve (ADBE Lumetri-0039)"), (73, "HSL Sliders (ADBE Lumetri-0073)")] { + let (g, r) = run(&[(suffix, Rec::NoData)]); + let l = losses(&r); + assert!(l.len() == 1 && l[0].contains(name) && l[0].contains("is missing"), "{suffix}: {l:?}"); + assert!(r.report.losses.iter().any(|x| x.category == LossCategory::DamagedData), "{suffix}"); + // The grade stays at the default. + assert_eq!(val(&g, "curves/rgbCurves/master"), Value::Str("0,0 1,1".into())); + assert_eq!(num(&g, "hslSecondary/key/hueRange"), 180.0); + } +} + #[test] fn colour_wheels_arrive_as_colours_their_brightness_is_reported() { // 1200 `-62-preset-wheels`: Shadows towards blue with the slider down, Midtones towards red, From 69114a8294e94072f7de5f5f71004b8cc313dc99 Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Fri, 6 Nov 2026 21:22:40 +0100 Subject: [PATCH 11/40] Roto Brush: per-split scratch vectors in the parallel distance transform (#2333) * Roto Brush: reuse scratch vectors in the distance transform matting::distance allocated four vectors per column plus a staging copy and three vectors per row. Run the columns and rows through four reused scratch vectors instead; the dt1 arithmetic is unchanged. Fixes #2324 Co-Authored-By: Claude Sonnet 5.5 * Roto Brush: keep the distance transform parallel, with per-split scratch The previous commit made the column and row passes serial, which was measured on one thread only. Both passes are parallel again: the column pass runs on a transposed buffer so every column is a contiguous chunk, and rayon's for_each_init gives each work split one set of scratch vectors instead of four allocations per line. The square root is folded into the row pass. A test keeps the old per-line implementation and checks that the output is bit-identical on a disk, its inverse, 1xN, Nx1, all-true, all-false, seeds on the frame edge and a sparse 333x211 pattern. An ignored benchmark prints the 1080p median and the rayon thread count. Co-Authored-By: Claude Opus 5.5 * Roto matting: size the distance-transform scratch per pass (columns h, rows w) Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Sonnet 5.5 Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> --- crates/track/src/roto/matting.rs | 140 +++++++++++++++++++++++++------ 1 file changed, 116 insertions(+), 24 deletions(-) diff --git a/crates/track/src/roto/matting.rs b/crates/track/src/roto/matting.rs index cb22b680a..3f5327085 100644 --- a/crates/track/src/roto/matting.rs +++ b/crates/track/src/roto/matting.rs @@ -45,36 +45,46 @@ fn dt1(f: &[f32], d: &mut [f32], v: &mut [usize], z: &mut [f64]) { } } +/// Scratch vectors (`f`, `v`, `z`) for `dt1` over a line of `n` samples; sized per pass so a +/// 1 x N image does not allocate N-sized buffers for each of its N one-pixel rows. +fn line_scratch(n: usize) -> (Vec, Vec, Vec) { + (vec![0.0; n], vec![0; n], vec![0.0; n + 1]) +} + /// Euclidean distance from every pixel to the nearest pixel where `seed` is true (BIG.sqrt() /// when there is none). pub fn distance(seed: &[bool], w: usize, h: usize) -> Vec { if w == 0 || h == 0 { return vec![]; } - let mut g: Vec = seed.iter().map(|s| if *s { 0.0 } else { BIG }).collect(); - // Columns. - let cols: Vec> = (0..w) - .into_par_iter() - .map(|x| { - let f: Vec = (0..h).map(|y| g[y * w + x]).collect(); - let mut d = vec![0.0; h]; - let (mut v, mut z) = (vec![0usize; h], vec![0.0f64; h + 1]); - dt1(&f, &mut d, &mut v, &mut z); - d - }) - .collect(); - for (x, c) in cols.iter().enumerate() { - for y in 0..h { - g[y * w + x] = c[y]; - } - } - // Rows. - g.par_chunks_mut(w).for_each(|row| { - let f = row.to_vec(); - let (mut v, mut z) = (vec![0usize; w], vec![0.0f64; w + 1]); - dt1(&f, row, &mut v, &mut z); - }); - g.par_iter_mut().for_each(|v| *v = v.sqrt()); + // dt1 needs its input intact while it writes the output, so each line goes through scratch + // (`f`, `v`, `z`) that rayon creates once per work split, not once per line. The column pass + // runs on a transposed copy so that every column is a contiguous chunk. + // Columns: `t[x * h + y]` is pixel (x, y). + let mut t = vec![0.0f32; w * h]; + t.par_chunks_mut(h).enumerate().for_each_init( + || line_scratch(h), + |(f, v, z), (x, col)| { + for (y, fv) in f.iter_mut().enumerate() { + *fv = if seed.get(y * w + x).copied().unwrap_or(false) { 0.0 } else { BIG }; + } + dt1(f, col, v, z); + }, + ); + // Rows, then the square root. + let mut g = vec![0.0f32; w * h]; + g.par_chunks_mut(w).enumerate().for_each_init( + || line_scratch(w), + |(f, v, z), (y, row)| { + for (x, fv) in f.iter_mut().enumerate() { + *fv = t[x * h + y]; + } + dt1(f, row, v, z); + for d in row.iter_mut() { + *d = d.sqrt(); + } + }, + ); g } @@ -431,6 +441,88 @@ pub fn motion_blur(a: &[f32], w: usize, h: usize, v: [f64; 2], samples: usize) - mod tests { use super::*; + #[test] + fn line_scratch_is_sized_to_the_line_not_the_image() { + let (f, v, z) = line_scratch(1); + assert_eq!((f.len(), v.len(), z.len()), (1, 1, 2)); + // A 1 x N image: every row job needs one sample, every column job N. + let (w, h) = (1usize, 50_000usize); + let seed: Vec = (0..w * h).map(|i| i == 777).collect(); + let d = distance(&seed, w, h); + let r = distance_reference(&seed, w, h); + assert!(d.iter().zip(&r).all(|(a, b)| a.to_bits() == b.to_bits())); + } + + /// The distance transform as it was before the scratch reuse (one set of vectors per line). + fn distance_reference(seed: &[bool], w: usize, h: usize) -> Vec { + if w == 0 || h == 0 { + return vec![]; + } + let mut g: Vec = seed.iter().map(|s| if *s { 0.0 } else { BIG }).collect(); + let cols: Vec> = (0..w) + .map(|x| { + let f: Vec = (0..h).map(|y| g[y * w + x]).collect(); + let mut d = vec![0.0; h]; + let (mut v, mut z) = (vec![0usize; h], vec![0.0f64; h + 1]); + dt1(&f, &mut d, &mut v, &mut z); + d + }) + .collect(); + for (x, c) in cols.iter().enumerate() { + for y in 0..h { + g[y * w + x] = c[y]; + } + } + for row in g.chunks_mut(w) { + let f = row.to_vec(); + let (mut v, mut z) = (vec![0usize; w], vec![0.0f64; w + 1]); + dt1(&f, row, &mut v, &mut z); + } + g.iter().map(|v| v.sqrt()).collect() + } + + #[test] + fn distance_is_bit_identical_to_the_per_line_version() { + let disk = + |w: usize, h: usize, cx: f64, cy: f64, r: f64| -> Vec { (0..w * h).map(|i| ((i % w) as f64 - cx).hypot((i / w) as f64 - cy) <= r).collect() }; + let cases: Vec<(usize, usize, Vec)> = vec![ + (64, 48, disk(64, 48, 30.0, 20.0, 11.0)), + (64, 48, disk(64, 48, 30.0, 20.0, 11.0).iter().map(|b| !b).collect()), + (97, 1, (0..97).map(|i| i % 13 == 0).collect()), + (1, 97, (0..97).map(|i| i % 17 == 5).collect()), + (40, 30, vec![true; 1200]), + (40, 30, vec![false; 1200]), + (40, 30, (0..1200).map(|i| i % 40 == 39 || i / 40 == 0).collect()), + (333, 211, (0..333 * 211).map(|i| (i * 7919) % 1031 == 0).collect()), + ]; + for (w, h, seed) in cases { + let a = distance(&seed, w, h); + let b = distance_reference(&seed, w, h); + assert_eq!(a.len(), b.len()); + for (i, (x, y)) in a.iter().zip(&b).enumerate() { + assert_eq!(x.to_bits(), y.to_bits(), "{w}x{h} pixel {i}: {x} vs {y}"); + } + } + assert!(distance(&[], 0, 5).is_empty()); + } + + /// `cargo test --release -p effectcraft-track distance_bench -- --ignored --nocapture` + /// (set `RAYON_NUM_THREADS` to compare thread counts). + #[test] + #[ignore] + fn distance_bench() { + let (w, h) = (1920, 1080); + let seed: Vec = (0..w * h).map(|i| ((i % w) as f64 - 960.0).hypot((i / w) as f64 - 540.0) <= 300.0).collect(); + let mut times = vec![]; + for _ in 0..15 { + let t = std::time::Instant::now(); + std::hint::black_box(distance(&seed, w, h)); + times.push(t.elapsed().as_secs_f64() * 1000.0); + } + times.sort_by(f64::total_cmp); + eprintln!("distance 1080p, {} threads: median {:.2} ms", rayon::current_num_threads(), times[times.len() / 2]); + } + #[test] fn distance_matches_brute_force() { let (w, h) = (23, 17); From 392e8276268e8efdc6acd6d951bde5b45fab3066 Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Fri, 6 Nov 2026 21:47:00 +0100 Subject: [PATCH 12/40] Roto Brush: propagate on the band bounding box (#2335) * Roto Brush: propagate on the band bounding box propagate() ran the signed distance, gauss, graph cut, model fit and clean over the whole frame. Work on the crop of the band bounding box (|sd| <= r plus the core, padded) and paste the labels back; fall back to the full frame when the crop is not smaller. warp_prior stays full-frame. Fixes #2323 Co-Authored-By: Claude Sonnet 5.5 * Roto Brush: band crop padded by the prior blur, models fitted on the full frame Review follow-up for the band bounding-box crop in propagate: - The crop pad is now the reach of the prior blur (three box passes of matting::gauss, exposed as matting::gauss_reach) instead of 1 px, so every band pixel sees the same blur window as on the full frame. - When the previous frame has no colour models they are fitted on the full frame before cropping, as the full-frame path does. - The free pixels and the clean seeds are cut out of the full-frame signed distance instead of being recomputed on the crop; the seeds equal core_of(prior.soft), which saves one signed distance per frame. - The full-frame path and the crop share recut_band/cut_band; full frame is just the whole rectangle. A frame with no band and no core (no foreground) skips the cut, which was a no-op. - The w - 1 / h - 1 underflow on zero-sized frames is gone (band_rect returns None); regression test for 4x0, 0x4 and 0x0 (panicked before in debug builds). Tests: crop vs full frame labels on a disk, a disk at the frame corner, a donut, r = 2 and r = 3 with prior edges wider than the band, and no foreground, each with fitted, given and equal colour models; the padded crop blurs the prior like the full frame at every band pixel while a 1 px pad does not. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Sonnet 5.5 Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> --- crates/track/src/roto.rs | 91 +++++++++++++++++++++++--- crates/track/src/roto/matting.rs | 18 ++++-- crates/track/src/roto/tests.rs | 108 +++++++++++++++++++++++++++++++ 3 files changed, 204 insertions(+), 13 deletions(-) diff --git a/crates/track/src/roto.rs b/crates/track/src/roto.rs index c742654e9..3bab65dff 100644 --- a/crates/track/src/roto.rs +++ b/crates/track/src/roto.rs @@ -901,6 +901,87 @@ pub fn warp_prior(prev_img: &Image, prev: &FrameSeg, next_img: &Image, opts: &Se Prior { soft: res.iter().map(|r| r.0).collect(), fg: prev.fg.clone(), bg: prev.bg.clone(), refine: res.iter().map(|r| r.1).collect(), weight: PRIOR } } +/// The inputs of a band re-cut on one (sub)image of `size`. +struct Band<'a> { + size: (usize, usize), + rgb: &'a [[f32; 3]], + /// The warped soft matte (the prior, before blurring). + soft: &'a [f32], + free: &'a [bool], + seeds: &'a [bool], +} + +/// Graph cut of the free pixels with the blurred prior, then [`clean`]. +fn cut_band(b: &Band, labels: &mut [u8], sigma: f64, models: (&Gmm, &Gmm)) { + let (w, h) = b.size; + let soft = matting::gauss(b.soft, w, h, sigma); + cut(b.rgb, b.size, labels, b.free, &vec![0u8; w * h], models, Some((&soft, PRIOR))); + clean(labels, b.seeds, &vec![false; w * h], w, h); +} + +/// The half-open rectangle `[x0, y0, x1, y1)` around the pixels with `sd >= -r` (the band +/// `|sd| <= r` and the core `sd > r`), grown by `pad` and clipped to the frame; `None` when +/// there are none. +fn band_rect(sd: &[f32], size: (usize, usize), r: f32, pad: usize) -> Option<[usize; 4]> { + let (w, h) = size; + let (mut x0, mut y0, mut x1, mut y1) = (usize::MAX, usize::MAX, 0, 0); + for (i, d) in sd.iter().enumerate() { + if *d >= -r { + let (x, y) = (i % w.max(1), i / w.max(1)); + (x0, y0, x1, y1) = (x0.min(x), y0.min(y), x1.max(x), y1.max(y)); + } + } + (x0 <= x1).then(|| [x0.saturating_sub(pad), y0.saturating_sub(pad), x1.saturating_add(pad + 1).min(w), y1.saturating_add(pad + 1).min(h)]) +} + +/// The pixels of `rect` (row-major) of a `w`-wide plane. +fn crop_of(src: &[T], w: usize, rect: [usize; 4]) -> Vec { + let [x0, y0, x1, y1] = rect; + (y0..y1).flat_map(|y| src.get(y * w + x0..y * w + x1).unwrap_or(&[]).iter().copied()).collect() +} + +/// Re-cut the band `|sd| <= r` around the edge of `labels` (the warped matte) with `soft` as the +/// prior; outside it the labels stay. `models`: the colour models, fitted on the whole frame when +/// `None`. With `crop` the cut runs on the bounding box of the band and the core, padded by the +/// reach of the prior blur: outside that box every pixel is background more than `r` from the +/// edge, the free pixels, their neighbours and the seeds are the same, and every free pixel sees +/// the same blur window as on the full frame. +fn recut_band(rgb: &[[f32; 3]], size: (usize, usize), labels: &mut [u8], soft: &[f32], r: f32, models: Option<(&Gmm, &Gmm)>, crop: bool) { + let (w, h) = size; + let fitted; + let models = match models { + Some(m) => m, + None => { + fitted = fit_models(rgb, labels); + (&fitted.0, &fitted.1) + } + }; + let sd = matting::signed_distance(labels, w, h); + let free: Vec = sd.iter().map(|d| d.abs() <= r).collect(); + // The seeds of `core_of(soft, ..)`: `labels` is `soft >= 0.5`, so this is its core. + let core: Vec = sd.iter().map(|d| *d > r).collect(); + let seeds: Vec = if core.iter().any(|c| *c) { core } else { labels.iter().map(|v| *v != 0).collect() }; + let sigma = (r as f64 / 4.0).max(1.0); + let full = [0, 0, w, h]; + let rect = if crop { band_rect(&sd, size, r, matting::gauss_reach(sigma).max(1)) } else { Some(full) }; + // No band and no core: there is no foreground, so nothing is free and `clean` keeps all. + let Some(rect) = rect else { return }; + if rect == full { + cut_band(&Band { size, rgb, soft, free: &free, seeds: &seeds }, labels, sigma, models); + return; + } + let [x0, y0, x1, y1] = rect; + let cw = x1 - x0; + let (rgb_c, soft_c, free_c, seeds_c) = (crop_of(rgb, w, rect), crop_of(soft, w, rect), crop_of(&free, w, rect), crop_of(&seeds, w, rect)); + let mut cl = crop_of(labels, w, rect); + cut_band(&Band { size: (cw, y1 - y0), rgb: &rgb_c, soft: &soft_c, free: &free_c, seeds: &seeds_c }, &mut cl, sigma, models); + for (y, row) in (y0..y1).zip(cl.chunks(cw.max(1))) { + if let Some(dst) = labels.get_mut(y * w + x0..y * w + x1) { + dst.copy_from_slice(row); + } + } +} + /// Propagate the previous frame's segmentation to the next frame: warp it, then re-cut in a /// band of Search Radius pixels around the warped boundary. Strokes on the next frame re-cut /// the whole frame with the warped matte as a soft prior instead. @@ -912,15 +993,9 @@ pub fn propagate(prev_img: &Image, prev: &FrameSeg, next_img: &Image, strokes: & } let rgb = rgb_of(next_img); let mut labels: Vec = prior.soft.iter().map(|v| (*v >= 0.5) as u8).collect(); - let sd = matting::signed_distance(&labels, w, h); let r = (opts.search_radius * opts.scale).max(2.0) as f32; - let free: Vec = sd.iter().map(|d| d.abs() <= r).collect(); - let hard = vec![0u8; w * h]; - let soft = matting::gauss(&prior.soft, w, h, (r as f64 / 4.0).max(1.0)); - let (fg, bg) = if prev.fg.is_empty() || prev.bg.is_empty() { fit_models(&rgb, &labels) } else { (prev.fg.clone(), prev.bg.clone()) }; - cut(&rgb, (w, h), &mut labels, &free, &hard, (&fg, &bg), Some((&soft, PRIOR))); - let seeds = core_of(&prior.soft, w, h, r as f64); - clean(&mut labels, &seeds, &vec![false; w * h], w, h); + let models = (!prev.fg.is_empty() && !prev.bg.is_empty()).then_some((&prev.fg, &prev.bg)); + recut_band(&rgb, (w, h), &mut labels, &prior.soft, r, models, true); finish(next_img, &rgb, labels, strokes, Some(&prior.refine), opts, refine_radius) } diff --git a/crates/track/src/roto/matting.rs b/crates/track/src/roto/matting.rs index 3f5327085..ff6e33162 100644 --- a/crates/track/src/roto/matting.rs +++ b/crates/track/src/roto/matting.rs @@ -145,13 +145,21 @@ pub fn box_mean(src: &[f32], w: usize, h: usize, r: usize) -> Vec { out } +/// Box radius of [`gauss`]: three passes of it match the variance, 3·((2r+1)² − 1)/12 = σ². +/// `None` when the blur is a copy. +fn gauss_box(sigma: f64) -> Option { + (sigma >= 0.3).then(|| (((4.0 * sigma * sigma + 1.0).sqrt() - 1.0) / 2.0).round().max(1.0) as usize) +} + +/// How far (pixels, per axis) [`gauss`] reaches: an output pixel depends only on the input +/// within this distance. +pub fn gauss_reach(sigma: f64) -> usize { + gauss_box(sigma).map_or(0, |r| 3 * r) +} + /// Approximate Gaussian blur (three box passes) with standard deviation `sigma` pixels. pub fn gauss(src: &[f32], w: usize, h: usize, sigma: f64) -> Vec { - if sigma < 0.3 { - return src.to_vec(); - } - // Box radius whose three passes match the variance: 3·((2r+1)² − 1)/12 = σ². - let r = (((4.0 * sigma * sigma + 1.0).sqrt() - 1.0) / 2.0).round().max(1.0) as usize; + let Some(r) = gauss_box(sigma) else { return src.to_vec() }; let a = box_mean(src, w, h, r); let b = box_mean(&a, w, h, r); box_mean(&b, w, h, r) diff --git a/crates/track/src/roto/tests.rs b/crates/track/src/roto/tests.rs index bfc00df74..e50dbbce8 100644 --- a/crates/track/src/roto/tests.rs +++ b/crates/track/src/roto/tests.rs @@ -722,3 +722,111 @@ fn the_union_of_objects_is_their_largest_extent() { let odd = FrameSeg::empty(2, 2); assert_eq!(FrameSeg::union(vec![seg(&[1]), odd]).matte, vec![0, 255, 0, 0]); } + +/// A scene for the band re-cut: `rgb` of a `w`×`h` frame where the foreground is `inside`, with +/// a background that turns red left of `x = 30` (far from most shapes), and a soft prior that is +/// `inside` shifted by (3, 2) px with an edge `soft_edge` px wide. +fn band_scene(w: usize, h: usize, inside: &dyn Fn(f64, f64) -> f64, soft_edge: f64) -> (Vec<[f32; 3]>, Vec) { + let mut rgb = vec![[0.0f32; 3]; w * h]; + let mut soft = vec![0.0f32; w * h]; + for y in 0..h { + for x in 0..w { + let (px, py) = (x as f64 + 0.5, y as f64 + 0.5); + let a = inside(px, py).clamp(0.0, 1.0) as f32; + let f = fg_color(px, py); + let b = if px < 30.0 { [0.9, 0.1, 0.1] } else { bg_color(px, py) }; + rgb[y * w + x] = [f[0] * a + b[0] * (1.0 - a), f[1] * a + b[1] * (1.0 - a), f[2] * a + b[2] * (1.0 - a)]; + soft[y * w + x] = (inside(px - 3.0, py - 2.0) / soft_edge + 0.5).clamp(0.0, 1.0) as f32; + } + } + (rgb, soft) +} + +#[test] +fn band_crop_matches_the_full_frame() { + let (w, h) = (200usize, 150usize); + // Signed coverage: > 0.5 inside, falling off by 1 per pixel across the edge. + let disk = |cx: f64, cy: f64, r: f64| move |x: f64, y: f64| r + 0.5 - (x - cx).hypot(y - cy); + let mid = disk(120.0, 80.0, 30.0); + let corner = disk(185.0, 10.0, 28.0); + let donut = move |x: f64, y: f64| (40.0 + 0.5 - (x - 110.0).hypot(y - 75.0)).min((x - 110.0).hypot(y - 75.0) - 14.0 + 0.5); + let nothing = |_: f64, _: f64| -10.0; + let shapes: [(&str, &dyn Fn(f64, f64) -> f64, f32, f64); 8] = [ + ("disk", &mid, 8.0, 1.0), + ("frame corner", &corner, 8.0, 1.0), + ("donut", &donut, 6.0, 1.0), + ("r = 2, soft edge", &mid, 2.0, 3.0), + // A prior edge wider than the band: the blur sees prior values outside it. + ("r = 2, wide soft edge", &mid, 2.0, 10.0), + ("r = 3, wide soft edge at the corner", &corner, 3.0, 14.0), + ("r = 12, soft edge", &mid, 12.0, 4.0), + ("no foreground", ¬hing, 8.0, 1.0), + ]; + let mut changed = 0; + for (name, inside, r, edge) in shapes { + let (rgb, soft) = band_scene(w, h, inside, edge); + let start: Vec = soft.iter().map(|v| (*v >= 0.5) as u8).collect(); + let fitted = fit_models(&rgb, &start); + // Equal models leave the cut to the prior and the smoothness term, which makes it + // sensitive to the blurred prior. + for models in [None, Some((&fitted.0, &fitted.1)), Some((&fitted.1, &fitted.1))] { + let (mut full, mut crop) = (start.clone(), start.clone()); + recut_band(&rgb, (w, h), &mut full, &soft, r, models, false); + recut_band(&rgb, (w, h), &mut crop, &soft, r, models, true); + let diff = full.iter().zip(&crop).filter(|(a, b)| a != b).count(); + assert_eq!(diff, 0, "{name}, models {}: {diff} pixels differ", if models.is_some() { "given" } else { "fitted" }); + changed += full.iter().zip(&start).filter(|(a, b)| a != b).count(); + } + } + // The cut did move edges (the prior is offset from the shapes). + assert!(changed > 100, "{changed}"); +} + +/// Padded by the blur's reach, the crop blurs the prior exactly as the full frame does at every +/// band pixel (up to the summation rounding of the box sums); a 1 px pad does not when the prior +/// edge is wider than the band. +#[test] +fn band_rect_pad_covers_the_prior_blur() { + let (w, h) = (200usize, 150usize); + let mid = |x: f64, y: f64| 30.5 - (x - 120.0).hypot(y - 80.0); + let corner = |x: f64, y: f64| 28.5 - (x - 185.0).hypot(y - 10.0); + let cases: [(&dyn Fn(f64, f64) -> f64, f32, f64); 4] = [(&mid, 8.0, 1.0), (&mid, 2.0, 10.0), (&corner, 3.0, 14.0), (&mid, 12.0, 30.0)]; + for (inside, r, edge) in cases { + let (_, soft) = band_scene(w, h, inside, edge); + let labels: Vec = soft.iter().map(|v| (*v >= 0.5) as u8).collect(); + let sd = matting::signed_distance(&labels, w, h); + let sigma = (r as f64 / 4.0).max(1.0); + let full = matting::gauss(&soft, w, h, sigma); + let worst = |pad: usize| -> f32 { + let rect = band_rect(&sd, (w, h), r, pad).unwrap(); + let [x0, y0, x1, y1] = rect; + let blurred = matting::gauss(&crop_of(&soft, w, rect), x1 - x0, y1 - y0, sigma); + let mut worst = 0.0f32; + for y in y0..y1 { + for x in x0..x1 { + if sd[y * w + x].abs() <= r { + worst = worst.max((blurred[(y - y0) * (x1 - x0) + x - x0] - full[y * w + x]).abs()); + } + } + } + worst + }; + let reach = matting::gauss_reach(sigma); + assert!(worst(reach) < 1e-6, "r {r}, edge {edge}: {}", worst(reach)); + if edge > 2.0 * r as f64 { + assert!(worst(1) > 1e-4, "r {r}, edge {edge}: a 1 px pad should differ, {}", worst(1)); + } + } +} + +#[test] +fn propagate_survives_empty_frames() { + let opts = SegOpts::default(); + for (w, h) in [(4u32, 0u32), (0, 4), (0, 0)] { + let img = Image::new(w, h); + let prev = FrameSeg::empty(w as usize, h as usize); + let next = propagate(&img, &prev, &img, &[], &opts, 0.0); + assert_eq!((next.w, next.h), (w as usize, h as usize)); + assert!(next.matte.is_empty()); + } +} From 46f04d1a2d1c2899c0adba2a272bde3dbd61483d Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Fri, 6 Nov 2026 22:11:22 +0100 Subject: [PATCH 13/40] Subspace Warp: a symmetric QR eigen solver and a banded mesh solve make plan() 5x cheaper (#2319) (#2332) * Subspace Warp: QL eigen solver and banded mesh solve (#2319) plan() spent 43-96 % of its time in the cyclic Jacobi sym_eigen, whose absolute stop test never triggers on Gram matrices of magnitude ~1e8, and then ran a dense Cholesky on a mesh normal matrix of bandwidth ~30. Use Householder tridiagonalisation plus implicit QL inside subspace.rs (only the leading subspace is used, so basis and sign do not matter), and accumulate and factor the mesh normal equations in lower-band storage, without a Vec per data row. camtrack/linalg.rs is untouched. Co-Authored-By: Claude Sonnet 5.5 * Subspace Warp: replace the QL eigen solver with a clean-room symmetric QR The previous sym_eigen_ql followed a well-known published tred2/tqli listing too closely for the clean-room rules. It is replaced by sym_eigen_qr, written from the textbook method (Golub & Van Loan, Matrix Computations, ch. 8) in its own structure: - householder_tridiagonal: explicit reflectors with the symmetric rank-2 update B -= v w^T + w v^T (p = beta B v, w = p - (beta p^T v / 2) v), Q accumulated as rows of Q^T. - wilkinson_qr_step: one implicit QR step with the Wilkinson shift, Givens rotations chasing the bulge from the top of the unreduced block down. - sym_eigen_qr: deflation of negligible off-diagonal entries and the step driver, split so each function stays under the complexity limit. It returns None for non-finite input, a size mismatch or no convergence within 30 n steps; smooth_trajectories then falls back to the Jacobi sym_eigen, so it can never loop for ever or be worse than before. Tests: random symmetric matrices (n = 1..61) against Jacobi eigenvalues, residual |A v - lambda v| and V^T V = I; identity, repeated 3x3 blocks, zero, 1x1, 0x0, rows scaled from 1e-8 to 1e8 and a 1-2-1 tridiagonal; NaN, infinity and size mismatch return None; the leading-subspace projector of Gram-like low-rank matrices matches Jacobi. An ignored benchmark times plan() on a 300-frame synthetic parallax shot. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Sonnet 5.5 Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> --- crates/track/src/stabilize.rs | 26 +++ crates/track/src/subspace.rs | 362 +++++++++++++++++++++++++++++++++- 2 files changed, 381 insertions(+), 7 deletions(-) diff --git a/crates/track/src/stabilize.rs b/crates/track/src/stabilize.rs index 90cab6aab..092fc4ab4 100644 --- a/crates/track/src/stabilize.rs +++ b/crates/track/src/stabilize.rs @@ -887,6 +887,32 @@ mod tests { }); } + /// `cargo test --release -p effectcraft-track subspace_plan_bench -- --ignored --nocapture` + /// (`RAYON_NUM_THREADS=1` for one thread): `plan()` of a 300-frame synthetic parallax shot. + #[test] + #[ignore] + fn subspace_plan_bench() { + let n = 300; + let scene = Scene::new(n); + let mut an = Analyzer::new(scene.size, AnalyzeOpts::default()); + for t in 0..n { + let img = scene.frame(t); + an.push(&Frame { img: &img, offset: [0.0; 2] }); + } + let a = an.finish(0.0, 1.0 / 24.0); + for ripple in [Ripple::Automatic, Ripple::Enhanced] { + let s = StabSettings { method: Method::SubspaceWarp, ripple, framing: Framing::StabilizeOnly, fps: 24.0, ..Default::default() }; + let mut times = vec![]; + for _ in 0..5 { + let t = std::time::Instant::now(); + std::hint::black_box(plan(&a, &s)); + times.push(t.elapsed().as_secs_f64() * 1000.0); + } + times.sort_by(f64::total_cmp); + eprintln!("plan {ripple:?}, {} tracks, {} threads: median {:.1} ms", a.tracks.len(), rayon::current_num_threads(), times[2]); + } + } + #[test] fn subspace_warp_beats_perspective_on_parallax() { let n = 48; diff --git a/crates/track/src/subspace.rs b/crates/track/src/subspace.rs index 66b674b53..9c7d5ceeb 100644 --- a/crates/track/src/subspace.rs +++ b/crates/track/src/subspace.rs @@ -205,24 +205,75 @@ impl Default for MeshOpts { } } -/// Normal equations `AᵀA x = Aᵀb`, accumulated row by row. +/// Normal equations `AᵀA x = Aᵀb`, accumulated row by row. `AᵀA` is symmetric and banded (every +/// row couples unknowns at most `bw` apart), so only its lower band is stored: entry `(i, j)` +/// with `i − bw ≤ j ≤ i` sits at `i * (bw + 1) + j + bw − i`. struct Normal { - n: usize, + bw: usize, a: Vec, b: Vec, } impl Normal { fn row(&mut self, coefs: &[(usize, f64)], rhs: f64, w: f64) { + let width = self.bw + 1; for (ia, ca) in coefs { self.b[*ia] += w * ca * rhs; for (ib, cb) in coefs { - self.a[ia * self.n + ib] += w * ca * cb; + if ib <= ia { + self.a[ia * width + ib + self.bw - ia] += w * ca * cb; + } } } } } +/// Cholesky solve of `A x = b` for the banded `Normal::a`, in place. Returns false when `A` is not +/// positive definite. +fn cholesky_band(a: &mut [f64], n: usize, bw: usize, b: &mut [f64]) -> bool { + let w = bw + 1; + for j in 0..n { + let kj = j.saturating_sub(bw); + let rowj = j * w + kj + bw - j; + let mut d = a[j * w + bw]; + for v in &a[rowj..j * w + bw] { + d -= v * v; + } + if d <= 0.0 || !d.is_finite() { + return false; + } + let d = d.sqrt(); + a[j * w + bw] = d; + for i in j + 1..(j + bw + 1).min(n) { + let ki = i - bw.min(i); + let mut s = a[i * w + j + bw - i]; + let len = j - ki; + let (head, tail) = a.split_at_mut(i * w); + let li = &tail[ki + bw - i..ki + bw - i + len]; + let lj = &head[j * w + ki + bw - j..j * w + ki + bw - j + len]; + for (x, y) in li.iter().zip(lj) { + s -= x * y; + } + a[i * w + j + bw - i] = s / d; + } + } + for i in 0..n { + let mut s = b[i]; + for k in i.saturating_sub(bw)..i { + s -= a[i * w + k + bw - i] * b[k]; + } + b[i] = s / a[i * w + bw]; + } + for i in (0..n).rev() { + let mut s = b[i]; + for k in i + 1..(i + bw + 1).min(n) { + s -= a[k * w + i + bw - k] * b[k]; + } + b[i] = s / a[i * w + bw]; + } + b.iter().all(|v| v.is_finite()) +} + /// Fit the content-preserving warp of one frame: `pairs` are (source position, wanted /// stabilised position) of its features; `base` is the frame's perspective correction (source → /// stabilised), the prior. @@ -230,7 +281,9 @@ pub fn solve_mesh(size: [f64; 2], o: &MeshOpts, pairs: &[([f64; 2], [f64; 2])], let mut m = Mesh::from_homography(o.cols, o.rows, size, base); let nv = (m.cols + 1) * (m.rows + 1); let n = 2 * nv; - let mut ne = Normal { n, a: vec![0.0; n * n], b: vec![0.0; n] }; + // A cell couples its four corners and, through the triangles, vertices up to `cols + 2` apart. + let bw = (2 * (m.cols + 2) + 1).min(n - 1); + let mut ne = Normal { bw, a: vec![0.0; n * (bw + 1)], b: vec![0.0; n] }; // Prior. for k in 0..nv { let v = m.verts[k]; @@ -247,7 +300,7 @@ pub fn solve_mesh(size: [f64; 2], o: &MeshOpts, pairs: &[([f64; 2], [f64; 2])], let ks = [m.idx(i, j), m.idx(i + 1, j), m.idx(i, j + 1), m.idx(i + 1, j + 1)]; let w = [(1.0 - u) * (1.0 - v), u * (1.0 - v), (1.0 - u) * v, u * v]; for d in 0..2 { - let coefs: Vec<(usize, f64)> = ks.iter().zip(w).map(|(k, w)| (2 * k + d, w)).collect(); + let coefs: [(usize, f64); 4] = std::array::from_fn(|c| (2 * ks[c] + d, w[c])); ne.row(&coefs, src[d], 1.0); } used += 1; @@ -277,7 +330,7 @@ pub fn solve_mesh(size: [f64; 2], o: &MeshOpts, pairs: &[([f64; 2], [f64; 2])], } } let mut x = ne.b; - if cholesky_solve(&mut ne.a, n, &mut x) { + if cholesky_band(&mut ne.a, n, bw, &mut x) { for k in 0..nv { m.verts[k] = [x[2 * k], x[2 * k + 1]]; } @@ -285,6 +338,150 @@ pub fn solve_mesh(size: [f64; 2], o: &MeshOpts, pairs: &[([f64; 2], [f64; 2])], m } +/// Reduce the symmetric `a` (row-major `n × n`, consumed) to tridiagonal form `T = Qᵀ A Q` by +/// Householder reflections. Returns the diagonal of `T`, its off-diagonal (`off[i] = T[i][i+1]`) +/// and `Qᵀ` (row-major: row `j` is column `j` of `Q`). +/// +/// Step `k` picks the reflector `H = I − β v vᵀ` that maps column `k` below the diagonal onto a +/// multiple of the first unit vector, and applies it to the trailing block `B` from both sides +/// as the symmetric rank-2 update `B −= v wᵀ + w vᵀ` with `p = β B v`, `w = p − (β pᵀv / 2) v`. +fn householder_tridiagonal(mut a: Vec, n: usize) -> (Vec, Vec, Vec) { + let mut qt = vec![0.0; n * n]; + for i in 0..n { + qt[i * n + i] = 1.0; + } + let mut v = vec![0.0; n]; + let mut p = vec![0.0; n]; + let mut u = vec![0.0; n]; + for k in 0..n.saturating_sub(2) { + let s = k + 1; + let len = n - s; + for i in 0..len { + v[i] = a[(s + i) * n + k]; + } + let norm = v[..len].iter().map(|x| x * x).sum::().sqrt(); + if norm == 0.0 { + continue; + } + let alpha = if v[0] >= 0.0 { -norm } else { norm }; + v[0] -= alpha; + let beta = 2.0 / v[..len].iter().map(|x| x * x).sum::(); + for i in 0..len { + let row = &a[(s + i) * n + s..(s + i) * n + n]; + p[i] = beta * row.iter().zip(&v[..len]).map(|(x, y)| x * y).sum::(); + } + let half = 0.5 * beta * p[..len].iter().zip(&v[..len]).map(|(x, y)| x * y).sum::(); + for i in 0..len { + p[i] -= half * v[i]; + } + // `p` now holds `w`. + for i in 0..len { + let row = &mut a[(s + i) * n + s..(s + i) * n + n]; + for (j, x) in row.iter_mut().enumerate() { + *x -= v[i] * p[j] + p[i] * v[j]; + } + } + a[s * n + k] = alpha; + a[k * n + s] = alpha; + // Q ← Q H: with rows of Qᵀ, row j −= β v_j (Σ_l v_l row l). + u.fill(0.0); + for (l, vl) in v[..len].iter().enumerate() { + for (x, q) in u.iter_mut().zip(&qt[(s + l) * n..(s + l + 1) * n]) { + *x += vl * q; + } + } + for (j, vj) in v[..len].iter().enumerate() { + for (q, x) in qt[(s + j) * n..(s + j + 1) * n].iter_mut().zip(&u) { + *q -= beta * vj * x; + } + } + } + let diag = (0..n).map(|i| a[i * n + i]).collect(); + let off = (0..n.saturating_sub(1)).map(|i| a[(i + 1) * n + i]).collect(); + (diag, off, qt) +} + +/// One implicit symmetric QR step with the Wilkinson shift on the unreduced block `lo..=hi` of +/// the tridiagonal `(diag, off)`: a Givens rotation of rows/columns `k, k+1` for `k = lo..hi` +/// first introduces, then chases down a bulge below the subdiagonal. The rotations are applied to +/// the rows of `qt` as well. +fn wilkinson_qr_step(diag: &mut [f64], off: &mut [f64], qt: &mut [f64], n: usize, lo: usize, hi: usize) { + // The eigenvalue of the trailing 2×2 block nearer its last diagonal entry. + let t = off[hi - 1]; + let half = 0.5 * (diag[hi - 1] - diag[hi]); + let sign = if half >= 0.0 { 1.0 } else { -1.0 }; + let shift = diag[hi] - t * t / (half + sign * half.hypot(t)); + let (mut x, mut z) = (diag[lo] - shift, off[lo]); + for k in lo..hi { + let r = x.hypot(z); + let (c, s) = if r == 0.0 { (1.0, 0.0) } else { (x / r, z / r) }; + if k > lo { + off[k - 1] = r; + } + let (a, b, d) = (diag[k], off[k], diag[k + 1]); + diag[k] = c * c * a + 2.0 * c * s * b + s * s * d; + diag[k + 1] = s * s * a - 2.0 * c * s * b + c * c * d; + off[k] = c * s * (d - a) + (c * c - s * s) * b; + if k + 1 < hi { + // The rotation spreads `off[k+1]` into the bulge at (k+2, k). + x = off[k]; + z = s * off[k + 1]; + off[k + 1] *= c; + } + let (top, bottom) = qt.split_at_mut((k + 1) * n); + for (p, q) in top[k * n..].iter_mut().zip(&mut bottom[..n]) { + let (pk, qk) = (*p, *q); + *p = c * pk + s * qk; + *q = c * qk - s * pk; + } + } +} + +/// Symmetric eigen-decomposition: Householder reduction to tridiagonal form, then implicit QR +/// steps with the Wilkinson shift and deflation of negligible off-diagonal entries (the method of +/// Golub & Van Loan, *Matrix Computations*, ch. 8: Householder tridiagonalisation and the +/// symmetric QR algorithm). Same contract as `sym_eigen`: eigenvalues ascending, eigenvectors as +/// the columns of a row-major matrix. `None` for non-finite input, a size mismatch or no +/// convergence within `30 n` steps; the caller then falls back to Jacobi. +fn sym_eigen_qr(a: &[f64], n: usize) -> Option<(Vec, Vec)> { + if a.len() != n * n || a.iter().any(|x| !x.is_finite()) { + return None; + } + let (mut diag, mut off, mut qt) = householder_tridiagonal(a.to_vec(), n); + let mut budget = 30 * n.max(1); + let mut hi = n.saturating_sub(1); + while hi > 0 { + for i in 0..hi { + if off[i].abs() <= f64::EPSILON * (diag[i].abs() + diag[i + 1].abs()) { + off[i] = 0.0; + } + } + if off[hi - 1] == 0.0 { + hi -= 1; + continue; + } + let mut lo = hi - 1; + while lo > 0 && off[lo - 1] != 0.0 { + lo -= 1; + } + budget = budget.checked_sub(1)?; + wilkinson_qr_step(&mut diag, &mut off, &mut qt, n, lo, hi); + } + if diag.iter().chain(&qt).any(|x| !x.is_finite()) { + return None; + } + let mut order: Vec = (0..n).collect(); + order.sort_by(|&x, &y| diag[x].total_cmp(&diag[y])); + let vals = order.iter().map(|&j| diag[j]).collect(); + let mut vecs = vec![0.0; n * n]; + for (k, &j) in order.iter().enumerate() { + for r in 0..n { + vecs[r * n + k] = qt[j * n + r]; + } + } + Some((vals, vecs)) +} + /// Gaussian weights of the frames `lo..=hi` around `t`. fn gauss(lo: usize, hi: usize, t: usize, sigma: f64) -> Vec { let g: Vec = (lo..=hi).map(|j| (-((j as f64 - t as f64).powi(2)) / (2.0 * sigma * sigma)).exp()).collect(); @@ -336,7 +533,7 @@ pub fn smooth_trajectories(tracks: &[Track2D], frames: usize, sigma: f64, rank: gram[b * m + a] = s; } } - let (_, vecs) = sym_eigen(&gram, m); + let (_, vecs) = sym_eigen_qr(&gram, m).unwrap_or_else(|| sym_eigen(&gram, m)); // C[q][c] = vecs[c][m − 1 − q] (largest first). let cmat: Vec> = (0..k).map(|q| (0..m).map(|c| vecs[c * m + (m - 1 - q)]).collect()).collect(); let g = gauss(lo, hi, t, sigma.max(1e-6)); @@ -444,4 +641,155 @@ mod tests { } assert!(err_mesh < 0.35 * err_h, "{err_mesh} vs {err_h}"); } + + fn lcg(seed: &mut u64) -> f64 { + *seed = seed.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407); + (*seed >> 11) as f64 / (1u64 << 53) as f64 - 0.5 + } + + /// Checks an eigen-decomposition of `a` directly: `A v = λ v` per column, `VᵀV = I`, values + /// ascending; `tol` relative to the largest |entry| of `a`. + fn check_eigen(a: &[f64], n: usize, vals: &[f64], vecs: &[f64], tol: f64, what: &str) { + let scale = a.iter().fold(0.0f64, |m, x| m.max(x.abs())).max(f64::MIN_POSITIVE); + assert!(vals.windows(2).all(|w| w[0] <= w[1]), "{what}: values not ascending"); + for k in 0..n { + for i in 0..n { + let av: f64 = (0..n).map(|j| a[i * n + j] * vecs[j * n + k]).sum(); + let r = (av - vals[k] * vecs[i * n + k]).abs(); + assert!(r <= tol * scale, "{what}: residual {r} at ({i}, {k})"); + } + for l in 0..n { + let d: f64 = (0..n).map(|i| vecs[i * n + k] * vecs[i * n + l]).sum(); + let want = if k == l { 1.0 } else { 0.0 }; + assert!((d - want).abs() < 1e-10, "{what}: VᵀV ({k}, {l}) = {d}"); + } + } + } + + fn random_symmetric(n: usize, seed: &mut u64, scale: impl Fn(usize) -> f64) -> Vec { + let mut a = vec![0.0; n * n]; + for i in 0..n { + for j in 0..=i { + let v = lcg(seed) * scale(i) * scale(j); + a[i * n + j] = v; + a[j * n + i] = v; + } + } + a + } + + #[test] + fn qr_eigen_matches_jacobi_on_random_matrices() { + use crate::camtrack::linalg::sym_eigen; + let mut seed = 3; + for n in [1, 2, 3, 7, 20, 61] { + for _ in 0..3 { + let a = random_symmetric(n, &mut seed, |_| 1.0); + let (vals, vecs) = sym_eigen_qr(&a, n).unwrap(); + check_eigen(&a, n, &vals, &vecs, 1e-12, &format!("random n {n}")); + let (v0, _) = sym_eigen(&a, n); + for (x, y) in vals.iter().zip(&v0) { + assert!((x - y).abs() < 1e-11, "n {n}: {x} vs {y}"); + } + } + } + } + + #[test] + fn qr_eigen_handles_special_matrices() { + let mut seed = 5; + let n = 6; + let mut identity = vec![0.0; n * n]; + let mut blocks = vec![0.0; n * n]; + for i in 0..n { + identity[i * n + i] = 1.0; + // Two equal 3×3 blocks: every eigenvalue twice. + for j in 0..n { + if i / 3 == j / 3 { + blocks[i * n + j] = [[2.0, 1.0, 0.0], [1.0, 3.0, 1.0], [0.0, 1.0, 4.0]][i % 3][j % 3]; + } + } + } + let cases: Vec<(&str, usize, Vec)> = vec![ + ("identity", n, identity), + ("repeated blocks", n, blocks), + ("zero", n, vec![0.0; n * n]), + ("1x1", 1, vec![-4.5]), + ("0x0", 0, vec![]), + // Rows and columns scaled from 1e-8 to 1e8. + ("badly scaled", 9, random_symmetric(9, &mut seed, |i| 10f64.powi(2 * i as i32 - 8))), + ("tridiagonal 1-2-1", 30, (0..900usize).map(|k| [0.0, 1.0, 2.0][2 - (k / 30).abs_diff(k % 30).min(2)]).collect()), + ]; + for (what, n, a) in cases { + let (vals, vecs) = sym_eigen_qr(&a, n).unwrap(); + check_eigen(&a, n, &vals, &vecs, 1e-12, what); + } + let (vals, _) = sym_eigen_qr(&[1.0, 0.0, 0.0, 1.0], 2).unwrap(); + assert_eq!(vals, vec![1.0, 1.0]); + // Non-finite input or a size mismatch: None (the caller falls back to Jacobi) at once. + let mut nan = random_symmetric(8, &mut seed, |_| 1.0); + nan[9] = f64::NAN; + assert!(sym_eigen_qr(&nan, 8).is_none()); + assert!(sym_eigen_qr(&[f64::INFINITY], 1).is_none()); + assert!(sym_eigen_qr(&[1.0, 2.0, 3.0], 2).is_none()); + } + + #[test] + fn qr_eigen_keeps_the_leading_subspace_of_gram_like_matrices() { + use crate::camtrack::linalg::sym_eigen; + let mut seed = 7; + for n in [1, 2, 5, 31, 61] { + // Large magnitudes like a trajectory Gram matrix, with a low-rank part. + let rank = 3.min(n); + let f: Vec = (0..n * rank).map(|_| 300.0 * lcg(&mut seed)).collect(); + let mut a = vec![0.0; n * n]; + for i in 0..n { + for j in 0..n { + a[i * n + j] = (0..rank).map(|k| f[i * rank + k] * f[j * rank + k]).sum::() * 40.0; + } + } + let (v0, e0) = sym_eigen(&a, n); + let (v1, e1) = sym_eigen_qr(&a, n).unwrap(); + check_eigen(&a, n, &v1, &e1, 1e-12, &format!("gram n {n}")); + let top = v0[n - 1].abs().max(1.0); + for k in 0..n { + assert!((v0[k] - v1[k]).abs() < 1e-9 * top, "n {n} value {k}: {} vs {}", v0[k], v1[k]); + } + // The leading subspace (distinct eigenvalues, compared as a projector: signs and the + // basis are free). + for i in 0..n { + for j in 0..n { + let p0: f64 = (0..rank).map(|q| e0[i * n + n - 1 - q] * e0[j * n + n - 1 - q]).sum(); + let p1: f64 = (0..rank).map(|q| e1[i * n + n - 1 - q] * e1[j * n + n - 1 - q]).sum(); + assert!((p0 - p1).abs() < 1e-9, "n {n} projector ({i},{j}): {p0} vs {p1}"); + } + } + } + } + + #[test] + fn band_cholesky_matches_dense() { + let mut seed = 11; + for (n, bw) in [(1, 0), (6, 2), (40, 7), (40, 39)] { + let mut dense = vec![0.0; n * n]; + let mut band = vec![0.0; n * (bw + 1)]; + for i in 0..n { + for j in i.saturating_sub(bw)..=i { + let v = if i == j { 4.0 * bw as f64 + 2.0 + lcg(&mut seed) } else { lcg(&mut seed) }; + dense[i * n + j] = v; + dense[j * n + i] = v; + band[i * (bw + 1) + j + bw - i] = v; + } + } + let b: Vec = (0..n).map(|_| 10.0 * lcg(&mut seed)).collect(); + let (mut x0, mut x1) = (b.clone(), b); + assert!(cholesky_solve(&mut dense, n, &mut x0)); + assert!(cholesky_band(&mut band, n, bw, &mut x1)); + for (a, b) in x0.iter().zip(&x1) { + assert!((a - b).abs() < 1e-10, "{a} vs {b}"); + } + } + let mut band = vec![-1.0, 0.0, 0.0, 1.0]; + assert!(!cholesky_band(&mut band, 2, 1, &mut [1.0, 1.0])); + } } From 68a637adb9c6a0fd80ee13647a299bd484ea131d Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Fri, 6 Nov 2026 22:35:42 +0100 Subject: [PATCH 14/40] opusenc: memoise SILK rate-loop trials, ring buffer for noise feedback (#2399) * opusenc: memoise SILK rate-loop trials, ring buffer for noise feedback Rate loop: each probe clones the encoder and the range coder and codes the whole frame, about 7 trials per frame. The hard-limit check recomputed the trial of the chosen offset and the final step coded the frame a third time. Keep every trial (offset, bits, encoder state, range coder): the hard-limit check now hits the memo and the final step adopts the memoised state and coder. If the chosen offset is somehow not in the memo it is coded as before. Quantiser: the noise-feedback history was shifted with copy_within for every sample (the quantiser runs about 7 times per frame). Keep it in a double-length ring so the 16 most recent errors are one contiguous slice; the dot product reads the same pairs in the same order, and the history is written back to the channel at the end. The packet streams are byte-identical to before (cmp on 24 configurations of 90 s: speech-like and music-like input, mono and stereo, SILK NB/MB/WB and hybrid SWB/FB). Co-Authored-By: Claude Sonnet 5.5 * opusenc: noise-feedback ring as a helper type, equivalence tests for the SILK rate loop `quantize` was at cognitive complexity 31 on current main (limit 30). The double-length ring for the noise-feedback history moves into `NfRing` (push / window / to_array), and the end-of-frame bookkeeping of `encode` into `end_frame`. Tests: the ring matches a shifted history over 100 pushes, and an encoder that adopts the memoised trial produces the same bytes, noise-feedback history and LPC state, frame after frame, as one that codes every frame again at the chosen offset (the step before the memo), for 8/12/16 kHz, mono and stereo, with and without a tight hard limit. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Sonnet 5.5 Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> --- crates/opusenc/src/silk.rs | 168 ++++++++++++++++++++++++++++++++++--- 1 file changed, 158 insertions(+), 10 deletions(-) diff --git a/crates/opusenc/src/silk.rs b/crates/opusenc/src/silk.rs index 2678a96a0..9e202c958 100644 --- a/crates/opusenc/src/silk.rs +++ b/crates/opusenc/src/silk.rs @@ -125,6 +125,48 @@ struct Coded { pulses: Vec, } +/// Noise-feedback history (decoded − input), most recent first, as a double-length ring: each +/// sample is stored at `pos` and `pos + MAX_LPC_ORDER`, so `buf[pos..pos + MAX_LPC_ORDER]` is +/// always the contiguous window and a push costs two stores instead of a shift. +struct NfRing { + buf: [f64; 2 * MAX_LPC_ORDER], + /// Index of the most recent sample, always below `MAX_LPC_ORDER`. + pos: usize, +} + +impl NfRing { + fn new(hist: &[f64; MAX_LPC_ORDER]) -> Self { + let mut buf = [0.0; 2 * MAX_LPC_ORDER]; + buf[..MAX_LPC_ORDER].copy_from_slice(hist); + buf[MAX_LPC_ORDER..].copy_from_slice(hist); + NfRing { buf, pos: 0 } + } + + /// The history, most recent first. + fn window(&self) -> &[f64] { + self.buf.get(self.pos..self.pos + MAX_LPC_ORDER).unwrap_or(&[]) + } + + /// Makes `v` the most recent sample and drops the oldest. + fn push(&mut self, v: f64) { + self.pos = self.pos.checked_sub(1).unwrap_or(MAX_LPC_ORDER - 1); + for i in [self.pos, self.pos + MAX_LPC_ORDER] { + if let Some(slot) = self.buf.get_mut(i) { + *slot = v; + } + } + } + + /// The history as a plain array, most recent first. + fn to_array(&self) -> [f64; MAX_LPC_ORDER] { + let mut out = [0.0; MAX_LPC_ORDER]; + for (o, v) in out.iter_mut().zip(self.window()) { + *o = *v; + } + out + } +} + #[derive(Clone)] struct Channel { fs_khz: usize, @@ -233,7 +275,7 @@ impl Channel { let sub = self.sub; let order = self.order; let st = &mut self.dec; - let nf = &mut self.nf; + let mut ring = NfRing::new(&self.nf); let off = if p.signal_type == 0 { offset + INACTIVE_OFFSET } else { offset }; let gamma = nf_gamma(off); let mut nf_c = [0f64; MAX_LPC_ORDER]; @@ -351,7 +393,7 @@ impl Channel { } let lpc_q14 = lpc_pred.saturating_mul(16); // Target excitation (Q14) for this sample. - let fb: f64 = (0..order).map(|j| nf_c[j] * nf[j]).sum(); + let fb: f64 = nf_c.iter().zip(ring.window()).take(order).map(|(c, e)| c * e).sum(); let tgt = (x[n] as f64 + fb).clamp(-32768.0, 32767.0) * inv_g - lpc_q14 as f64 - ltp_q14 as f64; let sgn = if seed_v < 0 { -1.0 } else { 1.0 }; let u = sgn * tgt; @@ -390,11 +432,11 @@ impl Channel { let v = res.saturating_add(lpc_q14); s_lpc[MAX_LPC_ORDER + i] = v; xq[n] = sat16(rshift_round(smulww(v, gain_q10), 8)) as i16; - nf.copy_within(0..MAX_LPC_ORDER - 1, 1); - nf[0] = xq[n] as f64 - x[n] as f64; + ring.push(xq[n] as f64 - x[n] as f64); } s_lpc.copy_within(sub..sub + MAX_LPC_ORDER, 0); } + self.nf = ring.to_array(); st.s_lpc_q14.copy_from_slice(&s_lpc[..MAX_LPC_ORDER]); st.out_buf[..l].copy_from_slice(&xq); (Coded { gain_ix, gains_q16, seed, pulses }, xq) @@ -481,6 +523,14 @@ struct Prep { pred_q13: [i32; 2], } +/// One rate-loop trial: the frame coded at gain offset `offset`. +struct Trial { + offset: f64, + bits: i32, + state: SilkEncoder, + coder: RangeEncoder, +} + /// SILK encoder for one mono or stereo (mid/side) stream. #[derive(Clone)] pub struct SilkEncoder { @@ -631,11 +681,20 @@ impl SilkEncoder { pub fn encode(&mut self, input: &[Vec], target_bits: f64, max_bits: i32, enc: &mut RangeEncoder) { let prep = self.prepare(input); let start_bits = enc.tell(); - let trial = |s: &Self, o: f64| -> i32 { - let mut t = s.clone(); - let mut e = enc.clone(); - t.code(&prep, o, &mut e); - e.tell() - start_bits + // Every trial codes the frame into a clone of the encoder and the range coder. The result + // is kept per offset: the hard-limit check below hits the memo for the chosen offset, and + // the final step adopts that trial instead of coding the frame once more. + let mut trials: Vec = Vec::new(); + let mut trial = |s: &Self, o: f64| -> i32 { + if let Some(t) = trials.iter().find(|t| t.offset == o) { + return t.bits; + } + let mut state = s.clone(); + let mut coder = enc.clone(); + state.code(&prep, o, &mut coder); + let bits = coder.tell() - start_bits; + trials.push(Trial { offset: o, bits, state, coder }); + bits }; // Bisection on the gain offset: the smallest offset (finest quantisation) within budget. let target = target_bits.min(max_bits as f64); @@ -697,8 +756,20 @@ impl SilkEncoder { while trial(self, o) > max_bits && o < 12.0 { o += 1.0; } + match trials.iter().position(|t| t.offset == o) { + Some(i) => { + let t = trials.swap_remove(i); + *self = t.state; + *enc = t.coder; + } + None => self.code(&prep, o, enc), + } + self.end_frame(&prep, o); + } + + /// Advances the input history and the frame counter after frame `prep` was coded at `o`. + fn end_frame(&mut self, prep: &Prep, o: f64) { self.last_offset = o; - self.code(&prep, o, enc); for ch in 0..self.channels { self.ch[ch].push_history(&prep.x[ch]); } @@ -708,3 +779,80 @@ impl SilkEncoder { self.frame += 1; } } + +#[cfg(test)] +mod tests { + use super::*; + + /// Deterministic speech-like test input: two harmonics with a moving pitch, a syllable + /// envelope, noise and short silences, at the internal rate and 16-bit scale. + fn signal(len: usize, fs_khz: usize, seed: u32) -> Vec { + let mut s = seed; + let fs = (fs_khz * 1000) as f64; + (0..len) + .map(|i| { + s = s.wrapping_mul(1_664_525).wrapping_add(1_013_904_223); + let noise = (s >> 8) as f64 / (1u32 << 24) as f64 - 0.5; + let t = i as f64 / fs; + let f0 = 140.0 + 40.0 * (t * 1.3).sin(); + let env = ((t * 4.0).sin().max(0.0)).powf(0.7); + let voiced = (std::f64::consts::TAU * f0 * t).sin() + 0.5 * (std::f64::consts::TAU * 2.0 * f0 * t).sin(); + (8000.0 * env * voiced + 600.0 * noise) as f32 + }) + .collect() + } + + #[test] + fn nf_ring_matches_a_shifted_history() { + let mut hist = [0f64; MAX_LPC_ORDER]; + for (i, h) in hist.iter_mut().enumerate() { + *h = i as f64 * 0.5 - 3.0; + } + let mut ring = NfRing::new(&hist); + assert_eq!(ring.window(), &hist[..]); + for n in 0..100 { + let v = (n as f64 * 0.37).sin() * 100.0; + hist.copy_within(0..MAX_LPC_ORDER - 1, 1); + hist[0] = v; + ring.push(v); + assert_eq!(ring.window(), &hist[..], "after push {n}"); + } + assert_eq!(ring.to_array(), hist); + } + + /// The rate loop adopts the memoised trial for the chosen offset. A second encoder that codes + /// every frame afresh at that offset (what the loop did before the memo) must produce the + /// same bytes, frame after frame, so the adopted encoder and range-coder states are exact. + #[test] + fn adopting_the_memoised_trial_equals_coding_the_frame_again() { + for (fs_khz, channels, target_bits, max_bits) in + [(8, 1, 200.0, 1000), (12, 1, 320.0, 1000), (16, 1, 480.0, 1000), (16, 2, 640.0, 1000), (16, 1, 900.0, 400), (8, 2, 120.0, 160)] + { + let mut memo = SilkEncoder::new(fs_khz, channels); + let mut fresh = memo.clone(); + let l = memo.frame_len(); + let frames = 40; + let left = signal(l * frames, fs_khz, 7); + let right: Vec = signal(l * frames + 37, fs_khz, 11)[37..].iter().map(|v| v * 0.6).collect(); + for f in 0..frames { + let mut input = vec![left[f * l..(f + 1) * l].to_vec()]; + if channels == 2 { + input.push(right[f * l..(f + 1) * l].to_vec()); + } + let mut enc = RangeEncoder::new(); + memo.encode(&input, target_bits, max_bits, &mut enc); + let o = memo.last_offset; + let prep = fresh.prepare(&input); + let mut enc_fresh = RangeEncoder::new(); + fresh.code(&prep, o, &mut enc_fresh); + fresh.end_frame(&prep, o); + assert_eq!(enc.tell(), enc_fresh.tell(), "{fs_khz} kHz {channels} ch frame {f}"); + assert_eq!(enc.done(1275), enc_fresh.done(1275), "{fs_khz} kHz {channels} ch frame {f}"); + for c in 0..channels { + assert_eq!(memo.ch[c].nf, fresh.ch[c].nf, "noise feedback, channel {c}, frame {f}"); + assert_eq!(memo.ch[c].dec.s_lpc_q14, fresh.ch[c].dec.s_lpc_q14, "LPC state, channel {c}, frame {f}"); + } + } + } + } +} From a17e1f20d68f66c4be57770a4eefb72cbcf10d8e Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Fri, 6 Nov 2026 22:58:00 +0100 Subject: [PATCH 15/40] av1enc: motion search with visited set and early-exit SAD, fixed-size SATD, region-only snapshots (#2406) * av1enc: motion search with a visited set and early-exit SAD, fixed-size SATD, region-only BlockDecoded snapshot - motion_search remembered nothing: the diamond search evaluated the previous centre again and every SAD ran to the last row even when it had already lost. Full-sample and sub-sample positions are now tracked in a visited list (costs are deterministic, so a position that was evaluated cannot beat the best cost again), and the SAD stops after a row once sad + mv cost can no longer be below the best cost. The stop test is the same f64 expression as the strict "<" the callers apply, and it is monotone in the SAD, so the chosen vector is the same. - satd runs with a fixed block size (satd_k::<4> / satd_k::<8>): the difference block is a [[i32; K]; K], the vertical butterflies work on whole rows at once, and the old per-column gather is gone. The sum is an integer sum of the same values. - A snapshot copies only the BlockDecoded cells of the block area (at most 16x16 per plane), the only flags coding inside the block can change, instead of the whole 3x35x35 array. The encoded stream is unchanged. A unit test compares the new SATD with the previous implementation for 4..32 sample blocks at 8 and 10 bit. Fixes #2387 Co-Authored-By: Claude Sonnet 5.5 * av1enc: tests for the region-only BlockDecoded snapshot and the bounded SADs - `snapshot_restore_brings_back_every_blockdecoded_flag`: for every block size of a 64x64 superblock (4x4 .. 64x64) at every aligned position in two superblocks, from an all-clear and a random flag state, marking every sub-block of every size inside the block and restoring gives back the whole 3x35x35 array, so the 16x16 region covers every flag coding can set and leaves the neighbours alone. - `bounded_sad_stops_only_once_the_cost_cannot_win`: `sad_ref` and `sad_bounded` return the full SAD whenever `sad + lb < bound`, and otherwise a partial sum that already loses the strict `<` of the callers. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Sonnet 5.5 Co-authored-by: Codex Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> --- crates/av1enc/src/decide.rs | 310 ++++++++++++++++++++++++++++++------ 1 file changed, 259 insertions(+), 51 deletions(-) diff --git a/crates/av1enc/src/decide.rs b/crates/av1enc/src/decide.rs index d8bc1f825..b06852809 100644 --- a/crates/av1enc/src/decide.rs +++ b/crates/av1enc/src/decide.rs @@ -157,7 +157,8 @@ impl Default for TxScratch { /// Saved encoder state of a block area (reconstruction, BlockDecoded flags). struct Snapshot { planes: [Vec; 3], - decoded: Box<[[[bool; 35]; 35]; 3]>, + /// BlockDecoded flags of the block area only (the only flags coding inside it can change). + decoded: [[[bool; 16]; 16]; 3], } pub(crate) struct Decider<'a> { @@ -267,6 +268,13 @@ impl<'a> Decider<'a> { } } + /// The BlockDecoded cells `mark_decoded` can set for blocks inside (r, c, n4): rows and + /// columns `by + 1 .. by + 1 + step` / `bx + 1 ..` of `decoded[plane]`. + fn decoded_region(plane: usize, r: usize, c: usize, n4: usize) -> (usize, usize, usize) { + let s = (plane > 0) as usize; + ((r & 15) >> s, (c & 15) >> s, (n4 >> s).max(1)) + } + fn snapshot(&self, r: usize, c: usize, n4: usize) -> Snapshot { let planes = std::array::from_fn(|p| { let s = (p > 0) as usize; @@ -278,7 +286,14 @@ impl<'a> Decider<'a> { } v }); - Snapshot { planes, decoded: self.decoded.clone() } + let mut decoded = [[[false; 16]; 16]; 3]; + for (p, d) in decoded.iter_mut().enumerate() { + let (by, bx, step) = Self::decoded_region(p, r, c, n4); + for i in 0..step { + d[i][..step].copy_from_slice(&self.decoded[p][by + i + 1][bx + 1..bx + 1 + step]); + } + } + Snapshot { planes, decoded } } fn restore(&mut self, snap: &Snapshot, r: usize, c: usize, n4: usize) { @@ -290,7 +305,12 @@ impl<'a> Decider<'a> { pl.data[y * pl.stride + x0..y * pl.stride + x0 + n].copy_from_slice(&snap.planes[p][i * n..i * n + n]); } } - self.decoded.clone_from(&snap.decoded); + for p in 0..3 { + let (by, bx, step) = Self::decoded_region(p, r, c, n4); + for i in 0..step { + self.decoded[p][by + i + 1][bx + 1..bx + 1 + step].copy_from_slice(&snap.decoded[p][i][..step]); + } + } } fn set_mvs(&mut self, r: usize, c: usize, n4: usize, mv: [i32; 2]) { @@ -588,15 +608,22 @@ impl<'a> Decider<'a> { let comp = |d: i32| if d == 0 { 0.5 } else { 2.0 + 2.0 * log2_of(lg, (d.abs() / 8) as usize + 1) }; comp(m[0] - pred_mv[0]) + comp(m[1] - pred_mv[1]) }; - let cost = - |m: [i32; 2]| -> f64 { self.sad_ref(&refr.planes[0], x0 + (m[1] >> 3), y0 + (m[0] >> 3), c * 4, r * 4, n) as f64 + self.lambda_sad * mv_bits(m) }; + // `bound` is the cost to beat: the SAD stops early once the cost cannot be below it (the + // callers only accept a strictly lower cost, so the result is unchanged) + let cost = |m: [i32; 2], bound: f64| -> f64 { + let lb = self.lambda_sad * mv_bits(m); + self.sad_ref(&refr.planes[0], [x0 + (m[1] >> 3), y0 + (m[0] >> 3)], [c * 4, r * 4], n, [lb, bound]) as f64 + lb + }; + // positions already evaluated cannot beat `best` again (costs are deterministic) + let mut seen: Vec<[i32; 2]> = Vec::with_capacity(64); let mut best = ([0, 0], f64::MAX); for &m in &cands { let m = [m[0] & !7, m[1] & !7]; - if !valid(m) { + if !valid(m) || seen.contains(&m) { continue; } - let cst = cost(m); + seen.push(m); + let cst = cost(m, best.1); if cst < best.1 { best = (m, cst); } @@ -617,10 +644,11 @@ impl<'a> Decider<'a> { let center = best.0; for d in [[-step, 0], [step, 0], [0, -step], [0, step]] { let m = [center[0] + d[0], center[1] + d[1]]; - if !valid(m) { + if !valid(m) || seen.contains(&m) { continue; } - let cst = cost(m); + seen.push(m); + let cst = cost(m, best.1); if cst < best.1 { best = (m, cst); moved = true; @@ -631,15 +659,18 @@ impl<'a> Decider<'a> { } // half- then quarter-sample refinement (plus the exact neighbour candidates) let mut buf = vec![0u16; n * n]; - let sub_cost = |m: [i32; 2], buf: &mut Vec| -> f64 { + let sub_cost = |m: [i32; 2], buf: &mut Vec, bound: f64| -> f64 { self.search_block(m, c * 4, r * 4, n, buf); - self.sad(0, c * 4, r * 4, n, buf) as f64 + self.lambda_sad * mv_bits(m) + let lb = self.lambda_sad * mv_bits(m); + self.sad_bounded(0, [c * 4, r * 4], n, buf, [lb, bound]) as f64 + lb }; + let mut seen_sub: Vec<[i32; 2]> = Vec::with_capacity(24); for m in cands { if m[0] & 7 != 0 || m[1] & 7 != 0 { let m = [m[0] & !1, m[1] & !1]; - if valid(m) { - let cst = sub_cost(m, &mut buf); + if valid(m) && !seen_sub.contains(&m) { + seen_sub.push(m); + let cst = sub_cost(m, &mut buf, best.1); if cst < best.1 { best = (m, cst); } @@ -650,10 +681,11 @@ impl<'a> Decider<'a> { let center = best.0; for d in [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]] { let m = [center[0] + d[0] * step, center[1] + d[1] * step]; - if !valid(m) { + if !valid(m) || seen_sub.contains(&m) { continue; } - let cst = sub_cost(m, &mut buf); + seen_sub.push(m); + let cst = sub_cost(m, &mut buf, best.1); if cst < best.1 { best = (m, cst); } @@ -739,7 +771,8 @@ impl<'a> Decider<'a> { } /// SAD of the source block at (x, y) (luma) against the reference block at (rx, ry). - fn sad_ref(&self, refp: &Plane, rx: i32, ry: i32, x: usize, y: usize, n: usize) -> u64 { + /// Stops after a row once `sad + lb >= bound` (the cost can no longer win). + fn sad_ref(&self, refp: &Plane, [rx, ry]: [i32; 2], [x, y]: [usize; 2], n: usize, [lb, bound]: [f64; 2]) -> u64 { let (vw, vh) = (self.g.width, self.g.height); let w = n.min(vw.saturating_sub(x)); let h = n.min(vh.saturating_sub(y)); @@ -759,45 +792,16 @@ impl<'a> Decider<'a> { sad += (s[j] as i32 - b as i32).unsigned_abs() as u64; } } + if sad as f64 + lb >= bound { + return sad; + } } sad } - /// Sum of absolute Hadamard-transformed differences (4x4 or 8x8 sub-blocks) of a prediction - /// against the source, scaled to about the size of the SAD. - fn satd(&self, p: usize, x: usize, y: usize, n: usize, pred: &[u16]) -> u64 { - let src = &self.src[p]; - let k = n.min(8); - let mut total = 0u64; - let mut d = [0i32; 64]; - for by in (0..n).step_by(k) { - for bx in (0..n).step_by(k) { - for i in 0..k { - let row = &src.row(y + by + i)[x + bx..x + bx + k]; - for j in 0..k { - d[i * k + j] = row[j] as i32 - pred[(by + i) * n + bx + j] as i32; - } - } - for i in 0..k { - hadamard(&mut d[i * k..i * k + k]); - } - let mut col = [0i32; 8]; - let mut s = 0u64; - for j in 0..k { - for i in 0..k { - col[i] = d[i * k + j]; - } - hadamard(&mut col[..k]); - s += col[..k].iter().map(|v| v.unsigned_abs() as u64).sum::(); - } - total += s / (k as u64 / 2); - } - } - total - } - - /// SAD of a prediction against the source over the visible part of the block. - fn sad(&self, p: usize, x: usize, y: usize, n: usize, pred: &[u16]) -> u64 { + /// SAD of a prediction against the source over the visible part of the block. Stops after a row + /// once `sad + lb >= bound` (the cost can no longer win). + fn sad_bounded(&self, p: usize, [x, y]: [usize; 2], n: usize, pred: &[u16], [lb, bound]: [f64; 2]) -> u64 { let (vw, vh) = self.g.visible(p); let w = n.min(vw.saturating_sub(x)); let h = n.min(vh.saturating_sub(y)); @@ -806,10 +810,60 @@ impl<'a> Decider<'a> { for i in 0..h { let row = &src.row(y + i)[x..x + w]; s += row.iter().zip(&pred[i * n..i * n + w]).map(|(&a, &b)| (a as i32 - b as i32).unsigned_abs()).sum::() as u64; + if s as f64 + lb >= bound { + return s; + } } s } + /// Sum of absolute Hadamard-transformed differences (4x4 or 8x8 sub-blocks) of a prediction + /// against the source, scaled to about the size of the SAD. + fn satd(&self, p: usize, x: usize, y: usize, n: usize, pred: &[u16]) -> u64 { + if n >= 8 { self.satd_k::<8>(p, x, y, n, pred) } else { self.satd_k::<4>(p, x, y, n, pred) } + } + + /// `satd` with K x K Hadamard sub-blocks (fixed sizes so the butterflies vectorise). + fn satd_k(&self, p: usize, x: usize, y: usize, n: usize, pred: &[u16]) -> u64 { + let src = &self.src[p]; + let mut total = 0u64; + for by in (0..n).step_by(K) { + for bx in (0..n).step_by(K) { + // d[i] holds row i of the differences + let mut d = [[0i32; K]; K]; + for (i, di) in d.iter_mut().enumerate() { + let row = &src.row(y + by + i)[x + bx..x + bx + K]; + let pr = &pred[(by + i) * n + bx..(by + i) * n + bx + K]; + for j in 0..K { + di[j] = row[j] as i32 - pr[j] as i32; + } + } + // vertical butterflies across rows (all columns at once) + let mut h = 1; + while h < K { + for i0 in (0..K).step_by(2 * h) { + for i in i0..i0 + h { + let (a, b) = (d[i], d[i + h]); + for j in 0..K { + d[i][j] = a[j] + b[j]; + d[i + h][j] = a[j] - b[j]; + } + } + } + h *= 2; + } + // horizontal butterflies within each row + let mut s = 0u64; + for di in d.iter_mut() { + hadamard(di); + s += di.iter().map(|v| v.unsigned_abs() as u64).sum::(); + } + total += s / (K as u64 / 2); + } + } + total + } + fn sse(&self, p: usize, x: usize, y: usize, n: usize, blk: &[u16]) -> f64 { let (vw, vh) = self.g.visible(p); let w = n.min(vw.saturating_sub(x)); @@ -1062,4 +1116,158 @@ mod tests { assert_eq!(log2_of(t, v).to_bits(), (v as f64).log2().to_bits(), "{v}"); } } + + /// The SATD as it was before the fixed-size version: runtime block size, column gather. + fn satd_ref(src: &Plane, x: usize, y: usize, n: usize, pred: &[u16]) -> u64 { + let k = n.min(8); + let mut total = 0u64; + let mut d = [0i32; 64]; + for by in (0..n).step_by(k) { + for bx in (0..n).step_by(k) { + for i in 0..k { + let row = &src.row(y + by + i)[x + bx..x + bx + k]; + for j in 0..k { + d[i * k + j] = row[j] as i32 - pred[(by + i) * n + bx + j] as i32; + } + } + for i in 0..k { + hadamard(&mut d[i * k..i * k + k]); + } + let mut col = [0i32; 8]; + let mut s = 0u64; + for j in 0..k { + for i in 0..k { + col[i] = d[i * k + j]; + } + hadamard(&mut col[..k]); + s += col[..k].iter().map(|v| v.unsigned_abs() as u64).sum::(); + } + total += s / (k as u64 / 2); + } + } + total + } + + #[test] + fn satd_fixed_size_matches_runtime_size() { + let g = FrameGeom::new(100, 80); + let mut state = 0x9e37_79b9_7f4a_7c15u64; + let mut next = move || { + state ^= state << 13; + state ^= state >> 7; + state ^= state << 17; + state + }; + for bd in [8u32, 10] { + let max = (1u64 << bd) - 1; + let mut mk = |w: usize, h: usize| { + let mut p = Plane::new(w, h); + p.data.iter_mut().for_each(|v| *v = (next() % (max + 1)) as u16); + p + }; + let src = [mk(128, 128), mk(64, 64), mk(64, 64)]; + let dec = Decider::new(&g, bd, 100, true, &src, None); + for n in [4usize, 8, 16, 32] { + let pred: Vec = (0..n * n).map(|_| (next() % (max + 1)) as u16).collect(); + for (p, x, y) in [(0, 0, 0), (0, 32, 40), (1, 8, 4)] { + assert_eq!(dec.satd(p, x, y, n, &pred), satd_ref(&src[p], x, y, n, &pred), "n {n} plane {p}"); + } + } + } + } + + fn xorshift(seed: u64) -> impl FnMut() -> u64 { + let mut state = seed; + move || { + state ^= state << 13; + state ^= state >> 7; + state ^= state << 17; + state + } + } + + /// A snapshot keeps only the BlockDecoded cells of the block area. Coding inside the block + /// marks sub-blocks of every smaller size; restoring must give back the whole 3x35x35 array + /// as it was, for every block size of a 64x64 superblock and every aligned position. + #[test] + fn snapshot_restore_brings_back_every_blockdecoded_flag() { + let g = FrameGeom::new(256, 256); + let mut next = xorshift(0x2545_f491_4f6c_dd1d); + let src = [Plane::new(256, 256), Plane::new(128, 128), Plane::new(128, 128)]; + let mut dec = Decider::new(&g, 8, 100, true, &src, None); + for random_start in [false, true] { + for n4 in [1usize, 2, 4, 8, 16] { + for sb in [0usize, 16] { + for r in (sb..sb + 16).step_by(n4) { + for c in (sb..sb + 16).step_by(n4) { + for plane in dec.decoded.iter_mut() { + for row in plane.iter_mut() { + for v in row.iter_mut() { + *v = random_start && next() & 1 == 1; + } + } + } + let before = dec.decoded.clone(); + let snap = dec.snapshot(r, c, n4); + // every sub-block of every size inside the block, as coding marks them + let mut m = n4; + loop { + for rr in (r..r + n4).step_by(m) { + for cc in (c..c + n4).step_by(m) { + for p in 0..3 { + dec.mark_decoded(p, rr, cc, m); + } + } + } + if m == 1 { + break; + } + m /= 2; + } + dec.restore(&snap, r, c, n4); + assert!(dec.decoded == before, "n4 {n4} at ({r}, {c}), random start {random_start}"); + } + } + } + } + } + } + + /// The bounded SADs return the full SAD whenever the cost can still win (`sad + lb < bound`) + /// and otherwise a partial sum that already loses, so the callers' strict `<` decides the same. + #[test] + fn bounded_sad_stops_only_once_the_cost_cannot_win() { + let g = FrameGeom::new(100, 80); + let mut next = xorshift(0x9e37_79b9_7f4a_7c15); + let mut mk = |w: usize, h: usize| { + let mut p = Plane::new(w, h); + p.data.iter_mut().for_each(|v| *v = (next() % 256) as u16); + p + }; + let src = [mk(128, 128), mk(64, 64), mk(64, 64)]; + let refp = mk(128, 128); + let mut next = xorshift(0x1234_5678_9abc_def1); + let dec = Decider::new(&g, 8, 100, false, &src, None); + for n in [4usize, 8, 16, 32] { + for (x, y, rx, ry) in [(0usize, 0usize, 0i32, 0i32), (32, 40, 29, 43), (96, 72, 90, 70), (8, 8, -5, -3)] { + let full_ref = dec.sad_ref(&refp, [rx, ry], [x, y], n, [0.0, f64::INFINITY]); + let pred: Vec = (0..n * n).map(|_| (next() % 256) as u16).collect(); + let full_pred = dec.sad_bounded(0, [x, y], n, &pred, [0.0, f64::INFINITY]); + for _ in 0..50 { + let lb = (next() % 64) as f64 * 0.75; + let b_ref = (next() % (2 * full_ref + 2)) as f64; + let b_pred = (next() % (2 * full_pred + 2)) as f64; + let got_ref = dec.sad_ref(&refp, [rx, ry], [x, y], n, [lb, b_ref]); + let got_pred = dec.sad_bounded(0, [x, y], n, &pred, [lb, b_pred]); + for (got, full, bound) in [(got_ref, full_ref, b_ref), (got_pred, full_pred, b_pred)] { + if full as f64 + lb < bound { + assert_eq!(got, full, "n {n} at ({x}, {y}) bound {bound}"); + } else { + assert!(got as f64 + lb >= bound && got <= full, "n {n} at ({x}, {y}) bound {bound}"); + } + } + } + } + } + } } From 1ac3315ac4b862799601eb50b8bfb6e8854ca5cf Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Fri, 6 Nov 2026 23:22:19 +0100 Subject: [PATCH 16/40] SAM 2 tracking: prompt frames in frame order, no second fetch for the size check (#3030) (#3034) * SAM 2 tracking: prompt frames in frame order, size-check frame reused (#3030) With several objects prompted on three or more frames, the prompts went to the tracker object by object. The tracker keeps features for two frames, so every prompt after the first object fetched and encoded its frame again. Each prompt frame was also fetched once only to check its size and then fetched again for the encoder. Prompts now go to the tracker in frame order (then object order), and the frame fetched for the size check is handed to the tracker the first time it asks for that frame (up to 256 MB of pixel data kept; beyond that the frame is fetched again as before). Objects do not influence each other, so the results are unchanged. Tests cover the prompt order, one host fetch per prompt frame, the order of several prompts of one object on one frame, and the memory cap. Co-Authored-By: Claude Sonnet 5.5 * SAM 2 tracking test: the held-frame cap is cumulative Co-Authored-By: Claude Sonnet 5.5 --------- Co-authored-by: Claude Sonnet 5.5 Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> --- crates/sam2/src/track.rs | 156 +++++++++++++++++++++++++++++++++------ 1 file changed, 135 insertions(+), 21 deletions(-) diff --git a/crates/sam2/src/track.rs b/crates/sam2/src/track.rs index 7e73a1c74..d7717b5d0 100644 --- a/crates/sam2/src/track.rs +++ b/crates/sam2/src/track.rs @@ -28,6 +28,35 @@ struct Source<'a> { count: usize, fetch: RefCell>, sizes: Rc>>, + /// Prompt frames fetched only to learn their size, kept for the encoder (taken on first use). + held: RefCell, +} + +/// Most pixel data (in bytes) kept from the size check of the prompt frames; frames beyond it are +/// fetched again when the tracker needs them. +const HELD_BYTES: usize = 256 << 20; + +#[derive(Default)] +struct Held { + frames: HashMap>, + bytes: usize, +} + +impl Held { + fn keep(&mut self, index: usize, f: &Arc) { + let bytes = f.rgb.len().saturating_mul(std::mem::size_of::<[f32; 3]>()); + let fits = self.bytes.checked_add(bytes).filter(|t| *t <= HELD_BYTES); + if let (Some(total), false) = (fits, self.frames.contains_key(&index)) { + self.frames.insert(index, f.clone()); + self.bytes = total; + } + } + + fn take(&mut self, index: usize) -> Option> { + let f = self.frames.remove(&index)?; + self.bytes = self.bytes.saturating_sub(f.rgb.len().saturating_mul(std::mem::size_of::<[f32; 3]>())); + Some(f) + } } impl FrameSource for Source<'_> { @@ -41,7 +70,11 @@ impl FrameSource for Source<'_> { .filter(|_| index < self.count) .and_then(|offset| self.first.checked_add(offset)) .ok_or_else(|| Error::Input(format!("frame index {index} is outside the clip")))?; - let f = (self.fetch.borrow_mut())(number).ok_or_else(|| Error::Input(format!("frame {number} is not available")))?; + let held = self.held.borrow_mut().take(index); + let f = match held { + Some(f) => f, + None => (self.fetch.borrow_mut())(number).ok_or_else(|| Error::Input(format!("frame {number} is not available")))?, + }; self.sizes.borrow_mut().insert(index, (f.w, f.h)); preprocess(&f.rgb, f.w, f.h) } @@ -58,6 +91,36 @@ fn to_frame(m: &FrameMask, size: (usize, usize)) -> Result { /// Most objects one request may track. const MAX_OBJECTS: usize = 32; +/// Every prompt as `(object, frame index, prompt)`, in frame order (then object order), after +/// checking each prompt frame and recording its size in `source`. Frame order keeps the tracker's +/// two-frame feature cache useful: all objects prompted on a frame are encoded together, so each +/// prompt frame is encoded once however many objects there are. Objects do not influence each +/// other, so the order of prompts across objects does not change any result. +fn gather_prompts<'r>(req: &'r TrackRequest, source: &Source<'_>) -> Result> { + // Prompt coordinates are in the frame's pixels and the model works at 1024 x 1024, so the + // prompted frames' sizes are needed first. + let mut prompt_frames = vec![]; + for (oi, prompts) in req.objects.iter().enumerate() { + for (frame, p) in prompts { + let idx = frame + .checked_sub(req.first) + .and_then(|offset| usize::try_from(offset).ok()) + .filter(|i| *i < req.count) + .ok_or_else(|| Error::Input(format!("prompt frame {frame} is outside the clip")))?; + if !source.sizes.borrow().contains_key(&idx) { + let f = (source.fetch.borrow_mut())(*frame).ok_or_else(|| Error::Input(format!("frame {frame} is not available")))?; + validate_frame_size(f.w, f.h, f.rgb.len())?; + source.sizes.borrow_mut().insert(idx, (f.w, f.h)); + source.held.borrow_mut().keep(idx, &f); + } + prompt_frames.push((oi, idx, p)); + } + } + // stable: prompts of one object on one frame keep their order + prompt_frames.sort_by_key(|(oi, idx, _)| (*idx, *oi)); + Ok(prompt_frames) +} + impl Sam2Mask { fn run_track(&self, req: &TrackRequest, frames: Frames<'_>, cancel: &dyn Fn() -> bool, out: &mut dyn FnMut(usize, i64, TrackedFrame)) -> Result<()> { if req.count == 0 || req.count > MAX_CLIP { @@ -68,25 +131,8 @@ impl Sam2Mask { return Err(Error::Input(format!("tracking needs 1 to {MAX_OBJECTS} objects, each with a prompt on at least one frame"))); } let sizes = Rc::new(RefCell::new(HashMap::new())); - let source = Source { first: req.first, count: req.count, fetch: RefCell::new(frames), sizes: sizes.clone() }; - // Prompt coordinates are in the frame's pixels and the model works at 1024 x 1024, so the - // prompted frames' sizes are needed first. - let mut prompt_frames = vec![]; - for (oi, prompts) in req.objects.iter().enumerate() { - for (frame, p) in prompts { - let idx = frame - .checked_sub(req.first) - .and_then(|offset| usize::try_from(offset).ok()) - .filter(|i| *i < req.count) - .ok_or_else(|| Error::Input(format!("prompt frame {frame} is outside the clip")))?; - if !sizes.borrow().contains_key(&idx) { - let f = (source.fetch.borrow_mut())(*frame).ok_or_else(|| Error::Input(format!("frame {frame} is not available")))?; - validate_frame_size(f.w, f.h, f.rgb.len())?; - sizes.borrow_mut().insert(idx, (f.w, f.h)); - } - prompt_frames.push((oi, idx, p)); - } - } + let source = Source { first: req.first, count: req.count, fetch: RefCell::new(frames), sizes: sizes.clone(), held: RefCell::default() }; + let prompt_frames = gather_prompts(req, &source)?; let mut tracker = VideoTracker::new(self.video_model().clone(), Box::new(source))?; let object_id = |oi: usize| ObjectId(oi as u32 + 1); // each object's first prompted frame: its pass starts there, forwards and backwards @@ -174,8 +220,76 @@ mod tests { #[test] fn source_rejects_overflowing_and_out_of_range_indices_before_fetching() { let mut fetch = |_| panic!("invalid indices must not fetch a frame"); - let source = Source { first: i64::MAX, count: 2, fetch: RefCell::new(&mut fetch), sizes: Default::default() }; + let source = Source { first: i64::MAX, count: 2, fetch: RefCell::new(&mut fetch), sizes: Default::default(), held: RefCell::default() }; assert!(matches!(source.frame(1), Err(Error::Input(_)))); assert!(matches!(source.frame(usize::MAX), Err(Error::Input(_)))); } + + fn clip_frame(w: usize, h: usize) -> Arc { + Arc::new(ClipFrame { rgb: vec![[0.5, 0.25, 0.75]; w * h], w, h }) + } + + fn point_prompt() -> effectcraft_segment::Prompt { + effectcraft_segment::Prompt { points: vec![([1.0, 1.0], true)], bbox: None, mask: None } + } + + /// Several objects prompted on the same frames: prompts come out frame by frame (so the + /// two-frame feature cache holds each prompt frame for all of its objects), and each prompt + /// frame is fetched from the host once, size check and encoding together. + #[test] + fn prompts_run_frame_major_and_each_prompt_frame_is_fetched_once() { + let frames_prompted = [10i64, 13, 16]; + let req = TrackRequest { first: 10, count: 8, objects: (0..4).map(|_| frames_prompted.iter().map(|f| (*f, point_prompt())).collect()).collect() }; + let fetched = RefCell::new(vec![]); + let mut fetch = |n: i64| { + fetched.borrow_mut().push(n); + Some(clip_frame(4, 3)) + }; + let source = Source { first: req.first, count: req.count, fetch: RefCell::new(&mut fetch), sizes: Default::default(), held: RefCell::default() }; + let order: Vec<(usize, usize)> = gather_prompts(&req, &source).unwrap().into_iter().map(|(oi, idx, _)| (idx, oi)).collect(); + let expected: Vec<(usize, usize)> = [0usize, 3, 6].iter().flat_map(|f| (0..4).map(move |o| (*f, o))).collect(); + assert_eq!(order, expected); + assert_eq!(*fetched.borrow(), vec![10, 13, 16], "one size-check fetch per distinct prompt frame"); + // the tracker's first look at each prompt frame reuses the frame already fetched + for idx in [0usize, 3, 6] { + source.frame(idx).unwrap(); + } + assert_eq!(fetched.borrow().len(), 3, "encoding a prompt frame must not fetch it again"); + // a held frame is handed over once; a second look fetches again + source.frame(0).unwrap(); + assert_eq!(*fetched.borrow(), vec![10, 13, 16, 10]); + } + + #[test] + fn prompts_of_one_object_on_one_frame_keep_their_order() { + let (mut a, mut b) = (point_prompt(), point_prompt()); + a.points = vec![([1.0, 1.0], true)]; + b.points = vec![([2.0, 2.0], false)]; + let req = TrackRequest { first: 0, count: 3, objects: vec![vec![(2, a.clone()), (1, point_prompt()), (2, b.clone())]] }; + let mut fetch = |_| Some(clip_frame(2, 2)); + let source = Source { first: 0, count: 3, fetch: RefCell::new(&mut fetch), sizes: Default::default(), held: RefCell::default() }; + let got = gather_prompts(&req, &source).unwrap(); + assert_eq!(got.iter().map(|(_, i, _)| *i).collect::>(), vec![1, 2, 2]); + assert_eq!(got[1].2.points, a.points); + assert_eq!(got[2].2.points, b.points); + } + + #[test] + fn held_frames_are_bounded() { + let mut held = Held::default(); + let big = Arc::new(ClipFrame { rgb: vec![[0.0; 3]; HELD_BYTES / 12 + 1], w: 1, h: HELD_BYTES / 12 + 1 }); + held.keep(0, &big); + assert!(held.take(0).is_none(), "a frame over the cap is not kept"); + let small = clip_frame(4, 4); + held.keep(1, &small); + assert!(held.take(1).is_some()); + assert_eq!(held.bytes, 0); + // the cap is cumulative: frames that fit together are kept, the one that breaks it is not + let third = Arc::new(ClipFrame { rgb: vec![[0.0; 3]; HELD_BYTES / 12 / 3 + 1], w: 1, h: HELD_BYTES / 12 / 3 + 1 }); + for i in 0..4 { + held.keep(i, &third); + } + assert_eq!(held.frames.len(), 2); + assert!(held.bytes <= HELD_BYTES); + } } From c5bb8bfda4c20f577f341deb3ae71211989f3933 Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Fri, 6 Nov 2026 23:38:34 +0100 Subject: [PATCH 17/40] SAM 2 mask decoder: transposed convolutions as matrix product plus pixel shuffle (#3031) (#3035) * SAM 2 mask decoder: transposed convolutions as matrix product plus pixel shuffle (#3031) Both transposed convolutions of the mask decoder have a 2x2 kernel, stride 2 and no padding, so each input pixel owns its own 2x2 output block. That is one matrix product plus a pixel shuffle, which is about twice as fast on the CPU as candle's conv_transpose2d. The first convolution also takes the decoder's key tokens directly, without the transpose and copy to an image. The candle path stays in the code for the tests. They compare the two to 1e-6 (relative to the largest output value) on the decoder's real sizes, odd and degenerate sizes, large values, zeros and a single hot pixel, check that other kernels are refused, and compare a whole decoder forward pass (single and multi mask) on random weights. Co-Authored-By: Claude Sonnet 5.5 * SAM 2 decoder test: bound the weight discovery loop Co-Authored-By: Claude Sonnet 5.5 --------- Co-authored-by: Claude Sonnet 5.5 Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> --- crates/sam2/src/decoder.rs | 145 ++++++++++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 3 deletions(-) diff --git a/crates/sam2/src/decoder.rs b/crates/sam2/src/decoder.rs index d6b25a7e4..bb9f67d43 100644 --- a/crates/sam2/src/decoder.rs +++ b/crates/sam2/src/decoder.rs @@ -144,6 +144,25 @@ fn add_bias(x: Tensor, b: &Tensor) -> Result { Ok(x.broadcast_add(&b.reshape((1, b.dim(0)?, 1, 1))?)?) } +/// `conv_transpose2d` with a 2 x 2 kernel, stride 2, no padding, on tokens `[h * w, c]` (the image +/// laid out row by row) with weight `[c, o, 2, 2]`, as one matrix product plus a pixel shuffle: +/// every input pixel owns its own 2 x 2 output block, so there is no overlap to add up. Returns +/// `[1, o, 2h, 2w]` without the bias. candle's transposed convolution takes about twice as long. +fn conv_transpose_2x2(tokens: &Tensor, h: usize, w: usize, weight: &Tensor) -> Result { + let (c, o, kh, kw) = weight.dims4()?; + if (kh, kw) != (2, 2) || tokens.dims() != [h * w, c] { + return Err(Error::Input(format!("a 2x2 transposed convolution got tokens {:?} for a {c}x{o}x{kh}x{kw} weight on {h}x{w}", tokens.dims()))); + } + let y = tokens.matmul(&weight.reshape((c, o * 4))?)?; // [h * w, (o, 2, 2)] + Ok(y.reshape((h, w, o, 2, 2))?.permute((2, 0, 3, 1, 4))?.contiguous()?.reshape((1, o, 2 * h, 2 * w))?) +} + +/// The same convolution on an image `[1, c, h, w]`. +fn conv_transpose_2x2_image(x: &Tensor, weight: &Tensor) -> Result { + let (_, c, h, w) = x.dims4()?; + conv_transpose_2x2(&x.reshape((c, h * w))?.t()?.contiguous()?, h, w, weight) +} + impl MaskDecoder { pub fn load(w: &Weights) -> Result { let layers = (0..2) @@ -194,6 +213,22 @@ impl MaskDecoder { /// no-memory embedding already added when there is no memory), `sparse`: `[1, n, 256]`, /// `dense`: `[1, 256, g, g]`, `high`: the skip features from [`MaskDecoder::high_res`]. pub fn forward(&self, image: &Tensor, pos: &Tensor, sparse: &Tensor, dense: &Tensor, high: &(Tensor, Tensor), multimask: bool) -> Result { + self.forward_with(image, pos, sparse, dense, high, multimask, true) + } + + /// [`MaskDecoder::forward`]; `matmul_upscale` picks the matrix-product transposed convolutions + /// (the normal path) or candle's `conv_transpose2d` (the reference the tests compare with). + #[allow(clippy::too_many_arguments)] + fn forward_with( + &self, + image: &Tensor, + pos: &Tensor, + sparse: &Tensor, + dense: &Tensor, + high: &(Tensor, Tensor), + multimask: bool, + matmul_upscale: bool, + ) -> Result { let (_, c, g, gw) = image.dims4()?; if c != DIM || g != gw { return Err(Error::Input(format!("image embedding must be 256 x g x g, got {:?}", image.dims()))); @@ -214,13 +249,19 @@ impl MaskDecoder { let mask_tokens_out = queries.narrow(1, 2, MASK_TOKENS)?; let obj_out = queries.narrow(1, 0, 1)?.squeeze(1)?; - let emb = keys.transpose(1, 2)?.contiguous()?.reshape((1, DIM, g, g))?; let (s0, s1) = high; - let up = add_bias(emb.conv_transpose2d(&self.up1.0, 0, 0, 2, 1)?, &self.up1.1)?; + let up = if matmul_upscale { + // the keys are already the image's tokens, row by row: no transpose needed + conv_transpose_2x2(&keys.reshape((g * g, DIM))?, g, g, &self.up1.0)? + } else { + keys.transpose(1, 2)?.contiguous()?.reshape((1, DIM, g, g))?.conv_transpose2d(&self.up1.0, 0, 0, 2, 1)? + }; + let up = add_bias(up, &self.up1.1)?; let up = (up + s1)?; let up = self.up_ln.forward(&up.permute((0, 2, 3, 1))?)?.permute((0, 3, 1, 2))?.contiguous()?; let up = gelu(&up)?; - let up = (add_bias(up.conv_transpose2d(&self.up2.0, 0, 0, 2, 1)?, &self.up2.1)? + s0)?; + let up = if matmul_upscale { conv_transpose_2x2_image(&up, &self.up2.0)? } else { up.conv_transpose2d(&self.up2.0, 0, 0, 2, 1)? }; + let up = (add_bias(up, &self.up2.1)? + s0)?; let up = gelu(&up)?; let hyper: Vec = self.hyper.iter().enumerate().map(|(i, m)| m.forward(&mask_tokens_out.narrow(1, i, 1)?.squeeze(1)?)).collect::>()?; @@ -258,3 +299,101 @@ fn dynamic_single(masks: &Tensor, iou: &Tensor) -> Result<(Tensor, Tensor)> { let best = multi_iou.iter().enumerate().fold((0usize, f32::NEG_INFINITY), |b, (i, v)| if *v > b.1 { (i, *v) } else { b }).0; Ok((masks.narrow(1, 1 + best, 1)?, iou.narrow(1, 1 + best, 1)?)) } + +#[cfg(test)] +mod tests { + use std::collections::HashMap; + + use candle_core::{DType, Device}; + + use super::*; + + fn max_diff(a: &Tensor, b: &Tensor) -> f32 { + assert_eq!(a.dims(), b.dims()); + (a - b).unwrap().abs().unwrap().flatten_all().unwrap().max(0).unwrap().to_scalar::().unwrap() + } + + /// The matrix-product form equals `conv_transpose2d` (kernel 2, stride 2, no padding, the only + /// variant the decoder uses) to rounding, for the decoder's two sizes and for odd ones. + #[test] + fn matmul_transposed_convolution_matches_conv_transpose2d() { + let d = &Device::Cpu; + // (in channels, out channels, height, width) + let cases = + [(256, 64, 64, 64), (64, 32, 128, 128), (256, 64, 16, 16), (3, 5, 7, 11), (5, 3, 1, 9), (4, 2, 9, 1), (1, 1, 1, 1), (17, 1, 3, 5), (1, 19, 6, 2)]; + for (c, o, h, w) in cases { + for (std, scale) in [(1.0, 0.05), (30.0, 3.0)] { + let x = Tensor::randn(0f32, std, (1, c, h, w), d).unwrap(); + let k = Tensor::randn(0f32, scale, (c, o, 2, 2), d).unwrap(); + let want = x.conv_transpose2d(&k, 0, 0, 2, 1).unwrap(); + let got = conv_transpose_2x2_image(&x, &k).unwrap(); + // 1e-6 of the largest output value (at least 1e-6 absolute): float rounding only + let peak = want.abs().unwrap().flatten_all().unwrap().max(0).unwrap().to_scalar::().unwrap(); + let tol = 1e-6 * peak.max(1.0); + let diff = max_diff(&want, &got); + assert!(diff <= tol, "c{c} o{o} {h}x{w} std {std}: max diff {diff:e} > {tol:e}"); + } + } + } + + #[test] + fn matmul_transposed_convolution_edge_values() { + let d = &Device::Cpu; + // zeros, a single hot pixel and negative values land in the right 2x2 block + let k = Tensor::randn(0f32, 1.0, (3, 2, 2, 2), d).unwrap(); + let zero = Tensor::zeros((1, 3, 4, 5), DType::F32, d).unwrap(); + assert_eq!(max_diff(&zero.conv_transpose2d(&k, 0, 0, 2, 1).unwrap(), &conv_transpose_2x2_image(&zero, &k).unwrap()), 0.0); + let mut v = vec![0f32; 3 * 4 * 5]; + v[2 * 20 + 3 * 5 + 1] = -7.5; + let hot = Tensor::from_vec(v, (1, 3, 4, 5), d).unwrap(); + assert!(max_diff(&hot.conv_transpose2d(&k, 0, 0, 2, 1).unwrap(), &conv_transpose_2x2_image(&hot, &k).unwrap()) <= 1e-6); + // other kernels are refused, not computed wrongly + let k3 = Tensor::zeros((3, 2, 3, 3), DType::F32, d).unwrap(); + assert!(conv_transpose_2x2_image(&hot, &k3).is_err()); + } + + /// Random weights for every tensor the decoder asks for, found by loading until nothing is missing. + fn random_decoder() -> MaskDecoder { + let d = &Device::Cpu; + let mut map: HashMap = HashMap::new(); + for _ in 0..1000 { + match MaskDecoder::load(&Weights::from_map(map.clone()).unwrap()) { + Ok(m) => return m, + Err(Error::Weights(m)) => { + let name = m.split('`').nth(1).unwrap().to_string(); + let shape: Vec = match m.split("expected [").nth(1) { + Some(e) => e.trim_end_matches(']').split(',').map(|s| s.trim().parse().unwrap()).collect(), + None => vec![1], + }; + let t = if name.contains("layer_norm") && name.ends_with("weight") { + Tensor::ones(shape, DType::F32, d) + } else { + Tensor::randn(0f32, 0.05, shape, d) + }; + map.insert(name, t.unwrap()); + } + Err(e) => panic!("{e}"), + } + } + panic!("the decoder kept asking for tensors"); + } + + #[test] + fn decoder_output_is_the_same_with_either_transposed_convolution() { + let d = &Device::Cpu; + let dec = random_decoder(); + let g = 16; + let r = |dims: &[usize]| Tensor::randn(0f32, 1.0, dims, d).unwrap(); + let (image, pos, dense) = (r(&[1, DIM, g, g]), r(&[1, DIM, g, g]), r(&[1, DIM, g, g])); + let sparse = r(&[1, 3, DIM]); + let high = dec.high_res(&r(&[1, DIM, 4 * g, 4 * g]), &r(&[1, DIM, 2 * g, 2 * g])).unwrap(); + for multimask in [false, true] { + let a = dec.forward_with(&image, &pos, &sparse, &dense, &high, multimask, false).unwrap(); + let b = dec.forward_with(&image, &pos, &sparse, &dense, &high, multimask, true).unwrap(); + assert!(max_diff(&a.masks, &b.masks) <= 2e-5, "masks differ by {:e}", max_diff(&a.masks, &b.masks)); + assert!(max_diff(&a.iou, &b.iou) <= 1e-5); + assert!(max_diff(&a.sam_tokens, &b.sam_tokens) <= 1e-5); + assert!(max_diff(&a.object_score, &b.object_score) <= 1e-5); + } + } +} From e28475868356530eb793b91ec70f34fdba738488 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Sat, 7 Nov 2026 00:03:41 +0100 Subject: [PATCH 18/40] CI: run the gate on macOS on pushes to main (#3177) Co-authored-by: Claude Opus 5.5 --- .github/workflows/ci-macos.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/ci-macos.yml diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml new file mode 100644 index 000000000..3ef98173a --- /dev/null +++ b/.github/workflows/ci-macos.yml @@ -0,0 +1,28 @@ +name: CI (macOS) + +# The macOS leg of the gate: `cargo xtask ci` on Apple silicon, through the suite's shared gate +# workflow. The Linux gate (ci.yml) has no real GPU and runs on x86, so GPU tests on Metal and +# results that depend on the platform's math library first ran on a contributor's Mac. +# +# On pushes to main, not on every pull request: macOS runners are scarce. A newer push cancels the +# older run, so main is checked at its latest commit. Pull requests that change this file run it. +on: + push: + branches: [main] + pull_request: + paths: [.github/workflows/ci-macos.yml] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ci-macos-${{ github.ref }} + cancel-in-progress: true + +jobs: + gate: + uses: storytold/craft-common-actions/.github/workflows/gate.yml@main + with: + os: '["macos-15"]' + timeout-minutes: 120 From 719b9170dd6cad31aaa75d6612ad37b4073d05b7 Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Sat, 7 Nov 2026 00:03:52 +0100 Subject: [PATCH 19/40] 3D rotation order, keyed Orientation, linear-to-eased keyframes and Timewarp behave as in After Effects (#1876) * 3D: Orientation and X/Y/Z Rotation turn Z first, keyed Orientation slerps, as After Effects After Effects composes a 3D layer's (and a camera's) Orientation and its X/Y/Z Rotation as Rx * Ry * Rz each, Orientation before the axis rotations; EffectCraft used Rz * Ry * Rx. Measured on synthetic AE 2026 cases: Orientation [10,20,30] (488) was 5.2 % of the frame off and now matches to the anti-aliased edge (0.03 %); X/Y/Z Rotation 10/20/30 (800), Orientation + X Rotation (801) and one-node cameras (804, 805) likewise. Keyed Orientation moves along the shortest arc between the keys (quaternion slerp, eased in time, angles written in [0, 360)): keys [0,0,0] -> [10,20,30] read back [6.2643, 9.3531, 15.2190] half-way where EffectCraft gave [5,10,15]; [0,0,0] -> [60,80,40] linear and eased match AE's read-backs within 0.002 deg. lookAt() returns AE's angles (z axis on the target, x axis level; two AE read-backs within 1e-3 deg). The camera tracker, VR editor, Look At and orbit commands use the new decomposition. Co-Authored-By: Claude Opus 5.5 * Keyframes: a linear side next to an eased side has 16.67 % influence, as After Effects In a segment that is Bezier on one side and linear on the other, the linear side keeps the segment's average speed, but with the 16.67 % influence After Effects shows for linear keys in the Keyframe Velocity dialog (and reports to scripts), not 33.3 %. Measured on an After Effects 2026 time-remap render (a square at x = 50 + 455 * remap): out of a key at 2 s (3.5, speed 0, influence 50 %) into a linear key at 4 s (0.5), AE plays 3.290 at 2.5 s and 2.657 at 3 s; EffectCraft played 3.308 and 2.629 (8 and 13 px off), now the same square positions to the pixel. LINEAR_SIDE_INFLUENCE is used by evaluation (scalar, per-dimension, paths and spatial), side_ease (Graph Editor, velocity dialog, keyIn/OutTemporalEase) and the Lottie export, so exported easing plays as EffectCraft does. Segments linear on both sides stay straight lines. Co-Authored-By: Claude Opus 5.5 * Timewarp: retime the layer's source without the effects above it, as After Effects After Effects' Timewarp reads the layer's source (with its masks) at the retimed times and ignores the effects applied before it: a red solid with a Gradient Ramp and then Timewarp (Speed 25) renders as the red solid in AE 2026 (EXPORTER e2 read-back). EffectCraft retimed the layer with its effects (mean difference 127.5/255 over the comp), now identical (0, CPU and GPU). Echo, Posterize Time and the other time effects keep reading the effects before them, as measured before. Co-Authored-By: Claude Opus 5.5 * Image sequences: a gap in the numbering holds the previous frame, as After Effects After Effects 2026 shows the last existing file across a gap in a sequence's numbering (case 860: files 1, 2, 4, 5 show frame 2 at frame 3; VERIFY read-back). EffectCraft drew colour bars there. The media pool now holds the previous file (Footage::sequence_file_held); colour bars remain only where no file precedes the frame. Missing-frame reports on import are unchanged. Co-Authored-By: Claude Opus 5.5 * Review: keyed Orientation uses LINEAR_SIDE_INFLUENCE for linear sides; real NaN assert evaluate_orientation still gave a linear side (and the unreachable missing-key fallback) 1/3 influence while segment_value, side_ease and the Lottie export use LINEAR_SIDE_INFLUENCE (1/6), so a keyed Orientation next to an eased key moved on a different curve than every other property (CodeRabbit on #1876). New test: orientation_linear_side_next_to_an_eased_side_matches_a_scalar (both directions). The always-true NaN assert in keyed_orientation_slerps_as_after_effects now checks that a non-finite key comes back as given; Property::value_at says why the match_id "orientation" routing is safe. Co-Authored-By: Claude Opus 5.5 * Format keyframe orientation test (cargo fmt) Co-Authored-By: Claude Sonnet 5.5 * Move the image-sequence gap change out of this branch The gap change (hold the previous file instead of colour bars) reverses #297's documented behaviour and goes to its own PR, as requested in review. pool.rs, sequence.rs, the footage test and docs/footage.md / docs/agents.md are back to main. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 Co-authored-by: Codex Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> --- crates/effects/src/time_fx.rs | 49 +++- crates/engine/src/cmd/layer/parent.rs | 140 +--------- crates/engine/src/cmd/three_d.rs | 2 +- crates/engine/src/cmd/vr_editor.rs | 8 +- crates/engine/src/tests/rig3d.rs | 20 +- .../engine/tests/it/parenting_3d_position.rs | 48 +++- crates/expr/src/prelude.js | 22 +- crates/expr/src/tests.rs | 6 + crates/geom/src/lib.rs | 160 ++++++++++- crates/keyframe/src/lib.rs | 79 +++++- crates/keyframe/src/tests.rs | 90 ++++++ crates/lottie/src/anim.rs | 8 +- crates/project/src/props.rs | 7 + crates/render/src/eval.rs | 8 +- crates/render/src/three_d/camera.rs | 13 +- crates/render/src/three_d/tests_orient.rs | 261 ++++++++++++++++++ crates/script/src/tests/ease_presets.rs | 4 +- crates/track/src/camtrack/linalg.rs | 12 +- docs/effects-parity.md | 3 +- docs/fidelity/README.md | 12 + 20 files changed, 755 insertions(+), 197 deletions(-) diff --git a/crates/effects/src/time_fx.rs b/crates/effects/src/time_fx.rs index cf7624d92..f8886d58c 100644 --- a/crates/effects/src/time_fx.rs +++ b/crates/effects/src/time_fx.rs @@ -4,8 +4,10 @@ //! These read the layer at *other* layer times through [`EffectHost::self_at`]: its source with //! its masks and the effects applied before them, as After Effects renders them (SceneYard: //! Echo after CC Particle Systems II echoes the fireworks, not the black solid under them; -//! Posterize Time after Turbulent Displace steps the displacement). Without a host (tests, -//! thumbnails) they pass their input through. +//! Posterize Time after Turbulent Displace steps the displacement). Timewarp is the exception: +//! it retimes the layer's source with its masks and ignores the effects above it (After +//! Effects 2026: a red solid with a Gradient Ramp and then Timewarp shows the red solid). +//! Without a host (tests, thumbnails) they pass their input through. //! //! Timewarp's Pixel Motion estimates block-matching optical flow between neighbouring frames //! ([`effectcraft_raster::flow`]); Pixel Motion Blur averages sub-frame samples. @@ -163,15 +165,21 @@ struct Frames { imgs: Vec, } -/// Fetch the layer (source + masks) at layer times `times`. `None` without a host. +/// Fetch the layer (source + masks + the effects before this one) at layer times `times`. +/// `None` without a host. fn fetch(ctx: &EffectCtx, times: &[f64]) -> Option { + fetch_with(ctx, times, usize::MAX) +} + +/// [`fetch`] with the first `effects` effects of the stack only (0: source and masks). +fn fetch_with(ctx: &EffectCtx, times: &[f64], effects: usize) -> Option { let host = ctx.env.host?; // Dedupe times (sub-microsecond differences are the same frame). let mut uniq: Vec = times.iter().map(|t| (t * 1e6).round() as i64).collect(); uniq.sort_unstable(); uniq.dedup(); // Every effect before this one (the host bounds the count to them). - let bufs: Vec<(i64, Option)> = uniq.iter().map(|&k| (k, host.self_at(k as f64 / 1e6, usize::MAX))).collect(); + let bufs: Vec<(i64, Option)> = uniq.iter().map(|&k| (k, host.self_at(k as f64 / 1e6, effects))).collect(); let first = bufs.iter().find_map(|(_, b)| b.as_ref())?; let scale = first.scale; // Union of every frame's extent in layer pixels (offset = where layer (0,0) sits). @@ -851,7 +859,8 @@ pub fn timewarp_plan(ctx: &EffectCtx) -> Option { let (instants, times, fps) = timewarp_instants(ctx); let method = ctx.params.e("method"); let one = method > 0 && ctx.params.b("tuning/buildFromOneImage"); - let fr = fetch(ctx, ×)?; + // The source with its masks, without the effects above Timewarp. + let fr = fetch_with(ctx, ×, 0)?; let pm = PixelMotion::from(ctx, fr.grid.scale); let mattes = fetch_layer(ctx, "matteLayer", ×, &fr.grid); let warps = fetch_layer(ctx, "warpLayer", ×, &fr.grid); @@ -1082,8 +1091,8 @@ mod tests { None } fn self_at(&self, t: f64, effects: usize) -> Option { - // Time effects see every effect before them. - assert_eq!(effects, usize::MAX); + // Time effects see every effect before them; Timewarp only the source and masks. + assert!(effects == usize::MAX || effects == 0, "{effects}"); let v = if self.static_layer { 0.4 } else { t as f32 }; Some(Buf { img: Image::filled(6, 4, [v, v, v, 1.0]), offset: [0.0; 2], scale: 1.0 }) } @@ -1094,6 +1103,32 @@ mod tests { run_fx(id, vals, Image::filled(6, 4, [0.9, 0.0, 0.0, 1.0]), t, env) } + /// After Effects 2026: Timewarp retimes the layer's source (with masks) and ignores the + /// effects above it; Echo keeps them. + #[test] + fn timewarp_reads_the_source_without_the_effects_above_it() { + struct Asked(std::sync::Mutex>); + impl EffectHost for Asked { + fn layer(&self, _: u64, _: bool) -> Option { + None + } + fn audio(&self, _: u64, _: f64, _: usize, _: u32) -> Option> { + None + } + fn self_at(&self, _: f64, effects: usize) -> Option { + self.0.lock().unwrap_or_else(std::sync::PoisonError::into_inner).push(effects); + // The source (effects 0) is red, the layer with its effects green. + let c = if effects == 0 { [1.0, 0.0, 0.0, 1.0] } else { [0.0, 1.0, 0.0, 1.0] }; + Some(Buf { img: Image::filled(6, 4, c), offset: [0.0; 2], scale: 1.0 }) + } + } + let host = Asked(std::sync::Mutex::new(vec![])); + let env = EffectEnv { host: Some(&host), frame_rate: 10.0, comp_time: 1.0, ..Default::default() }; + let out = run_fx("ec.time.timewarp", &[("speed", num(25.0))], Image::filled(6, 4, [0.0, 1.0, 0.0, 1.0]), 1.0, env); + assert_eq!(out.img.get(2, 2), [1.0, 0.0, 0.0, 1.0]); + assert!(host.0.lock().unwrap_or_else(std::sync::PoisonError::into_inner).iter().all(|&e| e == 0)); + } + #[test] fn posterize_time_holds_frames() { let h = Clock { static_layer: false }; diff --git a/crates/engine/src/cmd/layer/parent.rs b/crates/engine/src/cmd/layer/parent.rs index 870d22f5f..3611ef047 100644 --- a/crates/engine/src/cmd/layer/parent.rs +++ b/crates/engine/src/cmd/layer/parent.rs @@ -175,23 +175,7 @@ fn uniform_rotation(m: effectcraft_geom::Mat4) -> Option<(effectcraft_geom::Mat4 Some((rotation, factor)) } -/// The turn (degrees) of a rotation about Z alone, or `None` for any other rotation. -fn z_only_turn(correction: effectcraft_geom::Mat4) -> Option { - let m = correction.0; - let about_z = [m[0][2], m[1][2], m[2][0], m[2][1]].iter().all(|v| v.abs() < 1e-9) && (m[2][2] - 1.0).abs() < 1e-9; - about_z.then(|| m[1][0].atan2(m[0][0]).to_degrees()) -} - -/// ZYX Euler angles in degrees of a row-major rotation (`Rz * Ry * Rx`), safe at gimbal lock. -fn euler_zyx(r: [[f64; 4]; 4]) -> [f64; 3] { - // atan2 rather than asin: near ±90 degrees asin loses precision, while cos(y) stays exact. - let cy = r[0][0].hypot(r[1][0]); - let y = (-r[2][0]).atan2(cy); - let (x, z) = if cy > 1e-9 { (r[2][1].atan2(r[2][2]), r[1][0].atan2(r[0][0])) } else { ((-r[1][2]).atan2(r[1][1]), 0.0) }; - [x.to_degrees(), y.to_degrees(), z.to_degrees()] -} - -/// The equivalent ZYX Euler triple nearest `reference`: each axis moved by whole turns, or the +/// The equivalent XYZ Euler triple nearest `reference`: each axis moved by whole turns, or the /// `(x + 180, 180 - y, z + 180)` form when that is nearer. fn nearest_euler(euler: [f64; 3], reference: [f64; 3]) -> [f64; 3] { let near = |v: [f64; 3]| -> [f64; 3] { std::array::from_fn(|i| v[i] + ((reference[i] - v[i]) / 360.0).round() * 360.0) }; @@ -204,136 +188,30 @@ fn nearest_euler(euler: [f64; 3], reference: [f64; 3]) -> [f64; 3] { /// The Euler Orientation of `correction * Orientation(o)`, in the form nearest `reference`. fn reexpress_euler(correction: effectcraft_geom::Mat4, o: [f64; 3], reference: [f64; 3]) -> [f64; 3] { let world = correction * effectcraft_geom::Mat4::orientation(effectcraft_geom::Vec3::from(o)); - nearest_euler(euler_zyx(world.0), reference) + let angles = world.orientation_angles(); + nearest_euler([angles.x, angles.y, angles.z], reference) } -/// Largest angle (degrees) a baked Orientation may drift from the exact rotation between its keys. -const BAKE_TOLERANCE_DEGREES: f64 = 0.05; -/// How many times a segment may be halved while baking, and the most keys a property may end up with. -const BAKE_MAX_DEPTH: u32 = 10; -const BAKE_MAX_KEYS: usize = 4096; - -/// The angle (degrees) between two rotations. -fn rotation_angle(a: effectcraft_geom::Mat4, b: effectcraft_geom::Mat4) -> f64 { - let trace: f64 = (0..3).flat_map(|i| (0..3).map(move |j| (i, j))).map(|(i, j)| a.0[i][j] * b.0[i][j]).sum(); - ((trace - 1.0) / 2.0).clamp(-1.0, 1.0).acos().to_degrees() -} - -/// Adds keys between `(ta, ea)` and `(tb, eb)` (already converted) wherever the straight Euler blend -/// between them drifts from `correction * Orientation(authored)` by more than the tolerance. `out` -/// never grows past `budget` keys: what the whole property may still add, not what one segment may. -fn bake_between( - correction: effectcraft_geom::Mat4, - authored: &effectcraft_project::Property, - (ta, ea): (Tick, [f64; 3]), - (tb, eb): (Tick, [f64; 3]), - depth: u32, - budget: usize, - out: &mut Vec, -) { - use effectcraft_geom::{Mat4, Vec3}; - if depth == 0 || tb.0 - ta.0 < 2 || out.len() >= budget { - return; - } - let tm = Tick(ta.0 + (tb.0 - ta.0) / 2); - let blend = [(ea[0] + eb[0]) / 2.0, (ea[1] + eb[1]) / 2.0, (ea[2] + eb[2]) / 2.0]; - let exact = correction * Mat4::orientation(Vec3::from(authored.value_at(tm).as_vec3())); - // Symmetric easing crosses the straight blend at its midpoint. Check both sides too before - // accepting a segment whose original easing will be replaced with a linear blend. - let quarter = (tb.0 - ta.0) / 4; - if [Tick(ta.0 + quarter), tm, Tick(tb.0 - quarter)].into_iter().all(|t| { - let u = (t.0 - ta.0) as f64 / (tb.0 - ta.0) as f64; - let linear = std::array::from_fn(|i| ea[i] + (eb[i] - ea[i]) * u); - let target = correction * Mat4::orientation(Vec3::from(authored.value_at(t).as_vec3())); - rotation_angle(Mat4::orientation(Vec3::from(linear)), target) <= BAKE_TOLERANCE_DEGREES - }) { - return; - } - let em = nearest_euler(euler_zyx(exact.0), blend); - bake_between(correction, authored, (ta, ea), (tm, em), depth - 1, budget, out); - if out.len() >= budget { - return; - } - out.push(effectcraft_keyframe::Keyframe::new(tm, KV::Vec3(em))); - bake_between(correction, authored, (tm, em), (tb, eb), depth - 1, budget, out); -} - -/// Re-expresses Orientation as `correction * Orientation`. A Z-only correction shifts Z exactly in the -/// value and every key. For any other correction a static value is converted directly; keys are -/// converted, and keys are added between them wherever the Euler blend between two keys would drift -/// from the exact rotation (the segments become linear, with the original easing baked in). +/// Re-express Orientation as `correction * Orientation`, retaining authored keys and easing. +/// Orientation interpolates along quaternion arcs: a constant left rotation preserves those arcs +/// and their angular speeds, so converting the endpoints preserves the entire eased animation. fn reexpress_orientation(correction: effectcraft_geom::Mat4, pr: &mut effectcraft_project::Property) { - if let Some(turn) = z_only_turn(correction) { - // No turn (an identity correction) leaves every authored value as it is. - if turn.abs() <= 1e-12 { - return; - } - let shift = |value: &KV| { - let [x, y, z] = value.as_vec3(); - KV::Vec3([x, y, z + turn]) - }; - pr.value = shift(&pr.value); - for key in &mut pr.keys { - key.value = shift(&key.value); - } + if (0..3).all(|row| (0..3).all(|col| (correction.0[row][col] - if row == col { 1.0 } else { 0.0 }).abs() < 1e-12)) { return; } let value = pr.value.as_vec3(); pr.value = KV::Vec3(reexpress_euler(correction, value, value)); - if pr.keys.is_empty() { - return; - } - let authored = pr.clone(); - // Each key keeps the authored change from the previous key on top of its converted value. - let mut converted: Vec<[f64; 3]> = vec![]; let mut prev: Option<([f64; 3], [f64; 3])> = None; - for key in &authored.keys { + for key in &mut pr.keys { let o = key.value.as_vec3(); let reference = match prev { Some((before, after)) => [after[0] + o[0] - before[0], after[1] + o[1] - before[1], after[2] + o[2] - before[2]], None => o, }; let n = reexpress_euler(correction, o, reference); - converted.push(n); + key.value = KV::Vec3(n); prev = Some((o, n)); } - use effectcraft_keyframe::Interp; - let mut keys: Vec = vec![]; - let mut after_baked_segment = false; - for (i, key) in authored.keys.iter().enumerate() { - let mut k = key.clone(); - k.value = KV::Vec3(converted[i]); - if after_baked_segment { - k.in_interp = Interp::Linear; - k.in_ease.clear(); - k.auto_bezier = false; - k.continuous = false; - } - after_baked_segment = false; - let segment = authored.keys.get(i + 1).filter(|_| key.out_interp != Interp::Hold); - let mut between = vec![]; - if let Some(next) = segment { - // What the whole property may still add: the keys it will have already (the ones written - // and the authored ones still to come) count against the cap. - let budget = BAKE_MAX_KEYS.saturating_sub(keys.len() + authored.keys.len() - i); - bake_between(correction, &authored, (key.time, converted[i]), (next.time, converted[i + 1]), BAKE_MAX_DEPTH, budget, &mut between); - // With the cap reached the segment can't be checked or subdivided: it keeps its authored easing between - // the converted keys, rather than becoming a straight blend that was never checked against the original. - if between.len() >= budget { - between.clear(); - // An eased segment, or one that gained keys, becomes a run of straight blends. - } else if !between.is_empty() || key.out_interp != Interp::Linear || next.in_interp != Interp::Linear { - k.out_interp = Interp::Linear; - k.out_ease.clear(); - k.auto_bezier = false; - k.continuous = false; - after_baked_segment = true; - } - } - keys.push(k); - keys.extend(between); - } - pr.keys = keys; } /// Correction for a two-node rig's Orientation: after a uniform parent change its aim is diff --git a/crates/engine/src/cmd/three_d.rs b/crates/engine/src/cmd/three_d.rs index f7b1c3e08..009a33b2e 100644 --- a/crates/engine/src/cmd/three_d.rs +++ b/crates/engine/src/cmd/three_d.rs @@ -492,7 +492,7 @@ fn camera_tool(s: &mut Session, p: &Value, op: ToolOp, cmd: &str, label: &str) - let poi = if two { Vec3::from(get_at(l, "transform/poi", t).map(|v| v.as_vec3()).unwrap_or([w / 2.0, h / 2.0, 0.0])) } else { - let fwd = (Mat4::orientation(Vec3::from(o)) * Mat4::rotate_y(ry) * Mat4::rotate_x(rx)).apply_vec(vec3(0.0, 0.0, 1.0)); + let fwd = (Mat4::orientation(Vec3::from(o)) * Mat4::rotation_xyz(rx, ry, 0.0)).apply_vec(vec3(0.0, 0.0, 1.0)); pos + fwd * zoom }; let mut rig = Rig { eye: pos, poi, zoom, ortho: false }; diff --git a/crates/engine/src/cmd/vr_editor.rs b/crates/engine/src/cmd/vr_editor.rs index e62281128..12ebcda5b 100644 --- a/crates/engine/src/cmd/vr_editor.rs +++ b/crates/engine/src/cmd/vr_editor.rs @@ -79,12 +79,10 @@ fn norm(a: f64) -> f64 { (r * 1e6).round() / 1e6 } -/// Orientation angles (X, Y, Z degrees, applied X then Y then Z) of a rotation matrix. +/// Orientation angles (X, Y, Z degrees, [`Mat4::orientation`] order) of a rotation matrix. pub fn euler(m: Mat4) -> [f64; 3] { - let m = m.0; - let y = (-m[2][0]).clamp(-1.0, 1.0).asin(); - let (x, z) = if y.cos().abs() > 1e-6 { (m[2][1].atan2(m[2][2]), m[1][0].atan2(m[0][0])) } else { ((-m[1][2]).atan2(m[1][1]), 0.0) }; - [norm(x.to_degrees()), norm(y.to_degrees()), norm(z.to_degrees())] + let o = m.orientation_angles(); + [norm(o.x), norm(o.y), norm(o.z)] } /// The current view orientation of an environment (from its Front camera). diff --git a/crates/engine/src/tests/rig3d.rs b/crates/engine/src/tests/rig3d.rs index cf2518447..db64a9066 100644 --- a/crates/engine/src/tests/rig3d.rs +++ b/crates/engine/src/tests/rig3d.rs @@ -292,7 +292,7 @@ fn parented_point_light_keeps_its_direction_under_a_rotated_null() { assert!((eye1 - eye0).length() < 1e-6 && (f1 - f0).length() < 1e-6, "{eye0:?} {eye1:?} {f0:?} {f1:?}"); } -/// Keyed Orientation under a Z-only turn is shifted exactly, so the light keeps its direction at +/// Keyed Orientation under a Z-only turn is re-expressed exactly, so the light keeps its direction at /// every time, between the keys too. #[test] fn keyed_orientation_under_a_z_turn_keeps_the_direction_at_every_time() { @@ -310,8 +310,8 @@ fn keyed_orientation_under_a_z_turn_keeps_the_direction_at_every_time() { } } -/// Under a tilted null the keys alone cannot follow (Euler angles are blended between them), so keys are -/// added between them: the light keeps its direction within a small angle at every time. +/// Under a tilted null the re-expressed endpoints preserve the quaternion arc exactly, +/// without adding keys between them. #[test] fn keyed_orientation_under_a_tilted_null_follows_between_the_keys() { { @@ -326,10 +326,9 @@ fn keyed_orientation_under_a_tilted_null_follows_between_the_keys() { s.execute("layer.setParent", json!({"layers": [light], "parent": nul})).unwrap(); for (t, b) in times.into_iter().zip(before) { let a = frame_at(&s, light, t); - // 0.05 degrees is about 9e-4 of a radian on a unit vector. - assert!((a.0 - b.0).length() < 1e-6 && (a.1 - b.1).length() < 2e-3, "at {t:?}: {:?} vs {:?}", a.1, b.1); + assert!((a.0 - b.0).length() < 1e-6 && (a.1 - b.1).length() < 1e-8, "at {t:?}: {:?} vs {:?}", a.1, b.1); } - assert!(layer_in(&s, cid(&s), light).props.prop("transform/orientation").unwrap().keys.len() > 2, "keys were added between the two"); + assert_eq!(layer_in(&s, cid(&s), light).props.prop("transform/orientation").unwrap().keys.len(), 2, "quaternion arcs need no extra keys"); } } @@ -351,10 +350,9 @@ fn one_node_light_under_a_mirrored_null_keeps_its_authored_values() { assert_eq!(v3(&after, "transform/orientation"), v3(&before, "transform/orientation")); } -/// The cap on keys added by baking is for the whole Orientation property, not for each segment: -/// many strongly eased segments under a tilted parent stay within it. +/// Many strongly eased Orientation segments keep their authored key count and easing. #[test] -fn baked_orientation_keys_are_capped_across_the_whole_property() { +fn reexpressed_orientation_preserves_key_count_across_the_whole_property() { let mut s = session(); let light = s.execute("layer.newLight", json!({"kind": "Point", "position": [320, 180, -500]})).unwrap()["layer"].as_u64().unwrap(); let count = 120; @@ -369,8 +367,8 @@ fn baked_orientation_keys_are_capped_across_the_whole_property() { let nul = rotated_null(&mut s, [20.0, -35.0, 60.0], 30.0); s.execute("layer.setParent", json!({"layers": [light], "parent": nul})).unwrap(); let n = layer_in(&s, cid(&s), light).props.prop("transform/orientation").unwrap().keys.len(); - assert!(n <= 4096, "{n} keys: the cap is for the property, not per segment"); - // the segments the cap left unchecked keep their authored easing instead of turning into straight blends + assert_eq!(n, count, "re-expressing quaternion arcs must not add keys"); + // Re-expressed endpoints retain their authored easing. let orientation = layer_in(&s, cid(&s), light); let keys = &orientation.props.prop("transform/orientation").unwrap().keys; let last = keys.iter().rev().nth(1).expect("the penultimate key"); diff --git a/crates/engine/tests/it/parenting_3d_position.rs b/crates/engine/tests/it/parenting_3d_position.rs index 61440e273..de2bc5dad 100644 --- a/crates/engine/tests/it/parenting_3d_position.rs +++ b/crates/engine/tests/it/parenting_3d_position.rs @@ -431,7 +431,7 @@ fn parenting_animated_orientation_and_nonuniform_parent_keep_authored_pose_bound } /// Keyed Orientation under a uniform parent is re-expressed at every key, so the child's world pose -/// and pixels stay put at every time (the parent is Z-only, so the paths between keys stay exact too). +/// and pixels stay put at every time along the quaternion arcs between keys. #[test] fn parenting_uniform_parent_re_expresses_keyed_orientation() { for factor in [120.0, -120.0] { @@ -544,3 +544,49 @@ fn parenting_camera_to_default_null_preserves_framing() { assert_eq!(authored(&s, "transform/position"), pos0, "unparenting restores position"); assert_eq!(authored(&s, "transform/poi"), poi0, "unparenting restores point of interest"); } + +/// A constant parent rotation preserves the full eased quaternion path, including mixed axes. +#[test] +fn parenting_mixed_axis_eased_orientation_preserves_arcs_and_key_metadata() { + use effectcraft_engine::keyframe::{Ease, Interp}; + for factor in [120.0, -120.0] { + let (mut s, p, c) = fixture(true, true); + set(&mut s, p, "transform/scale", json!([factor, factor, factor])); + for (time, value) in [(0.0, json!([-35.0, 48.0, 150.0])), (0.7, json!([62.0, -27.0, -145.0])), (1.6, json!([-12.0, 58.0, 70.0]))] { + command(&mut s, "prop.addKey", json!({"layer":c,"path":"transform/orientation","time":time,"value":value})); + } + let cid = s.active_comp_id().unwrap(); + let orientation = Arc::make_mut(&mut s.project).comp_mut(cid).unwrap().layer_mut(LayerId(c)).unwrap().props.prop_mut("transform/orientation").unwrap(); + for key in &mut orientation.keys { + key.in_interp = Interp::Bezier; + key.out_interp = Interp::Bezier; + key.in_ease = vec![Ease { speed: 17.0, influence: 0.3 }]; + key.out_ease = vec![Ease { speed: 11.0, influence: 0.4 }]; + } + orientation.keys[1].auto_bezier = true; + let original = orientation.keys.clone(); + let times: Vec<_> = (0..=32).map(|i| Tick::from_seconds_f64(i as f64 * 0.05)).collect(); + let before: Vec<_> = times.iter().map(|&t| world(&s, c, t)).collect(); + let old_project = s.project.clone(); + parent(&mut s, c, Some(p), true); + let converted = &s.active_comp().unwrap().layer(LayerId(c)).unwrap().props.prop("transform/orientation").unwrap().keys; + assert_eq!(converted.len(), original.len()); + for (new, old) in converted.iter().zip(&original) { + let mut metadata = new.clone(); + metadata.value = old.value.clone(); + assert_eq!(&metadata, old, "all authored key metadata must survive"); + } + // Rotation matrices represent both q and -q identically, so compare transformed geometry + // rather than Euler representatives or quaternion signs. + for (&t, &matrix) in times.iter().zip(&before) { + assert!(displacement(matrix, world(&s, c, t)) < 1e-8, "pose changed at {t:?}, factor {factor}"); + } + parent(&mut s, c, None, true); + for (&t, &matrix) in times.iter().zip(&before) { + assert!(displacement(matrix, world(&s, c, t)) < 1e-8, "unparent changed pose at {t:?}"); + } + assert!(s.undo()); + assert!(s.undo()); + assert!(Arc::ptr_eq(&old_project, &s.project)); + } +} diff --git a/crates/expr/src/prelude.js b/crates/expr/src/prelude.js index eefacc876..cc0405251 100644 --- a/crates/expr/src/prelude.js +++ b/crates/expr/src/prelude.js @@ -167,12 +167,28 @@ function normalize(a) { return l === 0 ? a.map(function () { return 0; }) : div(a, l); } +// Orientation that points the layer's z axis at `at` with its x axis kept level, in the +// Orientation order (Rx · Ry · Rz) and wrapped to [0, 360), as After Effects returns it. function lookAt(from, at) { var d = normalize(sub(__v(at), __v(from))); var x = d[0], y = d[1], z = d[2] || 0; - var rx = -Math.asin(Math.max(-1, Math.min(1, y))) * 180 / Math.PI; - var ry = Math.atan2(x, z) * 180 / Math.PI; - return [rx, ry, 0]; + var p = Math.asin(Math.max(-1, Math.min(1, -y))); + var w = Math.atan2(x, z); + var cw = Math.cos(w), sw = Math.sin(w), cp = Math.cos(p), sp = Math.sin(p); + // The rotation Ry(w) · Rx(p), written as Orientation angles. + var oy = Math.asin(Math.max(-1, Math.min(1, sw * cp))); + var ox, oz; + if (Math.sqrt(cw * cw + sw * sw * sp * sp) > 1e-9) { + ox = Math.atan2(sp, cw * cp); + oz = Math.atan2(-sw * sp, cw); + } else { + ox = Math.atan2(cw * sp, cp); + oz = 0; + } + return [ox, oy, oz].map(function (r) { + var a = ((r * 180 / Math.PI) % 360 + 360) % 360; + return a >= 360 - 1e-9 || Math.abs(a) < 1e-9 ? 0 : a; + }); } function degreesToRadians(d) { return d * Math.PI / 180; } diff --git a/crates/expr/src/tests.rs b/crates/expr/src/tests.rs index 48f656e52..a7d2489c7 100644 --- a/crates/expr/src/tests.rs +++ b/crates/expr/src/tests.rs @@ -586,6 +586,12 @@ fn angles_and_look_at() { assert_close!(f.num("degreesToRadians(90)", 0.0), std::f64::consts::FRAC_PI_2); let o = f.ev(f.a, "transform/orientation", "lookAt([0, 0, 0], [100, 0, 100])", 0.0).unwrap().as_vec3(); assert!(close(o[1], 45.0) && close(o[0], 0.0), "{o:?}"); + // After Effects 2026 read-backs of lookAt(position, …) on a layer at [960, 540, 0]. + for (at, want) in [([1500.0, 200.0, 300.0], [48.5763, 49.9802, 319.0442]), ([500.0, 900.0, -400.0], [221.9872, 319.4766, 210.3184])] { + let e = format!("lookAt([960, 540, 0], [{}, {}, {}])", at[0], at[1], at[2]); + let o = f.ev(f.a, "transform/orientation", &e, 0.0).unwrap().as_vec3(); + assert!((0..3).all(|i| (o[i] - want[i]).abs() < 1e-3), "{e}: {o:?}"); + } } // ---- interpolation ---------------------------------------------------------------------------- diff --git a/crates/geom/src/lib.rs b/crates/geom/src/lib.rs index 32121ffcb..794761f6c 100644 --- a/crates/geom/src/lib.rs +++ b/crates/geom/src/lib.rs @@ -3,7 +3,8 @@ //! //! Conventions follow After Effects' public documentation: y grows downwards, angles are degrees //! clockwise on screen, 3D uses a left-handed system with +z pointing into the screen, and a 3D -//! layer's rotation is Orientation (X, Y, Z) followed by X Rotation, Y Rotation, Z Rotation. +//! layer's rotation is Orientation then X/Y/Z Rotation, each composed as `Rx · Ry · Rz` (Z turns +//! the vector first; measured in After Effects). #![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)] @@ -321,17 +322,32 @@ impl Mat4 { let (s, c) = deg.to_radians().sin_cos(); Mat4([[c, -s, 0.0, 0.0], [s, c, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]) } - /// Orientation (degrees, X then Y then Z applied to the vector in that order). + /// Orientation (degrees): `Rx(x) · Ry(y) · Rz(z)`, i.e. Z is applied to the vector first, + /// then Y, then X. Measured in After Effects 2026 (Orientation [10,20,30] and X/Y/Z Rotation + /// 10/20/30 on a 3D solid match this order to the anti-aliased edge; the reverse order is + /// 5 % of the frame off). pub fn orientation(o: Vec3) -> Mat4 { - Mat4::rotate_z(o.z) * Mat4::rotate_y(o.y) * Mat4::rotate_x(o.x) + Mat4::rotate_x(o.x) * Mat4::rotate_y(o.y) * Mat4::rotate_z(o.z) } - /// The 3D layer transform: layer space → parent space. + /// X, Y and Z Rotation of a 3D layer (degrees), composed like [`Mat4::orientation`]. + pub fn rotation_xyz(x: f64, y: f64, z: f64) -> Mat4 { + Mat4::rotate_x(x) * Mat4::rotate_y(y) * Mat4::rotate_z(z) + } + /// The Orientation angles (degrees) of this matrix's rotation part: the inverse of + /// [`Mat4::orientation`] (Y in [-90, 90], X and Z in (-180, 180]; Z = 0 at gimbal lock). + pub fn orientation_angles(&self) -> Vec3 { + let m = &self.0; + let sy = m[0][2].clamp(-1.0, 1.0); + let cy = m[0][0].hypot(m[0][1]); + let y = sy.atan2(cy); + let (x, z) = if cy > 1e-9 { ((-m[1][2]).atan2(m[2][2]), (-m[0][1]).atan2(m[0][0])) } else { (m[2][1].atan2(m[1][1]), 0.0) }; + vec3(x.to_degrees(), y.to_degrees(), z.to_degrees()) + } + /// The 3D layer transform: layer space → parent space (Orientation, then X/Y/Z Rotation). pub fn layer_3d(anchor: Vec3, position: Vec3, scale_pct: Vec3, orientation: Vec3, rotation: Vec3) -> Mat4 { Mat4::translate(position) * Mat4::orientation(orientation) - * Mat4::rotate_z(rotation.z) - * Mat4::rotate_y(rotation.y) - * Mat4::rotate_x(rotation.x) + * Mat4::rotation_xyz(rotation.x, rotation.y, rotation.z) * Mat4::scale(scale_pct / 100.0) * Mat4::translate(-anchor) } @@ -448,6 +464,76 @@ pub fn look_at(pos: Vec3, poi: Vec3, extra: Mat4) -> Mat4 { extra * rot * Mat4::translate(-pos) } +/// Unit quaternion `[w, x, y, z]` of [`Mat4::orientation`]`(o)`. +fn orientation_quat(o: Vec3) -> [f64; 4] { + let half = |d: f64| (d.to_radians() * 0.5).sin_cos(); + let (sx, cx) = half(o.x); + let (sy, cy) = half(o.y); + let (sz, cz) = half(o.z); + // qx · qy · qz (Hamilton product), matching Rx · Ry · Rz. + let (w, x, y, z) = (cx * cy, sx * cy, cx * sy, sx * sy); + [w * cz - z * sz, x * cz + y * sz, y * cz - x * sz, z * cz + w * sz] +} + +fn quat_matrix(q: [f64; 4]) -> Mat4 { + let [w, x, y, z] = q; + Mat4([ + [1.0 - 2.0 * (y * y + z * z), 2.0 * (x * y - z * w), 2.0 * (x * z + y * w), 0.0], + [2.0 * (x * y + z * w), 1.0 - 2.0 * (x * x + z * z), 2.0 * (y * z - x * w), 0.0], + [2.0 * (x * z - y * w), 2.0 * (y * z + x * w), 1.0 - 2.0 * (x * x + y * y), 0.0], + [0.0, 0.0, 0.0, 1.0], + ]) +} + +/// Angle (degrees, 0..=180) of the shortest rotation between two Orientations. +pub fn orientation_arc_deg(a: Vec3, b: Vec3) -> f64 { + let (p, q) = (orientation_quat(a), orientation_quat(b)); + let d = (p[0] * q[0] + p[1] * q[1] + p[2] * q[2] + p[3] * q[3]).abs().clamp(0.0, 1.0); + let arc = 2.0 * d.acos().to_degrees(); + if arc.is_finite() { arc } else { 0.0 } +} + +/// Orientation between two Orientations at fraction `t`, as After Effects interpolates keyed +/// Orientation: spherical linear interpolation of the two rotations along the shortest arc, +/// written as angles in [0, 360) (measured in After Effects 2026: keys [0,0,0] → [10,20,30] read +/// back [6.2643, 9.3531, 15.2190] half-way, [0,0,0] → [60,80,40] [30.6186, 35.7617, 28.4317], +/// [0,0,0] → [0,0,270] [0, 0, 315], [0,0,0] → [0,0,720] [0, 0, 0]). +pub fn orientation_slerp(a: Vec3, b: Vec3, t: f64) -> Vec3 { + let blend = a + (b - a) * t; + if !t.is_finite() || !blend.x.is_finite() || !blend.y.is_finite() || !blend.z.is_finite() { + return a; + } + let p = orientation_quat(a); + let mut q = orientation_quat(b); + let mut d = p[0] * q[0] + p[1] * q[1] + p[2] * q[2] + p[3] * q[3]; + if d < 0.0 { + q = q.map(|c| -c); + d = -d; + } + let d = d.clamp(-1.0, 1.0); + let (ka, kb) = if d > 1.0 - 1e-12 { + (1.0 - t, t) + } else { + let om = d.acos(); + let s = om.sin(); + (((1.0 - t) * om).sin() / s, (t * om).sin() / s) + }; + let mut r = [0.0; 4]; + for (i, c) in r.iter_mut().enumerate() { + *c = ka * p[i] + kb * q[i]; + } + let n = r.iter().map(|c| c * c).sum::().sqrt(); + if !(n > 1e-12 && n.is_finite()) { + return a; + } + let e = quat_matrix(r.map(|c| c / n)).orientation_angles(); + let wrap = |v: f64| { + let w = v.rem_euclid(360.0); + if w >= 360.0 - 1e-9 || w.abs() < 1e-9 { 0.0 } else { w } + }; + vec3(wrap(e.x), wrap(e.y), wrap(e.z)) +} + #[cfg(test)] mod tests { use super::*; @@ -512,6 +598,66 @@ mod tests { assert!((i.apply(m.apply(p)) - p).length() < 1e-9); } + fn near3(a: Vec3, b: [f64; 3], tol: f64) -> bool { + (a.x - b[0]).abs() < tol && (a.y - b[1]).abs() < tol && (a.z - b[2]).abs() < tol + } + + #[test] + fn orientation_applies_z_then_y_then_x() { + // Rx · Ry · Rz: the vector is turned about Z first. + let o = Mat4::orientation(vec3(90.0, 0.0, 90.0)); + let p = o.apply_vec(vec3(1.0, 0.0, 0.0)); + // Rz(90): +x → +y; Rx(90): +y → +z. + assert!((p - vec3(0.0, 0.0, 1.0)).length() < 1e-12, "{p:?}"); + let r = Mat4::rotation_xyz(10.0, 20.0, 30.0); + assert_eq!(r, Mat4::orientation(vec3(10.0, 20.0, 30.0))); + } + + #[test] + fn orientation_angles_invert_orientation() { + for o in [[10.0, 20.0, 30.0], [-45.0, 80.0, 170.0], [120.0, -30.0, -90.0], [0.0, 90.0, 0.0], [30.0, -90.0, 0.0]] { + let m = Mat4::orientation(Vec3::from(o)); + let back = Mat4::orientation(m.orientation_angles()); + for r in 0..3 { + for c in 0..3 { + assert!((m.0[r][c] - back.0[r][c]).abs() < 1e-9, "{o:?}"); + } + } + } + } + + #[test] + fn keyed_orientation_slerps_as_after_effects() { + // After Effects 2026 read-backs of linear Orientation keys (cases 703 and 802). + let a = vec3(0.0, 0.0, 0.0); + let b = vec3(10.0, 20.0, 30.0); + assert!(near3(orientation_slerp(a, b, 0.25), [3.4341, 4.4691, 7.7129], 1e-3)); + assert!(near3(orientation_slerp(a, b, 0.5), [6.2643, 9.3531, 15.2190], 1e-3)); + assert!(near3(orientation_slerp(a, b, 0.75), [8.4650, 14.5598, 22.6095], 1e-3)); + let b = vec3(60.0, 80.0, 40.0); + assert!(near3(orientation_slerp(a, b, 0.25), [16.9201, 16.0688, 16.0629], 1e-3)); + assert!(near3(orientation_slerp(a, b, 0.5), [30.6186, 35.7617, 28.4317], 1e-3)); + // The shortest way round, written in [0, 360). + assert!(near3(orientation_slerp(a, vec3(0.0, 0.0, 270.0), 0.5), [0.0, 0.0, 315.0], 1e-9)); + assert!(near3(orientation_slerp(a, vec3(0.0, 0.0, 270.0), 0.25), [0.0, 0.0, 337.5], 1e-9)); + assert!(near3(orientation_slerp(a, vec3(350.0, 0.0, 0.0), 0.5), [355.0, 0.0, 0.0], 1e-9)); + assert!(near3(orientation_slerp(a, vec3(0.0, 0.0, 720.0), 0.5), [0.0, 0.0, 0.0], 1e-9)); + // The ends are the key rotations. + let k = vec3(200.0, 10.0, 5.0); + let end = Mat4::orientation(orientation_slerp(vec3(0.0, 0.0, 350.0), k, 1.0)); + let want = Mat4::orientation(k); + assert!((0..3).all(|r| (0..3).all(|c| (end.0[r][c] - want.0[r][c]).abs() < 1e-9))); + // Equal rotations and hostile input do not blow up. + let whole = Mat4::orientation(orientation_slerp(a, vec3(0.0, 0.0, 360.0), 0.5)).apply_vec(vec3(1.0, 0.0, 0.0)); + assert!((whole - vec3(1.0, 0.0, 0.0)).length() < 1e-9 && orientation_arc_deg(a, vec3(0.0, 0.0, 360.0)) < 1e-6); + let nan = orientation_slerp(vec3(f64::NAN, 0.0, 0.0), b, 0.5); + // A non-finite key comes back as given (the first key), not as a blended rotation. + assert!(nan.x.is_nan() && nan.y == 0.0 && nan.z == 0.0, "{nan:?}"); + assert!(orientation_slerp(a, b, f64::INFINITY).x.is_finite()); + assert!((orientation_arc_deg(a, vec3(0.0, 0.0, 90.0)) - 90.0).abs() < 1e-9); + assert!((orientation_arc_deg(a, vec3(0.0, 0.0, 270.0)) - 90.0).abs() < 1e-9); + } + #[test] fn default_camera_sees_z0_plane_unscaled() { let (w, h) = (1920.0, 1080.0); diff --git a/crates/keyframe/src/lib.rs b/crates/keyframe/src/lib.rs index abf929fe9..0998790a1 100644 --- a/crates/keyframe/src/lib.rs +++ b/crates/keyframe/src/lib.rs @@ -57,6 +57,12 @@ impl Ease { pub const EASY: Ease = Ease { speed: 0.0, influence: 1.0 / 3.0 }; } +/// Influence of a linear key side in a segment whose other side is eased: the side keeps the +/// segment's average speed with a 16.67 % influence, as After Effects shows it in the Keyframe +/// Velocity dialog and evaluates it (time-remap read-backs: a bezier-out (speed 0, 50 %) into a +/// linear-in from 3.5 to 0.5 over 2 s gives 3.290 at a quarter and 2.657 at half of the segment). +pub const LINEAR_SIDE_INFLUENCE: f64 = 1.0 / 6.0; + #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Keyframe { pub time: Tick, @@ -408,7 +414,7 @@ fn effective_ease>(keys: &[K], i: usize, d: usize, spatial: /// The ease a key side presents in the Graph Editor and the Keyframe Velocity dialog: stored /// Bezier eases, auto-Bezier slopes, or the equivalent of a linear side (speed of the straight -/// segment, 33.3 % influence). `None` for hold sides and sides without a neighbour. +/// segment, [`LINEAR_SIDE_INFLUENCE`]). `None` for hold sides and sides without a neighbour. pub fn side_ease(keys: &[Keyframe], i: usize, d: usize, spatial: bool, out: bool) -> Option { let k = keys.get(i)?; let j = if out { i + 1 } else { i.checked_sub(1)? }; @@ -429,7 +435,7 @@ pub fn side_ease(keys: &[Keyframe], i: usize, d: usize, spatial: bool, out: bool let dv = b.get(d).unwrap_or(&0.0) - a.get(d).unwrap_or(&0.0); if out { dv } else { -dv } }; - return Some(Ease { speed: dv / dur, influence: 1.0 / 3.0 }); + return Some(Ease { speed: dv / dur, influence: LINEAR_SIDE_INFLUENCE }); } Some(effective_ease(keys, i, if is_spatial { 0 } else { d }, is_spatial, out)) } @@ -546,6 +552,63 @@ fn evaluate_active>(keys: &[K], t: Tick, spatial: bool) -> O Some(segment_value_of(keys, i, t, spatial)) } +/// Evaluate keyed 3D Orientation at `t` as After Effects does: the temporal ease gives the +/// progress through each segment, and the rotation moves along the shortest arc between the two +/// keys ([`effectcraft_geom::orientation_slerp`]) instead of blending each angle. Speeds are +/// degrees per second along that arc. Values other than 3D vectors evaluate as [`evaluate`]. +pub fn evaluate_orientation(keys: &[Keyframe], t: Tick) -> Option { + let first = keys.first()?; + if keys.len() == 1 || t <= first.time { + return Some(first.value.clone()); + } + let last = keys.last()?; + if t >= last.time { + return Some(last.value.clone()); + } + let i = keys.partition_point(|k| k.time <= t).checked_sub(1)?; + let (a, b) = (keys.get(i)?, keys.get(i + 1)?); + let (Value::Vec3(va), Value::Vec3(vb)) = (&a.value, &b.value) else { return Some(segment_value(keys, i, t, false)) }; + if a.out_interp == Interp::Hold { + return Some(a.value.clone()); + } + let (t0, t1) = (secs(a.time), secs(b.time)); + let dur = (t1 - t0).max(1e-12); + let x = ((secs(t) - t0) / dur).clamp(0.0, 1.0); + // On a key: its own value, as stored. + if x <= 0.0 { + return Some(a.value.clone()); + } + let arc = effectcraft_geom::orientation_arc_deg((*va).into(), (*vb).into()); + let lin_out = a.out_interp == Interp::Linear; + let lin_in = b.in_interp != Interp::Bezier; + let f = if lin_out && lin_in || arc <= 1e-9 { + x + } else { + // Auto-Bezier keys take the arc speed between their neighbours. + let side = |j: usize, out: bool| -> Ease { + // A linear side keeps the segment's average speed at the same influence as in + // `segment_value` (and a missing key, unreachable here, is treated as one). + let Some(k) = keys.get(j) else { return Ease { speed: arc / dur, influence: LINEAR_SIDE_INFLUENCE } }; + let linear = if out { lin_out } else { lin_in }; + if linear { + return Ease { speed: arc / dur, influence: LINEAR_SIDE_INFLUENCE }; + } + if k.auto_bezier && j > 0 && j + 1 < keys.len() { + let span = (secs(keys[j + 1].time) - secs(keys[j - 1].time)).max(1e-12); + let (Value::Vec3(p), Value::Vec3(n)) = (&keys[j - 1].value, &keys[j + 1].value) else { return Ease { speed: arc / dur, influence: 1.0 / 6.0 } }; + return Ease { speed: effectcraft_geom::orientation_arc_deg((*p).into(), (*n).into()) / span, influence: 1.0 / 6.0 }; + } + let list = if out { &k.out_ease } else { &k.in_ease }; + list.first().copied().unwrap_or_default() + }; + let (eo, ei) = (side(i, true), side(i + 1, false)); + ease_progress(eo.speed * dur / arc, eo.influence, ei.speed * dur / arc, ei.influence, x) + }; + let f = if f.is_finite() { f } else { x }; + let o = effectcraft_geom::orientation_slerp((*va).into(), (*vb).into(), f); + Some(Value::Vec3([o.x, o.y, o.z])) +} + /// Value inside segment `i` → `i+1` at time `t`. pub fn segment_value(keys: &[Keyframe], i: usize, t: Tick, spatial: bool) -> Value { segment_value_of(keys, i, t, spatial) @@ -576,8 +639,8 @@ fn segment_value_of>(keys: &[K], i: usize, t: Tick, spatial: let f = if lin_out && lin_in || len <= 1e-12 { x } else { - let eo = if lin_out { Ease { speed: len / dur, influence: 1.0 / 3.0 } } else { effective_ease(keys, i, 0, true, true) }; - let ei = if lin_in { Ease { speed: len / dur, influence: 1.0 / 3.0 } } else { effective_ease(keys, i + 1, 0, true, false) }; + let eo = if lin_out { Ease { speed: len / dur, influence: LINEAR_SIDE_INFLUENCE } } else { effective_ease(keys, i, 0, true, true) }; + let ei = if lin_in { Ease { speed: len / dur, influence: LINEAR_SIDE_INFLUENCE } } else { effective_ease(keys, i + 1, 0, true, false) }; ease_progress(eo.speed * dur / len, eo.influence, ei.speed * dur / len, ei.influence, x) }; // A straight path (both handles on the chord, as auto-Bezier keys on a line have) is the @@ -596,16 +659,16 @@ fn segment_value_of>(keys: &[K], i: usize, t: Tick, spatial: let cb = b.value.components(); if ca.is_empty() || ca.len() != cb.len() { // Paths, gradients: ease on dimension 0 as overall progress. - let eo = if lin_out { Ease { speed: 1.0 / dur, influence: 1.0 / 3.0 } } else { effective_ease(keys, i, 0, false, true) }; - let ei = if lin_in { Ease { speed: 1.0 / dur, influence: 1.0 / 3.0 } } else { effective_ease(keys, i + 1, 0, false, false) }; + let eo = if lin_out { Ease { speed: 1.0 / dur, influence: LINEAR_SIDE_INFLUENCE } } else { effective_ease(keys, i, 0, false, true) }; + let ei = if lin_in { Ease { speed: 1.0 / dur, influence: LINEAR_SIDE_INFLUENCE } } else { effective_ease(keys, i + 1, 0, false, false) }; let f = ease_progress(eo.speed * dur, eo.influence, ei.speed * dur, ei.influence, x); return a.value.lerp(&b.value, f); } let mut out = Vec::with_capacity(ca.len()); for d in 0..ca.len() { let dv = cb[d] - ca[d]; - let eo = if lin_out { Ease { speed: dv / dur, influence: 1.0 / 3.0 } } else { effective_ease(keys, i, d, false, true) }; - let ei = if lin_in { Ease { speed: dv / dur, influence: 1.0 / 3.0 } } else { effective_ease(keys, i + 1, d, false, false) }; + let eo = if lin_out { Ease { speed: dv / dur, influence: LINEAR_SIDE_INFLUENCE } } else { effective_ease(keys, i, d, false, true) }; + let ei = if lin_in { Ease { speed: dv / dur, influence: LINEAR_SIDE_INFLUENCE } } else { effective_ease(keys, i + 1, d, false, false) }; // Bezier in (time, value) space directly: P1 = (i0, v0 + s0*i0*dur), P2 = (1-i1, v1 - s1*i1*dur). let (i0, i1) = (eo.influence.clamp(0.0, 1.0), ei.influence.clamp(0.0, 1.0)); let u = solve_u(0.0, i0, 1.0 - i1, 1.0, x); diff --git a/crates/keyframe/src/tests.rs b/crates/keyframe/src/tests.rs index 312703239..88f9f3249 100644 --- a/crates/keyframe/src/tests.rs +++ b/crates/keyframe/src/tests.rs @@ -92,6 +92,41 @@ fn maximum_influence_resolves_flat_midpoint_time_curve() { } } +/// Keyed Orientation moves along the shortest arc, eased in time, as After Effects 2026 reads +/// it back (cases 802 and 803: keys [0,0,0] at 0 s and [60,80,40] at 2 s). +#[test] +fn keyed_orientation_matches_after_effects() { + let close = |v: Value, e: [f64; 3]| { + let v = v.as_vec3(); + assert!((0..3).all(|i| (v[i] - e[i]).abs() < 2e-3), "{v:?} vs {e:?}"); + }; + let lin = vec![Keyframe::new(s(0.0), Value::Vec3([0.0; 3])), Keyframe::new(s(2.0), Value::Vec3([60.0, 80.0, 40.0]))]; + close(evaluate_orientation(&lin, s(0.5)).unwrap(), [16.9201, 16.0688, 16.0629]); + close(evaluate_orientation(&lin, s(1.0)).unwrap(), [30.6186, 35.7617, 28.4317]); + close(evaluate_orientation(&lin, s(2.0)).unwrap(), [60.0, 80.0, 40.0]); + // A middle key reads back as stored (not as another angle triple of the same rotation). + let three = + vec![Keyframe::new(s(0.0), Value::Vec3([0.0; 3])), Keyframe::new(s(1.0), Value::Vec3([0.0, 120.0, 0.0])), Keyframe::new(s(2.0), Value::Vec3([0.0; 3]))]; + assert_eq!(evaluate_orientation(&three, s(1.0)), Some(Value::Vec3([0.0, 120.0, 0.0]))); + // Easy ease (AE's preset: speed 0, influence 33 %) on both keys. + let ease = |k: Keyframe| { + let mut k = k.eased(); + k.in_ease = vec![Ease { speed: 0.0, influence: 0.33 }]; + k.out_ease = vec![Ease { speed: 0.0, influence: 0.33 }]; + k + }; + let eased: Vec = lin.into_iter().map(ease).collect(); + close(evaluate_orientation(&eased, s(0.5)).unwrap(), [11.0974, 9.5750, 10.5916]); + close(evaluate_orientation(&eased, s(1.0)).unwrap(), [30.6186, 35.7617, 28.4317]); + close(evaluate_orientation(&eased, s(1.5)).unwrap(), [47.6915, 65.7590, 40.3338]); + // Hold keys and other value types. + let held = vec![Keyframe::new(s(0.0), Value::Vec3([1.0, 2.0, 3.0])).hold(), Keyframe::new(s(1.0), Value::Vec3([0.0; 3]))]; + close(evaluate_orientation(&held, s(0.5)).unwrap(), [1.0, 2.0, 3.0]); + let scalar = vec![Keyframe::new(s(0.0), Value::Scalar(0.0)), Keyframe::new(s(1.0), Value::Scalar(10.0))]; + assert_eq!(evaluate_orientation(&scalar, s(0.5)), Some(Value::Scalar(5.0))); + assert_eq!(evaluate_orientation(&[], s(0.5)), None); +} + /// M13.15: agents set gradients as plain JSON, not only the tagged form `get` returns. #[test] fn gradients_coerce_from_plain_json() { @@ -189,6 +224,61 @@ fn bezier_with_linear_speed_matches_linear() { } } +/// A linear side next to an eased one keeps the segment's average speed at 16.67 % +/// influence. After Effects time-remap read-backs (a square at x = 50 + 455 * remap): out of +/// a key at 2 s (3.5, speed 0, influence 50 %) into a linear key at 4 s (0.5) the remap is +/// 3.290 at 2.5 s and 2.657 at 3 s (33.3 % gave 3.308 and 2.629). +#[test] +fn a_linear_side_next_to_an_eased_side_matches_after_effects() { + let mut a = Keyframe::new(s(2.0), Value::Scalar(3.5)); + a.out_interp = Interp::Bezier; + a.out_ease = vec![Ease { speed: 0.0, influence: 0.5 }]; + let keys = vec![a, Keyframe::new(s(4.0), Value::Scalar(0.5))]; + for (t, ae) in [(2.5, 3.290), (3.0, 2.657)] { + let v = evaluate(&keys, s(t), false).unwrap().as_f64(); + // AE's square edge is read to the pixel: 1 px = 1 / 455 of remap. + assert!((v - ae).abs() < 2.0 / 455.0, "{t}: {v} vs {ae}"); + } + // The mirror case: a linear out into an eased in. + let mut b = Keyframe::new(s(4.0), Value::Scalar(0.5)); + b.in_interp = Interp::Bezier; + b.in_ease = vec![Ease { speed: 0.0, influence: 0.5 }]; + let mirror = vec![Keyframe::new(s(2.0), Value::Scalar(3.5)), b]; + let v = evaluate(&mirror, s(3.5), false).unwrap().as_f64(); + assert!((v - (4.0 - 3.290)).abs() < 2.0 / 455.0, "{v}"); + assert_eq!(side_ease(&keys, 1, 0, false, false).map(|e| e.influence), Some(LINEAR_SIDE_INFLUENCE)); +} + +/// Keyed Orientation shapes a linear side next to an eased one as a scalar property does +/// (`LINEAR_SIDE_INFLUENCE`): about one axis the shortest arc is the angle itself, so the +/// orientation follows the same curve as a scalar with the same keys (CodeRabbit on #1876). +#[test] +fn orientation_linear_side_next_to_an_eased_side_matches_a_scalar() { + let ease = vec![Ease { speed: 0.0, influence: 0.5 }]; + let (mut a, mut sa) = (Keyframe::new(s(2.0), Value::Vec3([0.0, 0.0, 0.0])), Keyframe::new(s(2.0), Value::Scalar(0.0))); + for k in [&mut a, &mut sa] { + k.out_interp = Interp::Bezier; + k.out_ease = ease.clone(); + } + let orient = vec![a, Keyframe::new(s(4.0), Value::Vec3([0.0, 0.0, 90.0]))]; + let scalar = vec![sa, Keyframe::new(s(4.0), Value::Scalar(90.0))]; + // The mirror: a linear out into an eased in. + let (mut b, mut sb) = (Keyframe::new(s(4.0), Value::Vec3([0.0, 0.0, 90.0])), Keyframe::new(s(4.0), Value::Scalar(90.0))); + for k in [&mut b, &mut sb] { + k.in_interp = Interp::Bezier; + k.in_ease = ease.clone(); + } + let orient_m = vec![Keyframe::new(s(2.0), Value::Vec3([0.0, 0.0, 0.0])), b]; + let scalar_m = vec![Keyframe::new(s(2.0), Value::Scalar(0.0)), sb]; + for (o, sc) in [(&orient, &scalar), (&orient_m, &scalar_m)] { + for t in [2.25, 2.5, 3.0, 3.5, 3.75] { + let Some(Value::Vec3(v)) = evaluate_orientation(o, s(t)) else { panic!("orientation at {t}") }; + let want = evaluate(sc, s(t), false).unwrap().as_f64(); + assert!((v[2] - want).abs() < 1e-6 && v[0].abs() < 1e-9 && v[1].abs() < 1e-9, "{t}: {v:?} vs {want}"); + } + } +} + #[test] fn spatial_linear_constant_speed() { let keys = vec![Keyframe::new(s(0.0), Value::Vec2([0.0, 0.0])), Keyframe::new(s(1.0), Value::Vec2([300.0, 400.0]))]; diff --git a/crates/lottie/src/anim.rs b/crates/lottie/src/anim.rs index 4925460a9..5b6dabf50 100644 --- a/crates/lottie/src/anim.rs +++ b/crates/lottie/src/anim.rs @@ -150,11 +150,15 @@ fn segment_ease(keys: &[Keyframe], i: usize, spatial: bool) -> (Vec, Vec EvalCtx<'a> { // Auto-orient (along path / towards camera) replaces Orientation. let orient = crate::three_d::camera::auto_orient_3d(self, layer, p) .unwrap_or_else(|| Mat4::orientation(Vec3::from(self.v3(layer, tr, "orientation", [0.0; 3])))); - Mat4::translate(p) - * orient - * Mat4::rotate_z(rz) - * Mat4::rotate_y(ry) - * Mat4::rotate_x(rx) - * Mat4::scale(Vec3::from(scale) / 100.0) - * Mat4::translate(-Vec3::from(anchor)) + Mat4::translate(p) * orient * Mat4::rotation_xyz(rx, ry, rz) * Mat4::scale(Vec3::from(scale) / 100.0) * Mat4::translate(-Vec3::from(anchor)) } /// Layer space → comp (world) space, including parents. diff --git a/crates/render/src/three_d/camera.rs b/crates/render/src/three_d/camera.rs index a927e2ceb..6aee50a78 100644 --- a/crates/render/src/three_d/camera.rs +++ b/crates/render/src/three_d/camera.rs @@ -117,12 +117,15 @@ pub fn basis_view(eye: Vec3, forward: Vec3, down_hint: Vec3) -> Mat4 { Mat4([[r.x, r.y, r.z, 0.0], [d.x, d.y, d.z, 0.0], [f.x, f.y, f.z, 0.0], [0.0, 0.0, 0.0, 1.0]]) * Mat4::translate(-eye) } -/// Orientation angles (degrees, AE order X→Y→Z with Z = 0) that point +z along `dir`. +/// Orientation angles (degrees, [`Mat4::orientation`]'s order) that point +z along `dir` with +/// the layer's x axis kept level (no roll): the pitch about x, then the turn about the world's +/// vertical axis, written as Orientation. pub fn orientation_for(dir: Vec3) -> [f64; 3] { let d = dir.normalize(); - let x = (-d.y).clamp(-1.0, 1.0).asin().to_degrees(); - let y = d.x.atan2(d.z).to_degrees(); - [norm360(x), norm360(y), 0.0] + let pitch = (-d.y).clamp(-1.0, 1.0).asin().to_degrees(); + let yaw = d.x.atan2(d.z).to_degrees(); + let o = (Mat4::rotate_y(yaw) * Mat4::rotate_x(pitch)).orientation_angles(); + [norm360(o.x), norm360(o.y), norm360(o.z)] } fn norm360(a: f64) -> f64 { @@ -177,7 +180,7 @@ pub fn layer_rotation(ctx: &EvalCtx, layer: &Layer) -> Mat4 { let rx = ctx.f(layer, tr, "rotationX", 0.0); let ry = ctx.f(layer, tr, "rotationY", 0.0); let rz = ctx.f(layer, tr, "rotation", 0.0); - Mat4::orientation(Vec3::from(o)) * Mat4::rotate_z(rz) * Mat4::rotate_y(ry) * Mat4::rotate_x(rx) + Mat4::orientation(Vec3::from(o)) * Mat4::rotation_xyz(rx, ry, rz) } /// World matrix of a layer's parent chain (identity when unparented). diff --git a/crates/render/src/three_d/tests_orient.rs b/crates/render/src/three_d/tests_orient.rs index f9c72e296..bbecc7fc0 100644 --- a/crates/render/src/three_d/tests_orient.rs +++ b/crates/render/src/three_d/tests_orient.rs @@ -215,3 +215,264 @@ fn layer_cache_is_independent_of_camera_lights_and_view() { assert_ne!(third, second); assert!(cache.stats().hits > 0, "the cache was actually used"); } + +/// A 1920 × 1080 comp with a full-frame 3D solid whose transform `set` changes (and an optional +/// one-node camera at the default camera's place), as the After Effects reference cases. +fn ae_frame(set: impl Fn(&mut Layer), camera: Option<([f64; 3], [f64; 3])>) -> (Project, ItemId) { + let mut p = Project::default(); + let comp = Comp::new(1920, 1080, FrameRate::FPS_25, Tick::from_seconds_f64(5.0)); + let cid = p.add_item("C", Label::Sandstone, None, ItemKind::Comp(comp.clone().into())); + let sid = p.add_item("L", Label::Red, None, ItemKind::Solid(Solid { color: [1.0, 0.0, 0.0], width: 1920, height: 1080, pixel_aspect: 1.0 })); + let mut l = build::layer(&mut p, &comp, "L", LayerSource::Solid { item: sid }, (1920, 1080), None); + l.switches.three_d = true; + set(&mut l); + let mut layers = vec![]; + if let Some((orientation, rotation)) = camera { + let mut cam = build::layer(&mut p, &comp, "K", LayerSource::Camera, (1920, 1080), None); + cam.auto_orient = AutoOrient::Off; + cam.props.prop_mut("transform/position").unwrap().value = Value::Vec3([960.0, 540.0, -1920.0 * 50.0 / 36.0]); + cam.props.prop_mut("transform/orientation").unwrap().value = Value::Vec3(orientation); + for (m, v) in [("transform/rotationX", rotation[0]), ("transform/rotationY", rotation[1]), ("transform/rotation", rotation[2])] { + cam.props.prop_mut(m).unwrap().value = Value::Scalar(v); + } + cam.props.prop_mut("cameraOptions/zoom").unwrap().value = Value::Scalar(1920.0 * 50.0 / 36.0); + layers.push(cam); + } + layers.push(l); + p.comp_mut(cid).unwrap().layers = layers.into(); + (p, cid) +} + +/// Whether comp pixel (x, y) shows the solid, from its layer → comp mapping. +fn covers(p: &Project, cid: ItemId, secs: f64, x: u32, y: u32) -> bool { + let c = p.comp(cid).unwrap(); + let ctx = EvalCtx::new(p, cid, c, Tick::from_seconds_f64(secs)); + let l = c.layers.last().unwrap(); + let inv = ctx.layer_to_comp(l).0.inverse().unwrap(); + let u = inv.apply(effectcraft_geom::vec2(x as f64 + 0.5, y as f64 + 0.5)); + (0.0..=1920.0).contains(&u.x) && (0.0..=1080.0).contains(&u.y) +} + +fn check_points(p: &Project, cid: ItemId, secs: f64, case: &str, pts: &[(u32, u32, bool)]) { + for &(x, y, red) in pts { + assert_eq!(covers(p, cid, secs, x, y), red, "case {case}: pixel ({x}, {y}) should be {}", if red { "red" } else { "black" }); + } +} + +fn set3(l: &mut Layer, m: &str, v: [f64; 3]) { + l.props.prop_mut(m).unwrap().value = Value::Vec3(v); +} + +fn set1(l: &mut Layer, m: &str, v: f64) { + l.props.prop_mut(m).unwrap().value = Value::Scalar(v); +} + +/// Orientation and X/Y/Z Rotation compose as `Rx · Ry · Rz` (Z turns the layer first), and +/// Orientation comes before the axis rotations, in layers and cameras alike. The points are +/// sampled from After Effects 2026 renders of the synthetic cases (each at least 3 px from an +/// edge; red = the solid covers the pixel), a third of them where the old Z · Y · X order differed. +#[test] +fn rotation_order_matches_after_effects() { + // 488: Orientation [10, 20, 30]. + let (p, cid) = ae_frame(|l| set3(l, "transform/orientation", [10.0, 20.0, 30.0]), None); + check_points( + &p, + cid, + 1.0, + "488", + &[ + (328, 687, false), + (416, 764, false), + (209, 237, true), + (548, 861, false), + (1899, 425, false), + (87, 462, true), + (162, 581, false), + (662, 948, false), + (682, 849, true), + (618, 413, true), + (1380, 181, true), + (605, 378, true), + (1830, 518, true), + (559, 197, true), + (1760, 843, true), + (550, 823, true), + (572, 952, false), + (272, 963, false), + (268, 761, false), + (628, 1073, false), + (218, 721, false), + (256, 807, false), + (225, 881, false), + (167, 637, false), + ], + ); + // 800: X / Y / Z Rotation 10 / 20 / 30. + let (p, cid) = ae_frame( + |l| { + set1(l, "transform/rotationX", 10.0); + set1(l, "transform/rotationY", 20.0); + set1(l, "transform/rotation", 30.0); + }, + None, + ); + check_points( + &p, + cid, + 1.0, + "800", + &[ + (104, 450, true), + (755, 1002, false), + (1407, 149, false), + (271, 66, true), + (288, 54, true), + (113, 393, true), + (204, 174, true), + (1790, 360, false), + (1414, 324, true), + (682, 343, true), + (1147, 153, true), + (345, 446, true), + (1516, 542, true), + (666, 25, true), + (1327, 1065, true), + (778, 267, true), + (1588, 5, false), + (1706, 147, false), + (357, 978, false), + (97, 689, false), + (1483, 79, false), + (433, 848, false), + (255, 802, false), + (636, 1057, false), + ], + ); + // 801: Orientation [0, 30, 0] with X Rotation 40 (Orientation first). + let (p, cid) = ae_frame( + |l| { + set3(l, "transform/orientation", [0.0, 30.0, 0.0]); + set1(l, "transform/rotationX", 40.0); + }, + None, + ); + check_points( + &p, + cid, + 1.0, + "801", + &[ + (1356, 35, true), + (1762, 19, true), + (190, 227, true), + (108, 182, true), + (502, 832, true), + (1539, 203, true), + (722, 812, true), + (1872, 76, true), + (1166, 165, true), + (1640, 380, true), + (629, 619, true), + (1796, 574, true), + (1767, 311, true), + (1432, 421, true), + (1819, 425, true), + (283, 252, true), + (563, 1062, false), + (428, 963, false), + (77, 417, false), + (47, 833, false), + (995, 933, false), + (159, 839, false), + (827, 947, false), + (564, 908, false), + ], + ); + // 804: a one-node camera with Orientation [4, 6, 30]; 805: the same as X / Y / Z Rotation. + for (case, cam) in [("804", ([4.0, 6.0, 30.0], [0.0; 3])), ("805", ([0.0; 3], [4.0, 6.0, 30.0]))] { + let (p, cid) = ae_frame(|_| {}, Some(cam)); + check_points( + &p, + cid, + 1.0, + case, + &[ + (204, 410, false), + (1077, 38, false), + (60, 492, false), + (1732, 752, true), + (265, 475, false), + (1743, 821, true), + (1417, 1043, true), + (1559, 944, true), + (1280, 310, true), + (702, 984, true), + (1072, 893, true), + (370, 1042, true), + (1353, 570, true), + (1178, 136, true), + (1201, 289, true), + (1241, 605, true), + (75, 337, false), + (71, 138, false), + (352, 24, false), + (1764, 109, false), + (186, 338, false), + (1835, 668, false), + (211, 269, false), + (157, 143, false), + ], + ); + } +} + +/// Keyed Orientation turns along the shortest arc between the keys (case 802: [0, 0, 0] at 0 s +/// to [60, 80, 40] at 2 s, linear; points from the After Effects render at 1 s, a third of them +/// where blending each angle on its own differed). +#[test] +fn keyed_orientation_renders_as_after_effects() { + let (p, cid) = ae_frame( + |l| { + l.props.prop_mut("transform/orientation").unwrap().keys = + vec![Keyframe::new(Tick::ZERO, Value::Vec3([0.0; 3])), Keyframe::new(Tick::from_seconds_f64(2.0), Value::Vec3([60.0, 80.0, 40.0]))]; + }, + None, + ); + check_points( + &p, + cid, + 1.0, + "802", + &[ + (1880, 472, false), + (1598, 191, false), + (248, 285, true), + (1157, 51, false), + (1628, 129, false), + (357, 37, true), + (1865, 891, true), + (1915, 946, true), + (1728, 1021, true), + (1178, 665, true), + (1303, 631, true), + (1339, 954, true), + (910, 891, true), + (1257, 1002, true), + (1349, 890, true), + (1388, 551, true), + (356, 500, false), + (490, 1058, false), + (524, 829, false), + (73, 29, false), + (393, 769, false), + (1867, 124, false), + (42, 733, false), + (648, 1007, false), + ], + ); + // The value After Effects reads back half-way. + let c = p.comp(cid).unwrap(); + let v = c.layers[0].props.prop("transform/orientation").unwrap().value_at(Tick::from_seconds_f64(1.0)).as_vec3(); + let want = [30.6186, 35.7617, 28.4317]; + assert!((0..3).all(|i| (v[i] - want[i]).abs() < 1e-3), "{v:?}"); +} diff --git a/crates/script/src/tests/ease_presets.rs b/crates/script/src/tests/ease_presets.rs index f075250b2..3d1f95f31 100644 --- a/crates/script/src/tests/ease_presets.rs +++ b/crates/script/src/tests/ease_presets.rs @@ -90,7 +90,7 @@ fn per_key_methods_keep_the_key_selection_and_report_eases_as_they_play() { let r = ok( &mut s, r#"var comp = app.project.activeItem, p = comp.layer(1).transform.opacity; - // A linear side reports the speed it plays at (33.3 % influence). + // A linear side reports the speed it plays at (16.67 % influence, as After Effects). var lin = p.keyInTemporalEase(3)[0]; p.setTemporalEaseAtKey(2, [new KeyframeEase(0, 50)], [new KeyframeEase(0, 75)]); p.setInterpolationTypeAtKey(3, KeyframeInterpolationType.HOLD, KeyframeInterpolationType.HOLD); @@ -98,7 +98,7 @@ fn per_key_methods_keep_the_key_selection_and_report_eases_as_they_play() { var sel = comp.selectedProperties; [lin.speed, lin.influence, p.selectedKeys, sel.length, sel.length ? sel[0].name : ""]"#, ); - assert!(close(r[0].as_f64().unwrap(), -100.0, 1e-9) && close(r[1].as_f64().unwrap(), 100.0 / 3.0, 1e-9), "{r}"); + assert!(close(r[0].as_f64().unwrap(), -100.0, 1e-9) && close(r[1].as_f64().unwrap(), 100.0 / 6.0, 1e-9), "{r}"); assert_eq!(r[2], json!([1, 3]), "the selection is the user's"); assert_eq!((r[3].clone(), r[4].clone()), (json!(1), json!("Opacity"))); assert_eq!(s.state.selected_keys, before); diff --git a/crates/track/src/camtrack/linalg.rs b/crates/track/src/camtrack/linalg.rs index 71e88e109..0e5ff8982 100644 --- a/crates/track/src/camtrack/linalg.rs +++ b/crates/track/src/camtrack/linalg.rs @@ -503,16 +503,16 @@ pub fn umeyama(src: &[V3], dst: &[V3]) -> Option { Some(Similarity { s, r, t }) } -/// Euler angles (degrees) `[x, y, z]` with `m = Rz(z) Ry(y) Rx(x)` (After Effects' Orientation -/// order: X, then Y, then Z applied to the vector). +/// Euler angles (degrees) `[x, y, z]` with `m = Rx(x) Ry(y) Rz(z)`: After Effects' Orientation +/// order (Z is applied to the vector first, then Y, then X; see `effectcraft_geom::Mat4::orientation`). pub fn euler_xyz(m: &M3) -> V3 { - let sy = (-m[2][0]).clamp(-1.0, 1.0); + let sy = m[0][2].clamp(-1.0, 1.0); let y = sy.asin(); - let (x, z) = if sy.abs() < 0.999_999 { (m[2][1].atan2(m[2][2]), m[1][0].atan2(m[0][0])) } else { ((-m[1][2]).atan2(m[1][1]), 0.0) }; + let (x, z) = if sy.abs() < 0.999_999 { ((-m[1][2]).atan2(m[2][2]), (-m[0][1]).atan2(m[0][0])) } else { (m[2][1].atan2(m[1][1]), 0.0) }; [x.to_degrees(), y.to_degrees(), z.to_degrees()] } -/// `Rz(z) Ry(y) Rx(x)` from degrees. +/// `Rx(x) Ry(y) Rz(z)` from degrees. pub fn from_euler_xyz(e: V3) -> M3 { let (sx, cx) = e[0].to_radians().sin_cos(); let (sy, cy) = e[1].to_radians().sin_cos(); @@ -520,7 +520,7 @@ pub fn from_euler_xyz(e: V3) -> M3 { let rx = [[1.0, 0.0, 0.0], [0.0, cx, -sx], [0.0, sx, cx]]; let ry = [[cy, 0.0, sy], [0.0, 1.0, 0.0], [-sy, 0.0, cy]]; let rz = [[cz, -sz, 0.0], [sz, cz, 0.0], [0.0, 0.0, 1.0]]; - mm(&rz, &mm(&ry, &rx)) + mm(&rx, &mm(&ry, &rz)) } #[cfg(test)] diff --git a/docs/effects-parity.md b/docs/effects-parity.md index da4ae78db..c7f850834 100644 --- a/docs/effects-parity.md +++ b/docs/effects-parity.md @@ -44,7 +44,7 @@ corpus compares renders, each effect is assumed to differ somewhere, and users k | Simulation | 18 | 18 | Particle Playground lacks Particle Exploder, text particles, ephemeral mapper; CC Particle World camera fixed (#397) | | Stylize | 25 | 25 | Glow's halo (coverage of a dim layer's edge) and blur width match After Effects 2026 renders; glows above the threshold match too (each channel 8 × (value − threshold + 0.061), measured at three thresholds and two radii); Composite Original's labels are swapped against After Effects (EffectCraft's On Top adds the glow over the original, which After Effects calls Behind); Motion Tile output size (#369) | | Text | 2 | 2 | — | -| Time | 8 | 8 | #535 (Pixel Motion Blur, Vector Detail) is closed | +| Time | 8 | 8 | Timewarp retimes the layer's source and masks without the effects above it, as After Effects 2026; #535 (Pixel Motion Blur, Vector Detail) is closed | | Transition | 17 | 17 | Venetian Blinds matches After Effects 2026 renders (band phase from the layer centre, Gaussian feather on both edges) except within ~6 px of the layer edge (up to 48/255); Radial Wipe's Feather matches After Effects 2026 (a Gaussian of σ = 0.4 × Feather pixels on both edges of the wedge) | | Utility | 9 | 7 | — | @@ -71,6 +71,7 @@ the GPU is performance, not parity. | 2026-10-19 | minor | Radial Wipe: Feather is in pixels on both edges of the wiped wedge (was degrees on the moving edge only), measured against After Effects 2026 (CPU and GPU) | | 2026-10-19 | minor | Fractal / Turbulent Noise: lattice cell = Scale × 2/3 px (Block noise every 66.7 px at Scale 100, as After Effects 2026), CPU and GPU | | 2026-10-19 | minor | Transform: After Effects' skew order and output beyond the layer bounds, measured against After Effects 2026 renders of three cases (CPU and GPU) | +| 2026-10-19 | minor | Timewarp ignores the effects above it (source and masks only), measured against After Effects 2026 | | 2026-10-19 | minor | Tritone uses Rec. 601 luminance, measured against After Effects 2026 renders of a red solid and a grey ramp (CPU and GPU) | | 2026-10-19 | minor | Black & White's Tint keeps the gray's luminosity (Color blend), measured against After Effects 2026 renders (CPU and GPU) | | 2026-10-19 | minor | Levels: "Off for 32 bpc Color" no longer clips in 32 bpc projects, unclipped values extrapolate below Output Black; Levels (Individual Controls) applies the channel controls before the RGB ones, measured against After Effects 2026 (CPU and GPU) | diff --git a/docs/fidelity/README.md b/docs/fidelity/README.md index 0398118c5..f9ecdd99f 100644 --- a/docs/fidelity/README.md +++ b/docs/fidelity/README.md @@ -71,6 +71,18 @@ After the fix, all ten tangents equal AE's to the printed 0.001 px, and the two test `spatial_auto_bezier_tangents_follow_after_effects` checks the rule on other original keys, including a timing change. AE's output stays local; only the script and these scores are tracked. +## Linear side next to an eased side + +Measured on 19 October 2026 with After Effects 2026 (26.2) through a time-remapped precomposition +(a square moving at 455 px per second of source time, read off rendered frames to the pixel): a +segment from a Bezier out side (speed 0, influence 50 %) at 2 s, value 3.5, into a linear key at +4 s, value 0.5, plays 3.290 at 2.5 s and 2.657 at 3 s. EffectCraft gave the linear side the +segment's average speed at 33.3 % influence (3.308 and 2.629, 8 and 13 px off); AE uses the average +speed at 16.67 %, the influence its Keyframe Velocity dialog shows for linear keys. Now the same +square positions to the pixel. `LINEAR_SIDE_INFLUENCE` holds the value for evaluation, the Graph +Editor / velocity dialog sides and the Lottie export; segments that are linear on both sides stay +straight. Regression test: `a_linear_side_next_to_an_eased_side_matches_after_effects`. + ## Justify All with the every-line composer Measured on 19 October 2026 with After Effects 2026 (26.2) on box text (EXPORTER read-back t6): From 23c1f33c88a199469b387ba151e3bc4b3c4de86c Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Sat, 7 Nov 2026 00:24:10 +0100 Subject: [PATCH 20/40] Echo: Blend, Composite In Back and In Front match After Effects (#3132) * Echo: swap Composite In Back and Composite In Front (#3124) After Effects 2026 renders of the importer sample (opaque test card with a moving square, one echo at -1/30 s) show Composite In Front keeping the layer on top (the output equals the current frame) and Composite In Back putting the echo over the layer. EffectCraft had the two the other way round, which made ~0.5 % of the pixels differ at the moving edge. The CPU and GPU (fxn_echo) arms are swapped together. A regression test rebuilds row 130 of the test card and checks Add, Maximum, Minimum, Screen and both Composite operators against the measured After Effects row. Blend is left unchanged: the sample (one echo, intensity 1, decay 1) cannot tell its normalisation apart. Co-Authored-By: Claude Opus 5.5 * Echo: Blend sums the weighted frames like Add (#3124) New After Effects 2026 renders (our own 1110-extra sample, 16-bit PNGs, opaque test card with a moving square) show that Blend does not normalise: - 3 echoes at intensity 1 and decay 1 give four times the layer. - 2 echoes at intensity 0.5 and decay 0.5 give alpha 0.875 (0.5 + 0.25 + 0.125). EffectCraft divided by the number of frames. The division is gone on the CPU and in fxn_echo_fin on the GPU. The same sample pins Composite In Back with three echoes: each older echo goes over what is there with its weight as opacity, so the oldest is on top, as the branch already does. Composite In Front with three echoes equals the current frame. A regression test checks four measured 16-bit rows within 4 codes (24 on square-edge pixels): Blend 3/1/1, Blend 2/0.5/0.5 with alpha, and both composite modes at 3 echoes, -0.08 s, decay 0.5. Co-Authored-By: Claude Opus 5.5 * Echo: doc comments on the CPU and GPU entry points Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> --- crates/effects/src/time_fx.rs | 160 ++++++++++++++++++++++++--- crates/gpu/src/fx_noise.rs | 5 +- crates/gpu/src/shaders/fx_noise.wgsl | 13 +-- 3 files changed, 156 insertions(+), 22 deletions(-) diff --git a/crates/effects/src/time_fx.rs b/crates/effects/src/time_fx.rs index f8886d58c..79b0ce479 100644 --- a/crates/effects/src/time_fx.rs +++ b/crates/effects/src/time_fx.rs @@ -269,6 +269,9 @@ fn mean_of(ctx: &EffectCtx, b: Buf, times: &[f64]) -> Buf { // ---------------------------------------------------------------- Echo +/// Echo: the layer at the current time and `numberOfEchoes` earlier (or later) times +/// `echoTime` apart, each weighted Starting Intensity × Decay^i and combined by the Echo Operator +/// (Add, Maximum, Minimum, Screen, Composite In Back, Composite In Front, Blend). fn echo(ctx: &EffectCtx, b: Buf) -> Buf { let n = ctx.params.f("numberOfEchoes").round().clamp(0.0, 255.0) as usize; let dt = ctx.params.f("echoTime"); @@ -278,7 +281,6 @@ fn echo(ctx: &EffectCtx, b: Buf) -> Buf { let times: Vec = (0..=n).map(|i| ctx.time + i as f64 * dt).collect(); let Some(fr) = fetch(ctx, ×) else { return b }; let weights: Vec = (0..=n).map(|i| start * decay.powi(i as i32)).collect(); - let count = (n + 1) as f32; let w = fr.grid.img.width; let h = fr.grid.img.height; let mut out = Image::new(w, h); @@ -297,23 +299,26 @@ fn echo(ctx: &EffectCtx, b: Buf) -> Buf { 2 => (0..4).for_each(|c| acc[c] = acc[c].min(q[c])), // Screen 3 => (0..4).for_each(|c| acc[c] = acc[c] + q[c] - acc[c] * q[c]), - // Composite In Back: each later echo goes behind what is there. + // Composite In Back: the layer goes in back, each echo is composited over what + // is there, the oldest on top, with its weight as opacity (After Effects 2026, + // opaque layer, one and three echoes). Whether the weight scales the alpha of a + // transparent layer's echo or fades it is not measured. 4 => { - let ia = 1.0 - acc[3]; - (0..4).for_each(|c| acc[c] += q[c] * ia); - } - // Composite In Front: each later echo goes on top. - 5 => { let ia = 1.0 - q[3]; (0..4).for_each(|c| acc[c] = q[c] + acc[c] * ia); } - // Blend (average) and Add + // Composite In Front: the layer stays in front, each echo goes behind what is + // there (After Effects 2026: an opaque layer hides its echo). + 5 => { + let ia = 1.0 - acc[3]; + (0..4).for_each(|c| acc[c] += q[c] * ia); + } + // Add, and Blend: After Effects 2026 sums the weighted frames for Blend as well, + // with no normalisation (3 echoes at intensity 1 give 4x the layer; intensity + // 0.5, decay 0.5 and 2 echoes give alpha 0.875). _ => (0..4).for_each(|c| acc[c] += q[c]), } } - if op == 6 { - acc.iter_mut().for_each(|c| *c /= count); - } if op == 2 && acc[0] == f32::MAX { acc = [0.0; 4]; } @@ -1147,7 +1152,7 @@ mod tests { let want = 0.8 + 0.5 * 0.7 + 0.25 * 0.6; assert!((out.img.data[0][0] - want as f32).abs() < 1e-4, "{}", out.img.data[0][0]); assert_eq!(out.img.data[0][3], 1.0); - // Maximum picks the brightest weighted frame; Blend averages. + // Maximum picks the brightest weighted frame; Blend sums like Add (#3124). let mut v = vals.to_vec(); v.push(("echoOperator", Value::Enum(1))); let out = run("ec.time.echo", &v, 0.8, &h); @@ -1155,7 +1160,136 @@ mod tests { v.pop(); v.push(("echoOperator", Value::Enum(6))); let out = run("ec.time.echo", &v, 0.8, &h); - assert!((out.img.data[0][0] - want as f32 / 3.0).abs() < 1e-4); + assert!((out.img.data[0][0] - want as f32).abs() < 1e-4, "{}", out.img.data[0][0]); + } + + /// Row y = 130, x = 60..111 of the importer sample's SRC test card (#3124): a black-to-white + /// ramp across 320 px under an opaque white 30 px square whose centre moves from x = 20 at + /// 0 s to x = 300 at 2 s. + struct MovingSquare; + impl EffectHost for MovingSquare { + fn layer(&self, _: u64, _: bool) -> Option { + None + } + fn audio(&self, _: u64, _: f64, _: usize, _: u32) -> Option> { + None + } + fn self_at(&self, t: f64, _: usize) -> Option { + let centre = 20.0 + 140.0 * t; + let (s0, s1) = (centre - 15.0, centre + 15.0); + let mut img = Image::new(52, 1); + for (i, px) in img.data.iter_mut().enumerate() { + let x = 60.0 + i as f64; + let cover = ((x + 1.0).min(s1) - x.max(s0)).clamp(0.0, 1.0) as f32; + let ramp = ((x + 0.5) / 320.0) as f32; + let v = cover + (1.0 - cover) * ramp; + *px = [v, v, v, 1.0]; + } + Some(Buf { img, offset: [0.0; 2], scale: 1.0 }) + } + } + + /// After Effects 2026 renders of that row at 0.5 s, Echo Time −1/30 s, one echo, Starting + /// Intensity 1, Decay 1 (renders/echo-00 ... echo-10 of the 2026-11-05 importer sample, 32 bpc, + /// saved as 8-bit PNGs that hold floor(value × 25.5)). + #[rustfmt::skip] + const AE_ECHO_ROW: [(u32, &str, [u8; 52]); 6] = [ + (0, "Add", [9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 24, 31, 31, 31, 31, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 39, 33, 33, 33, 33, 16, 16, 17, 17, 17, 17, 17]), + (1, "Maximum", [4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 18, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 8, 8, 8, 8, 8, 8, 8]), + (2, "Minimum", [4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 13, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]), + (3, "Screen", [8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 20, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 14, 14, 14, 14, 14, 14, 14]), + (4, "Composite In Back", [4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 18, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 13, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]), + (5, "Composite In Front", [4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 8, 8, 8, 8, 8, 8, 8]), + ]; + + /// #3124: every operator but Blend against the After Effects row. Composite In Back puts + /// the echo over the layer (the trailing echo hides the square's leading edge), In Front + /// keeps the layer on top (the output is the current frame). + #[test] + fn echo_operators_match_after_effects_at_the_moving_edge() { + let h = MovingSquare; + for (op, name, ae) in AE_ECHO_ROW { + let vals = [("echoTime", num(-1.0 / 30.0)), ("numberOfEchoes", num(1.0)), ("echoOperator", Value::Enum(op))]; + let env = EffectEnv { host: Some(&h), frame_rate: 25.0, comp_time: 0.5, ..Default::default() }; + let out = run_fx("ec.time.echo", &vals, Image::new(52, 1), 0.5, env); + for (x, want) in ae.iter().enumerate() { + let got = (out.img.data[x][0] * 25.5).floor(); + assert!((got - f32::from(*want)).abs() <= 1.0, "{name}: x = {} got {got}, After Effects {want}", 60 + x); + assert_eq!(out.img.data[x][3], 1.0, "{name}: alpha at x = {}", 60 + x); + } + } + } + + /// Row y = 130, x = 36..111 of the same test card as read back from 16-bit renders: there the + /// ramp is x / 320 at the pixel's left edge (the 8-bit row above cannot tell that apart). + struct MovingSquareRow16; + impl EffectHost for MovingSquareRow16 { + fn layer(&self, _: u64, _: bool) -> Option { + None + } + fn audio(&self, _: u64, _: f64, _: usize, _: u32) -> Option> { + None + } + fn self_at(&self, t: f64, _: usize) -> Option { + let centre = 20.0 + 140.0 * t; + let (s0, s1) = (centre - 15.0, centre + 15.0); + let mut img = Image::new(76, 1); + for (i, px) in img.data.iter_mut().enumerate() { + let x = 36.0 + i as f64; + let cover = ((x + 1.0).min(s1) - x.max(s0)).clamp(0.0, 1.0); + let v = (cover + (1.0 - cover) * x / 320.0) as f32; + *px = [v, v, v, 1.0]; + } + Some(Buf { img, offset: [0.0; 2], scale: 1.0 }) + } + } + + /// After Effects 2026 renders of that row at 0.5 s (renders/echo-13 ... echo-16 of the + /// 2026-11-05 importer sample, group 1110-extra, 32 bpc, 16-bit PNGs holding value × 6553.5): + /// operator, Echo Time, Number Of Echoes, Starting Intensity, Decay, alpha code, row codes. + #[rustfmt::skip] + const AE_ECHO_ROW16: [(u32, f64, f64, f64, f64, u16, [u16; 76]); 4] = [ + (6, -1.0 / 30.0, 3.0, 1.0, 1.0, 65535, [2949, 3031, 3111, 3193, 3275, 3357, 3439, 3521, 3603, 3685, 3767, 3849, 3931, 4013, 4095, 4177, 4259, 4341, 4423, 4505, 4587, 4669, 4751, 4833, 4915, 10301, 10361, 10423, 10485, 12293, 15809, 15851, 15891, 15933, 19369, 21113, 21135, 21155, 21175, 26205, 26213, 26213, 26213, 26213, 26213, 26213, 26213, 26213, 26213, 26213, 26213, 26213, 26213, 26213, 26213, 21523, 21543, 21565, 21585, 20063, 17039, 17079, 17121, 17161, 14215, 12759, 12819, 12881, 12943, 8607, 8683, 8765, 8847, 8929, 9011, 9093]), + (6, -1.0 / 30.0, 2.0, 0.5, 0.5, 57343, [643, 661, 679, 697, 715, 733, 751, 769, 787, 805, 823, 839, 859, 877, 895, 911, 929, 949, 965, 983, 1001, 1021, 1037, 1055, 1073, 1091, 1109, 1127, 1145, 1381, 1831, 1847, 1861, 1877, 2743, 3183, 3193, 3203, 3213, 5727, 5733, 5733, 5733, 5733, 5733, 5733, 5733, 5733, 5733, 5733, 5733, 5733, 5733, 5733, 5733, 5733, 5733, 5733, 5733, 5541, 5159, 5163, 5165, 5167, 4423, 4051, 4059, 4065, 4073, 1883, 1897, 1917, 1933, 1951, 1969, 1987]), + (4, -0.08, 3.0, 1.0, 0.5, 65535, [737, 757, 777, 797, 819, 1267, 1571, 1589, 1607, 1625, 1643, 1661, 1679, 1697, 1715, 1733, 2229, 2965, 2977, 2991, 3005, 3017, 3031, 3045, 3059, 3071, 3085, 3443, 4833, 4839, 4845, 4853, 4859, 4865, 4873, 4497, 4251, 4261, 4269, 5923, 5927, 5931, 5933, 5935, 5939, 5941, 5517, 4885, 4891, 4899, 4905, 4913, 4919, 4927, 4933, 4941, 4947, 4649, 3443, 3457, 3471, 3485, 3497, 3511, 3525, 3539, 3553, 3567, 3581, 2151, 2169, 2191, 2211, 2231, 2251, 2273]), + (5, -0.08, 3.0, 1.0, 0.5, 65535, [737, 757, 777, 797, 819, 839, 859, 879, 901, 921, 941, 961, 983, 1003, 1023, 1043, 1063, 1085, 1105, 1125, 1145, 1167, 1187, 1207, 1227, 1249, 1269, 1289, 1309, 1331, 1351, 1371, 1391, 1413, 1433, 1453, 1473, 1495, 1515, 6545, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 6553, 2157, 2169, 2191, 2211, 2231, 2251, 2273]), + ]; + + /// #3124: Blend sums the weighted frames like Add (no normalisation, Starting Intensity weights + /// the current frame too), and with three echoes Composite In Back stacks the oldest echo on + /// top while In Front leaves the opaque current frame alone. The alpha is checked as measured. + /// The RGB comparison of the half-transparent Blend row reads the PNG as premultiplied colour + /// (`saveFrameToPng` does not document which it writes); the opaque rows do not depend on it. + #[test] + fn echo_blend_and_three_echo_composites_match_after_effects() { + let h = MovingSquareRow16; + for (op, dt, n, start, decay, alpha, ae) in AE_ECHO_ROW16 { + let vals = [ + ("echoTime", num(dt)), + ("numberOfEchoes", num(n)), + ("startingIntensity", num(start)), + ("decay", num(decay)), + ("echoOperator", Value::Enum(op)), + ]; + let env = EffectEnv { host: Some(&h), frame_rate: 25.0, comp_time: 0.5, ..Default::default() }; + let out = run_fx("ec.time.echo", &vals, Image::new(76, 1), 0.5, env); + // Pixels a square edge passes through: After Effects anti-aliases the card's square a + // little differently from the box coverage above, so they get 24 codes (0.4 %). + let edges: Vec = (0..=n as usize) + .flat_map(|i| { + let c = 20.0 + 140.0 * (0.5 + i as f64 * dt); + [(c - 15.0).floor(), (c + 15.0).floor()] + }) + .collect(); + for (x, want) in ae.iter().enumerate() { + let px = out.img.data[x]; + let got = px[0] * 6553.5; + let tol = if edges.contains(&(36.0 + x as f64)) { 24.0 } else { 4.0 }; + assert!((got - f32::from(*want)).abs() <= tol, "op {op}, n {n}: x = {} got {got}, After Effects {want}", 36 + x); + let a = px[3] * 65535.0; + assert!((a - f32::from(alpha)).abs() <= 2.0, "op {op}, n {n}: alpha at x = {} got {a}, After Effects {alpha}", 36 + x); + } + } } #[test] diff --git a/crates/gpu/src/fx_noise.rs b/crates/gpu/src/fx_noise.rs index 22f23fd86..9ae503994 100644 --- a/crates/gpu/src/fx_noise.rs +++ b/crates/gpu/src/fx_noise.rs @@ -601,6 +601,8 @@ fn minimax(e: &mut Enc, ctx: &EffectCtx, mut b: GBuf) -> Option { // ---------------------------------------------------------------- Echo / Posterize Time (time_fx.rs) +/// Echo on the GPU (`time_fx::echo`): the frames fetched on the CPU, folded in order by +/// `fxn_echo` into two ping-pong images, then `fxn_echo_fin` clamps the result. fn echo(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option { let n = ctx.params.f("numberOfEchoes").round().clamp(0.0, 255.0) as usize; let dt = ctx.params.f("echoTime"); @@ -620,8 +622,7 @@ fn echo(e: &mut Enc, ctx: &EffectCtx, b: GBuf) -> Option { e.pixels("fxn_echo", &p, a, Some(&frame), o, None); acc.swap(0, 1); } - let mut p = with_u0([op, 0, 0, 0]); - p.f[0][0] = (n + 1) as f32; + let p = with_u0([op, 0, 0, 0]); let img = run(e, "fxn_echo_fin", &p, &acc[0], None, None); Some(GBuf { img, offset: grid.offset, scale: grid.scale }) } diff --git a/crates/gpu/src/shaders/fx_noise.wgsl b/crates/gpu/src/shaders/fx_noise.wgsl index d2f2977ad..3d0a7977d 100644 --- a/crates/gpu/src/shaders/fx_noise.wgsl +++ b/crates/gpu/src/shaders/fx_noise.wgsl @@ -407,12 +407,14 @@ fn fxn_echo(@builtin(global_invocation_id) gid: vec3) { case 3u: { acc = acc + q - acc * q; } + // Composite In Back: each echo over what is there (time_fx.rs echo). case 4u: { - acc += q * (1.0 - acc.w); - } - case 5u: { acc = q + acc * (1.0 - q.w); } + // Composite In Front: each echo behind what is there. + case 5u: { + acc += q * (1.0 - acc.w); + } default: { acc += q; } @@ -420,7 +422,7 @@ fn fxn_echo(@builtin(global_invocation_id) gid: vec3) { textureStore(out, p, acc); } -// Echo's finish. u[0].x = operator; f[0].x = number of frames. +// Echo's finish. u[0].x = operator. Blend sums like Add (time_fx.rs echo), so nothing divides. @compute @workgroup_size(16, 16) fn fxn_echo_fin(@builtin(global_invocation_id) gid: vec3) { let p = fxn_pixel(gid); @@ -429,9 +431,6 @@ fn fxn_echo_fin(@builtin(global_invocation_id) gid: vec3) { } let op = P.u[0].x; var acc = textureLoad(src, p, 0); - if (op == 6u) { - acc = acc / P.f[0].x; - } if (op == 2u && acc.x == FXN_MAX) { acc = vec4(0.0); } From 52bca964f58e5547ffb0eba84a1825f775f875dc Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Sat, 7 Nov 2026 00:40:24 +0100 Subject: [PATCH 21/40] Image sequences: a gap in the numbering holds the previous frame, as After Effects (#3137) * Image sequences: a gap in the numbering holds the previous frame, as After Effects Split out of #1876 (originally 7850cbf4), because it reverses the colour bars documented in #297 and needs its own discussion. After Effects 2026 shows the last existing file across a gap in a sequence's numbering (files 1, 2, 4, 5 show frame 2 at frame 3; read back from After Effects). EffectCraft drew colour bars there. The media pool now holds the previous file (Footage::sequence_file_held); colour bars remain only where no file precedes the frame. Missing-frame reports on import are unchanged. Co-Authored-By: Claude Opus 5.5 * Image sequences: hold the first file of the preceding number across a gap; fix the import warning A gap now holds the file sequence_file picks for the preceding number, so files sharing a number do not switch at the gap. The Report Missing Frames warning says the previous frame is held instead of "shown as placeholders". Co-Authored-By: Claude Opus 5.5 * Image sequences: Interpret Footage says a gap holds the previous frame The Interpret Footage note for a numbered sequence with gaps still said the missing frames are shown as colour bars; the media pool holds the previous frame there now. The note, its comment and two test doc comments say so, and a forms test checks the note's wording. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> --- crates/engine/src/cmd/file.rs | 2 +- crates/engine/src/tests/sequence.rs | 5 +++-- crates/media/src/pool.rs | 4 ++-- crates/media/tests/it/footage.rs | 14 ++++++------- crates/project/src/sequence.rs | 27 +++++++++++++++++++++++++ crates/ui-egui/src/panels/forms.rs | 24 +++++++++++++++++++--- crates/ui-egui/tests/it/ui_drag_drop.rs | 4 ++-- docs/agents.md | 4 ++-- docs/footage.md | 4 ++-- 9 files changed, 66 insertions(+), 22 deletions(-) diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index e1f58a1cc..f5bae86d0 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -327,7 +327,7 @@ impl Prober { && self.report_missing_frames && let Some(gaps) = crate::sequence::missing_report(&f.sequence) { - warning = Some(format!("{name}: {gaps} (shown as placeholders)")); + warning = Some(format!("{name}: {gaps} (the previous frame is held)")); } // Settings ▸ Import ▸ Interpret Unlabeled Alpha As: images only (a 3D model renders its // own alpha, and audio and data have none). diff --git a/crates/engine/src/tests/sequence.rs b/crates/engine/src/tests/sequence.rs index cf6968e3f..c5faa232b 100644 --- a/crates/engine/src/tests/sequence.rs +++ b/crates/engine/src/tests/sequence.rs @@ -1,6 +1,6 @@ //! Image sequences (#297): File ▸ Import with the " Sequence" option, picked ranges, //! folders, Force Alphabetical Order, the import frame rate, Replace Footage, missing frames -//! (placeholders, as in After Effects) and Interpret Footage ▸ Start Timecode. +//! (they hold the previous frame) and Interpret Footage ▸ Start Timecode. use effectcraft_project::{Footage, FootageKind, ItemId, ItemKind}; use effectcraft_time::{FrameRate, Tick}; @@ -62,12 +62,13 @@ fn one_picked_numbered_file_imports_its_run_as_one_sequence() { assert_eq!(name, "shot_[0001-0005].png"); assert_eq!((f.kind, f.sequence.len(), f.alphabetical), (FootageKind::Sequence, 4, false)); assert_eq!(f.path, at(&dir, "shot_0001.png")); - // Frames 1–5 at Settings ▸ Import ▸ Sequence Footage (30 fps); frame 3 is a placeholder. + // Frames 1–5 at Settings ▸ Import ▸ Sequence Footage (30 fps); frame 3 holds frame 2. assert_eq!(f.duration, FrameRate::FPS_30.tick_of(5)); assert_eq!(f.sequence_file(2), None); // Settings ▸ Import ▸ Report Missing Frames. let w = r["warnings"][0].as_str().unwrap(); assert!(w.contains("1 missing frame (3)"), "{w}"); + assert!(w.contains("previous frame is held") && !w.contains("placeholder"), "{w}"); } /// Picking every frame of a sequence used to make one item per frame (each a whole sequence on diff --git a/crates/media/src/pool.rs b/crates/media/src/pool.rs index b0b2f2539..9e10b4eb3 100644 --- a/crates/media/src/pool.rs +++ b/crates/media/src/pool.rs @@ -736,9 +736,9 @@ impl Inner { match footage.kind { FootageKind::Sequence if !footage.sequence.is_empty() => { let i = Self::frame_index(footage.frame_rate, t, footage.sequence_frames(), footage.loop_count); - match footage.sequence_file(i) { + match footage.sequence_file_held(i) { Some(path) => Loc { key: key(path, 0), media_t: None, float }, - // A gap in the numbering: colour bars, as in After Effects. + // No file at or before the frame: colour bars. None => Loc { key: key(PLACEHOLDER, ((footage.width as i64) << 32) | footage.height as i64), media_t: None, float }, } } diff --git a/crates/media/tests/it/footage.rs b/crates/media/tests/it/footage.rs index 0cae33417..7f0de6ae4 100644 --- a/crates/media/tests/it/footage.rs +++ b/crates/media/tests/it/footage.rs @@ -710,10 +710,11 @@ fn png_sequence_import() { assert_eq!(*img, load_png(&first.with_file_name("seq_0004.png"))); } -/// A gap in a sequence's numbering shows colour bars, as in After Effects; in Force -/// Alphabetical Order the files play back to back (#297). +/// A gap in a sequence's numbering holds the previous frame, as After Effects 2026 does (files +/// 1, 2, 4, 5 show frame 2 at frame 3); in Force Alphabetical Order the files play back to back +/// (#297). #[test] -fn sequence_gaps_show_placeholders() { +fn sequence_gaps_hold_the_previous_frame() { let dir = fixtures().join(format!("gap-seq-{}", std::process::id())); std::fs::create_dir_all(&dir).expect("mkdir"); // Frames 1, 2 and 4: frame 3 is missing. Each frame is a flat grey of its number. @@ -731,11 +732,8 @@ fn sequence_gaps_show_placeholders() { let at = |f: &Footage, n: i64| pool.frame_at(f, t_of(f.frame_rate, n)).expect("frame"); let level = |img: &Image| (img.get(0, 0)[0] * 255.0).round() as u32; assert_eq!(level(&at(&f, 1)), 100); - // The placeholder: colour bars across the frame, starting with 75 % white. - let bars = at(&f, 2); - assert_eq!((bars.width, bars.height), (8, 4)); - assert_eq!(bars.get(0, 0), [0.75, 0.75, 0.75, 1.0]); - assert_eq!(bars.get(7, 3), [0.0, 0.0, 0.75, 1.0], "blue on the right"); + // The gap holds frame 2. + assert_eq!(level(&at(&f, 2)), 100); assert_eq!(level(&at(&f, 3)), 200); f.alphabetical = true; f.sync_sequence_duration(); diff --git a/crates/project/src/sequence.rs b/crates/project/src/sequence.rs index 716c9b4fd..0b23d528f 100644 --- a/crates/project/src/sequence.rs +++ b/crates/project/src/sequence.rs @@ -114,6 +114,22 @@ impl Footage { self.sequence.get(k).filter(|p| frame_number(p) == Some(n)).map(String::as_str) } + /// The file an image sequence shows at its frame `i`, holding the last existing file across a + /// gap in the numbering (After Effects 2026: files 1, 2, 4, 5 show frame 2 at frame 3). + /// `None` only when no file precedes the frame (or there are no files). + pub fn sequence_file_held(&self, i: i64) -> Option<&str> { + if let Some(p) = self.sequence_file(i) { + return Some(p); + } + let first = self.numbered()?; + let k = self.first_file_from(first.saturating_add(i)); + // The preceding number, then the file `sequence_file` picks for it (the first with that + // number), so files sharing a number (`shot_0002`, `shot_002`) don't switch at a gap. + let prev = self.file_number(k.checked_sub(1)?)?; + let j = self.first_file_from(prev); + self.sequence.get(j).filter(|p| frame_number(p) == Some(prev)).map(String::as_str) + } + /// Set an image sequence's duration to its frames at its frame rate (after its files or /// frame rate changed). pub fn sync_sequence_duration(&mut self) { @@ -131,6 +147,17 @@ mod tests { Footage { kind: FootageKind::Sequence, sequence: numbers.iter().map(|n| format!("C:\\shots\\a_{n:04}.png")).collect(), ..Default::default() } } + #[test] + fn a_gap_holds_the_file_shown_for_the_preceding_number() { + let mut f = seq(&[]); + f.sequence = ["a_0001.png", "a_0002.png", "a_002.png", "a_0005.png"].map(String::from).to_vec(); + assert_eq!(f.sequence_file(1), Some("a_0002.png")); + // Frames 3 and 4 (numbers 3, 4) hold what number 2 shows: the first file with it. + assert_eq!(f.sequence_file_held(2), Some("a_0002.png")); + assert_eq!(f.sequence_file_held(3), Some("a_0002.png")); + assert_eq!(f.sequence_file_held(4), Some("a_0005.png")); + } + #[test] fn numbers_and_names() { assert_eq!(split_frame_number("shot_0012"), Some(("shot_", "0012"))); diff --git a/crates/ui-egui/src/panels/forms.rs b/crates/ui-egui/src/panels/forms.rs index 65d825b45..635ef9a43 100644 --- a/crates/ui-egui/src/panels/forms.rs +++ b/crates/ui-egui/src/panels/forms.rs @@ -310,13 +310,13 @@ fn interpret_footage_form(s: &effectcraft_engine::Session, proxy: bool, base: &m m.insert("pointUnits".into(), json!(c.units.id())); } } - // After Frame Rate: an image sequence's frames (missing ones show colour bars, as in - // After Effects), then Start Timecode. + // After Frame Rate: an image sequence's frames (a missing one holds the previous frame), + // then Start Timecode. let mut timing = Vec::new(); if f.kind == effectcraft_engine::project::FootageKind::Sequence { let gaps = match effectcraft_engine::sequence::missing_report(&f.sequence) { _ if f.alphabetical => "files in alphabetical order".into(), - Some(gaps) => format!("{gaps} shown as color bars"), + Some(gaps) => format!("{gaps} (the previous frame is held)"), None => "no missing frames".into(), }; timing.push(Field::note("sequenceInfo", &format!("Image sequence: {} files, {} frames; {gaps}.", f.sequence.len(), f.sequence_frames()))); @@ -1172,6 +1172,24 @@ mod tests { } } + /// Interpret Footage on an image sequence with a gap says the previous frame is held there + /// (what the media pool shows), not colour bars. + #[test] + fn interpret_footage_says_a_sequence_gap_holds_the_previous_frame() { + use effectcraft_engine::project::{Footage, FootageKind, ItemKind}; + let mut app = EffectcraftApp::new(effectcraft_engine::Session::default()); + let sequence: Vec = ["/m/a_001.png", "/m/a_002.png", "/m/a_005.png"].map(String::from).to_vec(); + let footage = Footage { path: sequence[0].clone(), kind: FootageKind::Sequence, sequence, width: 4, height: 4, has_video: true, ..Default::default() }; + let project = std::sync::Arc::make_mut(&mut app.session.project); + let item = project.add_item("a_[001-005].png", Default::default(), None, ItemKind::Footage(footage)); + app.session.state.project_selection = vec![item]; + assert!(open_form(&mut app, "file.interpretFootage", &json!({}))); + let note = app.dialog_state.form.fields.iter().find(|f| f.key == "sequenceInfo").map(|f| f.kind.clone()); + let Some(FieldKind::Note(text)) = note else { panic!("no sequence note: {note:?}") }; + assert!(text.contains("2 missing frames (3–4)") && text.contains("the previous frame is held"), "{text}"); + assert!(!text.contains("color bars"), "{text}"); + } + /// Interpret Footage shows Cineon Settings for DPX footage only. The converted points show in /// the footage's Units, and choosing other Units reads the shown values in the old ones. #[test] diff --git a/crates/ui-egui/tests/it/ui_drag_drop.rs b/crates/ui-egui/tests/it/ui_drag_drop.rs index 42d0273f8..5a0d94ddf 100644 --- a/crates/ui-egui/tests/it/ui_drag_drop.rs +++ b/crates/ui-egui/tests/it/ui_drag_drop.rs @@ -667,8 +667,8 @@ fn new_composition_from_footage_makes_a_comp_of_the_picked_file() { } /// #297: a folder of frames dropped on the window arrives as one image sequence, and Interpret -/// Footage shows its frames and Start Timecode (missing frames always show colour bars, as in -/// After Effects: there is no Missing Frames choice). #431: dropped files import as stills, one +/// Footage shows its frames and Start Timecode (a missing frame always holds the previous one: +/// there is no Missing Frames choice). #431: dropped files import as stills, one /// item each, as in After Effects. #[test] fn a_dropped_folder_imports_as_one_sequence_with_sequence_interpretation() { diff --git a/docs/agents.md b/docs/agents.md index 124db6b80..9831ec031 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -302,8 +302,8 @@ build real projects through these interfaces; they are worked examples of everyt file's whole numbered run as one item (several picked frames: that range; a folder: each run in it, also without `sequence`). Without `"sequence": true` a picked or dropped numbered file imports as one still, as in After Effects; `"alphabetical": true`: Force Alphabetical Order, the files - play one after another) at `frameRate` or 30 fps (Settings ▸ Import). Missing frames show - colour bars, as in After Effects. `file.interpretFootage {"items":[id], "frameRate":12, + play one after another) at `frameRate` or 30 fps (Settings ▸ Import). A gap in the numbering holds + the previous frame, as in After Effects. `file.interpretFootage {"items":[id], "frameRate":12, "startTimecode":1001}` conforms them and sets Override Start (the item and layers that ran to its end get the new length). See [footage.md](footage.md). * **Colour of footage**: `file.interpretFootage {"items":[id], "preserveRgb":true}` is Interpret diff --git a/docs/footage.md b/docs/footage.md index e2effa996..7841dc84c 100644 --- a/docs/footage.md +++ b/docs/footage.md @@ -47,8 +47,8 @@ Stills of any format EffectCraft reads can form a sequence: PNG, JPEG, TIFF, Ope WebP. Layered and vector documents (PSD, SVG, PDF) import one by one. **Missing frames.** Where the numbering skips a number (`shot_0003.png` is missing between -`0002` and `0004`), the sequence shows a placeholder of colour bars for that frame, as After -Effects does, so every other frame stays at its number. Render or copy the missing files into the +`0002` and `0004`), the sequence holds the previous frame (`0002`) there, as After Effects 2026 +does, so every other frame stays at its number. Render or copy the missing files into the folder and choose File ▸ Reload Footage to fill the gaps. Agents: `file.import {"paths": ["/shots/shot_0001.png"], "sequence": true, "frameRate": 24}`. From bb2d2005cee68458a10ae2cc32d609d070b21744 Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Sat, 7 Nov 2026 00:56:54 +0100 Subject: [PATCH 22/40] Layer: Un-precompose a selected pre-comp layer back into its parent composition (#3081) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Layer: Un-precompose a selected pre-comp layer back into its parent composition (#2918) layer.unprecompose copies the nested composition's layers into the parent at the pre-comp layer's place with timing and position carried over, and refuses what it can't keep exactly. Co-Authored-By: Claude Sonnet 5.5 * Un-precompose: refuse a pre-comp layer with Solo or Guide on A soloed pre-comp layer hides the comp's other layers and a guide layer is left out of renders; the expanded copies carry neither switch, so the picture would change. Listed with the other blockers, in the command description and the agents.md Cookbook entry; the refusal test covers both switches. Co-Authored-By: Claude Opus 5.5 * Un-precompose: warn instead of refusing, only a locked layer stops it A locked pre-comp layer is still refused, with or without `force`. Every other former refusal reason is a warning: without `force`, `layer.unprecompose` returns an error that lists the reasons and changes nothing. `dryRun` returns `{dryRun, warnings}`. With `force` the layer is unpacked in one undo step and the result carries `warnings`. Whatever the pre-comp layer itself carried is dropped, and other layers' parent, track matte and layer-property links to it are removed. Layer > Un-precompose in the UI lists the reasons in a prompt with Unpack Anyway / Cancel (`dialog.unprecompose.force` / `dialog.unprecompose.cancel`). A layer without reasons unpacks at once. Co-Authored-By: Claude Opus 5.5 * Un-precompose: warn about expressions that refer to the pre-comp layer An expression on another layer of the comp that names the pre-comp layer would no longer find it once the layer is unpacked. The expression can name it in quotes or call `layer()` with its index, bare or on thisComp; another comp's comp("…").layer(…) is not counted. Each such property is now listed once as a warning. Like the other warnings, `force` unpacks and `dryRun` lists it. The expressions are left as written. Co-Authored-By: Claude Opus 5.5 * Un-precompose: warn about lost frame sampling and Position expressions, keep markers in order Review follow-up (CodeRabbit on #3081): - A nested comp that preserves a frame rate other than the parent's samples its layers on its own frames, and the expanded copies would lose that. Motion-blurred nested layers under a different shutter would also blur with the parent's shutter. Both are now warnings. - When the pre-comp layer's Position differs from its Anchor Point, the move is added to the stored Position of the unparented nested layers. An unparented layer whose Position, or a separated axis, has an expression may ignore that move, so it is now a warning. - Copied comp markers are sorted into time order with the comp's own. - New tests: a 10 fps nested comp with Preserve Frame Rate in a 30 fps comp, a different shutter, a Position expression with and without a move, and nested matte and layer-value remapping with shifted markers merged in order. Co-Authored-By: Claude Opus 5.5 * Un-precompose: warn when an expression's layer numbers shift; the prompt keeps its target Co-Authored-By: Claude Opus 5.5 * Un-precompose: a shorter renumbering warning Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Sonnet 5.5 Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> --- crates/engine/src/cmd/layer.rs | 11 +- crates/engine/src/cmd/layer/timing.rs | 316 +++++++++++++++ crates/engine/src/menus.rs | 1 + crates/engine/src/tests/menu_cmds.rs | 466 ++++++++++++++++++++++ crates/ui-egui/src/i18n/ui.rs | 1 + crates/ui-egui/src/lib.rs | 2 + crates/ui-egui/src/menus/invoke.rs | 4 + crates/ui-egui/src/panels.rs | 1 + crates/ui-egui/src/panels/dialogs.rs | 3 + crates/ui-egui/src/panels/unprecompose.rs | 181 +++++++++ docs/agents.md | 24 ++ 11 files changed, 1009 insertions(+), 1 deletion(-) create mode 100644 crates/ui-egui/src/panels/unprecompose.rs diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index 2c3024cac..f88ab32c8 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -31,7 +31,7 @@ use replace::{has_replace_source, replace_source}; pub(crate) use select::select_only; use select::{select, select_next, select_prev, select_step}; use switches::{blend, rename, set_comment, set_switch, track_matte}; -use timing::{arrange, move_frames, precompose, slip, timing}; +use timing::{arrange, move_frames, precompose, slip, timing, unprecompose}; use transform::{has_layer_settings, layer_settings, transform_op}; pub(crate) use transform::{offset_position, transform_default, update_position}; @@ -177,6 +177,15 @@ pub fn specs() -> Vec { has_layers, precompose ), + cmd!( + "layer.unprecompose", + "Un-precompose", + ["Layer"], + None, + "{layer?, force?, dryRun?} → {layers, warnings}: expands the selected pre-comp layer into its composition's layers (copies, in order, with timing and position carried over). A locked pre-comp layer is refused, changing nothing. What would change the picture (the pre-comp layer has a parent, matte, effects, masks, layer styles, a non-default Scale/Rotation/Opacity, an animated transform, time remap/stretch, a blending mode, Video/Audio off, Solo/Guide on, is 3D/collapsing/adjustment, is used by another layer or named in another layer's expression; or the nested comp has cameras, lights, adjustment, 3D, collapsing, soloed or blend-mode / Preserve Transparency layers, preserves another frame rate, has another motion-blur shutter, or has Position expressions the move can't reach) is an error listing the reasons, changing nothing, unless `force`: then it unpacks anyway in one undo step, drops what the pre-comp layer carried, removes other layers' parent/matte/property links to it and lists the reasons as `warnings`. `dryRun` returns {dryRun, warnings} and changes nothing", + has_layers, + unprecompose + ), cmd!( "layer.addMask", "New Mask", diff --git a/crates/engine/src/cmd/layer/timing.rs b/crates/engine/src/cmd/layer/timing.rs index 15a6628d4..9fe85ac83 100644 --- a/crates/engine/src/cmd/layer/timing.rs +++ b/crates/engine/src/cmd/layer/timing.rs @@ -1,3 +1,5 @@ +use effectcraft_project::TrackMatte; + use super::{ EngineError, ItemKind, Label, Layer, LayerId, LayerSource, Result, Session, Tick, Value, b_p, bad, build, f_p, json, layer_mut, layers_p, merge_p, resolve_layer, str_p, unlocked, with, @@ -307,3 +309,317 @@ pub(super) fn precompose(s: &mut Session, p: &Value) -> Result { } Ok(json!({"comp": new.0.0, "layer": new.1.0})) } + +/// Why expanding a pre-comp layer in place would change the picture or drop something, one entry +/// per cause. Un-precompose keeps the picture exactly for a pre-comp layer that only places the +/// nested composition (Position/Anchor Point, timing); anything the layer itself adds to the look, +/// and what only holds inside the nested comp, is listed. These are warnings: `force` unpacks +/// anyway and drops it. A lock is not listed here: it always refuses. +fn unprecompose_warnings(comp: &effectcraft_project::Comp, layer: &Layer, nested: &effectcraft_project::Comp) -> Vec { + let mut why = vec![]; + if layer.parent.is_some() { + why.push("the layer has a parent".to_string()); + } + if layer.track_matte.is_some() { + why.push("the layer has a track matte".to_string()); + } + if comp.layers.iter().any(|o| o.id != layer.id && (o.parent == Some(layer.id) || o.track_matte.is_some_and(|m| m.layer == layer.id))) { + why.push("another layer uses it as its parent or track matte (that link is removed)".to_string()); + } + if layer.is_3d() || layer.switches.collapse || layer.switches.adjustment || layer.preserve_transparency { + why.push("the layer is 3D, collapses transformations, is an adjustment layer or preserves transparency".to_string()); + } + if !layer.switches.video || !layer.switches.audio { + why.push("the layer's Video or Audio switch is off".to_string()); + } + if layer.switches.solo || layer.switches.guide { + // Solo hides the comp's other layers and a guide layer is left out of renders; the + // expanded copies would carry neither, so the picture would change. + why.push("the layer's Solo or Guide switch is on".to_string()); + } + if comp.layers.iter().any(|o| o.id != layer.id && refers_to(&o.props, layer.id)) { + why.push("a property of another layer refers to it (that reference is cleared)".to_string()); + } + why.extend(expression_warnings(comp, layer, nested.layers.len())); + if layer.blend_mode != effectcraft_color::BlendMode::default() { + why.push("the layer has a blending mode".to_string()); + } + if layer.stretch != 100.0 || layer.props.prop("timeRemap").is_some() { + why.push("the layer is time-stretched or time-remapped".to_string()); + } + if layer.effects().is_some_and(|e| !e.children.is_empty()) { + why.push("the layer has effects".to_string()); + } + if layer.masks().is_some_and(|m| !m.children.is_empty()) { + why.push("the layer has masks".to_string()); + } + if layer.styles_change_pixels() { + why.push("the layer has layer styles".to_string()); + } + if let Some(tr) = layer.transform() { + let at = |m: &str, d: [f64; 3]| tr.get(m).map(|p| p.value.as_vec3()).unwrap_or(d); + let animated = tr.props().any(|p| !p.keys.is_empty() || p.expr.is_some()); + let separated = tr.get("positionX").is_some(); + if animated || separated { + why.push("its transform is animated, has an expression or has separated dimensions".to_string()); + } else { + let (sc, rot, ori) = (at("scale", [100.0; 3]), at("rotation", [0.0; 3]), at("orientation", [0.0; 3])); + let op = tr.get("opacity").map(|p| p.value.as_f64()).unwrap_or(100.0); + if sc[0] != 100.0 || sc[1] != 100.0 || rot[0] != 0.0 || ori != [0.0; 3] || op != 100.0 { + why.push("its Scale, Rotation or Opacity is not at its default".to_string()); + } + } + } + if nested.layers.iter().any(|l| l.is_camera() || l.is_light()) { + why.push("the composition has a camera or light".to_string()); + } + // Inside the nested comp these composite against the nested stack only; in the parent they + // would act on everything below. + if nested.layers.iter().any(|l| { + l.switches.adjustment || l.switches.collapse || l.is_3d() || l.preserve_transparency || l.blend_mode != effectcraft_color::BlendMode::default() + }) { + why.push("the composition has adjustment, 3D or collapsing layers or layers with a blending mode or Preserve Transparency".to_string()); + } + // A solo hides only the nested comp's other layers; a soloed copy would hide the parent's. + if nested.layers.iter().any(|l| l.switches.solo) { + why.push("the composition has a soloed layer".to_string()); + } + why.extend(sampling_warnings(comp, nested)); + why.extend(position_expression_warnings(layer, nested)); + why +} + +/// What the nested comp's own frame sampling does that the expanded layers lose: a preserved +/// frame rate other than the parent's (its layers then change only on its own frames), and +/// motion blur with a shutter other than the parent's. +fn sampling_warnings(comp: &effectcraft_project::Comp, nested: &effectcraft_project::Comp) -> Vec { + let mut why = vec![]; + if nested.preserve_frame_rate && nested.frame_rate != comp.frame_rate { + why.push("the composition preserves a frame rate other than this one's (its layers would be sampled at this comp's frames)".to_string()); + } + let shutter = nested.shutter_angle != comp.shutter_angle || nested.shutter_phase != comp.shutter_phase; + if shutter && nested.layers.iter().any(|l| l.switches.motion_blur) { + why.push("the composition's motion blur shutter differs from this one's".to_string()); + } + why +} + +/// The move from the pre-comp layer's Position against its Anchor Point, which expansion adds to +/// the Position of the nested comp's unparented layers. +fn placement_offset(layer: &Layer) -> (f64, f64) { + let tr = layer.transform(); + let at = |m: &str| tr.and_then(|t| t.get(m)).map(|p| p.value.as_vec3()).unwrap_or([0.0; 3]); + let (anchor, position) = (at("anchor"), at("position")); + (position[0] - anchor[0], position[1] - anchor[1]) +} + +/// Unparented nested layers whose Position (or a separated axis) has an expression: the move from +/// [`placement_offset`] is added to the stored value and keys, which an expression can ignore. +fn position_expression_warnings(layer: &Layer, nested: &effectcraft_project::Comp) -> Vec { + let (dx, dy) = placement_offset(layer); + if dx == 0.0 && dy == 0.0 { + return vec![]; + } + nested + .layers + .iter() + .filter(|l| l.parent.is_none()) + .filter(|l| l.transform().is_some_and(|tr| ["position", "positionX", "positionY"].iter().any(|m| tr.get(m).is_some_and(|p| p.expr.is_some())))) + .map(|l| format!("layer “{}” has a Position expression, so the move to the pre-comp layer's Position may not apply to it", l.name)) + .collect() +} + +/// One warning per property of another layer in `comp` whose expression names `layer`: by its +/// name in quotes, or as `layer()` with its 1-based index (not on another comp's +/// `comp("…").layer(…)`), and one per expression naming a layer by a number below it while the +/// `added` layers replacing it renumber those. Detection is by text; the expressions are left as +/// they are. +fn expression_warnings(comp: &effectcraft_project::Comp, layer: &Layer, added: usize) -> Vec { + let index = comp.layers.iter().position(|l| l.id == layer.id).map(|i| i.saturating_add(1)); + let quoted = [format!("\"{}\"", layer.name), format!("'{}'", layer.name)]; + let names_it = |text: &str| quoted.iter().any(|q| text.contains(q.as_str())) || index.is_some_and(|i| indexed_layers(text).contains(&i)); + let renumbered = |text: &str| added != 1 && index.is_some_and(|i| indexed_layers(text).iter().any(|n| *n > i)); + let mut out = vec![]; + for o in comp.layers.iter().filter(|o| o.id != layer.id) { + o.props.walk("", &mut |_, p| { + if p.expr.as_ref().is_some_and(|e| !names_it(&e.text) && renumbered(&e.text)) { + out.push(format!("layer “{}” {} names a layer by number, and the layers below “{}” are renumbered", o.name, p.name, layer.name)); + } + if p.expr.as_ref().is_some_and(|e| names_it(&e.text)) { + out.push(format!("layer “{}” {} has an expression that refers to “{}” (it will no longer find it)", o.name, p.name, layer.name)); + } + }); + } + out +} + +/// The indexes expression `text` calls `layer()` with (spaces allowed) on this comp: bare, +/// `thisComp.layer(…)`, not `comp("Other").layer(…)` or `thisLayer(…)`. +fn indexed_layers(text: &str) -> Vec { + text.match_indices("layer(") + .filter_map(|(at, _)| { + let before = text.get(..at).unwrap_or(""); + let on_other = before.ends_with(").") || before.chars().next_back().is_some_and(|c| c.is_alphanumeric() || c == '_'); + if on_other && !before.ends_with("thisComp.") { + return None; + } + let rest = text.get(at + "layer(".len()..).unwrap_or("").trim_start(); + let digits: String = rest.chars().take_while(char::is_ascii_digit).collect(); + let after = rest.get(digits.len()..).unwrap_or("").trim_start(); + digits.parse::().ok().filter(|_| after.starts_with(')')) + }) + .collect() +} + +/// Whether any property (value or key) in `props` holds a reference to layer `id`. +fn refers_to(props: &effectcraft_project::PropGroup, id: LayerId) -> bool { + let is = |v: &effectcraft_keyframe::Value| matches!(v, effectcraft_keyframe::Value::Layer(Some(l)) if *l == id.0); + props.children.iter().any(|c| match c { + effectcraft_project::Node::Prop(p) => is(&p.value) || p.keys.iter().any(|k| is(&k.value)), + effectcraft_project::Node::Group(g) => refers_to(g, id), + }) +} + +/// Clear every reference to layer `id` (`Value::Layer`, value or key) in `props`; references to +/// other layers stay. +fn clear_layer_refs(props: &mut effectcraft_project::PropGroup, id: LayerId) { + let fix = |v: &mut effectcraft_keyframe::Value| { + if matches!(v, effectcraft_keyframe::Value::Layer(Some(l)) if *l == id.0) { + *v = effectcraft_keyframe::Value::Layer(None); + } + }; + for c in &mut props.children { + match c { + effectcraft_project::Node::Prop(p) => { + fix(&mut p.value); + for k in &mut p.keys { + fix(&mut k.value); + } + } + effectcraft_project::Node::Group(g) => clear_layer_refs(g, id), + } + } +} + +/// The layers of `comp` other than `id` let go of it: parent, track matte and property references +/// to it are removed, so nothing points at a layer that is gone. +fn detach_from(comp: &mut effectcraft_project::Comp, id: LayerId) { + for l in comp.layers.iter_mut().filter(|l| l.id != id) { + if l.parent == Some(id) { + l.parent = None; + } + if l.track_matte.is_some_and(|m| m.layer == id) { + l.track_matte = None; + } + clear_layer_refs(&mut l.props, id); + } +} + +/// Replace layer references (`Value::Layer`) found in `props` by `map` (old id → new id), the +/// way copies of a set of layers keep pointing at each other. A reference to a layer outside the +/// set is cleared: it named a layer of the nested comp that is no longer there. +fn remap_layer_values(props: &mut effectcraft_project::PropGroup, map: &[(LayerId, LayerId)]) { + let fix = |v: &mut effectcraft_keyframe::Value| { + if let effectcraft_keyframe::Value::Layer(Some(id)) = v { + *v = effectcraft_keyframe::Value::Layer(map.iter().find(|(o, _)| o.0 == *id).map(|(_, n)| n.0)); + } + }; + for c in &mut props.children { + match c { + effectcraft_project::Node::Prop(p) => { + fix(&mut p.value); + for k in &mut p.keys { + fix(&mut k.value); + } + } + effectcraft_project::Node::Group(g) => remap_layer_values(g, map), + } + } +} + +/// Layer ▸ Un-precompose: expand a selected pre-comp layer back into its composition. The nested +/// comp's layers become copies in this comp at the pre-comp layer's place, in their order and +/// with their keyframes, effects, masks, parenting, mattes, markers and audio; their timing is +/// moved by the pre-comp layer's Start and trimmed to the span it showed, and an Anchor Point +/// different from Position moves the unparented ones by the difference. The nested comp stays in +/// the project. The nested comp's frame no longer clips what the layers draw outside it. +/// +/// A locked pre-comp layer is refused, changing nothing. Anything else that would change the +/// picture or drop something (see [`unprecompose_warnings`]) is an error listing the reasons unless +/// `force` is set; with `force` the layer is expanded the same way, what the pre-comp layer itself +/// carried (effects, masks, styles, transform beyond Position, time remap, blending mode, switches, +/// parent, matte) goes with it, and the other layers' parent, matte and property links to it are +/// removed. The result lists the reasons as `warnings`; `dryRun` only lists them. +pub(super) fn unprecompose(s: &mut Session, p: &Value) -> Result { + let c = "layer.unprecompose"; + let (cid, ids) = layers_p(s, p)?; + let [lid] = ids[..] else { return Err(bad(c, "select exactly one pre-comp layer")) }; + let comp = s.project.comp(cid).ok_or(EngineError::NoComp)?.clone(); + let layer = comp.layer(lid).ok_or(EngineError::NoComp)?.clone(); + let LayerSource::Comp { item } = layer.source else { return Err(bad(c, format!("“{}” is not a pre-comp layer", layer.name))) }; + if layer.switches.locked { + return Err(bad(c, format!("can't un-precompose “{}”: the layer is locked (unlock it first)", layer.name))); + } + let nested = s.project.comp(item).ok_or_else(|| bad(c, "the layer's composition is missing"))?.clone(); + let warnings = unprecompose_warnings(&comp, &layer, &nested); + if b_p(p, "dryRun").unwrap_or(false) { + return Ok(json!({"dryRun": true, "warnings": warnings})); + } + if !warnings.is_empty() && !b_p(p, "force").unwrap_or(false) { + let why = warnings.join("; "); + return Err(bad( + c, + format!( + "can't un-precompose “{}” without changing it: {why} (nothing changed: pass `force` to unpack anyway, or `dryRun` to list the reasons)", + layer.name + ), + )); + } + let (dx, dy) = placement_offset(&layer); + let shown = (layer.in_point.max(layer.start_time), layer.out_point.min(layer.start_time + nested.duration)); + let new = s.edit("Un-precompose", None, |proj, st| { + let mut next = proj.next_id; + let mut copies: Vec = nested.layers.iter().cloned().collect(); + let mut map = vec![]; + for l in &mut copies { + let old = l.id; + crate::cmd::edit::reid(l, &mut next); + map.push((old, l.id)); + } + let link = |id: LayerId| map.iter().find(|(o, _)| *o == id).map(|(_, n)| *n); + for l in &mut copies { + l.parent = l.parent.and_then(link); + l.track_matte = l.track_matte.and_then(|m| link(m.layer).map(|layer| TrackMatte { layer, ..m })); + remap_layer_values(&mut l.props, &map); + l.start_time += layer.start_time; + l.in_point = (l.in_point + layer.start_time).clamp(shown.0, shown.1.max(shown.0)); + l.out_point = (l.out_point + layer.start_time).clamp(l.in_point, shown.1.max(l.in_point)); + if l.parent.is_none() + && let Some(tr) = l.transform_mut() + { + super::offset_position(tr, dx, dy); + } + } + proj.next_id = next; + let target = proj.comp_mut(cid).ok_or(EngineError::NoComp)?; + detach_from(target, lid); + let at = target.layers.iter().position(|l| l.id == lid).unwrap_or(0); + target.layers.retain(|l| l.id != lid); + let mut made = vec![]; + for (k, mut l) in copies.into_iter().enumerate() { + l.name = target.unique_layer_name(&l.name); + made.push(l.id); + target.layers.insert((at + k).min(target.layers.len()), l); + } + for m in &nested.markers { + let mut m = m.clone(); + m.time += layer.start_time; + target.markers.push(m); + } + // Comp markers are kept in time order (`thisComp.marker.key(n)`, next/previous marker). + target.markers.sort_by_key(|m| m.time); + st.selected_layers = made.clone(); + Ok(made) + })?; + Ok(json!({"layers": new.iter().map(|l| l.0).collect::>(), "warnings": warnings})) +} diff --git a/crates/engine/src/menus.rs b/crates/engine/src/menus.rs index e778e02da..ed52d6e03 100644 --- a/crates/engine/src/menus.rs +++ b/crates/engine/src/menus.rs @@ -1018,6 +1018,7 @@ Layer Duplicate and Assign Material | material.duplicateAssign Auto-trace... | layer.autoTrace Pre-compose... | layer.precompose + Un-precompose | layer.unprecompose Scene Edit Detection... | layer.sceneEditDetection Effect Effect Controls | window.panel {"panel":"effectControls"} | F3, Cmd+Shift+T diff --git a/crates/engine/src/tests/menu_cmds.rs b/crates/engine/src/tests/menu_cmds.rs index fc6d4d152..4cf0a4205 100644 --- a/crates/engine/src/tests/menu_cmds.rs +++ b/crates/engine/src/tests/menu_cmds.rs @@ -2066,6 +2066,472 @@ fn precompose_unlinks_layers_left_behind_and_numbers_default_names() { assert_eq!(names, ["Pre-comp 1", "Pre-comp 2"]); } +fn id_named(s: &Session, name: &str) -> u64 { + s.active_comp().unwrap().layers.iter().find(|l| l.name == name).unwrap_or_else(|| panic!("no layer {name}")).id.0 +} + +/// A comp with solids A (keyed Position, parent of B), B and C. +fn precomp_scene() -> Session { + let mut s = comp(); + for (name, color, pos) in [("A", "#ff0000", [150.0, 100.0]), ("B", "#00ff00", [350.0, 220.0]), ("C", "#0000ff", [500.0, 100.0])] { + let l = solid(&mut s, color); + s.execute("layer.rename", json!({"layers": [l], "name": name})).unwrap(); + s.execute("prop.set", json!({"layer": l, "path": "transform/position", "value": pos})).unwrap(); + } + let (a, b) = (id_named(&s, "A"), id_named(&s, "B")); + s.execute("prop.addKey", json!({"layer": a, "path": "transform/position", "time": 0, "value": [150, 100]})).unwrap(); + s.execute("prop.addKey", json!({"layer": a, "path": "transform/position", "time": 1, "value": [300, 200]})).unwrap(); + s.execute("layer.setParent", json!({"layers": [b], "parent": a})).unwrap(); + s +} + +/// Where A, B and C are drawn at a few times. +fn scene_look(s: &mut Session) -> Vec<[f64; 4]> { + let mut out = vec![]; + for t in [0.0, 0.5, 1.0, 2.0] { + s.execute("time.set", json!({"time": t})).unwrap(); + for n in ["A", "B", "C"] { + let id = id_named(s, n); + out.push(seen_bounds(s, id)); + } + } + out +} + +/// Un-precompose (#2918) gives the picture back: precompose A and B, expand the pre-comp layer +/// again, and every layer is drawn where it was at every time, parenting and stacking order are +/// kept, as one undo step. +#[test] +fn unprecompose_restores_what_precompose_nested() { + let mut s = precomp_scene(); + let before = scene_look(&mut s); + let order: Vec = s.active_comp().unwrap().layers.iter().map(|l| l.name.clone()).collect(); + let (a, b) = (id_named(&s, "A"), id_named(&s, "B")); + let r = s.execute("layer.precompose", json!({"layers": [a, b], "name": "Inner"})).unwrap(); + let pre = r["layer"].as_u64().unwrap(); + assert_eq!(s.active_comp().unwrap().layers.len(), 2); + let undo = s.history.undo.len(); + let r = s.execute("layer.unprecompose", json!({"layers": [pre]})).unwrap(); + assert_eq!(r["layers"].as_array().unwrap().len(), 2); + assert_eq!(s.history.undo.len(), undo + 1, "one undo step"); + let after: Vec = s.active_comp().unwrap().layers.iter().map(|l| l.name.clone()).collect(); + assert_eq!(after, order, "the layers are back in their order"); + let (a, b) = (id_named(&s, "A"), id_named(&s, "B")); + assert_eq!(layer(&s, b).parent, Some(effectcraft_project::LayerId(a)), "B is still A's child"); + for (w, g) in before.iter().zip(scene_look(&mut s)) { + assert!(w.iter().zip(g).all(|(x, y)| (x - y).abs() < 1e-6), "a layer moved: {w:?} → {g:?}"); + } + s.execute("edit.undo", json!({})).unwrap(); + assert_eq!(s.active_comp().unwrap().layers.len(), 2, "undo brings the pre-comp layer back"); +} + +/// A pre-comp layer that was moved or started later places the nested layers the same way after it +/// is expanded: its Position (against the Anchor Point) and its Start carry over. +#[test] +fn unprecompose_carries_the_precomp_layers_position_and_start() { + let mut s = precomp_scene(); + let before = scene_look(&mut s); + let (a, b) = (id_named(&s, "A"), id_named(&s, "B")); + let pre = s.execute("layer.precompose", json!({"layers": [a, b], "name": "Inner"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("prop.set", json!({"layer": pre, "path": "transform/position", "value": [360, 160]})).unwrap(); + s.execute("layer.unprecompose", json!({"layers": [pre]})).unwrap(); + // The pre-comp's Anchor Point sat at the comp centre (320, 180): everything moved by (+40, −20). + let after = scene_look(&mut s); + for (i, (w, g)) in before.iter().zip(after).enumerate() { + let n = i % 3; + let (dx, dy) = if n < 2 { (40.0, -20.0) } else { (0.0, 0.0) }; + let want = [w[0] + dx, w[1] + dy, w[2] + dx, w[3] + dy]; + assert!(want.iter().zip(g).all(|(x, y)| (x - y).abs() < 1e-6), "layer {n}: wanted {want:?}, drawn {g:?}"); + } + + // Starting later: the nested layers start later by as much, and are trimmed to the span shown. + let mut s = precomp_scene(); + let (a, b) = (id_named(&s, "A"), id_named(&s, "B")); + let pre = s.execute("layer.precompose", json!({"layers": [a, b], "name": "Inner"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("layer.timing", json!({"layers": [pre], "op": "set", "start": 2.0})).unwrap(); + let start = layer(&s, pre).start_time; + s.execute("layer.unprecompose", json!({"layers": [pre]})).unwrap(); + let a = layer(&s, id_named(&s, "A")); + assert_eq!(a.start_time, start, "the nested layer's time 0 sits at the pre-comp layer's Start"); + assert!(a.in_point >= start, "and it doesn't show before it"); +} + +/// A pre-comp scene: the outer comp, the nested comp and the pre-comp layer (A and B nested). +fn unprecompose_scene() -> (Session, effectcraft_project::ItemId, u64, u64) { + let mut s = precomp_scene(); + let (a, b) = (id_named(&s, "A"), id_named(&s, "B")); + let outer = s.active_comp_id().unwrap(); + let r = s.execute("layer.precompose", json!({"layers": [a, b], "name": "Inner"})).unwrap(); + (s, outer, r["comp"].as_u64().unwrap(), r["layer"].as_u64().unwrap()) +} + +/// Everything un-precompose could change: every comp (layers and markers) and the item count. +fn whole_project(s: &Session) -> (Vec, usize) { + (s.project.comps().map(|(_, c)| c.clone()).collect(), s.project.items.len()) +} + +/// Without `force`, a reason is an error naming it that changes nothing (no undo step), and the +/// dry run lists it; with `force` the layer is unpacked anyway in one undo step, the result lists +/// the reason as a warning, and undo restores the exact project. +fn warned_then_forced(s: &mut Session, pre: u64, what: &str) { + let undo = s.history.undo.len(); + let before = whole_project(s); + let e = s.execute("layer.unprecompose", json!({"layers": [pre]})).expect_err(what).to_string(); + assert!(e.contains(what) && e.contains("force"), "{what}: {e}"); + assert!(whole_project(s) == before, "{what}: nothing changed"); + assert_eq!(s.history.undo.len(), undo, "{what}: no undo step"); + let dry = s.execute("layer.unprecompose", json!({"layers": [pre], "dryRun": true})).unwrap(); + assert!(dry["warnings"].as_array().unwrap().iter().any(|w| w.as_str().unwrap().contains(what)), "{what}: {dry}"); + assert!(whole_project(s) == before, "{what}: the dry run changed nothing"); + let r = s.execute("layer.unprecompose", json!({"layers": [pre], "force": true})).expect(what); + assert!(r["warnings"].as_array().unwrap().iter().any(|w| w.as_str().unwrap().contains(what)), "{what}: {r}"); + assert!(r["layers"].as_array().unwrap().len() >= 2, "{what}: A and B are back"); + assert_eq!(s.history.undo.len(), undo + 1, "{what}: one undo step"); + let comp = s.active_comp().unwrap(); + assert!(comp.layers.iter().all(|l| l.id.0 != pre), "{what}: the pre-comp layer is gone"); + for l in &comp.layers { + assert!(l.parent.is_none_or(|p| comp.layer(p).is_some()), "{what}: {} has a dangling parent", l.name); + assert!(l.track_matte.is_none_or(|m| comp.layer(m.layer).is_some()), "{what}: {} has a dangling matte", l.name); + } + scene_look(s); + s.execute("edit.undo", json!({})).unwrap(); + assert!(whole_project(s) == before, "{what}: undo restores the exact project"); +} + +/// What the pre-comp layer itself adds to the look is a warning (#2918): an error listing it +/// without `force`, unpacked anyway with it. +#[test] +fn unprecompose_warns_about_what_the_precomp_layer_itself_adds() { + let fresh = unprecompose_scene; + let (mut s, _, _, pre) = fresh(); + s.execute("prop.set", json!({"layer": pre, "path": "transform/opacity", "value": 50})).unwrap(); + warned_then_forced(&mut s, pre, "Opacity"); + let (mut s, _, _, pre) = fresh(); + s.execute("prop.set", json!({"layer": pre, "path": "transform/rotation", "value": 10})).unwrap(); + warned_then_forced(&mut s, pre, "Rotation"); + let (mut s, _, _, pre) = fresh(); + s.execute("prop.addKey", json!({"layer": pre, "path": "transform/scale", "time": 0, "value": [100, 100]})).unwrap(); + warned_then_forced(&mut s, pre, "animated"); + for switch in ["solo", "guide"] { + let (mut s, _, _, pre) = fresh(); + s.execute("layer.setSwitch", json!({"layers": [pre], "switch": switch, "value": true})).unwrap(); + warned_then_forced(&mut s, pre, "Solo or Guide"); + } + for switch in ["video", "audio"] { + let (mut s, _, _, pre) = fresh(); + s.execute("layer.setSwitch", json!({"layers": [pre], "switch": switch, "value": false})).unwrap(); + warned_then_forced(&mut s, pre, "Video or Audio"); + } + for switch in ["threeD", "collapse", "adjustment", "preserveTransparency"] { + let (mut s, _, _, pre) = fresh(); + s.execute("layer.setSwitch", json!({"layers": [pre], "switch": switch, "value": true})).unwrap(); + warned_then_forced(&mut s, pre, "3D, collapses"); + } + let (mut s, _, _, pre) = fresh(); + let c = id_named(&s, "C"); + s.execute("layer.setParent", json!({"layers": [pre], "parent": c})).unwrap(); + warned_then_forced(&mut s, pre, "has a parent"); + let (mut s, _, _, pre) = fresh(); + let c = id_named(&s, "C"); + s.execute("layer.setTrackMatte", json!({"layer": pre, "matte": c})).unwrap(); + warned_then_forced(&mut s, pre, "has a track matte"); + let (mut s, _, _, pre) = fresh(); + s.execute("effect.apply", json!({"layers": [pre], "effect": "Gaussian Blur"})).unwrap(); + warned_then_forced(&mut s, pre, "effects"); + let (mut s, _, _, pre) = fresh(); + s.execute("layer.addMask", json!({"layer": pre})).unwrap(); + warned_then_forced(&mut s, pre, "masks"); + let (mut s, _, _, pre) = fresh(); + s.execute("layer.style.add", json!({"layers": [pre], "style": "dropShadow"})).unwrap(); + warned_then_forced(&mut s, pre, "layer styles"); + let (mut s, _, _, pre) = fresh(); + s.execute("layer.setBlendMode", json!({"layers": [pre], "mode": "Multiply"})).unwrap(); + warned_then_forced(&mut s, pre, "blending mode"); + let (mut s, _, _, pre) = fresh(); + s.execute("layer.timeStretch", json!({"layers": [pre], "percent": 200.0})).unwrap(); + warned_then_forced(&mut s, pre, "time-stretched"); + let (mut s, _, _, pre) = fresh(); + s.execute("layer.enableTimeRemap", json!({"layers": [pre], "value": true})).unwrap(); + warned_then_forced(&mut s, pre, "time-remapped"); + // A layer that is not a pre-comp, and a selection of several, are refused, even forced. + let (mut s, _, _, pre) = fresh(); + let c = id_named(&s, "C"); + assert!(s.execute("layer.unprecompose", json!({"layers": [c], "force": true})).is_err()); + assert!(s.execute("layer.unprecompose", json!({"layers": [pre, c], "force": true})).is_err()); +} + +/// What only holds inside the nested comp (a camera or light, a soloed, 3D, adjustment or +/// Preserve Transparency layer) is a warning too. +#[test] +fn unprecompose_warns_about_what_only_holds_inside_the_nested_comp() { + let inside = |switch: &str, what: &str| { + let (mut s, outer, inner, pre) = unprecompose_scene(); + s.execute("comp.open", json!({"comp": inner})).unwrap(); + let a = id_named(&s, "A"); + s.execute("layer.setSwitch", json!({"layers": [a], "switch": switch, "value": true})).unwrap(); + s.execute("comp.open", json!({"comp": outer.0})).unwrap(); + warned_then_forced(&mut s, pre, what); + }; + inside("solo", "soloed layer"); + inside("preserveTransparency", "Preserve Transparency"); + inside("adjustment", "adjustment, 3D"); + inside("threeD", "adjustment, 3D"); + let (mut s, outer, inner, pre) = unprecompose_scene(); + s.execute("comp.open", json!({"comp": inner})).unwrap(); + s.execute("layer.newLight", json!({})).unwrap(); + s.execute("comp.open", json!({"comp": outer.0})).unwrap(); + warned_then_forced(&mut s, pre, "camera or light"); +} + +/// A locked pre-comp layer is the one hard stop: refused with and without `force`, and by the dry +/// run, changing nothing. +#[test] +fn unprecompose_refuses_a_locked_layer_even_forced() { + let (mut s, _, _, pre) = unprecompose_scene(); + s.execute("prop.set", json!({"layer": pre, "path": "transform/opacity", "value": 50})).unwrap(); + s.execute("layer.setSwitch", json!({"layers": [pre], "switch": "lock", "value": true})).unwrap(); + let undo = s.history.undo.len(); + let before = whole_project(&s); + for p in [json!({"layers": [pre]}), json!({"layers": [pre], "force": true}), json!({"layers": [pre], "dryRun": true})] { + let e = s.execute("layer.unprecompose", p.clone()).expect_err("locked").to_string(); + assert!(e.contains("locked"), "{p}: {e}"); + assert!(whole_project(&s) == before, "{p}: nothing changed"); + assert_eq!(s.history.undo.len(), undo, "{p}: no undo step"); + } + // A clean, locked pre-comp layer is refused too. + let (mut s, _, _, pre) = unprecompose_scene(); + s.execute("layer.setSwitch", json!({"layers": [pre], "switch": "lock", "value": true})).unwrap(); + assert!(s.execute("layer.unprecompose", json!({"layers": [pre]})).unwrap_err().to_string().contains("locked")); +} + +/// Layers that use the pre-comp layer as parent, track matte or in a property lose that link when +/// it is unpacked by force; links to other layers stay, and nothing dangles or crashes. +#[test] +fn unprecompose_forced_drops_the_links_other_layers_had_to_it() { + let (mut s, outer, _, pre) = unprecompose_scene(); + let c = id_named(&s, "C"); + let d = solid(&mut s, "#ffff00"); + s.execute("layer.rename", json!({"layers": [d], "name": "D"})).unwrap(); + s.execute("layer.setParent", json!({"layers": [c], "parent": pre})).unwrap(); + s.execute("layer.setTrackMatte", json!({"layer": d, "matte": pre})).unwrap(); + s.execute("effect.apply", json!({"layers": [c], "effect": "Set Matte"})).unwrap(); + s.execute("effect.apply", json!({"layers": [d], "effect": "Set Matte"})).unwrap(); + { + let proj = std::sync::Arc::make_mut(&mut s.project); + let comp = proj.comp_mut(outer).unwrap(); + let set = |comp: &mut effectcraft_project::Comp, on: u64, to: u64| { + let l = comp.layer_mut(effectcraft_project::LayerId(on)).unwrap(); + l.props.walk_mut(&mut |p| { + if matches!(p.value, KV::Layer(_)) { + p.value = KV::Layer(Some(to)); + } + }); + }; + set(comp, c, pre); + set(comp, d, c); + } + let refs = |s: &Session, on: u64| { + let mut out = vec![]; + layer(s, on).props.walk("", &mut |_, p| { + if let KV::Layer(v) = p.value { + out.push(v); + } + }); + out + }; + assert_eq!(refs(&s, c), vec![Some(pre)], "the test set C's reference"); + let e = s.execute("layer.unprecompose", json!({"layers": [pre]})).expect_err("used by others").to_string(); + assert!(e.contains("parent or track matte") && e.contains("refers to it"), "{e}"); + let undo = s.history.undo.len(); + let before = whole_project(&s); + let r = s.execute("layer.unprecompose", json!({"layers": [pre], "force": true})).unwrap(); + let w = r["warnings"].to_string(); + assert!(w.contains("link is removed") && w.contains("reference is cleared"), "{w}"); + assert_eq!(layer(&s, c).parent, None, "C lost its parent"); + assert!(layer(&s, d).track_matte.is_none(), "D lost its matte"); + assert_eq!(refs(&s, c), vec![None], "C's reference to the pre-comp layer is cleared"); + assert_eq!(refs(&s, d), vec![Some(c)], "D's reference to C stays"); + scene_look(&mut s); + s.execute("edit.undo", json!({})).unwrap(); + assert!(whole_project(&s) == before, "undo restores the links"); + assert_eq!(s.history.undo.len(), undo); +} + +/// Expressions of other layers that name the pre-comp layer (in quotes, or by its index) would no +/// longer find it: one warning per property; an expression naming another layer is not one. Forced, +/// the expressions stay as they are and the comp still renders. +#[test] +fn unprecompose_warns_about_expressions_that_refer_to_it() { + let (mut s, _, _, pre) = unprecompose_scene(); + let c = id_named(&s, "C"); + let d = solid(&mut s, "#ffff00"); + s.execute("layer.rename", json!({"layers": [d], "name": "D"})).unwrap(); + let index = s.active_comp().unwrap().layers.iter().position(|l| l.id.0 == pre).unwrap() + 1; + let set = |s: &mut Session, on: u64, path: &str, text: &str| { + s.execute("prop.setExpression", json!({"layer": on, "path": path, "expression": text})).unwrap(); + }; + set(&mut s, c, "transform/position", "thisComp.layer(\"Inner\").transform.position"); + set(&mut s, c, "transform/rotation", &format!("thisComp.layer( {index} ).transform.rotation")); + // Naming another layer, or another comp's layer at the same index, is no reference to it. + set(&mut s, d, "transform/position", "thisComp.layer(\"C\").transform.position"); + set(&mut s, d, "transform/rotation", &format!("comp(\"Other\").layer({index}).transform.rotation")); + let dry = s.execute("layer.unprecompose", json!({"layers": [pre], "dryRun": true})).unwrap(); + let exprs: Vec = + dry["warnings"].as_array().unwrap().iter().filter_map(|w| w.as_str()).filter(|w| w.contains("expression")).map(str::to_string).collect(); + assert_eq!(exprs.len(), 2, "{exprs:?}"); + assert!(exprs.iter().all(|w| w.contains("layer “C”") && w.contains("“Inner”") && w.contains("no longer find it")), "{exprs:?}"); + assert!(exprs.iter().any(|w| w.contains("Position")) && exprs.iter().any(|w| w.contains("Rotation")), "{exprs:?}"); + warned_then_forced(&mut s, pre, "has an expression that refers to “Inner”"); + // Forced, the expressions are left as written. + s.execute("layer.unprecompose", json!({"layers": [pre], "force": true})).unwrap(); + let text = layer(&s, c).transform().unwrap().get("position").unwrap().expr.clone().unwrap().text; + assert_eq!(text, "thisComp.layer(\"Inner\").transform.position"); + scene_look(&mut s); +} + +/// An expression naming a layer by a number below the pre-comp layer points at another layer once +/// the nested comp's two layers replace it: a warning. One naming a number above it does not move. +#[test] +fn unprecompose_warns_when_it_renumbers_the_layers_an_expression_names() { + let (mut s, _, _, pre) = unprecompose_scene(); + let c = id_named(&s, "C"); + let index = s.active_comp().unwrap().layers.iter().position(|l| l.id.0 == pre).unwrap() + 1; + let warned = |s: &mut Session, number: usize| { + let text = format!("thisComp.layer({number}).transform.rotation"); + s.execute("prop.setExpression", json!({"layer": c, "path": "transform/rotation", "expression": text})).unwrap(); + let dry = s.execute("layer.unprecompose", json!({"layers": [pre], "dryRun": true})).unwrap(); + dry["warnings"].as_array().unwrap().iter().filter_map(|w| w.as_str()).any(|w| w.contains("by number")) + }; + assert!(warned(&mut s, index + 1), "a number below it"); + assert!(!warned(&mut s, index - 1), "a number above it"); +} + +/// A nested comp that preserves its own frame rate (10 fps in a 30 fps comp) samples its layers on +/// its own frames; expanded, they would change on every frame of the parent: a warning. Without +/// Preserve Frame Rate the nested layers are sampled at the parent's times already: no warning. +#[test] +fn unprecompose_warns_when_the_nested_comp_preserves_another_frame_rate() { + let (mut s, _, inner, pre) = unprecompose_scene(); + s.execute("comp.settings", json!({"comp": inner, "frameRate": 10})).unwrap(); + let dry = s.execute("layer.unprecompose", json!({"layers": [pre], "dryRun": true})).unwrap(); + assert_eq!(dry["warnings"], json!([]), "a different rate alone samples at the parent's times"); + s.execute("comp.settings", json!({"comp": inner, "preserveFrameRate": true})).unwrap(); + warned_then_forced(&mut s, pre, "preserves a frame rate"); + + // A motion-blurred nested layer under another shutter would be blurred with the parent's. + let (mut s, outer, inner, pre) = unprecompose_scene(); + s.execute("comp.settings", json!({"comp": inner, "shutterAngle": 90})).unwrap(); + let dry = s.execute("layer.unprecompose", json!({"layers": [pre], "dryRun": true})).unwrap(); + assert_eq!(dry["warnings"], json!([]), "no layer uses motion blur"); + s.execute("comp.open", json!({"comp": inner})).unwrap(); + let a = id_named(&s, "A"); + s.execute("layer.setSwitch", json!({"layers": [a], "switch": "motionBlur", "value": true})).unwrap(); + s.execute("comp.open", json!({"comp": outer.0})).unwrap(); + warned_then_forced(&mut s, pre, "motion blur shutter"); +} + +/// The pre-comp layer's move (Position against Anchor Point) is added to the stored Position of +/// unparented nested layers; one whose Position has an expression may ignore it: a warning, only +/// when there is a move. +#[test] +fn unprecompose_warns_about_position_expressions_it_cannot_move() { + let (mut s, outer, inner, pre) = unprecompose_scene(); + s.execute("comp.open", json!({"comp": inner})).unwrap(); + let a = id_named(&s, "A"); + s.execute("prop.setExpression", json!({"layer": a, "path": "transform/position", "expression": "[100, 100]"})).unwrap(); + s.execute("comp.open", json!({"comp": outer.0})).unwrap(); + let dry = s.execute("layer.unprecompose", json!({"layers": [pre], "dryRun": true})).unwrap(); + assert_eq!(dry["warnings"], json!([]), "no move, nothing to lose"); + s.execute("prop.set", json!({"layer": pre, "path": "transform/position", "value": [360, 160]})).unwrap(); + warned_then_forced(&mut s, pre, "layer “A” has a Position expression"); +} + +/// Expanded copies keep pointing at each other: a track matte and a layer-valued effect property +/// on a nested layer follow the copy of the layer they named, and the nested comp's markers are +/// moved by the pre-comp layer's Start and merged in time order with the comp's own. +#[test] +fn unprecompose_remaps_mattes_layer_values_and_merges_markers_in_order() { + let (mut s, outer, inner, pre) = unprecompose_scene(); + s.execute("comp.open", json!({"comp": inner})).unwrap(); + let (a, b) = (id_named(&s, "A"), id_named(&s, "B")); + s.execute("layer.setParent", json!({"layers": [b], "parent": null})).unwrap(); + s.execute("layer.setTrackMatte", json!({"layer": b, "matte": a})).unwrap(); + s.execute("effect.apply", json!({"layers": [b], "effect": "Set Matte"})).unwrap(); + { + let proj = std::sync::Arc::make_mut(&mut s.project); + let l = proj.comp_mut(effectcraft_project::ItemId(inner)).unwrap().layer_mut(effectcraft_project::LayerId(b)).unwrap(); + l.props.walk_mut(&mut |p| { + if matches!(p.value, KV::Layer(_)) { + p.value = KV::Layer(Some(a)); + } + }); + } + for t in [2.5, 0.5] { + s.execute("comp.addMarker", json!({"time": t, "comment": format!("in {t}")})).unwrap(); + } + s.execute("comp.open", json!({"comp": outer.0})).unwrap(); + s.execute("comp.addMarker", json!({"time": 2.0, "comment": "out"})).unwrap(); + s.execute("layer.timing", json!({"layers": [pre], "op": "set", "start": 1.0})).unwrap(); + s.execute("layer.unprecompose", json!({"layers": [pre]})).unwrap(); + let (a, b) = (layer(&s, id_named(&s, "A")), layer(&s, id_named(&s, "B"))); + assert_eq!(b.track_matte.map(|m| m.layer), Some(a.id), "B's matte is the copy of A"); + let mut refs = vec![]; + b.props.walk("", &mut |_, p| { + if let KV::Layer(v) = p.value { + refs.push(v); + } + }); + assert_eq!(refs, vec![Some(a.id.0)], "Set Matte names the copy of A"); + let markers: Vec<(f64, String)> = s.active_comp().unwrap().markers.iter().map(|m| (m.time.seconds(), m.comment.clone())).collect(); + let want = [(1.5, "in 0.5"), (2.0, "out"), (3.5, "in 2.5")]; + assert_eq!(markers.len(), 3, "{markers:?}"); + for ((t, c), (wt, wc)) in markers.iter().zip(want) { + assert!((t - wt).abs() < 1e-9 && c == wc, "{markers:?}"); + } + scene_look(&mut s); +} + +/// Every reason at once, forced: unpacked without a crash, one undo step, undone exactly. +#[test] +fn unprecompose_forced_with_everything_at_once() { + let (mut s, outer, inner, pre) = unprecompose_scene(); + let c = id_named(&s, "C"); + s.execute("comp.open", json!({"comp": inner})).unwrap(); + let a = id_named(&s, "A"); + for sw in ["solo", "threeD", "adjustment", "preserveTransparency"] { + s.execute("layer.setSwitch", json!({"layers": [a], "switch": sw, "value": true})).unwrap(); + } + s.execute("layer.newCamera", json!({})).unwrap(); + s.execute("comp.open", json!({"comp": outer.0})).unwrap(); + s.execute("prop.set", json!({"layer": pre, "path": "transform/opacity", "value": 20})).unwrap(); + s.execute("prop.addKey", json!({"layer": pre, "path": "transform/rotation", "time": 0, "value": 30})).unwrap(); + s.execute("effect.apply", json!({"layers": [pre], "effect": "Gaussian Blur"})).unwrap(); + s.execute("layer.addMask", json!({"layer": pre})).unwrap(); + s.execute("layer.style.add", json!({"layers": [pre], "style": "dropShadow"})).unwrap(); + s.execute("layer.setBlendMode", json!({"layers": [pre], "mode": "Screen"})).unwrap(); + s.execute("layer.enableTimeRemap", json!({"layers": [pre], "value": true})).unwrap(); + s.execute("layer.timeStretch", json!({"layers": [pre], "percent": -50.0})).unwrap(); + for sw in ["solo", "guide", "threeD", "collapse", "adjustment", "preserveTransparency"] { + s.execute("layer.setSwitch", json!({"layers": [pre], "switch": sw, "value": true})).unwrap(); + } + s.execute("layer.setSwitch", json!({"layers": [pre], "switch": "video", "value": false})).unwrap(); + s.execute("layer.setParent", json!({"layers": [pre], "parent": c})).unwrap(); + s.execute("layer.setTrackMatte", json!({"layer": pre, "matte": c})).unwrap(); + let undo = s.history.undo.len(); + let before = whole_project(&s); + let r = s.execute("layer.unprecompose", json!({"layers": [pre], "force": true})).unwrap(); + assert!(r["warnings"].as_array().unwrap().len() >= 10, "{r}"); + // The undo history is capped (32 levels by default), so its length may stay; one undo is what + // takes the whole unpack back. + assert!(s.history.undo.len() == undo + 1 || s.history.undo.len() == undo, "one undo step"); + assert!(whole_project(&s) != before, "it unpacked"); + scene_look(&mut s); + assert!(s.history.redo.is_empty()); + s.execute("edit.undo", json!({})).unwrap(); + assert_eq!(s.history.redo.len(), 1, "one undo step took it all back"); + assert!(whole_project(&s) == before, "undo restores the exact project"); +} + /// Quick Set Anchor (#2967): every one of the nine points moves the Anchor Point of a rotated, /// scaled layer with keyed Position to that point of its content, and the layer looks the same /// on every frame (Position and its keys are compensated), in one undo step. diff --git a/crates/ui-egui/src/i18n/ui.rs b/crates/ui-egui/src/i18n/ui.rs index 09c8b3af0..15bf774f9 100644 --- a/crates/ui-egui/src/i18n/ui.rs +++ b/crates/ui-egui/src/i18n/ui.rs @@ -10290,6 +10290,7 @@ mod tests { ("panels/comp_settings.rs", include_str!("../panels/comp_settings.rs")), ("panels/content_fill_panel.rs", include_str!("../panels/content_fill_panel.rs")), ("panels/delete_items.rs", include_str!("../panels/delete_items.rs")), + ("panels/unprecompose.rs", include_str!("../panels/unprecompose.rs")), ("panels/gradient_editor.rs", include_str!("../panels/gradient_editor.rs")), ("panels/dialogs.rs", include_str!("../panels/dialogs.rs")), ("panels/dialogs_3d.rs", include_str!("../panels/dialogs_3d.rs")), diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 88f99a657..795a01e1e 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -156,6 +156,8 @@ pub enum Dialog { /// Import an After Effects project although some of it cannot be imported exactly? /// (`panels::aep_losses`). AepLosses, + /// Un-precompose although it changes the picture or drops something? (`panels::unprecompose`). + Unprecompose, /// A gradient property's Gradient Editor (`panels::gradient_editor`, `prop.editGradient`). GradientEditor, /// Delete a user template from Home? (`panels::templates`). diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs index 4d2c15b2a..0c7573c91 100644 --- a/crates/ui-egui/src/menus/invoke.rs +++ b/crates/ui-egui/src/menus/invoke.rs @@ -284,6 +284,10 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V if crate::panels::delete_items::guard(app, id, ¶ms) { return Ok(json!({"dialog": "deleteItems"})); } + // Un-precompose that would change the picture lists why and asks before unpacking anyway. + if crate::panels::unprecompose::guard(app, id, ¶ms)? { + return Ok(json!({"dialog": "unprecompose"})); + } // An After Effects import with a path that loses something asks first (the menu's file // dialog asks in `run_with_picked`). if params.get("path").is_some() && crate::panels::aep_losses::guard(app, id, ¶ms)? { diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index 26ff1b148..ccff0fdcd 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -56,6 +56,7 @@ pub mod text_panels; pub mod text_range_handles; pub mod timeline; pub mod tracker; +pub mod unprecompose; pub mod unsaved; pub mod viewer; pub mod viewer_drop; diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rs index 08f416623..458ce60a9 100644 --- a/crates/ui-egui/src/panels/dialogs.rs +++ b/crates/ui-egui/src/panels/dialogs.rs @@ -71,6 +71,8 @@ pub struct DialogState { /// Deleting Project items in use: the deletion waiting on the prompt. pub delete_items: super::delete_items::Pending, pub aep_losses: super::aep_losses::Pending, + /// Un-precompose with reasons: the unpack waiting on the prompt. + pub unprecompose: super::unprecompose::Pending, /// The Gradient Editor's draft and the property it edits. pub gradient: super::gradient_editor::Draft, /// Preview of the settings dialog being edited (Solid, Camera, Light, Composition Settings). @@ -323,6 +325,7 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { Dialog::UnsavedChanges => super::unsaved::show(app, ctx, &t), Dialog::DeleteItems => super::delete_items::show(app, ctx, &t), Dialog::AepLosses => super::aep_losses::show(app, ctx, &t), + Dialog::Unprecompose => super::unprecompose::show(app, ctx, &t), Dialog::GradientEditor => super::gradient_editor::show(app, ctx, &t), Dialog::DeleteTemplate => super::templates::show_delete(app, ctx, &t), } diff --git a/crates/ui-egui/src/panels/unprecompose.rs b/crates/ui-egui/src/panels/unprecompose.rs new file mode 100644 index 000000000..55f3545d5 --- /dev/null +++ b/crates/ui-egui/src/panels/unprecompose.rs @@ -0,0 +1,181 @@ +//! Layer ▸ Un-precompose from the menu: when expanding the pre-comp layer would change the picture +//! or drop something (the command's dry run lists why), the reasons are shown first and the user +//! chooses to cancel or to unpack anyway (`force`). Cancel changes nothing; a pre-comp layer +//! without reasons is unpacked at once, and one that cannot be unpacked at all (locked, not a +//! pre-comp) reports its error without the prompt. Agents running `layer.unprecompose` with +//! `engine.execute` are never asked: they pass `force` or get the error listing the reasons. +//! +//! Automation ids: `dialog.unprecompose.force`, `dialog.unprecompose.cancel`. + +use crate::i18n::tr; +use egui::vec2; +use serde_json::{Value, json}; + +use crate::theme::Tokens; +use crate::{Dialog, EffectcraftApp}; + +const COMMAND: &str = "layer.unprecompose"; + +/// The unpack waiting on the prompt: its params and the dry run's reasons. +#[derive(Clone, Debug, Default)] +pub struct Pending { + pub command: Option<(Value, Vec)>, +} + +/// Whether command `id` with `params` needs the prompt first. When it does, the prompt opens +/// holding the command and the caller must not run it. `Err` when the dry run fails (a locked +/// layer, a layer that is not a pre-comp, several layers), with the message. +pub fn guard(app: &mut EffectcraftApp, id: &str, params: &Value) -> Result { + if id != COMMAND || params.get("force") == Some(&Value::Bool(true)) || params.get("dryRun") == Some(&Value::Bool(true)) { + return Ok(false); + } + let mut dry = params.as_object().cloned().unwrap_or_default(); + dry.insert("dryRun".into(), Value::Bool(true)); + let r = app.session.execute(COMMAND, Value::Object(dry)).map_err(|e| e.to_string())?; + let warnings: Vec = r["warnings"].as_array().map(|w| w.iter().filter_map(Value::as_str).map(str::to_string).collect()).unwrap_or_default(); + if warnings.is_empty() { + return Ok(false); + } + // The layer the warnings are about, whatever is selected by the time the prompt is answered. + let mut pinned = params.as_object().cloned().unwrap_or_default(); + if !pinned.contains_key("layer") && !pinned.contains_key("layers") { + pinned.insert("layers".into(), json!(app.session.state.selected_layers.iter().map(|l| l.0).collect::>())); + } + if let Some(comp) = app.session.active_comp_id().filter(|_| !pinned.contains_key("comp")) { + pinned.insert("comp".into(), json!(comp.0)); + } + app.dialog_state.unprecompose.command = Some((Value::Object(pinned), warnings)); + app.dialog = Some(Dialog::Unprecompose); + Ok(true) +} + +pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) { + let Some((_, warnings)) = app.dialog_state.unprecompose.command.clone() else { + app.dialog = None; + return; + }; + let mut answer: Option = None; + super::dialogs::modal_vertical(ctx, "Un-precompose", vec2(520.0, 300.0), t, |ui| { + ui.label(egui::RichText::new(tr("Unpacking this pre-comp layer changes the picture or drops something:")).color(t.tab_text_active)); + ui.add_space(6.0); + egui::ScrollArea::vertical().max_height(160.0).show(ui, |ui| { + for w in &warnings { + ui.label(egui::RichText::new(format!("• {w}")).color(t.tab_text_active)); + } + }); + ui.add_space(4.0); + ui.label(egui::RichText::new(tr("What the pre-comp layer itself carries is dropped. You can undo this.")).color(t.text_dim).size(11.0)); + ui.add_space(14.0); + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + let label = tr("Unpack Anyway"); + let r = ui.button(label); + app.auto.add("dialog.unprecompose.force", r.rect, label); + if r.clicked() { + answer = Some(true); + } + let r = ui.button(tr("Cancel")); + app.auto.add("dialog.unprecompose.cancel", r.rect, "Cancel"); + if r.clicked() { + answer = Some(false); + } + }); + }); + if answer.is_none() && ctx.input(|i| i.key_pressed(egui::Key::Escape)) { + answer = Some(false); + } + if let Some(go) = answer { + finish(app, ctx, go); + } +} + +/// The prompt's answer: Cancel (`false`) drops the unpack, Unpack Anyway runs it with `force`. +fn finish(app: &mut EffectcraftApp, ctx: &egui::Context, go: bool) { + app.dialog = None; + let Some((params, _)) = app.dialog_state.unprecompose.command.take() else { return }; + if go { + // An error is already in the status bar. + let _ = crate::menus::run_engine(app, ctx, COMMAND, forced(¶ms)); + } +} + +/// `params` with the user's consent to the reasons the prompt listed. +fn forced(params: &Value) -> Value { + let mut p = params.as_object().cloned().unwrap_or_default(); + p.insert("force".into(), json!(true)); + Value::Object(p) +} + +#[cfg(test)] +mod tests { + use super::*; + use effectcraft_engine::Session; + + /// A comp with two solids nested into a pre-comp; the pre-comp layer's id. + fn scene(app: &mut EffectcraftApp) -> u64 { + let s = &mut app.session; + s.execute("comp.new", json!({"name": "Main", "width": 640, "height": 360, "duration": 4.0, "fps": 24.0})).unwrap(); + let a = s.execute("layer.newSolid", json!({"color": "#ff0000"})).unwrap()["layer"].as_u64().unwrap(); + let b = s.execute("layer.newSolid", json!({"color": "#00ff00"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("layer.precompose", json!({"layers": [a, b], "name": "Inner"})).unwrap()["layer"].as_u64().unwrap() + } + + fn layer_count(s: &Session) -> usize { + s.active_comp().map_or(0, |c| c.layers.len()) + } + + fn fresh() -> (egui::Context, EffectcraftApp) { + let ctx = egui::Context::default(); + let app = EffectcraftApp::new(Session::default()); + crate::theme::install(&ctx, &app.tokens, crate::i18n::language(&app)); + (ctx, app) + } + + #[test] + fn the_menu_asks_and_unpack_anyway_unpacks() { + let (ctx, mut app) = fresh(); + let pre = scene(&mut app); + app.session.execute("prop.set", json!({"layer": pre, "path": "transform/opacity", "value": 50})).unwrap(); + let params = json!({"layers": [pre]}); + let r = crate::menus::invoke(&mut app, &ctx, COMMAND, params.clone()).unwrap(); + assert_eq!(r, json!({"dialog": "unprecompose"})); + assert_eq!(app.dialog, Some(Dialog::Unprecompose)); + let (_, warnings) = app.dialog_state.unprecompose.command.clone().unwrap(); + assert!(warnings.iter().any(|w| w.contains("Opacity")), "{warnings:?}"); + // Drawn, the prompt offers both answers under their automation ids. + crate::panels::dialogs::press_key(&mut app, &ctx, egui::Key::A, egui::Modifiers::NONE); + assert!(app.auto.find("dialog.unprecompose.force").is_some() && app.auto.find("dialog.unprecompose.cancel").is_some()); + // Escape is Cancel: nothing changes. + crate::panels::dialogs::press_key(&mut app, &ctx, egui::Key::Escape, egui::Modifiers::NONE); + assert!(app.dialog.is_none() && app.dialog_state.unprecompose.command.is_none()); + assert_eq!(layer_count(&app.session), 1, "Cancel left the pre-comp layer"); + // Unpack Anyway unpacks. + crate::menus::invoke(&mut app, &ctx, COMMAND, params).unwrap(); + assert_eq!(app.dialog, Some(Dialog::Unprecompose)); + finish(&mut app, &ctx, true); + assert!(app.dialog.is_none()); + assert_eq!(layer_count(&app.session), 2, "the two solids are back"); + } + + #[test] + fn a_clean_precomp_unpacks_without_asking_and_a_locked_one_is_an_error() { + let (ctx, mut app) = fresh(); + let pre = scene(&mut app); + assert_eq!(guard(&mut app, COMMAND, &json!({"layers": [pre]})), Ok(false)); + crate::menus::invoke(&mut app, &ctx, COMMAND, json!({"layers": [pre]})).unwrap(); + assert!(app.dialog.is_none()); + assert_eq!(layer_count(&app.session), 2); + + let (_, mut app) = fresh(); + let pre = scene(&mut app); + app.session.execute("prop.set", json!({"layer": pre, "path": "transform/opacity", "value": 50})).unwrap(); + app.session.execute("layer.setSwitch", json!({"layers": [pre], "switch": "lock", "value": true})).unwrap(); + let e = guard(&mut app, COMMAND, &json!({"layers": [pre]})).unwrap_err(); + assert!(e.contains("locked"), "{e}"); + assert!(app.dialog.is_none()); + assert_eq!(layer_count(&app.session), 1); + // Consented and dry-run calls, and other commands, are not asked. + assert_eq!(guard(&mut app, COMMAND, &json!({"layers": [pre], "force": true})), Ok(false)); + assert_eq!(guard(&mut app, COMMAND, &json!({"layers": [pre], "dryRun": true})), Ok(false)); + assert_eq!(guard(&mut app, "layer.precompose", &json!({})), Ok(false)); + } +} diff --git a/docs/agents.md b/docs/agents.md index 9831ec031..ac77439b7 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -261,6 +261,30 @@ build real projects through these interfaces; they are worked examples of everyt `layer.centerAnchor` skip them and fail when every target is locked ("… is locked"); Select All and `layer.selectNext` / `selectPrevious` step over them. Unlock with `layer.setSwitch {"layers": [...], "switch": "lock", "value": false}` or `layer.unlockAll`. +* **Un-precompose**: `layer.unprecompose {layer?, force?, dryRun?}` (Layer ▸ Un-precompose) expands the + selected pre-comp layer into copies of its composition's layers at its place (order, keyframes, + effects, masks, parenting, mattes, markers kept; timing moved by the layer's Start and trimmed to + what it showed; Position minus Anchor Point added to the unparented ones). One undo step; the + nested comp stays in the project; the nested comp's frame no longer clips what its layers draw + outside it. Only a **locked** pre-comp layer is refused (with or without `force`), changing + nothing. Everything that would change the picture or drop something is a warning: the pre-comp + layer has a parent or matte, effects, masks, layer styles, a non-default Scale / Rotation / + Opacity, an animated transform, time remap or stretch, a blending mode, Video or Audio off, Solo + or Guide on, the 3D / collapse / adjustment switch or Preserve Transparency, or is used by another + layer (parent, matte or a layer property), or an expression of another layer names it (by name in + quotes or as `layer()`; listed per property, the expression is left as written and will + no longer find it); or the nested comp holds a camera, light, adjustment, + 3D, collapsing or soloed layer, or a layer with a blending mode or Preserve Transparency, preserves + a frame rate other than the comp's, has a motion-blur shutter other than the comp's (with motion + blur layers), or has an unparented layer with a Position expression while the pre-comp layer's + Position differs from its Anchor Point (the move is added to stored values only). Without + `force` such a call is an error listing every reason and nothing changes; `dryRun: true` returns + `{dryRun, warnings}` without changing anything. With `force: true` it unpacks anyway and returns + `{layers, warnings}`: what the pre-comp layer itself carried (effects, masks, styles, transform + beyond Position, time remap, blending mode, switches, its parent and matte) is dropped, and other + layers' parent, track matte and layer-property links to it are removed. The menu shows the + reasons and asks (Unpack Anyway / Cancel, `dialog.unprecompose.force` / + `dialog.unprecompose.cancel`); a layer without reasons unpacks without asking. * **Quick Set Anchor**: `layer.quickSetAnchor {point: topLeft|top|topRight|left|center|right|bottomLeft|bottom|bottomRight, layers?}` (Layer ▸ Transform ▸ Quick Set Anchor) moves the Anchor Point of 2D layers to that point of their content and shifts Position and its keys so the layers don't move, in one undo step. 3D and From 61af9e5b725658ec1d8a394cfb6d2b14391ba0f7 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 15:41:14 +0100 Subject: [PATCH 23/40] #3233: a text layer's name follows its text until the user renames it A text layer's name followed its Source Text whenever the name started with "Text", so a user's "Text Title" was replaced by the next text edit. The layer now records whether its name follows the text (`name_follows_text`, optional in the project file). A new text layer named after its text follows it; a name given at creation or by Rename (Enter, layer.rename, a script's layer.name, Layer Settings' name) is the user's and stays; renaming to an empty name shows the text again and follows it; committing the unchanged name changes nothing; copies keep the state. On-canvas typing and layer.setText share the rule. The name is the text's first paragraph, which ends at a line feed or a bare carriage return (After Effects' paragraph break). Projects saved without the state keep the old rule for the names that followed: a name that is empty, the text's own, or "Text"/"Text 2"... follows; any other name stays. AEP import records a stored layer name as the user's and no name as following, and names an empty text layer without a name "Text" instead of "Layer"; export writes no name for a following layer and keeps the name the user gave, even when it equals the text. Fixes #3233 --- crates/aep/src/export/plan.rs | 5 +- crates/aep/src/import/build.rs | 11 ++- crates/aep/tests/it/export/text.rs | 42 ++++++++++ crates/engine/src/cmd/layer.rs | 10 ++- crates/engine/src/cmd/layer/contents.rs | 12 +-- crates/engine/src/cmd/layer/create.rs | 4 +- crates/engine/src/cmd/layer/switches.rs | 26 ++++++- crates/engine/src/cmd/layer/transform.rs | 4 +- crates/engine/src/cmd/text_edit.rs | 15 ++-- crates/engine/src/tests/text_edit.rs | 99 ++++++++++++++++++++++++ crates/project/src/build.rs | 1 + crates/project/src/layer.rs | 26 +++++++ crates/project/src/lib.rs | 2 +- docs/agents.md | 2 + 14 files changed, 236 insertions(+), 23 deletions(-) diff --git a/crates/aep/src/export/plan.rs b/crates/aep/src/export/plan.rs index 9f45c50cd..f8aa2b3b8 100644 --- a/crates/aep/src/export/plan.rs +++ b/crates/aep/src/export/plan.rs @@ -1047,9 +1047,10 @@ fn plan_layer(cx: &PlanCx<'_>, at: CompAt<'_>, cp: &CompPlan, layer: &Layer, col let props = plan_transform(layer, &src, comp, source_size, cp, comp_name, col); let remap = remap_prop.filter(|_| remapped).map(|p| plan_remap(p, comp, cp, &layer.name, comp_name, col)); let mut name = cut_name(&layer.name, 255, &what("layer"), col); - // A text layer named after its text stores no name (110, 113: After Effects shows the text). + // A text layer named after its text stores no name (110, 113: After Effects shows the text): + // the layer's own rule decides (#3233). if let LayerSrc::Text(tp) = &src - && tp.text.split('\r').next().is_some_and(|first| first.chars().take(64).collect::() == name) + && layer.name_follows_text(&effectcraft_project::text_layer_name(&tp.text)) { name.clear(); } diff --git a/crates/aep/src/import/build.rs b/crates/aep/src/import/build.rs index 4ec346328..fa66ee411 100644 --- a/crates/aep/src/import/build.rs +++ b/crates/aep/src/import/build.rs @@ -479,7 +479,12 @@ fn build_layers(project: &mut Project, cx: &mut Ctx<'_>, defs: &EffectDefinition .map(|d| crate::import::text::first_paragraph(&d.raw_text)) .filter(|t| !t.trim().is_empty()) }; - let name = aep_name.clone().or_else(|| src.as_ref().map(|s| s.name.clone())).or_else(text_name).unwrap_or_else(|| "Layer".to_string()); + let name = aep_name + .clone() + .or_else(|| src.as_ref().map(|s| s.name.clone())) + .or_else(text_name) + // An empty text layer without a name is named as a new one is (#3233). + .unwrap_or_else(|| if h.layer_type == LayerType::Text { "Text" } else { "Layer" }.to_string()); let skip = |cx: &mut Ctx<'_>, skipped: &mut HashMap, category: LossCategory, what: &str| { cx.col.lose(category, format!("{comp_name}: {what} '{name}'")); skipped.insert(h.id, what.to_string()); @@ -537,6 +542,10 @@ fn build_layers(project: &mut Project, cx: &mut Ctx<'_>, defs: &EffectDefinition }; let mut l: Layer = build::layer(project, &comp, &name, source.clone(), size, None); l.name = name.clone(); + // A text layer without a stored name follows its text; a stored name is the user's (#3233). + if is_text { + l.name_follows_text = Some(aep_name.is_none()); + } l.label = Label::ALL.get(usize::from(h.label)).copied().unwrap_or(Label::None); apply_timing(&mut l, &h, &tm, &name, &mut cx.col); apply_switches(&mut l, &h); diff --git a/crates/aep/tests/it/export/text.rs b/crates/aep/tests/it/export/text.rs index 32c7572c5..32e55a269 100644 --- a/crates/aep/tests/it/export/text.rs +++ b/crates/aep/tests/it/export/text.rs @@ -196,6 +196,48 @@ fn documents_built_in_code_are_written_as_their_fields() { assert_eq!(layer.header().map(|h| h.layer_type), Some(effectcraft_aep::LayerType::Text)); } +/// #3233: whether a text layer's name follows its text survives export and import. A followed +/// name is written as no name (After Effects shows the text) and comes back following; a name the +/// user gave is written, even when it equals the text, and comes back as the user's. Without a +/// recorded state (older projects) a name equal to the text follows. +#[test] +fn a_text_layer_name_follows_its_text_through_export_and_import() { + for (name, follows, stored) in [ + ("Hello", Some(false), Some("Hello")), + ("Hello 2", Some(true), None), + ("Hello", None, None), + ("Text 2", None, None), + ("Text Title", None, Some("Text Title")), + ("Text Title", Some(false), Some("Text Title")), + ] { + let case = format!("{name:?} {follows:?}"); + let (mut p, c) = text_project(vec![TextDoc::plain("Hello")]); + with_layer(&mut p, c, 0, |l| { + l.name = name.into(); + l.name_follows_text = follows; + }); + let r = export_all(&p); + let file = parse(&r.bytes).expect("parse"); + let view = effectcraft_aep::Project::new(&file).expect("project"); + let layer = view.all_items().into_iter().find_map(|i| i.comp()).and_then(|c| c.layers().next()).expect("layer"); + assert_eq!(layer.name().as_deref(), stored, "stored name ({case})"); + let back = reimport(&r.bytes); + let l = back.comps().flat_map(|(_, c)| c.layers.iter()).find(|l| matches!(l.source, LayerSource::Text)).expect("text layer"); + assert_eq!(l.name, stored.unwrap_or("Hello"), "imported name ({case})"); + assert_eq!(l.name_follows_text, Some(stored.is_none()), "imported state ({case})"); + } + // An empty text layer that follows its text is written without a name, as After Effects + // writes it, and comes back named "Text", still following. + let (mut p, c) = text_project(vec![TextDoc::plain("")]); + with_layer(&mut p, c, 0, |l| { + l.name = "Text".into(); + l.name_follows_text = Some(true); + }); + let back = reimport(&export_all(&p).bytes); + let l = back.comps().flat_map(|(_, c)| c.layers.iter()).find(|l| matches!(l.source, LayerSource::Text)).expect("text layer"); + assert_eq!((l.name.as_str(), l.name_follows_text), ("Text", Some(true)), "an empty text layer"); +} + #[test] fn what_a_text_document_cannot_hold_is_reported() { let mut d = TextDoc::plain("x"); diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index f88ab32c8..b015b72b4 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -114,7 +114,15 @@ pub fn specs() -> Vec { has_layers, set_switch ), - cmd!("layer.rename", "Rename", [], Some("Enter"), "{layer?, name}", has_layers, rename), + cmd!( + "layer.rename", + "Rename", + [], + Some("Enter"), + "{layer?, name} — a text layer's name follows its text until renamed; an empty name follows it again", + has_layers, + rename + ), cmd!("layer.setComment", "Layer Comment", [], None, "{layers?, comment}", has_layers, set_comment), cmd!("layer.setBlendMode", "Blending Mode", [], None, "{layers?, mode?: Normal|Multiply|Screen|…, step?: ±1}", has_layers, blend), cmd!( diff --git a/crates/engine/src/cmd/layer/contents.rs b/crates/engine/src/cmd/layer/contents.rs index 5eb253beb..3015f4ecf 100644 --- a/crates/engine/src/cmd/layer/contents.rs +++ b/crates/engine/src/cmd/layer/contents.rs @@ -207,14 +207,14 @@ pub(super) fn set_text(s: &mut Session, p: &Value) -> Result { KV::Str(t) => TextDoc::plain(&t), _ => TextDoc::default(), }; + let before = effectcraft_project::text_layer_name(&doc.text); apply_text_params("layer.setText", p, &mut doc, range.clone())?; pr.set_value_at(lt, KV::Text(Box::new(doc.clone()))); - if let Some(first) = doc.text.lines().next() - && str_p(p, "text").is_some() - && !first.is_empty() - && (l.name.starts_with("Text") || l.name.is_empty()) - { - l.name = first.chars().take(40).collect(); + // Text layers are named after their text until renamed (#3233). + let after = effectcraft_project::text_layer_name(&doc.text); + if str_p(p, "text").is_some() && !after.is_empty() && l.name_follows_text(&before) { + l.name = after; + l.name_follows_text = Some(true); } Ok(()) })?; diff --git a/crates/engine/src/cmd/layer/create.rs b/crates/engine/src/cmd/layer/create.rs index 621ae866b..0196b5aee 100644 --- a/crates/engine/src/cmd/layer/create.rs +++ b/crates/engine/src/cmd/layer/create.rs @@ -187,8 +187,10 @@ pub(super) fn new_text(s: &mut Session, p: &Value) -> Result { } let edit = b_p(p, "edit").unwrap_or(false); let id = s.edit("New Text Layer", None, |proj, st| { - let name: String = layer_name.clone().unwrap_or_else(|| doc.text.lines().next().unwrap_or("").chars().take(40).collect()); + let name: String = layer_name.clone().unwrap_or_else(|| effectcraft_project::text_layer_name(&doc.text)); let mut l = build::layer(proj, &comp, if name.is_empty() { "Text" } else { &name }, LayerSource::Text, (comp.width, comp.height), None); + // Named after its text, the name follows the text until renamed; a given name does not. + l.name_follows_text = Some(layer_name.as_deref().is_none_or(str::is_empty)); if let Some(pr) = l.props.prop_mut("text/sourceText") { pr.value = KV::Text(Box::new(doc.clone())); } diff --git a/crates/engine/src/cmd/layer/switches.rs b/crates/engine/src/cmd/layer/switches.rs index 366c1eeb1..afee522c6 100644 --- a/crates/engine/src/cmd/layer/switches.rs +++ b/crates/engine/src/cmd/layer/switches.rs @@ -139,13 +139,37 @@ fn drop_3d_values(l: &mut Layer) { pub(super) fn rename(s: &mut Session, p: &Value) -> Result { let (cid, lid) = layer_p(s, p, "layer.rename")?; let name = str_p(p, "name").ok_or_else(|| bad("layer.rename", "missing `name`"))?.to_string(); + let t = s.time(); s.edit("Rename Layer", None, |proj, _| { - layer_mut(proj, cid, lid)?.name = name.clone(); + set_layer_name(layer_mut(proj, cid, lid)?, &name, t); Ok(()) })?; Ok(Value::Null) } +/// Give layer `l` the name `name` the user typed (comp time `t` picks the text). A text layer's +/// name follows its text until the user renames it; an empty name makes it follow the text again +/// (After Effects, #3233). Committing the unchanged name changes nothing. +pub(super) fn set_layer_name(l: &mut Layer, name: &str, t: effectcraft_time::Tick) { + let text_name = + l.props.prop("text/sourceText").filter(|_| matches!(l.source, effectcraft_project::LayerSource::Text)).map(|pr| match pr.value_at(l.layer_time(t)) { + KV::Text(d) => effectcraft_project::text_layer_name(&d.text), + KV::Str(txt) => effectcraft_project::text_layer_name(&txt), + _ => String::new(), + }); + match text_name { + Some(first) if name.trim().is_empty() => { + l.name = if first.is_empty() { "Text".to_string() } else { first }; + l.name_follows_text = Some(true); + } + Some(_) if name != l.name => { + l.name = name.to_string(); + l.name_follows_text = Some(false); + } + _ => l.name = name.to_string(), + } +} + /// The Timeline's Comment column. pub(super) fn set_comment(s: &mut Session, p: &Value) -> Result { let (cid, ids) = layers_p(s, p)?; diff --git a/crates/engine/src/cmd/layer/transform.rs b/crates/engine/src/cmd/layer/transform.rs index eb0f610f9..87403fb26 100644 --- a/crates/engine/src/cmd/layer/transform.rs +++ b/crates/engine/src/cmd/layer/transform.rs @@ -172,10 +172,12 @@ pub(super) fn layer_settings(s: &mut Session, p: &Value) -> Result { let pixel_aspect = pixel_aspect_p(p)?; let name = str_p(p, "name").map(str::trim).filter(|n| !n.is_empty()).map(str::to_string); let affect_all = p.get("affectAll").and_then(Value::as_bool).unwrap_or(true); + let t = s.time(); let solid = s.edit("Layer Settings", None, |proj, _| { let src = layer_mut(proj, cid, lid)?.source.clone(); if let Some(n) = &name { - layer_mut(proj, cid, lid)?.name = n.clone(); + // A user name: a text layer's name stops following its text (#3233). + super::switches::set_layer_name(layer_mut(proj, cid, lid)?, n, t); } let LayerSource::Solid { item } = src else { return Ok(None) }; let shared = proj.comps().flat_map(|(_, c)| &c.layers).filter(|l| l.source == src).count() > 1; diff --git a/crates/engine/src/cmd/text_edit.rs b/crates/engine/src/cmd/text_edit.rs index cdb650486..9240f0c1a 100644 --- a/crates/engine/src/cmd/text_edit.rs +++ b/crates/engine/src/cmd/text_edit.rs @@ -6,7 +6,7 @@ //! Positions are character indices. The selection is `anchor..caret` (either order). use effectcraft_keyframe::{CharStyle, TextDoc, Value as KV}; -use effectcraft_project::{ItemId, LayerId, LayerSource}; +use effectcraft_project::{ItemId, LayerId, LayerSource, text_layer_name}; use serde::{Deserialize, Serialize}; use serde_json::{Value, json}; @@ -288,10 +288,6 @@ fn session_on(s: &mut Session, lid: LayerId) -> TextEdit { } } -fn first_line_name(text: &str) -> String { - text.lines().next().unwrap_or("").chars().take(40).collect() -} - /// Edit a layer's Source Text at the CTI (one undo step, or merged by `merge`), then set the /// session's selection. pub(crate) fn edit_doc( @@ -319,12 +315,13 @@ pub(crate) fn edit_doc( // already has) must not turn a static Str into Text or add a keyframe at the CTI: that // would change the project and record an empty undo step. if doc != original { - let before = first_line_name(&original.text); - let after = first_line_name(&doc.text); + let before = text_layer_name(&original.text); + let after = text_layer_name(&doc.text); pr.set_value_at(lt, KV::Text(Box::new(doc))); - // Text layers are named after their text until renamed. - if before != after && !after.is_empty() && (l.name == before || l.name.starts_with("Text") || l.name.is_empty()) { + // Text layers are named after their text until renamed (#3233). + if before != after && !after.is_empty() && l.name_follows_text(&before) { l.name = after; + l.name_follows_text = Some(true); } } Ok(()) diff --git a/crates/engine/src/tests/text_edit.rs b/crates/engine/src/tests/text_edit.rs index eb1de6f89..bcb4f0559 100644 --- a/crates/engine/src/tests/text_edit.rs +++ b/crates/engine/src/tests/text_edit.rs @@ -1417,3 +1417,102 @@ fn duplicate_of_an_empty_type_tool_layer_ends_the_edit_and_copies_it() { assert_eq!(layer_count(&s), before + 1, "the empty layer is kept, as text.endEdit keeps it, and copied"); assert_eq!(s.state.selected_layers, vec![LayerId(copy)], "and the copy is selected"); } + +fn layer_name(s: &Session, t: u64) -> String { + s.active_comp().unwrap().layer(effectcraft_project::LayerId(t)).unwrap().name.clone() +} + +/// Replace the text with `text` in the on-canvas editor (everything selected, typed, committed). +fn retype(s: &mut Session, t: u64, text: &str) { + begin_edit(s, t); + s.execute("text.insert", json!({"text": text})).unwrap(); + s.execute("text.endEdit", json!({})).unwrap(); +} + +/// #3233: a text layer's name follows its Source Text, edited on canvas or by `layer.setText`, +/// until the user renames it (After Effects). A user name stays, even one that starts with +/// "Text", and so does a copy's; renaming to an empty name follows the text again. +#[test] +fn a_text_layer_name_follows_its_text_until_renamed() { + let (mut s, t) = session("Hello"); + assert_eq!(layer_name(&s, t), "Hello"); + retype(&mut s, t, "World"); + assert_eq!(layer_name(&s, t), "World", "a new text layer follows its text"); + s.execute("layer.setText", json!({"layer": t, "text": "Again"})).unwrap(); + assert_eq!(layer_name(&s, t), "Again"); + s.execute("layer.rename", json!({"layer": t, "name": "Text Title"})).unwrap(); + s.execute("layer.setText", json!({"layer": t, "text": "Changed"})).unwrap(); + assert_eq!(layer_name(&s, t), "Text Title", "layer.setText keeps the user's name"); + retype(&mut s, t, "Typed"); + assert_eq!(layer_name(&s, t), "Text Title", "typing keeps the user's name"); + s.execute("layer.select", json!({"layers": [t]})).unwrap(); + let copy = s.execute("edit.duplicate", json!({})).unwrap()[0].as_u64().unwrap(); + let copy_name = layer_name(&s, copy); + s.execute("layer.setText", json!({"layer": copy, "text": "Copied"})).unwrap(); + assert_eq!(layer_name(&s, copy), copy_name, "a copy keeps the user's name too"); + // Renaming to an empty name: the name is the text's again, and follows it. + s.execute("layer.rename", json!({"layer": t, "name": ""})).unwrap(); + assert_eq!(layer_name(&s, t), "Typed", "an empty name shows the text"); + retype(&mut s, t, "Followed"); + assert_eq!(layer_name(&s, t), "Followed", "and follows it again"); + // Committing the unchanged name (Enter, Enter) does not stop the following. + s.execute("layer.rename", json!({"layer": t, "name": "Followed"})).unwrap(); + s.execute("layer.setText", json!({"layer": t, "text": "Still"})).unwrap(); + assert_eq!(layer_name(&s, t), "Still"); + // A name given in Layer Settings is the user's too. The UI offers Layer Settings only for + // solids, nulls, cameras and lights (as After Effects does); this guards the command, which + // agents can call on any layer. + s.execute("layer.settings", json!({"layer": t, "name": "Settings Name"})).unwrap(); + s.execute("layer.setText", json!({"layer": t, "text": "Later"})).unwrap(); + assert_eq!(layer_name(&s, t), "Settings Name", "Layer Settings names it for good"); + // A layer given a name when it is made does not follow. + let named = s.execute("layer.newText", json!({"text": "Body", "name": "Caption"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("layer.setText", json!({"layer": named, "text": "Other"})).unwrap(); + assert_eq!(layer_name(&s, named), "Caption"); +} + +/// #3233: After Effects breaks paragraphs with a bare carriage return; the name is the first +/// paragraph, without the break, and an older layer named after it counts as following. +#[test] +fn a_text_layer_name_ends_at_a_bare_carriage_return() { + let (mut s, t) = session("A\rB"); + assert_eq!(layer_name(&s, t), "A"); + s.execute("layer.setText", json!({"layer": t, "text": "C\rD"})).unwrap(); + assert_eq!(layer_name(&s, t), "C"); + retype(&mut s, t, "E\rF"); + assert_eq!(layer_name(&s, t), "E"); + let cid = s.active_comp_id().unwrap(); + let l = std::sync::Arc::make_mut(&mut s.project).comp_mut(cid).unwrap().layer_mut(effectcraft_project::LayerId(t)).unwrap(); + l.name = "Para1".into(); + l.name_follows_text = None; + l.props.prop_mut("text/sourceText").unwrap().value = effectcraft_keyframe::Value::Text(Box::new(TextDoc::plain("Para1\rPara2"))); + s.execute("layer.setText", json!({"layer": t, "text": "Next\rLine"})).unwrap(); + assert_eq!(layer_name(&s, t), "Next", "an older layer named after its first paragraph follows"); +} + +/// #3233: projects saved before the state was recorded load without it; there a name that is +/// the text's, empty, or the default "Text"/"Text 2"… follows the text, any other name stays. +#[test] +fn older_text_layers_without_the_name_state_follow_as_before() { + let (mut s, t) = session("Hello"); + let mut v = serde_json::to_value(s.active_comp().unwrap().layer(effectcraft_project::LayerId(t)).unwrap()).unwrap(); + v.as_object_mut().unwrap().remove("name_follows_text"); + let old: effectcraft_project::Layer = serde_json::from_value(v).unwrap(); + assert_eq!(old.name_follows_text, None, "an older project has no state"); + for (name, follows) in [("Hello", true), ("", true), ("Text", true), ("Text 3", true), ("Text Title", false), ("Text 3b", false), ("Title", false)] { + let l = effectcraft_project::Layer { name: name.into(), ..old.clone() }; + assert_eq!(l.name_follows_text("Hello"), follows, "{name:?}"); + } + let legacy = |s: &mut Session, name: &str| { + let cid = s.active_comp_id().unwrap(); + let l = std::sync::Arc::make_mut(&mut s.project).comp_mut(cid).unwrap().layer_mut(effectcraft_project::LayerId(t)).unwrap(); + l.name = name.into(); + l.name_follows_text = None; + }; + legacy(&mut s, "Hello"); + s.execute("layer.setText", json!({"layer": t, "text": "World"})).unwrap(); + assert_eq!(layer_name(&s, t), "World", "a name equal to the text follows it"); + legacy(&mut s, "Title"); + retype(&mut s, t, "Typed"); + assert_eq!(layer_name(&s, t), "Title", "another name stays"); +} diff --git a/crates/project/src/build.rs b/crates/project/src/build.rs index 1aa8d7c90..7a960dbfb 100644 --- a/crates/project/src/build.rs +++ b/crates/project/src/build.rs @@ -935,6 +935,7 @@ pub fn layer(project: &mut Project, comp: &Comp, name: &str, source: LayerSource Layer { id, name: comp.unique_layer_name(name), + name_follows_text: None, source, label, comment: String::new(), diff --git a/crates/project/src/layer.rs b/crates/project/src/layer.rs index 34eeb50c0..f7b3b5e51 100644 --- a/crates/project/src/layer.rs +++ b/crates/project/src/layer.rs @@ -299,6 +299,8 @@ impl Layer { let Layer { id, name, + // Whether the name follows the text changes no pixels until the name changes. + name_follows_text: _, source, label, comment, @@ -474,6 +476,11 @@ pub enum AutoOrient { pub struct Layer { pub id: LayerId, pub name: String, + /// A text layer's name follows the first line of its Source Text until the user renames it + /// (After Effects). `Some(true)`: it follows, `Some(false)`: the user named it. `None` (older + /// projects, layers made before this was recorded): see [`Layer::name_follows_text()`]. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub name_follows_text: Option, pub source: LayerSource, pub label: Label, #[serde(default)] @@ -512,7 +519,26 @@ pub struct Layer { pub props: PropGroup, } +/// The name a text layer takes from its text: the first 40 characters of the first line. A line +/// ends at a line feed or at a bare carriage return (After Effects' paragraph break). +pub fn text_layer_name(text: &str) -> String { + text.split(['\r', '\n']).next().unwrap_or("").chars().take(40).collect() +} + +/// A text layer's default name when its text gives none: "Text", numbered "Text 2", "Text 3"… +fn is_default_text_name(name: &str) -> bool { + name == "Text" || name.strip_prefix("Text ").is_some_and(|n| !n.is_empty() && n.chars().all(|c| c.is_ascii_digit())) +} + impl Layer { + /// Whether this text layer's name follows its Source Text, whose first line gives the name + /// `current` (see [`text_layer_name`]). Without a recorded state (an older project), a name + /// that is empty, the text's own, or the default "Text"/"Text 2"… follows; any other name was + /// given by the user. + pub fn name_follows_text(&self, current: &str) -> bool { + self.name_follows_text.unwrap_or_else(|| self.name.is_empty() || self.name == current || is_default_text_name(&self.name)) + } + /// The layers this layer reads: its parent, track matte, layer parameters (Displacement Map, /// Audio Spectrum's Audio Layer…) and tracker targets. pub fn referenced_layers(&self) -> Vec { diff --git a/crates/project/src/lib.rs b/crates/project/src/lib.rs index 079b81765..fabcd607f 100644 --- a/crates/project/src/lib.rs +++ b/crates/project/src/lib.rs @@ -43,7 +43,7 @@ pub use item::NO_LAYER; pub use item::{Heard, Item, ItemId, ItemKind, LayerId}; pub use layer::{ AutoOrient, FrameBlend, Layer, LayerSource, LightKind, MatteKind, PrimitiveKind, Quality, Sampling, Switches, TrackMatte, is_audio_effect, - reads_other_frames, + reads_other_frames, text_layer_name, }; pub use layers::Layers; pub use settings::{ diff --git a/docs/agents.md b/docs/agents.md index ac77439b7..27664cb73 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -713,6 +713,8 @@ in the Plug-in Library: [publishing-plugins.md](publishing-plugins.md). step (separated X/Y/Z Position; Orientation and X/Y/Z Rotation on 3D layers). * Rename a layer with Enter (or double-click a name): the whole name is selected, Enter or a click elsewhere commits, Escape cancels; `layer.rename {layer, name}` does it directly. + A text layer's name follows its text until it is renamed; renaming it to an empty name makes + it follow the text again (After Effects). * Ctrl/Cmd-click on the current-time display (Timeline or Composition panel) toggles the Time Display Style between Timecode and Frames: `file.projectSettings {"timeDisplay": "frames"}`. * `prop.pickWhip {layer, prop, target: {layer, prop, dimension?}}` links a property as its From 2abd727338dea0a7b48131794689253ba01a8173 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 16:41:56 +0100 Subject: [PATCH 24/40] AEP import: Puppet (ADBE FreePin3) arrives as EffectCraft's Puppet, its meshes and pins are reported After Effects' Puppet was dropped with a one-line "has the effect" loss. It now arrives as EffectCraft's Puppet (ec.distort.puppet) in its place in the stack, with its name and fx switch, and the report lists per mesh Triangles, Expansion and per pin group (Deform, Overlap, Stiffness) the pins, keyed pins and atom match names; entries outside the known tree are named once, and long lists stop at ten with "and N more". No pins are created: a pin's rest place is a vertex of the hidden mesh data and the unit of its Position is unknown, and no corpus file holds a Puppet. The tree (docs/aep-format.md 3.7) comes from an external scripting listing, not the corpus; the sample that settles it is described there. The fx_inject test helpers can now inject any effect instance, which the new tests use. Refs #3093 --- crates/aep/src/import.rs | 1 + crates/aep/src/import/effects.rs | 7 +- crates/aep/src/import/puppet.rs | 234 ++++++++++++++++++++++++ crates/aep/tests/it/import.rs | 1 + crates/aep/tests/it/import/fx_inject.rs | 40 ++-- crates/aep/tests/it/import/puppet.rs | 171 +++++++++++++++++ docs/aep-format.md | 49 ++++- docs/aep-import.md | 4 +- 8 files changed, 489 insertions(+), 18 deletions(-) create mode 100644 crates/aep/src/import/puppet.rs create mode 100644 crates/aep/tests/it/import/puppet.rs diff --git a/crates/aep/src/import.rs b/crates/aep/src/import.rs index 956e3b1c5..938d0c46e 100644 --- a/crates/aep/src/import.rs +++ b/crates/aep/src/import.rs @@ -30,6 +30,7 @@ mod effects; mod markers; mod masks; mod props; +mod puppet; mod report; mod settings; mod shapes; diff --git a/crates/aep/src/import/effects.rs b/crates/aep/src/import/effects.rs index 8409a6f7e..f205245eb 100644 --- a/crates/aep/src/import/effects.rs +++ b/crates/aep/src/import/effects.rs @@ -76,6 +76,11 @@ pub(crate) fn import_effects<'f, 'a>( col: &mut Collector, ) { for fx in layer.effects() { + // Puppet keeps its meshes and pins in nested groups, not in `parT` (its own step). + if fx.match_name() == crate::import::puppet::MATCH_NAME { + crate::import::puppet::import_puppet(defs, &fx, cx, ids, target, col); + continue; + } let shown = fx.display_name().unwrap_or_else(|| fx.match_name().to_string()); let Some(map) = EFFECTS.iter().find(|m| m.match_name == fx.match_name()) else { col.lose(LossCategory::Effects, format!("{}: '{}' has the effect '{shown}' ({})", cx.comp, cx.layer, fx.match_name())); @@ -112,7 +117,7 @@ pub(crate) fn import_effects<'f, 'a>( } /// Parameters that never carry a value to import. -fn carries_nothing(p: &EffectParam<'_, '_>) -> bool { +pub(crate) fn carries_nothing(p: &EffectParam<'_, '_>) -> bool { matches!(p.kind, ParamKind::Button | ParamKind::NoData | ParamKind::GroupStart | ParamKind::GroupEnd) || (p.index == 0 && p.kind == ParamKind::Layer) } diff --git a/crates/aep/src/import/puppet.rs b/crates/aep/src/import/puppet.rs new file mode 100644 index 000000000..ce10ae7f5 --- /dev/null +++ b/crates/aep/src/import/puppet.rs @@ -0,0 +1,234 @@ +//! After Effects' Puppet effect (`ADBE FreePin3`) arrives as EffectCraft's Puppet +//! (`ec.distort.puppet`) in its place in the stack, with its name and fx switch, but **without +//! its meshes and pins**: how After Effects stores a pin's rest place (a vertex index and offset +//! into the hidden mesh data) and its Position (pixels or a fraction of the layer) is not decoded +//! yet, and a guessed rest place would deform the layer wrongly without a word. What the instance +//! holds is reported instead, mesh by mesh: Triangles, Expansion, and per pin container (Deform, +//! Stiffness, Overlap) the number of pins, how many are keyed or carry an expression, and the +//! match names of their atoms (Advanced and Bend pins show up there). Any entry this reader does +//! not know is named verbatim. +//! +//! The tree read here (docs/aep-format.md 3.7, Puppet) comes from an external scripting listing +//! of the effect's property tree, not from the corpus (no corpus file has a Puppet): **?** until a +//! byte sample exists. It is read with the same verified group reader as masks, shapes and layer +//! styles; a file whose tree differs is reported, never guessed at. + +use effectcraft_project::build::Ids; +use effectcraft_project::{Node, PropGroup}; + +use crate::import::effects::{LayerCtx, carries_nothing}; +use crate::import::report::{Collector, LossCategory}; +use crate::{Effect as AepEffect, EffectDefinitions, ParamValue, PropGroup as AepGroup, PropNode, Property as AepProperty}; + +/// After Effects' Puppet effect. +pub(crate) const MATCH_NAME: &str = "ADBE FreePin3"; +/// The hidden group that holds the meshes (`arap`). +const ARAP: &str = "ADBE FreePin3 ARAP Group"; +/// Auto-traced Shapes, beside the meshes. +const OUTLINES: &str = "ADBE FreePin3 Outlines"; +/// The hidden group of the meshes. +const MESH_GROUP: &str = "ADBE FreePin3 Mesh Group"; +/// One mesh (`Mesh 1`). +const MESH_ATOM: &str = "ADBE FreePin3 Mesh Atom"; +/// A mesh's hidden triangulation. +const MESH_DATA: &str = "ADBE FreePin3 Mesh"; +const TRIANGLES: &str = "ADBE FreePin3 Mesh Tri Count"; +const EXPANSION: &str = "ADBE FreePin3 Mesh Expansion"; +/// At most this many meshes, pin atom names or unrecognised names are listed in a report line; +/// the rest are counted (`and 3 more`). +const LIST_CAP: usize = 10; +/// The pin containers of a mesh: match name and the name After Effects shows. +const PIN_GROUPS: [(&str, &str); 3] = [("ADBE FreePin3 PosPins", "Deform"), ("ADBE FreePin3 HghtPins", "Overlap"), ("ADBE FreePin3 StarchPins", "Stiffness")]; + +/// Imports a Puppet instance (the caller checked the match name) into `target`. +pub(crate) fn import_puppet<'f, 'a>( + defs: &EffectDefinitions<'f, 'a>, + fx: &AepEffect<'f, 'a>, + cx: &LayerCtx<'_>, + ids: &mut Ids<'_>, + target: &mut PropGroup, + col: &mut Collector, +) { + let shown = fx.display_name().unwrap_or_else(|| fx.match_name().to_string()); + let here = format!("{}: '{}' effect '{shown}' ({MATCH_NAME})", cx.comp, cx.layer); + let Some(spec) = effectcraft_effects::find(effectcraft_effects::puppet::ID) else { + col.lose(LossCategory::Effects, format!("{}: '{}' has the effect '{shown}' ({MATCH_NAME})", cx.comp, cx.layer)); + return; + }; + let size = [f64::from(cx.size.0), f64::from(cx.size.1)]; + let mut group = effectcraft_effects::instantiate(spec, ids, &shown, size); + match fx.enabled() { + Some(on) => group.enabled = on, + None => col.lose(LossCategory::DamagedData, format!("{}: '{}': the fx switch of '{shown}' is unreadable, imported switched on", cx.comp, cx.layer)), + } + // The ordinary parameters (`parT`): none is mapped yet, so a stored one is reported. + let params = defs.params(fx); + for p in ¶ms { + if carries_nothing(p) { + continue; + } + if p.stored().is_some() && !matches!(p.stored_value(), Some(ParamValue::Layer(0))) { + let label = if p.name.is_empty() { p.match_name.clone() } else { format!("{} ({})", p.name, p.match_name) }; + col.lose(LossCategory::Effects, format!("{here}: parameter {label} not imported")); + } + } + report_meshes(fx, ¶ms.iter().map(|p| p.match_name.as_str()).collect::>(), &here, col); + // The effect itself arrives (an EffectCraft Puppet the user can pin again), so it counts as + // imported; what it held is in the losses above. + col.imported.effects = col.imported.effects.saturating_add(1); + target.children.push(Node::Group(group)); +} + +/// Reports the meshes and pins of `fx` and every entry of its value group that is neither a +/// `parT` parameter (`param_names`) nor the mesh tree. +fn report_meshes(fx: &AepEffect<'_, '_>, param_names: &[&str], here: &str, col: &mut Collector) { + let mut unknown: Vec = Vec::new(); + let values = fx.chunk().child_list(b"tdgp").and_then(AepGroup::from_chunk); + let mut arap = None; + for e in values.map(|g| g.entries()).unwrap_or_default() { + if e.match_name == ARAP { + if let PropNode::Group(g) = e.node { + if arap.is_none() { + arap = Some(g); + } + } else { + push_unique(&mut unknown, e.match_name); + } + } else if !param_names.contains(&e.match_name.as_str()) { + match e.node { + // A value outside `parT` (On Transparent, ...): reported with what it holds. + PropNode::Property(p) => col.lose(LossCategory::Effects, format!("{here}: property {} ({}) not imported", e.match_name, describe(&p))), + PropNode::Group(_) | PropNode::Other(_) => push_unique(&mut unknown, e.match_name), + } + } + } + let mut meshes: Vec = Vec::new(); + let mut found = false; + if let Some(arap) = arap { + for e in arap.entries() { + match (e.match_name.as_str(), e.node) { + (MESH_GROUP, PropNode::Group(g)) if !found => { + found = true; + for m in g.entries() { + match (m.match_name.as_str(), m.node) { + (MESH_ATOM, PropNode::Group(mesh)) => { + let n = meshes.len().saturating_add(1); + meshes.push(mesh_summary(&mesh, n, &mut unknown)); + } + _ => push_unique(&mut unknown, m.match_name.clone()), + } + } + } + // Auto-traced Shapes are made from the layer again (EffectCraft traces the alpha). + (OUTLINES, _) => {} + _ => push_unique(&mut unknown, e.match_name.clone()), + } + } + } + let extra = if unknown.is_empty() { String::new() } else { format!("; not recognised: {}", capped(&unknown, ", ")) }; + if !found { + col.lose( + LossCategory::Effects, + format!("{here}: imported without meshes or pins: its mesh group ({ARAP} / {MESH_GROUP}) was not found or is not a group{extra}"), + ); + } else if !meshes.is_empty() { + col.lose( + LossCategory::Effects, + format!( + "{here}: imported without its meshes and pins (After Effects' pin rest places and positions are not decoded yet): {}{extra}", + capped(&meshes, "; ") + ), + ); + } else if !unknown.is_empty() { + col.lose(LossCategory::Effects, format!("{here}: no mesh{extra}")); + } +} + +/// `Mesh n (Triangles t, Expansion e): Deform 3 pins (1 keyed) [atom names], Overlap no pins, ...` +fn mesh_summary(mesh: &AepGroup<'_, '_>, n: usize, unknown: &mut Vec) -> String { + let name = mesh.user_name().unwrap_or_else(|| format!("Mesh {n}")); + let mut settings: Vec = Vec::new(); + let mut containers: Vec = Vec::new(); + for e in mesh.entries() { + let label = match e.match_name.as_str() { + TRIANGLES => Some("Triangles"), + EXPANSION => Some("Expansion"), + _ => None, + }; + match (label, e.node) { + (Some(label), PropNode::Property(p)) => settings.push(format!("{label} {}", describe(&p))), + // The triangulation After Effects keeps; EffectCraft builds its own. + _ if e.match_name == MESH_DATA => {} + _ => match (PIN_GROUPS.iter().find(|(m, _)| *m == e.match_name), e.node) { + (Some((_, shown)), PropNode::Group(g)) => containers.push(format!("{shown} {}", pins_summary(&g, unknown))), + _ => push_unique(unknown, e.match_name), + }, + } + } + let settings = if settings.is_empty() { String::new() } else { format!(" ({})", settings.join(", ")) }; + let containers = if containers.is_empty() { "no pin groups".to_string() } else { containers.join(", ") }; + format!("{name}{settings}: {containers}") +} + +/// `3 pins (1 keyed, 1 with an expression) [ADBE FreePin3 PosPin Atom]`, or `no pins`. An entry +/// of the container that is not a group (a pin is one) goes to `unknown`. +fn pins_summary(container: &AepGroup<'_, '_>, unknown: &mut Vec) -> String { + let mut count = 0usize; + let mut keyed = 0usize; + let mut expressions = 0usize; + let mut atoms: Vec = Vec::new(); + for e in container.entries() { + let PropNode::Group(pin) = e.node else { + push_unique(unknown, e.match_name); + continue; + }; + count = count.saturating_add(1); + push_unique(&mut atoms, e.match_name); + let props: Vec> = + pin.entries().into_iter().filter_map(|p| if let PropNode::Property(p) = p.node { Some(p) } else { None }).collect(); + if props.iter().any(AepProperty::is_animated) { + keyed = keyed.saturating_add(1); + } + if props.iter().any(|p| p.expression().is_some()) { + expressions = expressions.saturating_add(1); + } + } + if count == 0 { + return "no pins".to_string(); + } + let mut what = vec![format!("{keyed} keyed")]; + if expressions > 0 { + what.push(format!("{expressions} with an expression")); + } + format!("{count} pin{} ({}) [{}]", if count == 1 { "" } else { "s" }, what.join(", "), capped(&atoms, ", ")) +} + +/// A stored property's value for the report: `keyed`, the static value, or `unreadable`. +fn describe(p: &AepProperty<'_, '_>) -> String { + if p.is_animated() { + return "keyed".to_string(); + } + match p.static_value() { + Some(v) if v.len() == 1 => v.first().map(|x| format!("{x}")).unwrap_or_default(), + Some(v) => format!("[{}]", v.iter().map(|x| format!("{x}")).collect::>().join(", ")), + None => "unreadable".to_string(), + } +} + +/// Adds `name` to `names` unless it is there already. +fn push_unique(names: &mut Vec, name: String) { + if !names.contains(&name) { + names.push(name); + } +} + +/// The first [`LIST_CAP`] of `items` joined by `sep`, and how many more there are. +fn capped(items: &[String], sep: &str) -> String { + let shown: Vec<&str> = items.iter().take(LIST_CAP).map(String::as_str).collect(); + let mut out = shown.join(sep); + let more = items.len().saturating_sub(LIST_CAP); + if more > 0 { + out.push_str(&format!("{sep}and {more} more")); + } + out +} diff --git a/crates/aep/tests/it/import.rs b/crates/aep/tests/it/import.rs index 102a215c8..61a04c401 100644 --- a/crates/aep/tests/it/import.rs +++ b/crates/aep/tests/it/import.rs @@ -19,6 +19,7 @@ mod fx_inject; mod markers; mod masks; mod mattes; +mod puppet; mod resaved_defaults; mod robustness; mod shapes; diff --git a/crates/aep/tests/it/import/fx_inject.rs b/crates/aep/tests/it/import/fx_inject.rs index 81e6a821a..ae61794d3 100644 --- a/crates/aep/tests/it/import/fx_inject.rs +++ b/crates/aep/tests/it/import/fx_inject.rs @@ -103,18 +103,18 @@ pub fn tdmn(name: &str) -> Chunk<'static> { } /// A UTF-8 string chunk (`Utf8`). -fn utf8(s: &str) -> Chunk<'static> { +pub fn utf8(s: &str) -> Chunk<'static> { Chunk::data(*b"Utf8", s.as_bytes().to_vec()) } /// A chunk whose body is chunks without being a `LIST` (`pdnm`, `fnam`: `NESTED_IDS`). -fn nested(id: [u8; 4], children: Vec>) -> Chunk<'static> { +pub fn nested(id: [u8; 4], children: Vec>) -> Chunk<'static> { Chunk { id, body: Body::Chunks(children), pad: None } } /// A static value record holding `v`, after the one After Effects wrote for Glow's A & B Midpoint /// (its header; without the expression). -fn record(template: &Chunk<'_>, v: f64) -> Chunk<'static> { +pub fn record(template: &Chunk<'_>, v: f64) -> Chunk<'static> { let mut kids = Vec::new(); for c in template.children() { match &c.body { @@ -131,7 +131,7 @@ fn record(template: &Chunk<'_>, v: f64) -> Chunk<'static> { } /// A keyframed value record: `record`'s header with a key list of linear one-component keys. -fn keyed_record(template: &Chunk<'_>, keys: &[(i32, f64)]) -> Chunk<'static> { +pub fn keyed_record(template: &Chunk<'_>, keys: &[(i32, f64)]) -> Chunk<'static> { let Body::List { children, .. } = record(template, keys.first().map_or(0.0, |k| k.1)).body else { unreachable!("record builds a LIST") }; let mut children = children; let mut lhd3 = vec![0u8; 52]; @@ -229,39 +229,51 @@ fn find_glow_template(chunks: &[Chunk<'_>]) -> Option> { None } -/// Replaces every Glow (`ADBE Glo2` with its `sspc`) below `chunks` with `fx`; the number replaced. -fn replace_glow(chunks: &mut [Chunk<'_>], fx: &Fx, template: &Chunk<'_>) -> usize { +/// Replaces every Glow (`ADBE Glo2` with its `sspc`) below `chunks` with the effect `match_name` +/// and its `sspc`; the number replaced. +fn replace_glow(chunks: &mut [Chunk<'_>], match_name: &str, sspc: &Chunk<'static>) -> usize { let mut n = 0; for ch in chunks { let kids = ch.children_mut(); if let Some(at) = kids.iter().position(|k| k.is(b"tdmn") && k.bytes().is_some_and(|b| b.starts_with(b"ADBE Glo2\0"))) && kids.get(at + 1).is_some_and(|k| k.is_list(b"sspc")) { - kids[at] = tdmn(fx.match_name); - kids[at + 1] = sspc(fx, template); + kids[at] = tdmn(match_name); + kids[at + 1] = sspc.clone(); n += 1; } - n += replace_glow(kids, fx, template); + n += replace_glow(kids, match_name, sspc); } n } -/// `synthetic.aep` with `fx` in place of the Glow effect. -pub fn bytes_with(fx: &Fx) -> Vec { +/// `synthetic.aep` with the effect `match_name` in place of the Glow effect; `make` builds its +/// `sspc` from the Glow's value record (the template of every record). +pub fn bytes_with_effect(match_name: &str, make: impl Fn(&Chunk<'_>) -> Chunk<'static>) -> Vec { let file = parse(SYNTHETIC).unwrap(); let template = find_glow_template(&file.chunks).expect("Glow's A & B Midpoint record"); + let sspc = make(&template); let mut file = parse(SYNTHETIC).unwrap(); - assert_eq!(replace_glow(&mut file.chunks, fx, &template), 2, "the Glow effect and its shared definitions"); + assert_eq!(replace_glow(&mut file.chunks, match_name, &sspc), 2, "the Glow effect and its shared definitions"); write(&file).unwrap() } +/// `synthetic.aep` with `fx` in place of the Glow effect. +pub fn bytes_with(fx: &Fx) -> Vec { + bytes_with_effect(fx.match_name, |t| sspc(fx, t)) +} + /// Imports `synthetic.aep` with `fx` in place of its Glow: the EffectCraft effect `effect` (if /// imported) and the result. pub fn run(fx: &Fx, effect: &str) -> (Option, ImportResult) { - let bytes = bytes_with(fx); + import_bytes(&bytes_with(fx), effect) +} + +/// Imports `bytes`: the first EffectCraft effect `effect` (if imported) and the result. +pub fn import_bytes(bytes: &[u8], effect: &str) -> (Option, ImportResult) { let mut project = Project::default(); let none = |_: &str| false; - let r = import(&mut project, &bytes, &ImportOptions { allow_losses: true, ..ImportOptions::new(&none) }).unwrap(); + let r = import(&mut project, bytes, &ImportOptions { allow_losses: true, ..ImportOptions::new(&none) }).unwrap(); let g = project .comps() .flat_map(|(_, c)| c.layers.iter()) diff --git a/crates/aep/tests/it/import/puppet.rs b/crates/aep/tests/it/import/puppet.rs new file mode 100644 index 000000000..a3054286e --- /dev/null +++ b/crates/aep/tests/it/import/puppet.rs @@ -0,0 +1,171 @@ +//! After Effects' Puppet (`ADBE FreePin3`, #3093) arrives as EffectCraft's Puppet +//! (`ec.distort.puppet`) in its place in the stack, and what its meshes and pins hold is reported +//! mesh by mesh instead of the one line "has the effect 'Puppet'". The effect is built into the +//! committed `synthetic.aep` in place of its Glow (`fx_inject`, in memory), in the tree +//! docs/aep-format.md 3.7 gives for Puppet. That tree comes from an external scripting listing, +//! not a byte sample: these tests prove the reader's walk and its report, not the format. + +use effectcraft_aep::Chunk; +use effectcraft_aep::import::{ImportOptions, LossCategory, import}; +use effectcraft_project::Project; + +use crate::import::fx_inject::{bytes_with_effect, import_bytes, keyed_record, losses, nested, record, tdmn, utf8}; + +const SYNTHETIC: &[u8] = include_bytes!("../../fixtures/synthetic.aep"); +const PUPPET: &str = "ADBE FreePin3"; +const POS_ATOM: &str = "ADBE FreePin3 PosPin Atom"; + +fn tdsb(v: u32) -> Chunk<'static> { + Chunk::data(*b"tdsb", v.to_be_bytes().to_vec()) +} + +/// A property group of `entries` (match name, node). +fn group(entries: Vec<(&str, Chunk<'static>)>) -> Chunk<'static> { + let mut kids = vec![tdsb(1)]; + for (name, node) in entries { + kids.push(tdmn(name)); + kids.push(node); + } + Chunk::list(*b"tdgp", kids) +} + +/// A pin atom with its hidden vertex records and Position (keyed when `keys`). The values are +/// one-component records: the reader only asks whether a pin is keyed. +fn pin(t: &Chunk<'_>, atom: &'static str, keys: bool) -> (&'static str, Chunk<'static>) { + let position = if keys { keyed_record(t, &[(0, 1.0), (25_600, 2.0)]) } else { record(t, 1.0) }; + ( + atom, + group(vec![ + ("ADBE FreePin3 PosPin Vtx Offset", record(t, 0.0)), + ("ADBE FreePin3 PosPin Vtx Index", record(t, 7.0)), + ("ADBE FreePin3 PosPin Position", position), + ]), + ) +} + +/// `Mesh 1`: Triangles 500, Expansion 5, four Deform pins (one keyed, one with an atom name +/// nobody knows) and a property among them, no Overlap pin, one Stiffness pin, and a group +/// nobody knows. +fn full_mesh(t: &Chunk<'_>) -> Chunk<'static> { + let mesh_data = + Chunk::list(*b"tdbs", vec![tdsb(1), Chunk::data(*b"cdat", vec![0u8; 4]), Chunk::list(*b"aRbs", vec![Chunk::data(*b"aRbp", vec![1, 2, 3, 4])])]); + let deform = group(vec![ + pin(t, POS_ATOM, false), + pin(t, POS_ATOM, true), + pin(t, POS_ATOM, false), + pin(t, "ADBE FreePin3 Test Atom", false), + ("ADBE FreePin3 Test Prop", record(t, 3.0)), + ]); + let starch = group(vec![("ADBE FreePin3 StarchPin Atom", group(vec![("ADBE FreePin3 StarchPin Amount", record(t, 0.5))]))]); + group(vec![ + ("ADBE FreePin3 Mesh", mesh_data), + ("ADBE FreePin3 Mesh Tri Count", record(t, 500.0)), + ("ADBE FreePin3 Mesh Expansion", record(t, 5.0)), + ("ADBE FreePin3 PosPins", deform), + ("ADBE FreePin3 HghtPins", group(vec![])), + ("ADBE FreePin3 StarchPins", starch), + ("ADBE FreePin3 Test Group", group(vec![])), + ]) +} + +/// The Puppet instance: `fx_switch` is the value group's `tdsb`, `arap` its mesh tree (`None`: +/// none), `extra` more entries of its value group. +fn sspc(fx_switch: u32, arap: Option>, extra: Vec<(&str, Chunk<'static>)>) -> Chunk<'static> { + let pard = |kind: u8| { + let mut b = vec![0u8; 148]; + b[15] = kind; + Chunk::data(*b"pard", b) + }; + let part = vec![Chunk::data(*b"parn", 2u32.to_be_bytes().to_vec()), tdmn("ADBE FreePin3-0000"), pard(0), tdmn("ADBE Effect Built In Params"), pard(9)]; + let mut values = vec![tdsb(fx_switch)]; + if let Some(arap) = arap { + values.push(tdmn("ADBE FreePin3 ARAP Group")); + values.push(arap); + } + for (name, node) in extra { + values.push(tdmn(name)); + values.push(node); + } + Chunk::list(*b"sspc", vec![nested(*b"fnam", vec![utf8("Puppet")]), Chunk::list(*b"parT", part), Chunk::list(*b"tdgp", values)]) +} + +/// The layer that holds `effect`, the effect's place in that layer's stack and the stack's size. +fn stack_place(bytes: &[u8], effect: &str) -> Option<(String, usize, usize)> { + let mut project = Project::default(); + let none = |_: &str| false; + import(&mut project, bytes, &ImportOptions { allow_losses: true, ..ImportOptions::new(&none) }).unwrap(); + project.comps().flat_map(|(_, c)| c.layers.iter()).find_map(|l| { + let fx: Vec<_> = l.props.sub("effects")?.children.iter().filter_map(|n| n.as_group()).collect(); + let at = fx.iter().position(|g| g.match_id == effect)?; + Some((l.name.clone(), at, fx.len())) + }) +} + +#[test] +fn puppet_arrives_and_its_pins_are_reported_mesh_by_mesh() { + let bytes = bytes_with_effect(PUPPET, |t| { + let arap = group(vec![("ADBE FreePin3 Outlines", group(vec![])), ("ADBE FreePin3 Mesh Group", group(vec![("ADBE FreePin3 Mesh Atom", full_mesh(t))]))]); + sspc(1, Some(arap), vec![("ADBE FreePin3 On Transparent", record(t, 1.0))]) + }); + let (g, r) = import_bytes(&bytes, effectcraft_effects::puppet::ID); + let g = g.expect("an EffectCraft Puppet in the Glow's place"); + assert!(g.enabled); + assert_eq!(g.name, "Puppet"); + // No pin is made up: the rest places are not decoded. + assert_eq!(effectcraft_effects::puppet::pin_count(&g), 0); + // In the Glow's place in its layer's stack (the second of two effects there). + assert!(stack_place(SYNTHETIC, "ec.stylize.glow").is_some_and(|(_, at, n)| at > 0 && n > 1)); + assert_eq!(stack_place(&bytes, effectcraft_effects::puppet::ID), stack_place(SYNTHETIC, "ec.stylize.glow")); + let l = losses(&r, LossCategory::Effects, PUPPET); + assert_eq!(l.len(), 2, "{l:#?}"); + assert!(!l.iter().any(|d| d.contains("has the effect")), "not the old one-line report: {l:#?}"); + assert!(l.iter().any(|d| d.ends_with("property ADBE FreePin3 On Transparent (1) not imported")), "{l:#?}"); + let mesh = l.iter().find(|d| d.contains("imported without its meshes and pins")).expect("the mesh report"); + assert!( + mesh.ends_with( + ": Mesh 1 (Triangles 500, Expansion 5): Deform 4 pins (1 keyed) [ADBE FreePin3 PosPin Atom, ADBE FreePin3 Test Atom], \ + Overlap no pins, Stiffness 1 pin (0 keyed) [ADBE FreePin3 StarchPin Atom]; not recognised: ADBE FreePin3 Test Prop, ADBE FreePin3 Test Group" + ), + "{mesh}" + ); + assert_eq!(losses(&r, LossCategory::DamagedData, PUPPET), Vec::::new()); +} + +#[test] +fn many_meshes_are_listed_up_to_ten_and_names_once() { + let bytes = bytes_with_effect(PUPPET, |_| { + let mesh = || group(vec![("ADBE FreePin3 Test Group", group(vec![]))]); + let meshes = (0..12).map(|_| ("ADBE FreePin3 Mesh Atom", mesh())).collect(); + sspc(1, Some(group(vec![("ADBE FreePin3 Mesh Group", group(meshes))])), vec![]) + }); + let (_, r) = import_bytes(&bytes, effectcraft_effects::puppet::ID); + let l = losses(&r, LossCategory::Effects, PUPPET); + assert_eq!(l.len(), 1, "{l:#?}"); + assert!(l[0].ends_with("Mesh 9: no pin groups; Mesh 10: no pin groups; and 2 more; not recognised: ADBE FreePin3 Test Group"), "{}", l[0]); +} + +#[test] +fn a_puppet_without_a_mesh_loses_nothing_and_keeps_its_fx_switch() { + let bytes = bytes_with_effect(PUPPET, |_| sspc(0, Some(group(vec![("ADBE FreePin3 Mesh Group", group(vec![]))])), vec![])); + let (g, r) = import_bytes(&bytes, effectcraft_effects::puppet::ID); + let g = g.expect("an EffectCraft Puppet"); + assert!(!g.enabled, "switched off in the Effect Controls"); + assert_eq!(losses(&r, LossCategory::Effects, PUPPET), Vec::::new()); +} + +#[test] +fn a_puppet_whose_mesh_tree_is_not_found_is_reported() { + let bytes = bytes_with_effect(PUPPET, |t| sspc(1, None, vec![("ADBE FreePin3 Other Group", group(vec![("x", record(t, 1.0))]))])); + let (g, r) = import_bytes(&bytes, effectcraft_effects::puppet::ID); + assert!(g.is_some(), "the effect still arrives"); + let l = losses(&r, LossCategory::Effects, PUPPET); + assert_eq!(l.len(), 1, "{l:#?}"); + assert!( + l[0].ends_with( + "imported without meshes or pins: its mesh group (ADBE FreePin3 ARAP Group / ADBE FreePin3 Mesh Group) was not found or is not a group; \ + not recognised: ADBE FreePin3 Other Group" + ), + "{}", + l[0] + ); +} diff --git a/docs/aep-format.md b/docs/aep-format.md index d6ec7fb14..db0d79d1c 100644 --- a/docs/aep-format.md +++ b/docs/aep-format.md @@ -1,6 +1,6 @@ # After Effects project format (`.aep`) -> **Last reviewed:** 2026-11-05 · **Last updated:** 2026-11-05 · **Change:** versions: `svap` is the version that wrote the file, `head` bytes 4 to 7 the version it is written for, and what a Save a Copy As 25.x / 24.x of After Effects 2026 changes (section 1, "Versions"); before that: the stretch numerator is signed (a negative one reverses the layer, 981-983); layer styles (3.12b, 950-980); before that: footage: `sspc@118` of an image sequence is its folder's modification time (860, read-back x1-x3); before that: text: paragraph `/24`, `/35` and style `/68` are neutral for 0 and 1 (732-734, edited in place); before that: keyframes: the ease of mask path keys (599, 700), the spatial speed unit of fractional values (597, 598, 730); before that: text: character and paragraph settings, manual kerning, vertical text, `/nil` is neutral (S17: 538-578, 595, 596); before that: cameras, lights and 3D rotations (S16: the auto Position of a two-node camera is where After Effects renders it, 537; camera and light defaults read back 255, 256; Orientation `otst/otda` 488), Timewarp (529-533), an expression on an effect parameter (534); before that: text: style slot /13 is superscript / subscript (526-528; every scripted text of the corpus is superscript), wrapping box text 517; before that: effects of batch 5 (409-450, 511-516: integer sliders, checkbox defaults in `pard`, arbitrary data of Hue/Saturation and Levels, the parameters of Invert, Fast Box Blur, Gaussian Blur, Drop Shadow, Glow; section 3.7); before that: shape items of batch 5 (451-484, 519: ellipse, fill and stroke opacity, fill rule, group transform, shape layer anchor, trim paths, rectangle roundness, polystar fields, gradient default, nested groups, the defaults of every item; section 3.9); before that: track mattes: mode at `ldta` byte 107 and the matte layer id at byte 160 (cases 402-408, section 3.1); before that: text: automatic leading is verified (400); Exposure (`ADBE Exposure2`, cases 389-397): group start / end parameter types 13 / 14, float slider valid minimum and slider range (section 3.7); before that: text: U+0003 is a paragraph break (386, 387); before that: a stored text Anchor Point is pixels (385, now V); before that: the XML form `.aepx` is read into the same chunk tree (section 1, "The XML form"); the `head` save counter is a `u32` at byte 16; text documents for the importer (stroke colour, automatic leading, the font of each run, the undecoded-slot check, the text-layer Anchor Point, the Source Text record); before that: third round of verified field layouts (explicit-default semantics, type-major bezier ease, exact time stretch and in / out points, Time Remapping state, comp pixel aspect / shutter phase / display start, Point default, Layer Control None, dropdown selection, one `mkif` per mask, polystar and radial gradient records, text styles, camera and light options, marker cue data, audio and image-sequence footage) added to the typed view of `effectcraft-aep` · **Target:** Adobe After Effects 2026 +> **Last reviewed:** 2026-11-05 · **Last updated:** 2026-11-07 · **Change:** Puppet (`ADBE FreePin3`, 3.7): the property tree from an external scripting listing, **?** until a byte sample exists (#3093); before that: versions: `svap` is the version that wrote the file, `head` bytes 4 to 7 the version it is written for, and what a Save a Copy As 25.x / 24.x of After Effects 2026 changes (section 1, "Versions"); before that: the stretch numerator is signed (a negative one reverses the layer, 981-983); layer styles (3.12b, 950-980); before that: footage: `sspc@118` of an image sequence is its folder's modification time (860, read-back x1-x3); before that: text: paragraph `/24`, `/35` and style `/68` are neutral for 0 and 1 (732-734, edited in place); before that: keyframes: the ease of mask path keys (599, 700), the spatial speed unit of fractional values (597, 598, 730); before that: text: character and paragraph settings, manual kerning, vertical text, `/nil` is neutral (S17: 538-578, 595, 596); before that: cameras, lights and 3D rotations (S16: the auto Position of a two-node camera is where After Effects renders it, 537; camera and light defaults read back 255, 256; Orientation `otst/otda` 488), Timewarp (529-533), an expression on an effect parameter (534); before that: text: style slot /13 is superscript / subscript (526-528; every scripted text of the corpus is superscript), wrapping box text 517; before that: effects of batch 5 (409-450, 511-516: integer sliders, checkbox defaults in `pard`, arbitrary data of Hue/Saturation and Levels, the parameters of Invert, Fast Box Blur, Gaussian Blur, Drop Shadow, Glow; section 3.7); before that: shape items of batch 5 (451-484, 519: ellipse, fill and stroke opacity, fill rule, group transform, shape layer anchor, trim paths, rectangle roundness, polystar fields, gradient default, nested groups, the defaults of every item; section 3.9); before that: track mattes: mode at `ldta` byte 107 and the matte layer id at byte 160 (cases 402-408, section 3.1); before that: text: automatic leading is verified (400); Exposure (`ADBE Exposure2`, cases 389-397): group start / end parameter types 13 / 14, float slider valid minimum and slider range (section 3.7); before that: text: U+0003 is a paragraph break (386, 387); before that: a stored text Anchor Point is pixels (385, now V); before that: the XML form `.aepx` is read into the same chunk tree (section 1, "The XML form"); the `head` save counter is a `u32` at byte 16; text documents for the importer (stroke colour, automatic leading, the font of each run, the undecoded-slot check, the text-layer Anchor Point, the Source Text record); before that: third round of verified field layouts (explicit-default semantics, type-major bezier ease, exact time stretch and in / out points, Time Remapping state, comp pixel aspect / shutter phase / display start, Point default, Layer Control None, dropdown selection, one `mkif` per mask, polystar and radial gradient records, text styles, camera and light options, marker cue data, audio and image-sequence footage) added to the typed view of `effectcraft-aep` · **Target:** Adobe After Effects 2026 What `crates/aep` ([`effectcraft-aep`](../crates/aep/README.md)) reads and writes, and the evidence for each statement. Everything here was observed on project files we generated ourselves; no @@ -610,6 +610,52 @@ presets, and After Effects draws exactly the picked objects as selected (`crypto `crypto-07`: box and disc, the two objects of `mat_paint`). API: `CryptomatteData` (refuses data without `cry1`, a length past the end or a non-zero byte at 112). +**Puppet (`ADBE FreePin3`; ?: external listing, not the corpus, #3093).** No file of the +corpus, the committed fixtures or the samples holds a Puppet. The tree below comes from outside +the corpus: a public scripting listing of the effect's properties (a forum post, an After Effects +release from before the Advanced and Bend pins and Density). It is not bytes we have seen; that +After Effects writes it by the general rule (a `tdmn` and the `LIST tdgp` or `tdbs` it names, +nested in the instance's value group `sspc/tdgp`, as masks, shapes and layer styles are) is +**H**: + +```text +Puppet ADBE FreePin3 + On Transparent ADBE FreePin3 On Transparent + arap ADBE FreePin3 ARAP Group (hidden) + Auto-traced Shapes ADBE FreePin3 Outlines + Mesh ADBE FreePin3 Mesh Group (hidden) + Mesh 1 ADBE FreePin3 Mesh Atom + Mesh ADBE FreePin3 Mesh (hidden: the triangulation) + Triangles ADBE FreePin3 Mesh Tri Count + Expansion ADBE FreePin3 Mesh Expansion + Deform ADBE FreePin3 PosPins + Puppet Pin 1 ADBE FreePin3 PosPin Atom + Vertex Offset ADBE FreePin3 PosPin Vtx Offset (hidden, 2 values) + Vertex Index ADBE FreePin3 PosPin Vtx Index (hidden; 4294967295 = none) + Position ADBE FreePin3 PosPin Position + Overlap ADBE FreePin3 HghtPins (hidden while empty) + Stiffness ADBE FreePin3 StarchPins (hidden while empty) +``` + +A pin's rest place is not a property: it is a vertex of the hidden mesh (Vertex Index) plus an +offset, so it cannot be read without decoding the mesh data. The unit of Position (layer pixels, +or a fraction of the layer as effect points are) is **?**. The match names of the Overlap and +Starch pin atoms and their properties, of the Advanced and Bend pins (Scale, Rotation) and of +Density, Mesh Rotation Refinement and the Puppet Engine are **?**, and so is which of them are +`parT` parameters; whether After Effects stores some `parT` parameters of a fresh Puppet even at +their defaults (the importer would then report them every time) is **?**; whether a Puppet +without pins has an (empty) Mesh Group, or no ARAP group at all, is **?**. The importer +(`import/puppet.rs`) therefore brings the effect in as EffectCraft's Puppet without meshes or +pins and reports, per mesh, Triangles, Expansion and per pin group the pins, how many are keyed +or carry an expression, and their atom match names; every entry outside this tree is named in the +report. The sample that settles it: a fresh Puppet with no pins in one composition and, in +another, a 400 x 800 solid in a larger composition (pixels against fractions) with a Puppet of +three Position pins (one keyed, one moved off its rest place without +keys), one Advanced, one Bend, one Starch and one Overlap pin, Triangles, Expansion and Density +off their defaults, a second mesh, and a scripting read-back of every property's match name and +value, the hidden ones included. Pins added by script are reported to come out disabled, so the +pins are placed by hand or by a preset. + ### 3.8 Masks and bezier paths (`tdgp[ADBE Mask Parade]`) | Field | Chunk path | Offset | Type | Meaning | Evidence | Conf. | @@ -894,6 +940,7 @@ another value). **Effects** - `pard` byte 48 (flags: **?**), 68 / 72 (the point default as a percent pair: **V** in the corpus for 074 and 368, not exposed), 120 (the float slider default again as f32: **V**, not exposed), 124 (display decimals: **H**), 132..147 (fixed slider slider-max, default copy and flags; the low bit of @144 is set on the two percent-displayed sliders and clear on Scatter: **H** "display as percent"), the colour default copy at @60, and the stale memory after the parameter name. The fixed slider valid minimum is not decoded (the float slider one is, 389). +- Puppet (`ADBE FreePin3`, 3.7): the hidden mesh data, a pin's Vertex Index and Vertex Offset (its rest place), the unit of a pin's Position, the Overlap, Starch, Advanced and Bend pins, Density, Mesh Rotation Refinement and the Puppet Engine: no sample (**?**). - Effects renamed, or stacked twice on ONE layer (`Gradient Ramp 2`: does the second keep an empty `parT`?); which instance keeps the full `parT` when a second instance is created on a layer below the first; expressions on effect parameters; keyed per-channel Exposure values and a keyed checkbox; Curves / Levels (arrays), Fractal Noise, and whether the `tdpi` of a Layer Control holds an id or an index after the referenced layer is reordered or deleted. **Masks, shapes** diff --git a/docs/aep-import.md b/docs/aep-import.md index ed3ab57f5..5d268e503 100644 --- a/docs/aep-import.md +++ b/docs/aep-import.md @@ -1,6 +1,6 @@ # After Effects project import -> **Last reviewed:** 2026-11-05 · **Last updated:** 2026-11-05 · **Change:** the report names the After Effects version a file is written for and the one that wrote it (`aeVersion`); copies saved as 25.x and 24.x import like the 2026 save; before that: Curves and Mesh Warp are imported (961-965, 985; FORMAT S of the corpus); before that: a shape item's eye switch is imported (bit 0 of its group flags, 986 / 987: a switched-off Fill under Trim Paths is no longer drawn, render equal to After Effects), and a layer style's (switch group `tdsb` 0, 988); before that: a negative time stretch (Time Reverse Layer) is imported: in and out point in order, the layer plays backwards (981-983: render equal to After Effects at 7 points); before that: After Effects' None on Compound Blur, Displacement Map and Set Matte arrives as an explicit None (`NO_LAYER`), not as the owning layer; before that: layer styles are imported (the nine styles and Blending Options, 951-979; Global Light becomes the composition's); before that: the 27 effects of round 3 are in the table (`effectcraft_aep::effect_map`); before that: a layer of a clip, sequence or sound ends at its source's end (After Effects ends it there when it opens a project, read-back test f1), unless it is remapped or looped or runs less than a frame past; before that: keys of shape colours are read (the reader took their 152-byte spatial records for plain ones: `tdb4` byte 7 is 0 there, 854); before that: the effect table moved to `effectcraft_aep::effect_map`; point defaults in percent and a popup default slot of 0 (After Effects' save of a project it opened, e1 / e2 re-saves) are read; before that: the justification of right-to-left paragraphs is read relative to the direction (t7); before that: 24 more layer blend modes (906, 907); before that: 27 more effects are imported (batch 6: 903-905), with layer parameters; before that: a Rec. 709 working space also sets the output space (After Effects renders in the working space, 902); before that: a mask whose path was never set arrives as the source rectangle (900, 901); before that: Offset Paths' Copy Offset arrives as EffectCraft's (After Effects' value minus 1, 828); before that: project settings, image sequences, conformed clips and effect instance names are imported, next to the mattes, shapes, text settings and animators, effects, markers, time remapping, cameras and lights); before that: parallel and ambient lights (701, 702) and keyed Orientation (703) are imported; before that: masks on text and shape layers (705, 706: AE vs EffectCraft render 12 and 0 of 5184 points, glyph edges) and Merge Paths, Offset Paths, Repeater (707-710, 731; merge renders equal but for edges; Repeater copy opacity and Offset Paths' outline differ in EffectCraft's renderer) are imported; before that: keyframes: the ease of Anchor Point, effect point, effect colour and mask path keys is imported (597-599, 700, 730: within 0.5 px of After Effects' read-backs); before that: effects: Directional Blur, Radial Blur, CC Radial Blur, Venetian Blinds, Channel Blur, Black & White, Tritone, Luma Key, Simple Choker, Matte Choker and Transform are imported (711-723; render checks: CC Radial Blur and Channel Blur equal, Directional Blur within 5/255; Venetian Blinds, Radial Blur, Black & White (8/255), Tritone (19/255), Luma Key, Matte Choker and Transform differ in EffectCraft's renderer, see STATUS); before that: text: character and paragraph settings (stroke, scales, baseline shift, kerning, ligatures, tsume, indents, spacing, justified text, composer, direction, vertical text; 538-578) and text animators with range selectors (579-594, 114) are imported; render checks 594 (keyed range selector at 0 / 0.5 / 1 / 1.5 / 2.5 s), 595, 596 equal but for glyph edges; before that: cameras, spot and point lights, X / Y Rotation and Orientation, Timewarp and expressions on effect parameters are imported (render checks 486, 535-537 equal but for edges; 488 differs by 5.25 %, cause in EffectCraft's renderer not isolated); before that: text: superscript and subscript are imported (526-528); before that: effects: Invert, Fast Box Blur, Gaussian Blur, Drop Shadow, Glow, Fill, Hue/Saturation, Levels and five expression controls are imported, popups are mapped by item name, checkbox defaults come from the file; before that: shape layers are imported (groups, paths, paints, trim paths, round corners; 451-484, 519 added); before that: markers and Time Remapping are imported (509, 510 added); before that: track mattes are imported (402-408); before that: text: automatic leading is verified (400); effects: Exposure is imported (Channels, all twelve sliders, Bypass, keys), next to Tint and Gradient Ramp; before that: text: U+0003 is a paragraph break (386, 387); before that: a stored text Anchor Point is pixels (385, now V); before that: effects: Tint and Gradient Ramp are imported (all parameters and keys), other effects stay reported; `.aepx` is accepted; text layers are imported (Source Text with style runs, paragraphs and box text; fonts by PostScript name, missing fonts listed); layer styles are reported; before that: layer masks · **Target:** Adobe After Effects 2026 +> **Last reviewed:** 2026-11-05 · **Last updated:** 2026-11-07 · **Change:** After Effects' Puppet arrives as EffectCraft's Puppet without its meshes and pins, which are reported mesh by mesh (#3093; the storage is not sampled yet, aep-format 3.7); before that: the report names the After Effects version a file is written for and the one that wrote it (`aeVersion`); copies saved as 25.x and 24.x import like the 2026 save; before that: Curves and Mesh Warp are imported (961-965, 985; FORMAT S of the corpus); before that: a shape item's eye switch is imported (bit 0 of its group flags, 986 / 987: a switched-off Fill under Trim Paths is no longer drawn, render equal to After Effects), and a layer style's (switch group `tdsb` 0, 988); before that: a negative time stretch (Time Reverse Layer) is imported: in and out point in order, the layer plays backwards (981-983: render equal to After Effects at 7 points); before that: After Effects' None on Compound Blur, Displacement Map and Set Matte arrives as an explicit None (`NO_LAYER`), not as the owning layer; before that: layer styles are imported (the nine styles and Blending Options, 951-979; Global Light becomes the composition's); before that: the 27 effects of round 3 are in the table (`effectcraft_aep::effect_map`); before that: a layer of a clip, sequence or sound ends at its source's end (After Effects ends it there when it opens a project, read-back test f1), unless it is remapped or looped or runs less than a frame past; before that: keys of shape colours are read (the reader took their 152-byte spatial records for plain ones: `tdb4` byte 7 is 0 there, 854); before that: the effect table moved to `effectcraft_aep::effect_map`; point defaults in percent and a popup default slot of 0 (After Effects' save of a project it opened, e1 / e2 re-saves) are read; before that: the justification of right-to-left paragraphs is read relative to the direction (t7); before that: 24 more layer blend modes (906, 907); before that: 27 more effects are imported (batch 6: 903-905), with layer parameters; before that: a Rec. 709 working space also sets the output space (After Effects renders in the working space, 902); before that: a mask whose path was never set arrives as the source rectangle (900, 901); before that: Offset Paths' Copy Offset arrives as EffectCraft's (After Effects' value minus 1, 828); before that: project settings, image sequences, conformed clips and effect instance names are imported, next to the mattes, shapes, text settings and animators, effects, markers, time remapping, cameras and lights); before that: parallel and ambient lights (701, 702) and keyed Orientation (703) are imported; before that: masks on text and shape layers (705, 706: AE vs EffectCraft render 12 and 0 of 5184 points, glyph edges) and Merge Paths, Offset Paths, Repeater (707-710, 731; merge renders equal but for edges; Repeater copy opacity and Offset Paths' outline differ in EffectCraft's renderer) are imported; before that: keyframes: the ease of Anchor Point, effect point, effect colour and mask path keys is imported (597-599, 700, 730: within 0.5 px of After Effects' read-backs); before that: effects: Directional Blur, Radial Blur, CC Radial Blur, Venetian Blinds, Channel Blur, Black & White, Tritone, Luma Key, Simple Choker, Matte Choker and Transform are imported (711-723; render checks: CC Radial Blur and Channel Blur equal, Directional Blur within 5/255; Venetian Blinds, Radial Blur, Black & White (8/255), Tritone (19/255), Luma Key, Matte Choker and Transform differ in EffectCraft's renderer, see STATUS); before that: text: character and paragraph settings (stroke, scales, baseline shift, kerning, ligatures, tsume, indents, spacing, justified text, composer, direction, vertical text; 538-578) and text animators with range selectors (579-594, 114) are imported; render checks 594 (keyed range selector at 0 / 0.5 / 1 / 1.5 / 2.5 s), 595, 596 equal but for glyph edges; before that: cameras, spot and point lights, X / Y Rotation and Orientation, Timewarp and expressions on effect parameters are imported (render checks 486, 535-537 equal but for edges; 488 differs by 5.25 %, cause in EffectCraft's renderer not isolated); before that: text: superscript and subscript are imported (526-528); before that: effects: Invert, Fast Box Blur, Gaussian Blur, Drop Shadow, Glow, Fill, Hue/Saturation, Levels and five expression controls are imported, popups are mapped by item name, checkbox defaults come from the file; before that: shape layers are imported (groups, paths, paints, trim paths, round corners; 451-484, 519 added); before that: markers and Time Remapping are imported (509, 510 added); before that: track mattes are imported (402-408); before that: text: automatic leading is verified (400); effects: Exposure is imported (Channels, all twelve sliders, Bypass, keys), next to Tint and Gradient Ramp; before that: text: U+0003 is a paragraph break (386, 387); before that: a stored text Anchor Point is pixels (385, now V); before that: effects: Tint and Gradient Ramp are imported (all parameters and keys), other effects stay reported; `.aepx` is accepted; text layers are imported (Source Text with style runs, paragraphs and box text; fonts by PostScript name, missing fonts listed); layer styles are reported; before that: layer masks · **Target:** Adobe After Effects 2026 File ▸ Import ▸ After Effects Project… (`file.importAep`) reads an `.aep` or its XML form `.aepx` and adds its items to the open project, in a folder named after the file (as After Effects does when it imports a project). @@ -58,7 +58,7 @@ outside the sampled ones keeps the current value and is reported as `project set | Text | the Source Text of a text layer: the text (paragraphs separated by CR; a hard line break is a CR too; U+0003 is laid out by After Effects exactly like a CR (386 against 387) and becomes a CR), per style run the font (PostScript name), size, fill and stroke colour, whether fill and stroke are drawn, stroke width, stroke over fill (one switch for the text), tracking, leading (automatic or explicit), faux bold, faux italic, all caps, small caps, superscript and subscript (526-528), horizontal and vertical scale, baseline shift, automatic kerning (metrics, optical, none), ligatures, tsume (538-578); per paragraph the justification (left, centre, right and the four justified variants), first-line / start / end indent, space before / after, direction, composer, hanging punctuation (in a right-to-left paragraph the stored justification is relative to the direction: After Effects lays 0 and 3 out flush right and 1 and 4 flush left, read-back test t7, so they arrive as right / left); point text or box text (box size and top-left in layer pixels); vertical right-to-left text (575) | | Text animators | every animator with its name and its range selectors (Start, End, Offset, or the Index range when Units is Index; Units, Based On, Mode, Amount, Shape, Smoothness, Ease High / Low, Randomize Order, Random Seed) and the properties Anchor Point, Position, Scale, Skew, Skew Axis, Rotation, Opacity, Fill Color, Stroke Color, Stroke Width, Tracking Amount, Line Spacing, Blur, Character Offset and Character Range, with keys and expressions (579-594, 114, 728). Values are stored as After Effects shows them; popups are 1-based in the file | | Masks | every mask of an imported layer, in stack order (on text and shape layers, which have no source, the stored mask box is in layer pixels: 705, 706): name, path (vertices and tangents in layer pixels, open or closed), mode (None, Add, Subtract, Intersect, Lighten, Darken, Difference), inverted, feather (x, y in pixels), opacity (percent), expansion (pixels); path keyframes (time, linear or hold sides, roving, label), feather / opacity / expansion keyframes with ease | -| Effects | **Curves** (961-964: the five curves' points from the arbitrary data as EffectCraft's `x,y` points in 0..1; render within 6 levels: EffectCraft interpolates monotone, After Effects stores a natural spline) and **Mesh Warp** (965, 985: Rows, Columns, Quality and the Distortion Mesh as per-vertex offsets in layer pixels; Bezier handles moved on their own are kept as eight extra numbers of the vertex for the export and reported, EffectCraft draws the mesh bilinear; the header is rows + 1, columns + 1; render 985: 1.4 % of pixels > 2 levels around the moved vertex), **Tint**, **Gradient Ramp**, **Exposure**, **Invert**, **Fast Box Blur**, **Gaussian Blur**, **Drop Shadow**, **Glow**, **Fill**, **Hue/Saturation**, **Levels**, **Timewarp** (Method, Adjust Time By, Speed with keys, Source Frame; 529-533), **Directional Blur**, **Radial Blur**, **CC Radial Blur**, **Venetian Blinds**, **Channel Blur**, **Black & White**, **Tritone**, **Luma Key**, **Simple Choker**, **Matte Choker**, **Transform** (all parameters; 711-723) and the expression controls **Slider**, **Angle**, **Checkbox**, **Color** and **Point Control** (table below) on any imported layer (also text and shape layers and layers with masks), in stack order, with the instance name, every parameter (static value or default) and its keyframes; also the second and later instances of a type, whose parameter definitions are only in the project's shared definition list. Other effects are reported (below) | +| Effects | **Curves** (961-964: the five curves' points from the arbitrary data as EffectCraft's `x,y` points in 0..1; render within 6 levels: EffectCraft interpolates monotone, After Effects stores a natural spline) and **Mesh Warp** (965, 985: Rows, Columns, Quality and the Distortion Mesh as per-vertex offsets in layer pixels; Bezier handles moved on their own are kept as eight extra numbers of the vertex for the export and reported, EffectCraft draws the mesh bilinear; the header is rows + 1, columns + 1; render 985: 1.4 % of pixels > 2 levels around the moved vertex), **Tint**, **Gradient Ramp**, **Exposure**, **Invert**, **Fast Box Blur**, **Gaussian Blur**, **Drop Shadow**, **Glow**, **Fill**, **Hue/Saturation**, **Levels**, **Timewarp** (Method, Adjust Time By, Speed with keys, Source Frame; 529-533), **Directional Blur**, **Radial Blur**, **CC Radial Blur**, **Venetian Blinds**, **Channel Blur**, **Black & White**, **Tritone**, **Luma Key**, **Simple Choker**, **Matte Choker**, **Transform** (all parameters; 711-723) and the expression controls **Slider**, **Angle**, **Checkbox**, **Color** and **Point Control** (table below) on any imported layer (also text and shape layers and layers with masks), in stack order, with the instance name, every parameter (static value or default) and its keyframes; also the second and later instances of a type, whose parameter definitions are only in the project's shared definition list. **Puppet** arrives in its place with its name and fx switch but without meshes and pins (a pin's rest place lies in the mesh data, not decoded yet); per mesh the report gives Triangles, Expansion and each pin group's pins, keyed pins and atom match names. Other effects are reported (below) | | Layer styles | Drop Shadow, Inner Shadow, Outer Glow, Inner Glow, Bevel and Emboss, Satin, Color Overlay, Gradient Overlay and Stroke when applied (switch group `tdsb` 1): every parameter, starting from After Effects' defaults (Use Global Light is off there), with keys on scalars and colours and expressions; Blending Options: Fill Opacity, the channel switches, Blend Interior Styles as Group, Use Blend Ranges, and Global Light Angle / Altitude, which the composition adopts (one setting per composition here). Units and popups through `effectcraft_aep::style_map` (aep-format 3.12b). Render check against After Effects (`proof\styles`): drop shadow, inner shadow, satin, colour overlay, stroke within a few levels; glow and bevel intensities and the Gradient Overlay direction differ in EffectCraft's renderer | | Shape layers | groups (nested, with anchor, position, scale, skew, skew axis, rotation, opacity), rectangle (size, position, roundness), ellipse (size, position), polystar (star or polygon, points, position, rotation, radii, roundness), bezier path (vertices and tangents in layer pixels, path keys), fill (colour, opacity, fill rule), stroke (colour, opacity, width, cap, join, miter limit), gradient fill and stroke (linear or radial, start and end point; the default white-to-black colours), trim paths (start, end, offset, trim multiple shapes), round corners (radius), merge paths (mode; 707, 708), offset paths (amount, line join, miter limit, copies, copy offset; 710; After Effects offsets copy *i* by Amount x (*i* + Copy Offset), default 1, EffectCraft by Amount x (*i* + 1 + copyOffset), so the copy offset arrives 1 less, also its keys; an expression on it is kept and reported; 826-828, 828 renders equal to After Effects on every grid point), repeater (copies, offset, composite, transform; 709), in file order, with keyframes and expressions, the operators' defaults as After Effects reads them back (731); the layer anchor in pixels; 238-242, 330-333, 451-484, 519, 705-710, 731 | | Markers | layer and composition markers: time (layer time for layer markers, exact frames), duration (1/600 s units, 509, 510), comment, chapter, URL, frame target, label, cue point (name, event or navigation, parameters); 122, 123, 249, 347-349, 509, 510 | From 5f73e5b5e935aae74587d18f20034f93a85e811e Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 17:03:59 +0100 Subject: [PATCH 25/40] =?UTF-8?q?Time=20stretch:=20hold=20a=20loaded=20or?= =?UTF-8?q?=20imported=20stretch=20to=20=C2=B11=20%=20to=20=C2=B19900=20%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A project file, an .aep, a timeline document or a Lottie file could give a layer a time stretch of 1e-300 %, 0 or 1e300 %. Layer and comp time divide by it and the audio mix read about usize::MAX source samples for one block, which overflowed or tried a huge allocation and aborted the app. - limits::stretch brings a stretch within After Effects' range (±1 % to ±9900 %, Layer.stretch in the scripting guide), sign kept; 0 and NaN are 100 %. Opening a project file corrects each layer and says so; a stretch written as null (NaN in an auto-save) now opens instead of failing. - .aep import and Lottie import clamp and report the stretch; timeline import clamps the clip speed and warns. - layer.timeStretch refuses a non-number and more than 9900 %; the Time Stretch dialog's ranges match. - Layer::layer_time / comp_time and the audio mix use the clamped stretch, so a value set in memory can't divide by zero or read without bound. Fixes #3247 --- crates/aep/src/import/build.rs | 9 +- crates/aep/tests/it/import/synthetic.rs | 41 ++++++++ crates/engine/src/cmd/layer_time.rs | 7 ++ crates/engine/src/tests/limits.rs | 18 ++++ crates/interchange/src/import.rs | 24 ++++- crates/interchange/src/tests.rs | 18 ++++ crates/lottie/src/import.rs | 7 +- crates/lottie/src/tests.rs | 15 +++ crates/project/src/layer.rs | 28 +++++- crates/project/src/limits.rs | 113 +++++++++++++++++++++- crates/render/src/audio.rs | 7 +- crates/render/src/tests.rs | 1 + crates/render/src/tests/stretch_limits.rs | 96 ++++++++++++++++++ crates/ui-egui/src/panels/key_dialogs.rs | 16 ++- 14 files changed, 389 insertions(+), 11 deletions(-) create mode 100644 crates/render/src/tests/stretch_limits.rs diff --git a/crates/aep/src/import/build.rs b/crates/aep/src/import/build.rs index 4ec346328..ded1e64ad 100644 --- a/crates/aep/src/import/build.rs +++ b/crates/aep/src/import/build.rs @@ -681,7 +681,14 @@ fn apply_timing(l: &mut Layer, h: &LayerHeader, tm: &TimeMap, name: &str, col: & col.lose(LossCategory::DamagedData, format!("layer '{name}': the time stretch is zero or unreadable, 100 % is used")); Rational { num: 1, den: 1 } }); - l.stretch = stretch.to_f64().map_or(100.0, |r| r * 100.0); + let stored = stretch.to_f64().map_or(100.0, |r| r * 100.0); + // A ratio such as 1/2^31 (5e-8 %) or 2^31/1 is outside what After Effects allows (±1 % to + // ±9900 %); taken as stored, the layer and audio time would divide by ~0 (#3247). The in and + // out points keep the comp times the file stores. + l.stretch = effectcraft_project::limits::stretch(stored); + if l.stretch.to_bits() != stored.to_bits() { + col.lose(LossCategory::DamagedData, format!("layer '{name}': the time stretch of {stored:e} % is outside ±1 % to ±9900 %, {} % is used", l.stretch)); + } // A stored time with a zero denominator (or a sum that overflows) has no value; it is read as 0 // and reported, so the layer's timing never changes silently. let unreadable: Vec<&str> = [("start", h.start), ("in point", h.in_relative), ("out point", h.out_relative)] diff --git a/crates/aep/tests/it/import/synthetic.rs b/crates/aep/tests/it/import/synthetic.rs index 18709f9e5..e2fb20da4 100644 --- a/crates/aep/tests/it/import/synthetic.rs +++ b/crates/aep/tests/it/import/synthetic.rs @@ -273,6 +273,47 @@ fn layer_times_with_a_zero_denominator_are_reported() { assert!(losses(&r.unwrap(), LossCategory::DamagedData).is_empty()); } +/// The time stretch of every imported layer. +fn stretches(p: &Project) -> Vec { + p.items.values().filter_map(|i| if let ItemKind::Comp(c) = &i.kind { Some(c) } else { None }).flat_map(|c| c.layers.iter().map(|l| l.stretch)).collect() +} + +#[test] +fn a_time_stretch_outside_one_to_9900_percent_is_clamped_and_reported() { + // ldta byte 8 is the stretch numerator (i32), byte 108 the denominator (u32). 1/(2^31 - 1) is + // about 5e-8 %: imported as stored, the layer and audio time divided by ~0 (#3247). + for (num, den, want) in [(1i32, i32::MAX as u32, 1.0), (-1, i32::MAX as u32, -1.0), (i32::MAX, 1, 9900.0), (i32::MIN, 1, -9900.0)] { + let bytes = mutate(&mut |c| { + if c.id == *b"ldta" { + set_data(c, 8, &num.to_be_bytes()); + set_data(c, 108, &den.to_be_bytes()); + } + }); + let (p, r) = run(&bytes, true); + let r = r.unwrap(); + let found = losses(&r, LossCategory::DamagedData); + assert!(found.iter().any(|d| d.contains("time stretch") && d.contains("outside")), "{num}/{den}: {found:?}"); + let s = stretches(&p); + assert!(!s.is_empty() && s.iter().all(|v| *v == want), "{num}/{den}: {s:?}"); + let (p, r) = run(&bytes, false); + assert!(r.is_err(), "{num}/{den}: strict import must refuse"); + assert!(p.items.is_empty()); + } + // A small stretch within the range (1/64: 1.5625 %) and -9900 % itself are no damage. + for (num, den, want) in [(1i32, 64u32, 1.5625), (-99, 1, -9900.0)] { + let bytes = mutate(&mut |c| { + if c.id == *b"ldta" { + set_data(c, 8, &num.to_be_bytes()); + set_data(c, 108, &den.to_be_bytes()); + } + }); + let (p, r) = run(&bytes, true); + let r = r.unwrap(); + assert!(!losses(&r, LossCategory::DamagedData).iter().any(|d| d.contains("time stretch")), "{num}/{den}: {:?}", r.report.losses); + assert!(stretches(&p).iter().all(|v| *v == want), "{num}/{den}: {:?}", stretches(&p)); + } +} + /// The project with `nhed` bytes from `at` replaced. fn header(at: usize, bytes: &[u8]) -> Vec { mutate(&mut |c| { diff --git a/crates/engine/src/cmd/layer_time.rs b/crates/engine/src/cmd/layer_time.rs index 4ecf725ec..a6fe3d990 100644 --- a/crates/engine/src/cmd/layer_time.rs +++ b/crates/engine/src/cmd/layer_time.rs @@ -59,9 +59,16 @@ fn time_stretch(s: &mut Session, p: &Value) -> Result { (None, Some(d)) if span > 0.0 => old * d / span, _ => old, }; + if !new.is_finite() { + return Err(bad("layer.timeStretch", "the stretch factor must be a number")); + } if new.abs() < 1.0 { return Err(bad("layer.timeStretch", "the stretch factor must be at least 1 %")); } + // After Effects' largest stretch; a project file holds no more either (#3247). + if new.abs() > effectcraft_project::limits::MAX_STRETCH { + return Err(bad("layer.timeStretch", "the stretch factor must be at most 9900 %")); + } // The hold point keeps showing the same layer time. let h = match hold { "current" => cti, diff --git a/crates/engine/src/tests/limits.rs b/crates/engine/src/tests/limits.rs index 524719bbf..9c156c4f7 100644 --- a/crates/engine/src/tests/limits.rs +++ b/crates/engine/src/tests/limits.rs @@ -103,6 +103,24 @@ fn commands_cap_sizes_at_30000_px() { assert_eq!((f.width, f.height, f.frame_rate), (limits::MAX_SIZE, 8, FrameRate::FPS_29_97)); } +/// Time Stretch takes After Effects' range, ±1 % to ±9900 %: before, 1e300 % was set, and a +/// project file holding it opened at 9900 % (#3247). +#[test] +fn time_stretch_refuses_more_than_9900_percent() { + let mut s = Session::default(); + s.execute("comp.new", json!({"name": "Main", "width": 64, "height": 32, "frameRate": 30, "duration": 2})).unwrap(); + let layer = s.execute("layer.newSolid", json!({"color": "#ff0000"})).unwrap()["layer"].as_u64().unwrap(); + let stretch = |s: &Session| s.active_comp().unwrap().layers.iter().find(|l| l.id.0 == layer).unwrap().stretch; + for pct in [1e300, -1e300, 9900.5] { + assert!(s.execute("layer.timeStretch", json!({"layers": [layer], "percent": pct})).is_err(), "{pct}"); + assert_eq!(stretch(&s), 100.0, "{pct}"); + } + for pct in [limits::MAX_STRETCH, -limits::MAX_STRETCH] { + s.execute("layer.timeStretch", json!({"layers": [layer], "percent": pct})).unwrap(); + assert_eq!(stretch(&s), pct); + } +} + #[test] fn a_project_with_a_precomp_cycle_opens_adds_and_renders_without_running_out_of_stack() { // Comps A and B nest each other (a damaged file); C is unrelated. Checking whether A diff --git a/crates/interchange/src/import.rs b/crates/interchange/src/import.rs index 9789ceb89..22e22b4f2 100644 --- a/crates/interchange/src/import.rs +++ b/crates/interchange/src/import.rs @@ -522,11 +522,31 @@ impl Importer<'_> { // ---- timing let start = tick_in(ti.start); let dur = tick_in(ti.duration); - let speed = if ti.speed.abs() < 1e-9 { 1.0 } else { ti.speed.abs() }; + // A zero, tiny (below 1e-9) or non-finite speed plays at 100 %. Otherwise the layer's + // stretch (100 / speed) is held to the range the app supports (±1 % to ±9900 %): a speed + // of 1e300 or 1e-300 from a damaged file made the layer and audio time divide by ~0 + // (#3247). The speed follows the stretch so the start time below matches it. + let raw = ti.speed.abs(); + let (speed, stretch) = if !raw.is_finite() || raw < 1e-9 { + // A speed of exactly 0 keeps its old silent 100 %; a tiny or non-finite one is named. + if !raw.is_finite() || raw > 0.0 { + self.warn(format!("clip \"{}\": a speed of {} is not supported (100 % used)", ti.name, ti.speed)); + } + (1.0, 100.0) + } else { + let stretch = effectcraft_project::limits::stretch(100.0 / raw); + if stretch.to_bits() == (100.0 / raw).to_bits() { + (raw, stretch) + } else { + let speed = 100.0 / stretch; + self.warn(format!("clip \"{}\": a speed of {:e} % is outside what a layer supports ({} % used)", ti.name, raw * 100.0, speed * 100.0)); + (speed, stretch) + } + }; let reverse = ti.reverse || ti.speed < 0.0; let src_in = tick_in(ti.source_in); let span = Tick((dur.0 as f64 * speed).round() as i64); - l.stretch = if reverse { -100.0 / speed } else { 100.0 / speed }; + l.stretch = if reverse { -stretch } else { stretch }; l.start_time = if reverse { start + Tick(((src_in + span).0 as f64 / speed).round() as i64) } else { start - Tick((src_in.0 as f64 / speed).round() as i64) }; l.in_point = start; diff --git a/crates/interchange/src/tests.rs b/crates/interchange/src/tests.rs index f4c9158f8..b451ecf81 100644 --- a/crates/interchange/src/tests.rs +++ b/crates/interchange/src/tests.rs @@ -314,6 +314,24 @@ fn imports_fcp7_xml_fcpxml_and_otio() { } } +/// A clip speed past what a layer's stretch supports (±1 % to ±9900 %) is held to it and named. +/// Before, a speed of 1e6 gave a stretch of 1e-4 % and the layer and audio time divided by ~0 +/// (#3247). +#[test] +fn an_extreme_clip_speed_is_held_to_the_stretch_range() { + for (speed, stretch) in [(1e6, 1.0), (1e-6, 9900.0)] { + let (mut doc, main) = edit(); + doc.sequence_mut(main).unwrap().video_tracks[1].items[0].speed = speed; + let (bytes, _) = fc::export(&doc, main, fc::Format::Otio, &Default::default()).unwrap(); + let (p, r) = import_doc(&bytes, "Main.otio", &mut probe); + let main_comp = r.comps.iter().copied().find(|c| p.item(*c).unwrap().name == "Main").expect("Main comp"); + let c = p.comp(main_comp).unwrap(); + let stretched: Vec = c.layers.iter().map(|l| l.stretch).filter(|s| (s - 100.0).abs() > 1e-9).collect(); + assert_eq!(stretched, [stretch], "speed {speed}"); + assert!(r.warnings.iter().any(|w| w.contains("speed") && w.contains("outside")), "speed {speed}: {:?}", r.warnings); + } +} + #[test] fn imports_aaf_and_omf() { let (doc, main) = edit(); diff --git a/crates/lottie/src/import.rs b/crates/lottie/src/import.rs index 53b1ba71c..57ef6427a 100644 --- a/crates/lottie/src/import.rs +++ b/crates/lottie/src/import.rs @@ -431,7 +431,12 @@ fn build_layers(cx: &mut Ctx, project: &mut Project, comp: &mut Comp, layers: &[ // Below 1 % (or 0) the layer time divides by ~0, and layer.timeStretch refuses it too. let sr = f(j, "sr").unwrap_or(1.0); l.stretch = if sr.is_finite() && sr.abs() >= 0.01 { - sr * 100.0 + // Past ±9900 % too (#3247): the largest stretch a layer supports, sign kept. + let pct = effectcraft_project::limits::stretch(sr * 100.0); + if pct.to_bits() != (sr * 100.0).to_bits() { + cx.im.warn(format!("{name}: a time stretch of {} % is not supported ({pct} % used)", sr * 100.0)); + } + pct } else { cx.im.warn(format!("{name}: a time stretch of {} % is not supported (100 % used)", sr * 100.0)); 100.0 diff --git a/crates/lottie/src/tests.rs b/crates/lottie/src/tests.rs index d26b3642d..414c875f0 100644 --- a/crates/lottie/src/tests.rs +++ b/crates/lottie/src/tests.rs @@ -520,6 +520,21 @@ fn zero_time_stretch_is_not_imported() { assert!(imp.warnings.iter().any(|w| w.contains("time stretch")), "{:?}", imp.warnings); } +#[test] +fn a_time_stretch_past_9900_percent_is_held_to_it() { + // `sr` 1e300 was imported as 1e302 % (#3247); the sign of a reversed layer is kept. + for (sr, want) in [(1e300, 9900.0), (-1e300, -9900.0), (99.0, 9900.0)] { + let doc = json!({"w": 20, "h": 20, "fr": 30, "ip": 0, "op": 30, "assets": [], + "layers": [{"ty": 1, "ind": 1, "sc": "#ff0000", "sw": 20, "sh": 20, "sr": sr, "ip": 0, "op": 30, "st": 0, "ks": {}}]}); + let mut q = Project::default(); + let imp = import(&mut q, doc.to_string().as_bytes(), "Imported", "", &mut |_| None).unwrap(); + let l = &q.comp(imp.comp).unwrap().layers[0]; + assert_eq!(l.stretch, want, "sr {sr}"); + let warned = imp.warnings.iter().any(|w| w.contains("time stretch")); + assert_eq!(warned, sr != 99.0, "sr {sr}: {:?}", imp.warnings); + } +} + #[test] fn embedded_glyphs_are_reported_when_dropped() { let glyph = |ch: &str, fam: &str| json!({"ch": ch, "size": 100, "style": "Regular", "w": 60, "fFamily": fam, "data": {"shapes": []}}); diff --git a/crates/project/src/layer.rs b/crates/project/src/layer.rs index 34eeb50c0..bc747bd88 100644 --- a/crates/project/src/layer.rs +++ b/crates/project/src/layer.rs @@ -470,6 +470,20 @@ pub enum AutoOrient { TowardsPointOfInterest, } +/// A stretch written as `null` (a NaN or infinite stretch: JSON holds neither, and auto-saves +/// write it so) reads as NaN, so the project still opens and loading brings it to 100 % with a +/// note ([`crate::limits::stretch`], #3247) instead of the whole file being refused. An infinite +/// stretch therefore also reopens at 100 %, not at ±9900 %. +fn stretch_or_nan<'de, D: serde::Deserializer<'de>>(d: D) -> Result { + Ok(Option::::deserialize(d)?.unwrap_or(f64::NAN)) +} + +/// `t × mul / div` in ticks, within [`Tick::MIN`]..=[`Tick::MAX`] (the cast saturates, NaN is 0), +/// so a layer time of an extreme stretch can't overflow later tick arithmetic. +fn scaled(t: Tick, mul: f64, div: f64) -> Tick { + Tick(((t.0 as f64 * mul / div) as i64).clamp(Tick::MIN.0, Tick::MAX.0)) +} + #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Layer { pub id: LayerId, @@ -484,6 +498,7 @@ pub struct Layer { pub in_point: Tick, pub out_point: Tick, /// Time stretch in percent (100 = normal, negative = reversed). + #[serde(deserialize_with = "stretch_or_nan")] pub stretch: f64, pub switches: Switches, pub blend_mode: BlendMode, @@ -555,15 +570,24 @@ impl Layer { t >= self.in_point && t < self.out_point } + /// The time stretch the layer plays at: [`Layer::stretch`] within + /// [`limits::stretch`](crate::limits::stretch) (a damaged value that got past loading, 0 or + /// NaN, never divides the layer's time by zero). + pub fn effective_stretch(&self) -> f64 { + crate::limits::stretch(self.stretch) + } + /// Layer time for a comp time (stretch-aware). pub fn layer_time(&self, comp_t: Tick) -> Tick { let d = comp_t - self.start_time; - if (self.stretch - 100.0).abs() < 1e-9 { d } else { Tick((d.0 as f64 * 100.0 / self.stretch) as i64) } + let s = self.effective_stretch(); + if (s - 100.0).abs() < 1e-9 { d } else { scaled(d, 100.0, s) } } /// Comp time for a layer time. pub fn comp_time(&self, layer_t: Tick) -> Tick { - if (self.stretch - 100.0).abs() < 1e-9 { self.start_time + layer_t } else { self.start_time + Tick((layer_t.0 as f64 * self.stretch / 100.0) as i64) } + let s = self.effective_stretch(); + if (s - 100.0).abs() < 1e-9 { self.start_time + layer_t } else { self.start_time + scaled(layer_t, s, 100.0) } } pub fn transform(&self) -> Option<&PropGroup> { diff --git a/crates/project/src/limits.rs b/crates/project/src/limits.rs index 998f40225..7a74c992b 100644 --- a/crates/project/src/limits.rs +++ b/crates/project/src/limits.rs @@ -27,6 +27,30 @@ pub const MAX_PIXEL_ASPECT: f64 = 10.0; pub const MOTION_BLUR_SAMPLES: (u32, u32) = (2, 64); /// Composition Settings ▸ Advanced ▸ Adaptive Sample Limit. pub const ADAPTIVE_SAMPLE_LIMIT: (u32, u32) = (16, 256); +/// The smallest time stretch, in percent, either way (After Effects sets a stretch between 0 and +/// 1 % to 1 %, between -1 % and 0 to -1 %; `layer.timeStretch` refuses less). +pub const MIN_STRETCH: f64 = 1.0; +/// The largest time stretch, in percent, either way (After Effects' `Layer.stretch` range is +/// -9900 to 9900). +pub const MAX_STRETCH: f64 = 9900.0; + +/// A layer's time stretch from [`MIN_STRETCH`] to [`MAX_STRETCH`] % either way, its sign (a +/// reversed layer) kept; 100 % for 0 or NaN. Layer and comp time divide by the stretch, and the +/// audio mix reads `100 / stretch` source samples per sample, so a stretch of 1e-300 % or NaN +/// from a damaged file must not reach them (#3247). +pub fn stretch(v: f64) -> f64 { + if v.is_nan() || v == 0.0 { + return 100.0; + } + // Infinity clamps to the largest stretch with its sign. + v.signum() * v.abs().clamp(MIN_STRETCH, MAX_STRETCH) +} + +/// A stretch for a note: a plain number in a readable range, scientific notation beyond it (a +/// plain 1e-300 would print 300 digits). +fn percent(v: f64) -> String { + if v == 0.0 || (1e-3..1e7).contains(&v.abs()) { format!("{v} %") } else { format!("{v:e} %") } +} /// A width or height from 1 to [`MAX_SIZE`]. pub fn size(v: u64) -> u32 { @@ -97,9 +121,11 @@ fn repair_comp(name: &str, c: &Comp, notes: &mut Vec) -> Option { let duration = c.duration.max(rate.frame_duration()); let samples = c.motion_blur_samples.clamp(MOTION_BLUR_SAMPLES.0, MOTION_BLUR_SAMPLES.1); let adaptive = c.motion_blur_adaptive_limit.clamp(ADAPTIVE_SAMPLE_LIMIT.0, ADAPTIVE_SAMPLE_LIMIT.1); + let stretch_ok = |l: &crate::Layer| stretch(l.stretch).to_bits() == l.stretch.to_bits(); let unchanged = (width, height, rate, duration, samples, adaptive) == (c.width, c.height, c.frame_rate, c.duration, c.motion_blur_samples, c.motion_blur_adaptive_limit) - && pa.to_bits() == c.pixel_aspect.to_bits(); + && pa.to_bits() == c.pixel_aspect.to_bits() + && c.layers.iter().all(stretch_ok); if unchanged { return None; } @@ -125,6 +151,12 @@ fn repair_comp(name: &str, c: &Comp, notes: &mut Vec) -> Option { } (n.width, n.height, n.pixel_aspect, n.frame_rate, n.duration) = (width, height, pa, rate, duration); (n.motion_blur_samples, n.motion_blur_adaptive_limit) = (samples, adaptive); + // Only the layers out of range are copied (the others stay shared). + for l in n.layers.iter_mut_where(|l| !stretch_ok(l)) { + let fixed = stretch(l.stretch); + note(notes, name, &format!("layer '{}' time stretch", l.name), percent(l.stretch), percent(fixed)); + l.stretch = fixed; + } Some(n) } @@ -217,6 +249,85 @@ mod tests { ); } + #[test] + fn a_stretch_is_held_to_one_to_9900_percent_with_its_sign() { + assert_eq!(stretch(f64::NAN), 100.0); + assert_eq!(stretch(0.0), 100.0); + assert_eq!(stretch(-0.0), 100.0); + assert_eq!(stretch(1e-300), MIN_STRETCH); + assert_eq!(stretch(-1e-300), -MIN_STRETCH); + assert_eq!(stretch(0.5), MIN_STRETCH); + assert_eq!(stretch(1e300), MAX_STRETCH); + assert_eq!(stretch(f64::INFINITY), MAX_STRETCH); + assert_eq!(stretch(f64::NEG_INFINITY), -MAX_STRETCH); + for v in [1.0, -1.0, 33.3, 100.0, -100.0, 200.0, 9900.0, -9900.0] { + assert_eq!(stretch(v).to_bits(), v.to_bits(), "{v} is in range"); + } + } + + /// A layer whose stretch got past loading (0, NaN, 1e-300 %, set in memory) still maps time + /// through a stretch in range: before, 0 and 1e-300 % saturated every layer time to the end of + /// time and NaN collapsed it to 0 (#3247). + #[test] + fn layer_and_comp_time_use_a_stretch_in_range() { + let mut p = crate::Project::default(); + let comp = Comp::new(64, 64, FrameRate::FPS_25, Tick::from_seconds_f64(10.0)); + let mut l = crate::build::layer(&mut p, &comp, "L", crate::LayerSource::Camera, (64, 64), None); + l.start_time = Tick::from_seconds_f64(1.0); + let at = |s: f64| Tick::from_seconds_f64(s); + for (bad, effective) in [(0.0, 100.0), (f64::NAN, 100.0), (1e-300, 1.0), (-1e-300, -1.0), (1e300, 9900.0), (f64::NEG_INFINITY, -9900.0)] { + l.stretch = bad; + assert_eq!(l.effective_stretch(), effective, "{bad}"); + // One comp second after the start is 100 / stretch layer seconds. + let want = Tick((at(1.0).0 as f64 * 100.0 / effective) as i64); + assert_eq!(l.layer_time(at(2.0)), want, "{bad}"); + // And back, within the rounding of the two conversions. + assert!((l.comp_time(l.layer_time(at(2.0))) - at(2.0)).abs() <= Tick(100), "{bad}"); + } + } + + #[test] + fn a_stretch_out_of_range_in_a_file_is_corrected_and_reported() { + let mut p = crate::Project::default(); + let comp = Comp::new(64, 64, FrameRate::FPS_25, Tick::from_seconds_f64(2.0)); + let mut c = comp.clone(); + for (name, s) in [("tiny", 1e-300), ("reversed tiny", -1e-300), ("zero", 0.0), ("huge", 1e300), ("reversed huge", -5e4), ("fine", -50.0)] { + let mut l = crate::build::layer(&mut p, &comp, name, crate::LayerSource::Camera, (64, 64), None); + l.stretch = s; + c.layers.push(l); + } + // Added through `add_item`, the comp is held to the limits too: write the values back in. + let id = p.add_item("Comp", effectcraft_color::Label::None, None, ItemKind::Comp(Arc::new(c.clone()))); + assert!(p.comp(id).unwrap().layers.iter().all(|l| l.stretch.abs() >= MIN_STRETCH && l.stretch.abs() <= MAX_STRETCH)); + let mut v: serde_json::Value = serde_json::from_str(&p.to_json()).unwrap(); + for (k, l) in c.layers.iter().enumerate() { + v["items"][id.0.to_string()]["kind"]["layers"][k]["stretch"] = serde_json::json!(l.stretch); + } + let (back, notes) = crate::Project::from_json_repaired(&v.to_string()).unwrap(); + let got: Vec = back.comp(id).unwrap().layers.iter().map(|l| l.stretch).collect(); + assert_eq!(got, [1.0, -1.0, 100.0, 9900.0, -9900.0, -50.0]); + assert_eq!( + notes, + [ + "Comp: layer 'tiny' time stretch 1e-300 % → 1 %", + "Comp: layer 'reversed tiny' time stretch -1e-300 % → -1 %", + "Comp: layer 'zero' time stretch 0 % → 100 %", + "Comp: layer 'huge' time stretch 1e300 % → 9900 %", + "Comp: layer 'reversed huge' time stretch -50000 % → -9900 %", + ] + ); + // A NaN stretch is written as null (an auto-save): the file opens, at 100 %, and says so. + // Before, the whole project was refused. + v["items"][id.0.to_string()]["kind"]["layers"][0]["stretch"] = serde_json::Value::Null; + let (back, notes) = crate::Project::from_json_repaired(&v.to_string()).unwrap(); + assert_eq!(back.comp(id).unwrap().layers.iter().next().unwrap().stretch, 100.0); + assert_eq!(notes.first().map(String::as_str), Some("Comp: layer 'tiny' time stretch NaN % → 100 %")); + let mut nan = p.clone(); + nan.comp_mut(id).unwrap().layers.iter_mut().for_each(|l| l.stretch = f64::NAN); + let (back, _) = crate::Project::from_json_repaired(&nan.to_json_compact()).unwrap(); + assert!(back.comp(id).unwrap().layers.iter().all(|l| l.stretch == 100.0)); + } + #[test] fn a_comp_in_range_is_not_copied() { let c = Comp::new(1920, 1080, FrameRate::FPS_24, Tick::from_seconds_f64(2.0)); diff --git a/crates/render/src/audio.rs b/crates/render/src/audio.rs index e2861340c..00342847d 100644 --- a/crates/render/src/audio.rs +++ b/crates/render/src/audio.rs @@ -155,7 +155,9 @@ impl MixEnv<'_> { return out; } let m = b - a; - let speed = 100.0 / l.stretch; + // Within ±1 % to ±9900 % (#3247): a stretch of 1e-300 % set in memory read about + // usize::MAX source samples for one block. + let speed = 100.0 / l.effective_stretch(); let src_n = ((m as f64 * speed).ceil() as usize).max(1); let lt = l.layer_time(sample_tick(i0 + a as i64, rate)); let buf = match &l.source { @@ -291,7 +293,8 @@ fn mix_into(sources: &AudioSources<'_>, comp_id: ItemId, start: Tick, out: &mut let any_solo = comp.layers.iter().any(|l| l.switches.solo && audible(project, l)); let s0 = start.to_units_floor(rate as i64); for l in &comp.layers { - if !audible(project, l) || (any_solo && !l.switches.solo) || l.stretch <= 0.0 { + // The stretch the layer's time uses (#3247): 0 and NaN play at 100 %, as `layer_time`. + if !audible(project, l) || (any_solo && !l.switches.solo) || l.effective_stretch() <= 0.0 { continue; } // Sample range of the block that falls inside the layer's [in, out). diff --git a/crates/render/src/tests.rs b/crates/render/src/tests.rs index c77fc2d94..930bd810b 100644 --- a/crates/render/src/tests.rs +++ b/crates/render/src/tests.rs @@ -22,6 +22,7 @@ mod nested; mod paint; mod remap; mod roi; +mod stretch_limits; mod styles; mod time; diff --git a/crates/render/src/tests/stretch_limits.rs b/crates/render/src/tests/stretch_limits.rs new file mode 100644 index 000000000..17bdff317 --- /dev/null +++ b/crates/render/src/tests/stretch_limits.rs @@ -0,0 +1,96 @@ +//! A project file whose layers carry a time stretch outside ±1 % to ±9900 % (1e-300 %, 0, +//! 1e300 %…) opens with the stretch brought into that range, and a frame of it draws and its audio +//! mixes with bounded source reads. Before, a stretch of 1e-300 % asked the footage for about +//! `usize::MAX` samples and the mix overflowed or tried a huge allocation, aborting the app (#3247). + +use std::sync::Arc; +use std::sync::atomic::{AtomicUsize, Ordering}; + +use effectcraft_color::Label; +use effectcraft_project::{Footage, FootageKind, ItemId, ItemKind, LayerSource, Project, build, limits}; +use effectcraft_time::Tick; + +use super::{setup, solid}; +use crate::{FootageSource, Image, audio::mix_comp, render_frame}; + +/// Silent audio footage that records the longest read asked of it and refuses a read past a +/// thousand seconds (so a runaway read can't take the machine's memory: the mix then fills the +/// read with silence itself). +#[derive(Default)] +struct Probe { + longest: AtomicUsize, +} + +impl FootageSource for Probe { + fn frame(&self, _: ItemId, _: &Footage, _: Tick) -> Option> { + None + } + fn audio(&self, _: ItemId, _: &Footage, _: Tick, frames: usize, rate: u32) -> Option> { + self.longest.fetch_max(frames, Ordering::Relaxed); + (frames <= rate as usize * 1000).then(|| vec![0.0; frames * 2]) + } +} + +/// The project file of a comp holding a red solid and a sound, both with their stretch set to +/// `stretch` in the file text. +fn file_with_stretch(stretch: f64) -> (String, ItemId) { + let (mut p, cid, comp) = setup(); + let red = solid(&mut p, &comp, [1.0, 0.0, 0.0], 200, 100); + let f = Footage { + path: "tone.wav".into(), + kind: FootageKind::Audio, + has_audio: true, + frame_rate: comp.frame_rate, + duration: Tick::from_seconds_f64(10.0), + ..Default::default() + }; + let fid = p.add_item("tone.wav", Label::SeaFoam, None, ItemKind::Footage(f)); + let sound = build::layer(&mut p, &comp, "sound", LayerSource::Footage { item: fid }, (0, 0), None); + let c = p.comp_mut(cid).unwrap(); + c.layers.push(red); + c.layers.push(sound); + // Both layers are at 100 %; `{:e}` writes a JSON number for any finite value, and NaN is + // written as null, as serializing the project writes it. + let text = p.to_json(); + assert_eq!(text.matches("\"stretch\": 100.0").count(), 2); + let value = if stretch.is_nan() { "null".to_string() } else { format!("{stretch:e}") }; + (text.replace("\"stretch\": 100.0", &format!("\"stretch\": {value}")), cid) +} + +#[test] +fn a_file_with_an_extreme_stretch_opens_in_range_draws_and_mixes_with_bounded_reads() { + for (stored, opened) in + [(1e-300, 1.0), (-1e-300, -1.0), (0.0, 100.0), (1e300, limits::MAX_STRETCH), (-1e300, -limits::MAX_STRETCH), (0.5, 1.0), (f64::NAN, 100.0)] + { + let (text, cid) = file_with_stretch(stored); + let (p, notes) = Project::from_json_repaired(&text).unwrap(); + assert!(notes.iter().filter(|n| n.contains("time stretch")).count() == 2, "{stored}: {notes:?}"); + let c = p.comp(cid).unwrap(); + assert!(c.layers.iter().all(|l| l.stretch == opened), "{stored}: {:?}", c.layers.iter().map(|l| l.stretch).collect::>()); + // A frame draws: the solid has no keys and keeps its in and out points, so it is red. + let img = render_frame(&p, cid, Tick::ZERO, 1.0); + assert_eq!(img.get(10, 10), [1.0, 0.0, 0.0, 1.0], "{stored}"); + // The audio mixes, reading at most 100 source samples per comp sample (a stretch of 1 %). + let (rate, n) = (8000, 4000); + let probe = Probe::default(); + let mixed = mix_comp(&p, &probe, None, cid, Tick::from_seconds_f64(0.5), n, rate); + assert_eq!(mixed.len(), n * 2, "{stored}"); + assert!(probe.longest.load(Ordering::Relaxed) <= 100 * n + 1, "{stored}: a read of {} samples", probe.longest.load(Ordering::Relaxed)); + } +} + +/// A stretch set in memory (not through a file, so not repaired) mixes as the clamped stretch the +/// layer's time uses: before, 1e-300 % read about `usize::MAX` source samples and overflowed. +#[test] +fn an_in_memory_extreme_stretch_mixes_with_bounded_reads() { + for stretch in [1e-300, 0.0, f64::NAN, 1e300] { + let (text, cid) = file_with_stretch(100.0); + let (mut p, _) = Project::from_json_repaired(&text).unwrap(); + p.comp_mut(cid).unwrap().layers.iter_mut().for_each(|l| l.stretch = stretch); + let (rate, n) = (8000, 4000); + let probe = Probe::default(); + let mixed = mix_comp(&p, &probe, None, cid, Tick::from_seconds_f64(0.5), n, rate); + assert_eq!(mixed.len(), n * 2, "{stretch}"); + assert!(probe.longest.load(Ordering::Relaxed) <= 100 * n + 1, "{stretch}: a read of {} samples", probe.longest.load(Ordering::Relaxed)); + } +} diff --git a/crates/ui-egui/src/panels/key_dialogs.rs b/crates/ui-egui/src/panels/key_dialogs.rs index 2a5579837..db3144ffd 100644 --- a/crates/ui-egui/src/panels/key_dialogs.rs +++ b/crates/ui-egui/src/panels/key_dialogs.rs @@ -262,7 +262,14 @@ pub fn time_stretch(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) { ui.end_row(); ui.label(tr("Stretch Factor:")); let before = d.percent; - drag(ui, app, "dialog.timeStretch.percent", &mut d.percent, DragSpec { speed: 0.5, range: -10000.0..=10000.0, suffix: " %" }, true); + drag( + ui, + app, + "dialog.timeStretch.percent", + &mut d.percent, + DragSpec { speed: 0.5, range: -effectcraft_project::limits::MAX_STRETCH..=effectcraft_project::limits::MAX_STRETCH, suffix: " %" }, + true, + ); if (before - d.percent).abs() > 1e-9 && d.orig_percent.abs() > 1e-9 { d.duration = d.orig_duration * d.percent.abs() / d.orig_percent.abs(); } @@ -271,7 +278,12 @@ pub fn time_stretch(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) { let before = d.duration; drag(ui, app, "dialog.timeStretch.duration", &mut d.duration, DragSpec { speed: 0.05, range: 0.01..=100000.0, suffix: " s" }, true); if (before - d.duration).abs() > 1e-9 && d.orig_duration > 1e-9 { - d.percent = d.orig_percent.signum() * d.orig_percent.abs() * d.duration / d.orig_duration; + let wanted = d.orig_percent.signum() * d.orig_percent.abs() * d.duration / d.orig_duration; + // Within what Time Stretch accepts (±1 % to ±9900 %, #3247); the duration follows. + d.percent = effectcraft_project::limits::stretch(wanted); + if d.percent.to_bits() != wanted.to_bits() && d.orig_percent.abs() > 1e-9 { + d.duration = d.orig_duration * d.percent.abs() / d.orig_percent.abs(); + } } ui.end_row(); }); From 99e24f5867e1460be9a820f1558cc1fce6134a11 Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Sun, 8 Nov 2026 01:33:26 +0100 Subject: [PATCH 26/40] .aep import: image sequences without a filename prefix or with Force alphabetical order (#3213) * AEP import: read image sequences without a filename prefix and with Force alphabetical order (#3174) After Effects leaves out an empty filename prefix, so only one Utf8 (the suffix, such as `.png`) follows the alias. The single part is now placed by the first file name stored in `opti`: a name starting with it has it as the prefix, one ending with it as the suffix; without that evidence a part starting with `.` is the suffix and anything else is not read. A sequence imported with Force alphabetical order stores its files in `LIST StVc` (`StVS` with the count as a little-endian u32, then one Utf8 per file name) instead of prefix and suffix; that list now replaces the numbering. A list with a name that is not a plain file name (a separator, a colon, `.` or `..`) is not read, since the names are joined to the folder. A folder alias whose naming still cannot be read is reported as an import loss instead of silently linking the folder. docs/aep-format.md describes the empty prefix and StVc/StVS. * AEP import: a listed sequence file name with a control character such as NUL is not read (#3174) A NUL or another control character in a Force alphabetical order file name now makes the whole list unreadable, like a separator or a dot directory, so the import reports the naming instead of linking files that cannot exist. * AEP import: a sequence file list without a readable count is not read (#3174) After Effects writes the StVS count before the names. A StVc list without StVS, or with one shorter than its u32, is now reported as unreadable naming instead of taking every listed name. * Doc comments for the functions this PR touches --- crates/aep/src/container/footage.rs | 89 ++++++++++++- crates/aep/src/import/build.rs | 36 ++++-- crates/aep/tests/it/import/synthetic.rs | 161 ++++++++++++++++++++++++ docs/aep-format.md | 5 +- 4 files changed, 274 insertions(+), 17 deletions(-) diff --git a/crates/aep/src/container/footage.rs b/crates/aep/src/container/footage.rs index 3c9148155..da0369d64 100644 --- a/crates/aep/src/container/footage.rs +++ b/crates/aep/src/container/footage.rs @@ -2,6 +2,7 @@ //! of a layer's source. use crate::container::bytes::{be_f32, be_f64, be_u32, cstr, le_u32, text}; +use crate::container::chunk::Chunk; use crate::container::header::Rational; use crate::container::typed::{Item, ItemKind, Layer, Project}; @@ -159,19 +160,25 @@ fn json_string_at(json: &[u8], mut i: usize) -> Option { } } -/// The numbering of an image sequence item (353, 603). +/// The numbering of an image sequence item (353, 603), or its file list when it was imported with +/// Force alphabetical order. #[derive(Debug, Clone, PartialEq, Eq)] pub struct SequenceInfo { /// The file name before the frame number (`seq_`, `shot_`): the first `Utf8` after the alias. + /// An empty prefix is not stored (`0001.png`): the one `Utf8` is then the suffix. pub prefix: String, /// The file name after the frame number (`.png`, `.exr`): the second `Utf8` after the alias. pub suffix: String, /// The first and last frame number (`sspc` `u32` at 172 and 176: 1 and 3 in 353, 101 and 103 - /// in 603). + /// in 603; both `0xFFFFFFFF` for a sequence with a file list). pub start: u32, pub end: u32, /// The digits of the frame number (`sspc` `u32` at 180: 3 for `seq_001`, 4 for `shot_0101`). pub digits: u32, + /// The file names in order for a sequence imported with Force alphabetical order (`LIST StVc` + /// after the alias: `StVS` with the count as a little-endian `u32`, then one `Utf8` per file); + /// empty for a numbered sequence. When set, it replaces the numbering. + pub files: Vec, } impl SequenceInfo { @@ -180,6 +187,62 @@ impl SequenceInfo { let width = usize::try_from(self.digits.min(16)).unwrap_or(0); format!("{}{n:0width$}{}", self.prefix, self.suffix) } + + /// The number of files: the listed files, or the frame numbers from start to end (0 when the + /// end lies before the start). + pub fn frame_count(&self) -> u32 { + if self.files.is_empty() { + self.end.checked_sub(self.start).map_or(0, |d| d.saturating_add(1)) + } else { + u32::try_from(self.files.len()).unwrap_or(u32::MAX) + } + } + + /// The name of the `i`-th file (from 0): from the file list, or numbered from `start`; `None` + /// past the last file. + pub fn nth_file_name(&self, i: u32) -> Option { + if self.files.is_empty() { + let n = self.start.checked_add(i).filter(|n| *n <= self.end)?; + Some(self.file_name(n)) + } else { + self.files.get(usize::try_from(i).ok()?).cloned() + } + } +} + +/// The file names of a `LIST StVc` (Force alphabetical order): the `Utf8` children in order, at most +/// as many as the count in `StVS` (little-endian `u32`) says. Empty names count toward that number +/// and are then skipped. Without a readable count (no `StVS`, or one shorter than 4 bytes) the list +/// is unreadable (empty). A name that is not a plain file name (holding `/`, `\`, `:` or a control +/// character such as NUL, or being `.` or `..`) makes the whole list unreadable (empty): the names +/// are joined to the folder. +fn sequence_file_list(list: &Chunk<'_>) -> Vec { + // After Effects writes the count first (the one sample); a list without a readable count is + // not read rather than guessed. + let Some(count) = list.child(b"StVS").and_then(|c| c.bytes()).and_then(|b| le_u32(b, 0)).and_then(|n| usize::try_from(n).ok()) else { + return Vec::new(); + }; + let names: Vec = + list.children().iter().filter(|c| c.is(b"Utf8")).filter_map(|c| c.bytes()).take(count).map(text).filter(|n| !n.is_empty()).collect(); + if names.iter().any(|n| n.contains(|c: char| matches!(c, '/' | '\\' | ':') || c.is_control()) || n == "." || n == "..") { + return Vec::new(); + } + names +} + +/// The prefix and suffix of a sequence whose naming holds one `Utf8` (`part`): After Effects leaves +/// out an empty prefix (`0001.png` stores only `.png`). The stored first file name (`opti`) decides: +/// a name starting with `part` has it as the prefix, one ending with it as the suffix. Without that +/// evidence, a `part` starting with `.` is the suffix (an extension); anything else is not read. +fn single_name_part(part: &str, first_file: Option<&str>) -> Option<(String, String)> { + if let Some(first) = first_file.filter(|_| !part.is_empty()) { + match (first.starts_with(part), first.ends_with(part)) { + (true, false) => return Some((part.to_string(), String::new())), + (false, true) => return Some((String::new(), part.to_string())), + _ => {} + } + } + part.starts_with('.').then(|| (String::new(), part.to_string())) } impl<'f, 'a> Item<'f, 'a> { @@ -194,10 +257,24 @@ impl<'f, 'a> Item<'f, 'a> { let sspc = pin.child(b"sspc")?.bytes()?; let kids = pin.children(); let after = kids.iter().position(|c| c.is_list(b"Als2"))?; - let mut names = kids.iter().skip(after + 1).take_while(|c| !c.is(b"opti")).filter(|c| c.is(b"Utf8")).filter_map(|c| c.bytes()).map(text); - let prefix = names.next()?; - let suffix = names.next()?; - Some(SequenceInfo { prefix, suffix, start: be_u32(sspc, 172)?, end: be_u32(sspc, 176)?, digits: be_u32(sspc, 180)? }) + let naming = || kids.iter().skip(after.saturating_add(1)).take_while(|c| !c.is(b"opti")); + let (start, end, digits) = (be_u32(sspc, 172)?, be_u32(sspc, 176)?, be_u32(sspc, 180)?); + // Force alphabetical order: the file list replaces the numbering. + if let Some(list) = naming().find(|c| c.is_list(b"StVc")) { + let files = sequence_file_list(list); + if files.is_empty() { + return None; + } + return Some(SequenceInfo { prefix: String::new(), suffix: String::new(), start, end, digits, files }); + } + let names: Vec = naming().filter(|c| c.is(b"Utf8")).filter_map(|c| c.bytes()).map(text).take(2).collect(); + let (prefix, suffix) = match names.as_slice() { + [prefix, suffix] => (prefix.clone(), suffix.clone()), + // An empty prefix is not stored (`0001.png` has only `.png`). + [one] => single_name_part(one, f.name.as_deref())?, + _ => return None, + }; + Some(SequenceInfo { prefix, suffix, start, end, digits, files: Vec::new() }) } /// The rate a clip is conformed to (Interpret Footage ▸ Conform to frame rate; `sspc` `u32` at diff --git a/crates/aep/src/import/build.rs b/crates/aep/src/import/build.rs index 4ec346328..48ae1c1a5 100644 --- a/crates/aep/src/import/build.rs +++ b/crates/aep/src/import/build.rs @@ -206,6 +206,8 @@ fn new_comp(h: &CompHeader, renderer: Option, map: &TimeMap, name: comp } +/// Adds one footage item to the project under the given parent. +/// Unreadable footage is recorded as a loss, solids and null placeholders are handled separately, and file and sequence footage is linked to its files. fn import_footage(project: &mut Project, cx: &mut Ctx<'_>, item: &AepItem<'_, '_>, name: String, label: Label, parent: ItemId, null_only: &HashSet) { let Some(f) = item.footage() else { cx.col.lose(LossCategory::DamagedData, format!("footage '{name}': data unreadable, not imported")); @@ -240,31 +242,42 @@ fn import_footage(project: &mut Project, cx: &mut Ctx<'_>, item: &AepItem<'_, '_ } let mut path = f.path.clone().unwrap_or_default(); // An image sequence's alias is its folder; its files are named by the stored numbering - // (353, 603). The first file stands for the sequence, as in EffectCraft. + // (353, 603), or listed one by one when imported with Force alphabetical order. The first + // file stands for the sequence, as in EffectCraft. let mut sequence = Vec::new(); - if let Some(seq) = item.sequence_info().filter(|s| !path.is_empty() && s.end >= s.start) { - let frames = (seq.end - seq.start).saturating_add(1); + if let Some(seq) = item.sequence_info().filter(|s| !path.is_empty() && s.frame_count() > 0) { + let frames = seq.frame_count(); let sep = if path.contains('\\') { '\\' } else { '/' }; let folder = path.trim_end_matches(['\\', '/']).to_string(); - // One name is the folder, a separator and the file name; the number is as wide as the stored - // digits or as the largest number, whichever is longer (an upper bound for every frame). - let name_bytes = (folder.len() + 1 + seq.prefix.len() + seq.suffix.len() + usize::try_from(seq.digits.min(16)).unwrap_or(16).max(10)) as u64; - let bytes = name_bytes.saturating_mul(u64::from(frames)); + // One name is the folder, a separator and the file name. A numbered name is as wide as the + // stored digits or as the largest number, whichever is longer (an upper bound for every + // frame); listed names are counted as they are. + let len = |n: usize| u64::try_from(n).unwrap_or(u64::MAX); + let file_bytes = if seq.files.is_empty() { + len(seq.prefix.len().saturating_add(seq.suffix.len()).saturating_add(usize::try_from(seq.digits.min(16)).unwrap_or(16).max(10))) + .saturating_mul(u64::from(frames)) + } else { + seq.files.iter().fold(0u64, |sum, n| sum.saturating_add(len(n.len()))) + }; + let bytes = len(folder.len().saturating_add(1)).saturating_mul(u64::from(frames)).saturating_add(file_bytes); if frames > MAX_SEQUENCE_FRAMES || frames > cx.sequence_budget || bytes > cx.sequence_bytes { // Not expanded: the item keeps its first file (a still standing for the sequence). cx.col.lose( LossCategory::DamagedData, format!("footage '{name}': a sequence of {frames} frames is longer than the import expands; only its first file is linked"), ); - path = format!("{folder}{sep}{}", seq.file_name(seq.start)); + path = format!("{folder}{sep}{}", seq.nth_file_name(0).unwrap_or_default()); } else { cx.sequence_budget -= frames; cx.sequence_bytes -= bytes; - sequence = (seq.start..=seq.end).map(|n| format!("{folder}{sep}{}", seq.file_name(n))).collect(); + sequence = (0..frames).filter_map(|i| seq.nth_file_name(i)).map(|n| format!("{folder}{sep}{n}")).collect(); } if let Some(first) = sequence.first() { path = first.clone(); } + } else if f.is_sequence && !path.is_empty() { + // The alias is a folder, but the file names could not be read: the item links the folder. + cx.col.lose(LossCategory::DamagedData, format!("footage '{name}': image sequence naming not read, linked to its folder")); } let present = !path.is_empty() && (cx.options.exists)(&path); if !present { @@ -318,6 +331,11 @@ fn import_footage(project: &mut Project, cx: &mut Ctx<'_>, item: &AepItem<'_, '_ /// sequence the name with the frame range (`shot_[0101-0103].exr`). fn default_footage_name(item: &AepItem<'_, '_>, f: &crate::Footage) -> Option { if let Some(s) = item.sequence_info() { + // A listed sequence (Force alphabetical order) has no numbering: its first file names it. + // Assumption: what After Effects shows for such an item without a stored name was not sampled. + if let Some(first) = s.files.first() { + return Some(first.clone()); + } let w = usize::try_from(s.digits.min(16)).unwrap_or(0); return Some(format!("{}[{:0w$}-{:0w$}]{}", s.prefix, s.start, s.end, s.suffix)); } diff --git a/crates/aep/tests/it/import/synthetic.rs b/crates/aep/tests/it/import/synthetic.rs index 18709f9e5..5d4d89c56 100644 --- a/crates/aep/tests/it/import/synthetic.rs +++ b/crates/aep/tests/it/import/synthetic.rs @@ -77,6 +77,167 @@ fn a_sequence_with_long_names_is_not_expanded_past_the_byte_budget() { assert_eq!(longest, 0, "the sequence was not expanded"); } +/// The project with the sequence's naming (the chunks between `Als2` and `opti` in its `Pin `) +/// replaced by `naming`, and the `sspc` numbering (start, end, digits at 172, 176, 180) set to +/// `numbering` when given. +fn with_sequence_naming(naming: &[Chunk<'static>], numbering: Option<[u32; 3]>) -> Vec { + let mut file: AepFile<'_> = parse(SYNTHETIC).unwrap(); + let mut patched = 0; + visit(&mut file.chunks, &mut |c| { + if !c.is_list(b"Pin ") { + return; + } + let Body::List { children, .. } = &mut c.body else { return }; + let Some(als) = children.iter().position(|k| k.is_list(b"Als2")) else { return }; + let Some(opti) = children.iter().position(|k| k.is(b"opti")) else { return }; + assert!(als < opti); + let tail = children.split_off(opti); + children.truncate(als + 1); + children.extend(naming.iter().map(shorten)); + children.extend(tail); + if let Some(numbering) = numbering { + let sspc = children.iter_mut().find(|k| k.is(b"sspc")).unwrap(); + for (at, v) in [172, 176, 180].into_iter().zip(numbering) { + set_data(sspc, at, &v.to_be_bytes()); + } + } + patched += 1; + }); + assert_eq!(patched, 1, "the synthetic project has one sequence"); + write(&file).unwrap() +} + +/// `bytes` with the first file name the sequence stores in its png `opti` (byte 58, NUL-terminated) +/// set to `name`. +fn with_first_file(bytes: &[u8], name: &str) -> Vec { + let mut file: AepFile<'_> = parse(bytes).unwrap(); + let mut patched = 0; + visit(&mut file.chunks, &mut |c| { + if c.is(b"opti") && c.bytes().is_some_and(|d| d.get(..4) == Some(&b"png!"[..])) { + let mut z = name.as_bytes().to_vec(); + z.push(0); + set_data(c, 58, &z); + patched += 1; + } + }); + assert_eq!(patched, 1, "the synthetic project has one png item"); + write(&file).unwrap() +} + +/// The imported sequence item's footage. +fn the_footage(p: &Project) -> effectcraft_project::Footage { + p.items.values().find_map(|i| if let ItemKind::Footage(f) = &i.kind { Some(f.clone()) } else { None }).expect("the sequence") +} + +/// The file names (without the folder) of a footage's sequence. +fn file_names(f: &effectcraft_project::Footage) -> Vec { + f.sequence.iter().map(|s| s.rsplit(['\\', '/']).next().unwrap_or_default().to_string()).collect() +} + +/// A copy of `c` that borrows for any lifetime (a chunk is covariant in its lifetime). +fn shorten<'a>(c: &Chunk<'static>) -> Chunk<'a> { + c.clone() +} + +/// A `Utf8` string chunk holding `s`. +fn utf8(s: &str) -> Chunk<'static> { + Chunk::data(*b"Utf8", s.as_bytes().to_vec()) +} + +/// A sequence whose naming has only a suffix (no filename prefix) imports as a sequence of its files. +#[test] +fn a_sequence_without_a_filename_prefix_imports_its_files() { + // `0001.png` .. `0003.png`: After Effects omits the empty prefix, so only `.png` follows the + // alias. Before, `.png` was read as the prefix, the suffix was missing and the item became a + // video linked to its folder. + let (p, r) = run(&with_sequence_naming(&[utf8(".png")], None), true); + r.unwrap(); + let f = the_footage(&p); + assert_eq!(f.kind, FootageKind::Sequence); + assert_eq!(file_names(&f), ["0001.png", "0002.png", "0003.png"]); + assert!(f.path.ends_with("0001.png"), "{}", f.path); +} + +/// A single `Utf8` naming part is read as the suffix or the prefix depending on how the stored first file name matches it. +#[test] +fn a_single_naming_part_is_placed_by_the_stored_first_file_name() { + // `0001_v2.png` ..: the one `Utf8` is the suffix, as the first file name (`opti`) ends with it. + let bytes = with_first_file(&with_sequence_naming(&[utf8("_v2.png")], None), "0001_v2.png"); + let (p, r) = run(&bytes, true); + r.unwrap(); + let f = the_footage(&p); + assert_eq!(f.kind, FootageKind::Sequence); + assert_eq!(file_names(&f), ["0001_v2.png", "0002_v2.png", "0003_v2.png"]); + // `shot_0001` ..: a name without an extension; the one `Utf8` is the prefix. + let bytes = with_first_file(&with_sequence_naming(&[utf8("shot_")], None), "shot_0001"); + let (p, r) = run(&bytes, true); + r.unwrap(); + assert_eq!(file_names(&the_footage(&p)), ["shot_0001", "shot_0002", "shot_0003"]); + // Without that evidence (the stored first file is `shot_0001.png`), a part that is no extension + // is not guessed: the item is reported. + let bytes = with_sequence_naming(&[utf8("_v2.png")], None); + reported_and_refused(&bytes, LossCategory::DamagedData, "image sequence naming not read, linked to its folder"); +} + +/// A file list containing a name with a separator, drive colon, dot directory or control character is refused and reported. +#[test] +fn a_file_list_with_a_name_that_is_not_a_plain_file_name_is_reported() { + // The listed names are joined to the folder: a separator, a drive colon or a dot directory + // would point outside it, and a NUL or another control character is no file name, so such a + // list is not read. + for hostile in ["..\\..\\x.png", "../x.png", "C:x.png", "..", ".", "x\0.png", "x\n.png"] { + let list = Chunk::list(*b"StVc", vec![Chunk::data(*b"StVS", 2u32.to_le_bytes().to_vec()), utf8("a.png"), utf8(hostile)]); + let bytes = with_sequence_naming(&[list], Some([u32::MAX, u32::MAX, 0])); + reported_and_refused(&bytes, LossCategory::DamagedData, "image sequence naming not read, linked to its folder"); + } +} + +/// A file list with a missing or too short count chunk is refused and reported. +#[test] +fn a_file_list_without_a_readable_count_is_reported() { + // No `StVS`, or one too short for its `u32`: the list is not read rather than taken whole. + for count in [None, Some(vec![2u8, 0])] { + let mut kids: Vec> = count.map(|c| Chunk::data(*b"StVS", c)).into_iter().collect(); + kids.extend([utf8("a.png"), utf8("b.png")]); + let bytes = with_sequence_naming(&[Chunk::list(*b"StVc", kids)], Some([u32::MAX, u32::MAX, 0])); + reported_and_refused(&bytes, LossCategory::DamagedData, "image sequence naming not read, linked to its folder"); + } +} + +/// A force-alphabetical sequence imports its stored file list in the stored order. +#[test] +fn a_sequence_imported_with_force_alphabetical_order_imports_its_file_list() { + // Force alphabetical order: `LIST StVc` with `StVS` (the count, little-endian) and one `Utf8` + // per file instead of the prefix and suffix; the numbering in `sspc` is not set. Before, the + // item became a video linked to its folder. + let list = Chunk::list(*b"StVc", vec![Chunk::data(*b"StVS", 3u32.to_le_bytes().to_vec()), utf8("b_take.png"), utf8("a_take.png"), utf8("c_take.png")]); + let (p, r) = run(&with_sequence_naming(&[list], Some([u32::MAX, u32::MAX, 0])), true); + let r = r.unwrap(); + let f = the_footage(&p); + assert_eq!(f.kind, FootageKind::Sequence); + // The stored order is kept. + assert_eq!(file_names(&f), ["b_take.png", "a_take.png", "c_take.png"]); + assert!(f.path.ends_with("b_take.png"), "{}", f.path); + assert!(losses(&r, LossCategory::DamagedData).is_empty(), "{:?}", r.report.losses); + // The count bounds the list. + let list = Chunk::list(*b"StVc", vec![Chunk::data(*b"StVS", 2u32.to_le_bytes().to_vec()), utf8("x.png"), utf8("y.png"), utf8("z.png")]); + let (p, r) = run(&with_sequence_naming(&[list], Some([u32::MAX, u32::MAX, 0])), true); + r.unwrap(); + assert_eq!(file_names(&the_footage(&p)), ["x.png", "y.png"]); +} + +/// A sequence with no naming or an empty file list is reported and linked to its folder. +#[test] +fn a_sequence_whose_naming_cannot_be_read_is_reported() { + // No naming at all after the alias. Before, the item silently linked its folder. + let bytes = with_sequence_naming(&[], None); + reported_and_refused(&bytes, LossCategory::DamagedData, "image sequence naming not read, linked to its folder"); + // An empty file list is no naming either. + let empty = Chunk::list(*b"StVc", vec![Chunk::data(*b"StVS", 0u32.to_le_bytes().to_vec())]); + let bytes = with_sequence_naming(&[empty], Some([u32::MAX, u32::MAX, 0])); + reported_and_refused(&bytes, LossCategory::DamagedData, "image sequence naming not read, linked to its folder"); +} + #[test] fn a_solid_with_a_nan_channel_is_repaired_and_reported() { let nan = f32::NAN.to_be_bytes(); diff --git a/docs/aep-format.md b/docs/aep-format.md index d6ec7fb14..99a1199f0 100644 --- a/docs/aep-format.md +++ b/docs/aep-format.md @@ -1,6 +1,6 @@ # After Effects project format (`.aep`) -> **Last reviewed:** 2026-11-05 · **Last updated:** 2026-11-05 · **Change:** versions: `svap` is the version that wrote the file, `head` bytes 4 to 7 the version it is written for, and what a Save a Copy As 25.x / 24.x of After Effects 2026 changes (section 1, "Versions"); before that: the stretch numerator is signed (a negative one reverses the layer, 981-983); layer styles (3.12b, 950-980); before that: footage: `sspc@118` of an image sequence is its folder's modification time (860, read-back x1-x3); before that: text: paragraph `/24`, `/35` and style `/68` are neutral for 0 and 1 (732-734, edited in place); before that: keyframes: the ease of mask path keys (599, 700), the spatial speed unit of fractional values (597, 598, 730); before that: text: character and paragraph settings, manual kerning, vertical text, `/nil` is neutral (S17: 538-578, 595, 596); before that: cameras, lights and 3D rotations (S16: the auto Position of a two-node camera is where After Effects renders it, 537; camera and light defaults read back 255, 256; Orientation `otst/otda` 488), Timewarp (529-533), an expression on an effect parameter (534); before that: text: style slot /13 is superscript / subscript (526-528; every scripted text of the corpus is superscript), wrapping box text 517; before that: effects of batch 5 (409-450, 511-516: integer sliders, checkbox defaults in `pard`, arbitrary data of Hue/Saturation and Levels, the parameters of Invert, Fast Box Blur, Gaussian Blur, Drop Shadow, Glow; section 3.7); before that: shape items of batch 5 (451-484, 519: ellipse, fill and stroke opacity, fill rule, group transform, shape layer anchor, trim paths, rectangle roundness, polystar fields, gradient default, nested groups, the defaults of every item; section 3.9); before that: track mattes: mode at `ldta` byte 107 and the matte layer id at byte 160 (cases 402-408, section 3.1); before that: text: automatic leading is verified (400); Exposure (`ADBE Exposure2`, cases 389-397): group start / end parameter types 13 / 14, float slider valid minimum and slider range (section 3.7); before that: text: U+0003 is a paragraph break (386, 387); before that: a stored text Anchor Point is pixels (385, now V); before that: the XML form `.aepx` is read into the same chunk tree (section 1, "The XML form"); the `head` save counter is a `u32` at byte 16; text documents for the importer (stroke colour, automatic leading, the font of each run, the undecoded-slot check, the text-layer Anchor Point, the Source Text record); before that: third round of verified field layouts (explicit-default semantics, type-major bezier ease, exact time stretch and in / out points, Time Remapping state, comp pixel aspect / shutter phase / display start, Point default, Layer Control None, dropdown selection, one `mkif` per mask, polystar and radial gradient records, text styles, camera and light options, marker cue data, audio and image-sequence footage) added to the typed view of `effectcraft-aep` · **Target:** Adobe After Effects 2026 +> **Last reviewed:** 2026-11-05 · **Last updated:** 2026-11-07 · **Change:** footage: an image sequence without a filename prefix stores only the suffix `Utf8`, and one imported with Force alphabetical order stores its file list in `LIST StVc` / `StVS` (section 3, footage); before that: versions: `svap` is the version that wrote the file, `head` bytes 4 to 7 the version it is written for, and what a Save a Copy As 25.x / 24.x of After Effects 2026 changes (section 1, "Versions"); before that: the stretch numerator is signed (a negative one reverses the layer, 981-983); layer styles (3.12b, 950-980); before that: footage: `sspc@118` of an image sequence is its folder's modification time (860, read-back x1-x3); before that: text: paragraph `/24`, `/35` and style `/68` are neutral for 0 and 1 (732-734, edited in place); before that: keyframes: the ease of mask path keys (599, 700), the spatial speed unit of fractional values (597, 598, 730); before that: text: character and paragraph settings, manual kerning, vertical text, `/nil` is neutral (S17: 538-578, 595, 596); before that: cameras, lights and 3D rotations (S16: the auto Position of a two-node camera is where After Effects renders it, 537; camera and light defaults read back 255, 256; Orientation `otst/otda` 488), Timewarp (529-533), an expression on an effect parameter (534); before that: text: style slot /13 is superscript / subscript (526-528; every scripted text of the corpus is superscript), wrapping box text 517; before that: effects of batch 5 (409-450, 511-516: integer sliders, checkbox defaults in `pard`, arbitrary data of Hue/Saturation and Levels, the parameters of Invert, Fast Box Blur, Gaussian Blur, Drop Shadow, Glow; section 3.7); before that: shape items of batch 5 (451-484, 519: ellipse, fill and stroke opacity, fill rule, group transform, shape layer anchor, trim paths, rectangle roundness, polystar fields, gradient default, nested groups, the defaults of every item; section 3.9); before that: track mattes: mode at `ldta` byte 107 and the matte layer id at byte 160 (cases 402-408, section 3.1); before that: text: automatic leading is verified (400); Exposure (`ADBE Exposure2`, cases 389-397): group start / end parameter types 13 / 14, float slider valid minimum and slider range (section 3.7); before that: text: U+0003 is a paragraph break (386, 387); before that: a stored text Anchor Point is pixels (385, now V); before that: the XML form `.aepx` is read into the same chunk tree (section 1, "The XML form"); the `head` save counter is a `u32` at byte 16; text documents for the importer (stroke colour, automatic leading, the font of each run, the undecoded-slot check, the text-layer Anchor Point, the Source Text record); before that: third round of verified field layouts (explicit-default semantics, type-major bezier ease, exact time stretch and in / out points, Time Remapping state, comp pixel aspect / shutter phase / display start, Point default, Layer Control None, dropdown selection, one `mkif` per mask, polystar and radial gradient records, text styles, camera and light options, marker cue data, audio and image-sequence footage) added to the typed view of `effectcraft-aep` · **Target:** Adobe After Effects 2026 What `crates/aep` ([`effectcraft-aep`](../crates/aep/README.md)) reads and writes, and the evidence for each statement. Everything here was observed on project files we generated ourselves; no @@ -279,7 +279,8 @@ Footage items beyond solids and stills (`Pin /sspc`, 222 bytes; audio and image | bits per pixel | 60 | u32 | RGBA still 32, RGB sequence 24, 0 for solids and audio | 126, 352 | V | | **sample rate** | 160 | f64 | 48 000.0 for the WAV; the same for an mp4 with sound (48 000.0 and 44 100.0 read back from AAC tracks of those rates), absent for an mp4 without (the importer takes a clip's audio from it) | 350, read-back vid-audio | V | | **file size** | 208 | u32 | bytes of the source file(s): png 149, WAV 96 044 (44 + 48 000 x 2), three png of 168 bytes 504 | 126, 350, 352 | V | -| **sequence numbering** | 172, 176, 180 | u32 x 3 | first and last frame number and the digits of a sequence: 1, 3, 3 for `seq_001.png`..`seq_003.png` (353), 101, 103, 4 for `shot_0101.exr`..`shot_0103.exr` (603); 0 for single files (604, 605, 607). The name around the number is the pair of `Utf8` chunks between `Als2` and `opti` in `Pin ` (`seq_` / `.png`, `shot_` / `.exr`), absent on single files. `Item::sequence_info`, `SequenceInfo::file_name` | 353, 603, 604, 605, 607 | V | +| **sequence numbering** | 172, 176, 180 | u32 x 3 | first and last frame number and the digits of a sequence: 1, 3, 3 for `seq_001.png`..`seq_003.png` (353), 101, 103, 4 for `shot_0101.exr`..`shot_0103.exr` (603); 0 for single files (604, 605, 607). The name around the number is the pair of `Utf8` chunks between `Als2` and `opti` in `Pin ` (`seq_` / `.png`, `shot_` / `.exr`), absent on single files. **An empty prefix is not written**: `0001.png`..`0005.png` leave one `Utf8` (`.png`) there, so a single `Utf8` is the prefix when the first file name in `opti` (byte 58: `0001.png`) starts with it and the suffix when it ends with it; without that evidence the reader takes one starting with `.` as the suffix and reads nothing else. `Item::sequence_info`, `SequenceInfo::file_name` | 353, 603, 604, 605, 607; the prefix-less sequence of issue 3174 (After Effects 25.2) | V | +| **sequence file list** (Force alphabetical order) | `Pin /LIST StVc` | `StVS` (4 bytes, `u32` LE), then `Utf8` x count | a sequence imported with Force alphabetical order has, between `Als2` and `opti`, a `LIST StVc` instead of the prefix and suffix `Utf8`s: `StVS` holds the file count as a **little-endian** `u32` (`05 00 00 00`), followed by one `Utf8` per file name in order (`shot_0001.png`..`shot_0005.png`). The numbering at @172 / @176 is then `0xFFFFFFFF` and the digits @180 0; duration and rate are stored as for a numbered sequence (5/30, 30). The list replaces the numbering; a list without a readable `StVS` count, or with a name that is not a plain file name (`/`, `\`, `:`, a control character such as NUL, `.`, `..`), is not read. Without a stored item name the importer names the item after its first listed file (an assumption: what After Effects shows was not sampled). `SequenceInfo::files`, `SequenceInfo::nth_file_name` | the alphabetical sequence of issue 3174 (After Effects 25.2) | V | | **sequence folder time** | 118 | u32 (unaligned) | seconds since 1904-01-01 UTC: the modification time of a sequence's folder when After Effects scanned it (860: 0xe6fb443a = 2026-10-19 03:51:22, the folder's and its files' time). With the folder's time After Effects keeps the stored numbering on open; with another (an older time, the first or the last file's time while the folder's differs: x1, x2 against x3) it scans the folder again and warns about a gap in a modal dialog | 860, `export-tests\sparse860\exp` x1-x3 | V | | still duration denominator | 42 | u32 | 1 for png (126, 607), 600 for jpeg (605), 100 for OpenEXR (604): a still's duration is 0 over a per-format denominator | 126, 604, 605, 607 | V | From 514e16c027cae577ee40bac5ef27790365775af6 Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Sun, 8 Nov 2026 01:57:47 +0100 Subject: [PATCH 27/40] .aep import: effects without definitions borrow them from another instance (#3223) Refs #3170 (the Color Control part). Some files have no project-level effect definition list (EfdG); it was seen in 17 projects, all from inside After Effects-made Motion Graphics templates. In those, one instance per effect type keeps the full parameter definitions (parT) and every other instance of the type has an empty parT. The others were reported "without readable parameter definitions" and dropped (129 Color Controls of one template). The definition index now falls back to the parT of the first instance of the same match name that has its own (DefinitionSource::OtherInstance). Values still come from each instance's own records; a value record that borrowed definitions do not name is reported instead of vanishing. The "Color ... holds an unreadable value" report came from 0.21.1, which read only written records (tdsb 1). Reading default-state records (tdsb 3, #3126) probably fixes it, but that is not confirmed for Color Control; a synthetic test now pins a default-state colour record. --- crates/aep/src/container/effects.rs | 65 +++++- crates/aep/src/import/effects.rs | 16 ++ crates/aep/tests/it/container/robustness.rs | 6 +- crates/aep/tests/it/import/robustness.rs | 12 +- crates/aep/tests/it/import/synthetic.rs | 237 ++++++++++++++++++++ docs/aep-format.md | 2 +- 6 files changed, 322 insertions(+), 16 deletions(-) diff --git a/crates/aep/src/container/effects.rs b/crates/aep/src/container/effects.rs index e336d84e5..2fa77d017 100644 --- a/crates/aep/src/container/effects.rs +++ b/crates/aep/src/container/effects.rs @@ -12,6 +12,11 @@ //! project-level `LIST EfdG` (one `EfDf` per effect type: a `tdmn` with the match name, then a copy //! of one instance's `sspc`), see [`Project::effect_params`]. That copy also carries the values of //! the instance it was copied from, so values are only ever read from the instance's own `tdgp`. +//! +//! Some files have no `EfdG` at all (seen in 17 projects, all from inside After Effects-made +//! Motion Graphics templates). In those, one instance per effect type kept its full `parT` (which +//! one is not known) and it is the only place the definitions are written, so the other instances +//! of that type borrow them from it (#3170). use std::collections::{HashMap, HashSet}; @@ -138,7 +143,11 @@ pub enum DefinitionSource { /// The project-level `EfdG/EfDf` copy for the effect's match name (the instance's own `parT` /// is empty, 383). Project, - /// Neither has any: the effect has no readable parameter definitions. + /// The own `parT` of another instance of the same match name in the file: the instance's + /// own `parT` is empty and the file has no project-level copy of the type (a project without + /// `EfdG`, #3170). + OtherInstance, + /// None of these has any: the effect has no readable parameter definitions. Missing, } @@ -155,7 +164,8 @@ pub struct EffectParam<'f, 'a> { pub name: String, /// The popup items (`pdnm`, split at `|`; for a button its label, e.g. `Swap Colors`). pub items: Option>, - /// True when the definition is the project-level copy (see [`DefinitionSource::Project`]). + /// True when the definition is borrowed: the project-level copy ([`DefinitionSource::Project`]) + /// or another instance's ([`DefinitionSource::OtherInstance`]). pub borrowed_definition: bool, pard: &'f [u8], stored: Option>, @@ -214,6 +224,22 @@ impl<'f, 'a> Effect<'f, 'a> { self.chunk.child_list(b"parT").is_some_and(has_pard) } + /// The match names of the value records in the instance's own `tdgp` (properties only, not + /// groups), in file order, each once. + pub fn value_record_names(&self) -> Vec { + let mut seen: HashSet = HashSet::new(); + self.chunk + .child_list(b"tdgp") + .and_then(PropGroup::from_chunk) + .map(|g| g.entries()) + .unwrap_or_default() + .into_iter() + .filter(|e| matches!(e.node, PropNode::Property(_))) + .map(|e| e.match_name) + .filter(|n| seen.insert(n.clone())) + .collect() + } + /// The parameters in the order of the instance's own `parT`. Empty for an instance whose /// `parT` is empty; [`Project::effect_params`] falls back to the project's definitions. pub fn params(&self) -> Vec> { @@ -299,8 +325,25 @@ impl<'f, 'a> Project<'f, 'a> { /// [`Self::effect_definitions`] indexed by match name, for looking up many effects: build it /// once per file, not once per effect (a file can hold many definitions and many instances). + /// For a type without a project-level copy it also keeps the own `parT` of the first instance + /// in the file (items, layers and effects in file order) that has one. pub fn effect_definition_index(&self) -> EffectDefinitions<'f, 'a> { - EffectDefinitions { by_name: self.effect_definitions().into_iter().collect() } + let by_name: HashMap> = self.effect_definitions().into_iter().collect(); + let mut instances: HashMap> = HashMap::new(); + for item in self.all_items() { + let Some(comp) = item.comp() else { continue }; + for layer in comp.layers() { + for fx in layer.effects() { + if by_name.contains_key(&fx.match_name) || instances.contains_key(&fx.match_name) { + continue; + } + if let Some(part) = fx.chunk.child_list(b"parT").filter(|p| has_pard(p)) { + instances.insert(fx.match_name, part); + } + } + } + } + EffectDefinitions { by_name, instances } } /// Where the parameter definitions of `effect` come from. Builds the index each call: use @@ -316,10 +359,13 @@ impl<'f, 'a> Project<'f, 'a> { } } -/// The project-level effect definitions by match name ([`Project::effect_definition_index`]). +/// The borrowable effect definitions by match name ([`Project::effect_definition_index`]). #[derive(Debug, Clone, Default)] pub struct EffectDefinitions<'f, 'a> { + /// The project-level copies (`EfdG`). by_name: HashMap>, + /// For a type without a project-level copy: the own `parT` of the first instance that has one. + instances: HashMap>, } impl<'f, 'a> EffectDefinitions<'f, 'a> { @@ -329,20 +375,23 @@ impl<'f, 'a> EffectDefinitions<'f, 'a> { DefinitionSource::Instance } else if self.by_name.contains_key(effect.match_name()) { DefinitionSource::Project + } else if self.instances.contains_key(effect.match_name()) { + DefinitionSource::OtherInstance } else { DefinitionSource::Missing } } /// The parameters of `effect`: from its own `parT`, or, when that is empty, from the - /// project-level definition of its match name ([`EffectParam::borrowed_definition`]). Values - /// always come from the instance's own records (absent = the `pard` default); the project - /// copy's values belong to another instance and are never read. + /// project-level definition of its match name, else from another instance of it that has + /// its own ([`EffectParam::borrowed_definition`]). Values always come from the instance's own + /// records (absent = the `pard` default); the values next to borrowed definitions belong to + /// another instance and are never read. pub fn params(&self, effect: &Effect<'f, 'a>) -> Vec> { if effect.has_own_definitions() { return effect.params(); } - match self.by_name.get(effect.match_name()) { + match self.by_name.get(effect.match_name()).or_else(|| self.instances.get(effect.match_name())) { Some(part) => effect.params_from(part, true), None => Vec::new(), } diff --git a/crates/aep/src/import/effects.rs b/crates/aep/src/import/effects.rs index 8409a6f7e..b097c3600 100644 --- a/crates/aep/src/import/effects.rs +++ b/crates/aep/src/import/effects.rs @@ -99,6 +99,22 @@ pub(crate) fn import_effects<'f, 'a>( None => col.lose(LossCategory::DamagedData, format!("{}: '{}': the fx switch of '{shown}' is unreadable, imported switched on", cx.comp, cx.layer)), } let params = defs.params(&fx); + // Borrowed definitions (another instance's or the project copy) may not name every value + // record this instance has: such a record has nothing to import into, so it is reported. + if params.first().is_some_and(|p| p.borrowed_definition) { + let defined: std::collections::HashSet<&str> = params.iter().map(|p| p.match_name.as_str()).collect(); + for name in fx.value_record_names().iter().filter(|n| !defined.contains(n.as_str())) { + col.lose( + LossCategory::Effects, + format!( + "{}: '{}' effect '{shown}' ({}): the value record {name} has no parameter definition, not imported", + cx.comp, + cx.layer, + fx.match_name() + ), + ); + } + } if map.extra == Extra::Cryptomatte { import_cryptomatte(&fx, ¶ms, cx, &shown, &mut group, col); } else { diff --git a/crates/aep/tests/it/container/robustness.rs b/crates/aep/tests/it/container/robustness.rs index 27622d887..5c3422a10 100644 --- a/crates/aep/tests/it/container/robustness.rs +++ b/crates/aep/tests/it/container/robustness.rs @@ -237,9 +237,11 @@ fn exercise_layer(project: &Project<'_, '_>, comp_size: (u32, u32), layer: &Laye if let Some(root) = layer.properties() { exercise_group(&root, 0); } + // One index for the layer's effects: building it walks every layer of the file. + let defs = project.effect_definition_index(); for e in layer.effects() { - let _ = (e.match_name().len(), e.name(), e.declared_param_count(), e.has_own_definitions(), project.definition_source(&e)); - for p in e.params().into_iter().chain(project.effect_params(&e)) { + let _ = (e.match_name().len(), e.name(), e.declared_param_count(), e.has_own_definitions(), defs.source(&e)); + for p in e.params().into_iter().chain(defs.params(&e)) { let _ = (p.index, p.kind, p.name.len(), p.items.as_ref().map(Vec::len), p.pard().len(), p.value(), p.stored_value(), p.pard_default()); let _ = (p.is_default(), p.popup_item_count(), p.popup_selected_index(), p.popup_selected_item(), p.valid_max(), p.is_animated()); let _ = (p.valid_min(), p.slider_range()); diff --git a/crates/aep/tests/it/import/robustness.rs b/crates/aep/tests/it/import/robustness.rs index 1a42665bc..902c9cc4b 100644 --- a/crates/aep/tests/it/import/robustness.rs +++ b/crates/aep/tests/it/import/robustness.rs @@ -626,9 +626,10 @@ fn bogus_effect_structure_is_reported_not_imported_blindly() { "{r:?}" ); - // No project-level definitions: a Ramp with an empty parT cannot be read and is reported; one - // with its own parT still arrives. (In the single-case file one of the two had its own; in - // the combined file an earlier case holds the definitions, so both take the project copy.) + // No project-level definitions: a Ramp with an empty parT borrows the definitions of a Ramp + // in the file that has its own parT (#3170). In the single-case file one of the two has its + // own, so both arrive; in the case cut from the combined file an earlier case (not kept) + // held them, so neither has readable definitions and both are reported. let own = { let bytes = skip!(crate::common::try_fixture("383-fx-ramp-on-100x100-start-10-20.aep")); let file = parse(&bytes).unwrap(); @@ -646,8 +647,9 @@ fn bogus_effect_structure_is_reported_not_imported_blindly() { } })); let r = report_of(&bytes); - assert_eq!(r.imported.effects, own, "{r:?}"); - assert_eq!(r.count(effectcraft_aep::import::LossCategory::Effects), 2 - own, "{r:?}"); + let arrive = if own > 0 { 2 } else { 0 }; + assert_eq!(r.imported.effects, arrive, "{r:?}"); + assert_eq!(r.count(effectcraft_aep::import::LossCategory::Effects), 2 - arrive, "{r:?}"); assert!(try_all(&bytes)); // 368, the first Gradient Ramp of its file, has its own parT: it still arrives. let bytes = skip!(mutate("368-fx-ramp-default.aep", &mut |c| { if let Body::List { list_type, .. } = &mut c.body diff --git a/crates/aep/tests/it/import/synthetic.rs b/crates/aep/tests/it/import/synthetic.rs index 5d4d89c56..a023bb162 100644 --- a/crates/aep/tests/it/import/synthetic.rs +++ b/crates/aep/tests/it/import/synthetic.rs @@ -553,6 +553,186 @@ fn default_state_effect_records_import_like_written_ones() { assert_eq!(clip, vec![("clipToOutputBlack".to_string(), effectcraft_keyframe::Value::Enum(1))]); } +/// Sets the `cdat` of the value record `param` in the value group `tdgp` (the first `f64`), and +/// its state to `tdsb` when given. True when the group has that record. +fn patch_record(tdgp: &mut Chunk<'_>, param: &str, tdsb: Option, value: f64) -> bool { + let kids = tdgp.children_mut(); + let Some(at) = kids.iter().position(|k| k.is(b"tdmn") && k.bytes().is_some_and(|b| b.split(|x| *x == 0).next() == Some(param.as_bytes()))) else { + return false; + }; + let Some(record) = kids.get_mut(at + 1).filter(|k| k.is_list(b"tdbs")) else { return false }; + for k in record.children_mut() { + if k.is(b"tdsb") + && let Some(state) = tdsb + { + set_data(k, 0, &state.to_be_bytes()); + } else if k.is(b"cdat") { + set_data(k, 0, &value.to_be_bytes()); + } + } + true +} + +/// The project without its project-level effect definitions (`EfdG`; some files have none, seen +/// in the projects inside After Effects-made Motion Graphics templates) and with a second Glow +/// just above the first on the layer: a copy of it whose `parT` is empty, as such files write +/// every instance of a type but one. `edit_copy` is applied to every chunk of the copy; with +/// `empty_original` the original's `parT` is emptied too. +fn second_glow_without_definitions(edit_copy: &mut dyn FnMut(&mut Chunk<'_>), empty_original: bool) -> Vec { + fn empty_part(fx: &mut Chunk<'_>) { + for k in fx.children_mut() { + if let Body::List { list_type, children, .. } = &mut k.body + && list_type == b"parT" + { + children.clear(); + } + } + } + let mut file: AepFile<'_> = parse(SYNTHETIC).unwrap(); + let mut added = 0; + visit(&mut file.chunks, &mut |c| { + if let Body::List { list_type, children, .. } = &mut c.body { + if list_type == b"EfdG" { + *list_type = *b"XfdG"; + return; + } + if list_type != b"tdgp" { + return; + } + let Some(at) = children.iter().position(|k| k.is(b"tdmn") && k.bytes().is_some_and(|b| b.split(|x| *x == 0).next() == Some(b"ADBE Glo2"))) else { + return; + }; + let (Some(name), Some(mut fx)) = (children.get(at).cloned(), children.get(at + 1).filter(|k| k.is_list(b"sspc")).cloned()) else { return }; + empty_part(&mut fx); + edit_copy(&mut fx); + visit(fx.children_mut(), edit_copy); + if empty_original && let Some(original) = children.get_mut(at + 1) { + empty_part(original); + } + children.insert(at, fx); + children.insert(at, name); + added += 1; + } + }); + assert_eq!(added, 1, "one Glow on the layer"); + write(&file).unwrap() +} + +/// The imported Glows in stack order, each as its property values by property id. +fn glow_values(p: &Project) -> Vec> { + let glow = effectcraft_project::GroupKind::Effect { effect: "ec.stylize.glow".to_string() }; + let mut glows = Vec::new(); + for item in p.items.values() { + if let ItemKind::Comp(c) = &item.kind { + for layer in &c.layers { + for node in layer.effects().map(|fx| fx.children.as_slice()).unwrap_or_default() { + if let effectcraft_project::Node::Group(g) = node + && g.kind == glow + { + let mut values = Vec::new(); + g.walk("", &mut |_, prop| values.push((prop.match_id.clone(), prop.value.clone()))); + glows.push(values); + } + } + } + } + } + glows +} + +/// The value of property `id` in `values`. +fn value_of<'v>(values: Option<&'v Vec<(String, effectcraft_keyframe::Value)>>, id: &str) -> Option<&'v effectcraft_keyframe::Value> { + values?.iter().find(|(i, _)| i == id).map(|(_, v)| v) +} + +/// Every instance of an effect type but one has an empty `parT`; without a project-level copy the +/// others borrow the definitions of that one (#3170: 129 Color Controls of a template were +/// reported "without readable parameter definitions" and dropped). +#[test] +fn an_instance_without_definitions_imports_with_those_of_another_instance() { + // Both Glows import; before, the copy was reported and not imported. + let (p, r) = run(&second_glow_without_definitions(&mut |_| {}, false), true); + let r = r.unwrap(); + let found = losses(&r, LossCategory::Effects); + assert!(!found.iter().any(|d| d.contains("without readable parameter definitions") || d.contains("no parameter definition")), "{found:?}"); + assert_eq!(r.report.imported.effects, 3, "Levels and both Glows: {:?}", r.report.losses); + let glows = glow_values(&p); + assert_eq!(glows.len(), 2); + assert_eq!(glows.first(), glows.get(1), "the copy has the same records, so the same values"); + + // The values come from each instance's own records: the copy's A & B Midpoint (`-0011`) set + // to 0.75 arrives as 75 % in the copy only; the Glow it borrows from keeps its own. + let mut patched = 0; + let bytes = second_glow_without_definitions( + &mut |c| { + if c.is_list(b"tdgp") && patch_record(c, "ADBE Glo2-0011", None, 0.75) { + patched += 1; + } + }, + false, + ); + assert_eq!(patched, 1, "the copy's record"); + let (p, r) = run(&bytes, true); + r.unwrap(); + let glows = glow_values(&p); + let seventy_five = effectcraft_keyframe::Value::Scalar(75.0); + assert_eq!(value_of(glows.first(), "abMidpoint"), Some(&seventy_five)); + let own = value_of(glows.get(1), "abMidpoint"); + assert!(own.is_some() && own != Some(&seventy_five), "{own:?}"); +} + +/// A value record that the borrowed definitions do not name is reported, not dropped silently. +#[test] +fn a_value_record_the_borrowed_definitions_do_not_name_is_reported() { + let bytes = second_glow_without_definitions( + &mut |c| { + if c.is(b"tdmn") && c.bytes().is_some_and(|b| b.split(|x| *x == 0).next() == Some(b"ADBE Glo2-0011")) { + set_data(c, 0, b"ADBE Glo2-0099\0"); + } + }, + false, + ); + let (_, r) = run(&bytes, true); + let r = r.unwrap(); + let found = losses(&r, LossCategory::Effects); + assert!(found.iter().any(|d| d.contains("ADBE Glo2-0099") && d.contains("no parameter definition")), "{found:?}"); + assert_eq!(r.report.imported.effects, 3, "{:?}", r.report.losses); +} + +/// When no instance of the type keeps its definitions, every instance is reported. +#[test] +fn instances_without_any_definitions_are_reported() { + let (p, r) = run(&second_glow_without_definitions(&mut |_| {}, true), true); + let r = r.unwrap(); + let found = losses(&r, LossCategory::Effects); + assert_eq!(found.iter().filter(|d| d.contains("ADBE Glo2") && d.contains("without readable parameter definitions, not imported")).count(), 2, "{found:?}"); + assert_eq!(r.report.imported.effects, 1, "Levels only: {:?}", r.report.losses); + assert!(glow_values(&p).is_empty()); +} + +/// The reader's side: the copy's definitions come from the other instance. +#[test] +fn an_instance_without_definitions_reads_those_of_another_instance() { + let bytes = second_glow_without_definitions(&mut |_| {}, false); + let file = parse(&bytes).unwrap(); + let project = effectcraft_aep::Project::new(&file).unwrap(); + let defs = project.effect_definition_index(); + let mut sources = Vec::new(); + for item in project.all_items() { + let Some(comp) = item.comp() else { continue }; + for layer in comp.layers() { + for fx in layer.effects().iter().filter(|fx| fx.match_name() == "ADBE Glo2") { + sources.push(defs.source(fx)); + let params = defs.params(fx); + assert_eq!(params.len(), 16, "Glow's parameters"); + assert_eq!(params.iter().all(|p| p.borrowed_definition), defs.source(fx) == effectcraft_aep::DefinitionSource::OtherInstance); + } + } + } + // The copy is above the instance it borrows from (earlier in the stack). + assert_eq!(sources, [effectcraft_aep::DefinitionSource::OtherInstance, effectcraft_aep::DefinitionSource::Instance]); +} + /// A record in a state other than 1 or 3 is not read and is reported. #[test] fn an_effect_record_in_another_state_is_reported_as_damaged() { @@ -564,3 +744,60 @@ fn an_effect_record_in_another_state_is_reported_as_damaged() { assert!(damaged.iter().any(|l| l.contains("unreadable value")), "tdsb {tdsb}: {:?}", r.report.losses); } } + +/// The project with a value record for Glow's Color A (`ADBE Glo2-0012`, which the project does +/// not store) in state `tdsb` holding the ARGB doubles `argb` (0..255): a copy of the A & B +/// Midpoint record (`-0011`) made a 4-component colour without its expression. +fn with_color_a(tdsb: u32, argb: [f64; 4]) -> Vec { + let mut file: AepFile<'_> = parse(SYNTHETIC).unwrap(); + let mut added = 0; + visit(&mut file.chunks, &mut |c| { + let Body::List { list_type, children, .. } = &mut c.body else { return }; + if list_type != b"tdgp" { + return; + } + let Some(at) = children.iter().position(|k| k.is(b"tdmn") && k.bytes().is_some_and(|b| b.split(|x| *x == 0).next() == Some(b"ADBE Glo2-0011"))) else { + return; + }; + let (Some(mut name), Some(mut record)) = (children.get(at).cloned(), children.get(at + 1).filter(|k| k.is_list(b"tdbs")).cloned()) else { return }; + set_data(&mut name, 0, b"ADBE Glo2-0012\0"); + if let Body::List { children: kids, .. } = &mut record.body { + kids.retain(|k| !k.is(b"Utf8")); + for k in kids.iter_mut() { + if k.is(b"tdsb") { + set_data(k, 0, &tdsb.to_be_bytes()); + } else if k.is(b"tdb4") { + // 4 components; no expression (bytes 76, 77 and 120). + set_data(k, 3, &[4]); + for byte in [76, 77, 120] { + set_data(k, byte, &[0]); + } + } else if k.is(b"cdat") { + *k = Chunk::data(*b"cdat", argb.iter().flat_map(|v| v.to_be_bytes()).collect::>()); + } + } + } + children.insert(at + 2, record); + children.insert(at + 2, name); + added += 1; + }); + assert_eq!(added, 2, "the instance and the EfdG copy"); + write(&file).unwrap() +} + +/// A colour recorded in the default state (`tdsb` 3) reads like a written one (#3170's "parameter +/// Color ... holds an unreadable value" on 0.21.1, which read only written records). +#[test] +fn a_default_state_colour_record_holds_the_value() { + let argb = [255.0, 51.0, 153.0, 255.0]; + let (written, r1) = run(&with_color_a(1, argb), true); + let (default_state, r3) = run(&with_color_a(3, argb), true); + let (r1, r3) = (r1.unwrap(), r3.unwrap()); + assert!(losses(&r3, LossCategory::DamagedData).is_empty(), "{:?}", r3.report.losses); + assert_eq!(r3.report.losses, r1.report.losses); + let colour = |p: &Project| value_of(glow_values(p).first(), "colorA").cloned(); + let (unchanged, _) = run(SYNTHETIC, true); + assert!(colour(&written).is_some()); + assert_eq!(colour(&default_state), colour(&written)); + assert_ne!(colour(&default_state), colour(&unchanged), "the recorded colour, not the default"); +} diff --git a/docs/aep-format.md b/docs/aep-format.md index 99a1199f0..d6eff25f8 100644 --- a/docs/aep-format.md +++ b/docs/aep-format.md @@ -461,7 +461,7 @@ The expression engine is project-wide (`LIST ExEn/Utf8`, `javascript-1.0`). API: | **default** | `pard` | 56 | by type | float slider: f64 (Slider 0, **Blurriness 25**); fixed slider and angle: 16.16 (drop shadow opacity 127.5, direction 135, distance 5, softness 0; Fill opacity 1.0 = 100 %; **Tint Amount to Tint 100, Ramp Scatter 0, Blend With Original 0**); **colour: ARGB bytes (drop shadow `ff000000` black, Fill `ffff0000` red; Ramp Start `ff000000`, End `ffffffff`; Tint Map Black To `00000000` and Map White To `00ffffff`: alpha 0, which is what After Effects reads back)**; popup: u32 index (1); **point: two 16.16 fractions of the layer size at 56 and 60 (Point Control 0.5, 0.5; Ramp Start 0.5, 0 and End 0.5, 1)** | 071, 077, 080, 214, 215, 356, 368, 383 | V | | **valid maximum** | `pard` | 128 / 108 | 16.16 / f32 | the largest valid value of a fixed slider (128: Tint Amount 100, Ramp Scatter 512, Blend With Original **1.0**) and of a float slider (108: Blurriness 30 000; **Exposure 100, Offset 2, Gamma Correction 10**). The stored scale differs per slider (below), so this is the reader's only hint at it | 356, 368, 078, 389 | V | | **float slider valid minimum, slider range** | `pard` | 104; 112 / 116 | f32; f32 x 2 | the smallest valid value (Exposure -100, Offset -2, Gamma Correction 0.1 as f32) and the range the slider covers (Exposure -4..4, Offset -0.5..0.5, Gamma 0.1..10); the slider range is repeated as `tdum` / `tduM` (f64) in each value record (391-394). @120 holds the default again as f32 (Gamma 1.0, Blurriness 25), u16 @124 the display decimals (**H**: Exposure 2, Offset 4) | 389, 391-394 | V | -| **definitions of a second instance** | top-level `LIST EfdG` | | | one `EfDf` per effect TYPE (`tdmn` = match name, then a copy of ONE instance's `sspc`, including that instance's value records); the `EfDC` count before them is a little-endian u32. When two layers carry the same effect type, only one instance keeps a full `parT`; **the other has an empty `LIST parT` (4 bytes)** but its own `tdgp` (input layer `-0000` with its own `tdpi`, the button record, and its value records). Its definitions come from the `EfdG` copy by match name, its values from its own records, never from the copy (383: the copy holds S100's Start [0.1, 0.2]; L's Ramp reads the 368 defaults). Which instance keeps the full `parT` is **?** (in 383 S100 is both first in the file and newest). The `EfDf` order follows the stack order (365 / 366); `Pefl/pjef` does not | 365, 366, 383 | V | +| **definitions of a second instance** | top-level `LIST EfdG` | | | one `EfDf` per effect TYPE (`tdmn` = match name, then a copy of ONE instance's `sspc`, including that instance's value records); the `EfDC` count before them is a little-endian u32. When two layers carry the same effect type, only one instance keeps a full `parT`; **the other has an empty `LIST parT` (4 bytes)** but its own `tdgp` (input layer `-0000` with its own `tdpi`, the button record, and its value records). Its definitions come from the `EfdG` copy by match name, its values from its own records, never from the copy (383: the copy holds S100's Start [0.1, 0.2]; L's Ramp reads the 368 defaults). Which instance keeps the full `parT` is **?** (in 383 S100 is both first in the file and newest). The `EfDf` order follows the stack order (365 / 366); `Pefl/pjef` does not. **Some files have no `EfdG` at all** (seen in 17 projects, all from inside After Effects-made Motion Graphics templates). In each of them every effect type (196 in all; 2 to 14 Color Controls per file) has exactly one instance with a full `parT` and an empty one in every other instance, and the reader takes the others' definitions from that instance (`DefinitionSource::OtherInstance`, #3170). Which instance keeps it is **?** here too | 365, 366, 383; templates | V | | popup items | `parT/pdnm/Utf8` | | text | items separated by `\|` | 077 (`Item 1\|Item 2\|Item 3`), 214 | V | | stored value | `sspc/tdgp/-NNNN` | | `tdbs` | present only for a parameter that differs from its default; `tdsb` 1, `cdat` as in 3.4. **Absent record = the `pard` default.** Some parameters are recorded in the default state (`tdsb` 3) and the record still holds the value After Effects uses: every one of the 25 such records in the corpus and the samples differs from its `pard` default and reads back as recorded (Lumetri Color's hidden controls High Dynamic Range, HDR Specular, the second Look, Legacy Tone And Saturation, Face Detection, Auto Color, Auto Intensity and SemanticAutoTone Progress, 1200; Cryptomatte's Selection Mode on, 1400). No effect record in the default state holds a value that does not count. The reader takes the value in either state (`EffectParam::recorded_value`, `EffectParam::value`); `EffectParam::stored_value` keeps to written records, and a record in any other state (no sample has one) is not read: the importer reports it as damaged data. That other effects record values so is H (no sample shows one) | see below; 1200, 1400 | V (1200, 1400), H (other effects) | From 84382487bbeaef3d45dde3e1c76a91597132ac57 Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Sun, 8 Nov 2026 02:30:59 +0100 Subject: [PATCH 28/40] Disk cache: entries keep the files they read, keys from memory (#3184) (#3191) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Disk cache: record the source files each frame reads Part of #3184 (step 1): renders now report which footage files they read, each with its identity (size and modification time) as read. Nothing uses the list yet: images, cache keys and cache behaviour are unchanged. - render: `reads` module with `FileStamp`, `ReadFile`, `ReadFiles` (sorted, deduplicated, bounded; marked incomplete when it can't vouch for every file) and the thread-safe `ReadLog`. `Renderer::reads` collects a frame's files; `FootageSource::recording` lets a source note what it reads. `file_stamp` uses the same identity. - Layer cache entries keep the files their buffer was made of and report them on every hit; derived entries (styles, blend space, flattened) keep their base's. Buffers from the disk cache or the browser store don't know their files yet and mark the list incomplete. - Media pool: every file read notes its identity, taken from the file it opens. Decoded frames, opened movies, GIFs, models and EXR channels keep it with the cache entry, so a frame served from memory reports its file without touching the disk. - Viewer frame worker collects each frame's list and carries it to where the disk entry is written (step 2 stores it). Co-Authored-By: Claude Opus 5.5 * Automation: confined footage passes on the files it reads Part of #3184: ConfinedFootage forwards FootageSource::recording to the source it wraps, so renders of an automation session list their files instead of coming back incomplete. The read tests also render through the viewer's CancellableFootage wrapper. Co-Authored-By: Claude Opus 5.5 * Disk cache: frame entries keep their source files, comp key from memory Part of #3184 (step 2). Fixes #3175: opening a comp no longer stamps every footage file of the project before its first frame can show. - The comp's content key (`disk_cache::comp_content_key`) is taken from the project in memory alone: no footage or proxy file is stamped, no `VirtualFileId` is asked. `comp_content_key_with` is gone; `frame_key` hashes a new entry version, so entries of the earlier format are never looked up again (LRU evicts them). - Frame entries (formats 2 and 3) store the files the frame read (`EntryFiles`: size and modification time as read; size and content hash through `VirtualFileId` for files from memory; missing files), then the pixels. Formats 0 and 1 read as misses and are deleted. - Check on hit: `get_frame`/`get_frame_f16` look only at the listed files (one metadata call each) on the frame worker. A changed, back or unreadable file, or a damaged entry, is a miss: the entry is deleted and the frame rendered and stored again. - A frame whose file list is incomplete is shown but not stored. The RAM preview keeps each frame's files, so `persist_missing` writes only frames with a complete list. - Remote frame worker: `FrameServer` records each frame's reads (`take_files`); the web worker stores them with the entry and the page checks them through the file table before using it. The browser's media epoch existed only for the old key and is removed. Export does not use frame entries. - The cache indicator still only asks whether an entry exists. Tests: entry format round trip and damage, the check per file, and in the viewer: a changed file re-renders exactly its frames (and a reopen reads the rest from disk); a frame checks only its own files in a project with a large unused sequence and the key looks at no file; missing, unreadable files and damaged entries never serve a stale frame. Co-Authored-By: Claude Opus 5.5 * Disk cache: layer entries keep their source files, no footage salt Part of #3184 (step 3 of 4). Layer buffers on disk (and in the browser's layer store) now carry the files they were made of, like frame entries since step 2, and are checked against exactly those files when used. The project-wide footage salt is gone: nothing stamps every footage file any more. - Layer entry format 4: the buffer's EntryFiles, then the pixels. A hit checks only the listed files (metadata, or the VirtualFileId hook for files from memory; Missing must still be missing); a change, a damaged entry or the old format 0 is a miss and the entry is deleted, so the re-rendered buffer replaces it. A hit reports its file list, so frames made of buffers from disk are complete and get stored again. - Buffers whose files can't all be named are not written. - Layer disk keys: layer_disk_key = hash of the layer entry version, the renderer version and the layer cache key (which names the footage items with their paths and settings, from memory). - PrefetchStore checks on use; an entry made of changed files is dropped and forgotten, so the new buffer is queued over it. FrameServer passes its virtual-file hook to its layer cache. - Removed: footage_salt(_with), file_stamp, footage_stamp, set_disk_salt, set_store_salt, Session::refresh_disk_salt, poll_disk_salt, footage_fingerprint, disk_salt, disk_salt_background, disk_salt_job, DiskSaltJob, the UI's per-frame poll, the salt in FrameServer and in the availability worker (with its cache_enabled plumbing). The disk cache is attached as soon as it is configured. - Docs: architecture.md, web.md. Tests: layer entries check their files (size, time, missing/back, folder, damaged, old format, incomplete); virtual files; prefetch store; media tests with a real pool across restarts (only the changed file is read, projects with the same item ids never share an entry, missing, unreadable and damaged never serve stale buffers); engine tests that the cache is attached at once and edits do no file work (#1926, #3106). Co-Authored-By: Claude Opus 5.5 * Disk cache: no-salt worker test, sequence paths in the frame-blend key Part of #3184 (step 3 of 4). - A frame-blended footage frame's layer-cache key now hashes the sequence's file list: with no project-wide salt, two projects whose items share an id and a first frame must not share its disk entry. - Test: a frame worker syncing, patching and rendering a project with an unused 5000-frame sequence asks its file hook only about the file its buffer reads (the salt asked about every file at every sync). Co-Authored-By: Claude Opus 5.5 * Disk cache: the comp key covers what its expressions can read With an expression anywhere in the project, every comp's disk key hashed every item of the project, so any edit (another comp, an unused footage item) threw away every comp's frames on disk. The key now covers what the comp can draw plus what the expressions among it can reach (Project::pixel_reach): - without expressions: the items the comp draws, without silent layers, plus the footage its precomp layers swap in (Media Replacement); - with expressions: every layer of the comps they reach, their markers, the comps and footage they name with string literals (comp("Name"), footage("Name")) together with which items have those names now, and the footage named like a reached source (its data is read by name); - the whole project when an expression computes a name, uses the object model's constructors or internals, dynamic code, computed keys or writes, or text the scanner can't read for sure (regex literals, template strings, escapes): expression_reach errs towards reaching more. Markers count only where an expression can read them (#1083). Memory only, no file is looked at. Tests: scanner and reach unit tests in the project crate; engine tests for the key (own-comp expressions keep the key through edits elsewhere, comp("Other") follows Other and not a third comp, a second comp taking the name counts, a computed name counts every item, markers read from another comp); a ui-egui test that the disk frames outside an expression layer are carried when the comp it names changes. Part of #3184. Part of #1492. Co-Authored-By: Claude Opus 5.5 * Disk cache: Reload Footage drops the entries of its files, docs File > Reload Footage now deletes the frame and layer entries whose file lists name the reloaded item's files (DiskCache::drop_files), so a file replaced by one with the same size and modification time, which the check on hit can't tell apart, is read again. The index knows keys, not files: the writer thread reads the files section at the start of each frame and layer entry (not the pixels) after the writes queued before it, and deletes the entries that list one of the files. Until it is done, an entry made of one of them is a miss and frames aren't linked to new keys. The entries are gone for good, so they don't come back after a restart. Automatic reloads don't drop anything: they follow a changed stamp, which the check on hit catches. The browser needs nothing (its file identities are content hashes). Removed: disk_cache::seal, which steps 2 and 3 left without callers (the tests use seal_format). Updated the module, seal_format and forget_media docs, and docs/architecture.md / docs/web.md describe the final design: what is cached, keys from memory, file lists checked on hit, nothing scans the project, incomplete lists stay in memory, Reload Footage drops entries, edits keep the frames they can't change. Tests: render unit tests (same size and time passes the check but not the drop; other files' entries stay; an entry queued before the drop is dropped; a layer entry too; written again afterwards it is used; the drop survives a restart; a pending drop is a miss), and an engine test through file.reloadFootage. Closes #3184. Part of #1492. Co-Authored-By: Claude Opus 5.5 * Disk cache: file stamps keep the whole modification time A file's modification time was nanoseconds since 1970 as u64: a time before 1970 read as "no time" (two such files of one size looked alike) and times after 2554 were truncated. It is now i128 nanoseconds, negative before the epoch; None only means the file system has no time. The content-key hash writes a presence tag and the full value. Co-Authored-By: Claude Opus 5.5 * Automation: a refused footage read leaves the render's file list incomplete Footage outside the read roots shows nothing and was noted as no file at all, so a picture made without it had a complete, empty list and could be kept on disk for a later session with other roots. A refused read during `recording` now marks the list incomplete. Co-Authored-By: Claude Opus 5.5 * Render: a buffer kept by another worker comes with its own files LayerCache::insert returns the files of the buffer it keeps, and Renderer::keep notes them in the render's log and returns them, so a render that uses another worker's buffer lists that buffer's files (a file changed between the two reads then has two identities and the list is incomplete). Co-Authored-By: Claude Opus 5.5 * Render: sampleImage and text fonts note the files they read EvalCtx carries the render's read log. A sampleImage render records its footage reads, keeps them with its per-thread cached buffer and notes them in the evaluating render's log on every use. Text notes the font files it is drawn with, with the identity their bytes were read with; a family that isn't installed, a fallback or missing glyph, or a font from memory leaves the list incomplete. Co-Authored-By: Claude Opus 5.5 * Disk cache: frame entries store the whole modification time A frame entry's file list stores a file's modification time as i128 nanoseconds since 1970 (negative before), as the file stamps now keep it; the frame entry format version goes to frame-entry-files-2 so entries in the old layout are not read. Co-Authored-By: Claude Opus 5.5 * Disk cache: layer entries store the whole modification time Layer entries share the frame entries' file list layout, which now stores the full i128 modification time: the layer entry format version goes to layer-entry-files-2. The module doc names the font files text is drawn with among an entry's source files, and what keeps a list incomplete. Co-Authored-By: Claude Opus 5.5 * Layer cache: buffers that read other layers are keyed by the switches passed down A layer whose effect reads another layer (Gradient Wipe, Set Matte, Blend…) gets that layer drawn by its own renderer. Through a precomp layer, Switches Affect Nested Comps, the switches inherited from the precomp layers above and motion blur on change those pixels, but the key held only the layers' own switches: a buffer made with the setting on was reused (from memory or the disk cache) with it off. Such layers now derive their key with what the renderer passes down. Co-Authored-By: Claude Opus 5.5 * Layer cache: masked buffers are keyed by the mask motion blur gate A mask with Mask Motion Blur On blurs even when the layer's own switch is off, as long as the render's gate is open (Render Settings motion blur, and with Switches Affect Nested Comps the precomp layers above). The key held the layer's own motion blur state only, so a buffer blurred with the gate open was reused with it closed (and the other way round), also from the disk cache. Masked layer, input and footprint keys now tell a closed gate apart. Co-Authored-By: Claude Opus 5.5 * Render: cached buffers list what their expressions and substituted characters read - Buffers made under `Renderer::recorded` (layer content, a Time effect's input, an adjustment layer's footprint) evaluate their masks, shapes and effects with the context that notes into the buffer's own read log, so a file an expression reads (`sampleImage`, also at shutter times mask motion blur adds and the cache key doesn't see) is in the buffer's files. - A styled layer served from the cache lists the files of the cached body and passes too, so the buffers made of it (flattened, blending space) don't get a complete list when one of them came with an incomplete one. - A character put in by Character Offset or Character Value without a relayout notes the font it is drawn with; a fallback face (or none) leaves the list incomplete. Co-Authored-By: Claude Opus 5.5 * Render: text lists the font file of a run that draws no glyph; tests clean their temp dirs An empty first paragraph draws no glyph, but in a box its face sets the first baseline that places every later line. The read list took faces only from glyphs, so it could be complete without that file. Note each style run's resolved face as well. The font-reads and confine tests use tempfile::tempdir(): a fresh directory per run, removed on panic too. Co-Authored-By: Claude Opus 5.5 * Disk cache: Reload Footage closes the gaps around its drop (#3184) - A reload while the disk cache is off is kept on the session (pending_disk_drops) and applied when the cache is switched on, before anything is read from it. - Each render takes the cache's drop generation before it reads (frame worker; layer cache at the miss). An entry listing a file dropped after that is refused under the queue's lock, so a render that was under way during the reload can't store pixels from before it. Such a frame is shown with an incomplete file list, so persist_missing skips it too. The per-file record is bounded (past it, everything older is refused). - An entry read while its drop was pending is a miss even when the writer ends the sweep between the read and the check (a stale hit found under load): the pending drops and the generation are taken before the entry is read. - Test: a reopened project serves its frame from disk with no source file opened or decoded. Co-Authored-By: Claude Opus 5.5 * Disk cache: RAM frames keep the drop generation their render started at Reload Footage empties the RAM preview, but an idle pass of persist_missing may already hold a frame from before the reload. It took the cache's drop generation when it ran, after the drop, so the old pixels could be written back and, with the file's size and time unchanged, served again after a restart. Each RAM frame now keeps the disk cache its render started with and that cache's drop generation then. persist_missing writes a frame only to that cache, with that generation, and skips it once one of its files was dropped since; a frame rendered without that cache is not written from there. Tests use tempfile directories (the layer drop test, the frame_files folders under target/). Co-Authored-By: Claude Opus 5.5 * Doc comments for the functions this PR touches * Disk cache: cap the free-space reserve at 10 GB, skip encodes the limit refuses The reserve the cache leaves free on its disk was max(2 GB, 5% of the disk) (#2551). On a 4 TB disk with 190 GB free that is 200 GB, so a cache set to 20 GB had a limit of 0: every write was refused, the cache never held anything, and only a log warning said so. The reserve is now clamp(5% of the disk, 2 GB, 10 GB). It is there to keep the cache from filling the disk, not to keep a share of a large disk free: 10 GB leaves the system room to work on any disk, a small disk still keeps 2 GB, and a 100 GB disk keeps 5 GB as before. After Effects has only a maximum cache size and no reserve; a clamp keeps the floor for small disks, where a fixed 10 GB would take most of the space. Writes the limit refuses cost no work: DiskCache::accepts_writes (one atomic read) is checked before a frame is converted (put_disk_frame) and before frames and layers are compressed (put_frame, put_frame_f16, put_layer). The frame workers spent about 8 ms per frame and 14 ms per layer on encodes that were then refused. persist_missing returns at once at limit 0 instead of converting the RAM frames on every idle pass. Settings > Disk shows the limit in effect in MB under Maximum Disk Cache Size, with a note when free disk space lowers it (settings.disk.cacheLimit). * Disk cache: refuse writes below 64 MB of room, show this disk's reserve Review follow-ups to the reserve fix: - accepts_writes also refuses while free disk space leaves less than 64 MB of room (a limit the setting asks for is always used): a few frames would fill it, and the rest would be compressed only to be refused. - While writes are refused the idle passes ask for no repaint, so the UI keeps a frame coming every 5 s: the free space is read again and the RAM frames are written once there is room. - Settings > Disk names the space kept free on this disk (the reserve the last reading applied; the rule from MIN/MAX_DISK_RESERVE when it is unknown), and the "no room" note follows accepts_writes. - The settings.disk.cacheLimit automation label is machine-readable and the same in every language: limitMb, maxMb, reserveMb, spaceLimited, writes. - cargo fmt. * Disk cache: follow 3D model sources in the comp's reach The reach walk followed comp, footage and solid sources but not LayerSource::Model. An expression reading a model layer's source (thisComp.layer("Model").source.name) left the model item out of the comp's content key, so renaming the model kept the key and the old frames on disk were served. Every source item is followed now (LayerSource::item), which also counts the model when no expression reads it (Advanced 3D draws it). The same omission is fixed in the RAM preview's content walk (frames.rs) and in the layer key's walk of referenced layers (cache/dependencies.rs). * Disk cache: a render's drop generation travels with its reads; no disk entries for Expression Selectors Drop generation per render: the layer cache recovered a buffer's drop generation from the latest miss of its key, so a second render of the key that started after File > Reload Footage lent its generation to a render still running from before, and that render's buffer (the file as it was) was written after the sweep. Now Renderer::recorded starts each buffer's read log at the store's drop generation before anything is read (ReadLog::starting_at); ReadFiles carries the earliest generation through merges, so derived buffers (styles, the blend-space copy, the flattened layer) and frames that use a buffer from memory carry it too. LayerCache::insert keeps a buffer made of a file dropped since its reads began neither on disk nor in memory; a list that doesn't say counts as made before every drop. DiskCache::dropped_since takes the list's own generation too. missed_at keeps only the miss time. Expression Selectors: the layer key evaluates a text Expression Selector's amount for the first character only, so a per-character dependency such as textIndex == 1 ? 0 : footage("ref.png").width was not in the key, and after the footage item's width changed a reopened session reused the old layer entry. A text layer with an Expression Selector now marks its reads unkeyed (ReadFiles::is_unkeyed), which merges like the generation; such buffers stay in memory and are never written to disk. Frame entries are unaffected: the comp's frame key hashes what the expressions name. The equality and hash of ReadFiles ignore both new fields. * Disk cache: never serve a RAM layer buffer made before a drop of its files A render that passed the drop check could sit in put_layer's encode while Reload Footage cleared the layer cache and dropped the file, then publish its old pixels to memory after the purge; get, and a fresh render's insert, then served them. The disk-hit promotion went through the same insert_mem. Every way the cache hands out a RAM buffer (get, the kept-first path of insert, an existing entry in insert_mem) now checks the entry's files against the store's drops from their own generation (ReadFiles::since): an entry made before a drop of one of its files is forgotten and the lookup misses, so a fresh render's buffer replaces it. insert_mem also re-checks a buffer just before publishing it. --------- Co-authored-by: Claude Opus 5.5 --- Cargo.lock | 3 + apps/effectcraft-web/src/app.rs | 2 +- apps/effectcraft-web/src/diskcache.rs | 24 +- apps/effectcraft-web/src/frames.rs | 7 +- apps/effectcraft-web/src/store.rs | 18 +- apps/effectcraft/src/main.rs | 3 - crates/automation/Cargo.toml | 1 + crates/automation/src/confine.rs | 105 +- crates/engine/src/analysis/tracking.rs | 2 +- crates/engine/src/background/remote.rs | 53 +- crates/engine/src/background/remote/tests.rs | 138 +- crates/engine/src/cmd/effect.rs | 5 + crates/engine/src/cmd/layer/parent.rs | 1 + crates/engine/src/cmd/layer_time.rs | 1 + crates/engine/src/cmd/path_nulls.rs | 4 + crates/engine/src/cmd/prop.rs | 3 + crates/engine/src/cmd/puppet.rs | 13 +- crates/engine/src/cmd/rig3d.rs | 2 + crates/engine/src/cmd/three_d.rs | 27 +- crates/engine/src/footage/availability.rs | 43 +- crates/engine/src/footage/footage_check.rs | 2 +- crates/engine/src/footage/footage_reload.rs | 45 +- crates/engine/src/lib.rs | 17 +- crates/engine/src/session.rs | 2 +- crates/engine/src/session/edit.rs | 117 -- .../engine/src/settings/session_settings.rs | 14 +- crates/engine/src/tests/crypto_pick.rs | 1 + crates/engine/src/tests/disk_cache.rs | 352 +++-- crates/engine/src/tests/rig3d.rs | 14 +- crates/engine/src/tests/sequence.rs | 21 +- crates/expr/src/host.rs | 2 + crates/expr/src/lib.rs | 1 + crates/expr/src/sample.rs | 24 +- crates/expr/src/tests.rs | 39 + crates/gpu/src/tests/adv3d.rs | 2 + crates/host/src/tests.rs | 34 + crates/media/Cargo.toml | 4 + crates/media/src/exr_channels.rs | 84 +- crates/media/src/lib.rs | 26 +- crates/media/src/pool.rs | 202 ++- crates/media/src/reads.rs | 120 ++ crates/media/src/reads/tests.rs | 390 +++++ crates/media/src/stream.rs | 17 +- crates/project/src/lib.rs | 2 + crates/project/src/reach.rs | 405 +++++ crates/project/src/reach/tests.rs | 198 +++ crates/render/Cargo.toml | 3 + crates/render/src/accel.rs | 23 +- crates/render/src/cache.rs | 597 +++++-- crates/render/src/cache/dependencies.rs | 2 +- crates/render/src/disk_cache.rs | 1390 +++++++++++++---- crates/render/src/disk_cache/entry_files.rs | 276 ++++ crates/render/src/eval.rs | 6 +- crates/render/src/footage.rs | 19 + crates/render/src/fx_host.rs | 3 +- crates/render/src/layers.rs | 87 +- crates/render/src/lib.rs | 5 + crates/render/src/pipeline.rs | 236 ++- crates/render/src/reads.rs | 348 +++++ crates/render/src/tests.rs | 174 +++ crates/render/src/tests/collapse.rs | 13 +- crates/render/src/tests/mask_blur.rs | 29 + crates/render/src/tests/styles.rs | 31 + crates/render/src/tests/time.rs | 1 + crates/render/src/text.rs | 72 +- crates/render/src/text/tests.rs | 87 ++ crates/render/src/three_d/adv/scene.rs | 11 +- crates/render/src/three_d/adv/tests.rs | 4 + crates/render/src/three_d/compose.rs | 6 +- crates/script/src/tests/ui_more.rs | 1 + crates/text/src/fonts.rs | 33 +- crates/ui-egui/src/app/frame.rs | 4 - crates/ui-egui/src/frames.rs | 339 ++-- crates/ui-egui/src/frames/tests.rs | 548 ++++++- crates/ui-egui/src/menus/invoke.rs | 1 + .../src/panels/effect_controls/panel.rs | 1 + crates/ui-egui/src/panels/layer_panel.rs | 1 + crates/ui-egui/src/panels/properties.rs | 1 + crates/ui-egui/src/panels/roto_tool.rs | 1 + crates/ui-egui/src/panels/settings.rs | 110 +- crates/ui-egui/src/panels/text_panels.rs | 1 + crates/ui-egui/src/panels/timeline.rs | 1 + crates/ui-egui/src/panels/viewer.rs | 2 + crates/ui-egui/src/panels/viewer/shapes.rs | 2 + crates/ui-egui/src/panels/viewer/view.rs | 1 + crates/ui-egui/src/prefs_live.rs | 6 + .../ui-egui/tests/it/ui_unreadable_footage.rs | 3 +- crates/ui-egui/tests/it/ui_web_gpu_storage.rs | 9 +- docs/architecture.md | 47 +- docs/preferences.md | 7 +- docs/web.md | 15 +- 91 files changed, 5945 insertions(+), 1202 deletions(-) create mode 100644 crates/media/src/reads.rs create mode 100644 crates/media/src/reads/tests.rs create mode 100644 crates/project/src/reach.rs create mode 100644 crates/project/src/reach/tests.rs create mode 100644 crates/render/src/disk_cache/entry_files.rs create mode 100644 crates/render/src/reads.rs diff --git a/Cargo.lock b/Cargo.lock index 5b426c8f8..f897737db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1468,6 +1468,7 @@ dependencies = [ "effectcraft-script", "image", "serde_json", + "tempfile", "thiserror 2.0.21", ] @@ -1741,6 +1742,7 @@ version = "0.21.0" dependencies = [ "craft-docpath", "effectcraft-color", + "effectcraft-effects", "effectcraft-model", "effectcraft-pdf", "effectcraft-project", @@ -1877,6 +1879,7 @@ dependencies = [ "lz4_flex", "rayon", "serde", + "tempfile", "web-time", ] diff --git a/apps/effectcraft-web/src/app.rs b/apps/effectcraft-web/src/app.rs index 2882b16cf..99e71117f 100644 --- a/apps/effectcraft-web/src/app.rs +++ b/apps/effectcraft-web/src/app.rs @@ -329,7 +329,7 @@ pub async fn start(canvas_id: String) -> Result<(), JsValue> { if n > 0 { app.frames.set_remote(Some(Arc::new(frames::WebFrames::start(n, !query_flag("nogpuworkers"))))); } - app.frames.set_virtual_media(files::STORE.media_epoch(), Arc::new(|path| files::STORE.file_identity(path))); + app.frames.set_virtual_id(Arc::new(|path| files::STORE.file_identity(path))); let (tx, rx) = std::sync::mpsc::channel(); api::set_sender(tx); app = app.with_control(rx); diff --git a/apps/effectcraft-web/src/diskcache.rs b/apps/effectcraft-web/src/diskcache.rs index ef9d46f8c..72e9a9e11 100644 --- a/apps/effectcraft-web/src/diskcache.rs +++ b/apps/effectcraft-web/src/diskcache.rs @@ -4,23 +4,28 @@ //! //! - **Writes** happen in the frame workers: a render request carries the frame's disk-cache key //! (`effectcraft_engine::remote::FrameMsg::Render`), the worker posts the frame, then writes -//! the sealed entry (`disk_cache::frame_entry`: LZ4, checksum) with a synchronous access -//! handle into a temporary file moved into place (`js/host.js` `cacheWrite`), and reports -//! `FrameReply::Stored`. +//! the sealed entry (`disk_cache::frame_entry`: the source files the frame read, LZ4, +//! checksum) with a synchronous access handle into a temporary file moved into place +//! (`js/host.js` `cacheWrite`), and reports `FrameReply::Stored`. A frame whose files can't +//! all be named is not stored. //! - **The index** lives here, on the page ([`DiskIndex`], shared with the desktop's cache): //! rebuilt at startup from the folder listing (oldest files first), updated by the workers' //! `Stored` replies and by reads; eviction deletes the least recently used files. //! - **Reads** are asynchronous: a frame whose key is indexed is read and decoded here instead -//! of rendering it (`crate::frames`); a damaged or missing file is a miss and is forgotten. +//! of rendering it (`crate::frames`), if the files its entry lists still have the size and +//! content hash it was made of (the file table's identities); a damaged or missing entry, or +//! one whose files changed, is a miss and is deleted. //! //! - **Layer buffers** too (`layers/<32 hex>.ecc`): a layer lookup happens in the middle of a //! synchronous render, where the browser's file system can't be read, so the frame workers //! back their layer caches with a `PrefetchStore`. They report each frame's layer-cache //! misses; before the next request the page names the recent misses that are on disk //! ([`layer_prefetch`], `disk_cache::LayerPrefetch`), and the worker reads those entries -//! into memory before rendering, so the lookups find them. Slow buffers are written by the -//! worker after its frame and indexed here like frames (one least-recently-used order for -//! both kinds). +//! into memory before rendering, so the lookups find them; an entry is used only while the +//! files it lists (the file table's size and content hash) are unchanged, and a buffer whose +//! files can't all be named is not written (#3184). Slow buffers are written by the worker +//! after its frame and indexed here like frames (one least-recently-used order for both +//! kinds). use std::cell::RefCell; @@ -187,11 +192,12 @@ pub fn note_miss() { } /// Read and decode a cached frame; `None` (forgotten and deleted) when the file is missing or -/// damaged. +/// damaged, or the source files it was made of changed since. pub async fn read(key: u128) -> Option { let name = disk_cache::entry_name(key); let bytes = JsFuture::from(cache_read(&name)).await.ok().and_then(|b| b.dyn_into::().ok()).map(|b| b.to_vec()); - let frame = bytes.as_deref().and_then(disk_cache::read_frame_entry); + let identity = |path: &str| crate::files::STORE.file_identity(path); + let frame = bytes.as_deref().and_then(|b| disk_cache::read_frame_entry(b, Some(&identity))); ST.with(|s| { let mut s = s.borrow_mut(); if frame.is_some() { diff --git a/apps/effectcraft-web/src/frames.rs b/apps/effectcraft-web/src/frames.rs index 69089e308..0159fe23b 100644 --- a/apps/effectcraft-web/src/frames.rs +++ b/apps/effectcraft-web/src/frames.rs @@ -473,10 +473,13 @@ pub async fn worker_frame(json: String) { g.settled().await; replies = SERVER.with(|c| c.borrow_mut().as_mut().map(|s| s.resume()).unwrap_or_default()); } + // The source files the frame read, kept with its entry (checked by the page before use); a + // frame whose files can't all be named is not stored (#3184). + let (files, virtual_id) = SERVER.with(|c| c.borrow_mut().as_mut().map(|s| (s.take_files(), s.virtual_id().cloned())).unwrap_or_default()); for (r, px) in replies { post_reply(&r, px.as_deref()); - if let (FrameReply::Frame { width, height, .. }, Some(px), Some(key)) = (&r, &px, &disk) { - let entry = effectcraft_engine::render::disk_cache::frame_entry(*width, *height, px); + if let (FrameReply::Frame { width, height, .. }, Some(px), Some(key), Some(files)) = (&r, &px, &disk, &files) { + let Some(entry) = effectcraft_engine::render::disk_cache::frame_entry(*width, *height, px, files, virtual_id.as_deref()) else { continue }; let name = format!("{key}.ecc"); match JsFuture::from(crate::diskcache::cache_write(&name, js_sys::Uint8Array::from(&entry[..]))).await { Ok(n) => post_reply(&FrameReply::Stored { key: key.clone(), bytes: n.as_f64().unwrap_or(entry.len() as f64) as u64, layer: false }, None), diff --git a/apps/effectcraft-web/src/store.rs b/apps/effectcraft-web/src/store.rs index 0cc877948..a4947600b 100644 --- a/apps/effectcraft-web/src/store.rs +++ b/apps/effectcraft-web/src/store.rs @@ -20,7 +20,6 @@ use std::collections::BTreeMap; use std::path::{Path, PathBuf}; -use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::{Arc, Mutex, OnceLock}; use effectcraft_engine::config::{ConfigStore, FileOps}; @@ -187,13 +186,12 @@ pub struct Store { pub on_change: OnceLock, /// Clock in milliseconds since the Unix epoch (tests pin it). pub clock: OnceLock f64>, - /// Bumped when a virtual file is written. Preview cache lookups key on it; they do not hash. - media_epoch: Arc, } impl Default for Store { + /// An empty store with no mirror contents, change callback or clock. fn default() -> Self { - Self { mirror: Mutex::default(), on_change: OnceLock::new(), clock: OnceLock::new(), media_epoch: Arc::new(AtomicU64::new(0)) } + Self { mirror: Mutex::default(), on_change: OnceLock::new(), clock: OnceLock::new() } } } @@ -218,22 +216,12 @@ impl Store { pub fn put_file(&self, path: &str, data: Arc<[u8]>, persist: bool) { let now = self.now(); let key = file_key(path); - let replaced = self.lock().get(&key).is_none_or(|e| !Arc::ptr_eq(&e.data, &data)); self.lock().put(&key, data, now, persist); - if replaced { - self.media_epoch.fetch_add(1, Ordering::Relaxed); - } if persist { self.changed(); } } - /// The generation preview cache lookups key on. It changes when [`Self::put_file`] writes - /// a different blob, and it is not a content hash. - pub fn media_epoch(&self) -> Arc { - self.media_epoch.clone() - } - /// Size and content hash of the file under `path`. The hash is stored on the entry so a /// later key does not walk the bytes again. pub fn file_identity(&self, path: &str) -> Option<(u64, u64)> { @@ -541,11 +529,9 @@ mod tests { assert_ne!(a, b); assert_eq!(&data[..], b"blue"); assert_eq!(s.file_versioned("/collision.png").map(|f| f.1), Some(b), "reading doesn't change it"); - let epoch = s.media_epoch().load(Ordering::Relaxed); let id = s.file_identity("/collision.png").expect("identity"); assert_eq!(id, (4, content_hash(b"blue"))); assert_eq!(s.file_identity("/collision.png"), Some(id), "the hash is kept on the entry"); - assert!(epoch >= 2, "each new blob bumps the generation the preview keys on"); } /// A write that failed is flushed again with the key's latest state (#215). diff --git a/apps/effectcraft/src/main.rs b/apps/effectcraft/src/main.rs index 07d327a21..5350addbe 100644 --- a/apps/effectcraft/src/main.rs +++ b/apps/effectcraft/src/main.rs @@ -276,9 +276,6 @@ fn main() -> eframe::Result { // written on background threads (M13.14). session.check_footage_on_open = true; session.autosave.background = true; - // The disk cache's footage stamps too: an imported or opened project with thousands of - // sequence frames on a network share took half a minute to stamp. - session.disk_salt_background = true; // Settings, shortcut presets and the crash-recovery sentinel live in the platform // config directory. Agent-driven runs (`--control`) skip crash recovery. if let Some(dir) = effectcraft_host::config_dir() { diff --git a/crates/automation/Cargo.toml b/crates/automation/Cargo.toml index 916cc3501..e0caf3218 100644 --- a/crates/automation/Cargo.toml +++ b/crates/automation/Cargo.toml @@ -19,3 +19,4 @@ effectcraft-model = { workspace = true } [dev-dependencies] effectcraft-script = { workspace = true } effectcraft-host = { workspace = true } +tempfile = { workspace = true } diff --git a/crates/automation/src/confine.rs b/crates/automation/src/confine.rs index 6d8ce2819..570726932 100644 --- a/crates/automation/src/confine.rs +++ b/crates/automation/src/confine.rs @@ -346,32 +346,60 @@ impl ConfinedFootage { fn inside(&self, f: &Footage) -> bool { std::iter::once(&f.path).chain(&f.sequence).filter(|p| !p.is_empty()).all(|p| self.confinement.check(p, Access::Read).is_ok()) } + + /// [`Self::inside`] for a read: a refused one is counted on this thread, so the render + /// [`recording`](FootageSource::recording) it can't list what it made without the footage. + fn readable(&self, f: &Footage) -> bool { + let inside = self.inside(f); + if !inside { + let _ = REFUSED_READS.try_with(|n| n.set(n.get().wrapping_add(1))); + } + inside + } +} + +thread_local! { + /// Footage reads refused on this thread (see [`ConfinedFootage::readable`]). + static REFUSED_READS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// The number of reads this thread has refused for lying outside the allowed roots. +fn refused_reads() -> u64 { + REFUSED_READS.try_with(std::cell::Cell::get).unwrap_or(0) } impl FootageSource for ConfinedFootage { + /// The frame from the inner source, or `None` when the footage lies outside the allowed roots. fn frame(&self, item: ItemId, footage: &Footage, t: Tick) -> Option> { - self.inside(footage).then(|| self.inner.frame(item, footage, t)).flatten() + self.readable(footage).then(|| self.inner.frame(item, footage, t)).flatten() } + /// The frame scaled to `width` by `height`, or `None` when the footage lies outside the allowed roots. fn frame_at_size(&self, item: ItemId, footage: &Footage, t: Tick, width: u32, height: u32) -> Option> { - self.inside(footage).then(|| self.inner.frame_at_size(item, footage, t, width, height)).flatten() + self.readable(footage).then(|| self.inner.frame_at_size(item, footage, t, width, height)).flatten() } + /// The frame with an explicit size and float curve, or `None` when the footage lies outside the allowed roots. fn frame_with(&self, item: ItemId, footage: &Footage, t: Tick, size: Option<(u32, u32)>, float: FloatCurve) -> Option> { - self.inside(footage).then(|| self.inner.frame_with(item, footage, t, size, float)).flatten() + self.readable(footage).then(|| self.inner.frame_with(item, footage, t, size, float)).flatten() } + /// The footage audio from the inner source, or `None` when the footage lies outside the allowed roots. fn audio(&self, item: ItemId, footage: &Footage, t: Tick, frames: usize, rate: u32) -> Option> { - self.inside(footage).then(|| self.inner.audio(item, footage, t, frames, rate)).flatten() + self.readable(footage).then(|| self.inner.audio(item, footage, t, frames, rate)).flatten() } + /// The auxiliary channels of the footage frame, or `None` when the footage lies outside the allowed roots. fn aux(&self, item: ItemId, footage: &Footage, t: Tick) -> Option> { - self.inside(footage).then(|| self.inner.aux(item, footage, t)).flatten() + self.readable(footage).then(|| self.inner.aux(item, footage, t)).flatten() } + /// Forwards the auxiliary footage paths to the inner source. fn set_aux_footage(&self, paths: &[String]) { self.inner.set_aux_footage(paths) } + /// The 3D model for the footage, or `None` when the footage lies outside the allowed roots. fn model(&self, item: ItemId, footage: &Footage) -> Option> { - self.inside(footage).then(|| self.inner.model(item, footage)).flatten() + self.readable(footage).then(|| self.inner.model(item, footage)).flatten() } + /// The rasterised vector footage at `scale`, or `None` when the footage lies outside the allowed roots. fn vector_frame(&self, item: ItemId, footage: &Footage, scale: f64) -> Option> { - self.inside(footage).then(|| self.inner.vector_frame(item, footage, scale)).flatten() + self.readable(footage).then(|| self.inner.vector_frame(item, footage, scale)).flatten() } /// Says why footage outside the roots shows nothing, so the agent can act on it. fn problem(&self, footage: &Footage) -> Option { @@ -392,15 +420,29 @@ impl FootageSource for ConfinedFootage { fn set_conform_folder(&self, folder: Option) { self.inner.set_conform_folder(folder) } + /// The inner source's cache budget. fn cache_budget(&self) -> Option { self.inner.cache_budget() } + /// Runs `f` under the inner source's cancel flag. fn cancellable(&self, cancel: &Arc, f: &mut dyn FnMut()) { self.inner.cancellable(cancel, f) } + /// Whether the inner source has been called off. fn called_off(&self) -> bool { self.inner.called_off() } + /// The files read inside the roots, as the inner source notes them. Footage outside reads + /// nothing, and what is made without it can't be listed by its files: a refused read makes + /// the list incomplete, so it never outlives the session in a disk cache (another session + /// with other roots would read the footage). + fn recording(&self, reads: &effectcraft_engine::render::reads::ReadLog, f: &mut dyn FnMut()) { + let refused = refused_reads(); + self.inner.recording(reads, f); + if refused_reads() != refused { + reads.mark_incomplete(); + } + } } /// The session's file reads, only inside the read roots: what a project or an imported file @@ -593,6 +635,55 @@ mod tests { } } + /// Footage outside the roots shows nothing: a render that asked for it can't be listed by its + /// files (#3184), or a disk cache would keep the empty picture for a session with other + /// roots. Reads inside the roots record as the inner source tells. + #[test] + fn a_refused_footage_read_makes_the_render_unlisted() { + use effectcraft_engine::render::reads::{FileStamp, ReadFile, ReadLog}; + /// Reads every file, noting it. + struct Noting; + impl FootageSource for Noting { + /// Returns a 1x1 frame and notes the footage path it was asked for. + fn frame(&self, _: ItemId, f: &Footage, _: Tick) -> Option> { + NOTED.with(|n| n.borrow_mut().push(f.path.clone())); + Some(Arc::new(Image::new(1, 1))) + } + /// Runs `f`, then reports every path noted meanwhile to `reads` as a file with a missing stamp. + fn recording(&self, reads: &ReadLog, f: &mut dyn FnMut()) { + f(); + for p in NOTED.with(|n| std::mem::take(&mut *n.borrow_mut())) { + reads.note(ReadFile::new(p, FileStamp::Missing)); + } + } + } + thread_local! { + static NOTED: std::cell::RefCell> = const { std::cell::RefCell::new(Vec::new()) }; + } + // (a fresh directory, removed when the test ends, panicking or not) + let tmp = tempfile::tempdir().unwrap(); + let base = tmp.path(); + let (inside, outside) = (base.join("in"), base.join("elsewhere")); + for d in [&inside, &outside] { + std::fs::create_dir_all(d).unwrap(); + } + let c = Confinement::new(std::slice::from_ref(&inside), &[]).unwrap(); + let src = ConfinedFootage::new(Arc::new(Noting), c); + let footage = |d: &std::path::Path| Footage { path: d.join("a.png").to_string_lossy().into_owned(), ..Default::default() }; + let read = |f: &Footage| { + let log = ReadLog::new(); + let mut got = None; + src.recording(&log, &mut || got = src.frame(ItemId(1), f, Tick::ZERO)); + (got.is_some(), log.into_files()) + }; + let (shown, files) = read(&footage(&inside)); + assert!(shown && files.is_complete() && files.len() == 1, "inside the roots: {files:?}"); + let (shown, files) = read(&footage(&outside)); + assert!(!shown && !files.is_complete(), "outside the roots: {files:?}"); + // The next render on the thread is not affected. + assert!(read(&footage(&inside)).1.is_complete()); + } + #[test] fn relative_and_outside_paths_of_newly_listed_commands_are_refused() { let base = std::env::temp_dir().join(format!("ec-confine-1243-{}", std::process::id())); diff --git a/crates/engine/src/analysis/tracking.rs b/crates/engine/src/analysis/tracking.rs index 221b28602..912a8adfe 100644 --- a/crates/engine/src/analysis/tracking.rs +++ b/crates/engine/src/analysis/tracking.rs @@ -208,7 +208,7 @@ pub(crate) fn source_frame( t: Tick, expr: Option<&dyn ExprHost>, ) -> Option<(Arc, [f64; 2])> { - let ctx = EvalCtx { project, comp_id: cid, comp, time: t, expr, footage: None, property_overrides: &[], media_overrides: &[] }; + let ctx = EvalCtx { project, comp_id: cid, comp, time: t, expr, footage: None, property_overrides: &[], media_overrides: &[], reads: None }; if let effectcraft_project::LayerSource::Footage { item } = &layer.source && let Some(effectcraft_project::ItemKind::Footage(f)) = project.item(*item).map(|i| &i.kind) && f.has_video diff --git a/crates/engine/src/background/remote.rs b/crates/engine/src/background/remote.rs index 27f9396e1..aea210ec5 100644 --- a/crates/engine/src/background/remote.rs +++ b/crates/engine/src/background/remote.rs @@ -20,13 +20,16 @@ //! calls [`FrameServer::resume`] for the next. Backend Auto picks CPU or GPU per comp from //! the frames' total times ([`effectcraft_render::AutoPick`]). //! - Disk cache: a render request may carry the frame's disk-cache key ([`FrameMsg::Render`] -//! `disk`); the transport stores the finished frame under it (the browser: in the Origin -//! Private File System) and reports [`FrameReply::Stored`]. +//! `disk`); the transport stores the finished frame under it with the source files it read +//! ([`FrameServer::take_files`], `disk_cache::frame_entry`; the browser: in the Origin Private +//! File System) and reports [`FrameReply::Stored`]. A frame whose files can't all be named is +//! not stored. The page checks an entry's files before it uses it (#3184). //! - Layer buffers on disk: with `layers`, the server's layer cache is backed by a //! [`PrefetchStore`] ([`FrameServer::set_layer_store`]): before the request the transport //! fetches the entries named in `prefetch` (recent misses that are on disk, chosen by the -//! page, `disk_cache::LayerPrefetch`), so the lookups in the middle of the render find them; -//! the reply lists the layer keys that missed and those served from the store +//! page, `disk_cache::LayerPrefetch`), so the lookups in the middle of the render find them +//! (each entry keeps the source files its buffer was made of and is used only while they are +//! unchanged, #3184); the reply lists the layer keys that missed and those served from the store //! ([`FrameReply::Frame`] `layer_misses` / `layer_hits`), and slow buffers queue up for the //! transport to write after the frame ([`PrefetchStore::take_writes`], reported as //! [`FrameReply::Stored`] with `layer`). @@ -37,6 +40,7 @@ use std::sync::Arc; use effectcraft_project::{ItemId, Project}; +use effectcraft_render::reads::{ReadFiles, ReadLog}; use effectcraft_render::{Accelerator, AutoKey, Backend, ExprHost, FootageSource, Image, LayerCache, LayerStore, PrefetchStore, RenderOpts, Renderer}; use effectcraft_time::Tick; use serde::{Deserialize, Serialize}; @@ -177,7 +181,7 @@ pub enum FrameReply { passes: u32, #[serde(default)] gpu: bool, - /// Layer-cache lookups that missed the store (salted keys, 32 hex digits). + /// Layer-cache lookups that missed the store (disk keys, 32 hex digits). #[serde(default, rename = "layerMisses", skip_serializing_if = "Vec::is_empty")] layer_misses: Vec, /// Layer buffers served from the store (fetched from disk). @@ -260,11 +264,12 @@ pub struct FrameServer { revision: Option, /// The frame being rendered in passes. pending: Option, - /// The disk cache's layer buffers (see the module docs) and the project's salt. + /// The disk cache's layer buffers (see the module docs). layer_store: Option>, - salt: u64, /// Size and content hash for footage paths with no native metadata (the browser file table). virtual_id: Option Option<(u64, u64)> + Send + Sync>>, + /// The source files the last finished frame read ([`FrameServer::take_files`]). + files: Option, } /// A frame whose readbacks are in flight. @@ -284,6 +289,7 @@ struct Pending { pub const MAX_PASSES: u32 = 24; impl FrameServer { + /// A frame server over `footage` and the optional expression host, with an empty layer cache. pub fn new(footage: Arc, expr: Option>) -> FrameServer { FrameServer { footage, @@ -295,17 +301,30 @@ impl FrameServer { revision: None, pending: None, layer_store: None, - salt: 0, virtual_id: None, + files: None, } } - /// Identity of virtual footage files, used when native metadata cannot describe the path. - /// Called from `FrameServer::load`, not from the UI thread's cache lookup. + /// Identity of virtual footage files, used when native metadata cannot describe the path: + /// what the disk entries of frames and layer buffers keep for them and are checked against. pub fn set_virtual_id(&mut self, id: Option Option<(u64, u64)> + Send + Sync>>) { + self.cache.set_virtual_id(id.clone()); self.virtual_id = id; } + /// The source files the frame of the last [`FrameReply::Frame`] read, with their identities + /// as read: what its disk entry keeps (`disk_cache::frame_entry`). Taken once. + pub fn take_files(&mut self) -> Option { + self.files.take() + } + + /// The identity of footage paths with no native metadata (the browser file table), to store + /// with a frame's disk entry. + pub fn virtual_id(&self) -> Option<&Arc Option<(u64, u64)> + Send + Sync>> { + self.virtual_id.as_ref() + } + /// The store behind the layer cache when a request asks for `layers` (the browser: the /// disk cache's layer buffers, fetched before the request). pub fn set_layer_store(&mut self, store: Option>) { @@ -316,11 +335,6 @@ impl FrameServer { self.layer_store.as_ref() } - /// The salt of the replica's layer keys on disk (keys are `(salt, key)`). - pub fn salt(&self) -> u64 { - self.salt - } - /// Render with `accel` when the request's backend asks for it (the worker's GPU). Its miss /// gate keeps placeholder buffers of unfinished passes out of the layer cache. pub fn set_accel(&mut self, accel: Option>) { @@ -347,8 +361,6 @@ impl FrameServer { fn load(&mut self, revision: u64) -> Result<(), String> { let p = Project::from_json(&self.doc.to_string()).map_err(|e| e.to_string())?; - self.salt = effectcraft_render::disk_cache::footage_salt_with(&p, self.virtual_id.as_deref()); - self.cache.set_store_salt(self.salt); self.project = Some(Arc::new(p)); self.revision = Some(revision); Ok(()) @@ -392,7 +404,7 @@ impl FrameServer { } FrameMsg::Render { id, revision, comp, time, opts, layers, .. } => { let store = self.layer_store.clone().filter(|_| layers); - self.cache.set_store(store.map(|s| (s as Arc, self.salt))); + self.cache.set_store(store.map(|s| s as Arc)); let fail = |error: String, stale: bool| vec![(FrameReply::Failed { id, error, stale }, None)]; if self.revision != Some(revision) { return fail(format!("the replica is at {:?}, not {revision}", self.revision), true); @@ -432,12 +444,16 @@ impl FrameServer { /// Run the next pass of the frame in progress; its reply once it is done. pub fn resume(&mut self) -> Vec<(FrameReply, Option>)> { let Some(mut pr) = self.pending.take() else { return vec![] }; + self.files = None; pr.passes += 1; let accel = self.accel.clone().filter(|_| pr.opts.backend != Backend::Cpu); let give_up = pr.passes > MAX_PASSES; + // (each pass renders the whole frame: the last one's files are the frame's) + let reads = ReadLog::new(); let mut r = Renderer::new(&pr.project, self.footage.as_ref(), pr.opts); r.expr = self.expr.as_deref(); r.cache = Some(&self.cache); + r.reads = Some(&reads); if !give_up { r.accel = accel.as_deref(); } @@ -451,6 +467,7 @@ impl FrameServer { } let ms = pr.t0.elapsed().as_secs_f64() * 1000.0; let gpu = r.accel.is_some() && r.active_accel().is_some(); + self.files = Some(reads.files()); let hex = |v: Vec| v.into_iter().map(|k| format!("{k:032x}")).collect::>(); let (layer_misses, layer_hits) = match &self.layer_store { Some(st) => (hex(st.take_misses()), hex(st.take_hits())), diff --git a/crates/engine/src/background/remote/tests.rs b/crates/engine/src/background/remote/tests.rs index e2db10b8e..e6d797f9d 100644 --- a/crates/engine/src/background/remote/tests.rs +++ b/crates/engine/src/background/remote/tests.rs @@ -69,7 +69,8 @@ fn layer_buffers_go_through_the_disk_store() { assert!(!layer_misses.is_empty() && layer_hits.is_empty()); let writes = store_a.take_writes(); assert!(!writes.is_empty()); - assert!(writes.iter().all(|(k, _)| (*k >> 64) as u64 == a.salt()), "keys are salted per project"); + // Sealed with the files each buffer was made of (none here: the demo reads no footage). + assert!(writes.iter().all(|(_, e)| effectcraft_render::disk_cache::read_layer_entry(e).is_some_and(|(_, f)| f.is_empty()))); let mut index = DiskIndex::default(); let mut disk = std::collections::HashMap::new(); for (k, e) in writes { @@ -375,3 +376,138 @@ fn every_frame_begin_has_a_frame_end() { assert!(matches!(w.handle(req(6, s.revision, comp, cpu))[0].0, FrameReply::Frame { id: 6, .. })); assert_eq!(load(), (3, 3)); } + +/// Footage that reads one file from memory (the browser's file table) for every frame. +struct OneVirtualFile { + /// Tell which files it reads (else every render's list is incomplete). + records: bool, +} + +impl FootageSource for OneVirtualFile { + fn frame(&self, _: ItemId, _: &effectcraft_project::Footage, _: Tick) -> Option> { + Some(Arc::new(Image::filled(4, 4, [1.0, 0.5, 0.0, 1.0]))) + } + fn recording(&self, reads: &ReadLog, f: &mut dyn FnMut()) { + if self.records { + reads.note(effectcraft_render::reads::ReadFile::new("/clip.png", effectcraft_render::reads::FileStamp::Virtual)); + } else { + reads.mark_incomplete(); + } + f() + } +} + +/// The worker hands the transport the files each frame read, so its disk entry keeps them; the +/// page reads the entry back only while those files are unchanged. A frame whose files can't +/// all be named is not stored (#3184). +#[test] +fn the_worker_reports_the_files_of_each_frame_for_its_disk_entry() { + use effectcraft_project::{Comp, Footage, ItemKind, LayerSource, Project, build}; + use effectcraft_render::disk_cache::{frame_entry, read_frame_entry}; + use effectcraft_time::FrameRate; + let mut p = Project::default(); + let f = Footage { path: "/clip.png".into(), width: 4, height: 4, duration: Tick::from_seconds_f64(1.0), has_video: true, ..Default::default() }; + let fid = p.add_item("clip.png", effectcraft_color::Label::None, None, ItemKind::Footage(f)); + let mut comp = Comp::new(4, 4, FrameRate::FPS_30, Tick::from_seconds_f64(1.0)); + comp.layers = vec![build::layer(&mut p, &comp, "clip", LayerSource::Footage { item: fid }, (4, 4), None)].into(); + let cid = p.add_item("C", effectcraft_color::Label::None, None, ItemKind::Comp(comp.into())); + let id = |mark: u64| move |path: &str| (path == "/clip.png").then_some((10, mark)); + let (one, two) = (id(1), id(2)); + for records in [true, false] { + let mut w = FrameServer::new(Arc::new(OneVirtualFile { records }), None); + w.set_virtual_id(Some(Arc::new(one))); + let mut m = Mirror::default(); + assert!(w.handle(round(&m.sync(1, &p).unwrap())).is_empty()); + assert!(w.take_files().is_none(), "no frame yet"); + let out = w.handle(round(&FrameMsg::Render { + id: 1, + revision: 1, + comp: cid, + time: Tick::ZERO, + opts: Box::default(), + disk: Some(format!("{:032x}", 5u128)), + layers: false, + prefetch: vec![], + })); + let (FrameReply::Frame { width, height, .. }, Some(px)) = &out[0] else { panic!("{:?}", out[0].0) }; + let files = w.take_files().expect("the frame's files"); + assert!(w.take_files().is_none(), "taken once"); + let vid = w.virtual_id().cloned(); + let entry = frame_entry(*width, *height, px, &files, vid.as_deref()); + if !records { + assert!(!files.is_complete() && entry.is_none(), "an incomplete list is not stored"); + continue; + } + assert_eq!(files.files().iter().map(|f| &*f.path).collect::>(), ["/clip.png"]); + let entry = entry.expect("stored"); + assert_eq!(read_frame_entry(&entry, Some(&one)).map(|f| f.rgba), Some(px.clone())); + assert!(read_frame_entry(&entry, Some(&two)).is_none(), "the file was replaced: a miss"); + } +} + +/// No salt work at all (#3184, replacing the background salt of #3106): syncing a project with a +/// large image sequence nobody shows, patching it and rendering with the layer store never asks +/// the file hook about the sequence (the salt asked about every file at every sync). Only the +/// file the rendered buffer reads is asked about: to store its entry and, in another worker, to +/// check it before the buffer from the store is used. +#[test] +fn the_worker_asks_only_about_the_files_its_buffers_read() { + use effectcraft_project::{Comp, Footage, FootageKind, ItemKind, LayerSource, Project, build}; + use effectcraft_time::FrameRate; + use std::sync::Mutex; + let mut p = Project::default(); + let f = Footage { path: "/clip.png".into(), width: 4, height: 4, has_video: true, ..Default::default() }; + let fid = p.add_item("clip.png", effectcraft_color::Label::None, None, ItemKind::Footage(f)); + let seq = Footage { + kind: FootageKind::Sequence, + path: "/seq/f_00000.png".into(), + sequence: (0..5000).map(|i| format!("/seq/f_{i:05}.png")).collect(), + width: 4, + height: 4, + has_video: true, + ..Default::default() + }; + p.add_item("seq", effectcraft_color::Label::None, None, ItemKind::Footage(seq)); + let mut comp = Comp::new(4, 4, FrameRate::FPS_30, Tick::from_seconds_f64(1.0)); + comp.layers = vec![build::layer(&mut p, &comp, "clip", LayerSource::Footage { item: fid }, (4, 4), None)].into(); + let cid = p.add_item("C", effectcraft_color::Label::None, None, ItemKind::Comp(comp.into())); + let asked: Arc>> = Arc::default(); + let worker = || { + let mut w = FrameServer::new(Arc::new(OneVirtualFile { records: true }), None); + let seen = asked.clone(); + w.set_virtual_id(Some(Arc::new(move |path: &str| { + seen.lock().unwrap().push(path.to_string()); + (path == "/clip.png").then_some((10, 1)) + }))); + let store = Arc::new(PrefetchStore::new(1 << 20).with_min_ms(0)); + w.set_layer_store(Some(store.clone())); + (w, store) + }; + let render = |w: &mut FrameServer, revision: u64, prefetch: Vec| { + let out = w.handle(round(&FrameMsg::Render { id: 1, revision, comp: cid, time: Tick::ZERO, opts: Box::default(), disk: None, layers: true, prefetch })); + let FrameReply::Frame { layer_hits, .. } = &out[0].0 else { panic!("{:?}", out[0].0) }; + layer_hits.len() + }; + // Worker A: synced, patched, rendered; its buffer is queued with its file. + let (mut a, store_a) = worker(); + let mut m = Mirror::default(); + assert!(a.handle(round(&m.sync(1, &p).unwrap())).is_empty()); + let mut edited = p.clone(); + edited.item_mut(cid).unwrap().name = "Renamed".into(); + assert!(a.handle(round(&m.sync(2, &edited).unwrap())).is_empty()); + assert!(asked.lock().unwrap().is_empty(), "syncing looks at no file"); + assert_eq!(render(&mut a, 2, vec![]), 0); + let writes = store_a.take_writes(); + assert!(!writes.is_empty(), "the clip's buffer is stored"); + // Worker B: fetched before its frame, checked, used. + let (mut b, store_b) = worker(); + let mut m = Mirror::default(); + assert!(b.handle(round(&m.sync(2, &edited).unwrap())).is_empty()); + for (k, e) in &writes { + assert!(store_b.provide(*k, e)); + } + assert!(render(&mut b, 2, writes.iter().map(|(k, _)| format!("{k:032x}")).collect()) > 0, "served from the store"); + let asked = asked.lock().unwrap(); + assert!(!asked.is_empty(), "the hook names the buffer's file"); + assert!(asked.iter().all(|p| p == "/clip.png"), "only the file the buffer read: {:?}", &asked[..asked.len().min(5)]); +} diff --git a/crates/engine/src/cmd/effect.rs b/crates/engine/src/cmd/effect.rs index 69bdb5a4a..1d352d192 100644 --- a/crates/engine/src/cmd/effect.rs +++ b/crates/engine/src/cmd/effect.rs @@ -345,6 +345,7 @@ fn warning(s: &mut Session, p: &Value) -> Result { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; Ok(json!({"effect": uid, "warning": effectcraft_effects::warning(g, &mut |pr| ctx.value(layer, pr))})) } @@ -378,6 +379,7 @@ fn pick_color(s: &mut Session, p: &Value) -> Result { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let mut r = effectcraft_render::Renderer::new(&s.project, &*s.footage, effectcraft_render::RenderOpts::default()); r.expr = s.expr.as_deref(); @@ -515,6 +517,7 @@ impl CryptoProbe { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let params = effectcraft_effects::flatten_params(g, &mut |pr| ctx.value(layer, pr)); let aux = r.layer_aux(&ctx, layer).ok_or(NO_CRYPTO)?; @@ -586,6 +589,7 @@ fn probe_key<'a>(s: &'a Session, p: &Value, cmd: &str) -> Result<(ProbeKey, Tick footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let frame = probe_frame(&ctx, layer, pos); let o = s.render_opts(Default::default()); @@ -780,6 +784,7 @@ fn crypto_hit(s: &Session, p: &Value, cmd: &str) -> Result { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let selection = effectcraft_effects::flatten_params(g, &mut |pr| ctx.value(layer, pr)).s("selection").to_string(); let driven = prop.expr.as_ref().is_some_and(|e| e.enabled); diff --git a/crates/engine/src/cmd/layer/parent.rs b/crates/engine/src/cmd/layer/parent.rs index 3611ef047..cd923c950 100644 --- a/crates/engine/src/cmd/layer/parent.rs +++ b/crates/engine/src/cmd/layer/parent.rs @@ -249,6 +249,7 @@ pub(crate) fn parent_fixes(s: &Session, cid: ItemId, ids: &[LayerId], parent: Op footage: Some(s.footage.as_ref()), property_overrides: &[], media_overrides: &[], + reads: None, }; let space = |id: Option| -> effectcraft_geom::Mat3 { id.and_then(|i| comp.layer(i)).filter(|l| !l.is_3d()).map(|l| ectx.layer_to_comp(l).0).unwrap_or(effectcraft_geom::Mat3::IDENTITY) diff --git a/crates/engine/src/cmd/layer_time.rs b/crates/engine/src/cmd/layer_time.rs index 4ecf725ec..2f8661885 100644 --- a/crates/engine/src/cmd/layer_time.rs +++ b/crates/engine/src/cmd/layer_time.rs @@ -194,6 +194,7 @@ fn freeze(s: &mut Session, p: &Value, last: bool) -> Result { footage: Some(s.footage.as_ref()), property_overrides: &[], media_overrides: &[], + reads: None, }; let now: Vec<(effectcraft_project::LayerId, f64)> = comp .layers diff --git a/crates/engine/src/cmd/path_nulls.rs b/crates/engine/src/cmd/path_nulls.rs index 93d71cd67..6da43afde 100644 --- a/crates/engine/src/cmd/path_nulls.rs +++ b/crates/engine/src/cmd/path_nulls.rs @@ -73,6 +73,8 @@ struct PathInfo { span: (f64, f64), } +/// Reads a mask or shape path at the current time and returns its comp-space vertices, value, expression reference and layer name. +/// Errors when the property is missing, is not a path or has no vertices. fn info(s: &Session, cid: ItemId, lid: LayerId, uid: Uid, cmd: &str) -> Result { let comp = s.project.comp(cid).ok_or(EngineError::NoComp)?; let layer = comp.layer(lid).ok_or(EngineError::NoComp)?; @@ -87,6 +89,7 @@ fn info(s: &Session, cid: ItemId, lid: LayerId, uid: Uid, cmd: &str) -> Result

Result Result { convert_one_expr(s, cid, lid, uid) } +/// Replaces the expression on one property with keyframes sampled from its evaluated values. +/// Returns the number of properties converted. fn convert_one_expr(s: &mut Session, cid: ItemId, lid: LayerId, uid: Uid) -> Result { let comp = s.project.comp(cid).ok_or(EngineError::NoComp)?.clone(); let layer = comp.layer(lid).ok_or(EngineError::NoComp)?.clone(); @@ -1397,6 +1399,7 @@ fn convert_one_expr(s: &mut Session, cid: ItemId, lid: LayerId, uid: Uid) -> Res footage: Some(s.footage.as_ref()), property_overrides: &[], media_overrides: &[], + reads: None, }; keys.push(Keyframe::new(layer.layer_time(t), ctx.value(&layer, &pr))); t += fd; diff --git a/crates/engine/src/cmd/puppet.rs b/crates/engine/src/cmd/puppet.rs index d894516c2..bd20bd885 100644 --- a/crates/engine/src/cmd/puppet.rs +++ b/crates/engine/src/cmd/puppet.rs @@ -39,8 +39,17 @@ pub fn puppet_eval(s: &Session, cid: ItemId, lid: LayerId, fx_uid: Uid, t: Tick) let fx = layer.effects()?; let index = fx.groups().position(|g| g.uid == fx_uid)?; let g = fx.groups().nth(index)?; - let ctx = - EvalCtx { project: &s.project, comp_id: cid, comp, time: t, expr: s.expr.as_deref(), footage: None, property_overrides: &[], media_overrides: &[] }; + let ctx = EvalCtx { + project: &s.project, + comp_id: cid, + comp, + time: t, + expr: s.expr.as_deref(), + footage: None, + property_overrides: &[], + media_overrides: &[], + reads: None, + }; let mut r = Renderer::new(&s.project, &*s.footage, RenderOpts::default()); r.expr = s.expr.as_deref(); r.cache = Some(&s.layer_cache); diff --git a/crates/engine/src/cmd/rig3d.rs b/crates/engine/src/cmd/rig3d.rs index dbcaa3c3c..58a4281a8 100644 --- a/crates/engine/src/cmd/rig3d.rs +++ b/crates/engine/src/cmd/rig3d.rs @@ -47,6 +47,7 @@ impl Env { fn of(s: &Session, cid: ItemId) -> Env { Env { time: s.time_of(cid), expr: s.expr.clone(), footage: s.footage.clone() } } + /// The evaluation context of `comp` in `proj` at the session's current time. fn ctx<'a>(&'a self, proj: &'a Project, cid: ItemId, comp: &'a Comp) -> EvalCtx<'a> { EvalCtx { project: proj, @@ -57,6 +58,7 @@ impl Env { footage: Some(self.footage.as_ref()), property_overrides: &[], media_overrides: &[], + reads: None, } } } diff --git a/crates/engine/src/cmd/three_d.rs b/crates/engine/src/cmd/three_d.rs index 009a33b2e..3355b68e3 100644 --- a/crates/engine/src/cmd/three_d.rs +++ b/crates/engine/src/cmd/three_d.rs @@ -418,14 +418,24 @@ fn set_view_camera(s: &mut Session, p: &Value) -> Result { Ok(json!({"view": v.id()})) } +/// Returns the active comp's 3D view state, with the comp size, for the 3D view commands. fn get_3d(s: &mut Session, p: &Value) -> Result { let cid = comp_id(s, p)?; let comp = s.project.comp(cid).ok_or(EngineError::NoComp)?; let (w, h) = (comp.width as f64, comp.height as f64); let vs = s.state.views3d.get(&cid).cloned().unwrap_or_default(); let t = s.state.times.get(&cid).copied().unwrap_or(Tick::ZERO); - let ctx = - EvalCtx { project: &s.project, comp_id: cid, comp, time: t, expr: s.expr.as_deref(), footage: None, property_overrides: &[], media_overrides: &[] }; + let ctx = EvalCtx { + project: &s.project, + comp_id: cid, + comp, + time: t, + expr: s.expr.as_deref(), + footage: None, + property_overrides: &[], + media_overrides: &[], + reads: None, + }; let cam = vs.override_camera(w, h).unwrap_or_else(|| camera::active_camera(&ctx)); let f = cam.forward(); let lights: Vec = comp @@ -567,8 +577,17 @@ fn auto_orient(s: &mut Session, p: &Value) -> Result { /// through each layer's world matrix; cameras and lights contribute their position). fn layer_points(s: &Session, cid: ItemId, ids: &[LayerId], t: Tick) -> Vec { let Some(comp) = s.project.comp(cid) else { return vec![] }; - let ctx = - EvalCtx { project: &s.project, comp_id: cid, comp, time: t, expr: s.expr.as_deref(), footage: None, property_overrides: &[], media_overrides: &[] }; + let ctx = EvalCtx { + project: &s.project, + comp_id: cid, + comp, + time: t, + expr: s.expr.as_deref(), + footage: None, + property_overrides: &[], + media_overrides: &[], + reads: None, + }; let mut out = vec![]; for l in comp.layers.iter().filter(|l| ids.contains(&l.id)) { let m = ctx.world_matrix(l); diff --git a/crates/engine/src/footage/availability.rs b/crates/engine/src/footage/availability.rs index 7ad2bc03f..75e2a1e1c 100644 --- a/crates/engine/src/footage/availability.rs +++ b/crates/engine/src/footage/availability.rs @@ -215,20 +215,18 @@ impl Scanner { } } -/// A disk observation prepared entirely by the existing worker, including the potentially -/// expensive sequence stamps used for disk-cache keys. The UI only swaps a current snapshot. +/// A disk observation prepared entirely by the existing worker. The UI only swaps a current +/// snapshot (the disk cache needs nothing: its entries check their own files when read, #3184). pub(crate) struct Update { before: Arc, after: Arc, paths: BTreeSet, newly_missing: usize, - cache_enabled: bool, - salt: Option<(u64, u64)>, } -/// Prepare a replacement only when availability changed. Project cloning and optional disk -/// salt computation belong on the worker; apply later rejects an outdated project snapshot. -pub(crate) fn prepare(project: &Arc, sources: &[Source], missing: &[bool], cache_enabled: bool) -> Option { +/// Prepare a replacement only when availability changed. Project cloning belongs on the +/// worker; apply later rejects an outdated project snapshot. +pub(crate) fn prepare(project: &Arc, sources: &[Source], missing: &[bool]) -> Option { let mut after = project.clone(); let mut paths = BTreeSet::new(); let mut newly_missing = 0; @@ -245,22 +243,17 @@ pub(crate) fn prepare(project: &Arc, sources: &[Source], missing: &[boo if paths.is_empty() { return None; } - let salt = cache_enabled.then(|| (Session::footage_fingerprint(&after), crate::render::disk_cache::footage_salt(&after))); - Some(Update { before: project.clone(), after, paths, newly_missing, cache_enabled, salt }) + Some(Update { before: project.clone(), after, paths, newly_missing }) } impl Update { - /// False means a newer project or cache configuration needs a fresh observation. + /// False means a newer project needs a fresh observation. pub fn apply(self, s: &mut Session) -> bool { - if !Arc::ptr_eq(&s.project, &self.before) || s.disk_cache.is_some() != self.cache_enabled { + if !Arc::ptr_eq(&s.project, &self.before) { return false; } let dirty = s.is_dirty(); s.project = self.after; - if let Some((fingerprint, salt)) = self.salt { - s.disk_salt = Some((fingerprint, salt)); - s.layer_cache.set_disk_salt(salt); - } s.bump(); if !dirty { s.mark_saved(); @@ -371,7 +364,7 @@ mod tests { fn stale_observation_cannot_mark_a_replacement_missing() { let (mut s, id) = session(Arc::new(Disk::default())); let old = sources(&s); - let update = prepare(&s.project, &old, &[true, true], false).unwrap(); + let update = prepare(&s.project, &old, &[true, true]).unwrap(); if let ItemKind::Footage(f) = &mut Arc::make_mut(&mut s.project).item_mut(id).unwrap().kind { f.path = "/new.png".into(); } @@ -398,9 +391,12 @@ mod tests { assert_eq!(disk.looks.load(Ordering::Relaxed), 2, "one file per source, no scan of an unmounted folder"); } + /// An availability change does no disk-cache work (#3184): the cache stays attached and + /// no file is looked at for it, on the worker or when the UI applies the observation (it + /// used to stamp every footage file for a new layer salt). #[test] - fn applying_prepared_cache_salt_does_not_restat_files_on_the_ui_thread() { - let dir = std::env::temp_dir().join(format!("ec-availability-salt-{}", std::process::id())); + fn applying_an_availability_change_does_no_disk_cache_work() { + let dir = std::env::temp_dir().join(format!("ec-availability-cache-{}", std::process::id())); std::fs::create_dir_all(&dir).unwrap(); let file = dir.join("plate.png"); std::fs::write(&file, b"plate").unwrap(); @@ -413,16 +409,13 @@ mod tests { ); let cache = crate::render::disk_cache::DiskCache::open(dir.join("cache"), 1 << 20).unwrap(); s.disk_cache = Some(cache.clone()); - s.layer_cache.set_disk(Some((cache, 0))); + s.layer_cache.set_disk(Some(cache.clone())); s.mark_saved(); - let update = prepare(&s.project, &sources(&s), &[false], true).unwrap(); - let expected = update.salt.unwrap().1; - // The filesystem can change again after the worker's observation. Applying it must - // retain that observation's salt, rather than scan the disk a second time on the UI. + let update = prepare(&s.project, &sources(&s), &[false]).unwrap(); std::fs::remove_file(file).unwrap(); - assert_ne!(crate::render::disk_cache::footage_salt(&update.after), expected); assert!(update.apply(&mut s)); - assert_eq!(s.disk_salt.map(|(_, salt)| salt), Some(expected)); + assert!(s.layer_cache.disk().is_some_and(|d| Arc::ptr_eq(&d, &cache)), "still attached"); + assert_eq!(cache.file_checks(), 0, "no file looked at for the disk cache"); assert!(!s.is_dirty()); drop(s); std::fs::remove_dir_all(dir).unwrap(); diff --git a/crates/engine/src/footage/footage_check.rs b/crates/engine/src/footage/footage_check.rs index 9e941a6ed..42401d195 100644 --- a/crates/engine/src/footage/footage_check.rs +++ b/crates/engine/src/footage/footage_check.rs @@ -272,7 +272,7 @@ mod tests { let id = source.id; let mut recovered = source.footage.clone(); recovered.path = "/new/project/plate.png".into(); - let observed = super::super::availability::prepare(&s.project, std::slice::from_ref(&source), &[true], false).unwrap(); + let observed = super::super::availability::prepare(&s.project, std::slice::from_ref(&source), &[true]).unwrap(); assert!(observed.apply(&mut s)); assert!(matches!(&s.project.item(id).unwrap().kind, ItemKind::Footage(f) if f.missing)); let result = apply(&mut s, vec![(source, Found::Moved(Box::new(recovered)))]); diff --git a/crates/engine/src/footage/footage_reload.rs b/crates/engine/src/footage/footage_reload.rs index 7065620af..e56e16a96 100644 --- a/crates/engine/src/footage/footage_reload.rs +++ b/crates/engine/src/footage/footage_reload.rs @@ -6,7 +6,8 @@ //! or PDF page an item shows and its interpretation (alpha, conformed frame rate, pixel aspect, //! fields, colour). A Photoshop layer is found again by name when layers were added or removed //! around it. The media layer then forgets the file and the layer cache is emptied, so the next -//! render reads the new pixels. +//! render reads the new pixels; File ▸ Reload Footage also deletes the disk cache entries made of +//! the file (#3184). //! //! The automatic part compares each footage file's size and modification time with what they //! were when the file was last seen. The desktop app keeps a [`Watcher`]: a worker thread that @@ -76,7 +77,6 @@ pub struct Watched { reload: BTreeSet, sources: Arc>, project: Option>, - cache_enabled: bool, reload_mode: String, stored_paths: crate::doc_path::StoredPaths, } @@ -85,8 +85,7 @@ impl PartialEq for Watched { /// Compare watched inputs, excluding unrelated project edits whose latest Arc is refreshed /// separately without waking the worker or restarting partial sequence scans. fn eq(&self, other: &Self) -> bool { - self.cache_enabled == other.cache_enabled - && self.stored_paths == other.stored_paths + self.stored_paths == other.stored_paths && self.reload_mode == other.reload_mode && self.reload == other.reload && (Arc::ptr_eq(&self.sources, &other.sources) || self.sources == other.sources) @@ -100,7 +99,6 @@ pub fn watched(s: &Session) -> Watched { reload: automatic_paths(s), sources: Arc::new(if s.check_footage_on_open { availability::sources(s) } else { Vec::new() }), project: Some(s.project.clone()), - cache_enabled: s.disk_cache.is_some(), reload_mode: s.prefs.import.auto_reload_footage.clone(), stored_paths: s.stored_paths.clone(), } @@ -139,10 +137,10 @@ pub struct Scan { } impl Scan { - /// Prepare availability and cache state before the session applies the observation. + /// Prepare the availability change before the session applies the observation. /// Automatic callers construct this result on the worker; explicit commands run inline. fn new(watched: Watched, observation: Observation, policy: ReloadPolicy) -> Self { - let update = watched.project.as_ref().and_then(|p| availability::prepare(p, &watched.sources, &observation.missing, watched.cache_enabled)); + let update = watched.project.as_ref().and_then(|p| availability::prepare(p, &watched.sources, &observation.missing)); Self { watched, observation, update, policy } } @@ -281,7 +279,17 @@ fn reload(s: &mut Session, ids: &[ItemId], undoable: bool) -> crate::Result<(usi } let n = updates.len(); apply_reloads(s, updates, undoable)?; - forget(s, &paths); + forget_media(s, &paths); + // An explicit reload also reads files again that kept their size and time (the check on hit + // can't tell those apart): their entries in the disk cache go (#3184), when the cache is + // switched on if it is off now. An automatic one only follows a changed stamp, which the + // check catches. + if undoable { + match &s.disk_cache { + Some(dc) => dc.drop_files(paths.iter().map(String::as_str)), + None => s.pending_disk_drops.extend(paths), + } + } Ok((n, failed)) } @@ -320,14 +328,9 @@ fn apply_reloads(s: &mut Session, updates: Vec<(ItemId, Footage)>, undoable: boo Ok(()) } -/// Make the media layer and the layer cache let go of `paths`, so renders read them again. -fn forget(s: &mut Session, paths: &BTreeSet) { - forget_media(s, paths); - s.refresh_disk_salt(true); -} - -/// Invalidate decoded and rendered buffers without probing the disk for a new salt. -/// Availability updates already carry their worker-computed salt; content reload refreshes it. +/// Make the media layer and the layer cache let go of `paths`, so renders read them again. Disk +/// cache entries check the files they were made of when read (#3184); File ▸ Reload Footage +/// also drops the entries of its files ([`reload`]). pub(crate) fn forget_media(s: &mut Session, paths: &BTreeSet) { for p in paths { s.footage.forget(p); @@ -374,7 +377,7 @@ pub fn apply_stamps(s: &mut Session, now: Vec<(String, Option)>) -> crate return Ok(json!({"files": 0, "reloaded": 0})); } // Changed frames of image sequences (their items keep their metadata). - forget(s, &changed); + forget_media(s, &changed); let files = changed.len(); s.toast(if reloaded > 0 { format!("Reloaded {reloaded} footage item(s) changed on disk") @@ -391,7 +394,6 @@ pub(crate) fn command(s: &mut Session, _: &Value) -> crate::Result { reload: reload_paths(s), sources: Arc::new(availability::sources(s)), project: Some(s.project.clone()), - cache_enabled: s.disk_cache.is_some(), reload_mode: s.prefs.import.auto_reload_footage.clone(), stored_paths: s.stored_paths.clone(), }; @@ -452,12 +454,7 @@ impl Watcher { pub fn update(&mut self, s: &Session) { let same_sources = availability::sources_match(s, &self.paths.sources); let same_data = self.paths.project.as_ref().is_some_and(|before| data_paths(before).eq(data_paths(&s.project))); - if same_sources - && same_data - && self.paths.stored_paths == s.stored_paths - && self.paths.reload_mode == s.prefs.import.auto_reload_footage - && self.paths.cache_enabled == s.disk_cache.is_some() - { + if same_sources && same_data && self.paths.stored_paths == s.stored_paths && self.paths.reload_mode == s.prefs.import.auto_reload_footage { let project = Some(s.project.clone()); self.paths.project = project.clone(); self.pending.lock().unwrap_or_else(PoisonError::into_inner).paths.project = project; diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index e50b15d04..599aba1b7 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -97,7 +97,7 @@ pub use error::{EngineError, Result}; pub use event::Event; pub use fonts::{FontRow, font_features, font_menu, font_preview, font_styles, text_families}; pub use services::{FsServices, Importer, Services}; -pub use session::{DiskSaltJob, upgrade_effects}; +pub use session::upgrade_effects; pub struct Session { pub project: Arc, @@ -171,6 +171,9 @@ pub struct Session { pub crypto_probe: Arc>, /// The persistent disk cache (Settings ▸ Media & Disk Cache), when enabled. pub disk_cache: Option>, + /// Files File ▸ Reload Footage reloaded while the disk cache was off: their entries are + /// dropped when it is switched on ([`Session::configure_disk_cache`]), before it is used. + pub pending_disk_drops: std::collections::BTreeSet, /// Settings (Preferences). pub prefs: prefs::Prefs, /// Bumped whenever settings change (frontends re-apply theme, labels…). @@ -254,14 +257,6 @@ pub struct Session { /// Each footage file's size and modification time when last seen (Settings ▸ Import ▸ /// Reload Footage Changed on Disk, [`footage_reload`]). pub footage_stamps: std::collections::HashMap, - /// The disk cache's footage salt and the footage it was taken for ([`Session::refresh_disk_salt`]). - pub disk_salt: Option<(u64, u64)>, - /// Take the disk cache's footage salt on a worker thread ([`Session::refresh_disk_salt`]): - /// frontends with an event loop (the desktop app) turn this on and call - /// [`Session::poll_disk_salt`] each frame; headless sessions take it at once. - pub disk_salt_background: bool, - /// The footage salt being taken in the background. - pub disk_salt_job: Option, /// The footage files effects read the channels of, as last given to the footage source /// ([`Session::refresh_aux_footage`]); `None` = not given yet. pub aux_footage: Option>, @@ -356,6 +351,7 @@ impl Default for Session { layer_cache: Arc::new(LayerCache::default()), crypto_probe: Default::default(), disk_cache: None, + pending_disk_drops: Default::default(), prefs: prefs::Prefs::default(), prefs_revision: 0, config: None, @@ -391,9 +387,6 @@ impl Default for Session { check_footage_on_open: false, stored_paths: Default::default(), footage_stamps: Default::default(), - disk_salt: None, - disk_salt_background: false, - disk_salt_job: None, aux_footage: None, script_calls: ScriptCalls::default(), } diff --git a/crates/engine/src/session.rs b/crates/engine/src/session.rs index 31ed40c1d..18b0ff4cf 100644 --- a/crates/engine/src/session.rs +++ b/crates/engine/src/session.rs @@ -10,4 +10,4 @@ mod dispatch; mod edit; mod render; -pub use edit::{DiskSaltJob, upgrade_effects}; +pub use edit::upgrade_effects; diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index 28813e2ec..67a8e4dcb 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -97,114 +97,10 @@ impl Session { if Arc::ptr_eq(&self.project, &self.saved_project) { self.saved_revision = self.revision; } - self.refresh_disk_salt(false); self.refresh_aux_footage(); self.events.push(Event::ProjectChanged { revision: self.revision }); } - /// Salt the disk cache's layer keys with the project's footage files - /// ([`effectcraft_render::disk_cache::footage_salt`]) and attach the disk cache to the layer - /// cache with it. Taking it reads the size and time of every file, every frame of an image - /// sequence included, so it is taken again only when the footage items changed, or with - /// `force` (a project opened, footage reloaded, the disk cache attached), not at every edit: - /// with a few large sequences that cost each keystroke in a text field over half a second - /// (#1926). - /// - /// With [`Session::disk_salt_background`] the files are read on a worker thread: an imported - /// or opened project with thousands of sequence frames on a network share took half a minute - /// to stamp, all of it on the UI thread. Until [`Session::poll_disk_salt`] picks the salt up, - /// renders use the memory cache only (keys under the old salt may name other files, or - /// another project's items) and this returns `None`. - pub fn refresh_disk_salt(&mut self, force: bool) -> Option { - let Some(dc) = self.disk_cache.clone() else { - self.disk_salt = None; - self.disk_salt_job = None; - return None; - }; - self.poll_disk_salt(); - let footage = Self::footage_fingerprint(&self.project); - if !force { - if let Some((seen, salt)) = self.disk_salt - && seen == footage - { - return Some(salt); - } - if self.disk_salt_job.as_ref().is_some_and(|j| j.footage == footage) { - return None; - } - } - if self.disk_salt_background && !cfg!(target_arch = "wasm32") { - let project = self.project.clone(); - let slot: Arc>> = Arc::default(); - let out = slot.clone(); - let spawned = std::thread::Builder::new().name("ec-disk-salt".into()).spawn(move || { - let salt = effectcraft_render::disk_cache::footage_salt(&project); - if let Ok(mut s) = out.lock() { - *s = Some(salt); - } - }); - // Without a thread the salt is taken here, as before. - if let Ok(thread) = spawned { - self.disk_salt = None; - self.disk_salt_job = Some(DiskSaltJob { footage, slot, thread }); - self.layer_cache.set_disk(None); - return None; - } - } - self.disk_salt_job = None; - let salt = effectcraft_render::disk_cache::footage_salt(&self.project); - self.disk_salt = Some((footage, salt)); - self.layer_cache.set_disk(Some((dc, salt))); - Some(salt) - } - - /// Pick up a footage salt taken in the background ([`Session::refresh_disk_salt`]) and attach - /// the disk cache with it. Returns whether one is still being taken (frontends call this each - /// frame while it is). - pub fn poll_disk_salt(&mut self) -> bool { - let Some(job) = &self.disk_salt_job else { return false }; - // (looked at first: a worker that has finished has left its salt in the slot) - let finished = job.thread.is_finished(); - let salt = job.slot.lock().ok().and_then(|mut s| s.take()); - let footage = job.footage; - match salt { - Some(salt) => { - self.disk_salt_job = None; - if let Some(dc) = self.disk_cache.clone() { - self.disk_salt = Some((footage, salt)); - self.layer_cache.set_disk(Some((dc, salt))); - } - false - } - None if finished => { - // The worker stopped without a salt: the disk cache stays off until the next - // edit takes it again. - log::warn!("disk cache: the footage files could not be stamped; the disk cache is off until the next edit"); - self.disk_salt_job = None; - false - } - None => true, - } - } - - /// In-memory identity of the footage settings represented by a disk salt. Workers use the - /// same fingerprint when preparing availability changes without disk access on the UI. - pub(crate) fn footage_fingerprint(project: &effectcraft_project::Project) -> u64 { - use std::hash::{Hash, Hasher}; - let mut h = std::collections::hash_map::DefaultHasher::new(); - for (id, item) in &project.items { - if let effectcraft_project::ItemKind::Footage(f) = &item.kind { - id.hash(&mut h); - format!("{f:?}").hash(&mut h); - } - if let Some(proxy) = &item.proxy { - id.hash(&mut h); - format!("{proxy:?}").hash(&mut h); - } - } - h.finish() - } - /// Set a comp's Resolution. As in After Effects it is saved with the project (which becomes /// modified) but is no undo step, and it changes no pixels: the comp's cached frames stay /// valid ([`effectcraft_project::Comp::same_pixels`]). @@ -322,11 +218,6 @@ impl Session { } self.layer_cache.clear(); self.project = Arc::new(p); - // Its files may have changed since they were last stamped. - self.disk_salt = None; - // A salt still being taken is for the old project's files: dropped, so that the next refresh - // stamps the new project anew (a matching fingerprint would otherwise keep the stale job). - self.disk_salt_job = None; // The set of footage effects read the channels of is sent again, even when it is empty. self.aux_footage = None; self.history = History::default(); @@ -389,11 +280,3 @@ pub fn upgrade_effects(p: &mut Project) { p.next_id = next; p.schema = effectcraft_project::SCHEMA_VERSION; } - -/// A footage salt being taken on a worker thread ([`Session::refresh_disk_salt`]). -pub struct DiskSaltJob { - /// The footage it is taken for ([`Session::footage_fingerprint`]). - footage: u64, - slot: Arc>>, - thread: std::thread::JoinHandle<()>, -} diff --git a/crates/engine/src/settings/session_settings.rs b/crates/engine/src/settings/session_settings.rs index 056616201..8ade9f8a3 100644 --- a/crates/engine/src/settings/session_settings.rs +++ b/crates/engine/src/settings/session_settings.rs @@ -137,10 +137,6 @@ impl Session { // over the store of a roto test running beside it. Serialise them with the roto tests. #[cfg(test)] crate::tests::roto::hold_roto_cache_test_lock(); - // Another setting changed (the disk cache stays as it is): its salt still holds, and - // stamping every footage file again would cost each settings change seconds with large - // sequences. - let kept = self.disk_cache.as_ref().is_some_and(|c| c.folder() == folder.as_path()); let dc = match &self.disk_cache { Some(c) if c.folder() == folder.as_path() => { c.set_max_bytes(max); @@ -162,11 +158,17 @@ impl Session { } }, }; + // Files reloaded while the cache was off: their entries go before anything is read from + // it (until the writer has deleted them they are misses, and no frame is linked). + if !self.pending_disk_drops.is_empty() { + dc.drop_files(std::mem::take(&mut self.pending_disk_drops)); + } self.disk_cache = Some(dc.clone()); // The reserve applies from the start (a new folder's watcher is idle). self.poll_disk_space(); - // Attaches the disk cache to the layer cache once the footage salt is known. - self.refresh_disk_salt(!kept); + // Used at once (no file is looked at first: each entry checks the source files it lists + // when it is read, #3184). + self.layer_cache.set_disk(Some(dc.clone())); // Roto Brush / Object Matte segmentations persist there too (held weakly: switching the // disk cache off drops it). let store: std::sync::Arc = dc.clone(); diff --git a/crates/engine/src/tests/crypto_pick.rs b/crates/engine/src/tests/crypto_pick.rs index e3a8cd50c..82fe21e71 100644 --- a/crates/engine/src/tests/crypto_pick.rs +++ b/crates/engine/src/tests/crypto_pick.rs @@ -214,6 +214,7 @@ fn rendered_matte_of_pick(s: &mut Session, x: f64, y: f64, scale: f64) -> (Strin footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let buf = s.renderer(effectcraft_render::RenderOpts { scale, ..Default::default() }).content_buf(&ctx, layer).unwrap(); let (px, py) = buf.to_px([x, y]); diff --git a/crates/engine/src/tests/disk_cache.rs b/crates/engine/src/tests/disk_cache.rs index 4805d68fe..4c610dceb 100644 --- a/crates/engine/src/tests/disk_cache.rs +++ b/crates/engine/src/tests/disk_cache.rs @@ -76,11 +76,13 @@ fn disk_cache_settings_persistence_and_invalidation() { assert!(s2.layer_cache.disk().is_none()); } +/// The comp key comes from the project in memory: a footage file that changes on disk doesn't +/// change it (the entries check their own files, #3184); edits that change pixels do. #[test] -fn footage_changes_change_the_salt() { - let dir = folder("salt"); +fn comp_content_keys_come_from_memory() { + let dir = folder("keys"); let mut s = session(&dir); - let foot = std::env::temp_dir().join(format!("effectcraft-salt-{}.png", std::process::id())); + let foot = std::env::temp_dir().join(format!("effectcraft-keys-{}.png", std::process::id())); std::fs::write(&foot, b"one").unwrap(); s.edit("add", None, |p, _| { let f = effectcraft_project::Footage { @@ -108,12 +110,10 @@ fn footage_changes_change_the_salt() { Ok(()) }) .unwrap(); - let a = effectcraft_render::disk_cache::footage_salt(&s.project); - std::fs::write(&foot, b"two, longer").unwrap(); - let b = effectcraft_render::disk_cache::footage_salt(&s.project); - assert_ne!(a, b); let cid = project(&mut s); let k1 = effectcraft_render::disk_cache::comp_content_key(&s.project, cid); + std::fs::write(&foot, b"two, longer").unwrap(); + assert_eq!(effectcraft_render::disk_cache::comp_content_key(&s.project, cid), k1, "no file is looked at"); s.execute("prop.set", json!({"layer": "#1", "path": "transform/opacity", "value": 50})).unwrap(); let k2 = effectcraft_render::disk_cache::comp_content_key(&s.project, cid); assert_ne!(k1, k2); @@ -137,66 +137,51 @@ fn footage_changes_change_the_salt() { assert_ne!(set_proxy(&mut s, false), k3); } -/// The desktop app stamps footage files for the disk cache's salt on a worker thread: importing an -/// After Effects project with thousands of sequence frames on a network share stamped them all -/// inside the import's edit, freezing the UI for half a minute. Until the salt lands the disk -/// cache sits out (keys under the old salt may name other files); a newer footage change -/// supersedes a salt still being taken; a settings change keeps the salt. +/// No salt and no scan (#3184, replacing the background footage salt of #3106): the disk cache +/// is attached to the layer cache as soon as it is switched on, and stays attached through +/// edits that add footage (a large image sequence included), settings changes and opening a +/// project, none of which looks at a single file for it. The first render may use it at once. #[test] -fn footage_salt_is_taken_off_the_ui_thread_and_the_disk_cache_waits_for_it() { - let dir = folder("bg-salt"); +fn the_disk_cache_is_attached_at_once_and_edits_do_no_file_work() { + let dir = folder("attach"); let mut s = session(&dir); - s.disk_salt_background = true; - let at = |n: &str| std::env::temp_dir().join(format!("effectcraft-bg-salt-{}-{n}.png", std::process::id())); - let add = |s: &mut Session, path: &std::path::Path| { - let f = effectcraft_project::Footage { - path: path.to_string_lossy().to_string(), - kind: effectcraft_project::FootageKind::Still, - width: 1, - height: 1, - has_video: true, - ..Default::default() - }; - s.edit("add", None, |p, _| { - p.add_item("f.png", effectcraft_color::Label::None, None, effectcraft_project::ItemKind::Footage(f)); - Ok(()) - }) - .unwrap(); + let dc = s.disk_cache.clone().unwrap(); + let attached = |s: &Session| s.layer_cache.disk().is_some_and(|d| std::sync::Arc::ptr_eq(&d, &dc)); + assert!(attached(&s), "attached at once"); + // A sequence of 5000 frames that don't even exist. + let seq_dir = std::env::temp_dir().join(format!("effectcraft-no-scan-{}", std::process::id())); + let f = effectcraft_project::Footage { + path: seq_dir.join("f_00000.exr").to_string_lossy().to_string(), + kind: effectcraft_project::FootageKind::Sequence, + sequence: (0..5000).map(|i| seq_dir.join(format!("f_{i:05}.exr")).to_string_lossy().to_string()).collect(), + width: 8, + height: 8, + has_video: true, + ..Default::default() }; - let wait = |s: &mut Session| { - let t0 = std::time::Instant::now(); - while s.poll_disk_salt() { - assert!(t0.elapsed().as_secs() < 20, "the salt never landed"); - std::thread::sleep(std::time::Duration::from_millis(5)); - } - }; - assert!(s.layer_cache.disk().is_some(), "attached with its salt"); - std::fs::write(at("a"), b"one").unwrap(); - add(&mut s, &at("a")); - // The edit returned before the files were stamped, and the disk cache waits for the salt. - assert!(s.disk_salt.is_none() && s.layer_cache.disk().is_none()); - // Edits that leave the footage alone don't start over (and may pick up the salt meanwhile). - s.execute("comp.new", json!({"name": "C", "width": 8, "height": 8, "frameRate": 30, "duration": 1})).unwrap(); - let r = s.refresh_disk_salt(false); - assert!(r.is_none() || r == Some(effectcraft_render::disk_cache::footage_salt(&s.project)), "{r:?}"); - // New footage while it is taken: the salt for the newest footage lands. - std::fs::write(at("b"), b"two").unwrap(); - add(&mut s, &at("b")); - wait(&mut s); - let salt = effectcraft_render::disk_cache::footage_salt(&s.project); - assert_eq!(s.disk_salt.map(|(_, salt)| salt), Some(salt)); - assert_eq!(s.refresh_disk_salt(false), Some(salt)); - assert!(s.layer_cache.disk().is_some(), "attached again"); - // Another setting keeps the salt and the disk cache attached. + s.edit("add", None, |p, _| { + p.add_item("seq", effectcraft_color::Label::None, None, effectcraft_project::ItemKind::Footage(f)); + Ok(()) + }) + .unwrap(); + assert!(attached(&s), "an import keeps it attached"); + let cid = project(&mut s); + s.execute("prop.set", json!({"layer": "#1", "path": "transform/opacity", "value": 50})).unwrap(); s.execute_checked("prefs.set", json!({"key": "disk.diskCacheMaxGb", "value": 30})).unwrap(); - assert!(s.layer_cache.disk().is_some() && s.disk_salt.map(|(_, salt)| salt) == Some(salt)); - // Turned off and on again: stamped anew, in the background. + assert!(attached(&s), "edits and other settings keep it attached"); + let same = (*s.project).clone(); + s.replace_project(same, None); + assert!(attached(&s), "opening a project keeps it attached"); + // The first render uses it: a solid reads no file, so nothing is checked either. + s.render(cid, s.time(), RenderOpts::default()); + dc.flush(); + assert!(dc.stats().entries > 0, "written by the first render"); + assert_eq!(dc.file_checks(), 0, "no file looked at for the disk cache"); + // Switched off and on: attached again at once. s.execute_checked("prefs.set", json!({"key": "disk.diskCacheEnabled", "value": false})).unwrap(); + assert!(s.layer_cache.disk().is_none()); s.execute_checked("prefs.set", json!({"key": "disk.diskCacheEnabled", "value": true})).unwrap(); - wait(&mut s); - assert_eq!(s.refresh_disk_salt(false), Some(salt)); - let _ = std::fs::remove_file(at("a")); - let _ = std::fs::remove_file(at("b")); + assert!(s.layer_cache.disk().is_some()); } /// Marker edits keep the disk key (the sound of a playing preview must not wait for frames to @@ -258,38 +243,227 @@ fn protected_markers_with_a_duration_change_the_content_key() { assert_ne!(key(&s), k1, "its duration"); } -/// A project opened while a footage salt is still being taken must not keep that salt when it -/// names the same footage: its files may have changed since the worker read them. +/// With expressions the comp key covers what they can read, not the whole project (#3184, +/// #1492): an expression reading only its own comp keeps the key through edits of another comp +/// and of unused footage; `comp("Other")` makes "Other" count (and which comps have that name), +/// not a third comp; a computed name counts every item. #[test] -fn opening_a_project_drops_the_footage_salt_being_taken() { - let dir = folder("bg-salt-open"); - let mut s = session(&dir); - s.disk_salt_background = true; - let path = std::env::temp_dir().join(format!("effectcraft-bg-salt-open-{}.png", std::process::id())); - std::fs::write(&path, b"one").unwrap(); - let f = effectcraft_project::Footage { - path: path.to_string_lossy().to_string(), - kind: effectcraft_project::FootageKind::Still, - width: 1, - height: 1, - has_video: true, - ..Default::default() +fn expressions_reach_only_what_they_name() { + let mut s = Session::default(); + let comp = |s: &mut Session, name: &str| { + let c = s.execute("comp.new", json!({"name": name, "width": 8, "height": 8, "frameRate": 30, "duration": 1})).unwrap()["comp"].as_u64().unwrap(); + let l = s.execute("layer.newSolid", json!({"comp": c, "color": "#ff0000"})).unwrap()["layer"].as_u64().unwrap(); + (effectcraft_project::ItemId(c), (c, l)) }; - s.edit("add", None, |p, _| { - p.add_item("f.png", effectcraft_color::Label::None, None, effectcraft_project::ItemKind::Footage(f)); + let (main, ml) = comp(&mut s, "Main"); + let (_, ol) = comp(&mut s, "Other"); + let (third, tl) = comp(&mut s, "Third"); + let unused = s.edit("add", None, |p, _| { + let f = effectcraft_project::Footage { path: "/nowhere/a.png".into(), has_video: true, ..Default::default() }; + Ok(p.add_item("a.png", effectcraft_color::Label::None, None, effectcraft_project::ItemKind::Footage(f))) + }); + let unused = unused.unwrap(); + let key = |s: &Session| effectcraft_render::disk_cache::comp_content_key(&s.project, main); + let expr = |s: &mut Session, (comp, layer): (u64, u64), text: &str| { + s.execute("prop.setExpression", json!({"comp": comp, "layer": layer, "path": "transform/opacity", "expression": text})).unwrap(); + }; + let opacity = |s: &mut Session, (comp, layer): (u64, u64), v: f64| { + s.execute("prop.set", json!({"comp": comp, "layer": layer, "path": "transform/opacity", "value": v})).unwrap(); + }; + let repath = |s: &mut Session, path: &str| { + let path = path.to_string(); + s.edit("repath", None, move |p, _| { + if let Some(effectcraft_project::ItemKind::Footage(f)) = p.item_mut(unused).map(|i| &mut i.kind) { + f.path = path; + } + Ok(()) + }) + .unwrap(); + }; + // Its own comp only. + expr(&mut s, ml, "thisComp.layer(1).transform.rotation + wiggle(1, 1)[0]"); + expr(&mut s, ol, "wiggle(2, 10)"); + let k0 = key(&s); + opacity(&mut s, ol, 40.0); + expr(&mut s, tl, "time * 10"); + repath(&mut s, "/nowhere/b.png"); + s.execute("comp.addMarker", json!({"comp": third.0, "time": 0.5})).unwrap(); + assert_eq!(key(&s), k0, "edits elsewhere keep the key"); + // An edit in the comp itself changes it. + opacity(&mut s, ml, 30.0); + assert_ne!(key(&s), k0); + // `comp("Other")`: Other counts, Third doesn't. + expr(&mut s, ml, "comp(\"Other\").layer(1).transform.opacity"); + let k1 = key(&s); + expr(&mut s, ol, "wiggle(3, 10)"); + let k2 = key(&s); + assert_ne!(k2, k1, "the comp it names"); + opacity(&mut s, tl, 20.0); + repath(&mut s, "/nowhere/c.png"); + assert_eq!(key(&s), k2, "a comp it doesn't name"); + // Another comp taking the name changes what it may read. + s.edit("rename", None, |p, _| { + p.item_mut(third).unwrap().name = "Other".into(); Ok(()) }) .unwrap(); - // The file changes after the edit started the salt, before the same footage is opened again. - std::fs::write(&path, b"a longer content").unwrap(); - let same = (*s.project).clone(); - s.replace_project(same, None); - let t0 = std::time::Instant::now(); - while s.poll_disk_salt() { - assert!(t0.elapsed().as_secs() < 20, "the salt never landed"); - std::thread::sleep(std::time::Duration::from_millis(5)); + let k3 = key(&s); + assert_ne!(k3, k2, "a second comp named Other"); + // A computed name reaches every item. + expr(&mut s, ml, "comp(\"Oth\" + \"er\").layer(1).transform.opacity"); + let k4 = key(&s); + repath(&mut s, "/nowhere/d.png"); + assert_ne!(key(&s), k4, "unused footage counts with a computed name"); +} + +/// Markers count only for the comps whose expressions can read them (#1083): an expression in +/// another comp that reads markers leaves this comp's markers out of its key. +#[test] +fn markers_count_only_where_an_expression_can_read_them() { + let mut s = Session::default(); + s.execute("comp.new", json!({"name": "M", "width": 8, "height": 8, "frameRate": 30, "duration": 2})).unwrap(); + let cid = s.active_comp_id().unwrap(); + s.execute("layer.newSolid", json!({"color": "#ff0000"})).unwrap(); + let other = s.execute("comp.new", json!({"name": "N", "width": 8, "height": 8, "frameRate": 30, "duration": 2})).unwrap()["comp"].as_u64().unwrap(); + let ol = s.execute("layer.newSolid", json!({"comp": other, "color": "#ff0000"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("prop.setExpression", json!({"comp": other, "layer": ol, "path": "transform/opacity", "expression": "thisComp.marker.numKeys"})).unwrap(); + let key = |s: &Session| effectcraft_render::disk_cache::comp_content_key(&s.project, cid); + let k0 = key(&s); + s.execute("comp.addMarker", json!({"comp": cid.0, "time": 0.5, "comment": "beat"})).unwrap(); + assert_eq!(key(&s), k0, "no expression of M reads its markers"); + s.execute("prop.setExpression", json!({"comp": other, "layer": ol, "path": "transform/opacity", "expression": "comp(\"M\").marker.numKeys"})).unwrap(); + let other_key = |s: &Session| effectcraft_render::disk_cache::comp_content_key(&s.project, effectcraft_project::ItemId(other)); + let n0 = other_key(&s); + s.execute("comp.addMarker", json!({"comp": cid.0, "time": 1.0})).unwrap(); + assert_ne!(other_key(&s), n0, "N reads M's markers"); + assert_eq!(key(&s), k0, "M itself still doesn't"); +} + +/// File ▸ Reload Footage drops the disk entries made of the item's files (#3184): a file +/// replaced by one with the same size and modification time is read again (the check on hit +/// can't tell), and entries of other files stay. +#[test] +fn reload_footage_drops_the_entries_of_its_files() { + use crate::render::reads::{FileStamp, ReadFile, ReadFiles}; + struct Probe; + impl crate::Importer for Probe { + fn probe(&self, path: &str) -> std::result::Result { + Ok(effectcraft_project::Footage { + path: path.into(), + kind: effectcraft_project::FootageKind::Still, + width: 1, + height: 1, + has_video: true, + ..Default::default() + }) + } } - let now = effectcraft_render::disk_cache::footage_salt(&s.project); - assert_eq!(s.disk_salt.map(|(_, salt)| salt), Some(now), "the salt reflects the file as it is now"); - let _ = std::fs::remove_file(&path); + let dir = folder("reload"); + let mut s = Session { importer: Some(std::sync::Arc::new(Probe)), ..Default::default() }; + s.execute_checked("prefs.set", json!({"values": {"disk.diskCacheFolder": &dir, "disk.diskCacheEnabled": true}})).unwrap(); + let src = std::path::Path::new(&dir).join("src"); + std::fs::create_dir_all(&src).unwrap(); + let mut add = |name: &str| { + let p = src.join(name); + std::fs::write(&p, b"aa").unwrap(); + let path = p.to_string_lossy().to_string(); + let f = effectcraft_project::Footage { + path: path.clone(), + kind: effectcraft_project::FootageKind::Still, + width: 1, + height: 1, + has_video: true, + ..Default::default() + }; + let id = s.edit("add", None, |p, _| Ok(p.add_item(name, effectcraft_color::Label::None, None, effectcraft_project::ItemKind::Footage(f)))).unwrap(); + (id, path) + }; + let (a, a_path) = add("a.png"); + let (_, b_path) = add("b.png"); + let dc = s.disk_cache.clone().unwrap(); + let read = |p: &str| -> ReadFiles { [ReadFile::new(p, FileStamp::native(p).unwrap())].into_iter().collect() }; + dc.put_frame_now(1, 1, 1, &[1; 4], &read(&a_path)); + dc.put_frame_now(2, 1, 1, &[2; 4], &read(&b_path)); + dc.put_layer_now(3, &effectcraft_effects::Buf { img: effectcraft_raster::Image::new(1, 1), offset: [0.0; 2], scale: 1.0 }, &read(&a_path)); + // Other bytes, same size, the old time back. + let t = std::fs::metadata(&a_path).unwrap().modified().unwrap(); + std::fs::write(&a_path, b"AA").unwrap(); + std::fs::File::options().append(true).open(&a_path).unwrap().set_modified(t).unwrap(); + assert!(dc.contains(crate::render::disk_cache::Kind::Frame, 1)); + s.execute_checked("file.reloadFootage", json!({"item": a.0})).unwrap(); + dc.flush(); + assert!(dc.get_frame(1, None).is_none(), "the reloaded file's frame renders again"); + assert!(dc.get_layer(3, None).is_none(), "and its layer buffer"); + assert!(dc.get_frame(2, None).is_some(), "another file's frame stays"); + let _ = std::fs::remove_dir_all(&dir); +} + +/// Reload Footage while the disk cache is off (#3184): when it is switched on later in the +/// session, the entries made of the reloaded files are dropped before anything is read from it +/// (a file replaced by one with the same size and time would pass the check on hit); entries of +/// other files stay. +#[test] +fn reload_footage_while_the_disk_cache_is_off_drops_its_entries_when_it_is_on() { + use crate::render::disk_cache::{DiskCache, Kind}; + use crate::render::reads::{FileStamp, ReadFile, ReadFiles}; + struct Probe; + impl crate::Importer for Probe { + fn probe(&self, path: &str) -> std::result::Result { + Ok(effectcraft_project::Footage { + path: path.into(), + kind: effectcraft_project::FootageKind::Still, + width: 1, + height: 1, + has_video: true, + ..Default::default() + }) + } + } + let dir = folder("reload-off"); + let src = std::path::Path::new(&dir).join("src"); + std::fs::create_dir_all(&src).unwrap(); + let mut s = Session { importer: Some(std::sync::Arc::new(Probe)), ..Default::default() }; + let mut add = |name: &str| { + let p = src.join(name); + std::fs::write(&p, b"aa").unwrap(); + let path = p.to_string_lossy().to_string(); + let f = effectcraft_project::Footage { + path: path.clone(), + kind: effectcraft_project::FootageKind::Still, + width: 1, + height: 1, + has_video: true, + ..Default::default() + }; + let id = s.edit("add", None, |p, _| Ok(p.add_item(name, effectcraft_color::Label::None, None, effectcraft_project::ItemKind::Footage(f)))).unwrap(); + (id, path) + }; + let (a, a_path) = add("a.png"); + let (_, b_path) = add("b.png"); + // Entries from an earlier session in the cache folder. + let read = |p: &str| -> ReadFiles { [ReadFile::new(p, FileStamp::native(p).unwrap())].into_iter().collect() }; + { + let dc = DiskCache::open(&dir, 1 << 30).unwrap(); + dc.put_frame_now(1, 1, 1, &[1; 4], &read(&a_path)); + dc.put_frame_now(2, 1, 1, &[2; 4], &read(&b_path)); + dc.put_layer_now(3, &effectcraft_effects::Buf { img: effectcraft_raster::Image::new(1, 1), offset: [0.0; 2], scale: 1.0 }, &read(&a_path)); + } + // Other bytes, same size, the old time back; reloaded while the cache is off. + let t = std::fs::metadata(&a_path).unwrap().modified().unwrap(); + std::fs::write(&a_path, b"AA").unwrap(); + std::fs::File::options().append(true).open(&a_path).unwrap().set_modified(t).unwrap(); + assert!(s.disk_cache.is_none()); + s.execute_checked("file.reloadFootage", json!({"item": a.0})).unwrap(); + // Switched on: the reloaded file's entries are misses from the start, and then gone. + s.execute_checked("prefs.set", json!({"values": {"disk.diskCacheFolder": &dir, "disk.diskCacheEnabled": true}})).unwrap(); + let dc = s.disk_cache.clone().unwrap(); + assert!(dc.get_frame(1, None).is_none(), "the reloaded file's frame renders again"); + assert!(dc.get_layer(3, None).is_none(), "and its layer buffer"); + dc.flush(); + assert!(!dc.contains(Kind::Frame, 1) && !dc.contains(Kind::Layer, 3)); + assert!(dc.get_frame(2, None).is_some(), "another file's frame stays"); + assert!(s.pending_disk_drops.is_empty(), "applied once"); + drop(dc); + drop(s); + let _ = std::fs::remove_dir_all(&dir); } diff --git a/crates/engine/src/tests/rig3d.rs b/crates/engine/src/tests/rig3d.rs index db64a9066..634d84e02 100644 --- a/crates/engine/src/tests/rig3d.rs +++ b/crates/engine/src/tests/rig3d.rs @@ -40,7 +40,17 @@ fn close3(a: [f64; 3], b: [f64; 3], tol: f64) -> bool { fn frame(s: &Session, id: u64) -> (Vec3, Vec3) { let c = cid(s); let comp = s.project.comp(c).unwrap(); - let ctx = EvalCtx { project: &s.project, comp_id: c, comp, time: Tick::ZERO, expr: None, footage: None, property_overrides: &[], media_overrides: &[] }; + let ctx = EvalCtx { + project: &s.project, + comp_id: c, + comp, + time: Tick::ZERO, + expr: None, + footage: None, + property_overrides: &[], + media_overrides: &[], + reads: None, + }; let (e, f, _) = layer_frame(&ctx, comp.layer(LayerId(id)).unwrap()); (e, f) } @@ -244,7 +254,7 @@ fn parented_camera_keeps_its_frame_under_an_offset_null() { fn frame_at(s: &Session, id: u64, t: Tick) -> (Vec3, Vec3, Vec3) { let c = cid(s); let comp = s.project.comp(c).unwrap(); - let ctx = EvalCtx { project: &s.project, comp_id: c, comp, time: t, expr: None, footage: None, property_overrides: &[], media_overrides: &[] }; + let ctx = EvalCtx { project: &s.project, comp_id: c, comp, time: t, expr: None, footage: None, property_overrides: &[], media_overrides: &[], reads: None }; layer_frame(&ctx, comp.layer(LayerId(id)).unwrap()) } diff --git a/crates/engine/src/tests/sequence.rs b/crates/engine/src/tests/sequence.rs index c5faa232b..b084e6b36 100644 --- a/crates/engine/src/tests/sequence.rs +++ b/crates/engine/src/tests/sequence.rs @@ -269,30 +269,31 @@ fn dpx_and_cineon_runs_import_as_sequences() { assert_eq!(got, [("plate.[0001-0003].dpx".to_string(), 3), ("scan_[01-02].cin".to_string(), 2)], "{r}"); } -/// #1926: an edit that leaves the footage alone doesn't stamp every frame of its image sequences -/// again for the disk cache's salt (with large sequences each keystroke in a text field took over -/// half a second); Reload Footage does, and so does new footage. +/// #1926, #3184: an edit does no file work at all for the disk cache (it used to stamp every +/// frame of the project's image sequences for a salt; with large sequences each keystroke in a +/// text field took over half a second): the cache stays attached and no file is looked at, after +/// edits, after a frame of the sequence was rewritten, after Reload Footage and new footage. +/// Entries check the files they list when they are read instead. #[test] -fn edits_keep_the_disk_salt_and_reload_stamps_the_files_again() { +fn edits_do_no_disk_cache_file_work() { let dir = folder(&RUN); - let cache = std::env::temp_dir().join(format!("ec-seq-salt-{}", std::process::id())); + let cache = std::env::temp_dir().join(format!("ec-seq-nofiles-{}", std::process::id())); let _ = std::fs::remove_dir_all(&cache); let mut s = session(); s.execute_checked("prefs.set", json!({"values": {"disk.diskCacheFolder": cache.to_string_lossy(), "disk.diskCacheEnabled": true}})).unwrap(); + let dc = s.disk_cache.clone().expect("a disk cache"); + let attached = |s: &Session| s.layer_cache.disk().is_some_and(|d| std::sync::Arc::ptr_eq(&d, &dc)); s.execute("comp.new", json!({"name": "C", "width": 64, "height": 32, "frameRate": 30, "duration": 1})).unwrap(); let r = s.execute("file.import", json!({"paths": [at(&dir, "shot_0002.png")], "sequence": true, "addToComp": true})).unwrap(); let item = r["items"][0].clone(); - let salt = s.refresh_disk_salt(false).expect("a disk cache"); // A frame rewritten in place: same footage settings, another size on disk. std::fs::write(at(&dir, "shot_0004.png"), b"a new render of this frame").unwrap(); s.execute("layer.newText", json!({"text": "title"})).unwrap(); s.execute("layer.setText", json!({"text": "title 2"})).unwrap(); - assert_eq!(s.refresh_disk_salt(false), Some(salt), "edits don't stamp the files again"); s.execute("file.reloadFootage", json!({"items": [item]})).unwrap(); - let reloaded = s.refresh_disk_salt(false).unwrap(); - assert_ne!(reloaded, salt, "Reload Footage stamps them again"); std::fs::write(at(&dir, "extra.png"), b"").unwrap(); s.execute("file.import", json!({"paths": [at(&dir, "extra.png")]})).unwrap(); - assert_ne!(s.refresh_disk_salt(false), Some(reloaded), "new footage counts"); + assert!(attached(&s), "attached all along"); + assert_eq!(dc.file_checks(), 0, "no file looked at for the disk cache"); let _ = std::fs::remove_dir_all(&cache); } diff --git a/crates/expr/src/host.rs b/crates/expr/src/host.rs index fa2993f97..43400ea1d 100644 --- a/crates/expr/src/host.rs +++ b/crates/expr/src/host.rs @@ -297,6 +297,7 @@ impl<'a> Resolver<'a> { } self.comp(c)?.layer(LayerId(l)) } + /// The evaluation context for comp `c` at time `t` seconds, or `None` when the comp does not exist. fn ctx_at(&self, c: u64, t: f64) -> Option> { let comp = self.comp(c)?; let same_comp = c == self.ctx.comp_id.0; @@ -309,6 +310,7 @@ impl<'a> Resolver<'a> { footage: self.ctx.footage, property_overrides: if same_comp { self.ctx.property_overrides } else { &[] }, media_overrides: if same_comp { self.ctx.media_overrides } else { &[] }, + reads: self.ctx.reads, }) } fn prop(&self, c: u64, l: u64, path: &str) -> Option<(&'a Layer, &'a Property)> { diff --git a/crates/expr/src/lib.rs b/crates/expr/src/lib.rs index 9e78d250f..ae9e647f8 100644 --- a/crates/expr/src/lib.rs +++ b/crates/expr/src/lib.rs @@ -172,6 +172,7 @@ fn evaluate_out( footage: ctx.footage, property_overrides: ctx.property_overrides, media_overrides: ctx.media_overrides, + reads: ctx.reads, }; let comp = ctx.comp_id.0; let path = layer.props.path_of(prop.uid).unwrap_or_else(|| format!("@{}", prop.uid)); diff --git a/crates/expr/src/sample.rs b/crates/expr/src/sample.rs index 28f830bb2..38f617289 100644 --- a/crates/expr/src/sample.rs +++ b/crates/expr/src/sample.rs @@ -4,13 +4,16 @@ //! expression (its footage source; [`EvalCtx::footage`]): source → masks → effects for //! `postEffect = true`, the bare source otherwise, in layer space (before the transform). Buffers //! are cached per thread for the frame, so many expressions sampling the same layer at the same -//! time render it once. +//! time render it once. The source files a sampled render reads are kept with its buffer and +//! noted in the evaluating render's log ([`EvalCtx::reads`]) on every use, so a frame whose +//! expressions sample footage lists that footage too (#3184). use std::cell::RefCell; use std::collections::HashMap; use std::sync::Arc; use effectcraft_project::{ItemId, Layer}; +use effectcraft_render::reads::{ReadFiles, ReadLog}; use effectcraft_render::{EvalCtx, NoFootage, RenderOpts, Renderer}; use effectcraft_time::Tick; @@ -26,7 +29,8 @@ struct Sampled { type Key = (usize, u64, u64, u64, bool, u64); thread_local! { - static CACHE: RefCell>> = RefCell::new(HashMap::new()); + /// The sampled buffers and the source files each was made of. + static CACHE: RefCell, Arc)>> = RefCell::new(HashMap::new()); /// Nested sampleImage renders (a sampled layer whose expressions sample again). static DEPTH: RefCell = const { RefCell::new(0) }; } @@ -42,13 +46,21 @@ fn fingerprint(layer: &Layer) -> u64 { h.finish() } +/// Renders `layer` of `comp` at time `t` for an expression sample, before or after effects as `post` says. +/// Returns `None` once the nesting depth limit is reached. fn render(ctx: EvalCtx, comp: ItemId, layer: &Layer, post: bool, t: f64) -> Option { let depth = DEPTH.with(|d| *d.borrow()); if depth >= MAX_DEPTH { return None; } let key: Key = (ctx.project as *const _ as usize, comp.0, layer.id.0, t.to_bits(), post, fingerprint(layer)); - if let Some(hit) = CACHE.with(|c| c.borrow().get(&key).cloned()) { + let note = |files: &ReadFiles| { + if let Some(log) = ctx.reads { + log.note_all(files); + } + }; + if let Some((hit, files)) = CACHE.with(|c| c.borrow().get(&key).cloned()) { + note(&files); return hit; } DEPTH.with(|d| *d.borrow_mut() += 1); @@ -60,20 +72,24 @@ fn render(ctx: EvalCtx, comp: ItemId, layer: &Layer, post: bool, t: f64) -> Opti } let _pop = Pop; let footage: &dyn effectcraft_render::FootageSource = ctx.footage.unwrap_or(&NoFootage); + let log = ReadLog::new(); let mut r = Renderer::new(ctx.project, footage, RenderOpts { motion_blur: false, ..Default::default() }); r.expr = ctx.expr; + r.reads = Some(&log); let ectx = r.eval_ctx(comp, Tick::from_seconds_f64(t))?; let out = if post { r.content_buf(&ectx, layer).map(|b| Sampled { img: Arc::new(b.img.clone()), offset: b.offset, scale: b.scale }) } else { r.layer_source(&ectx, layer).map(|b| Sampled { img: Arc::new(b.img), offset: b.offset, scale: b.scale }) }; + let files = Arc::new(log.into_files()); + note(&files); CACHE.with(|c| { let mut c = c.borrow_mut(); if c.len() >= MAX_CACHE { c.clear(); } - c.insert(key, out.clone()); + c.insert(key, (out.clone(), files)); }); out } diff --git a/crates/expr/src/tests.rs b/crates/expr/src/tests.rs index a7d2489c7..050a5a550 100644 --- a/crates/expr/src/tests.rs +++ b/crates/expr/src/tests.rs @@ -1332,6 +1332,7 @@ fn source_dimensions_follow_media_replacement() { footage: None, property_overrides: &[], media_overrides: &[media], + reads: None, }; assert_eq!(ctx.value(l, l.props.prop(ROT).unwrap()), Value::Scalar(130.0)); } @@ -1554,6 +1555,7 @@ fn text_expression_selector_values() { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let doc = effectcraft_render::text::source_text(&ctx, l).unwrap(); let lay = effectcraft_text::layout_doc(&doc); @@ -1606,6 +1608,43 @@ fn sample_image_reads_rendered_pixels() { assert_close!(f.num(&code("thisComp.layer(\"B\").sampleImage([-50, -50])"), 0.0), 0.0); } +/// The footage `sampleImage` renders is a file the evaluating render read (#3184): it is noted in +/// the render's log, also when the sampled buffer comes from the per-thread cache. +#[test] +fn sample_image_notes_the_files_it_reads() { + use effectcraft_render::reads::{FileStamp, ReadFile, ReadLog}; + /// A grey picture of any footage, noting `/clip.png` for every read. + struct Clip; + impl effectcraft_render::FootageSource for Clip { + fn frame(&self, _: ItemId, f: &effectcraft_project::Footage, _: Tick) -> Option> { + let mut img = effectcraft_render::Image::new(f.width, f.height); + img.data.fill([0.5, 0.5, 0.5, 1.0]); + Some(std::sync::Arc::new(img)) + } + fn recording(&self, reads: &ReadLog, f: &mut dyn FnMut()) { + f(); + reads.note(ReadFile::new("/clip.png", FileStamp::Native { len: 3, modified: Some(1) })); + } + } + let mut p = Project::default(); + let comp = Comp::new(20, 20, FrameRate::FPS_30, Tick::from_seconds_f64(1.0)); + let footage = + effectcraft_project::Footage { path: "/clip.png".into(), width: 8, height: 8, has_video: true, frame_rate: FrameRate::FPS_30, ..Default::default() }; + let item = p.add_item("Clip", Label::Aqua, None, ItemKind::Footage(footage)); + let layer = build::layer(&mut p, &comp, "Clip", LayerSource::Footage { item }, (8, 8), None); + let cid = p.add_item("C", Label::Sandstone, None, ItemKind::Comp(comp.into())); + let c = p.comp(cid).unwrap(); + for pass in ["rendered", "cached"] { + let log = ReadLog::new(); + let ctx = EvalCtx { footage: Some(&Clip), reads: Some(&log), ..EvalCtx::new(&p, cid, c, Tick::ZERO) }; + let px = crate::sample::sample_image(ctx, cid, &layer, [4.0, 4.0], [0.5, 0.5], false, 0.0).unwrap(); + assert!((px[0] - 0.5).abs() < 1e-3 && px[3] > 0.99, "{pass}: {px:?}"); + let files = log.into_files(); + assert_eq!(files.files().iter().map(|f| &*f.path).collect::>(), ["/clip.png"], "{pass}"); + assert!(files.is_complete(), "{pass}"); + } +} + /// A huge sample point saturates the pixel coordinates; it must not overflow the loop bounds. #[test] fn sample_image_huge_point_is_transparent() { diff --git a/crates/gpu/src/tests/adv3d.rs b/crates/gpu/src/tests/adv3d.rs index 00b1fee14..4914c4912 100644 --- a/crates/gpu/src/tests/adv3d.rs +++ b/crates/gpu/src/tests/adv3d.rs @@ -123,6 +123,7 @@ pub(crate) fn scene(p: &Project, cid: ItemId) -> Scene { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let run: Vec<&effectcraft_project::Layer> = ctx.comp.layers.iter().rev().filter(|l| l.is_3d() && l.has_video()).collect(); adv::scene_of(&r, &ctx, &run, (ctx.comp.width, ctx.comp.height)) @@ -315,6 +316,7 @@ pub(crate) fn run_of(p: &Project, cid: ItemId) -> (EvalCtx<'_>, Vec<&effectcraft footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let run: Vec<&effectcraft_project::Layer> = ctx.comp.layers.iter().rev().filter(|l| l.is_3d() && l.has_video()).collect(); (ctx, run) diff --git a/crates/host/src/tests.rs b/crates/host/src/tests.rs index f628ce4e4..55240698f 100644 --- a/crates/host/src/tests.rs +++ b/crates/host/src/tests.rs @@ -343,6 +343,7 @@ fn value(s: &effectcraft_engine::Session, l: u64, path: &str) -> effectcraft_eng footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; ctx.value(layer, layer.props.prop(path).unwrap()) } @@ -606,6 +607,7 @@ fn stereo_rig_expressions_follow_the_master_camera() { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; ctx.value(layer, layer.props.prop(path).unwrap()).as_vec3() }; @@ -624,3 +626,35 @@ fn stereo_rig_expressions_follow_the_master_camera() { assert!(close(v3(&s, "transform/position"), [300.0 - d, 180.0, -800.0]), "{:?}", v3(&s, "transform/position")); assert!(close(v3(&s, "transform/poi"), [300.0, 180.0, 0.0]), "{:?}", v3(&s, "transform/poi")); } + +/// A text layer showing a 3D model's name (`thisComp.layer("Model").source.name`): renaming the +/// model gives the comp a new disk key and the text shows the new name (expressions on). +#[test] +fn renaming_a_model_a_text_expression_reads_changes_the_key_and_the_text() { + use effectcraft_engine::Session; + let mut s = super::session(); + let cid = effectcraft_project::ItemId( + s.execute("comp.new", json!({"name": "M", "width": 160, "height": 60, "frameRate": 30, "duration": 1})).unwrap()["comp"].as_u64().unwrap(), + ); + let model = s + .edit("add model", None, |p, _| { + let f = effectcraft_project::Footage { kind: effectcraft_project::FootageKind::Model, ..Default::default() }; + let model = p.add_item("chair.glb", Default::default(), None, effectcraft_project::ItemKind::Footage(f)); + let comp = p.comp(cid).cloned().unwrap(); + let mut l = effectcraft_project::build::layer(p, &comp, "Model", effectcraft_project::LayerSource::Model { item: model }, (16, 16), None); + // (not drawn: no model file; an expression still reads its source) + l.switches.video = false; + p.comp_mut(cid).unwrap().layers.push(l); + Ok(model) + }) + .unwrap(); + let text = s.execute("layer.newText", json!({"comp": cid.0, "text": "x"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("prop.setExpression", json!({"comp": cid.0, "layer": text, "path": "text/sourceText", "expression": "thisComp.layer(\"Model\").source.name"})) + .unwrap(); + let key = effectcraft_engine::render::disk_cache::comp_content_key(&s.project, cid); + let shown = |s: &mut Session| s.execute("prop.get", json!({"comp": cid.0, "layer": text, "path": "text/sourceText"})).unwrap()["evaluated"].to_string(); + assert!(shown(&mut s).contains("chair.glb"), "{}", shown(&mut s)); + s.execute("project.rename", json!({"item": model.0, "name": "table.glb"})).unwrap(); + assert_ne!(effectcraft_engine::render::disk_cache::comp_content_key(&s.project, cid), key, "the comp's frames on disk hold the old name"); + assert!(shown(&mut s).contains("table.glb"), "the text shows the new name: {}", shown(&mut s)); +} diff --git a/crates/media/Cargo.toml b/crates/media/Cargo.toml index a4070297b..4947d928a 100644 --- a/crates/media/Cargo.toml +++ b/crates/media/Cargo.toml @@ -36,3 +36,7 @@ rayon = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } log = { workspace = true } + +[dev-dependencies] +# (tests render comps that read layers through effects; already a dependency of effectcraft-render) +effectcraft-effects = { workspace = true } diff --git a/crates/media/src/exr_channels.rs b/crates/media/src/exr_channels.rs index c3e7cfc3d..d0acf590f 100644 --- a/crates/media/src/exr_channels.rs +++ b/crates/media/src/exr_channels.rs @@ -17,6 +17,7 @@ use std::sync::{Arc, Mutex, OnceLock, PoisonError}; use effectcraft_raster::channels3d::{BACKGROUND_DEPTH, split_channel}; use effectcraft_raster::{AuxChannels, Image}; +use effectcraft_render::reads::{ReadFile, ReadFiles}; use exr::block::UncompressedBlock; use exr::block::chunk::TileCoordinates; use exr::image::read::image::ReadImage; @@ -477,8 +478,8 @@ fn layered_picture_of(aux: &AuxChannels, op: AlphaOp) -> Option { /// decoded anyway), else of the picture's channels alone (also when the cache has no channels /// for the file: a read that failed, or a broken part the picture doesn't use). `Err(Some(why))` /// when the file is too large to decode, `Err(None)` when it isn't a readable multi-layer EXR. -pub(crate) fn layered_picture(path: &str, bytes: Arc<[u8]>, op: AlphaOp, shared: bool) -> Result> { - if shared && let Some(d) = cache().get(path, Use::Picture, || Some(bytes.clone())) { +pub(crate) fn layered_picture(path: &str, bytes: Arc<[u8]>, file: &ReadFile, op: AlphaOp, shared: bool) -> Result> { + if shared && let Some(d) = cache().get(path, Use::Picture, || read_as(file, bytes.clone())) { return layered_picture_of(&d.aux, op).ok_or(None); } let (d, rgb, a) = picture_only(&bytes).map_err(|r| match r { @@ -499,8 +500,8 @@ pub(crate) fn layered_picture(path: &str, bytes: Arc<[u8]>, op: AlphaOp, shared: /// decoder shows for a file it reads, [`layered_image`]'s rule for one it refuses. `None` when /// the planes can't stand in for the `image` crate's picture (decode with it), or the file is /// not a readable EXR. -pub(crate) fn cached_picture(path: &str, bytes: Arc<[u8]>, op: AlphaOp) -> Option { - let d = cache().get(path, Use::Picture, || Some(bytes))?; +pub(crate) fn cached_picture(path: &str, bytes: Arc<[u8]>, file: &ReadFile, op: AlphaOp) -> Option { + let d = cache().get(path, Use::Picture, || read_as(file, bytes))?; let aux = &d.aux; match d.rgb { Rgb::None => layered_picture_of(aux, op), @@ -536,8 +537,16 @@ const CACHE_FILES: usize = 64; /// rendered at once. The oldest stops being kept when another comes. const HELD_FILES: usize = 4; -/// A file's decode: done once, by the first caller; the others wait for it. -type Slot = Arc>>>; +/// A file's decode: done once, by the first caller; the others wait for it. With the files read +/// for it (see [`crate::reads`]), noted again on every hit. +type Slot = Arc>, ReadFiles)>>; + +/// Bytes the caller already read from `file`, given to the cache as read from it (so the entry +/// keeps the file's identity). +fn read_as(file: &ReadFile, bytes: Arc<[u8]>) -> Option> { + crate::reads::note(file.clone()); + Some(bytes) +} struct Entry { path: String, @@ -554,8 +563,8 @@ impl Entry { fn in_use(&self) -> bool { match self.slot.get() { None => true, - Some(None) => false, - Some(Some(d)) => Arc::strong_count(d) > 1 || Arc::strong_count(&d.aux) > 1, + Some((None, _)) => false, + Some((Some(d), _)) => Arc::strong_count(d) > 1 || Arc::strong_count(&d.aux) > 1, } } } @@ -648,30 +657,18 @@ impl ChannelCache { // is safe because the decode never waits on rayon's global pool (the exr crate // decompresses on a pool of its own and this thread only receives the blocks), so the // decoding thread can't be waiting for this one. - let v = slot - .get_or_init(|| { - decoded_here = true; - self.decodes.fetch_add(1, Ordering::Relaxed); - #[cfg(test)] - count_decode(true); - let _abandon = Abandon { cache: self, slot: &slot }; - let bytes = read()?; - // The planes it will allocate count against the budget while it decodes. - if let Ok(meta) = exr::meta::MetaData::read_from_buffered(std::io::Cursor::new(&bytes[..]), false) - && let Some(need) = planes_bytes(&meta, &|_| true) - { - self.account(&slot, need.min(MAX_DECODE_BYTES)); - } - match decode(&bytes, &|_| true) { - Ok(d) => Some(Arc::new(d)), - Err(Refused::TooLarge(why)) => { - log::warn!("media: {path}: {why}"); - None - } - Err(Refused::Unreadable) => None, - } - }) - .clone(); + let (v, files) = slot.get_or_init(|| { + decoded_here = true; + self.decodes.fetch_add(1, Ordering::Relaxed); + #[cfg(test)] + count_decode(true); + let _abandon = Abandon { cache: self, slot: &slot }; + let (bytes, files) = crate::reads::captured(read); + (bytes.and_then(|bytes| self.decode_file(path, &slot, &bytes)), files) + }); + // The file(s) the decode was made of, read now or for an earlier caller. + crate::reads::note_all(files); + let v = v.clone(); if decoded_here { self.account(&slot, v.as_ref().map_or(0, |d| d.bytes())); } @@ -692,6 +689,24 @@ impl ChannelCache { v } + /// Decode the file at `path` whose bytes are `bytes` for `slot` (see [`ChannelCache::get`]). + fn decode_file(&self, path: &str, slot: &Slot, bytes: &[u8]) -> Option> { + // The planes it will allocate count against the budget while it decodes. + if let Ok(meta) = exr::meta::MetaData::read_from_buffered(std::io::Cursor::new(bytes), false) + && let Some(need) = planes_bytes(&meta, &|_| true) + { + self.account(slot, need.min(MAX_DECODE_BYTES)); + } + match decode(bytes, &|_| true) { + Ok(d) => Some(Arc::new(d)), + Err(Refused::TooLarge(why)) => { + log::warn!("media: {path}: {why}"); + None + } + Err(Refused::Unreadable) => None, + } + } + /// Drop least recently used files not in use until the rest fit the budget, keeping `newest`. fn evict(entries: &mut Vec, budget: usize, newest: &Slot) { while entries.iter().map(|e| e.bytes).sum::() > budget || entries.len() > CACHE_FILES { @@ -996,7 +1011,7 @@ mod tests { let path = "/474-shared-fallback.exr"; assert!(cache().get(path, Use::Channels, || None).is_none(), "a read that failed"); let op = AlphaOp::of(&Footage::default(), FloatCurve::Linear); - let img = layered_picture(path, bytes, op, true).unwrap(); + let img = layered_picture(path, bytes, &ReadFile::new(path, effectcraft_render::reads::FileStamp::Virtual), op, true).unwrap(); assert_eq!(img.get(1, 1), [0.5, 0.5, 0.5, 1.0]); } @@ -1174,7 +1189,8 @@ mod tests { for curve in [FloatCurve::Srgb, FloatCurve::Linear, FloatCurve::Gamma24] { let op = AlphaOp::of(&Footage { alpha, premul_color: [0.2, 0.4, 0.6], ..Default::default() }, curve); let want = crate::convert::dynamic_to_image(&img, op); - let got = cached_picture(&path, bytes.as_slice().into(), op).unwrap(); + let got = cached_picture(&path, bytes.as_slice().into(), &ReadFile::new(path.as_str(), effectcraft_render::reads::FileStamp::Virtual), op) + .unwrap(); assert_eq!((got.width, got.height), (want.width, want.height)); assert_eq!(bits(&got), bits(&want), "file {k} {alpha:?} {curve:?}"); } diff --git a/crates/media/src/lib.rs b/crates/media/src/lib.rs index 31478f111..0b509c45f 100644 --- a/crates/media/src/lib.rs +++ b/crates/media/src/lib.rs @@ -25,6 +25,7 @@ mod layered; pub use layered::vector_doc; mod pool; mod probe; +mod reads; mod stream; mod wav_markers; mod webp_anim; @@ -85,7 +86,15 @@ pub fn is_importable(path: &std::path::Path) -> bool { /// A whole file's bytes, refusing anything that isn't a regular file: a project can name /// `/dev/zero` or a FIFO as footage, and reading those never ends (#2134). pub(crate) fn read_regular_file(path: &std::path::Path) -> std::io::Result> { + read_regular_file_stamped(path).map(|(bytes, _)| bytes) +} + +/// [`read_regular_file`] with the file's identity, from the metadata of the open file (no +/// second look at the path). +pub(crate) fn read_regular_file_stamped(path: &std::path::Path) -> std::io::Result<(Vec, effectcraft_render::reads::FileStamp)> { use std::io::Read; + #[cfg(test)] + count_open(path); let mut file = std::fs::File::open(path)?; let meta = file.metadata()?; if !meta.is_file() { @@ -95,7 +104,22 @@ pub(crate) fn read_regular_file(path: &std::path::Path) -> std::io::Result> = std::sync::Mutex::new(Vec::new()); + +/// Count an open of a file (tests: which files a render touched on disk). +#[cfg(test)] +pub(crate) fn count_open(path: &std::path::Path) { + OPENS.lock().unwrap_or_else(std::sync::PoisonError::into_inner).push(path.to_path_buf()); +} + +/// How many times files under `dir` were opened so far (tests). +#[cfg(test)] +pub(crate) fn opens_under(dir: &std::path::Path) -> usize { + OPENS.lock().unwrap_or_else(std::sync::PoisonError::into_inner).iter().filter(|p| p.starts_with(dir)).count() } pub(crate) fn ext_of(path: &std::path::Path) -> String { diff --git a/crates/media/src/pool.rs b/crates/media/src/pool.rs index 9e10b4eb3..a60048b66 100644 --- a/crates/media/src/pool.rs +++ b/crates/media/src/pool.rs @@ -6,6 +6,7 @@ use std::sync::{Arc, Condvar, Mutex, OnceLock}; use effectcraft_project::{AlphaMode, Footage, FootageKind, ItemId}; use effectcraft_raster::{Image, Px}; +use effectcraft_render::reads::{FileStamp, ReadFile, ReadFiles, ReadLog}; use effectcraft_render::{FloatCurve, FootageSource}; use effectcraft_time::{FrameRate, TICKS_PER_SECOND, Tick}; use filmcraft_media::{FrameRequest, SharedSource}; @@ -14,6 +15,7 @@ use image::metadata::Orientation; use crate::convert::{AlphaOp, dynamic_to_image, frame_to_image_in, frame_to_image_scaled, turned}; use crate::downmix::Order; use crate::gif_anim::{self, Anim}; +use crate::reads; use crate::{MediaError, Result}; /// Default frame-cache budget: 1 GiB of decoded frames. @@ -53,6 +55,8 @@ struct Key { struct Entry { img: Arc, + /// The files the frame was decoded from (see [`crate::reads`]). + files: Arc, stamp: u64, bytes: usize, } @@ -106,18 +110,20 @@ struct Lru { } impl Lru { - fn get(&mut self, k: &Key) -> Option> { + /// The cached image and its read files for `k`, marking the entry as most recently used. + fn get(&mut self, k: &Key) -> Option<(Arc, Arc)> { let e = self.map.get_mut(k)?; self.order.remove(&e.stamp); self.clock += 1; e.stamp = self.clock; self.order.insert(e.stamp, k.clone()); - Some(e.img.clone()) + Some((e.img.clone(), e.files.clone())) } - fn insert(&mut self, k: Key, img: Arc, budget: usize) { + /// Stores an image with its read files under `k` and evicts the least recently used entries until the cache fits `budget` bytes. + fn insert(&mut self, k: Key, img: Arc, files: Arc, budget: usize) { let bytes = img.data.len() * std::mem::size_of::() + 64; self.clock += 1; - if let Some(old) = self.map.insert(k.clone(), Entry { img, stamp: self.clock, bytes }) { + if let Some(old) = self.map.insert(k.clone(), Entry { img, files, stamp: self.clock, bytes }) { self.order.remove(&old.stamp); self.bytes -= old.bytes; } @@ -180,8 +186,9 @@ struct CacheState { } /// A movie/audio source by path ([`Opened`]), opened by the first caller while the others wait -/// for it (`None`: failed to open; not retried until `forget`). -type SourceSlot = Arc>>; +/// for it (`None`: failed to open; not retried until `forget`), with the file's identity as +/// opened. +type SourceSlot = Arc, ReadFile)>>; /// An opened movie/audio source, the turn its picture is shown with and the order its decoded /// audio channels arrive in. @@ -211,7 +218,7 @@ fn channel_order(src: &SharedSource, header: Option<&[u8]>, file: Option<&dyn fi } /// An animated GIF by path, as [`SourceSlot`] (the error message when it failed to load). -type GifSlot = Arc, String>>>; +type GifSlot = Arc, String>, ReadFile)>>; struct Inner { /// Opened movie/audio sources by path. @@ -220,8 +227,9 @@ struct Inner { opened: AtomicU64, /// In-memory files registered with `add_bytes` (web builds, tests). files: Mutex>>, - /// Parsed 3D models by path (`None`: failed to load; not retried until `forget`). - models: Mutex>>>, + /// Parsed 3D models by path (`None`: failed to load; not retried until `forget`), with the + /// files read for them (the model's and the resources it names). + models: Mutex>, Arc)>>, /// Decoded animated GIFs and WebPs by path, loaded by the first caller while the others wait (an /// `Err` is not retried until `forget`). gifs: Mutex, GifSlot>>, @@ -439,11 +447,13 @@ impl MediaPool { } /// The conformed-audio file of `path` at `rate` (named by a hash of the path, size and - /// modification time, so an edited file conforms again, and of `CONFORM_VERSION`). + /// modification time, so an edited file conforms again, and of `CONFORM_VERSION`). Notes + /// `path` as read with that identity (see [`crate::reads`]): its samples come from it. pub fn conformed_path(&self, path: &str, rate: u32) -> Option { use std::hash::{Hash, Hasher}; let folder = lock(&self.inner.conform).clone()?; let meta = std::fs::metadata(path).ok()?; + reads::note(ReadFile::new(path, FileStamp::of_metadata(&meta))); let mut h = std::collections::hash_map::DefaultHasher::new(); (CONFORM_VERSION, path, meta.len(), meta.modified().ok()).hash(&mut h); Some(folder.join(format!("{:016x}_{rate}.ecaf", h.finish()))) @@ -612,16 +622,20 @@ impl Inner { /// A 3D model file and its sibling resources (buffers, textures, MTL files), parsed once. fn model(&self, path: &str) -> Option> { - if let Some(m) = lock(&self.models).get(path) { - return m.clone(); + let found = lock(&self.models).get(path).cloned(); + if let Some((m, files)) = found { + reads::note_all(&files); + return m; } - let loaded = self.read(path).map_err(|e| e.to_string()).and_then(|bytes| { - // Files the model names are read only when local or on the model's own network share. - let resolve = |uri: &str| -> Option> { - let p = craft_docpath::resolve_absolute(uri, Some(std::path::Path::new(path))).ok()?; - self.read(&p.to_string_lossy()).ok().map(|b| b.to_vec()) - }; - effectcraft_model::load(path, &bytes, &resolve).map_err(|e| e.to_string()) + let (loaded, files) = reads::captured(|| { + self.read(path).map_err(|e| e.to_string()).and_then(|bytes| { + // Files the model names are read only when local or on the model's own network share. + let resolve = |uri: &str| -> Option> { + let p = craft_docpath::resolve_absolute(uri, Some(std::path::Path::new(path))).ok()?; + self.read(&p.to_string_lossy()).ok().map(|b| b.to_vec()) + }; + effectcraft_model::load(path, &bytes, &resolve).map_err(|e| e.to_string()) + }) }); let m = match loaded { Ok(m) => Some(Arc::new(m)), @@ -630,14 +644,29 @@ impl Inner { None } }; - lock(&self.models).entry(path.to_string()).or_insert(m).clone() + let (m, files) = lock(&self.models).entry(path.to_string()).or_insert((m, Arc::new(files))).clone(); + reads::note_all(&files); + m } + /// The bytes of the file at `path`, noted as read (see [`crate::reads`]). fn read(&self, path: &str) -> Result> { - if let Some(b) = lock(&self.files).get(path) { - return Ok(b.clone()); + let (bytes, file) = self.read_file(path); + reads::note(file); + bytes + } + + /// The bytes of the file at `path` and its identity as read ([`FileStamp::Missing`] when it + /// can't be read), not noted. + fn read_file(&self, path: &str) -> (Result>, ReadFile) { + let in_memory = lock(&self.files).get(path).cloned(); + if let Some(b) = in_memory { + return (Ok(b), ReadFile::new(path, FileStamp::Virtual)); + } + match crate::read_regular_file_stamped(std::path::Path::new(path)) { + Ok((bytes, stamp)) => (Ok(bytes.into()), ReadFile::new(path, stamp)), + Err(e) => (Err(MediaError::Io(format!("{path}: {e}"))), ReadFile::new(path, FileStamp::Missing)), } - crate::read_regular_file(std::path::Path::new(path)).map(Into::into).map_err(|e| MediaError::Io(format!("{path}: {e}"))) } /// The opened movie/audio source for `path` ([`Opened`]). The first caller opens it, outside @@ -645,35 +674,42 @@ impl Inner { /// files are decoded whole); callers asking for the same file meanwhile wait for that instead /// of opening it again: a preview's frame workers, audio feeder, conform and waveform threads /// each decoded a long FLAC in full at once (#408). + /// Each call notes the file as read (see [`crate::reads`]), with its identity as opened. fn opened(&self, path: &Arc) -> Option { let slot = lock(&self.sources).entry(path.clone()).or_default().clone(); - slot.get_or_init(|| { - self.opened.fetch_add(1, Ordering::Relaxed); - // Files on disk are read in place (the index, then samples on demand) rather than - // whole; in-memory files (`add_bytes`) and wasm32 builds open from bytes. - let in_memory = lock(&self.files).contains_key(&**path); - let file = std::path::Path::new(&**path); - let in_place = if in_memory { None } else { crate::stream::open_source(file) }; - let in_place = in_place.map(|src| { - let (header, reader) = (crate::stream::movie_header(file), crate::stream::file_reader(file)); - src.map(|src| Opened::new(src, header.as_deref(), reader.as_deref())) + let (opened, file) = slot.get_or_init(|| self.open(path)); + reads::note(file.clone()); + opened.clone() + } + + /// Open the movie/audio file at `path` (see [`Inner::opened`]), with its identity as opened. + fn open(&self, path: &Arc) -> (Option, ReadFile) { + self.opened.fetch_add(1, Ordering::Relaxed); + // Files on disk are read in place (the index, then samples on demand) rather than + // whole; in-memory files (`add_bytes`) and wasm32 builds open from bytes. + let in_memory = lock(&self.files).contains_key(&**path); + let file = std::path::Path::new(&**path); + let in_place = if in_memory { None } else { crate::stream::open_source(file) }; + let in_place = in_place.map(|(src, stamp)| { + let (header, reader) = (crate::stream::movie_header(file), crate::stream::file_reader(file)); + (src.map(|src| Opened::new(src, header.as_deref(), reader.as_deref())), ReadFile::new(path.clone(), stamp)) + }); + let (opened, read) = in_place.unwrap_or_else(|| { + let (bytes, read) = self.read_file(path); + let opened = bytes.and_then(|bytes| { + let name = std::path::Path::new(&**path).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default(); + let src = filmcraft_codecs::open_bytes(&name, bytes.clone()).map_err(MediaError::from)?; + Ok(Opened::new(src, Some(&bytes), Some(&filmcraft_media::reader::MemReader(bytes.clone())))) }); - let opened = in_place.unwrap_or_else(|| { - self.read(path).and_then(|bytes| { - let name = std::path::Path::new(&**path).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default(); - let src = filmcraft_codecs::open_bytes(&name, bytes.clone()).map_err(MediaError::from)?; - Ok(Opened::new(src, Some(&bytes), Some(&filmcraft_media::reader::MemReader(bytes.clone())))) - }) - }); - match opened { - Ok(s) => Some(s), - Err(e) => { - self.note_problem(path, "", &e); - None - } + (opened, read) + }); + match opened { + Ok(s) => (Some(s), read), + Err(e) => { + self.note_problem(path, "", &e); + (None, read) } - }) - .clone() + } } /// Remember why the movie at `path` cannot be shown (`codec` is the footage's, when known) @@ -694,13 +730,15 @@ impl Inner { /// map's lock; callers asking for the same file meanwhile wait for that. fn gif(&self, path: &Arc) -> Result> { let slot = lock(&self.gifs).entry(path.clone()).or_default().clone(); - let loaded = slot.get_or_init(|| { - let loaded = self.read(path).and_then(|bytes| Anim::load(&bytes)); - loaded.map(Arc::new).map_err(|e| { + let (loaded, file) = slot.get_or_init(|| { + let (bytes, file) = self.read_file(path); + let loaded = bytes.and_then(|bytes| Anim::load(&bytes)).map(Arc::new).map_err(|e| { log::warn!("media: cannot decode {path}: {e}"); e.to_string() - }) + }); + (loaded, file) }); + reads::note(file.clone()); loaded.clone().map_err(|e| MediaError::Decode(format!("{path}: {e}"))) } @@ -783,19 +821,15 @@ impl Inner { let mut c = lock(&self.cache); // sequential playback of a movie: read the next frame ahead if playback && movie { - let prev = c.last.insert(loc.key.path.clone(), loc.key.frame); - if prev == Some(loc.key.frame - 1) && self.read_ahead.load(Ordering::Relaxed) { - let next_t = t + footage.frame_rate.frame_duration(); - let mut next = Self::locate(footage, next_t, float); - next.key.size = loc.key.size; - if next.key != loc.key && !c.lru.map.contains_key(&next.key) && !c.inflight.contains(&next.key) { - self.prefetch(footage, next_t, size, float); - } - } + self.prefetch_next(&mut c, &loc, footage, t, size, float); } + // (Each exit notes the files the frame came from, see `crate::reads`; a cached frame + // notes those it was decoded from, without touching them.) loop { - if let Some(img) = c.lru.get(&loc.key) { + if let Some((img, files)) = c.lru.get(&loc.key) { self.hits.fetch_add(1, Ordering::Relaxed); + drop(c); + reads::note_all(&files); return Ok(img); } if !c.inflight.contains(&loc.key) { @@ -808,7 +842,9 @@ impl Inner { if rayon::current_thread_index().is_some() { self.misses.fetch_add(1, Ordering::Relaxed); drop(c); - return Ok(Arc::new(self.decode(&loc, footage)?)); + let (img, files) = reads::captured(|| self.decode(&loc, footage)); + reads::note_all(&files); + return Ok(Arc::new(img?)); } c = self.done.wait(c).unwrap_or_else(std::sync::PoisonError::into_inner); } @@ -816,11 +852,26 @@ impl Inner { c.inflight.insert(loc.key.clone()); drop(c); let _guard = Inflight { inner: self, key: loc.key.clone() }; - let img = Arc::new(self.decode(&loc, footage)?); - lock(&self.cache).lru.insert(loc.key, img.clone(), self.budget()); + let (img, files) = reads::captured(|| self.decode(&loc, footage)); + reads::note_all(&files); + let img = Arc::new(img?); + lock(&self.cache).lru.insert(loc.key, img.clone(), Arc::new(files), self.budget()); Ok(img) } + /// Sequential playback of a movie (`loc`, at `t`): read the frame after it ahead. + fn prefetch_next(self: &Arc, c: &mut CacheState, loc: &Loc, footage: &Footage, t: Tick, size: Option<(u32, u32)>, float: FloatCurve) { + let prev = c.last.insert(loc.key.path.clone(), loc.key.frame); + if prev == Some(loc.key.frame - 1) && self.read_ahead.load(Ordering::Relaxed) { + let next_t = t + footage.frame_rate.frame_duration(); + let mut next = Self::locate(footage, next_t, float); + next.key.size = loc.key.size; + if next.key != loc.key && !c.lru.map.contains_key(&next.key) && !c.inflight.contains(&next.key) { + self.prefetch(footage, next_t, size, float); + } + } + } + #[cfg(not(target_arch = "wasm32"))] fn prefetch(self: &Arc, footage: &Footage, t: Tick, size: Option<(u32, u32)>, float: FloatCurve) { let (me, f) = (self.clone(), footage.clone()); @@ -856,13 +907,17 @@ impl Inner { } } + /// Decodes the still image at `loc` and applies the footage alpha and float handling. + /// A placeholder path decodes to colour bars. fn decode_still(&self, loc: &Loc, footage: &Footage) -> Result { let op = AlphaOp::of(footage, loc.float); let path = &loc.key.path; if &**path == PLACEHOLDER { return Ok(colour_bars(footage.width, footage.height)); } - let bytes = self.read(path)?; + let (bytes, file) = self.read_file(path); + reads::note(file.clone()); + let bytes = bytes?; if let Some(img) = crate::dpx::decode(path, &bytes)? { return Ok(dynamic_to_image(&img, op)); } @@ -880,7 +935,7 @@ impl Inner { let shared = lock(&self.aux_footage).contains(&footage.path); if shared && path.to_ascii_lowercase().ends_with(".exr") - && let Some(img) = crate::exr_channels::cached_picture(path, bytes.clone(), op) + && let Some(img) = crate::exr_channels::cached_picture(path, bytes.clone(), &file, op) { return Ok(img); } @@ -889,7 +944,7 @@ impl Inner { match crate::probe::load_oriented(&bytes, crate::still_format(path, &bytes)) { Ok(img) => Ok(dynamic_to_image(&img, op)), // A multi-layer OpenEXR file without an unnamed RGB layer: its colour layer. - Err(e) => crate::exr_channels::layered_picture(path, bytes, op, shared) + Err(e) => crate::exr_channels::layered_picture(path, bytes, &file, op, shared) .map_err(|why| MediaError::Decode(format!("{path}: {}", why.unwrap_or_else(|| e.to_string())))), } } @@ -957,6 +1012,13 @@ impl FootageSource for MediaPool { fn cancellable(&self, cancel: &Arc, f: &mut dyn FnMut()) { filmcraft_media::cancel::with_cancel(cancel, f) } + /// Every read of a file notes it (see [`crate::reads`]): a frame's image file or sequence + /// frame, a movie, a model and the files it names, an EXR's channels, a movie's audio. A + /// frame (or other entry) served from memory notes the files it was made of, as they were + /// when read, without reading them again. A missing sequence frame (colour bars) reads none. + fn recording(&self, reads: &ReadLog, f: &mut dyn FnMut()) { + reads::recording(reads, f) + } fn frame(&self, item: ItemId, footage: &Footage, t: Tick) -> Option> { self.frame_sized(item, footage, t, None, FloatCurve::Srgb) } @@ -1207,13 +1269,13 @@ mod tests { let k = |i| Key { path: "a".into(), frame: i, interp: 0, matte: [0; 3], size: (0, 0), nominal: (0, 0) }; let budget = 3 * (4096 + 64); for i in 0..10 { - c.insert(k(i), img(), budget); + c.insert(k(i), img(), Arc::default(), budget); } assert_eq!(c.map.len(), 3); assert!(c.get(&k(9)).is_some() && c.get(&k(6)).is_none()); // touching 7 makes 8 the oldest c.get(&k(7)); - c.insert(k(10), img(), budget); + c.insert(k(10), img(), Arc::default(), budget); assert!(c.get(&k(7)).is_some() && c.get(&k(8)).is_none()); assert_eq!(c.spare.len(), MAX_SPARE); assert_eq!(c.take_spare(256).len(), 256); diff --git a/crates/media/src/reads.rs b/crates/media/src/reads.rs new file mode 100644 index 000000000..43ea209b8 --- /dev/null +++ b/crates/media/src/reads.rs @@ -0,0 +1,120 @@ +//! Which files the [`MediaPool`](crate::MediaPool) reads for a render +//! ([`FootageSource::recording`](effectcraft_render::FootageSource::recording)). +//! +//! Every read of a file notes it, with the identity it had when read, in the innermost scope open +//! on this thread. The pool's caches (decoded frames, opened movies, GIFs, models, EXR channels) +//! keep what their entries were made of and note it again on each hit, so a frame served from +//! memory reports its file without touching the disk. +//! +//! The scopes are per thread: a read noted while a render's scope is open on the thread belongs +//! to that render. A thread waiting inside a decode can run another job meanwhile (rayon); that +//! job's reads go to its own scope when it opens one, and otherwise to the scope below it, which +//! then lists a file more than it read (never fewer). + +use std::cell::RefCell; + +use effectcraft_render::reads::{ReadFile, ReadFiles, ReadLog}; + +/// Scopes nested deeper than this are not opened (a thread that keeps taking jobs while it waits +/// cannot pile them up without bound): their reads go to the scope below, and they come back +/// incomplete. +const MAX_DEPTH: usize = 64; + +thread_local! { + /// The open scopes on this thread, innermost last, each with the files noted in it. + static SCOPES: RefCell> = const { RefCell::new(Vec::new()) }; +} + +/// Note `file` in the innermost open scope on this thread (nothing when none is open). +pub(crate) fn note(file: ReadFile) { + let _ = SCOPES.try_with(|s| { + if let Ok(mut s) = s.try_borrow_mut() + && let Some(top) = s.last_mut() + { + top.add(file); + } + }); +} + +/// Note every file of `files` in the innermost open scope on this thread. +pub(crate) fn note_all(files: &ReadFiles) { + if files.is_empty() && files.is_complete() { + return; + } + let _ = SCOPES.try_with(|s| { + if let Ok(mut s) = s.try_borrow_mut() + && let Some(top) = s.last_mut() + { + top.extend(files); + } + }); +} + +/// Closes the scope it opened, also when what runs inside panics: its files go to `out`. +struct Scope<'a> { + out: Out<'a>, + opened: bool, +} + +enum Out<'a> { + /// A render's log ([`recording`]). + Log(&'a ReadLog), + /// The caller's ([`captured`]). + Files(&'a mut ReadFiles), +} + +impl Scope<'_> { + /// Starts collecting the files read on this thread into `out`. + /// At the nesting limit the scope stays closed and reports an incomplete list. + fn open(out: Out<'_>) -> Scope<'_> { + let opened = SCOPES + .try_with(|s| match s.try_borrow_mut() { + Ok(mut s) if s.len() < MAX_DEPTH => { + s.push(ReadFiles::default()); + true + } + _ => false, + }) + .unwrap_or(false); + Scope { out, opened } + } +} + +impl Drop for Scope<'_> { + /// Ends the scope and hands the collected files to its output, marked incomplete when the scope could not be opened. + fn drop(&mut self) { + let files = if self.opened { SCOPES.try_with(|s| s.try_borrow_mut().ok().and_then(|mut s| s.pop())).ok().flatten() } else { None }; + // A scope that could not open saw nothing: what it made can't name its files. + let files = files.unwrap_or_else(|| { + let mut f = ReadFiles::default(); + f.mark_incomplete(); + f + }); + match &mut self.out { + Out::Log(log) => log.note_all(&files), + Out::Files(out) => out.extend(&files), + } + } +} + +/// Run `f` with the files it reads on this thread noted in `log` +/// ([`FootageSource::recording`](effectcraft_render::FootageSource::recording)). +pub(crate) fn recording(log: &ReadLog, f: &mut dyn FnMut()) { + let _scope = Scope::open(Out::Log(log)); + f(); +} + +/// Run `f` and return what it returns with the files it read on this thread (to keep with a +/// cache entry made of them). They are not noted in the enclosing scope: the caller notes them, +/// as it does on each later hit of the entry. +pub(crate) fn captured(f: impl FnOnce() -> T) -> (T, ReadFiles) { + let mut files = ReadFiles::default(); + let out = { + let _scope = Scope::open(Out::Files(&mut files)); + f() + }; + (out, files) +} + +#[cfg(test)] +mod tests; diff --git a/crates/media/src/reads/tests.rs b/crates/media/src/reads/tests.rs new file mode 100644 index 000000000..5dae8415a --- /dev/null +++ b/crates/media/src/reads/tests.rs @@ -0,0 +1,390 @@ +//! The files a render reads, as the media pool reports them (#3184): exactly the files the frame +//! was made of, also when its pixels come from memory. + +use std::path::{Path, PathBuf}; + +use effectcraft_color::Label; +use effectcraft_project::build::{self, Ids}; +use effectcraft_project::{Comp, Footage, FootageKind, ItemId, ItemKind, Layer, LayerSource, Project, Solid, Value}; +use effectcraft_render::reads::{FileStamp, ReadFiles, ReadLog}; +use effectcraft_render::{LayerCache, RenderOpts, Renderer}; +use effectcraft_time::FrameRate; + +use crate::MediaPool; + +const RATE: FrameRate = FrameRate::FPS_30; +const SIZE: (u32, u32) = (16, 8); + +/// A fresh folder for test `name` (on the build drive, not the system temp folder). +fn folder(name: &str) -> PathBuf { + let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join(format!("../../target/test-reads-{name}-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + dir +} + +/// A PNG at `path`, a flat grey of `level`. +fn png(path: &Path, level: u8) -> String { + image::RgbaImage::from_pixel(SIZE.0, SIZE.1, image::Rgba([level, level, level, 255])).save(path).unwrap(); + path.to_string_lossy().to_string() +} + +/// An image sequence of `n` PNG frames in `dir`. +fn sequence(dir: &Path, n: usize) -> Footage { + let files: Vec = (0..n).map(|i| png(&dir.join(format!("seq_{i:04}.png")), 20 + i as u8 * 10)).collect(); + let mut f = Footage { kind: FootageKind::Sequence, sequence: files, frame_rate: RATE, ..crate::probe(dir.join("seq_0000.png")).unwrap() }; + f.sync_sequence_duration(); + f +} + +/// A still footage item of `path`. +fn still(path: &Path, level: u8) -> Footage { + png(path, level); + crate::probe(path).unwrap() +} + +fn comp() -> Comp { + Comp::new(SIZE.0, SIZE.1, RATE, RATE.tick_of(10)) +} + +fn footage_layer(p: &mut Project, comp: &Comp, name: &str, f: Footage) -> Layer { + let item = p.add_item(name, Label::Aqua, None, ItemKind::Footage(f)); + build::layer(p, comp, name, LayerSource::Footage { item }, SIZE, Some(comp.duration)) +} + +fn add_comp(p: &mut Project, name: &str, mut comp: Comp, layers: Vec) -> ItemId { + comp.layers = layers.into(); + p.add_item(name, Label::Sandstone, None, ItemKind::Comp(comp.into())) +} + +/// Render frame `frame` of `comp` with `pool` and `cache`: the picture's top-left pixel and the +/// files the render reports. +fn render(p: &Project, pool: &MediaPool, cache: &LayerCache, comp: ItemId, frame: i64) -> ([f32; 4], ReadFiles) { + let log = ReadLog::new(); + let mut r = Renderer::new(p, pool, RenderOpts::default()); + r.cache = Some(cache); + r.reads = Some(&log); + let img = r.comp_frame(comp, RATE.tick_of(frame)); + (img.get(0, 0), log.into_files()) +} + +fn paths(files: &ReadFiles) -> Vec { + files.files().iter().map(|f| f.path.to_string()).collect() +} + +/// Every listed file has the identity it has on disk now. +fn assert_stamps_match_disk(files: &ReadFiles) { + for f in files.files() { + assert_eq!(Some(f.stamp), FileStamp::native(&f.path), "{}", f.path); + } +} + +/// (a) One frame of a comp with an image-sequence layer reads that frame's file and nothing else +/// of the sequence; a large sequence in the project that no layer uses adds nothing, not even a +/// look at its files. +#[test] +fn a_sequence_frame_reports_only_its_own_file() { + let dir = folder("sequence"); + let unused_dir = dir.join("unused"); + let mut p = Project::default(); + let c = comp(); + let seq = sequence(&dir, 5); + let (frame_2, frame_4) = (seq.sequence[2].clone(), seq.sequence[4].clone()); + let layer = footage_layer(&mut p, &c, "Seq", seq); + // 5000 frames nobody shows (they don't even exist). + let unused = Footage { + kind: FootageKind::Sequence, + sequence: (0..5000).map(|i| unused_dir.join(format!("big_{i:05}.exr")).to_string_lossy().to_string()).collect(), + frame_rate: RATE, + width: SIZE.0, + height: SIZE.1, + has_video: true, + ..Default::default() + }; + p.add_item("Unused", Label::Aqua, None, ItemKind::Footage(unused)); + let cid = add_comp(&mut p, "C", c, vec![layer]); + let (pool, cache) = (MediaPool::new(), LayerCache::default()); + let opened = crate::opens_under(&dir); + let (px, files) = render(&p, &pool, &cache, cid, 2); + assert!((px[0] - 40.0 / 255.0).abs() < 0.01, "frame 2 shows: {px:?}"); + assert_eq!(paths(&files), [frame_2]); + assert!(files.is_complete()); + assert_stamps_match_disk(&files); + assert_eq!(crate::opens_under(&dir) - opened, 1, "one file opened: the frame's"); + assert_eq!(crate::opens_under(&unused_dir), 0, "the unused sequence was not looked at"); + // Another frame reads its own file, also through the viewer's wrapper of the pool. + let viewer = effectcraft_render::CancellableFootage { inner: &pool, cancel: Default::default() }; + let log = ReadLog::new(); + let mut r = Renderer::new(&p, &viewer, RenderOpts::default()); + r.cache = Some(&cache); + r.reads = Some(&log); + r.comp_frame(cid, RATE.tick_of(4)); + let files = log.into_files(); + assert_eq!(paths(&files), [frame_4]); + assert!(files.is_complete()); + let _ = std::fs::remove_dir_all(&dir); +} + +/// (b) A precomp reports the files of what it draws, and an effect that reads another layer +/// reports that layer's files (the layer itself is hidden: its pixels come only through the +/// effect). +#[test] +fn precomps_and_layers_read_by_effects_report_their_files() { + let dir = folder("nested"); + let mut p = Project::default(); + let c = comp(); + let seq = sequence(&dir, 4); + let nested_frame = seq.sequence[3].clone(); + let inner_layer = footage_layer(&mut p, &c, "Seq", seq); + let inner = add_comp(&mut p, "Inner", c.clone(), vec![inner_layer]); + let pre = build::layer(&mut p, &c, "Inner", LayerSource::Comp { item: inner }, SIZE, Some(c.duration)); + let matte_path = dir.join("matte.png"); + let mut matte = footage_layer(&mut p, &c, "Matte", still(&matte_path, 255)); + matte.switches.video = false; + let sid = p.add_item("S", Label::Red, None, ItemKind::Solid(Solid { color: [1.0, 0.0, 0.0], width: SIZE.0, height: SIZE.1, pixel_aspect: 1.0 })); + let mut solid = build::layer(&mut p, &c, "S", LayerSource::Solid { item: sid }, SIZE, Some(c.duration)); + let spec = effectcraft_effects::find("ec.channel.setmatte").unwrap(); + let mut next = p.next_id; + let mut fx = effectcraft_effects::instantiate(spec, &mut Ids(&mut next), spec.name, [SIZE.0 as f64, SIZE.1 as f64]); + p.next_id = next; + fx.prop_mut("takeMatteFromLayer").unwrap().value = Value::Layer(Some(matte.id.0)); + solid.props.sub_mut("effects").unwrap().children.push(fx.into()); + let cid = add_comp(&mut p, "Outer", c, vec![solid, matte, pre]); + let (pool, cache) = (MediaPool::new(), LayerCache::default()); + let (_, files) = render(&p, &pool, &cache, cid, 3); + let mut want = vec![matte_path.to_string_lossy().to_string(), nested_frame]; + want.sort(); + assert_eq!(paths(&files), want); + assert!(files.is_complete()); + assert_stamps_match_disk(&files); + let _ = std::fs::remove_dir_all(&dir); +} + +/// (c) A frame rendered again comes from memory (the sequence frame from the media pool, the +/// still layer from the layer cache) and reports the same files, with the identities they had +/// when read, without opening anything: here the files are even gone by then. +#[test] +fn a_frame_served_from_memory_reports_its_files_without_touching_them() { + let dir = folder("memory"); + let mut p = Project::default(); + let c = comp(); + // The sequence at half opacity over the still: both show. + let mut seq = footage_layer(&mut p, &c, "Seq", sequence(&dir, 3)); + seq.props.prop_mut("transform/opacity").unwrap().value = Value::Scalar(50.0); + let plate = footage_layer(&mut p, &c, "Plate", still(&dir.join("plate.png"), 128)); + let cid = add_comp(&mut p, "C", c, vec![seq, plate]); + let (pool, cache) = (MediaPool::new(), LayerCache::default()); + let (px, first) = render(&p, &pool, &cache, cid, 1); + assert_eq!(first.len(), 2, "{:?}", paths(&first)); + assert_stamps_match_disk(&first); + std::fs::remove_dir_all(&dir).unwrap(); + let opened = crate::opens_under(&dir); + let hits = cache.stats().hits; + let (again_px, again) = render(&p, &pool, &cache, cid, 1); + assert_eq!(again_px, px, "the same picture"); + assert_eq!(again, first, "the same files, as they were when read"); + assert!(cache.stats().hits > hits, "the still layer came from the layer cache"); + // The media pool alone (a new layer cache) reports them too. + let (_, from_pool) = render(&p, &pool, &LayerCache::default(), cid, 1); + assert_eq!(from_pool, first); + assert_eq!(crate::opens_under(&dir), opened, "nothing was opened on disk"); +} + +// ---------------------------------------------------------------- layer entries on disk (#3184) + +use std::sync::Arc; + +use effectcraft_render::disk_cache::{DiskCache, Kind}; + +/// A "session": a new media pool and layer cache over the disk cache in `cache` (opened anew, +/// as after a restart), writing every layer buffer however quick to render. +fn session(cache: &Path) -> (MediaPool, LayerCache, Arc) { + let dc = DiskCache::open(cache, 1 << 30).unwrap(); + dc.set_min_layer_ms(0); + let lc = LayerCache::default(); + lc.set_disk(Some(dc.clone())); + (MediaPool::new(), lc, dc) +} + +/// Give `path` a later modification time, so a rewrite within the clock's resolution counts. +fn touch_later(path: &Path) { + let t = std::fs::metadata(path).unwrap().modified().unwrap() + std::time::Duration::from_secs(7); + std::fs::File::options().append(true).open(path).unwrap().set_modified(t).unwrap(); +} + +/// Two still plates (the upper one at half opacity, so both show), and a 5000-frame sequence +/// in the project that no layer uses (its files don't even exist). +fn plates(dir: &Path) -> (Project, ItemId, PathBuf) { + let mut p = Project::default(); + let c = comp(); + let a = dir.join("a.png"); + let mut top = footage_layer(&mut p, &c, "A", still(&a, 60)); + top.props.prop_mut("transform/opacity").unwrap().value = Value::Scalar(50.0); + let bottom = footage_layer(&mut p, &c, "B", still(&dir.join("b.png"), 200)); + let unused = dir.join("unused"); + let seq = Footage { + kind: FootageKind::Sequence, + sequence: (0..5000).map(|i| unused.join(format!("big_{i:05}.exr")).to_string_lossy().to_string()).collect(), + frame_rate: RATE, + width: SIZE.0, + height: SIZE.1, + has_video: true, + ..Default::default() + }; + p.add_item("Unused", Label::Aqua, None, ItemKind::Footage(seq)); + let cid = add_comp(&mut p, "C", c, vec![top, bottom]); + (p, cid, a) +} + +/// Correct and no scan: after a restart, only the layer buffer whose source file changed is +/// rendered again (only that file is opened); the other comes from disk with its file list, so +/// the frame's list is complete again (its frame entry can be stored). The disk cache checks +/// exactly the files its entries list, never the unused sequence. The re-rendered buffer +/// replaces its entry: the next restart opens nothing. +#[test] +fn a_changed_file_renders_only_the_layer_buffers_that_read_it_again() { + let dir = folder("layer-disk"); + let (src, cache) = (dir.join("src"), dir.join("cache")); + std::fs::create_dir_all(&src).unwrap(); + let (p, cid, a) = plates(&src); + let (pool, lc, dc) = session(&cache); + let (px, files) = render(&p, &pool, &lc, cid, 0); + assert!(files.is_complete() && files.len() == 2, "{:?}", paths(&files)); + dc.flush(); + let entries = dc.keys(Kind::Layer).len(); + assert!(entries >= 2, "both plates' buffers are on disk: {entries}"); + drop((pool, lc, dc)); + + // Restart without a change: everything from disk, nothing opened, a complete list. + let (pool, lc, dc) = session(&cache); + let opened = crate::opens_under(&src); + let (again, files_again) = render(&p, &pool, &lc, cid, 0); + assert_eq!(again, px); + assert_eq!(files_again, files, "the files of the entries, as they were read"); + assert!(files_again.is_complete(), "a frame made of buffers from disk can be stored"); + assert_eq!(crate::opens_under(&src), opened, "nothing opened"); + let checks = dc.file_checks(); + assert!(checks >= 2 && checks as usize <= entries, "one check per entry used: {checks} of {entries}"); + drop((pool, lc, dc)); + + // a.png gets new pixels: only the top plate renders again. + png(&a, 120); + touch_later(&a); + let (pool, lc, dc) = session(&cache); + let opened = crate::opens_under(&src); + let (changed, files_changed) = render(&p, &pool, &lc, cid, 0); + assert_ne!(changed, px, "the new pixels show"); + assert_eq!(crate::opens_under(&src) - opened, 1, "only the changed file is read"); + assert!(files_changed.is_complete() && files_changed.len() == 2); + assert_stamps_match_disk(&files_changed); + assert!(dc.file_checks() as usize <= entries, "only listed files are checked"); + assert_eq!(crate::opens_under(&src.join("unused")), 0); + dc.flush(); + drop((pool, lc, dc)); + + // Its entry was replaced: the next restart opens nothing and shows the new pixels. + let (pool, lc, _dc) = session(&cache); + let opened = crate::opens_under(&src); + let (last, _) = render(&p, &pool, &lc, cid, 0); + assert_eq!(last, changed); + assert_eq!(crate::opens_under(&src), opened, "both from disk"); + let _ = std::fs::remove_dir_all(&dir); +} + +/// Two projects whose footage items have the same ids but name different files never share a +/// layer entry: the layer key names the item's path and settings. +#[test] +fn projects_with_the_same_item_ids_never_share_a_layer_entry() { + let dir = folder("layer-disk-projects"); + let (src, cache) = (dir.join("src"), dir.join("cache")); + std::fs::create_dir_all(&src).unwrap(); + let mut p = Project::default(); + let c = comp(); + let layer = footage_layer(&mut p, &c, "Plate", still(&src.join("one.png"), 40)); + let LayerSource::Footage { item } = layer.source else { panic!("a footage layer") }; + let cid = add_comp(&mut p, "C", c, vec![layer]); + let mut other = p.clone(); + other.item_mut(item).unwrap().kind = ItemKind::Footage(still(&src.join("two.png"), 220)); + let (pool, lc, dc) = session(&cache); + let (one, _) = render(&p, &pool, &lc, cid, 0); + dc.flush(); + drop((pool, lc, dc)); + let (pool, lc, dc) = session(&cache); + let hits = dc.stats().hits; + let (two, files) = render(&other, &pool, &lc, cid, 0); + assert!((two[0] - 220.0 / 255.0).abs() < 0.01, "the other project's own file shows: {two:?}"); + assert_ne!(two, one); + assert_eq!(dc.stats().hits, hits, "no entry of the first project is used"); + assert_eq!(paths(&files), [src.join("two.png").to_string_lossy().to_string()]); + let _ = std::fs::remove_dir_all(&dir); +} + +/// Safe: a damaged layer entry, a source file that is missing, one replaced by something +/// unreadable (a folder), and one back with other pixels never serve a stale buffer after a +/// restart; the damaged entry is rendered again, replaced and then used. +#[test] +fn missing_unreadable_files_and_damaged_layer_entries_never_serve_stale_buffers() { + let dir = folder("layer-disk-safe"); + let (src, cache) = (dir.join("src"), dir.join("cache")); + std::fs::create_dir_all(&src).unwrap(); + let mut p = Project::default(); + let c = comp(); + let path = src.join("plate.png"); + let layer = footage_layer(&mut p, &c, "Plate", still(&path, 90)); + let cid = add_comp(&mut p, "C", c, vec![layer]); + let (pool, lc, dc) = session(&cache); + let (shown, _) = render(&p, &pool, &lc, cid, 0); + assert!(shown[3] > 0.99, "the plate shows: {shown:?}"); + dc.flush(); + drop((pool, lc, dc)); + + // A damaged entry: a miss, deleted, rendered again and stored anew. + let layers = cache.join("v1").join(Kind::Layer.dir()); + for shard in std::fs::read_dir(&layers).unwrap().flatten() { + for f in std::fs::read_dir(shard.path()).unwrap().flatten() { + let mut d = std::fs::read(f.path()).unwrap(); + let n = d.len() / 2; + d[n] ^= 0x5a; + std::fs::write(f.path(), d).unwrap(); + } + } + let (pool, lc, dc) = session(&cache); + let opened = crate::opens_under(&src); + let (again, files) = render(&p, &pool, &lc, cid, 0); + assert_eq!(again, shown); + assert_eq!(crate::opens_under(&src) - opened, 1, "read again, not served from the damaged entry"); + assert!(files.is_complete()); + dc.flush(); + drop((pool, lc, dc)); + let (pool, lc, dc) = session(&cache); + let hits = dc.stats().hits; + assert_eq!(render(&p, &pool, &lc, cid, 0).0, shown); + assert!(dc.stats().hits > hits, "the rewritten entry is used"); + drop((pool, lc, dc)); + + // The file is gone: not the old plate. + std::fs::remove_file(&path).unwrap(); + let (pool, lc, dc) = session(&cache); + let hits = dc.stats().hits; + let (gone, files) = render(&p, &pool, &lc, cid, 0); + assert!(gone[3] < 0.01, "a missing file shows nothing, never the cached plate: {gone:?}"); + assert_eq!(dc.stats().hits, hits); + assert!(files.files().iter().all(|f| f.stamp == FileStamp::Missing), "{files:?}"); + dc.flush(); + drop((pool, lc, dc)); + + // Something unreadable at its path (a folder): still not the old plate. + std::fs::create_dir(&path).unwrap(); + let (pool, lc, _dc) = session(&cache); + let (unreadable, _) = render(&p, &pool, &lc, cid, 0); + assert!(unreadable[3] < 0.01, "{unreadable:?}"); + std::fs::remove_dir(&path).unwrap(); + + // Back with other pixels: those show, not the entry made of the old file. + png(&path, 240); + touch_later(&path); + let (pool, lc, _dc) = session(&cache); + let (back, _) = render(&p, &pool, &lc, cid, 0); + assert!((back[0] - 240.0 / 255.0).abs() < 0.01, "{back:?}"); + let _ = std::fs::remove_dir_all(&dir); +} diff --git a/crates/media/src/stream.rs b/crates/media/src/stream.rs index 80db21fc4..0155b4acd 100644 --- a/crates/media/src/stream.rs +++ b/crates/media/src/stream.rs @@ -9,6 +9,7 @@ use std::path::Path; +use effectcraft_render::reads::FileStamp; use filmcraft_media::SharedSource; use crate::Result; @@ -19,17 +20,22 @@ use crate::Result; pub(crate) struct FileReader { file: std::fs::File, len: u64, + /// The file's identity when it was opened. + stamp: FileStamp, } #[cfg(any(unix, windows))] impl FileReader { + /// Opens `path` for reading and records its length and modification time. pub(crate) fn open(path: &Path) -> std::io::Result { + #[cfg(test)] + crate::count_open(path); let file = std::fs::File::open(path)?; let m = file.metadata()?; if !m.is_file() { return Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, format!("{} is not a file", path.display()))); } - Ok(Self { file, len: m.len() }) + Ok(Self { file, len: m.len(), stamp: FileStamp::of_metadata(&m) }) } } @@ -72,16 +78,19 @@ fn name_of(path: &Path) -> String { /// Open a movie/audio file for the media pool, reading only what its container needs; files the /// reader openers don't handle are read whole and opened from memory, exactly as before. `None` /// when the file can't be opened in place (the caller reads it whole, which reports the error). +/// With the file's identity as opened. #[cfg(any(unix, windows))] -pub(crate) fn open_source(path: &Path) -> Option> { +pub(crate) fn open_source(path: &Path) -> Option<(Result, FileStamp)> { let reader = FileReader::open(path).ok()?; + let stamp = reader.stamp; let reader: filmcraft_media::SharedReader = std::sync::Arc::new(reader); let opened = filmcraft_media::reader::open_reader(&name_of(path), reader, &filmcraft_codecs::reader_openers(), &filmcraft_codecs::openers()); - Some(opened.map_err(Into::into)) + Some((opened.map_err(Into::into), stamp)) } +/// Without a native file system there is no in-place source: always `None`. #[cfg(not(any(unix, windows)))] -pub(crate) fn open_source(_path: &Path) -> Option> { +pub(crate) fn open_source(_path: &Path) -> Option<(Result, FileStamp)> { None } diff --git a/crates/project/src/lib.rs b/crates/project/src/lib.rs index 079b81765..c9322ac37 100644 --- a/crates/project/src/lib.rs +++ b/crates/project/src/lib.rs @@ -35,6 +35,7 @@ mod footage; mod item; mod layer; mod layers; +mod reach; mod settings; pub use comp::{Comp, Guide, Renderer, Resolution}; @@ -46,6 +47,7 @@ pub use layer::{ reads_other_frames, }; pub use layers::Layers; +pub use reach::{ExprReach, PixelReach, expression_reach}; pub use settings::{ APP_VERSION, BitDepth, ColorEngine, CuePoint, HdrMode, Marker, ProjectError, ProjectSettings, SCHEMA_EFFECT_SPACE, SCHEMA_VERSION, SavedView, TimeDisplayStyle, is_newer_version, saved_by, saved_view, diff --git a/crates/project/src/reach.rs b/crates/project/src/reach.rs new file mode 100644 index 000000000..31a2ed567 --- /dev/null +++ b/crates/project/src/reach.rs @@ -0,0 +1,405 @@ +//! What a composition's pixels can depend on, from the project in memory: the items it draws +//! and, when expressions are among them, what those expressions can read (#3184). The disk +//! cache keys a comp's frames by exactly these items, so an edit elsewhere in the project keeps +//! them. +//! +//! An expression reaches its own comp's layers (`thisComp`, `thisLayer`), the sources of the +//! layers it can read (`layer.source`, a precomp's layers through it), and other items by name: +//! `comp("Name")` and `footage("Name")`. A name given as a plain string literal is followed; a +//! computed name (`comp("Shot " + index)`), the object model's constructors and internals +//! (`new Comp(7)`, `__h`), dynamic code (`eval`, `Function`) and anything the scanner can't read +//! for sure (a regular expression literal, a template string, an escape in a name) count as +//! reaching every item of the project. The scan errs on the side of reaching more: an item +//! wrongly left out would serve a stale frame, one wrongly let in only renders again. +//! +//! Known limit (`ponytail`): an expression that builds the names of the object model's private +//! fields at run time into a variable and writes them with a computed key it reads from that +//! variable could forge another comp's id. That is deliberate tampering with the internals, not +//! an expression one writes; the scan refuses every direct form of it (`__` names, the +//! constructors, `Object`, `JSON`, `call`/`apply`/`bind`, computed writes and computed keys). +//! Upgrade: have the expression host record which items an evaluation reached. + +use std::collections::{BTreeMap, BTreeSet}; + +use crate::{Comp, ItemId, ItemKind, LayerId, Node, Project, PropGroup, Value}; + +/// What an expression's text can reach outside its own comp and the layers it can read. +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum ExprReach { + /// Only items named by string literals: comps by `comp("…")`, footage by `footage("…")`. + Names { comps: Vec, footage: Vec }, + /// Any item of the project. + Anything, +} + +/// Names that hand an expression another item by id, run code built at run time, or give it the +/// tools to forge the object model's private fields. +const REACHES_ANYTHING: &[&str] = &[ + "Comp", + "Footage", + "Layer", + "Prop", + "Markers", + "eval", + "Function", + "globalThis", + "this", + "self", + "window", + "arguments", + "constructor", + "prototype", + "Object", + "Reflect", + "Proxy", + "JSON", + "call", + "apply", + "bind", + "class", + "with", + "import", + "require", + "fromCharCode", + "fromCodePoint", + "getOwnPropertyDescriptor", + "getOwnPropertyDescriptors", + "getPrototypeOf", + "setPrototypeOf", + "defineProperty", +]; + +/// Keywords after which a `/` starts a regular expression. +const BEFORE_REGEX: &[&str] = &["return", "typeof", "instanceof", "in", "of", "new", "delete", "void", "throw", "case", "do", "else", "yield", "await"]; + +/// Keywords whose `( … )` a regular expression may follow (`if (a) /x/.test(s)`). +const CONTROL: &[&str] = &["if", "while", "for", "with"]; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Tok<'a> { + Ident(&'a str), + /// A string literal's text between its quotes; `plain` when it has no escape. + Str { + text: &'a str, + plain: bool, + }, + Num, + Punct(u8), +} + +/// The tokens of `text`, or `None` when it can't be read for sure. +fn tokens(text: &str) -> Option>> { + let b = text.as_bytes(); + let mut out: Vec> = Vec::new(); + // Per open `(`: whether a control keyword is before it; whether the last `)` closed one + // (only looked at right after a `)`). + let mut parens: Vec = Vec::new(); + let mut control_close = false; + let mut i = 0; + while let Some(&c) = b.get(i) { + match c { + b' ' | b'\t' | b'\n' | b'\r' | 0x0b | 0x0c => i += 1, + b'/' if b.get(i + 1) == Some(&b'/') => { + while b.get(i).is_some_and(|c| *c != b'\n') { + i += 1; + } + } + b'/' if b.get(i + 1) == Some(&b'*') => { + let end = text.get(i + 2..)?.find("*/")?; + i += 2 + end + 2; + } + b'/' => { + if regex_may_start(out.last(), control_close) { + return None; + } + out.push(Tok::Punct(c)); + i += 1; + } + b'"' | b'\'' => { + let start = i + 1; + let mut j = start; + let mut plain = true; + loop { + match *b.get(j)? { + q if q == c => break, + b'\n' | b'\r' => return None, + b'\\' => { + // Only escapes that can't spell a name: `\n`, `\t`, a quote... + if !matches!(b.get(j + 1)?, b'n' | b'r' | b't' | b'b' | b'f' | b'v' | b'\'' | b'"' | b'\\') { + return None; + } + plain = false; + j += 2; + } + _ => j += 1, + } + } + let s = text.get(start..j)?; + if s.contains("__") { + return None; + } + out.push(Tok::Str { text: s, plain }); + i = j + 1; + } + b'0'..=b'9' => { + while b.get(i).is_some_and(|c| c.is_ascii_alphanumeric() || *c == b'_' || *c == b'.') { + i += 1; + } + out.push(Tok::Num); + } + b'.' if b.get(i + 1).is_some_and(u8::is_ascii_digit) => { + i += 1; + while b.get(i).is_some_and(|c| c.is_ascii_alphanumeric() || *c == b'_' || *c == b'.') { + i += 1; + } + out.push(Tok::Num); + } + c if c.is_ascii_alphabetic() || c == b'_' || c == b'$' => { + let start = i; + while b.get(i).is_some_and(|c| c.is_ascii_alphanumeric() || *c == b'_' || *c == b'$') { + i += 1; + } + out.push(Tok::Ident(text.get(start..i)?)); + } + // A template string (code inside `${}`), an escaped identifier, a name in another + // alphabet: not followed. + b'`' | b'\\' => return None, + c if !c.is_ascii() => return None, + c => { + match c { + b'(' => parens.push(matches!(out.last(), Some(Tok::Ident(k)) if CONTROL.contains(k))), + b')' => control_close = parens.pop().unwrap_or(false), + _ => {} + } + out.push(Tok::Punct(c)); + i += 1; + } + } + } + Some(out) +} + +/// Whether a `/` after `prev` may start a regular expression literal (which the scanner doesn't +/// read: its text could hide a quote). +fn regex_may_start(prev: Option<&Tok<'_>>, control_close: bool) -> bool { + match prev { + None => true, + Some(Tok::Ident(k)) => BEFORE_REGEX.contains(k), + Some(Tok::Num | Tok::Str { .. }) => false, + Some(Tok::Punct(b')')) => control_close, + Some(Tok::Punct(b']')) => false, + Some(Tok::Punct(_)) => true, + } +} + +/// What the expression `text` can reach by name, or [`ExprReach::Anything`]. +pub fn expression_reach(text: &str) -> ExprReach { + expression_names(text).map_or(ExprReach::Anything, |(comps, footage)| ExprReach::Names { comps, footage }) +} + +/// The comp names and footage names an expression references by literal name. +/// Returns `None` when it can reach anything by a computed name or cannot be tokenised. +fn expression_names(text: &str) -> Option<(Vec, Vec)> { + let toks = tokens(text)?; + let (mut comps, mut footage) = (Vec::new(), Vec::new()); + // Per open `[`: a computed key (`{[k]: v}`), a computed member (`o[k]`). + let mut brackets: Vec<(bool, bool)> = Vec::new(); + for (i, t) in toks.iter().enumerate() { + let prev = i.checked_sub(1).and_then(|p| toks.get(p)); + let next = |n: usize| toks.get(i + n); + match *t { + Tok::Ident(name) if name.starts_with("__") || REACHES_ANYTHING.contains(&name) => return None, + Tok::Ident(name @ ("comp" | "footage")) => { + // Only a call with a plain literal, not a property of something else. + let (Some(Tok::Punct(b'(')), Some(Tok::Str { text, plain: true }), Some(Tok::Punct(b')'))) = (next(1), next(2), next(3)) else { return None }; + if matches!(prev, Some(Tok::Punct(b'.'))) { + return None; + } + if name == "comp" { comps.push((*text).to_string()) } else { footage.push((*text).to_string()) } + } + Tok::Punct(b'[') => { + let key = matches!(prev, Some(Tok::Punct(b'{' | b',')) | Some(Tok::Ident("get" | "set" | "static" | "async")) | Some(Tok::Punct(b'*'))); + let member = matches!(prev, Some(Tok::Ident(_) | Tok::Str { .. } | Tok::Num | Tok::Punct(b')' | b']' | b'.'))); + brackets.push((key, member)); + } + Tok::Str { .. } if brackets.last().is_some_and(|(_, member)| *member) => return None, + Tok::Punct(b']') => { + let (key, _) = brackets.pop().unwrap_or((true, true)); + // A computed key (`{[k]: v}`, `{[k]() {}}`) or a write through brackets (`o[k] = v`, + // `o[k] ||= v`, `for (o[k] in …)`, `[o[k]] = v`) could name a private field. + if key && matches!(next(1), Some(Tok::Punct(b':' | b'('))) { + return None; + } + if assigns(&toks, i + 1) || matches!(next(1), Some(Tok::Ident("in" | "of"))) { + return None; + } + } + // A destructuring write (`({a: o[k]} = v)`). + Tok::Punct(b'}') if assigns(&toks, i + 1) => return None, + _ => {} + } + } + Some((comps, footage)) +} + +/// Whether the tokens from `at` are an assignment operator (`=`, `+=`, `>>>=`, `??=`...), not a +/// comparison (`==`, `<=`) or an arrow (`=>`). +fn assigns(toks: &[Tok<'_>], at: usize) -> bool { + let mut op = Vec::new(); + for t in toks.iter().skip(at).take(5) { + match t { + Tok::Punct(c) if b"+-*/%&|^<>?=".contains(c) => op.push(*c), + _ => break, + } + } + let Some(eq) = op.iter().position(|c| *c == b'=') else { return false }; + let (before, after) = op.split_at(eq); + if after.get(1).is_some_and(|c| *c == b'=' || *c == b'>') { + return false; + } + matches!(before, b"" | b"+" | b"-" | b"*" | b"/" | b"%" | b"&" | b"|" | b"^" | b"**" | b"<<" | b">>" | b">>>" | b"&&" | b"||" | b"??") +} + +/// The items a comp's pixels can depend on ([`Project::pixel_reach`]). +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub struct PixelReach { + /// The items whose state counts; `None`: every item of the project. + pub items: Option>, + /// Expressions are among them: they can read every layer of the comps they reach (hidden + /// and silent ones too) and the markers, which therefore count as well (#1083). + pub expressions: bool, + /// The names expressions look items up by (`true`: a comp's, `false`: footage's), each with + /// the ids of the items of that kind that have it now, in id order (the first one is what + /// the lookup finds; another item taking or giving up the name changes it). + pub names: Vec<(bool, String, Vec)>, +} + +/// Each property of a group and its subgroups (iterative: no depth limit to hit). +fn each_prop<'a>(g: &'a PropGroup, f: &mut dyn FnMut(&'a crate::Property) -> Option<()>) -> Option<()> { + let mut stack = vec![g]; + while let Some(g) = stack.pop() { + for n in &g.children { + match n { + Node::Prop(p) => f(p)?, + Node::Group(sub) => stack.push(sub), + } + } + } + Some(()) +} + +impl Project { + /// The items comp `comp` draws ([`Self::silent_layers`] aside, with `heard`) and the + /// footage its precomp layers swap in (Essential Graphics Media Replacement); with an + /// expression in any of its comps, everything those expressions can reach + /// ([`expression_reach`]). Memory only: no file is looked at. + pub fn pixel_reach(&self, comp: ItemId, heard: &crate::Heard) -> PixelReach { + let Some(drawn) = self.reach_walk(comp, &|id, c| self.silent_layers(id, c, heard), &mut |_| Some(vec![])) else { return PixelReach::every() }; + let has_expression = |g: &PropGroup| each_prop(g, &mut |p| p.expr.is_none().then_some(())).is_none(); + if !drawn.iter().filter_map(|id| self.comp(*id)).any(|c| c.layers.iter().any(|l| has_expression(&l.props))) { + return PixelReach { items: Some(drawn), expressions: false, names: vec![] }; + } + // Expressions: every layer of a comp they reach counts, and what they name. + let mut names: BTreeMap<(bool, String), Vec> = BTreeMap::new(); + let mut scan = |p: &crate::Property| match p.expr.as_ref().map(|e| expression_reach(&e.text)) { + None => Some(vec![]), + Some(ExprReach::Anything) => None, + Some(ExprReach::Names { comps, footage }) => { + let mut found = vec![]; + for (is_comp, name) in comps.into_iter().map(|n| (true, n)).chain(footage.into_iter().map(|n| (false, n))) { + let ids = self.named(is_comp, &name); + found.extend(ids.iter().copied()); + names.insert((is_comp, name), ids); + } + Some(found) + } + }; + let Some(mut items) = self.reach_walk(comp, &|_, _| BTreeSet::new(), &mut scan) else { return PixelReach::every() }; + // A source's data is read by its name (`layer.source.sourceData`). + let footage_names: BTreeSet<&str> = + items.iter().filter_map(|id| self.item(*id)).filter(|i| matches!(i.kind, ItemKind::Footage(_))).map(|i| i.name.as_str()).collect(); + let same_name: Vec = + self.items.values().filter(|i| matches!(i.kind, ItemKind::Footage(_)) && footage_names.contains(i.name.as_str())).map(|i| i.id).collect(); + items.extend(same_name); + PixelReach { items: Some(items), expressions: true, names: names.into_iter().map(|((c, n), ids)| (c, n, ids)).collect() } + } + + /// The items of one kind (`is_comp`: comps, else footage) named `name`, in id order. + fn named(&self, is_comp: bool, name: &str) -> Vec { + self.items + .values() + .filter(|i| i.name == name && if is_comp { matches!(i.kind, ItemKind::Comp(_)) } else { matches!(i.kind, ItemKind::Footage(_)) }) + .map(|i| i.id) + .collect() + } + + /// The items reached from `comp` through its layers (but those `quiet` names) and the items + /// `scan` returns for each of their properties; `None` when something reaches every item. + /// (A stack and a visited set: each item is visited once, cycles included.) + fn reach_walk( + &self, + comp: ItemId, + quiet: &dyn Fn(ItemId, &Comp) -> BTreeSet, + scan: &mut dyn FnMut(&crate::Property) -> Option>, + ) -> Option> { + let mut seen = BTreeSet::new(); + let mut stack = vec![comp]; + while let Some(id) = stack.pop() { + if !seen.insert(id) { + continue; + } + let Some(c) = self.comp(id) else { continue }; + let quiet = quiet(id, c); + for l in c.layers.iter().filter(|l| !quiet.contains(&l.id)) { + // Every source item: a 3D model's too (it is drawn, and `layer.source` reads its + // name and size). + if let Some(item) = l.source.item() { + stack.push(item); + } + stack.extend(self.media_replacements(l)?); + let mut reached = vec![]; + each_prop(&l.props, &mut |p| { + reached.extend(scan(p)?); + Some(()) + })?; + stack.extend(reached); + } + } + Some(seen) + } + + /// The footage a precomp layer swaps in through its Essential Properties (Media Replacement): + /// the items its overridden properties name. `None` when they can't be listed (an + /// expression or keyframes choose the item over time). + fn media_replacements(&self, layer: &crate::Layer) -> Option> { + let over = crate::essential::overridden(layer); + let Some(g) = crate::essential::group(layer).filter(|_| !over.is_empty()) else { return Some(vec![]) }; + let mut out = vec![]; + each_prop(g, &mut |p| { + if !over.contains(&p.uid) { + return Some(()); + } + if p.expr.is_some() || !p.keys.is_empty() { + return None; + } + if let Value::Scalar(id) = p.value { + let item = ItemId(id.max(0.0) as u64); + if matches!(self.item(item).map(|i| &i.kind), Some(ItemKind::Footage(_))) { + out.push(item); + } + } + Some(()) + })?; + Some(out) + } +} + +impl PixelReach { + /// Every item of the project, with expressions. + fn every() -> PixelReach { + PixelReach { items: None, expressions: true, names: vec![] } + } +} + +#[cfg(test)] +mod tests; diff --git a/crates/project/src/reach/tests.rs b/crates/project/src/reach/tests.rs new file mode 100644 index 000000000..53db8172a --- /dev/null +++ b/crates/project/src/reach/tests.rs @@ -0,0 +1,198 @@ +use super::*; +use crate::{Expression, LayerSource, Solid, build}; +use effectcraft_time::{FrameRate, Tick}; + +fn names(comps: &[&str], footage: &[&str]) -> ExprReach { + ExprReach::Names { comps: comps.iter().map(|s| s.to_string()).collect(), footage: footage.iter().map(|s| s.to_string()).collect() } +} + +/// Expressions that read their own comp, or other items by literal names, are followed; every +/// way to reach items by a computed name or an id, or text the scanner can't read for sure, +/// reaches everything. +#[test] +fn expression_reach_follows_literal_names_and_refuses_the_rest() { + let follows = [ + ("wiggle(2, 20)", names(&[], &[])), + ("thisComp.layer(\"Comp 1 Layer\").transform.opacity * 2 / 3", names(&[], &[])), + ("value + [10, 0]; value[0] / 2", names(&[], &[])), + ("// comp(name) in a comment\n/* footage(x) */ value", names(&[], &[])), + ("\"a string that says comp(x) and Layer\"", names(&[], &[])), + ("comp(\"Other\").layer(1).transform.position", names(&["Other"], &[])), + ("comp( 'A' ).width + comp(\"B\").height", names(&["A", "B"], &[])), + ("footage(\"data.json\").sourceData.x", names(&[], &["data.json"])), + ("x = a[0] <= b ? a[1] : 0; y = a[0] == 1", names(&[], &[])), + ("thisLayer.source.layer(1).name", names(&[], &[])), + ("if (a) x = 1; else x = 2; (a + b) / 2", names(&[], &[])), + ("\"Ünïcödé name\"", names(&[], &[])), + ("const f = (v) => v * 2; f(1)", names(&[], &[])), + ]; + for (text, want) in follows { + assert_eq!(expression_reach(text), want, "{text}"); + } + let anything = [ + "comp(\"Shot \" + index).layer(1)", + "comp(name)", + "var n = \"Other\"; comp(n)", + "comp(\"O\\\"ther\")", + "x.comp(\"Other\")", + "var comp = 1", + "footage(thisComp.name)", + "new Comp(7).layer(1)", + "Layer(7, 3).name", + "__h(__COMP, 7)", + "o.__c = 7", + "eval('1')", + "Function('return 1')()", + "this.x", + "({}).constructor", + "Object.getPrototypeOf(thisComp)", + "JSON.parse(s)", + "thisComp.layer.call(o, 1)", + "o['_' + '_c']", + "o[k] = 7", + "o[k] ||= 7", + "o[k] += 7", + "[o[k]] = [7]", + "({a: o[k]} = {a: 7})", + "for (o[k] in x) {}", + "({[k]: 7})", + "({a: 1, [k]: 7})", + "o = {'__c': 7}", + "'\\x5f\\x5fc'", + "'\\_\\_c'", + "`${x}`", + "c\\u006fmp('A')", + "comp\u{0430}('A')", + "/\"/.test(s); comp(n); \"", + "return /x/", + "if (a) /\"/.test(s)", + "x = '", + "/* comp(n)", + "class X {}", + "String.fromCharCode(95)", + ]; + for text in anything { + assert_eq!(expression_reach(text), ExprReach::Anything, "{text}"); + } +} + +/// `a / b` divides after a name, a number, a string and a closing bracket or parenthesis. +#[test] +fn division_is_not_a_regular_expression() { + for text in ["a / b", "2 / 3", "'a' / 2", "x[0] / 2", "(a + b) / 2", "f(x) / 2 / g(y)"] { + assert_eq!(expression_reach(text), names(&[], &[]), "{text}"); + } +} + +struct Fixture { + p: Project, + main: ItemId, + other: ItemId, + third: ItemId, + unused: ItemId, + solid: ItemId, +} + +/// Comps "Main" (a solid), "Other" (a solid), "Third" (empty), an unused footage item. +fn fixture() -> Fixture { + let mut p = Project::default(); + let comp = Comp::new(64, 64, FrameRate::FPS_30, Tick::from_seconds_f64(2.0)); + let solid = + p.add_item("Solid", effectcraft_color::Label::None, None, ItemKind::Solid(Solid { color: [1.0, 0.0, 0.0], width: 64, height: 64, pixel_aspect: 1.0 })); + let main = p.add_item("Main", effectcraft_color::Label::None, None, ItemKind::Comp(comp.clone().into())); + let other = p.add_item("Other", effectcraft_color::Label::None, None, ItemKind::Comp(comp.clone().into())); + let third = p.add_item("Third", effectcraft_color::Label::None, None, ItemKind::Comp(comp.clone().into())); + let unused = p.add_item("unused.png", effectcraft_color::Label::None, None, ItemKind::Footage(crate::Footage { has_video: true, ..Default::default() })); + for c in [main, other] { + let l = build::layer(&mut p, &comp, "S", LayerSource::Solid { item: solid }, (64, 64), None); + p.comp_mut(c).unwrap().layers.push(l); + } + Fixture { p, main, other, third, unused, solid } +} + +fn set_expr(p: &mut Project, comp: ItemId, text: &str) { + let l = p.comp_mut(comp).unwrap().layers.first_mut().unwrap(); + l.props.prop_mut("transform/opacity").unwrap().expr = Some(Expression { text: text.into(), enabled: true }); +} + +fn reach(p: &Project, comp: ItemId) -> PixelReach { + p.pixel_reach(comp, &p.heard_layers()) +} + +#[test] +fn pixel_reach_is_what_the_comp_draws_and_what_its_expressions_name() { + let mut f = fixture(); + let ids = |r: &PixelReach| r.items.clone().map(|s| s.into_iter().collect::>()); + assert_eq!(reach(&f.p, f.main), PixelReach { items: Some([f.solid, f.main].into()), expressions: false, names: vec![] }); + // An expression reading only its own comp: what it draws, with expressions. + set_expr(&mut f.p, f.main, "thisComp.layer(1).transform.opacity"); + let r = reach(&f.p, f.main); + assert!(r.expressions); + assert_eq!(ids(&r), Some(vec![f.solid, f.main])); + // An expression in another comp doesn't reach this one. + set_expr(&mut f.p, f.other, "wiggle(1, 1)"); + assert_eq!(ids(&reach(&f.p, f.main)), Some(vec![f.solid, f.main])); + // A literal name: that comp and what it draws, with the name and the comps that have it. + set_expr(&mut f.p, f.main, "comp(\"Other\").layer(1).transform.opacity"); + let r = reach(&f.p, f.main); + assert_eq!(ids(&r), Some(vec![f.solid, f.main, f.other])); + assert_eq!(r.names, vec![(true, "Other".to_string(), vec![f.other])]); + // Another comp taking the name is part of it, whichever the lookup finds. + f.p.item_mut(f.third).unwrap().name = "Other".into(); + let r = reach(&f.p, f.main); + assert_eq!(r.names, vec![(true, "Other".to_string(), vec![f.other, f.third])]); + assert!(r.items.unwrap().contains(&f.third)); + // A name no item has yet still counts (with no item). + set_expr(&mut f.p, f.main, "footage(\"later.json\").sourceData"); + assert_eq!(reach(&f.p, f.main).names, vec![(false, "later.json".to_string(), vec![])]); + // A computed name reaches everything. + set_expr(&mut f.p, f.main, "comp(\"Ot\" + \"her\").width"); + assert_eq!(reach(&f.p, f.main), PixelReach { items: None, expressions: true, names: vec![] }); + // Footage reached as a layer's source brings the footage of its name (its data is read by + // name). + let comp = f.p.comp(f.main).unwrap().clone(); + let l = build::layer(&mut f.p, &comp, "U", LayerSource::Footage { item: f.unused }, (64, 64), None); + f.p.comp_mut(f.main).unwrap().layers.push(l); + let twin = f.p.add_item("unused.png", effectcraft_color::Label::None, None, ItemKind::Footage(crate::Footage::default())); + set_expr(&mut f.p, f.main, "value"); + let r = reach(&f.p, f.main).items.unwrap(); + assert!(r.contains(&f.unused) && r.contains(&twin), "{r:?}"); +} + +/// A comp nested in the reach is scanned too: its expression's names count for the outer comp. +#[test] +fn nested_comps_bring_their_expressions_reach() { + let mut f = fixture(); + let comp = f.p.comp(f.main).unwrap().clone(); + let pre = build::layer(&mut f.p, &comp, "Pre", LayerSource::Comp { item: f.other }, (64, 64), None); + f.p.comp_mut(f.main).unwrap().layers.push(pre); + set_expr(&mut f.p, f.other, "comp(\"Third\").width"); + let r = reach(&f.p, f.main); + assert!(r.expressions && r.items.unwrap().contains(&f.third)); + // A cycle through names ends. + let l = build::layer(&mut f.p, &comp, "S", LayerSource::Solid { item: f.solid }, (64, 64), None); + f.p.comp_mut(f.third).unwrap().layers.push(l); + set_expr(&mut f.p, f.third, "comp(\"Main\").width"); + assert!(reach(&f.p, f.main).items.unwrap().contains(&f.main)); +} + +/// A 3D model layer's item is reached like any other source: it is drawn, and an expression +/// reads its name and size through `layer.source` (a renamed model left the comp's disk key and +/// its old frames in place). +#[test] +fn model_sources_are_reached() { + let mut f = fixture(); + let model = f.p.add_item( + "chair.glb", + effectcraft_color::Label::None, + None, + ItemKind::Footage(crate::Footage { kind: crate::FootageKind::Model, ..Default::default() }), + ); + let comp = f.p.comp(f.main).unwrap().clone(); + let l = build::layer(&mut f.p, &comp, "Model", LayerSource::Model { item: model }, (64, 64), None); + f.p.comp_mut(f.main).unwrap().layers.push(l); + assert!(reach(&f.p, f.main).items.unwrap().contains(&model), "drawn"); + set_expr(&mut f.p, f.main, "thisComp.layer(\"Model\").source.name.length"); + let r = reach(&f.p, f.main); + assert!(r.expressions && r.items.unwrap().contains(&model), "read by an expression"); +} diff --git a/crates/render/Cargo.toml b/crates/render/Cargo.toml index efbd1fc19..cd67e846a 100644 --- a/crates/render/Cargo.toml +++ b/crates/render/Cargo.toml @@ -26,3 +26,6 @@ rayon = { workspace = true } web-time = { workspace = true } serde = { workspace = true } log = { workspace = true } + +[dev-dependencies] +tempfile = { workspace = true } diff --git a/crates/render/src/accel.rs b/crates/render/src/accel.rs index f545a62ee..0f271c59d 100644 --- a/crates/render/src/accel.rs +++ b/crates/render/src/accel.rs @@ -224,7 +224,7 @@ impl<'a> Renderer<'a> { LayerSource::Footage { item } => { let item = ctx.media_item(layer, *item); let ItemKind::Footage(f) = &self.project.item(item)?.kind else { return None }; - let a = self.footage.aux(item, f, ctx.source_time(layer))?; + let a = self.read(|| self.footage.aux(item, f, ctx.source_time(layer)))?; // Aux pixels per layer pixel (the layer is the footage at its nominal size). The // planes are only copied when that changes the scale. let scale = a.width as f64 / f.width as f64; @@ -349,20 +349,19 @@ impl<'a> Renderer<'a> { pub fn adjustment_footprint(&self, ctx: &EvalCtx, layer: &Layer) -> Option> { // Cached, so an accelerator sees the same buffer (and uploads it once) every frame. let key = self.cache.and_then(|_| cache::footprint_key(ctx, layer, self.raster_scale(ctx, layer), self.opts.draft, self.mb_on(ctx, layer))); - if let (Some(c), Some(k)) = (self.cache, key) - && let Some(b) = c.get(k) - { + let key = self.mask_gate_key(ctx, layer, key); + if let Some((b, _)) = self.cached(key) { return Some(b); } - let mut foot = self.source(ctx, layer)?; - let _ = masks::apply(ctx, layer, &mut foot, self.mask_blur(ctx, layer)); - let foot = Arc::new(foot); + let (foot, files) = self.recorded(key, |r| { + // (what the masks' expressions read, at shutter times too, goes to the buffer's files) + let ctx = &r.with_reads(ctx); + let mut foot = r.source(ctx, layer)?; + let _ = masks::apply(ctx, layer, &mut foot, r.mask_blur(ctx, layer)); + Some(foot) + }); // The buffer the cache keeps (another worker's, if it kept one first). - let foot = match (self.cache_to_keep(), key) { - (Some(c), Some(k)) => c.insert(k, foot), - _ => foot, - }; - Some(foot) + Some(self.keep(key, Arc::new(foot?), &files).0) } /// Draw one 2D layer into `canvas` on the CPU (any kind: adjustment, wireframe, styled…). diff --git a/crates/render/src/cache.rs b/crates/render/src/cache.rs index cf1a84e82..8a3d7b8ae 100644 --- a/crates/render/src/cache.rs +++ b/crates/render/src/cache.rs @@ -22,27 +22,36 @@ use std::hash::{Hash, Hasher}; use std::sync::{Arc, Mutex}; use effectcraft_effects::Buf; +use effectcraft_keyframe::Value; use effectcraft_project::{FootageKind, ItemKind, Layer, LayerSource, Node, PropGroup}; +use crate::disk_cache::{EntryFiles, SharedVirtualFileId, VirtualFileId, layer_disk_key}; use crate::eval::EvalCtx; +use crate::reads::ReadFiles; mod dependencies; /// Thread-safe, memory-budgeted cache of processed layer buffers, optionally backed by the /// persistent [`DiskCache`](crate::disk_cache::DiskCache): a memory miss reads the disk, and -/// buffers that were slow to render are written there (keys salted per project, see -/// [`LayerCache::set_disk`]). +/// buffers that were slow to render are written there with the source files they were made of +/// (keys: [`crate::disk_cache::layer_disk_key`]; an entry is used only while its files are +/// unchanged, #3184). pub struct LayerCache { inner: Mutex, - disk: Mutex, u64)>>, + disk: Mutex>>, /// Another persistent store when there is no disk cache (the browser's, [`PrefetchStore`]). - store: Mutex, u64)>>, + store: Mutex>>, + /// Size and content hash of files served from memory (the browser file table), to store + /// and check the source files of persistent entries. + virtual_id: Mutex>, /// While set, inserts are dropped (see [`LayerCache::set_gate`]). gate: Mutex>>, } struct Entry { buf: Arc, + /// The source files the buffer was made of (see [`crate::reads`]). + files: Arc, bytes: usize, last_use: u64, } @@ -54,7 +63,9 @@ struct Inner { clock: u64, hits: u64, misses: u64, - /// When each recent miss happened (to time the render that follows it). + /// When each recent miss happened, to time the render that follows it (the drop generation + /// a render's reads started at travels with its files instead, [`ReadFiles::since`]: two + /// renders of a key may overlap). missed_at: HashMap, } @@ -80,6 +91,7 @@ impl LayerCache { inner: Mutex::new(Inner { map: HashMap::new(), bytes: 0, budget, clock: 0, hits: 0, misses: 0, missed_at: HashMap::new() }), disk: Mutex::new(None), store: Mutex::new(None), + virtual_id: Mutex::new(None), gate: Mutex::new(None), } } @@ -98,77 +110,75 @@ impl LayerCache { self.gate.lock().ok().and_then(|g| g.as_ref().map(|g| g.load(std::sync::atomic::Ordering::Relaxed))).unwrap_or(false) } - /// Attach (or detach) the disk cache. `salt` separates projects and footage versions (see - /// `footage_salt`); keys on disk are `(salt, key)`. - pub fn set_disk(&self, disk: Option<(Arc, u64)>) { + /// Attach (or detach) the disk cache. It is used at once: its entries check their own + /// source files when read, so nothing has to be looked at first. + pub fn set_disk(&self, disk: Option>) { if let Ok(mut d) = self.disk.lock() { *d = disk; } } - /// Change the disk salt (after footage changed) keeping the attached disk cache. - pub fn set_disk_salt(&self, salt: u64) { - if let Ok(mut d) = self.disk.lock() - && let Some((_, s)) = d.as_mut() - { - *s = salt; - } - } - + /// The attached disk cache, if any. pub fn disk(&self) -> Option> { - self.disk.lock().ok()?.as_ref().map(|d| d.0.clone()) + self.disk.lock().ok()?.clone() } /// Attach (or detach) a [`LayerStore`] used when no disk cache is attached (the browser's - /// Origin Private File System through a [`PrefetchStore`]); `salt` as in - /// [`LayerCache::set_disk`]. - pub fn set_store(&self, store: Option<(Arc, u64)>) { + /// Origin Private File System through a [`PrefetchStore`]). + pub fn set_store(&self, store: Option>) { if let Ok(mut s) = self.store.lock() { *s = store; } } - /// Change the store's salt (a new project or footage), keeping the store. - pub fn set_store_salt(&self, salt: u64) { - if let Ok(mut d) = self.store.lock() - && let Some((_, s)) = d.as_mut() - { - *s = salt; + /// Size and content hash of files served from memory (the browser file table): what a + /// persistent entry keeps for them and checks them against. + pub fn set_virtual_id(&self, id: Option) { + if let Ok(mut v) = self.virtual_id.lock() { + *v = id; } } - fn disk_key(&self, key: u64) -> Option<(Arc, u128)> { - let salted = |salt: u64| ((salt as u128) << 64) | key as u128; - if let Some((dc, salt)) = self.disk.lock().ok()?.as_ref() { - return Some((dc.clone() as Arc, salted(*salt))); - } - let s = self.store.lock().ok()?; - let (st, salt) = s.as_ref()?; - Some((st.clone(), salted(*salt))) + /// The attached virtual-file identity lookup, if any. + fn virtual_id(&self) -> Option { + self.virtual_id.lock().ok()?.clone() } - pub fn get(&self, key: u64) -> Option> { - let mut g = self.inner.lock().ok()?; - g.clock += 1; - let now = g.clock; - match g.map.get_mut(&key) { - Some(e) => { - e.last_use = now; - let b = e.buf.clone(); - g.hits += 1; - Some(b) - } + /// The persistent store behind the memory: the disk cache, else the other store. + fn persistent(&self) -> Option> { + if let Some(dc) = self.disk.lock().ok()?.as_ref() { + return Some(dc.clone() as Arc); + } + self.store.lock().ok()?.clone() + } + + /// The buffer kept under `key` and the source files it was made of (see [`crate::reads`]). + /// A buffer from the disk cache or another store comes with the files its entry lists, after + /// they were found unchanged. A buffer made of a file dropped since its reads began (File ▸ + /// Reload Footage) is never served: it is forgotten, and the lookup is a miss. + pub fn get(&self, key: u64) -> Option<(Arc, Arc)> { + match self.kept(key, true) { + Some(found) => Some(found), None => { + let mut g = self.inner.lock().ok()?; g.misses += 1; - if g.missed_at.len() > 4096 { - g.missed_at.clear(); - } - g.missed_at.insert(key, web_time::Instant::now()); drop(g); - // Disk cache: a hit comes back into memory. - let (dc, dk) = self.disk_key(key)?; - let buf = dc.get_layer(dk)?; - Some(self.insert_mem(key, buf)) + let store = self.persistent(); + // (before the entry is read: what it is made of may be dropped meanwhile) + let since = store.as_ref().map_or(0, |s| s.drop_generation()); + if let Ok(mut g) = self.inner.lock() { + if g.missed_at.len() > 4096 { + g.missed_at.clear(); + } + g.missed_at.insert(key, web_time::Instant::now()); + } + // Disk cache: a hit comes back into memory, read at generation `since`. + let store = store?; + let id = self.virtual_id(); + let (buf, mut files) = store.get_layer(layer_disk_key(key), id.as_deref())?; + files.note_since(since); + let files = Arc::new(files); + Some(self.insert_mem(key, buf, files)) } } } @@ -178,39 +188,113 @@ impl LayerCache { /// together each rendered every layer; sharing the first buffer, the GPU compositor uploads /// and packs it once instead of once per worker, which ran it out of memory). Renders don't /// wait for each other: on the frame workers' shared thread pool a wait can end up under - /// the very work it waits for. - pub fn insert(&self, key: u64, buf: Arc) -> Arc { + /// the very work it waits for. `files`: the source files `buf` was made of (see + /// [`crate::reads`]); a buffer whose files can't all be named stays in memory. The files + /// returned are the ones the returned buffer was made of. + /// + /// The drop generation `buf`'s reads started at comes with `files` ([`ReadFiles::since`], + /// from [`LayerCache::drop_generation`] when the render began): a buffer made of a file + /// dropped since (File ▸ Reload Footage while it rendered) is kept neither on disk nor in + /// memory. A list that doesn't say counts as made before every drop. A buffer made of values + /// its key doesn't capture ([`ReadFiles::is_unkeyed`]) stays in memory. + pub fn insert(&self, key: u64, buf: Arc, files: Arc) -> (Arc, Arc) { if self.gated() { - return buf; + return (buf, files); } - if let Some(kept) = self.inner.lock().ok().and_then(|g| g.map.get(&key).map(|e| e.buf.clone())) { + if let Some(kept) = self.kept(key, false) { return kept; } + let store = self.persistent(); + let since = files.since().unwrap_or(0); + // (before the miss's time is taken: it may time another render of the key) + if store.as_ref().is_some_and(|s| s.dropped_since(&files, since)) { + return (buf, files); + } let started = self.inner.lock().ok().and_then(|mut g| g.missed_at.remove(&key)); - if let Some((dc, dk)) = self.disk_key(key) { - let slow = started.is_some_and(|t| t.elapsed().as_secs_f64() * 1e3 >= dc.min_layer_ms() as f64); - if slow { - dc.put_layer(dk, &buf); + if let Some(store) = store { + let id = self.virtual_id(); + // (an incomplete list, or a file from memory without its identity: not stored) + if let Some(t) = started + && !files.is_unkeyed() + && t.elapsed().as_secs_f64() * 1e3 >= store.min_layer_ms() as f64 + && let Some(entry) = EntryFiles::of(&files, id.as_deref()) + { + store.put_layer(layer_disk_key(key), &buf, &entry, since); } } - self.insert_mem(key, buf) + self.insert_mem(key, buf, files) } - /// See [`LayerCache::insert`]: the buffer kept under `key` (`buf`, unless one was kept first - /// or `buf` is too large to keep). - fn insert_mem(&self, key: u64, buf: Arc) -> Arc { + /// The buffer kept in memory under `key` with its files, if it is not made of a file dropped + /// since its reads began (one that is, is forgotten). `hit`: count it as a hit and as just + /// used. (A render that started before a drop may publish its buffer after the drop's + /// purge, Reload Footage clearing the cache while the buffer was being written: the check + /// here, not the order of the two, keeps it from being served.) + fn kept(&self, key: u64, hit: bool) -> Option<(Arc, Arc)> { + let found = { + let mut g = self.inner.lock().ok()?; + g.clock += 1; + let now = g.clock; + let e = g.map.get_mut(&key)?; + if hit { + e.last_use = now; + } + (e.buf.clone(), e.files.clone()) + }; + if self.made_before_a_drop(&found.1) { + if let Ok(mut g) = self.inner.lock() + && g.map.get(&key).is_some_and(|e| Arc::ptr_eq(&e.files, &found.1)) + && let Some(e) = g.map.remove(&key) + { + g.bytes = g.bytes.saturating_sub(e.bytes); + } + return None; + } + if hit && let Ok(mut g) = self.inner.lock() { + g.hits += 1; + } + Some(found) + } + + /// Whether a buffer made of `files` holds a file as it was before a drop that came after its + /// reads began ([`ReadFiles::since`]; a list that doesn't say counts as made before every + /// drop). + fn made_before_a_drop(&self, files: &ReadFiles) -> bool { + self.persistent().is_some_and(|s| s.dropped_since(files, files.since().unwrap_or(0))) + } + + /// The persistent store's drop generation now ([`LayerStore::drop_generation`]), taken by a + /// render before it starts reading (`None` without a store). + pub fn drop_generation(&self) -> Option { + self.persistent().map(|s| s.drop_generation()) + } + + /// See [`LayerCache::insert`]: the buffer kept under `key` and its files (`buf` and `files`, + /// unless one was kept first or `buf` is too large to keep). + fn insert_mem(&self, key: u64, buf: Arc, files: Arc) -> (Arc, Arc) { let bytes = buf.img.data.len() * std::mem::size_of::(); - let Ok(mut g) = self.inner.lock() else { return buf }; + let Ok(mut g) = self.inner.lock() else { return (buf, files) }; if bytes > g.budget / 4 { - return buf; + return (buf, files); } g.clock += 1; let now = g.clock; if let Some(e) = g.map.get_mut(&key) { - e.last_use = now; - return e.buf.clone(); + // (one made before a drop gives way: see [`LayerCache::kept`]) + if !self.made_before_a_drop(&e.files) { + e.last_use = now; + return (e.buf.clone(), e.files.clone()); + } + if let Some(old) = g.map.remove(&key) { + g.bytes = g.bytes.saturating_sub(old.bytes); + } } - g.map.insert(key, Entry { buf: buf.clone(), bytes, last_use: now }); + // (checked again just before it is published: a drop may have come since `insert` + // checked; one that comes later is caught when the buffer is looked up) + if self.made_before_a_drop(&files) { + return (buf, files); + } + g.map.insert(key, Entry { buf: buf.clone(), files: files.clone(), bytes, last_use: now }); g.bytes += bytes; if g.bytes > g.budget { // Evict least-recently used entries down to 3/4 of the budget. @@ -226,7 +310,7 @@ impl LayerCache { } } } - buf + (buf, files) } /// The memory budget in bytes. @@ -264,12 +348,28 @@ impl LayerCache { } } -/// Persistent storage of layer buffers behind a [`LayerCache`] (keys salted per project). +/// Persistent storage of layer buffers behind a [`LayerCache`] (keys: +/// [`crate::disk_cache::layer_disk_key`]). Every entry keeps the source files its buffer was made +/// of and is used only while they are unchanged (#3184). pub trait LayerStore: Send + Sync { - /// A stored buffer (synchronous: mid-render). - fn get_layer(&self, key: u128) -> Option>; - /// Keep a buffer that was slow to render. - fn put_layer(&self, key: u128, buf: &Buf); + /// A stored buffer whose source files are unchanged, with those files (synchronous: + /// mid-render). An entry whose files changed, or damaged, is a miss and is dropped, so the + /// buffer rendered again replaces it. `virtual_id` names files served from memory. + fn get_layer(&self, key: u128, virtual_id: Option>) -> Option<(Arc, ReadFiles)>; + /// Keep a buffer that was slow to render, with the source files it was made of. `since`: the + /// [`LayerStore::drop_generation`] when its render started (a buffer made of a file dropped + /// after that is refused). + fn put_layer(&self, key: u128, buf: &Buf, files: &EntryFiles, since: u64); + /// How many times files were dropped from the store (File ▸ Reload Footage, + /// [`crate::disk_cache::DiskCache::drop_files`]); `0` for a store that never drops. + fn drop_generation(&self) -> u64 { + 0 + } + /// Whether one of `files` was dropped after generation `since`: what was made of them is + /// from before the drop. `false` for a store that never drops. + fn dropped_since(&self, _files: &ReadFiles, _since: u64) -> bool { + false + } /// Buffers faster to render than this (ms) are not stored. fn min_layer_ms(&self) -> u64 { 0 @@ -281,9 +381,10 @@ pub const PREFETCH_MIN_LAYER_MS: u64 = 20; /// A [`LayerStore`] over storage that can't be read in the middle of a render (the browser's /// Origin Private File System, read asynchronously). Lookups are served from buffers fetched -/// before the frame ([`PrefetchStore::provide`]); the keys a render looked up and didn't find -/// are recorded ([`PrefetchStore::take_misses`]) so the transport can fetch them before the next -/// frame; buffers to store queue up as sealed entries ([`PrefetchStore::take_writes`]) for the +/// before the frame ([`PrefetchStore::provide`]), once the files their entries list are found +/// unchanged; the keys a render looked up and didn't find are recorded +/// ([`PrefetchStore::take_misses`]) so the transport can fetch them before the next frame; +/// buffers to store queue up as sealed entries ([`PrefetchStore::take_writes`]) for the /// transport to write after the frame. Fetched buffers are kept least recently used first, up /// to a byte budget. pub struct PrefetchStore { @@ -292,9 +393,21 @@ pub struct PrefetchStore { min_ms: u64, } +/// A fetched entry: the buffer, the source files it was made of, its last use. +struct Fetched { + buf: Arc, + files: Arc, + used: u64, +} + +/// The memory a buffer's pixels take, in bytes. +fn buf_bytes(b: &Buf) -> usize { + b.img.data.len().saturating_mul(std::mem::size_of::()) +} + #[derive(Default)] struct Prefetched { - ready: HashMap, u64)>, + ready: HashMap, bytes: usize, clock: u64, misses: Vec, @@ -304,6 +417,22 @@ struct Prefetched { known: std::collections::HashSet, } +impl Prefetched { + /// Records a missed key for prefetching, up to a fixed bound. + fn note_miss(&mut self, key: u128) { + if !self.misses.contains(&key) && self.misses.len() < 1024 { + self.misses.push(key); + } + } + + /// Drops the prefetched entry for `key` and frees its bytes. + fn remove(&mut self, key: u128) { + if let Some(f) = self.ready.remove(&key) { + self.bytes = self.bytes.saturating_sub(buf_bytes(&f.buf)); + } + } +} + impl Default for PrefetchStore { fn default() -> Self { PrefetchStore::new(256 << 20) @@ -327,23 +456,21 @@ impl PrefetchStore { } /// A fetched entry (sealed bytes, [`crate::disk_cache::layer_entry`]) for `key`; `false` - /// when damaged. + /// when damaged or of another format. Its files are checked when the buffer is used. pub fn provide(&self, key: u128, entry: &[u8]) -> bool { - let Some(buf) = crate::disk_cache::read_layer_entry(entry) else { return false }; - let bytes = buf.img.data.len() * std::mem::size_of::(); + let Some((buf, files)) = crate::disk_cache::read_layer_entry(entry) else { return false }; + let buf = Arc::new(buf); + let bytes = buf_bytes(&buf); let Ok(mut s) = self.st.lock() else { return false }; s.clock += 1; - let now = s.clock; - if let Some((old, _)) = s.ready.insert(key, (Arc::new(buf), now)) { - s.bytes -= old.img.data.len() * std::mem::size_of::(); - } - s.bytes += bytes; + let used = s.clock; + s.remove(key); + s.ready.insert(key, Fetched { buf, files: Arc::new(files), used }); + s.bytes = s.bytes.saturating_add(bytes); s.known.insert(key); while s.bytes > self.budget { - let Some((&k, _)) = s.ready.iter().min_by_key(|(_, (_, t))| *t) else { break }; - if let Some((b, _)) = s.ready.remove(&k) { - s.bytes -= b.img.data.len() * std::mem::size_of::(); - } + let Some(oldest) = s.ready.iter().min_by_key(|(_, f)| f.used).map(|(k, _)| *k) else { break }; + s.remove(oldest); } true } @@ -372,32 +499,46 @@ impl PrefetchStore { } impl LayerStore for PrefetchStore { - fn get_layer(&self, key: u128) -> Option> { + /// The prefetched layer for `key` with its read files, or `None` when it is not ready. + fn get_layer(&self, key: u128, virtual_id: Option>) -> Option<(Arc, ReadFiles)> { + let found = { + let mut s = self.st.lock().ok()?; + s.clock += 1; + let now = s.clock; + match s.ready.get_mut(&key) { + Some(f) => { + f.used = now; + Some((f.buf.clone(), f.files.clone())) + } + None => { + s.note_miss(key); + None + } + } + }; + let (buf, files) = found?; + // (looked at without the lock: one call of the hook, or one `metadata`, per file) + let unchanged = files.unchanged(virtual_id); let mut s = self.st.lock().ok()?; - s.clock += 1; - let now = s.clock; - match s.ready.get_mut(&key) { - Some((b, t)) => { - *t = now; - let b = b.clone(); - if !s.hits.contains(&key) { - s.hits.push(key); - } - Some(b) - } - None => { - if !s.misses.contains(&key) && s.misses.len() < 1024 { - s.misses.push(key); - } - None - } + if !unchanged { + // Made of files that changed since: forgotten, so the buffer rendered again is + // written over its entry. + s.remove(key); + s.known.remove(&key); + s.note_miss(key); + return None; } + if !s.hits.contains(&key) { + s.hits.push(key); + } + Some((buf, files.to_read_files())) } - fn put_layer(&self, key: u128, buf: &Buf) { + /// Queues the layer for writing to the persistent store the first time `key` is seen. + fn put_layer(&self, key: u128, buf: &Buf, files: &EntryFiles, _since: u64) { let Ok(mut s) = self.st.lock() else { return }; if s.known.insert(key) { - s.writes.push((key, crate::disk_cache::layer_entry(buf))); + s.writes.push((key, crate::disk_cache::layer_entry(buf, files))); } } @@ -470,6 +611,12 @@ fn time_dependent(layer: &Layer, effects: bool) -> bool { false } +/// A text layer with an Expression Selector: its amount is evaluated per character, and the +/// layer's key holds only the first character's (see [`crate::reads::ReadFiles::is_unkeyed`]). +pub(crate) fn per_character_expressions(layer: &Layer) -> bool { + matches!(layer.source, LayerSource::Text) && layer.props.sub("text").is_some_and(|t| group_has(t, "expressionSelector")) +} + fn group_has(g: &PropGroup, match_id: &str) -> bool { g.children.iter().any(|c| match c { Node::Group(sub) => sub.match_id == match_id || group_has(sub, match_id), @@ -741,6 +888,21 @@ fn key_any(ctx: &EvalCtx, layer: &Layer, scale: f64, draft: bool, blur: bool, fo Some(h.finish()) } +/// Does the layer read another layer through an enabled effect's layer parameter (Gradient Wipe, +/// Set Matte…)? Those layers are drawn by the reading layer's renderer, so the switches it +/// passes down belong in the key (`Renderer::nested_look`). +pub(crate) fn reads_layers(ctx: &EvalCtx, layer: &Layer) -> bool { + /// Whether any enabled layer-valued property of `layer` points at another layer. + fn reads(ctx: &EvalCtx, layer: &Layer, g: &PropGroup, depth: usize) -> bool { + depth < 32 + && g.children.iter().any(|n| match n { + Node::Prop(p) => matches!(p.value, Value::Layer(_)) && ctx.value(layer, p).as_layer().is_some_and(|id| id != layer.id.0), + Node::Group(sub) => sub.enabled && reads(ctx, layer, sub, depth + 1), + }) + } + layer.switches.effects && layer.effects().is_some_and(|fx| fx.groups().any(|g| g.enabled && reads(ctx, layer, g, 0))) +} + /// Does the layer run an effect that reads the comp camera or lights (Card Dance, CC Particle /// World…)? fn reads_comp_scene(layer: &Layer) -> bool { @@ -786,8 +948,211 @@ mod shared_insert_tests { let cache = LayerCache::default(); let buf = || Arc::new(Buf { img: Image::new(4, 4), offset: [0.0; 2], scale: 1.0 }); let (a, b) = (buf(), buf()); - assert!(Arc::ptr_eq(&cache.insert(3, a.clone()), &a)); - assert!(Arc::ptr_eq(&cache.insert(3, b), &a), "the later render gets the first buffer"); - assert!(Arc::ptr_eq(&cache.get(3).unwrap(), &a)); + assert!(Arc::ptr_eq(&cache.insert(3, a.clone(), Default::default()).0, &a)); + assert!(Arc::ptr_eq(&cache.insert(3, b, Default::default()).0, &a), "the later render gets the first buffer"); + assert!(Arc::ptr_eq(&cache.get(3).unwrap().0, &a)); + } + + /// The browser's store (#3184): a fetched entry is used only while the files it lists are + /// unchanged (here from memory, through the hook), and comes with them; one made of files + /// that changed is dropped and counts as a miss, so the buffer rendered again is queued over + /// it. A buffer whose files can't all be named is not queued at all. + #[test] + fn the_prefetch_store_checks_the_files_of_its_entries() { + use super::{LayerStore, PrefetchStore}; + use crate::disk_cache::{EntryFiles, layer_disk_key, layer_entry}; + use crate::reads::{FileStamp, ReadFile, ReadFiles}; + let buf = || Buf { img: Image::new(2, 2), offset: [0.0; 2], scale: 1.0 }; + let files: ReadFiles = [ReadFile::new("/v.png", FileStamp::Virtual)].into_iter().collect(); + let (one, two) = (|_: &str| Some((3, 1)), |_: &str| Some((3, 2))); + let entry = layer_entry(&buf(), &EntryFiles::of(&files, Some(&one)).unwrap()); + let store = PrefetchStore::new(1 << 20).with_min_ms(0); + assert!(store.provide(5, &entry)); + assert!(!store.provide(6, b"damaged")); + let (_, got) = store.get_layer(5, Some(&one)).unwrap(); + assert_eq!(got, files); + assert_eq!(store.take_hits(), [5]); + // The file changed: a miss, forgotten, and the new buffer is queued over it. + assert!(store.get_layer(5, Some(&two)).is_none()); + assert!(!store.has(5)); + assert_eq!(store.take_misses(), [5]); + store.put_layer(5, &buf(), &EntryFiles::of(&files, Some(&two)).unwrap(), 0); + assert_eq!(store.take_writes().len(), 1, "written over the changed entry"); + // Through the layer cache: a hit reports its files; incomplete lists are not queued. + let cache = LayerCache::default(); + let store = Arc::new(PrefetchStore::new(1 << 20).with_min_ms(0)); + cache.set_store(Some(store.clone())); + cache.set_virtual_id(Some(Arc::new(one))); + assert!(store.provide(layer_disk_key(9), &entry)); + let (_, from_store) = cache.get(9).unwrap(); + assert!(*from_store == files && from_store.is_complete()); + let mut incomplete = files.clone(); + incomplete.mark_incomplete(); + assert!(cache.get(10).is_none()); + cache.insert(10, Arc::new(buf()), Arc::new(incomplete)); + assert!(cache.get(11).is_none()); + cache.insert(11, Arc::new(buf()), Arc::new(files.clone())); + let written: Vec = store.take_writes().into_iter().map(|w| w.0).collect(); + assert_eq!(written, [layer_disk_key(11)], "only the buffer whose files are all named"); + } + + /// A layer buffer whose render started before Reload Footage dropped its file (#3184) is + /// not written to the disk cache when it is kept afterwards; one whose render started after + /// the drop is. + #[test] + fn a_buffer_rendered_across_a_drop_is_not_written() { + use crate::disk_cache::{DiskCache, Kind, layer_disk_key}; + use crate::reads::{FileStamp, ReadFile, ReadLog}; + let dir = tempfile::tempdir().unwrap(); + let dc = DiskCache::open(dir.path(), 1 << 30).unwrap(); + dc.set_min_layer_ms(0); + let cache = LayerCache::default(); + cache.set_disk(Some(dc.clone())); + let buf = || Arc::new(Buf { img: Image::new(2, 2), offset: [0.0; 2], scale: 1.0 }); + // A render's files, read after it took the drop generation (`Renderer::recorded`). + let render = || { + let log = ReadLog::starting_at(cache.drop_generation().unwrap()); + move || { + log.note(ReadFile::new("/a.png", FileStamp::Native { len: 3, modified: Some(1) })); + Arc::new(log.into_files()) + } + }; + // The miss starts the render; the file is reloaded before the buffer is kept. + assert!(cache.get(1).is_none()); + let a = render(); + dc.drop_files(["/a.png"]); + dc.flush(); + // Another render of the same key starts after the drop, while the first one still runs + // (its miss must not lend the first render its generation). + assert!(cache.get(1).is_none()); + let b = render(); + let (stale, _) = cache.insert(1, buf(), a()); + dc.flush(); + assert!(!dc.contains(Kind::Layer, layer_disk_key(1)), "made of the file as it was before the drop"); + // Not kept in memory either: the second render keeps its own buffer, and writes it. + let fresh = buf(); + let (kept, _) = cache.insert(1, fresh.clone(), b()); + assert!(Arc::ptr_eq(&kept, &fresh) && !Arc::ptr_eq(&kept, &stale)); + // A render of another key after the drop. + assert!(cache.get(2).is_none()); + cache.insert(2, buf(), render()()); + dc.flush(); + assert!(dc.contains(Kind::Layer, layer_disk_key(1)), "the render after the drop"); + assert!(dc.contains(Kind::Layer, layer_disk_key(2))); + // A list that doesn't say when its reads began counts as made before the drop. + assert!(cache.get(3).is_none()); + cache.insert(3, buf(), Arc::new([ReadFile::new("/a.png", FileStamp::Native { len: 3, modified: Some(1) })].into_iter().collect())); + dc.flush(); + assert!(!dc.contains(Kind::Layer, layer_disk_key(3))); + drop((cache, dc)); + } + + /// A disk cache whose layer writes stop at a barrier until the test lets them go on. + struct PausedWrites { + dc: Arc, + arrived: std::sync::Barrier, + go_on: std::sync::Barrier, + } + + impl super::LayerStore for PausedWrites { + fn get_layer(&self, key: u128, virtual_id: Option>) -> Option<(Arc, crate::reads::ReadFiles)> { + super::LayerStore::get_layer(&*self.dc, key, virtual_id) + } + fn put_layer(&self, key: u128, buf: &Buf, files: &crate::disk_cache::EntryFiles, since: u64) { + self.arrived.wait(); + self.go_on.wait(); + super::LayerStore::put_layer(&*self.dc, key, buf, files, since); + } + fn drop_generation(&self) -> u64 { + self.dc.drop_generation() + } + fn dropped_since(&self, files: &crate::reads::ReadFiles, since: u64) -> bool { + self.dc.dropped_since(files, since) + } + } + + /// Reload Footage while a render from before it is writing its buffer: the cache is cleared + /// and the file dropped after the buffer passed its check, before it is kept. The buffer + /// then reaches memory after the purge, but it is never served, and a render after the drop + /// keeps its own buffer (#3191 review). + #[test] + fn a_buffer_kept_after_the_purge_of_a_reload_is_not_served() { + use crate::reads::{FileStamp, ReadFile, ReadLog}; + let dir = tempfile::tempdir().unwrap(); + let dc = crate::disk_cache::DiskCache::open(dir.path(), 1 << 30).unwrap(); + let store = Arc::new(PausedWrites { dc: dc.clone(), arrived: std::sync::Barrier::new(2), go_on: std::sync::Barrier::new(2) }); + let cache = Arc::new(LayerCache::default()); + cache.set_store(Some(store.clone())); + let buf = || Arc::new(Buf { img: Image::new(2, 2), offset: [0.0; 2], scale: 1.0 }); + let files = |cache: &LayerCache| { + let log = ReadLog::starting_at(cache.drop_generation().unwrap()); + log.note(ReadFile::new("/a.png", FileStamp::Native { len: 3, modified: Some(1) })); + Arc::new(log.into_files()) + }; + // The old render: a miss, its reads, then its insert, which stops in the disk write. + assert!(cache.get(1).is_none()); + let old_files = files(&cache); + let old = buf(); + let writer = { + let (cache, old) = (cache.clone(), old.clone()); + std::thread::spawn(move || cache.insert(1, old, old_files)) + }; + store.arrived.wait(); + // Reload Footage meanwhile: the layer cache is purged and the file dropped. + cache.clear(); + dc.drop_files(["/a.png"]); + dc.flush(); + store.go_on.wait(); + let _ = writer.join().unwrap(); + dc.flush(); + assert!(!dc.contains(crate::disk_cache::Kind::Layer, crate::disk_cache::layer_disk_key(1)), "not on disk"); + assert!(cache.get(1).is_none(), "the old pixels are not served from memory"); + // A render after the drop keeps its own buffer. + let fresh = buf(); + let new_files = files(&cache); + let mut kept = None; + std::thread::scope(|s| { + s.spawn(|| { + store.arrived.wait(); + store.go_on.wait(); + }); + kept = Some(cache.insert(1, fresh.clone(), new_files).0); + }); + let kept = kept.unwrap(); + assert!(Arc::ptr_eq(&kept, &fresh) && !Arc::ptr_eq(&kept, &old)); + assert!(Arc::ptr_eq(&cache.get(1).unwrap().0, &fresh)); + } + + /// A render that gets another render's buffer gets that buffer's files too (#3184): when a + /// file changed between the two reads, its frame lists the file with both identities, so the + /// list is incomplete and the frame is not kept on disk with the new identity and the old + /// pixels. + #[test] + fn the_buffer_kept_first_brings_its_files() { + use crate::reads::{FileStamp, ReadFile, ReadFiles, ReadLog}; + use crate::{NoFootage, RenderOpts, Renderer}; + let cache = LayerCache::default(); + let buf = || Arc::new(Buf { img: Image::new(4, 4), offset: [0.0; 2], scale: 1.0 }); + let files = |len| Arc::new([ReadFile::new("/a.png", FileStamp::Native { len, modified: Some(1) })].into_iter().collect::()); + let (first, second) = (files(1), files(2)); + let a = buf(); + cache.insert(3, a.clone(), first.clone()); + let project = effectcraft_project::Project::default(); + let log = ReadLog::new(); + let mut r = Renderer::new(&project, &NoFootage, RenderOpts::default()); + r.cache = Some(&cache); + r.reads = Some(&log); + // (what `Renderer::recorded` noted for the second render) + log.note_all(&second); + let (kept, kept_files) = r.keep(Some(3), buf(), &second); + assert!(Arc::ptr_eq(&kept, &a)); + assert_eq!(kept_files, first); + assert!(!log.files().is_complete()); + // The same files: nothing changes. + let same = ReadLog::new(); + r.reads = Some(&same); + same.note_all(&first); + let _ = r.keep(Some(3), buf(), &files(1)); + assert!(same.files().is_complete()); } } diff --git a/crates/render/src/cache/dependencies.rs b/crates/render/src/cache/dependencies.rs index db1465c07..dc4216098 100644 --- a/crates/render/src/cache/dependencies.rs +++ b/crates/render/src/cache/dependencies.rs @@ -156,7 +156,7 @@ impl Dependencies<'_> { layer.layer_time(ctx.time).0.hash(self.h); } match layer.source { - LayerSource::Solid { item } | LayerSource::Footage { item } | LayerSource::Comp { item } => { + LayerSource::Solid { item } | LayerSource::Footage { item } | LayerSource::Comp { item } | LayerSource::Model { item } => { let item = match layer.source { LayerSource::Footage { .. } => ctx.media_item(layer, item), _ => item, diff --git a/crates/render/src/disk_cache.rs b/crates/render/src/disk_cache.rs index 427198ad2..f509a5896 100644 --- a/crates/render/src/disk_cache.rs +++ b/crates/render/src/disk_cache.rs @@ -2,15 +2,25 @@ //! and layer cache entries kept on disk between sessions, like After Effects' disk cache. //! //! * Entries are files keyed by a 128-bit content hash (`/v1//<2 hex>/<32 hex>.ecc`): -//! frames by the hash of the composition's content (the comp and everything it uses, footage -//! files' size and modification time included) plus frame, scale and view; layer buffers by -//! the layer cache's content key salted with the project's footage fingerprint. A changed -//! project therefore never reads stale pixels: its keys simply change. +//! frames by the hash of the composition's content as it is in memory (the comp and what it can +//! draw, footage items with their settings and paths, and what its expressions can read; no +//! file is looked at, [`comp_content_key`]) plus frame, scale and view; layer buffers by the +//! layer cache's content key (which names the footage items a buffer uses with their settings +//! and paths) and the renderer version ([`layer_disk_key`]). A changed project therefore never +//! reads stale pixels: its keys simply change, and an edit elsewhere keeps them. +//! * Frame and layer entries keep the source files they were made of (footage, and the font +//! files text is drawn with), each with the size and modification time it was read with +//! ([`EntryFiles`], #3184). An entry is used only while those files are unchanged: a handful +//! of `metadata` calls when it is read, never a scan of the project's files. A frame or +//! buffer whose files can't all be named is not stored (text in a family that isn't installed +//! or with fallback glyphs, footage refused by automation read roots, …). File ▸ Reload +//! Footage deletes the entries made of the reloaded files ([`DiskCache::drop_files`]): a file +//! replaced by one of the same size and time is read again. //! * Payloads are LZ4-compressed (`lz4_flex`, MIT): frames as 8-bit premultiplied RGBA (or, for //! 32 bpc viewer frames, half-float RGBA with the bytes shuffled into planes; the entry -//! header's format byte tells them apart, 8-bit entries keep format 0), layer -//! buffers as `f32` RGBA with the bytes shuffled into planes (exact, so cached and fresh -//! renders are bit-identical), Roto Brush / Object Matte segmentations as +//! header's format byte tells them apart: 2 and 3, both with their source files first), layer +//! buffers (format 4, their source files first) as `f32` RGBA with the bytes shuffled into +//! planes (exact, so cached and fresh renders are bit-identical), Roto Brush / Object Matte segmentations as //! `FrameSeg::to_bytes` (keyed by their content-keyed chain key and scale, so they are //! reused whenever the same frames, settings and prompt come back, also after a restart). Every file ends in a checksum; damaged files read as misses and //! are deleted. @@ -32,6 +42,11 @@ use std::sync::{Arc, Condvar, Mutex}; use effectcraft_effects::Buf; use effectcraft_raster::Image; +use crate::reads::ReadFiles; + +mod entry_files; +pub use entry_files::{EntryFile, EntryFiles, EntryStamp}; + /// File format version (part of the folder layout). const VERSION: &str = "v1"; const MAGIC: &[u8; 4] = b"ECDC"; @@ -87,9 +102,16 @@ pub struct FrameF16 { pub rgba: Vec, } -/// The entry header's format byte of frame entries. +/// The entry header's format byte: segmentations (and 8-bit frames and layer buffers before +/// #3184). const FORMAT_RGBA8: u8 = 0; -const FORMAT_F16: u8 = 1; +/// Frame entries: their source files ([`EntryFiles`]), then 8-bit or half-float pixels. The +/// formats before them (0: 8-bit, 1: half float, without files) read as misses and are deleted. +const FORMAT_RGBA8_FILES: u8 = 2; +const FORMAT_F16_FILES: u8 = 3; +/// Layer entries: their source files ([`EntryFiles`]), then the buffer. The format before it +/// (0, without files) reads as a miss and is deleted. +const FORMAT_LAYER_FILES: u8 = 4; /// Counters for tests, the Info panel and `cache.diskStats`. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] @@ -220,7 +242,7 @@ pub struct LayerPrefetch { const PREFETCH_RECENT: usize = 512; impl LayerPrefetch { - /// A frame's layer-cache misses (salted keys). + /// A frame's layer-cache misses (disk keys, [`layer_disk_key`]). pub fn note_misses(&mut self, keys: impl IntoIterator) { for k in keys { self.recent.retain(|x| *x != k); @@ -243,6 +265,8 @@ impl LayerPrefetch { enum Job { /// Kind, key, header format byte, payload. Write(Kind, u128, u8, Vec), + /// Delete the frame and layer entries made of these files ([`DiskCache::drop_files`]). + Drop(Vec>), } struct Queue { @@ -255,14 +279,55 @@ struct Queue { busy: bool, /// Keys of frames queued or being written. pending_frames: std::collections::HashSet, + /// The drops so far (under the queue's lock: a write is queued either before a drop, which + /// then sweeps it, or after it, when this refuses it if it was made from before). + drops: Drops, +} + +/// Files dropped from the cache files beyond this are not remembered one by one: everything made +/// before the drop that forgot them is refused instead. +const MAX_DROPPED_PATHS: usize = 1 << 16; + +/// The [`DiskCache::drop_files`] calls so far: their number (the drop generation) and the last one +/// of each file. An entry made of a file read before that file's last drop (its render started at +/// an earlier generation) holds the pixels from before and is refused. +#[derive(Default)] +struct Drops { + generation: u64, + last: HashMap, u64>, + /// Everything made before this generation is refused (the per-file record was forgotten). + floor: u64, +} + +impl Drops { + /// Notes that the given paths were dropped, bumping the generation and tracking them for later checks. + fn record(&mut self, paths: &[Arc]) { + self.generation = self.generation.saturating_add(1); + if self.last.len().saturating_add(paths.len()) > MAX_DROPPED_PATHS { + self.last.clear(); + self.floor = self.generation; + return; + } + for p in paths { + self.last.insert(p.clone(), self.generation); + } + } + + /// Whether something made of `paths`, whose reads started at generation `since`, read one of + /// them before it was dropped. + fn stale<'a>(&self, mut paths: impl Iterator>, since: u64) -> bool { + since < self.floor || paths.any(|p| self.last.get(p).is_some_and(|g| *g > since)) + } } impl Queue { + /// Takes the next queued job, frames first, and releases the bytes it held. #[cfg(not(target_arch = "wasm32"))] fn pop(&mut self) -> Option { if let Some(j) = self.frames.pop_front() { - let Job::Write(_, _, _, p) = &j; - self.frame_bytes = self.frame_bytes.saturating_sub(p.len()); + if let Job::Write(_, _, _, p) = &j { + self.frame_bytes = self.frame_bytes.saturating_sub(p.len()); + } return Some(j); } self.jobs.pop_front() @@ -280,16 +345,25 @@ pub struct DiskCache { disk_cap: AtomicU64, /// Free space is limiting the cache (warned once per episode). space_limited: AtomicBool, + /// The free space the cache leaves on its disk ([`disk_reserve`]); 0 = unknown. + reserve: AtomicU64, hits: AtomicU64, misses: AtomicU64, writes: AtomicU64, evictions: AtomicU64, dropped: AtomicU64, failed: AtomicU64, + /// Source files looked at to check frame and layer entries ([`DiskCache::file_checks`]). + file_checks: AtomicU64, + /// Frame and layer entries compressed for a queued write ([`DiskCache::encodes`]). + encodes: AtomicU64, tmp_counter: AtomicU64, queue: Arc<(Mutex, Condvar)>, /// Layer buffers that took less than this to render are not written (ms). min_layer_ms: AtomicU64, + /// Files whose entries are being deleted ([`DiskCache::drop_files`]), each with the number + /// of drops of it pending: until then an entry made of one is a miss. + dropping: Mutex, u32>>, } /// FNV-1a 128-bit (content keys). @@ -326,6 +400,23 @@ fn checksum(data: &[u8]) -> u64 { h } +/// The least free space the disk cache leaves on its disk. +pub const MIN_DISK_RESERVE: u64 = 2 << 30; +/// The most free space the disk cache leaves on its disk: 5% of a large disk is far more than +/// the system needs to keep working (on a 4 TB disk it held a 20 GB cache at 0 with 190 GB free). +pub const MAX_DISK_RESERVE: u64 = 10 << 30; +/// Below this much room left by free disk space, frame and layer writes are refused before they +/// are encoded ([`DiskCache::accepts_writes`]): a few frames would fill it, and the rest would be +/// compressed only to be refused. +const MIN_WRITE_ROOM: u64 = 64 << 20; + +/// The free space the disk cache leaves on a disk of `total` bytes: 5% of it, at least 2 GB and +/// at most 10 GB. It keeps the cache from filling the disk; the cache's size is the user's +/// Maximum Disk Cache Size (After Effects has that maximum and no reserve). +pub fn disk_reserve(total: u64) -> u64 { + (total / 20).clamp(MIN_DISK_RESERVE, MAX_DISK_RESERVE) +} + /// The platform's default disk cache folder. pub fn default_folder() -> PathBuf { let home = std::env::var_os("HOME").map(PathBuf::from); @@ -356,12 +447,15 @@ impl DiskCache { max_bytes: AtomicU64::new(max_bytes), disk_cap: AtomicU64::new(u64::MAX), space_limited: AtomicBool::new(false), + reserve: AtomicU64::new(0), hits: AtomicU64::new(0), misses: AtomicU64::new(0), writes: AtomicU64::new(0), evictions: AtomicU64::new(0), dropped: AtomicU64::new(0), failed: AtomicU64::new(0), + file_checks: AtomicU64::new(0), + encodes: AtomicU64::new(0), tmp_counter: AtomicU64::new(0), queue: Arc::new(( Mutex::new(Queue { @@ -370,10 +464,12 @@ impl DiskCache { jobs: Default::default(), busy: cfg!(not(target_arch = "wasm32")), pending_frames: Default::default(), + drops: Drops::default(), }), Condvar::new(), )), min_layer_ms: AtomicU64::new(30), + dropping: Mutex::new(HashMap::new()), }); dc.rescan(); // Shrinking a large cache deletes many files: the writer thread does it. @@ -446,19 +542,22 @@ impl DiskCache { self.max_bytes().min(self.disk_cap.load(Ordering::Relaxed)) } - /// The cache's disk: `(total, available)` bytes, `None` = unknown. The cache leaves at least - /// 2 GB or 5% of the disk free, whichever is more (evicting when it must). + /// The cache's disk: `(total, available)` bytes, `None` = unknown. The cache leaves + /// [`disk_reserve`] free (5% of the disk, at least 2 GB and at most 10 GB), evicting when it + /// must. pub fn set_disk_space(&self, space: Option<(u64, u64)>) { + let mut reserve = 0; let cap = match space { // (a disk reported as 0 bytes, such as an automount map, is unknown) Some((total, available)) if total > 0 => { - let reserve = (2u64 << 30).max(total / 20); + reserve = disk_reserve(total); let used = self.index.lock().map(|g| g.total()).unwrap_or_default(); // The cache's own files count as free: below the reserve it gives space back. used.saturating_add(available).saturating_sub(reserve) } _ => u64::MAX, }; + self.reserve.store(reserve, Ordering::Relaxed); self.disk_cap.store(cap, Ordering::Relaxed); let limited = cap < self.max_bytes(); if self.space_limited.swap(limited, Ordering::Relaxed) != limited && limited { @@ -467,6 +566,33 @@ impl DiskCache { self.evict(); } + /// Whether frame and layer writes are worth encoding now: `false` while free disk space + /// holds the limit at 0 or under 64 MB (a limit the setting asks for is always used). Two + /// atomic reads, so writes check it before they spend time converting and compressing + /// pixels that [`DiskCache::write_format`] would refuse anyway. (Whether a given entry fits + /// is known only once it is compressed: `write_format` decides.) + pub fn accepts_writes(&self) -> bool { + let (max, limit) = (self.max_bytes(), self.limit_bytes()); + limit > 0 && (limit >= MIN_WRITE_ROOM || limit == max) + } + + /// The free space the cache leaves on its disk ([`disk_reserve`]), once the disk's size is + /// known ([`DiskCache::set_disk_space`]). + pub fn reserve_bytes(&self) -> Option { + Some(self.reserve.load(Ordering::Relaxed)).filter(|r| *r > 0) + } + + /// Frame and layer entries compressed for writing so far (tests: a write refused up front + /// costs no encode). + pub fn encodes(&self) -> u64 { + self.encodes.load(Ordering::Relaxed) + } + + /// Count one entry compressed for a queued write. + fn count_encode(&self) { + self.encodes.fetch_add(1, Ordering::Relaxed); + } + /// Layer buffers faster to render than this are not worth a disk write. pub fn set_min_layer_ms(&self, ms: u64) { self.min_layer_ms.store(ms, Ordering::Relaxed); @@ -541,36 +667,94 @@ impl DiskCache { /// An entry's payload and its header's format byte. fn read_entry(&self, kind: Kind, key: u128) -> Option<(u8, Vec)> { + let entry = self.load(kind, key); + match &entry { + Some(_) => self.hit(kind, key), + None => _ = self.misses.fetch_add(1, Ordering::Relaxed), + } + entry + } + + /// An entry's payload and format byte, without counting it as a hit or miss. A damaged file + /// is deleted; a missing one forgotten. + fn load(&self, kind: Kind, key: u128) -> Option<(u8, Vec)> { if !self.contains(kind, key) { - self.misses.fetch_add(1, Ordering::Relaxed); return None; } let path = self.path(kind, key); let data = std::fs::read(&path).ok(); - let ok = data.as_deref().and_then(|d| verify(d, kind).map(|p| (d[5], p))); - match ok { - Some((format, payload)) => { - let payload = (format, payload.to_vec()); - self.hits.fetch_add(1, Ordering::Relaxed); - if let Ok(mut g) = self.index.lock() { - g.touch(kind, key); - } - // Persist the recency for the next session (best effort). - if let Ok(f) = std::fs::File::options().append(true).open(&path) { - let _ = f.set_modified(std::time::SystemTime::now()); - } - Some(payload) - } - None => { - self.misses.fetch_add(1, Ordering::Relaxed); - // Gone (another process evicted it) or damaged: forget it. - if data.is_some() { - let _ = std::fs::remove_file(&path); - } - self.forget(kind, key); - None + let ok = data.as_deref().and_then(|d| Some((*d.get(5)?, verify(d, kind)?.to_vec()))); + if ok.is_none() { + // Gone (another process evicted it) or damaged: forget it. + if data.is_some() { + let _ = std::fs::remove_file(&path); } + self.forget(kind, key); } + ok + } + + /// Count a hit: the entry becomes the most recently used, also for the next session. + fn hit(&self, kind: Kind, key: u128) { + self.hits.fetch_add(1, Ordering::Relaxed); + if let Ok(mut g) = self.index.lock() { + g.touch(kind, key); + } + // Persist the recency for the next session (best effort). + if let Ok(f) = std::fs::File::options().append(true).open(self.path(kind, key)) { + let _ = f.set_modified(std::time::SystemTime::now()); + } + } + + /// An entry of `kind` and `format` whose source files are unchanged, decoded by `decode`, + /// with those files. An entry whose files changed, of the format before #3184, or damaged, + /// is a miss and is deleted (it renders again and is stored anew). A frame entry of the + /// other current frame format (8-bit and half-float frames have keys of their own) is a miss + /// and stays. + fn get_checked( + &self, + kind: Kind, + key: u128, + format: u8, + virtual_id: Option>, + decode: impl FnOnce(&[u8]) -> Option, + ) -> Option<(T, ReadFiles)> { + let miss = || { + self.misses.fetch_add(1, Ordering::Relaxed); + None + }; + // (before the file is read: the writer may finish a drop's sweep between the read and the + // check below, and a drop may start meanwhile) + let drops = self.drops_now(); + let Some((found, payload)) = self.load(kind, key) else { return miss() }; + if found != format { + let other_frame_format = kind == Kind::Frame && (found == FORMAT_RGBA8_FILES || found == FORMAT_F16_FILES); + if !other_frame_format { + self.discard(kind, key); + } + return miss(); + } + let Some((files, body)) = EntryFiles::decode(&payload) else { + self.discard(kind, key); + return miss(); + }; + self.file_checks.fetch_add(files.len() as u64, Ordering::Relaxed); + if self.made_of_dropped(&files, &drops) || !files.unchanged(virtual_id) { + self.discard(kind, key); + return miss(); + } + let Some(value) = decode(body) else { + self.discard(kind, key); + return miss(); + }; + self.hit(kind, key); + Some((value, files.to_read_files())) + } + + /// Source files looked at so far to check frame and layer entries before using them (one per + /// file a read entry lists; tests). + pub fn file_checks(&self) -> u64 { + self.file_checks.load(Ordering::Relaxed) } /// A valid file whose payload does not decode: delete it, as a damaged one. @@ -587,13 +771,19 @@ impl DiskCache { /// Queue a write; `false` when it was dropped (a full queue). fn enqueue(&self, kind: Kind, key: u128, payload: Vec) -> bool { - self.enqueue_format(kind, key, FORMAT_RGBA8, payload) + self.enqueue_format(kind, key, FORMAT_RGBA8, payload, None) } - /// [`DiskCache::enqueue`] with the entry's header format byte. - fn enqueue_format(&self, kind: Kind, key: u128, format: u8, payload: Vec) -> bool { + /// [`DiskCache::enqueue`] with the entry's header format byte. `made`: the source files of a + /// frame or layer entry and the drop generation its reads started at + /// ([`DiskCache::drop_generation`]); refused (`false`) when one of them was dropped since. + fn enqueue_format(&self, kind: Kind, key: u128, format: u8, payload: Vec, made: Option<(&EntryFiles, u64)>) -> bool { + let stale = |q: &Queue| made.is_some_and(|(files, since)| q.drops.stale(files.files().iter().map(|f| &f.path), since)); #[cfg(target_arch = "wasm32")] { + if self.queue.0.lock().is_ok_and(|q| stale(&q)) { + return false; + } self.write_format(kind, key, format, &payload); true } @@ -601,6 +791,9 @@ impl DiskCache { { let (m, cv) = &*self.queue; let Ok(mut q) = m.lock() else { return false }; + if stale(&q) { + return false; + } let full = match kind { Kind::Frame => q.frame_bytes.saturating_add(payload.len()) > FRAME_QUEUE_BYTES, _ => q.jobs.len() >= QUEUE_LIMIT, @@ -622,10 +815,6 @@ impl DiskCache { } /// Write an entry now (atomic rename), then evict down to the limit. - fn write_now(&self, kind: Kind, key: u128, payload: &[u8]) { - self.write_format(kind, key, FORMAT_RGBA8, payload); - } - fn write_format(&self, kind: Kind, key: u128, format: u8, payload: &[u8]) { if self.contains(kind, key) { return; @@ -680,70 +869,229 @@ impl DiskCache { } } + /// Delete the frame and layer entries made of any of `paths` (File ▸ Reload Footage: a file + /// replaced by one with the same size and modification time must be read again, which the + /// check on hit can't tell). The index knows keys, not files, so the writer thread reads the + /// files section at the start of each frame and layer entry (no pixels) and deletes the + /// entries that list one of `paths`, after the writes queued before (those are swept too); + /// until it is done, an entry made of one of them is a miss. Entries are deleted for good, + /// so they don't come back after a restart. Nothing else in the cache is touched. + /// + /// A render that was under way meanwhile may still offer an entry made of one of `paths` as + /// it was before: it is refused, see [`DiskCache::drop_generation`]. + pub fn drop_files(&self, paths: impl IntoIterator>>) { + let paths: Vec> = paths.into_iter().map(Into::into).collect(); + if paths.is_empty() { + return; + } + { + let mut d = self.dropping.lock().unwrap_or_else(std::sync::PoisonError::into_inner); + for p in &paths { + let n = d.entry(p.clone()).or_default(); + *n = n.saturating_add(1); + } + } + #[cfg_attr(target_arch = "wasm32", allow(unused_variables))] + let (m, cv) = &*self.queue; + match m.lock() { + Ok(mut q) => { + q.drops.record(&paths); + #[cfg(not(target_arch = "wasm32"))] + { + // (never refused for a full queue) + q.jobs.push_back(Job::Drop(paths)); + cv.notify_all(); + return; + } + } + // (no writer thread to take the job any more) + Err(poisoned) => poisoned.into_inner().drops.record(&paths), + } + self.sweep(&paths); + } + + /// The number of [`DiskCache::drop_files`] calls so far. A render takes it before it starts + /// reading and hands it to `put_frame` / `put_layer` with what it made: an entry listing a + /// file dropped after that is refused (the render may have read the file as it was before). + pub fn drop_generation(&self) -> u64 { + self.queue.0.lock().unwrap_or_else(std::sync::PoisonError::into_inner).drops.generation + } + + /// Whether one of `files` was dropped after generation `since` ([`DiskCache::drop_generation`]), + /// or after the earlier generation the list's own reads started at ([`ReadFiles::since`]: a + /// buffer made by an earlier render, from memory): what was made of them then is from before + /// the drop (shown, never stored). + pub fn dropped_since(&self, files: &ReadFiles, since: u64) -> bool { + let since = files.since().map_or(since, |s| s.min(since)); + self.queue.0.lock().unwrap_or_else(std::sync::PoisonError::into_inner).drops.stale(files.files().iter().map(|f| &f.path), since) + } + + /// Whether a [`DiskCache::drop_files`] is pending. + pub fn is_dropping(&self) -> bool { + !self.dropping.lock().unwrap_or_else(std::sync::PoisonError::into_inner).is_empty() + } + + /// The drop generation and the files being dropped now, taken before an entry is read + /// (see [`DiskCache::made_of_dropped`]). + fn drops_now(&self) -> (u64, Vec>) { + let generation = self.drop_generation(); + let d = self.dropping.lock().unwrap_or_else(std::sync::PoisonError::into_inner); + (generation, d.keys().cloned().collect()) + } + + /// An entry read after [`DiskCache::drops_now`] gave `drops` that is made of a file whose + /// drop was pending then (its sweep may have ended since, after the entry was read) or that + /// was dropped since. + fn made_of_dropped(&self, files: &EntryFiles, drops: &(u64, Vec>)) -> bool { + let (since, pending) = drops; + let paths = || files.files().iter().map(|f| &f.path); + paths().any(|p| pending.contains(p)) || self.queue.0.lock().unwrap_or_else(std::sync::PoisonError::into_inner).drops.stale(paths(), *since) + } + + /// The writer's part of [`DiskCache::drop_files`]: delete the entries made of `paths`, then + /// end their drop. + fn sweep(&self, paths: &[Arc]) { + let set: std::collections::HashSet<&str> = paths.iter().map(|p| &**p).collect(); + for kind in [Kind::Frame, Kind::Layer] { + for key in self.keys(kind) { + if self.entry_files(kind, key).is_some_and(|f| f.files().iter().any(|f| set.contains(&*f.path))) { + self.discard(kind, key); + } + } + } + let mut d = self.dropping.lock().unwrap_or_else(std::sync::PoisonError::into_inner); + for p in paths { + if let Some(n) = d.get_mut(p) { + *n = n.saturating_sub(1); + if *n == 0 { + d.remove(p); + } + } + } + } + + /// The source files a frame or layer entry lists, read from the start of its file (the + /// whole file only when the list is longer than that). `None` when it has none to read (an + /// earlier format, gone, damaged): such an entry is never used anyway. + fn entry_files(&self, kind: Kind, key: u128) -> Option { + use std::io::Read; + const HEAD: u64 = 64 << 10; + let parse = |d: &[u8]| { + let format = *d.get(5)?; + let ours = d.get(..4)? == MAGIC && *d.get(4)? == kind.tag(); + if !ours || !matches!(format, FORMAT_RGBA8_FILES | FORMAT_F16_FILES | FORMAT_LAYER_FILES) { + return None; + } + EntryFiles::decode(d.get(8..)?).map(|(files, _)| files) + }; + let path = self.path(kind, key); + let mut head = Vec::new(); + std::fs::File::open(&path).ok()?.take(HEAD).read_to_end(&mut head).ok()?; + parse(&head).or_else(|| if head.len() as u64 == HEAD { parse(&std::fs::read(&path).ok()?) } else { None }) + } + // ------------------------------------------------------------ typed entries - /// An 8-bit frame (`None` for a half-float entry of that key, which [`DiskCache::get_frame_f16`] - /// reads). - pub fn get_frame(&self, key: u128) -> Option { - let (format, p) = self.read_entry(Kind::Frame, key)?; - if format != FORMAT_RGBA8 { - return None; - } - decode_frame(&p) + /// An 8-bit frame whose source files are unchanged (see [`DiskCache::get_checked`]), with + /// those files; `None` for a half-float entry of that key, which + /// [`DiskCache::get_frame_f16`] reads. `virtual_id` names files served from memory. + pub fn get_frame(&self, key: u128, virtual_id: Option>) -> Option<(Frame8, ReadFiles)> { + self.get_checked(Kind::Frame, key, FORMAT_RGBA8_FILES, virtual_id, decode_frame) } - /// A half-float frame (32 bpc viewer frames). A damaged one is deleted. - pub fn get_frame_f16(&self, key: u128) -> Option { - let (format, p) = self.read_entry(Kind::Frame, key)?; - if format != FORMAT_F16 { - return None; - } - let f = decode_frame_f16(&p); - if f.is_none() { - self.discard(Kind::Frame, key); - } - f + /// A half-float frame (32 bpc viewer frames), as [`DiskCache::get_frame`]. + pub fn get_frame_f16(&self, key: u128, virtual_id: Option>) -> Option<(FrameF16, ReadFiles)> { + self.get_checked(Kind::Frame, key, FORMAT_F16_FILES, virtual_id, decode_frame_f16) } - /// Queue a half-float frame for writing (`width * height * 4` binary16 values). `true` when - /// it is on disk or queued; `false` when refused (wrong size, a full queue). - pub fn put_frame_f16(&self, key: u128, width: u32, height: u32, rgba: &[u16]) -> bool { + /// Queue a half-float frame for writing (`width * height * 4` binary16 values) with the + /// source files it was made of. `true` when it is on disk or queued; `false` when refused + /// (wrong size, a full queue, no room on the disk, files that can't be checked later: see + /// [`EntryFiles::of`]; a file dropped after `since`, the [`DiskCache::drop_generation`] the + /// render started at). + #[allow(clippy::too_many_arguments)] + pub fn put_frame_f16( + &self, + key: u128, + width: u32, + height: u32, + rgba: &[u16], + files: &ReadFiles, + virtual_id: Option>, + since: u64, + ) -> bool { if rgba.len() as u64 != width as u64 * height as u64 * 4 { return false; } - self.contains(Kind::Frame, key) || self.enqueue_format(Kind::Frame, key, FORMAT_F16, encode_frame_f16(width, height, rgba)) - } - - /// Write a half-float frame synchronously (tests). - pub fn put_frame_f16_now(&self, key: u128, width: u32, height: u32, rgba: &[u16]) { - self.write_format(Kind::Frame, key, FORMAT_F16, &encode_frame_f16(width, height, rgba)); - } - - /// Queue a frame for writing (8-bit premultiplied RGBA, `width * height * 4` bytes). `true` - /// when it is on disk or queued; `false` when refused (wrong size, a full queue). - pub fn put_frame(&self, key: u128, width: u32, height: u32, rgba: &[u8]) -> bool { - if rgba.len() != width as usize * height as usize * 4 { + let Some(files) = EntryFiles::of(files, virtual_id) else { return false }; + if self.contains(Kind::Frame, key) { + return true; + } + // (no room on the disk: refused before the pixels are compressed) + if !self.accepts_writes() { return false; } - self.contains(Kind::Frame, key) || self.enqueue(Kind::Frame, key, encode_frame(width, height, rgba)) + self.count_encode(); + let payload = with_files(&files, encode_frame_f16(width, height, rgba)); + self.enqueue_format(Kind::Frame, key, FORMAT_F16_FILES, payload, Some((&files, since))) } - pub fn get_layer(&self, key: u128) -> Option { - let p = self.read(Kind::Layer, key)?; - decode_layer(&p) + /// Write a half-float frame synchronously (tests); a list that can't be stored is not. + pub fn put_frame_f16_now(&self, key: u128, width: u32, height: u32, rgba: &[u16], files: &ReadFiles) { + if let Some(files) = EntryFiles::of(files, None) { + self.write_format(Kind::Frame, key, FORMAT_F16_FILES, &with_files(&files, encode_frame_f16(width, height, rgba))); + } } - /// Queue a layer buffer for writing. - pub fn put_layer(&self, key: u128, buf: &Buf) { - if self.contains(Kind::Layer, key) { + /// Queue a frame for writing (8-bit premultiplied RGBA, `width * height * 4` bytes) with the + /// source files it was made of. `true` when it is on disk or queued; `false` when refused + /// (wrong size, a full queue, no room on the disk, files that can't be checked later: see + /// [`EntryFiles::of`]; a file dropped after `since`, the [`DiskCache::drop_generation`] the + /// render started at). + #[allow(clippy::too_many_arguments)] + pub fn put_frame(&self, key: u128, width: u32, height: u32, rgba: &[u8], files: &ReadFiles, virtual_id: Option>, since: u64) -> bool { + if rgba.len() as u64 != width as u64 * height as u64 * 4 { + return false; + } + let Some(files) = EntryFiles::of(files, virtual_id) else { return false }; + if self.contains(Kind::Frame, key) { + return true; + } + // (no room on the disk: refused before the pixels are compressed) + if !self.accepts_writes() { + return false; + } + self.count_encode(); + let payload = with_files(&files, encode_frame(width, height, rgba)); + self.enqueue_format(Kind::Frame, key, FORMAT_RGBA8_FILES, payload, Some((&files, since))) + } + + /// A layer buffer (key: [`layer_disk_key`]) whose source files are unchanged, with those + /// files, as [`DiskCache::get_checked`]: an entry whose files changed, damaged, or of the + /// format before #3184 is a miss and is deleted, so the buffer renders again and replaces it. + /// `virtual_id` names files served from memory. + pub fn get_layer(&self, key: u128, virtual_id: Option>) -> Option<(Buf, ReadFiles)> { + self.get_checked(Kind::Layer, key, FORMAT_LAYER_FILES, virtual_id, decode_layer) + } + + /// Queue a layer buffer for writing with the source files it was made of (see + /// [`EntryFiles::of`]: a buffer whose files can't all be named must not be stored). Refused + /// when one of them was dropped after `since`, the [`DiskCache::drop_generation`] its render + /// started at. + pub fn put_layer(&self, key: u128, buf: &Buf, files: &EntryFiles, since: u64) { + // (no room on the disk: refused before the buffer is compressed) + if self.contains(Kind::Layer, key) || !self.accepts_writes() { return; } - let _ = self.enqueue(Kind::Layer, key, encode_layer(buf)); + self.count_encode(); + let _ = self.enqueue_format(Kind::Layer, key, FORMAT_LAYER_FILES, with_files(files, encode_layer(buf)), Some((files, since))); } - /// Write a layer buffer synchronously (tests). - pub fn put_layer_now(&self, key: u128, buf: &Buf) { - self.write_now(Kind::Layer, key, &encode_layer(buf)); + /// Write a layer buffer synchronously (tests); a list that can't be stored is not. + pub fn put_layer_now(&self, key: u128, buf: &Buf, files: &ReadFiles) { + if let Some(files) = EntryFiles::of(files, None) { + self.write_format(Kind::Layer, key, FORMAT_LAYER_FILES, &with_files(&files, encode_layer(buf))); + } } /// A segmentation (chain key, scale) written by [`DiskCache::put_seg`]. @@ -767,7 +1115,8 @@ impl DiskCache { /// has no links. `false` when `from` isn't cached, `to` already is, or the file system /// refused. (Entries don't contain their key, so the same file serves both.) pub fn link_frame(&self, from: u128, to: u128) -> bool { - if !self.contains(Kind::Frame, from) || self.contains(Kind::Frame, to) { + // (while files are being dropped, `from` may be made of one: it renders again instead) + if !self.contains(Kind::Frame, from) || self.contains(Kind::Frame, to) || self.is_dropping() { return false; } let (src, dst) = (self.path(Kind::Frame, from), self.path(Kind::Frame, to)); @@ -794,12 +1143,23 @@ impl DiskCache { true } - /// Write a frame synchronously (tests). - pub fn put_frame_now(&self, key: u128, width: u32, height: u32, rgba: &[u8]) { - self.write_now(Kind::Frame, key, &encode_frame(width, height, rgba)); + /// Write a frame synchronously (tests); a list that can't be stored is not. + pub fn put_frame_now(&self, key: u128, width: u32, height: u32, rgba: &[u8], files: &ReadFiles) { + if let Some(files) = EntryFiles::of(files, None) { + self.write_format(Kind::Frame, key, FORMAT_RGBA8_FILES, &with_files(&files, encode_frame(width, height, rgba))); + } } } +/// A frame or layer entry's payload: its source files, then its pixels. +fn with_files(files: &EntryFiles, pixels: Vec) -> Vec { + let mut out = Vec::with_capacity(pixels.len() + 64); + files.encode(&mut out); + out.extend_from_slice(&pixels); + out +} + +/// The writer thread: evicts to the limit at open, then drains the job queue until the cache is dropped. #[cfg(not(target_arch = "wasm32"))] fn writer(dc: std::sync::Weak, q: Arc<(Mutex, Condvar)>) { let (m, cv) = &*q; @@ -830,12 +1190,20 @@ fn writer(dc: std::sync::Weak, q: Arc<(Mutex, Condvar)>) { } }; let Some(cache) = dc.upgrade() else { return }; - let Job::Write(kind, key, format, payload) = job; - cache.write_format(kind, key, format, &payload); + let written = match job { + Job::Write(kind, key, format, payload) => { + cache.write_format(kind, key, format, &payload); + (kind == Kind::Frame).then_some(key) + } + Job::Drop(paths) => { + cache.sweep(&paths); + None + } + }; drop(cache); if let Ok(mut g) = m.lock() { g.busy = false; - if kind == Kind::Frame { + if let Some(key) = written { g.pending_frames.remove(&key); } } @@ -843,12 +1211,9 @@ fn writer(dc: std::sync::Weak, q: Arc<(Mutex, Condvar)>) { } } -/// An entry file's bytes: header (magic, kind, format 0), payload, checksum. -pub fn seal(kind: Kind, payload: &[u8]) -> Vec { - seal_format(kind, FORMAT_RGBA8, payload) -} - -/// [`seal`] with the header's format byte (frames: 0 = 8-bit, 1 = half float). +/// An entry file's bytes: header (magic, kind, the format byte: [`FORMAT_RGBA8`] for +/// segmentations, [`FORMAT_RGBA8_FILES`] / [`FORMAT_F16_FILES`] for frames, +/// [`FORMAT_LAYER_FILES`] for layer buffers), payload, checksum. fn seal_format(kind: Kind, format: u8, payload: &[u8]) -> Vec { let mut data = Vec::with_capacity(payload.len() + 16); data.extend_from_slice(MAGIC); @@ -860,26 +1225,47 @@ fn seal_format(kind: Kind, format: u8, payload: &[u8]) -> Vec { data } -/// A sealed frame entry ([`seal`] of the encoded frame): what the browser's frame workers -/// write to the Origin Private File System. -pub fn frame_entry(width: u32, height: u32, rgba: &[u8]) -> Vec { - seal(Kind::Frame, &encode_frame(width, height, rgba)) +/// A sealed 8-bit frame entry with the source files it was made of: what the browser's frame +/// workers write to the Origin Private File System. `None` when the frame must not be stored +/// (its files can't be checked later, see [`EntryFiles::of`]; or a wrong size). +pub fn frame_entry(width: u32, height: u32, rgba: &[u8], files: &ReadFiles, virtual_id: Option>) -> Option> { + if rgba.len() as u64 != width as u64 * height as u64 * 4 { + return None; + } + let files = EntryFiles::of(files, virtual_id)?; + Some(seal_format(Kind::Frame, FORMAT_RGBA8_FILES, &with_files(&files, encode_frame(width, height, rgba)))) } -/// A frame from a sealed entry's bytes (`None` when damaged). -pub fn read_frame_entry(data: &[u8]) -> Option { - decode_frame(verify(data, Kind::Frame)?) +/// The frame of a sealed entry's bytes, if its source files are unchanged. `None` when damaged, +/// of another format, or made of files that changed since: a miss, to be rendered again. +pub fn read_frame_entry(data: &[u8], virtual_id: Option>) -> Option { + let payload = verify(data, Kind::Frame)?; + if data.get(5) != Some(&FORMAT_RGBA8_FILES) { + return None; + } + let (files, pixels) = EntryFiles::decode(payload)?; + if !files.unchanged(virtual_id) { + return None; + } + decode_frame(pixels) } -/// A sealed layer-buffer entry: what the browser's frame workers write to the Origin Private -/// File System (`layers/<32 hex>.ecc`). -pub fn layer_entry(buf: &Buf) -> Vec { - seal(Kind::Layer, &encode_layer(buf)) +/// A sealed layer-buffer entry with the source files it was made of: what the browser's frame +/// workers write to the Origin Private File System (`layers/<32 hex>.ecc`). +pub fn layer_entry(buf: &Buf, files: &EntryFiles) -> Vec { + seal_format(Kind::Layer, FORMAT_LAYER_FILES, &with_files(files, encode_layer(buf))) } -/// A layer buffer from a sealed entry's bytes (`None` when damaged). -pub fn read_layer_entry(data: &[u8]) -> Option { - decode_layer(verify(data, Kind::Layer)?) +/// A layer buffer and its source files from a sealed entry's bytes (`None` when damaged or of +/// another format). The files are not looked at here: the store checks them when the buffer is +/// used ([`EntryFiles::unchanged`]). +pub fn read_layer_entry(data: &[u8]) -> Option<(Buf, EntryFiles)> { + let payload = verify(data, Kind::Layer)?; + if data.get(5) != Some(&FORMAT_LAYER_FILES) { + return None; + } + let (files, body) = EntryFiles::decode(payload)?; + Some((decode_layer(body)?, files)) } /// The disk key of a segmentation: its chain key and scale. @@ -901,11 +1287,20 @@ impl effectcraft_effects::roto::SegStore for DiskCache { } impl crate::cache::LayerStore for DiskCache { - fn get_layer(&self, key: u128) -> Option> { - DiskCache::get_layer(self, key).map(Arc::new) + /// The layer for `key` from the disk cache, or `None` when it is missing or stale. + fn get_layer(&self, key: u128, virtual_id: Option>) -> Option<(Arc, ReadFiles)> { + DiskCache::get_layer(self, key, virtual_id).map(|(b, f)| (Arc::new(b), f)) } - fn put_layer(&self, key: u128, buf: &Buf) { - DiskCache::put_layer(self, key, buf); + /// Queues a layer write on the disk cache. + fn put_layer(&self, key: u128, buf: &Buf, files: &EntryFiles, since: u64) { + DiskCache::put_layer(self, key, buf, files, since); + } + /// The current drop generation of the disk cache. + fn drop_generation(&self) -> u64 { + DiskCache::drop_generation(self) + } + fn dropped_since(&self, files: &ReadFiles, since: u64) -> bool { + DiskCache::dropped_since(self, files, since) } fn min_layer_ms(&self) -> u64 { DiskCache::min_layer_ms(self) @@ -1015,6 +1410,7 @@ fn encode_layer(b: &Buf) -> Vec { out } +/// Decodes a stored layer payload into a buffer, or `None` when it is too short or damaged. fn decode_layer(p: &[u8]) -> Option { if p.len() < 32 { return None; @@ -1025,8 +1421,8 @@ fn decode_layer(p: &[u8]) -> Option { let offset = [f(8)?, f(16)?]; let scale = f(24)?; let planes = lz4_flex::decompress_size_prepended(&p[32..]).ok()?; - let n = w as usize * h as usize; - if planes.len() != n * 16 { + let n = (w as usize).checked_mul(h as usize)?; + if planes.len() != n.checked_mul(16)? { return None; } let mut img = Image::new(w, h); @@ -1047,6 +1443,7 @@ fn decode_layer(p: &[u8]) -> Option { /// Bump when rendering changes in a way that makes old disk entries wrong. const RENDER_VERSION: &str = "effectcraft-render-6"; +/// Feeds the `Debug` form of `v` into the hash, followed by a separator byte. fn hash_debug(h: &mut Hash128, v: &impl std::fmt::Debug) { h.write(format!("{v:?}").as_bytes()); h.write(&[0xff]); @@ -1055,126 +1452,63 @@ fn hash_debug(h: &mut Hash128, v: &impl std::fmt::Debug) { /// Size and content hash of a path that has no native metadata (the browser file table). pub type VirtualFileId<'a> = &'a (dyn Fn(&str) -> Option<(u64, u64)> + Send + Sync); -/// A file's size and modification time (so edited footage gets new keys). When the path has no -/// native metadata, `virtual_id` supplies a durable size and content hash instead. -fn file_stamp(h: &mut Hash128, path: &str, virtual_id: Option>) { - if path.is_empty() { - return; - } - if let Ok(md) = std::fs::metadata(path) { - h.write_u64(md.len()); - if let Ok(t) = md.modified() - && let Ok(d) = t.duration_since(std::time::UNIX_EPOCH) - { - h.write_u64(d.as_nanos() as u64); - } - return; - } - if let Some((len, hash)) = virtual_id.and_then(|id| id(path)) { - h.write_u64(len); - h.write_u64(hash); - } -} +/// A [`VirtualFileId`] a cache can keep (the browser file table's identities). +pub type SharedVirtualFileId = Arc Option<(u64, u64)> + Send + Sync>; -fn footage_stamp(h: &mut Hash128, f: &effectcraft_project::Footage, virtual_id: Option>) { - file_stamp(h, &f.path, virtual_id); - for p in &f.sequence { - file_stamp(h, p, virtual_id); - } -} +/// Layer entries with their source files (#3184), part of every layer disk key: entries of the +/// earlier format (keyed by a project-wide footage salt instead) are never looked up again; +/// least recently used, they are evicted. +const LAYER_ENTRY_VERSION: &[u8] = b"layer-entry-files-2"; -/// Salt for layer cache keys on disk: the renderer version and every footage file's identity -/// (layer keys name footage items, not file contents). -pub fn footage_salt(project: &effectcraft_project::Project) -> u64 { - footage_salt_with(project, None) -} - -/// [`footage_salt`] with [`VirtualFileId`] for paths `std::fs::metadata` cannot describe. -pub fn footage_salt_with(project: &effectcraft_project::Project, virtual_id: Option>) -> u64 { +/// Disk key of a layer buffer: the layer cache's content key ([`crate::cache::layer_key`] and +/// the keys derived from it), the layer entry format and the renderer version. The content key +/// comes from memory alone: it names the footage items the buffer uses with their settings and +/// paths, so two projects only share an entry for the same pixels of the same files; whether +/// those files still hold what the buffer was made of is checked when the entry is read +/// ([`EntryFiles`]). No file is looked at here. +pub fn layer_disk_key(key: u64) -> u128 { let mut h = Hash128::default(); + h.write(LAYER_ENTRY_VERSION); h.write(RENDER_VERSION.as_bytes()); - // Footage another layer reads (Audio Spectrum's Audio Layer); a read precomp can hold any. - let mut read = std::collections::BTreeSet::new(); - let mut read_comp = false; - for (_, c) in project.comps() { - for l in c.layers.iter() { - for r in l.referenced_layers().into_iter().filter(|r| *r != l.id) { - match c.layer(r).map(|x| &x.source) { - Some(effectcraft_project::LayerSource::Footage { item }) => _ = read.insert(*item), - Some(effectcraft_project::LayerSource::Comp { .. }) => read_comp = true, - _ => {} - } - } - } - } - for (id, it) in &project.items { - // (files without video make layer buffers only through a layer that reads them: - // importing music keeps the keys) - if let effectcraft_project::ItemKind::Footage(f) = &it.kind - && (f.has_video || read_comp || read.contains(id)) - { - h.write_u64(id.0); - hash_debug(&mut h, f); - footage_stamp(&mut h, f, virtual_id); - } - if let Some(proxy) = it.proxy.as_ref().filter(|p| p.enabled) { - h.write_u64(id.0); - hash_debug(&mut h, proxy); - footage_stamp(&mut h, &proxy.footage, virtual_id); - } - } - let v = h.finish(); - (v as u64) ^ ((v >> 64) as u64) + h.write_u64(key); + h.finish() } -/// Content key of a composition's pixels: project render settings, the comp and everything it -/// uses (nested comps, footage, solids, their proxies and Use Proxy switches, footage and proxy -/// files' size and time). With expressions in play (which can read any comp) the whole project -/// counts. Switches that don't change pixels (Audio, Lock, Shy, Hide Shy Layers) don't count, and -/// neither do markers unless an expression mentions them. +/// Content key of a composition's pixels, from the project in memory alone (no file is looked +/// at: the frame entries check their own source files when read, see [`EntryFiles`]): project +/// render settings, the comp and the items it can draw (nested comps, footage items with their +/// settings and paths, solids, Media Replacement footage, their proxies and Use Proxy switches; +/// [`effectcraft_project::Project::pixel_reach`]). With expressions among them, everything those +/// expressions can read counts too: every layer of their comps, markers, the comps and footage +/// they name with literal names (and which items have those names), or the whole project when +/// they compute a name or reach items another way. An edit to an item the comp can't reach keeps +/// its key and its frames on disk (#3184, #1492). Switches that don't change pixels (Audio, Lock, +/// Shy, Hide Shy Layers) don't count, and neither do markers unless an expression can read them. pub fn comp_content_key(project: &effectcraft_project::Project, comp: effectcraft_project::ItemId) -> u128 { - comp_content_key_with(project, comp, None) + comp_content_key_for_renderer(project, comp, RENDER_VERSION) } -/// [`comp_content_key`] with [`VirtualFileId`] for paths `std::fs::metadata` cannot describe. -pub fn comp_content_key_with(project: &effectcraft_project::Project, comp: effectcraft_project::ItemId, virtual_id: Option>) -> u128 { - comp_content_key_for_renderer(project, comp, virtual_id, RENDER_VERSION) -} - -fn comp_content_key_for_renderer( - project: &effectcraft_project::Project, - comp: effectcraft_project::ItemId, - virtual_id: Option>, - renderer: &str, -) -> u128 { - use effectcraft_project::{ItemKind, LayerSource}; +/// The content key of `comp` for one renderer: its settings, the comps and footage it uses, and the renderer name. +fn comp_content_key_for_renderer(project: &effectcraft_project::Project, comp: effectcraft_project::ItemId, renderer: &str) -> u128 { + use effectcraft_project::ItemKind; let mut h = Hash128::default(); h.write(renderer.as_bytes()); hash_debug(&mut h, &project.settings); - // Expressions can read anything (every item counts); without them, layers that can't - // change the picture (music, hidden layers nothing reads) and their files don't count. - let expressions = project.reads_markers(); let heard = project.heard_layers(); + let reach = project.pixel_reach(comp, &heard); + // Expressions can read any layer of the comps they reach, hidden or not, and their markers + // (#1083); without them, layers that can't change the picture (music, hidden layers nothing + // reads) don't count. + let expressions = reach.expressions; let silent = |id, c: &effectcraft_project::Comp| if expressions { Default::default() } else { project.silent_layers(id, c, &heard) }; - let mut seen = std::collections::BTreeSet::new(); - let mut stack = vec![comp]; - while let Some(id) = stack.pop() { - if !seen.insert(id) { - continue; - } - let Some(it) = project.item(id) else { continue }; - if let ItemKind::Comp(c) = &it.kind { - let quiet = silent(id, c); - for l in c.layers.iter().filter(|l| !quiet.contains(&l.id)) { - if let LayerSource::Comp { item } | LayerSource::Footage { item } | LayerSource::Solid { item } = l.source { - stack.push(item); - } - } - } + // (the names expressions look items up by: which items have them now) + if !reach.names.is_empty() { + hash_debug(&mut h, &reach.names); } - // Markers are pixels only to the expressions that read them (#1083). - let markers = expressions; - let ids: Vec = if expressions { project.items.keys().copied().collect() } else { seen.into_iter().collect() }; + let ids: Vec = match reach.items { + Some(items) => items.into_iter().collect(), + None => project.items.keys().copied().collect(), + }; for id in ids { let Some(it) = project.item(id) else { continue }; h.write_u64(id.0); @@ -1184,30 +1518,30 @@ fn comp_content_key_for_renderer( let quiet = silent(id, c); let heard = |l| heard.contains(id, l); if quiet.is_empty() { - hash_debug(&mut h, &c.pixel_form_with(markers, &heard)); + hash_debug(&mut h, &c.pixel_form_with(expressions, &heard)); } else { let mut pic = (**c).clone(); pic.layers.retain(|l| !quiet.contains(&l.id)); - hash_debug(&mut h, &pic.pixel_form_with(markers, &heard)); + hash_debug(&mut h, &pic.pixel_form_with(expressions, &heard)); } } k => hash_debug(&mut h, k), } - if let ItemKind::Footage(f) = &it.kind { - footage_stamp(&mut h, f, virtual_id); - } hash_debug(&mut h, &it.proxy); - if let Some(px) = &it.proxy { - footage_stamp(&mut h, &px.footage, virtual_id); - } } h.write_u64(comp.0); h.finish() } +/// Frame entries with their source files (#3184), part of every frame key: entries of the +/// earlier format (keyed by footage stamps instead) are never looked up again; least recently +/// used, they are evicted. +const FRAME_ENTRY_VERSION: &[u8] = b"frame-entry-files-2"; + /// Disk key of one viewer frame. pub fn frame_key(content: u128, frame: i64, scale_milli: u32, view: u64) -> u128 { let mut h = Hash128::default(); + h.write(FRAME_ENTRY_VERSION); h.write(&content.to_le_bytes()); h.write_u64(frame as u64); h.write_u64(scale_milli as u64); @@ -1231,18 +1565,18 @@ mod tests { fn link_frame_serves_a_frame_under_a_new_key() { let dc = DiskCache::open(tmpdir("link"), 1 << 30).unwrap(); let rgba: Vec = (0..16).collect(); - dc.put_frame_now(1, 2, 2, &rgba); + dc.put_frame_now(1, 2, 2, &rgba, &ReadFiles::default()); assert!(dc.link_frame(1, 2)); - assert_eq!(dc.get_frame(2).map(|f| f.rgba), Some(rgba.clone())); + assert_eq!(dc.get_frame(2, None).map(|f| f.0).map(|f| f.rgba), Some(rgba.clone())); assert!(!dc.link_frame(1, 2), "already there"); assert!(!dc.link_frame(3, 4), "nothing to link"); assert!(!dc.contains(Kind::Frame, 4)); - dc.put_frame_now(5, 2, 2, &[7; 16]); + dc.put_frame_now(5, 2, 2, &[7; 16], &ReadFiles::default()); assert!(!dc.link_frame(5, 2), "an existing entry stays"); - assert_eq!(dc.get_frame(2).map(|f| f.rgba), Some(rgba.clone())); + assert_eq!(dc.get_frame(2, None).map(|f| f.0).map(|f| f.rgba), Some(rgba.clone())); let _ = std::fs::remove_file(dc.path(Kind::Frame, 1)); dc.forget(Kind::Frame, 1); - assert_eq!(dc.get_frame(2).map(|f| f.rgba), Some(rgba), "the link outlives the original"); + assert_eq!(dc.get_frame(2, None).map(|f| f.0).map(|f| f.rgba), Some(rgba), "the link outlives the original"); } fn buf(seed: u32, w: u32, h: u32) -> Buf { @@ -1277,11 +1611,21 @@ mod tests { #[test] fn frame_entries_round_trip_and_names_parse() { let rgba: Vec = (0..4 * 6 * 3).map(|i| (i * 7 % 256) as u8).collect(); - let e = frame_entry(6, 3, &rgba); - assert_eq!(read_frame_entry(&e), Some(Frame8 { width: 6, height: 3, rgba: rgba.clone() })); + let files: ReadFiles = [crate::reads::ReadFile::new("/v.png", crate::reads::FileStamp::Virtual)].into_iter().collect(); + let (one, two) = (|_: &str| Some((4, 1)), |_: &str| Some((4, 2))); + assert!(frame_entry(6, 3, &rgba, &files, None).is_none(), "a file from memory needs its identity"); + assert!(frame_entry(6, 3, &rgba[1..], &files, Some(&one)).is_none(), "a wrong size"); + let e = frame_entry(6, 3, &rgba, &files, Some(&one)).unwrap(); + assert_eq!(read_frame_entry(&e, Some(&one)), Some(Frame8 { width: 6, height: 3, rgba: rgba.clone() })); + assert!(read_frame_entry(&e, Some(&two)).is_none(), "the file changed"); + let mut incomplete = files.clone(); + incomplete.mark_incomplete(); + assert!(frame_entry(6, 3, &rgba, &incomplete, Some(&one)).is_none(), "an incomplete list is not stored"); let mut bad = e.clone(); bad[20] ^= 1; - assert!(read_frame_entry(&bad).is_none()); + assert!(read_frame_entry(&bad, Some(&one)).is_none()); + // An entry of the format before #3184 (pixels without files) is never read. + assert!(read_frame_entry(&seal_format(Kind::Frame, FORMAT_RGBA8, &encode_frame(6, 3, &rgba)), Some(&one)).is_none()); let key = 0x0123_4567_89ab_cdef_0011_2233_4455_6677u128; assert_eq!(parse_entry_name(&entry_name(key)), Some(key)); assert_eq!(parse_entry_name("abc.ecc"), None); @@ -1298,27 +1642,27 @@ mod tests { let (w, h) = (7u32, 5u32); // 4.0, 16.0, -0.25, 65504 and a spread of bit patterns. let rgba: Vec = (0..w * h * 4).map(|i| [0x4400, 0x4c00, 0xb400, 0x7bff][i as usize % 4] ^ ((i * 37) as u16 & 0x03ff)).collect(); - dc.put_frame_f16_now(1, w, h, &rgba); - assert_eq!(dc.get_frame_f16(1), Some(FrameF16 { width: w, height: h, rgba: rgba.clone() })); - assert!(dc.get_frame(1).is_none(), "not an 8-bit frame"); - dc.put_frame_now(2, 2, 2, &[9; 16]); - assert!(dc.get_frame_f16(2).is_none() && dc.contains(Kind::Frame, 2), "an 8-bit entry stays valid"); - assert_eq!(dc.get_frame(2).unwrap().rgba, vec![9; 16]); + dc.put_frame_f16_now(1, w, h, &rgba, &ReadFiles::default()); + assert_eq!(dc.get_frame_f16(1, None).map(|f| f.0), Some(FrameF16 { width: w, height: h, rgba: rgba.clone() })); + assert!(dc.get_frame(1, None).map(|f| f.0).is_none(), "not an 8-bit frame"); + dc.put_frame_now(2, 2, 2, &[9; 16], &ReadFiles::default()); + assert!(dc.get_frame_f16(2, None).map(|f| f.0).is_none() && dc.contains(Kind::Frame, 2), "an 8-bit entry stays valid"); + assert_eq!(dc.get_frame(2, None).map(|f| f.0).unwrap().rgba, vec![9; 16]); assert!(dc.stats().bytes > 0); // Reopened, still there (format byte persisted). drop(dc); let dc = DiskCache::open(&dir, 1 << 30).unwrap(); - assert_eq!(dc.get_frame_f16(1).unwrap().rgba, rgba); + assert_eq!(dc.get_frame_f16(1, None).map(|f| f.0).unwrap().rgba, rgba); // A sealed entry with a payload of the wrong size: deleted on read. let p = dc.path(Kind::Frame, 3); std::fs::create_dir_all(p.parent().unwrap()).unwrap(); - std::fs::write(&p, seal_format(Kind::Frame, FORMAT_F16, &encode_frame_f16(w, h + 1, &rgba[..])[..])).unwrap(); + std::fs::write(&p, seal_format(Kind::Frame, FORMAT_F16_FILES, &with_files(&EntryFiles::default(), encode_frame_f16(w, h + 1, &rgba[..])))).unwrap(); dc.rescan(); assert!(dc.contains(Kind::Frame, 3)); - assert!(dc.get_frame_f16(3).is_none()); + assert!(dc.get_frame_f16(3, None).map(|f| f.0).is_none()); assert!(!dc.contains(Kind::Frame, 3) && !p.exists()); // Wrong lengths are not written. - dc.put_frame_f16(4, w, h, &rgba[1..]); + dc.put_frame_f16(4, w, h, &rgba[1..], &ReadFiles::default(), None, 0); dc.flush(); assert!(!dc.contains(Kind::Frame, 4)); let _ = std::fs::remove_dir_all(&dir); @@ -1360,26 +1704,27 @@ mod tests { fn hit_miss_and_exact_round_trip() { let dir = tmpdir("hit"); let dc = DiskCache::open(&dir, 1 << 30).unwrap(); - assert!(dc.get_layer(42).is_none()); + assert!(dc.get_layer(42, None).is_none()); let b = buf(1, 33, 17); - dc.put_layer(42, &b); + dc.put_layer(42, &b, &EntryFiles::default(), 0); dc.flush(); - let back = dc.get_layer(42).unwrap(); + let (back, files) = dc.get_layer(42, None).unwrap(); + assert!(files.is_empty() && files.is_complete()); assert_eq!(back.img, b.img); assert_eq!((back.offset, back.scale), (b.offset, b.scale)); let rgba: Vec = (0..20 * 10 * 4).map(|i| (i % 251) as u8).collect(); - assert!(dc.put_frame(7, 20, 10, &rgba)); - assert!(!dc.put_frame(8, 2, 2, &[0; 3]), "a wrong-size frame is refused"); + assert!(dc.put_frame(7, 20, 10, &rgba, &ReadFiles::default(), None, 0)); + assert!(!dc.put_frame(8, 2, 2, &[0; 3], &ReadFiles::default(), None, 0), "a wrong-size frame is refused"); dc.flush(); - assert_eq!(dc.get_frame(7).unwrap().rgba, rgba); + assert_eq!(dc.get_frame(7, None).map(|f| f.0).unwrap().rgba, rgba); let st = dc.stats(); assert_eq!((st.entries, st.hits, st.misses, st.writes), (2, 2, 1, 2)); // Wrong kind is a miss. - assert!(dc.get_frame(42).is_none()); + assert!(dc.get_frame(42, None).map(|f| f.0).is_none()); } /// Music doesn't change a comp's disk keys (adding it to the timeline kept no blue frame); - /// hiding a clip does. Importing music keeps the layer-cache salt. + /// hiding a clip does. Importing music keeps them too. #[test] fn music_keeps_the_disk_keys() { use effectcraft_project::{Comp, Footage, FootageKind, ItemKind, LayerSource, Project, Solid, build}; @@ -1391,14 +1736,14 @@ mod tests { let clip = build::layer(&mut p, &comp, "Clip", LayerSource::Solid { item: sid }, (64, 64), None); let clip_id = clip.id; p.comp_mut(cid).unwrap().layers.push(clip); - let (key, salt) = (comp_content_key(&p, cid), footage_salt(&p)); + let key = comp_content_key(&p, cid); let song = p.add_item( "song.wav", Default::default(), None, ItemKind::Footage(Footage { kind: FootageKind::Audio, has_video: false, has_audio: true, ..Default::default() }), ); - assert_eq!(footage_salt(&p), salt, "importing music"); + assert_eq!(comp_content_key(&p, cid), key, "importing music"); let music = build::layer(&mut p, &comp, "Music", LayerSource::Footage { item: song }, (64, 64), None); p.comp_mut(cid).unwrap().layers.insert(0, music); assert_eq!(comp_content_key(&p, cid), key, "music on the timeline"); @@ -1406,6 +1751,28 @@ mod tests { assert_ne!(comp_content_key(&p, cid), key, "a hidden clip"); } + /// An expression that reads a 3D model layer's source (`thisComp.layer("Model").source.name`) + /// gives a new key when the model item is renamed: the frames on disk hold the old name. + #[test] + fn renaming_a_model_an_expression_reads_changes_the_disk_key() { + use effectcraft_project::{Comp, Expression, Footage, FootageKind, ItemKind, LayerSource, Project, Solid, build}; + use effectcraft_time::{FrameRate, Tick}; + let mut p = Project::default(); + let comp = Comp::new(64, 64, FrameRate::FPS_30, Tick::from_seconds_f64(2.0)); + let cid = p.add_item("Main", Default::default(), None, ItemKind::Comp(comp.clone().into())); + let model = p.add_item("chair.glb", Default::default(), None, ItemKind::Footage(Footage { kind: FootageKind::Model, ..Default::default() })); + let sid = p.add_item("Solid", Default::default(), None, ItemKind::Solid(Solid { color: [1.0, 0.0, 0.0], width: 64, height: 64, pixel_aspect: 1.0 })); + let mut m = build::layer(&mut p, &comp, "Model", LayerSource::Model { item: model }, (64, 64), None); + m.switches.video = false; + let mut s = build::layer(&mut p, &comp, "Reader", LayerSource::Solid { item: sid }, (64, 64), None); + s.props.prop_mut("transform/opacity").unwrap().expr = + Some(Expression { text: "thisComp.layer(\"Model\").source.name.length * 10".into(), enabled: true }); + p.comp_mut(cid).unwrap().layers.extend([s, m]); + let key = comp_content_key(&p, cid); + p.item_mut(model).unwrap().name = "table.glb".into(); + assert_ne!(comp_content_key(&p, cid), key, "the expression reads the model's name"); + } + /// A burst of layer writes never crowds out frames: every frame of a fully cached comp is /// on disk afterwards (the blue bar came back with gaps). #[test] @@ -1413,11 +1780,11 @@ mod tests { let dir = tmpdir("burst"); let dc = DiskCache::open(&dir, 1 << 30).unwrap(); for k in 0..300 { - dc.put_layer(10_000 + k, &buf(1, 64, 64)); + dc.put_layer(10_000 + k, &buf(1, 64, 64), &EntryFiles::default(), 0); } let rgba = vec![7u8; 32 * 32 * 4]; for k in 0..300 { - dc.put_frame(k, 32, 32, &rgba); + dc.put_frame(k, 32, 32, &rgba, &ReadFiles::default(), None, 0); } dc.flush(); assert!((0..300).all(|k| dc.contains(Kind::Frame, k)), "every frame written"); @@ -1432,17 +1799,17 @@ mod tests { let comp = Comp::new(2, 2, FrameRate::FPS_30, Tick::from_seconds_f64(1.0)); let id = project.add_item("Cached composition", effectcraft_color::Label::None, None, ItemKind::Comp(comp.into())); let key = frame_key(comp_content_key(&project, id), 0, 1000, 0); - let previous_key = frame_key(comp_content_key_for_renderer(&project, id, None, "effectcraft-render-5"), 0, 1000, 0); + let previous_key = frame_key(comp_content_key_for_renderer(&project, id, "effectcraft-render-5"), 0, 1000, 0); let dir = tmpdir("previous-renderer"); { let cache = DiskCache::open(&dir, 1 << 30).unwrap(); - cache.put_frame_now(previous_key, 2, 2, &[9; 16]); + cache.put_frame_now(previous_key, 2, 2, &[9; 16], &ReadFiles::default()); } let cache = DiskCache::open(&dir, 1 << 30).unwrap(); - assert_eq!(cache.get_frame(previous_key).unwrap().rgba, vec![9; 16]); - assert!(cache.get_frame(key).is_none()); - cache.put_frame_now(key, 2, 2, &[17; 16]); - assert_eq!(cache.get_frame(key).unwrap().rgba, vec![17; 16]); + assert_eq!(cache.get_frame(previous_key, None).map(|f| f.0).unwrap().rgba, vec![9; 16]); + assert!(cache.get_frame(key, None).map(|f| f.0).is_none()); + cache.put_frame_now(key, 2, 2, &[17; 16], &ReadFiles::default()); + assert_eq!(cache.get_frame(key, None).map(|f| f.0).unwrap().rgba, vec![17; 16]); } #[test] @@ -1450,16 +1817,16 @@ mod tests { let dir = tmpdir("persist"); { let dc = DiskCache::open(&dir, 1 << 30).unwrap(); - dc.put_layer_now(1, &buf(1, 8, 8)); - dc.put_frame_now(2, 2, 2, &[9; 16]); + dc.put_layer_now(1, &buf(1, 8, 8), &ReadFiles::default()); + dc.put_frame_now(2, 2, 2, &[9; 16], &ReadFiles::default()); } let dc = DiskCache::open(&dir, 1 << 30).unwrap(); assert_eq!(dc.stats().entries, 2); assert!(dc.contains(Kind::Layer, 1) && dc.contains(Kind::Frame, 2)); - assert_eq!(dc.get_frame(2).unwrap().rgba, vec![9; 16]); + assert_eq!(dc.get_frame(2, None).map(|f| f.0).unwrap().rgba, vec![9; 16]); dc.clear(); assert_eq!(dc.stats().entries, 0); - assert!(dc.get_frame(2).is_none()); + assert!(dc.get_frame(2, None).map(|f| f.0).is_none()); let again = DiskCache::open(&dir, 1 << 30).unwrap(); assert_eq!(again.stats().entries, 0); } @@ -1469,11 +1836,11 @@ mod tests { let dir = tmpdir("lru"); let dc = DiskCache::open(&dir, u64::MAX).unwrap(); for k in 0..6u128 { - dc.put_layer_now(k, &buf(k as u32, 64, 64)); + dc.put_layer_now(k, &buf(k as u32, 64, 64), &ReadFiles::default()); } let per = dc.stats().bytes / 6; // Touch 0 so it is the most recently used. - assert!(dc.get_layer(0).is_some()); + assert!(dc.get_layer(0, None).is_some()); dc.set_max_bytes(per * 3 + per * 3 / 4); let st = dc.stats(); assert!(st.bytes <= per * 3 + per * 3 / 4, "{st:?}"); @@ -1485,7 +1852,7 @@ mod tests { let files = walk(&dir); assert_eq!(files, 3); // New writes keep evicting. - dc.put_layer_now(99, &buf(9, 64, 64)); + dc.put_layer_now(99, &buf(9, 64, 64), &ReadFiles::default()); assert!(dc.stats().bytes <= per * 3 + per * 3 / 4); } @@ -1510,7 +1877,7 @@ mod tests { let dir = tmpdir("space"); let dc = DiskCache::open(&dir, 1 << 30).unwrap(); for k in 0..4u128 { - dc.put_layer_now(k, &buf(k as u32, 64, 64)); + dc.put_layer_now(k, &buf(k as u32, 64, 64), &ReadFiles::default()); } let used = dc.stats().bytes; // Unknown space: the setting alone. @@ -1519,17 +1886,18 @@ mod tests { // A disk reported as 0 bytes is unknown. dc.set_disk_space(Some((0, 0))); assert_eq!(dc.stats().limit_bytes, 1 << 30); - // 100 GB disk, 5 GB reserved, exactly 5 GB free: the cache may not grow. + // 100 GB disk, 5 GB reserved (5%, between the 2 GB floor and the 10 GB cap), exactly + // 5 GB free: the cache may not grow. dc.set_disk_space(Some((100 << 30, 5 << 30))); let st = dc.stats(); assert_eq!((st.max_bytes, st.limit_bytes), (1 << 30, used)); - dc.put_layer_now(9, &buf(9, 64, 64)); + dc.put_layer_now(9, &buf(9, 64, 64), &ReadFiles::default()); let st = dc.stats(); assert!(st.bytes <= st.limit_bytes && st.bytes <= used - used / 10 && st.evictions > 0, "{st:?}"); assert!(dc.contains(Kind::Layer, 9), "the new entry is the most recently used"); // Below the reserve the cache gives its space back, and skips writes that can't fit. dc.set_disk_space(Some((100 << 30, 4 << 30))); - dc.put_layer_now(10, &buf(10, 64, 64)); + dc.put_layer_now(10, &buf(10, 64, 64), &ReadFiles::default()); let st = dc.stats(); assert_eq!((st.limit_bytes, st.entries, st.bytes), (0, 0, 0), "{st:?}"); // Plenty of space again: back to the setting. @@ -1538,14 +1906,86 @@ mod tests { let _ = std::fs::remove_dir_all(&dir); } + /// The reserve is 5% of the disk, at least 2 GB and at most 10 GB: a large disk with plenty + /// free keeps the user's size. (A 4 TB disk with 190 GB free reserved 200 GB, held a 20 GB + /// cache at 0, and every write was refused.) + #[test] + fn a_large_disk_reserves_at_most_ten_gb() { + const GB: u64 = 1 << 30; + assert_eq!(disk_reserve(4096 * GB), 10 * GB); + assert_eq!(disk_reserve(100 * GB), 5 * GB); + assert_eq!(disk_reserve(32 * GB), 2 * GB); + assert_eq!(disk_reserve(1), 2 * GB); + let dir = tmpdir("space-large"); + let dc = DiskCache::open(&dir, 20 * GB).unwrap(); + dc.set_disk_space(Some((4096 * GB, 190 * GB))); + let st = dc.stats(); + assert_eq!((st.max_bytes, st.limit_bytes), (20 * GB, 20 * GB), "{st:?}"); + assert!(dc.accepts_writes()); + assert_eq!(dc.reserve_bytes(), Some(10 * GB)); + // Just above the 10 GB reserve: the cache may use what is left above it. + dc.set_disk_space(Some((4096 * GB, 15 * GB))); + assert_eq!(dc.stats().limit_bytes, 5 * GB); + // A small disk still keeps 2 GB free: 3 GB free leaves 1 GB for the cache. + dc.set_disk_space(Some((32 * GB, 3 * GB))); + assert_eq!(dc.stats().limit_bytes, GB); + // Below the floor: nothing. + dc.set_disk_space(Some((32 * GB, GB))); + assert_eq!(dc.stats().limit_bytes, 0); + assert!(!dc.accepts_writes()); + let _ = std::fs::remove_dir_all(&dir); + } + + /// A write the free disk space refuses is refused before its pixels are compressed: the + /// frame workers spent about 8 ms per frame and 14 ms per layer encoding entries that were + /// then refused (`limit_bytes=0`). + #[test] + fn no_encode_while_the_disk_has_no_room() { + const GB: u64 = 1 << 30; + let dir = tmpdir("space-no-encode"); + let dc = DiskCache::open(&dir, 20 * GB).unwrap(); + // 4 TB disk, 1 GB free: under the 10 GB reserve, the limit is 0. + dc.set_disk_space(Some((4096 * GB, GB))); + assert_eq!(dc.stats().limit_bytes, 0); + let rgba = vec![7u8; 16 * 16 * 4]; + assert!(!dc.put_frame(1, 16, 16, &rgba, &ReadFiles::default(), None, 0), "refused"); + assert!(!dc.put_frame_f16(2, 16, 16, &[0x3c00u16; 16 * 16 * 4], &ReadFiles::default(), None, 0), "refused"); + dc.put_layer(3, &buf(3, 16, 16), &EntryFiles::default(), 0); + dc.flush(); + assert_eq!(dc.encodes(), 0, "nothing compressed"); + assert_eq!(dc.stats().entries, 0); + // 32 MB of room above the reserve: a few frames would fill it, the rest would be + // compressed only to be refused. Not worth encoding either. + dc.set_disk_space(Some((4096 * GB, 10 * GB + (32 << 20)))); + assert_eq!(dc.stats().limit_bytes, 32 << 20); + assert!(!dc.accepts_writes()); + assert!(!dc.put_frame(1, 16, 16, &rgba, &ReadFiles::default(), None, 0), "refused"); + dc.put_layer(3, &buf(3, 16, 16), &EntryFiles::default(), 0); + assert_eq!(dc.encodes(), 0, "nothing compressed"); + // A small limit the setting asks for (not free space) is used. + dc.set_disk_space(None); + dc.set_max_bytes(32 << 20); + assert!(dc.accepts_writes()); + dc.set_max_bytes(20 * GB); + // Room again: the same writes are compressed and stored. + dc.set_disk_space(Some((4096 * GB, 500 * GB))); + assert!(dc.put_frame(1, 16, 16, &rgba, &ReadFiles::default(), None, 0)); + assert!(dc.put_frame_f16(2, 16, 16, &[0x3c00u16; 16 * 16 * 4], &ReadFiles::default(), None, 0)); + dc.put_layer(3, &buf(3, 16, 16), &EntryFiles::default(), 0); + dc.flush(); + assert_eq!(dc.encodes(), 3); + assert_eq!(dc.stats().entries, 3); + let _ = std::fs::remove_dir_all(&dir); + } + #[test] fn failed_writes_are_counted() { let dir = tmpdir("failed"); let dc = DiskCache::open(&dir, 1 << 30).unwrap(); // A file where the layers folder should be: every layer write fails. std::fs::write(dir.join(VERSION).join(Kind::Layer.dir()), b"x").unwrap(); - dc.put_layer_now(1, &buf(1, 8, 8)); - dc.put_layer_now(2, &buf(2, 8, 8)); + dc.put_layer_now(1, &buf(1, 8, 8), &ReadFiles::default()); + dc.put_layer_now(2, &buf(2, 8, 8), &ReadFiles::default()); let st = dc.stats(); assert_eq!((st.failed, st.writes, st.entries), (2, 0, 0)); let _ = std::fs::remove_dir_all(&dir); @@ -1570,13 +2010,13 @@ mod tests { fn damaged_files_are_misses() { let dir = tmpdir("damaged"); let dc = DiskCache::open(&dir, 1 << 30).unwrap(); - dc.put_frame_now(5, 4, 4, &[1; 64]); + dc.put_frame_now(5, 4, 4, &[1; 64], &ReadFiles::default()); let p = dc.path(Kind::Frame, 5); let mut d = std::fs::read(&p).unwrap(); let n = d.len(); d[n / 2] ^= 0xff; std::fs::write(&p, d).unwrap(); - assert!(dc.get_frame(5).is_none()); + assert!(dc.get_frame(5, None).map(|f| f.0).is_none()); assert!(!dc.contains(Kind::Frame, 5)); assert!(!p.exists()); } @@ -1594,8 +2034,8 @@ mod tests { for i in 0..20u128 { let k = i % 5; let w = if t % 2 == 0 { &a } else { &b }; - w.put_layer_now(k, &buf(k as u32, 16, 16)); - if let Some(x) = w.get_layer(k) { + w.put_layer_now(k, &buf(k as u32, 16, 16), &ReadFiles::default()); + if let Some((x, _)) = w.get_layer(k, None) { assert_eq!(x.img, buf(k as u32, 16, 16).img); } } @@ -1604,39 +2044,16 @@ mod tests { }); b.rescan(); for k in 0..5u128 { - assert_eq!(b.get_layer(k).unwrap().img, buf(k as u32, 16, 16).img); + assert_eq!(b.get_layer(k, None).unwrap().0.img, buf(k as u32, 16, 16).img); } } - /// An audio file nothing reads stays out of the layer salt; one a layer reads (Audio - /// Spectrum) is in it, so overwriting it doesn't reuse that layer's buffers. + /// Replaced bytes of a path with no native metadata (the browser file table) change neither + /// the comp key nor a layer's disk key (both from memory): the frame and layer entries made + /// of them check the hook's size and content hash when read and are misses, deleted (#1253, + /// #3184). #[test] - fn read_audio_counts_in_the_footage_salt() { - use effectcraft_project::build; - use effectcraft_project::{Comp, Footage, FootageKind, ItemKind, LayerSource, MatteKind, Project, TrackMatte}; - use effectcraft_time::{FrameRate, Tick}; - - let mut p = Project::default(); - let f = Footage { path: "/song.wav".into(), kind: FootageKind::Audio, has_video: false, has_audio: true, ..Default::default() }; - let song = p.add_item("song.wav", effectcraft_color::Label::None, None, ItemKind::Footage(f)); - let mut comp = Comp::new(16, 9, FrameRate::FPS_30, Tick::from_seconds_f64(1.0)); - let music = build::layer(&mut p, &comp, "music", LayerSource::Footage { item: song }, (16, 9), None); - let mut reader = build::layer(&mut p, &comp, "reader", LayerSource::Null, (16, 9), None); - let music_id = music.id; - comp.layers = vec![reader.clone(), music].into(); - let cid = p.add_item("C", effectcraft_color::Label::None, None, ItemKind::Comp(comp.into())); - - let id = |mark: u64| move |path: &str| (path == "/song.wav").then_some((8, mark)); - let (one, two) = (id(1), id(2)); - assert_eq!(footage_salt_with(&p, Some(&one)), footage_salt_with(&p, Some(&two)), "unread music stays out"); - reader.track_matte = Some(TrackMatte { layer: music_id, kind: MatteKind::Alpha }); - *p.comp_mut(cid).unwrap().layers.first_mut().unwrap() = reader; - assert_ne!(footage_salt_with(&p, Some(&one)), footage_salt_with(&p, Some(&two)), "read audio counts"); - } - - /// A path with no native metadata takes its key from the caller's size and content hash (#1253). - #[test] - fn virtual_file_bytes_change_content_keys() { + fn virtual_file_bytes_are_checked_by_the_entries_not_the_keys() { use effectcraft_project::build; use effectcraft_project::{Comp, Footage, ItemKind, LayerSource, Project}; use effectcraft_time::{FrameRate, Tick}; @@ -1650,12 +2067,335 @@ mod tests { let id = |mark: u64| move |path: &str| (path == "/virtual.mov").then_some((8, mark)); let (one, two) = (id(1), id(2)); - let a = footage_salt_with(&p, Some(&one)); - let b = footage_salt_with(&p, Some(&two)); - let ka = comp_content_key_with(&p, cid, Some(&one)); - let kb = comp_content_key_with(&p, cid, Some(&two)); - assert_ne!(a, b, "replaced virtual media must not reuse the salt"); - assert_ne!(ka, kb, "replaced virtual media must not reuse the frame key"); - assert_eq!(comp_content_key(&p, cid), comp_content_key_with(&p, cid, None)); + let dc = DiskCache::open(tmpdir("virtual"), 1 << 30).unwrap(); + let k = frame_key(comp_content_key(&p, cid), 0, 1000, 0); + let files: ReadFiles = [crate::reads::ReadFile::new("/virtual.mov", crate::reads::FileStamp::Virtual)].into_iter().collect(); + assert!(dc.put_frame(k, 1, 1, &[1, 2, 3, 4], &files, Some(&one), 0)); + dc.flush(); + assert!(dc.get_frame(k, Some(&one)).is_some_and(|(_, f)| f == files)); + assert!(dc.get_frame(k, Some(&two)).is_none() && !dc.contains(Kind::Frame, k), "replaced: a miss, deleted"); + // A layer buffer made of it. + let lk = layer_disk_key(7); + dc.put_layer(lk, &buf(1, 4, 4), &EntryFiles::of(&files, Some(&one)).unwrap(), 0); + dc.flush(); + assert!(dc.get_layer(lk, Some(&one)).is_some_and(|(b, f)| b.img == buf(1, 4, 4).img && f == files && f.is_complete())); + assert!(dc.get_layer(lk, None).is_none() && !dc.contains(Kind::Layer, lk), "no identity: a miss, deleted"); + dc.put_layer(lk, &buf(1, 4, 4), &EntryFiles::of(&files, Some(&one)).unwrap(), 0); + dc.flush(); + assert!(dc.get_layer(lk, Some(&two)).is_none() && !dc.contains(Kind::Layer, lk), "replaced: a miss, deleted"); + // The browser's sealed layer entries carry the same list. + let e = layer_entry(&buf(2, 3, 2), &EntryFiles::of(&files, Some(&one)).unwrap()); + let (b, list) = read_layer_entry(&e).unwrap(); + assert!(b.img == buf(2, 3, 2).img && list.unchanged(Some(&one)) && !list.unchanged(Some(&two))); + assert!(read_layer_entry(&seal_format(Kind::Layer, FORMAT_RGBA8, &encode_layer(&buf(2, 3, 2)))).is_none(), "the format before #3184"); + let mut bad = e.clone(); + bad[12] ^= 1; + assert!(read_layer_entry(&bad).is_none(), "damaged"); + } + + /// Layer disk keys come from the layer cache's key alone (no file, no project-wide salt) and + /// differ per key. + #[test] + fn layer_disk_keys_need_no_files() { + assert_eq!(layer_disk_key(1), layer_disk_key(1)); + assert_ne!(layer_disk_key(1), layer_disk_key(2)); + // Not the layout of the salted keys before #3184 (`salt << 64 | key`). + assert_ne!(layer_disk_key(1) as u64, 1); + } + + /// A layer entry is used only while the files it lists are what the buffer was made of: a + /// new size, a new time, a missing file that is back, a file replaced by a folder, a damaged + /// files section and the format before #3184 are misses, and the entry is deleted so the + /// buffer is rendered and stored again. A buffer whose files can't all be named is not + /// stored. Only the listed files are looked at. + #[test] + fn layer_entries_check_their_files() { + use crate::reads::{FileStamp, ReadFile}; + let dir = tmpdir("layer-check"); + let src = dir.join("src"); + std::fs::create_dir_all(&src).unwrap(); + let file = |name: &str, bytes: &[u8]| { + let p = src.join(name); + std::fs::write(&p, bytes).unwrap(); + p.to_string_lossy().to_string() + }; + let (a, b) = (file("a.png", b"aa"), file("b.png", b"bb")); + let gone = src.join("gone.png").to_string_lossy().to_string(); + let read = |paths: &[&str]| -> ReadFiles { paths.iter().map(|p| ReadFile::new(*p, FileStamp::native(p).unwrap_or(FileStamp::Missing))).collect() }; + let dc = DiskCache::open(&dir, 1 << 30).unwrap(); + dc.put_layer_now(1, &buf(1, 4, 4), &read(&[&a])); + dc.put_layer_now(2, &buf(2, 4, 4), &read(&[&b, &gone])); + dc.put_layer_now(3, &buf(3, 4, 4), &read(&[&b])); + let (one, files) = dc.get_layer(1, None).unwrap(); + assert!(one.img == buf(1, 4, 4).img && files == read(&[&a]) && files.is_complete()); + assert_eq!(dc.file_checks(), 1, "only the file of that buffer"); + // a.png gets a new size: entry 1 is a miss and deleted, the others stay. + std::fs::write(&a, b"aaa").unwrap(); + assert!(dc.get_layer(1, None).is_none() && !dc.contains(Kind::Layer, 1)); + assert!(dc.get_layer(2, None).is_some() && dc.get_layer(3, None).is_some()); + // b.png gets a new time only. + let t = std::fs::metadata(&b).unwrap().modified().unwrap() + std::time::Duration::from_secs(7); + std::fs::File::options().append(true).open(&b).unwrap().set_modified(t).unwrap(); + assert!(dc.get_layer(3, None).is_none() && !dc.contains(Kind::Layer, 3)); + assert!(dc.get_layer(2, None).is_none(), "b.png is listed there too"); + // A missing file that is back. + dc.put_layer_now(4, &buf(4, 4, 4), &read(&[&gone])); + assert!(dc.get_layer(4, None).is_some(), "missing, still missing"); + file("gone.png", b"g"); + assert!(dc.get_layer(4, None).is_none() && !dc.contains(Kind::Layer, 4), "back"); + // A file replaced by a folder (unreadable). + let c = file("c.png", b"cc"); + dc.put_layer_now(5, &buf(5, 4, 4), &read(&[&c])); + std::fs::remove_file(&c).unwrap(); + std::fs::create_dir(&c).unwrap(); + assert!(dc.get_layer(5, None).is_none() && !dc.contains(Kind::Layer, 5)); + // Written again after the miss: a hit with the new identity. + dc.put_layer_now(1, &buf(9, 4, 4), &read(&[&a])); + assert_eq!(dc.get_layer(1, None).map(|l| l.0.img), Some(buf(9, 4, 4).img)); + // The format before #3184 (no files): a miss, deleted. + dc.write_format(Kind::Layer, 6, FORMAT_RGBA8, &encode_layer(&buf(6, 4, 4))); + assert!(dc.contains(Kind::Layer, 6)); + assert!(dc.get_layer(6, None).is_none() && !dc.contains(Kind::Layer, 6)); + // A valid checksum over a damaged files section, or over a cut buffer: misses, deleted. + let mut payload = vec![]; + payload.extend_from_slice(&3u32.to_le_bytes()); + payload.extend_from_slice(&encode_layer(&buf(7, 4, 4))); + dc.write_format(Kind::Layer, 7, FORMAT_LAYER_FILES, &payload); + assert!(dc.get_layer(7, None).is_none() && !dc.contains(Kind::Layer, 7)); + let mut cut = vec![]; + EntryFiles::default().encode(&mut cut); + cut.extend_from_slice(&encode_layer(&buf(8, 4, 4))[..40]); + dc.write_format(Kind::Layer, 8, FORMAT_LAYER_FILES, &cut); + assert!(dc.get_layer(8, None).is_none() && !dc.contains(Kind::Layer, 8)); + // A damaged file on disk. + dc.put_layer_now(9, &buf(9, 4, 4), &ReadFiles::default()); + let p = dc.path(Kind::Layer, 9); + let mut d = std::fs::read(&p).unwrap(); + let n = d.len(); + d[n / 2] ^= 0xff; + std::fs::write(&p, d).unwrap(); + assert!(dc.get_layer(9, None).is_none() && !dc.contains(Kind::Layer, 9) && !p.exists()); + // Buffers whose files can't all be named are not stored. + let mut incomplete = read(&[&a]); + incomplete.mark_incomplete(); + dc.put_layer_now(10, &buf(10, 4, 4), &incomplete); + assert!(!dc.contains(Kind::Layer, 10)); + let _ = std::fs::remove_dir_all(&dir); + } + + /// A frame entry is used only while the files it lists are what it was made of: a new size, + /// a new time, a missing file that is back, a file replaced by a folder are misses, and the + /// entry is deleted so the frame is rendered and stored again. Only the listed files are + /// looked at. Entries of the format before #3184 are misses and deleted. + #[test] + fn frame_entries_check_their_files() { + use crate::reads::{FileStamp, ReadFile}; + let dir = tmpdir("check"); + let src = dir.join("src"); + std::fs::create_dir_all(&src).unwrap(); + let file = |name: &str, bytes: &[u8]| { + let p = src.join(name); + std::fs::write(&p, bytes).unwrap(); + p.to_string_lossy().to_string() + }; + let (a, b) = (file("a.png", b"aa"), file("b.png", b"bb")); + let gone = src.join("gone.png").to_string_lossy().to_string(); + let read = |paths: &[&str]| -> ReadFiles { paths.iter().map(|p| ReadFile::new(*p, FileStamp::native(p).unwrap_or(FileStamp::Missing))).collect() }; + let dc = DiskCache::open(&dir, 1 << 30).unwrap(); + dc.put_frame_now(1, 1, 1, &[1; 4], &read(&[&a])); + dc.put_frame_now(2, 1, 1, &[2; 4], &read(&[&b, &gone])); + dc.put_frame_now(3, 1, 1, &[3; 4], &read(&[&b])); + assert_eq!(dc.get_frame(1, None).map(|f| f.1), Some(read(&[&a]))); + assert_eq!(dc.file_checks(), 1, "only the file of that frame"); + // a.png gets a new size: frame 1 is a miss and deleted, the others stay. + std::fs::write(&a, b"aaa").unwrap(); + assert!(dc.get_frame(1, None).is_none() && !dc.contains(Kind::Frame, 1)); + assert!(dc.get_frame(2, None).is_some() && dc.get_frame(3, None).is_some()); + // b.png gets a new time only. + let t = std::fs::metadata(&b).unwrap().modified().unwrap() + std::time::Duration::from_secs(7); + std::fs::File::options().append(true).open(&b).unwrap().set_modified(t).unwrap(); + assert!(dc.get_frame(3, None).is_none() && !dc.contains(Kind::Frame, 3)); + assert!(dc.get_frame(2, None).is_none(), "b.png is listed there too"); + // A missing file that is back. + dc.put_frame_now(4, 1, 1, &[4; 4], &read(&[&gone])); + assert!(dc.get_frame(4, None).is_some(), "missing, still missing"); + file("gone.png", b"g"); + assert!(dc.get_frame(4, None).is_none() && !dc.contains(Kind::Frame, 4), "back"); + // A file replaced by a folder (unreadable). + let c = file("c.png", b"cc"); + dc.put_frame_now(5, 1, 1, &[5; 4], &read(&[&c])); + std::fs::remove_file(&c).unwrap(); + std::fs::create_dir(&c).unwrap(); + assert!(dc.get_frame(5, None).is_none() && !dc.contains(Kind::Frame, 5)); + // Written again after the miss: a hit with the new identity. + let fresh = file("d.png", b"dd"); + dc.put_frame_now(1, 1, 1, &[9; 4], &read(&[&fresh])); + assert_eq!(dc.get_frame(1, None).map(|f| f.0.rgba), Some(vec![9; 4])); + // The format before #3184 (no files): a miss, deleted. + dc.write_format(Kind::Frame, 6, FORMAT_RGBA8, &encode_frame(1, 1, &[6; 4])); + assert!(dc.contains(Kind::Frame, 6)); + assert!(dc.get_frame(6, None).is_none() && !dc.contains(Kind::Frame, 6)); + // A valid checksum over a damaged files section: a miss, deleted. + let mut payload = vec![]; + payload.extend_from_slice(&3u32.to_le_bytes()); + payload.extend_from_slice(&encode_frame(1, 1, &[7; 4])); + dc.write_format(Kind::Frame, 7, FORMAT_RGBA8_FILES, &payload); + assert!(dc.get_frame(7, None).is_none() && !dc.contains(Kind::Frame, 7)); + // Frames whose files can't all be named are not stored. + let mut incomplete = read(&[&fresh]); + incomplete.mark_incomplete(); + assert!(!dc.put_frame(8, 1, 1, &[8; 4], &incomplete, None, 0)); + dc.flush(); + assert!(!dc.contains(Kind::Frame, 8)); + let _ = std::fs::remove_dir_all(&dir); + } + + /// Reload Footage drops the entries made of the reloaded files (#3184): a file replaced by + /// one with the same size and modification time passes the check on hit, so only the drop + /// makes the next use a miss. Entries of other files stay; an entry written after the drop + /// is used; a layer entry and one written while the drop waits in the queue are dropped too; + /// the drop survives a restart (the files are gone). + #[test] + fn dropped_files_take_their_entries_with_them() { + use crate::reads::{FileStamp, ReadFile}; + let dir = tmpdir("drop"); + let src = dir.join("src"); + std::fs::create_dir_all(&src).unwrap(); + let file = |name: &str, bytes: &[u8]| { + let p = src.join(name); + std::fs::write(&p, bytes).unwrap(); + p.to_string_lossy().to_string() + }; + let (a, b) = (file("a.png", b"aa"), file("b.png", b"bb")); + let read = |paths: &[&str]| -> ReadFiles { paths.iter().map(|p| ReadFile::new(*p, FileStamp::native(p).unwrap())).collect() }; + let dc = DiskCache::open(&dir, 1 << 30).unwrap(); + dc.put_frame_now(1, 1, 1, &[1; 4], &read(&[&a])); + dc.put_frame_now(2, 1, 1, &[2; 4], &read(&[&b])); + dc.put_frame_now(3, 1, 1, &[3; 4], &read(&[&a, &b])); + dc.put_layer_now(4, &buf(4, 2, 2), &read(&[&a])); + // a.png gets other bytes of the same size and its old time back: the check can't tell. + let t = std::fs::metadata(&a).unwrap().modified().unwrap(); + std::fs::write(&a, b"AA").unwrap(); + std::fs::File::options().append(true).open(&a).unwrap().set_modified(t).unwrap(); + assert!(dc.get_frame(1, None).is_some(), "same size and time: still a hit"); + // A frame queued (not written yet) when the drop comes is dropped too. + assert!(dc.put_frame(5, 1, 1, &[5; 4], &read(&[&a]), None, 0)); + dc.drop_files([a.clone()]); + dc.flush(); + assert!(!dc.is_dropping()); + for (kind, key) in [(Kind::Frame, 1), (Kind::Frame, 3), (Kind::Layer, 4), (Kind::Frame, 5)] { + assert!(!dc.contains(kind, key), "{kind:?} {key} made of a.png is gone"); + } + assert!(dc.get_frame(1, None).is_none() && dc.get_layer(4, None).is_none()); + assert_eq!(dc.get_frame(2, None).map(|f| f.0.rgba), Some(vec![2; 4]), "b.png's frame stays"); + // Written again from the reloaded file: used. + dc.put_frame_now(1, 1, 1, &[9; 4], &read(&[&a])); + assert_eq!(dc.get_frame(1, None).map(|f| f.0.rgba), Some(vec![9; 4])); + // The drop is for good: a new session on the folder finds what is left. + drop(dc); + let dc = DiskCache::open(&dir, 1 << 30).unwrap(); + assert_eq!(dc.keys(Kind::Frame).into_iter().collect::>(), [1, 2].into()); + assert!(dc.keys(Kind::Layer).is_empty()); + let _ = std::fs::remove_dir_all(&dir); + } + + /// A render under way when Reload Footage drops its files offers its entries after the drop + /// (#3184), when the writer has already deleted the old ones: made of the files as they were, + /// they are refused, frames and layer buffers alike. What the same render made of other files + /// is stored, and so is what a render that started after the drop makes. + #[test] + fn entries_made_before_a_drop_are_refused_after_it() { + use crate::reads::{FileStamp, ReadFile}; + let dir = tmpdir("drop-in-flight"); + std::fs::create_dir_all(&dir).unwrap(); + let file = |name: &str| { + let p = dir.join(name); + std::fs::write(&p, name.as_bytes()).unwrap(); + p.to_string_lossy().to_string() + }; + let (a, b) = (file("a.png"), file("b.png")); + let read = |paths: &[&str]| -> ReadFiles { paths.iter().map(|p| ReadFile::new(*p, FileStamp::native(p).unwrap())).collect() }; + let dc = DiskCache::open(dir.join("cache"), 1 << 30).unwrap(); + // The render starts (and reads a.png and b.png), then a.png is reloaded. + let before = dc.drop_generation(); + dc.drop_files([a.clone()]); + dc.flush(); + assert!(!dc.is_dropping()); + assert!(dc.dropped_since(&read(&[&a]), before) && !dc.dropped_since(&read(&[&b]), before)); + assert!(!dc.put_frame(1, 1, 1, &[1; 4], &read(&[&a, &b]), None, before), "a frame from before the drop"); + assert!(!dc.put_frame_f16(2, 1, 1, &[1; 4], &read(&[&a]), None, before)); + dc.put_layer(3, &buf(3, 2, 2), &EntryFiles::of(&read(&[&a]), None).unwrap(), before); + assert!(dc.put_frame(4, 1, 1, &[4; 4], &read(&[&b]), None, before), "b.png wasn't dropped"); + dc.flush(); + assert!(!dc.contains(Kind::Frame, 1) && !dc.contains(Kind::Frame, 2) && !dc.contains(Kind::Layer, 3)); + assert!(dc.get_frame(1, None).is_none() && dc.get_layer(3, None).is_none()); + assert_eq!(dc.get_frame(4, None).map(|f| f.0.rgba), Some(vec![4; 4])); + // A render that starts after the drop reads the reloaded file: stored and served. + let after = dc.drop_generation(); + assert!(after > before && !dc.dropped_since(&read(&[&a]), after)); + assert!(dc.put_frame(5, 1, 1, &[5; 4], &read(&[&a]), None, after)); + dc.put_layer(6, &buf(6, 2, 2), &EntryFiles::of(&read(&[&a]), None).unwrap(), after); + dc.flush(); + assert_eq!(dc.get_frame(5, None).map(|f| f.0.rgba), Some(vec![5; 4])); + assert!(dc.get_layer(6, None).is_some()); + let _ = std::fs::remove_dir_all(&dir); + } + + /// The record of dropped files is bounded: past it, everything made before the drop that + /// forgot the record is refused, and what is made after it is stored. + #[test] + fn the_record_of_dropped_files_is_bounded() { + let mut d = Drops::default(); + let a: Arc = "/a.png".into(); + d.record(std::slice::from_ref(&a)); + assert!(d.stale([&a].into_iter(), 0) && !d.stale([&a].into_iter(), 1)); + let many: Vec> = (0..=MAX_DROPPED_PATHS).map(|i| format!("/f{i}").into()).collect(); + d.record(&many); + assert!(d.last.is_empty(), "forgotten, not grown"); + let other: Arc = "/other.png".into(); + assert!(d.stale([&other].into_iter(), 1), "made before the drop that forgot the record"); + assert!(!d.stale([&a].into_iter(), 2), "made after it"); + } + + /// While a drop waits, an entry made of a dropped file is a miss (and deleted), and frames + /// aren't linked to new keys. + #[test] + fn entries_of_a_pending_drop_are_misses() { + use crate::reads::{FileStamp, ReadFile}; + let dir = tmpdir("drop-pending"); + std::fs::create_dir_all(&dir).unwrap(); + let a = dir.join("a.png"); + std::fs::write(&a, b"aa").unwrap(); + let a = a.to_string_lossy().to_string(); + let files: ReadFiles = [ReadFile::new(a.as_str(), FileStamp::native(&a).unwrap())].into_iter().collect(); + let dc = DiskCache::open(dir.join("cache"), 1 << 30).unwrap(); + dc.put_frame_now(1, 1, 1, &[1; 4], &files); + dc.dropping.lock().unwrap().insert(a.as_str().into(), 1); + assert!(!dc.link_frame(1, 2)); + assert!(dc.get_frame(1, None).is_none() && !dc.contains(Kind::Frame, 1)); + let _ = std::fs::remove_dir_all(&dir); + } + + /// An entry read while its file's drop was pending is a miss even when the writer ends the + /// sweep between the read and the check (it deleted the file, but its bytes were read), and + /// so is one read before a drop that starts meanwhile. Found under load: a stale hit. + #[test] + fn a_sweep_ending_during_a_read_never_makes_a_hit() { + use crate::reads::{FileStamp, ReadFile}; + let dir = tmpdir("drop-race"); + let dc = DiskCache::open(dir.join("cache"), 1 << 30).unwrap(); + let files = EntryFiles::of(&[ReadFile::new("/a.png", FileStamp::Missing)].into_iter().collect(), None).unwrap(); + // Read while the drop is pending; the sweep ends before the check. + dc.dropping.lock().unwrap().insert("/a.png".into(), 1); + let drops = dc.drops_now(); + dc.dropping.lock().unwrap().clear(); + assert!(dc.made_of_dropped(&files, &drops)); + // Read before a drop that starts (and ends) before the check. + let drops = dc.drops_now(); + dc.drop_files(["/a.png"]); + dc.flush(); + assert!(dc.made_of_dropped(&files, &drops)); + assert!(!dc.made_of_dropped(&files, &dc.drops_now()), "read after the drop: used"); + let _ = std::fs::remove_dir_all(&dir); } } diff --git a/crates/render/src/disk_cache/entry_files.rs b/crates/render/src/disk_cache/entry_files.rs new file mode 100644 index 000000000..a36ca1033 --- /dev/null +++ b/crates/render/src/disk_cache/entry_files.rs @@ -0,0 +1,276 @@ +//! The source files a frame entry on disk was made of (#3184): stored with the pixels, checked +//! when the entry is used. Only the files that frame read are looked at, never every file of the +//! project. +//! +//! Layout (little endian), before the frame's pixel payload: +//! `u32 count`, then per file `u32 path length`, the path (UTF-8), a tag byte and its fields: +//! `0` a file on disk (`u64 size`, `u8 has time`, `i128 time`: nanoseconds since the Unix epoch, +//! negative before it), `1` bytes from the browser's file table (`u64 size`, `u64 content +//! hash`), `2` a file that could not be read. + +use std::sync::Arc; + +use super::VirtualFileId; +use crate::reads::{FileStamp, MAX_READ_FILES, ReadFile, ReadFiles}; + +/// Longest path an entry stores (bytes): a longer one is not a path this app opened. +const MAX_PATH_BYTES: usize = 1 << 16; + +/// A file's identity as a frame entry keeps it. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum EntryStamp { + /// Size and modification time (nanoseconds since the Unix epoch, negative before it) on + /// disk. + Native { len: u64, modified: Option }, + /// Size and content hash from the [`VirtualFileId`] hook (the browser's file table). + Virtual { len: u64, hash: u64 }, + /// It could not be read when the frame was made: it still must not be readable. + Missing, +} + +/// One file of a frame entry. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct EntryFile { + pub path: Arc, + pub stamp: EntryStamp, +} + +/// Every file a frame entry was made of. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub struct EntryFiles(Vec); + +impl EntryFiles { + /// The list to store for a frame that read `files`: `None` when the frame can't be checked + /// against its files later (the list is incomplete, or a file from memory has no identity), + /// so the frame must not be stored. Native stamps are the ones the files were read with, + /// never a fresh look at the disk (a file changed during the render keeps the old one). + pub fn of(files: &ReadFiles, virtual_id: Option>) -> Option { + if !files.is_complete() { + return None; + } + let mut out = Vec::with_capacity(files.len()); + for f in files.files() { + let stamp = match f.stamp { + FileStamp::Native { len, modified } => EntryStamp::Native { len, modified }, + FileStamp::Virtual => { + let (len, hash) = virtual_id.and_then(|id| id(&f.path))?; + EntryStamp::Virtual { len, hash } + } + FileStamp::Missing => EntryStamp::Missing, + }; + out.push(EntryFile { path: f.path.clone(), stamp }); + } + Some(EntryFiles(out)) + } + + /// The listed files. + pub fn files(&self) -> &[EntryFile] { + &self.0 + } + + /// The number of listed files. + pub fn len(&self) -> usize { + self.0.len() + } + + /// Whether no files are listed. + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + + /// The files as a render reports them (to keep with the frame in memory). + pub fn to_read_files(&self) -> ReadFiles { + self.0 + .iter() + .map(|f| { + let stamp = match f.stamp { + EntryStamp::Native { len, modified } => FileStamp::Native { len, modified }, + EntryStamp::Virtual { .. } => FileStamp::Virtual, + EntryStamp::Missing => FileStamp::Missing, + }; + ReadFile::new(f.path.clone(), stamp) + }) + .collect() + } + + /// Whether every file still is what the frame was made of: one `metadata` call per file + /// (and the hook for files from memory). + pub fn unchanged(&self, virtual_id: Option>) -> bool { + self.0.iter().all(|f| file_unchanged(f, virtual_id)) + } + + /// Appends the list to `out` in little-endian binary form. + pub(super) fn encode(&self, out: &mut Vec) { + out.extend_from_slice(&(self.0.len() as u32).to_le_bytes()); + for f in &self.0 { + out.extend_from_slice(&(f.path.len() as u32).to_le_bytes()); + out.extend_from_slice(f.path.as_bytes()); + match f.stamp { + EntryStamp::Native { len, modified } => { + out.push(0); + out.extend_from_slice(&len.to_le_bytes()); + out.push(u8::from(modified.is_some())); + out.extend_from_slice(&modified.unwrap_or(0).to_le_bytes()); + } + EntryStamp::Virtual { len, hash } => { + out.push(1); + out.extend_from_slice(&len.to_le_bytes()); + out.extend_from_slice(&hash.to_le_bytes()); + } + EntryStamp::Missing => out.push(2), + } + } + } + + /// The list at the start of `p` and what follows it; `None` when it is damaged. + pub(super) fn decode(p: &[u8]) -> Option<(EntryFiles, &[u8])> { + let mut r = Reader(p); + let n = r.u32()? as usize; + if n > MAX_READ_FILES { + return None; + } + let mut out = Vec::with_capacity(n); + for _ in 0..n { + let len = r.u32()? as usize; + if len > MAX_PATH_BYTES { + return None; + } + let path: Arc = std::str::from_utf8(r.take(len)?).ok()?.into(); + let stamp = match r.u8()? { + 0 => { + let len = r.u64()?; + let has = r.u8()?; + let t = r.i128()?; + match has { + 0 => EntryStamp::Native { len, modified: None }, + 1 => EntryStamp::Native { len, modified: Some(t) }, + _ => return None, + } + } + 1 => EntryStamp::Virtual { len: r.u64()?, hash: r.u64()? }, + 2 => EntryStamp::Missing, + _ => return None, + }; + out.push(EntryFile { path, stamp }); + } + Some((EntryFiles(out), r.0)) + } +} + +/// Whether the file still matches its stored stamp, by its native stamp or by its in-memory identity. +fn file_unchanged(f: &EntryFile, virtual_id: Option>) -> bool { + let from_memory = || virtual_id.and_then(|id| id(&f.path)); + match f.stamp { + EntryStamp::Native { len, modified } => FileStamp::native(&f.path) == Some(FileStamp::Native { len, modified }), + EntryStamp::Virtual { len, hash } => from_memory() == Some((len, hash)), + // (a folder at the path is still not a file to read) + EntryStamp::Missing => !std::fs::metadata(&*f.path).is_ok_and(|m| m.is_file()) && from_memory().is_none(), + } +} + +/// Reads little-endian fields off the front of a byte slice. +struct Reader<'a>(&'a [u8]); + +impl<'a> Reader<'a> { + /// Takes the next `n` bytes, or `None` when fewer remain. + fn take(&mut self, n: usize) -> Option<&'a [u8]> { + let head = self.0.get(..n)?; + self.0 = self.0.get(n..)?; + Some(head) + } + /// Reads one byte. + fn u8(&mut self) -> Option { + self.take(1)?.first().copied() + } + /// Reads a little-endian `u32`. + fn u32(&mut self) -> Option { + Some(u32::from_le_bytes(self.take(4)?.try_into().ok()?)) + } + /// Reads a little-endian `u64`. + fn u64(&mut self) -> Option { + Some(u64::from_le_bytes(self.take(8)?.try_into().ok()?)) + } + /// Reads a little-endian `i128`. + fn i128(&mut self) -> Option { + Some(i128::from_le_bytes(self.take(16)?.try_into().ok()?)) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + /// A sample list of native, missing and virtual files for the tests. + fn files() -> ReadFiles { + [ + ReadFile::new("/a.png", FileStamp::Native { len: 3, modified: Some(9) }), + ReadFile::new("/b.png", FileStamp::Native { len: 4, modified: None }), + // Before 1970, and past where `u64` nanoseconds end (2554). + ReadFile::new("/d.png", FileStamp::Native { len: 5, modified: Some(-86_400_000_000_000) }), + ReadFile::new("/e.png", FileStamp::Native { len: 6, modified: Some(i128::from(u64::MAX) + 1) }), + ReadFile::new("/c.png", FileStamp::Missing), + ReadFile::new("/v.mov", FileStamp::Virtual), + ] + .into_iter() + .collect() + } + + #[test] + fn lists_round_trip_and_damage_is_caught() { + let id = |p: &str| (p == "/v.mov").then_some((8, 77)); + let list = EntryFiles::of(&files(), Some(&id)).unwrap(); + assert_eq!(list.files()[5].stamp, EntryStamp::Virtual { len: 8, hash: 77 }); + let mut bytes = vec![]; + list.encode(&mut bytes); + bytes.extend_from_slice(b"rest"); + let (back, rest) = EntryFiles::decode(&bytes).unwrap(); + assert_eq!((back, rest), (list.clone(), &b"rest"[..])); + assert_eq!(list.to_read_files(), files()); + // Every truncation is caught (never a panic, never a shorter list). + let mut plain = vec![]; + list.encode(&mut plain); + for n in 0..plain.len() { + assert!(EntryFiles::decode(&plain[..n]).is_none(), "cut at {n}"); + } + // Bad tags and counts. + let mut bad = plain.clone(); + bad[0..4].copy_from_slice(&u32::MAX.to_le_bytes()); + assert!(EntryFiles::decode(&bad).is_none()); + } + + #[test] + fn frames_that_cant_be_checked_are_not_stored() { + let mut incomplete = files(); + incomplete.mark_incomplete(); + let id = |_: &str| Some((1, 1)); + assert!(EntryFiles::of(&incomplete, Some(&id)).is_none(), "an incomplete list"); + assert!(EntryFiles::of(&files(), None).is_none(), "a file from memory without the hook"); + assert!(EntryFiles::of(&ReadFiles::default(), None).is_some_and(|l| l.is_empty()), "a frame that reads no file"); + } + + #[test] + fn the_check_looks_at_the_listed_files() { + let dir = std::env::temp_dir().join(format!("effectcraft-entry-files-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let p = dir.join("f.bin"); + std::fs::write(&p, b"abc").unwrap(); + let path = p.to_string_lossy().to_string(); + let gone = dir.join("gone.bin").to_string_lossy().to_string(); + let stamp = FileStamp::native(&path).unwrap(); + let read: ReadFiles = [ReadFile::new(path.as_str(), stamp), ReadFile::new(gone.as_str(), FileStamp::Missing)].into_iter().collect(); + let list = EntryFiles::of(&read, None).unwrap(); + assert!(list.unchanged(None)); + std::fs::write(&p, b"abcd").unwrap(); + assert!(!list.unchanged(None), "a new size"); + std::fs::write(&gone, b"x").unwrap(); + let list = EntryFiles::of(&[ReadFile::new(gone.as_str(), FileStamp::Missing)].into_iter().collect(), None).unwrap(); + assert!(!list.unchanged(None), "a missing file that is back"); + let v: ReadFiles = [ReadFile::new("/v", FileStamp::Virtual)].into_iter().collect(); + let one = |_: &str| Some((1, 1)); + let two = |_: &str| Some((1, 2)); + let list = EntryFiles::of(&v, Some(&one)).unwrap(); + assert!(list.unchanged(Some(&one)) && !list.unchanged(Some(&two)) && !list.unchanged(None)); + let _ = std::fs::remove_dir_all(&dir); + } +} diff --git a/crates/render/src/eval.rs b/crates/render/src/eval.rs index 0a10afa45..41e6132d3 100644 --- a/crates/render/src/eval.rs +++ b/crates/render/src/eval.rs @@ -44,11 +44,15 @@ pub struct EvalCtx<'a> { /// Media Replacement values overridden by the Essential Properties of a collapsed precomp /// instance. pub media_overrides: &'a [crate::MediaOverride], + /// Where the source files of what expressions render (`sampleImage`) are noted: the + /// renderer's [`Renderer::reads`](crate::Renderer::reads) while rendering. + pub reads: Option<&'a crate::reads::ReadLog>, } impl<'a> EvalCtx<'a> { + /// A context for `comp` at `time` with no expressions, footage, overrides or read log. pub fn new(project: &'a Project, comp_id: ItemId, comp: &'a Comp, time: Tick) -> EvalCtx<'a> { - EvalCtx { project, comp_id, comp, time, expr: None, footage: None, property_overrides: &[], media_overrides: &[] } + EvalCtx { project, comp_id, comp, time, expr: None, footage: None, property_overrides: &[], media_overrides: &[], reads: None } } pub fn at(&self, time: Tick) -> EvalCtx<'a> { EvalCtx { time, ..*self } diff --git a/crates/render/src/footage.rs b/crates/render/src/footage.rs index 4c90967d3..0e17f152d 100644 --- a/crates/render/src/footage.rs +++ b/crates/render/src/footage.rs @@ -1,4 +1,5 @@ use super::{Arc, AtomicBool, Footage, Image, ItemId, ItemKind, Ordering, Tick}; +use crate::reads::ReadLog; /// How a [`FootageSource`] hands over float footage (OpenEXR, float TIFF), whose values are /// linear light: encoded with a curve, as the compositor takes footage, or as stored. Other @@ -92,6 +93,15 @@ pub trait FootageSource: Send + Sync { fn called_off(&self) -> bool { false } + /// Run `f`, which reads from this source on this thread, noting in `reads` every source file + /// those reads use, with its identity as read (see [`crate::reads`]): the file a frame was + /// decoded from, also when it comes from the source's own memory cache (without reading the + /// file again). Sources that can't tell which files they read keep the default, which marks + /// `reads` incomplete. + fn recording(&self, reads: &ReadLog, f: &mut dyn FnMut()) { + reads.mark_incomplete(); + f() + } /// Why `footage` shows no picture although its file is there: a read of it failed because /// no decoder handles its codec, profile, chroma format or bit depth, or the stream is damaged /// (e.g. "H.264 (High 4:2:2) isn't supported by the built-in decoder: ..."). `None` while it @@ -194,6 +204,10 @@ impl FootageSource for CancellableFootage<'_> { fn called_off(&self) -> bool { self.cancel.load(Ordering::Relaxed) || self.inner.called_off() } + /// Runs `f` with the inner source, collecting the files it reads into `reads`. + fn recording(&self, reads: &ReadLog, f: &mut dyn FnMut()) { + self.inner.recording(reads, f) + } fn problem(&self, footage: &Footage) -> Option { self.inner.problem(footage) } @@ -211,7 +225,12 @@ pub fn is_vector_footage(f: &Footage) -> bool { pub struct NoFootage; impl FootageSource for NoFootage { + /// Always `None`: there is no footage. fn frame(&self, _: ItemId, _: &Footage, _: Tick) -> Option> { None } + /// Reads no files. + fn recording(&self, _: &ReadLog, f: &mut dyn FnMut()) { + f() + } } diff --git a/crates/render/src/fx_host.rs b/crates/render/src/fx_host.rs index 65bafe002..3a6f1a34c 100644 --- a/crates/render/src/fx_host.rs +++ b/crates/render/src/fx_host.rs @@ -95,6 +95,7 @@ impl EffectHost for FxHost<'_, '_, '_> { Some(self.pixels(other, buf, false)) } + /// The audio of footage layer `id` from `start`, or `None` when the layer is not footage. fn audio(&self, id: u64, start: f64, frames: usize, rate: u32) -> Option> { let other = self.ctx.layer(effectcraft_project::LayerId(id))?; let LayerSource::Footage { item } = &other.source else { return None }; @@ -104,7 +105,7 @@ impl EffectHost for FxHost<'_, '_, '_> { return None; } let st = other.layer_time(Tick::from_seconds_f64(start)); - self.r.footage.audio(item, f, st, frames, rate) + self.r.read(|| self.r.footage.audio(item, f, st, frames, rate)) } fn self_at(&self, layer_time: f64, effects: usize) -> Option { diff --git a/crates/render/src/layers.rs b/crates/render/src/layers.rs index d105c6f13..df976a857 100644 --- a/crates/render/src/layers.rs +++ b/crates/render/src/layers.rs @@ -34,21 +34,43 @@ impl Shutter { } } +/// `files` (a content's) with the files of the buffers made of it that the layer cache kept: +/// `files` itself when they are all its own. +fn with_kept_files(files: Arc, kept: &[Arc]) -> Arc { + if kept.iter().all(|f| Arc::ptr_eq(f, &files)) { + return files; + } + let mut all = (*files).clone(); + kept.iter().for_each(|f| all.extend(f)); + Arc::new(all) +} + impl<'a> Renderer<'a> { /// The layer with its styles: exterior passes and body (cached per pass). pub(crate) fn styled(&self, ctx: &EvalCtx, layer: &Layer, mut timing: Option<&mut LayerTiming>) -> Option { - let (content, ckey) = self.content_buf_timed(ctx, layer, timing.as_deref_mut())?; + let (content, ckey, files) = self.content_buf_timed(ctx, layer, timing.as_deref_mut())?; if !styles::active(ctx, layer) { - return Some(StyledLayer { passes: vec![], body: content.clone(), content, key: ckey, ckey, plain: true }); + return Some(StyledLayer { passes: vec![], body: content.clone(), content, key: ckey, ckey, plain: true, files }); } let modes = styles::pass_modes(ctx, layer); let key = ckey.map(|k| cache::styles_key(ctx, layer, k)); - if let (Some(c), Some(k)) = (self.cache, key) - && let Some(body) = c.get(k) - { - let passes: Option> = modes.iter().enumerate().map(|(i, m)| c.get(cache::derive(k, i as u64 + 1)).map(|b| (b, *m))).collect(); + // (a cached body or pass may have been made of other files than the content: another + // worker's, or one from disk; the styled layer lists the files of every buffer it holds) + if let Some((body, body_files)) = self.cached(key) { + let mut kept_files = vec![body_files]; + let passes: Option> = modes + .iter() + .enumerate() + .map(|(i, m)| { + self.cached(key.map(|k| cache::derive(k, i as u64 + 1))).map(|(b, f)| { + kept_files.push(f); + (b, *m) + }) + }) + .collect(); if let Some(passes) = passes { - return Some(StyledLayer { passes, body, content, key, ckey, plain: false }); + let files = with_kept_files(files, &kept_files); + return Some(StyledLayer { passes, body, content, key, ckey, plain: false, files }); } } let t0 = web_time::Instant::now(); @@ -59,16 +81,23 @@ impl<'a> Renderer<'a> { t.cached = false; t.effects.push(("layerStyles".into(), t0.elapsed().as_secs_f64() * 1e3)); } - let mut body = Arc::new(st.body); - let mut passes: Vec<_> = st.passes.into_iter().map(|(b, m)| (Arc::new(b), m)).collect(); - // The buffers the cache keeps (another worker's, if it kept them first). - if let (Some(c), Some(k)) = (self.cache_to_keep(), key) { - body = c.insert(k, body); - for (i, (b, _)) in passes.iter_mut().enumerate() { - *b = c.insert(cache::derive(k, i as u64 + 1), b.clone()); - } - } - Some(StyledLayer { passes, body, content, key, ckey, plain: false }) + // The buffers the cache keeps (another worker's, if it kept them first), made of the + // content's files; the styled layer then lists the files of every buffer it holds. + let mut kept_files = vec![]; + let (body, f) = self.keep(key, Arc::new(st.body), &files); + kept_files.push(f); + let passes: Vec<_> = st + .passes + .into_iter() + .enumerate() + .map(|(i, (b, m))| { + let (b, f) = self.keep(key.map(|k| cache::derive(k, i as u64 + 1)), Arc::new(b), &files); + kept_files.push(f); + (b, m) + }) + .collect(); + let files = with_kept_files(files, &kept_files); + Some(StyledLayer { passes, body, content, key, ckey, plain: false, files }) } /// The styled layer's buffers in the blending space. @@ -76,9 +105,10 @@ impl<'a> Renderer<'a> { if self.pipe.to_blend().is_none() { return st; } - let body = self.to_blend(st.body, st.key); - let content = if st.plain { body.clone() } else { self.to_blend(st.content, st.ckey) }; - let passes = st.passes.into_iter().enumerate().map(|(i, (b, m))| (self.to_blend(b, st.key.map(|k| cache::derive(k, i as u64 + 1))), m)).collect(); + let body = self.to_blend(st.body, st.key, &st.files); + let content = if st.plain { body.clone() } else { self.to_blend(st.content, st.ckey, &st.files) }; + let passes = + st.passes.into_iter().enumerate().map(|(i, (b, m))| (self.to_blend(b, st.key.map(|k| cache::derive(k, i as u64 + 1)), &st.files), m)).collect(); StyledLayer { passes, body, content, ..st } } @@ -236,7 +266,11 @@ impl<'a> Renderer<'a> { /// A processed-layer cache key that also covers content motion blur (the averaged source /// depends on the content at every sub-sample). pub(crate) fn content_key(&self, ctx: &EvalCtx, layer: &Layer, key: Option) -> Option { - let k = key?; + let k = self.mask_gate_key(ctx, layer, key)?; + // A layer that reads other layers through its effects' layer parameters gets them drawn + // by this renderer: the switches it passes down (Switches Affect Nested Comps, the + // precomp layers above, motion blur on) change those pixels, not just the layers' own. + let k = if cache::reads_layers(ctx, layer) { cache::derive(k, self.nested_look()) } else { k }; let Some(times) = self.content_times(ctx, layer) else { return Some(k) }; times.iter().try_fold(cache::derive(k, 0x6d62_6c72), |d, t| Some(cache::derive(d, cache::layer_key(&ctx.at(*t), layer, 1.0, false, false)?))) } @@ -257,6 +291,15 @@ impl<'a> Renderer<'a> { } } + /// A cache key of a masked layer's buffer, told apart when mask motion blur can't run at all + /// in this render ([`Self::mask_blur`]'s gate: the render options, the precomp layers above). + /// The key has the layer's own motion blur state, but a mask set to On blurs without it. + pub(crate) fn mask_gate_key(&self, ctx: &EvalCtx, layer: &Layer, key: Option) -> Option { + let k = key?; + let masked = layer.masks().is_some_and(|m| !m.children.is_empty()); + Some(if masked && !self.mask_blur(ctx, layer).allowed { cache::derive(k, 0x6d62_6f66) } else { k }) + } + /// Motion-blur sub-samples for a layer buffer (1 = no motion blur). As in After Effects, a 2D /// layer gets about one sample per output pixel its corners travel during the shutter, /// at least Samples Per Frame and at most the comp's Adaptive Sample Limit; a layer that @@ -582,6 +625,8 @@ pub struct StyledLayer { ckey: Option, /// No layer styles: composite `body` the usual way. pub plain: bool, + /// The source files the layer's buffers were made of (see [`crate::reads`]). + pub(crate) files: Arc, } /// Where a layer buffer lands (see [`Renderer::placement`]). diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index dbd948320..e09794de2 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -17,6 +17,7 @@ use color::Region; pub mod eval; pub mod masks; pub mod passes; +pub mod reads; pub mod shapes; pub mod styles; pub mod text; @@ -69,6 +70,10 @@ pub struct Renderer<'a> { pub opts: RenderOpts, /// Processed-layer cache shared across frames (see [`cache`]). `None` renders everything. pub cache: Option<&'a LayerCache>, + /// Where the source files this render reads are noted (see [`reads`]): the frame's own, + /// from the footage source and from the buffers the layer cache serves. `None` records + /// nothing for the frame (buffers kept in the layer cache still record theirs). + pub reads: Option<&'a reads::ReadLog>, /// Optional per-layer timing sink (`frame --bench` / perf readouts). pub profile: Option<&'a std::sync::Mutex>>, /// GPU backend used when [`RenderOpts::backend`] asks for it. diff --git a/crates/render/src/pipeline.rs b/crates/render/src/pipeline.rs index e84348fdf..6c79ba7bb 100644 --- a/crates/render/src/pipeline.rs +++ b/crates/render/src/pipeline.rs @@ -3,6 +3,7 @@ use super::footage::{FootageSource, is_vector_footage}; use super::frames::{blend_frames, cineon_frame, content_bounds, field_frame, frame_blend_mode, frame_position, frame_size, interpret_pixels, roi_inside}; use super::fx_host::{FxHost, essential_overrides}; use super::opts::{Collapse3d, LayerTiming, MAX_THROUGH, RenderOpts, Through}; +use super::reads::{ReadFiles, ReadLog}; use super::{ Arc, AutoKey, AutoPick, BlendMode, Buf, Comp, EffectCtx, EffectEnv, EvalCtx, Footage, FootageKind, FrameBlend, FrameRate, GroupKind, Image, ItemId, ItemKind, Layer, LayerCache, LayerSource, Params, Project, Quality, Region, Renderer, Tick, cache, color, masks, shapes, styles, text, three_d, vec2, @@ -101,6 +102,7 @@ fn collapsed_instance(ctx: &EvalCtx, layer: &Layer, item: ItemId) -> Option<(Vec } impl<'a> Renderer<'a> { + /// A renderer over `project` and `footage` with the given options. pub fn new(project: &'a Project, footage: &'a dyn FootageSource, opts: RenderOpts) -> Renderer<'a> { Renderer { project, @@ -108,6 +110,7 @@ impl<'a> Renderer<'a> { expr: None, opts, cache: None, + reads: None, profile: None, accel: None, depth: 0, @@ -129,6 +132,67 @@ impl<'a> Renderer<'a> { self.cache.filter(|_| !self.footage.called_off()) } + /// `read`, a read of this render's footage source, with the files it uses noted in + /// [`Renderer::reads`] (see [`FootageSource::recording`]). + pub(crate) fn read(&self, read: impl FnOnce() -> Option) -> Option { + let Some(log) = self.reads else { return read() }; + let (mut read, mut out) = (Some(read), None); + self.footage.recording(log, &mut || out = read.take().and_then(|f| f())); + out + } + + /// `ctx` noting what it reads (fonts, `sampleImage`) in this render's [`Renderer::reads`]: + /// a context made by an outer render carries that render's log, not the one of the buffer + /// [`Renderer::recorded`] makes. + pub(crate) fn with_reads<'c>(&'c self, ctx: &EvalCtx<'c>) -> EvalCtx<'c> { + EvalCtx { reads: self.reads, ..*ctx } + } + + /// The buffer the layer cache keeps under `key`, with the files it was made of noted in + /// [`Renderer::reads`]. + pub(crate) fn cached(&self, key: Option) -> Option<(Arc, Arc)> { + let (buf, files) = self.cache?.get(key?)?; + if let Some(log) = self.reads { + log.note_all(&files); + } + Some((buf, files)) + } + + /// Keep `buf`, made of `files`, under `key` (see [`Renderer::recorded`]): the buffer the cache + /// keeps (another worker's, if it kept one first), or `buf` when nothing is kept, with the + /// files that buffer was made of. Another worker's files are noted in [`Renderer::reads`] + /// too: its pixels are the ones this render uses (a file that changed between the two reads + /// then has two identities, and the list is incomplete). + pub(crate) fn keep(&self, key: Option, buf: Arc, files: &Arc) -> (Arc, Arc) { + let (Some(c), Some(k)) = (self.cache_to_keep(), key) else { return (buf, files.clone()) }; + let (kept, kept_files) = c.insert(k, buf, files.clone()); + if !Arc::ptr_eq(&kept_files, files) + && let Some(log) = self.reads + { + log.note_all(&kept_files); + } + (kept, kept_files) + } + + /// Run `make`, which makes a buffer to keep under `key` in the layer cache, on this renderer + /// with its reads noted apart: what `make` returns and the files it read (from the footage + /// source, or the files of cached buffers it used), which go to [`Renderer::reads`] too. A + /// cached buffer then reports the files it was made of whichever render uses it. Without a + /// cache or a key, `make` runs on this renderer as it is (no files: nothing is kept). + pub(crate) fn recorded(&self, key: Option, make: impl FnOnce(&Renderer<'_>) -> T) -> (T, Arc) { + if key.is_none() || self.cache.is_none() { + return (make(self), Arc::default()); + } + // (the generation before any read: a file dropped while `make` runs makes it stale) + let log = self.cache.and_then(LayerCache::drop_generation).map_or_else(ReadLog::new, ReadLog::starting_at); + let out = make(&Renderer { reads: Some(&log), ..*self }); + let files = log.into_files(); + if let Some(own) = self.reads { + own.note_all(&files); + } + (out, Arc::new(files)) + } + /// A layer's Quality switch, limited by the precomp layers above it when /// [`RenderOpts::nested_switches`] is on. pub fn quality(&self, layer: &Layer) -> Quality { @@ -143,6 +207,24 @@ impl<'a> Renderer<'a> { } } + /// What this renderer passes down to the layers it draws beyond their own switches + /// ([`RenderOpts::nested_switches`], the switches inherited from the precomp layers above, + /// motion blur on): part of the cache key of a buffer that reads other layers. + pub(crate) fn nested_look(&self) -> u64 { + let inherited = match self.inherited { + None => 0, + Some((q, mb)) => { + let q = match q { + Quality::Best => 0, + Quality::Draft => 1, + Quality::Wireframe => 2, + }; + 1 + q * 2 + u64::from(mb) + } + }; + 0x6e65_7374_0000_0000 | inherited << 2 | u64::from(self.opts.nested_switches) << 1 | u64::from(self.opts.motion_blur) + } + /// A layer's Motion Blur switch, limited by the precomp layers above it. pub(crate) fn layer_motion_blur(&self, layer: &Layer) -> bool { layer.switches.motion_blur && self.inherited.is_none_or(|(_, mb)| mb) @@ -366,8 +448,19 @@ impl<'a> Renderer<'a> { } } + /// The evaluation context of `comp` at `t`, carrying this renderer's expressions, footage and read log. pub(crate) fn ctx(&self, comp_id: ItemId, comp: &'a Comp, t: Tick) -> EvalCtx<'a> { - EvalCtx { project: self.project, comp_id, comp, time: t, expr: self.expr, footage: Some(self.footage), property_overrides: &[], media_overrides: &[] } + EvalCtx { + project: self.project, + comp_id, + comp, + time: t, + expr: self.expr, + footage: Some(self.footage), + property_overrides: &[], + media_overrides: &[], + reads: self.reads, + } } /// This renderer with another accelerator (or none): the passes of @@ -760,7 +853,7 @@ impl<'a> Renderer<'a> { // Continuously rasterised vector footage: drawn at the on-screen scale. if layer.switches.collapse && is_vector_footage(f) { let k = self.raster_scale(ctx, layer); - if let Some(img) = self.footage.vector_frame(item, f, k) { + if let Some(img) = self.read(|| self.footage.vector_frame(item, f, k)) { let mut buf = Buf { img: (*img).clone(), offset: [0.0; 2], scale: k }; if let Some(c) = self.pipe.media_in(f) { color::convert(&mut buf.img, &c); @@ -776,7 +869,20 @@ impl<'a> Renderer<'a> { let img = self.footage_frame(ctx, layer, item, pf, lt, size)?; Some(self.footage_buf(&img, pf, f.width, f.height)) } - LayerSource::Text => Some(self.authored(text::render(ctx, layer, self.raster_scale(ctx, layer)))), + // (the font files go to this render's log, which `ctx` may not carry: see + // [`Renderer::with_reads`]) + LayerSource::Text => { + // An Expression Selector evaluates per character: its results at other characters + // than the first are not in the layer's cache key (an amount reading a footage + // item's size by name, `textIndex == 1 ? 0 : footage("ref.png").width`), so the + // buffer is kept in memory only, never on disk (the frame's key covers them). + if cache::per_character_expressions(layer) + && let Some(log) = self.reads + { + log.mark_unkeyed(); + } + Some(self.authored(text::render(&self.with_reads(ctx), layer, self.raster_scale(ctx, layer)))) + } LayerSource::Shape => layer.props.sub("contents").map(|c| self.authored(shapes::render(ctx, layer, c, self.raster_scale(ctx, layer)))), _ => None, } @@ -831,7 +937,7 @@ impl<'a> Renderer<'a> { if f.fields != effectcraft_project::FieldOrder::Off && matches!(f.kind, FootageKind::Video | FootageKind::Sequence) { let field_rate = FrameRate::new(f.frame_rate.num * 2, f.frame_rate.den); let i = field_rate.frame_at(t).max(0); - let img = cineon_frame(self.footage.frame_with(item, f, f.frame_rate.tick_of(i / 2), None, self.pipe.float_curve(f))?, f); + let img = cineon_frame(self.read(|| self.footage.frame_with(item, f, f.frame_rate.tick_of(i / 2), None, self.pipe.float_curve(f)))?, f); let dominant_upper = f.fields == effectcraft_project::FieldOrder::UpperFirst; // Upper field = even lines (0, 2, …). let parity = if (i % 2 == 0) == dominant_upper { 0 } else { 1 }; @@ -844,6 +950,8 @@ impl<'a> Renderer<'a> { if per_pixel { Some(Arc::new(interpret_pixels(&img, f, self.pipe.linear_footage_space(f)))) } else { Some(img) } } + /// The footage frame at source time `t` after frame blending: the average of the source frames one comp frame spans, else a blend of the two neighbouring frames, else the plain frame. + /// Log scans are converted first, and blended frames are cached. fn footage_frame_raw(&self, ctx: &EvalCtx, layer: &Layer, item: ItemId, f: &Footage, t: Tick, size: Option<(u32, u32)>) -> Option> { let mode = frame_blend_mode(ctx, layer); let float = self.pipe.float_curve(f); @@ -855,6 +963,9 @@ impl<'a> Renderer<'a> { use std::hash::{Hash, Hasher}; let mut h = std::collections::hash_map::DefaultHasher::new(); (0x00f8_a3e5_u64, item, i, (w as f32).to_bits(), mode as u8, f.frame_rate.num, f.frame_rate.den, &f.path, float).hash(&mut h); + // Every file of a sequence: the key must tell two projects apart whose items + // share an id and a first frame (on disk, no project-wide salt does, #3184). + f.sequence.hash(&mut h); (f.alpha as u8).hash(&mut h); if f.alpha == effectcraft_project::AlphaMode::Premultiplied { f.premul_color.map(f32::to_bits).hash(&mut h); @@ -865,24 +976,22 @@ impl<'a> Renderer<'a> { } h.finish() }); - if let (Some(c), Some(k)) = (self.cache, key) - && let Some(b) = c.get(k) - { + if let Some((b, _)) = self.cached(key) { return Some(Arc::new(b.img.clone())); } // Log scans are converted before they blend: the conversion is not linear. - let a = self.footage.frame_with(item, f, f.frame_rate.tick_of(i), None, float).map(|a| cineon_frame(a, f)); - let b = self.footage.frame_with(item, f, f.frame_rate.tick_of(i + 1), None, float).map(|b| cineon_frame(b, f)); + let ((a, b), files) = self.recorded(key, |r| { + let frame = |i| r.read(|| r.footage.frame_with(item, f, f.frame_rate.tick_of(i), None, float)).map(|a| cineon_frame(a, f)); + (frame(i), frame(i + 1)) + }); if let (Some(a), Some(b)) = (a, b) { let img = blend_frames(mode, &a, &b, w as f32); - if let (Some(c), Some(k)) = (self.cache_to_keep(), key) { - c.insert(k, Arc::new(Buf { img: img.clone(), offset: [0.0; 2], scale: 1.0 })); - } + let _kept = self.keep(key, Arc::new(Buf { img: img.clone(), offset: [0.0; 2], scale: 1.0 }), &files); return Some(Arc::new(img)); } } } - self.footage.frame_with(item, f, t, size, float).map(|img| cineon_frame(img, f)) + self.read(|| self.footage.frame_with(item, f, t, size, float)).map(|img| cineon_frame(img, f)) } /// Source → masks, clamped/quantised to the project depth. @@ -902,52 +1011,41 @@ impl<'a> Renderer<'a> { /// Fully processed layer buffer (source → masks → effects → layer styles, flattened). /// Served from the layer cache when the layer's content key matches. pub fn layer_buf(&self, ctx: &EvalCtx, layer: &Layer) -> Option> { - self.layer_buf_keyed(ctx, layer).map(|(b, _)| b) + self.layer_buf_keyed(ctx, layer).map(|(b, _, _)| b) } /// [`Self::layer_buf`] in the blending space (linear with Blend Colors Using 1.0 Gamma). pub fn blend_layer_buf(&self, ctx: &EvalCtx, layer: &Layer) -> Option> { - let (b, k) = self.layer_buf_keyed(ctx, layer)?; - Some(self.to_blend(b, k)) + let (b, k, files) = self.layer_buf_keyed(ctx, layer)?; + Some(self.to_blend(b, k, &files)) } - /// A buffer converted to the blending space (cached under a key derived from `key`). - pub(crate) fn to_blend(&self, b: Arc, key: Option) -> Arc { + /// A buffer converted to the blending space (cached under a key derived from `key`, with + /// `files`, the source files `b` was made of). + pub(crate) fn to_blend(&self, b: Arc, key: Option, files: &Arc) -> Arc { let Some(c) = self.pipe.to_blend() else { return b }; let key = key.map(|k| cache::derive(k, 0x1ea7)); - if let (Some(cache), Some(k)) = (self.cache, key) - && let Some(x) = cache.get(k) - { + if let Some((x, _)) = self.cached(key) { return x; } let mut nb = (*b).clone(); color::convert(&mut nb.img, &c); - let nb = Arc::new(nb); - // The buffer the cache keeps (another worker's, if it kept one first). - match (self.cache_to_keep(), key) { - (Some(cache), Some(k)) => cache.insert(k, nb), - _ => nb, - } + self.keep(key, Arc::new(nb), files).0 } - fn layer_buf_keyed(&self, ctx: &EvalCtx, layer: &Layer) -> Option<(Arc, Option)> { + /// The flattened layer buffer, its cache key and the source files it was made of. + fn layer_buf_keyed(&self, ctx: &EvalCtx, layer: &Layer) -> Option<(Arc, Option, Arc)> { let st = self.styled(ctx, layer, None)?; if st.passes.is_empty() { - return Some((st.body, st.key)); + return Some((st.body, st.key, st.files)); } let key = st.key.map(|k| cache::derive(k, 0xf1a7)); - if let (Some(c), Some(k)) = (self.cache, key) - && let Some(b) = c.get(k) - { - return Some((b, key)); + if let Some((b, files)) = self.cached(key) { + return Some((b, key, files)); } let flat = Arc::new(styles::Styled { passes: st.passes.iter().map(|(b, m)| ((**b).clone(), *m)).collect(), body: (*st.body).clone() }.flatten()); - // The buffer the cache keeps (another worker's, if it kept one first). - let flat = match (self.cache_to_keep(), key) { - (Some(c), Some(k)) => c.insert(k, flat), - _ => flat, - }; - Some((flat, key)) + let (flat, files) = self.keep(key, flat, &st.files); + Some((flat, key, files)) } /// A layer's source pixels at the context time, before masks, effects and the transform @@ -983,28 +1081,32 @@ impl<'a> Renderer<'a> { /// Layer pixels after source → masks → effects (no layer styles). pub fn content_buf(&self, ctx: &EvalCtx, layer: &Layer) -> Option> { - self.content_buf_timed(ctx, layer, None).map(|(b, _)| b) + self.content_buf_timed(ctx, layer, None).map(|(b, _, _)| b) } - pub(crate) fn content_buf_timed(&self, ctx: &EvalCtx, layer: &Layer, mut timing: Option<&mut LayerTiming>) -> Option<(Arc, Option)> { + /// [`Self::content_buf`], its cache key and the source files it was made of. + pub(crate) fn content_buf_timed( + &self, + ctx: &EvalCtx, + layer: &Layer, + mut timing: Option<&mut LayerTiming>, + ) -> Option<(Arc, Option, Arc)> { let key = self.cache.and_then(|_| cache::layer_key(ctx, layer, self.raster_scale(ctx, layer), self.opts.draft, self.mb_on(ctx, layer))); let key = self.content_key(ctx, layer, key); - if let (Some(c), Some(k)) = (self.cache, key) - && let Some(b) = c.get(k) - { + if let Some((b, files)) = self.cached(key) { if let Some(t) = timing.as_deref_mut() { t.cached = true; } - return Some((b, key)); + return Some((b, key, files)); } - let buf = self.masked_source(ctx, layer)?; - let buf = Arc::new(self.apply_effects_timed(ctx, layer, buf, false, usize::MAX, timing.map(|t| &mut t.effects))); - // The buffer the cache keeps (another worker's, if it kept one first). - let buf = match (self.cache_to_keep(), key) { - (Some(c), Some(k)) => c.insert(k, buf), - _ => buf, - }; - Some((buf, key)) + let (buf, files) = self.recorded(key, |r| { + // (what expressions read while it is made, at shutter times too, goes to its files) + let ctx = &r.with_reads(ctx); + let buf = r.masked_source(ctx, layer)?; + Some(r.apply_effects_timed(ctx, layer, buf, false, usize::MAX, timing.map(|t| &mut t.effects))) + }); + let (buf, files) = self.keep(key, Arc::new(buf?), &files); + Some((buf, key, files)) } /// A layer's input at the context time: source → masks → its first `effects` effects @@ -1014,23 +1116,19 @@ impl<'a> Renderer<'a> { pub fn layer_input(&self, ctx: &EvalCtx, layer: &Layer, effects: usize) -> Option> { let key = self.cache.and_then(|_| cache::input_key(ctx, layer, self.raster_scale(ctx, layer), self.opts.draft, self.mb_on(ctx, layer), effects)); let key = self.content_key(ctx, layer, key); - if let (Some(c), Some(k)) = (self.cache, key) - && let Some(b) = c.get(k) - { + if let Some((b, _)) = self.cached(key) { return Some(b); } - let mut buf = self.masked_source(ctx, layer)?; - let origin = ctx.effect_bounds(layer).1; - buf.rebase(origin); - if effects > 0 { - buf = self.effect_space_stack(ctx, layer, buf, EffectStack { adjustment: false, limit: effects, origin }, None); - } - let buf = Arc::new(buf); - // The buffer the cache keeps (another worker's, if it kept one first). - let buf = match (self.cache_to_keep(), key) { - (Some(c), Some(k)) => c.insert(k, buf), - _ => buf, - }; - Some(buf) + let (buf, files) = self.recorded(key, |r| { + let ctx = &r.with_reads(ctx); + let mut buf = r.masked_source(ctx, layer)?; + let origin = ctx.effect_bounds(layer).1; + buf.rebase(origin); + if effects > 0 { + buf = r.effect_space_stack(ctx, layer, buf, EffectStack { adjustment: false, limit: effects, origin }, None); + } + Some(buf) + }); + Some(self.keep(key, Arc::new(buf?), &files).0) } } diff --git a/crates/render/src/reads.rs b/crates/render/src/reads.rs new file mode 100644 index 000000000..ed97e50fd --- /dev/null +++ b/crates/render/src/reads.rs @@ -0,0 +1,348 @@ +//! The source files a render read: which footage files its pixels came from, each with its +//! identity (size and modification time) as it was when it was read. +//! +//! A [`FootageSource`](crate::FootageSource) that knows which files it opens notes them while +//! [`FootageSource::recording`](crate::FootageSource::recording) runs; the renderer collects them +//! in a [`ReadLog`] ([`Renderer::reads`](crate::Renderer::reads)). Buffers in the layer cache keep +//! the files they were made of, so a frame served from memory reports the same files as the +//! render that made it, without touching the disk. +//! +//! The list is what a cache entry on disk has to check before it is used: a handful of files per +//! frame, never every file of every footage item. + +use std::sync::{Arc, Mutex, PoisonError}; + +/// The identity of a file as a render read it (frame and layer entries on disk store it, see +/// [`EntryFiles`](crate::disk_cache::EntryFiles)). +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub enum FileStamp { + /// A file on disk: its size in bytes and its modification time (nanoseconds since the Unix + /// epoch, negative before it; `None` only where the file system has none). + Native { len: u64, modified: Option }, + /// Bytes given from memory instead of the file system (the browser's file table): their + /// identity is the size and content hash a + /// [`VirtualFileId`](crate::disk_cache::VirtualFileId) gives for the path. + Virtual, + /// The file could not be read (missing, not a regular file, no permission). What was made + /// without it changes once it can be read again. + Missing, +} + +impl FileStamp { + /// The identity of a file from metadata the caller already has (of an open file). + pub fn of_metadata(md: &std::fs::Metadata) -> FileStamp { + FileStamp::Native { len: md.len(), modified: md.modified().ok().map(epoch_nanos) } + } + + /// The identity of the file at `path` now: one `metadata` call. `None` when the file system + /// can't describe it (missing, or a path served from memory). + pub fn native(path: &str) -> Option { + std::fs::metadata(path).ok().map(|md| FileStamp::of_metadata(&md)) + } +} + +/// `t` in nanoseconds since the Unix epoch, negative before it: every time a file system can +/// store fits (`i128` nanoseconds span far more than any `SystemTime`), saturating otherwise. +pub fn epoch_nanos(t: std::time::SystemTime) -> i128 { + let nanos = |d: std::time::Duration| i128::try_from(d.as_nanos()).unwrap_or(i128::MAX); + match t.duration_since(std::time::UNIX_EPOCH) { + Ok(after) => nanos(after), + Err(before) => nanos(before.duration()).saturating_neg(), + } +} + +/// One file a render read. +#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub struct ReadFile { + pub path: Arc, + pub stamp: FileStamp, +} + +impl ReadFile { + /// A file read with the given path and stamp. + pub fn new(path: impl Into>, stamp: FileStamp) -> ReadFile { + ReadFile { path: path.into(), stamp } + } +} + +/// At most this many files are listed per render or cached buffer; more mark the list +/// incomplete (a comp reading more files than this for one frame is not checked file by file). +pub const MAX_READ_FILES: usize = 4096; + +/// The files a render (or one cached buffer) read, each once, sorted by path. +/// +/// Incomplete when it can't say for sure: a footage source that doesn't tell what it reads, a +/// buffer from a store that doesn't keep its files, more than [`MAX_READ_FILES`] files, or one +/// file read with two identities (it changed during the render). A cache entry whose list is +/// incomplete can't be checked against the files, so it must not outlive the session. +/// +/// It also carries where its reads come from, which equality and hashing ignore: the drop +/// generation the earliest of them started at ([`ReadFiles::since`]), and whether a layer cache +/// key can't capture what it was made of ([`ReadFiles::is_unkeyed`]). +#[derive(Clone, Debug, Default)] +pub struct ReadFiles { + files: Vec, + incomplete: bool, + /// The disk cache's drop generation ([`DiskCache::drop_generation`]) when the earliest read + /// behind the list started; `None` when nothing says (a list built by hand). + /// + /// [`DiskCache::drop_generation`]: crate::disk_cache::DiskCache::drop_generation + since: Option, + /// Made of values a layer's cache key doesn't capture (a text Expression Selector evaluates + /// per character): such a buffer is not stored on disk. + unkeyed: bool, +} + +impl PartialEq for ReadFiles { + /// The same files with the same identities (where the reads come from doesn't count). + fn eq(&self, other: &Self) -> bool { + self.files == other.files && self.incomplete == other.incomplete + } +} + +impl Eq for ReadFiles {} + +impl std::hash::Hash for ReadFiles { + /// Hashes what [`PartialEq`] compares. + fn hash(&self, state: &mut H) { + self.files.hash(state); + self.incomplete.hash(state); + } +} + +impl ReadFiles { + /// Note a file read (once per path). + pub fn add(&mut self, file: ReadFile) { + match self.files.binary_search_by(|f| f.path.cmp(&file.path)) { + Ok(i) => { + if self.files.get(i).is_some_and(|f| f.stamp != file.stamp) { + self.incomplete = true; + } + } + Err(i) => { + if self.files.len() >= MAX_READ_FILES { + self.incomplete = true; + } else { + self.files.insert(i, file); + } + } + } + } + + /// Note every file of `other` (whether it is incomplete or unkeyed, and its generation). + pub fn extend(&mut self, other: &ReadFiles) { + self.incomplete |= other.incomplete; + self.unkeyed |= other.unkeyed; + if let Some(g) = other.since { + self.note_since(g); + } + for f in &other.files { + self.add(f.clone()); + } + } + + /// Some files read may be missing from the list (see [`ReadFiles`]). + pub fn mark_incomplete(&mut self) { + self.incomplete = true; + } + + /// Whether the list names every file read. + pub fn is_complete(&self) -> bool { + !self.incomplete + } + + /// The drop generation the earliest read behind the list started at (`None`: unknown). A + /// buffer made of a file dropped after it holds that file as it was before the drop. + pub fn since(&self) -> Option { + self.since + } + + /// A read behind the list started at drop generation `generation` (the earliest one counts). + pub fn note_since(&mut self, generation: u64) { + self.since = Some(self.since.map_or(generation, |s| s.min(generation))); + } + + /// Made of values a layer cache key doesn't capture (see [`ReadFiles::is_unkeyed`]). + pub fn mark_unkeyed(&mut self) { + self.unkeyed = true; + } + + /// Made of values a layer cache key doesn't capture: kept in memory, never stored on disk as + /// a layer buffer. (A frame's key captures them: frame entries are not affected.) + pub fn is_unkeyed(&self) -> bool { + self.unkeyed + } + + /// The files, sorted by path. + pub fn files(&self) -> &[ReadFile] { + &self.files + } + + /// The identity `path` was read with. + pub fn get(&self, path: &str) -> Option { + let i = self.files.binary_search_by(|f| (*f.path).cmp(path)).ok()?; + self.files.get(i).map(|f| f.stamp) + } + + /// The number of files in the list. + pub fn len(&self) -> usize { + self.files.len() + } + + /// Whether the list holds no files. + pub fn is_empty(&self) -> bool { + self.files.is_empty() + } +} + +impl FromIterator for ReadFiles { + /// Collects files into a list, adding each in turn. + fn from_iter>(iter: I) -> Self { + let mut out = ReadFiles::default(); + for f in iter { + out.add(f); + } + out + } +} + +/// Collects the files a render reads, from any thread (the layers of a frame render in +/// parallel). +#[derive(Debug, Default)] +pub struct ReadLog { + files: Mutex, +} + +impl ReadLog { + /// An empty read log. + pub fn new() -> ReadLog { + ReadLog::default() + } + + /// An empty read log for reads that start at drop generation `generation` (see + /// [`ReadFiles::since`]). + pub fn starting_at(generation: u64) -> ReadLog { + let mut files = ReadFiles::default(); + files.note_since(generation); + ReadLog { files: Mutex::new(files) } + } + + /// Locks the file list, recovering from a poisoned lock. + fn lock(&self) -> std::sync::MutexGuard<'_, ReadFiles> { + self.files.lock().unwrap_or_else(PoisonError::into_inner) + } + + /// Note a file read. + pub fn note(&self, file: ReadFile) { + self.lock().add(file); + } + + /// Note every file of `files` (and whether it is incomplete). + pub fn note_all(&self, files: &ReadFiles) { + if files.is_empty() && files.is_complete() && files.since.is_none() && !files.unkeyed { + return; + } + self.lock().extend(files); + } + + /// Some files read can't be listed (see [`ReadFiles`]). + pub fn mark_incomplete(&self) { + self.lock().mark_incomplete(); + } + + /// What is read is made of values a layer cache key doesn't capture + /// ([`ReadFiles::is_unkeyed`]). + pub fn mark_unkeyed(&self) { + self.lock().mark_unkeyed(); + } + + /// The files noted so far. + pub fn files(&self) -> ReadFiles { + self.lock().clone() + } + + /// The files noted. + pub fn into_files(self) -> ReadFiles { + self.files.into_inner().unwrap_or_else(PoisonError::into_inner) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + /// A native file with the given length for the tests. + fn file(path: &str, len: u64) -> ReadFile { + ReadFile::new(path, FileStamp::Native { len, modified: Some(7) }) + } + + #[test] + fn files_are_listed_once_sorted_by_path() { + let files: ReadFiles = [file("/b", 1), file("/a", 2), file("/b", 1)].into_iter().collect(); + assert_eq!(files.files().iter().map(|f| &*f.path).collect::>(), ["/a", "/b"]); + assert!(files.is_complete()); + assert_eq!(files.get("/a"), Some(FileStamp::Native { len: 2, modified: Some(7) })); + assert_eq!(files.get("/c"), None); + } + + /// A file read twice with different identities changed during the render: the list can't + /// vouch for what was made of it. + #[test] + fn a_file_read_with_two_identities_makes_the_list_incomplete() { + let files: ReadFiles = [file("/a", 1), file("/a", 2)].into_iter().collect(); + assert_eq!(files.len(), 1); + assert!(!files.is_complete()); + } + + /// Modification times keep their full value: before 1970 (not "no time") and past 2554 + /// (where `u64` nanoseconds end), so two such files never look alike. + #[test] + fn modification_times_are_kept_whole() { + use std::time::{Duration, UNIX_EPOCH}; + let day = Duration::from_secs(86_400); + assert_eq!(epoch_nanos(UNIX_EPOCH), 0); + assert_eq!(epoch_nanos(UNIX_EPOCH - day), -86_400_000_000_000); + let far = 600 * 365 * day; + if let Some(t) = UNIX_EPOCH.checked_add(far) { + assert_eq!(epoch_nanos(t), i128::try_from(far.as_nanos()).unwrap()); + } + let dir = std::env::temp_dir().join(format!("effectcraft-stamp-1969-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let (a, b) = (dir.join("a.bin"), dir.join("b.bin")); + let mut stamps = vec![]; + for (p, back) in [(&a, day), (&b, 2 * day)] { + std::fs::write(p, b"abc").unwrap(); + let f = std::fs::File::options().write(true).open(p).unwrap(); + if f.set_modified(UNIX_EPOCH - back).is_err() { + // (a file system that can't store times before 1970) + let _ = std::fs::remove_dir_all(&dir); + return; + } + drop(f); + stamps.push(FileStamp::native(&p.to_string_lossy()).unwrap()); + } + assert!(matches!(stamps[0], FileStamp::Native { modified: Some(t), .. } if t < 0), "{:?}", stamps[0]); + assert_ne!(stamps[0], stamps[1], "two files from before 1970 with the same size"); + let _ = std::fs::remove_dir_all(&dir); + } + + #[test] + fn the_list_is_bounded() { + let files: ReadFiles = (0..MAX_READ_FILES + 3).map(|i| file(&format!("/f{i:06}"), 1)).collect(); + assert_eq!(files.len(), MAX_READ_FILES); + assert!(!files.is_complete(), "files past the bound make the list incomplete, never silently short"); + } + + #[test] + fn incompleteness_carries_over() { + let mut part = ReadFiles::default(); + part.mark_incomplete(); + let log = ReadLog::new(); + log.note(file("/a", 1)); + log.note_all(&part); + let all = log.into_files(); + assert_eq!(all.len(), 1); + assert!(!all.is_complete()); + } +} diff --git a/crates/render/src/tests.rs b/crates/render/src/tests.rs index c77fc2d94..80b1aa12d 100644 --- a/crates/render/src/tests.rs +++ b/crates/render/src/tests.rs @@ -482,6 +482,145 @@ impl crate::eval::ExprHost for ControllerRate { } } +/// An expression that reads a file (as `sampleImage` does, into [`EvalCtx::reads`]) and keeps +/// the value. +/// +/// [`EvalCtx::reads`]: crate::eval::EvalCtx::reads +struct ReadsAFile; + +impl crate::eval::ExprHost for ReadsAFile { + fn eval(&self, ctx: &crate::eval::EvalCtx, _: &effectcraft_project::Layer, _: &effectcraft_project::Property, value: &Value) -> Result { + if let Some(log) = ctx.reads { + log.note(crate::reads::ReadFile::new("/sampled.png", crate::reads::FileStamp::Native { len: 3, modified: Some(1) })); + } + Ok(value.clone()) + } +} + +/// What expressions read while a cached buffer is made (a mask expression, which mask motion +/// blur also runs at shutter times the cache key doesn't see) goes to that buffer's files, not +/// only to the frame's (#3184): a later render served the buffer lists the file too. Content, +/// a Time effect's input and an adjustment layer's footprint. +#[test] +fn what_expressions_read_goes_to_the_files_of_the_buffer_they_make() { + use crate::reads::ReadLog; + use crate::{NoFootage, RenderOpts, Renderer}; + let (mut p, cid, comp) = setup(); + for adjustment in [false, true] { + let mut l = solid(&mut p, &comp, [1.0, 1.0, 1.0], 200, 100); + l.switches.adjustment = adjustment; + let mut next = p.next_id; + let m = build::mask(&mut Ids(&mut next), "Mask 1", ShapePath::rect([50.0, 50.0], 40.0, 40.0), MaskMode::Add, [255, 255, 0]); + p.next_id = next; + l.props.sub_mut("masks").unwrap().children.push(m.into()); + l.props.prop_mut("masks/#1/path").unwrap().expr = Some(effectcraft_project::Expression { text: "sampled".into(), enabled: true }); + p.comp_mut(cid).unwrap().layers.push(l); + } + let cache = crate::LayerCache::default(); + let c = p.comp(cid).unwrap(); + let (content, adjustment) = (&c.layers[0], &c.layers[1]); + // `make`, rendered once with the expressions (the files go to `log`) and then served from + // the cache to a render without them: the files that render lists. + let files_served = |what: &str, make: &dyn Fn(&Renderer, &crate::eval::EvalCtx) -> bool| { + let log = ReadLog::new(); + let mut r = Renderer::new(&p, &NoFootage, RenderOpts::default()); + r.expr = Some(&ReadsAFile); + r.cache = Some(&cache); + r.reads = Some(&log); + assert!(make(&r, &r.ctx(cid, c, Tick::ZERO)), "{what}"); + assert!(log.files().get("/sampled.png").is_some(), "{what}: the frame lists the file"); + let hits = cache.stats().hits; + let served = ReadLog::new(); + r.expr = None; + r.reads = Some(&served); + assert!(make(&r, &r.ctx(cid, c, Tick::ZERO)), "{what}"); + assert!(cache.stats().hits > hits, "{what}: served from the cache"); + served.into_files() + }; + let files = files_served("content", &|r, ctx| r.content_buf(ctx, content).is_some()); + assert!(files.get("/sampled.png").is_some(), "content: {files:?}"); + let files = files_served("input", &|r, ctx| r.layer_input(ctx, content, 0).is_some()); + assert!(files.get("/sampled.png").is_some(), "input: {files:?}"); + let files = files_served("footprint", &|r, ctx| r.adjustment_footprint(ctx, adjustment).is_some()); + assert!(files.get("/sampled.png").is_some(), "footprint: {files:?}"); +} + +/// A text Expression Selector whose Amount is 0 for the first character and the width of the +/// footage item named `ref.png` for the others (`textIndex == 1 ? 0 : footage("ref.png").width`). +struct WidthOfRef; + +impl crate::eval::ExprHost for WidthOfRef { + fn eval(&self, _: &crate::eval::EvalCtx, _: &effectcraft_project::Layer, _: &effectcraft_project::Property, value: &Value) -> Result { + Ok(value.clone()) + } + fn eval_text_selector( + &self, + ctx: &crate::eval::EvalCtx, + _: &effectcraft_project::Layer, + _: &effectcraft_project::Property, + index: usize, + _: usize, + _: [f64; 3], + ) -> Result<[f64; 3], String> { + let width = ctx.project.items.values().find(|i| i.name == "ref.png").and_then(|i| i.dimensions()).map_or(0.0, |d| d.0 as f64); + Ok([if index == 1 { 0.0 } else { width }; 3]) + } +} + +/// A text layer whose Expression Selector reads a footage item's size for every character but +/// the first: the layer's key holds the first character's amount only, so its buffer is not +/// stored on disk. Reopened over the same disk cache after the footage's width changed (16 to +/// 64), the frame matches one rendered without a cache. +#[test] +fn a_text_expression_selector_is_not_served_from_the_disk_cache() { + use crate::disk_cache::{DiskCache, Kind}; + use crate::{LayerCache, NoFootage, RenderOpts, Renderer}; + let project = |width: u32| { + let (mut p, cid, comp) = setup(); + let f = effectcraft_project::Footage { has_video: true, width, height: 16, ..Default::default() }; + p.add_item("ref.png", Label::None, None, ItemKind::Footage(f)); + let mut l = build::layer(&mut p, &comp, "Text", LayerSource::Text, (200, 100), None); + l.props.prop_mut("text/sourceText").unwrap().value = Value::Text(Box::new(TextDoc { text: "HH".into(), size: 60.0, ..Default::default() })); + let mut next = p.next_id; + let mut ids = Ids(&mut next); + let mut props = build::text_anim_props(&mut ids, "opacity", false); + for pr in &mut props { + pr.value = Value::Scalar(0.0); + } + let mut animator = build::text_animator(&mut ids, "Animator 1", props); + let sel = build::expression_selector(&mut ids, "Expression Selector 1"); + p.next_id = next; + animator.sub_mut("selectors").unwrap().children.push(sel.into()); + l.props.group_mut("text/animators").unwrap().children.push(animator.into()); + p.comp_mut(cid).unwrap().layers.push(l); + (p, cid) + }; + let render = |p: &Project, cid: ItemId, cache: Option<&LayerCache>| { + let mut r = Renderer::new(p, &NoFootage, RenderOpts::default()); + r.expr = Some(&WidthOfRef); + r.cache = cache; + r.comp_frame(cid, Tick::ZERO) + }; + let dir = tempfile::tempdir().unwrap(); + let dc = DiskCache::open(dir.path(), 1 << 30).unwrap(); + dc.set_min_layer_ms(0); + // First session: the 16 px wide footage. + let (p16, cid) = project(16); + let cache = LayerCache::default(); + cache.set_disk(Some(dc.clone())); + let first = render(&p16, cid, Some(&cache)); + dc.flush(); + assert!(first.data.iter().any(|px| px[3] > 0.5), "the text renders"); + // Reopened with a fresh memory cache, the footage now 64 px wide. + let (p64, cid) = project(64); + let uncached = render(&p64, cid, None); + assert_ne!(uncached.data, first.data, "the second character's opacity follows the width"); + let reopened = LayerCache::default(); + reopened.set_disk(Some(dc.clone())); + assert_eq!(render(&p64, cid, Some(&reopened)).data, uncached.data, "not the buffer from before the change"); + assert!(dc.keys(Kind::Layer).is_empty(), "the text layer's buffer is not on disk"); +} + /// A Birth Rate expression reading another layer: changing that layer changes the history but /// not the current rate (0) nor this layer's properties, which is all the layer cache key sees. /// CC Particle World layers with expressions therefore aren't layer cached. @@ -820,6 +959,41 @@ fn effects_read_layer_params() { assert!(px[2] > 0.99 && px[0] < 0.01, "{px:?}"); } +/// A cached layer whose effect reads a precomp layer: how the precomp's layers render depends on +/// Switches Affect Nested Comps (the precomp layer's Draft quality passes down) and on the +/// switches the reading layer's own comp inherits, so the key must tell them apart (a buffer +/// made under the other setting, from memory or disk, is stale). +#[test] +fn a_cached_layer_reading_a_precomp_is_keyed_by_the_nested_switches() { + let (mut p, cid, comp) = setup(); + let mut inner = Comp::new(200, 100, FrameRate::FPS_30, Tick::from_seconds_f64(2.0)); + // A rotated square off the pixel grid: Draft (nearest) and Best (bilinear) sampling differ. + let mut dot = solid(&mut p, &inner, [1.0, 1.0, 1.0], 40, 40); + dot.props.prop_mut("transform/position").unwrap().value = Value::Vec3([100.3, 50.6, 0.0]); + dot.props.prop_mut("transform/rotation").unwrap().value = Value::Scalar(30.0); + inner.layers.push(dot); + let iid = p.add_item("Inner", Label::Sandstone, None, ItemKind::Comp(inner.into())); + let mut pre = build::layer(&mut p, &comp, "Inner", LayerSource::Comp { item: iid }, (200, 100), None); + pre.switches.video = false; + pre.switches.quality = effectcraft_project::Quality::Draft; + let mut top = solid(&mut p, &comp, [1.0, 0.0, 0.0], 200, 100); + add_effect_200(&mut p, &mut top, "ec.channel.blend", &[("blendWithLayer", Value::Layer(Some(pre.id.0)))]); + let c = p.comp_mut(cid).unwrap(); + c.layers.push(top); + c.layers.push(pre); + let frame = |nested_switches: bool, cache: Option<&crate::LayerCache>| { + let mut r = crate::Renderer::new(&p, &crate::NoFootage, crate::RenderOpts { nested_switches, ..Default::default() }); + r.cache = cache; + r.comp_frame(cid, Tick::ZERO).data + }; + let (on, off) = (frame(true, None), frame(false, None)); + assert!(on != off, "the precomp layer's Draft quality passes down"); + let cache = crate::LayerCache::default(); + assert!(frame(true, Some(&cache)) == on); + assert!(frame(false, Some(&cache)) == off, "not the buffer made with switches affecting nested comps"); + assert!(frame(true, Some(&cache)) == on, "and back"); +} + /// Records whether the GPU compositor was asked to draw a frame. struct ProbeAccel(std::sync::atomic::AtomicBool); impl crate::Accelerator for ProbeAccel { diff --git a/crates/render/src/tests/collapse.rs b/crates/render/src/tests/collapse.rs index 30d2163c1..4104e0b38 100644 --- a/crates/render/src/tests/collapse.rs +++ b/crates/render/src/tests/collapse.rs @@ -161,8 +161,17 @@ fn referenced_layer_overrides_change_the_owner_cache_key() { let opacity = comp.layer(aid).unwrap().props.prop("transform/opacity").unwrap().uid; let key = |value: f64| { let overrides = [crate::PropertyOverride { layer: aid, prop: opacity, value: Value::Scalar(value), font: false }]; - let ctx = - EvalCtx { project: &p, comp_id: cid, comp, time: Tick::ZERO, expr: None, footage: None, property_overrides: &overrides, media_overrides: &[] }; + let ctx = EvalCtx { + project: &p, + comp_id: cid, + comp, + time: Tick::ZERO, + expr: None, + footage: None, + property_overrides: &overrides, + media_overrides: &[], + reads: None, + }; crate::cache::layer_key(&ctx, b, 1.0, false, false) }; let (opaque, half) = (key(100.0), key(50.0)); diff --git a/crates/render/src/tests/mask_blur.rs b/crates/render/src/tests/mask_blur.rs index 07bc1e95f..5f3ff4e2a 100644 --- a/crates/render/src/tests/mask_blur.rs +++ b/crates/render/src/tests/mask_blur.rs @@ -75,3 +75,32 @@ fn mask_motion_blur_follows_the_render_and_the_comp() { let (p, cid) = project(false); assert!(alpha_at_25(&p, cid, true) < 0.01, "the comp's switch off"); } + +/// Whether mask motion blur may run at all (the render options, Switches Affect Nested Comps with +/// a precomp layer's switch off) is part of the layer cache key, also for a layer whose own +/// switch is off: a buffer made with the gate open must not serve a render with it closed. +#[test] +fn the_mask_motion_blur_gate_keys_the_layer_cache() { + let (mut p, inner) = project(true); + let mut outer = Comp::new(100, 100, FrameRate::FPS_30, Tick::from_seconds_f64(1.0)); + outer.enable_motion_blur = true; + let mut pre = build::layer(&mut p, &outer, "Inner", LayerSource::Comp { item: inner }, (100, 100), None); + pre.switches.motion_blur = false; + outer.layers.push(pre); + let oid = p.add_item("Outer", Label::Sandstone, None, ItemKind::Comp(outer.into())); + let half = Tick::from_seconds_f64(0.5 / 30.0); + let cache = crate::LayerCache::default(); + let render = |cid: ItemId, opts: RenderOpts, cached: bool| { + let mut r = Renderer::new(&p, &NoFootage, opts); + r.cache = cached.then_some(&cache); + r.comp_frame(cid, half).data + }; + let on = RenderOpts { motion_blur: true, nested_switches: true, ..Default::default() }; + let off = RenderOpts { nested_switches: false, ..on }; + assert!(render(oid, on, false) != render(oid, off, false), "the precomp layer's switch closes the gate"); + assert!(render(oid, off, true) == render(oid, off, false)); + assert!(render(oid, on, true) == render(oid, on, false), "not the buffer blurred with the gate open"); + let still = RenderOpts { motion_blur: false, ..on }; + assert!(render(inner, on, true) == render(inner, on, false)); + assert!(render(inner, still, true) == render(inner, still, false), "Render Settings ▸ Motion Blur off"); +} diff --git a/crates/render/src/tests/styles.rs b/crates/render/src/tests/styles.rs index 2450fcf64..a9de6fb52 100644 --- a/crates/render/src/tests/styles.rs +++ b/crates/render/src/tests/styles.rs @@ -507,3 +507,34 @@ fn workers_styling_a_layer_at_once_share_its_buffers() { assert!(st.passes.iter().zip(&first.passes).all(|(a, b)| std::sync::Arc::ptr_eq(&a.0, &b.0)), "one set of passes"); } } + +/// A styled layer served from the cache lists the files of the body and passes it was served, +/// not only its content's (#3184): one made of other files (another worker's, or from disk, +/// whose list can't vouch for them) passes that on to the buffers made of it (flattened, in the +/// blending space), which are then not kept on disk as complete. +#[test] +fn a_cached_styled_layer_lists_the_files_of_its_cached_buffers() { + let (p, cid) = scene([1.0; 3], None, |p, c, l| add(p, c, l, "dropShadow")); + let layer = &p.comp(cid).unwrap().layers[0]; + let styled = |cache: &crate::LayerCache| { + let mut r = Renderer::new(&p, &NoFootage, RenderOpts::default()); + r.cache = Some(cache); + let ctx = r.eval_ctx(cid, Tick::ZERO).unwrap(); + r.styled_layer(&ctx, layer).unwrap() + }; + let first = styled(&crate::LayerCache::default()); + assert!(first.files.is_complete() && !first.passes.is_empty()); + let key = first.key.unwrap(); + // Body and passes kept with a list that can't vouch for them; the content renders again. + let cache = crate::LayerCache::default(); + let mut unsure = crate::reads::ReadFiles::default(); + unsure.mark_incomplete(); + let unsure = std::sync::Arc::new(unsure); + cache.insert(key, first.body.clone(), unsure.clone()); + for (i, (b, _)) in first.passes.iter().enumerate() { + cache.insert(crate::cache::derive(key, i as u64 + 1), b.clone(), unsure.clone()); + } + let hit = styled(&cache); + assert!(std::sync::Arc::ptr_eq(&hit.body, &first.body), "the cached body"); + assert!(!hit.files.is_complete(), "{:?}", hit.files); +} diff --git a/crates/render/src/tests/time.rs b/crates/render/src/tests/time.rs index e9599f70b..715c37ef0 100644 --- a/crates/render/src/tests/time.rs +++ b/crates/render/src/tests/time.rs @@ -143,6 +143,7 @@ fn input_keys_ignore_later_effects() { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let l = &comp.layers[0]; (crate::cache::input_key(&ctx, l, 1.0, false, false, 1), crate::cache::input_key(&ctx, l, 1.0, false, false, 2)) diff --git a/crates/render/src/text.rs b/crates/render/src/text.rs index 683da82ee..ed369afa5 100644 --- a/crates/render/src/text.rs +++ b/crates/render/src/text.rs @@ -243,6 +243,13 @@ pub fn animator_selection(ctx: &EvalCtx, layer: &Layer, anim: &PropGroup, lay: & } "expressionSelector" => { let Some(prop) = sel.get("amount") else { continue }; + // Evaluated per character (`textIndex`): the layer's cache key holds the amount + // for the first character only, so the buffer must not outlive the session. + if prop.has_expression() + && let Some(log) = ctx.reads + { + log.mark_unkeyed(); + } let stat = ctx.v3(layer, sel, "amount", [100.0; 3]); Box::new(move |i, n, prev| { let pv = prev.map(|x| x * 100.0); @@ -638,11 +645,73 @@ fn align_index(j: Justify) -> u8 { } } +/// Note the font files `lay` is drawn with in [`EvalCtx::reads`] (#3184), each with its identity +/// as its bytes were read, so a cache entry of the text is checked against them. What the +/// files can't vouch for makes the list incomplete: a family that is not installed (installing +/// it changes the text), a character drawn with a fallback face or with none (another installed +/// font could take it), a font from memory. +fn note_fonts(ctx: &EvalCtx, lay: &TextLayout) { + note_layout_fonts(ctx, &lay.styles, &lay.layout); +} + +/// A character put in by Character Offset or Character Value (`ch`, in style `st`), outside a +/// relayout: its outline and advance, with the font it is drawn with noted as [`note_fonts`] does +/// (the run's face may not have it: a fallback face then draws it). +fn substituted_glyph(ctx: &EvalCtx, st: &effectcraft_keyframe::CharStyle, ch: char) -> (BezPath, f64) { + if ctx.reads.is_some() { + // (the layout `char_glyph_style` makes, served from the layout cache there) + let lay = effectcraft_text::layout_text(&ch.to_string(), &effectcraft_text::text_style(st), &effectcraft_text::ParagraphStyle::default()); + note_layout_fonts(ctx, std::slice::from_ref(st), &lay); + } + char_glyph_style(st, ch) +} + +/// [`note_fonts`] for `layout`, whose glyphs' runs index `styles`. +fn note_layout_fonts(ctx: &EvalCtx, styles: &[effectcraft_keyframe::CharStyle], layout: &effectcraft_text::Layout) { + use crate::reads::{FileStamp, ReadFile}; + use effectcraft_text::fonts; + let Some(log) = ctx.reads else { return }; + let resolved: Vec = styles.iter().map(|s| fonts::resolve(&s.font, &s.style)).collect(); + if resolved.iter().any(|r| r.missing) { + log.mark_incomplete(); + } + // Each run's face, glyphs or not: an empty paragraph's face sets its line's metrics (in a + // box, the first baseline that places every later line). + let mut faces: Vec = Vec::new(); + for r in &resolved { + if !faces.contains(&r.face) { + faces.push(r.face); + } + } + for g in &layout.glyphs { + if g.id == 0 || resolved.get(g.run).is_none_or(|r| r.face != g.face) { + log.mark_incomplete(); + } + if !faces.contains(&g.face) { + faces.push(g.face); + } + } + for id in faces { + let face = fonts::face(id); + match &face.info.data { + fonts::FaceData::Static(_) => {} + fonts::FaceData::Shared(_) => log.mark_incomplete(), + fonts::FaceData::File(_) => { + if let Some((path, meta)) = face.file_read() { + let stamp = meta.map_or(FileStamp::Missing, FileStamp::of_metadata); + log.note(ReadFile::new(path.to_string_lossy().as_ref(), stamp)); + } + } + } + } +} + /// Lay out and animate a text layer. pub fn text_geom(ctx: &EvalCtx, layer: &Layer) -> Option { let doc = source_text(ctx, layer)?; let text = layer.props.sub("text")?; let lay = layout_doc(&doc); + note_fonts(ctx, &lay); let xfs = char_transforms(ctx, layer, text, &lay); let three = per_char_3d(ctx, layer); let more = text.sub("moreOptions"); @@ -665,6 +734,7 @@ pub fn text_geom(ctx: &EvalCtx, layer: &Layer) -> Option { // Same character count: the style runs still line up. let d2 = TextDoc { text: chars.into_iter().collect(), ..doc.clone() }; let l2 = layout_doc(&d2); + note_fonts(ctx, &l2); let by_char: std::collections::HashMap = lay.glyphs.iter().zip(&xfs).map(|(g, x)| (g.char_index, *x)).collect(); let x2: Vec = l2.glyphs.iter().map(|g| by_char.get(&g.char_index).copied().unwrap_or_default()).collect(); subs = vec![None; l2.glyphs.len()]; @@ -789,7 +859,7 @@ pub fn text_geom(ctx: &EvalCtx, layer: &Layer) -> Option { // Outline (substituted characters aligned in the original slot). let (outline, adv) = match subs[gi] { Some(c) => { - let (p, a) = char_glyph_style(st, c); + let (p, a) = substituted_glyph(ctx, st, c); let dx = match x.char_align { 0 => 0.0, 2 => g.advance - a, diff --git a/crates/render/src/text/tests.rs b/crates/render/src/text/tests.rs index 0280115a5..9b52d3098 100644 --- a/crates/render/src/text/tests.rs +++ b/crates/render/src/text/tests.rs @@ -715,3 +715,90 @@ fn range_bar_drag_values() { assert_eq!(range_value_of(3.6 / 7.0, 0.0, true, 7), 4.0); assert_eq!(range_value_of(3.6 / 7.0, 2.0 / 7.0, true, 7), 2.0, "less a 2-character Offset"); } + +/// Text names the font files it is drawn with (#3184), with their identity as they were read, so +/// a cache entry of it is checked against them; what the files can't vouch for (a family that +/// isn't installed) leaves the list incomplete. +#[test] +fn text_notes_the_font_files_it_draws_with() { + use crate::reads::{FileStamp, ReadLog}; + use effectcraft_text::fonts::{self, FaceData, FaceInfo, FontSource}; + struct OneFile(std::path::PathBuf); + impl FontSource for OneFile { + fn faces(&self) -> Vec { + vec![FaceInfo { + family: "Reads Test Sans".into(), + style: "Regular".into(), + weight: 400, + italic: false, + index: 0, + data: FaceData::File(self.0.clone()), + origin: "system", + native_family: None, + full_name: "Reads Test Sans Regular".into(), + postscript: None, + variable: false, + instances: vec![], + }] + } + } + // (a fresh directory, removed when the test ends, panicking or not) + let dir = tempfile::tempdir().unwrap(); + let font = dir.path().join("reads-test-sans.ttf"); + std::fs::write(&font, fonts::INTER_REGULAR).unwrap(); + fonts::add_source(&OneFile(font.clone())); + let stamp = FileStamp::native(&font.to_string_lossy()).unwrap(); + // (`value`: a Character Value animator puts that character in for every one) + let files_with = |family: &str, value: Option| { + let (mut p, cid, comp) = setup(200, 80); + let mut l = + text_layer(&mut p, &comp, TextDoc { text: "Hi there\rtwo".into(), font: family.into(), style: "Regular".into(), size: 30.0, ..Default::default() }); + if let Some(c) = value { + animator(&mut p, &mut l, &["characterValue"], &["range"]); + set(&mut l, "text/animators/#1/properties/characterValue", Value::Scalar(c as u32 as f64)); + } + p.comp_mut(cid).unwrap().layers.push(l); + let log = ReadLog::new(); + let c = EvalCtx { reads: Some(&log), ..ctx(&p, cid, 0.0) }; + assert!(text_geom(&c, &p.comp(cid).unwrap().layers[0]).is_some()); + log.into_files() + }; + let files_of = |family: &str| files_with(family, None); + let files = files_of("Reads Test Sans"); + assert!(files.is_complete(), "{files:?}"); + assert_eq!(files.files().len(), 1, "{files:?}"); + assert_eq!(files.get(&font.to_string_lossy()), Some(stamp)); + // The bundled family reads no file. + let files = files_of(effectcraft_text::fonts::DEFAULT_FAMILY); + assert!(files.is_complete() && files.is_empty(), "{files:?}"); + // A family that isn't installed falls back: installing it would change the text. + assert!(!files_of("No Such Family 3184").is_complete()); + // A substituted character the face has is drawn with it: the same one file. + let files = files_with("Reads Test Sans", Some('B')); + assert!(files.is_complete(), "{files:?}"); + assert_eq!(files.get(&font.to_string_lossy()), Some(stamp)); + // One it lacks (Inter has no CJK) is drawn with a fallback face, or none: another installed + // font could take it, so the list can't vouch for the text. + assert!(!files_with("Reads Test Sans", Some('\u{4e2d}')).is_complete()); + // An empty first paragraph in the face draws no glyph, but in a box its face sets the first + // baseline that places the lines after it: the file is read all the same. + let (mut p, cid, comp) = setup(200, 80); + let base = TextDoc { + text: "\rHi".into(), + font: fonts::DEFAULT_FAMILY.into(), + style: "Regular".into(), + size: 30.0, + box_size: Some([180.0, 60.0]), + ..Default::default() + }; + let first = effectcraft_keyframe::CharStyle { font: "Reads Test Sans".into(), ..base.base_style() }; + let runs = vec![effectcraft_keyframe::StyleRun { len: 1, style: first }, effectcraft_keyframe::StyleRun { len: 2, style: base.base_style() }]; + let l = text_layer(&mut p, &comp, TextDoc { runs, ..base }); + p.comp_mut(cid).unwrap().layers.push(l); + let log = ReadLog::new(); + let c = EvalCtx { reads: Some(&log), ..ctx(&p, cid, 0.0) }; + assert!(text_geom(&c, &p.comp(cid).unwrap().layers[0]).is_some()); + let files = log.into_files(); + assert!(files.is_complete(), "{files:?}"); + assert_eq!(files.get(&font.to_string_lossy()), Some(stamp), "{files:?}"); +} diff --git a/crates/render/src/three_d/adv/scene.rs b/crates/render/src/three_d/adv/scene.rs index 22507069e..6d2b071d5 100644 --- a/crates/render/src/three_d/adv/scene.rs +++ b/crates/render/src/three_d/adv/scene.rs @@ -477,6 +477,7 @@ fn clip_start(ctx: &EvalCtx, layer: &Layer, prop: &Property, lt: Tick) -> Tick { start } +/// Adds a model layer to the Advanced 3D scene with its material options, opacity and world transform. fn model_layer(r: &Renderer, ctx: &EvalCtx, layer: &Layer, b: &mut Builder) { let lin = b.s.linear_io; let (opts, prim_mat) = model_options(ctx, layer, lin); @@ -487,7 +488,7 @@ fn model_layer(r: &Renderer, ctx: &EvalCtx, layer: &Layer, b: &mut Builder) { LayerSource::Model { item } => { let Some(it) = r.project.item(*item) else { return }; let ItemKind::Footage(f) = &it.kind else { return }; - let Some(m) = r.footage.model(*item, f) else { return }; + let Some(m) = r.read(|| r.footage.model(*item, f)) else { return }; let unit = geo.map_or(1.0, |g| ctx.f(layer, g, "unitScale", 1.0)); let clip = geo.map_or(0, |g| ctx.e(layer, g, "animation")) as usize; let clip = clip.checked_sub(1).filter(|c| *c < m.animations.len()); @@ -651,12 +652,13 @@ pub fn extruded_meshes(ctx: &EvalCtx, layer: &Layer, p: &model::extrude::Extrude out } +/// Adds an extruded layer to the Advanced 3D scene with its card material, opacity and world transform. fn extruded_layer(r: &Renderer, ctx: &EvalCtx, layer: &Layer, p: &model::extrude::ExtrudeParams, b: &mut Builder) { let base = card_material(ctx, layer); let opacity = (ctx.opacity(layer) as f32 * r.opacity_mul()).clamp(0.0, 1.0); let world = b.outer * ctx.world_matrix(layer); let lin = b.s.linear_io; - for (mesh, c, local) in extruded_meshes(ctx, layer, p) { + for (mesh, c, local) in extruded_meshes(&r.with_reads(ctx), layer, p) { let l = |v: f32| if lin { v } else { srgb_to_linear(v) }; let m = b.material(Material { base: [l(c[0]), l(c[1]), l(c[2]), c[3]], @@ -694,13 +696,14 @@ fn card(b: &mut Builder, buf: &Buf, world: Mat4, mut mat: Material) { b.emit(&p, m, &|_| world); } +/// Adds a flat card layer to the Advanced 3D scene with its material, opacity and world transform. fn card_layer(r: &Renderer, ctx: &EvalCtx, layer: &Layer, b: &mut Builder) { let mut mat = card_material(ctx, layer); mat.opacity = (ctx.opacity(layer) as f32 * r.opacity_mul()).clamp(0.0, 1.0); let world = b.outer * ctx.world_matrix(layer); if crate::text::per_char_3d(ctx, layer) { - for (buf, m) in crate::text::per_char_planes(ctx, layer, r.opts.scale) { - let buf = r.to_blend(Arc::new(buf), None); + for (buf, m) in crate::text::per_char_planes(&r.with_reads(ctx), layer, r.opts.scale) { + let buf = r.to_blend(Arc::new(buf), None, &Arc::default()); card(b, &buf, world * m, mat); } return; diff --git a/crates/render/src/three_d/adv/tests.rs b/crates/render/src/three_d/adv/tests.rs index b2612de98..88e805882 100644 --- a/crates/render/src/three_d/adv/tests.rs +++ b/crates/render/src/three_d/adv/tests.rs @@ -822,6 +822,7 @@ fn extruded_text_renders_as_a_mesh() { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let l = &ctx.comp.layers[0]; let params = scene::extrusion_params(&ctx, l).unwrap(); @@ -870,6 +871,7 @@ fn shape_surface_items_colour_the_extruded_surfaces() { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let l = &ctx.comp.layers[0]; let params = scene::extrusion_params(&ctx, l).unwrap(); @@ -915,6 +917,7 @@ fn text_animators_colour_the_extruded_surfaces() { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let l = &ctx.comp.layers[0]; let params = scene::extrusion_params(&ctx, l).unwrap(); @@ -1122,6 +1125,7 @@ fn extruded_strokes_render_as_bevelled_meshes() { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let l = &ctx.comp.layers[0]; let params = scene::extrusion_params(&ctx, l).unwrap(); diff --git a/crates/render/src/three_d/compose.rs b/crates/render/src/three_d/compose.rs index a5a7c170e..ff08eb05f 100644 --- a/crates/render/src/three_d/compose.rs +++ b/crates/render/src/three_d/compose.rs @@ -203,9 +203,11 @@ pub(crate) fn prepare<'a>(r: &Renderer, ctx: &EvalCtx<'_>, layer: &'a Layer, ord /// Prepare a layer as planes: one per character for per-character 3D text, else one. pub(crate) fn prepare_all<'a>(r: &Renderer, ctx: &EvalCtx<'_>, layer: &'a Layer, order: usize, out: (u32, u32), in_run: bool) -> Vec> { if crate::text::per_char_3d(ctx, layer) { - return crate::text::per_char_planes(ctx, layer, r.opts.scale) + return crate::text::per_char_planes(&r.with_reads(ctx), layer, r.opts.scale) .into_iter() - .filter_map(|(buf, m)| prepare_with(r, ctx, layer, order, out, in_run, PlaneInput { buf: r.to_blend(Arc::new(buf), None), local: m })) + .filter_map(|(buf, m)| { + prepare_with(r, ctx, layer, order, out, in_run, PlaneInput { buf: r.to_blend(Arc::new(buf), None, &Arc::default()), local: m }) + }) .collect(); } prepare(r, ctx, layer, order, out, in_run).into_iter().collect() diff --git a/crates/script/src/tests/ui_more.rs b/crates/script/src/tests/ui_more.rs index 483d686ef..c15aee0ae 100644 --- a/crates/script/src/tests/ui_more.rs +++ b/crates/script/src/tests/ui_more.rs @@ -231,6 +231,7 @@ fn position_now(s: &Session, layer: u64) -> [f64; 2] { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let v = ctx.value(l, l.props.prop("transform/position").unwrap()).components(); [v[0], v[1]] diff --git a/crates/text/src/fonts.rs b/crates/text/src/fonts.rs index 5388629cf..d199bf0ff 100644 --- a/crates/text/src/fonts.rs +++ b/crates/text/src/fonts.rs @@ -158,11 +158,24 @@ fn info_from(n: FaceNames, data: FaceData, origin: &'static str) -> FaceInfo { } } +/// A font file's bytes and its metadata from the same open file (so the metadata describes the +/// bytes, not a later version of the file). +fn read_with_metadata(path: &std::path::Path) -> std::io::Result<(Vec, std::fs::Metadata)> { + use std::io::Read; + let mut f = std::fs::File::open(path)?; + let meta = f.metadata()?; + let mut bytes = Vec::new(); + f.read_to_end(&mut bytes)?; + Ok((bytes, meta)) +} + /// A loaded (or loadable) face. pub struct Face { pub id: FaceId, pub info: FaceInfo, bytes: OnceLock>, + /// The file's metadata as its bytes were read (a [`FaceData::File`] face, once loaded). + file_meta: OnceLock, shaper: OnceLock, } @@ -195,16 +208,29 @@ pub struct VMetrics { } impl Face { + /// The font file bytes, loaded once on first use, or `None` when they cannot be read. fn bytes(&self) -> Option<&[u8]> { self.bytes .get_or_init(|| match &self.info.data { FaceData::Static(b) => Some(FaceBytes::Static(b)), FaceData::Shared(b) => Some(FaceBytes::Shared(b.clone())), - FaceData::File(p) => std::fs::read(p).ok().map(|v| FaceBytes::Shared(Arc::new(v))), + FaceData::File(p) => { + let (bytes, meta) = read_with_metadata(p).ok()?; + let _ = self.file_meta.set(meta); + Some(FaceBytes::Shared(Arc::new(bytes))) + } }) .as_ref() .map(FaceBytes::get) } + /// The file a [`FaceData::File`] face is drawn from, with its metadata as its bytes were read + /// (`None` when it could not be read): what text drawn with the face was made of. Loads the + /// face. `None` for bundled faces and faces from memory. + pub fn file_read(&self) -> Option<(&std::path::Path, Option<&std::fs::Metadata>)> { + let FaceData::File(p) = &self.info.data else { return None }; + let _ = self.bytes(); + Some((p, self.file_meta.get())) + } /// The parsed font (None if the file is missing or unreadable). pub fn font(&self) -> Option> { FontRef::from_index(self.bytes()?, self.info.index).ok() @@ -314,7 +340,7 @@ fn bundled_default_face() -> Arc { variable: false, instances: Vec::new(), }); - Arc::new(Face { id: 0, info, bytes: OnceLock::new(), shaper: OnceLock::new() }) + Arc::new(Face { id: 0, info, bytes: OnceLock::new(), file_meta: OnceLock::new(), shaper: OnceLock::new() }) } fn db() -> &'static RwLock { @@ -331,9 +357,10 @@ fn db() -> &'static RwLock { }) } +/// Adds a face to the database and returns its id. fn push(db: &mut Db, info: FaceInfo) -> FaceId { let id = db.faces.len(); - db.faces.push(Arc::new(Face { id, info, bytes: OnceLock::new(), shaper: OnceLock::new() })); + db.faces.push(Arc::new(Face { id, info, bytes: OnceLock::new(), file_meta: OnceLock::new(), shaper: OnceLock::new() })); id } diff --git a/crates/ui-egui/src/app/frame.rs b/crates/ui-egui/src/app/frame.rs index e77f07840..8ebea08fc 100644 --- a/crates/ui-egui/src/app/frame.rs +++ b/crates/ui-egui/src/app/frame.rs @@ -170,10 +170,6 @@ impl EffectcraftApp { self.session.poll_jobs(); ctx.request_repaint_after(std::time::Duration::from_millis(100)); } - // The disk cache's footage salt, taken off the UI thread after footage changed. - if self.session.poll_disk_salt() { - ctx.request_repaint_after(std::time::Duration::from_millis(100)); - } // Analyses running in a worker (the web app). if !self.session.offloaded.is_empty() { self.session.poll_offload(); diff --git a/crates/ui-egui/src/frames.rs b/crates/ui-egui/src/frames.rs index 001790116..968b2d791 100644 --- a/crates/ui-egui/src/frames.rs +++ b/crates/ui-egui/src/frames.rs @@ -15,9 +15,12 @@ //! egui frames, within a time budget. //! //! With the disk cache on (Settings ▸ Media & Disk Cache), every CPU-rendered frame is also -//! written to disk under a content key (the comp's content hash, frame, scale, view and render -//! options), and a job first looks there: frames survive restarts and project reopenings. The -//! timeline shows disk-only frames as a blue cache bar. +//! written to disk under a content key (the comp's content hash from the project in memory, +//! frame, scale, view and render options) with the source files it read, and a job first looks +//! there: frames survive restarts and project reopenings. An entry is used only while the files +//! it lists are unchanged, checked by the frame worker when it reads the entry (a frame whose +//! files can't all be named is shown but not stored). The timeline shows disk-only frames as a +//! blue cache bar (present entries; their files are checked only when a frame is used). //! //! With Mercury GPU Acceleration (a [`Gpu`] on egui-wgpu's device and the project's renderer set //! to the GPU) frames stay on the GPU: the compositor writes an RGBA8 texture that the viewer @@ -29,11 +32,12 @@ //! cache keeps them as half-float entries. use std::collections::{BTreeSet, HashMap, HashSet, VecDeque}; -use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; +use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; -use effectcraft_engine::project::{Comp, Heard, ItemId, ItemKind, LayerSource, Node, Project, PropGroup}; +use effectcraft_engine::project::{Comp, Heard, ItemId, ItemKind, Node, Project, PropGroup}; use effectcraft_engine::render::disk_cache::{self, DiskCache}; +use effectcraft_engine::render::reads::{ReadFiles, ReadLog}; use effectcraft_engine::render::{CancellableFootage, ExprHost, FootageSource, LayerCache, RenderOpts, Renderer}; use effectcraft_engine::time::Tick; use effectcraft_gpu::{DisplayFrame, FrameError, Gpu}; @@ -156,8 +160,41 @@ impl Playhead { } } +/// A frame in the RAM preview and the source files it was made of (`None`: unknown, a frame +/// rendered elsewhere or kept on the GPU), so it can be written to the disk cache later +/// ([`Frames::persist_missing`]). +struct Cached { + img: FrameImage, + /// (the browser's frames are stored by its frame workers, not from here) + #[cfg_attr(target_arch = "wasm32", allow(dead_code))] + files: Option>, + /// The disk cache its render started with and that cache's drop generation then: the frame + /// is written to that cache only, and only while none of its files was dropped since + /// (`None`: rendered without a disk cache, or elsewhere; never written from here). + #[cfg_attr(target_arch = "wasm32", allow(dead_code))] + since: Option, +} + +/// A disk cache and its drop generation ([`DiskCache::drop_generation`]) when a render started. +#[derive(Clone)] +struct DiskSince(std::sync::Weak, u64); + +impl DiskSince { + /// A marker for the drop generation of `dc` at the time of a render. + fn of(dc: &Arc, generation: u64) -> DiskSince { + DiskSince(Arc::downgrade(dc), generation) + } + + /// The generation, when `dc` is the cache it was taken from (the weak reference keeps that + /// cache's address from being reused by another). + #[cfg_attr(target_arch = "wasm32", allow(dead_code))] + fn for_cache(&self, dc: &Arc) -> Option { + std::ptr::eq(self.0.as_ptr(), Arc::as_ptr(dc)).then_some(self.1) + } +} + struct Cache { - map: HashMap, + map: HashMap, order: VecDeque, bytes: usize, /// Bytes of GPU frames (also counted in `bytes`). @@ -174,10 +211,17 @@ struct Cache { } impl Cache { + /// A frame without its source files (tests). + #[cfg(test)] fn insert(&mut self, k: FrameKey, img: FrameImage) { + self.insert_with(k, img, None, None); + } + /// [`Cache::insert`] with the source files the frame was made of and the disk cache's drop + /// generation when its render started. + fn insert_with(&mut self, k: FrameKey, img: FrameImage, files: Option>, since: Option) { let (sz, gpu) = (img.bytes(), img.is_gpu()); - if let Some(old) = self.map.insert(k, img) { - self.forget(&old); + if let Some(old) = self.map.insert(k, Cached { img, files, since }) { + self.forget(&old.img); } else { self.order.push_back(k); } @@ -215,7 +259,7 @@ impl Cache { /// than the one on screen first (a zoom or resolution change). fn evict_gpu(&mut self) { while self.gpu_bytes > self.gpu_budget { - let is_gpu = |k: &FrameKey| self.map.get(k).is_some_and(FrameImage::is_gpu); + let is_gpu = |k: &FrameKey| self.map.get(k).is_some_and(|c| c.img.is_gpu()); let other_scale = self.order.iter().position(|k| Some(k.scale) != self.scale && is_gpu(k)); let Some(i) = other_scale.or_else(|| self.order.iter().position(is_gpu)) else { break }; if let Some(old) = self.order.remove(i) { @@ -251,9 +295,10 @@ impl Cache { self.gpu_bytes = self.gpu_bytes.saturating_sub(img.bytes()); } } + /// Removes the entry for `k` and releases its image. fn remove(&mut self, k: &FrameKey) { if let Some(i) = self.map.remove(k) { - self.forget(&i); + self.forget(&i.img); } } /// Shown again: last in line for eviction. @@ -316,10 +361,10 @@ pub struct RenderSource { /// ([`Frames::identity`]). type Identity = (u64, Option>); -/// Content keys of (project revision, comp, virtual-file generation). The generation is one -/// counter bumped when a browser file is replaced, so a lookup stays a map read. Hashing the -/// new bytes happens only when that generation misses. -type ContentKeys = Arc>>; +/// Disk-cache content keys ([`disk_cache::comp_content_key`]) of (project revision, comp). They +/// come from the project in memory alone: the files a frame read are checked by its entry +/// when it is read (#3184). +type ContentKeys = Arc>>; #[cfg(not(target_arch = "wasm32"))] #[derive(Default)] @@ -328,16 +373,17 @@ struct ContentKeyJobs { pending: VecDeque<(Arc, u64, u64)>, } -fn content_key(keys: &ContentKeys, project: &Project, revision: u64, comp: u64, epoch: u64, virtual_id: Option>) -> u128 { - if let Some(k) = keys.lock().ok().and_then(|m| m.get(&(revision, comp, epoch)).copied()) { +/// The content key of `comp` at `revision`, memoised per revision. +fn content_key(keys: &ContentKeys, project: &Project, revision: u64, comp: u64) -> u128 { + if let Some(k) = keys.lock().ok().and_then(|m| m.get(&(revision, comp)).copied()) { return k; } - let k = disk_cache::comp_content_key_with(project, ItemId(comp), virtual_id); + let k = disk_cache::comp_content_key(project, ItemId(comp)); if let Ok(mut m) = keys.lock() { if m.len() > 256 { m.clear(); } - m.insert((revision, comp, epoch), k); + m.insert((revision, comp), k); } k } @@ -388,7 +434,8 @@ fn comp_content_with<'a>( let Some(ItemKind::Comp(c)) = item(id).map(|i| &i.kind) else { continue }; let c = version(id, c); for l in &c.layers { - if let LayerSource::Comp { item } | LayerSource::Footage { item } | LayerSource::Solid { item } = l.source { + // (a 3D model's item too) + if let Some(item) = l.source.item() { stack.push(item); } expressions = expressions || (everything && has_expression(&l.props)); @@ -423,18 +470,30 @@ pub fn opts_hash(o: &RenderOpts) -> u64 { } /// Disk key of a viewer frame (render options included: region of interest, draft…). -fn frame_disk_key( - keys: &ContentKeys, - project: &Project, - key: &FrameKey, - opts_hash: u64, - epoch: u64, - virtual_id: Option>, -) -> u128 { - let content = content_key(keys, project, key.revision, key.comp, epoch, virtual_id); +fn frame_disk_key(keys: &ContentKeys, project: &Project, key: &FrameKey, opts_hash: u64) -> u128 { + let content = content_key(keys, project, key.revision, key.comp); disk_cache::frame_key(content, key.frame, key.scale, key.view ^ opts_hash) } +/// Queue `img` for the disk cache under `dk` with the source files it was made of. `false` when +/// refused: a GPU frame (no CPU pixels), files that can't be checked when the entry is read +/// (an incomplete list, #3184: the frame is shown, not stored), a full queue, a file dropped +/// (File ▸ Reload Footage) after `since`, the drop generation its render started at; no room on +/// the disk (checked first: the conversion and compression would be wasted). +fn put_disk_frame(dc: &DiskCache, dk: u128, img: &FrameImage, files: &ReadFiles, virtual_id: Option>, since: u64) -> bool { + if !files.is_complete() || !dc.accepts_writes() { + return false; + } + match img { + FrameImage::Cpu(img) => { + let rgba: Vec = img.pixels.iter().flat_map(|c| c.to_array()).collect(); + dc.put_frame(dk, img.size[0] as u32, img.size[1] as u32, &rgba, files, virtual_id, since) + } + FrameImage::CpuF16(f) => dc.put_frame_f16(dk, f.width, f.height, f.bits(), files, virtual_id, since), + FrameImage::Gpu(_) => false, + } +} + /// A frame for a [`RemoteFrames`] renderer. pub struct RemoteJob { pub project: Arc, @@ -512,9 +571,8 @@ pub struct Frames { /// Render time of the last viewer (urgent) frame in ms, for the Info panel / perf readout. pub last_ms: Arc>, content_keys: ContentKeys, - /// Bumped when a virtual file is replaced. Lookups key on it instead of statting footage. - virtual_epoch: Arc, - /// Size and content hash for paths with no native metadata. Called only on a cache miss. + /// Size and content hash for paths with no native metadata (the browser's file table): to + /// store and check the files of disk entries. virtual_id: Option Option<(u64, u64)> + Send + Sync>>, #[cfg(not(target_arch = "wasm32"))] content_key_jobs: Arc>, @@ -602,7 +660,6 @@ impl Default for Frames { ctx: None, last_ms: Arc::new(Mutex::new(0.0)), content_keys: Arc::default(), - virtual_epoch: Arc::new(AtomicU64::new(0)), virtual_id: None, #[cfg(not(target_arch = "wasm32"))] content_key_jobs: Arc::default(), @@ -754,7 +811,7 @@ impl Frames { pub fn retire_gpu(&self) { self.gpu_retired.store(true, Ordering::Release); if let Ok(mut cache) = self.cache.lock() { - let keys: Vec<_> = cache.map.iter().filter_map(|(key, image)| image.is_gpu().then_some(*key)).collect(); + let keys: Vec<_> = cache.map.iter().filter_map(|(key, c)| c.img.is_gpu().then_some(*key)).collect(); for key in keys { cache.remove(&key); } @@ -789,7 +846,7 @@ impl Frames { /// The cached frame, which becomes the most recently used. pub fn get(&self, k: &FrameKey) -> Option { let mut c = self.cache.lock().ok()?; - let img = c.map.get(k).cloned()?; + let img = c.map.get(k).map(|c| c.img.clone())?; c.touch(k); Some(img) } @@ -825,7 +882,7 @@ impl Frames { }) .max_by_key(|k| k.revision) .copied()?; - let img = c.map.get(&newest).cloned()?; + let img = c.map.get(&newest).map(|c| c.img.clone())?; c.touch(&newest); Some((newest, img)) } @@ -968,7 +1025,6 @@ impl Frames { if src.disk.is_none() && remote.is_none() { return vec![]; } - let epoch = self.virtual_epoch.load(Ordering::Relaxed); #[cfg(not(target_arch = "wasm32"))] { self.note_disk_series(base.comp, base.scale, base.view ^ opts_hash(opts)); @@ -976,7 +1032,7 @@ impl Frames { } #[cfg(not(target_arch = "wasm32"))] let content = { - let known = self.content_keys.lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(&(base.revision, base.comp, epoch)).copied(); + let known = self.content_keys.lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(&(base.revision, base.comp)).copied(); let Some(content) = known else { self.request_content_key(src.project.clone(), base.revision, base.comp); return vec![]; @@ -984,7 +1040,7 @@ impl Frames { content }; #[cfg(target_arch = "wasm32")] - let content = content_key(&self.content_keys, &src.project, base.revision, base.comp, epoch, self.virtual_id.as_deref()); + let content = content_key(&self.content_keys, &src.project, base.revision, base.comp); let ram: HashSet = self.cached_frames(base).into_iter().collect(); let oh = opts_hash(opts); (start..end).filter(|f| !ram.contains(f)).filter(|f| contains(disk_cache::frame_key(content, *f, base.scale, base.view ^ oh))).collect() @@ -995,20 +1051,27 @@ impl Frames { /// are converted on the frame pool, each queued once. `true` while there may be more to /// write (a content key being computed, frames being converted): call again soon, since a /// refused write is only retried by a later call. Disk keys hash `opts` the way the worker - /// writes them (`base.opts` also carries the Roto Brush model stamp). + /// writes them (`base.opts` also carries the Roto Brush model stamp). Only frames that know + /// every source file they were made of are written (an entry is checked against them). #[cfg(not(target_arch = "wasm32"))] pub fn persist_missing(&self, src: &RenderSource, base: &FrameKey, opts: &RenderOpts) -> bool { let Some(dc) = src.disk.clone() else { return false }; let oh = opts_hash(opts); self.note_disk_series(base.comp, base.scale, base.view ^ oh); self.carry_disk(src); - let epoch = self.virtual_epoch.load(Ordering::Relaxed); - let known = self.content_keys.lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(&(base.revision, base.comp, epoch)).copied(); + // Free disk space leaves the cache (next to) no room: nothing would be stored, so nothing + // is converted (a refusal doesn't count as a try, so every idle pass would convert them + // all again). A later idle pass writes them once there is room (`prefs_live::memory_watch` + // keeps frames coming meanwhile). + if !dc.accepts_writes() { + return false; + } + let known = self.content_keys.lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(&(base.revision, base.comp)).copied(); let Some(content) = known else { self.request_content_key(src.project.clone(), base.revision, base.comp); return true; }; - let (missing, converting): (Vec<(u128, FrameImage)>, bool) = { + let (missing, converting): (Vec<(u128, FrameImage, Arc, u64)>, bool) = { let (Ok(c), Ok(mut queued), Ok(mut written)) = (self.cache.lock(), self.persisted.lock(), self.written.lock()) else { return false }; if queued.len() > 100_000 { queued.clear(); @@ -1021,14 +1084,17 @@ impl Frames { .map .iter() .filter(|(k, _)| k.same_series(base)) - .filter_map(|(k, img)| { - // (GPU frames have no CPU pixels to write) - if img.is_gpu() { - return None; - } + .filter_map(|(k, c)| { + // (GPU frames have no CPU pixels to write; a frame that can't name its files + // can't be checked when read) + let files = c.files.as_ref().filter(|f| f.is_complete() && !c.img.is_gpu())?; + // (only with the generation its render started at, for this cache: a frame + // made of a file Reload Footage dropped since holds the pixels from before) + let since = c.since.as_ref().and_then(|s| s.for_cache(&dc)).filter(|s| !dc.dropped_since(files, *s))?; let dk = disk_cache::frame_key(content, k.frame, k.scale, k.view ^ oh); let tries = written.1.get(&dk).copied().unwrap_or(0); - (tries < 2 && !dc.contains(disk_cache::Kind::Frame, dk) && !dc.frame_pending(dk) && queued.insert(dk)).then(|| (dk, img.clone())) + (tries < 2 && !dc.contains(disk_cache::Kind::Frame, dk) && !dc.frame_pending(dk) && queued.insert(dk)) + .then(|| (dk, c.img.clone(), files.clone(), since)) }) .collect(); (missing, !queued.is_empty()) @@ -1036,19 +1102,12 @@ impl Frames { if missing.is_empty() { return converting; } - let (persisted, written) = (self.persisted.clone(), self.written.clone()); + let (persisted, written, virtual_id) = (self.persisted.clone(), self.written.clone(), self.virtual_id.clone()); let work = move || { - for (dk, img) in missing { + for (dk, img, files, since) in missing { // (accepted: the disk cache tracks it until written, and it counts as a try; // refused by a full queue: retried, without counting) - let accepted = match &img { - FrameImage::Cpu(img) => { - let rgba: Vec = img.pixels.iter().flat_map(|c| c.to_array()).collect(); - dc.put_frame(dk, img.size[0] as u32, img.size[1] as u32, &rgba) - } - FrameImage::CpuF16(f) => dc.put_frame_f16(dk, f.width, f.height, f.bits()), - FrameImage::Gpu(_) => false, - }; + let accepted = put_disk_frame(&dc, dk, &img, &files, virtual_id.as_deref(), since); if accepted && let Ok(mut w) = written.lock() { let n = w.1.entry(dk).or_default(); *n = n.saturating_add(1); @@ -1091,7 +1150,6 @@ impl Frames { return; } let (carries, scheduled, series, ctx) = (self.disk_carries.clone(), self.carry_scheduled.clone(), self.disk_series.clone(), self.ctx.clone()); - let virtual_id = self.virtual_id.clone(); let work = move || { let mut linked = false; loop { @@ -1111,7 +1169,7 @@ impl Frames { let Some(series) = series.lock().ok().and_then(|m| m.get(&c.comp).cloned()) else { return false }; let comp = ItemId(c.comp); let n = c.to.comp(comp).map_or(0, |k| k.frame_rate.frame_at(k.duration)).clamp(0, 100_000); - let key = |p: &Project| disk_cache::comp_content_key_with(p, comp, virtual_id.as_deref()); + let key = |p: &Project| disk_cache::comp_content_key(p, comp); let (a, b) = (key(&c.from), key(&c.to)); if a == b { return false; @@ -1137,6 +1195,7 @@ impl Frames { } } + /// Queues a background hash of `comp` at `revision`, coalescing rapid edits so only a bounded number of snapshots are kept. #[cfg(not(target_arch = "wasm32"))] fn request_content_key(&self, project: Arc, revision: u64, comp: u64) { let mut jobs = self.content_key_jobs.lock().unwrap_or_else(std::sync::PoisonError::into_inner); @@ -1153,7 +1212,6 @@ impl Frames { jobs.running = true; drop(jobs); let (jobs, keys, ctx) = (self.content_key_jobs.clone(), self.content_keys.clone(), self.ctx.clone()); - let (epoch, id) = (self.virtual_epoch.clone(), self.virtual_id.clone()); let work = move || loop { let next = { let mut jobs = jobs.lock().unwrap_or_else(std::sync::PoisonError::into_inner); @@ -1164,9 +1222,7 @@ impl Frames { next }; let Some((project, revision, comp)) = next else { return }; - let epoch = epoch.load(Ordering::Relaxed); - let id = id.clone(); - if std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| content_key(&keys, &project, revision, comp, epoch, id.as_deref()))).is_err() { + if std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| content_key(&keys, &project, revision, comp))).is_err() { log::error!("could not compute a preview disk-cache key; the cache indicator will retry"); } if let Some(ctx) = &ctx { @@ -1192,6 +1248,7 @@ impl Frames { self.cache.lock().map(|c| c.budget).unwrap_or(0) } + /// Drops every cached frame and purges the remote server, if there is one. pub fn clear(&self) { if let Some(r) = &self.remote { r.purge(); @@ -1205,9 +1262,8 @@ impl Frames { c.gpu_pressure = None; c.gpu_adjusted = None; } - // Disk keys hash the footage files' size and time, but are remembered per revision; a - // file reloaded from disk without a new revision (a re-rendered image sequence) must be - // keyed again, or the disk cache serves the frames from before. + // (the disk keys of a revision don't depend on files: a file changed on disk is caught + // when its frames' entries are read; they are forgotten with the frames all the same) if let Ok(mut k) = self.content_keys.lock() { k.clear(); } @@ -1386,6 +1442,7 @@ impl Frames { } } + /// A render worker sharing this cache's queue, cache and in-flight set. fn worker(&self) -> Worker { Worker { queue: self.queue.clone(), @@ -1394,20 +1451,15 @@ impl Frames { ctx: self.ctx.clone(), last: self.last_ms.clone(), content_keys: self.content_keys.clone(), - virtual_epoch: self.virtual_epoch.clone(), virtual_id: self.virtual_id.clone(), gpu_retired: self.gpu_retired.clone(), } } - /// Browser file table: `epoch` bumps on each replacement, and `id` is the size and content - /// hash used when a content key is rebuilt. Neither runs on a cache hit. - pub fn set_virtual_media(&mut self, epoch: Arc, id: Arc Option<(u64, u64)> + Send + Sync>) { - self.virtual_epoch = epoch; + /// Browser file table: `id` gives the size and content hash of a path served from memory, + /// stored with the disk entries of the frames that read it and checked when they are read. + pub fn set_virtual_id(&mut self, id: Arc Option<(u64, u64)> + Send + Sync>) { self.virtual_id = Some(id); - if let Ok(mut keys) = self.content_keys.lock() { - keys.clear(); - } } /// Render frames with `remote` from now on (`None`: on this thread again). @@ -1465,8 +1517,10 @@ impl Frames { let gpu_here = job.src.gpu.is_some() && job.src.gpu_display && !(remote.gpu() && comp_has_effects(&job.src.project, job.comp)); if gpu_here { let t0 = web_time::Instant::now(); - if let Some(img) = w.render_gpu(&job) { - w.finish(&job, img, t0); + // (A frame kept on the GPU is not written to the disk cache: its files are not + // needed.) + if let Some((img, _files)) = w.render_gpu(&job) { + w.finish(&job, img, None, None, t0); continue; } } @@ -1478,8 +1532,7 @@ impl Frames { let fw = self.worker(); let busy = self.remote_busy.clone(); let t0 = web_time::Instant::now(); - let epoch = w.virtual_epoch.load(Ordering::Relaxed); - let disk_key = remote.disk().then(|| frame_disk_key(&w.content_keys, &job.src.project, &key, opts_hash(&job.opts), epoch, w.virtual_id.as_deref())); + let disk_key = remote.disk().then(|| frame_disk_key(&w.content_keys, &job.src.project, &key, opts_hash(&job.opts))); let rj = RemoteJob { project: job.src.project.clone(), revision: key.revision, comp: job.comp, t: job.t, opts: job.opts, disk_key }; remote.start( rj, @@ -1490,7 +1543,7 @@ impl Frames { match r { Ok(f) => { let img = egui::ColorImage::from_rgba_premultiplied([f.width as usize, f.height as usize], &f.rgba); - fw.finish_key(key, urgent, FrameImage::Cpu(Arc::new(img)), t0); + fw.finish_key(key, urgent, FrameImage::Cpu(Arc::new(img)), None, None, t0); } Err(e) => { // Not rendered (a stale revision, a lost worker): the viewer asks again. @@ -1536,7 +1589,6 @@ struct Worker { ctx: Option, last: Arc>, content_keys: ContentKeys, - virtual_epoch: Arc, virtual_id: Option Option<(u64, u64)> + Send + Sync>>, gpu_retired: Arc, } @@ -1599,28 +1651,17 @@ impl Worker { job }; let t0 = web_time::Instant::now(); - let epoch = self.virtual_epoch.load(Ordering::Relaxed); - let disk = job - .src - .disk - .as_ref() - .map(|dc| (dc.clone(), frame_disk_key(content_keys, &job.src.project, &job.key, opts_hash(&job.opts), epoch, self.virtual_id.as_deref()))); - // Half-float frames (32 bpc) have entries of their own (their key has the options). - let from_disk = disk.as_ref().and_then(|(dc, k)| { - if job.opts.skip_hdr_step { - let f = dc.get_frame_f16(*k)?; - let encoding = effectcraft_engine::viewer::FrameEncoding::of(&job.src.project.settings, true); - Some(FrameImage::CpuF16(Arc::new(F16Frame::from_bits(f.width, f.height, f.rgba, encoding)))) - } else { - let f = dc.get_frame(*k)?; - Some(FrameImage::Cpu(Arc::new(egui::ColorImage::from_rgba_premultiplied([f.width as usize, f.height as usize], &f.rgba)))) - } - }); + // (the drop generation before the frame reads anything: File ▸ Reload Footage meanwhile + // makes what it read from a reloaded file stale) + let disk = + job.src.disk.as_ref().map(|dc| (dc.clone(), frame_disk_key(content_keys, &job.src.project, &job.key, opts_hash(&job.opts)), dc.drop_generation())); + let from_disk = disk.as_ref().and_then(|(dc, k, _)| self.disk_frame(dc, *k, &job)); let disk_hit = from_disk.is_some(); - let ci = match from_disk { - Some(f) => f, + // `files`: the source files the frame was made of (see `render::reads`). + let (ci, files) = match from_disk { + Some(hit) => hit, None => match self.render_guarded(&job).filter(|_| !job.cancel.load(Ordering::Relaxed)) { - Some(ci) => ci, + Some(rendered) => rendered, // Called off (frames it read may be missing) or failed: not cached, and not // "in progress" forever: the viewer asks for it again. None => { @@ -1629,42 +1670,61 @@ impl Worker { } }, }; + let mut files = files; + if let Some((dc, _, since)) = &disk + && dc.dropped_since(&files, *since) + { + // Made of a file as it was before File ▸ Reload Footage dropped it: shown, but its + // list can't vouch for it, so neither this worker nor `persist_missing` stores it. + files.mark_incomplete(); + } + let files = Arc::new(files); // Publish the shared frame and wake the viewer before optional RGBA conversion // and compression. Persistence still runs on this worker, using the same snapshot. - self.finish(&job, ci.clone(), t0); - if !disk_hit && let Some((dc, k)) = &disk { - let written = match &ci { - FrameImage::Cpu(img) => { - let rgba: Vec = img.pixels.iter().flat_map(|c| c.to_array()).collect(); - dc.put_frame(*k, img.size[0] as u32, img.size[1] as u32, &rgba); - true - } - FrameImage::CpuF16(f) => { - dc.put_frame_f16(*k, f.width, f.height, f.bits()); - true - } - FrameImage::Gpu(_) => false, - }; - if written && let Some(ctx) = &self.ctx { - ctx.request_repaint(); - } + let since = disk.as_ref().map(|(dc, _, since)| DiskSince::of(dc, *since)); + self.finish(&job, ci.clone(), Some(files.clone()), since, t0); + if !disk_hit + && let Some((dc, k, since)) = &disk + && put_disk_frame(dc, *k, &ci, &files, self.virtual_id.as_deref(), *since) + && let Some(ctx) = &self.ctx + { + ctx.request_repaint(); } true } - /// Store a finished frame and release its job. - fn finish(&self, job: &Job, img: FrameImage, t0: web_time::Instant) { - self.finish_key(job.key, job.urgent, img, t0); + /// The frame of `job` from the disk cache (key `k`), if its entry is there and the source + /// files it lists are unchanged (checked here, on the frame worker: a few `metadata` calls + /// for that frame's files). An entry whose files changed is deleted: the frame renders again + /// and its new entry replaces it. + fn disk_frame(&self, dc: &DiskCache, k: u128, job: &Job) -> Option<(FrameImage, ReadFiles)> { + let virtual_id = self.virtual_id.as_deref(); + // Half-float frames (32 bpc) have entries of their own (their key has the options). + if job.opts.skip_hdr_step { + let (f, files) = dc.get_frame_f16(k, virtual_id)?; + let encoding = effectcraft_engine::viewer::FrameEncoding::of(&job.src.project.settings, true); + Some((FrameImage::CpuF16(Arc::new(F16Frame::from_bits(f.width, f.height, f.rgba, encoding))), files)) + } else { + let (f, files) = dc.get_frame(k, virtual_id)?; + Some((FrameImage::Cpu(Arc::new(egui::ColorImage::from_rgba_premultiplied([f.width as usize, f.height as usize], &f.rgba))), files)) + } } - fn finish_key(&self, key: FrameKey, urgent: bool, img: FrameImage, t0: web_time::Instant) { + /// Store a finished frame (with the source files it was made of, when known) and release its + /// job. + fn finish(&self, job: &Job, img: FrameImage, files: Option>, since: Option, t0: web_time::Instant) { + self.finish_key(job.key, job.urgent, img, files, since, t0); + } + + /// Stores a finished frame in the cache with its read files, records the render time for urgent jobs, then releases the job. + fn finish_key(&self, key: FrameKey, urgent: bool, img: FrameImage, files: Option>, since: Option, t0: web_time::Instant) { if urgent && let Ok(mut l) = self.last.lock() { *l = t0.elapsed().as_secs_f64() * 1000.0; } if let Ok(mut c) = self.cache.lock() && (!img.is_gpu() || !self.gpu_retired.load(Ordering::Acquire)) { - c.insert(key, img); + c.insert_with(key, img, files, since); } self.release(key, urgent); } @@ -1689,9 +1749,13 @@ impl Worker { } /// [`Worker::render_job`], again on the CPU if it panicked (the panic hook has logged it); - /// `None` if that panicked too. - fn render_guarded(&self, job: &Job) -> Option { - let attempt = |gpu: bool| std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| self.render_job(job, gpu))).ok(); + /// `None` if that panicked too. With the source files the frame was made of. + fn render_guarded(&self, job: &Job) -> Option<(FrameImage, ReadFiles)> { + let attempt = |gpu: bool| { + let files = ReadLog::new(); + let img = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| self.render_job(job, gpu, &files))).ok()?; + Some((img, files.into_files())) + }; let img = attempt(true).or_else(|| { log::error!("a frame render panicked (frame {})", job.key.frame); job.src.gpu.as_ref().and_then(|_| attempt(false)) @@ -1721,26 +1785,31 @@ impl Worker { } } + /// Tells the cache that a GPU render succeeded. fn gpu_succeeded(&self) { if let Ok(mut c) = self.cache.lock() { c.gpu_succeeded(); } } + /// Whether GPU rendering is available and has not been retired. fn gpu_ready(&self) -> bool { !self.gpu_retired.load(Ordering::Acquire) && self.cache.lock().is_ok_and(|c| c.gpu_ready()) } - /// The frame on the GPU, kept there for the viewer, if the compositor can do it alone. - fn render_gpu(&self, job: &Job) -> Option { + /// The frame on the GPU, kept there for the viewer, if the compositor can do it alone, with + /// the source files it was made of. + fn render_gpu(&self, job: &Job) -> Option<(FrameImage, ReadFiles)> { if !self.gpu_ready() { return None; } let g = job.src.gpu.as_ref()?; let footage = job.footage(); + let files = ReadLog::new(); let mut r = Renderer::new(&job.src.project, &footage, job.opts); r.expr = job.src.expr.as_deref(); r.cache = Some(&job.src.layer_cache); + r.reads = Some(&files); r.accel = Some(g as &dyn effectcraft_engine::render::Accelerator); r.active_accel()?; let f = g.within_memory(|| g.render_display(&r, job.comp, job.t)); @@ -1750,7 +1819,7 @@ impl Worker { if f.is_some() { self.gpu_succeeded(); } - f.map(|f| FrameImage::Gpu(Arc::new(f))) + f.map(|f| (FrameImage::Gpu(Arc::new(f)), files.into_files())) } Err(e) => { self.gpu_attempt_failed(g, &e); @@ -1759,11 +1828,13 @@ impl Worker { } } - /// Render a frame; `gpu: false` keeps it off the GPU compositor. - fn render_job(&self, job: &Job, gpu: bool) -> FrameImage { + /// Render a frame; `gpu: false` keeps it off the GPU compositor. The source files it reads + /// are noted in `files` (a GPU attempt that falls back to the CPU notes both renders'). + fn render_job(&self, job: &Job, gpu: bool, files: &ReadLog) -> FrameImage { let footage = job.footage(); let mut r = Renderer::new(&job.src.project, &footage, job.opts); r.expr = job.src.expr.as_deref(); + r.reads = Some(files); let gpu_allowed = gpu && self.gpu_ready(); // A failed GPU attempt may have populated intermediate entries before its scope // reported failure. The CPU retry must compute its own pixels from the snapshot. @@ -1789,7 +1860,7 @@ impl Worker { // Time the GPU's work, not just its recording. g.wait(); if g.context().check_health().is_err() { - return self.render_job(job, false); + return self.render_job(job, false, files); } p.record(key, true, t0.elapsed().as_secs_f64() * 1000.0); } @@ -1802,7 +1873,7 @@ impl Worker { } Err(e) => { self.gpu_attempt_failed(g, &e); - return self.render_job(job, false); + return self.render_job(job, false, files); } } } @@ -1822,7 +1893,7 @@ impl Worker { } Err(e) => { self.gpu_attempt_failed(g, &e); - self.render_job(job, false) + self.render_job(job, false, files) } }; } diff --git a/crates/ui-egui/src/frames/tests.rs b/crates/ui-egui/src/frames/tests.rs index df7b3900c..360ddf1b6 100644 --- a/crates/ui-egui/src/frames/tests.rs +++ b/crates/ui-egui/src/frames/tests.rs @@ -1,4 +1,5 @@ use super::*; +use effectcraft_engine::project::LayerSource; #[test] fn render_scales_are_the_factors_the_thousandths_stand_for() { @@ -60,7 +61,7 @@ fn disk_fixture(stored_frames: &[i64]) -> (Frames, RenderSource, FrameKey, Rende disk.keys.lock().unwrap().extend(stored_frames.iter().map(|frame| disk_cache::frame_key(content, *frame, base.scale, base.view ^ opts_hash(&opts)))); let mut frames = Frames::default(); frames.set_remote(Some(disk.clone())); - frames.content_keys.lock().unwrap().insert((base.revision, base.comp, 0), content); + frames.content_keys.lock().unwrap().insert((base.revision, base.comp), content); let source = RenderSource { project: session.project.clone(), footage: session.footage.clone(), @@ -126,7 +127,7 @@ fn disk_indicator_does_not_hash_on_ui_thread_and_coalesces_edits() { assert_eq!(frames.content_key_jobs.lock().unwrap().pending.len(), 1); release.send(()).unwrap(); let until = Instant::now() + Duration::from_secs(3); - while !frames.content_keys.lock().unwrap().contains_key(&(base.revision, base.comp, 0)) { + while !frames.content_keys.lock().unwrap().contains_key(&(base.revision, base.comp)) { assert!(Instant::now() < until); std::thread::sleep(Duration::from_millis(1)); } @@ -153,7 +154,7 @@ fn disk_indicator_range_tracks_live_membership() { let mut revised = base; revised.revision += 1; - frames.content_keys.lock().unwrap().insert((revised.revision, revised.comp, 0), 5678); + frames.content_keys.lock().unwrap().insert((revised.revision, revised.comp), 5678); assert!(frames.disk_frames(&src, &revised, 10..13, &opts).is_empty()); let changed = FrameKey { scale: base.scale + 1, ..base }; @@ -211,7 +212,7 @@ fn retirement_reaches_existing_workers_and_keeps_cpu_frames_and_completion_live( let next = key(1, 1, 0); frames.inflight.lock().unwrap().insert(next); frames.queue.lock().unwrap().running.insert(next); - worker.finish_key(next, false, img(), web_time::Instant::now()); + worker.finish_key(next, false, img(), None, None, web_time::Instant::now()); assert!(frames.is_cached(&next), "CPU retry can still publish"); assert_eq!(frames.inflight(), 0); assert!(frames.queue.lock().unwrap().running.is_empty()); @@ -996,7 +997,7 @@ fn the_frames_an_edit_keeps_match_a_fresh_render() { // The work area is a preview and render range: setting it (B, N) keeps every frame, on // disk too. let n = s.project.comp(comp).map(|c| c.frame_rate.frame_at(c.duration)).unwrap(); - let disk = |s: &Session| effectcraft_engine::render::disk_cache::comp_content_key_with(&s.project, comp, None); + let disk = |s: &Session| effectcraft_engine::render::disk_cache::comp_content_key(&s.project, comp); let d0 = disk(&s); let work_area = |start: f64, end: f64| json!({"cmd": "comp.workArea", "params": {"comp": comp.0, "start": start, "end": end}}); assert_eq!(kept(&mut s, comp, work_area(1.0, 4.0)), (0..n).collect::>()); @@ -1593,6 +1594,71 @@ fn half_float_ram_frames_missing_on_disk_are_written() { ram_frames_missing_on_disk_are_written_as(true); } +/// A RAM frame whose render started before Reload Footage dropped one of its files (#3184) +/// holds the pixels from before: writing it later to the disk cache (an idle pass after the +/// drop) would bring them back, also after a restart, since the file kept its size and time. It +/// is written only with the drop generation its render started at, for the cache it started +/// with: so it is not written, nor is a frame rendered without that cache. Frames of other files, +/// and frames rendered after the drop, are written. +#[test] +fn ram_frames_from_before_a_drop_are_not_written() { + use effectcraft_engine::Session; + use effectcraft_engine::render::reads::{FileStamp, ReadFile}; + use serde_json::json; + let dir = tempfile::tempdir().unwrap(); + let disk = DiskCache::open(dir.path().join("cache"), 1 << 30).unwrap(); + let other = DiskCache::open(dir.path().join("other"), 1 << 30).unwrap(); + let mut s = Session::default(); + let cid = ItemId(s.execute("comp.new", json!({"name": "A", "width": 8, "height": 8, "duration": 1})).unwrap()["comp"].as_u64().unwrap()); + s.execute("layer.newSolid", json!({})).unwrap(); + let src = RenderSource { + project: s.project.clone(), + footage: Arc::new(effectcraft_engine::render::NoFootage), + expr: None, + layer_cache: Arc::default(), + gpu: None, + gpu_display: false, + disk: Some(disk.clone()), + }; + let f = Frames::default(); + let series = FrameKey { revision: 1, content: f.content_of(&src.project, 1, cid), comp: cid.0, opts: opts_hash(&RenderOpts::default()), ..key(0, 0, 0) }; + let read = |p: &str| Some(Arc::new([ReadFile::new(p, FileStamp::Native { len: 3, modified: Some(1) })].into_iter().collect::())); + let before = DiskSince::of(&disk, disk.drop_generation()); + { + let mut c = f.cache.lock().unwrap(); + c.insert_with(FrameKey { frame: 0, ..series }, img(), read("/a.png"), Some(before.clone())); + c.insert_with(FrameKey { frame: 1, ..series }, img(), read("/b.png"), Some(before)); + c.insert_with(FrameKey { frame: 2, ..series }, img(), read("/a.png"), None); + c.insert_with(FrameKey { frame: 3, ..series }, img(), read("/a.png"), Some(DiskSince::of(&other, other.drop_generation()))); + } + // Reload Footage of a.png. + disk.drop_files(["/a.png"]); + disk.flush(); + f.cache.lock().unwrap().insert_with(FrameKey { frame: 4, ..series }, img(), read("/a.png"), Some(DiskSince::of(&disk, disk.drop_generation()))); + let on_disk = |fr: i64| { + disk.contains( + disk_cache::Kind::Frame, + frame_disk_key(&f.content_keys, &src.project, &FrameKey { frame: fr, ..series }, opts_hash(&RenderOpts::default())), + ) + }; + // Idle passes until there is nothing left to write. + let mut done = false; + for _ in 0..1000 { + let more = f.persist_missing(&src, &series, &RenderOpts::default()); + disk.flush(); + if !more && f.persisted.lock().unwrap().is_empty() { + done = true; + break; + } + std::thread::sleep(std::time::Duration::from_millis(5)); + } + assert!(done, "the idle passes end"); + assert!(on_disk(1) && on_disk(4), "another file's frame, and a frame rendered after the drop"); + assert!(!on_disk(0), "made of a.png as it was before the drop"); + assert!(!on_disk(2) && !on_disk(3), "rendered without this disk cache"); + assert_eq!(disk.stats().entries, 2); +} + fn ram_frames_missing_on_disk_are_written_as(half: bool) { use effectcraft_engine::Session; use serde_json::json; @@ -1616,19 +1682,12 @@ fn ram_frames_missing_on_disk_are_written_as(half: bool) { FrameKey { revision: 1, content: f.content_of(&src.project, 1, cid), comp: cid.0, opts: opts_hash(&RenderOpts::default()) ^ 1, ..key(0, 0, 0) }; for fr in 0..10 { let frame = if half { FrameImage::CpuF16(Arc::new(F16Frame::from_image(&effectcraft_engine::render::Image::new(8, 8), SRGB))) } else { img() }; - f.cache.lock().unwrap().insert(FrameKey { frame: fr, ..series }, frame); + f.cache.lock().unwrap().insert_with(FrameKey { frame: fr, ..series }, frame, Some(Arc::default()), Some(DiskSince::of(&disk, disk.drop_generation()))); } let on_disk = |fr: i64| { disk.contains( disk_cache::Kind::Frame, - frame_disk_key( - &f.content_keys, - &src.project, - &FrameKey { frame: fr, ..series }, - opts_hash(&RenderOpts::default()), - f.virtual_epoch.load(Ordering::Relaxed), - None, - ), + frame_disk_key(&f.content_keys, &src.project, &FrameKey { frame: fr, ..series }, opts_hash(&RenderOpts::default())), ) }; let persist = || { @@ -1674,6 +1733,71 @@ fn ram_frames_missing_on_disk_are_written_as(half: bool) { let _ = std::fs::remove_dir_all(&dir); } +/// While free disk space holds the disk cache at 0, frames are not converted or compressed for +/// it (the frame workers spent about 8 ms per frame on writes that were then refused), and idle +/// passes don't keep converting the RAM frames; with room again they are written. +#[test] +fn no_frame_is_encoded_while_the_disk_has_no_room() { + use effectcraft_engine::Session; + use serde_json::json; + const GB: u64 = 1 << 30; + let dir = std::env::temp_dir().join(format!("ec-persist-full-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + let disk = DiskCache::open(&dir, 20 * GB).unwrap(); + // 4 TB disk, 1 GB free: under the 10 GB reserve. + disk.set_disk_space(Some((4096 * GB, GB))); + assert!(!disk.accepts_writes()); + // The frame worker's write: refused up front. + assert!(!put_disk_frame(&disk, 1, &img(), &ReadFiles::default(), None, disk.drop_generation())); + let mut s = Session::default(); + let cid = ItemId(s.execute("comp.new", json!({"name": "A", "width": 8, "height": 8, "duration": 1})).unwrap()["comp"].as_u64().unwrap()); + s.execute("layer.newSolid", json!({})).unwrap(); + let src = RenderSource { + project: s.project.clone(), + footage: Arc::new(effectcraft_engine::render::NoFootage), + expr: None, + layer_cache: Arc::default(), + gpu: None, + gpu_display: false, + disk: Some(disk.clone()), + }; + let f = Frames::default(); + let series = + FrameKey { revision: 1, content: f.content_of(&src.project, 1, cid), comp: cid.0, opts: opts_hash(&RenderOpts::default()) ^ 1, ..key(0, 0, 0) }; + for fr in 0..10 { + f.cache.lock().unwrap().insert_with(FrameKey { frame: fr, ..series }, img(), Some(Arc::default()), Some(DiskSince::of(&disk, disk.drop_generation()))); + } + // Idle passes: nothing to do, nothing converted. + for _ in 0..20 { + assert!(!f.persist_missing(&src, &series, &RenderOpts::default()), "no idle passes while there is no room"); + std::thread::sleep(std::time::Duration::from_millis(2)); + } + disk.flush(); + assert!(f.persisted.lock().unwrap().is_empty()); + assert_eq!((disk.encodes(), disk.stats().entries), (0, 0)); + // Room again: the RAM frames are written. + disk.set_disk_space(Some((4096 * GB, 500 * GB))); + let on_disk = |fr: i64| { + disk.contains( + disk_cache::Kind::Frame, + frame_disk_key(&f.content_keys, &src.project, &FrameKey { frame: fr, ..series }, opts_hash(&RenderOpts::default())), + ) + }; + let mut written = false; + for _ in 0..1000 { + f.persist_missing(&src, &series, &RenderOpts::default()); + disk.flush(); + if (0..10).all(on_disk) && f.persisted.lock().unwrap().is_empty() { + written = true; + break; + } + std::thread::sleep(std::time::Duration::from_millis(5)); + } + assert!(written, "every RAM frame written once there is room"); + assert_eq!(disk.encodes(), 10); + let _ = std::fs::remove_dir_all(&dir); +} + /// Audio changes pixels only where something draws it: a clip's Audio Levels, audio effects and /// Audio switch keep every frame, in RAM and on disk, until a waveform picks the clip (on another /// layer, on itself, or through a precomp of it); then the frames of the reader render again. @@ -1681,7 +1805,7 @@ fn ram_frames_missing_on_disk_are_written_as(half: bool) { fn audio_edits_keep_the_frames_until_something_draws_the_audio() { use effectcraft_engine::Session; use effectcraft_engine::project::{Footage, GroupKind, LayerId, Value, build}; - use effectcraft_engine::render::disk_cache::comp_content_key_with; + use effectcraft_engine::render::disk_cache::comp_content_key; use serde_json::json; let mut s = Session::default(); let cid = ItemId(s.execute("comp.new", json!({"name": "A", "width": 8, "height": 8, "duration": 4, "frameRate": 30})).unwrap()["comp"].as_u64().unwrap()); @@ -1736,7 +1860,7 @@ fn audio_edits_keep_the_frames_until_something_draws_the_audio() { let mut p1 = p0.clone(); edit(Arc::make_mut(&mut p1)); let id1 = f.content_of(&p1, 2, view); - (f.cached_frames(&k(id1, 0)), comp_content_key_with(&p0, view, None) == comp_content_key_with(&p1, view, None)) + (f.cached_frames(&k(id1, 0)), comp_content_key(&p0, view) == comp_content_key(&p1, view)) }; let all: Vec = (0..120).collect(); let edits: [(&str, &dyn Fn(&mut Project)); 3] = [("levels", &levels), ("audio effect", &backwards), ("audio switch", &mute)]; @@ -1933,9 +2057,9 @@ fn disk_frames_outlive_an_edit_that_cant_change_them() { disk: Some(disk.clone()), }; // Every frame of `p0` on disk, none in RAM. - let content0 = disk_cache::comp_content_key_with(&p0, cid, None); + let content0 = disk_cache::comp_content_key(&p0, cid); for f in 0..30 { - disk.put_frame_now(disk_cache::frame_key(content0, f, 1000, oh), 1, 1, &[1, 2, 3, 255]); + disk.put_frame_now(disk_cache::frame_key(content0, f, 1000, oh), 1, 1, &[1, 2, 3, 255], &ReadFiles::default()); } let rename: fn(&mut Project, ItemId, LayerId) = |p, c, l| p.comp_mut(c).unwrap().layer_mut(l).unwrap().name = "Renamed".into(); let trim: fn(&mut Project, ItemId, LayerId) = |p, c, l| { @@ -1982,6 +2106,80 @@ fn disk_frames_outlive_an_edit_that_cant_change_them() { let _ = std::fs::remove_dir_all(&dir); } +/// With expressions the disk key covers what they can read (#3184, #1492): an edit to a comp no +/// expression names keeps every frame on disk under the same key; an edit to the comp one names +/// gives the comp a new key, and the frames outside the layer with that expression are carried to +/// it (the dirty spans of #2795). +#[test] +fn disk_frames_outlive_edits_their_expressions_cant_read() { + use effectcraft_engine::Session; + use effectcraft_engine::project::{Expression, LayerId, Value}; + use serde_json::json; + let dir = std::env::temp_dir().join(format!("ec-disk-carry-expr-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + let disk = DiskCache::open(&dir, 1 << 30).unwrap(); + let mut s = Session::default(); + let comp = |s: &mut Session, name: &str| { + ItemId(s.execute("comp.new", json!({"name": name, "width": 8, "height": 8, "duration": 1, "frameRate": 30})).unwrap()["comp"].as_u64().unwrap()) + }; + let solid = |s: &mut Session, c: ItemId| LayerId(s.execute("layer.newSolid", json!({"comp": c.0, "color": "#ff0000"})).unwrap()["layer"].as_u64().unwrap()); + let cid = comp(&mut s, "A"); + let (a, b) = (solid(&mut s, cid), solid(&mut s, cid)); + let other = comp(&mut s, "Other"); + let o = solid(&mut s, other); + let third = comp(&mut s, "Third"); + let t = solid(&mut s, third); + let fr = s.project.comp(cid).unwrap().frame_rate; + let mut p0 = (*s.project).clone(); + for (l, i, out) in [(a, 0, 15), (b, 15, 30)] { + let l = p0.comp_mut(cid).unwrap().layer_mut(l).unwrap(); + (l.start_time, l.in_point, l.out_point) = (fr.tick_of(i), fr.tick_of(i), fr.tick_of(out)); + } + p0.comp_mut(cid).unwrap().layer_mut(a).unwrap().props.prop_mut("transform/opacity").unwrap().expr = + Some(Expression { text: "comp(\"Other\").layer(1).transform.opacity".into(), enabled: true }); + let p0 = Arc::new(p0); + let opts = RenderOpts::default(); + let oh = opts_hash(&opts); + let src = |p: &Arc| RenderSource { + project: p.clone(), + footage: Arc::new(effectcraft_engine::render::NoFootage), + expr: None, + layer_cache: Arc::default(), + gpu: None, + gpu_display: false, + disk: Some(disk.clone()), + }; + let content0 = disk_cache::comp_content_key(&p0, cid); + for f in 0..30 { + disk.put_frame_now(disk_cache::frame_key(content0, f, 1000, oh), 1, 1, &[1, 2, 3, 255], &ReadFiles::default()); + } + let opacity = |p: &mut Project, c: ItemId, l: LayerId| { + p.comp_mut(c).unwrap().layer_mut(l).unwrap().props.prop_mut("transform/opacity").unwrap().value = Value::Scalar(40.0) + }; + for (name, edited, layer, same_key, kept) in [("Third", third, t, true, (0..30).collect::>()), ("Other", other, o, false, (17..30).collect())] { + let f = Frames::default(); + let series = |p: &Arc, rev: u64| FrameKey { revision: rev, content: f.content_of(p, rev, cid), comp: cid.0, opts: oh, ..key(0, 0, 0) }; + let blue = |p: &Arc, rev: u64, want: &[i64]| { + let base = series(p, rev); + let mut got = vec![]; + for _ in 0..1000 { + got = f.disk_frames(&src(p), &base, 0..30, &opts); + if got == want { + break; + } + std::thread::sleep(std::time::Duration::from_millis(5)); + } + got + }; + assert_eq!(blue(&p0, 1, &(0..30).collect::>()), (0..30).collect::>(), "{name}: before"); + let mut p1 = p0.clone(); + opacity(Arc::make_mut(&mut p1), edited, layer); + assert_eq!(disk_cache::comp_content_key(&p1, cid) == content0, same_key, "{name}: the key"); + assert_eq!(blue(&p1, 2, &kept), kept, "{name}: after"); + } + let _ = std::fs::remove_dir_all(&dir); +} + /// A keyframe edit re-renders only around the keys it changed: two keys either side (auto-Bezier /// and continuous tangents reach the neighbouring segments), and from the layer's in point when /// the first key changes. A static value or an expression still reaches the whole layer. Every @@ -2041,7 +2239,7 @@ fn a_keyframe_edit_reaches_only_the_keys_around_it() { fn music_volume_keeps_the_frames_with_expressions_that_dont_read_audio() { use effectcraft_engine::Session; use effectcraft_engine::project::{Expression, Footage, FootageKind, LayerId, Value, build}; - use effectcraft_engine::render::disk_cache::comp_content_key_with; + use effectcraft_engine::render::disk_cache::comp_content_key; use serde_json::json; let mut s = Session::default(); let cid = ItemId(s.execute("comp.new", json!({"name": "A", "width": 8, "height": 8, "duration": 4, "frameRate": 30})).unwrap()["comp"].as_u64().unwrap()); @@ -2069,7 +2267,7 @@ fn music_volume_keeps_the_frames_with_expressions_that_dont_read_audio() { let mut p1 = p0.clone(); Arc::make_mut(&mut p1).comp_mut(cid).unwrap().layer_mut(music_id).unwrap().props.prop_mut("audio/levels").unwrap().value = Value::Vec2([-6.0, -6.0]); let id1 = f.content_of(&p1, 2, cid); - (f.cached_frames(&k(id1, 0)).len(), comp_content_key_with(&p0, cid, None) == comp_content_key_with(&p1, cid, None)) + (f.cached_frames(&k(id1, 0)).len(), comp_content_key(&p0, cid) == comp_content_key(&p1, cid)) }; assert_eq!(kept("wiggle(2, 20)"), (120, true), "a wiggle reads no audio"); let (frames, disk) = kept("value + thisComp.layer(\"Music\")(\"Audio\")(\"Audio Levels\")[0]"); @@ -2449,3 +2647,313 @@ fn a_keyframe_edit_beside_muted_keys_reaches_the_keys_that_play() { assert!(same(i), "kept frame {i} renders differently after the edit"); } } + +/// Disk-cache frame entries that keep the source files they were made of (#3184): a sequence +/// comp in a folder of its own, with a large unused sequence in the project. +mod frame_files { + use super::*; + use effectcraft_engine::project::{Footage, FootageKind, build}; + use effectcraft_engine::time::FrameRate; + use std::path::{Path, PathBuf}; + use std::sync::atomic::AtomicUsize; + + const RATE: FrameRate = FrameRate::FPS_30; + const FRAMES: i64 = 5; + + /// A fresh folder for test `name` (on the build drive, not the system temp folder), deleted + /// when the guard is dropped. + fn folder(name: &str) -> tempfile::TempDir { + let target = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../target"); + std::fs::create_dir_all(&target).unwrap(); + tempfile::Builder::new().prefix(&format!("test-frame-files-{name}-")).tempdir_in(target).unwrap() + } + + /// A flat grey PNG of `level` at `path`. + fn png(path: &Path, level: u8) -> String { + image::RgbaImage::from_pixel(16, 8, image::Rgba([level, level, level, 255])).save(path).unwrap(); + path.to_string_lossy().to_string() + } + + /// The grey level of sequence frame `i` as first written. + fn level(i: i64) -> u8 { + 20 + i as u8 * 30 + } + + /// A project with a comp showing a sequence of [`FRAMES`] PNGs (in `dir/seq`) and, unused, a + /// sequence of 5000 frames that don't even exist. The files of the shown sequence. + fn project(dir: &Path) -> (Arc, ItemId, Vec) { + let seq_dir = dir.join("seq"); + std::fs::create_dir_all(&seq_dir).unwrap(); + let files: Vec = (0..FRAMES).map(|i| png(&seq_dir.join(format!("f_{i:04}.png")), level(i))).collect(); + let mut seq = Footage { kind: FootageKind::Sequence, sequence: files.clone(), frame_rate: RATE, ..effectcraft_media::probe(&files[0]).unwrap() }; + seq.sync_sequence_duration(); + let unused = Footage { + kind: FootageKind::Sequence, + sequence: (0..5000).map(|i| dir.join("unused").join(format!("big_{i:05}.exr")).to_string_lossy().to_string()).collect(), + frame_rate: RATE, + width: 16, + height: 8, + has_video: true, + ..Default::default() + }; + let mut p = Project::default(); + p.add_item("Unused", effectcraft_engine::color::Label::Aqua, None, ItemKind::Footage(unused)); + let item = p.add_item("Seq", effectcraft_engine::color::Label::Aqua, None, ItemKind::Footage(seq)); + let mut comp = Comp::new(16, 8, RATE, RATE.tick_of(FRAMES)); + comp.layers = vec![build::layer(&mut p, &comp, "Seq", LayerSource::Footage { item }, (16, 8), Some(comp.duration))].into(); + let cid = p.add_item("C", effectcraft_engine::color::Label::None, None, ItemKind::Comp(comp.into())); + (Arc::new(p), cid, files) + } + + /// A session over the disk cache in `dir`: a new preview cache, media pool, layer cache and + /// disk cache instance (as after reopening the project), counting the calls of the hook for + /// files served from memory. + struct Session { + frames: Frames, + src: RenderSource, + disk: Arc, + hook_calls: Arc, + /// The session's media pool (`src.footage`): what it decoded and opened. + pool: Arc, + } + + fn session(p: &Arc, dir: &Path) -> Session { + let disk = DiskCache::open(dir.join("cache"), 1 << 30).unwrap(); + let hook_calls = Arc::new(AtomicUsize::new(0)); + let mut frames = Frames::default(); + let calls = hook_calls.clone(); + frames.set_virtual_id(Arc::new(move |_| { + calls.fetch_add(1, Ordering::Relaxed); + None + })); + let pool = Arc::new(effectcraft_media::MediaPool::new()); + let src = RenderSource { + project: p.clone(), + footage: pool.clone(), + expr: None, + layer_cache: Arc::default(), + gpu: None, + gpu_display: false, + disk: Some(disk.clone()), + }; + Session { frames, src, disk, hook_calls, pool } + } + + impl Session { + fn key(&self, cid: ItemId, frame: i64) -> FrameKey { + FrameKey { + revision: 1, + content: self.frames.content_of(&self.src.project, 1, cid), + comp: cid.0, + frame, + scale: 1000, + view: 0, + opts: opts_hash(&RenderOpts::default()), + } + } + + /// Show `frames` of `cid` (rendered or read from disk); the grey level of each, once + /// their disk writes are done. + fn show(&self, cid: ItemId, frames: &[i64]) -> Vec { + for &f in frames { + self.frames.request(&self.src, self.key(cid, f), cid, RATE.tick_of(f), RenderOpts::default()); + } + wait_for_renders(&self.frames); + // (the worker queues the write after it has released the frame) + for _ in 0..400 { + self.disk.flush(); + if frames.iter().all(|f| self.disk.contains(disk_cache::Kind::Frame, self.disk_key(cid, *f))) { + break; + } + std::thread::sleep(std::time::Duration::from_millis(5)); + } + frames + .iter() + .map(|f| match self.frames.get(&self.key(cid, *f)) { + Some(FrameImage::Cpu(c)) => c.pixels[0].r(), + _ => panic!("frame {f}: an 8-bit CPU frame"), + }) + .collect() + } + + fn disk_key(&self, cid: ItemId, frame: i64) -> u128 { + frame_disk_key(&self.frames.content_keys, &self.src.project, &self.key(cid, frame), opts_hash(&RenderOpts::default())) + } + + /// (disk hits, disk misses) so far. + fn hits(&self) -> (u64, u64) { + let s = self.disk.stats(); + (s.hits, s.misses) + } + } + + fn close(a: u8, b: u8) -> bool { + a.abs_diff(b) <= 2 + } + + /// Give `path` a modification time `secs` later, contents and size unchanged. + fn touch(path: &str, secs: u64) { + let t = std::fs::metadata(path).unwrap().modified().unwrap() + std::time::Duration::from_secs(secs); + std::fs::File::options().append(true).open(path).unwrap().set_modified(t).unwrap(); + } + + /// Correct: a source file of the sequence changes (new contents and size; or only a new + /// time): exactly the frames that read it render again and their entries are replaced; the + /// others come from disk, also after reopening. + #[test] + fn a_changed_source_file_re_renders_exactly_its_frames() { + let tmp = folder("correct"); + let dir = tmp.path(); + let (p, cid, files) = project(dir); + let all: Vec = (0..FRAMES).collect(); + let first = session(&p, dir); + let shown = first.show(cid, &all); + assert!(all.iter().all(|f| close(shown[*f as usize], level(*f))), "{shown:?}"); + assert_eq!(first.hits(), (0, FRAMES as u64), "rendered, nothing on disk yet"); + assert_eq!(first.disk.stats().entries, FRAMES as usize, "every frame stored"); + drop(first); + // Frame 2's file gets new pixels (and size), frame 3's only a new time. + png(Path::new(&files[2]), 250); + touch(&files[3], 30); + let second = session(&p, dir); + let shown = second.show(cid, &all); + assert!(close(shown[2], 250), "frame 2 shows its new file: {shown:?}"); + assert!([0, 1, 3, 4].iter().all(|f| close(shown[*f as usize], level(*f))), "{shown:?}"); + assert_eq!(second.hits(), (3, 2), "frames 0, 1 and 4 from disk; 2 and 3 rendered again"); + assert_eq!(second.disk.file_checks(), FRAMES as u64, "one file checked per frame read"); + assert_eq!(second.disk.stats().entries, FRAMES as usize, "the entries of 2 and 3 were replaced"); + drop(second); + // Reopened: every frame from disk, the replaced ones with their new pixels. + let third = session(&p, dir); + let shown = third.show(cid, &all); + assert_eq!(third.hits(), (FRAMES as u64, 0)); + assert!(close(shown[2], 250) && close(shown[3], level(3)), "{shown:?}"); + } + + /// Reopened (a new preview cache, media pool, layer cache and disk cache on the same folder): + /// the frame comes from disk, its one source file is checked (a `metadata` call), and no + /// source file is opened or decoded for it. + #[test] + fn a_reopened_project_serves_its_frame_from_disk_without_opening_a_source_file() { + let tmp = folder("reopen"); + let dir = tmp.path(); + let (p, cid, _) = project(dir); + let first = session(&p, dir); + let shown = first.show(cid, &[1]); + assert!(close(shown[0], level(1)), "{shown:?}"); + assert!(first.pool.stats().misses > 0, "the first session decodes the frame's file: {:?}", first.pool.stats()); + assert!(first.disk.contains(disk_cache::Kind::Frame, first.disk_key(cid, 1))); + drop(first); + let again = session(&p, dir); + let shown = again.show(cid, &[1]); + assert!(close(shown[0], level(1)), "{shown:?}"); + assert_eq!(again.hits(), (1, 0), "served from disk"); + assert_eq!(again.disk.file_checks(), 1, "its one file checked"); + assert_eq!(again.pool.stats(), effectcraft_media::PoolStats::default(), "no source file opened or decoded"); + } + + /// No scan: opening a comp of a project that also holds a large sequence, and showing a + /// frame, looks only at the files that frame reads; the comp's key looks at no file (it + /// stays the same when its files change, and never asks for the identity of a path). + #[test] + fn showing_a_frame_checks_only_the_files_it_reads() { + let tmp = folder("no-scan"); + let dir = tmp.path(); + let (p, cid, files) = project(dir); + let key = disk_cache::comp_content_key(&p, cid); + png(Path::new(&files[1]), 99); + touch(&files[2], 5); + assert_eq!(disk_cache::comp_content_key(&p, cid), key, "the key looks at no file"); + let first = session(&p, dir); + first.show(cid, &[2]); + drop(first); + let again = session(&p, dir); + // (the indicator's key is computed off the UI thread first) + let mut blue = vec![]; + for _ in 0..400 { + blue = again.frames.disk_frames(&again.src, &again.key(cid, 0), 0..FRAMES, &RenderOpts::default()); + if !blue.is_empty() { + break; + } + std::thread::sleep(std::time::Duration::from_millis(5)); + } + assert_eq!(blue, vec![2], "the blue bar: present entries, no file looked at"); + assert_eq!(again.disk.file_checks(), 0, "the indicator checks no file"); + let shown = again.show(cid, &[2]); + assert!(close(shown[0], level(2)), "{shown:?}"); + assert_eq!(again.hits(), (1, 0)); + assert_eq!(again.disk.file_checks(), 1, "only the file frame 2 read"); + assert_eq!(again.hook_calls.load(Ordering::Relaxed), 0, "no path of the unused sequence was asked about"); + } + + /// The frame entry files under the cache folder. + fn entries(dir: &Path) -> Vec { + let mut out = vec![]; + let mut stack = vec![dir.join("cache")]; + while let Some(d) = stack.pop() { + for e in std::fs::read_dir(&d).into_iter().flatten().flatten() { + let p = e.path(); + if p.is_dir() { + stack.push(p); + } else if p.extension().is_some_and(|x| x == "ecc") && p.to_string_lossy().contains("frames") { + out.push(p); + } + } + } + out + } + + /// Safe: a missing source file, an unreadable one (a folder in its place) and a damaged + /// cache entry never serve the frame from before; each is rendered again and stored anew. + #[test] + fn missing_or_unreadable_files_and_damaged_entries_never_serve_a_stale_frame() { + let tmp = folder("safe"); + let dir = tmp.path(); + let (p, cid, files) = project(dir); + let first = session(&p, dir); + first.show(cid, &[0]); + assert_eq!(first.disk.stats().entries, 1); + drop(first); + // Missing: not served; the frame is rendered without it. + std::fs::remove_file(&files[0]).unwrap(); + let missing = session(&p, dir); + let shown = missing.show(cid, &[0]); + assert!(!close(shown[0], level(0)), "the frame from before was served: {shown:?}"); + assert_eq!(missing.hits(), (0, 1)); + drop(missing); + // Back, with other pixels: the entry made while it was missing is not served either. + png(Path::new(&files[0]), 180); + let back = session(&p, dir); + let shown = back.show(cid, &[0]); + assert!(close(shown[0], 180), "{shown:?}"); + assert_eq!(back.hits(), (0, 1)); + drop(back); + // Unreadable (a folder in its place). + std::fs::remove_file(&files[0]).unwrap(); + std::fs::create_dir(&files[0]).unwrap(); + let unreadable = session(&p, dir); + let shown = unreadable.show(cid, &[0]); + assert!(!close(shown[0], 180), "the frame from before was served: {shown:?}"); + assert_eq!(unreadable.hits(), (0, 1)); + drop(unreadable); + std::fs::remove_dir(&files[0]).unwrap(); + png(Path::new(&files[0]), 120); + let fresh = session(&p, dir); + assert!(close(fresh.show(cid, &[0])[0], 120)); + drop(fresh); + // A damaged entry: a miss, rendered, stored again, then served. + let found = entries(dir); + assert_eq!(found.len(), 1, "{found:?}"); + let mut bytes = std::fs::read(&found[0]).unwrap(); + let n = bytes.len() / 2; + bytes[n] ^= 0x5a; + std::fs::write(&found[0], bytes).unwrap(); + let damaged = session(&p, dir); + assert!(close(damaged.show(cid, &[0])[0], 120)); + assert_eq!(damaged.hits(), (0, 1)); + drop(damaged); + let healed = session(&p, dir); + assert!(close(healed.show(cid, &[0])[0], 120)); + assert_eq!(healed.hits(), (1, 0), "the rewritten entry is used"); + } +} diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs index 0c7573c91..76a70426e 100644 --- a/crates/ui-egui/src/menus/invoke.rs +++ b/crates/ui-egui/src/menus/invoke.rs @@ -163,6 +163,7 @@ fn vertex_delta(app: &EffectcraftApp, layer: effectcraft_engine::project::LayerI footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let (l2c, _) = crate::panels::viewer::l2c(&ectx, l); l2c.inverse().map_or(d, |inv| { diff --git a/crates/ui-egui/src/panels/effect_controls/panel.rs b/crates/ui-egui/src/panels/effect_controls/panel.rs index 0857dfa3f..39fd4847a 100644 --- a/crates/ui-egui/src/panels/effect_controls/panel.rs +++ b/crates/ui-egui/src/panels/effect_controls/panel.rs @@ -186,6 +186,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let hdr = Rect::from_min_size(rect.min, vec2(rect.width(), 24.0)); p.text(pos2(hdr.min.x + 10.0, hdr.center().y), Align2::LEFT_CENTER, format!("{} • {}", comp_name, layer.name), Tokens::ui(11.5), t.text_dim); diff --git a/crates/ui-egui/src/panels/layer_panel.rs b/crates/ui-egui/src/panels/layer_panel.rs index 8e4f3502f..e23e11cfb 100644 --- a/crates/ui-egui/src/panels/layer_panel.rs +++ b/crates/ui-egui/src/panels/layer_panel.rs @@ -113,6 +113,7 @@ fn render_tex( footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let mut r = Renderer::new(&app.session.project, &*app.session.footage, RenderOpts { scale, ..Default::default() }); r.expr = app.session.expr.as_deref(); diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs index 25829be7d..4edcbb31a 100644 --- a/crates/ui-egui/src/panels/properties.rs +++ b/crates/ui-egui/src/panels/properties.rs @@ -79,6 +79,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let scroll = widgets::PanelScroll::begin(ui, egui::Id::unique("props-scroll"), rect); let rect = scroll.content; diff --git a/crates/ui-egui/src/panels/roto_tool.rs b/crates/ui-egui/src/panels/roto_tool.rs index 194bba26a..c01a8f07e 100644 --- a/crates/ui-egui/src/panels/roto_tool.rs +++ b/crates/ui-egui/src/panels/roto_tool.rs @@ -114,6 +114,7 @@ pub fn draw_overlay( footage: None, property_overrides: &[], media_overrides: &[], + reads: None, }; let mut r = Renderer::new(&app.session.project, &*app.session.footage, RenderOpts { scale, ..Default::default() }); r.expr = app.session.expr.as_deref(); diff --git a/crates/ui-egui/src/panels/settings.rs b/crates/ui-egui/src/panels/settings.rs index 72564f112..cdeb85116 100644 --- a/crates/ui-egui/src/panels/settings.rs +++ b/crates/ui-egui/src/panels/settings.rs @@ -5,7 +5,8 @@ //! //! Automation ids: `settings.page.`, `settings.` (e.g. `settings.general.undoLevels`), //! `settings.labels..name` / `.color`, `settings.button.

- A CC Particle World burst with Glow, and the Effect Controls panel listing the particle system's parameters -

- ## 3D Classic 3D compositing: 3D layers with orientation and material options, diff --git a/apps/effectcraft-cli/src/main.rs b/apps/effectcraft-cli/src/main.rs index 2981519e9..b8634178e 100644 --- a/apps/effectcraft-cli/src/main.rs +++ b/apps/effectcraft-cli/src/main.rs @@ -35,8 +35,8 @@ //! //! Project: --project F.ecproj (or a positional *.ecproj) | --demo | --empty (default: demo; mcp: empty) //! Saving: --save (back to --project) | --save-as F.ecproj -//! GPU: --gpu renders on the GPU compositor (Mercury GPU Acceleration) when an adapter exists; -//! the default is the CPU (Mercury Software Only) +//! GPU: --gpu renders on the GPU compositor (GPU Acceleration) when an adapter exists; +//! the default is the CPU (Software Rendering) //! Bridge: --bridge PORT drives a running `effectcraft --control PORT` instead of a headless session //! Output: --json for one compact JSON document on stdout (errors: {"error": …}, exit 1) //! ``` @@ -466,7 +466,7 @@ fn backend(args: &Args, default_demo: bool) -> Result { } /// A wired session; `--gpu` attaches the GPU compositor (renders then follow the project's -/// renderer setting, Mercury GPU Acceleration by default). +/// renderer setting, GPU Acceleration by default). fn session(args: &Args) -> Result { let mut s = effectcraft_host::session(); if args.flag("--autosave") { @@ -1443,7 +1443,7 @@ fn adv3d_bench_comp(p: &mut effectcraft_engine::project::Project) -> Option Result<(), Failure> { use effectcraft_render::Backend; diff --git a/crates/automation/tests/qa/compositing.rs b/crates/automation/tests/qa/compositing.rs index d5de8f687..3cf8356fb 100644 --- a/crates/automation/tests/qa/compositing.rs +++ b/crates/automation/tests/qa/compositing.rs @@ -106,7 +106,7 @@ fn track_matte(qa: &mut Qa) { fn adjustment_layer(qa: &mut Qa, normal: &Img) { // Adjustment layer: Lumetri exposure, inside a feathered, expanded elliptical mask; then Glow. qa.exec("layer.newAdjustment", json!({"name": "Grade"})); - let fx = qa.exec("effect.apply", json!({"effect": "Lumetri Color", "layers": ["Grade"]})); + let fx = qa.exec("effect.apply", json!({"effect": "Color Grading", "layers": ["Grade"]})); assert_eq!(fx["paths"], json!(["effects/#1"]), "effect.apply answers with the instance path: {fx}"); qa.tool("set_property", json!({"layer": "Grade", "path": "effects/#1/basicCorrection/tone/exposure", "value": 2})); let before = qa.frame(None, 0.5); diff --git a/crates/effects/src/blur2.rs b/crates/effects/src/blur2.rs index 929f41553..880ad16c5 100644 --- a/crates/effects/src/blur2.rs +++ b/crates/effects/src/blur2.rs @@ -1,6 +1,6 @@ //! Blur & Sharpen, batch 2: edge-preserving blurs (Bilateral, Smart), per-channel and map-driven //! blurs (Channel, Compound, CC Vector), bokeh (Camera Lens Blur), radial streaks and small -//! utilities (Reduce Interlace Flicker, CC Cross Blur). +//! utilities (Reduce Interlace Flicker, Cross Blur). use effectcraft_color::luminance; use effectcraft_keyframe::Value; @@ -507,9 +507,9 @@ fn camera_lens_blur(ctx: &EffectCtx, mut b: Buf) -> Buf { } // --------------------------------------------------------------------------------------------- -// CC Radial Fast Blur +// Fast Radial Blur -/// Transparent pixels CC Radial Fast Blur adds on every side of a `w` × `h` buffer with Center +/// Transparent pixels Fast Radial Blur adds on every side of a `w` × `h` buffer with Center /// at `c` (buffer pixels) and smear `s`: content `r` from Center streaks out to `r / (1 − s)`, /// so the farthest corner reaches `d · s / (1 − s)` past itself (at most 4096, as the other /// growing effects). Shared with the GPU path so both grow the same way. @@ -562,7 +562,7 @@ fn radial_fast_blur(ctx: &EffectCtx, mut b: Buf) -> Buf { } // --------------------------------------------------------------------------------------------- -// CC Vector Blur +// Vector Blur fn vector_blur(ctx: &EffectCtx, mut b: Buf) -> Buf { let amount = ctx.params.f("amount").max(0.0) * b.scale; @@ -616,7 +616,7 @@ fn vector_blur(ctx: &EffectCtx, mut b: Buf) -> Buf { } // --------------------------------------------------------------------------------------------- -// Reduce Interlace Flicker / CC Cross Blur +// Reduce Interlace Flicker / Cross Blur fn reduce_flicker(ctx: &EffectCtx, mut b: Buf) -> Buf { let s = ctx.params.f("softness").max(0.0) * b.scale; @@ -735,7 +735,7 @@ pub fn specs() -> Vec { ), spec( "ec.blur.ccradialfast", - "CC Radial Fast Blur", + "Fast Radial Blur", vec![ p("center", "Center", Value::Vec2([0.5, 0.5]), ParamUi::Point), p("amount", "Amount", num(50.0), slider(0.0, 100.0, 0.0, 100.0, 1)), @@ -745,7 +745,7 @@ pub fn specs() -> Vec { ), spec( "ec.blur.ccvector", - "CC Vector Blur", + "Vector Blur", vec![ p("type", "Type", Value::Enum(0), popup(&["Natural", "Constant Length", "Perpendicular", "Direction Center", "Direction Fading"])), p("amount", "Amount", num(10.0), slider(0.0, 500.0, 0.0, 100.0, 1)), @@ -765,7 +765,7 @@ pub fn specs() -> Vec { }, spec( "ec.blur.cccross", - "CC Cross Blur", + "Cross Blur", vec![ p("radiusX", "Radius X", num(10.0), slider(0.0, 500.0, 0.0, 100.0, 1)), p("radiusY", "Radius Y", num(10.0), slider(0.0, 500.0, 0.0, 100.0, 1)), diff --git a/crates/effects/src/blur3.rs b/crates/effects/src/blur3.rs index aee2a2713..6369a8ced 100644 --- a/crates/effects/src/blur3.rs +++ b/crates/effects/src/blur3.rs @@ -1,6 +1,6 @@ -//! Blur & Sharpen: CC Radial Blur and Camera-Shake Deblur. +//! Blur & Sharpen: Variable Radial Blur and Camera-Shake Deblur. //! -//! * **CC Radial Blur** — zoom (straight, fading, centred both ways) and rotational (plain or +//! * **Variable Radial Blur** — zoom (straight, fading, centred both ways) and rotational (plain or //! fading) blurs around a centre point, sampled along the ray / arc through each pixel with a //! sample count set by Quality. //! * **Camera-Shake Deblur** — frame-based restoration in the spirit of published video deblurring @@ -22,7 +22,7 @@ fn spec(id: &'static str, name: &'static str, params: Vec, ren EffectSpec { id, name, category: "Blur & Sharpen", params, render, gpu: false, float: true } } -// ---------------------------------------------------------------- CC Radial Blur +// ---------------------------------------------------------------- Variable Radial Blur pub const RADIAL_TYPES: [&str; 5] = ["Straight Zoom", "Fading Zoom", "Centered", "Rotate", "Rotate Fading"]; @@ -246,7 +246,7 @@ pub fn specs() -> Vec { vec![ spec( "ec.blur.ccradial", - "CC Radial Blur", + "Variable Radial Blur", vec![ p("type", "Type", Value::Enum(1), popup(&RADIAL_TYPES)), p("amount", "Amount", num(10.0), slider(-100.0, 100.0, -100.0, 100.0, 1)), diff --git a/crates/effects/src/channel2.rs b/crates/effects/src/channel2.rs index 5be3c94e7..ef391f6f1 100644 --- a/crates/effects/src/channel2.rs +++ b/crates/effects/src/channel2.rs @@ -1,5 +1,5 @@ //! Channel effects, batch 2: layer-to-layer combinations (Blend, Calculations, Compound -//! Arithmetic) and CC Composite. Second layers come from layer parameters through the effect +//! Arithmetic) and Source Composite. Second layers come from layer parameters through the effect //! host; with no layer chosen the effect uses the layer itself, as After Effects does. use effectcraft_color::{BlendMode, blend_pixel, hsl_to_rgb, luminance, rgb_to_hsl}; @@ -69,7 +69,7 @@ fn blend(ctx: &EffectCtx, mut b: Buf) -> Buf { // ---------------------------------------------------------------- Calculations -/// Blending modes offered by Calculations / CC Composite (menu order). +/// Blending modes offered by Calculations / Source Composite (menu order). const CALC_MODES: [BlendMode; 22] = [ BlendMode::Normal, BlendMode::Darken, @@ -150,7 +150,7 @@ fn calculations(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---------------------------------------------------------------- CC Composite +// ---------------------------------------------------------------- Source Composite const CC_COMPOSITE_MODES: [&str; 16] = [ "In Front", @@ -321,7 +321,7 @@ pub fn specs() -> Vec { ), spec( "ec.channel.cccomposite", - "CC Composite", + "Source Composite", vec![ p("opacity", "Opacity", num(100.0), pct()), p("compositeOriginal", "Composite Original", Value::Enum(0), popup(&CC_COMPOSITE_MODES)), diff --git a/crates/effects/src/color2.rs b/crates/effects/src/color2.rs index 25203cd7a..6639e649e 100644 --- a/crates/effects/src/color2.rs +++ b/crates/effects/src/color2.rs @@ -878,7 +878,7 @@ fn broadcast_colors(ctx: &EffectCtx, mut b: Buf) -> Buf { } // --------------------------------------------------------------------------------------------- -// CC Toner, CC Color Offset, CC Kernel +// Multi-Tone Tint, Channel Offset, Convolution Kernel fn cc_toner(ctx: &EffectCtx, mut b: Buf) -> Buf { let g = |id: &str| { @@ -1101,7 +1101,7 @@ pub fn specs() -> Vec { ), spec( "ec.color.cctoner", - "CC Toner", + "Multi-Tone Tint", vec![ p("tones", "Tones", Value::Enum(1), popup(&["Duotone", "Tritone", "Pentone"])), p("highlights", "Highlights", col(1.0, 1.0, 1.0), ParamUi::Color), @@ -1115,7 +1115,7 @@ pub fn specs() -> Vec { ), spec( "ec.color.cccoloroffset", - "CC Color Offset", + "Channel Offset", vec![ p("redPhase", "Red Phase", num(0.0), ParamUi::Angle), p("greenPhase", "Green Phase", num(0.0), ParamUi::Angle), @@ -1124,7 +1124,7 @@ pub fn specs() -> Vec { ], cc_color_offset, ), - spec("ec.color.cckernel", "CC Kernel", k_params, cc_kernel), + spec("ec.color.cckernel", "Convolution Kernel", k_params, cc_kernel), ] } diff --git a/crates/effects/src/color3.rs b/crates/effects/src/color3.rs index d4cdedd98..d0d398100 100644 --- a/crates/effects/src/color3.rs +++ b/crates/effects/src/color3.rs @@ -1,5 +1,5 @@ -//! Color Correction effects, batch 3: Change Color, Video Limiter, CC Color Neutralizer, -//! PS Arbitrary Map and Lumetri Color (Basic Correction, Creative, Curves, Color Wheels, +//! Color Correction effects, batch 3: Change Color, Video Limiter, Color Neutralizer, +//! PS Arbitrary Map and Color Grading (Basic Correction, Creative, Curves, Color Wheels, //! Vignette). use effectcraft_color::{hsl_to_rgb, luminance, rgb_to_hsl}; @@ -154,7 +154,7 @@ fn video_limiter(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---------------------------------------------------------------- CC Color Neutralizer +// ---------------------------------------------------------------- Color Neutralizer fn color_neutralizer(ctx: &EffectCtx, mut b: Buf) -> Buf { let pairs = [("shadowsUnbalance", "shadowsBalance"), ("midtonesUnbalance", "midtonesBalance"), ("highlightsUnbalance", "highlightsBalance")]; @@ -225,7 +225,7 @@ fn arbitrary_map(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---------------------------------------------------------------- Lumetri Color +// ---------------------------------------------------------------- Color Grading /// Smooth tone-curve adjustment: offsets for shadows/midtones/highlights (each -1..1), with the /// end points fixed. @@ -431,7 +431,7 @@ impl HslKey { } } -/// Lumetri Color: Basic Correction (input LUT, white balance, HDR range, tone, saturation), +/// Color Grading: Basic Correction (input LUT, white balance, HDR range, tone, saturation), /// Creative (look, adjustments), Curves (tone sliders, RGB curves, hue/saturation curves), /// Color Wheels, HSL Secondary (key, refine, correction), Vignette, in that order. fn lumetri(ctx: &EffectCtx, mut b: Buf) -> Buf { @@ -834,7 +834,7 @@ pub fn specs() -> Vec { ), spec( "ec.color.cccolorneutralizer", - "CC Color Neutralizer", + "Color Neutralizer", vec![ p("shadowsUnbalance", "Shadows Unbalance", col(0.0, 0.0, 0.0), ParamUi::Color), p("shadowsBalance", "Shadows Balance", col(0.0, 0.0, 0.0), ParamUi::Color), @@ -860,7 +860,7 @@ pub fn specs() -> Vec { ], arbitrary_map, ), - spec("ec.color.lumetri", "Lumetri Color", lum, lumetri), + spec("ec.color.lumetri", "Color Grading", lum, lumetri), ] } diff --git a/crates/effects/src/display_names.rs b/crates/effects/src/display_names.rs new file mode 100644 index 000000000..b30c00d46 --- /dev/null +++ b/crates/effects/src/display_names.rs @@ -0,0 +1,123 @@ +//! Display naming must not change file, command or script identities. +use crate::{find, instantiate, lookup, name_matches}; +use effectcraft_project::build::Ids; + +const RENAMED: &[(&str, &str, &str)] = &[ + ("ec.sim.ccballaction", "CC Ball Action", "Ball Grid"), + ("ec.distort.ccbendit", "CC Bend It", "Two-Point Bend"), + ("ec.distort.ccbender", "CC Bender", "Flexible Bend"), + ("ec.distort.ccblobbylize", "CC Blobbylize", "Organic Displacement"), + ("ec.stylize.ccblockload", "CC Block Load", "Block Reveal"), + ("ec.sim.ccbubbles", "CC Bubbles", "Bubbles"), + ("ec.stylize.ccburnfilm", "CC Burn Film", "Film Burn"), + ("ec.color.cccolorneutralizer", "CC Color Neutralizer", "Color Neutralizer"), + ("ec.color.cccoloroffset", "CC Color Offset", "Channel Offset"), + ("ec.channel.cccomposite", "CC Composite", "Source Composite"), + ("ec.blur.cccross", "CC Cross Blur", "Cross Blur"), + ("ec.perspective.cccylinder", "CC Cylinder", "Cylinder Wrap"), + ("ec.sim.ccdrizzle", "CC Drizzle", "Water Ripples"), + ("ec.perspective.ccenvironment", "CC Environment", "Environment Map"), + ("ec.distort.ccflomotion", "CC Flo Motion", "Dual Lens Warp"), + ("ec.time.ccforcemotionblur", "CC Force Motion Blur", "Temporal Motion Blur"), + ("ec.stylize.ccglass", "CC Glass", "Glass Relief"), + ("ec.transition.ccglasswipe", "CC Glass Wipe", "Glass Wipe"), + ("ec.generate.ccgluegun", "CC Glue Gun", "Paint Beads"), + ("ec.transition.ccgridwipe", "CC Grid Wipe", "Grid Wipe"), + ("ec.distort.ccgriddler", "CC Griddler", "Tile Grid"), + ("ec.sim.cchair", "CC Hair", "Surface Fibers"), + ("ec.stylize.cchextile", "CC HexTile", "Hexagonal Tiles"), + ("ec.transition.ccimagewipe", "CC Image Wipe", "Luminance Image Wipe"), + ("ec.transition.ccjaws", "CC Jaws", "Serrated Wipe"), + ("ec.stylize.cckaleida", "CC Kaleida", "Kaleidoscope"), + ("ec.color.cckernel", "CC Kernel", "Convolution Kernel"), + ("ec.distort.cclens", "CC Lens", "Lens Distortion"), + ("ec.generate.cclightburst", "CC Light Burst 2.5", "Radial Light Burst"), + ("ec.generate.cclightrays", "CC Light Rays", "Light Rays"), + ("ec.generate.cclightsweep", "CC Light Sweep", "Light Sweep"), + ("ec.transition.cclightwipe", "CC Light Wipe", "Light Wipe"), + ("ec.transition.cclinesweep", "CC Line Sweep", "Line Sweep"), + ("ec.sim.ccmrmercury", "CC Mr. Mercury", "Liquid Particles"), + ("ec.stylize.ccmrsmoothie", "CC Mr. Smoothie", "Palette Map"), + ("ec.utility.ccoverbrights", "CC Overbrights", "Out-of-Range Display"), + ("ec.distort.ccpageturn", "CC Page Turn", "Page Curl"), + ("ec.sim.ccparticlesystems2", "CC Particle Systems II", "Particle Emitter 2D"), + ("ec.sim.ccparticleworld", "CC Particle World", "Particle Emitter 3D"), + ("ec.sim.ccpixelpolly", "CC Pixel Polly", "Pixel Shatter"), + ("ec.stylize.ccplastic", "CC Plastic", "Plastic Shading"), + ("ec.distort.ccpowerpin", "CC Power Pin", "Perspective Pin"), + ("ec.blur.ccradial", "CC Radial Blur", "Variable Radial Blur"), + ("ec.blur.ccradialfast", "CC Radial Fast Blur", "Fast Radial Blur"), + ("ec.transition.ccradialscalewipe", "CC Radial ScaleWipe", "Radial Scale Wipe"), + ("ec.sim.ccrainfall", "CC Rainfall", "Rainfall"), + ("ec.stylize.ccrepetile", "CC RepeTile", "Edge Tile Repeat"), + ("ec.distort.ccripplepulse", "CC Ripple Pulse", "Pulsed Ripple"), + ("ec.transition.ccscalewipe", "CC Scale Wipe", "Scale Wipe"), + ("ec.sim.ccscatterize", "CC Scatterize", "Pixel Scatter"), + ("ec.key.ccsimplewireremoval", "CC Simple Wire Removal", "Line Removal"), + ("ec.distort.ccslant", "CC Slant", "Slant"), + ("ec.distort.ccsmear", "CC Smear", "Directional Smear"), + ("ec.sim.ccsnowfall", "CC Snowfall", "Snowfall"), + ("ec.perspective.ccsphere", "CC Sphere", "Sphere Wrap"), + ("ec.distort.ccsplit", "CC Split", "Split Warp"), + ("ec.distort.ccsplit2", "CC Split 2", "Dual Split Warp"), + ("ec.perspective.ccspotlight", "CC Spotlight", "Surface Spotlight"), + ("ec.sim.ccstarburst", "CC Star Burst", "Starfield"), + ("ec.generate.ccthreads", "CC Threads", "Woven Threads"), + ("ec.stylize.ccthreshold", "CC Threshold", "Channel Threshold"), + ("ec.stylize.ccthresholdrgb", "CC Threshold RGB", "RGB Threshold"), + ("ec.distort.cctiler", "CC Tiler", "Scaled Tiles"), + ("ec.color.cctoner", "CC Toner", "Multi-Tone Tint"), + ("ec.transition.cctwister", "CC Twister", "Twist Wipe"), + ("ec.blur.ccvector", "CC Vector Blur", "Vector Blur"), + ("ec.stylize.ccvignette", "CC Vignette", "Vignette"), + ("ec.transition.ccwarpomatic", "CC WarpoMatic", "Warp Dissolve"), + ("ec.time.ccwidetime", "CC Wide Time", "Temporal Blend"), + ("ec.color.lumetri", "Lumetri Color", "Color Grading"), + ("ec.obsolete.mochashape", "Mocha shape", "Tracked Shape Matte"), + ("ec.keying.keylight", "Key Light", "Screen Color Key"), +]; + +#[test] +fn descriptive_names_keep_every_legacy_lookup_and_search() { + for &(id, old, new) in RENAMED { + let spec = find(id).unwrap(); + assert_eq!(spec.name, new, "{id}"); + for query in [id.to_string(), old.to_string(), old.to_lowercase(), new.to_string()] { + assert_eq!(lookup(&query).map(|s| s.id), Some(id), "{query}"); + } + assert!(name_matches(spec, &old.to_lowercase()), "{old}"); + assert!(name_matches(spec, &new.to_lowercase()), "{new}"); + } + for alias in ["Keylight", "Keylight (1.2)", "Key Light"] { + assert_eq!(lookup(alias).map(|s| s.id), Some("ec.keying.keylight")); + } +} + +#[test] +fn descriptive_display_names_do_not_collide() { + let mut names = std::collections::HashSet::new(); + for spec in crate::registry() { + assert!(names.insert(spec.name.to_lowercase()), "duplicate name {}", spec.name); + let label = spec.name.to_lowercase(); + assert!(!label.starts_with("cc "), "{}", spec.name); + for mark in ["lumetri", "mercury", "mocha", "keylight"] { + assert!(!label.contains(mark), "{}", spec.name); + } + } +} + +#[test] +fn legacy_instance_names_and_parameter_data_survive_refresh() { + for &(id, old, _) in RENAMED { + let spec = find(id).unwrap(); + for stored in [old.to_string(), format!("{old} 2"), "My custom instance".to_string()] { + let mut next = 1; + let mut ids = Ids(&mut next); + let mut instance = instantiate(spec, &mut ids, &stored, [128.0, 72.0]); + let before = serde_json::to_value(&instance).unwrap(); + crate::migrate::upgrade_instance(spec, &mut instance, &mut ids, [128.0, 72.0]); + assert_eq!(instance.name, stored, "{id}: never rewrite a stored instance name"); + assert_eq!(serde_json::to_value(&instance).unwrap(), before, "{id}"); + } + } +} diff --git a/crates/effects/src/distort2.rs b/crates/effects/src/distort2.rs index 7add5fc58..bbd8738a8 100644 --- a/crates/effects/src/distort2.rs +++ b/crates/effects/src/distort2.rs @@ -1,6 +1,6 @@ //! Distort effects, batch 2: Turbulent Displace, Displacement Map (self as map), Optics -//! Compensation, Magnify, Mesh Warp, Bezier Warp, CC Bend It, CC Lens, CC Page Turn, CC Tiler, -//! CC Griddler. +//! Compensation, Magnify, Mesh Warp, Bezier Warp, Two-Point Bend, Lens Distortion, Page Curl, Scaled Tiles, +//! Tile Grid. //! //! Mesh Warp and Bezier Warp share a grid rasteriser: a (nx+1)×(ny+1) grid of destination points //! and matching source points is split into triangles, bucketed per output row and filled @@ -550,7 +550,7 @@ pub fn bezier_grid(ctx: &EffectCtx, offset: [f64; 2], scale: f64) -> (usize, Vec (n, dest, srcp) } -// ---------------------------------------------------------------- CC Bend It +// ---------------------------------------------------------------- Two-Point Bend fn bend_it(ctx: &EffectCtx, mut b: Buf) -> Buf { let mut beta = ctx.params.f("bend").to_radians(); @@ -606,7 +606,7 @@ fn bend_it(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---------------------------------------------------------------- CC Lens +// ---------------------------------------------------------------- Lens Distortion fn cc_lens(ctx: &EffectCtx, mut b: Buf) -> Buf { let c = b.to_px(ctx.params.v2("center")); @@ -629,7 +629,7 @@ fn cc_lens(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---------------------------------------------------------------- CC Page Turn +// ---------------------------------------------------------------- Page Curl fn page_turn(ctx: &EffectCtx, mut b: Buf) -> Buf { let f = b.to_px(ctx.params.v2("foldPosition")); @@ -679,7 +679,7 @@ fn page_turn(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---------------------------------------------------------------- CC Tiler / CC Griddler +// ---------------------------------------------------------------- Scaled Tiles / Tile Grid fn cc_tiler(ctx: &EffectCtx, mut b: Buf) -> Buf { let s = (ctx.params.f("scale") / 100.0).max(0.001); @@ -829,7 +829,7 @@ pub fn specs() -> Vec { ), spec( "ec.distort.ccbendit", - "CC Bend It", + "Two-Point Bend", vec![ p("bend", "Bend", num(0.0), ParamUi::Angle), p("start", "Start", pt(0.5, 0.2), ParamUi::Point), @@ -840,7 +840,7 @@ pub fn specs() -> Vec { ), spec( "ec.distort.cclens", - "CC Lens", + "Lens Distortion", vec![ p("center", "Center", pt(0.5, 0.5), ParamUi::Point), p("size", "Size", num(50.0), slider(0.0, 400.0, 0.0, 200.0, 1)), @@ -850,7 +850,7 @@ pub fn specs() -> Vec { ), spec( "ec.distort.ccpageturn", - "CC Page Turn", + "Page Curl", vec![ p("foldPosition", "Fold Position", pt(0.7, 0.7), ParamUi::Point), p("foldDirection", "Fold Direction", num(315.0), ParamUi::Angle), @@ -864,7 +864,7 @@ pub fn specs() -> Vec { ), spec( "ec.distort.cctiler", - "CC Tiler", + "Scaled Tiles", vec![ p("scale", "Scale", num(50.0), slider(1.0, 10000.0, 1.0, 200.0, 1)), p("center", "Center", pt(0.5, 0.5), ParamUi::Point), @@ -874,7 +874,7 @@ pub fn specs() -> Vec { ), spec( "ec.distort.ccgriddler", - "CC Griddler", + "Tile Grid", vec![ p("horizontalScale", "Horizontal Scale", num(100.0), slider(1.0, 1000.0, 1.0, 400.0, 1)), p("verticalScale", "Vertical Scale", num(100.0), slider(1.0, 1000.0, 1.0, 400.0, 1)), diff --git a/crates/effects/src/distort3.rs b/crates/effects/src/distort3.rs index a02ab5743..34fc282ed 100644 --- a/crates/effects/src/distort3.rs +++ b/crates/effects/src/distort3.rs @@ -1,5 +1,5 @@ -//! Distort effects, batch 3: CC Bender, CC Blobbylize, CC Power Pin, CC Ripple Pulse, CC Slant, -//! CC Smear, CC Split, CC Split 2, Smear and Reshape (mask driven), Twirl (Legacy), Warp (the +//! Distort effects, batch 3: Flexible Bend, Organic Displacement, Perspective Pin, Pulsed Ripple, Slant, +//! Directional Smear, Split Warp, Dual Split Warp, Smear and Reshape (mask driven), Twirl (Legacy), Warp (the //! fifteen warp styles) and Detail-preserving Upscale. //! //! All warps are inverse mapped: every output pixel finds the source point that lands on it. @@ -59,7 +59,7 @@ fn elastic_exp(i: u32) -> f64 { [1.0, 1.25, 1.5, 2.0, 2.5, 3.0, 3.5, 4.5][(i as usize).min(7)] } -// ---------------------------------------------------------------- CC Bender +// ---------------------------------------------------------------- Flexible Bend fn cc_bender(ctx: &EffectCtx, mut b: Buf) -> Buf { let amount = ctx.params.f("amount") / 100.0; @@ -107,7 +107,7 @@ fn norm3(v: [f64; 3]) -> [f64; 3] { [v[0] / l, v[1] / l, v[2] / l] } -/// f32 normal/dot helpers for the CC Blobbylize lighting pass. The GPU kernel runs in f32; +/// f32 normal/dot helpers for the Organic Displacement lighting pass. The GPU kernel runs in f32; /// matching its precision here keeps specular highlights within the CPU/GPU parity tolerance. fn norm3f(v: [f32; 3]) -> [f32; 3] { let l = (v[0] * v[0] + v[1] * v[1] + v[2] * v[2]).sqrt().max(1e-12); @@ -118,7 +118,7 @@ fn dot3f(a: [f32; 3], b: [f32; 3]) -> f32 { a[0] * b[0] + a[1] * b[1] + a[2] * b[2] } -// ---------------------------------------------------------------- CC Blobbylize +// ---------------------------------------------------------------- Organic Displacement fn cc_blobbylize(ctx: &EffectCtx, mut b: Buf) -> Buf { let soft = ctx.params.f("softness").max(0.0) * b.scale; @@ -221,7 +221,7 @@ fn cc_blobbylize(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---------------------------------------------------------------- CC Power Pin +// ---------------------------------------------------------------- Perspective Pin fn cc_power_pin(ctx: &EffectCtx, mut b: Buf) -> Buf { let (lw, lh) = (ctx.layer_size[0].max(1.0), ctx.layer_size[1].max(1.0)); @@ -304,7 +304,7 @@ fn cc_power_pin(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---------------------------------------------------------------- CC Ripple Pulse +// ---------------------------------------------------------------- Pulsed Ripple fn cc_ripple_pulse(ctx: &EffectCtx, mut b: Buf) -> Buf { let level = ctx.params.f("pulseLevel") / 100.0; @@ -350,7 +350,7 @@ fn cc_ripple_pulse(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---------------------------------------------------------------- CC Slant +// ---------------------------------------------------------------- Slant fn cc_slant(ctx: &EffectCtx, mut b: Buf) -> Buf { let k = ctx.params.f("slant") / 100.0; @@ -375,7 +375,7 @@ fn cc_slant(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---------------------------------------------------------------- CC Smear +// ---------------------------------------------------------------- Directional Smear fn cc_smear(ctx: &EffectCtx, mut b: Buf) -> Buf { let reach = ctx.params.f("reach") / 100.0; @@ -403,7 +403,7 @@ fn cc_smear(ctx: &EffectCtx, mut b: Buf) -> Buf { } /// The transparent pixels to add on every side of a buffer `size` pixels big (with `offset` and -/// `scale`) for CC Smear: it moves pixels by up to Reach × From→To, and they may move out to the +/// `scale`) for Directional Smear: it moves pixels by up to Reach × From→To, and they may move out to the /// layer bounds. A text or shape layer's buffer ends at its content while its bounds are /// comp-sized, so the smear was cut off at the content's box (#659). pub fn cc_smear_pad(ctx: &EffectCtx, size: [u32; 2], offset: [f64; 2], scale: f64) -> u32 { @@ -417,7 +417,7 @@ pub fn cc_smear_pad(ctx: &EffectCtx, size: [u32; 2], offset: [f64; 2], scale: f6 (moved.min(4096.0) as u32).min(crate::util::layer_cover_pad(ctx, size, offset, scale)) } -// ---------------------------------------------------------------- CC Split / CC Split 2 +// ---------------------------------------------------------------- Split Warp / Dual Split Warp fn split_impl(ctx: &EffectCtx, mut b: Buf, s1: f64, s2: f64) -> Buf { if s1 == 0.0 && s2 == 0.0 { @@ -913,7 +913,7 @@ pub fn specs() -> Vec { vec![ spec( "ec.distort.ccbender", - "CC Bender", + "Flexible Bend", vec![ p("amount", "Amount", num(0.0), slider(-200.0, 200.0, -100.0, 100.0, 1)), p("style", "Style", Value::Enum(0), popup(&["Bend", "Marilyn", "Sharp", "Boxer"])), @@ -925,7 +925,7 @@ pub fn specs() -> Vec { ), spec( "ec.distort.ccblobbylize", - "CC Blobbylize", + "Organic Displacement", vec![ p("blobLayer", "Blob Layer", Value::Layer(None), ParamUi::Layer), p("property", "Property", Value::Enum(0), popup(&crate::util::SRC_NAMES[..8])), @@ -947,7 +947,7 @@ pub fn specs() -> Vec { ), spec( "ec.distort.ccpowerpin", - "CC Power Pin", + "Perspective Pin", vec![ p("topLeft", "Top Left", pt(0.0, 0.0), ParamUi::Point), p("topRight", "Top Right", pt(1.0, 0.0), ParamUi::Point), @@ -964,7 +964,7 @@ pub fn specs() -> Vec { ), spec( "ec.distort.ccripplepulse", - "CC Ripple Pulse", + "Pulsed Ripple", vec![ p("center", "Center", pt(0.5, 0.5), ParamUi::Point), p("pulseLevel", "Pulse Level (animate)", num(0.0), slider(-1000.0, 1000.0, -100.0, 100.0, 1)), @@ -976,7 +976,7 @@ pub fn specs() -> Vec { ), spec( "ec.distort.ccslant", - "CC Slant", + "Slant", vec![ p("slant", "Slant", num(0.0), slider(-1000.0, 1000.0, -100.0, 100.0, 1)), p("stretching", "Stretching", Value::Bool(false), ParamUi::Checkbox), @@ -987,7 +987,7 @@ pub fn specs() -> Vec { ), spec( "ec.distort.ccsmear", - "CC Smear", + "Directional Smear", vec![ p("from", "From", pt(0.35, 0.5), ParamUi::Point), p("to", "To", pt(0.65, 0.5), ParamUi::Point), @@ -998,7 +998,7 @@ pub fn specs() -> Vec { ), spec( "ec.distort.ccsplit", - "CC Split", + "Split Warp", vec![ p("pointA", "Point A", pt(0.25, 0.5), ParamUi::Point), p("pointB", "Point B", pt(0.75, 0.5), ParamUi::Point), @@ -1008,7 +1008,7 @@ pub fn specs() -> Vec { ), spec( "ec.distort.ccsplit2", - "CC Split 2", + "Dual Split Warp", vec![ p("pointA", "Point A", pt(0.25, 0.5), ParamUi::Point), p("pointB", "Point B", pt(0.75, 0.5), ParamUi::Point), diff --git a/crates/effects/src/distort4.rs b/crates/effects/src/distort4.rs index b724a5830..9913c6ea5 100644 --- a/crates/effects/src/distort4.rs +++ b/crates/effects/src/distort4.rs @@ -1,6 +1,6 @@ -//! Distort: CC Flo Motion, Liquify and Rolling Shutter Repair. +//! Distort: Dual Lens Warp, Liquify and Rolling Shutter Repair. //! -//! * **CC Flo Motion** — two knots that pull the image toward themselves (positive amount) or +//! * **Dual Lens Warp** — two knots that pull the image toward themselves (positive amount) or //! push it away (negative), with a falloff exponent, optional tiling and supersampled //! antialiasing. //! * **Liquify** — brush strokes build a displacement mesh (a grid of layer-space offsets). The @@ -32,7 +32,7 @@ fn spec(id: &'static str, name: &'static str, params: Vec, ren EffectSpec { id, name, category: "Distort", params, render, gpu: false, float: true } } -// ---------------------------------------------------------------- CC Flo Motion +// ---------------------------------------------------------------- Dual Lens Warp fn flo_motion(ctx: &EffectCtx, mut b: Buf) -> Buf { let knots = [(ctx.params.v2("knot1"), ctx.params.f("amount1") / 100.0), (ctx.params.v2("knot2"), ctx.params.f("amount2") / 100.0)]; @@ -560,7 +560,7 @@ pub fn specs() -> Vec { vec![ spec( "ec.distort.ccflomotion", - "CC Flo Motion", + "Dual Lens Warp", vec![ p("knot1", "Knot 1", Value::Vec2([0.25, 0.5]), ParamUi::Point), p("amount1", "Amount 1", num(50.0), slider(-400.0, 100.0, -100.0, 100.0, 1)), diff --git a/crates/effects/src/generate2.rs b/crates/effects/src/generate2.rs index b4781b793..ad80cb9cd 100644 --- a/crates/effects/src/generate2.rs +++ b/crates/effects/src/generate2.rs @@ -1,5 +1,5 @@ //! Generate effects, batch 2: Cell Pattern (Worley), Ellipse, Lens Flare, Beam, Radio Waves, -//! Advanced Lightning, CC Light Rays, CC Light Burst 2.5, CC Light Sweep. +//! Advanced Lightning, Light Rays, Radial Light Burst, Light Sweep. //! //! All designs are original procedural renderings written from the public descriptions of what //! each effect produces. @@ -897,7 +897,7 @@ fn advanced_lightning(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---------------------------------------------------------------- CC Light Rays / Burst +// ---------------------------------------------------------------- Light Rays / Burst const RAY_STEPS: usize = 32; @@ -1007,7 +1007,7 @@ fn light_burst(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---------------------------------------------------------------- CC Light Sweep +// ---------------------------------------------------------------- Light Sweep fn light_sweep(ctx: &EffectCtx, mut b: Buf) -> Buf { let c = b.to_px(ctx.params.v2("center")); @@ -1192,7 +1192,7 @@ pub fn specs() -> Vec { ), spec( "ec.generate.cclightrays", - "CC Light Rays", + "Light Rays", vec![ p("intensity", "Intensity", num(100.0), slider(0.0, 600.0, 0.0, 200.0, 1)), p("center", "Center", pt(0.5, 0.5), ParamUi::Point), @@ -1207,7 +1207,7 @@ pub fn specs() -> Vec { ), spec( "ec.generate.cclightburst", - "CC Light Burst 2.5", + "Radial Light Burst", vec![ p("center", "Center", pt(0.5, 0.5), ParamUi::Point), p("intensity", "Intensity", num(100.0), slider(0.0, 600.0, 0.0, 200.0, 1)), @@ -1220,7 +1220,7 @@ pub fn specs() -> Vec { ), spec( "ec.generate.cclightsweep", - "CC Light Sweep", + "Light Sweep", vec![ p("center", "Center", pt(0.5, 0.5), ParamUi::Point), p("direction", "Direction", num(-30.0), ang()), diff --git a/crates/effects/src/generate3/registry.rs b/crates/effects/src/generate3/registry.rs index f3e08c2d5..baa493110 100644 --- a/crates/effects/src/generate3/registry.rs +++ b/crates/effects/src/generate3/registry.rs @@ -180,7 +180,7 @@ pub fn specs() -> Vec { ), spec( "ec.generate.ccgluegun", - "CC Glue Gun", + "Paint Beads", vec![ p("brushPosition", "Brush Position", pt(0.5, 0.5), ParamUi::Point), p("strokeWidth", "Stroke Width", num(25.0), slider(0.0, 500.0, 0.0, 100.0, 1)), @@ -194,7 +194,7 @@ pub fn specs() -> Vec { ), spec( "ec.generate.ccthreads", - "CC Threads", + "Woven Threads", vec![ p("width", "Width", num(50.0), slider(1.0, 1000.0, 1.0, 200.0, 1)), p("height", "Height", num(50.0), slider(1.0, 1000.0, 1.0, 200.0, 1)), diff --git a/crates/effects/src/keying2.rs b/crates/effects/src/keying2.rs index a03fe804d..5512d1820 100644 --- a/crates/effects/src/keying2.rs +++ b/crates/effects/src/keying2.rs @@ -317,7 +317,7 @@ fn unmult(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---------------------------------------------------------------- CC Simple Wire Removal +// ---------------------------------------------------------------- Line Removal fn wire_removal(ctx: &EffectCtx, mut b: Buf) -> Buf { let pa = ctx.params.v2("pointA"); @@ -464,7 +464,7 @@ pub fn specs() -> Vec { ), spec( "ec.key.ccsimplewireremoval", - "CC Simple Wire Removal", + "Line Removal", vec![ p("pointA", "Point A", Value::Vec2([0.25, 0.25]), ParamUi::Point), p("pointB", "Point B", Value::Vec2([0.75, 0.75]), ParamUi::Point), diff --git a/crates/effects/src/keylight.rs b/crates/effects/src/keylight.rs index 84085f4e3..fb36075cb 100644 --- a/crates/effects/src/keylight.rs +++ b/crates/effects/src/keylight.rs @@ -1,6 +1,6 @@ -//! Key Light — a full screen-colour keyer with the controls of After Effects' bundled +//! Screen Color Key — a full screen-colour keyer with the controls of After Effects' bundled //! "Keylight (1.2)" (that name is a trademark of its vendor, so the effect is registered as -//! **Key Light**; `lookup("Keylight (1.2)")` finds it through [`KEYLIGHT_ALIASES`]). +//! **Screen Color Key**; `lookup("Keylight (1.2)")` finds it through [`KEYLIGHT_ALIASES`]). //! //! The method is the textbook *screen difference* key, written from the public description of //! the controls: @@ -31,7 +31,7 @@ use crate::util::{Plane, gauss_plane, morph_frac, point_in_poly, premul, unpremu use crate::{Buf, EffectCtx, EffectSpec, col, num, p, popup, slider}; /// Other names the effect answers to in [`crate::lookup`]. -pub const KEYLIGHT_ALIASES: &[&str] = &["Keylight (1.2)", "Keylight"]; +pub const KEYLIGHT_ALIASES: &[&str] = &["Keylight (1.2)", "Keylight", "Key Light"]; pub const VIEWS: [&str; 11] = [ "Source", @@ -463,7 +463,7 @@ pub fn specs() -> Vec { let cc = |id: &'static str, name: &'static str| p(id, name, num(0.0), slider(-100.0, 100.0, -100.0, 100.0, 1)); vec![EffectSpec { id: "ec.keying.keylight", - name: "Key Light", + name: "Screen Color Key", category: "Keying", params: vec![ p("view", "View", Value::Enum(10), popup(&VIEWS)), @@ -622,7 +622,7 @@ mod tests { let spec = crate::find("ec.keying.keylight").unwrap(); let mut next = 1; let mut ids = Ids(&mut next); - let mut g = crate::instantiate(spec, &mut ids, "Key Light", [10.0, 10.0]); + let mut g = crate::instantiate(spec, &mut ids, "Screen Color Key", [10.0, 10.0]); // Flatten it the way older versions saved it. let mut flat = vec![]; g.walk_mut(&mut |p| flat.push(p.clone())); diff --git a/crates/effects/src/lib.rs b/crates/effects/src/lib.rs index bd239aa6f..0d78c3619 100644 --- a/crates/effects/src/lib.rs +++ b/crates/effects/src/lib.rs @@ -23,6 +23,8 @@ mod color3; mod color_fx; pub mod controls; pub mod crypto_select; +#[cfg(test)] +mod display_names; mod distort; mod distort2; mod distort3; @@ -36,6 +38,7 @@ mod keying; mod keying2; pub mod keylight; mod matte; + pub mod migrate; mod misc; pub mod mocha_shape; @@ -560,7 +563,7 @@ pub trait EffectHost: Sync { } /// Parameter `id` (a [`flatten_params`] id such as `birthRate`) of effect `effect_index` in /// the layer's stack (the running effect's [`EffectEnv::effect_index`]) at another **layer - /// time**: CC Particle World samples its Birth Rate at every step it simulates (#1373). + /// time**: Particle Emitter 3D samples its Birth Rate at every step it simulates (#1373). /// `None` when unavailable. fn param_at(&self, _effect_index: usize, _id: &str, _layer_time: f64) -> Option { None @@ -776,8 +779,82 @@ pub fn categories() -> Vec<&'static str> { v } -/// After Effects' third-party display names of effects we register under a generic name. -const ALIASES: &[(&str, &[&str])] = &[("ec.keying.keylight", keylight::KEYLIGHT_ALIASES)]; +/// Legacy display names accepted for saved scripts and searches. Never display these as +/// native feature names; stable effect IDs and external format match names stay unchanged. +const ALIASES: &[(&str, &[&str])] = &[ + ("ec.sim.ccballaction", &["CC Ball Action"]), + ("ec.distort.ccbendit", &["CC Bend It"]), + ("ec.distort.ccbender", &["CC Bender"]), + ("ec.distort.ccblobbylize", &["CC Blobbylize"]), + ("ec.stylize.ccblockload", &["CC Block Load"]), + ("ec.sim.ccbubbles", &["CC Bubbles"]), + ("ec.stylize.ccburnfilm", &["CC Burn Film"]), + ("ec.color.cccolorneutralizer", &["CC Color Neutralizer"]), + ("ec.color.cccoloroffset", &["CC Color Offset"]), + ("ec.channel.cccomposite", &["CC Composite"]), + ("ec.blur.cccross", &["CC Cross Blur"]), + ("ec.perspective.cccylinder", &["CC Cylinder"]), + ("ec.sim.ccdrizzle", &["CC Drizzle"]), + ("ec.perspective.ccenvironment", &["CC Environment"]), + ("ec.distort.ccflomotion", &["CC Flo Motion"]), + ("ec.time.ccforcemotionblur", &["CC Force Motion Blur"]), + ("ec.stylize.ccglass", &["CC Glass"]), + ("ec.transition.ccglasswipe", &["CC Glass Wipe"]), + ("ec.generate.ccgluegun", &["CC Glue Gun"]), + ("ec.transition.ccgridwipe", &["CC Grid Wipe"]), + ("ec.distort.ccgriddler", &["CC Griddler"]), + ("ec.sim.cchair", &["CC Hair"]), + ("ec.stylize.cchextile", &["CC HexTile"]), + ("ec.transition.ccimagewipe", &["CC Image Wipe"]), + ("ec.transition.ccjaws", &["CC Jaws"]), + ("ec.stylize.cckaleida", &["CC Kaleida"]), + ("ec.color.cckernel", &["CC Kernel"]), + ("ec.distort.cclens", &["CC Lens"]), + ("ec.generate.cclightburst", &["CC Light Burst 2.5"]), + ("ec.generate.cclightrays", &["CC Light Rays"]), + ("ec.generate.cclightsweep", &["CC Light Sweep"]), + ("ec.transition.cclightwipe", &["CC Light Wipe"]), + ("ec.transition.cclinesweep", &["CC Line Sweep"]), + ("ec.sim.ccmrmercury", &["CC Mr. Mercury"]), + ("ec.stylize.ccmrsmoothie", &["CC Mr. Smoothie"]), + ("ec.utility.ccoverbrights", &["CC Overbrights"]), + ("ec.distort.ccpageturn", &["CC Page Turn"]), + ("ec.sim.ccparticlesystems2", &["CC Particle Systems II"]), + ("ec.sim.ccparticleworld", &["CC Particle World"]), + ("ec.sim.ccpixelpolly", &["CC Pixel Polly"]), + ("ec.stylize.ccplastic", &["CC Plastic"]), + ("ec.distort.ccpowerpin", &["CC Power Pin"]), + ("ec.blur.ccradial", &["CC Radial Blur"]), + ("ec.blur.ccradialfast", &["CC Radial Fast Blur"]), + ("ec.transition.ccradialscalewipe", &["CC Radial ScaleWipe"]), + ("ec.sim.ccrainfall", &["CC Rainfall"]), + ("ec.stylize.ccrepetile", &["CC RepeTile"]), + ("ec.distort.ccripplepulse", &["CC Ripple Pulse"]), + ("ec.transition.ccscalewipe", &["CC Scale Wipe"]), + ("ec.sim.ccscatterize", &["CC Scatterize"]), + ("ec.key.ccsimplewireremoval", &["CC Simple Wire Removal"]), + ("ec.distort.ccslant", &["CC Slant"]), + ("ec.distort.ccsmear", &["CC Smear"]), + ("ec.sim.ccsnowfall", &["CC Snowfall"]), + ("ec.perspective.ccsphere", &["CC Sphere"]), + ("ec.distort.ccsplit", &["CC Split"]), + ("ec.distort.ccsplit2", &["CC Split 2"]), + ("ec.perspective.ccspotlight", &["CC Spotlight"]), + ("ec.sim.ccstarburst", &["CC Star Burst"]), + ("ec.generate.ccthreads", &["CC Threads"]), + ("ec.stylize.ccthreshold", &["CC Threshold"]), + ("ec.stylize.ccthresholdrgb", &["CC Threshold RGB"]), + ("ec.distort.cctiler", &["CC Tiler"]), + ("ec.color.cctoner", &["CC Toner"]), + ("ec.transition.cctwister", &["CC Twister"]), + ("ec.blur.ccvector", &["CC Vector Blur"]), + ("ec.stylize.ccvignette", &["CC Vignette"]), + ("ec.transition.ccwarpomatic", &["CC WarpoMatic"]), + ("ec.time.ccwidetime", &["CC Wide Time"]), + ("ec.color.lumetri", &["Lumetri Color"]), + ("ec.obsolete.mochashape", &["Mocha shape", "mocha shape"]), + ("ec.keying.keylight", keylight::KEYLIGHT_ALIASES), +]; /// Other names effect `id` answers to (in [`lookup`] and searches). pub fn aliases(id: &str) -> &'static [&'static str] { @@ -861,7 +938,7 @@ pub fn instantiate(spec: &EffectSpec, ids: &mut Ids, instance_name: &str, layer_ /// effects without their own table. pub const PARAM_GROUPS: &[(&str, &str)] = &[ // Color Correction: Exposure, Levels (Individual Controls), Change to Color, Colorama, - // Shadow/Highlight, Lumetri Color. + // Shadow/Highlight, Color Grading. ("master", "Master"), ("rgb", "RGB"), ("red", "Red"), @@ -990,7 +1067,7 @@ pub const PARAM_GROUPS: &[(&str, &str)] = &[ ("particleExploder", "Particle Exploder"), ("affects", "Affects"), ("options", "Options"), - // Keying, Matte, Obsolete (Key Light's groups are in `keylight::GROUPS`). + // Keying, Matte, Obsolete (Screen Color Key's groups are in `keylight::GROUPS`). ("ultraSettings", "Ultra Settings"), ("additionalForeground", "Additional Foreground"), ("additionalBackground", "Additional Background"), @@ -1075,7 +1152,7 @@ fn nested_group<'a>(g: &'a mut PropGroup, ids: &mut Ids, path: &str) -> Option<& } /// Effects the GPU compositor (`effectcraft-gpu`) implements with the CPU effect's semantics -/// (Mercury GPU Acceleration; the Effects & Presets GPU badge). Expression controls are +/// (GPU Acceleration; the Effects & Presets GPU badge). Expression controls are /// pass-throughs and count as GPU effects too. pub const GPU_EFFECTS: &[&str] = &[ "ec.blur.gaussian", @@ -1495,7 +1572,7 @@ mod tests { assert_eq!(grow_sides(lo, hi, 20, 10), Some([0, 0, 30, 20])); } - /// #2261: a 20 × 20 layer with CC Radial Fast Blur's Center far away grows to at most 16 Mpx; + /// #2261: a 20 × 20 layer with Fast Radial Blur's Center far away grows to at most 16 Mpx; /// big layers may still grow to four times their area, and small pads are untouched. #[test] fn padded_buffers_stay_within_the_budget() { diff --git a/crates/effects/src/mocha_shape.rs b/crates/effects/src/mocha_shape.rs index cf9e2bd88..c669580c6 100644 --- a/crates/effects/src/mocha_shape.rs +++ b/crates/effects/src/mocha_shape.rs @@ -1,4 +1,4 @@ -//! Matte ▸ Mocha shape: renders planar-tracked roto shapes as a matte. +//! Matte ▸ Tracked Shape Matte: renders planar-tracked roto shapes as a matte. //! //! Mocha's own clipboard / export formats are not publicly specified, so the effect reads shape //! data in a small documented JSON format of ours (in the hidden `shapeData` parameter, either the @@ -184,7 +184,7 @@ fn mocha_shape(ctx: &EffectCtx, mut b: Buf) -> Buf { pub fn specs() -> Vec { vec![EffectSpec { id: "ec.obsolete.mochashape", - name: "Mocha shape", + name: "Tracked Shape Matte", category: "Matte", params: vec![ p("blendMode", "Blend mode", Value::Enum(0), popup(&["Add", "Subtract", "Intersect", "Difference"])), diff --git a/crates/effects/src/perspective.rs b/crates/effects/src/perspective.rs index 24c561ecd..69c63caf9 100644 --- a/crates/effects/src/perspective.rs +++ b/crates/effects/src/perspective.rs @@ -1,5 +1,5 @@ -//! Perspective effects (batch 2): Bevel Alpha, Bevel Edges, Radial Shadow, CC Cylinder, -//! CC Sphere and CC Spotlight. +//! Perspective effects (batch 2): Bevel Alpha, Bevel Edges, Radial Shadow, Cylinder Wrap, +//! Sphere Wrap and Surface Spotlight. //! //! Angles follow the convention used by Drop Shadow: measured clockwise from "up", so a light //! angle `a` sits in the direction `(sin a, -cos a)` (y grows downwards). 3D vectors use x right, @@ -158,7 +158,7 @@ fn radial_shadow(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -/// Phong-style shading shared by CC Cylinder and CC Sphere. +/// Phong-style shading shared by Cylinder Wrap and Sphere Wrap. struct Shading { l: [f64; 3], color: [f32; 4], @@ -451,11 +451,11 @@ pub fn specs() -> Vec { ], radial_shadow, ), - spec("ec.perspective.cccylinder", "CC Cylinder", cyl, cylinder), - spec("ec.perspective.ccsphere", "CC Sphere", sph, sphere), + spec("ec.perspective.cccylinder", "Cylinder Wrap", cyl, cylinder), + spec("ec.perspective.ccsphere", "Sphere Wrap", sph, sphere), spec( "ec.perspective.ccspotlight", - "CC Spotlight", + "Surface Spotlight", vec![ p("from", "From", pt(0.3, 0.2), ParamUi::Point), p("to", "To", pt(0.5, 0.5), ParamUi::Point), diff --git a/crates/effects/src/perspective2.rs b/crates/effects/src/perspective2.rs index 13846607f..2bc7e3e7e 100644 --- a/crates/effects/src/perspective2.rs +++ b/crates/effects/src/perspective2.rs @@ -1,4 +1,4 @@ -//! Perspective effects, batch 2: CC Environment (reflection mapping of an environment layer +//! Perspective effects, batch 2: Environment Map (reflection mapping of an environment layer //! onto the layer's luminance/alpha relief) and 3D Glasses (stereo pairs and anaglyphs from a //! left and right view layer). @@ -17,7 +17,7 @@ fn spec(id: &'static str, name: &'static str, params: Vec, ren EffectSpec { id, name, category: "Perspective", params, render, gpu: false, float: true } } -// ---------------------------------------------------------------- CC Environment +// ---------------------------------------------------------------- Environment Map /// Environment direction (x right, y down, z towards the viewer) → normalised map coordinates. fn env_uv(mapping: u32, r: [f64; 3]) -> (f64, f64) { @@ -194,7 +194,7 @@ pub fn specs() -> Vec { vec![ spec( "ec.perspective.ccenvironment", - "CC Environment", + "Environment Map", vec![ p("environment", "Environment", Value::Layer(None), ParamUi::Layer), p("mapping", "Mapping", Value::Enum(0), popup(&["Spherical", "Probe", "Vertical Cross"])), diff --git a/crates/effects/src/sim/registry.rs b/crates/effects/src/sim/registry.rs index f55b99e27..4df07c50a 100644 --- a/crates/effects/src/sim/registry.rs +++ b/crates/effects/src/sim/registry.rs @@ -32,7 +32,7 @@ pub fn specs() -> Vec { vec![ spec( "ec.sim.ccrainfall", - "CC Rainfall", + "Rainfall", vec![ p("drops", "Drops", num(5000.0), slider(0.0, 100_000.0, 0.0, 20_000.0, 0)), p("size", "Size", num(1.0), slider(0.0, 50.0, 0.0, 10.0, 2)), @@ -53,7 +53,7 @@ pub fn specs() -> Vec { ), spec( "ec.sim.ccsnowfall", - "CC Snowfall", + "Snowfall", vec![ p("flakes", "Flakes", num(10_000.0), slider(0.0, 200_000.0, 0.0, 50_000.0, 0)), p("size", "Size", num(3.0), slider(0.0, 50.0, 0.0, 20.0, 2)), @@ -79,7 +79,7 @@ pub fn specs() -> Vec { ), spec( "ec.sim.ccbubbles", - "CC Bubbles", + "Bubbles", vec![ p("bubbleAmount", "Bubble Amount", num(100.0), slider(0.0, 10_000.0, 0.0, 1000.0, 0)), p("bubbleSpeed", "Bubble Speed", num(0.5), slider(-10.0, 10.0, -2.0, 2.0, 2)), @@ -93,7 +93,7 @@ pub fn specs() -> Vec { ), spec( "ec.sim.ccdrizzle", - "CC Drizzle", + "Water Ripples", vec![ p("dripRate", "Drip Rate", num(10.0), slider(0.0, 200.0, 0.0, 50.0, 2)), p("longevity", "Longevity (sec)", num(1.0), slider(0.0, 30.0, 0.0, 5.0, 2)), @@ -114,7 +114,7 @@ pub fn specs() -> Vec { ), spec( "ec.sim.ccstarburst", - "CC Star Burst", + "Starfield", vec![ p("scatter", "Scatter", num(100.0), slider(0.0, 1000.0, 0.0, 300.0, 1)), p("speed", "Speed", num(1.0), slider(-10.0, 10.0, -4.0, 4.0, 2)), @@ -127,7 +127,7 @@ pub fn specs() -> Vec { ), spec( "ec.sim.ccparticleworld", - "CC Particle World", + "Particle Emitter 3D", vec![ p("birthRate", "Birth Rate", num(0.5), slider(0.0, 100.0, 0.0, 10.0, 2)), p("longevity", "Longevity (sec)", num(1.0), slider(0.0, 100.0, 0.0, 10.0, 2)), @@ -170,7 +170,7 @@ pub fn specs() -> Vec { ), spec( "ec.sim.ccparticlesystems2", - "CC Particle Systems II", + "Particle Emitter 2D", vec![ p("birthRate", "Birth Rate", num(2.0), slider(0.0, 100.0, 0.0, 20.0, 2)), p("longevity", "Longevity (sec)", num(1.0), slider(0.0, 100.0, 0.0, 10.0, 2)), @@ -198,7 +198,7 @@ pub fn specs() -> Vec { ), spec( "ec.sim.ccmrmercury", - "CC Mr. Mercury", + "Liquid Particles", vec![ p("radiusX", "Radius X", num(50.0), slider(0.0, 2000.0, 0.0, 300.0, 1)), p("radiusY", "Radius Y", num(50.0), slider(0.0, 2000.0, 0.0, 300.0, 1)), diff --git a/crates/effects/src/sim2/registry.rs b/crates/effects/src/sim2/registry.rs index 333916a16..dc64b7097 100644 --- a/crates/effects/src/sim2/registry.rs +++ b/crates/effects/src/sim2/registry.rs @@ -79,7 +79,7 @@ pub fn specs() -> Vec { vec![ spec( "ec.sim.ccballaction", - "CC Ball Action", + "Ball Grid", vec![ p("scatter", "Scatter", num(0.0), slider(0.0, 2000.0, 0.0, 300.0, 1)), p("rotationAxis", "Rotation Axis", Value::Enum(0), popup(&["X Axis", "Y Axis", "Z Axis", "XY Axis", "XZ Axis", "YZ Axis", "XYZ Axis"])), @@ -94,7 +94,7 @@ pub fn specs() -> Vec { ), spec( "ec.sim.ccpixelpolly", - "CC Pixel Polly", + "Pixel Shatter", vec![ p("force", "Force", num(100.0), slider(-1000.0, 1000.0, -300.0, 300.0, 1)), p("gravity", "Gravity", num(1.0), slider(-20.0, 20.0, -5.0, 5.0, 2)), @@ -111,7 +111,7 @@ pub fn specs() -> Vec { ), spec( "ec.sim.ccscatterize", - "CC Scatterize", + "Pixel Scatter", vec![ p("scatter", "Scatter", num(0.0), slider(0.0, 1000.0, 0.0, 200.0, 1)), p("rightTwist", "Right Twist", num(0.0), ParamUi::Angle), diff --git a/crates/effects/src/sim3.rs b/crates/effects/src/sim3.rs index 88a16d981..c2a286390 100644 --- a/crates/effects/src/sim3.rs +++ b/crates/effects/src/sim3.rs @@ -1,4 +1,4 @@ -//! Simulation: Particle Playground and CC Hair. +//! Simulation: Particle Playground and Surface Fibers. //! //! **Particle Playground** is a deterministic 2D particle system stepped from layer time 0 at //! [`SPS`] steps per second through [`SimCache`] (seeking anywhere gives the same frame as @@ -17,7 +17,7 @@ //! being rendered (their pixels are part of the cache key). Particles replace the layer's own //! pixels, as in After Effects. //! -//! **CC Hair** grows strands from the layer's opaque pixels (Density per 1 000 px²), each a +//! **Surface Fibers** grows strands from the layer's opaque pixels (Density per 1 000 px²), each a //! quadratic curve of Length that droops with Weight, optionally steered and scaled by a hairfall //! map layer (luminance → length, horizontal/vertical gradient → lean), and shades them with a //! Kajiya–Kay-style strand model (diffuse ∝ sin(tangent, light), specular from the half vector). @@ -934,7 +934,7 @@ impl PgPlan { } } -// ---------------------------------------------------------------- CC Hair +// ---------------------------------------------------------------- Surface Fibers fn cc_hair(ctx: &EffectCtx, b: Buf) -> Buf { let Some(mut plan) = hair_plan(ctx, &b) else { return b }; @@ -942,7 +942,7 @@ fn cc_hair(ctx: &EffectCtx, b: Buf) -> Buf { plan.finish(b) } -/// CC Hair's strands as line sprites (each coloured from its root, see [`Tint::Root`]); +/// Surface Fibers's strands as line sprites (each coloured from its root, see [`Tint::Root`]); /// `None` = no hair (the layer passes through). pub(crate) fn hair_plan(ctx: &EffectCtx, b: &Buf) -> Option { let pr = ctx.params; @@ -1144,7 +1144,7 @@ pub fn specs() -> Vec { spec("ec.sim.particleplayground", "Particle Playground", pg, particle_playground), spec( "ec.sim.cchair", - "CC Hair", + "Surface Fibers", vec![ sp("length", "Length", px(30.0, 200.0)), p("thickness", "Thickness", num(1.0), slider(0.05, 20.0, 0.1, 5.0, 2)), diff --git a/crates/effects/src/stylize2.rs b/crates/effects/src/stylize2.rs index 94eda6370..247854352 100644 --- a/crates/effects/src/stylize2.rs +++ b/crates/effects/src/stylize2.rs @@ -343,7 +343,7 @@ fn brush_strokes(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---- CC Kaleida ---- +// ---- Kaleidoscope ---- fn kaleida(ctx: &EffectCtx, mut b: Buf) -> Buf { let c = b.to_px(ctx.params.v2("center")); @@ -368,7 +368,7 @@ fn kaleida(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---- CC RepeTile ---- +// ---- Edge Tile Repeat ---- #[inline] fn tile_coord(v: f64, size: f64) -> (i64, f64) { @@ -491,7 +491,7 @@ fn color_emboss(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---- CC Vignette ---- +// ---- Vignette ---- fn vignette(ctx: &EffectCtx, mut b: Buf) -> Buf { let amt = ctx.params.f("amount") as f32 / 100.0; @@ -523,7 +523,7 @@ fn vignette(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ---- CC Threshold / CC Threshold RGB ---- +// ---- Channel Threshold / RGB Threshold ---- fn cc_threshold(ctx: &EffectCtx, mut b: Buf) -> Buf { let t = ctx.params.f("threshold") as f32 / 255.0; @@ -669,7 +669,7 @@ pub fn specs() -> Vec { ), spec( "ec.stylize.cckaleida", - "CC Kaleida", + "Kaleidoscope", vec![ p("center", "Center", pt(0.5, 0.5), ParamUi::Point), p("size", "Size", num(100.0), slider(1.0, 1000.0, 1.0, 400.0, 1)), @@ -680,7 +680,7 @@ pub fn specs() -> Vec { ), spec( "ec.stylize.ccrepetile", - "CC RepeTile", + "Edge Tile Repeat", vec![ p("expandRight", "Expand Right", num(0.0), slider(0.0, 4000.0, 0.0, 500.0, 0)), p("expandLeft", "Expand Left", num(0.0), slider(0.0, 4000.0, 0.0, 500.0, 0)), @@ -718,7 +718,7 @@ pub fn specs() -> Vec { ), spec( "ec.stylize.ccvignette", - "CC Vignette", + "Vignette", vec![ p("amount", "Amount", num(50.0), slider(-100.0, 100.0, -100.0, 100.0, 1)), p("angleOfView", "Angle of View", num(60.0), slider(0.0, 179.0, 0.0, 179.0, 1)), @@ -729,7 +729,7 @@ pub fn specs() -> Vec { ), spec( "ec.stylize.ccthreshold", - "CC Threshold", + "Channel Threshold", vec![ p("threshold", "Threshold", num(127.0), thr()), p("channel", "Channel", Value::Enum(0), popup(&["Luminance", "RGB", "Saturation", "Alpha"])), @@ -740,7 +740,7 @@ pub fn specs() -> Vec { ), spec( "ec.stylize.ccthresholdrgb", - "CC Threshold RGB", + "RGB Threshold", vec![ p("redThreshold", "Red Threshold", num(127.0), thr()), p("greenThreshold", "Green Threshold", num(127.0), thr()), diff --git a/crates/effects/src/stylize3.rs b/crates/effects/src/stylize3.rs index e8a141cf4..1121f737b 100644 --- a/crates/effects/src/stylize3.rs +++ b/crates/effects/src/stylize3.rs @@ -1,5 +1,5 @@ -//! Stylize effects, batch 3: CC Block Load, CC Burn Film, CC Glass, CC HexTile, CC Mr. Smoothie -//! and CC Plastic. +//! Stylize effects, batch 3: Block Reveal, Film Burn, Glass Relief, Hexagonal Tiles, Palette Map +//! and Plastic Shading. //! //! Written from the public descriptions of what these effects do (progressive block loading, //! burning film, bump-mapped glass / plastic surfaces lit by an effect light, hexagonal tiling, @@ -27,7 +27,7 @@ fn pt(x: f64, y: f64) -> Value { Value::Vec2([x, y]) } -// ------------------------------------------------------------------ CC Block Load +// ------------------------------------------------------------------ Block Reveal /// Mean colour of every `s`×`s` block (grid of `ceil(w/s)`×`ceil(h/s)`). fn block_means(img: &Image, s: usize) -> (usize, usize, Vec) { @@ -135,7 +135,7 @@ fn block_load(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ------------------------------------------------------------------ CC Burn Film +// ------------------------------------------------------------------ Film Burn fn burn_film(ctx: &EffectCtx, mut b: Buf) -> Buf { let burn = (ctx.params.f("burn") / 100.0).clamp(0.0, 1.0) as f32; @@ -180,7 +180,7 @@ fn burn_film(ctx: &EffectCtx, mut b: Buf) -> Buf { const BUMP_PROPS: [&str; 6] = ["Red", "Green", "Blue", "Alpha", "Luminance", "Lightness"]; -/// The bump-map layer parameter: CC Glass's Bump Map, CC Plastic's Bump Layer. +/// The bump-map layer parameter: Glass Relief's Bump Map, Plastic Shading's Bump Layer. pub fn bump_layer_id(ctx: &EffectCtx) -> &'static str { if ctx.params.get("bumpLayer").is_some() { "bumpLayer" } else { "bumpMap" } } @@ -208,7 +208,7 @@ fn height_field(ctx: &EffectCtx, b: &Buf) -> Plane { pl } -/// The effect light and surface of CC Glass / CC Plastic (shared with the GPU compositor). +/// The effect light and surface of Glass Relief / Plastic Shading (shared with the GPU compositor). pub struct BumpLight { pub intensity: f32, pub color: [f32; 3], @@ -342,7 +342,7 @@ fn plastic(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ------------------------------------------------------------------ CC HexTile +// ------------------------------------------------------------------ Hexagonal Tiles /// Axial hex cell (pointy-top) containing (x, y) for circumradius `r`; returns the cell centre /// and integer cell coordinates. @@ -418,7 +418,7 @@ fn hextile(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ------------------------------------------------------------------ CC Mr. Smoothie +// ------------------------------------------------------------------ Palette Map const SMOOTHIE_PROPS: [&str; 8] = ["Red", "Green", "Blue", "Alpha", "Luminance", "Lightness", "Hue", "Saturation"]; @@ -518,7 +518,7 @@ pub fn specs() -> Vec { vec![ spec( "ec.stylize.ccblockload", - "CC Block Load", + "Block Reveal", vec![ p("completion", "Completion", num(0.0), pct()), p("scanlines", "Scanlines", Value::Bool(true), ParamUi::Checkbox), @@ -530,7 +530,7 @@ pub fn specs() -> Vec { ), spec( "ec.stylize.ccburnfilm", - "CC Burn Film", + "Film Burn", vec![ p("burn", "Burn", num(0.0), pct()), p("center", "Center", pt(0.5, 0.5), ParamUi::Point), @@ -538,10 +538,10 @@ pub fn specs() -> Vec { ], burn_film, ), - spec("ec.stylize.ccglass", "CC Glass", glass_p, glass), + spec("ec.stylize.ccglass", "Glass Relief", glass_p, glass), spec( "ec.stylize.cchextile", - "CC HexTile", + "Hexagonal Tiles", vec![ p("render", "Render", Value::Enum(0), popup(&["Normal", "Mirrored", "Rotated"])), p("radius", "Radius", num(50.0), slider(1.0, 4000.0, 2.0, 500.0, 1)), @@ -553,7 +553,7 @@ pub fn specs() -> Vec { ), spec( "ec.stylize.ccmrsmoothie", - "CC Mr. Smoothie", + "Palette Map", vec![ p("flowLayer", "Flow Layer", Value::Layer(None), ParamUi::Layer), p("property", "Property", Value::Enum(4), popup(&SMOOTHIE_PROPS)), @@ -565,7 +565,7 @@ pub fn specs() -> Vec { ], smoothie, ), - spec("ec.stylize.ccplastic", "CC Plastic", plastic_p, plastic), + spec("ec.stylize.ccplastic", "Plastic Shading", plastic_p, plastic), ] } diff --git a/crates/effects/src/time_fx.rs b/crates/effects/src/time_fx.rs index 79b0ce479..b9d20e2a7 100644 --- a/crates/effects/src/time_fx.rs +++ b/crates/effects/src/time_fx.rs @@ -1,9 +1,9 @@ //! Time effects (Effect > Time): Echo, Posterize Time, Time Difference, Time Displacement, -//! Timewarp, CC Force Motion Blur, CC Wide Time and Pixel Motion Blur. +//! Timewarp, Temporal Motion Blur, Temporal Blend and Pixel Motion Blur. //! //! These read the layer at *other* layer times through [`EffectHost::self_at`]: its source with //! its masks and the effects applied before them, as After Effects renders them (SceneYard: -//! Echo after CC Particle Systems II echoes the fireworks, not the black solid under them; +//! Echo after Particle Emitter 2D echoes the fireworks, not the black solid under them; //! Posterize Time after Turbulent Displace steps the displacement). Timewarp is the exception: //! it retimes the layer's source with its masks and ignores the effects above it (After //! Effects 2026: a red solid with a Gradient Ramp and then Timewarp shows the red solid). @@ -123,7 +123,7 @@ pub fn specs() -> Vec { ), spec( "ec.time.ccforcemotionblur", - "CC Force Motion Blur", + "Temporal Motion Blur", vec![ p("motionBlurLevels", "Motion Blur Levels", num(8.0), slider(2.0, 64.0, 2.0, 32.0, 0)), p("overrideShutterAngle", "Override Shutter Angle", Value::Bool(true), ParamUi::Checkbox), @@ -134,7 +134,7 @@ pub fn specs() -> Vec { ), spec( "ec.time.ccwidetime", - "CC Wide Time", + "Temporal Blend", vec![ p("forwardSteps", "Forward Steps", num(3.0), slider(0.0, 45.0, 0.0, 15.0, 0)), p("backwardSteps", "Backward Steps", num(3.0), slider(0.0, 45.0, 0.0, 15.0, 0)), @@ -994,7 +994,7 @@ fn matte_image(m: &[f32], like: &Image) -> Image { out } -// ---------------------------------------------------------------- CC Force Motion Blur / CC Wide Time / Pixel Motion Blur +// ---------------------------------------------------------------- Temporal Motion Blur / Temporal Blend / Pixel Motion Blur fn force_motion_blur(ctx: &EffectCtx, b: Buf) -> Buf { let n = ctx.params.f("motionBlurLevels").round().clamp(2.0, 64.0) as usize; diff --git a/crates/effects/src/transition.rs b/crates/effects/src/transition.rs index e465ffd1b..da3e85694 100644 --- a/crates/effects/src/transition.rs +++ b/crates/effects/src/transition.rs @@ -1,5 +1,5 @@ //! Transition effects (batch 2): Block Dissolve, Gradient Wipe (gradient layer or self), Iris Wipe, Card -//! Wipe (3D cards with camera, lighting and jitter), CC Grid Wipe, CC Radial ScaleWipe, CC Scale Wipe and CC Light Wipe. +//! Wipe (3D cards with camera, lighting and jitter), Grid Wipe, Radial Scale Wipe, Scale Wipe and Light Wipe. //! //! Every transition is the identity at 0 % completion. Angles are clockwise from "up". @@ -595,7 +595,7 @@ pub fn specs() -> Vec { ), spec( "ec.transition.ccgridwipe", - "CC Grid Wipe", + "Grid Wipe", vec![ cc_done(), p("center", "Center", pt(0.5, 0.5), ParamUi::Point), @@ -609,13 +609,13 @@ pub fn specs() -> Vec { ), spec( "ec.transition.ccradialscalewipe", - "CC Radial ScaleWipe", + "Radial Scale Wipe", vec![cc_done(), p("center", "Center", pt(0.5, 0.5), ParamUi::Point), p("reverse", "Reverse Transition", Value::Bool(false), ParamUi::Checkbox)], radial_scale_wipe, ), spec( "ec.transition.ccscalewipe", - "CC Scale Wipe", + "Scale Wipe", vec![ p("stretch", "Stretch", num(0.0), slider(0.0, 1000.0, 0.0, 50.0, 2)), p("center", "Center", pt(0.5, 0.5), ParamUi::Point), @@ -625,7 +625,7 @@ pub fn specs() -> Vec { ), spec( "ec.transition.cclightwipe", - "CC Light Wipe", + "Light Wipe", vec![ cc_done(), p("center", "Center", pt(0.5, 0.5), ParamUi::Point), diff --git a/crates/effects/src/transition2.rs b/crates/effects/src/transition2.rs index 2e1738b28..6f19a660b 100644 --- a/crates/effects/src/transition2.rs +++ b/crates/effects/src/transition2.rs @@ -1,5 +1,5 @@ -//! Transition effects, batch 2: CC Glass Wipe, CC Image Wipe, CC Jaws, CC Line Sweep, -//! CC Twister and CC WarpoMatic. +//! Transition effects, batch 2: Glass Wipe, Luminance Image Wipe, Serrated Wipe, Line Sweep, +//! Twist Wipe and Warp Dissolve. //! //! Written from the public descriptions of these transitions (gradient-driven wipes with glass //! refraction or warping, jagged "jaws" opening, staggered line sweeps, a ribbon twist that @@ -68,7 +68,7 @@ fn grad(pl: &Plane, x: usize, y: usize) -> (f32, f32) { ((pl.get_clamped(xi + 1, yi) - pl.get_clamped(xi - 1, yi)) * 0.5, (pl.get_clamped(xi, yi + 1) - pl.get_clamped(xi, yi - 1)) * 0.5) } -// ------------------------------------------------------------------ CC Glass Wipe +// ------------------------------------------------------------------ Glass Wipe fn glass_wipe(ctx: &EffectCtx, mut b: Buf) -> Buf { let c = completion(ctx); @@ -105,7 +105,7 @@ fn glass_wipe(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ------------------------------------------------------------------ CC Image Wipe +// ------------------------------------------------------------------ Luminance Image Wipe fn image_wipe(ctx: &EffectCtx, mut b: Buf) -> Buf { let c = completion(ctx); @@ -132,7 +132,7 @@ fn image_wipe(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ------------------------------------------------------------------ CC Jaws +// ------------------------------------------------------------------ Serrated Wipe fn jaws(ctx: &EffectCtx, mut b: Buf) -> Buf { let c = completion(ctx) as f64; @@ -193,7 +193,7 @@ fn jaws(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ------------------------------------------------------------------ CC Line Sweep +// ------------------------------------------------------------------ Line Sweep fn line_sweep(ctx: &EffectCtx, mut b: Buf) -> Buf { let c = completion(ctx) as f64; @@ -235,7 +235,7 @@ fn line_sweep(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ------------------------------------------------------------------ CC Twister +// ------------------------------------------------------------------ Twist Wipe fn twister(ctx: &EffectCtx, mut b: Buf) -> Buf { let c = completion(ctx) as f64; @@ -283,7 +283,7 @@ fn twister(ctx: &EffectCtx, mut b: Buf) -> Buf { b } -// ------------------------------------------------------------------ CC WarpoMatic +// ------------------------------------------------------------------ Warp Dissolve fn warpomatic(ctx: &EffectCtx, mut b: Buf) -> Buf { let c = completion(ctx); @@ -350,7 +350,7 @@ pub fn specs() -> Vec { vec![ spec( "ec.transition.ccglasswipe", - "CC Glass Wipe", + "Glass Wipe", vec![ done(), p("layerToReveal", "Layer to Reveal", Value::Layer(None), ParamUi::Layer), @@ -362,7 +362,7 @@ pub fn specs() -> Vec { ), spec( "ec.transition.ccimagewipe", - "CC Image Wipe", + "Luminance Image Wipe", vec![ done(), p("borderSoftness", "Border Softness", num(0.0), pct()), @@ -376,7 +376,7 @@ pub fn specs() -> Vec { ), spec( "ec.transition.ccjaws", - "CC Jaws", + "Serrated Wipe", vec![ done(), p("center", "Center", pt(0.5, 0.5), ParamUi::Point), @@ -389,7 +389,7 @@ pub fn specs() -> Vec { ), spec( "ec.transition.cclinesweep", - "CC Line Sweep", + "Line Sweep", vec![ done(), p("direction", "Direction", num(0.0), ParamUi::Angle), @@ -401,7 +401,7 @@ pub fn specs() -> Vec { ), spec( "ec.transition.cctwister", - "CC Twister", + "Twist Wipe", vec![ done(), p("backside", "Backside", Value::Layer(None), ParamUi::Layer), @@ -413,7 +413,7 @@ pub fn specs() -> Vec { ), spec( "ec.transition.ccwarpomatic", - "CC WarpoMatic", + "Warp Dissolve", vec![ done(), p("layerToReveal", "Layer to Reveal", Value::Layer(None), ParamUi::Layer), diff --git a/crates/effects/src/utility.rs b/crates/effects/src/utility.rs index e87c6d3ff..fca9d607e 100644 --- a/crates/effects/src/utility.rs +++ b/crates/effects/src/utility.rs @@ -365,7 +365,7 @@ pub fn specs() -> Vec { spec("ec.utility.growbounds", "Grow Bounds", vec![p("pixels", "Pixels", num(0.0), slider(0.0, 4000.0, 0.0, 500.0, 0))], grow_bounds), spec( "ec.utility.ccoverbrights", - "CC Overbrights", + "Out-of-Range Display", vec![ p("channel", "Channel", Value::Enum(0), popup(&["Max RGB", "Red", "Green", "Blue", "Alpha", "Luminance"])), p("highlightColor", "Highlight Color", col(1.0, 0.0, 0.0), ParamUi::Color), diff --git a/crates/engine/src/background/offload.rs b/crates/engine/src/background/offload.rs index f9038accb..b28527f02 100644 --- a/crates/engine/src/background/offload.rs +++ b/crates/engine/src/background/offload.rs @@ -375,7 +375,7 @@ pub(crate) fn job_accel() -> Option> { } /// Render options of an analysis's input frames: 100 %; with an accelerator, the project's -/// renderer (Mercury GPU Acceleration: its GPU effects on the device; Software Only: the CPU). +/// renderer (GPU Acceleration: its GPU effects on the device; Software Only: the CPU). pub(crate) fn analysis_opts(accel: Option<&dyn Accelerator>) -> RenderOpts { RenderOpts { scale: 1.0, backend: if accel.is_some() { Backend::Auto } else { Backend::Cpu }, ..Default::default() } } diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index f5bae86d0..8129759c5 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -719,8 +719,8 @@ fn project_settings(s: &mut Session, p: &Value) -> Result { Ok(serde_json::to_value(&s.project.settings).unwrap_or_default()) } -/// Video Rendering and Effects: report or set the renderer (Mercury GPU Acceleration when a GPU -/// adapter exists, else Mercury Software Only). +/// Video Rendering and Effects: report or set the renderer (GPU Acceleration when a GPU +/// adapter exists, else Software Rendering). fn render_backend(s: &mut Session, p: &Value) -> Result { if let Some(b) = p.get("backend").or_else(|| p.get("renderer")) { let gpu = match b { @@ -748,14 +748,14 @@ pub fn backend_status(s: &Session) -> Value { let gpu = s.project.settings.gpu_acceleration; // Why it renders on the CPU (#262). let why = if !gpu { - Some("the project's renderer is Mercury Software Only".to_string()) + Some("the project's renderer is Software Rendering".to_string()) } else if adapter.is_none() { Some(s.accel_note.clone().unwrap_or_else(|| "no GPU compositor is attached".into())) } else { None }; json!({ - "renderer": if gpu { "Mercury GPU Acceleration" } else { "Mercury Software Only" }, + "renderer": if gpu { "GPU Acceleration" } else { "Software Rendering" }, "gpuAcceleration": gpu, "adapter": adapter, "active": if gpu && adapter.is_some() { "gpu" } else { "cpu" }, diff --git a/crates/engine/src/cmd/panels_cmds.rs b/crates/engine/src/cmd/panels_cmds.rs index 40241e6f4..95bc57c3c 100644 --- a/crates/engine/src/cmd/panels_cmds.rs +++ b/crates/engine/src/cmd/panels_cmds.rs @@ -1,4 +1,4 @@ -//! Commands behind the Progress, Media Browser, Metadata and Lumetri Scopes panels. +//! Commands behind the Progress, Media Browser, Metadata and Video Scopes panels. use effectcraft_project::ItemId; use effectcraft_raster::Image; @@ -159,7 +159,7 @@ fn project_comment(s: &mut Session, p: &Value) -> Result { Ok(Value::Null) } -// ---------------------------------------------------------------- Lumetri Scopes +// ---------------------------------------------------------------- Video Scopes /// The comp frame the scopes read (the viewer's image: over the comp background), at most /// `max_side` pixels on the long side. @@ -257,7 +257,7 @@ pub fn specs() -> Vec { cmd!("project.setProjectComment", "Project Comment", [], None, "{comment}", always, project_comment), query!( "scopes.analyze", - "Lumetri Scopes", + "Video Scopes", "{comp?, time?|frame?, scope?: waveformRgb|waveformLuma|waveformYc|vectorscopeYuv|vectorscopeHls|histogram|paradeRgb|paradeYuv, standard?: rec601|rec709|rec2020, float?, clamp?, size?}", scopes_analyze ), diff --git a/crates/engine/src/home/demo.rs b/crates/engine/src/home/demo.rs index 7503178fa..ec1c353bc 100644 --- a/crates/engine/src/home/demo.rs +++ b/crates/engine/src/home/demo.rs @@ -238,7 +238,7 @@ fn showcase_3d(p: &mut Project, solids: ItemId) -> Comp { anim(&mut cam, "cameraOptions/focusDistance", keys(&[(0.0, Value::Scalar(1700.0)), (5.0, Value::Scalar(1900.0)), (10.0, Value::Scalar(1650.0))])); // Key light: warm spot casting soft shadows. Fill: cool ambient. - let mut key = build::layer(p, &c, "Key Light", LayerSource::Light { kind: effectcraft_project::LightKind::Spot }, (1920, 1080), None); + let mut key = build::layer(p, &c, "Screen Color Key", LayerSource::Light { kind: effectcraft_project::LightKind::Spot }, (1920, 1080), None); set(&mut key, "transform/position", Value::Vec3([500.0, -500.0, -700.0])); set(&mut key, "transform/poi", Value::Vec3([960.0, 600.0, 300.0])); set(&mut key, "lightOptions/intensity", Value::Scalar(150.0)); diff --git a/crates/engine/src/home/learn.rs b/crates/engine/src/home/learn.rs index cea729368..9c89b2dbf 100644 --- a/crates/engine/src/home/learn.rs +++ b/crates/engine/src/home/learn.rs @@ -259,7 +259,7 @@ pub fn tutorials() -> Vec { target: Some("menu.Layer"), accepts: &["layer.newLight"], when: Value::Null, - show: vec![("layer.newLight", json!({"kind": "Spot", "name": "Key Light"}))], + show: vec![("layer.newLight", json!({"kind": "Spot", "name": "Screen Color Key"}))], }), step(S { title: "Add a camera", diff --git a/crates/engine/src/menus.rs b/crates/engine/src/menus.rs index ed52d6e03..70acbd1fb 100644 --- a/crates/engine/src/menus.rs +++ b/crates/engine/src/menus.rs @@ -1263,7 +1263,7 @@ Window Essential Graphics | window.panel {"panel":"essentialGraphics"} Info | window.panel {"panel":"info"} | Cmd+2 Learn | help.inAppTutorials - Lumetri Scopes | window.panel {"panel":"lumetriScopes"} + Video Scopes | window.panel {"panel":"lumetriScopes"} Mask Interpolation | window.panel {"panel":"maskInterpolation"} Media Browser | window.panel {"panel":"mediaBrowser"} Metadata | window.panel {"panel":"metadata"} diff --git a/crates/engine/src/menus/tests.rs b/crates/engine/src/menus/tests.rs index 913a0e92e..8de3cc6dc 100644 --- a/crates/engine/src/menus/tests.rs +++ b/crates/engine/src/menus/tests.rs @@ -23,6 +23,25 @@ fn platform_entries(mac: bool) -> Vec<(Vec, MenuEntry)> { out } +/// Guard the generated display tree, not command IDs, format tokens or dynamic user names. +#[test] +fn builtin_menu_labels_do_not_reintroduce_vendor_feature_names() { + for mac in [true, false] { + let entries = platform_entries(mac); + for (path, entry) in &entries { + for label in path.iter().chain(std::iter::once(&entry.label)) { + let folded = label.to_lowercase(); + assert!(!folded.starts_with("cc "), "{label}"); + for mark in ["lumetri", "mercury", "mocha", "keylight"] { + assert!(!folded.contains(mark), "{label}"); + } + } + } + let scopes = entries.iter().find(|(_, e)| e.command == "window.panel" && e.params["panel"] == "lumetriScopes").unwrap(); + assert_eq!(scopes.1.label, "Video Scopes"); + } +} + #[test] fn top_level_order_matches_after_effects() { let mac: Vec = diff --git a/crates/engine/src/tests/rig3d.rs b/crates/engine/src/tests/rig3d.rs index 634d84e02..2c1557c91 100644 --- a/crates/engine/src/tests/rig3d.rs +++ b/crates/engine/src/tests/rig3d.rs @@ -439,7 +439,7 @@ const RIGGED: &str = r#"{ ], "cameras": [{"type": "perspective", "name": "Shot", "perspective": {"yfov": 0.6, "znear": 0.1}}], "extensions": {"KHR_lights_punctual": {"lights": [ - {"type": "spot", "name": "Key Light", "color": [1, 0.8, 0.6], "intensity": 1.5, "spot": {"innerConeAngle": 0.25, "outerConeAngle": 0.5}}, + {"type": "spot", "name": "Screen Color Key", "color": [1, 0.8, 0.6], "intensity": 1.5, "spot": {"innerConeAngle": 0.25, "outerConeAngle": 0.5}}, {"type": "point", "name": "Fill Light", "intensity": 0.5, "range": 4} ]}} }"#; @@ -478,7 +478,7 @@ fn cameras_and_lights_from_model() { let r = s.execute("light.fromModel", json!({})).unwrap(); let ls: Vec = r["layers"].as_array().unwrap().iter().map(|v| layer_in(&s, cid(&s), v.as_u64().unwrap())).collect(); assert_eq!(ls.len(), 2); - let key = ls.iter().find(|l| l.name == "Key Light").unwrap(); + let key = ls.iter().find(|l| l.name == "Screen Color Key").unwrap(); assert_eq!(key.source, LayerSource::Light { kind: LightKind::Spot }); assert!((key.props.prop("lightOptions/coneAngle").unwrap().value.as_f64() - 1.0f64.to_degrees()).abs() < 1e-6); assert!((key.props.prop("lightOptions/coneFeather").unwrap().value.as_f64() - 50.0).abs() < 1e-6); diff --git a/crates/engine/src/tests/settings.rs b/crates/engine/src/tests/settings.rs index 7d65061ea..b37c5ca3e 100644 --- a/crates/engine/src/tests/settings.rs +++ b/crates/engine/src/tests/settings.rs @@ -1221,7 +1221,35 @@ fn render_backend_says_why_it_renders_on_the_cpu() { assert_eq!(why(&mut s), json!("no GPU compositor is attached")); s.accel_note = Some("headless: renders on the CPU unless started with --gpu".into()); assert_eq!(why(&mut s), json!("headless: renders on the CPU unless started with --gpu")); - assert_eq!(s.execute("render.backend", json!({"backend": "cpu"})).unwrap()["why"], json!("the project's renderer is Mercury Software Only")); + assert_eq!(s.execute("render.backend", json!({"backend": "cpu"})).unwrap()["why"], json!("the project's renderer is Software Rendering")); +} + +/// Display labels are descriptive; machine-readable settings remain the same. +#[test] +fn renderer_labels_keep_their_stable_machine_values() { + let mut s = Session::default(); + for (backend, label, gpu) in [("cpu", "Software Rendering", false), ("gpu", "GPU Acceleration", true)] { + let status = s.execute("render.backend", json!({"backend": backend})).unwrap(); + assert_eq!(status["renderer"], json!(label)); + assert_eq!(status["gpuAcceleration"], json!(gpu)); + assert_eq!(status["active"], json!("cpu"), "the headless test has no GPU adapter"); + } +} + +/// The label `render.backend` reports is one it accepts back, so a caller can round-trip the +/// status instead of guessing the command's own values. +#[test] +fn renderer_status_labels_round_trip_through_the_command() { + let mut s = Session::default(); + for (backend, label, gpu) in [("cpu", "Software Rendering", false), ("gpu", "GPU Acceleration", true)] { + let reported = s.execute("render.backend", json!({"backend": backend})).unwrap()["renderer"].clone(); + assert_eq!(reported, json!(label)); + let parsed = effectcraft_render::Backend::parse(reported.as_str().unwrap()).expect("the reported renderer parses back"); + assert_eq!(parsed == effectcraft_render::Backend::Cpu, !gpu, "{reported}"); + let again = s.execute("render.backend", json!({"backend": reported})).unwrap(); + assert_eq!(again["renderer"], reported); + assert_eq!(again["gpuAcceleration"], json!(gpu)); + } } /// Settings ▸ GPU Information names what the GPU compositor runs on, or why it is off, and the diff --git a/crates/render/src/accel.rs b/crates/render/src/accel.rs index 0f271c59d..1eb8b546f 100644 --- a/crates/render/src/accel.rs +++ b/crates/render/src/accel.rs @@ -21,10 +21,13 @@ pub enum Backend { } impl Backend { + /// The backend `s` names, whatever case it is written in: the project's own values (`cpu`, + /// `gpu`, `auto`), the labels Project Settings ▸ Video Rendering and Effects draws + /// (`GPU Acceleration`, `Software Rendering`) and the older After Effects wording. pub fn parse(s: &str) -> Option { match s.to_ascii_lowercase().as_str() { - "cpu" | "software" | "mercury software only" => Some(Backend::Cpu), - "gpu" | "mercury gpu acceleration" => Some(Backend::Gpu), + "cpu" | "software" | "mercury software only" | "software rendering" => Some(Backend::Cpu), + "gpu" | "mercury gpu acceleration" | "gpu acceleration" => Some(Backend::Gpu), "auto" => Some(Backend::Auto), _ => None, } diff --git a/crates/render/src/tests.rs b/crates/render/src/tests.rs index 50ed65c73..59fa0fadc 100644 --- a/crates/render/src/tests.rs +++ b/crates/render/src/tests.rs @@ -329,7 +329,7 @@ fn card_dance_comp_camera_matches_the_default_view() { assert!(img.get(10, 50)[3] < 0.01); } -/// A black 2D solid with CC Particle World, under a camera layer panned right by `pan` px. +/// A black 2D solid with Particle Emitter 3D, under a camera layer panned right by `pan` px. fn particle_world_scene(pan: f64) -> (Project, ItemId) { let (mut p, cid, comp) = setup(); let mut l = solid(&mut p, &comp, [0.0, 0.0, 0.0], 200, 100); @@ -359,7 +359,7 @@ fn particles_x(img: &crate::Image) -> f32 { sx / m } -/// #397: CC Particle World on a 2D layer is seen through the comp's camera layer, and the layer +/// #397: Particle Emitter 3D on a 2D layer is seen through the comp's camera layer, and the layer /// cache notices the camera moving. #[test] fn particle_world_follows_the_comp_camera() { @@ -374,7 +374,7 @@ fn particle_world_follows_the_comp_camera() { assert!(b < a - 20.0, "panning the camera right moves the particles left: {a} -> {b}"); } -/// A black solid with CC Particle World whose Birth Rate is 3 until layer time `cut`, then 0 a +/// A black solid with Particle Emitter 3D whose Birth Rate is 3 until layer time `cut`, then 0 a /// frame later (`None`: 3 throughout); the layer starts at comp time `start`, stretched `stretch` %. fn burst_scene(cut: Option, start: f64, stretch: f64) -> (Project, ItemId) { burst_scene_keys(cut, start, stretch, false) @@ -624,7 +624,7 @@ fn a_text_expression_selector_is_not_served_from_the_disk_cache() { /// A Birth Rate expression reading another layer: changing that layer changes the history but /// not the current rate (0) nor this layer's properties, which is all the layer cache key sees. -/// CC Particle World layers with expressions therefore aren't layer cached. +/// Particle Emitter 3D layers with expressions therefore aren't layer cached. #[test] fn particle_world_with_a_birth_rate_expression_is_not_served_from_the_layer_cache() { let scene = |opacity: f64| { @@ -657,8 +657,8 @@ fn particle_world_with_a_birth_rate_expression_is_not_served_from_the_layer_cach assert!(light(&b) > 1.0 && light(&b) < light(&a), "fewer births: {} vs {}", light(&b), light(&a)); } -/// A grey solid (CC Mr. Mercury shades its blobs from it) with effect `id` (CC Particle Systems -/// II, CC Mr. Mercury): Birth Rate `rate`, +/// A grey solid (Liquid Particles shades its blobs from it) with effect `id` (CC Particle Systems +/// II, Liquid Particles): Birth Rate `rate`, /// or keyed 3 until 0.5 s and 0 a frame later (`None`); Longevity 1 s. fn system_scene(id: &str, rate: Option) -> (Project, ItemId) { let (mut p, cid, comp) = setup(); @@ -677,7 +677,7 @@ fn system_scene(id: &str, rate: Option) -> (Project, ItemId) { (p, cid) } -/// #1373 for CC Particle Systems II and CC Mr. Mercury through the renderer: a keyed burst +/// #1373 for Particle Emitter 2D and Liquid Particles through the renderer: a keyed burst /// draws as the constant rate during it, still draws after the rate drops to 0 (unlike a rate /// of 0 throughout), and draws as nothing born once Longevity has run out. #[test] @@ -1057,6 +1057,27 @@ fn comp_frame_ends_the_frame_when_the_render_panics() { assert_eq!(a.ends.load(Ordering::SeqCst), 1); } +/// The renderer labels Project Settings ▸ Video Rendering and Effects draws parse back as the +/// backend they name (in any case), and the older spellings still work. +#[test] +fn renderer_labels_parse_back_and_keep_the_older_spellings() { + use crate::Backend; + for (label, backend) in [ + ("GPU Acceleration", Backend::Gpu), + ("gpu acceleration", Backend::Gpu), + ("Mercury GPU Acceleration", Backend::Gpu), + ("gpu", Backend::Gpu), + ("Software Rendering", Backend::Cpu), + ("software rendering", Backend::Cpu), + ("Mercury Software Only", Backend::Cpu), + ("cpu", Backend::Cpu), + ("Auto", Backend::Auto), + ] { + assert_eq!(Backend::parse(label), Some(backend), "{label}"); + } + assert_eq!(Backend::parse("Vulkan"), None); +} + #[test] fn auto_backend_sends_2d_and_3d_comps_to_the_gpu() { let (mut p, cid, comp) = setup(); @@ -1223,11 +1244,11 @@ fn effects_on_text_reach_past_the_text_bounds() { } assert!( painted > 50 && hi.saturating_sub(lo) > 100, - "CC Tiler tiles the glyphs across the layer region, not just its text bounds: {painted} painted, x-span {lo}..{hi}" + "Scaled Tiles tiles the glyphs across the layer region, not just its text bounds: {painted} painted, x-span {lo}..{hi}" ); } -/// #658: CC Smear drags text glyphs beyond the text layer's own bounds. Pixels smeared past +/// #658: Directional Smear drags text glyphs beyond the text layer's own bounds. Pixels smeared past /// the painted rectangle used to fall off its edge, so the liquid trail never appeared. #[test] fn cc_smear_trails_text_past_its_bounds() { @@ -1246,7 +1267,7 @@ fn cc_smear_trails_text_past_its_bounds() { ); p.comp_mut(cid).unwrap().layers = vec![l].into(); let smeared = right(&render_frame(&p, cid, Tick::ZERO, 1.0)); - assert!(plain > 40 && smeared > plain + 25, "CC Smear trails the glyphs past the text bounds: right edge {plain} → {smeared}"); + assert!(plain > 40 && smeared > plain + 25, "Directional Smear trails the glyphs past the text bounds: right edge {plain} → {smeared}"); } /// A layer parameter pointing at a shape layer sees all of it (in its effect space), and the @@ -1502,7 +1523,7 @@ fn solo_excludes_other_layers_outside_the_soloed_layers_range() { assert_eq!(second.get(100, 50), [0.0, 0.0, 1.0, 1.0], "only B inside its range"); } -/// #1252: a layer blended with a CC Particle World layer, under a camera panned by `pan` px. +/// #1252: a layer blended with a Particle Emitter 3D layer, under a camera panned by `pan` px. fn scene_reader_dependency(pan: f64) -> (Project, ItemId) { let (mut p, cid, comp) = setup(); let mut source = solid(&mut p, &comp, [0.0, 0.0, 0.0], 200, 100); diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs index c8ada9bf8..f126db257 100644 --- a/crates/ui-egui/src/dock.rs +++ b/crates/ui-egui/src/dock.rs @@ -124,7 +124,7 @@ impl PanelKind { PanelKind::EssentialGraphics => "Essential Graphics", PanelKind::ScriptPanel(_) => "ScriptUI Panel", PanelKind::Viewer(_) => "Composition", - PanelKind::LumetriScopes => "Lumetri Scopes", + PanelKind::LumetriScopes => "Video Scopes", PanelKind::Footage => "Footage", PanelKind::MediaBrowser => "Media Browser", PanelKind::Metadata => "Metadata", @@ -709,6 +709,16 @@ mod tests { w.apply(action, permissions).unwrap(); } + /// Only the title changes: existing saved workspace layouts still deserialize. + #[test] + fn scopes_label_is_descriptive_and_its_saved_identity_stays_compatible() { + let panel: PanelKind = serde_json::from_str("\"LumetriScopes\"").unwrap(); + assert_eq!(panel, LumetriScopes); + assert_eq!(panel.title(), "Video Scopes"); + assert_eq!(panel.id(), "LumetriScopes"); + assert_eq!(serde_json::to_string(&panel).unwrap(), "\"LumetriScopes\""); + } + #[test] fn after_effects_workspaces_exist_with_their_core_panels() { for name in WORKSPACES { diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs index 68e58f842..c998538d4 100644 --- a/crates/ui-egui/src/i18n.rs +++ b/crates/ui-egui/src/i18n.rs @@ -1054,7 +1054,7 @@ const SIMPLIFIED_CHINESE: &[(&str, &str, &str)] = &[ ("window.panel", "Essential Graphics", "基本图形"), ("window.panel", "Info", "信息"), ("help.inAppTutorials", "Learn", "学习"), - ("window.panel", "Lumetri Scopes", "Lumetri 范围"), + ("window.panel", "Video Scopes", "视频示波器"), ("window.panel", "Mask Interpolation", "蒙版插值"), ("window.panel", "Media Browser", "媒体浏览器"), ("window.panel", "Metadata", "元数据"), @@ -1690,7 +1690,7 @@ const SWEDISH: &[(&str, &str, &str)] = &[ ("window.panel", "Essential Graphics", "Grundläggande grafik"), ("window.panel", "Info", "Info"), ("help.inAppTutorials", "Learn", "Lär dig"), - ("window.panel", "Lumetri Scopes", "Lumetri-scope"), + ("window.panel", "Video Scopes", "Videoskop"), ("window.panel", "Mask Interpolation", "Maskinterpolering"), ("window.panel", "Media Browser", "Mediebläddrare"), ("window.panel", "Metadata", "Metadata"), @@ -2336,7 +2336,7 @@ const TRADITIONAL_CHINESE: &[(&str, &str, &str)] = &[ ("window.panel", "Essential Graphics", "基本圖形"), ("window.panel", "Info", "資訊"), ("help.inAppTutorials", "Learn", "學習"), - ("window.panel", "Lumetri Scopes", "Lumetri 示波器"), + ("window.panel", "Video Scopes", "視訊示波器"), ("window.panel", "Mask Interpolation", "遮色片插補"), ("window.panel", "Media Browser", "媒體瀏覽器"), ("window.panel", "Metadata", "中繼資料"), @@ -2975,7 +2975,7 @@ const JAPANESE: &[(&str, &str, &str)] = &[ ("window.panel", "Essential Graphics", "エッセンシャルグラフィックス"), ("window.panel", "Info", "情報"), ("help.inAppTutorials", "Learn", "学習"), - ("window.panel", "Lumetri Scopes", "Lumetriスコープ"), + ("window.panel", "Video Scopes", "ビデオスコープ"), ("window.panel", "Mask Interpolation", "マスク補間"), ("window.panel", "Media Browser", "メディアブラウザー"), ("window.panel", "Metadata", "メタデータ"), @@ -3617,7 +3617,7 @@ const UKRAINIAN: &[(&str, &str, &str)] = &[ ("window.panel", "Essential Graphics", "Основна графіка"), ("window.panel", "Info", "Інформація"), ("help.inAppTutorials", "Learn", "Навчання"), - ("window.panel", "Lumetri Scopes", "Вимірювачі Lumetri"), + ("window.panel", "Video Scopes", "Відеоскопи"), ("window.panel", "Mask Interpolation", "Інтерполяція маски"), ("window.panel", "Media Browser", "Браузер медіа"), ("window.panel", "Metadata", "Метадані"), @@ -4260,7 +4260,7 @@ const SPANISH: &[(&str, &str, &str)] = &[ ("window.panel", "Essential Graphics", "Gráficos esenciales"), ("window.panel", "Info", "Información"), ("help.inAppTutorials", "Learn", "Aprender"), - ("window.panel", "Lumetri Scopes", "Ámbitos de Lumetri"), + ("window.panel", "Video Scopes", "Monitores de vídeo"), ("window.panel", "Mask Interpolation", "Interpolación de máscara"), ("window.panel", "Media Browser", "Navegador de medios"), ("window.panel", "Metadata", "Metadatos"), @@ -4901,7 +4901,7 @@ const PORTUGUESE: &[(&str, &str, &str)] = &[ ("window.panel", "Essential Graphics", "Gráficos essenciais"), ("window.panel", "Info", "Informações"), ("help.inAppTutorials", "Learn", "Aprender"), - ("window.panel", "Lumetri Scopes", "Escopos Lumetri"), + ("window.panel", "Video Scopes", "Escopos de vídeo"), ("window.panel", "Mask Interpolation", "Interpolação de máscara"), ("window.panel", "Media Browser", "Navegador de mídia"), ("window.panel", "Metadata", "Metadados"), @@ -5544,7 +5544,7 @@ const RUSSIAN: &[(&str, &str, &str)] = &[ ("window.panel", "Essential Graphics", "Основная графика"), ("window.panel", "Info", "Информация"), ("help.inAppTutorials", "Learn", "Обучение"), - ("window.panel", "Lumetri Scopes", "Измерители Lumetri"), + ("window.panel", "Video Scopes", "Видеоскопы"), ("window.panel", "Mask Interpolation", "Интерполяция маски"), ("window.panel", "Media Browser", "Обозреватель медиа"), ("window.panel", "Metadata", "Метаданные"), @@ -6185,7 +6185,7 @@ const FRENCH: &[(&str, &str, &str)] = &[ ("window.panel", "Essential Graphics", "Graphiques essentiels"), ("window.panel", "Info", "Informations"), ("help.inAppTutorials", "Learn", "Apprentissage"), - ("window.panel", "Lumetri Scopes", "Oscilloscopes Lumetri"), + ("window.panel", "Video Scopes", "Oscilloscopes vidéo"), ("window.panel", "Mask Interpolation", "Interpolation de masque"), ("window.panel", "Media Browser", "Navigateur multimédia"), ("window.panel", "Metadata", "Métadonnées"), @@ -6826,7 +6826,7 @@ const GERMAN: &[(&str, &str, &str)] = &[ ("window.panel", "Essential Graphics", "Essential-Grafik"), ("window.panel", "Info", "Info"), ("help.inAppTutorials", "Learn", "Lernen"), - ("window.panel", "Lumetri Scopes", "Lumetri-Scopes"), + ("window.panel", "Video Scopes", "Videoskope"), ("window.panel", "Mask Interpolation", "Maskeninterpolation"), ("window.panel", "Media Browser", "Medienbrowser"), ("window.panel", "Metadata", "Metadaten"), @@ -7464,7 +7464,7 @@ const POLISH: &[(&str, &str, &str)] = &[ ("window.panel", "Essential Graphics", "Essential Graphics"), ("window.panel", "Info", "Informacje"), ("help.inAppTutorials", "Learn", "Nauka"), - ("window.panel", "Lumetri Scopes", "Zakresy Lumetri"), + ("window.panel", "Video Scopes", "Wskaźniki wideo"), ("window.panel", "Mask Interpolation", "Interpolacja maski"), ("window.panel", "Media Browser", "Przeglądarka multimediów"), ("window.panel", "Metadata", "Metadane"), @@ -8106,7 +8106,7 @@ const CZECH: &[(&str, &str, &str)] = &[ ("window.panel", "Essential Graphics", "Základní grafika"), ("window.panel", "Info", "Informace"), ("help.inAppTutorials", "Learn", "Výuka"), - ("window.panel", "Lumetri Scopes", "Měřicí přístroje Lumetri"), + ("window.panel", "Video Scopes", "Videoskopy"), ("window.panel", "Mask Interpolation", "Interpolace masek"), ("window.panel", "Media Browser", "Prohlížeč médií"), ("window.panel", "Metadata", "Metadata"), @@ -8748,7 +8748,7 @@ const GEORGIAN: &[(&str, &str, &str)] = &[ ("window.panel", "Essential Graphics", "ძირითადი გრაფიკა"), ("window.panel", "Info", "ინფორმაცია"), ("help.inAppTutorials", "Learn", "სწავლა"), - ("window.panel", "Lumetri Scopes", "Lumetri Scopes"), + ("window.panel", "Video Scopes", "ვიდეოსკოპები"), ("window.panel", "Mask Interpolation", "ნიღბის ინტერპოლაცია"), ("window.panel", "Media Browser", "მედიის ბრაუზერი"), ("window.panel", "Metadata", "მეტამონაცემები"), @@ -8799,6 +8799,21 @@ mod tests { use serde_json::json; use std::collections::BTreeSet; + #[test] + fn renamed_menu_translations_do_not_reintroduce_vendor_names() { + for code in CATALOG_CODES { + set_current(code); + for (id, source) in [("window.panel", "Video Scopes")] { + let rendered = command_label(id, source); + let label = rendered.to_lowercase(); + for mark in ["lumetri", "mercury"] { + assert!(!label.contains(mark), "{code}: {id} -> {rendered}"); + } + } + } + set_current("en"); + } + /// The four options at the foot of the header's workspace menu say what After Effects says, /// read from its workspace button on 2026-10-31: reset, save over this one, save a copy, then /// edit the list. diff --git a/crates/ui-egui/src/i18n/effects.rs b/crates/ui-egui/src/i18n/effects.rs index ec952ccb0..55893115a 100644 --- a/crates/ui-egui/src/i18n/effects.rs +++ b/crates/ui-egui/src/i18n/effects.rs @@ -18,14 +18,19 @@ //! another effect. An effect with no row draws the registry's English name; the //! `missing_translations_report` test (run by `cargo xtask ci`) lists those per language. //! -//! A language decides for itself which names stay English: After Effects' Japanese interface -//! leaves the `CC` series in English and gives the `VR` and `OCIO` sets a Japanese tail -//! (`VR ブラー`, `OCIO CDL 変換`), while its Simplified Chinese one translates them (the `CC` -//! names come from Adobe's Chinese *documentation*, which names 68 of the 69). Repeating the -//! English name is therefore a language-level choice, not a missing row. +//! Own feature names are descriptive. The renamed effects use original translations in every +//! existing effect catalog; legacy vendor names remain search aliases in the effects crate. +//! External format tokens and stored instance names are not localized or rewritten. //! -//! The Simplified Chinese names come from the installed After Effects 2026 (26.5.0.89) -//! Simplified Chinese interface, its 21 category folder names included; `Cryptomatte`, +//! The rows of the effects this cleanup did not rename keep the provenance they had. A language +//! decides for itself which names stay English: After Effects' Japanese interface leaves the `CC` +//! series in English and gives the `VR` and `OCIO` sets a Japanese tail (`VR ブラー`, +//! `OCIO CDL 変換`), while its Simplified Chinese one translates them. Repeating the English name +//! is therefore a language-level choice, not a missing row. +//! +//! The Simplified Chinese names of unchanged effects come from the installed After Effects 2026 +//! (26.5.0.89) Simplified Chinese interface, its 21 category folder names included (the `CC` names +//! came from Adobe's Chinese *documentation*, which names 68 of the 69); `Cryptomatte`, //! `EXtractoR`, `IDentifier`, `Key Light` and `Unmult` stay in English as brand names, and //! `Face Measurements` / `Face Track Points` are EffectCraft's own effects, so their wording is //! ours. @@ -33,16 +38,15 @@ //! The Traditional Chinese names for Taiwan are written from the meaning of the English ones, with //! the terms Taiwan's creative software uses (`圖層`, `遮罩`, `筆刷`, `雜訊`, `發光`, `漸層`); they //! are not converted from the Simplified table. Brand and coined names (`Cryptomatte`, -//! `EXtractoR`, `IDentifier`, `Key Light`, `Unmult`, `Lumetri Color`, `Colorama`, `Minimax`, -//! `Vegas`, `Mocha`) stay in English; the `CC` series keeps its prefix and translates the -//! descriptive tail, and the `VR` and `OCIO` sets keep their prefix in Chinese word order. +//! `EXtractoR`, `IDentifier`, `Key Light`, `Unmult`, `Colorama`, `Minimax`, `Vegas`) stay in +//! English, and the `VR` and `OCIO` sets keep their prefix in Chinese word order. //! //! The French names are written from the meaning of the English ones, with the vocabulary of the //! French menus; they come from no other application's interface. Brand and coined names -//! (`Cryptomatte`, `EXtractoR`, `IDentifier`, `Key Light`, `Unmult`, `Lumetri Color`, `Colorama`, -//! `Minimax`, `Tritone`, `Vibrance`, `Vegas`) and the whole `CC` series stay in English; a series -//! tag that prefixes a descriptive name (`VR`, `OCIO`, `PS`, `HDR`) stays and follows the -//! French word order (`Flou VR`, `Transformation CDL OCIO`). +//! (`Cryptomatte`, `EXtractoR`, `IDentifier`, `Key Light`, `Unmult`, `Colorama`, `Minimax`, +//! `Tritone`, `Vibrance`, `Vegas`) stay in English; a series tag that prefixes a descriptive name +//! (`VR`, `OCIO`, `PS`, `HDR`) stays and follows the French word order (`Flou VR`, +//! `Transformation CDL OCIO`). use std::collections::HashMap; use std::sync::OnceLock; @@ -122,19 +126,21 @@ pub(super) fn translated_rows(language: &str) -> usize { /// The name to draw for an effect group the property tree stores as `stored`: the catalog name, /// plus the instance index the engine appends to a repeat (`Gaussian Blur 2` → `高斯模糊 2`). /// -/// A name that is neither the registry's nor the registry's plus an index was typed by the user -/// (Effect Controls ▸ Rename), so it stays verbatim — as does the whole string in a language -/// with no row. +/// Current and legacy default names (including numeric instance suffixes) draw the current +/// name. Other names were supplied by the user and stay verbatim. Stored data is never changed. pub(crate) fn group(id: &str, stored: &str) -> String { - let Some((english, translated)) = catalog(current()).and_then(|c| c.row(id)) else { return stored.to_string() }; - if stored == english { - return translated.to_string(); - } - if let Some(index) = stored.strip_prefix(english).and_then(|rest| rest.strip_prefix(' ')) - && !index.is_empty() - && index.bytes().all(|b| b.is_ascii_digit()) - { - return format!("{translated} {index}"); + let Some(spec) = effectcraft_engine::effects::find(id) else { return stored.to_string() }; + let translated = name(id, spec.name); + for source in std::iter::once(spec.name).chain(effectcraft_engine::effects::aliases(id).iter().copied()) { + if stored == source { + return translated; + } + if let Some(index) = stored.strip_prefix(source).and_then(|rest| rest.strip_prefix(' ')) + && !index.is_empty() + && index.bytes().all(|b| b.is_ascii_digit()) + { + return format!("{translated} {index}"); + } } stored.to_string() } @@ -149,6 +155,7 @@ pub(crate) fn category(source: &str) -> String { /// `query` (lowercase)? Both names match, so a translated interface can be searched either way. pub(crate) fn matches(id: &str, english: &str, query: &str) -> bool { english.to_lowercase().contains(query) + || effectcraft_engine::effects::find(id).is_some_and(|spec| effectcraft_engine::effects::name_matches(spec, query)) || catalog(current()).and_then(|c| c.row(id)).is_some_and(|(_, translated)| translated.to_lowercase().contains(query)) } @@ -192,10 +199,10 @@ const SIMPLIFIED_CHINESE: &[Row] = &[ ("ec.blur.bilateral", "Bilateral Blur", "双向模糊"), ("ec.blur.cameralens", "Camera Lens Blur", "摄像机镜头模糊"), ("ec.blur.camerashakedeblur", "Camera-Shake Deblur", "摄像机抖动去模糊"), - ("ec.blur.cccross", "CC Cross Blur", "CC 交叉模糊"), - ("ec.blur.ccradial", "CC Radial Blur", "CC 径向模糊"), - ("ec.blur.ccradialfast", "CC Radial Fast Blur", "CC 径向快速模糊"), - ("ec.blur.ccvector", "CC Vector Blur", "CC 矢量模糊"), + ("ec.blur.cccross", "Cross Blur", "十字模糊"), + ("ec.blur.ccradial", "Variable Radial Blur", "可变径向模糊"), + ("ec.blur.ccradialfast", "Fast Radial Blur", "快速径向模糊"), + ("ec.blur.ccvector", "Vector Blur", "矢量模糊"), ("ec.blur.channel", "Channel Blur", "通道模糊"), ("ec.blur.compound", "Compound Blur", "复合模糊"), ("ec.blur.directional", "Directional Blur", "定向模糊"), @@ -209,7 +216,7 @@ const SIMPLIFIED_CHINESE: &[Row] = &[ ("ec.channel.arithmetic", "Arithmetic", "算术"), ("ec.channel.blend", "Blend", "混合"), ("ec.channel.calculations", "Calculations", "计算"), - ("ec.channel.cccomposite", "CC Composite", "CC 合成"), + ("ec.channel.cccomposite", "Source Composite", "源图合成"), ("ec.channel.combiner", "Channel Combiner", "通道合成器"), ("ec.channel.compoundarithmetic", "Compound Arithmetic", "复合运算"), ("ec.channel.invert", "Invert", "反转"), @@ -225,10 +232,10 @@ const SIMPLIFIED_CHINESE: &[Row] = &[ ("ec.color.blackwhite", "Black & White", "黑色和白色"), ("ec.color.brightnesscontrast", "Brightness & Contrast", "亮度和对比度"), ("ec.color.broadcast", "Broadcast Colors", "广播颜色"), - ("ec.color.cccolorneutralizer", "CC Color Neutralizer", "CC 颜色中和器"), - ("ec.color.cccoloroffset", "CC Color Offset", "CC 颜色偏移"), - ("ec.color.cckernel", "CC Kernel", "CC 内核"), - ("ec.color.cctoner", "CC Toner", "CC 调色器"), + ("ec.color.cccolorneutralizer", "Color Neutralizer", "色偏校正"), + ("ec.color.cccoloroffset", "Channel Offset", "通道偏移"), + ("ec.color.cckernel", "Convolution Kernel", "卷积核"), + ("ec.color.cctoner", "Multi-Tone Tint", "多色调着色"), ("ec.color.changecolor", "Change Color", "更改颜色"), ("ec.color.changetocolor", "Change to Color", "更改为颜色"), ("ec.color.channelmixer", "Channel Mixer", "通道混合器"), @@ -245,7 +252,7 @@ const SIMPLIFIED_CHINESE: &[Row] = &[ ("ec.color.leavecolor", "Leave Color", "保留颜色"), ("ec.color.levels", "Levels", "色阶"), ("ec.color.levelsic", "Levels (Individual Controls)", "色阶 (单独控件)"), - ("ec.color.lumetri", "Lumetri Color", "Lumetri 颜色"), + ("ec.color.lumetri", "Color Grading", "色彩分级"), ("ec.color.ociocdl", "OCIO CDL Transform", "OCIO CDL 变换"), ("ec.color.ociocolorspace", "OCIO Color Space Transform", "OCIO 颜色空间变换"), ("ec.color.ociodisplay", "OCIO Display Transform", "OCIO 显示变换"), @@ -270,20 +277,20 @@ const SIMPLIFIED_CHINESE: &[Row] = &[ ("ec.control.stereo3d", "Stereo 3D Controls", "立体 3D 控制"), ("ec.distort.bezierwarp", "Bezier Warp", "贝塞尔曲线变形"), ("ec.distort.bulge", "Bulge", "凸出"), - ("ec.distort.ccbender", "CC Bender", "CC 弯曲器"), - ("ec.distort.ccbendit", "CC Bend It", "CC 弯曲"), - ("ec.distort.ccblobbylize", "CC Blobbylize", "CC 融化"), - ("ec.distort.ccflomotion", "CC Flo Motion", "CC 流动运动"), - ("ec.distort.ccgriddler", "CC Griddler", "CC 网格生成器"), - ("ec.distort.cclens", "CC Lens", "CC 镜头"), - ("ec.distort.ccpageturn", "CC Page Turn", "CC 翻页"), - ("ec.distort.ccpowerpin", "CC Power Pin", "CC 强力边角定位"), - ("ec.distort.ccripplepulse", "CC Ripple Pulse", "CC 波纹脉冲"), - ("ec.distort.ccslant", "CC Slant", "CC 倾斜"), - ("ec.distort.ccsmear", "CC Smear", "CC 漩涡条纹"), - ("ec.distort.ccsplit", "CC Split", "CC 拆分"), - ("ec.distort.ccsplit2", "CC Split 2", "CC 拆分 2"), - ("ec.distort.cctiler", "CC Tiler", "CC 拼贴器"), + ("ec.distort.ccbender", "Flexible Bend", "柔性弯曲"), + ("ec.distort.ccbendit", "Two-Point Bend", "两点弯曲"), + ("ec.distort.ccblobbylize", "Organic Displacement", "有机置换"), + ("ec.distort.ccflomotion", "Dual Lens Warp", "双镜头变形"), + ("ec.distort.ccgriddler", "Tile Grid", "平铺网格"), + ("ec.distort.cclens", "Lens Distortion", "镜头畸变"), + ("ec.distort.ccpageturn", "Page Curl", "页面卷曲"), + ("ec.distort.ccpowerpin", "Perspective Pin", "透视定位"), + ("ec.distort.ccripplepulse", "Pulsed Ripple", "脉冲涟漪"), + ("ec.distort.ccslant", "Slant", "倾斜"), + ("ec.distort.ccsmear", "Directional Smear", "定向涂抹"), + ("ec.distort.ccsplit", "Split Warp", "分割变形"), + ("ec.distort.ccsplit2", "Dual Split Warp", "双重分割变形"), + ("ec.distort.cctiler", "Scaled Tiles", "缩放平铺"), ("ec.distort.cornerpin", "Corner Pin", "边角定位"), ("ec.distort.displacementmap", "Displacement Map", "置换图"), ("ec.distort.liquify", "Liquify", "液化"), @@ -311,11 +318,11 @@ const SIMPLIFIED_CHINESE: &[Row] = &[ ("ec.generate.audiospectrum", "Audio Spectrum", "音频频谱"), ("ec.generate.audiowaveform", "Audio Waveform", "音频波形"), ("ec.generate.beam", "Beam", "光束"), - ("ec.generate.ccgluegun", "CC Glue Gun", "CC 胶水枪"), - ("ec.generate.cclightburst", "CC Light Burst 2.5", "CC 光束放射 2.5"), - ("ec.generate.cclightrays", "CC Light Rays", "CC 光线"), - ("ec.generate.cclightsweep", "CC Light Sweep", "CC 光线扫描"), - ("ec.generate.ccthreads", "CC Threads", "CC 编织条"), + ("ec.generate.ccgluegun", "Paint Beads", "颜料珠"), + ("ec.generate.cclightburst", "Radial Light Burst", "径向光芒"), + ("ec.generate.cclightrays", "Light Rays", "光线"), + ("ec.generate.cclightsweep", "Light Sweep", "扫光"), + ("ec.generate.ccthreads", "Woven Threads", "编织线"), ("ec.generate.cellpattern", "Cell Pattern", "单元格图案"), ("ec.generate.checkerboard", "Checkerboard", "棋盘"), ("ec.generate.circle", "Circle", "圆形"), @@ -334,7 +341,7 @@ const SIMPLIFIED_CHINESE: &[Row] = &[ ("ec.generate.vegas", "Vegas", "勾画"), ("ec.generate.writeon", "Write-on", "写入"), ("ec.key.advancedspill", "Advanced Spill Suppressor", "高级溢出抑制器"), - ("ec.key.ccsimplewireremoval", "CC Simple Wire Removal", "CC 简单丝线移除"), + ("ec.key.ccsimplewireremoval", "Line Removal", "线条移除"), ("ec.key.colordifference", "Color Difference Key", "颜色差值键"), ("ec.key.colorkey", "Color Key", "颜色键"), ("ec.key.colorrange", "Color Range", "颜色范围"), @@ -347,7 +354,7 @@ const SIMPLIFIED_CHINESE: &[Row] = &[ ("ec.key.screen", "Screen Key", "屏幕键"), ("ec.key.spill", "Spill Suppressor", "溢出抑制"), ("ec.key.unmult", "Unmult", "Unmult"), - ("ec.keying.keylight", "Key Light", "Key Light"), + ("ec.keying.keylight", "Screen Color Key", "屏幕色键"), ("ec.matte.mattechoker", "Matte Choker", "遮罩阻塞工具"), ("ec.matte.objectmatte", "Object Matte", "对象遮罩"), ("ec.matte.refinehard", "Refine Hard Matte", "调整实边遮罩"), @@ -371,50 +378,50 @@ const SIMPLIFIED_CHINESE: &[Row] = &[ ("ec.obsolete.basictext", "Basic Text", "基本文字"), ("ec.obsolete.gaussianlegacy", "Gaussian Blur (Legacy)", "高斯模糊 (旧版)"), ("ec.obsolete.lightning", "Lightning", "闪电"), - ("ec.obsolete.mochashape", "Mocha shape", "Mocha 形状"), + ("ec.obsolete.mochashape", "Tracked Shape Matte", "跟踪形状遮罩"), ("ec.obsolete.pathtext", "Path Text", "路径文本"), ("ec.paint.paint", "Paint", "绘画"), ("ec.perspective.3dglasses", "3D Glasses", "3D 眼镜"), ("ec.perspective.bevelalpha", "Bevel Alpha", "斜面 Alpha"), ("ec.perspective.beveledges", "Bevel Edges", "边缘斜面"), ("ec.perspective.cameratracker", "3D Camera Tracker", "3D 摄像机跟踪器"), - ("ec.perspective.cccylinder", "CC Cylinder", "CC 圆柱体"), - ("ec.perspective.ccenvironment", "CC Environment", "CC 环境"), - ("ec.perspective.ccsphere", "CC Sphere", "CC 球体"), - ("ec.perspective.ccspotlight", "CC Spotlight", "CC 聚光"), + ("ec.perspective.cccylinder", "Cylinder Wrap", "圆柱包裹"), + ("ec.perspective.ccenvironment", "Environment Map", "环境映射"), + ("ec.perspective.ccsphere", "Sphere Wrap", "球面包裹"), + ("ec.perspective.ccspotlight", "Surface Spotlight", "表面聚光灯"), ("ec.perspective.dropshadow", "Drop Shadow", "投影"), ("ec.perspective.radialshadow", "Radial Shadow", "径向阴影"), ("ec.sim.carddance", "Card Dance", "卡片动画"), ("ec.sim.caustics", "Caustics", "焦散"), - ("ec.sim.ccballaction", "CC Ball Action", "CC 球动作"), - ("ec.sim.ccbubbles", "CC Bubbles", "CC 气泡"), - ("ec.sim.ccdrizzle", "CC Drizzle", "CC 细雨波纹"), - ("ec.sim.cchair", "CC Hair", "CC 毛发"), - ("ec.sim.ccmrmercury", "CC Mr. Mercury", "CC 水银流体"), - ("ec.sim.ccparticlesystems2", "CC Particle Systems II", "CC 粒子系统 II"), - ("ec.sim.ccparticleworld", "CC Particle World", "CC 粒子世界"), - ("ec.sim.ccpixelpolly", "CC Pixel Polly", "CC 像素多边形"), - ("ec.sim.ccrainfall", "CC Rainfall", "CC 降雨"), - ("ec.sim.ccscatterize", "CC Scatterize", "CC 散射"), - ("ec.sim.ccsnowfall", "CC Snowfall", "CC 降雪"), - ("ec.sim.ccstarburst", "CC Star Burst", "CC 星爆"), + ("ec.sim.ccballaction", "Ball Grid", "球体网格"), + ("ec.sim.ccbubbles", "Bubbles", "气泡"), + ("ec.sim.ccdrizzle", "Water Ripples", "水面涟漪"), + ("ec.sim.cchair", "Surface Fibers", "表面纤维"), + ("ec.sim.ccmrmercury", "Liquid Particles", "液体粒子"), + ("ec.sim.ccparticlesystems2", "Particle Emitter 2D", "二维粒子发射器"), + ("ec.sim.ccparticleworld", "Particle Emitter 3D", "三维粒子发射器"), + ("ec.sim.ccpixelpolly", "Pixel Shatter", "像素破碎"), + ("ec.sim.ccrainfall", "Rainfall", "降雨"), + ("ec.sim.ccscatterize", "Pixel Scatter", "像素散射"), + ("ec.sim.ccsnowfall", "Snowfall", "降雪"), + ("ec.sim.ccstarburst", "Starfield", "星空"), ("ec.sim.foam", "Foam", "泡沫"), ("ec.sim.particleplayground", "Particle Playground", "粒子运动场"), ("ec.sim.shatter", "Shatter", "碎片"), ("ec.sim.waveworld", "Wave World", "波形环境"), ("ec.stylize.brushstrokes", "Brush Strokes", "画笔描边"), ("ec.stylize.cartoon", "Cartoon", "卡通"), - ("ec.stylize.ccblockload", "CC Block Load", "CC 块加载"), - ("ec.stylize.ccburnfilm", "CC Burn Film", "CC 烧毁胶片"), - ("ec.stylize.ccglass", "CC Glass", "CC 玻璃"), - ("ec.stylize.cchextile", "CC HexTile", "CC 六边形拼贴"), - ("ec.stylize.cckaleida", "CC Kaleida", "CC 万花筒"), - ("ec.stylize.ccmrsmoothie", "CC Mr. Smoothie", "CC 像素溶解"), - ("ec.stylize.ccplastic", "CC Plastic", "CC 塑料"), - ("ec.stylize.ccrepetile", "CC RepeTile", "CC 重复拼贴"), - ("ec.stylize.ccthreshold", "CC Threshold", "CC 阈值"), - ("ec.stylize.ccthresholdrgb", "CC Threshold RGB", "CC 阈值 RGB"), - ("ec.stylize.ccvignette", "CC Vignette", "CC 暗角"), + ("ec.stylize.ccblockload", "Block Reveal", "块状显现"), + ("ec.stylize.ccburnfilm", "Film Burn", "胶片灼烧"), + ("ec.stylize.ccglass", "Glass Relief", "玻璃浮雕"), + ("ec.stylize.cchextile", "Hexagonal Tiles", "六边形平铺"), + ("ec.stylize.cckaleida", "Kaleidoscope", "万花筒"), + ("ec.stylize.ccmrsmoothie", "Palette Map", "调色板映射"), + ("ec.stylize.ccplastic", "Plastic Shading", "塑料着色"), + ("ec.stylize.ccrepetile", "Edge Tile Repeat", "边缘平铺重复"), + ("ec.stylize.ccthreshold", "Channel Threshold", "通道阈值"), + ("ec.stylize.ccthresholdrgb", "RGB Threshold", "RGB 阈值"), + ("ec.stylize.ccvignette", "Vignette", "晕影"), ("ec.stylize.coloremboss", "Color Emboss", "彩色浮雕"), ("ec.stylize.emboss", "Emboss", "浮雕"), ("ec.stylize.findedges", "Find Edges", "查找边缘"), @@ -429,8 +436,8 @@ const SIMPLIFIED_CHINESE: &[Row] = &[ ("ec.stylize.threshold", "Threshold", "阈值"), ("ec.text.numbers", "Numbers", "编号"), ("ec.text.timecode", "Timecode", "时间码"), - ("ec.time.ccforcemotionblur", "CC Force Motion Blur", "CC 强制运动模糊"), - ("ec.time.ccwidetime", "CC Wide Time", "CC 宽泛时间"), + ("ec.time.ccforcemotionblur", "Temporal Motion Blur", "时间运动模糊"), + ("ec.time.ccwidetime", "Temporal Blend", "时间混合"), ("ec.time.echo", "Echo", "残影"), ("ec.time.pixelmotionblur", "Pixel Motion Blur", "像素运动模糊"), ("ec.time.posterizetime", "Posterize Time", "抽帧"), @@ -439,23 +446,23 @@ const SIMPLIFIED_CHINESE: &[Row] = &[ ("ec.time.timewarp", "Timewarp", "时间扭曲"), ("ec.transition.blockdissolve", "Block Dissolve", "块溶解"), ("ec.transition.cardwipe", "Card Wipe", "卡片擦除"), - ("ec.transition.ccglasswipe", "CC Glass Wipe", "CC 玻璃擦除"), - ("ec.transition.ccgridwipe", "CC Grid Wipe", "CC 网格擦除"), - ("ec.transition.ccimagewipe", "CC Image Wipe", "CC 图像擦除"), - ("ec.transition.ccjaws", "CC Jaws", "CC 锯齿"), - ("ec.transition.cclightwipe", "CC Light Wipe", "CC 光线擦除"), - ("ec.transition.cclinesweep", "CC Line Sweep", "CC 线条扫掠"), - ("ec.transition.ccradialscalewipe", "CC Radial ScaleWipe", "CC 径向缩放擦除"), - ("ec.transition.ccscalewipe", "CC Scale Wipe", "CC 缩放擦除"), - ("ec.transition.cctwister", "CC Twister", "CC 扭曲器"), - ("ec.transition.ccwarpomatic", "CC WarpoMatic", "CC 自动扭曲"), + ("ec.transition.ccglasswipe", "Glass Wipe", "玻璃擦除"), + ("ec.transition.ccgridwipe", "Grid Wipe", "网格擦除"), + ("ec.transition.ccimagewipe", "Luminance Image Wipe", "亮度图像擦除"), + ("ec.transition.ccjaws", "Serrated Wipe", "锯齿擦除"), + ("ec.transition.cclightwipe", "Light Wipe", "光线擦除"), + ("ec.transition.cclinesweep", "Line Sweep", "线条扫过"), + ("ec.transition.ccradialscalewipe", "Radial Scale Wipe", "径向缩放擦除"), + ("ec.transition.ccscalewipe", "Scale Wipe", "缩放擦除"), + ("ec.transition.cctwister", "Twist Wipe", "扭转擦除"), + ("ec.transition.ccwarpomatic", "Warp Dissolve", "变形溶解"), ("ec.transition.gradientwipe", "Gradient Wipe", "渐变擦除"), ("ec.transition.iriswipe", "Iris Wipe", "光圈擦除"), ("ec.transition.linearwipe", "Linear Wipe", "线性擦除"), ("ec.transition.radialwipe", "Radial Wipe", "径向擦除"), ("ec.transition.venetian", "Venetian Blinds", "百叶窗"), ("ec.utility.applylut", "Apply Color LUT", "应用颜色 LUT"), - ("ec.utility.ccoverbrights", "CC Overbrights", "CC 高光溢出"), + ("ec.utility.ccoverbrights", "Out-of-Range Display", "超出范围显示"), ("ec.utility.cineon", "Cineon Converter", "Cineon 转换器"), ("ec.utility.colorprofileconverter", "Color Profile Converter", "颜色配置文件转换器"), ("ec.utility.facemeasurements", "Face Measurements", "面部测量"), @@ -480,9 +487,9 @@ const SIMPLIFIED_CHINESE: &[Row] = &[ /// [`SIMPLIFIED_CHINESE`]. Written from the meaning of the English names with the vocabulary /// Taiwan's creative software uses (圖層, 遮罩, 筆刷, 雜訊, 發光, 漸層), not converted from the /// Simplified table. Brand and coined names (`Cryptomatte`, `EXtractoR`, `IDentifier`, `Key Light`, -/// `Unmult`, `Lumetri Color`, `Colorama`, `Minimax`, `Vegas`, `Mocha`) stay in English; the `CC` -/// series keeps its prefix and translates the descriptive tail, and the `VR` and `OCIO` sets keep -/// their prefix in Chinese word order. +/// `Unmult`, `Colorama`, `Minimax`, `Vegas`) stay in English; the `VR` and `OCIO` sets keep their +/// prefix in Chinese word order. The effects this cleanup renamed are translated from their new +/// descriptive names. const TRADITIONAL_CHINESE: &[Row] = &[ ("ec.3d.channelextract", "3D Channel Extract", "3D 通道擷取"), ("ec.3d.cryptomatte", "Cryptomatte", "Cryptomatte"), @@ -509,10 +516,10 @@ const TRADITIONAL_CHINESE: &[Row] = &[ ("ec.blur.bilateral", "Bilateral Blur", "雙邊模糊"), ("ec.blur.cameralens", "Camera Lens Blur", "相機鏡頭模糊"), ("ec.blur.camerashakedeblur", "Camera-Shake Deblur", "相機晃動去模糊"), - ("ec.blur.cccross", "CC Cross Blur", "CC 十字模糊"), - ("ec.blur.ccradial", "CC Radial Blur", "CC 徑向模糊"), - ("ec.blur.ccradialfast", "CC Radial Fast Blur", "CC 徑向快速模糊"), - ("ec.blur.ccvector", "CC Vector Blur", "CC 向量模糊"), + ("ec.blur.cccross", "Cross Blur", "十字模糊"), + ("ec.blur.ccradial", "Variable Radial Blur", "可變放射狀模糊"), + ("ec.blur.ccradialfast", "Fast Radial Blur", "快速放射狀模糊"), + ("ec.blur.ccvector", "Vector Blur", "向量模糊"), ("ec.blur.channel", "Channel Blur", "通道模糊"), ("ec.blur.compound", "Compound Blur", "複合模糊"), ("ec.blur.directional", "Directional Blur", "方向模糊"), @@ -526,7 +533,7 @@ const TRADITIONAL_CHINESE: &[Row] = &[ ("ec.channel.arithmetic", "Arithmetic", "算術"), ("ec.channel.blend", "Blend", "混合"), ("ec.channel.calculations", "Calculations", "運算"), - ("ec.channel.cccomposite", "CC Composite", "CC 合成"), + ("ec.channel.cccomposite", "Source Composite", "來源影像合成"), ("ec.channel.combiner", "Channel Combiner", "通道合成器"), ("ec.channel.compoundarithmetic", "Compound Arithmetic", "複合算術"), ("ec.channel.invert", "Invert", "反轉"), @@ -542,10 +549,10 @@ const TRADITIONAL_CHINESE: &[Row] = &[ ("ec.color.blackwhite", "Black & White", "黑白"), ("ec.color.brightnesscontrast", "Brightness & Contrast", "亮度與對比"), ("ec.color.broadcast", "Broadcast Colors", "廣播色彩"), - ("ec.color.cccolorneutralizer", "CC Color Neutralizer", "CC 色彩中和器"), - ("ec.color.cccoloroffset", "CC Color Offset", "CC 色彩偏移"), - ("ec.color.cckernel", "CC Kernel", "CC 核心"), - ("ec.color.cctoner", "CC Toner", "CC 色調"), + ("ec.color.cccolorneutralizer", "Color Neutralizer", "色偏校正"), + ("ec.color.cccoloroffset", "Channel Offset", "色版偏移"), + ("ec.color.cckernel", "Convolution Kernel", "卷積核心"), + ("ec.color.cctoner", "Multi-Tone Tint", "多色調著色"), ("ec.color.changecolor", "Change Color", "變更色彩"), ("ec.color.changetocolor", "Change to Color", "變更為色彩"), ("ec.color.channelmixer", "Channel Mixer", "通道混合器"), @@ -562,7 +569,7 @@ const TRADITIONAL_CHINESE: &[Row] = &[ ("ec.color.leavecolor", "Leave Color", "保留色彩"), ("ec.color.levels", "Levels", "色階"), ("ec.color.levelsic", "Levels (Individual Controls)", "色階(個別控制項)"), - ("ec.color.lumetri", "Lumetri Color", "Lumetri Color"), + ("ec.color.lumetri", "Color Grading", "色彩分級"), ("ec.color.ociocdl", "OCIO CDL Transform", "OCIO CDL 轉換"), ("ec.color.ociocolorspace", "OCIO Color Space Transform", "OCIO 色彩空間轉換"), ("ec.color.ociodisplay", "OCIO Display Transform", "OCIO 顯示轉換"), @@ -587,20 +594,20 @@ const TRADITIONAL_CHINESE: &[Row] = &[ ("ec.control.stereo3d", "Stereo 3D Controls", "立體 3D 控制"), ("ec.distort.bezierwarp", "Bezier Warp", "貝茲彎曲"), ("ec.distort.bulge", "Bulge", "凸出"), - ("ec.distort.ccbender", "CC Bender", "CC 彎曲"), - ("ec.distort.ccbendit", "CC Bend It", "CC 彎折"), - ("ec.distort.ccblobbylize", "CC Blobbylize", "CC 團塊化"), - ("ec.distort.ccflomotion", "CC Flo Motion", "CC 流動"), - ("ec.distort.ccgriddler", "CC Griddler", "CC 格線"), - ("ec.distort.cclens", "CC Lens", "CC 鏡頭"), - ("ec.distort.ccpageturn", "CC Page Turn", "CC 翻頁"), - ("ec.distort.ccpowerpin", "CC Power Pin", "CC 強力釘選"), - ("ec.distort.ccripplepulse", "CC Ripple Pulse", "CC 漣漪脈衝"), - ("ec.distort.ccslant", "CC Slant", "CC 傾斜"), - ("ec.distort.ccsmear", "CC Smear", "CC 塗抹"), - ("ec.distort.ccsplit", "CC Split", "CC 分割"), - ("ec.distort.ccsplit2", "CC Split 2", "CC 分割 2"), - ("ec.distort.cctiler", "CC Tiler", "CC 並排"), + ("ec.distort.ccbender", "Flexible Bend", "柔性彎曲"), + ("ec.distort.ccbendit", "Two-Point Bend", "兩點彎曲"), + ("ec.distort.ccblobbylize", "Organic Displacement", "有機置換"), + ("ec.distort.ccflomotion", "Dual Lens Warp", "雙鏡頭變形"), + ("ec.distort.ccgriddler", "Tile Grid", "拼貼網格"), + ("ec.distort.cclens", "Lens Distortion", "鏡頭畸變"), + ("ec.distort.ccpageturn", "Page Curl", "頁面捲曲"), + ("ec.distort.ccpowerpin", "Perspective Pin", "透視定位"), + ("ec.distort.ccripplepulse", "Pulsed Ripple", "脈衝漣漪"), + ("ec.distort.ccslant", "Slant", "傾斜"), + ("ec.distort.ccsmear", "Directional Smear", "定向塗抹"), + ("ec.distort.ccsplit", "Split Warp", "分割變形"), + ("ec.distort.ccsplit2", "Dual Split Warp", "雙重分割變形"), + ("ec.distort.cctiler", "Scaled Tiles", "縮放平鋪"), ("ec.distort.cornerpin", "Corner Pin", "邊角釘選"), ("ec.distort.displacementmap", "Displacement Map", "位移映射"), ("ec.distort.liquify", "Liquify", "液化"), @@ -628,11 +635,11 @@ const TRADITIONAL_CHINESE: &[Row] = &[ ("ec.generate.audiospectrum", "Audio Spectrum", "音訊頻譜"), ("ec.generate.audiowaveform", "Audio Waveform", "音訊波形"), ("ec.generate.beam", "Beam", "光束"), - ("ec.generate.ccgluegun", "CC Glue Gun", "CC 膠水槍"), - ("ec.generate.cclightburst", "CC Light Burst 2.5", "CC 光爆 2.5"), - ("ec.generate.cclightrays", "CC Light Rays", "CC 光線"), - ("ec.generate.cclightsweep", "CC Light Sweep", "CC 光線掃掠"), - ("ec.generate.ccthreads", "CC Threads", "CC 絲線"), + ("ec.generate.ccgluegun", "Paint Beads", "顏料珠"), + ("ec.generate.cclightburst", "Radial Light Burst", "放射狀光芒"), + ("ec.generate.cclightrays", "Light Rays", "光線"), + ("ec.generate.cclightsweep", "Light Sweep", "掃光"), + ("ec.generate.ccthreads", "Woven Threads", "編織線"), ("ec.generate.cellpattern", "Cell Pattern", "細胞圖樣"), ("ec.generate.checkerboard", "Checkerboard", "棋盤格"), ("ec.generate.circle", "Circle", "圓形"), @@ -651,7 +658,7 @@ const TRADITIONAL_CHINESE: &[Row] = &[ ("ec.generate.vegas", "Vegas", "Vegas"), ("ec.generate.writeon", "Write-on", "書寫"), ("ec.key.advancedspill", "Advanced Spill Suppressor", "進階溢色抑制"), - ("ec.key.ccsimplewireremoval", "CC Simple Wire Removal", "CC 簡易鋼絲移除"), + ("ec.key.ccsimplewireremoval", "Line Removal", "線條移除"), ("ec.key.colordifference", "Color Difference Key", "色彩差異去背"), ("ec.key.colorkey", "Color Key", "色彩去背"), ("ec.key.colorrange", "Color Range", "色彩範圍"), @@ -664,7 +671,7 @@ const TRADITIONAL_CHINESE: &[Row] = &[ ("ec.key.screen", "Screen Key", "螢幕去背"), ("ec.key.spill", "Spill Suppressor", "溢色抑制"), ("ec.key.unmult", "Unmult", "Unmult"), - ("ec.keying.keylight", "Key Light", "Key Light"), + ("ec.keying.keylight", "Screen Color Key", "螢幕色鍵"), ("ec.matte.mattechoker", "Matte Choker", "遮罩收縮器"), ("ec.matte.objectmatte", "Object Matte", "物件遮罩"), ("ec.matte.refinehard", "Refine Hard Matte", "調整硬邊遮罩"), @@ -688,50 +695,50 @@ const TRADITIONAL_CHINESE: &[Row] = &[ ("ec.obsolete.basictext", "Basic Text", "基礎文字"), ("ec.obsolete.gaussianlegacy", "Gaussian Blur (Legacy)", "高斯模糊(舊版)"), ("ec.obsolete.lightning", "Lightning", "閃電"), - ("ec.obsolete.mochashape", "Mocha shape", "Mocha 形狀"), + ("ec.obsolete.mochashape", "Tracked Shape Matte", "追蹤形狀遮罩"), ("ec.obsolete.pathtext", "Path Text", "路徑文字"), ("ec.paint.paint", "Paint", "繪畫"), ("ec.perspective.3dglasses", "3D Glasses", "3D 眼鏡"), ("ec.perspective.bevelalpha", "Bevel Alpha", "Alpha 斜角"), ("ec.perspective.beveledges", "Bevel Edges", "邊緣斜角"), ("ec.perspective.cameratracker", "3D Camera Tracker", "3D 攝影機追蹤"), - ("ec.perspective.cccylinder", "CC Cylinder", "CC 圓柱"), - ("ec.perspective.ccenvironment", "CC Environment", "CC 環境"), - ("ec.perspective.ccsphere", "CC Sphere", "CC 球體"), - ("ec.perspective.ccspotlight", "CC Spotlight", "CC 聚光燈"), + ("ec.perspective.cccylinder", "Cylinder Wrap", "圓柱包覆"), + ("ec.perspective.ccenvironment", "Environment Map", "環境貼圖"), + ("ec.perspective.ccsphere", "Sphere Wrap", "球面包覆"), + ("ec.perspective.ccspotlight", "Surface Spotlight", "表面聚光燈"), ("ec.perspective.dropshadow", "Drop Shadow", "陰影"), ("ec.perspective.radialshadow", "Radial Shadow", "徑向陰影"), ("ec.sim.carddance", "Card Dance", "卡片舞蹈"), ("ec.sim.caustics", "Caustics", "焦散"), - ("ec.sim.ccballaction", "CC Ball Action", "CC 球狀動作"), - ("ec.sim.ccbubbles", "CC Bubbles", "CC 泡泡"), - ("ec.sim.ccdrizzle", "CC Drizzle", "CC 細雨"), - ("ec.sim.cchair", "CC Hair", "CC 毛髮"), - ("ec.sim.ccmrmercury", "CC Mr. Mercury", "CC 水銀先生"), - ("ec.sim.ccparticlesystems2", "CC Particle Systems II", "CC 粒子系統 II"), - ("ec.sim.ccparticleworld", "CC Particle World", "CC 粒子世界"), - ("ec.sim.ccpixelpolly", "CC Pixel Polly", "CC 像素破碎"), - ("ec.sim.ccrainfall", "CC Rainfall", "CC 下雨"), - ("ec.sim.ccscatterize", "CC Scatterize", "CC 散開"), - ("ec.sim.ccsnowfall", "CC Snowfall", "CC 下雪"), - ("ec.sim.ccstarburst", "CC Star Burst", "CC 星爆"), + ("ec.sim.ccballaction", "Ball Grid", "球體網格"), + ("ec.sim.ccbubbles", "Bubbles", "氣泡"), + ("ec.sim.ccdrizzle", "Water Ripples", "水面漣漪"), + ("ec.sim.cchair", "Surface Fibers", "表面纖維"), + ("ec.sim.ccmrmercury", "Liquid Particles", "液體粒子"), + ("ec.sim.ccparticlesystems2", "Particle Emitter 2D", "二維粒子發射器"), + ("ec.sim.ccparticleworld", "Particle Emitter 3D", "三維粒子發射器"), + ("ec.sim.ccpixelpolly", "Pixel Shatter", "像素破碎"), + ("ec.sim.ccrainfall", "Rainfall", "降雨"), + ("ec.sim.ccscatterize", "Pixel Scatter", "像素散射"), + ("ec.sim.ccsnowfall", "Snowfall", "降雪"), + ("ec.sim.ccstarburst", "Starfield", "星空"), ("ec.sim.foam", "Foam", "泡沫"), ("ec.sim.particleplayground", "Particle Playground", "粒子遊樂場"), ("ec.sim.shatter", "Shatter", "粉碎"), ("ec.sim.waveworld", "Wave World", "波浪世界"), ("ec.stylize.brushstrokes", "Brush Strokes", "筆觸"), ("ec.stylize.cartoon", "Cartoon", "卡通"), - ("ec.stylize.ccblockload", "CC Block Load", "CC 區塊載入"), - ("ec.stylize.ccburnfilm", "CC Burn Film", "CC 燒灼底片"), - ("ec.stylize.ccglass", "CC Glass", "CC 玻璃"), - ("ec.stylize.cchextile", "CC HexTile", "CC 六角並排"), - ("ec.stylize.cckaleida", "CC Kaleida", "CC 萬花筒"), - ("ec.stylize.ccmrsmoothie", "CC Mr. Smoothie", "CC 平滑先生"), - ("ec.stylize.ccplastic", "CC Plastic", "CC 塑膠"), - ("ec.stylize.ccrepetile", "CC RepeTile", "CC 重複並排"), - ("ec.stylize.ccthreshold", "CC Threshold", "CC 臨界值"), - ("ec.stylize.ccthresholdrgb", "CC Threshold RGB", "CC 臨界值 RGB"), - ("ec.stylize.ccvignette", "CC Vignette", "CC 暗角"), + ("ec.stylize.ccblockload", "Block Reveal", "區塊顯現"), + ("ec.stylize.ccburnfilm", "Film Burn", "膠片灼燒"), + ("ec.stylize.ccglass", "Glass Relief", "玻璃浮雕"), + ("ec.stylize.cchextile", "Hexagonal Tiles", "六角形拼貼"), + ("ec.stylize.cckaleida", "Kaleidoscope", "萬花筒"), + ("ec.stylize.ccmrsmoothie", "Palette Map", "調色盤對應"), + ("ec.stylize.ccplastic", "Plastic Shading", "塑膠著色"), + ("ec.stylize.ccrepetile", "Edge Tile Repeat", "邊緣拼貼重複"), + ("ec.stylize.ccthreshold", "Channel Threshold", "色版臨界值"), + ("ec.stylize.ccthresholdrgb", "RGB Threshold", "RGB 臨界值"), + ("ec.stylize.ccvignette", "Vignette", "暗角"), ("ec.stylize.coloremboss", "Color Emboss", "彩色浮雕"), ("ec.stylize.emboss", "Emboss", "浮雕"), ("ec.stylize.findedges", "Find Edges", "尋找邊緣"), @@ -746,8 +753,8 @@ const TRADITIONAL_CHINESE: &[Row] = &[ ("ec.stylize.threshold", "Threshold", "臨界值"), ("ec.text.numbers", "Numbers", "數字"), ("ec.text.timecode", "Timecode", "時間碼"), - ("ec.time.ccforcemotionblur", "CC Force Motion Blur", "CC 強制動態模糊"), - ("ec.time.ccwidetime", "CC Wide Time", "CC 寬廣時間"), + ("ec.time.ccforcemotionblur", "Temporal Motion Blur", "時間動態模糊"), + ("ec.time.ccwidetime", "Temporal Blend", "時間混合"), ("ec.time.echo", "Echo", "回音"), ("ec.time.pixelmotionblur", "Pixel Motion Blur", "像素動態模糊"), ("ec.time.posterizetime", "Posterize Time", "色調分離時間"), @@ -756,23 +763,23 @@ const TRADITIONAL_CHINESE: &[Row] = &[ ("ec.time.timewarp", "Timewarp", "時間扭曲"), ("ec.transition.blockdissolve", "Block Dissolve", "區塊溶解"), ("ec.transition.cardwipe", "Card Wipe", "卡片擦拭"), - ("ec.transition.ccglasswipe", "CC Glass Wipe", "CC 玻璃擦拭"), - ("ec.transition.ccgridwipe", "CC Grid Wipe", "CC 格線擦拭"), - ("ec.transition.ccimagewipe", "CC Image Wipe", "CC 影像擦拭"), - ("ec.transition.ccjaws", "CC Jaws", "CC 巨顎"), - ("ec.transition.cclightwipe", "CC Light Wipe", "CC 光線擦拭"), - ("ec.transition.cclinesweep", "CC Line Sweep", "CC 線條掃掠"), - ("ec.transition.ccradialscalewipe", "CC Radial ScaleWipe", "CC 徑向縮放擦拭"), - ("ec.transition.ccscalewipe", "CC Scale Wipe", "CC 縮放擦拭"), - ("ec.transition.cctwister", "CC Twister", "CC 扭轉"), - ("ec.transition.ccwarpomatic", "CC WarpoMatic", "CC 自動彎曲"), + ("ec.transition.ccglasswipe", "Glass Wipe", "玻璃擦拭"), + ("ec.transition.ccgridwipe", "Grid Wipe", "網格擦拭"), + ("ec.transition.ccimagewipe", "Luminance Image Wipe", "亮度影像擦拭"), + ("ec.transition.ccjaws", "Serrated Wipe", "鋸齒擦拭"), + ("ec.transition.cclightwipe", "Light Wipe", "光線擦拭"), + ("ec.transition.cclinesweep", "Line Sweep", "線條掃過"), + ("ec.transition.ccradialscalewipe", "Radial Scale Wipe", "放射狀縮放擦拭"), + ("ec.transition.ccscalewipe", "Scale Wipe", "縮放擦拭"), + ("ec.transition.cctwister", "Twist Wipe", "扭轉擦拭"), + ("ec.transition.ccwarpomatic", "Warp Dissolve", "變形溶解"), ("ec.transition.gradientwipe", "Gradient Wipe", "漸層擦拭"), ("ec.transition.iriswipe", "Iris Wipe", "光圈擦拭"), ("ec.transition.linearwipe", "Linear Wipe", "線性擦拭"), ("ec.transition.radialwipe", "Radial Wipe", "徑向擦拭"), ("ec.transition.venetian", "Venetian Blinds", "百葉窗"), ("ec.utility.applylut", "Apply Color LUT", "套用色彩 LUT"), - ("ec.utility.ccoverbrights", "CC Overbrights", "CC 過亮"), + ("ec.utility.ccoverbrights", "Out-of-Range Display", "超出範圍顯示"), ("ec.utility.cineon", "Cineon Converter", "Cineon 轉換器"), ("ec.utility.colorprofileconverter", "Color Profile Converter", "色彩設定檔轉換器"), ("ec.utility.facemeasurements", "Face Measurements", "臉部測量"), @@ -796,18 +803,18 @@ const TRADITIONAL_CHINESE: &[Row] = &[ /// Japanese (`ja`): reserved for the Japanese data point on #821, so both languages share this /// one catalog instead of inventing a second mechanism. A translator fills one row per effect, -/// ids from [`SIMPLIFIED_CHINESE`]; the names Adobe's Japanese interface leaves in English (the -/// `CC` series, `Cryptomatte`, `EXtractoR`, `IDentifier` and `Key Light`) repeat that English name -/// here rather than being left out; the `VR` and `OCIO` sets take a Japanese tail instead, and -/// `Unmult` keeps its English name in both catalogs. An effect with no row draws its English name -/// anyway, which is what `Twirl (Legacy)` and the two EffectCraft-only effects would do without -/// their rows. +/// ids from [`SIMPLIFIED_CHINESE`]; the names Adobe's Japanese interface leaves in English +/// (`Cryptomatte`, `EXtractoR`, `IDentifier` and `Key Light`) repeat that English name here rather +/// than being left out; the `VR` and `OCIO` sets take a Japanese tail instead, and `Unmult` keeps +/// its English name in both catalogs. An effect with no row draws its English name anyway, which +/// is what `Twirl (Legacy)` and the two EffectCraft-only effects would do without their rows. /// -/// The rows below come from AE 2026's Japanese interface where it was read directly (its Effect menu -/// and its Effects & Presets panel) and from Adobe's own Japanese help where the panel was not to -/// hand. A published glossary is used to cross-check, never as the only source: it normalises the -/// typography (half-width parentheses where AE draws full-width) and still carries CS6-era names for -/// the `CC` series, which AE 2026 leaves in English. +/// The rows of the effects this cleanup did not rename come from AE 2026's Japanese interface +/// where it was read directly (its Effect menu and its Effects & Presets panel) and from Adobe's +/// own Japanese help where the panel was not to hand. A published glossary is used to cross-check, +/// never as the only source: it normalises the typography (half-width parentheses where AE draws +/// full-width) and still carries CS6-era names for the `CC` series. The renamed effects are +/// translated from their new descriptive names. const JAPANESE_EFFECTS: &[Row] = &[ // Effects this application adds itself have no interface to read a name from, so they follow // the Chinese catalog's choice to translate them (顔の測定, 顔のトラッキングポイント) rather than @@ -847,10 +854,10 @@ const JAPANESE_EFFECTS: &[Row] = &[ ("ec.blur.bilateral", "Bilateral Blur", "ブラー(バイラテラル)"), ("ec.blur.cameralens", "Camera Lens Blur", "ブラー(カメラレンズ)"), ("ec.blur.camerashakedeblur", "Camera-Shake Deblur", "カメラぶれ除去"), - ("ec.blur.cccross", "CC Cross Blur", "CC Cross Blur"), - ("ec.blur.ccradial", "CC Radial Blur", "CC Radial Blur"), - ("ec.blur.ccradialfast", "CC Radial Fast Blur", "CC Radial Fast Blur"), - ("ec.blur.ccvector", "CC Vector Blur", "CC Vector Blur"), + ("ec.blur.cccross", "Cross Blur", "十字ぼかし"), + ("ec.blur.ccradial", "Variable Radial Blur", "可変放射状ぼかし"), + ("ec.blur.ccradialfast", "Fast Radial Blur", "高速放射状ぼかし"), + ("ec.blur.ccvector", "Vector Blur", "ベクトルぼかし"), ("ec.blur.channel", "Channel Blur", "ブラー(チャンネル)"), ("ec.blur.compound", "Compound Blur", "ブラー(合成)"), ("ec.blur.directional", "Directional Blur", "ブラー(方向)"), @@ -864,7 +871,7 @@ const JAPANESE_EFFECTS: &[Row] = &[ ("ec.channel.arithmetic", "Arithmetic", "アリスマチック"), ("ec.channel.blend", "Blend", "ブレンド"), ("ec.channel.calculations", "Calculations", "計算"), - ("ec.channel.cccomposite", "CC Composite", "CC Composite"), + ("ec.channel.cccomposite", "Source Composite", "元画像合成"), ("ec.channel.combiner", "Channel Combiner", "チャンネルコンバイナー"), ("ec.channel.compoundarithmetic", "Compound Arithmetic", "合成アリスマチック"), ("ec.channel.invert", "Invert", "反転"), @@ -879,10 +886,10 @@ const JAPANESE_EFFECTS: &[Row] = &[ ("ec.color.autolevels", "Auto Levels", "自動レベル補正"), ("ec.color.blackwhite", "Black & White", "白黒"), ("ec.color.brightnesscontrast", "Brightness & Contrast", "輝度&コントラスト"), - ("ec.color.cccolorneutralizer", "CC Color Neutralizer", "CC Color Neutralizer"), - ("ec.color.cccoloroffset", "CC Color Offset", "CC Color Offset"), - ("ec.color.cckernel", "CC Kernel", "CC Kernel"), - ("ec.color.cctoner", "CC Toner", "CC Toner"), + ("ec.color.cccolorneutralizer", "Color Neutralizer", "色かぶり補正"), + ("ec.color.cccoloroffset", "Channel Offset", "チャンネルオフセット"), + ("ec.color.cckernel", "Convolution Kernel", "畳み込みカーネル"), + ("ec.color.cctoner", "Multi-Tone Tint", "多色調ティント"), ("ec.color.changecolor", "Change Color", "色を変更"), ("ec.color.changetocolor", "Change to Color", "他のカラーへ変更"), ("ec.color.channelmixer", "Channel Mixer", "チャンネルミキサー"), @@ -899,7 +906,7 @@ const JAPANESE_EFFECTS: &[Row] = &[ ("ec.color.leavecolor", "Leave Color", "色抜き"), ("ec.color.levels", "Levels", "レベル補正"), ("ec.color.levelsic", "Levels (Individual Controls)", "レベル(個々の制御)"), - ("ec.color.lumetri", "Lumetri Color", "Lumetri カラー"), + ("ec.color.lumetri", "Color Grading", "カラーグレーディング"), ("ec.color.ociocdl", "OCIO CDL Transform", "OCIO CDL 変換"), ("ec.color.ociocolorspace", "OCIO Color Space Transform", "OCIO 色空間変換"), ("ec.color.ociodisplay", "OCIO Display Transform", "OCIO 表示変換"), @@ -909,7 +916,7 @@ const JAPANESE_EFFECTS: &[Row] = &[ ("ec.color.psarbitrarymap", "PS Arbitrary Map", "PS不定マップ"), ("ec.color.selectivecolor", "Selective Color", "特定色域の選択"), ("ec.color.shadowhighlight", "Shadow/Highlight", "シャドウ・ハイライト"), - ("ec.color.tint", "Tint", "色かぶり補正"), + ("ec.color.tint", "Tint", "着色"), ("ec.color.tritone", "Tritone", "トライトーン"), ("ec.color.vibrance", "Vibrance", "自然な彩度"), ("ec.color.videolimiter", "Video Limiter", "ビデオリミッター"), @@ -923,20 +930,20 @@ const JAPANESE_EFFECTS: &[Row] = &[ ("ec.control.slider", "Slider Control", "スライダー制御"), ("ec.distort.bezierwarp", "Bezier Warp", "ベジェワープ"), ("ec.distort.bulge", "Bulge", "バルジ"), - ("ec.distort.ccbender", "CC Bender", "CC Bender"), - ("ec.distort.ccbendit", "CC Bend It", "CC Bend It"), - ("ec.distort.ccblobbylize", "CC Blobbylize", "CC Blobbylize"), - ("ec.distort.ccflomotion", "CC Flo Motion", "CC Flo Motion"), - ("ec.distort.ccgriddler", "CC Griddler", "CC Griddler"), - ("ec.distort.cclens", "CC Lens", "CC Lens"), - ("ec.distort.ccpageturn", "CC Page Turn", "CC Page Turn"), - ("ec.distort.ccpowerpin", "CC Power Pin", "CC Power Pin"), - ("ec.distort.ccripplepulse", "CC Ripple Pulse", "CC Ripple Pulse"), - ("ec.distort.ccslant", "CC Slant", "CC Slant"), - ("ec.distort.ccsmear", "CC Smear", "CC Smear"), - ("ec.distort.ccsplit", "CC Split", "CC Split"), - ("ec.distort.ccsplit2", "CC Split 2", "CC Split 2"), - ("ec.distort.cctiler", "CC Tiler", "CC Tiler"), + ("ec.distort.ccbender", "Flexible Bend", "柔軟ベンド"), + ("ec.distort.ccbendit", "Two-Point Bend", "2点ベンド"), + ("ec.distort.ccblobbylize", "Organic Displacement", "有機変位"), + ("ec.distort.ccflomotion", "Dual Lens Warp", "ダブルレンズ変形"), + ("ec.distort.ccgriddler", "Tile Grid", "タイルグリッド"), + ("ec.distort.cclens", "Lens Distortion", "レンズ歪み"), + ("ec.distort.ccpageturn", "Page Curl", "ページカール"), + ("ec.distort.ccpowerpin", "Perspective Pin", "遠近ピン"), + ("ec.distort.ccripplepulse", "Pulsed Ripple", "パルス波紋"), + ("ec.distort.ccslant", "Slant", "傾斜"), + ("ec.distort.ccsmear", "Directional Smear", "方向性にじみ"), + ("ec.distort.ccsplit", "Split Warp", "分割変形"), + ("ec.distort.ccsplit2", "Dual Split Warp", "二重分割変形"), + ("ec.distort.cctiler", "Scaled Tiles", "スケールタイル"), ("ec.distort.cornerpin", "Corner Pin", "コーナーピン"), ("ec.distort.displacementmap", "Displacement Map", "ディスプレイスメントマップ"), ("ec.distort.liquify", "Liquify", "ゆがみ"), @@ -963,11 +970,11 @@ const JAPANESE_EFFECTS: &[Row] = &[ ("ec.generate.audiospectrum", "Audio Spectrum", "オーディオスペクトラム"), ("ec.generate.audiowaveform", "Audio Waveform", "オーディオウェーブフォーム"), ("ec.generate.beam", "Beam", "レーザー"), - ("ec.generate.ccgluegun", "CC Glue Gun", "CC Glue Gun"), - ("ec.generate.cclightburst", "CC Light Burst 2.5", "CC Light Burst 2.5"), - ("ec.generate.cclightrays", "CC Light Rays", "CC Light Rays"), - ("ec.generate.cclightsweep", "CC Light Sweep", "CC Light Sweep"), - ("ec.generate.ccthreads", "CC Threads", "CC Threads"), + ("ec.generate.ccgluegun", "Paint Beads", "絵の具の粒"), + ("ec.generate.cclightburst", "Radial Light Burst", "放射状の光"), + ("ec.generate.cclightrays", "Light Rays", "光線"), + ("ec.generate.cclightsweep", "Light Sweep", "光のスイープ"), + ("ec.generate.ccthreads", "Woven Threads", "織り糸"), ("ec.generate.cellpattern", "Cell Pattern", "セルパターン"), ("ec.generate.checkerboard", "Checkerboard", "チェッカーボード"), ("ec.generate.circle", "Circle", "円"), @@ -986,7 +993,7 @@ const JAPANESE_EFFECTS: &[Row] = &[ ("ec.generate.vegas", "Vegas", "ベガス"), ("ec.generate.writeon", "Write-on", "ブラシアニメーション"), ("ec.key.advancedspill", "Advanced Spill Suppressor", "Advanced Spill Suppressor"), - ("ec.key.ccsimplewireremoval", "CC Simple Wire Removal", "CC Simple Wire Removal"), + ("ec.key.ccsimplewireremoval", "Line Removal", "ライン除去"), ("ec.key.colordifference", "Color Difference Key", "カラー差キー"), ("ec.key.colorkey", "Color Key", "カラーキー"), ("ec.key.colorrange", "Color Range", "色範囲"), @@ -997,7 +1004,7 @@ const JAPANESE_EFFECTS: &[Row] = &[ ("ec.key.linearcolor", "Linear Color Key", "リニアカラーキー"), ("ec.key.luma", "Luma Key", "ルミナンスキー"), ("ec.key.spill", "Spill Suppressor", "スピルサプレッション"), - ("ec.keying.keylight", "Key Light", "Keylight (1.2)"), + ("ec.keying.keylight", "Screen Color Key", "スクリーンカラーキー"), ("ec.matte.mattechoker", "Matte Choker", "マットチョーク"), ("ec.matte.refinehard", "Refine Hard Matte", "ハードマットを調整"), ("ec.matte.refinesoft", "Refine Soft Matte", "ソフトマットを調整"), @@ -1019,49 +1026,49 @@ const JAPANESE_EFFECTS: &[Row] = &[ ("ec.obsolete.basictext", "Basic Text", "基本テキスト"), ("ec.obsolete.gaussianlegacy", "Gaussian Blur (Legacy)", "ブラー(ガウス)(レガシー)"), ("ec.obsolete.lightning", "Lightning", "稲妻"), - ("ec.obsolete.mochashape", "Mocha shape", "mocha shape"), + ("ec.obsolete.mochashape", "Tracked Shape Matte", "トラッキングシェイプマット"), ("ec.obsolete.pathtext", "Path Text", "パステキスト"), ("ec.perspective.3dglasses", "3D Glasses", "3Dメガネ"), ("ec.perspective.bevelalpha", "Bevel Alpha", "ベベルアルファ"), ("ec.perspective.beveledges", "Bevel Edges", "ベベルエッジ"), ("ec.perspective.cameratracker", "3D Camera Tracker", "3D カメラトラッカー"), - ("ec.perspective.cccylinder", "CC Cylinder", "CC Cylinder"), - ("ec.perspective.ccenvironment", "CC Environment", "CC Environment"), - ("ec.perspective.ccsphere", "CC Sphere", "CC Sphere"), - ("ec.perspective.ccspotlight", "CC Spotlight", "CC Spotlight"), + ("ec.perspective.cccylinder", "Cylinder Wrap", "円筒ラップ"), + ("ec.perspective.ccenvironment", "Environment Map", "環境マップ"), + ("ec.perspective.ccsphere", "Sphere Wrap", "球面ラップ"), + ("ec.perspective.ccspotlight", "Surface Spotlight", "表面スポットライト"), ("ec.perspective.dropshadow", "Drop Shadow", "ドロップシャドウ"), ("ec.perspective.radialshadow", "Radial Shadow", "放射状シャドウ"), ("ec.sim.carddance", "Card Dance", "カードダンス"), ("ec.sim.caustics", "Caustics", "コースティック"), - ("ec.sim.ccballaction", "CC Ball Action", "CC Ball Action"), - ("ec.sim.ccbubbles", "CC Bubbles", "CC Bubbles"), - ("ec.sim.ccdrizzle", "CC Drizzle", "CC Drizzle"), - ("ec.sim.cchair", "CC Hair", "CC Hair"), - ("ec.sim.ccmrmercury", "CC Mr. Mercury", "CC Mr. Mercury"), - ("ec.sim.ccparticlesystems2", "CC Particle Systems II", "CC Particle Systems II"), - ("ec.sim.ccparticleworld", "CC Particle World", "CC Particle World"), - ("ec.sim.ccpixelpolly", "CC Pixel Polly", "CC Pixel Polly"), - ("ec.sim.ccrainfall", "CC Rainfall", "CC Rainfall"), - ("ec.sim.ccscatterize", "CC Scatterize", "CC Scatterize"), - ("ec.sim.ccsnowfall", "CC Snowfall", "CC Snowfall"), - ("ec.sim.ccstarburst", "CC Star Burst", "CC Star Burst"), + ("ec.sim.ccballaction", "Ball Grid", "球体グリッド"), + ("ec.sim.ccbubbles", "Bubbles", "気泡"), + ("ec.sim.ccdrizzle", "Water Ripples", "水面の波紋"), + ("ec.sim.cchair", "Surface Fibers", "表面の繊維"), + ("ec.sim.ccmrmercury", "Liquid Particles", "液体パーティクル"), + ("ec.sim.ccparticlesystems2", "Particle Emitter 2D", "2Dパーティクルエミッター"), + ("ec.sim.ccparticleworld", "Particle Emitter 3D", "3Dパーティクルエミッター"), + ("ec.sim.ccpixelpolly", "Pixel Shatter", "ピクセル破砕"), + ("ec.sim.ccrainfall", "Rainfall", "雨"), + ("ec.sim.ccscatterize", "Pixel Scatter", "ピクセル散乱"), + ("ec.sim.ccsnowfall", "Snowfall", "雪"), + ("ec.sim.ccstarburst", "Starfield", "星空"), ("ec.sim.foam", "Foam", "泡"), ("ec.sim.particleplayground", "Particle Playground", "パーティクルプレイグラウンド"), ("ec.sim.shatter", "Shatter", "シャター"), ("ec.sim.waveworld", "Wave World", "ウェーブワールド"), ("ec.stylize.brushstrokes", "Brush Strokes", "ブラシストローク"), ("ec.stylize.cartoon", "Cartoon", "カートゥーン"), - ("ec.stylize.ccblockload", "CC Block Load", "CC Block Load"), - ("ec.stylize.ccburnfilm", "CC Burn Film", "CC Burn Film"), - ("ec.stylize.ccglass", "CC Glass", "CC Glass"), - ("ec.stylize.cchextile", "CC HexTile", "CC HexTile"), - ("ec.stylize.cckaleida", "CC Kaleida", "CC Kaleida"), - ("ec.stylize.ccmrsmoothie", "CC Mr. Smoothie", "CC Mr. Smoothie"), - ("ec.stylize.ccplastic", "CC Plastic", "CC Plastic"), - ("ec.stylize.ccrepetile", "CC RepeTile", "CC RepeTile"), - ("ec.stylize.ccthreshold", "CC Threshold", "CC Threshold"), - ("ec.stylize.ccthresholdrgb", "CC Threshold RGB", "CC Threshold RGB"), - ("ec.stylize.ccvignette", "CC Vignette", "CC Vignette"), + ("ec.stylize.ccblockload", "Block Reveal", "ブロック表示"), + ("ec.stylize.ccburnfilm", "Film Burn", "フィルム焼け"), + ("ec.stylize.ccglass", "Glass Relief", "ガラスレリーフ"), + ("ec.stylize.cchextile", "Hexagonal Tiles", "六角形タイル"), + ("ec.stylize.cckaleida", "Kaleidoscope", "万華鏡"), + ("ec.stylize.ccmrsmoothie", "Palette Map", "パレットマップ"), + ("ec.stylize.ccplastic", "Plastic Shading", "プラスチックシェーディング"), + ("ec.stylize.ccrepetile", "Edge Tile Repeat", "エッジタイル反復"), + ("ec.stylize.ccthreshold", "Channel Threshold", "チャンネルしきい値"), + ("ec.stylize.ccthresholdrgb", "RGB Threshold", "RGBしきい値"), + ("ec.stylize.ccvignette", "Vignette", "ビネット"), ("ec.stylize.coloremboss", "Color Emboss", "カラーエンボス"), ("ec.stylize.emboss", "Emboss", "エンボス"), ("ec.stylize.findedges", "Find Edges", "輪郭検出"), @@ -1076,8 +1083,8 @@ const JAPANESE_EFFECTS: &[Row] = &[ ("ec.stylize.threshold", "Threshold", "しきい値"), ("ec.text.numbers", "Numbers", "番号"), ("ec.text.timecode", "Timecode", "タイムコード"), - ("ec.time.ccforcemotionblur", "CC Force Motion Blur", "CC Force Motion Blur"), - ("ec.time.ccwidetime", "CC Wide Time", "CC Wide Time"), + ("ec.time.ccforcemotionblur", "Temporal Motion Blur", "時間方向モーションブラー"), + ("ec.time.ccwidetime", "Temporal Blend", "時間ブレンド"), ("ec.time.echo", "Echo", "エコー"), ("ec.time.pixelmotionblur", "Pixel Motion Blur", "ピクセルモーションブラー"), ("ec.time.posterizetime", "Posterize Time", "ポスタリゼーション時間"), @@ -1086,23 +1093,23 @@ const JAPANESE_EFFECTS: &[Row] = &[ ("ec.time.timewarp", "Timewarp", "タイムワープ"), ("ec.transition.blockdissolve", "Block Dissolve", "ブロックディゾルブ"), ("ec.transition.cardwipe", "Card Wipe", "カードワイプ"), - ("ec.transition.ccglasswipe", "CC Glass Wipe", "CC Glass Wipe"), - ("ec.transition.ccgridwipe", "CC Grid Wipe", "CC Grid Wipe"), - ("ec.transition.ccimagewipe", "CC Image Wipe", "CC Image Wipe"), - ("ec.transition.ccjaws", "CC Jaws", "CC Jaws"), - ("ec.transition.cclightwipe", "CC Light Wipe", "CC Light Wipe"), - ("ec.transition.cclinesweep", "CC Line Sweep", "CC Line Sweep"), - ("ec.transition.ccradialscalewipe", "CC Radial ScaleWipe", "CC Radial ScaleWipe"), - ("ec.transition.ccscalewipe", "CC Scale Wipe", "CC Scale Wipe"), - ("ec.transition.cctwister", "CC Twister", "CC Twister"), - ("ec.transition.ccwarpomatic", "CC WarpoMatic", "CC WarpoMatic"), + ("ec.transition.ccglasswipe", "Glass Wipe", "ガラスワイプ"), + ("ec.transition.ccgridwipe", "Grid Wipe", "グリッドワイプ"), + ("ec.transition.ccimagewipe", "Luminance Image Wipe", "輝度画像ワイプ"), + ("ec.transition.ccjaws", "Serrated Wipe", "鋸歯状ワイプ"), + ("ec.transition.cclightwipe", "Light Wipe", "ライトワイプ"), + ("ec.transition.cclinesweep", "Line Sweep", "ラインスイープ"), + ("ec.transition.ccradialscalewipe", "Radial Scale Wipe", "放射状スケールワイプ"), + ("ec.transition.ccscalewipe", "Scale Wipe", "スケールワイプ"), + ("ec.transition.cctwister", "Twist Wipe", "ツイストワイプ"), + ("ec.transition.ccwarpomatic", "Warp Dissolve", "変形ディゾルブ"), ("ec.transition.gradientwipe", "Gradient Wipe", "グラデーションワイプ"), ("ec.transition.iriswipe", "Iris Wipe", "アイリスワイプ"), ("ec.transition.linearwipe", "Linear Wipe", "リニアワイプ"), ("ec.transition.radialwipe", "Radial Wipe", "放射状ワイプ"), ("ec.transition.venetian", "Venetian Blinds", "ブラインド"), ("ec.utility.applylut", "Apply Color LUT", "カラー LUT を適用"), - ("ec.utility.ccoverbrights", "CC Overbrights", "CC Overbrights"), + ("ec.utility.ccoverbrights", "Out-of-Range Display", "範囲外表示"), ("ec.utility.cineon", "Cineon Converter", "Cineon コンバーター"), ("ec.utility.colorprofileconverter", "Color Profile Converter", "カラープロファイルコンバーター"), ("ec.utility.growbounds", "Grow Bounds", "範囲拡張"), @@ -1176,9 +1183,9 @@ const JAPANESE_CATEGORIES: &[(&str, &str)] = &[ /// Georgian (`ka`): one row per effect, ids from [`SIMPLIFIED_CHINESE`]. Written from the meaning /// of the English names, with the terms the Georgian menus and panels use (FilmCraft's Georgian -/// for the effects the two apps share). The `CC` series and the brand names (`Cryptomatte`, -/// `EXtractoR`, `IDentifier`, `Key Light`, `Unmult`, `Lumetri Color`) stay in English, as -/// Adobe's Japanese interface keeps the `CC` series; `VR` and `OCIO` keep their prefix. +/// for the effects the two apps share). The brand names (`Cryptomatte`, `EXtractoR`, `IDentifier`, +/// `Key Light`, `Unmult`) stay in English; `VR` and `OCIO` keep their prefix. The renamed effects +/// are translated from their new descriptive names. const GEORGIAN: &[Row] = &[ ("ec.3d.channelextract", "3D Channel Extract", "3D არხის ამოღება"), ("ec.3d.cryptomatte", "Cryptomatte", "Cryptomatte"), @@ -1205,10 +1212,10 @@ const GEORGIAN: &[Row] = &[ ("ec.blur.bilateral", "Bilateral Blur", "ბილატერალური გაბუნდოვნება"), ("ec.blur.cameralens", "Camera Lens Blur", "კამერის ობიექტივის გაბუნდოვნება"), ("ec.blur.camerashakedeblur", "Camera-Shake Deblur", "კამერის რყევით გაბუნდოვნების მოცილება"), - ("ec.blur.cccross", "CC Cross Blur", "CC Cross Blur"), - ("ec.blur.ccradial", "CC Radial Blur", "CC Radial Blur"), - ("ec.blur.ccradialfast", "CC Radial Fast Blur", "CC Radial Fast Blur"), - ("ec.blur.ccvector", "CC Vector Blur", "CC Vector Blur"), + ("ec.blur.cccross", "Cross Blur", "ჯვარედინი დაბინდვა"), + ("ec.blur.ccradial", "Variable Radial Blur", "ცვლადი რადიალური დაბინდვა"), + ("ec.blur.ccradialfast", "Fast Radial Blur", "სწრაფი რადიალური დაბინდვა"), + ("ec.blur.ccvector", "Vector Blur", "ვექტორული დაბინდვა"), ("ec.blur.channel", "Channel Blur", "არხის გაბუნდოვნება"), ("ec.blur.compound", "Compound Blur", "შედგენილი გაბუნდოვნება"), ("ec.blur.directional", "Directional Blur", "მიმართული გაბუნდოვნება"), @@ -1222,7 +1229,7 @@ const GEORGIAN: &[Row] = &[ ("ec.channel.arithmetic", "Arithmetic", "არითმეტიკა"), ("ec.channel.blend", "Blend", "შერევა"), ("ec.channel.calculations", "Calculations", "გამოთვლები"), - ("ec.channel.cccomposite", "CC Composite", "CC Composite"), + ("ec.channel.cccomposite", "Source Composite", "წყაროს კომპოზიცია"), ("ec.channel.combiner", "Channel Combiner", "არხების გამაერთიანებელი"), ("ec.channel.compoundarithmetic", "Compound Arithmetic", "შედგენილი არითმეტიკა"), ("ec.channel.invert", "Invert", "ინვერსია"), @@ -1238,10 +1245,10 @@ const GEORGIAN: &[Row] = &[ ("ec.color.blackwhite", "Black & White", "შავ-თეთრი"), ("ec.color.brightnesscontrast", "Brightness & Contrast", "სიკაშკაშე და კონტრასტი"), ("ec.color.broadcast", "Broadcast Colors", "სამაუწყებლო ფერები"), - ("ec.color.cccolorneutralizer", "CC Color Neutralizer", "CC Color Neutralizer"), - ("ec.color.cccoloroffset", "CC Color Offset", "CC Color Offset"), - ("ec.color.cckernel", "CC Kernel", "CC Kernel"), - ("ec.color.cctoner", "CC Toner", "CC Toner"), + ("ec.color.cccolorneutralizer", "Color Neutralizer", "ფერის ნეიტრალიზაცია"), + ("ec.color.cccoloroffset", "Channel Offset", "არხების წანაცვლება"), + ("ec.color.cckernel", "Convolution Kernel", "კონვოლუციის ბირთვი"), + ("ec.color.cctoner", "Multi-Tone Tint", "მრავალტონიანი შეფერილობა"), ("ec.color.changecolor", "Change Color", "ფერის შეცვლა"), ("ec.color.changetocolor", "Change to Color", "ფერად შეცვლა"), ("ec.color.channelmixer", "Channel Mixer", "არხების მიქშერი"), @@ -1258,7 +1265,7 @@ const GEORGIAN: &[Row] = &[ ("ec.color.leavecolor", "Leave Color", "ფერის დატოვება"), ("ec.color.levels", "Levels", "დონეები"), ("ec.color.levelsic", "Levels (Individual Controls)", "დონეები (ცალკეული მართვა)"), - ("ec.color.lumetri", "Lumetri Color", "Lumetri Color"), + ("ec.color.lumetri", "Color Grading", "ფერთა კორექცია"), ("ec.color.ociocdl", "OCIO CDL Transform", "OCIO CDL გარდაქმნა"), ("ec.color.ociocolorspace", "OCIO Color Space Transform", "OCIO ფერთა სივრცის გარდაქმნა"), ("ec.color.ociodisplay", "OCIO Display Transform", "OCIO ეკრანის გარდაქმნა"), @@ -1283,20 +1290,20 @@ const GEORGIAN: &[Row] = &[ ("ec.control.stereo3d", "Stereo 3D Controls", "სტერეო 3D მართვა"), ("ec.distort.bezierwarp", "Bezier Warp", "ბეზიეს დეფორმაცია"), ("ec.distort.bulge", "Bulge", "გამობერილობა"), - ("ec.distort.ccbender", "CC Bender", "CC Bender"), - ("ec.distort.ccbendit", "CC Bend It", "CC Bend It"), - ("ec.distort.ccblobbylize", "CC Blobbylize", "CC Blobbylize"), - ("ec.distort.ccflomotion", "CC Flo Motion", "CC Flo Motion"), - ("ec.distort.ccgriddler", "CC Griddler", "CC Griddler"), - ("ec.distort.cclens", "CC Lens", "CC Lens"), - ("ec.distort.ccpageturn", "CC Page Turn", "CC Page Turn"), - ("ec.distort.ccpowerpin", "CC Power Pin", "CC Power Pin"), - ("ec.distort.ccripplepulse", "CC Ripple Pulse", "CC Ripple Pulse"), - ("ec.distort.ccslant", "CC Slant", "CC Slant"), - ("ec.distort.ccsmear", "CC Smear", "CC Smear"), - ("ec.distort.ccsplit", "CC Split", "CC Split"), - ("ec.distort.ccsplit2", "CC Split 2", "CC Split 2"), - ("ec.distort.cctiler", "CC Tiler", "CC Tiler"), + ("ec.distort.ccbender", "Flexible Bend", "მოქნილი მოღუნვა"), + ("ec.distort.ccbendit", "Two-Point Bend", "ორწერტილიანი მოღუნვა"), + ("ec.distort.ccblobbylize", "Organic Displacement", "ორგანული გადაადგილება"), + ("ec.distort.ccflomotion", "Dual Lens Warp", "ორმაგი ლინზით დეფორმაცია"), + ("ec.distort.ccgriddler", "Tile Grid", "ფილების ბადე"), + ("ec.distort.cclens", "Lens Distortion", "ლინზის დამახინჯება"), + ("ec.distort.ccpageturn", "Page Curl", "გვერდის დახვევა"), + ("ec.distort.ccpowerpin", "Perspective Pin", "პერსპექტიული დამაგრება"), + ("ec.distort.ccripplepulse", "Pulsed Ripple", "პულსური ტალღა"), + ("ec.distort.ccslant", "Slant", "დახრა"), + ("ec.distort.ccsmear", "Directional Smear", "მიმართულებითი გაწელვა"), + ("ec.distort.ccsplit", "Split Warp", "გაყოფილი დეფორმაცია"), + ("ec.distort.ccsplit2", "Dual Split Warp", "ორმაგად გაყოფილი დეფორმაცია"), + ("ec.distort.cctiler", "Scaled Tiles", "მასშტაბირებული ფილები"), ("ec.distort.cornerpin", "Corner Pin", "კუთხეების მიმაგრება"), ("ec.distort.displacementmap", "Displacement Map", "წანაცვლების რუკა"), ("ec.distort.liquify", "Liquify", "გათხევადება"), @@ -1324,11 +1331,11 @@ const GEORGIAN: &[Row] = &[ ("ec.generate.audiospectrum", "Audio Spectrum", "აუდიოს სპექტრი"), ("ec.generate.audiowaveform", "Audio Waveform", "აუდიოს ტალღის ფორმა"), ("ec.generate.beam", "Beam", "სხივი"), - ("ec.generate.ccgluegun", "CC Glue Gun", "CC Glue Gun"), - ("ec.generate.cclightburst", "CC Light Burst 2.5", "CC Light Burst 2.5"), - ("ec.generate.cclightrays", "CC Light Rays", "CC Light Rays"), - ("ec.generate.cclightsweep", "CC Light Sweep", "CC Light Sweep"), - ("ec.generate.ccthreads", "CC Threads", "CC Threads"), + ("ec.generate.ccgluegun", "Paint Beads", "საღებავის მარცვლები"), + ("ec.generate.cclightburst", "Radial Light Burst", "რადიალური ნათება"), + ("ec.generate.cclightrays", "Light Rays", "სინათლის სხივები"), + ("ec.generate.cclightsweep", "Light Sweep", "სინათლის გავლა"), + ("ec.generate.ccthreads", "Woven Threads", "ნაქსოვი ძაფები"), ("ec.generate.cellpattern", "Cell Pattern", "უჯრედების პატერნი"), ("ec.generate.checkerboard", "Checkerboard", "ჭადრაკის დაფა"), ("ec.generate.circle", "Circle", "წრე"), @@ -1347,7 +1354,7 @@ const GEORGIAN: &[Row] = &[ ("ec.generate.vegas", "Vegas", "ვეგასი"), ("ec.generate.writeon", "Write-on", "თანდათანობითი წერა"), ("ec.key.advancedspill", "Advanced Spill Suppressor", "ფერის გადაღვრის გაფართოებული ჩამხშობი"), - ("ec.key.ccsimplewireremoval", "CC Simple Wire Removal", "CC Simple Wire Removal"), + ("ec.key.ccsimplewireremoval", "Line Removal", "ხაზის მოცილება"), ("ec.key.colordifference", "Color Difference Key", "ფერთა სხვაობის გასაღები"), ("ec.key.colorkey", "Color Key", "ფერის გასაღები"), ("ec.key.colorrange", "Color Range", "ფერების დიაპაზონი"), @@ -1360,7 +1367,7 @@ const GEORGIAN: &[Row] = &[ ("ec.key.screen", "Screen Key", "ეკრანის გასაღები"), ("ec.key.spill", "Spill Suppressor", "ფერის გადაღვრის ჩამხშობი"), ("ec.key.unmult", "Unmult", "Unmult"), - ("ec.keying.keylight", "Key Light", "Key Light"), + ("ec.keying.keylight", "Screen Color Key", "ეკრანის ფერის გამოყოფა"), ("ec.matte.mattechoker", "Matte Choker", "მატის შემკუმშველი"), ("ec.matte.objectmatte", "Object Matte", "ობიექტის მატი"), ("ec.matte.refinehard", "Refine Hard Matte", "მკვეთრი მატის დახვეწა"), @@ -1384,50 +1391,50 @@ const GEORGIAN: &[Row] = &[ ("ec.obsolete.basictext", "Basic Text", "საბაზო ტექსტი"), ("ec.obsolete.gaussianlegacy", "Gaussian Blur (Legacy)", "გაუსის გაბუნდოვნება (მოძველებული)"), ("ec.obsolete.lightning", "Lightning", "ელვა"), - ("ec.obsolete.mochashape", "Mocha shape", "Mocha-ს ფიგურა"), + ("ec.obsolete.mochashape", "Tracked Shape Matte", "თვალთვალის ფორმის ნიღაბი"), ("ec.obsolete.pathtext", "Path Text", "ტექსტი ტრაექტორიაზე"), ("ec.paint.paint", "Paint", "ხატვა"), ("ec.perspective.3dglasses", "3D Glasses", "3D სათვალე"), ("ec.perspective.bevelalpha", "Bevel Alpha", "ალფას ფასკა"), ("ec.perspective.beveledges", "Bevel Edges", "კიდეების ფასკა"), ("ec.perspective.cameratracker", "3D Camera Tracker", "3D კამერის ტრეკერი"), - ("ec.perspective.cccylinder", "CC Cylinder", "CC Cylinder"), - ("ec.perspective.ccenvironment", "CC Environment", "CC Environment"), - ("ec.perspective.ccsphere", "CC Sphere", "CC Sphere"), - ("ec.perspective.ccspotlight", "CC Spotlight", "CC Spotlight"), + ("ec.perspective.cccylinder", "Cylinder Wrap", "ცილინდრზე შემოხვევა"), + ("ec.perspective.ccenvironment", "Environment Map", "გარემოს რუკა"), + ("ec.perspective.ccsphere", "Sphere Wrap", "სფეროზე შემოხვევა"), + ("ec.perspective.ccspotlight", "Surface Spotlight", "ზედაპირის პროჟექტორი"), ("ec.perspective.dropshadow", "Drop Shadow", "ჩრდილი"), ("ec.perspective.radialshadow", "Radial Shadow", "რადიალური ჩრდილი"), ("ec.sim.carddance", "Card Dance", "მოცეკვავე ბარათები"), ("ec.sim.caustics", "Caustics", "კაუსტიკა"), - ("ec.sim.ccballaction", "CC Ball Action", "CC Ball Action"), - ("ec.sim.ccbubbles", "CC Bubbles", "CC Bubbles"), - ("ec.sim.ccdrizzle", "CC Drizzle", "CC Drizzle"), - ("ec.sim.cchair", "CC Hair", "CC Hair"), - ("ec.sim.ccmrmercury", "CC Mr. Mercury", "CC Mr. Mercury"), - ("ec.sim.ccparticlesystems2", "CC Particle Systems II", "CC Particle Systems II"), - ("ec.sim.ccparticleworld", "CC Particle World", "CC Particle World"), - ("ec.sim.ccpixelpolly", "CC Pixel Polly", "CC Pixel Polly"), - ("ec.sim.ccrainfall", "CC Rainfall", "CC Rainfall"), - ("ec.sim.ccscatterize", "CC Scatterize", "CC Scatterize"), - ("ec.sim.ccsnowfall", "CC Snowfall", "CC Snowfall"), - ("ec.sim.ccstarburst", "CC Star Burst", "CC Star Burst"), + ("ec.sim.ccballaction", "Ball Grid", "ბურთულების ბადე"), + ("ec.sim.ccbubbles", "Bubbles", "ბუშტები"), + ("ec.sim.ccdrizzle", "Water Ripples", "წყლის ტალღები"), + ("ec.sim.cchair", "Surface Fibers", "ზედაპირის ბოჭკოები"), + ("ec.sim.ccmrmercury", "Liquid Particles", "თხევადი ნაწილაკები"), + ("ec.sim.ccparticlesystems2", "Particle Emitter 2D", "ნაწილაკების 2D წყარო"), + ("ec.sim.ccparticleworld", "Particle Emitter 3D", "ნაწილაკების 3D წყარო"), + ("ec.sim.ccpixelpolly", "Pixel Shatter", "პიქსელების დაშლა"), + ("ec.sim.ccrainfall", "Rainfall", "წვიმა"), + ("ec.sim.ccscatterize", "Pixel Scatter", "პიქსელების გაფანტვა"), + ("ec.sim.ccsnowfall", "Snowfall", "თოვა"), + ("ec.sim.ccstarburst", "Starfield", "ვარსკვლავების ველი"), ("ec.sim.foam", "Foam", "ქაფი"), ("ec.sim.particleplayground", "Particle Playground", "ნაწილაკების სიმულაცია"), ("ec.sim.shatter", "Shatter", "დამსხვრევა"), ("ec.sim.waveworld", "Wave World", "ტალღების სამყარო"), ("ec.stylize.brushstrokes", "Brush Strokes", "ფუნჯის შტრიხები"), ("ec.stylize.cartoon", "Cartoon", "მულტფილმის სტილი"), - ("ec.stylize.ccblockload", "CC Block Load", "CC Block Load"), - ("ec.stylize.ccburnfilm", "CC Burn Film", "CC Burn Film"), - ("ec.stylize.ccglass", "CC Glass", "CC Glass"), - ("ec.stylize.cchextile", "CC HexTile", "CC HexTile"), - ("ec.stylize.cckaleida", "CC Kaleida", "CC Kaleida"), - ("ec.stylize.ccmrsmoothie", "CC Mr. Smoothie", "CC Mr. Smoothie"), - ("ec.stylize.ccplastic", "CC Plastic", "CC Plastic"), - ("ec.stylize.ccrepetile", "CC RepeTile", "CC RepeTile"), - ("ec.stylize.ccthreshold", "CC Threshold", "CC Threshold"), - ("ec.stylize.ccthresholdrgb", "CC Threshold RGB", "CC Threshold RGB"), - ("ec.stylize.ccvignette", "CC Vignette", "CC Vignette"), + ("ec.stylize.ccblockload", "Block Reveal", "ბლოკებით გამოჩენა"), + ("ec.stylize.ccburnfilm", "Film Burn", "ფირის დაწვა"), + ("ec.stylize.ccglass", "Glass Relief", "მინის რელიეფი"), + ("ec.stylize.cchextile", "Hexagonal Tiles", "ექვსკუთხა ფილები"), + ("ec.stylize.cckaleida", "Kaleidoscope", "კალეიდოსკოპი"), + ("ec.stylize.ccmrsmoothie", "Palette Map", "პალიტრის რუკა"), + ("ec.stylize.ccplastic", "Plastic Shading", "პლასტმასის დაჩრდილვა"), + ("ec.stylize.ccrepetile", "Edge Tile Repeat", "კიდეების განმეორება"), + ("ec.stylize.ccthreshold", "Channel Threshold", "არხის ზღვარი"), + ("ec.stylize.ccthresholdrgb", "RGB Threshold", "RGB ზღვარი"), + ("ec.stylize.ccvignette", "Vignette", "ვინიეტირება"), ("ec.stylize.coloremboss", "Color Emboss", "ფერადი რელიეფი"), ("ec.stylize.emboss", "Emboss", "რელიეფი"), ("ec.stylize.findedges", "Find Edges", "კიდეების პოვნა"), @@ -1442,8 +1449,8 @@ const GEORGIAN: &[Row] = &[ ("ec.stylize.threshold", "Threshold", "ზღვარი"), ("ec.text.numbers", "Numbers", "რიცხვები"), ("ec.text.timecode", "Timecode", "თაიმკოდი"), - ("ec.time.ccforcemotionblur", "CC Force Motion Blur", "CC Force Motion Blur"), - ("ec.time.ccwidetime", "CC Wide Time", "CC Wide Time"), + ("ec.time.ccforcemotionblur", "Temporal Motion Blur", "დროითი მოძრაობის დაბინდვა"), + ("ec.time.ccwidetime", "Temporal Blend", "დროითი შერევა"), ("ec.time.echo", "Echo", "ექო"), ("ec.time.pixelmotionblur", "Pixel Motion Blur", "პიქსელების მოძრაობის გაბუნდოვნება"), ("ec.time.posterizetime", "Posterize Time", "დროის პოსტერიზაცია"), @@ -1452,23 +1459,23 @@ const GEORGIAN: &[Row] = &[ ("ec.time.timewarp", "Timewarp", "Timewarp"), ("ec.transition.blockdissolve", "Block Dissolve", "ბლოკური გადადნობა"), ("ec.transition.cardwipe", "Card Wipe", "ბარათებით წმენდა"), - ("ec.transition.ccglasswipe", "CC Glass Wipe", "CC Glass Wipe"), - ("ec.transition.ccgridwipe", "CC Grid Wipe", "CC Grid Wipe"), - ("ec.transition.ccimagewipe", "CC Image Wipe", "CC Image Wipe"), - ("ec.transition.ccjaws", "CC Jaws", "CC Jaws"), - ("ec.transition.cclightwipe", "CC Light Wipe", "CC Light Wipe"), - ("ec.transition.cclinesweep", "CC Line Sweep", "CC Line Sweep"), - ("ec.transition.ccradialscalewipe", "CC Radial ScaleWipe", "CC Radial ScaleWipe"), - ("ec.transition.ccscalewipe", "CC Scale Wipe", "CC Scale Wipe"), - ("ec.transition.cctwister", "CC Twister", "CC Twister"), - ("ec.transition.ccwarpomatic", "CC WarpoMatic", "CC WarpoMatic"), + ("ec.transition.ccglasswipe", "Glass Wipe", "მინის გადასვლა"), + ("ec.transition.ccgridwipe", "Grid Wipe", "ბადის გადასვლა"), + ("ec.transition.ccimagewipe", "Luminance Image Wipe", "სიკაშკაშის გამოსახულებით გადასვლა"), + ("ec.transition.ccjaws", "Serrated Wipe", "დაკბილული გადასვლა"), + ("ec.transition.cclightwipe", "Light Wipe", "სინათლის გადასვლა"), + ("ec.transition.cclinesweep", "Line Sweep", "ხაზების გავლა"), + ("ec.transition.ccradialscalewipe", "Radial Scale Wipe", "რადიალური მასშტაბის გადასვლა"), + ("ec.transition.ccscalewipe", "Scale Wipe", "მასშტაბის გადასვლა"), + ("ec.transition.cctwister", "Twist Wipe", "მოგრეხილი გადასვლა"), + ("ec.transition.ccwarpomatic", "Warp Dissolve", "დეფორმაციით გადასვლა"), ("ec.transition.gradientwipe", "Gradient Wipe", "გრადიენტული წმენდა"), ("ec.transition.iriswipe", "Iris Wipe", "დიაფრაგმული წმენდა"), ("ec.transition.linearwipe", "Linear Wipe", "წრფივი წმენდა"), ("ec.transition.radialwipe", "Radial Wipe", "რადიალური წმენდა"), ("ec.transition.venetian", "Venetian Blinds", "ჟალუზი"), ("ec.utility.applylut", "Apply Color LUT", "ფერის LUT-ის გამოყენება"), - ("ec.utility.ccoverbrights", "CC Overbrights", "CC Overbrights"), + ("ec.utility.ccoverbrights", "Out-of-Range Display", "დიაპაზონის გარეთ ჩვენება"), ("ec.utility.cineon", "Cineon Converter", "Cineon-ის გარდამქმნელი"), ("ec.utility.colorprofileconverter", "Color Profile Converter", "ფერის პროფილის გარდამქმნელი"), ("ec.utility.facemeasurements", "Face Measurements", "სახის გაზომვები"), @@ -1517,8 +1524,8 @@ const GEORGIAN_CATEGORIES: &[(&str, &str)] = &[ /// French (`fr`): one row per effect, ids from [`SIMPLIFIED_CHINESE`]. Written from the meaning of the /// English names, with the terms the French menus use (calque, estampe for a matte, incrustation for -/// keying). The `CC` series and the brand names stay in English, `VR`, `OCIO`, `PS` and `HDR` keep -/// their tag after the translated name. +/// keying). The brand names stay in English, `VR`, `OCIO`, `PS` and `HDR` keep their tag after the +/// translated name. const FRENCH: &[Row] = &[ ("ec.3d.channelextract", "3D Channel Extract", "Extraction de canal 3D"), ("ec.3d.cryptomatte", "Cryptomatte", "Cryptomatte"), @@ -1544,10 +1551,10 @@ const FRENCH: &[Row] = &[ ("ec.blur.bilateral", "Bilateral Blur", "Flou bilatéral"), ("ec.blur.cameralens", "Camera Lens Blur", "Flou de l’objectif de la caméra"), ("ec.blur.camerashakedeblur", "Camera-Shake Deblur", "Correction du flou de bougé de caméra"), - ("ec.blur.cccross", "CC Cross Blur", "CC Cross Blur"), - ("ec.blur.ccradial", "CC Radial Blur", "CC Radial Blur"), - ("ec.blur.ccradialfast", "CC Radial Fast Blur", "CC Radial Fast Blur"), - ("ec.blur.ccvector", "CC Vector Blur", "CC Vector Blur"), + ("ec.blur.cccross", "Cross Blur", "Flou croisé"), + ("ec.blur.ccradial", "Variable Radial Blur", "Flou radial variable"), + ("ec.blur.ccradialfast", "Fast Radial Blur", "Flou radial rapide"), + ("ec.blur.ccvector", "Vector Blur", "Flou vectoriel"), ("ec.blur.channel", "Channel Blur", "Flou de canal"), ("ec.blur.compound", "Compound Blur", "Flou composé"), ("ec.blur.directional", "Directional Blur", "Flou directionnel"), @@ -1561,7 +1568,7 @@ const FRENCH: &[Row] = &[ ("ec.channel.arithmetic", "Arithmetic", "Arithmétique"), ("ec.channel.blend", "Blend", "Fusion"), ("ec.channel.calculations", "Calculations", "Calculs"), - ("ec.channel.cccomposite", "CC Composite", "CC Composite"), + ("ec.channel.cccomposite", "Source Composite", "Composition de la source"), ("ec.channel.combiner", "Channel Combiner", "Combinateur de canaux"), ("ec.channel.compoundarithmetic", "Compound Arithmetic", "Arithmétique composée"), ("ec.channel.invert", "Invert", "Inversion"), @@ -1577,10 +1584,10 @@ const FRENCH: &[Row] = &[ ("ec.color.blackwhite", "Black & White", "Noir et blanc"), ("ec.color.brightnesscontrast", "Brightness & Contrast", "Luminosité et contraste"), ("ec.color.broadcast", "Broadcast Colors", "Couleurs de diffusion"), - ("ec.color.cccolorneutralizer", "CC Color Neutralizer", "CC Color Neutralizer"), - ("ec.color.cccoloroffset", "CC Color Offset", "CC Color Offset"), - ("ec.color.cckernel", "CC Kernel", "CC Kernel"), - ("ec.color.cctoner", "CC Toner", "CC Toner"), + ("ec.color.cccolorneutralizer", "Color Neutralizer", "Neutralisation des couleurs"), + ("ec.color.cccoloroffset", "Channel Offset", "Décalage des canaux"), + ("ec.color.cckernel", "Convolution Kernel", "Noyau de convolution"), + ("ec.color.cctoner", "Multi-Tone Tint", "Teinte multiton"), ("ec.color.changecolor", "Change Color", "Changer la couleur"), ("ec.color.changetocolor", "Change to Color", "Changer en couleur"), ("ec.color.channelmixer", "Channel Mixer", "Mélangeur de canaux"), @@ -1597,7 +1604,7 @@ const FRENCH: &[Row] = &[ ("ec.color.leavecolor", "Leave Color", "Conserver la couleur"), ("ec.color.levels", "Levels", "Niveaux"), ("ec.color.levelsic", "Levels (Individual Controls)", "Niveaux (contrôles individuels)"), - ("ec.color.lumetri", "Lumetri Color", "Lumetri Color"), + ("ec.color.lumetri", "Color Grading", "Étalonnage des couleurs"), ("ec.color.ociocdl", "OCIO CDL Transform", "Transformation CDL OCIO"), ("ec.color.ociocolorspace", "OCIO Color Space Transform", "Transformation d’espace colorimétrique OCIO"), ("ec.color.ociodisplay", "OCIO Display Transform", "Transformation d’affichage OCIO"), @@ -1622,20 +1629,20 @@ const FRENCH: &[Row] = &[ ("ec.control.stereo3d", "Stereo 3D Controls", "Contrôles stéréo 3D"), ("ec.distort.bezierwarp", "Bezier Warp", "Déformation Bézier"), ("ec.distort.bulge", "Bulge", "Renflement"), - ("ec.distort.ccbender", "CC Bender", "CC Bender"), - ("ec.distort.ccbendit", "CC Bend It", "CC Bend It"), - ("ec.distort.ccblobbylize", "CC Blobbylize", "CC Blobbylize"), - ("ec.distort.ccflomotion", "CC Flo Motion", "CC Flo Motion"), - ("ec.distort.ccgriddler", "CC Griddler", "CC Griddler"), - ("ec.distort.cclens", "CC Lens", "CC Lens"), - ("ec.distort.ccpageturn", "CC Page Turn", "CC Page Turn"), - ("ec.distort.ccpowerpin", "CC Power Pin", "CC Power Pin"), - ("ec.distort.ccripplepulse", "CC Ripple Pulse", "CC Ripple Pulse"), - ("ec.distort.ccslant", "CC Slant", "CC Slant"), - ("ec.distort.ccsmear", "CC Smear", "CC Smear"), - ("ec.distort.ccsplit", "CC Split", "CC Split"), - ("ec.distort.ccsplit2", "CC Split 2", "CC Split 2"), - ("ec.distort.cctiler", "CC Tiler", "CC Tiler"), + ("ec.distort.ccbender", "Flexible Bend", "Courbure souple"), + ("ec.distort.ccbendit", "Two-Point Bend", "Courbure à deux points"), + ("ec.distort.ccblobbylize", "Organic Displacement", "Déplacement organique"), + ("ec.distort.ccflomotion", "Dual Lens Warp", "Déformation à deux lentilles"), + ("ec.distort.ccgriddler", "Tile Grid", "Grille de tuiles"), + ("ec.distort.cclens", "Lens Distortion", "Distorsion de lentille"), + ("ec.distort.ccpageturn", "Page Curl", "Page enroulée"), + ("ec.distort.ccpowerpin", "Perspective Pin", "Épinglage en perspective"), + ("ec.distort.ccripplepulse", "Pulsed Ripple", "Ondulation pulsée"), + ("ec.distort.ccslant", "Slant", "Inclinaison"), + ("ec.distort.ccsmear", "Directional Smear", "Étalement directionnel"), + ("ec.distort.ccsplit", "Split Warp", "Déformation divisée"), + ("ec.distort.ccsplit2", "Dual Split Warp", "Déformation à double division"), + ("ec.distort.cctiler", "Scaled Tiles", "Tuiles mises à l’échelle"), ("ec.distort.cornerpin", "Corner Pin", "Épinglage d’angles"), ("ec.distort.displacementmap", "Displacement Map", "Carte de déplacement"), ("ec.distort.liquify", "Liquify", "Liquéfier"), @@ -1663,11 +1670,11 @@ const FRENCH: &[Row] = &[ ("ec.generate.audiospectrum", "Audio Spectrum", "Spectre audio"), ("ec.generate.audiowaveform", "Audio Waveform", "Forme d’onde audio"), ("ec.generate.beam", "Beam", "Faisceau"), - ("ec.generate.ccgluegun", "CC Glue Gun", "CC Glue Gun"), - ("ec.generate.cclightburst", "CC Light Burst 2.5", "CC Light Burst 2.5"), - ("ec.generate.cclightrays", "CC Light Rays", "CC Light Rays"), - ("ec.generate.cclightsweep", "CC Light Sweep", "CC Light Sweep"), - ("ec.generate.ccthreads", "CC Threads", "CC Threads"), + ("ec.generate.ccgluegun", "Paint Beads", "Perles de peinture"), + ("ec.generate.cclightburst", "Radial Light Burst", "Éclat lumineux radial"), + ("ec.generate.cclightrays", "Light Rays", "Rayons lumineux"), + ("ec.generate.cclightsweep", "Light Sweep", "Balayage lumineux"), + ("ec.generate.ccthreads", "Woven Threads", "Fils tissés"), ("ec.generate.cellpattern", "Cell Pattern", "Motif cellulaire"), ("ec.generate.checkerboard", "Checkerboard", "Damier"), ("ec.generate.circle", "Circle", "Cercle"), @@ -1686,7 +1693,7 @@ const FRENCH: &[Row] = &[ ("ec.generate.vegas", "Vegas", "Vegas"), ("ec.generate.writeon", "Write-on", "Écriture progressive"), ("ec.key.advancedspill", "Advanced Spill Suppressor", "Suppresseur de débordement avancé"), - ("ec.key.ccsimplewireremoval", "CC Simple Wire Removal", "CC Simple Wire Removal"), + ("ec.key.ccsimplewireremoval", "Line Removal", "Suppression de ligne"), ("ec.key.colordifference", "Color Difference Key", "Incrustation par différence de couleur"), ("ec.key.colorkey", "Color Key", "Incrustation couleur"), ("ec.key.colorrange", "Color Range", "Plage de couleurs"), @@ -1699,7 +1706,7 @@ const FRENCH: &[Row] = &[ ("ec.key.screen", "Screen Key", "Incrustation d’écran"), ("ec.key.spill", "Spill Suppressor", "Suppresseur de débordement"), ("ec.key.unmult", "Unmult", "Unmult"), - ("ec.keying.keylight", "Key Light", "Key Light"), + ("ec.keying.keylight", "Screen Color Key", "Incrustation par couleur d’écran"), ("ec.matte.mattechoker", "Matte Choker", "Réducteur d’estampe"), ("ec.matte.objectmatte", "Object Matte", "Estampe d’objet"), ("ec.matte.refinehard", "Refine Hard Matte", "Affiner l’estampe nette"), @@ -1723,50 +1730,50 @@ const FRENCH: &[Row] = &[ ("ec.obsolete.basictext", "Basic Text", "Texte de base"), ("ec.obsolete.gaussianlegacy", "Gaussian Blur (Legacy)", "Flou gaussien (hérité)"), ("ec.obsolete.lightning", "Lightning", "Foudre"), - ("ec.obsolete.mochashape", "Mocha shape", "Forme Mocha"), + ("ec.obsolete.mochashape", "Tracked Shape Matte", "Cache de forme suivie"), ("ec.obsolete.pathtext", "Path Text", "Texte sur tracé"), ("ec.paint.paint", "Paint", "Peinture"), ("ec.perspective.3dglasses", "3D Glasses", "Lunettes 3D"), ("ec.perspective.bevelalpha", "Bevel Alpha", "Biseau alpha"), ("ec.perspective.beveledges", "Bevel Edges", "Biseau des bords"), ("ec.perspective.cameratracker", "3D Camera Tracker", "Suivi de caméra 3D"), - ("ec.perspective.cccylinder", "CC Cylinder", "CC Cylinder"), - ("ec.perspective.ccenvironment", "CC Environment", "CC Environment"), - ("ec.perspective.ccsphere", "CC Sphere", "CC Sphere"), - ("ec.perspective.ccspotlight", "CC Spotlight", "CC Spotlight"), + ("ec.perspective.cccylinder", "Cylinder Wrap", "Enroulement cylindrique"), + ("ec.perspective.ccenvironment", "Environment Map", "Carte d’environnement"), + ("ec.perspective.ccsphere", "Sphere Wrap", "Enroulement sphérique"), + ("ec.perspective.ccspotlight", "Surface Spotlight", "Projecteur de surface"), ("ec.perspective.dropshadow", "Drop Shadow", "Ombre portée"), ("ec.perspective.radialshadow", "Radial Shadow", "Ombre radiale"), ("ec.sim.carddance", "Card Dance", "Danse de cartes"), ("ec.sim.caustics", "Caustics", "Caustiques"), - ("ec.sim.ccballaction", "CC Ball Action", "CC Ball Action"), - ("ec.sim.ccbubbles", "CC Bubbles", "CC Bubbles"), - ("ec.sim.ccdrizzle", "CC Drizzle", "CC Drizzle"), - ("ec.sim.cchair", "CC Hair", "CC Hair"), - ("ec.sim.ccmrmercury", "CC Mr. Mercury", "CC Mr. Mercury"), - ("ec.sim.ccparticlesystems2", "CC Particle Systems II", "CC Particle Systems II"), - ("ec.sim.ccparticleworld", "CC Particle World", "CC Particle World"), - ("ec.sim.ccpixelpolly", "CC Pixel Polly", "CC Pixel Polly"), - ("ec.sim.ccrainfall", "CC Rainfall", "CC Rainfall"), - ("ec.sim.ccscatterize", "CC Scatterize", "CC Scatterize"), - ("ec.sim.ccsnowfall", "CC Snowfall", "CC Snowfall"), - ("ec.sim.ccstarburst", "CC Star Burst", "CC Star Burst"), + ("ec.sim.ccballaction", "Ball Grid", "Grille de sphères"), + ("ec.sim.ccbubbles", "Bubbles", "Bulles"), + ("ec.sim.ccdrizzle", "Water Ripples", "Ondulations de l’eau"), + ("ec.sim.cchair", "Surface Fibers", "Fibres de surface"), + ("ec.sim.ccmrmercury", "Liquid Particles", "Particules liquides"), + ("ec.sim.ccparticlesystems2", "Particle Emitter 2D", "Émetteur de particules 2D"), + ("ec.sim.ccparticleworld", "Particle Emitter 3D", "Émetteur de particules 3D"), + ("ec.sim.ccpixelpolly", "Pixel Shatter", "Éclatement des pixels"), + ("ec.sim.ccrainfall", "Rainfall", "Pluie"), + ("ec.sim.ccscatterize", "Pixel Scatter", "Dispersion des pixels"), + ("ec.sim.ccsnowfall", "Snowfall", "Neige"), + ("ec.sim.ccstarburst", "Starfield", "Champ d’étoiles"), ("ec.sim.foam", "Foam", "Mousse"), ("ec.sim.particleplayground", "Particle Playground", "Terrain de jeu de particules"), ("ec.sim.shatter", "Shatter", "Éclatement"), ("ec.sim.waveworld", "Wave World", "Monde des vagues"), ("ec.stylize.brushstrokes", "Brush Strokes", "Coups de pinceau"), ("ec.stylize.cartoon", "Cartoon", "Dessin animé"), - ("ec.stylize.ccblockload", "CC Block Load", "CC Block Load"), - ("ec.stylize.ccburnfilm", "CC Burn Film", "CC Burn Film"), - ("ec.stylize.ccglass", "CC Glass", "CC Glass"), - ("ec.stylize.cchextile", "CC HexTile", "CC HexTile"), - ("ec.stylize.cckaleida", "CC Kaleida", "CC Kaleida"), - ("ec.stylize.ccmrsmoothie", "CC Mr. Smoothie", "CC Mr. Smoothie"), - ("ec.stylize.ccplastic", "CC Plastic", "CC Plastic"), - ("ec.stylize.ccrepetile", "CC RepeTile", "CC RepeTile"), - ("ec.stylize.ccthreshold", "CC Threshold", "CC Threshold"), - ("ec.stylize.ccthresholdrgb", "CC Threshold RGB", "CC Threshold RGB"), - ("ec.stylize.ccvignette", "CC Vignette", "CC Vignette"), + ("ec.stylize.ccblockload", "Block Reveal", "Révélation par blocs"), + ("ec.stylize.ccburnfilm", "Film Burn", "Brûlure de pellicule"), + ("ec.stylize.ccglass", "Glass Relief", "Relief de verre"), + ("ec.stylize.cchextile", "Hexagonal Tiles", "Tuiles hexagonales"), + ("ec.stylize.cckaleida", "Kaleidoscope", "Kaléidoscope"), + ("ec.stylize.ccmrsmoothie", "Palette Map", "Palettmappning"), + ("ec.stylize.ccplastic", "Plastic Shading", "Ombrage plastique"), + ("ec.stylize.ccrepetile", "Edge Tile Repeat", "Répétition des tuiles aux bords"), + ("ec.stylize.ccthreshold", "Channel Threshold", "Seuil de canal"), + ("ec.stylize.ccthresholdrgb", "RGB Threshold", "Seuil RVB"), + ("ec.stylize.ccvignette", "Vignette", "Vignettage"), ("ec.stylize.coloremboss", "Color Emboss", "Estampage couleur"), ("ec.stylize.emboss", "Emboss", "Estampage"), ("ec.stylize.findedges", "Find Edges", "Détection des contours"), @@ -1781,8 +1788,8 @@ const FRENCH: &[Row] = &[ ("ec.stylize.threshold", "Threshold", "Seuil"), ("ec.text.numbers", "Numbers", "Nombres"), ("ec.text.timecode", "Timecode", "Timecode"), - ("ec.time.ccforcemotionblur", "CC Force Motion Blur", "CC Force Motion Blur"), - ("ec.time.ccwidetime", "CC Wide Time", "CC Wide Time"), + ("ec.time.ccforcemotionblur", "Temporal Motion Blur", "Flou de mouvement temporel"), + ("ec.time.ccwidetime", "Temporal Blend", "Fusion temporelle"), ("ec.time.echo", "Echo", "Écho"), ("ec.time.pixelmotionblur", "Pixel Motion Blur", "Flou de mouvement des pixels"), ("ec.time.posterizetime", "Posterize Time", "Postérisation temporelle"), @@ -1791,23 +1798,23 @@ const FRENCH: &[Row] = &[ ("ec.time.timewarp", "Timewarp", "Déformation temporelle"), ("ec.transition.blockdissolve", "Block Dissolve", "Fondu par blocs"), ("ec.transition.cardwipe", "Card Wipe", "Volet de cartes"), - ("ec.transition.ccglasswipe", "CC Glass Wipe", "CC Glass Wipe"), - ("ec.transition.ccgridwipe", "CC Grid Wipe", "CC Grid Wipe"), - ("ec.transition.ccimagewipe", "CC Image Wipe", "CC Image Wipe"), - ("ec.transition.ccjaws", "CC Jaws", "CC Jaws"), - ("ec.transition.cclightwipe", "CC Light Wipe", "CC Light Wipe"), - ("ec.transition.cclinesweep", "CC Line Sweep", "CC Line Sweep"), - ("ec.transition.ccradialscalewipe", "CC Radial ScaleWipe", "CC Radial ScaleWipe"), - ("ec.transition.ccscalewipe", "CC Scale Wipe", "CC Scale Wipe"), - ("ec.transition.cctwister", "CC Twister", "CC Twister"), - ("ec.transition.ccwarpomatic", "CC WarpoMatic", "CC WarpoMatic"), + ("ec.transition.ccglasswipe", "Glass Wipe", "Volet de verre"), + ("ec.transition.ccgridwipe", "Grid Wipe", "Volet en grille"), + ("ec.transition.ccimagewipe", "Luminance Image Wipe", "Volet par luminance d’image"), + ("ec.transition.ccjaws", "Serrated Wipe", "Volet dentelé"), + ("ec.transition.cclightwipe", "Light Wipe", "Volet lumineux"), + ("ec.transition.cclinesweep", "Line Sweep", "Balayage de lignes"), + ("ec.transition.ccradialscalewipe", "Radial Scale Wipe", "Volet d’échelle radial"), + ("ec.transition.ccscalewipe", "Scale Wipe", "Volet d’échelle"), + ("ec.transition.cctwister", "Twist Wipe", "Volet torsadé"), + ("ec.transition.ccwarpomatic", "Warp Dissolve", "Fondu déformant"), ("ec.transition.gradientwipe", "Gradient Wipe", "Volet en dégradé"), ("ec.transition.iriswipe", "Iris Wipe", "Volet en iris"), ("ec.transition.linearwipe", "Linear Wipe", "Volet linéaire"), ("ec.transition.radialwipe", "Radial Wipe", "Volet radial"), ("ec.transition.venetian", "Venetian Blinds", "Stores vénitiens"), ("ec.utility.applylut", "Apply Color LUT", "Appliquer une LUT de couleur"), - ("ec.utility.ccoverbrights", "CC Overbrights", "CC Overbrights"), + ("ec.utility.ccoverbrights", "Out-of-Range Display", "Affichage hors plage"), ("ec.utility.cineon", "Cineon Converter", "Convertisseur Cineon"), ("ec.utility.colorprofileconverter", "Color Profile Converter", "Convertisseur de profil colorimétrique"), ("ec.utility.facemeasurements", "Face Measurements", "Mesures du visage"), @@ -1909,10 +1916,10 @@ const SWEDISH: &[Row] = &[ ("ec.blur.bilateral", "Bilateral Blur", "Bilateral oskärpa"), ("ec.blur.cameralens", "Camera Lens Blur", "Kameralinsoskärpa"), ("ec.blur.camerashakedeblur", "Camera-Shake Deblur", "Ta bort oskärpa från kameraskakning"), - ("ec.blur.cccross", "CC Cross Blur", "CC Korsoskärpa"), - ("ec.blur.ccradial", "CC Radial Blur", "CC Radiell oskärpa"), - ("ec.blur.ccradialfast", "CC Radial Fast Blur", "CC Snabb radiell oskärpa"), - ("ec.blur.ccvector", "CC Vector Blur", "CC Vektoroskärpa"), + ("ec.blur.cccross", "Cross Blur", "Korsoskärpa"), + ("ec.blur.ccradial", "Variable Radial Blur", "Variabel radiell oskärpa"), + ("ec.blur.ccradialfast", "Fast Radial Blur", "Snabb radiell oskärpa"), + ("ec.blur.ccvector", "Vector Blur", "Vektoroskärpa"), ("ec.blur.channel", "Channel Blur", "Kanaloskärpa"), ("ec.blur.compound", "Compound Blur", "Sammansatt oskärpa"), ("ec.blur.directional", "Directional Blur", "Riktad oskärpa"), @@ -1926,7 +1933,7 @@ const SWEDISH: &[Row] = &[ ("ec.channel.arithmetic", "Arithmetic", "Aritmetik"), ("ec.channel.blend", "Blend", "Blanda"), ("ec.channel.calculations", "Calculations", "Beräkningar"), - ("ec.channel.cccomposite", "CC Composite", "CC Komposit"), + ("ec.channel.cccomposite", "Source Composite", "Källkomposition"), ("ec.channel.combiner", "Channel Combiner", "Kanalkombinerare"), ("ec.channel.compoundarithmetic", "Compound Arithmetic", "Sammansatt aritmetik"), ("ec.channel.invert", "Invert", "Invertera"), @@ -1942,10 +1949,10 @@ const SWEDISH: &[Row] = &[ ("ec.color.blackwhite", "Black & White", "Svartvitt"), ("ec.color.brightnesscontrast", "Brightness & Contrast", "Ljusstyrka och kontrast"), ("ec.color.broadcast", "Broadcast Colors", "Broadcast-färger"), - ("ec.color.cccolorneutralizer", "CC Color Neutralizer", "CC Färgneutraliserare"), - ("ec.color.cccoloroffset", "CC Color Offset", "CC Färgförskjutning"), - ("ec.color.cckernel", "CC Kernel", "CC Kärna"), - ("ec.color.cctoner", "CC Toner", "CC Toner"), + ("ec.color.cccolorneutralizer", "Color Neutralizer", "Färgneutralisering"), + ("ec.color.cccoloroffset", "Channel Offset", "Kanalförskjutning"), + ("ec.color.cckernel", "Convolution Kernel", "Faltningskärna"), + ("ec.color.cctoner", "Multi-Tone Tint", "Flertonsfärgning"), ("ec.color.changecolor", "Change Color", "Ändra färg"), ("ec.color.changetocolor", "Change to Color", "Ändra till färg"), ("ec.color.channelmixer", "Channel Mixer", "Kanalmixer"), @@ -1962,7 +1969,7 @@ const SWEDISH: &[Row] = &[ ("ec.color.leavecolor", "Leave Color", "Behåll färg"), ("ec.color.levels", "Levels", "Nivåer"), ("ec.color.levelsic", "Levels (Individual Controls)", "Nivåer (individuella kontroller)"), - ("ec.color.lumetri", "Lumetri Color", "Lumetri-färg"), + ("ec.color.lumetri", "Color Grading", "Färggradering"), ("ec.color.ociocdl", "OCIO CDL Transform", "OCIO CDL-transformering"), ("ec.color.ociocolorspace", "OCIO Color Space Transform", "OCIO färgrymdstransformering"), ("ec.color.ociodisplay", "OCIO Display Transform", "OCIO visningstransformering"), @@ -1987,20 +1994,20 @@ const SWEDISH: &[Row] = &[ ("ec.control.stereo3d", "Stereo 3D Controls", "Stereo 3D-kontroller"), ("ec.distort.bezierwarp", "Bezier Warp", "Bezierförvrängning"), ("ec.distort.bulge", "Bulge", "Utbuktning"), - ("ec.distort.ccbender", "CC Bender", "CC Bender"), - ("ec.distort.ccbendit", "CC Bend It", "CC Bend It"), - ("ec.distort.ccblobbylize", "CC Blobbylize", "CC Blobbylize"), - ("ec.distort.ccflomotion", "CC Flo Motion", "CC Flo Motion"), - ("ec.distort.ccgriddler", "CC Griddler", "CC Griddler"), - ("ec.distort.cclens", "CC Lens", "CC Objektiv"), - ("ec.distort.ccpageturn", "CC Page Turn", "CC Sidvändning"), - ("ec.distort.ccpowerpin", "CC Power Pin", "CC Power Pin"), - ("ec.distort.ccripplepulse", "CC Ripple Pulse", "CC Krusningspuls"), - ("ec.distort.ccslant", "CC Slant", "CC Lutning"), - ("ec.distort.ccsmear", "CC Smear", "CC Utsmetning"), - ("ec.distort.ccsplit", "CC Split", "CC Dela"), - ("ec.distort.ccsplit2", "CC Split 2", "CC Dela 2"), - ("ec.distort.cctiler", "CC Tiler", "CC Tiler"), + ("ec.distort.ccbender", "Flexible Bend", "Flexibel böjning"), + ("ec.distort.ccbendit", "Two-Point Bend", "Tvåpunktsböjning"), + ("ec.distort.ccblobbylize", "Organic Displacement", "Organisk förskjutning"), + ("ec.distort.ccflomotion", "Dual Lens Warp", "Dubbel linsförvrängning"), + ("ec.distort.ccgriddler", "Tile Grid", "Plattnät"), + ("ec.distort.cclens", "Lens Distortion", "Linsförvrängning"), + ("ec.distort.ccpageturn", "Page Curl", "Sidkrullning"), + ("ec.distort.ccpowerpin", "Perspective Pin", "Perspektivnålar"), + ("ec.distort.ccripplepulse", "Pulsed Ripple", "Pulserande krusning"), + ("ec.distort.ccslant", "Slant", "Lutning"), + ("ec.distort.ccsmear", "Directional Smear", "Riktningssmetning"), + ("ec.distort.ccsplit", "Split Warp", "Delad förvrängning"), + ("ec.distort.ccsplit2", "Dual Split Warp", "Dubbeldelad förvrängning"), + ("ec.distort.cctiler", "Scaled Tiles", "Skalade plattor"), ("ec.distort.cornerpin", "Corner Pin", "Hörnförankring"), ("ec.distort.displacementmap", "Displacement Map", "Förskjutningskarta"), ("ec.distort.liquify", "Liquify", "Gör flytande"), @@ -2028,11 +2035,11 @@ const SWEDISH: &[Row] = &[ ("ec.generate.audiospectrum", "Audio Spectrum", "Ljudspektrum"), ("ec.generate.audiowaveform", "Audio Waveform", "Ljudvågform"), ("ec.generate.beam", "Beam", "Stråle"), - ("ec.generate.ccgluegun", "CC Glue Gun", "CC Glue Gun"), - ("ec.generate.cclightburst", "CC Light Burst 2.5", "CC Ljusutbrott 2.5"), - ("ec.generate.cclightrays", "CC Light Rays", "CC Ljusstrålar"), - ("ec.generate.cclightsweep", "CC Light Sweep", "CC Ljussvep"), - ("ec.generate.ccthreads", "CC Threads", "CC Trådar"), + ("ec.generate.ccgluegun", "Paint Beads", "Färgpärlor"), + ("ec.generate.cclightburst", "Radial Light Burst", "Radiellt ljusutbrott"), + ("ec.generate.cclightrays", "Light Rays", "Ljusstrålar"), + ("ec.generate.cclightsweep", "Light Sweep", "Ljussvep"), + ("ec.generate.ccthreads", "Woven Threads", "Vävda trådar"), ("ec.generate.cellpattern", "Cell Pattern", "Cellmönster"), ("ec.generate.checkerboard", "Checkerboard", "Schackbräde"), ("ec.generate.circle", "Circle", "Cirkel"), @@ -2051,7 +2058,7 @@ const SWEDISH: &[Row] = &[ ("ec.generate.vegas", "Vegas", "Vegas"), ("ec.generate.writeon", "Write-on", "Framskrivning"), ("ec.key.advancedspill", "Advanced Spill Suppressor", "Avancerad spilldämpning"), - ("ec.key.ccsimplewireremoval", "CC Simple Wire Removal", "CC Enkel trådborttagning"), + ("ec.key.ccsimplewireremoval", "Line Removal", "Linjeborttagning"), ("ec.key.colordifference", "Color Difference Key", "Färgdifferensnyckel"), ("ec.key.colorkey", "Color Key", "Färgnyckel"), ("ec.key.colorrange", "Color Range", "Färgomfång"), @@ -2064,7 +2071,7 @@ const SWEDISH: &[Row] = &[ ("ec.key.screen", "Screen Key", "Skärmnyckel"), ("ec.key.spill", "Spill Suppressor", "Spilldämpning"), ("ec.key.unmult", "Unmult", "Unmult"), - ("ec.keying.keylight", "Key Light", "Key Light"), + ("ec.keying.keylight", "Screen Color Key", "Skärmfärgsnyckling"), ("ec.matte.mattechoker", "Matte Choker", "Mattekrympning"), ("ec.matte.objectmatte", "Object Matte", "Objektmatte"), ("ec.matte.refinehard", "Refine Hard Matte", "Förfina hård matte"), @@ -2088,50 +2095,50 @@ const SWEDISH: &[Row] = &[ ("ec.obsolete.basictext", "Basic Text", "Grundläggande text"), ("ec.obsolete.gaussianlegacy", "Gaussian Blur (Legacy)", "Gaussisk oskärpa (äldre)"), ("ec.obsolete.lightning", "Lightning", "Blixt"), - ("ec.obsolete.mochashape", "Mocha shape", "Mocha-form"), + ("ec.obsolete.mochashape", "Tracked Shape Matte", "Spårad formmask"), ("ec.obsolete.pathtext", "Path Text", "Text längs bana"), ("ec.paint.paint", "Paint", "Måla"), ("ec.perspective.3dglasses", "3D Glasses", "3D-glasögon"), ("ec.perspective.bevelalpha", "Bevel Alpha", "Alfafasning"), ("ec.perspective.beveledges", "Bevel Edges", "Fasade kanter"), ("ec.perspective.cameratracker", "3D Camera Tracker", "3D-kameraspårning"), - ("ec.perspective.cccylinder", "CC Cylinder", "CC Cylinder"), - ("ec.perspective.ccenvironment", "CC Environment", "CC Miljö"), - ("ec.perspective.ccsphere", "CC Sphere", "CC Sfär"), - ("ec.perspective.ccspotlight", "CC Spotlight", "CC Strålkastare"), + ("ec.perspective.cccylinder", "Cylinder Wrap", "Cylinderomslag"), + ("ec.perspective.ccenvironment", "Environment Map", "Miljökarta"), + ("ec.perspective.ccsphere", "Sphere Wrap", "Sfäromslag"), + ("ec.perspective.ccspotlight", "Surface Spotlight", "Ytstrålkastare"), ("ec.perspective.dropshadow", "Drop Shadow", "Slagskugga"), ("ec.perspective.radialshadow", "Radial Shadow", "Radiell skugga"), ("ec.sim.carddance", "Card Dance", "Kortdans"), ("ec.sim.caustics", "Caustics", "Kaustik"), - ("ec.sim.ccballaction", "CC Ball Action", "CC Bollåtgärd"), - ("ec.sim.ccbubbles", "CC Bubbles", "CC Bubblor"), - ("ec.sim.ccdrizzle", "CC Drizzle", "CC Duggregn"), - ("ec.sim.cchair", "CC Hair", "CC Hår"), - ("ec.sim.ccmrmercury", "CC Mr. Mercury", "CC Mr. Mercury"), - ("ec.sim.ccparticlesystems2", "CC Particle Systems II", "CC Partikelsystem II"), - ("ec.sim.ccparticleworld", "CC Particle World", "CC Partikelvärld"), - ("ec.sim.ccpixelpolly", "CC Pixel Polly", "CC Pixel Polly"), - ("ec.sim.ccrainfall", "CC Rainfall", "CC Regn"), - ("ec.sim.ccscatterize", "CC Scatterize", "CC Utspridning"), - ("ec.sim.ccsnowfall", "CC Snowfall", "CC Snöfall"), - ("ec.sim.ccstarburst", "CC Star Burst", "CC Stjärnexplosion"), + ("ec.sim.ccballaction", "Ball Grid", "Kulnät"), + ("ec.sim.ccbubbles", "Bubbles", "Bubblor"), + ("ec.sim.ccdrizzle", "Water Ripples", "Vattenkrusningar"), + ("ec.sim.cchair", "Surface Fibers", "Ytfibrer"), + ("ec.sim.ccmrmercury", "Liquid Particles", "Vätskepartiklar"), + ("ec.sim.ccparticlesystems2", "Particle Emitter 2D", "Partikelsändare 2D"), + ("ec.sim.ccparticleworld", "Particle Emitter 3D", "Partikelsändare 3D"), + ("ec.sim.ccpixelpolly", "Pixel Shatter", "Pixelsplittring"), + ("ec.sim.ccrainfall", "Rainfall", "Regn"), + ("ec.sim.ccscatterize", "Pixel Scatter", "Pixelspridning"), + ("ec.sim.ccsnowfall", "Snowfall", "Snöfall"), + ("ec.sim.ccstarburst", "Starfield", "Stjärnfält"), ("ec.sim.foam", "Foam", "Skum"), ("ec.sim.particleplayground", "Particle Playground", "Partikellekplats"), ("ec.sim.shatter", "Shatter", "Krossa"), ("ec.sim.waveworld", "Wave World", "Vågvärld"), ("ec.stylize.brushstrokes", "Brush Strokes", "Penseldrag"), ("ec.stylize.cartoon", "Cartoon", "Tecknat"), - ("ec.stylize.ccblockload", "CC Block Load", "CC Blockladdning"), - ("ec.stylize.ccburnfilm", "CC Burn Film", "CC Bränn film"), - ("ec.stylize.ccglass", "CC Glass", "CC Glas"), - ("ec.stylize.cchextile", "CC HexTile", "CC HexTile"), - ("ec.stylize.cckaleida", "CC Kaleida", "CC Kaleida"), - ("ec.stylize.ccmrsmoothie", "CC Mr. Smoothie", "CC Mr. Smoothie"), - ("ec.stylize.ccplastic", "CC Plastic", "CC Plast"), - ("ec.stylize.ccrepetile", "CC RepeTile", "CC RepeTile"), - ("ec.stylize.ccthreshold", "CC Threshold", "CC Tröskel"), - ("ec.stylize.ccthresholdrgb", "CC Threshold RGB", "CC Tröskel RGB"), - ("ec.stylize.ccvignette", "CC Vignette", "CC Vinjett"), + ("ec.stylize.ccblockload", "Block Reveal", "Blockframträdande"), + ("ec.stylize.ccburnfilm", "Film Burn", "Filmbränning"), + ("ec.stylize.ccglass", "Glass Relief", "Glasrelief"), + ("ec.stylize.cchextile", "Hexagonal Tiles", "Sexkantiga plattor"), + ("ec.stylize.cckaleida", "Kaleidoscope", "Kalejdoskop"), + ("ec.stylize.ccmrsmoothie", "Palette Map", "Mappage de palette"), + ("ec.stylize.ccplastic", "Plastic Shading", "Plastskuggning"), + ("ec.stylize.ccrepetile", "Edge Tile Repeat", "Kantupprepning"), + ("ec.stylize.ccthreshold", "Channel Threshold", "Kanaltröskel"), + ("ec.stylize.ccthresholdrgb", "RGB Threshold", "RGB-tröskel"), + ("ec.stylize.ccvignette", "Vignette", "Vinjettering"), ("ec.stylize.coloremboss", "Color Emboss", "Färgrelief"), ("ec.stylize.emboss", "Emboss", "Relief"), ("ec.stylize.findedges", "Find Edges", "Hitta kanter"), @@ -2146,8 +2153,8 @@ const SWEDISH: &[Row] = &[ ("ec.stylize.threshold", "Threshold", "Tröskel"), ("ec.text.numbers", "Numbers", "Siffror"), ("ec.text.timecode", "Timecode", "Tidskod"), - ("ec.time.ccforcemotionblur", "CC Force Motion Blur", "CC Tvinga rörelseoskärpa"), - ("ec.time.ccwidetime", "CC Wide Time", "CC Bred tid"), + ("ec.time.ccforcemotionblur", "Temporal Motion Blur", "Tidsbaserad rörelseoskärpa"), + ("ec.time.ccwidetime", "Temporal Blend", "Tidsblandning"), ("ec.time.echo", "Echo", "Eko"), ("ec.time.pixelmotionblur", "Pixel Motion Blur", "Pixelrörelseoskärpa"), ("ec.time.posterizetime", "Posterize Time", "Posterisera tid"), @@ -2156,23 +2163,23 @@ const SWEDISH: &[Row] = &[ ("ec.time.timewarp", "Timewarp", "Tidsförvrängning"), ("ec.transition.blockdissolve", "Block Dissolve", "Blockövertoning"), ("ec.transition.cardwipe", "Card Wipe", "Kortridå"), - ("ec.transition.ccglasswipe", "CC Glass Wipe", "CC Glasridå"), - ("ec.transition.ccgridwipe", "CC Grid Wipe", "CC Rutnätsridå"), - ("ec.transition.ccimagewipe", "CC Image Wipe", "CC Bildridå"), - ("ec.transition.ccjaws", "CC Jaws", "CC Käftar"), - ("ec.transition.cclightwipe", "CC Light Wipe", "CC Ljusridå"), - ("ec.transition.cclinesweep", "CC Line Sweep", "CC Linjesvep"), - ("ec.transition.ccradialscalewipe", "CC Radial ScaleWipe", "CC Radiell skalridå"), - ("ec.transition.ccscalewipe", "CC Scale Wipe", "CC Skalridå"), - ("ec.transition.cctwister", "CC Twister", "CC Virvel"), - ("ec.transition.ccwarpomatic", "CC WarpoMatic", "CC WarpoMatic"), + ("ec.transition.ccglasswipe", "Glass Wipe", "Glasövergång"), + ("ec.transition.ccgridwipe", "Grid Wipe", "Rutnätsövergång"), + ("ec.transition.ccimagewipe", "Luminance Image Wipe", "Luminansbildsövergång"), + ("ec.transition.ccjaws", "Serrated Wipe", "Tandad övergång"), + ("ec.transition.cclightwipe", "Light Wipe", "Ljusövergång"), + ("ec.transition.cclinesweep", "Line Sweep", "Linjesvep"), + ("ec.transition.ccradialscalewipe", "Radial Scale Wipe", "Radiell skalövergång"), + ("ec.transition.ccscalewipe", "Scale Wipe", "Skalövergång"), + ("ec.transition.cctwister", "Twist Wipe", "Vridövergång"), + ("ec.transition.ccwarpomatic", "Warp Dissolve", "Förvrängningsupplösning"), ("ec.transition.gradientwipe", "Gradient Wipe", "Gradientridå"), ("ec.transition.iriswipe", "Iris Wipe", "Irisridå"), ("ec.transition.linearwipe", "Linear Wipe", "Linjär ridå"), ("ec.transition.radialwipe", "Radial Wipe", "Radiell ridå"), ("ec.transition.venetian", "Venetian Blinds", "Persienner"), ("ec.utility.applylut", "Apply Color LUT", "Använd färg-LUT"), - ("ec.utility.ccoverbrights", "CC Overbrights", "CC Överljust"), + ("ec.utility.ccoverbrights", "Out-of-Range Display", "Visa utanför intervallet"), ("ec.utility.cineon", "Cineon Converter", "Cineon-konverterare"), ("ec.utility.colorprofileconverter", "Color Profile Converter", "Färgprofilkonverterare"), ("ec.utility.facemeasurements", "Face Measurements", "Ansiktsmått"), @@ -2226,6 +2233,38 @@ mod tests { use crate::i18n::set_current; use effectcraft_engine::effects; + #[test] + fn legacy_effect_names_draw_current_labels_without_changing_custom_names() { + for language in ["en", "ja", "zh-hans", "zh-hant", "fr", "sv", "ka", "cs", "de", "es", "pl", "pt-br", "ru", "uk"] { + set_current(language); + for spec in effects::registry() { + let translated = name(spec.id, spec.name); + for alias in effects::aliases(spec.id) { + assert_eq!(group(spec.id, alias), translated, "{language}: {alias}"); + assert!(matches(spec.id, alias, &spec.name.to_lowercase()), "{language}: search current name of {alias}"); + assert!(matches(spec.id, spec.name, &alias.to_lowercase()), "{language}: search legacy name {alias}"); + assert_eq!(group(spec.id, &format!("{alias} 2")), format!("{translated} 2")); + let custom = format!("{alias} custom"); + assert_eq!(group(spec.id, &custom), custom); + } + } + } + set_current("en"); + } + + #[test] + fn localized_effect_names_do_not_reintroduce_legacy_branding() { + for (language, rows) in COMPLETE.iter().chain(PARTIAL) { + for (_, _, translated) in *rows { + let label = translated.to_lowercase(); + assert!(!label.starts_with("cc "), "{language}: {translated}"); + for mark in ["lumetri", "mercury", "mocha", "keylight"] { + assert!(!label.contains(mark), "{language}: {translated}"); + } + } + } + } + /// Every row names an effect in the registry and still carries its English name, so a rename /// or a removal fails here rather than attaching a translation to a different effect. #[test] @@ -2242,6 +2281,20 @@ mod tests { } } + /// Two effects that draw one name cannot be told apart in the Effect menu, Effect Controls or + /// Effects & Presets, so every catalog names each effect it covers distinctly. + #[test] + fn display_names_are_unique_in_every_catalog() { + for (language, rows) in COMPLETE.iter().chain(PARTIAL) { + let mut seen: std::collections::HashMap<&str, &str> = std::collections::HashMap::new(); + for (id, _, translated) in *rows { + if let Some(other) = seen.insert(translated, id) { + assert_ne!(other, *id, "{language}: {id} and {other} are both {translated:?}"); + } + } + } + } + /// Rows are keyed by id, so a repeated id would shadow a translation. #[test] fn ids_are_unique() { diff --git a/crates/ui-egui/src/i18n/ui.rs b/crates/ui-egui/src/i18n/ui.rs index 15bf774f9..ac6504493 100644 --- a/crates/ui-egui/src/i18n/ui.rs +++ b/crates/ui-egui/src/i18n/ui.rs @@ -708,8 +708,8 @@ const JAPANESE: &[(&str, &str)] = &[ ("Import Photoshop File", "Photoshopファイルを読み込み"), ("Interpret Unlabeled Alpha As", "ラベルのないアルファの解釈"), ("Join the ArtCraft Discord", "ArtCraftのDiscordに参加"), - ("Mercury GPU Acceleration ({})", "Mercury GPUアクセラレーション({})"), - ("Mercury Software Only", "Mercuryソフトウェアのみ"), + ("GPU Acceleration ({})", "GPUアクセラレーション({})"), + ("Software Rendering", "ソフトウェアレンダリング"), ("OCIO (built-in ACES config)", "OCIO(組み込みACES設定)"), ("Off (Final Quality)", "オフ(最終品質)"), ("OpenGL (compatibility)", "OpenGL(互換)"), @@ -1118,7 +1118,7 @@ const JAPANESE: &[(&str, &str)] = &[ ("Script Console", "スクリプトコンソール"), ("Essential Graphics", "エッセンシャルグラフィックス"), ("ScriptUI Panel", "ScriptUIパネル"), - ("Lumetri Scopes", "Lumetriスコープ"), + ("Video Scopes", "ビデオスコープ"), ("Media Browser", "メディアブラウザー"), ("Content-Aware Fill", "コンテンツに応じた塗りつぶし"), ("Create Nulls From Paths", "パスからヌルを作成"), @@ -1318,6 +1318,7 @@ const JAPANESE: &[(&str, &str)] = &[ ("per second", "毎秒"), ("Waveform", "波形"), ("steps", "ステップ"), + ("GPU Acceleration (no GPU: software)", "GPUアクセラレーション(GPUなし:ソフトウェア)"), ]; const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[ @@ -1837,8 +1838,8 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[ ("Import Photoshop File", "导入 Photoshop 文件"), ("Interpret Unlabeled Alpha As", "将未标记的 Alpha 解释为"), ("Join the ArtCraft Discord", "加入 ArtCraft Discord"), - ("Mercury GPU Acceleration ({})", "Mercury GPU 加速({})"), - ("Mercury Software Only", "仅 Mercury 软件"), + ("GPU Acceleration ({})", "GPU 加速({})"), + ("Software Rendering", "软件渲染"), ("OCIO (built-in ACES config)", "OCIO(内置 ACES 配置)"), ("Off (Final Quality)", "关闭(最终质量)"), ("OpenGL (compatibility)", "OpenGL(兼容)"), @@ -2280,7 +2281,7 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[ ("Script Console", "脚本控制台"), ("Essential Graphics", "基本图形"), ("ScriptUI Panel", "ScriptUI 面板"), - ("Lumetri Scopes", "Lumetri 示波器"), + ("Video Scopes", "视频示波器"), ("Media Browser", "媒体浏览器"), ("Content-Aware Fill", "内容识别填充"), ("Create Nulls From Paths", "从路径创建空对象"), @@ -2433,6 +2434,7 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[ ("Blend Mode", "混合模式"), ("Show mesh", "显示网格"), ("Record Options...", "记录选项..."), + ("GPU Acceleration (no GPU: software)", "GPU 加速(无 GPU:软件)"), ]; /// Swedish (`sv`), written from the English source. @@ -2950,8 +2952,8 @@ const SWEDISH: &[(&str, &str)] = &[ ("Import Photoshop File", "Importera Photoshop-fil"), ("Interpret Unlabeled Alpha As", "Tolka omärkt alfa som"), ("Join the ArtCraft Discord", "Gå med i ArtCraft på Discord"), - ("Mercury GPU Acceleration ({})", "Mercury GPU-acceleration ({})"), - ("Mercury Software Only", "Endast Mercury-programvara"), + ("GPU Acceleration ({})", "GPU-acceleration ({})"), + ("Software Rendering", "Programvarurendering"), ("OCIO (built-in ACES config)", "OCIO (inbyggd ACES-konfiguration)"), ("Off (Final Quality)", "Av (slutlig kvalitet)"), ("OpenGL (compatibility)", "OpenGL (kompatibilitet)"), @@ -3191,7 +3193,7 @@ const SWEDISH: &[(&str, &str)] = &[ ("Drop {} files to import", "Släpp {} filer för att importera"), ("Effects", "Effekter"), ("Label of {}: {}", "Etikett för {}: {}"), - ("Mercury GPU Acceleration (no GPU: software)", "Mercury GPU-acceleration (ingen GPU: programvara)"), + ("GPU Acceleration (no GPU: software)", "GPU-acceleration (ingen GPU: programvara)"), ("Only one project can be opened per drop; skipped {} more", "Bara ett projekt kan öppnas per släpp; hoppade över {} till"), ("Open in Essential Graphics", "Öppna i Grundläggande grafik"), ("Original color: click to go back to it", "Originalfärg: klicka för att återgå till den"), @@ -3440,7 +3442,7 @@ const SWEDISH: &[(&str, &str)] = &[ ("Script Console", "Skriptkonsol"), ("Essential Graphics", "Grundläggande grafik"), ("ScriptUI Panel", "ScriptUI-panel"), - ("Lumetri Scopes", "Lumetri-scope"), + ("Video Scopes", "Videoskop"), ("Media Browser", "Mediebläddrare"), ("Content-Aware Fill", "Innehållsmedveten fyllning"), ("Create Nulls From Paths", "Skapa nullobjekt från banor"), @@ -4608,7 +4610,7 @@ const TRADITIONAL_CHINESE: &[(&str, &str)] = &[ ("Script Console", "指令碼主控台"), ("Essential Graphics", "基本圖形"), ("ScriptUI Panel", "ScriptUI 面板"), - ("Lumetri Scopes", "Lumetri 示波器"), + ("Video Scopes", "視訊示波器"), ("Media Browser", "媒體瀏覽器"), ("Content-Aware Fill", "內容感知填色"), ("Create Nulls From Paths", "從路徑建立空物件"), @@ -4761,6 +4763,9 @@ const TRADITIONAL_CHINESE: &[(&str, &str)] = &[ ("Blend Mode", "混合模式"), ("Show mesh", "顯示網格"), ("Record Options...", "記錄選項..."), + ("Software Rendering", "軟體算繪"), + ("GPU Acceleration ({})", "GPU 加速({})"), + ("GPU Acceleration (no GPU: software)", "GPU 加速(無 GPU:軟體)"), ]; /// Ukrainian (uk): original translations of the same interface rows as the Chinese catalogs. @@ -5301,8 +5306,8 @@ const UKRAINIAN: &[(&str, &str)] = &[ ("Import Photoshop File", "Імпорт файлу Photoshop"), ("Interpret Unlabeled Alpha As", "Інтерпретувати непозначену альфу як"), ("Join the ArtCraft Discord", "Приєднатися до Discord ArtCraft"), - ("Mercury GPU Acceleration ({})", "Прискорення Mercury GPU ({})"), - ("Mercury Software Only", "Лише програмний Mercury"), + ("GPU Acceleration ({})", "Прискорення GPU ({})"), + ("Software Rendering", "Програмне відтворення"), ("OCIO (built-in ACES config)", "OCIO (вбудована конфігурація ACES)"), ("Off (Final Quality)", "Вимкнено (остаточна якість)"), ("OpenGL (compatibility)", "OpenGL (сумісність)"), @@ -5348,6 +5353,8 @@ const UKRAINIAN: &[(&str, &str)] = &[ ("Project", "Проєкт"), ("Total Offset", "Загальний зсув"), ("Per Layer", "На шар"), + ("Video Scopes", "Відеоскопи"), + ("GPU Acceleration (no GPU: software)", "Прискорення GPU (без GPU: програмне)"), ]; // Brazilian Portuguese. @@ -5979,7 +5986,7 @@ const PORTUGUESE: &[(&str, &str)] = &[ ("Guess", "Adivinhar"), ("Import Image Sequence", "Importar sequência de imagens"), ("Import PDF / Illustrator File", "Importar arquivo PDF / Illustrator"), - ("Mercury Software Only", "Apenas software Mercury"), + ("Software Rendering", "Renderização por software"), ("OCIO (built-in ACES config)", "OCIO (config do ACES integrado)"), ("Still Duration", "Duração da imagem fixa"), ("Straight", "Direto"), @@ -6086,7 +6093,7 @@ const PORTUGUESE: &[(&str, &str)] = &[ ("Light", "Claro"), ("Lines", "Linhas"), ("Memory & CPU", "Memória e CPU"), - ("Mercury GPU Acceleration ({})", "Aceleração de GPU Mercury ({})"), + ("GPU Acceleration ({})", "Aceleração de GPU ({})"), ("Off", "Desativado"), ("Options", "Opções"), ("Overlay", "Sobrepor"), @@ -6111,6 +6118,8 @@ const PORTUGUESE: &[(&str, &str)] = &[ ("Video", "Vídeo"), ("channel", "canal"), ("files", "arquivos"), + ("Video Scopes", "Escopos de vídeo"), + ("GPU Acceleration (no GPU: software)", "Aceleração de GPU (sem GPU: software)"), ]; /// Polish (pl): original translations covering every row in the Chinese panel catalogs. @@ -6629,8 +6638,8 @@ const POLISH: &[(&str, &str)] = &[ ("Import Photoshop File", "Importuj plik Photoshopa"), ("Interpret Unlabeled Alpha As", "Interpretuj nieoznaczoną alfę jako"), ("Join the ArtCraft Discord", "Dołącz do Discorda ArtCraft"), - ("Mercury GPU Acceleration ({})", "Akceleracja Mercury GPU ({})"), - ("Mercury Software Only", "Tylko programowy Mercury"), + ("GPU Acceleration ({})", "Akceleracja GPU ({})"), + ("Software Rendering", "Renderowanie programowe"), ("OCIO (built-in ACES config)", "OCIO (wbudowana konfiguracja ACES)"), ("Off (Final Quality)", "Wył. (jakość końcowa)"), ("OpenGL (compatibility)", "OpenGL (zgodność)"), @@ -6868,6 +6877,8 @@ const POLISH: &[(&str, &str)] = &[ ("Resolution:", "Rozdzielczość:"), ("Guide Layer", "Warstwa pomocnicza"), ("Layer Styles", "Style warstwy"), + ("Video Scopes", "Wskaźniki wideo"), + ("GPU Acceleration (no GPU: software)", "Akceleracja GPU (bez GPU: programowa)"), ]; /// Czech (cs): original translations covering every row in the Chinese panel catalogs. @@ -7380,8 +7391,8 @@ const CZECH: &[(&str, &str)] = &[ ("Import Photoshop File", "Importovat soubor Photoshop"), ("Interpret Unlabeled Alpha As", "Interpretovat neoznačenou alfu jako"), ("Join the ArtCraft Discord", "Připojit se na Discord ArtCraft"), - ("Mercury GPU Acceleration ({})", "GPU akcelerace Mercury ({})"), - ("Mercury Software Only", "Pouze softwarové zpracování Mercury"), + ("GPU Acceleration ({})", "Akcelerace GPU ({})"), + ("Software Rendering", "Softwarové vykreslování"), ("OCIO (built-in ACES config)", "OCIO (vestavěná konfigurace ACES)"), ("Off (Final Quality)", "Vypnuto (finální kvalita)"), ("OpenGL (compatibility)", "OpenGL (kompatibilita)"), @@ -7432,6 +7443,8 @@ const CZECH: &[(&str, &str)] = &[ ("Variable fonts only", "Jen proměnná písma"), ("Total Offset", "Celkový posun"), ("Per Layer", "Na vrstvu"), + ("Video Scopes", "Videoskopy"), + ("GPU Acceleration (no GPU: software)", "Akcelerace GPU (bez GPU: software)"), ]; /// Spanish: neutral, tú, sentence case; the same source strings as the Chinese catalogs, in the same @@ -7960,8 +7973,8 @@ const SPANISH: &[(&str, &str)] = &[ ("Import Photoshop File", "Importar archivo de Photoshop"), ("Interpret Unlabeled Alpha As", "Interpretar alfa sin etiquetar como"), ("Join the ArtCraft Discord", "Únete al Discord de ArtCraft"), - ("Mercury GPU Acceleration ({})", "Aceleración por GPU Mercury ({})"), - ("Mercury Software Only", "Solo software Mercury"), + ("GPU Acceleration ({})", "Aceleración por GPU ({})"), + ("Software Rendering", "Renderizado por software"), ("OCIO (built-in ACES config)", "OCIO (configuración ACES integrada)"), ("Off (Final Quality)", "Desactivado (calidad final)"), ("OpenGL (compatibility)", "OpenGL (compatibilidad)"), @@ -8002,6 +8015,8 @@ const SPANISH: &[(&str, &str)] = &[ ("After Effects project", "Proyecto de After Effects"), ("Lottie animation", "Animación de Lottie"), ("Project", "Proyecto"), + ("Video Scopes", "Monitores de vídeo"), + ("GPU Acceleration (no GPU: software)", "Aceleración por GPU (sin GPU: software)"), ]; /// Georgian (ka): every row of the Chinese catalogs, in the same order (the tests keep them in step). @@ -8528,8 +8543,8 @@ const GEORGIAN: &[(&str, &str)] = &[ ("Import Photoshop File", "Photoshop ფაილის იმპორტი"), ("Interpret Unlabeled Alpha As", "უცნობი ალფას ინტერპრეტაცია"), ("Join the ArtCraft Discord", "შემოგვიერთდით Discord-ზე"), - ("Mercury GPU Acceleration ({})", "GPU აჩქარება ({})"), - ("Mercury Software Only", "მხოლოდ Mercury Software"), + ("GPU Acceleration ({})", "GPU აჩქარება ({})"), + ("Software Rendering", "პროგრამული რენდერი"), ("OCIO (built-in ACES config)", "OCIO (ჩაშენებული ACES კონფიგურაცია)"), ("Off (Final Quality)", "გამორთული (საბოლოო ხარისხი)"), ("OpenGL (compatibility)", "OpenGL (თავსებადობა)"), @@ -8761,6 +8776,7 @@ const GEORGIAN: &[(&str, &str)] = &[ ("Total Offset", "ჯამური წანაცვლება"), ("Per Layer", "შრიდან შრემდე"), ("Track", "ტრეკინგი"), + ("Video Scopes", "ვიდეოსკოპები"), ]; /// Georgian rows for interface text no other catalog has yet: strings the panels already send @@ -8951,7 +8967,7 @@ const GEORGIAN_PANELS: &[(&str, &str)] = &[ ("Solid Settings", "სოლიდის პარამეტრები"), ("Save as Template", "შაბლონად შენახვა"), ("My Custom RGB", "ჩემი მორგებული RGB"), - ("Mercury GPU Acceleration (no GPU: software)", "Mercury GPU აჩქარება (GPU არ არის: პროგრამული)"), + ("GPU Acceleration (no GPU: software)", "GPU აჩქარება (GPU არ არის: პროგრამული)"), ("Sort by {}, {}", "დალაგება: {}, {}"), ("Sort by {}", "დალაგება: {}"), ("Label of {}: {}", "{}-ის იარლიყი: {}"), @@ -9510,8 +9526,8 @@ const FRENCH: &[(&str, &str)] = &[ ("Import Photoshop File", "Importer un fichier Photoshop"), ("Interpret Unlabeled Alpha As", "Interpréter l’alpha non étiqueté comme"), ("Join the ArtCraft Discord", "Rejoindre le Discord ArtCraft"), - ("Mercury GPU Acceleration ({})", "Accélération GPU Mercury ({})"), - ("Mercury Software Only", "Mercury, logiciel uniquement"), + ("GPU Acceleration ({})", "Accélération GPU ({})"), + ("Software Rendering", "Rendu logiciel"), ("OCIO (built-in ACES config)", "OCIO (configuration ACES intégrée)"), ("Off (Final Quality)", "Désactivé (qualité finale)"), ("OpenGL (compatibility)", "OpenGL (compatibilité)"), @@ -9926,7 +9942,7 @@ const FRENCH: &[(&str, &str)] = &[ ("Solid Settings", "Paramètres du solide"), ("Save as Template", "Enregistrer en tant que modèle"), ("My Custom RGB", "Mon RVB personnalisé"), - ("Mercury GPU Acceleration (no GPU: software)", "Accélération GPU Mercury (aucun GPU : logiciel)"), + ("GPU Acceleration (no GPU: software)", "Accélération GPU (aucun GPU : logiciel)"), ("Sort by {}, {}", "Trier par {}, {}"), ("Sort by {}", "Trier par {}"), ("Label of {}: {}", "Étiquette de {} : {}"), @@ -10047,7 +10063,7 @@ const FRENCH: &[(&str, &str)] = &[ ("Script Console", "Console de scripts"), ("Essential Graphics", "Graphiques essentiels"), ("ScriptUI Panel", "Panneau ScriptUI"), - ("Lumetri Scopes", "Scopes Lumetri"), + ("Video Scopes", "Oscilloscopes vidéo"), ("Media Browser", "Explorateur de médias"), ("Content-Aware Fill", "Remplissage adapté au contenu"), ("Create Nulls From Paths", "Créer des objets nuls à partir de tracés"), @@ -10266,6 +10282,26 @@ const FRENCH: &[(&str, &str)] = &[ mod tests { use super::*; + /// Check rendered feature labels only. Format names, compatibility tokens and user text + /// are not subject to this guard, and a missing translation keeps its English fallback. + #[test] + fn renamed_panel_labels_do_not_reintroduce_vendor_names() { + for language in ["en", "ja", "zh-hans", "zh-hant", "fr", "sv", "ka", "cs", "de", "es", "pl", "pt-br", "ru", "uk"] { + set_current(language); + for source in ["GPU Acceleration ({})", "GPU Acceleration (no GPU: software)", "Software Rendering", "Video Scopes"] { + let rendered = tr(source); + assert!(!rendered.is_empty(), "{language}: {source}"); + let label = rendered.to_lowercase(); + for mark in ["lumetri", "mercury", "mocha", "keylight"] { + assert!(!label.contains(mark), "{language}: {source} -> {rendered}"); + } + } + // A real interchange label remains factual, not rewritten or rejected. + assert!(!tr("Export Adobe Premiere Pro Project").is_empty()); + } + set_current("en"); + } + /// The interface text that has moved into this catalog. Add a panel here when you convert it; /// `every_row_is_used_by_a_converted_panel` then looks for its rows' English sources in it. pub(super) const CONVERTED: &[(&str, &str)] = &[ diff --git a/crates/ui-egui/src/panels/forms.rs b/crates/ui-egui/src/panels/forms.rs index 635ef9a43..e83530fa4 100644 --- a/crates/ui-egui/src/panels/forms.rs +++ b/crates/ui-egui/src/panels/forms.rs @@ -338,11 +338,11 @@ fn interpret_footage_form(s: &effectcraft_engine::Session, proxy: bool, base: &m /// The Project Settings dialog's title and fields. fn project_settings_form(s: &effectcraft_engine::Session) -> (String, Vec) { let st = &s.project.settings; - // The catalogue row is `Mercury GPU Acceleration ({})`, so the value goes through + // The catalogue row is `GPU Acceleration ({})`, so the value goes through // tr_args: wrapping the assembled string in tr() would look up the backend's name. let gpu_label = match &s.accel { - Some(a) => tr_args("Mercury GPU Acceleration ({})", &[&a.name()]), - None => tr("Mercury GPU Acceleration (no GPU: software)").to_string(), + Some(a) => tr_args("GPU Acceleration ({})", &[&a.name()]), + None => tr("GPU Acceleration (no GPU: software)").to_string(), }; let depth = match st.bit_depth.label() { l if l.starts_with("16") => 1, @@ -436,7 +436,7 @@ fn project_settings_form(s: &effectcraft_engine::Session) -> (String, Vec Field::choice( "renderer", "Video rendering and effects", - &[(gpu_label.as_str(), json!("gpu")), ("Mercury Software Only", json!("software"))], + &[(gpu_label.as_str(), json!("gpu")), ("Software Rendering", json!("software"))], usize::from(!st.gpu_acceleration), ), ], @@ -1050,6 +1050,18 @@ pub fn show_view_options(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Toke mod tests { use super::*; + #[test] + fn renderer_form_keeps_descriptive_labels_and_stable_option_values() { + crate::i18n::set_current("en"); + let (_, fields) = project_settings_form(&effectcraft_engine::Session::default()); + let renderer = fields.iter().find(|field| field.key == "renderer").unwrap(); + let FieldKind::Choice { options, .. } = &renderer.kind else { panic!("renderer must be a choice") }; + assert_eq!( + options.as_slice(), + &[("GPU Acceleration (no GPU: software)".to_string(), json!("gpu")), ("Software Rendering".to_string(), json!("software"))] + ); + } + #[test] fn form_params_build_arrays_and_choices() { let f = Form { diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 60a30e97e..612aa0a10 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -756,7 +756,7 @@ pub struct UiState { /// Flowchart panel options (layers, effects, solids, direction, root comp). #[serde(default)] pub flowchart: crate::panels::flowchart::FlowOptions, - /// Lumetri Scopes panel options. + /// Video Scopes panel options. #[serde(default)] pub scopes: crate::panels::scopes_panel::ScopesState, } diff --git a/crates/ui-egui/tests/it/ui_angles.rs b/crates/ui-egui/tests/it/ui_angles.rs index 007e11286..40ad17bc1 100644 --- a/crates/ui-egui/tests/it/ui_angles.rs +++ b/crates/ui-egui/tests/it/ui_angles.rs @@ -38,7 +38,7 @@ fn harness(panel: Panel, angle: f64) -> (Harness<'static, EffectcraftApp>, u64, s.execute("comp.new", json!({"name": "Angles", "width": 320, "height": 180, "duration": 4})).unwrap(); let layer = s.execute("layer.newSolid", json!({"name": "Plate", "color": "#40b080"})).unwrap()["layer"].as_u64().unwrap(); let uid = if matches!(panel, Panel::EffectControls) { - let fx = s.execute("effect.apply", json!({"layer": layer, "effect": "CC Bend It"})).unwrap()["effects"][0].as_u64().unwrap(); + let fx = s.execute("effect.apply", json!({"layer": layer, "effect": "Two-Point Bend"})).unwrap()["effects"][0].as_u64().unwrap(); s.active_comp().unwrap().layer(LayerId(layer)).unwrap().props.find_group(fx).unwrap().get("bend").unwrap().uid } else { s.active_comp().unwrap().layer(LayerId(layer)).unwrap().props.prop("transform/rotation").unwrap().uid diff --git a/crates/ui-egui/tests/it/ui_color_hex.rs b/crates/ui-egui/tests/it/ui_color_hex.rs index 4f8a8ab14..8a5a39b8e 100644 --- a/crates/ui-egui/tests/it/ui_color_hex.rs +++ b/crates/ui-egui/tests/it/ui_color_hex.rs @@ -1,4 +1,4 @@ -//! The colour picker every colour input opens: its hex field sets an effect's colour (CC Toner), +//! The colour picker every colour input opens: its hex field sets an effect's colour (Multi-Tone Tint), //! the dialogs' colour button stores sRGB (egui's own `color_edit_button_rgba` read the stored //! sRGB values as linear, so mid-grey `#808080` was stored as `#373737`), the square, slider and //! HSB / RGB fields set the colour, and Cancel / Escape / the original swatch restore it. @@ -45,7 +45,7 @@ fn hex_code_sets_an_effect_colour() { let mut s = Session::default(); s.execute("comp.new", json!({"name": "Hex", "width": 320, "height": 180, "duration": 4})).unwrap(); let layer = s.execute("layer.newSolid", json!({"name": "Plate", "color": "#40b080"})).unwrap()["layer"].as_u64().unwrap(); - let fx = s.execute("effect.apply", json!({"layer": layer, "effect": "CC Toner"})).unwrap()["effects"][0].as_u64().unwrap(); + let fx = s.execute("effect.apply", json!({"layer": layer, "effect": "Multi-Tone Tint"})).unwrap()["effects"][0].as_u64().unwrap(); let uid = s.active_comp().unwrap().layer(LayerId(layer)).unwrap().props.find_group(fx).unwrap().get("midtones").unwrap().uid; s.state.selected_layers = vec![LayerId(layer)]; let mut app = EffectcraftApp::new(s); diff --git a/crates/ui-egui/tests/it/ui_effect_controls.rs b/crates/ui-egui/tests/it/ui_effect_controls.rs index 1db059220..15802d889 100644 --- a/crates/ui-egui/tests/it/ui_effect_controls.rs +++ b/crates/ui-egui/tests/it/ui_effect_controls.rs @@ -260,14 +260,14 @@ fn the_eyedropper_stays_armed_until_the_viewer_has_a_frame() { } } -/// Key Light's Screen Colour eyedropper picks from the effect's input: the shown frame is +/// Screen Color Key's Screen Colour eyedropper picks from the effect's input: the shown frame is /// already keyed (the default screen colour takes most of a green), so sampling it would miss. #[test] fn keyer_eyedropper_picks_the_screen_from_the_effect_input() { let mut s = Session::default(); s.execute("comp.new", json!({"name": "Key", "width": 320, "height": 180, "frameRate": 30, "duration": 1})).unwrap(); let screen = s.execute("layer.newSolid", json!({"name": "Screen", "color": "#30b050"})).unwrap()["layer"].as_u64().unwrap(); - let fx = s.execute("effect.apply", json!({"layers": [screen], "effect": "Key Light"})).unwrap()["effects"][0].as_u64().unwrap(); + let fx = s.execute("effect.apply", json!({"layers": [screen], "effect": "Screen Color Key"})).unwrap()["effects"][0].as_u64().unwrap(); let prop = layer(&s, screen).effects().unwrap().groups().find(|g| g.uid == fx).and_then(|g| g.get("screenColour")).map(|p| p.uid).unwrap(); s.state.selected_layers = vec![LayerId(screen)]; let mut app = EffectcraftApp::new(s); @@ -295,7 +295,7 @@ fn keyer_eyedropper_picks_the_screen_from_the_effect_input() { fn command_clicking_an_effect_twirl_closes_and_opens_its_groups() { let (app, x) = app(); let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| app); - let fx = h.state_mut().session.execute("effect.apply", json!({"layers": [x.small], "effect": "Lumetri Color"})).unwrap()["effects"][0].as_u64().unwrap(); + let fx = h.state_mut().session.execute("effect.apply", json!({"layers": [x.small], "effect": "Color Grading"})).unwrap()["effects"][0].as_u64().unwrap(); // Only this effect open, so its header is on screen. let l = layer(&h.state().session, x.small); let others: Vec = l.effects().unwrap().groups().map(|g| g.uid).filter(|u| *u != fx).collect(); diff --git a/crates/ui-egui/tests/it/ui_effect_drop_highlight.rs b/crates/ui-egui/tests/it/ui_effect_drop_highlight.rs index 6c0ede47a..ddef6c94b 100644 --- a/crates/ui-egui/tests/it/ui_effect_drop_highlight.rs +++ b/crates/ui-egui/tests/it/ui_effect_drop_highlight.rs @@ -13,7 +13,7 @@ fn rect(h: &Harness<'_, EffectcraftApp>, id: &str) -> Rect { fn drag_to(h: &mut Harness<'_, EffectcraftApp>, p: Pos2) { h.input_mut().events.push(Event::PointerMoved(p)); h.input_mut().events.push(Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); - egui::DragAndDrop::set_payload(&h.ctx, DragPayload::Effect("CC Bend It".into())); + egui::DragAndDrop::set_payload(&h.ctx, DragPayload::Effect("Two-Point Bend".into())); h.run_steps(2); } diff --git a/crates/ui-egui/tests/it/ui_fx_editors.rs b/crates/ui-egui/tests/it/ui_fx_editors.rs index b9530fdf4..b4d999311 100644 --- a/crates/ui-egui/tests/it/ui_fx_editors.rs +++ b/crates/ui-egui/tests/it/ui_fx_editors.rs @@ -130,7 +130,7 @@ fn undo(h: &mut Harness<'_, EffectcraftApp>) { #[test] fn lumetri_rgb_and_hue_saturation_curve_editors() { - let (s0, l, fx) = with_effect("Lumetri Color"); + let (s0, l, fx) = with_effect("Color Grading"); let mut h = harness(s0); only_groups(&mut h, l, fx, &["curves", "rgbCurves", "hueSaturationCurves"]); let pre = format!("effectControls.effect.{fx}.lumetri.rgbCurves"); diff --git a/crates/ui-egui/tests/it/ui_live_preview.rs b/crates/ui-egui/tests/it/ui_live_preview.rs index e72856bfc..abe3cc427 100644 --- a/crates/ui-egui/tests/it/ui_live_preview.rs +++ b/crates/ui-egui/tests/it/ui_live_preview.rs @@ -77,12 +77,12 @@ fn position_anchor_and_effect_edits_present_intermediate_pixels() { (None, "transform/position", json!([22, 18, 0]), json!([18, 18, 0])), (None, "transform/anchor", json!([9, 8, 0]), json!([6, 8, 0])), (Some("Gaussian Blur"), "blurriness", json!(3), json!(6)), - (Some("CC Radial Fast Blur"), "center", json!([4, 4]), json!([18, 12])), + (Some("Fast Radial Blur"), "center", json!([4, 4]), json!([18, 12])), ] { let mut session = Session::default(); session.execute("comp.new", json!({"width":64,"height":36,"duration":1})).unwrap(); let layer = session.execute("layer.newSolid", json!({"color":"#ffffff","width":24,"height":16})).unwrap()["layer"].as_u64().unwrap(); - if effect == Some("CC Radial Fast Blur") { + if effect == Some("Fast Radial Blur") { // A uniform solid is invariant under a radial blur; give the point edit visible detail. session.execute("effect.apply", json!({"layers":[layer],"effect":"Gradient Ramp"})).unwrap(); } diff --git a/crates/ui-egui/tests/it/ui_parameter_spacing.rs b/crates/ui-egui/tests/it/ui_parameter_spacing.rs index 71b70a14e..167029f7c 100644 --- a/crates/ui-egui/tests/it/ui_parameter_spacing.rs +++ b/crates/ui-egui/tests/it/ui_parameter_spacing.rs @@ -54,7 +54,7 @@ fn nested_groups_keep_indentation_value_alignment_and_effect_gaps_at_fixed_compa let mut s = Session::default(); s.execute("comp.new", json!({"width":64,"height":36,"duration":1})).unwrap(); s.execute("layer.newSolid", json!({"name":"Plate","color":"#406080"})).unwrap(); - let fx = s.execute("effect.apply", json!({"effect":"Lumetri Color"})).unwrap()["effects"][0].as_u64().unwrap(); + let fx = s.execute("effect.apply", json!({"effect":"Color Grading"})).unwrap()["effects"][0].as_u64().unwrap(); let next = s.execute("effect.apply", json!({"effect":"Checkbox Control"})).unwrap()["effects"][0].as_u64().unwrap(); let g = s.active_comp().unwrap().layers[0].props.find_group(fx).unwrap(); let basic = g.sub("basicCorrection").unwrap(); diff --git a/crates/ui-egui/tests/it/ui_viewer.rs b/crates/ui-egui/tests/it/ui_viewer.rs index 7b32fa2ec..e01608e16 100644 --- a/crates/ui-egui/tests/it/ui_viewer.rs +++ b/crates/ui-egui/tests/it/ui_viewer.rs @@ -2370,7 +2370,7 @@ fn command_clicking_a_group_twirl_opens_its_whole_tree() { // twirls open with it, and closed again with it. let mut h = harness(); let id = layer_id(&h, "Box"); - h.state_mut().session.execute("effect.apply", json!({"effect": "Lumetri Color", "layers": [id]})).unwrap(); + h.state_mut().session.execute("effect.apply", json!({"effect": "Color Grading", "layers": [id]})).unwrap(); fn walk(g: &effectcraft_engine::project::PropGroup, out: &mut Vec) { for sg in g.groups() { out.push(sg.uid); diff --git a/docs/architecture.md b/docs/architecture.md index 83c03f14f..a04907aec 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -121,7 +121,7 @@ are not rewritten, so an expression that computes an effect point on a shape or other values may need `+ [thisComp.width / 2, thisComp.height / 2]`. Effects that use the layer bounds (edge pinning, wipes, Offset, generators) now cover the whole comp-sized bounds instead of their bottom-right quarter. Tracking data of effects that analyse footage (Warp Stabilizer, 3D -Camera Tracker, Mocha shape) is left as it is: footage has a source rectangle, whose effect space +Camera Tracker, Tracked Shape Matte) is left as it is: footage has a source rectangle, whose effect space did not change. ## 4. Rendering @@ -331,7 +331,7 @@ before conversion (a quarter of the conversions; the result differs from convert in blocks where colours clip) and resampled from there, as other frames are from full size. **GPU compositor** (`crates/gpu`; Project Settings ▸ Video Rendering and Effects ▸ Mercury GPU -Acceleration, the default, or Mercury Software Only; `render.backend`). The CPU renderer is the +Acceleration, the default, or Software Rendering; `render.backend`). The CPU renderer is the reference and keeps rendering layer content (sources, masks, CPU effects, layer styles) into the layer cache. The render crate defines an `Accelerator` trait; `effectcraft_gpu::Gpu` implements it on wgpu compute shaders. `RenderOpts::backend` picks `Cpu`, `Gpu` or `Auto` (an accelerator @@ -341,7 +341,7 @@ per comp, output scale and path (readback or viewer display) it averages CPU and (warm-up on both sides, the fastest warm-up frame starting the average, single stalls capped), picks the GPU unless the CPU is clearly faster, and re-measures the other side every 48 frames. Render Queue jobs don't use Auto: every frame of a job renders on the project's renderer (the -GPU compositor with Mercury GPU Acceleration), so runs of a render don't differ by timing. +GPU compositor with GPU Acceleration), so runs of a render don't differ by timing. Light comps (a few small layers, which the CPU composites only within their bounds) then stay on the CPU instead of paying for full-frame passes and a readback. A GPU frame walks the comp like `draw_comp`: cached layer buffers are uploaded once per buffer, then transformed with the CPU's @@ -370,16 +370,16 @@ Preserve Transparency / blend kernels (a 3D track matte renders solo through the Environment Light Background layers draw their sky in a kernel (`adv_sky`, from `Renderer::sky_draw`) before the rest of the run, in Classic and Advanced 3D comps. Wireframe outlines draw on the GPU from the CPU's pixel list (`Renderer::wireframe_pixels`). GPU effects -(`effects::GPU_EFFECTS`, 280 of them: blurs, colour correction, keying incl. Key Light, mattes, -channel, stylize, distortion and warps (Warp, Bezier Warp, Smear, Reshape, CC Bend It, CC Page -Turn, CC Bender, CC Blobbylize), Cartoon, bevels, shapes, the transitions (CC light family, CC -transitions, Block Dissolve), perspective (Radial Shadow, CC Cylinder / Sphere / Spotlight / +(`effects::GPU_EFFECTS`, 280 of them: blurs, colour correction, keying incl. Screen Color Key, mattes, +channel, stylize, distortion and warps (Warp, Bezier Warp, Smear, Reshape, Two-Point Bend, CC Page +Turn, Flexible Bend, Organic Displacement), Cartoon, bevels, shapes, the transitions (CC light family, CC +transitions, Block Dissolve), perspective (Radial Shadow, Cylinder Wrap / Sphere / Spotlight / Environment, 3D Glasses), generators, noise, grain, text (Numbers, Timecode), time, 3D Channel (aux channels as an extra texture), Immersive Video, colour management (colour programs from `effects::color_program`, LUTs in a storage buffer) and the simulations' render passes (the simulation stays on the CPU and hands its plan — sprites, pieces, blobs, grids — to a tiled -rasteriser; the particle effects too, `gpu::fx_particles`: CC Particle World / Systems II, -Particle Playground with its Layer Map frames in one atlas, CC Ball Action, CC Pixel Polly, CC +rasteriser; the particle effects too, `gpu::fx_particles`: Particle Emitter 3D / Systems II, +Particle Playground with its Layer Map frames in one atlas, Ball Grid, Pixel Shatter, CC Scatterize; plans too large for one item table draw in several passes over the previous one), and the geometry generators (Lightning, Advanced Lightning, Radio Waves, Stroke, Scribble, Vegas, Write-on, Audio Spectrum / Waveform, Basic / Path Text: bolts, strokes, waves, audio @@ -390,7 +390,7 @@ as kernels, in one module per family (`gpu::fx_*` with `shaders/fx_*.wgsl`); con effects run as one chain with one upload and one readback. Statistics that need the whole frame (Auto Levels / Contrast / Color, Equalize, Shadow/Highlight, Color Stabilizer, Remove Grain's noise level) are measured on the CPU from one readback and applied on the GPU; effects reading -other frames (Echo, Posterize Time, Time Difference, Time Displacement, CC Force Motion Blur, CC +other frames (Echo, Posterize Time, Time Difference, Time Displacement, Temporal Motion Blur, CC Wide Time, Pixel Motion Blur, Timewarp) upload the frames the host renders (`time_frames`) and combine them on the GPU; Time Displacement's per-pixel times and Timewarp's motion vectors (`time_fx::timewarp_plan`) are computed on the CPU. Numbers and Timecode rasterise their glyph @@ -433,12 +433,12 @@ sentinel is implemented here. Browser scope futures are not synchronously awaite forwards shared-device errors, while owned worker devices install their own handlers. On the web (WebGPU) the GPU composites viewer frames; steps that need a readback fall back to the CPU (the Info panel's pixel readout reads GPU frames back asynchronously). **GPU particles** -(`effects::psim`, `gpu::particles`): CC Particle World, CC Particle Systems II and Particle +(`effects::psim`, `gpu::particles`): Particle Emitter 3D, Particle Emitter 2D and Particle Playground cannons without interacting forces evolve every particle independently, so the GPU backend (reached through `EffectHost::particles` when the GPU compositor is active) simulates one particle per invocation from the CPU's birth schedule and keeps per-key state checkpoints on the GPU, like `SimCache`; the CPU simulation stays the oracle (tests compare ids and positions). -CC Particle World, CC Particle Systems II and CC Mr. Mercury sample their Birth Rate at every +Particle Emitter 3D, Particle Emitter 2D and Liquid Particles sample their Birth Rate at every step (`EffectHost::param_at`, #1373), so a keyed rate only decides the births of its own time; the rate is left out of the simulation key, and a checkpoint is resumed only with the same rate history (the CPU state's `hist`, the GPU checkpoint's births). The rate's keyframes are read at the step's exact layer time @@ -629,7 +629,7 @@ Unix milliseconds. The layer's Start Time becomes `dataStart + videoStart − fi (`videoStart` given, or the file's creation date on the desktop; reduced to a time of day when the data has no dates). -**Lumetri Scopes** (`raster::scopes`) are density plots of the viewer frame (rendered over the +**Video Scopes** (`raster::scopes`) are density plots of the viewer frame (rendered over the comp background) with BT.601 / BT.709 / BT.2020 luma and colour-difference coefficients. ## 5. Expressions diff --git a/docs/effects.md b/docs/effects.md index d9f726481..723edd0d0 100644 --- a/docs/effects.md +++ b/docs/effects.md @@ -48,21 +48,21 @@ Effects are addressed by id (`ec..`) or display name in commands | Effect | Id | Params | GPU | 32 | Status | |---|---|---:|:-:|:-:|---| | Bilateral Blur | `ec.blur.bilateral` | 3 | GPU | 32 | Implemented | -| CC Cross Blur | `ec.blur.cccross` | 3 | GPU | 32 | Implemented | -| CC Radial Blur | `ec.blur.ccradial` | 4 | GPU | 32 | Implemented | -| CC Radial Fast Blur | `ec.blur.ccradialfast` | 3 | GPU | 32 | Implemented | -| CC Vector Blur | `ec.blur.ccvector` | 4 | GPU | 32 | Implemented | | Camera Lens Blur | `ec.blur.cameralens` | 16 | GPU | 32 | Implemented | | Camera-Shake Deblur | `ec.blur.camerashakedeblur` | 8 | | 32 | Implemented | | Channel Blur | `ec.blur.channel` | 6 | GPU | 32 | Implemented | | Compound Blur | `ec.blur.compound` | 4 | GPU | 32 | Implemented | +| Cross Blur | `ec.blur.cccross` | 3 | GPU | 32 | Implemented | | Directional Blur | `ec.blur.directional` | 2 | GPU | 32 | Implemented | | Fast Box Blur | `ec.blur.fastbox` | 4 | GPU | 32 | Implemented | +| Fast Radial Blur | `ec.blur.ccradialfast` | 3 | GPU | 32 | Implemented | | Gaussian Blur | `ec.blur.gaussian` | 3 | GPU | 32 | Implemented | | Radial Blur | `ec.blur.radial` | 4 | GPU | 32 | Implemented | | Sharpen | `ec.blur.sharpen` | 1 | GPU | 32 | Implemented | | Smart Blur | `ec.blur.smart` | 3 | GPU | 32 | Implemented | | Unsharp Mask | `ec.blur.unsharp` | 3 | GPU | 32 | Implemented | +| Variable Radial Blur | `ec.blur.ccradial` | 4 | GPU | 32 | Implemented | +| Vector Blur | `ec.blur.ccvector` | 4 | GPU | 32 | Implemented | ## Channel @@ -70,7 +70,6 @@ Effects are addressed by id (`ec..`) or display name in commands |---|---|---:|:-:|:-:|---| | Arithmetic | `ec.channel.arithmetic` | 5 | GPU | 32 | Implemented | | Blend | `ec.channel.blend` | 4 | GPU | 32 | Implemented | -| CC Composite | `ec.channel.cccomposite` | 3 | GPU | 32 | Implemented | | Calculations | `ec.channel.calculations` | 9 | GPU | 32 | Implemented | | Channel Combiner | `ec.channel.combiner` | 6 | GPU | 32 | Implemented | | Compound Arithmetic | `ec.channel.compoundarithmetic` | 6 | GPU | 32 | Implemented | @@ -81,6 +80,7 @@ Effects are addressed by id (`ec..`) or display name in commands | Set Matte | `ec.channel.setmatte` | 6 | GPU | 32 | Implemented | | Shift Channels | `ec.channel.shiftchannels` | 4 | GPU | 32 | Implemented | | Solid Composite | `ec.channel.solidcomposite` | 4 | GPU | 32 | Implemented | +| Source Composite | `ec.channel.cccomposite` | 3 | GPU | 32 | Implemented | ## Color Correction @@ -92,18 +92,18 @@ Effects are addressed by id (`ec..`) or display name in commands | Black & White | `ec.color.blackwhite` | 8 | GPU | 32 | Implemented | | Brightness & Contrast | `ec.color.brightnesscontrast` | 3 | GPU | 32 | Implemented | | Broadcast Colors | `ec.color.broadcast` | 3 | GPU | 32 | Implemented | -| CC Color Neutralizer | `ec.color.cccolorneutralizer` | 11 | GPU | 32 | Implemented | -| CC Color Offset | `ec.color.cccoloroffset` | 4 | GPU | 32 | Implemented | -| CC Kernel | `ec.color.cckernel` | 12 | GPU | 32 | Implemented | -| CC Toner | `ec.color.cctoner` | 7 | GPU | 32 | Implemented | | Change Color | `ec.color.changecolor` | 9 | GPU | 32 | Implemented | | Change to Color | `ec.color.changetocolor` | 9 | GPU | 32 | Implemented | | Channel Mixer | `ec.color.channelmixer` | 13 | GPU | 32 | Implemented | +| Channel Offset | `ec.color.cccoloroffset` | 4 | GPU | 32 | Implemented | | Color Balance | `ec.color.colorbalance` | 10 | GPU | 32 | Implemented | | Color Balance (HLS) | `ec.color.colorbalancehls` | 3 | GPU | 32 | Implemented | +| Color Grading | `ec.color.lumetri` | 66 | GPU | 32 | Implemented | | Color Link | `ec.color.colorlink` | 6 | GPU | 32 | Implemented | +| Color Neutralizer | `ec.color.cccolorneutralizer` | 11 | GPU | 32 | Implemented | | Color Stabilizer | `ec.color.colorstabilizer` | 6 | GPU | 32 | Implemented | | Colorama | `ec.color.colorama` | 20 | GPU | 32 | Implemented | +| Convolution Kernel | `ec.color.cckernel` | 12 | GPU | 32 | Implemented | | Curves | `ec.color.curves` | 0 | GPU | 32 | Implemented | | Equalize | `ec.color.equalize` | 2 | GPU | 32 | Implemented | | Exposure | `ec.color.exposure` | 14 | GPU | 32 | Implemented | @@ -112,7 +112,7 @@ Effects are addressed by id (`ec..`) or display name in commands | Leave Color | `ec.color.leavecolor` | 5 | GPU | 32 | Implemented | | Levels | `ec.color.levels` | 36 | GPU | 32 | Implemented | | Levels (Individual Controls) | `ec.color.levelsic` | 27 | GPU | 32 | Implemented | -| Lumetri Color | `ec.color.lumetri` | 66 | GPU | 32 | Implemented | +| Multi-Tone Tint | `ec.color.cctoner` | 7 | GPU | 32 | Implemented | | OCIO CDL Transform | `ec.color.ociocdl` | 12 | GPU | 32 | Implemented | | OCIO Color Space Transform | `ec.color.ociocolorspace` | 7 | GPU | 32 | Implemented | | OCIO Display Transform | `ec.color.ociodisplay` | 9 | GPU | 32 | Implemented | @@ -133,40 +133,40 @@ Effects are addressed by id (`ec..`) or display name in commands |---|---|---:|:-:|:-:|---| | Bezier Warp | `ec.distort.bezierwarp` | 13 | GPU | 32 | Implemented | | Bulge | `ec.distort.bulge` | 6 | GPU | 32 | Implemented | -| CC Bend It | `ec.distort.ccbendit` | 4 | GPU | 32 | Implemented | -| CC Bender | `ec.distort.ccbender` | 5 | GPU | 32 | Implemented | -| CC Blobbylize | `ec.distort.ccblobbylize` | 15 | GPU | 32 | Implemented | -| CC Flo Motion | `ec.distort.ccflomotion` | 7 | GPU | 32 | Implemented | -| CC Griddler | `ec.distort.ccgriddler` | 5 | GPU | 32 | Implemented | -| CC Lens | `ec.distort.cclens` | 3 | GPU | 32 | Implemented | -| CC Page Turn | `ec.distort.ccpageturn` | 7 | GPU | 32 | Implemented | -| CC Power Pin | `ec.distort.ccpowerpin` | 10 | GPU | 32 | Implemented | -| CC Ripple Pulse | `ec.distort.ccripplepulse` | 5 | GPU | 32 | Implemented | -| CC Slant | `ec.distort.ccslant` | 4 | GPU | 32 | Implemented | -| CC Smear | `ec.distort.ccsmear` | 4 | GPU | 32 | Implemented | -| CC Split | `ec.distort.ccsplit` | 3 | GPU | 32 | Implemented | -| CC Split 2 | `ec.distort.ccsplit2` | 4 | GPU | 32 | Implemented | -| CC Tiler | `ec.distort.cctiler` | 3 | GPU | 32 | Implemented | | Corner Pin | `ec.distort.cornerpin` | 4 | GPU | 32 | Implemented | | Detail-preserving Upscale | `ec.distort.upscale` | 4 | | 32 | Implemented | +| Directional Smear | `ec.distort.ccsmear` | 4 | GPU | 32 | Implemented | | Displacement Map | `ec.distort.displacementmap` | 8 | GPU | 32 | Implemented | +| Dual Lens Warp | `ec.distort.ccflomotion` | 7 | GPU | 32 | Implemented | +| Dual Split Warp | `ec.distort.ccsplit2` | 4 | GPU | 32 | Implemented | +| Flexible Bend | `ec.distort.ccbender` | 5 | GPU | 32 | Implemented | +| Lens Distortion | `ec.distort.cclens` | 3 | GPU | 32 | Implemented | | Liquify | `ec.distort.liquify` | 13 | GPU | 32 | Implemented | | Magnify | `ec.distort.magnify` | 10 | GPU | 32 | Implemented | | Mesh Warp | `ec.distort.meshwarp` | 3 | GPU | 32 | Implemented | | Mirror | `ec.distort.mirror` | 2 | GPU | 32 | Implemented | | Offset | `ec.distort.offset` | 2 | GPU | 32 | Implemented | | Optics Compensation | `ec.distort.opticscompensation` | 6 | GPU | 32 | Implemented | +| Organic Displacement | `ec.distort.ccblobbylize` | 15 | GPU | 32 | Implemented | +| Page Curl | `ec.distort.ccpageturn` | 7 | GPU | 32 | Implemented | +| Perspective Pin | `ec.distort.ccpowerpin` | 10 | GPU | 32 | Implemented | | Polar Coordinates | `ec.distort.polar` | 2 | GPU | 32 | Implemented | +| Pulsed Ripple | `ec.distort.ccripplepulse` | 5 | GPU | 32 | Implemented | | Puppet | `ec.distort.puppet` | 1 | | 32 | Implemented | | Reshape | `ec.distort.reshape` | 6 | GPU | 32 | Implemented | | Ripple | `ec.distort.ripple` | 7 | GPU | 32 | Implemented | | Rolling Shutter Repair | `ec.distort.rollingshutterrepair` | 5 | | 32 | Implemented | +| Scaled Tiles | `ec.distort.cctiler` | 3 | GPU | 32 | Implemented | +| Slant | `ec.distort.ccslant` | 4 | GPU | 32 | Implemented | | Smear | `ec.distort.smear` | 8 | GPU | 32 | Implemented | | Spherize | `ec.distort.spherize` | 2 | GPU | 32 | Implemented | +| Split Warp | `ec.distort.ccsplit` | 3 | GPU | 32 | Implemented | +| Tile Grid | `ec.distort.ccgriddler` | 5 | GPU | 32 | Implemented | | Transform | `ec.distort.transform` | 12 | GPU | 32 | Implemented | | Turbulent Displace | `ec.distort.turbulentdisplace` | 11 | GPU | 32 | Implemented | | Twirl | `ec.distort.twirl` | 3 | GPU | 32 | Implemented | | Twirl (Legacy) | `ec.distort.twirllegacy` | 3 | GPU | 32 | Implemented | +| Two-Point Bend | `ec.distort.ccbendit` | 4 | GPU | 32 | Implemented | | Warp | `ec.distort.warp` | 5 | GPU | 32 | Implemented | | Warp Stabilizer | `ec.distort.warpstabilizer` | 20 | | 32 | Implemented | | Wave Warp | `ec.distort.wavewarp` | 7 | GPU | 32 | Implemented | @@ -194,11 +194,6 @@ Effects are addressed by id (`ec..`) or display name in commands | Audio Spectrum | `ec.generate.audiospectrum` | 23 | GPU | 32 | Implemented | | Audio Waveform | `ec.generate.audiowaveform` | 17 | GPU | 32 | Implemented | | Beam | `ec.generate.beam` | 11 | GPU | 32 | Implemented | -| CC Glue Gun | `ec.generate.ccgluegun` | 7 | GPU | 32 | Implemented | -| CC Light Burst 2.5 | `ec.generate.cclightburst` | 6 | GPU | 32 | Implemented | -| CC Light Rays | `ec.generate.cclightrays` | 8 | GPU | 32 | Implemented | -| CC Light Sweep | `ec.generate.cclightsweep` | 9 | GPU | 32 | Implemented | -| CC Threads | `ec.generate.ccthreads` | 8 | GPU | 32 | Implemented | | Cell Pattern | `ec.generate.cellpattern` | 14 | GPU | 32 | Implemented | | Checkerboard | `ec.generate.checkerboard` | 10 | GPU | 32 | Implemented | | Circle | `ec.generate.circle` | 11 | GPU | 32 | Implemented | @@ -209,11 +204,16 @@ Effects are addressed by id (`ec..`) or display name in commands | Gradient Ramp | `ec.generate.gradientramp` | 7 | GPU | 32 | Implemented | | Grid | `ec.generate.grid` | 12 | GPU | 32 | Implemented | | Lens Flare | `ec.generate.lensflare` | 4 | GPU | 32 | Implemented | +| Light Rays | `ec.generate.cclightrays` | 8 | GPU | 32 | Implemented | +| Light Sweep | `ec.generate.cclightsweep` | 9 | GPU | 32 | Implemented | +| Paint Beads | `ec.generate.ccgluegun` | 7 | GPU | 32 | Implemented | | Paint Bucket | `ec.generate.paintbucket` | 11 | GPU | 32 | Implemented | +| Radial Light Burst | `ec.generate.cclightburst` | 6 | GPU | 32 | Implemented | | Radio Waves | `ec.generate.radiowaves` | 31 | GPU | 32 | Implemented | | Scribble | `ec.generate.scribble` | 25 | GPU | 32 | Implemented | | Stroke | `ec.generate.stroke` | 11 | GPU | 32 | Implemented | | Vegas | `ec.generate.vegas` | 26 | GPU | 32 | Implemented | +| Woven Threads | `ec.generate.ccthreads` | 8 | GPU | 32 | Implemented | | Write-on | `ec.generate.writeon` | 10 | GPU | 32 | Implemented | ## Immersive Video @@ -238,15 +238,15 @@ Effects are addressed by id (`ec..`) or display name in commands | Effect | Id | Params | GPU | 32 | Status | |---|---|---:|:-:|:-:|---| | Advanced Spill Suppressor | `ec.key.advancedspill` | 8 | GPU | 32 | Implemented | -| CC Simple Wire Removal | `ec.key.ccsimplewireremoval` | 7 | GPU | 32 | Implemented | | Color Difference Key | `ec.key.colordifference` | 16 | GPU | 32 | Implemented | | Color Range | `ec.key.colorrange` | 8 | GPU | 32 | Implemented | | Difference Matte | `ec.key.differencematte` | 6 | GPU | 32 | Implemented | | Extract | `ec.key.extract` | 6 | GPU | 32 | Implemented | | Inner/Outer Key | `ec.key.innerouter` | 88 | GPU | 32 | Implemented | | Key Cleaner | `ec.key.keycleaner` | 4 | GPU | 32 | Implemented | -| Key Light | `ec.keying.keylight` | 56 | GPU | 32 | Implemented | +| Line Removal | `ec.key.ccsimplewireremoval` | 7 | GPU | 32 | Implemented | | Linear Color Key | `ec.key.linearcolor` | 6 | GPU | 32 | Implemented | +| Screen Color Key | `ec.keying.keylight` | 56 | GPU | 32 | Implemented | | Screen Key | `ec.key.screen` | 11 | GPU | 32 | Implemented | | Unmult | `ec.key.unmult` | 6 | GPU | 32 | Implemented | @@ -255,12 +255,12 @@ Effects are addressed by id (`ec..`) or display name in commands | Effect | Id | Params | GPU | 32 | Status | |---|---|---:|:-:|:-:|---| | Matte Choker | `ec.matte.mattechoker` | 7 | GPU | 32 | Implemented | -| Mocha shape | `ec.obsolete.mochashape` | 6 | | 32 | Implemented | | Object Matte | `ec.matte.objectmatte` | 13 | | 32 | Implemented | | Refine Hard Matte | `ec.matte.refinehard` | 16 | GPU | 32 | Implemented | | Refine Soft Matte | `ec.matte.refinesoft` | 18 | GPU | 32 | Implemented | | Roto Brush & Refine Edge | `ec.matte.rotobrush` | 25 | | 32 | Implemented | | Simple Choker | `ec.matte.simplechoker` | 2 | GPU | 32 | Implemented | +| Tracked Shape Matte | `ec.obsolete.mochashape` | 6 | | 32 | Implemented | ## Noise & Grain @@ -308,65 +308,65 @@ Effects are addressed by id (`ec..`) or display name in commands | 3D Glasses | `ec.perspective.3dglasses` | 8 | GPU | 32 | Implemented | | Bevel Alpha | `ec.perspective.bevelalpha` | 4 | GPU | 32 | Implemented | | Bevel Edges | `ec.perspective.beveledges` | 4 | GPU | 32 | Implemented | -| CC Cylinder | `ec.perspective.cccylinder` | 15 | GPU | 32 | Implemented | -| CC Environment | `ec.perspective.ccenvironment` | 4 | GPU | 32 | Implemented | -| CC Sphere | `ec.perspective.ccsphere` | 14 | GPU | 32 | Implemented | -| CC Spotlight | `ec.perspective.ccspotlight` | 8 | GPU | 32 | Implemented | +| Cylinder Wrap | `ec.perspective.cccylinder` | 15 | GPU | 32 | Implemented | | Drop Shadow | `ec.perspective.dropshadow` | 6 | GPU | 32 | Implemented | +| Environment Map | `ec.perspective.ccenvironment` | 4 | GPU | 32 | Implemented | | Radial Shadow | `ec.perspective.radialshadow` | 9 | GPU | 32 | Implemented | +| Sphere Wrap | `ec.perspective.ccsphere` | 14 | GPU | 32 | Implemented | +| Surface Spotlight | `ec.perspective.ccspotlight` | 8 | GPU | 32 | Implemented | ## Simulation | Effect | Id | Params | GPU | 32 | Status | |---|---|---:|:-:|:-:|---| -| CC Ball Action | `ec.sim.ccballaction` | 8 | GPU | 32 | Implemented | -| CC Bubbles | `ec.sim.ccbubbles` | 7 | GPU | 32 | Implemented | -| CC Drizzle | `ec.sim.ccdrizzle` | 14 | GPU | 32 | Implemented | -| CC Hair | `ec.sim.cchair` | 20 | GPU | 32 | Implemented | -| CC Mr. Mercury | `ec.sim.ccmrmercury` | 23 | GPU | 32 | Implemented | -| CC Particle Systems II | `ec.sim.ccparticlesystems2` | 21 | GPU | 32 | Implemented | -| CC Particle World | `ec.sim.ccparticleworld` | 36 | GPU | 32 | Implemented | -| CC Pixel Polly | `ec.sim.ccpixelpolly` | 10 | GPU | 32 | Implemented | -| CC Rainfall | `ec.sim.ccrainfall` | 14 | GPU | 32 | Implemented | -| CC Scatterize | `ec.sim.ccscatterize` | 4 | GPU | 32 | Implemented | -| CC Snowfall | `ec.sim.ccsnowfall` | 19 | GPU | 32 | Implemented | -| CC Star Burst | `ec.sim.ccstarburst` | 6 | GPU | 32 | Implemented | +| Ball Grid | `ec.sim.ccballaction` | 8 | GPU | 32 | Implemented | +| Bubbles | `ec.sim.ccbubbles` | 7 | GPU | 32 | Implemented | | Card Dance | `ec.sim.carddance` | 53 | GPU | 32 | Implemented | | Caustics | `ec.sim.caustics` | 28 | GPU | 32 | Implemented | | Foam | `ec.sim.foam` | 36 | GPU | 32 | Implemented | +| Liquid Particles | `ec.sim.ccmrmercury` | 23 | GPU | 32 | Implemented | +| Particle Emitter 2D | `ec.sim.ccparticlesystems2` | 21 | GPU | 32 | Implemented | +| Particle Emitter 3D | `ec.sim.ccparticleworld` | 36 | GPU | 32 | Implemented | | Particle Playground | `ec.sim.particleplayground` | 92 | GPU | 32 | Implemented | +| Pixel Scatter | `ec.sim.ccscatterize` | 4 | GPU | 32 | Implemented | +| Pixel Shatter | `ec.sim.ccpixelpolly` | 10 | GPU | 32 | Implemented | +| Rainfall | `ec.sim.ccrainfall` | 14 | GPU | 32 | Implemented | | Shatter | `ec.sim.shatter` | 60 | GPU | 32 | Implemented | +| Snowfall | `ec.sim.ccsnowfall` | 19 | GPU | 32 | Implemented | +| Starfield | `ec.sim.ccstarburst` | 6 | GPU | 32 | Implemented | +| Surface Fibers | `ec.sim.cchair` | 20 | GPU | 32 | Implemented | +| Water Ripples | `ec.sim.ccdrizzle` | 14 | GPU | 32 | Implemented | | Wave World | `ec.sim.waveworld` | 35 | GPU | 32 | Implemented | ## Stylize | Effect | Id | Params | GPU | 32 | Status | |---|---|---:|:-:|:-:|---| +| Block Reveal | `ec.stylize.ccblockload` | 5 | GPU | 32 | Implemented | | Brush Strokes | `ec.stylize.brushstrokes` | 7 | GPU | 32 | Implemented | -| CC Block Load | `ec.stylize.ccblockload` | 5 | GPU | 32 | Implemented | -| CC Burn Film | `ec.stylize.ccburnfilm` | 3 | GPU | 32 | Implemented | -| CC Glass | `ec.stylize.ccglass` | 17 | GPU | 32 | Implemented | -| CC HexTile | `ec.stylize.cchextile` | 5 | GPU | 32 | Implemented | -| CC Kaleida | `ec.stylize.cckaleida` | 4 | GPU | 32 | Implemented | -| CC Mr. Smoothie | `ec.stylize.ccmrsmoothie` | 7 | GPU | 32 | Implemented | -| CC Plastic | `ec.stylize.ccplastic` | 18 | GPU | 32 | Implemented | -| CC RepeTile | `ec.stylize.ccrepetile` | 5 | GPU | 32 | Implemented | -| CC Threshold | `ec.stylize.ccthreshold` | 4 | GPU | 32 | Implemented | -| CC Threshold RGB | `ec.stylize.ccthresholdrgb` | 7 | GPU | 32 | Implemented | -| CC Vignette | `ec.stylize.ccvignette` | 4 | GPU | 32 | Implemented | | Cartoon | `ec.stylize.cartoon` | 12 | GPU | 32 | Implemented | +| Channel Threshold | `ec.stylize.ccthreshold` | 4 | GPU | 32 | Implemented | | Color Emboss | `ec.stylize.coloremboss` | 4 | GPU | 32 | Implemented | +| Edge Tile Repeat | `ec.stylize.ccrepetile` | 5 | GPU | 32 | Implemented | | Emboss | `ec.stylize.emboss` | 4 | GPU | 32 | Implemented | +| Film Burn | `ec.stylize.ccburnfilm` | 3 | GPU | 32 | Implemented | | Find Edges | `ec.stylize.findedges` | 2 | GPU | 32 | Implemented | +| Glass Relief | `ec.stylize.ccglass` | 17 | GPU | 32 | Implemented | | Glow | `ec.stylize.glow` | 14 | GPU | 32 | Implemented | +| Hexagonal Tiles | `ec.stylize.cchextile` | 5 | GPU | 32 | Implemented | +| Kaleidoscope | `ec.stylize.cckaleida` | 4 | GPU | 32 | Implemented | | Mosaic | `ec.stylize.mosaic` | 3 | GPU | 32 | Implemented | | Motion Tile | `ec.stylize.motiontile` | 8 | GPU | 32 | Implemented | +| Palette Map | `ec.stylize.ccmrsmoothie` | 7 | GPU | 32 | Implemented | +| Plastic Shading | `ec.stylize.ccplastic` | 18 | GPU | 32 | Implemented | | Posterize | `ec.stylize.posterize` | 1 | GPU | 32 | Implemented | +| RGB Threshold | `ec.stylize.ccthresholdrgb` | 7 | GPU | 32 | Implemented | | Roughen Edges | `ec.stylize.roughenedges` | 13 | GPU | 32 | Implemented | | Scatter | `ec.stylize.scatter` | 3 | GPU | 32 | Implemented | | Strobe Light | `ec.stylize.strobe` | 7 | GPU | 32 | Implemented | | Texturize | `ec.stylize.texturize` | 4 | GPU | 32 | Implemented | | Threshold | `ec.stylize.threshold` | 1 | GPU | 32 | Implemented | +| Vignette | `ec.stylize.ccvignette` | 4 | GPU | 32 | Implemented | ## Text @@ -379,11 +379,11 @@ Effects are addressed by id (`ec..`) or display name in commands | Effect | Id | Params | GPU | 32 | Status | |---|---|---:|:-:|:-:|---| -| CC Force Motion Blur | `ec.time.ccforcemotionblur` | 4 | GPU | 32 | Implemented | -| CC Wide Time | `ec.time.ccwidetime` | 3 | GPU | 32 | Implemented | | Echo | `ec.time.echo` | 5 | GPU | 32 | Implemented | | Pixel Motion Blur | `ec.time.pixelmotionblur` | 4 | GPU | 32 | Implemented | | Posterize Time | `ec.time.posterizetime` | 1 | GPU | 32 | Implemented | +| Temporal Blend | `ec.time.ccwidetime` | 3 | GPU | 32 | Implemented | +| Temporal Motion Blur | `ec.time.ccforcemotionblur` | 4 | GPU | 32 | Implemented | | Time Difference | `ec.time.timedifference` | 5 | GPU | 32 | Implemented | | Time Displacement | `ec.time.timedisplacement` | 4 | GPU | 32 | Implemented | | Timewarp | `ec.time.timewarp` | 28 | GPU | 32 | Implemented | @@ -393,29 +393,28 @@ Effects are addressed by id (`ec..`) or display name in commands | Effect | Id | Params | GPU | 32 | Status | |---|---|---:|:-:|:-:|---| | Block Dissolve | `ec.transition.blockdissolve` | 5 | GPU | 32 | Implemented | -| CC Glass Wipe | `ec.transition.ccglasswipe` | 5 | GPU | 32 | Implemented | -| CC Grid Wipe | `ec.transition.ccgridwipe` | 7 | GPU | 32 | Implemented | -| CC Image Wipe | `ec.transition.ccimagewipe` | 7 | GPU | 32 | Implemented | -| CC Jaws | `ec.transition.ccjaws` | 6 | GPU | 32 | Implemented | -| CC Light Wipe | `ec.transition.cclightwipe` | 8 | GPU | 32 | Implemented | -| CC Line Sweep | `ec.transition.cclinesweep` | 5 | GPU | 32 | Implemented | -| CC Radial ScaleWipe | `ec.transition.ccradialscalewipe` | 3 | GPU | 32 | Implemented | -| CC Scale Wipe | `ec.transition.ccscalewipe` | 3 | GPU | 32 | Implemented | -| CC Twister | `ec.transition.cctwister` | 5 | GPU | 32 | Implemented | -| CC WarpoMatic | `ec.transition.ccwarpomatic` | 8 | GPU | 32 | Implemented | | Card Wipe | `ec.transition.cardwipe` | 44 | GPU | 32 | Implemented | +| Glass Wipe | `ec.transition.ccglasswipe` | 5 | GPU | 32 | Implemented | | Gradient Wipe | `ec.transition.gradientwipe` | 5 | GPU | 32 | Implemented | +| Grid Wipe | `ec.transition.ccgridwipe` | 7 | GPU | 32 | Implemented | | Iris Wipe | `ec.transition.iriswipe` | 7 | GPU | 32 | Implemented | +| Light Wipe | `ec.transition.cclightwipe` | 8 | GPU | 32 | Implemented | +| Line Sweep | `ec.transition.cclinesweep` | 5 | GPU | 32 | Implemented | | Linear Wipe | `ec.transition.linearwipe` | 3 | GPU | 32 | Implemented | +| Luminance Image Wipe | `ec.transition.ccimagewipe` | 7 | GPU | 32 | Implemented | +| Radial Scale Wipe | `ec.transition.ccradialscalewipe` | 3 | GPU | 32 | Implemented | | Radial Wipe | `ec.transition.radialwipe` | 5 | GPU | 32 | Implemented | +| Scale Wipe | `ec.transition.ccscalewipe` | 3 | GPU | 32 | Implemented | +| Serrated Wipe | `ec.transition.ccjaws` | 6 | GPU | 32 | Implemented | +| Twist Wipe | `ec.transition.cctwister` | 5 | GPU | 32 | Implemented | | Venetian Blinds | `ec.transition.venetian` | 4 | GPU | 32 | Implemented | +| Warp Dissolve | `ec.transition.ccwarpomatic` | 8 | GPU | 32 | Implemented | ## Utility | Effect | Id | Params | GPU | 32 | Status | |---|---|---:|:-:|:-:|---| | Apply Color LUT | `ec.utility.applylut` | 1 | GPU | 32 | Implemented | -| CC Overbrights | `ec.utility.ccoverbrights` | 2 | GPU | 32 | Implemented | | Cineon Converter | `ec.utility.cineon` | 7 | GPU | 32 | Implemented | | Color Profile Converter | `ec.utility.colorprofileconverter` | 7 | GPU | 32 | Implemented | | Face Measurements | `ec.utility.facemeasurements` | 14 | | 32 | Implemented | @@ -423,4 +422,5 @@ Effects are addressed by id (`ec..`) or display name in commands | Grow Bounds | `ec.utility.growbounds` | 1 | GPU | 32 | Implemented | | HDR Compander | `ec.utility.hdrcompander` | 3 | GPU | 32 | Implemented | | HDR Highlight Compression | `ec.utility.hdrcompression` | 1 | GPU | 32 | Implemented | +| Out-of-Range Display | `ec.utility.ccoverbrights` | 2 | GPU | 32 | Implemented | diff --git a/docs/feature-naming.md b/docs/feature-naming.md new file mode 100644 index 000000000..a69bc713f --- /dev/null +++ b/docs/feature-naming.md @@ -0,0 +1,108 @@ +# Descriptive feature names + +Related to #1365. This is a naming cleanup, not a trademark clearance or a product rename. + +## Naming policy + +Use short, descriptive labels for EffectCraft implementations. Do not reuse a vendor prefix or +coined feature name as our branding. Qualify similar effects by what distinguishes them; each +English display name remains unique across the registry. + +- Renderer: **GPU Acceleration** / **Software Rendering**. +- Panel: **Video Scopes**. +- The table below covers the 69 former CC effects plus color grading, the shape matte and keying. + +## Compatibility contract + +Only presentation names change. Effect IDs, command IDs, parameter IDs, enum values, panel IDs, +serialized types and AEP import/export match names stay unchanged. Old effect display names +remain case-insensitive lookup and search aliases. Existing project instance names, custom names, +expressions, animation and values are not rewritten. The UI displays a current label for an exact +legacy default name, optionally followed by its numeric instance suffix; all other names stay +verbatim. A user-entered name identical to a legacy default cannot be distinguished from it, but +its saved value is still retained. + +External format specifications, comparison documents, attribution records and compatibility +fixtures may still name the external product or effect they actually describe. + +## Display mapping + +| Stable ID | Previous display name | Current display name | +|---|---|---| +| `ec.sim.ccballaction` | CC Ball Action | Ball Grid | +| `ec.distort.ccbendit` | CC Bend It | Two-Point Bend | +| `ec.distort.ccbender` | CC Bender | Flexible Bend | +| `ec.distort.ccblobbylize` | CC Blobbylize | Organic Displacement | +| `ec.stylize.ccblockload` | CC Block Load | Block Reveal | +| `ec.sim.ccbubbles` | CC Bubbles | Bubbles | +| `ec.stylize.ccburnfilm` | CC Burn Film | Film Burn | +| `ec.color.cccolorneutralizer` | CC Color Neutralizer | Color Neutralizer | +| `ec.color.cccoloroffset` | CC Color Offset | Channel Offset | +| `ec.channel.cccomposite` | CC Composite | Source Composite | +| `ec.blur.cccross` | CC Cross Blur | Cross Blur | +| `ec.perspective.cccylinder` | CC Cylinder | Cylinder Wrap | +| `ec.sim.ccdrizzle` | CC Drizzle | Water Ripples | +| `ec.perspective.ccenvironment` | CC Environment | Environment Map | +| `ec.distort.ccflomotion` | CC Flo Motion | Dual Lens Warp | +| `ec.time.ccforcemotionblur` | CC Force Motion Blur | Temporal Motion Blur | +| `ec.stylize.ccglass` | CC Glass | Glass Relief | +| `ec.transition.ccglasswipe` | CC Glass Wipe | Glass Wipe | +| `ec.generate.ccgluegun` | CC Glue Gun | Paint Beads | +| `ec.transition.ccgridwipe` | CC Grid Wipe | Grid Wipe | +| `ec.distort.ccgriddler` | CC Griddler | Tile Grid | +| `ec.sim.cchair` | CC Hair | Surface Fibers | +| `ec.stylize.cchextile` | CC HexTile | Hexagonal Tiles | +| `ec.transition.ccimagewipe` | CC Image Wipe | Luminance Image Wipe | +| `ec.transition.ccjaws` | CC Jaws | Serrated Wipe | +| `ec.stylize.cckaleida` | CC Kaleida | Kaleidoscope | +| `ec.color.cckernel` | CC Kernel | Convolution Kernel | +| `ec.distort.cclens` | CC Lens | Lens Distortion | +| `ec.generate.cclightburst` | CC Light Burst 2.5 | Radial Light Burst | +| `ec.generate.cclightrays` | CC Light Rays | Light Rays | +| `ec.generate.cclightsweep` | CC Light Sweep | Light Sweep | +| `ec.transition.cclightwipe` | CC Light Wipe | Light Wipe | +| `ec.transition.cclinesweep` | CC Line Sweep | Line Sweep | +| `ec.sim.ccmrmercury` | CC Mr. Mercury | Liquid Particles | +| `ec.stylize.ccmrsmoothie` | CC Mr. Smoothie | Palette Map | +| `ec.utility.ccoverbrights` | CC Overbrights | Out-of-Range Display | +| `ec.distort.ccpageturn` | CC Page Turn | Page Curl | +| `ec.sim.ccparticlesystems2` | CC Particle Systems II | Particle Emitter 2D | +| `ec.sim.ccparticleworld` | CC Particle World | Particle Emitter 3D | +| `ec.sim.ccpixelpolly` | CC Pixel Polly | Pixel Shatter | +| `ec.stylize.ccplastic` | CC Plastic | Plastic Shading | +| `ec.distort.ccpowerpin` | CC Power Pin | Perspective Pin | +| `ec.blur.ccradial` | CC Radial Blur | Variable Radial Blur | +| `ec.blur.ccradialfast` | CC Radial Fast Blur | Fast Radial Blur | +| `ec.transition.ccradialscalewipe` | CC Radial ScaleWipe | Radial Scale Wipe | +| `ec.sim.ccrainfall` | CC Rainfall | Rainfall | +| `ec.stylize.ccrepetile` | CC RepeTile | Edge Tile Repeat | +| `ec.distort.ccripplepulse` | CC Ripple Pulse | Pulsed Ripple | +| `ec.transition.ccscalewipe` | CC Scale Wipe | Scale Wipe | +| `ec.sim.ccscatterize` | CC Scatterize | Pixel Scatter | +| `ec.key.ccsimplewireremoval` | CC Simple Wire Removal | Line Removal | +| `ec.distort.ccslant` | CC Slant | Slant | +| `ec.distort.ccsmear` | CC Smear | Directional Smear | +| `ec.sim.ccsnowfall` | CC Snowfall | Snowfall | +| `ec.perspective.ccsphere` | CC Sphere | Sphere Wrap | +| `ec.distort.ccsplit` | CC Split | Split Warp | +| `ec.distort.ccsplit2` | CC Split 2 | Dual Split Warp | +| `ec.perspective.ccspotlight` | CC Spotlight | Surface Spotlight | +| `ec.sim.ccstarburst` | CC Star Burst | Starfield | +| `ec.generate.ccthreads` | CC Threads | Woven Threads | +| `ec.stylize.ccthreshold` | CC Threshold | Channel Threshold | +| `ec.stylize.ccthresholdrgb` | CC Threshold RGB | RGB Threshold | +| `ec.distort.cctiler` | CC Tiler | Scaled Tiles | +| `ec.color.cctoner` | CC Toner | Multi-Tone Tint | +| `ec.transition.cctwister` | CC Twister | Twist Wipe | +| `ec.blur.ccvector` | CC Vector Blur | Vector Blur | +| `ec.stylize.ccvignette` | CC Vignette | Vignette | +| `ec.transition.ccwarpomatic` | CC WarpoMatic | Warp Dissolve | +| `ec.time.ccwidetime` | CC Wide Time | Temporal Blend | +| `ec.color.lumetri` | Lumetri Color | Color Grading | +| `ec.obsolete.mochashape` | Mocha shape | Tracked Shape Matte | +| `ec.keying.keylight` | Key Light | Screen Color Key | + +`Roto Brush & Refine Edge` and `Warp Stabilizer` keep their current names; renaming them is +deferred. + +No effect algorithms or formats are changed. diff --git a/docs/web.md b/docs/web.md index 666ffe37b..f94a687be 100644 --- a/docs/web.md +++ b/docs/web.md @@ -174,7 +174,7 @@ the same futures with `passes::block_on`; they never wait there). - **Render Queue**: `effectcraft_export::export_async` renders each frame in passes (frames with deferred readbacks render one by one instead of in parallel batches) and encodes as before (`Exporter::export_async`). As on the desktop, a job renders every frame on the - project's renderer (the worker's GPU with Mercury GPU Acceleration), not on whichever + project's renderer (the worker's GPU with GPU Acceleration), not on whichever compositor measured faster, so runs don't differ by timing. - **Analyses** (Warp Stabilizer, 3D Camera Tracker, Track Motion, mask and face tracking, Roto Brush freeze and propagation): their work functions are `async`; started with `wait` inside From 7c62272305312b88c25c59a2f24f08d676ee97b5 Mon Sep 17 00:00:00 2001 From: Valentin Klein Date: Mon, 9 Nov 2026 04:52:32 +0100 Subject: [PATCH 39/40] .aep import: placed .ai/PDF footage framed by its ArtBox, Null anchors at the corner (#3099) (#3311) * #3099: placed .ai pages fill the size After Effects stored; null anchors default to the corner Footage of an .aep keeps the size After Effects stored for a placed PDF / Illustrator / EPS file (the ArtBox, rounded up), and masks and anchors are measured against it. The page was drawn as a PDF viewer frames it (CropBox, /Rotate) at its own size, scaled by the width ratio at full resolution and stretched to the stored aspect below 3/4: masks too large, art off centre, squeezed at half resolution. - effectcraft-pdf: Framing::Placed / parse_page_framed (ArtBox clipped to the CropBox, /Rotate ignored); boxes with a non-finite corner or span are not used - Footage::placed_page (set by the .aep importer, serialized only when true): the page is framed so and filled into the stored size (effectcraft_render::vector_fit), decoded, continuously rasterised and in Create Shapes from Vector Layer; Reload keeps the size; the frame cache keys it by size and framing - .aep import/export: a null's absent Anchor Point is [0, 0], as After Effects reads it - fixture ai-mask-3099.aep (own synthetic files, scrubbed, profiles stubbed) and tests against After Effects 2026's read-back * #3099: placed-page framing only for .ai and .pdf, EPS as before; doc comments After Effects' sizing was measured with PDFs named .ai only; an EPS from an .aep keeps its bounding box at its own size (listed as not measured in docs/gaps.md and docs/aep-import.md). Doc comments on the touched functions. * #3099: shapes from a placed page keep its frame (track matte) Create Shapes from Vector Layer converted every path of a placed page, so bleed, art past the artboard or the page's background showed where the footage's raster hides them. The layers it makes from a placed page now take a hidden " Frame" shape layer (the footage's width x height) as their Alpha track matte: drawn at the comp's resolution, its edge is the raster's on shape and image layers alike. The command returns the frame layer's id too. --- ATTRIBUTION.md | 2 +- crates/aep/README.md | 8 +- crates/aep/src/export/plan.rs | 13 +- crates/aep/src/import/build.rs | 29 +- crates/aep/src/import/props.rs | 14 +- crates/aep/tests/fixtures/ai-mask-3099.aep | Bin 0 -> 134446 bytes .../fixtures/ai-mask-3099.aep.attribution | 7 + crates/aep/tests/fixtures/tools/README.md | 1 + .../aep/tests/fixtures/tools/ai-mask-3099.jsx | 94 +++++ .../aep/tests/fixtures/tools/ai-mask-3099.py | 66 ++++ crates/aep/tests/it/export/built.rs | 39 ++ crates/aep/tests/it/import.rs | 1 + crates/aep/tests/it/import/ai_mask.rs | 113 ++++++ crates/engine/src/cmd/create.rs | 29 +- crates/engine/src/footage/footage_reload.rs | 8 +- crates/engine/src/interchange/vector.rs | 64 +++- crates/host/tests/it/vector_import.rs | 356 +++++++++++++++++- crates/media/src/layered.rs | 101 ++++- crates/media/src/pool.rs | 20 +- crates/pdf/README.md | 8 +- crates/pdf/src/lib.rs | 30 +- crates/pdf/src/page.rs | 41 +- crates/pdf/src/tests.rs | 80 ++++ crates/project/src/footage.rs | 8 + crates/render/src/footage.rs | 31 +- crates/render/src/lib.rs | 2 +- docs/aep-import.md | 10 +- docs/gaps.md | 6 + 28 files changed, 1132 insertions(+), 49 deletions(-) create mode 100644 crates/aep/tests/fixtures/ai-mask-3099.aep create mode 100644 crates/aep/tests/fixtures/ai-mask-3099.aep.attribution create mode 100644 crates/aep/tests/fixtures/tools/ai-mask-3099.jsx create mode 100644 crates/aep/tests/fixtures/tools/ai-mask-3099.py create mode 100644 crates/aep/tests/it/import/ai_mask.rs diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index 93b34b9bf..4bf3a044d 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -64,7 +64,7 @@ and licence texts are in [`NOTICE`](NOTICE). | `crates/model/tests/fixtures/cube.obj` | EffectCraft contributors | Original work: Wavefront OBJ test fixture (unit cube, two materials) | MIT OR Apache-2.0 | | `crates/model/tests/fixtures/cube.mtl` | EffectCraft contributors | Original work: MTL test fixture (materials of cube.obj) | MIT OR Apache-2.0 | -One small After Effects test project of `crates/aep` is in this repository: `crates/aep/tests/fixtures/synthetic.aep` (original work, made with After Effects 2026 from own data, working space None, the embedded colour profile removed; MIT OR Apache-2.0, with its `.attribution` sidecar). The other After Effects test projects of `crates/aep` are not in this repository. They are original work of an EffectCraft contributor, generated with After Effects 2026 as own test data (MIT OR Apache-2.0, each file with its `.attribution` sidecar); they are in [storytold/effectcraft-corpus](https://github.com/storytold/effectcraft-corpus) with their sidecars, fetched by `cargo xtask aep-corpus` (commit-pinned, SHA-256-verified), and the tests read them only from the folder named by `EFFECTCRAFT_AEP_FIXTURES` (opt-in). Their embedded colour profiles are replaced by stubs made with `crates/aep/examples/stubicc.rs` (a header and a description, no colour data), so no vendor profile data is in them. +Two small After Effects test projects of `crates/aep` are in this repository: `crates/aep/tests/fixtures/synthetic.aep` (original work, made with After Effects 2026 from own data, working space None, the embedded colour profile removed; MIT OR Apache-2.0, with its `.attribution` sidecar) and `crates/aep/tests/fixtures/ai-mask-3099.aep` (original work, made with After Effects 2026 from four hand-written one-page PDFs named `.ai`, footage paths and host name neutralised, the embedded colour profiles replaced by stubs made with `crates/aep/examples/stubicc.rs`; MIT OR Apache-2.0, with its `.attribution` sidecar). The other After Effects test projects of `crates/aep` are not in this repository. They are original work of an EffectCraft contributor, generated with After Effects 2026 as own test data (MIT OR Apache-2.0, each file with its `.attribution` sidecar); they are in [storytold/effectcraft-corpus](https://github.com/storytold/effectcraft-corpus) with their sidecars, fetched by `cargo xtask aep-corpus` (commit-pinned, SHA-256-verified), and the tests read them only from the folder named by `EFFECTCRAFT_AEP_FIXTURES` (opt-in). Their embedded colour profiles are replaced by stubs made with `crates/aep/examples/stubicc.rs` (a header and a description, no colour data), so no vendor profile data is in them. ## Screenshots diff --git a/crates/aep/README.md b/crates/aep/README.md index 965bea317..5e8035d8f 100644 --- a/crates/aep/README.md +++ b/crates/aep/README.md @@ -69,13 +69,19 @@ tests reach them only through `tests/it/common/mod.rs`, which hands a test its c of its own cut from the combined file; a test whose fixture is missing (or with the variable not set) prints `SKIPPED: fixture missing` and passes. -`tests/fixtures/synthetic.aep` (115 KB) is the one project in the repository: made in After Effects 2026 +`tests/fixtures/synthetic.aep` (115 KB) is one of the two projects in the repository: made in After Effects 2026 with the working space set to None (one composition, an image sequence of three 8x8 PNGs, a solid, a folder, a Levels and a Glow effect with expressions). Every After Effects project embeds the working space's ICC profile (HP sRGB IEC61966-2.1 for the default) in a JSON settings chunk; the one `Utf8` chunk of this file that held a profile was replaced by `{}`, and nothing else was changed. The tests in `tests/it/import/synthetic.rs` damage copies of it and need no other file. +`tests/fixtures/ai-mask-3099.aep` (131 KB, #3099) is the second: four hand-written one-page PDFs +named `.ai` with distinct page boxes, placed in a composition, one of them with two masks under a +Null parented to a Null (generated by `tests/fixtures/tools/ai-mask-3099.py` and +`ai-mask-3099.jsx`, scrubbed with `scrub.py` and `stubicc`). `tests/it/import/ai_mask.rs` checks +the import against After Effects' read-back, and the host's `vector_import` tests render it. + ## Tools - `tests/fixtures/tools/`: the generator of the test projects (regenerates the corpus with After diff --git a/crates/aep/src/export/plan.rs b/crates/aep/src/export/plan.rs index f8aa2b3b8..a6789eda9 100644 --- a/crates/aep/src/export/plan.rs +++ b/crates/aep/src/export/plan.rs @@ -817,7 +817,7 @@ fn plan_transform(layer: &Layer, src: &LayerSrc, comp: &Comp, source_size: (u32, let cam_light = matches!(src, LayerSrc::Camera(_) | LayerSrc::Light(_)); let is_shape = matches!(src, LayerSrc::Shape(_)); let mut props = Vec::new(); - let at = PropAt { comp, comp_name, layer: &layer.name, source: source_size, text: is_text || cam_light || is_shape }; + let at = PropAt { comp, comp_name, layer: &layer.name, source: source_size, text: is_text || cam_light || is_shape, null: matches!(src, LayerSrc::Null) }; if let Some(tr) = layer.transform() { for kind in PropKind::ALL { // A camera's or light's point of interest is After Effects' Anchor Point. @@ -1172,16 +1172,21 @@ struct PropAt<'a> { source: (u32, u32), /// The anchor is stored in pixels (text, camera, light and shape layers). text: bool, + /// A null layer: an Anchor Point that is not written is its top-left corner (#3099). + null: bool, } +/// What is written for transform property `p` (`kind`) of a layer: its value or keys in the +/// stored unit and its expression; `None` when it is at After Effects' default and has neither. fn plan_prop(kind: PropKind, label: Option<&str>, p: &Property, at: PropAt<'_>, cp: &CompPlan, col: &mut Collector) -> Option { - let PropAt { comp, comp_name, layer, source, text } = at; + let PropAt { comp, comp_name, layer, source, text, null } = at; // A text layer's anchor is stored in pixels, with the origin as its default (385). let (sw, sh) = if text { (1.0, 1.0) } else { (f64::from(source.0.max(1)), f64::from(source.1.max(1))) }; let what = format!("{comp_name}: '{layer}' {}", label.unwrap_or(kind.match_name())); let dims = kind.dims(); let default: Vec = match kind { - PropKind::Anchor if text => vec![0.0, 0.0, 0.0], + // After Effects 2026 reads a null's absent Anchor Point as `[0, 0]` (#3099). + PropKind::Anchor if text || null => vec![0.0, 0.0, 0.0], PropKind::Anchor => vec![0.5, 0.5, 0.0], PropKind::Position => vec![f64::from(comp.width) / 2.0, f64::from(comp.height) / 2.0, 0.0], PropKind::Scale => vec![1.0, 1.0, 1.0], @@ -1319,7 +1324,7 @@ fn plan_prop(kind: PropKind, label: Option<&str>, p: &Property, at: PropAt<'_>, /// back disabled). fn plan_remap(p: &Property, comp: &Comp, cp: &CompPlan, layer: &str, comp_name: &str, col: &mut Collector) -> PropPlan { // Rotation has the same layout (one component, stored as is, not spatial). - let at = PropAt { comp, comp_name, layer, source: (1, 1), text: false }; + let at = PropAt { comp, comp_name, layer, source: (1, 1), text: false, null: false }; let planned = plan_prop(PropKind::Rotation, Some("Time Remap"), p, at, cp, col); col.exported.time_remaps += 1; let mut plan = planned.unwrap_or_else(|| PropPlan { kind: PropKind::Rotation, value: vec![0.0], keys: Vec::new(), expr: None }); diff --git a/crates/aep/src/import/build.rs b/crates/aep/src/import/build.rs index 5a55c557a..7d5b902f1 100644 --- a/crates/aep/src/import/build.rs +++ b/crates/aep/src/import/build.rs @@ -285,6 +285,8 @@ fn import_footage(project: &mut Project, cx: &mut Ctx<'_>, item: &AepItem<'_, '_ cx.col.missing_footage.push(shown); } let kind = if sequence.is_empty() { footage_kind(&path, f.native_frame_rate, f.audio_sample_rate.is_some()) } else { FootageKind::Sequence }; + // A placed PDF / Illustrator file keeps After Effects' framing and size (#3099). + let placed_page = kind == FootageKind::Still && is_placed_page_path(&path); let mut footage = Footage { path, kind, @@ -295,6 +297,7 @@ fn import_footage(project: &mut Project, cx: &mut Ctx<'_>, item: &AepItem<'_, '_ // footage), and only then. has_audio: kind == FootageKind::Audio || (kind == FootageKind::Video && f.audio_sample_rate.is_some()), missing: !present, + placed_page, sequence, ..Footage::default() }; @@ -327,6 +330,14 @@ fn import_footage(project: &mut Project, cx: &mut Ctx<'_>, item: &AepItem<'_, '_ } } +/// Whether `path` names a file whose page is framed as After Effects places it +/// ([`Footage::placed_page`]): an Illustrator or PDF file, by its extension. EPS files keep +/// their bounding box at their own size: how After Effects sizes them was not measured (#3099). +fn is_placed_page_path(path: &str) -> bool { + let ext = path.rsplit(['/', '\\']).next().and_then(|name| name.rsplit_once('.')).map(|(_, ext)| ext.to_ascii_lowercase()); + matches!(ext.as_deref(), Some("pdf" | "ai")) +} + /// The name After Effects shows for a footage item that stores none: the file's name, or for a /// sequence the name with the frame range (`shot_[0101-0103].exr`). fn default_footage_name(item: &AepItem<'_, '_>, f: &crate::Footage) -> Option { @@ -453,11 +464,13 @@ fn camera_light_orient(auto_oriented: bool, light: Option) -> AutoOri } /// The unit a layer's anchor is stored in. -fn anchor_unit(camera_or_light: bool, text_or_shape: bool, size: (u32, u32)) -> AnchorUnit { +fn anchor_unit(camera_or_light: bool, text_or_shape: bool, null: bool, size: (u32, u32)) -> AnchorUnit { if camera_or_light { AnchorUnit::PointOfInterest } else if text_or_shape { AnchorUnit::Pixels + } else if null { + AnchorUnit::Null(size.0, size.1) } else { AnchorUnit::Source(size.0, size.1) } @@ -582,7 +595,7 @@ fn build_layers(project: &mut Project, cx: &mut Ctx<'_>, defs: &EffectDefinition import_layer_styles(&layer, &mut l, &comp.global_light, &mut Ids(&mut project.next_id), &tm, &what, &mut cx.col); // Text and shape layers store their anchor in pixels (385, 462); cameras and lights their // point of interest. - let anchor = anchor_unit(is_camera || light.is_some(), is_text || is_shape, size); + let anchor = anchor_unit(is_camera || light.is_some(), is_text || is_shape, is_null, size); if let Some(tr) = l.props.sub_mut("transform") { import_transform(&layer, &name, comp_size, anchor, &tm, tr, &mut cx.col); } @@ -906,6 +919,18 @@ fn resolve_parents( mod tests { use super::*; + /// #3099: an `.ai` or `.pdf` from an `.aep` is a placed page; an EPS (not measured in After + /// Effects) and other files are not. + #[test] + fn only_illustrator_and_pdf_files_are_placed_pages() { + for path in [r"C:\fixture\x\logo.ai", "/work/Logo.AI", "art.pdf", r"C:\a.b\page.PDF"] { + assert!(is_placed_page_path(path), "{path}"); + } + for path in [r"C:\fixture\x\still.eps", "a.epsf", "a.epsi", "still.png", r"C:\dir.ai\file", "ai", ""] { + assert!(!is_placed_page_path(path), "{path}"); + } + } + #[test] fn unlisted_extensions_follow_what_the_file_stores() { assert_eq!(footage_kind("C:/clips/a.MP4", 0, false), FootageKind::Video); diff --git a/crates/aep/src/import/props.rs b/crates/aep/src/import/props.rs index 838a2ee44..fd0a4f9fc 100644 --- a/crates/aep/src/import/props.rs +++ b/crates/aep/src/import/props.rs @@ -136,8 +136,12 @@ const IGNORED: [&str; 4] = ["ADBE Position_0", "ADBE Position_1", "ADBE Position /// How the stored Anchor Point becomes pixels. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(crate) enum AnchorUnit { - /// A fraction of a source this big (pixels): AV layers. + /// A fraction of a source this big (pixels): AV layers; the source's centre when absent. Source(u32, u32), + /// A fraction of a null object's source this big (pixels); its top-left corner when absent: + /// After Effects 2026 reads a null's absent Anchor Point as `[0, 0]` (#3099: two nulls made + /// with `addNull`, one left at its default, read back `[0, 0, 0]` and `[10, 20, 0]`). + Null(u32, u32), /// Pixels as stored, the origin when absent: text (385) and shape (462) layers, which have no /// source. Pixels, @@ -169,6 +173,14 @@ pub(crate) fn import_transform( let (sw, sh) = (f64::from(w), f64::from(h)); (Kind::Anchor(sw, sh), tr.anchor_px(sw, sh)) } + AnchorUnit::Null(w, h) => { + let (sw, sh) = (f64::from(w), f64::from(h)); + let px = match tr.anchor_fraction.source { + ValueSource::Default | ValueSource::Unreadable => [0.0; 3], + ValueSource::Stored | ValueSource::Keyframed => tr.anchor_px(sw, sh), + }; + (Kind::Anchor(sw, sh), px) + } AnchorUnit::Pixels | AnchorUnit::PointOfInterest => (Kind::Anchor(1.0, 1.0), tr.text_anchor_px()), }; let poi = anchor == AnchorUnit::PointOfInterest; diff --git a/crates/aep/tests/fixtures/ai-mask-3099.aep b/crates/aep/tests/fixtures/ai-mask-3099.aep new file mode 100644 index 0000000000000000000000000000000000000000..7223fda82f8a520db8d01325cd5bde56de1ae26e GIT binary patch literal 134446 zcmeHw3y>toS!VU@>_aPQwU*anEre+19NZez^XS=K%}ng>%6m??VrN@YxkhH{tx4rfY{u{3VD$csKm&-ik%8mElLi{!&TP9zWXCqiO%|%YX9L zJIj#vt>l8|t&n^t$T4~~z+?jF;p4RN3F_Ib-22;G-Mb<`bmD@ zI1JQYBDu9=NfgI7fxg^{6t`KS*?WM&kh_{nz2r3QH148hZ);j~Zq`h#c}6evMLDOxYivn|Hi=;COJI-ak2gex^JV z8Y`3>A+=4Ia`iBDjPmewn~aUirFvlM5PblCr0z5@IvaTXioO}RtPNg)3&)}3lECu` zjNvFSFTHdSu73;7)%c^WceUC`P@J*S*~Pdnsl1P*;!>2;RnOHbdxQQTiOl7CWQI$S ztrvbJI49^H;yJa*tdaN$iu9sWv&!>UO|RD-j|@7^ft9O$BQlr5M7jHTxkq@p2P(G) zZw*u+*GVYj1E2dCU`F1kL}=91#veWX#lL-QsxtmH_5{@tt{%FNW$F0efKCNBi?O(E zIgz`#B-Z~po(|NU>P+Cij44YJxpMXOmA)_8kd8vpdi zNci~pAF^X+<{XI<1<(1RLuQy3_iYbiTcqHQ5SzHnUhB@e7O$7%QYK=z29HHS{d$gFZ`$^4Dp<43nQ{fKgW z%DmF}IPU{&R{2JA{o)i}_Gddl>+aHS0iGzqm2gC!jo-id=s^QpAX8seG*%Muw{Nsh=ps7;^X;-iGv zq+wX~)>PEJG}MtCB@nqnXeql}-D8Nb5vDxlyFOVw%nA&V(!+)IF}*}@rS%kEqatPi z>5!3>&eDi;S^K#O|BXiC4xGuojp{4Hgu;S|$I?^pG1{7}EfH=Rh|98V#~|kt91!7% zbm53CM%?rprQ<5SvbbNOp=rmqS3~P|VsgT-OpVxL63W3xO4Spu=dY~`Nb?<9yRsh!b z*-PIXo1@p(E>@@N!4zOdm-crNGrl@+DKt=|6?d^V3;t?gv|jdLwJF`~K#$Gel|5t9 zB@0%dHy4CTk4tX21}CHyN^tJ*bAiEc6xKU&+vtKe9;JqjGObnze|(&v^t7cuo`dc= zg&eqG3tW^UaIU5tfT@>BLzBSM_CJvx@bwye3Q|Vp3<6-wDS_4G-IG8J;0WQ$opEr$!CPLl~;SN1!`>2 zw?K^z`WC3MLEi$vrb!!>mR78FGceG7^rhQ0-zA%?yMnY#mLa+1kRL6%6GI|D6;z3q+-hvll3R@pT5_wg zK}&8mHXYgK;x6$Lpj@wz_8-h?<;gTI-5FwN$&HrWWcTG0`E?GsOFZDk z1J@&?CAZMIpe45;4SGaNZUTd(OUhw&z2O@UE+x)_cUwkq2EreBMJLqwB#0`H62yjH<3~5b+dYSyF91E zr{Lw!ScuGUWG%7(mlQ40YVRys`efu2UP=*aw;l2+qCtL{?ATs-{w_bvUZU#oAKZ(=?mj8 zv6QSMNlX7o?yS756ixGMkw?y@md-JsNclUX)t)R`6%F?C&j77{;y?aDZd$E2*9d8~ zL962*Jiau3{rdIs&%p21SAUVi|@R_>>qi{2EAuM*sw80mztVkZ273bPh^Hf?rW056E?*Ks1p5kn!y)69Q}3F z*r30T8XNT2QDcMtI)F{9u^Yd<004;*xFc%8FE2EAzcwjbk_ymYhf*y1>!81m+|5L< z5-VQv)#jKq>M;qSJmtH7(43W~FbSdbaAYopAQdb@B3YSIdL72=biH)%vL5(8M{=F+ zYwR(iw&^2WEoCT^Gm=<2S^pf7=O+9&vMz61nuO#e`s<`-RP@&YN>gd#(O*Z^4GSTL z{yIfzYytgs3ie9$*C|S4=&w^0G4$6diWvIq6h#dEbvi=~{dLe^2mN)R@30_Az0-Q6 zm+3;FxZHHiUSaH2>JK_wVPt#y=$lqhzP4rsfn!=>Q&k{=*XHQ8wTsoMdO&tiC)x~= zo?Zvtxmqq*QDy~6Wp=YR3;t?gSmkT=$nm`}vn{y>D81i!9&ETJ0(-`!8(D#;N3wl5 z`sm328~IcfRXH^$*he ze-Xbc{yOjdKl-^Bzo?Hd2A>{3=lmgoo{zKWuOqq)KW6xr^<>eiAm5k&4bbYRMn-be z>R$5K*@Lt??!0D=FZ|dy$3Ok%()cGPf9js4)f~K%G|HpD4(Y+7Tc&z-c9hS$m$I)G zPnFsu_C67As?Fu`F*yB2BBlHhuRxdRdzK2XKp(oVxe|p^c9c(v5kr5Sq<;?j>u5@e zg7={J_|ff6KQeV7W@TQfck-{v+-O1lyzEZ*_3nz^nb1k$_jQ04BpN|~oirjvc@p&3 z8373K`#R{aBh52nlyQhJ6ReQ0xAbI+W%aZUf17=o&|gPtBpMMdh5kBfY|vjvjZH@$ z82Ei13D7O_;Z(Vt*iWgwopvu>IF;&9EFz@jSm)d3b}`CyL@nsA(+1t<%c6anuVkl4 z?SuY00Fr9`DbxB}d`*UNftkhuTkGSX2ZJu#MSWZ#g5TE>d%dE+PWI4~D^(hw&|im+ zPYKNy`s)-OvGMylMG-@Pox+HrzfM6u3jKA8(ir;d6h#dEb&4W}{yIewLw}vl5JP_* z^w&Xu9q2nONK!BQ>&!40m-38f3WS=E5@vjL9{qI~PUx>gaF8e@hrI{a+@iluE`OaP zZ%#w6bIpiYs=Wfg0|avj+-|jp8>B%OE`1%6NmriEwrTB!E0(RVx@1bo6|%~aTrYTr z(!{g>^1uVf2bV~x{F^8T#j{v@KlrZ|-%wF}V<*tP(Ds8`rW+ouJS+FUzgLvoYR|t( z&sgz;@|^E@Dl9marY&vTf0JdO_K>#kEeHkI7n&?>_w5sH+_tS~GYH${iI1@S6ED5d z_QqBjq<$S++M;c8PD|SuF|dzD28Z6-A4Cvf5*z?mAKVyt^8duUKoAEAo;fpO^Xy&r3aoE8Y(NI$4`M z=bXQu6Ma}5^W57ik3ja$-%QYK5U1Z;nuz0x(Y0vL$dRAZF3RKiq){`oVcw4^*P_6yFE$M>^mvDSX@l42a(sxMwF4hSD>PWzsl>(lbS*z_&e6 zdQQ_&4xV44Ih3Araukhh#r=V@DO!}6)gCB43v^l?QF<1-6s>n=J&f!%a}Dr`W2KmNdj_m4q0|&S@G#*_qCjMYub9LxH~?oq4$~17+tt4T7?BSIf>~ zYu=7z=S8X-$U`MG&sJpTedJjvJEQCjl+DOUX{w_{Lnu2_m;`p|BV24+ z8ByV?N=MmQg^VhlBZgMnKz+=iD3*CATqlg&6>}J{JE^^X|5p4!k;Qe3}t7OowXB!M%o=Exd&xufJ@cuaNSu&OA-yC>`Y-w%giDU z7g2WJ@{U3(N>rtz>}*=gZ0D_eS$0l)Jm1ghr6bvS-dSELV6?pz*?B*E7D~@3Jp;w= zW$F1hFVQX~q-WK5+%8?>C}PP5SDtf9HZfwj@>~=#l%8`UhAYo7h)LrVO3xG#TzSTo zXYF3y#}ci!+p%_u>q66p`-OFd$8%bGetzcM3f3->jM8&#|J?<4+eaUpl6TvFkT+#V((}}62-0);X~$YGtGU#eSlUU?V$-s$ z-L@Z;pT(r;BY&jW9eazrZr^`GQErpemau%pZ(zj@tv-=>Eg|8kvvV(ZtqZ>zcIV@- zzWVCV58b%)vp;kF`oi%~-g)IS^w{EMGcRQ#b_=EGoDzM zXa&#>RscGv_oPwU{G9K+?yMvf|L|636dsXv;dW`lYTR4Z{E5(hd#}G)Uj;O~-Bcq}r z+zTL$l!!|-gnI!{Skip8h{MGu{#xLe_qd}oIeIhXZ3f6E#tPJ9bfq5SA>Pzm)?<)O z2-}2h(_;*y9^*0eY5;0$vX9wAyU~C0I2!j8`6v2_93W8}0hh!I0QMoz>~ zkI|-wcXCFV{!9wEhEG^fZ`d-SXC{QAv{4(@5FY5#m>!7{G6Y;Q;6Hhz?U;h=>c zL;DcHG!;sO$D7rI+g1>!E=kek_Y<=87_^PV9a$N8n;sO;V(s~zk10Gqw&+oE@VgY{ zHc8A0tJawFM{EC_oPUfMN|!kiyB0W>7wM7Xd!o0bkE~~udi*Gi_^1bdS4&}JhD(r_ z^t3!H<_96)0S*35ZT!*GU;NuV8ncpiJY5@zXLaX{Y%GauGqTE|8TcE$$B%Ar`jM$a zqB5^Ehj5$o8_Flgeu1Cu04?&4rMK?ZY~IjRdjFS(YPMuo){weNwMfy^eYc$)&X zaXiloa#Uw`YU8g)R&dd62aT#_cLJL|Q=27g&2ndIOMV!(B%Ix8DPtw@Yu1GuEvusL zgWKFvq3=581;=&URA+avSq^lQFn;YSv^%w_>k)J+uU%z!sZZH~o`-C9sWz04C@@+w zzGEW_La*h-##*+tlA3vP&6=c}m#3Y;GE{N{r<+bWUn<=fkP|=(kp%wi>8fR_SoIWI z#g>`jqQs>XZJ${k=-tuX7A?dOJT}om`%LL!6qebHsbHG6);=JY0Ni({ecH8)xGuHN z74ngc@?xNSVa*A{EMb=;lHO@T*&kxd2KEuqu8`FVc*9N_hE;D(Mcqq79rba62&JX$ zZgr0#!bX_#l<)e1=ys_iL!|U@VGT$x(G+Ptg*70h4CPQpQmUGXD4z$OoABRAq;CJI zG(Jt%>y{pbWydSeTei#QRhh=_G1{7}EfM|{h|98V#~|nFHsFYK;fO8PyVGx!ju%=l zpLT3}HMHKQh+R%&lN~RF*h1YhR$V=40a+K**p48!;&_f{g`paGVQ0MrG%^9$22Ssela;lX!ZDSb5%eUEj9T;L|uFCLwm&Gp&uXZxb0P&@*+5 zTSM$E2nF?4+h$RiU+2KIG$KFrQo8Tm1g9Vgv7&m%$yL+wv)4HVfpUb?E0Rh**cMhK z`P!}($&#+92|4a!ZE|4AYlAj{j&4BXfL_IR>f{Xc^|oWXa7NYe9H);@UA}OQpZ8DI z7phYsv!5gi8E$`f=(-m<5v(xt_lUKhzum++LX~`y-8|V-SagZ-qSVQ3%%jkg_)Uhy}m%K4h~H$-Jt|vubFFbLMU>d z?f7*#5{ixJa6{?T_8WBEI8#&f!OvfgteOKBzocA3#g0jH$28_J3)n@fy@czDK(eb1 zIpd7`?Xj9{XQ#++^oH++4sI^)ycH+n=ka~p#fGr zhQI1Xx0dwK>Khw+LQ0JEVA+cL#;Q;B*{iM#tIaEYV|`O&H*ea`Mzk7OH*ap-yy*-N zj*eFJ%96ifh5fqI_e5Xa)g#*vYP7`A3f8RPmIsT&aQCHa3yXt;gOG`*uleq3%@UWN zrZKq6o_)&+Z`rb=XngQCWFRub^X-7Z*g#&;5Lm&E{qo4lh_&a~{AFlodn@4)4 zr>@K|SaruFd1%*5{OLUX+r~fJ|GB4r_!po1xihyu@Z$IXXV>xQ{7yQkRa>H?X-RYH z>!cR~APor*Nf%?-*#N+NiXynWc`T8r}apO-Zcqffc#BPPJJ)@ zEj@E;&~Tr+^u5mcXPntx zR1#pdoQ(H9Hw3Nl((WoRu><_VXOsK_={W`X1(JO``Gr@D@C&61JiV*Yg{2BnRqQyspyU>ynMj}`|AxKHVw%SKmx!@r10OjZWA`8eKr57H;ME1U z@Zit=hu{B)M=yQwBR_cK9XG!I(0?B^&xP>R+ z=|q}juX`R~8-?Z_=4w?H&Hs9R|2L6ET1x`keN zMgeYtWWQ_Ng7&BI^bPny5L|*dLegI37CxGbTi9;hf?0_Ir?%tlf>O6|0$PKp^S%K; zQVuw);Q&IYz(Q&*oWOXRXorZ@s!+ z(oBP{=)($ZJy>1>XyL5=io1p@x7;GJsHK-Y3VjOzUSJd=*>M!g=>LM=)0a9Pg+L#5 zuLdy+z4a4cDL?#)@AR`t}M#xg=%j-G?#l=Bi!EhhXdN|_7@5z9?UZ*bnxUOWJPBO!b94^4wOoE z2Hu%+5A9I7@7SSoAKsyI-?>BOKDa~u;sI@9N9gQ6s)O48qVM0K{&sAKaM*qXu*3uc ze2#td%DfrOuh5+`kAd_aD?>{C`~MQMm*!#PNI23Nn)7HAt`kP?ia8AFC$-n_|7xOG znC}k#KDjUPOI&8Byqw-Em!q0A*U$60zUdC0uv2sW0c~3K$O7rjbN#_>nd_U&J*2(6 zK)qC1o6GGjT~uW*kltMGeX)M2Kru~Oo69|{{XkQ$;t9>=-oHcTKB&E~c=ej@Xs+)A z+SR69#S@y#EnWuRfe0W1dkg_S-%igh&d=D3mWyd_*_spr;!P)whwc=cQKCl*^zq)8Vf7=)}`^L{5KC>~lQLEQrQ=#%k&Go{u zjkA5QPxq2F2InMsps!4`M7PiOO_B@c8?$q;VMkzhI3k%342dh%z`PautASz7tU>h~u)tfNF^w_eXsSo&^m^TO4EjNi zfi=(MwbyOfFcx;ggPj4x{(9iQA5P8;H12AkcLv^mY$~wy$PX5M-#y2uV3HJ2o?#`B zCO=(1@r>ia7VqJE&kUsR$tunQ-#qIaxwA4fSQ#2#96B{teR8aN^1BDCV}pZ56{JtX4*chKEOntGYQnI4p`z+}>0)e5?hA3f)cQA+<01 zh>T*I9(4&s6F=Cb{Xg!ObRbx;zE4gi^h(CAjn*@axq4%?Wg5cv3ATEjAL;KAb z+vnw+K`7QT&kRVZjcUbr^4px|2F!;tD?f3&`Wfphme-2lSy42Xx{%O^nF97rnp_5& z$kiEHvGRTC^3Mz~#CM=2LVay(?U1h{ZLJ-oA>%H#LxYZu72R95%yR>V??uqmf|5mg zz7}NdDt9q4GNigB%bJ)@*<4Kt114+W6$WBvp@~f5?zEjJ=~vv&vg5MwAu$wrP7tm< uD8+dYt{93uCkR&_l;S)HR}4j-6ND=dN^zc6a2;-_8(^=bvwiEJO!)sG$5C|v literal 0 HcmV?d00001 diff --git a/crates/aep/tests/fixtures/ai-mask-3099.aep.attribution b/crates/aep/tests/fixtures/ai-mask-3099.aep.attribution new file mode 100644 index 000000000..86efa3b65 --- /dev/null +++ b/crates/aep/tests/fixtures/ai-mask-3099.aep.attribution @@ -0,0 +1,7 @@ +asset: ai-mask-3099.aep +title: Small After Effects test project: placed .ai files with masks under two parented Nulls (#3099) +author: EffectCraft contributors +source: original work (made in After Effects 2026 from own data: four hand-written one-page PDFs named .ai, generated by tools/ai-mask-3099.py, imported and laid out by tools/ai-mask-3099.jsx) +license: MIT OR Apache-2.0 +added: 2026-11-08 by EffectCraft contributors +notes: Scrubbed with tools/scrub.py (footage paths C:\fixture\x\.ai of the same length, host name HOST000, the XMP packet of an empty project of the contributor); its four embedded colour profiles replaced by stubs (description only, no colour data) with crates/aep/examples/stubicc.rs, then checked with the corpus repository's tools/aep/inspect-embedded.py (CLEAN). No Adobe asset is in it. diff --git a/crates/aep/tests/fixtures/tools/README.md b/crates/aep/tests/fixtures/tools/README.md index eee0174ee..f1c720b2e 100644 --- a/crates/aep/tests/fixtures/tools/README.md +++ b/crates/aep/tests/fixtures/tools/README.md @@ -29,6 +29,7 @@ single-case files some cases are merged from, and the contributor's own animatio | `scrub.py` | fixture hygiene of a saved `.aep`: footage alias paths replaced by neutral ones of the same length (`C:\fixtures\...`), host name `HOST000...`, neutral ascend counts, the XMP packet replaced by the base project's | | `layers-comps-scrub-aepx.py` | the same XMP swap for the `.aepx` of the pair | | `patch-text.py` | the byte edits of the text cases 732 and 733 (see below) | +| `ai-mask-3099.py`, `ai-mask-3099.jsx` | the committed `../ai-mask-3099.aep` (#3099): the `.py` writes four one-page PDFs named `.ai` with distinct page boxes, the `.jsx` (ExtendScript, run once through an After Effects MCP server's script call in an empty untitled project) imports them, builds composition `ai-mask` and returns After Effects' read-back that `../../it/import/ai_mask.rs` compares against | ## Run order (per file) diff --git a/crates/aep/tests/fixtures/tools/ai-mask-3099.jsx b/crates/aep/tests/fixtures/tools/ai-mask-3099.jsx new file mode 100644 index 000000000..bcac03d0b --- /dev/null +++ b/crates/aep/tests/fixtures/tools/ai-mask-3099.jsx @@ -0,0 +1,94 @@ +// Issue 3099: how After Effects sizes a placed .ai (PDF) and where masks / parented layers land. +// Generates ai-mask-3099.aep: run `python -I ai-mask-3099.py ` first, set `dir` to that +// folder, then run this script (ExtendScript) in an empty, untitled project. It returns After +// Effects' read-back (footage sizes, transforms, mask vertices, toComp points; the tests compare +// against it) and saves /i3099-ai-mask.aep, which is then scrubbed (README: steps 5 and 6). +(function () { + var dir = "/"; + var out = {}; + if (app.project.file !== null || app.project.numItems !== 0) { + return "ABORT: project not empty/untitled (" + app.project.numItems + " items)"; + } + var target = new File(dir + "i3099-ai-mask.aep"); + if (target.exists) { return "ABORT: target exists"; } + var names = ["i3099-a-boxes.ai", "i3099-b-frac.ai", "i3099-c-rot.ai", "i3099-d-trim.ai"]; + var items = {}; + out.footage = {}; + for (var i = 0; i < names.length; i++) { + var io = new ImportOptions(new File(dir + names[i])); + io.importAs = ImportAsType.FOOTAGE; + var it = app.project.importFile(io); + items[names[i]] = it; + out.footage[names[i]] = { w: it.width, h: it.height, par: it.pixelAspect }; + } + var comp = app.project.items.addComp("ai-mask", 1920, 1080, 1, 5, 25); + var art = comp.layers.add(items["i3099-a-boxes.ai"]); + art.name = "art"; + var artD = comp.layers.add(items["i3099-d-trim.ai"]); + artD.name = "artD"; + artD.collapseTransformation = true; + var artC = comp.layers.add(items["i3099-c-rot.ai"]); + artC.name = "artC"; + artC.property("ADBE Transform Group").property("ADBE Position").setValue([1500, 800]); + var n1 = comp.layers.addNull(); n1.name = "N1"; + var n2 = comp.layers.addNull(); n2.name = "N2"; + n2.setParentWithJump(n1); + art.setParentWithJump(n2); + artD.setParentWithJump(n2); + var t = function (l, p, v) { l.property("ADBE Transform Group").property(p).setValue(v); }; + t(n1, "ADBE Position", [700, 400]); + t(n1, "ADBE Rotate Z", 15); + t(n1, "ADBE Scale", [80, 120]); + t(n2, "ADBE Anchor Point", [10, 20]); + t(n2, "ADBE Position", [50, -30]); + t(n2, "ADBE Scale", [150, 150]); + t(art, "ADBE Position", [0, 0]); + t(artD, "ADBE Position", [300, 250]); + // Two rectangular masks on each art layer, in layer pixels. + var rect = function (l, nm, x0, y0, x1, y1) { + var m = l.property("ADBE Mask Parade").addProperty("ADBE Mask Atom"); + m.name = nm; + var s = new Shape(); + s.vertices = [[x0, y0], [x1, y0], [x1, y1], [x0, y1]]; + s.closed = true; + m.property("ADBE Mask Shape").setValue(s); + }; + rect(art, "M1", 40, 30, 200, 90); + rect(art, "M2", 220, 100, 350, 160); + rect(artD, "M1", 40, 30, 200, 90); + rect(artD, "M2", 220, 100, 350, 160); + // World positions of layer points through the parent chain (toComp), read via a Point Control. + var probe = n1.property("ADBE Effect Parade").addProperty("ADBE Point Control"); + var pt = probe.property(1); + var toComp = function (ln, p) { + pt.expression = "thisComp.layer('" + ln + "').toComp([" + p[0] + "," + p[1] + "])"; + var v = pt.valueAtTime(0, false); + return [v[0], v[1]]; + }; + var rd = function (l) { + var tg = l.property("ADBE Transform Group"); + var r = { + w: l.width, h: l.height, + anchor: tg.property("ADBE Anchor Point").value, + position: tg.property("ADBE Position").value, + scale: tg.property("ADBE Scale").value, + rot: tg.property("ADBE Rotate Z").value, + masks: [] + }; + var mp = l.property("ADBE Mask Parade"); + for (var k = 1; k <= mp.numProperties; k++) { + r.masks.push(mp.property(k).property("ADBE Mask Shape").value.vertices); + } + return r; + }; + out.layers = { art: rd(art), artD: rd(artD), artC: rd(artC), N1: rd(n1), N2: rd(n2) }; + out.world = {}; + var pts = { tl: [0, 0], tr: [art.width, 0], bl: [0, art.height], m1: [40, 30], m2: [350, 160] }; + for (var key in pts) { out.world["art_" + key] = toComp("art", pts[key]); } + var ptsD = { tl: [0, 0], tr: [artD.width, 0], bl: [0, artD.height], m1: [40, 30] }; + for (var key2 in ptsD) { out.world["artD_" + key2] = toComp("artD", ptsD[key2]); } + probe.remove(); + app.project.save(target); + out.saved = target.fsName; + return out; +})(); diff --git a/crates/aep/tests/fixtures/tools/ai-mask-3099.py b/crates/aep/tests/fixtures/tools/ai-mask-3099.py new file mode 100644 index 000000000..6b5b7facf --- /dev/null +++ b/crates/aep/tests/fixtures/tools/ai-mask-3099.py @@ -0,0 +1,66 @@ +"""Writes hand-made one-page PDFs named .ai with distinct page boxes (issue 3099 repro).""" +import os +import sys + +out = sys.argv[1] +os.makedirs(out, exist_ok=True) + + +def pdf(page_extra, content): + objs = [ + b"<< /Type /Catalog /Pages 2 0 R >>", + b"<< /Type /Pages /Kids [3 0 R] /Count 1 >>", + b"<< /Type /Page /Parent 2 0 R " + page_extra.encode() + b" /Contents 4 0 R >>", + b"<< /Length " + str(len(content)).encode() + b" >>\nstream\n" + content + b"\nendstream", + ] + data = b"%PDF-1.4\n" + offs = [] + for i, o in enumerate(objs, 1): + offs.append(len(data)) + data += str(i).encode() + b" 0 obj\n" + o + b"\nendobj\n" + x = len(data) + data += b"xref\n0 " + str(len(objs) + 1).encode() + b"\n0000000000 65535 f \n" + for o in offs: + data += b"%010d 00000 n \n" % o + data += b"trailer\n<< /Size " + str(len(objs) + 1).encode() + b" /Root 1 0 R >>\nstartxref\n" + str(x).encode() + b"\n%%EOF\n" + return data + + +def boxes_content(boxes): + # One outline per box (different colours) plus a filled marker at the media box origin corner. + cols = ["0 0 0", "1 0 0", "0 0.6 0", "0 0 1", "1 0.5 0"] + s = b"0.85 0.85 0.85 rg " + x0, y0, x1, y1 = boxes[0] + s += b"%g %g %g %g re f\n" % (x0, y0, x1 - x0, y1 - y0) + for c, (a, b, cc, d) in zip(cols, boxes): + s += c.encode() + b" RG 1 w %g %g %g %g re S\n" % (a + 0.5, b + 0.5, cc - a - 1, d - b - 1) + # A solid square in the lower-left of the last (innermost) box: shows y orientation. + a, b, _, _ = boxes[-1] + s += b"0.2 0.2 0.8 rg %g %g 20 10 re f" % (a + 4, b + 4) + return s + + +def arr(b): + return "[%s]" % " ".join("%g" % v for v in b) + + +# A: every box distinct, nested, non-square. +media, crop, bleed, trim, art = [0, 0, 420, 220], [5, 5, 415, 215], [10, 10, 410, 210], [20, 20, 400, 200], [60, 50, 300.6, 170.4] +a = pdf( + f"/MediaBox {arr(media)} /CropBox {arr(crop)} /BleedBox {arr(bleed)} /TrimBox {arr(trim)} /ArtBox {arr(art)}", + boxes_content([media, crop, bleed, trim, art]), +) +# B: only a fractional media box. +mb = [0, 0, 300.6, 120.4] +b = pdf(f"/MediaBox {arr(mb)}", boxes_content([mb])) +# C: media box with an offset origin and /Rotate 90. +mc = [100, 50, 400, 150] +c = pdf(f"/MediaBox {arr(mc)} /Rotate 90", boxes_content([mc])) +# D: media + trim + art, no crop box (bleed around the artboard). +md, td, ad = [0, 0, 418, 218], [9, 9, 409, 209], [40, 30, 250, 150] +d = pdf(f"/MediaBox {arr(md)} /TrimBox {arr(td)} /BleedBox {arr(md)} /ArtBox {arr(ad)}", boxes_content([md, td, ad])) + +for name, data in [("i3099-a-boxes.ai", a), ("i3099-b-frac.ai", b), ("i3099-c-rot.ai", c), ("i3099-d-trim.ai", d)]: + with open(os.path.join(out, name), "wb") as f: + f.write(data) + print(name, len(data)) diff --git a/crates/aep/tests/it/export/built.rs b/crates/aep/tests/it/export/built.rs index 14f9d8795..0da683cc4 100644 --- a/crates/aep/tests/it/export/built.rs +++ b/crates/aep/tests/it/export/built.rs @@ -83,6 +83,45 @@ fn ntsc_and_odd_frame_rates_use_the_time_bases_after_effects_writes() { } } +/// #3099: After Effects reads a null's absent Anchor Point as its top-left corner `[0, 0]`. A +/// null anchored at its centre is written (it was left out as "the default" and came back at the +/// corner); one at the corner is not, and both import back as they were. +#[test] +fn null_anchor_points_round_trip() { + let mut p = Project::default(); + let c = add_comp(&mut p, "C", 800, 600, FrameRate::new(30, 1), 2.0, None); + add_layer(&mut p, c, "Corner", LayerSource::Null, (100, 100)); + add_layer(&mut p, c, "Centre", LayerSource::Null, (100, 100)); + for (idx, anchor) in [(0, [50.0, 50.0, 0.0]), (1, [0.0, 0.0, 0.0])] { + with_layer(&mut p, c, idx, |l| { + if let Some(a) = l.props.prop_mut("transform/anchor") { + a.value = Value::Vec3(anchor); + } + }); + } + let r = export_all(&p); + let file = parse(&r.bytes).expect("parse"); + let view = effectcraft_aep::Project::new(&file).expect("project"); + let comp = view.all_items().into_iter().find(|i| i.comp().is_some()).expect("comp"); + let stored: Vec<_> = + comp.comp().expect("c").layers().map(|l| (l.name().unwrap_or_default(), l.transform(800, 600).expect("transform").anchor_fraction.source)).collect(); + assert_eq!(stored, [("Centre".to_string(), effectcraft_aep::ValueSource::Stored), ("Corner".to_string(), effectcraft_aep::ValueSource::Default)]); + let mut back = Project::default(); + let none = |_: &str| false; + let res = effectcraft_aep::import::import( + &mut back, + &r.bytes, + &effectcraft_aep::import::ImportOptions { allow_losses: true, ..effectcraft_aep::import::ImportOptions::new(&none) }, + ) + .expect("import"); + let comp = res.comps.first().and_then(|id| back.comp(*id)).expect("comp"); + for (name, want) in [("Centre", [50.0, 50.0]), ("Corner", [0.0, 0.0])] { + let l = comp.layers.iter().find(|l| l.name == name).expect("layer"); + let a = l.props.prop("transform/anchor").expect("anchor").value.as_vec2(); + assert!(close(a[0], want[0]) && close(a[1], want[1]), "{name}: {a:?}"); + } +} + #[test] fn layer_header_fields() { let mut p = Project::default(); diff --git a/crates/aep/tests/it/import.rs b/crates/aep/tests/it/import.rs index eb6963d6f..2535edcff 100644 --- a/crates/aep/tests/it/import.rs +++ b/crates/aep/tests/it/import.rs @@ -4,6 +4,7 @@ mod helpers; mod aepx; +mod ai_mask; mod blend_modes; mod cameras; mod cases; diff --git a/crates/aep/tests/it/import/ai_mask.rs b/crates/aep/tests/it/import/ai_mask.rs new file mode 100644 index 000000000..e5f57abe0 --- /dev/null +++ b/crates/aep/tests/it/import/ai_mask.rs @@ -0,0 +1,113 @@ +//! A placed Illustrator file with masks under two parented Nulls (#3099), against After Effects +//! 2026's own read-back of the committed project `tests/fixtures/ai-mask-3099.aep` (generator: +//! `tests/fixtures/tools/ai-mask-3099.py` and `ai-mask-3099.jsx`). Most of these guard After +//! Effects' values the importer already read so (the drawing of the page is tested in +//! `effectcraft-media` and the host's `vector_import` tests); the Anchor Point of the null left +//! at its default (`[0, 0]`, not the centre) was wrong before #3099. +//! +//! The four `.ai` files are hand-written one-page PDFs with distinct page boxes. After Effects +//! sized them by their ArtBox (a, d), by the MediaBox rounded up (b: 300.6 × 120.4 → 301 × 121) +//! and ignored `/Rotate 90` (c). Composition `ai-mask` (1920 × 1080): `art` (a) and `artD` (d, +//! Continuously Rasterize) are children of Null `N2`, itself a child of Null `N1`; both carry two +//! rectangular masks; `artC` (c) is on its own. + +use effectcraft_aep::import::{ImportOptions, import}; +use effectcraft_keyframe::Value; +use effectcraft_project::{ItemKind, Layer, Project}; + +use crate::import::helpers::comp; + +const AI_MASK: &[u8] = include_bytes!("../../fixtures/ai-mask-3099.aep"); + +/// The fixture imported into an empty project (losses allowed, no footage file present). +fn load() -> (Project, effectcraft_aep::import::ImportResult) { + let mut project = Project::default(); + let none = |_: &str| false; + let r = import(&mut project, AI_MASK, &ImportOptions { allow_losses: true, ..ImportOptions::new(&none) }).unwrap(); + (project, r) +} + +/// The first two components of the static value of property `path` of `l`. +fn vec2(l: &Layer, path: &str) -> [f64; 2] { + let v = l.props.prop(path).unwrap_or_else(|| panic!("{}: {path}", l.name)).value.as_vec2(); + [v[0], v[1]] +} + +/// `a` and `b` agree within float32 noise. +fn near(a: [f64; 2], b: [f64; 2]) -> bool { + (a[0] - b[0]).abs() < 1e-3 && (a[1] - b[1]).abs() < 1e-3 +} + +/// The four `.ai` items have After Effects' sizes and are placed pages. +#[test] +fn placed_ai_sizes_are_after_effects_sizes() { + let (p, _) = load(); + let mut sizes: Vec<(String, (u32, u32))> = p + .items + .values() + .filter_map(|i| match &i.kind { + ItemKind::Footage(f) if f.path.ends_with(".ai") => { + // Framed and drawn as After Effects places the page (#3099). + assert!(f.placed_page, "{}", i.name); + Some((i.name.clone(), (f.width, f.height))) + } + _ => None, + }) + .collect(); + sizes.sort(); + assert_eq!( + sizes, + [ + ("i3099-a-boxes.ai".to_string(), (241, 121)), + ("i3099-b-frac.ai".to_string(), (301, 121)), + ("i3099-c-rot.ai".to_string(), (300, 100)), + ("i3099-d-trim.ai".to_string(), (210, 120)), + ] + ); +} + +/// Parents, transforms (the default null anchor at `[0, 0]`) and both masks of each art layer +/// as After Effects read them back. +#[test] +fn masks_anchors_and_parents_are_after_effects_values() { + let (p, r) = load(); + let (_, c) = comp(&p, &r, "ai-mask"); + let layer = |name: &str| c.layers.iter().find(|l| l.name == name).unwrap_or_else(|| panic!("no layer {name}")); + let (art, art_d, art_c, n1, n2) = (layer("art"), layer("artD"), layer("artC"), layer("N1"), layer("N2")); + // Parents: art, artD -> N2 -> N1. + assert_eq!(art.parent, Some(n2.id)); + assert_eq!(art_d.parent, Some(n2.id)); + assert_eq!(n2.parent, Some(n1.id)); + assert_eq!(n1.parent, None); + assert_eq!(art_c.parent, None); + // Transforms as After Effects read them back (anchor = half the source size for footage). + for (l, anchor, position, scale) in [ + (art, [120.5, 60.5], [0.0, 0.0], [100.0, 100.0]), + (art_d, [105.0, 60.0], [300.0, 250.0], [100.0, 100.0]), + (art_c, [150.0, 50.0], [1500.0, 800.0], [100.0, 100.0]), + (n1, [0.0, 0.0], [700.0, 400.0], [80.0, 120.0]), + (n2, [10.0, 20.0], [50.0, -30.0], [150.0, 150.0]), + ] { + assert!(near(vec2(l, "transform/anchor"), anchor), "{} anchor {:?}", l.name, vec2(l, "transform/anchor")); + assert!(near(vec2(l, "transform/position"), position), "{} position {:?}", l.name, vec2(l, "transform/position")); + assert!(near(vec2(l, "transform/scale"), scale), "{} scale {:?}", l.name, vec2(l, "transform/scale")); + } + match n1.props.prop("transform/rotation").map(|p| &p.value) { + Some(Value::Scalar(v)) => assert!((v - 15.0).abs() < 1e-9, "N1 rotation {v}"), + other => panic!("N1 rotation {other:?}"), + } + // Both art layers: M1 (40, 30)-(200, 90) and M2 (220, 100)-(350, 160) in layer pixels, the + // second reaching past the layer, as After Effects read the vertices back. + let rects = [[[40.0, 30.0], [200.0, 30.0], [200.0, 90.0], [40.0, 90.0]], [[220.0, 100.0], [350.0, 100.0], [350.0, 160.0], [220.0, 160.0]]]; + for l in [art, art_d] { + let masks: Vec<_> = l.masks().expect("masks").groups().collect(); + assert_eq!(masks.len(), 2, "{}", l.name); + for (m, want) in masks.iter().zip(&rects) { + let Some(Value::Path(path)) = m.get("path").map(|p| &p.value) else { panic!("{}: {} has no path", l.name, m.name) }; + assert_eq!(path.vertices.len(), 4, "{}: {}", l.name, m.name); + for (v, w) in path.vertices.iter().zip(want) { + assert!(near(*v, *w), "{}: {} vertex {v:?} != {w:?}", l.name, m.name); + } + } + } +} diff --git a/crates/engine/src/cmd/create.rs b/crates/engine/src/cmd/create.rs index 6c4b02c87..250ca836d 100644 --- a/crates/engine/src/cmd/create.rs +++ b/crates/engine/src/cmd/create.rs @@ -5,7 +5,7 @@ use effectcraft_color::Label; use effectcraft_keyframe::Value as KV; use effectcraft_project::build::{self, Ids}; -use effectcraft_project::{ItemKind, LayerSource, Solid}; +use effectcraft_project::{ItemKind, LayerSource, MatteKind, Solid, TrackMatte}; use serde_json::{Value, json}; use super::{CommandSpec, bad, has_layers, layers_p, str_p}; @@ -13,6 +13,8 @@ use crate::{EngineError, Result, Session, cmd}; const OPS: &str = "editableText|shapesFromText|masksFromText|shapesFromVector|instance3d"; +/// Layer ▸ Create (`layer.create`): the `op` ([`OPS`]) on the given or selected layers; returns +/// the created layer ids and what was skipped. fn create(s: &mut Session, p: &Value) -> Result { let op = str_p(p, "op").ok_or_else(|| bad("layer.create", format!("missing `op` ({OPS})")))?; let (cid, lids) = layers_p(s, p)?; @@ -99,8 +101,11 @@ fn create(s: &mut Session, p: &Value) -> Result { continue; }; let bytes = s.services.read_file(&f.path).map_err(|e| EngineError::Other(format!("cannot read {}: {e}", f.path)))?; - let doc = crate::vector::vector_doc(&f.path, &bytes, f.layer.as_ref(), f.page) + // In the source layer's pixels, as the footage is drawn (a placed page of an After + // Effects project fills the stored size, #3099). + let doc = crate::vector::footage_doc(&f, &bytes) .unwrap_or_else(|| Err(format!("{}: not a vector file", f.path))) + .map(|d| crate::vector::fitted_to_footage(d, &f)) .map_err(EngineError::Other)?; // Images become footage layers (PNG files written next to the source and // imported), parented to the shape layer below it. @@ -123,7 +128,7 @@ fn create(s: &mut Session, p: &Value) -> Result { // Without images: one shape layer. With images: the shapes between them // in layers of their own, so the stack keeps the document's paint order. let segments = if image_items.is_empty() { vec![doc.clone()] } else { crate::vector::split_at_images(&doc) }; - let top = crate::vector::shapes_from_vector(proj, &comp, &src, segments.last().unwrap_or(&doc)); + let mut top = crate::vector::shapes_from_vector(proj, &comp, &src, segments.last().unwrap_or(&doc)); // Top to bottom: the last segment, image n, segment n − 1, … image 1, segment 0. let mut stack = vec![]; for k in (0..segments.len().saturating_sub(1)).rev() { @@ -140,9 +145,25 @@ fn create(s: &mut Session, p: &Value) -> Result { sl.name = format!("{} {}", top.name, k + 1); stack.push(sl); } + // A placed page shows only its frame (the footage's raster ends there): every + // layer made from it takes a hidden frame layer as its track matte (#3099). + let matte = crate::vector::frame_matte(proj, &comp, &src, &f); + if let Some(m) = &matte { + let tm = Some(TrackMatte { layer: m.id, kind: MatteKind::Alpha }); + top.track_matte = tm; + for l in &mut stack { + l.track_matte = tm; + } + } let mut ids = vec![top.id]; ids.extend(stack.iter().filter(|l| matches!(l.source, LayerSource::Shape)).map(|l| l.id)); - // Each directly above the source: the top layer first. + // The frame matte is made too (last: the selection stays on the top layer). + ids.extend(matte.as_ref().map(|m| m.id)); + // Each directly above the source: the frame matte (when there is one) above + // all, then the top layer first. + if let Some(m) = matte { + insert_above(proj, cid, lid, m, true)?; + } insert_above(proj, cid, lid, top, true)?; for l in stack { insert_above(proj, cid, lid, l, true)?; diff --git a/crates/engine/src/footage/footage_reload.rs b/crates/engine/src/footage/footage_reload.rs index e56e16a96..5a0576f10 100644 --- a/crates/engine/src/footage/footage_reload.rs +++ b/crates/engine/src/footage/footage_reload.rs @@ -176,9 +176,11 @@ fn psd_layer(s: &Session, path: &str, l: &SourceLayer) -> Option<(u32, Option<(u Some((u32::try_from(found.index).ok()?, size)) } +/// The pixel size of vector footage `f` as its file is now (its page, framing and layer), or +/// `None` when the file cannot be read or shows nothing. fn vector_size(s: &Session, f: &Footage) -> Option<(u32, u32)> { let bytes = s.services.read_file(&f.path).ok()?; - let doc = crate::vector::vector_doc(&f.path, &bytes, f.layer.as_ref(), f.page)?.ok()?; + let doc = crate::vector::footage_doc(f, &bytes)?.ok()?; (!doc.root.children.is_empty()).then(|| doc.pixel_size()) } @@ -229,6 +231,10 @@ fn refreshed(s: &Session, f: &Footage, probed: Footage) -> Footage { // The layer is gone from the file: keep the item as it was. None => (w, h) = (f.width, f.height), }, + // A placed page of an After Effects project keeps the size After Effects stored: the + // layers' anchors and masks are measured against it, and the page is drawn to fill it + // (the probe would measure the page as a viewer frames it, #3099). + None if f.placed_page => (w, h) = (f.width, f.height), // A later page of a PDF: the probe measures the first page. None if f.page != 0 => (w, h) = (f.width, f.height), None => {} diff --git a/crates/engine/src/interchange/vector.rs b/crates/engine/src/interchange/vector.rs index 324d3a82a..b52517cb3 100644 --- a/crates/engine/src/interchange/vector.rs +++ b/crates/engine/src/interchange/vector.rs @@ -261,15 +261,73 @@ pub fn is_vector(f: &effectcraft_project::Footage) -> bool { effectcraft_render::is_vector_footage(f) || f.path.to_ascii_lowercase().ends_with(".svg") } +/// `doc` (the document of footage `f`) in the footage's layer pixels, as the renderer draws it +/// ([`effectcraft_render::vector_fit`]): a placed page of an After Effects project is scaled to +/// fill the size stored for it; other footage is unchanged. +pub fn fitted_to_footage(mut doc: Doc, f: &effectcraft_project::Footage) -> Doc { + let (_, [sx, sy]) = effectcraft_render::vector_fit(f, [doc.width, doc.height], doc.pixel_size(), 1.0); + if f.placed_page { + doc.root.transform = Affine::scale_non_uniform(sx, sy) * doc.root.transform; + (doc.width, doc.height) = (doc.width * sx, doc.height * sy); + } + doc +} + +/// Create Shapes from Vector Layer on a placed page of an After Effects project: a hidden shape +/// layer filling the frame the footage is drawn in (its `width` × `height` raster, in the layer +/// pixels of [`fitted_to_footage`]'s document), to be the Alpha track matte of every layer made +/// from the page, so bleed, art past the artboard and the page's background stay hidden as on +/// the footage (#3099). `None` for other footage, whose shapes are converted whole as before. +/// +/// A track matte is drawn at the composition's resolution, so its edge is the footage's raster +/// edge on shape and image layers alike; a mask on an image layer would be drawn at the image's +/// own resolution and blur its edge when the image is scaled up. +pub fn frame_matte(proj: &mut Project, comp: &Comp, src: &Layer, f: &effectcraft_project::Footage) -> Option { + if !f.placed_page || f.width == 0 || f.height == 0 { + return None; + } + let svg = format!( + r##""##, + f.width, f.height + ); + let doc = effectcraft_svg::parse(svg.as_bytes()).ok()?; + let mut l = build::layer(proj, comp, &format!("{} Frame", src.name), LayerSource::Shape, (0, 0), None); + add_doc_shapes(proj, &mut l, &doc); + copy_transform(proj, src, &mut l); + like_source(&mut l, src); + // The layers it mattes carry the source's opacity already. + if let Some(o) = l.props.prop_mut("transform/opacity") { + o.value = Value::Scalar(100.0); + o.keys.clear(); + o.expr = None; + } + l.name = comp.unique_layer_name(&format!("{} Frame", src.name)); + l.switches.video = false; + Some(l) +} + +/// The vector document of footage `f` (its file read as `bytes`; `None` for other formats): its +/// page, framed as [`effectcraft_project::Footage::placed_page`] says, restricted to its layer. +pub fn footage_doc(f: &effectcraft_project::Footage, bytes: &[u8]) -> Option> { + let framing = if f.placed_page { effectcraft_pdf::Framing::Placed } else { effectcraft_pdf::Framing::Viewer }; + vector_doc(&f.path, bytes, f.layer.as_ref(), f.page, framing) +} + /// The vector document of an SVG / PDF / AI / EPS file (`None` for other formats): page -/// `page` of a PDF, restricted to one layer when `layer` names it. -pub fn vector_doc(path: &str, bytes: &[u8], layer: Option<&effectcraft_project::SourceLayer>, page: u32) -> Option> { +/// `page` of a PDF framed as `framing` says, restricted to one layer when `layer` names it. +pub fn vector_doc( + path: &str, + bytes: &[u8], + layer: Option<&effectcraft_project::SourceLayer>, + page: u32, + framing: effectcraft_pdf::Framing, +) -> Option> { if path.to_ascii_lowercase().ends_with(".svg") || effectcraft_svg::looks_like_svg(bytes) { return Some(effectcraft_svg::parse(bytes).map_err(|e| format!("{path}: {e}"))); } effectcraft_pdf::sniff(bytes)?; Some( - effectcraft_pdf::parse_page(bytes, page as usize) + effectcraft_pdf::parse_page_framed(bytes, page as usize, framing) .map(|d| match layer { Some(l) => effectcraft_pdf::layer_doc_with_sizes(&d, l.index as usize, l.layer_size).0, None => d, diff --git a/crates/host/tests/it/vector_import.rs b/crates/host/tests/it/vector_import.rs index badd60b66..eff5b4b4b 100644 --- a/crates/host/tests/it/vector_import.rs +++ b/crates/host/tests/it/vector_import.rs @@ -466,6 +466,11 @@ fn psd_smart_objects_with_perspective_and_warp_bake_as_placed() { /// A PDF with two placed images (one turned a quarter) between a background and a shape. fn image_pdf() -> Vec { + image_pdf_with("") +} + +/// [`image_pdf`] with `boxes` added to the page dictionary. +fn image_pdf_with(boxes: &str) -> Vec { let content = "0.9 0.9 0.9 rg 0 0 120 80 re f\nq 60 0 0 30 10 40 cm /Im Do Q\nq 0 40 -20 0 110 10 cm /Im Do Q\n0 0 1 rg 20 5 30 20 re f\n"; // 8×8 pixels in quadrants: red, green / white, black. let quad = |x: usize, y: usize| -> [u8; 3] { [[[255, 0, 0], [0, 255, 0]], [[255, 255, 255], [0, 0, 0]]][y / 4][x / 4] }; @@ -474,7 +479,7 @@ fn image_pdf() -> Vec { &[ (1, "<< /Type /Catalog /Pages 2 0 R >>".into(), None), (2, "<< /Type /Pages /Kids [3 0 R] /Count 1 >>".into(), None), - (3, "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 120 80] /Resources << /XObject << /Im 5 0 R >> >> /Contents 4 0 R >>".into(), None), + (3, format!("<< /Type /Page /Parent 2 0 R /MediaBox [0 0 120 80] {boxes} /Resources << /XObject << /Im 5 0 R >> >> /Contents 4 0 R >>"), None), (4, "<< >>".into(), Some(content.as_bytes().to_vec())), (5, "<< /Type /XObject /Subtype /Image /Width 8 /Height 8 /ColorSpace /DeviceRGB /BitsPerComponent 8 >>".into(), Some(px)), ], @@ -546,6 +551,355 @@ fn retain_pdf(width: u32) -> Vec { ) } +/// A 200 × 100 pt page: red left half, blue right half. +fn halves_pdf() -> Vec { + effectcraft_pdf::write::pdf( + &[ + (1, "<< /Type /Catalog /Pages 2 0 R >>".into(), None), + (2, "<< /Type /Pages /Kids [3 0 R] /Count 1 >>".into(), None), + (3, "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 200 100] /Contents 4 0 R >>".into(), None), + (4, "<< >>".into(), Some(b"1 0 0 rg 0 0 100 100 re f 0 0 1 rg 100 0 100 100 re f".to_vec())), + ], + 1, + ) +} + +/// #3099: footage from an After Effects project ([`effectcraft_project::Footage::placed_page`]) +/// keeps the size After Effects stored for a placed .ai, which can differ from the page as read +/// here. The page fills that size at full and at reduced resolution alike: it was drawn at its own +/// aspect at full resolution and stretched to the stored size below 3/4 (the art jumped when the +/// viewer changed resolution, and the masks, stored against that size, came out too large at +/// full resolution). Two placed items of one file at different stored sizes each get their own +/// pixels, and neither reuses the file's frame at its own size, decoded first. +#[test] +fn placed_vector_footage_fills_its_stored_size_at_every_resolution() { + use effectcraft_project::ItemKind; + use effectcraft_time::Tick; + + let path = tmp("stored-size.ai"); + std::fs::write(&path, halves_pdf()).unwrap(); + let mut s = effectcraft_host::session(); + let item = ItemId(s.execute_checked("file.import", json!({"paths": [path]})).unwrap()["items"][0].as_u64().unwrap()); + let red = |p: [f32; 4]| p[3] > 0.99 && p[0] > 0.9 && p[2] < 0.1; + let blue = |p: [f32; 4]| p[3] > 0.99 && p[2] > 0.9 && p[0] < 0.1; + // At the file's own size first (its frame goes to the pool's cache). + s.execute("comp.new", json!({"name": "Own", "width": 200, "height": 100, "frameRate": 25, "duration": 1})).unwrap(); + s.execute_checked("layer.addItem", json!({"item": item.0})).unwrap(); + let own_comp = s.active_comp_id().unwrap(); + let own = s.render(own_comp, Tick::ZERO, RenderOpts::default()); + assert!(red(own.get(50, 90)) && blue(own.get(150, 90))); + // Two placed items of the file with the sizes an After Effects project stores (other aspects). + let proj = std::sync::Arc::make_mut(&mut s.project); + let ItemKind::Footage(f) = &mut proj.item_mut(item).unwrap().kind else { panic!("footage") }; + (f.width, f.height, f.placed_page) = (100, 80, true); + let tall = effectcraft_project::Footage { width: 60, height: 120, ..f.clone() }; + let tall = proj.add_item("tall", Default::default(), None, ItemKind::Footage(tall)); + for (item, (w, h)) in [(item, (100u32, 80u32)), (tall, (60, 120))] { + s.execute("comp.new", json!({"name": format!("Stored {w}"), "width": w, "height": h, "frameRate": 25, "duration": 1})).unwrap(); + let lid = s.execute_checked("layer.addItem", json!({"item": item.0})).unwrap()["layer"].as_u64().unwrap(); + let cid = s.active_comp_id().unwrap(); + let (l, r, top, bottom) = (i64::from(w / 4), i64::from(w * 3 / 4), 3, i64::from(h) - 4); + for collapse in [false, true] { + s.execute("layer.setSwitch", json!({"layers": [lid], "switch": "collapse", "value": collapse})).unwrap(); + let full = s.render(cid, Tick::ZERO, RenderOpts::default()); + assert_eq!((full.width, full.height), (w, h)); + for y in [top, bottom] { + let (a, b) = (full.get(l, y), full.get(r, y)); + assert!(red(a) && blue(b), "{w}×{h}, collapse {collapse}, full resolution, row {y}: {a:?} {b:?}"); + } + let half = s.render(cid, Tick::ZERO, RenderOpts { scale: 0.5, ..RenderOpts::default() }); + assert_eq!((half.width, half.height), (w / 2, h / 2)); + for y in [top / 2, bottom / 2] { + let (a, b) = (half.get(l / 2, y), half.get(r / 2, y)); + assert!(red(a) && blue(b), "{w}×{h}, collapse {collapse}, half resolution, row {y}: {a:?} {b:?}"); + } + } + // Create Shapes from Vector Layer draws the shapes where the footage is drawn. + s.execute_checked("layer.create", json!({"op": "shapesFromVector", "layers": [lid]})).unwrap(); + s.execute("layer.setSwitch", json!({"layers": [lid], "switch": "video", "value": false})).unwrap(); + let shapes = s.render(cid, Tick::ZERO, RenderOpts::default()); + for y in [top, bottom] { + let (a, b) = (shapes.get(l, y), shapes.get(r, y)); + assert!(red(a) && blue(b), "{w}×{h}, shapes, row {y}: {a:?} {b:?}"); + } + } +} + +/// #3099 review: Create Shapes from Vector Layer on a placed page keeps the page's frame. The +/// footage's raster shows only the ArtBox (241 × 121) of `art_box_ai()`, whose grey media box +/// reaches past it on every side; in a composition larger than the footage, the outlines show +/// the same colours inside the frame and nothing (the background) outside it. Without the clip +/// they showed the whole page: the grey background around the art. +#[test] +fn shapes_from_a_placed_page_stay_inside_its_frame() { + use effectcraft_project::ItemKind; + use effectcraft_time::Tick; + + let path = tmp("placed-frame.ai"); + std::fs::write(&path, art_box_ai()).unwrap(); + let mut s = effectcraft_host::session(); + let item = ItemId(s.execute_checked("file.import", json!({"paths": [path]})).unwrap()["items"][0].as_u64().unwrap()); + // As an After Effects project stores it: the ArtBox's size, placed. + let ItemKind::Footage(f) = &mut std::sync::Arc::make_mut(&mut s.project).item_mut(item).unwrap().kind else { panic!("footage") }; + (f.width, f.height, f.placed_page) = (241, 121, true); + s.execute("comp.new", json!({"name": "Big", "width": 400, "height": 300, "frameRate": 25, "duration": 1})).unwrap(); + let lid = s.execute_checked("layer.addItem", json!({"item": item.0})).unwrap()["layer"].as_u64().unwrap(); + let cid = s.active_comp_id().unwrap(); + // The layer is centred: layer pixel (x, y) is comp (x + 79.5, y + 89.5). + let at = |img: &Image, x: f64, y: f64| img.get((x + 79.5).floor() as i64, (y + 89.5).floor() as i64); + let red = |p: [f32; 4]| p[3] > 0.99 && p[0] > 0.9 && p[1] < 0.1 && p[2] < 0.1; + let blue = |p: [f32; 4]| p[3] > 0.99 && p[2] > 0.9 && p[0] < 0.1 && p[1] < 0.1; + let empty = |p: [f32; 4]| p[0] < 0.02 && p[1] < 0.02 && p[2] < 0.02; + let inside = [([20.0, 20.0], true), ([110.0, 100.0], true), ([130.0, 20.0], false), ([230.0, 110.0], false)]; + // Outside the frame, where the page's grey media box would show: left, right, above, below. + let outside = [[-20.0, 60.0], [-55.0, 100.0], [260.0, 60.0], [300.0, 10.0], [120.0, -20.0], [120.0, 140.0]]; + let check = |img: &Image, what: &str| { + for (p, want_red) in inside { + let px = at(img, p[0], p[1]); + assert!(if want_red { red(px) } else { blue(px) }, "{what}: inside the frame at {p:?}: {px:?}"); + } + for p in outside { + let px = at(img, p[0], p[1]); + assert!(empty(px), "{what}: outside the frame at {p:?}: {px:?}"); + } + }; + check(&s.render(cid, Tick::ZERO, RenderOpts::default()), "footage"); + s.execute_checked("layer.create", json!({"op": "shapesFromVector", "layers": [lid]})).unwrap(); + let comp = s.project.comp(cid).unwrap(); + assert!(!comp.layers.iter().find(|l| l.id.0 == lid).unwrap().switches.video, "the source is switched off"); + check(&s.render(cid, Tick::ZERO, RenderOpts::default()), "shapes"); +} + +/// #3099 review: the images of a placed page become footage layers clipped to the frame too. +/// `image_pdf_with` an ArtBox [20 15 100 70]: the upright image reaches past the frame's left +/// edge, the turned one past its right and bottom edges, the grey page around it. After the +/// conversion the layers inside the frame match the footage, and outside it nothing shows. +#[test] +fn images_from_a_placed_page_stay_inside_its_frame() { + use effectcraft_project::{ItemKind, MatteKind, TrackMatte}; + use effectcraft_time::Tick; + + let path = tmp("placed-images.pdf"); + std::fs::write(&path, image_pdf_with("/ArtBox [20 15 100 70]")).unwrap(); + let mut s = effectcraft_host::session(); + let item = ItemId(s.execute_checked("file.import", json!({"paths": [path]})).unwrap()["items"][0].as_u64().unwrap()); + let ItemKind::Footage(f) = &mut std::sync::Arc::make_mut(&mut s.project).item_mut(item).unwrap().kind else { panic!("footage") }; + (f.width, f.height, f.placed_page) = (80, 55, true); + s.execute("comp.new", json!({"name": "Big", "width": 200, "height": 150, "frameRate": 25, "duration": 1})).unwrap(); + let lid = s.execute_checked("layer.addItem", json!({"item": item.0})).unwrap()["layer"].as_u64().unwrap(); + let cid = s.active_comp_id().unwrap(); + // Centred: layer pixel (x, y) is comp (x + 60, y + 47.5). + let at = |img: &Image, x: f64, y: f64| img.get((x + 60.0).floor() as i64, (y + 47.5).floor() as i64); + let empty = |p: [f32; 4]| p[0] < 0.02 && p[1] < 0.02 && p[2] < 0.02; + // Inside: both images and the grey page; outside: the images past the frame, the grey page. + let inside = [[10.0, 8.0], [40.0, 8.0], [10.0, 22.0], [40.0, 22.0], [75.0, 25.0], [75.0, 50.0], [5.0, 40.0], [60.0, 10.0]]; + let outside = [[-5.0, 15.0], [85.0, 40.0], [75.0, 58.0], [-15.0, 50.0], [40.0, -5.0]]; + let footage = s.render(cid, Tick::ZERO, RenderOpts::default()); + for p in outside { + assert!(empty(at(&footage, p[0], p[1])), "footage outside the frame at {p:?}: {:?}", at(&footage, p[0], p[1])); + } + let r = s.execute_checked("layer.create", json!({"op": "shapesFromVector", "layers": [lid]})).unwrap(); + assert_eq!(r["skipped"], json!([]), "{r}"); + // One hidden frame layer is the Alpha track matte of every layer made from the page. + let comp = s.project.comp(cid).unwrap(); + let frame = comp.layers.iter().find(|l| l.name.ends_with(" Frame")).expect("the frame matte layer"); + assert!(!frame.switches.video); + let made: Vec<_> = comp.layers.iter().filter(|l| l.id != frame.id && l.id.0 != lid).collect(); + assert_eq!(made.iter().filter(|l| l.name == "Image").count(), 2); + for l in &made { + assert_eq!(l.track_matte, Some(TrackMatte { layer: frame.id, kind: MatteKind::Alpha }), "{}", l.name); + } + let shapes = s.render(cid, Tick::ZERO, RenderOpts::default()); + for p in inside { + let (a, b) = (at(&shapes, p[0], p[1]), at(&footage, p[0], p[1])); + assert!((0..4).all(|k| (a[k] - b[k]).abs() < 0.05), "inside the frame at {p:?}: {a:?} vs footage {b:?}"); + } + for p in outside { + assert!(empty(at(&shapes, p[0], p[1])), "shapes outside the frame at {p:?}: {:?}", at(&shapes, p[0], p[1])); + } +} + +/// A PDF with an ArtBox, imported here (not from an After Effects project), and a project saved +/// with it before #3099: shown as a PDF viewer frames it (the crop box, 410 × 210) at its own +/// size, exactly as before; the project file has no new field. +#[test] +fn a_pdf_with_an_art_box_imported_here_keeps_the_viewer_framing() { + use effectcraft_project::{ItemKind, Project}; + use effectcraft_time::Tick; + + let bytes = art_box_ai(); + let path = tmp("viewer-art-box.pdf"); + std::fs::write(&path, &bytes).unwrap(); + let mut s = effectcraft_host::session(); + let item = ItemId(s.execute_checked("file.import", json!({"paths": [path]})).unwrap()["items"][0].as_u64().unwrap()); + let ItemKind::Footage(f) = &s.project.item(item).unwrap().kind else { panic!("footage") }; + assert_eq!((f.width, f.height, f.placed_page), (410, 210, false)); + s.execute("comp.new", json!({"name": "V", "width": 410, "height": 210, "frameRate": 25, "duration": 1})).unwrap(); + s.execute_checked("layer.addItem", json!({"item": item.0})).unwrap(); + let cid = s.active_comp_id().unwrap(); + let direct = effectcraft_svg::rasterize(&effectcraft_pdf::parse(&bytes).unwrap(), 410, 210, 1.0); + assert!(mean_diff(&s.render(cid, Tick::ZERO, RenderOpts::default()), &direct) < 1.0 / 255.0); + let saved = s.project.to_json(); + assert!(!saved.contains("placed_page"), "the saved project is in the earlier format"); + s.project = std::sync::Arc::new(Project::from_json(&saved).unwrap()); + assert!(mean_diff(&s.render(cid, Tick::ZERO, RenderOpts::default()), &direct) < 1.0 / 255.0, "reopened"); +} + +/// `i3099-a-boxes.ai` of `effectcraft-aep`'s `ai-mask-3099.aep` (its boxes as in +/// `tests/fixtures/tools/ai-mask-3099.py`): MediaBox 420 × 220, CropBox, BleedBox and TrimBox +/// inside it, ArtBox [60 50 300.6 170.4]. Here grey over the media box, the art box red on its +/// left half and blue on its right half. +fn art_box_ai() -> Vec { + let page = "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 420 220] /CropBox [5 5 415 215] /BleedBox [10 10 410 210] /TrimBox [20 20 400 200] /ArtBox [60 50 300.6 170.4] /Contents 4 0 R >>"; + let content = b"0.5 g 0 0 420 220 re f 1 0 0 rg 60 50 120.3 120.4 re f 0 0 1 rg 180.3 50 120.3 120.4 re f"; + effectcraft_pdf::write::pdf( + &[ + (1, "<< /Type /Catalog /Pages 2 0 R >>".into(), None), + (2, "<< /Type /Pages /Kids [3 0 R] /Count 1 >>".into(), None), + (3, page.into(), None), + (4, "<< >>".into(), Some(content.to_vec())), + ], + 1, + ) +} + +/// `i3099-d-trim.ai` of `ai-mask-3099.aep`: MediaBox 418 × 218, TrimBox, ArtBox [40 30 250 150] +/// (no CropBox). Grey over the media box, the art box red on its left half, blue on its right. +fn trim_ai() -> Vec { + let page = "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 418 218] /TrimBox [9 9 409 209] /BleedBox [0 0 418 218] /ArtBox [40 30 250 150] /Contents 4 0 R >>"; + let content = b"0.5 g 0 0 418 218 re f 1 0 0 rg 40 30 105 120 re f 0 0 1 rg 145 30 105 120 re f"; + effectcraft_pdf::write::pdf( + &[ + (1, "<< /Type /Catalog /Pages 2 0 R >>".into(), None), + (2, "<< /Type /Pages /Kids [3 0 R] /Count 1 >>".into(), None), + (3, page.into(), None), + (4, "<< >>".into(), Some(content.to_vec())), + ], + 1, + ) +} + +/// `i3099-c-rot.ai` of `ai-mask-3099.aep`: MediaBox [100 50 400 150] with `/Rotate 90`, grey, +/// with a blue 20 × 10 marker 4 pt in from the media box's lower-left corner. +fn rotated_ai() -> Vec { + effectcraft_pdf::write::pdf( + &[ + (1, "<< /Type /Catalog /Pages 2 0 R >>".into(), None), + (2, "<< /Type /Pages /Kids [3 0 R] /Count 1 >>".into(), None), + (3, "<< /Type /Page /Parent 2 0 R /MediaBox [100 50 400 150] /Rotate 90 /Contents 4 0 R >>".into(), None), + (4, "<< >>".into(), Some(b"0.5 g 100 50 300 100 re f 0 0 1 rg 104 54 20 10 re f".to_vec())), + ], + 1, + ) +} + +/// #3099 end to end, against After Effects 2026's own read-back of the committed project +/// `ai-mask-3099.aep`: a placed .ai (ArtBox inside a larger crop box) parented to a Null parented +/// to a Null, with two rectangular masks. After Effects sizes the footage 241 × 121 (the ArtBox) +/// and puts the layer's corners at the comp points below (`toComp`). The art fills the layer +/// between the masks at full and at half resolution; it was drawn from the crop box (410 × 210) +/// scaled to the layer's width, so the masks cut the wrong part of it and half resolution +/// squeezed it, and the Null left at its default anchor moved it. `artC` (`/Rotate 90`) is drawn +/// unturned as After Effects draws it, `artD` (Continuously Rasterize) as `art`. +#[test] +fn aep_ai_layer_with_masks_under_two_nulls_renders_like_after_effects() { + use effectcraft_engine::render::EvalCtx; + use effectcraft_project::ItemKind; + use effectcraft_time::Tick; + + let dir = std::path::PathBuf::from(tmp("ai-mask-3099")); + std::fs::create_dir_all(&dir).unwrap(); + let aep = dir.join("ai-mask-3099.aep"); + // The fixture belongs to `effectcraft-aep` (its sidecar and generator are there); this test + // renders it through the wired session, which that crate cannot. + std::fs::write(&aep, include_bytes!("../../../aep/tests/fixtures/ai-mask-3099.aep")).unwrap(); + let mut s = effectcraft_host::session(); + s.execute_checked("file.importAep", json!({"path": aep.to_string_lossy(), "allowLosses": true})).unwrap(); + // The project's footage paths are neutral (`C:\fixture\x\...`): the files are linked here. + for (name, bytes, size) in + [("i3099-a-boxes.ai", art_box_ai(), (241, 121)), ("i3099-c-rot.ai", rotated_ai(), (300, 100)), ("i3099-d-trim.ai", trim_ai(), (210, 120))] + { + let file = dir.join(name); + std::fs::write(&file, bytes).unwrap(); + let item = s + .project + .items + .values() + .find(|i| matches!(&i.kind, ItemKind::Footage(f) if f.path.ends_with(name))) + .map(|i| i.id) + .unwrap_or_else(|| panic!("footage {name}")); + let ItemKind::Footage(f) = &mut std::sync::Arc::make_mut(&mut s.project).item_mut(item).unwrap().kind else { panic!("footage") }; + assert_eq!((f.width, f.height, f.placed_page), (size.0, size.1, true), "{name}: After Effects' size of the placed .ai"); + (f.path, f.missing) = (file.to_string_lossy().into_owned(), false); + } + let cid = s.project.items.values().find(|i| i.name == "ai-mask").map(|i| i.id).expect("comp ai-mask"); + + // After Effects' toComp of the art layer's points (layer pixels → comp pixels). + let ae = [ + ([0.0, 0.0], [634.193413913741, 195.085717365354]), + ([241.0, 0.0], [913.539162876539, 269.936185209003]), + ([0.0, 121.0], [577.822625890412, 405.464362331113]), + ([40.0, 30.0], [666.58162514008, 259.669026149884]), + ([350.0, 160.0], [965.342375965623, 581.976354279664]), + ]; + let comp = s.project.comp(cid).unwrap(); + let art = comp.layer_by_name("art").unwrap(); + let (m, _) = EvalCtx::new(&s.project, cid, comp, Tick::ZERO).layer_to_comp(art); + let to_comp = |[u, v]: [f64; 2]| [m.0[0][0] * u + m.0[0][1] * v + m.0[0][2], m.0[1][0] * u + m.0[1][1] * v + m.0[1][2]]; + for (p, want) in ae { + let got = to_comp(p); + assert!((got[0] - want[0]).abs() < 1e-3 && (got[1] - want[1]).abs() < 1e-3, "{p:?}: {got:?} vs After Effects {want:?}"); + } + + // Inside the masks (M1: x 40..200, y 30..90; M2: x 220..350, y 100..160, cut by the layer). + let red = |p: [f32; 4]| p[0] > 0.9 && p[1] < 0.1 && p[2] < 0.1; + let blue = |p: [f32; 4]| p[2] > 0.9 && p[0] < 0.1 && p[1] < 0.1; + let full = s.render(cid, Tick::ZERO, RenderOpts::default()); + let half = s.render(cid, Tick::ZERO, RenderOpts { scale: 0.5, ..RenderOpts::default() }); + for (p, want_red) in [([60.0, 45.0], true), ([100.0, 75.0], true), ([150.0, 40.0], false), ([190.0, 80.0], false), ([232.0, 112.0], false)] { + let [x, y] = to_comp(p); + let at = |img: &Image, k: f64| img.get((x * k).round() as i64, (y * k).round() as i64); + for (img, k, what) in [(&full, 1.0, "full"), (&half, 0.5, "half")] { + let px = at(img, k); + let ok = if want_red { red(px) } else { blue(px) }; + assert!(ok, "{what} resolution, layer point {p:?}: {px:?} (want {})", if want_red { "red" } else { "blue" }); + } + } + // Outside the masks the art is cut away: the black background. + for p in [[100.0, 110.0], [20.0, 60.0]] { + let [x, y] = to_comp(p); + let px = full.get(x.round() as i64, y.round() as i64); + assert!(px[0] < 0.05 && px[1] < 0.05 && px[2] < 0.05, "layer point {p:?}: {px:?}"); + } + // artC (/Rotate 90, position (1500, 800), anchor (150, 50)): After Effects draws the page + // unturned, 300 × 100, the marker at its lower left (comp 1354..1374, 836..846). + for (img, k, what) in [(&full, 1.0, "full"), (&half, 0.5, "half")] { + let at = |x: f64, y: f64| img.get((x * k).round() as i64, (y * k).round() as i64); + let marker = at(1364.0, 841.0); + assert!(blue(marker), "{what} resolution, artC marker: {marker:?}"); + for (x, y) in [(1450.0, 780.0), (1630.0, 790.0), (1364.0, 770.0)] { + let grey = at(x, y); + assert!(grey[3] > 0.99 && (grey[0] - grey[2]).abs() < 0.02 && grey[0] > 0.1 && grey[0] < 0.9, "{what} resolution, artC at ({x}, {y}): {grey:?}"); + } + } + for (x, y) in [(1340.0, 800.0), (1500.0, 870.0)] { + let px = full.get(x as i64, y as i64); + assert!(px[0] < 0.05 && px[2] < 0.05, "outside artC ({x}, {y}): {px:?}"); + } + // artD (ArtBox 210 × 120, Continuously Rasterize, the same masks, also under N2): placed by + // After Effects' toComp of its corners. + let (tl, tr, bl) = ([883.191424310055, 728.610562914909], [1126.6047325349, 793.832962280744], [827.286510567911, 937.250541393348]); + let d_to_comp = |[u, v]: [f64; 2]| [0, 1].map(|i| tl[i] + u / 210.0 * (tr[i] - tl[i]) + v / 120.0 * (bl[i] - tl[i])); + for (p, want_red) in [([60.0, 45.0], true), ([90.0, 75.0], true), ([150.0, 40.0], false), ([190.0, 80.0], false)] { + let [x, y] = d_to_comp(p); + for (img, k, what) in [(&full, 1.0, "full"), (&half, 0.5, "half")] { + let px = img.get((x * k).round() as i64, (y * k).round() as i64); + let ok = if want_red { red(px) } else { blue(px) }; + assert!(ok, "artD, {what} resolution, layer point {p:?}: {px:?} (want {})", if want_red { "red" } else { "blue" }); + } + } +} + #[test] fn ai_composition_retains_layer_sizes_and_positions() { use effectcraft_project::{ItemKind, LayerSource, Project}; diff --git a/crates/media/src/layered.rs b/crates/media/src/layered.rs index b259c8b7f..64ade9394 100644 --- a/crates/media/src/layered.rs +++ b/crates/media/src/layered.rs @@ -14,19 +14,20 @@ fn is_svg(path: &str, bytes: &[u8]) -> bool { } /// The vector document of an SVG / PDF / AI / EPS file (`None` for other formats): page -/// `page` of a PDF, restricted to the footage's layer when it names one. +/// `page` of a PDF framed as `framing` says, restricted to the footage's layer when it names one. pub fn vector_doc( path: &str, bytes: &[u8], layer: Option<&effectcraft_project::SourceLayer>, page: u32, + framing: effectcraft_pdf::Framing, ) -> Option> { if is_svg(path, bytes) { return Some(effectcraft_svg::parse(bytes).map_err(|e| format!("{path}: {e}"))); } effectcraft_pdf::sniff(bytes)?; Some( - effectcraft_pdf::parse_page(bytes, page as usize) + effectcraft_pdf::parse_page_framed(bytes, page as usize, framing) .map(|d| match layer { Some(l) => effectcraft_pdf::layer_doc_with_sizes(&d, l.index as usize, l.layer_size).0, None => d, @@ -111,14 +112,14 @@ pub(crate) fn decode(path: &str, bytes: &[u8], footage: &Footage, op: AlphaOp) - return Ok(Some(straight_to_image(px.width, px.height, &px.data, op))); } if is_svg(path, bytes) || is_pdf_like(path, bytes) { - let doc = vector_doc(path, bytes, footage.layer.as_ref(), footage.page).unwrap_or(Err(String::new())).map_err(MediaError::Decode)?; - let (w, h) = doc.pixel_size(); + let doc = footage_doc(path, bytes, footage).unwrap_or(Err(String::new())).map_err(MediaError::Decode)?; + let ((w, h), to_image) = fit(&doc, footage, 1.0); // A declared size up to 30000² would be a 14 GB allocation that aborts the app (#2136): // past what Continuously Rasterize can draw, the footage reports an error instead. if u64::from(w) * u64::from(h) > u64::from(MAX_VECTOR_SIDE) * u64::from(MAX_VECTOR_SIDE) { return Err(MediaError::Decode(format!("{path}: {w}×{h} pixels is larger than vector footage can be drawn ({MAX_VECTOR_SIDE}×{MAX_VECTOR_SIDE})"))); } - let img = effectcraft_svg::rasterize(&doc, w, h, 1.0); + let img = effectcraft_svg::rasterize_with(&doc, w, h, to_image); // The rasteriser produces premultiplied pixels already. let _ = op; return Ok(Some(img)); @@ -129,12 +130,29 @@ pub(crate) fn decode(path: &str, bytes: &[u8], footage: &Footage, op: AlphaOp) - /// The largest side vector footage is drawn at, decoded or continuously rasterised. const MAX_VECTOR_SIDE: u32 = 16384; -/// A vector file rasterised at `scale` × its pixel size (Continuously Rasterize). -pub(crate) fn rasterize_vector(path: &str, bytes: &[u8], layer: Option<&effectcraft_project::SourceLayer>, page: u32, scale: f64) -> Option { - let doc = vector_doc(path, bytes, layer, page)?.ok()?; - let (w, h) = doc.pixel_size(); - let (sw, sh) = (((w as f64 * scale).ceil() as u32).clamp(1, MAX_VECTOR_SIDE), ((h as f64 * scale).ceil() as u32).clamp(1, MAX_VECTOR_SIDE)); - Some(effectcraft_svg::rasterize(&doc, sw, sh, scale)) +/// The vector footage `footage` (of the file `path` with these `bytes`) rasterised at `scale` × +/// its size as [`effectcraft_render::vector_fit`] draws it (Continuously Rasterize). +pub(crate) fn rasterize_vector(path: &str, bytes: &[u8], footage: &Footage, scale: f64) -> Option { + let doc = footage_doc(path, bytes, footage)?.ok()?; + let ((sw, sh), to_image) = fit(&doc, footage, scale); + Some(effectcraft_svg::rasterize_with(&doc, sw.clamp(1, MAX_VECTOR_SIDE), sh.clamp(1, MAX_VECTOR_SIDE), to_image)) +} + +/// The page framing of vector footage: as After Effects places it for footage from an After +/// Effects project ([`Footage::placed_page`]), as a PDF viewer shows it otherwise. +fn framing(footage: &Footage) -> effectcraft_pdf::Framing { + if footage.placed_page { effectcraft_pdf::Framing::Placed } else { effectcraft_pdf::Framing::Viewer } +} + +/// [`vector_doc`] of `footage`'s page, layer and framing. +fn footage_doc(path: &str, bytes: &[u8], footage: &Footage) -> Option> { + vector_doc(path, bytes, footage.layer.as_ref(), footage.page, framing(footage)) +} + +/// The image size and document → image mapping of `doc` drawn for `footage` at `scale`. +fn fit(doc: &effectcraft_svg::Doc, footage: &Footage, scale: f64) -> ((u32, u32), effectcraft_svg::Affine) { + let (size, [sx, sy]) = effectcraft_render::vector_fit(footage, [doc.width, doc.height], doc.pixel_size(), scale); + (size, effectcraft_svg::Affine::scale_non_uniform(sx, sy)) } #[cfg(test)] @@ -154,4 +172,65 @@ mod tests { let img = decode("small.svg", small, &footage, AlphaOp::new(footage.alpha, footage.premul_color)).unwrap().unwrap(); assert_eq!((img.width, img.height), (40, 20)); } + + /// A 200 × 100 pt page: red left half, blue right half. + fn halves_pdf() -> Vec { + effectcraft_pdf::write::pdf( + &[ + (1, "<< /Type /Catalog /Pages 2 0 R >>".into(), None), + (2, "<< /Type /Pages /Kids [3 0 R] /Count 1 >>".into(), None), + (3, "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 200 100] /Contents 4 0 R >>".into(), None), + (4, "<< >>".into(), Some(b"1 0 0 rg 0 0 100 100 re f 0 0 1 rg 100 0 100 100 re f".to_vec())), + ], + 1, + ) + } + + /// An opaque red pixel. + fn is_red(p: [f32; 4]) -> bool { + p[3] > 0.99 && p[0] > 0.9 && p[2] < 0.1 + } + + /// An opaque blue pixel. + fn is_blue(p: [f32; 4]) -> bool { + p[3] > 0.99 && p[2] > 0.9 && p[0] < 0.1 + } + + /// #3099: an After Effects project keeps the size After Effects measured for a placed .ai or + /// PDF, which can differ from this reader's page size. A placed page fills that size (the + /// layer's anchor and masks are measured against it), decoded and continuously rasterised; + /// other footage is drawn at the page's own size as before, whatever size it says. + #[test] + fn placed_vector_footage_fills_the_footage_size() { + let pdf = halves_pdf(); + let mut footage = probe("art.ai", &pdf).unwrap().unwrap(); + assert_eq!((footage.width, footage.height), (200, 100)); + assert!(!footage.placed_page); + let op = AlphaOp::new(footage.alpha, footage.premul_color); + let own = decode("art.ai", &pdf, &footage, op).unwrap().unwrap(); + assert_eq!((own.width, own.height), (200, 100)); + assert!(is_red(own.get(50, 50)) && is_blue(own.get(150, 50))); + + (footage.width, footage.height) = (100, 80); + let unplaced = decode("art.ai", &pdf, &footage, op).unwrap().unwrap(); + assert!(unplaced == own, "not placed: drawn as before"); + assert_eq!(rasterize_vector("art.ai", &pdf, &footage, 0.5).map(|i| (i.width, i.height)), Some((100, 50))); + + footage.placed_page = true; + let img = decode("art.ai", &pdf, &footage, op).unwrap().unwrap(); + assert_eq!((img.width, img.height), (100, 80)); + for (x, y) in [(25, 3), (25, 76)] { + assert!(is_red(img.get(x, y)), "red at ({x}, {y}): {:?}", img.get(x, y)); + } + for (x, y) in [(75, 3), (75, 76)] { + assert!(is_blue(img.get(x, y)), "blue at ({x}, {y}): {:?}", img.get(x, y)); + } + + let sharp = rasterize_vector("art.ai", &pdf, &footage, 2.0).unwrap(); + assert_eq!((sharp.width, sharp.height), (200, 160)); + assert!(is_red(sharp.get(50, 155)) && is_blue(sharp.get(150, 155))); + // Placed at the page's own size: 1:1. + (footage.width, footage.height) = (200, 100); + assert!(decode("art.ai", &pdf, &footage, op).unwrap().unwrap() == own, "placed at its own size: 1:1"); + } } diff --git a/crates/media/src/pool.rs b/crates/media/src/pool.rs index a60048b66..cd6676220 100644 --- a/crates/media/src/pool.rs +++ b/crates/media/src/pool.rs @@ -42,14 +42,16 @@ fn colour_bars(w: u32, h: u32) -> Image { struct Key { path: Arc, frame: i64, - /// The alpha interpretation (bits 0–1) and how float values are encoded (bits 2–3: sRGB, - /// as stored, a 2.4 power curve): they change the decoded pixels. + /// The alpha interpretation (bits 0–1), how float values are encoded (bits 2–3: sRGB, as + /// stored, a 2.4 power curve) and a placed PDF / Illustrator page's framing (bit 4, + /// [`Footage::placed_page`]): they change the decoded pixels. interp: u8, matte: [u32; 3], /// A movie frame made at this size for a reduced-resolution render ((0, 0): as decoded). size: (u32, u32), /// A still at a reduced `size`: the footage's nominal size, which decides whether it is - /// resampled (see `Inner::still_at_size`); (0, 0) otherwise. + /// resampled (see `Inner::still_at_size`); also at its own size for a placed PDF / + /// Illustrator page, which is drawn to fill it ([`Footage::placed_page`]); (0, 0) otherwise. nominal: (u32, u32), } @@ -756,6 +758,8 @@ impl Inner { ((d.0 as i128 * rate.num as i128 + den / 2) / den) as i64 } + /// Where the frame of `footage` at `t` comes from (file, frame or media time) and its cache + /// key, at the footage's own size. fn locate(footage: &Footage, t: Tick, float: FloatCurve) -> Loc { let alpha = match footage.alpha { AlphaMode::Straight => 0, @@ -768,7 +772,8 @@ impl Inner { FloatCurve::Srgb => 0, FloatCurve::Linear => 1, FloatCurve::Gamma24 => 2, - } << 2); + } << 2) + | (u8::from(footage.placed_page) << 4); let matte = if footage.alpha == AlphaMode::Premultiplied { footage.premul_color.map(f32::to_bits) } else { [0; 3] }; let key = |path: &str, frame| Key { path: path.into(), frame, interp, matte, size: (0, 0), nominal: (0, 0) }; match footage.kind { @@ -818,6 +823,11 @@ impl Inner { loc.key.nominal = (footage.width, footage.height); } } + // A placed PDF / Illustrator page is drawn to fill the footage's size (`layered::decode`, + // #3099): two items of one file stored at different sizes have different pixels. + if footage.placed_page && !movie { + loc.key.nominal = (footage.width, footage.height); + } let mut c = lock(&self.cache); // sequential playback of a movie: read the next frame ahead if playback && movie { @@ -1041,7 +1051,7 @@ impl FootageSource for MediaPool { return None; } let bytes = self.inner.read(&footage.path).ok()?; - crate::layered::rasterize_vector(&footage.path, &bytes, footage.layer.as_ref(), footage.page, scale).map(Arc::new) + crate::layered::rasterize_vector(&footage.path, &bytes, footage, scale).map(Arc::new) } fn set_aux_footage(&self, paths: &[String]) { diff --git a/crates/pdf/README.md b/crates/pdf/README.md index 20f655611..eb960cc6e 100644 --- a/crates/pdf/README.md +++ b/crates/pdf/README.md @@ -29,7 +29,13 @@ ffmpeg elsewhere) to check the code tables against an independent implementation the app's existing object model. References retain object and generation numbers. A bounded compatibility repair recovers referenced objects from object streams when damaged xrefs omit them; every recovery or unresolved reference is reported in `Doc::skipped` (up to 64 messages). - The existing page tree preserves inherited resources, MediaBox / CropBox and `/Rotate`. + The existing page tree preserves inherited resources, MediaBox / CropBox and `/Rotate`. A page + is its CropBox (else MediaBox), turned by `/Rotate` (`Framing::Viewer`, the default). Footage + from an After Effects project is framed as After Effects places a PDF or `.ai` + (`Framing::Placed`, `parse_page_framed`): the page's own ArtBox clipped to the CropBox (else + MediaBox) when it has one, else the CropBox, else the MediaBox, with `/Rotate` ignored + (measured in After Effects 2026 with own files, #3099). Not measured: a CropBox without an + ArtBox, files saved by Illustrator itself, `.pdf` names. Content/image filters remain app-owned: Flate (with PNG predictors), LZW, ASCIIHex, ASCII85, RunLength and CCITTFax. Encrypted files remain refused; `page_count` returns zero when the reader refuses a document. diff --git a/crates/pdf/src/lib.rs b/crates/pdf/src/lib.rs index 567dca9c0..ff914e759 100644 --- a/crates/pdf/src/lib.rs +++ b/crates/pdf/src/lib.rs @@ -92,8 +92,25 @@ pub fn parse(bytes: &[u8]) -> Result { /// Parse page `index` of a PDF (EPS files have one page). pub fn parse_page(bytes: &[u8], index: usize) -> Result { + parse_page_framed(bytes, index, Framing::Viewer) +} + +/// Which region of a PDF page becomes the document, and whether `/Rotate` turns it. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub enum Framing { + /// As a PDF viewer shows the page: its CropBox (else MediaBox), turned by `/Rotate`. + #[default] + Viewer, + /// As After Effects places a PDF or `.ai` as footage: the page's ArtBox clipped to the + /// CropBox (else MediaBox) when it has one, else the CropBox, else the MediaBox, with + /// `/Rotate` ignored (measured in After Effects 2026 with own files, #3099). + Placed, +} + +/// [`parse_page`] with the page framed as `framing` says (EPS files are their bounding box). +pub fn parse_page_framed(bytes: &[u8], index: usize, framing: Framing) -> Result { match sniff(bytes) { - Some(Format::Pdf) => parse_pdf(bytes, index), + Some(Format::Pdf) => parse_pdf(bytes, index, framing), Some(Format::Eps) => parse_eps(bytes), None => Err(Error::NotVector), } @@ -142,17 +159,22 @@ fn finish(nodes: Vec, flags: Vec, skipped: Vec, width: f64, Doc { width, height, root, skipped } } -fn parse_pdf(bytes: &[u8], index: usize) -> Result { +/// Page `index` of a PDF framed as `framing` says, as a document in points (y down). +fn parse_pdf(bytes: &[u8], index: usize, framing: Framing) -> Result { let file = object::File::parse(bytes)?; let pages = page::pages(&file); if pages.is_empty() { return Err(Error::NoPages); } let pg = pages.get(index).ok_or(Error::PageOutOfRange(index))?; - let [x0, y0, x1, y1] = pg.bbox; + let (frame, rotate) = match framing { + Framing::Viewer => (pg.bbox, pg.rotate), + Framing::Placed => (pg.art.unwrap_or(pg.bbox), 0), + }; + let [x0, y0, x1, y1] = frame; let (w, h) = (x1 - x0, y1 - y0); // Default user space (y up) → document pixels (y down), with the page's /Rotate. - let (to_doc, dw, dh) = match pg.rotate { + let (to_doc, dw, dh) = match rotate { 90 => (Affine::new([0.0, 1.0, 1.0, 0.0, -y0, -x0]), h, w), 180 => (Affine::new([-1.0, 0.0, 0.0, 1.0, x1, -y0]), w, h), 270 => (Affine::new([0.0, -1.0, -1.0, 0.0, y1, x1]), h, w), diff --git a/crates/pdf/src/page.rs b/crates/pdf/src/page.rs index b7eb70fe0..0ebc0421d 100644 --- a/crates/pdf/src/page.rs +++ b/crates/pdf/src/page.rs @@ -23,6 +23,9 @@ pub struct Page { pub resources: Dict, /// CropBox (else MediaBox) `[x0, y0, x1, y1]`. pub bbox: [f64; 4], + /// The page's own ArtBox clipped to [`Page::bbox`] (ISO 32000-1 §14.11.2), when it has one + /// that keeps an area there; not inherited (table 30). + pub art: Option<[f64; 4]>, pub rotate: i32, } @@ -31,13 +34,15 @@ pub fn pages(file: &File) -> Vec { let mut out = vec![]; let Some(cat) = file.catalog() else { return out }; let Some(root) = file.get_dict(cat, "Pages") else { return out }; + /// Collects the pages under `node`, passing on the attributes pages inherit (resources, + /// MediaBox, CropBox, /Rotate); bounded in depth and page count. fn walk(file: &File, node: &Dict, inherited: (Option, Option>, Option>, i32), out: &mut Vec, depth: usize) { if depth > 32 || out.len() > 10_000 { return; } let res = file.get_dict(node, "Resources").cloned().or(inherited.0); - let media = file.get(node, "MediaBox").map(|m| file.nums(m)).filter(|v| v.len() == 4).or(inherited.1); - let crop = file.get(node, "CropBox").map(|m| file.nums(m)).filter(|v| v.len() == 4).or(inherited.2); + let media = file.get(node, "MediaBox").map(|m| file.nums(m)).filter(|v| is_area(v)).or(inherited.1); + let crop = file.get(node, "CropBox").map(|m| file.nums(m)).filter(|v| is_area(v)).or(inherited.2); let rot = file.get_num(node, "Rotate").map(|r| r as i32).unwrap_or(inherited.3); match file.get(node, "Kids").and_then(Obj::array) { Some(kids) if file.get(node, "Type").and_then(Obj::name) != Some("Page") => { @@ -49,8 +54,16 @@ pub fn pages(file: &File) -> Vec { } _ => { let b = crop.or(media).unwrap_or_else(|| vec![0.0, 0.0, 612.0, 792.0]); - let bbox = [b[0].min(b[2]), b[1].min(b[3]), b[0].max(b[2]), b[1].max(b[3])]; - out.push(Page { dict: node.clone(), resources: res.unwrap_or_default(), bbox, rotate: rot.rem_euclid(360) }); + let bbox = normalized(&b).unwrap_or([0.0, 0.0, 612.0, 792.0]); + // The ArtBox is the page's own (not inherited), clipped to the crop box. + let art = file + .get(node, "ArtBox") + .map(|m| file.nums(m)) + .filter(|v| is_area(v)) + .and_then(|v| normalized(&v)) + .map(|a| [a[0].max(bbox[0]), a[1].max(bbox[1]), a[2].min(bbox[2]), a[3].min(bbox[3])]) + .filter(|a| a[2] > a[0] && a[3] > a[1]); + out.push(Page { dict: node.clone(), resources: res.unwrap_or_default(), bbox, art, rotate: rot.rem_euclid(360) }); } } } @@ -58,6 +71,26 @@ pub fn pages(file: &File) -> Vec { out } +/// A box `[x0, y0, x1, y1]` (corners in any order) with finite corners and a finite span that +/// encloses an area. +fn is_area(v: &[f64]) -> bool { + match v { + [x0, y0, x1, y1] => { + let (w, h) = (x1 - x0, y1 - y0); + v.iter().all(|c| c.is_finite()) && w.is_finite() && h.is_finite() && w.abs() > 0.0 && h.abs() > 0.0 + } + _ => false, + } +} + +/// A box with its corners ordered (`x0 < x1`, `y0 < y1`), `None` unless [`is_area`]. +fn normalized(v: &[f64]) -> Option<[f64; 4]> { + match v { + [x0, y0, x1, y1] if is_area(v) => Some([x0.min(*x1), y0.min(*y1), x0.max(*x1), y0.max(*y1)]), + _ => None, + } +} + /// The page's content streams, decoded and joined. pub fn page_content(file: &File, page: &Page) -> Vec { let mut out = vec![]; diff --git a/crates/pdf/src/tests.rs b/crates/pdf/src/tests.rs index 2d09a7406..cd3eecdb2 100644 --- a/crates/pdf/src/tests.rs +++ b/crates/pdf/src/tests.rs @@ -112,6 +112,86 @@ fn pdf_forms_rotation_cmyk_and_alpha() { assert_eq!(img.get(30, 30)[3], 0.0, "form clipped to its bounding box"); } +/// A one-page PDF with a MediaBox [0 0 420 220], `pages` added to the /Pages node and `page` to +/// the page: grey over the media box, a blue 20 × 10 marker at PDF (64, 54). +fn boxes_pdf(pages: &str, page: &str) -> Vec { + let content = "0.5 g 0 0 420 220 re f 0 0 1 rg 64 54 20 10 re f"; + pdf( + &[ + (1, "<< /Type /Catalog /Pages 2 0 R >>".to_string(), None), + (2, format!("<< /Type /Pages /Kids [3 0 R] /Count 1 {pages} >>"), None), + (3, format!("<< /Type /Page /Parent 2 0 R /MediaBox [0 0 420 220] {page} /Contents 4 0 R >>"), None), + (4, "<< >>".to_string(), Some(content.as_bytes().to_vec())), + ], + 1, + ) +} + +/// The first page of `bytes` framed as After Effects places it. +fn placed(bytes: &[u8]) -> Doc { + parse_page_framed(bytes, 0, Framing::Placed).unwrap() +} + +/// #3099: After Effects 2026 places a .ai or PDF as footage by the page's ArtBox and shows only +/// that region (a page with MediaBox 420 × 220, CropBox 410 × 210, TrimBox 380 × 180 and ArtBox +/// [60 50 300.6 170.4] imports as 241 × 121). `Framing::Placed` frames it so; the viewer framing +/// (the default, used by File ▸ Import) stays the CropBox. +#[test] +fn placed_framing_is_the_art_box() { + let bytes = boxes_pdf("/CropBox [5 5 415 215]", "/TrimBox [20 20 400 200] /ArtBox [60 50 300.6 170.4]"); + let doc = placed(&bytes); + assert!((doc.width - 240.6).abs() < 1e-9 && (doc.height - 120.4).abs() < 1e-9, "{} × {}", doc.width, doc.height); + assert_eq!(doc.pixel_size(), (241, 121)); + // The art box's top-left corner is the document's origin: the marker (PDF x 64..84, y 54..64) + // is at x 4..24, y 106.4..116.4 from the top. + let (w, h) = doc.pixel_size(); + let img = effectcraft_svg::rasterize(&doc, w, h, 1.0); + let marker = img.get(10, 110); + assert!(marker[2] > 0.99 && marker[0] < 0.01, "{marker:?}"); + assert!(img.get(30, 110)[2] < 0.6, "{:?}", img.get(30, 110)); + let viewer = parse(&bytes).unwrap(); + assert_eq!((viewer.width, viewer.height), (410.0, 210.0), "the viewer framing is unchanged"); +} + +/// The ArtBox is clipped to the crop box (ISO 32000-1 §14.11.2); one that keeps no area there, +/// a degenerate or unreadable one, or one on the /Pages node (not inherited, table 30) leaves the +/// crop box (else the media box). +#[test] +fn placed_framing_clips_the_art_box_and_falls_back() { + let size = |pages: &str, page: &str| { + let d = placed(&boxes_pdf(pages, page)); + (d.width, d.height) + }; + let crop = "/CropBox [5 5 415 215]"; + assert_eq!(size(crop, "/ArtBox [-100 -100 1000 1000]"), (410.0, 210.0), "larger than the page"); + assert_eq!(size(crop, "/ArtBox [300 100 900 900]"), (115.0, 115.0), "partly outside"); + let (w, h) = size(crop, "/ArtBox [300.6 170.4 60 50]"); + assert!((w - 240.6).abs() < 1e-9 && (h - 120.4).abs() < 1e-9, "corners in any order: {w} × {h}"); + // Finite corners whose span is not. + let big = format!("1{}", "0".repeat(308)); + let unreadable = [format!("/ArtBox [-{big} 50 {big} 170]")]; + for page in ["/ArtBox [500 300 600 400]", "/ArtBox [60 50 60 170]", "/ArtBox [60 50 300]"].map(String::from).iter().chain(&unreadable) { + assert_eq!(size(crop, page), (410.0, 210.0), "{page}"); + } + assert_eq!(size("/ArtBox [60 50 300 170]", ""), (420.0, 220.0), "an ArtBox on /Pages is not inherited"); + // A crop box that is not a box leaves the media box. + assert_eq!(size("", &format!("/CropBox [-{big} 5 {big} 215]")), (420.0, 220.0)); +} + +/// After Effects ignores /Rotate on placed footage (a page [100 50 400 150] with /Rotate 90 +/// imports as 300 × 100, drawn unturned); the viewer framing turns it. +#[test] +fn placed_framing_ignores_rotate() { + let bytes = boxes_pdf("", "/Rotate 90"); + let doc = placed(&bytes); + assert_eq!((doc.width, doc.height), (420.0, 220.0)); + // Unturned: the marker at PDF (64..84, 54..64) is at x 64..84, y 156..166 from the top. + let img = effectcraft_svg::rasterize(&doc, 420, 220, 1.0); + assert!(img.get(70, 160)[2] > 0.99, "{:?}", img.get(70, 160)); + let viewer = parse(&bytes).unwrap(); + assert_eq!((viewer.width, viewer.height), (220.0, 420.0)); +} + const EPS: &str = "%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 100 100\n%%EndComments\n\ /m {moveto} bind def /l {lineto} bind def\n\ /cm { 6 array astore concat } bind def\n\ diff --git a/crates/project/src/footage.rs b/crates/project/src/footage.rs index 2cf887b1f..eeace5e81 100644 --- a/crates/project/src/footage.rs +++ b/crates/project/src/footage.rs @@ -269,6 +269,13 @@ pub struct Footage { /// made from the footage starts with them, and Update Markers From Source copies new ones. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub markers: Vec, + /// PDF / Illustrator footage (`.pdf`, `.ai`; not EPS) from an After Effects project: the page + /// is framed as After Effects places it (the ArtBox, `/Rotate` ignored) and drawn to fill + /// `width` × `height`, the size After Effects stored, which the layers' anchors and masks are + /// measured against (#3099). Other footage (and every project saved before this field) shows + /// the page as a PDF viewer does, at its own size. + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub placed_page: bool, } fn is_default(v: &T) -> bool { @@ -307,6 +314,7 @@ impl Default for Footage { start_timecode: None, file_timecode: None, markers: vec![], + placed_page: false, } } } diff --git a/crates/render/src/footage.rs b/crates/render/src/footage.rs index 0e17f152d..6b7fdcbf8 100644 --- a/crates/render/src/footage.rs +++ b/crates/render/src/footage.rs @@ -76,8 +76,9 @@ pub trait FootageSource: Send + Sync { fn cache_budget(&self) -> Option { None } - /// Vector footage (SVG) rasterised at `scale` × its pixel size, for Continuously Rasterize. - /// `None` when the footage is not vector or cannot be read. + /// Vector footage (SVG, PDF, Illustrator, EPS: [`is_vector_footage`]) rasterised at `scale` × + /// its size as [`vector_fit`] draws it, for Continuously Rasterize. `None` when the footage + /// is not vector or cannot be read. fn vector_frame(&self, _item: ItemId, _footage: &Footage, _scale: f64) -> Option> { None } @@ -216,9 +217,31 @@ impl FootageSource for CancellableFootage<'_> { } } -/// Footage that can be rasterised at any scale (SVG). +/// Footage that can be rasterised at any scale: SVG, PDF, Illustrator and EPS files, and a +/// placed page of an After Effects project (its codec is not stored there). pub fn is_vector_footage(f: &Footage) -> bool { - matches!(f.codec.as_str(), "SVG" | "PDF" | "AI" | "EPS") + matches!(f.codec.as_str(), "SVG" | "PDF" | "AI" | "EPS") || f.placed_page +} + +/// How vector footage `f` is drawn at `scale` × its size: the image size, and the x and y scale +/// from document pixels (`doc` = the document's width and height, `own` = its pixel size, the +/// size rounded up) to image pixels. +/// +/// Footage from an After Effects project ([`Footage::placed_page`]) fills its stored size, which +/// can round or measure the page differently: the layer's anchor and masks are measured against +/// that size, and the renderer resamples a reduced-resolution frame to it, so drawn at its own +/// size the art was scaled by the width ratio alone at full resolution (off against the masks) +/// and stretched to the stored aspect below 3/4 resolution (#3099). Other footage is drawn 1:1 at +/// the document's own size, as it always was. +pub fn vector_fit(f: &Footage, doc: [f64; 2], own: (u32, u32), scale: f64) -> ((u32, u32), [f64; 2]) { + let scale = if scale.is_finite() && scale > 0.0 { scale } else { 1.0 }; + let side = |px: u32| (f64::from(px) * scale).ceil().clamp(1.0, f64::from(u32::MAX)) as u32; + let size = (f.width, f.height); + let fills = f.placed_page && size != own && size.0 > 0 && size.1 > 0 && doc.iter().all(|d| d.is_finite() && *d > 0.0); + if !fills { + return ((side(own.0), side(own.1)), [scale, scale]); + } + ((side(size.0), side(size.1)), [scale * f64::from(size.0) / doc[0], scale * f64::from(size.1) / doc[1]]) } /// No footage available (renders footage layers as transparent). diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index e09794de2..65f3ee772 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -47,7 +47,7 @@ mod opts; mod pipeline; pub use accel::{Accelerator, Backend, FxStep, FxTarget}; -pub use footage::{CancellableFootage, FloatCurve, FootageSource, NoFootage, is_vector_footage, missing_item_problem}; +pub use footage::{CancellableFootage, FloatCurve, FootageSource, NoFootage, is_vector_footage, missing_item_problem, vector_fit}; pub use frames::{ adaptive_samples, blend_frames, cineon_frame, content_bounds, extended_region, field_frame, frame_position, frame_size, interpret_pixels, kurbo_path, render_frame, roi_inside, diff --git a/docs/aep-import.md b/docs/aep-import.md index 8a83de81f..f41ba3081 100644 --- a/docs/aep-import.md +++ b/docs/aep-import.md @@ -135,7 +135,15 @@ Units, the "absent = default" rule and the keyframe templates are the reader's text does not have; the runs are cut to the text. A range style splits `Hello` into runs of 1, 2 and 2 characters (248, 340). - **Null objects.** The hidden placeholder solid of a null object is not an item (null layers - have no source item here). + have no source item here). A null's Anchor Point that is not stored is its top-left corner + `[0, 0]`, not the centre, as After Effects 2026 reads it back (#3099). +- **Placed Illustrator and PDF files** (`.ai`, `.pdf`; `Footage::placed_page`): the page is + framed as After Effects places it (the ArtBox clipped to the crop box, `/Rotate` ignored) and + drawn to fill the stored footage size, which masks and anchors are measured against (#3099). + Create Shapes from Vector Layer on such a layer adds a hidden ` Frame` shape layer, the + Alpha track matte of every layer it makes, so they show only the frame, as the footage does. + EPS files keep their bounding box at their own size: how After Effects sizes them is not + measured. - **Track mattes.** The mode and the matte layer's id are in the target layer's header (aep-format.md 3.1). The matte layer can be any layer of the composition (407: below its target); it keeps its stored video switch (After Effects switches it off when the matte is set, diff --git a/docs/gaps.md b/docs/gaps.md index d481f9810..d9de84675 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -266,6 +266,12 @@ Issues #41–#47 (all from the Linux AppImage 0.1.1, 5 October): panning the vie The second means reading another implementation of the format, which AGENTS.md rules out unless the clean-room scope allows it. - Also in this area: relative footage paths and relinking when a project moves (gap 18). +- Placed PDF / Illustrator footage of an `.aep` is framed as After Effects places it (the ArtBox + clipped to the crop box, `/Rotate` ignored) and drawn to fill the size After Effects stored + (#3099), measured with hand-written PDFs named `.ai`. Not yet measured: files saved by + Illustrator itself (artboards, bleed, art past the artboard, private data), a CropBox without + an ArtBox, `.pdf` names, and EPS files (they keep their bounding box at their own size, not + the placed framing). - Done when: the decision is recorded and, if approved, a corpus of real-world-shaped projects opens with its comps, layers, keyframes, effects and expressions intact. From 91f35c73e1d17a45e854b7e8306e735ff151db6e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 8 Nov 2026 20:01:20 -0800 Subject: [PATCH 40/40] Updates: restart from the update result dialog --- crates/ui-egui/src/updates_ui.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ui-egui/src/updates_ui.rs b/crates/ui-egui/src/updates_ui.rs index bb8187f56..316e34ac4 100644 --- a/crates/ui-egui/src/updates_ui.rs +++ b/crates/ui-egui/src/updates_ui.rs @@ -91,6 +91,7 @@ pub(crate) fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { rt.updater.dismiss_status(); } CheckResultResponse::CheckAgain => rt.updater.check_now(ctx), + CheckResultResponse::RestartToUpdate => rt.updater.restart_to_update(), } // A check that found a release leaves the status idle and the startup prompt takes over. if matches!(rt.updater.status(), Status::Idle) && !rt.check_requested {