forge
Explore
Log in

Don't you dare go Hollow

Clips can be moved, scaled, rotated and cropped (edith 20)

Browse files at this commit

684b8a4331b321bfe137bea0252075e6ef3e25c7Ahmet Kaan GümüşParent: f4e379f
  • feat
    • clips can be moved, scaled, rotated and cropped (edith 20)
Show full message
✨ feat(engine): clips can be moved, scaled, rotated and cropped (edith 20)

Per-clip TransformParams (position, scale, 90-degree rotation, crop)
shared through a colour-style table, applied in both the playback
preview and the export compositor, persisted as the edith 20 dialect;
v19 files load untransformed.
crates/engine/src/edith.rsmodified+183 -9
@@ -16,9 +16,10 @@
1616 //! subtitle 3 test_av.mp4
1717 //! eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk
1818 //! color 0.1:1.2:0.9:-0.3
19-//! video 1 0 0 120 0 0 0 0 fit 1000 0 0
20-//! audio 1 0 0 120 0 0 0 - fit 1000 30 30
21-//! video 2 120 0 120 1 - - - fill 2000 0 0
19+//! transform 0.1:-0.1:1.5:90.0:0.0:0.0:0.0:0.0
20+//! video 1 0 0 120 0 0 0 0 fit 1000 0 0 0 -
21+//! audio 1 0 0 120 0 0 0 - fit 1000 30 30 0 -
22+//! video 2 120 0 120 1 - - - fill 2000 0 0 0 0
2223 //! audio 2
2324 //! sub 1 0 60 0 500000 1500000
2425 //! sub 2
@@ -109,8 +110,16 @@
109110 //! ([`crate::color::ColorParams`]), named by position exactly as an eq line is
110111 //! -- the first colour line is color 0 -- printed and refused by the same rules.
111112 //!
113+//! A transform line is `transform <pos_x>:<pos_y>:<scale>:<rotate>:<crop_l>:
114+//! <crop_r>:<crop_t>:<crop_b>` ([`crate::transform::TransformParams`]), named by
115+//! position exactly as an eq or a colour line is -- the first transform line is
116+//! transform 0 -- printed and refused by the same rules: how a clip's picture
117+//! sits, is sized, is turned and is trimmed on the canvas, on top of whatever
118+//! its fit policy already placed.
119+//!
112120 //! A lane line is `<kind> <lane> <start> <in> <out> <source> <link> <eq>
113-//! <color> <fit> <speed> <fade_in> <fade_out> <transition_out>`: which lane the clip is on -- its kind and its 1-based number
121+//! <color> <fit> <speed> <fade_in> <fade_out> <transition_out> <transform>`:
122+//! which lane the clip is on -- its kind and its 1-based number
114123 //! among the lanes of that kind, the [`crate::project::Lane::label`] a header
115124 //! column shows -- then where the clip sits on the timeline, the half-open
116125 //! source range it plays, the file it plays from, its group id, the eq line it
@@ -120,9 +129,12 @@
120129 //! in thousandths of real time ([`crate::project::Speed`], `1000` for a clip
121130 //! nobody has speeded), and finally its ramp up from silence and ramp down to
122131 //! it, in timeline frames ([`crate::project::Clip::fade_in`],
123-//! [`crate::project::Clip::fade_out`], `0 0` for a clip nobody has faded), and
124-//! finally its cross-dissolve into whatever abuts its end
125-//! ([`crate::project::Clip::transition_out`], `0` for a hard cut).
132+//! [`crate::project::Clip::fade_out`], `0 0` for a clip nobody has faded), its
133+//! cross-dissolve into whatever abuts its end
134+//! ([`crate::project::Clip::transition_out`], `0` for a hard cut), and last of
135+//! all the transform line it is placed, sized, turned and cropped by, on top
136+//! of everything its fit policy already did (`-` for a clip left at its fit
137+//! policy's own spot, [`crate::project::Clip::transform`]).
126138 //! Timeline placement is
127139 //! explicit, so a *gap* is simply a stretch no line covers -- there is nothing
128140 //! to write for one, and nothing that can disagree about its length. The `<in>`
@@ -148,7 +160,11 @@
148160 //! track 3 of a two-track palette is refused here, as a clip naming a source
149161 //! that is not there is.
150162 //!
151-//! **Version 17** was this without the clip's two fade fields: such a project
163+//! **Version 19** was this without the clip's transform field: such a project
164+//! places no clip anywhere but its fit policy's own spot, which is what `-`
165+//! still means. **Version 18** was that without the clip's transition field:
166+//! such a project dissolves no clip into its neighbor, which is what `0` still
167+//! means. **Version 17** was this without the clip's two fade fields: such a project
152168 //! holds no clip anyone has faded, which is what a `0 0` pair still means.
153169 //! **Version 15** was this without the caption's group field: such a project
154170 //! holds captions no hand ever grouped, which is every caption there could be.
@@ -187,7 +203,7 @@
187203 //! nothing, and an older one plays everything at real time, and an older one
188204 //! mixes flat, and an older one shows no subtitles, and an older one is shown
189205 //! in the reference rendition, and an older one places none of the words it
190-//! names -- and saving any of them writes v18. An older
206+//! names -- and saving any of them writes v20. An older
191207 //! reader refuses a newer file by name.
192208 //!
193209 //! Text because an edit list is a few integers and a path, and a path is
@@ -2602,6 +2618,164 @@ mod tests {
26022618 );
26032619 }
26042620
2621+ /// A v19 file is a v20 one that places no clip anywhere but its fit
2622+ /// policy's own spot: it loads with every clip's [`Clip::transform`] at
2623+ /// `None`, which is what a v19 file's missing field still means.
2624+ #[test]
2625+ fn a_v19_file_loads_untransformed() {
2626+ let dir = PathBuf::from("/proj");
2627+ // The v19 dialect: twelve clip fields, the last the transition -- no
2628+ // transform field after it at all, not even a `-`.
2629+ let v19 = b"edith 19\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2630+ video 1 0 0 30 0 - - - fit 1000 0 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0 0\n";
2631+ let old = parse(v19, &dir).expect("v19 parses");
2632+ assert!(old.transform.is_empty(), "nothing before v20 has a table");
2633+ assert!(
2634+ old.lanes
2635+ .iter()
2636+ .flat_map(|(_, clips)| clips)
2637+ .all(|c| c.transform.is_none()),
2638+ "nothing before v20 had a placement to name"
2639+ );
2640+ }
2641+
2642+ /// [`colours_round_trip_bit_exactly_and_are_shared`]'s twin: two clips
2643+ /// sharing one transform table entry write it once, and both bytes and
2644+ /// values come back bit-exact.
2645+ #[test]
2646+ fn transforms_round_trip_bit_exactly_and_are_shared() {
2647+ let dir = PathBuf::from("/proj");
2648+ let sources = vec![source("/proj/a.mp4", 0)];
2649+ let transform = vec![
2650+ TransformParams {
2651+ pos_x: 0.1,
2652+ pos_y: -0.2,
2653+ scale: 1.5,
2654+ rotate: 90.0,
2655+ crop_l: 0.1,
2656+ crop_r: 0.0,
2657+ crop_t: 0.0,
2658+ crop_b: 0.05,
2659+ },
2660+ // The awkward ones again: all 24 mantissa bits, an exponential
2661+ // spelling, a subnormal and a negative zero -- and the identity,
2662+ // which is a setting like any other.
2663+ TransformParams {
2664+ pos_x: -0.000_000_1,
2665+ pos_y: 16_777_215.0,
2666+ scale: f32::MIN_POSITIVE / 3.0,
2667+ rotate: -0.0,
2668+ crop_l: 0.0,
2669+ crop_r: 0.0,
2670+ crop_t: 0.0,
2671+ crop_b: 0.0,
2672+ },
2673+ TransformParams::default(),
2674+ ];
2675+ // Two clips share entry 0, so it is written once; one clip is untransformed.
2676+ let lanes = two(
2677+ vec![
2678+ Clip {
2679+ fade_in: 0,
2680+ fade_out: 0,
2681+ transition_out: 0,
2682+ transform: Some(0),
2683+ fit: FitPolicy::default(),
2684+ speed: Speed::NORMAL,
2685+ ..clip(0, 0, 30, 0, Some(0))
2686+ },
2687+ Clip {
2688+ fade_in: 0,
2689+ fade_out: 0,
2690+ transition_out: 0,
2691+ transform: Some(1),
2692+ fit: FitPolicy::default(),
2693+ speed: Speed::NORMAL,
2694+ ..clip(30, 10, 20, 0, None)
2695+ },
2696+ ],
2697+ vec![
2698+ Clip {
2699+ fade_in: 0,
2700+ fade_out: 0,
2701+ transition_out: 0,
2702+ transform: Some(0),
2703+ fit: FitPolicy::default(),
2704+ speed: Speed::NORMAL,
2705+ ..clip(0, 0, 30, 0, Some(0))
2706+ },
2707+ Clip {
2708+ fade_in: 0,
2709+ fade_out: 0,
2710+ transition_out: 0,
2711+ transform: Some(2),
2712+ fit: FitPolicy::default(),
2713+ speed: Speed::NORMAL,
2714+ ..clip(30, 0, 10, 0, None)
2715+ },
2716+ ],
2717+ );
2718+ let bytes = super::emit(
2719+ &dir,
2720+ &sources,
2721+ &lanes,
2722+ &[],
2723+ &[],
2724+ &[],
2725+ &[],
2726+ &[],
2727+ &transform,
2728+ (1280, 720),
2729+ None,
2730+ crate::tonemap::Preset::default(),
2731+ false,
2732+ true,
2733+ crate::export::EncoderSeat::default(),
2734+ Limiter::default(),
2735+ None,
2736+ 0,
2737+ );
2738+ assert_eq!(
2739+ String::from_utf8_lossy(&bytes),
2740+ "edith 20\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2741+ transform 0.1:-0.2:1.5:90.0:0.1:0.0:0.0:0.05\n\
2742+ transform -1e-7:16777215.0:3.918315e-39:-0.0:0.0:0.0:0.0:0.0\n\
2743+ transform 0.0:0.0:1.0:0.0:0.0:0.0:0.0:0.0\n\
2744+ video 1 0 0 30 0 0 - - fit 1000 0 0 0 0\nvideo 1 30 10 20 0 - - - fit 1000 0 0 0 1\n\
2745+ audio 1 0 0 30 0 0 - - fit 1000 0 0 0 0\naudio 1 30 0 10 0 - - - fit 1000 0 0 0 2\n",
2746+ "the table comes before the clips, and a clip names a line of it"
2747+ );
2748+
2749+ let back = parse(&bytes, &dir).expect("parse");
2750+ assert_eq!(back.lanes, lanes, "every clip keeps the transform it named");
2751+ for (i, (got, want)) in back.transform.iter().zip(&transform).enumerate() {
2752+ assert_eq!(
2753+ (
2754+ got.pos_x.to_bits(),
2755+ got.pos_y.to_bits(),
2756+ got.scale.to_bits(),
2757+ got.rotate.to_bits(),
2758+ got.crop_l.to_bits(),
2759+ got.crop_r.to_bits(),
2760+ got.crop_t.to_bits(),
2761+ got.crop_b.to_bits(),
2762+ ),
2763+ (
2764+ want.pos_x.to_bits(),
2765+ want.pos_y.to_bits(),
2766+ want.scale.to_bits(),
2767+ want.rotate.to_bits(),
2768+ want.crop_l.to_bits(),
2769+ want.crop_r.to_bits(),
2770+ want.crop_t.to_bits(),
2771+ want.crop_b.to_bits(),
2772+ ),
2773+ "transform {i} came back as other bits"
2774+ );
2775+ }
2776+ assert_eq!(back.transform.len(), 3);
2777+ }
2778+
26052779 /// The whole of the v9 bump, the speed test's twin: the mix a project was
26062780 /// left at -- every track's own volume and the master limiter -- plus the
26072781 /// rate it was cut at, all written, all read back as the very numbers, and
crates/engine/src/project.rsmodified+146 -2
@@ -5330,6 +5330,15 @@ mod tests {
53305330 }
53315331 }
53325332
5333+ /// A recognisable placement, `n` telling two of them apart -- [`grade_at`]'s
5334+ /// twin for the transform table.
5335+ fn transform_at(n: u32) -> TransformParams {
5336+ TransformParams {
5337+ pos_x: f64::from(n) as f32 * 0.05,
5338+ ..Default::default()
5339+ }
5340+ }
5341+
53335342 /// The `V1`, `A1` lane list a two-lane load hands [`Project::from_parts`].
53345343 fn two(video: Vec<Clip>, audio: Vec<Clip>) -> Vec<(LaneKind, Vec<Clip>)> {
53355344 vec![(LaneKind::Video, video), (LaneKind::Audio, audio)]
@@ -8104,6 +8113,125 @@ mod tests {
81048113 assert_eq!((lanes[0].1[0].eq, lanes[0].1[0].color), (Some(0), Some(0)));
81058114 }
81068115
8116+ /// [`a_colour_follows_the_clip_through_split_copy_and_undo`]'s twin: a
8117+ /// placement is the clip's, through every edit that copies one.
8118+ #[test]
8119+ fn a_transform_follows_the_clip_through_split_copy_and_undo() {
8120+ let mut p = three();
8121+ assert!(
8122+ p.transform_of(Lane::V1, 0).is_none(),
8123+ "a fresh clip is untransformed"
8124+ );
8125+ assert!(p.set_transform(Lane::V1, 0, Some(transform_at(2))));
8126+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(2)));
8127+ assert!(
8128+ p.transform_of(Lane::A1, 0).is_none(),
8129+ "one clip, not the lane below"
8130+ );
8131+ assert!(
8132+ p.color_of(Lane::V1, 0).is_none(),
8133+ "and a placement is not a grade"
8134+ );
8135+
8136+ // Cutting a transformed clip must not transform half of it: both
8137+ // halves inherit.
8138+ assert!(p.split(1));
8139+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(2)));
8140+ assert_eq!(p.transform_of(Lane::V1, 1), Some(&transform_at(2)));
8141+ assert!(
8142+ p.transform_of(Lane::V1, 2).is_none(),
8143+ "the clip after it is untransformed"
8144+ );
8145+
8146+ // A clipboard copy carries it -- onto another lane, at that.
8147+ let copied = p.lane(Lane::V1)[1];
8148+ assert!(p.place(Lane::A1, 20, copied));
8149+ assert_eq!(p.transform_of(Lane::A1, 4), Some(&transform_at(2)));
8150+ assert!(p.undo());
8151+ assert_eq!(p.lane(Lane::A1).len(), 4, "the placement came back off");
8152+
8153+ // ...and a change to one is one undo step, in both directions.
8154+ assert!(p.set_transform(Lane::V1, 0, Some(transform_at(5))));
8155+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(5)));
8156+ assert!(p.undo());
8157+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(2)));
8158+ assert!(
8159+ p.set_transform(Lane::V1, 0, None),
8160+ "and taking it off is an edit"
8161+ );
8162+ assert!(p.transform_of(Lane::V1, 0).is_none());
8163+ assert!(p.undo());
8164+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(2)));
8165+
8166+ // Two refusals, neither of which costs an undo step.
8167+ let nan = TransformParams {
8168+ scale: f32::NAN,
8169+ ..transform_at(1)
8170+ };
8171+ assert!(
8172+ !p.set_transform(Lane::V1, 99, Some(transform_at(1))),
8173+ "no clip there"
8174+ );
8175+ assert!(
8176+ !p.set_transform(Lane::V1, 0, Some(nan)),
8177+ "not a finite value"
8178+ );
8179+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(2)));
8180+ assert!(p.undo());
8181+ assert_eq!(
8182+ p.lane(Lane::V1).len(),
8183+ 3,
8184+ "one step back is before the split"
8185+ );
8186+ assert!(p.undo());
8187+ assert!(
8188+ p.transform_of(Lane::V1, 0).is_none(),
8189+ "and the next is before the placement: the refusals pushed none"
8190+ );
8191+ }
8192+
8193+ /// The transform table is append-only within a session, exactly as the eq
8194+ /// and colour ones are -- and a save is where an undone placement goes.
8195+ #[test]
8196+ fn an_undone_transform_is_pruned_when_the_project_is_saved() {
8197+ let mut p = three();
8198+ assert!(p.set_transform(Lane::V1, 0, Some(transform_at(1))));
8199+ assert!(p.set_transform(Lane::V1, 0, Some(transform_at(2))));
8200+ assert!(p.undo(), "back to the first placement");
8201+ assert_eq!(p.transform_of(Lane::V1, 0), Some(&transform_at(1)));
8202+
8203+ let (_, lanes, _, _, transform) = p.without_orphan_sources();
8204+ assert_eq!(
8205+ transform,
8206+ vec![transform_at(1)],
8207+ "what nothing plays is not written"
8208+ );
8209+ assert_eq!(
8210+ lanes[0].1[0].transform,
8211+ Some(0),
8212+ "and the survivor renumbers"
8213+ );
8214+ assert_eq!(lanes[0].1[1].transform, None);
8215+
8216+ // One placement on three clips is one entry: settings that are equal
8217+ // share.
8218+ assert!(p.set_transform(Lane::V1, 1, Some(transform_at(1))));
8219+ assert!(p.set_transform(Lane::A1, 2, Some(transform_at(1))));
8220+ let (_, lanes, _, _, transform) = p.without_orphan_sources();
8221+ assert_eq!(transform.len(), 1, "equal placements share their entry");
8222+ assert_eq!(lanes[1].1[2].transform, Some(0));
8223+ reloads(&p, "a transform that outlived an undo");
8224+
8225+ // A grade and a placement on one clip are two independent tables.
8226+ assert!(p.set_color(Lane::V1, 0, Some(grade_at(3))));
8227+ let (_, lanes, _, color, transform) = p.without_orphan_sources();
8228+ assert_eq!((color.len(), transform.len()), (1, 1));
8229+ assert_eq!(
8230+ (lanes[0].1[0].color, lanes[0].1[0].transform),
8231+ (Some(0), Some(0))
8232+ );
8233+ }
8234+
81078235 /// Not a claim about correctness but about cost: a clip is copied on every
81088236 /// paste, every undo snapshot and every lane clone, so its size is worth
81098237 /// knowing. The eq index fit the padding a `Copy` clip already had; the
@@ -8763,8 +8891,8 @@ mod tests {
87638891 /// handed back to the constructor a load goes through -- every lane of them,
87648892 /// and the reloaded timeline has to be the same lanes in the same order.
87658893 fn reloads(p: &Project, what: &str) {
8766- let (sources, lanes, eq, color, _transform) = p.clone().without_orphan_sources();
8767- match Project::from_parts(sources, lanes, eq, color, Vec::new()) {
8894+ let (sources, lanes, eq, color, transform) = p.clone().without_orphan_sources();
8895+ match Project::from_parts(sources, lanes, eq, color, transform) {
87688896 Err(e) => panic!("{what}: saved but would not load: {e}\n{:?}", p.lanes),
87698897 Ok(back) => {
87708898 assert_eq!(back.lanes(), p.lanes(), "{what}: the lane list changed");
@@ -8800,6 +8928,22 @@ mod tests {
88008928 .collect()
88018929 };
88028930 assert_eq!(colors(&back), colors(p), "{what}: the colours changed");
8931+ // ...and the transform table, by the same claim again.
8932+ let transforms = |p: &Project| -> Vec<Vec<Option<TransformParams>>> {
8933+ p.lanes()
8934+ .into_iter()
8935+ .map(|l| {
8936+ (0..p.lane(l).len())
8937+ .map(|i| p.transform_of(l, i).copied())
8938+ .collect()
8939+ })
8940+ .collect()
8941+ };
8942+ assert_eq!(
8943+ transforms(&back),
8944+ transforms(p),
8945+ "{what}: the transforms changed"
8946+ );
88038947 }
88048948 }
88058949 }
crates/engine/src/scale.rsmodified+147 -0
@@ -1352,4 +1352,151 @@ mod tests {
13521352 let (y1, _, _) = blend_i420((&a.0, &a.1, &a.2), (&b.0, &b.1, &b.2), 1.0);
13531353 assert_eq!(y1, b.0);
13541354 }
1355+
1356+ /// The crop fractions cut a rect out of a 100x100 source at the very
1357+ /// pixels the maths says, chroma-grid aligned like every other rect here.
1358+ #[test]
1359+ fn crop_rect_math() {
1360+ let t = TransformParams {
1361+ crop_l: 0.1,
1362+ crop_r: 0.2,
1363+ crop_t: 0.0,
1364+ crop_b: 0.0,
1365+ ..Default::default()
1366+ };
1367+ assert_eq!(
1368+ crop_rect(100, 100, &t),
1369+ Rect { x: 10, y: 0, w: 70, h: 100 },
1370+ "10% off the left, 20% off the right, nothing off top or bottom"
1371+ );
1372+ // Opposing crops clamp to 0.5 a side rather than meeting or crossing.
1373+ let extreme = TransformParams {
1374+ crop_l: 0.9,
1375+ crop_r: 0.9,
1376+ ..Default::default()
1377+ };
1378+ let r = crop_rect(100, 100, &extreme);
1379+ assert!(r.w >= 2, "the smallest surviving rect is one chroma sample");
1380+ // A zero-sized source has nothing to crop.
1381+ assert_eq!(crop_rect(0, 100, &TransformParams::default()), Rect { x: 0, y: 0, w: 0, h: 0 });
1382+ }
1383+
1384+ /// A placement moved by `pos_x`/`pos_y` (canvas fractions about its own
1385+ /// centre) and resized by `scale`, both about that same centre.
1386+ #[test]
1387+ fn transformed_dst_rect_at_pos_and_scale() {
1388+ let dst = Rect { x: 0, y: 0, w: 100, h: 100 };
1389+ // Moved a quarter of the canvas to the right, untouched vertically.
1390+ let moved = TransformParams {
1391+ pos_x: 0.25,
1392+ ..Default::default()
1393+ };
1394+ assert_eq!(
1395+ transformed_dst_rect(dst, &moved, 200, 200),
1396+ Rect { x: 50, y: 0, w: 100, h: 100 },
1397+ "25% of a 200-wide canvas is 50 pixels, about the placement's own centre"
1398+ );
1399+ // Doubled in place: the centre stays, the box fills the canvas.
1400+ let grown = TransformParams {
1401+ scale: 2.0,
1402+ ..Default::default()
1403+ };
1404+ assert_eq!(
1405+ transformed_dst_rect(dst, &grown, 200, 200),
1406+ Rect { x: 0, y: 0, w: 200, h: 200 },
1407+ "a 100x100 box doubled about its own centre on a 200x200 canvas fills it"
1408+ );
1409+ }
1410+
1411+ /// [`nearest_90_steps`] rounds to the closest quarter turn and folds a
1412+ /// non-finite value to the identity.
1413+ #[test]
1414+ fn nearest_90_steps_rounds_and_wraps() {
1415+ assert_eq!(nearest_90_steps(0.0), 0);
1416+ assert_eq!(nearest_90_steps(89.0), 1);
1417+ assert_eq!(nearest_90_steps(91.0), 1);
1418+ assert_eq!(nearest_90_steps(180.0), 2);
1419+ assert_eq!(nearest_90_steps(-90.0), 3);
1420+ assert_eq!(nearest_90_steps(360.0 + 90.0), 1);
1421+ assert_eq!(nearest_90_steps(f32::NAN), 0);
1422+ }
1423+
1424+ /// A marked corner pixel lands where a clockwise quarter turn puts it:
1425+ /// top-left to top-right at 90 degrees, to bottom-right at 180, to
1426+ /// bottom-left at 270 -- and the plane's own shape swaps at 90 and 270
1427+ /// and stays put at 180.
1428+ #[test]
1429+ fn rotate_i420_90s_places_a_marked_pixel() {
1430+ let (w, h) = (4usize, 3usize);
1431+ let mut y = vec![0u8; w * h];
1432+ y[0] = 99; // (x=0, y=0), the top-left corner.
1433+ let (u, v) = (vec![128u8; 2 * 2], vec![128u8; 2 * 2]);
1434+
1435+ let mark_at = |plane: &[u8], w: u32, x: u32, y: u32| plane[(y * w + x) as usize];
1436+
1437+ let (ry, _, _, rw, rh) = rotate_i420_90s(&y, &u, &v, w as u32, h as u32, 1);
1438+ assert_eq!((rw, rh), (h as u32, w as u32), "dims swap at 90 degrees");
1439+ assert_eq!(mark_at(&ry, rw, rw - 1, 0), 99, "top-left moves to top-right");
1440+
1441+ let (ry, _, _, rw, rh) = rotate_i420_90s(&y, &u, &v, w as u32, h as u32, 2);
1442+ assert_eq!((rw, rh), (w as u32, h as u32), "dims stay put at 180 degrees");
1443+ assert_eq!(
1444+ mark_at(&ry, rw, rw - 1, rh - 1),
1445+ 99,
1446+ "top-left moves to bottom-right"
1447+ );
1448+
1449+ let (ry, _, _, rw, rh) = rotate_i420_90s(&y, &u, &v, w as u32, h as u32, 3);
1450+ assert_eq!((rw, rh), (h as u32, w as u32), "dims swap at 270 degrees");
1451+ assert_eq!(
1452+ mark_at(&ry, rw, 0, rh - 1),
1453+ 99,
1454+ "top-left moves to bottom-left"
1455+ );
1456+
1457+ // Zero steps, and four of them, are both the identity.
1458+ let (ry, ru, rv, rw, rh) = rotate_i420_90s(&y, &u, &v, w as u32, h as u32, 0);
1459+ assert_eq!((ry, ru, rv, rw, rh), (y.clone(), u.clone(), v.clone(), w as u32, h as u32));
1460+ let (ry, _, _, rw, rh) = rotate_i420_90s(&y, &u, &v, w as u32, h as u32, 4);
1461+ assert_eq!((ry, rw, rh), (y, w as u32, h as u32), "four quarter turns is the identity");
1462+ }
1463+
1464+ /// [`Composer::place_transformed`] at compose level: a picture placed with
1465+ /// a `pos_x` offset lands its marked pixel shifted by exactly that many
1466+ /// canvas pixels, with black everywhere else.
1467+ #[test]
1468+ fn place_transformed_shifts_a_marked_pixel() {
1469+ let (src_w, src_h) = (64u32, 64u32);
1470+ let (y, u, v) = (
1471+ vec![200u8; (src_w * src_h) as usize],
1472+ vec![NEUTRAL_C; ((src_w / 2) * (src_h / 2)) as usize],
1473+ vec![NEUTRAL_C; ((src_w / 2) * (src_h / 2)) as usize],
1474+ );
1475+ let mut canvas = Composer::new(src_w, src_h, FitPolicy::Fit);
1476+ // Identity: a pass-through-shaped placement, fills the whole canvas.
1477+ let (iy, _, _, iw, ih) = canvas.place_transformed(&y, &u, &v, src_w, src_h, &TransformParams::default());
1478+ assert_eq!((iw, ih), (src_w, src_h));
1479+ assert!(iy.iter().all(|&p| p == 200), "identity fills the canvas");
1480+
1481+ // Moved a quarter of the canvas to the right: the left half is black,
1482+ // the right half (minus the strip pushed off the edge) is the picture.
1483+ let moved = TransformParams {
1484+ pos_x: 0.25,
1485+ ..Default::default()
1486+ };
1487+ let (my, _, _, mw, mh) = canvas.place_transformed(&y, &u, &v, src_w, src_h, &moved);
1488+ assert_eq!((mw, mh), (src_w, src_h), "canvas size never changes");
1489+ let shift = (f64::from(src_w) * 0.25).round() as usize;
1490+ for row in 0..mh as usize {
1491+ let r = &my[row * mw as usize..][..mw as usize];
1492+ assert!(
1493+ r[..shift].iter().all(|&p| p == BLACK_Y),
1494+ "row {row}: black ahead of the shifted picture"
1495+ );
1496+ assert!(
1497+ r[shift..].iter().all(|&p| p == 200),
1498+ "row {row}: the picture fills the rest, shifted right"
1499+ );
1500+ }
1501+ }
13551502 }
crates/engine/tests/audio_export.rsmodified+17 -1
@@ -73,6 +73,7 @@ fn mixed_project() -> Project {
7373 color: None,
7474 fit: FitPolicy::default(),
7575 speed: Speed::NORMAL,
76+ transform: None,
7677 };
7778 Project::from_parts(
7879 vec![
@@ -98,12 +99,14 @@ fn mixed_project() -> Project {
9899 color: None,
99100 fit: FitPolicy::default(),
100101 speed: Speed::NORMAL,
102+ transform: None,
101103 }],
102104 ),
103105 (LaneKind::Audio, vec![clip(0, 0), clip(60, 1)]),
104106 ],
105107 Vec::new(),
106108 Vec::new(),
109+ Vec::new(),
107110 )
108111 .expect("a two-source project with a hole in the audio lane")
109112 }
@@ -345,6 +348,7 @@ fn a_still_and_a_song_export_as_an_mp4_with_sound() {
345348 color: None,
346349 fit: FitPolicy::default(),
347350 speed: Speed::NORMAL,
351+ transform: None,
348352 };
349353 // Two seconds of each at the project's own 30 fps: a still has no length of
350354 // its own and the song is longer than what is placed.
@@ -356,6 +360,7 @@ fn a_still_and_a_song_export_as_an_mp4_with_sound() {
356360 ],
357361 Vec::new(),
358362 Vec::new(),
363+ Vec::new(),
359364 )
360365 .expect("a still under a song");
361366 // The project's own picture size and rate: the still decides the one and
@@ -412,6 +417,7 @@ fn a_fader_is_one_tracks_own_and_the_limiter_holds_the_sum() {
412417 color: None,
413418 fit: FitPolicy::default(),
414419 speed: Speed::NORMAL,
420+ transform: None,
415421 };
416422 let four = || {
417423 Project::from_parts(
@@ -425,7 +431,8 @@ fn a_fader_is_one_tracks_own_and_the_limiter_holds_the_sum() {
425431 ],
426432 Vec::new(),
427433 Vec::new(),
428- )
434+ Vec::new(),
435+ )
429436 .expect("one second on four audio tracks")
430437 };
431438 let write = |project: Project, name: &str| {
@@ -651,6 +658,7 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() {
651658 color: None,
652659 fit: FitPolicy::default(),
653660 speed: Speed::NORMAL,
661+ transform: None,
654662 }],
655663 ),
656664 (
@@ -668,11 +676,13 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() {
668676 color: None,
669677 fit: FitPolicy::default(),
670678 speed: Speed::NORMAL,
679+ transform: None,
671680 }],
672681 ),
673682 ],
674683 Vec::new(),
675684 Vec::new(),
685+ Vec::new(),
676686 )
677687 .expect("a still under a song");
678688 let meta = engine::VideoMeta {
@@ -726,6 +736,7 @@ fn a_silent_clip_exports_as_silence_over_its_own_span() {
726736 color: None,
727737 fit: FitPolicy::default(),
728738 speed: Speed::NORMAL,
739+ transform: None,
729740 };
730741 let project = Project::from_parts(
731742 vec![
@@ -739,6 +750,7 @@ fn a_silent_clip_exports_as_silence_over_its_own_span() {
739750 ],
740751 Vec::new(),
741752 Vec::new(),
753+ Vec::new(),
742754 )
743755 .expect("a project whose middle take is silent");
744756
@@ -821,10 +833,12 @@ fn a_51_ac3_source_round_trips_through_a_wav() {
821833 color: None,
822834 fit: FitPolicy::default(),
823835 speed: Speed::NORMAL,
836+ transform: None,
824837 }],
825838 )],
826839 Vec::new(),
827840 Vec::new(),
841+ Vec::new(),
828842 )
829843 .expect("a one-source AC-3 project");
830844 let video = engine::demux::Demuxer::open(&source).expect("open the fixture").0;
@@ -951,10 +965,12 @@ fn a_mono_timeline_exports_as_dual_mono_ogg() {
951965 color: None,
952966 fit: FitPolicy::default(),
953967 speed: Speed::NORMAL,
968+ transform: None,
954969 }],
955970 )],
956971 Vec::new(),
957972 Vec::new(),
973+ Vec::new(),
958974 )
959975 .expect("a one-source mono project");
960976
crates/engine/tests/eq_audio.rsmodified+3 -0
@@ -66,6 +66,7 @@ fn clip(start: u32, source: usize, frames: u32) -> Clip {
6666 color: None,
6767 fit: FitPolicy::default(),
6868 speed: Speed::NORMAL,
69+ transform: None,
6970 }
7071 }
7172
@@ -80,6 +81,7 @@ fn project(audio: Vec<Clip>) -> Project {
8081 ],
8182 Vec::new(),
8283 Vec::new(),
84+ Vec::new(),
8385 )
8486 .expect("a one-source project")
8587 }
@@ -245,6 +247,7 @@ fn a_lane_is_equalized_before_the_mix_and_never_after_it() {
245247 ],
246248 Vec::new(),
247249 Vec::new(),
250+ Vec::new(),
248251 )
249252 .expect("a two-audio-lane project");
250253 assert_eq!(p.audio_lanes().len(), 2, "both lanes hold something");
crates/engine/tests/export.rsmodified+4 -0
@@ -244,6 +244,7 @@ fn exports_at_the_project_resolution_with_the_watched_geometry() {
244244 link: Some(source as u32),
245245 eq: None,
246246 color: None,
247+ transform: None,
247248 fit: FitPolicy::default(),
248249 speed: Speed::NORMAL,
249250 };
@@ -259,6 +260,7 @@ fn exports_at_the_project_resolution_with_the_watched_geometry() {
259260 ],
260261 Vec::new(),
261262 Vec::new(),
263+ Vec::new(),
262264 )
263265 .expect("a two-source project");
264266 // The project's own resolution, which is neither source's: this is the
@@ -329,6 +331,7 @@ fn exports_the_audio_stream_the_timeline_plays() {
329331 link: Some(0),
330332 eq: None,
331333 color: None,
334+ transform: None,
332335 fit: FitPolicy::default(),
333336 speed: Speed::NORMAL,
334337 };
@@ -346,6 +349,7 @@ fn exports_the_audio_stream_the_timeline_plays() {
346349 ],
347350 Vec::new(),
348351 Vec::new(),
352+ Vec::new(),
349353 )
350354 .expect("a one-source project on stream 1");
351355 let out = out_path("stream1");
crates/engine/tests/lanes.rsmodified+6 -2
@@ -245,6 +245,7 @@ fn the_mp4_copy_follows_the_lane_that_holds_the_sound() {
245245 link: None,
246246 eq: None,
247247 color: None,
248+ transform: None,
248249 fit: FitPolicy::default(),
249250 speed: Speed::NORMAL,
250251 };
@@ -257,6 +258,7 @@ fn the_mp4_copy_follows_the_lane_that_holds_the_sound() {
257258 ],
258259 vec![],
259260 vec![],
261+ vec![],
260262 )
261263 .expect("valid parts");
262264 assert_eq!(
@@ -309,14 +311,15 @@ fn two_audio_lanes_are_summed() {
309311 link: None,
310312 eq: None,
311313 color: None,
314+ transform: None,
312315 fit: FitPolicy::default(),
313316 speed: Speed::NORMAL,
314317 };
315318 let a2 = project.add_lane(LaneKind::Audio);
316319 assert!(project.place(a2, TOP_IN, doubled), "place the second lane");
317- let (sources, lanes, eq, color) = project.without_orphan_sources();
320+ let (sources, lanes, eq, color, transform) = project.without_orphan_sources();
318321 assert_eq!(lanes.len(), 3, "V1, A1 and the new A2");
319- let project = Project::from_parts(sources, lanes, eq, color).expect("valid parts");
322+ let project = Project::from_parts(sources, lanes, eq, color, transform).expect("valid parts");
320323
321324 let (meta, _) = engine::demux::Demuxer::open(&asset("test_av.mp4")).unwrap();
322325 let wav = |name: &str, project: Project| {
@@ -507,6 +510,7 @@ fn a_subtitle_lane_is_a_peer_and_every_media_path_refuses_it() {
507510 vec![(LaneKind::Subtitle, vec![clip])],
508511 Vec::new(),
509512 Vec::new(),
513+ Vec::new(),
510514 )
511515 .expect_err("a file may not name one either");
512516 assert!(
crates/engine/tests/opus_export.rsmodified+4 -0
@@ -92,6 +92,7 @@ fn project(video: &Path, sound: &Path, sound_in: u32) -> Project {
9292 color: None,
9393 fit: FitPolicy::default(),
9494 speed: Speed::NORMAL,
95+ transform: None,
9596 };
9697 // The sound is source **0** on purpose: the timeline takes its rate and its
9798 // width from the first source that has any, so a project whose first source
@@ -109,6 +110,7 @@ fn project(video: &Path, sound: &Path, sound_in: u32) -> Project {
109110 ],
110111 Vec::new(),
111112 Vec::new(),
113+ Vec::new(),
112114 )
113115 .expect("a picture lane and an audio lane")
114116 }
@@ -436,6 +438,7 @@ fn a_copied_picture_names_the_sound_it_was_written_with() {
436438 color: None,
437439 fit: FitPolicy::default(),
438440 speed: Speed::NORMAL,
441+ transform: None,
439442 };
440443 // The sound is source 0, for the reason [`project`] gives: the timeline
441444 // takes its rate and its width from the first source that has any.
@@ -447,6 +450,7 @@ fn a_copied_picture_names_the_sound_it_was_written_with() {
447450 ],
448451 Vec::new(),
449452 Vec::new(),
453+ Vec::new(),
450454 )
451455 .expect("a picture lane and an audio lane");
452456 let out = out_path("copy_line");
crates/engine/tests/silence.rsmodified+6 -3
@@ -36,8 +36,8 @@ fn fixture() -> Project {
3636 /// is one no save could load: this is that check, through the same door a load
3737 /// takes.
3838 fn loadable(project: &Project) {
39- let (sources, lanes, eq, color) = project.without_orphan_sources();
40- Project::from_parts(sources, lanes, eq, color).expect("the lanes still load");
39+ let (sources, lanes, eq, color, transform) = project.without_orphan_sources();
40+ Project::from_parts(sources, lanes, eq, color, transform).expect("the lanes still load");
4141 }
4242
4343 fn spans(project: &Project) -> (Vec<(u32, u32)>, Vec<(u32, u32)>) {
@@ -150,6 +150,7 @@ fn speed_mode_refuses_a_clip_that_laps_over_a_silence() {
150150 color: None,
151151 fit: Default::default(),
152152 speed: Speed::NORMAL,
153+ transform: None,
153154 };
154155 assert!(p.place(lane, 40, broll));
155156 let before = spans(&p);
@@ -188,6 +189,7 @@ fn whole(source: usize, frames: u32) -> Clip {
188189 color: None,
189190 fit: Default::default(),
190191 speed: Speed::NORMAL,
192+ transform: None,
191193 }
192194 }
193195
@@ -370,7 +372,7 @@ fn scanning_a_clip_and_cutting_what_it_finds() {
370372 // same dialect it always was -- no wire change went with this feature.
371373 let dir = Scratch::dir("edith-silence");
372374 let file = dir.join("cut.edith");
373- let (sources, lanes, eq, color) = p.without_orphan_sources();
375+ let (sources, lanes, eq, color, transform) = p.without_orphan_sources();
374376 engine::edith::save(
375377 &file,
376378 &sources,
@@ -380,6 +382,7 @@ fn scanning_a_clip_and_cutting_what_it_finds() {
380382 p.subtitles(),
381383 &eq,
382384 &color,
385+ &transform,
383386 (1920, 1080),
384387 None,
385388 p.tone(),